diff --git a/CHANGELOG.md b/CHANGELOG.md index a5203640fee..be740b5fabf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Unreleased -- The built-in `sqlite3** module of Python is now enabled. +- The built-in `sqlite` and `bz2` modules of Python are now enabled. - New package: `nltk` diff --git a/Makefile b/Makefile index a6761596485..d6c42580496 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ LDFLAGS=\ -s USE_LIBPNG=1 \ -std=c++14 \ -L$(wildcard $(CPYTHONROOT)/build/sqlite*/.libs) -lsqlite3 \ + $(wildcard $(CPYTHONROOT)/build/bzip2*/libbz2.a) \ -lstdc++ \ --memory-init-file 0 \ -s "BINARYEN_TRAP_MODE='clamp'" \ diff --git a/cpython/Makefile b/cpython/Makefile index 6b554bc8136..357d1528e14 100644 --- a/cpython/Makefile +++ b/cpython/Makefile @@ -24,6 +24,10 @@ SQLITETARBALL=$(ROOT)/downloads/sqlite-autoconf-3270200.tar.gz SQLITEBUILD=$(ROOT)/build/sqlite-autoconf-3270200 SQLITEURL=https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz +BZIP2TARBALL=$(ROOT)/downloads/bzip2-1.0.2.tar.gz +BZIP2BUILD=$(ROOT)/build/bzip2-1.0.2 +BZIP2URL=ftp://sources.redhat.com/pub/bzip2/v102/bzip2-1.0.2.tar.gz + all: $(INSTALL)/lib/$(LIB) @@ -62,6 +66,11 @@ $(SQLITETARBALL): wget -q -O $@ $(SQLITEURL) +$(BZIP2TARBALL): + [ -d $(ROOT)/downloads ] || mkdir $(ROOT)/downloads + wget -q -O $@ $(BZIP2URL) + + $(HOSTPYTHON) $(HOSTPGEN): $(TARBALL) mkdir -p $(HOSTINSTALL) [ -d $(HOSTBUILD) ] || tar -C $(HOSTINSTALL) -xf $(TARBALL) @@ -98,21 +107,30 @@ $(SQLITEBUILD)/libsqlite3.la: $(SQLITETARBALL) ) -$(BUILD)/Makefile: $(BUILD)/.patched $(ZLIBBUILD)/.patched $(SQLITEBUILD)/libsqlite3.la +$(BZIP2BUILD)/libbz2.a: $(BZIP2TARBALL) + [ -d $(ROOT)/build ] || (mkdir $(ROOT)/build) + tar -C $(ROOT)/build/ -xf $(BZIP2TARBALL) + ( \ + cd $(BZIP2BUILD); \ + emmake make CC=emcc CFLAGS="-Wall -Winline -O2 -fomit-frame-pointer -D_FILE_OFFSET_BITS=64" AR=emar RANLIB=emranlib libbz2.a; \ + ) + + +$(BUILD)/Makefile: $(BUILD)/.patched $(ZLIBBUILD)/.patched $(SQLITEBUILD)/libsqlite3.la $(BZIP2BUILD)/libbz2.a cp config.site $(BUILD)/ ( \ cd $(BUILD); \ - CONFIG_SITE=./config.site READELF=true LD_RUN_PATH=$(SQLITEBUILD) emconfigure \ + CONFIG_SITE=./config.site READELF=true LD_RUN_PATH="$(SQLITEBUILD):$(BZIP2BUILD)" emconfigure \ ./configure \ - CPPFLAGS="-I$(SQLITEBUILD)" \ - LDFLAGS="-L$(SQLITEBUILD)" \ - --without-pymalloc \ - --disable-shared \ - --disable-ipv6 \ - --without-gcc \ - --host=asmjs-unknown-emscripten \ - --build=$(shell $(BUILD)/config.guess) \ - --prefix=$(INSTALL) ; \ + CPPFLAGS="-I$(SQLITEBUILD) -I$(BZIP2BUILD)" \ + LDFLAGS="-L$(SQLITEBUILD) -L$(BZIP2BUILD)" \ + --without-pymalloc \ + --disable-shared \ + --disable-ipv6 \ + --without-gcc \ + --host=asmjs-unknown-emscripten \ + --build=$(shell $(BUILD)/config.guess) \ + --prefix=$(INSTALL) ; \ ) diff --git a/cpython/Setup.local b/cpython/Setup.local index b11aaaf4cf6..7b189a606e4 100644 --- a/cpython/Setup.local +++ b/cpython/Setup.local @@ -37,6 +37,7 @@ _blake2 _blake2/blake2module.c _blake2/blake2b_impl.c ../../host/Python-3.7.0/Mo _sqlite3 _sqlite/cache.c _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c -I$(SQLITEBUILD) -L$(SQLITEBUILD) -lsqlite3 _crypt _cryptmodule.c +_bz2 _bz2module.c -I$(BZIP2BUILD) -L$(BZIP2BUILD) -lbz2 _queue _queuemodule.c diff --git a/src/js2python.c b/src/js2python.c index 4c95609d86f..2788a8b0c61 100644 --- a/src/js2python.c +++ b/src/js2python.c @@ -26,7 +26,7 @@ _js2python_number(double val) double i; if (modf(val, &i) == 0.0) - return (int)PyLong_FromLong(i); + return (int)PyLong_FromDouble(i); return (int)PyFloat_FromDouble(val); } diff --git a/test/python_tests.txt b/test/python_tests.txt index 248b987465e..2171c0be6c3 100644 --- a/test/python_tests.txt +++ b/test/python_tests.txt @@ -81,7 +81,7 @@ test_buffer test_bufio test_builtin floating point test_bytes -test_bz2 +test_bz2 threading test_c_locale_coercion test_calendar test_call diff --git a/test/test_bz2.py b/test/test_bz2.py new file mode 100644 index 00000000000..191f07c53af --- /dev/null +++ b/test/test_bz2.py @@ -0,0 +1,10 @@ +def test_bz2(selenium): + selenium.run(""" + import bz2 + + text = "Hello test test test test this is a test test test" + some_compressed_bytes = bz2.compress(text.encode('utf-8')) + assert some_compressed_bytes != text + decompressed_bytes = bz2.decompress(some_compressed_bytes) + assert decompressed_bytes.decode('utf-8') == text + """) diff --git a/test/test_python.py b/test/test_python.py index ac951ffd927..83ce6d596e0 100644 --- a/test/test_python.py +++ b/test/test_python.py @@ -224,10 +224,10 @@ def test_js2python(selenium): 'jsstring_ucs4 == "🐍"') assert selenium.run( 'from js import jsnumber0\n' - 'jsnumber0 == 42') + 'jsnumber0 == 42 and isinstance(jsnumber0, int)') assert selenium.run( 'from js import jsnumber1\n' - 'jsnumber1 == 42.5') + 'jsnumber1 == 42.5 and isinstance(jsnumber1, float)') assert selenium.run( 'from js import jsundefined\n' 'jsundefined is None')