Skip to content

Commit

Permalink
Include test_windirent and fix PYTHONPATH bug on travis
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayP13 committed Nov 15, 2018
1 parent 8093a46 commit b2f88fe
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ script:
- /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- brew install gcc@8 --without-multilib
- export CC="/usr/local/Cellar/gcc/8.2.0/bin/gcc-8"
- export PYTHONPATH=$(python3 -c "import site; print(site.getsitepackages())[0]")
- export PYTHONPATH=$(python3 -c "import site; print(site.getsitepackages()[0])")
- echo $PYTHONPATH
- $PIP install pip setuptools -U
- $PIP install cibuildwheel==0.10.0
Expand Down
29 changes: 21 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ def get_modules(THIRD_PARTY, INTERNAL, PROJ_PATH,
library_dirs=libraries,
libraries=[
"user32",
"Advapi32"] if sys.platform == "win32" else [],
"Advapi32",
"Kernel32"] if sys.platform == "win32" else [],
extra_compile_args=compile_args,
extra_link_args=link_args)

Expand All @@ -470,21 +471,33 @@ def sqlite_extension(ext, skip=[], module=None):
extra_compile_args=["-O4"],
extra_link_args=link_args)

def sqlite_misc_extensions(skip=[], zlib=[]):
def sqlite_misc_extensions(skip=[], zlib=[], windirent=[]):
miscs = []
for source in glob(os.path.join(SQLITE_EXT, 'misc', '*.c')):
if os.path.basename(source) in skip:
continue
module = os.path.basename(source)[:-2]
pyinit_source = source_for_module_with_pyinit(module)
z_sources = zlib_sources if os.path.basename(source) in zlib else []
windirent_sources = (
[
os.path.relpath(
os.path.join(
SQLITE3,
"test_windirent.c"),
PROJ_PATH)] if os.path.basename(source) in windirent else [])
miscs.append(
Extension(SO_PREFIX + module,
sources=[source] + z_sources + [pyinit_source],
include_dirs=includes,
library_dirs=libraries,
extra_compile_args=["-O4"],
extra_link_args=link_args))
Extension(
SO_PREFIX +
module,
sources=[source] +
z_sources +
windirent_sources +
[pyinit_source],
include_dirs=includes,
library_dirs=libraries,
extra_compile_args=["-O4"],
extra_link_args=link_args))
return miscs

lsm1 = sqlite_extension('lsm1')
Expand Down
2 changes: 1 addition & 1 deletion supersqlite/third_party/HOWTOUPGRADE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ There are a few components that need updating when updating the version of `sqli

3. **Update SQLite3:** Download the latest SQLite Amalgamation package from the [SQLite website](https://www.sqlite.org/download.html). Update `third_party/sqlite3/sqlite3.c.pre.c` (with `sqlite3.c`) and update `third_party/sqlite3/sqlite3.h`, `third_party/sqlite3/sqlite3_ext.h`, and `third_party/sqlite3/shell.c` from the SQLite Amalgamation package.

3. **Update SQLite3 Extensions:** Download the latest SQLite source code package from the [SQLite website](https://www.sqlite.org/download.html). Update the `third_party/sqlite3/ext` with the `ext` filder from the SQLite Amalgamation package.
3. **Update SQLite3 Extensions:** Download the latest SQLite source code package from the [SQLite website](https://www.sqlite.org/download.html). Update the `third_party/sqlite3/ext` with the `ext` folder from the SQLite source code package. Also copy `test_windirent.h` and `test_windirent.c` from the `src` folder to `third_party/sqlite3/`.

4. **Copy `shell.c`:** Copy `shell.c` from the root of `third_party/_apsw` (which was updated in step #1) to `third_party/sqlite3/apsw_shell.c`.

Expand Down
2 changes: 1 addition & 1 deletion supersqlite/third_party/_apsw/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def create_c_file(src, dest):
["src/apsw.c", "src/sqlite3.c", "src/icu.cpp"], # PLASTICITY
include_dirs=include_dirs + include_plasticity, # PLASTICITY
library_dirs=library_dirs,
libraries=libraries + (["user32", "Advapi32"] if sys.platform == "win32" else []), # PLASTICITY
libraries=libraries + (["user32", "Advapi32", "Kernel32"] if sys.platform == "win32" else []), # PLASTICITY
define_macros=define_macros,
extra_compile_args=["-O4", "-std=c++11"], # PLASTICITY
extra_link_args=["-flto"], # PLASTICITY
Expand Down
2 changes: 1 addition & 1 deletion supersqlite/third_party/_pysqlite/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def get_setup_args():
include_dirs=include_dirs + include_plasticity, # PLASTICITY
library_dirs=library_dirs,
runtime_library_dirs=runtime_library_dirs,
libraries=libraries + (["user32", "Advapi32"] if sys.platform == "win32" else []), # PLASTICITY
libraries=libraries + (["user32", "Advapi32", "Kernel32"] if sys.platform == "win32" else []), # PLASTICITY
extra_objects=extra_objects,
define_macros=define_macros,
extra_compile_args=["-O4", "-std=c++11"], # PLASTICITY
Expand Down
191 changes: 191 additions & 0 deletions supersqlite/third_party/sqlite3/test_windirent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/*
** 2015 November 30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code to implement most of the opendir() family of
** POSIX functions on Win32 using the MSVCRT.
*/

#if defined(_WIN32) && defined(_MSC_VER)
#include "test_windirent.h"

/*
** Implementation of the POSIX getenv() function using the Win32 API.
** This function is not thread-safe.
*/
const char *windirent_getenv(
const char *name
){
static char value[32768]; /* Maximum length, per MSDN */
DWORD dwSize = sizeof(value) / sizeof(char); /* Size in chars */
DWORD dwRet; /* Value returned by GetEnvironmentVariableA() */

memset(value, 0, sizeof(value));
dwRet = GetEnvironmentVariableA(name, value, dwSize);
if( dwRet==0 || dwRet>dwSize ){
/*
** The function call to GetEnvironmentVariableA() failed -OR-
** the buffer is not large enough. Either way, return NULL.
*/
return 0;
}else{
/*
** The function call to GetEnvironmentVariableA() succeeded
** -AND- the buffer contains the entire value.
*/
return value;
}
}

/*
** Implementation of the POSIX opendir() function using the MSVCRT.
*/
LPDIR opendir(
const char *dirname
){
struct _finddata_t data;
LPDIR dirp = (LPDIR)sqlite3_malloc(sizeof(DIR));
SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]);

if( dirp==NULL ) return NULL;
memset(dirp, 0, sizeof(DIR));

/* TODO: Remove this if Unix-style root paths are not used. */
if( sqlite3_stricmp(dirname, "/")==0 ){
dirname = windirent_getenv("SystemDrive");
}

memset(&data, 0, sizeof(struct _finddata_t));
_snprintf(data.name, namesize, "%s\\*", dirname);
dirp->d_handle = _findfirst(data.name, &data);

if( dirp->d_handle==BAD_INTPTR_T ){
closedir(dirp);
return NULL;
}

/* TODO: Remove this block to allow hidden and/or system files. */
if( is_filtered(data) ){
next:

memset(&data, 0, sizeof(struct _finddata_t));
if( _findnext(dirp->d_handle, &data)==-1 ){
closedir(dirp);
return NULL;
}

/* TODO: Remove this block to allow hidden and/or system files. */
if( is_filtered(data) ) goto next;
}

dirp->d_first.d_attributes = data.attrib;
strncpy(dirp->d_first.d_name, data.name, NAME_MAX);
dirp->d_first.d_name[NAME_MAX] = '\0';

return dirp;
}

/*
** Implementation of the POSIX readdir() function using the MSVCRT.
*/
LPDIRENT readdir(
LPDIR dirp
){
struct _finddata_t data;

if( dirp==NULL ) return NULL;

if( dirp->d_first.d_ino==0 ){
dirp->d_first.d_ino++;
dirp->d_next.d_ino++;

return &dirp->d_first;
}

next:

memset(&data, 0, sizeof(struct _finddata_t));
if( _findnext(dirp->d_handle, &data)==-1 ) return NULL;

/* TODO: Remove this block to allow hidden and/or system files. */
if( is_filtered(data) ) goto next;

dirp->d_next.d_ino++;
dirp->d_next.d_attributes = data.attrib;
strncpy(dirp->d_next.d_name, data.name, NAME_MAX);
dirp->d_next.d_name[NAME_MAX] = '\0';

return &dirp->d_next;
}

/*
** Implementation of the POSIX readdir_r() function using the MSVCRT.
*/
INT readdir_r(
LPDIR dirp,
LPDIRENT entry,
LPDIRENT *result
){
struct _finddata_t data;

if( dirp==NULL ) return EBADF;

if( dirp->d_first.d_ino==0 ){
dirp->d_first.d_ino++;
dirp->d_next.d_ino++;

entry->d_ino = dirp->d_first.d_ino;
entry->d_attributes = dirp->d_first.d_attributes;
strncpy(entry->d_name, dirp->d_first.d_name, NAME_MAX);
entry->d_name[NAME_MAX] = '\0';

*result = entry;
return 0;
}

next:

memset(&data, 0, sizeof(struct _finddata_t));
if( _findnext(dirp->d_handle, &data)==-1 ){
*result = NULL;
return ENOENT;
}

/* TODO: Remove this block to allow hidden and/or system files. */
if( is_filtered(data) ) goto next;

entry->d_ino = (ino_t)-1; /* not available */
entry->d_attributes = data.attrib;
strncpy(entry->d_name, data.name, NAME_MAX);
entry->d_name[NAME_MAX] = '\0';

*result = entry;
return 0;
}

/*
** Implementation of the POSIX closedir() function using the MSVCRT.
*/
INT closedir(
LPDIR dirp
){
INT result = 0;

if( dirp==NULL ) return EINVAL;

if( dirp->d_handle!=NULL_INTPTR_T && dirp->d_handle!=BAD_INTPTR_T ){
result = _findclose(dirp->d_handle);
}

sqlite3_free(dirp);
return result;
}

#endif /* defined(WIN32) && defined(_MSC_VER) */
Loading

0 comments on commit b2f88fe

Please sign in to comment.