zopefoundation / zodbpickle

Fork of Python's pickle module to work with ZODB
Other
17 stars 15 forks source link

Fails to build on Python 3.2 on Windows: 'stackUnderflow' undefined #16

Closed mgedmin closed 7 years ago

mgedmin commented 9 years ago

Here's an excerpt from the build log:

building 'zodbpickle._pickle' extension
creating build\temp.win32-3.2
creating build\temp.win32-3.2\Release
creating build\temp.win32-3.2\Release\src
creating build\temp.win32-3.2\Release\src\zodbpickle
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Ic:\Python32_32\include -Ic:\Python32_32\PC /Tcsrc/zodbpickle/_pickle_32.c /Fobuild\temp.win32-3.2\Release\src/zodbpickle/_pickle_32.obj
_pickle_32.c
src/zodbpickle/_pickle_32.c(5618) : warning C4013: 'stackUnderflow' undefined; assuming extern returning int
creating build\lib.win32-3.2
creating build\lib.win32-3.2\zodbpickle
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:c:\Python32_32\libs /LIBPATH:c:\Python32_32\PCbuild /EXPORT:PyInit__pickle build\temp.win32-3.2\Release\src/zodbpickle/_pickle_32.obj /OUT:build\lib.win32-3.2\zodbpickle\_pickle.pyd /IMPLIB:build\temp.win32-3.2\Release\src/zodbpickle\_pickle.lib /MANIFESTFILE:build\temp.win32-3.2\Release\src/zodbpickle\_pickle.pyd.manifest
   Creating library build\temp.win32-3.2\Release\src/zodbpickle\_pickle.lib and object build\temp.win32-3.2\Release\src/zodbpickle\_pickle.exp
_pickle_32.obj : error LNK2019: unresolved external symbol _stackUnderflow referenced in function _do_noload_setitems
build\lib.win32-3.2\zodbpickle\_pickle.pyd : fatal error LNK1120: 1 unresolved externals
mgedmin commented 9 years ago

_pickle_27.c has a static int stackUnderflow(). _pickle_32.c has a static int stack_underflow(). Looks like the C implementation of noload calls the wrong one:

diff --git a/src/zodbpickle/_pickle_32.c b/src/zodbpickle/_pickle_32.c
index 2e559da..a5076bc 100644
--- a/src/zodbpickle/_pickle_32.c
+++ b/src/zodbpickle/_pickle_32.c
@@ -5615,7 +5615,7 @@ do_noload_setitems(UnpicklerObject *self, Py_ssize_t x)
     Py_ssize_t len;

     if (!( (len=Py_SIZE(self->stack)) >= x
-           && x > 0 ))  return stackUnderflow();
+           && x > 0 ))  return stack_underflow();

     dict=self->stack->data[x-1];
     if (dict == Py_None) {

What's more worrying is that no tests fail when the C module cannot be built. This is why I'm not committing my fix yet.

mgedmin commented 9 years ago

BTW on Linux the undefined name doesn't cause a compile-time error, it causes an import-time error:

$ tox -e py32
...
building 'zodbpickle._pickle' extension
gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python3.2mu -c src/zodbpickle/_pickle_32.c -o build/temp.linux-x86_64-3.2/src/zodbpickle/_pickle_32.o
src/zodbpickle/_pickle_32.c: In function ‘do_noload_setitems’:
src/zodbpickle/_pickle_32.c:5618:12: warning: implicit declaration of function ‘stackUnderflow’ [-Wimplicit-function-declaration]
            && x > 0 ))  return stackUnderflow();
            ^
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-3.2/src/zodbpickle/_pickle_32.o -o build/lib.linux-x86_64-3.2/zodbpickle/_pickle.cpython-32mu.so
copying build/lib.linux-x86_64-3.2/zodbpickle/_pickle.cpython-32mu.so -> src/zodbpickle
.............s.........s..............sss......s..........................................
----------------------------------------------------------------------
Ran 90 tests in 0.335s

OK (skipped=6)

$ .tox/py32/bin/python
...
>>> from zodbpickle import _pickle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /home/mg/src/zopefoundation/zodbpickle/.tox/py32/lib/python3.2/site-packages/zodbpickle/_pickle.cpython-32mu.so: undefined symbol: stackUnderflow
mgedmin commented 7 years ago

Somebody ought to check whether this issue affects Python 3.3 and newer.

mgedmin commented 7 years ago

AFAICS this was only affecting Python 3.2, which we're no longer supporting, so closing this bug.