Undefined symbol _Py_ZeroStruct
Franck Pommereau <[email protected]> Wed, 30 Sep 2009 17:53:02 +0200
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------050506090406000407080907
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Hi all,
I'm trying to use Pyrex/Cython to build a bridge between Python and Java
using JNI. It works on simple examples but fails on more complex ones.
Essentially, I have the following structure:
- a file "hello.py" with a class "hello.Hello" inside
- "_hello.pyx" that wraps the methods of "hello.Hello" to functions
with the interface expected by JNI, it is compiled to "_hello.so"
- "Hello.java" that defines a class to wrap "hello.Hello" through the
functions provided in "_hello.so"
The trickery required to define "_hello.pyx" correctly is explained on
my blog:
http://pommereau.blogspot.com/2009/05/interfacing-java-and-python-through-jni.html
Everything is OK as long as module "hello" does not try to load and use
other modules. For instance, it could do
import xml.dom.minidom
xml.dom.minidom.parseString("...")
Then, function "init_hello" silently fails. I can notice it fails
because immediately after, the Python content of module "_hello" is not
available and "NameError"s are reported. If, just after calling
"init_hello", I manually try to import module "hello", this results in
an error report:
Exception ImportError: '/usr/lib/python2.6/lib-dynload/pyexpat.so:
undefined symbol: _Py_ZeroStruct' in '_hello.JNI_OnLoad' ignored
"_hello.JNI_OnLoad" is a function that calls "Py_Initialize()" and
"init_hello()" and that is called automatically by the JVM just after it
loaded "_hello.so". I tried to replace "xml.dom.minidom" with other
modules, this result in the same error (except that "pyexpat.so" is
replaced with what was required and loaded instead).
Notice that module "_hello" is always loaded perfectly from a Python
interpreter and I never get this undefined symbol problem.
I attach all the files required to reproduce the error.
Does anyone has an idea? I'd be very grateful for any hint, I'm out of
ideas...
Many thanks in advance,
Franck
--------------050506090406000407080907
Content-Type: text/x-chdr;
name="cythonjni.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="cythonjni.h"
#define RET_jlong JNIEXPORT jlong JNICALL
#define RET_void JNIEXPORT void JNICALL
#define RET_jint JNIEXPORT jint JNICALL
#define long_toRET(x) (jlong)x
#define int_toRET(x) (jint)x
--------------050506090406000407080907
Content-Type: text/x-python;
name="hello.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="hello.py"
## comment this two lines to remove errors
import xml.dom.minidom
print xml.dom.minidom.parseString("""<?xml version="1.0" encoding="utf-8"?><doc></doc>""")
class Hello :
def __init__ (self, base) :
self.base = base
def add (self, nbr) :
return nbr + self.base
--------------050506090406000407080907
Content-Type: text/plain;
name="_hello.pyx"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="_hello.pyx"
Y2RlZiBleHRlcm4gZnJvbSAiY3l0aG9uam5pLmgiIDoKICAgIGN0eXBlZGVmIHN0cnVjdCBS
RVRfamxvbmcgOgogICAgICAgIHBhc3MKICAgIGN0eXBlZGVmIHN0cnVjdCBSRVRfamludCA6
CiAgICAgICAgcGFzcwogICAgY3R5cGVkZWYgc3RydWN0IFJFVF92b2lkIDoKICAgICAgICBw
YXNzCiAgICBSRVRfamxvbmcgbG9uZ190b1JFVChsb25nKQogICAgUkVUX2ppbnQgaW50X3Rv
UkVUKGludCkKCmNkZWYgZXh0ZXJuIGZyb20gImpuaS5oIiA6CiAgICBjdHlwZWRlZiBzdHJ1
Y3QgSk5JRW52IDoKICAgICAgICBwYXNzCiAgICBjdHlwZWRlZiBzdHJ1Y3QgamxvbmcgOgog
ICAgICAgIHBhc3MKICAgIGN0eXBlZGVmIHN0cnVjdCBqaW50IDoKICAgICAgICBwYXNzCiAg
ICBjdHlwZWRlZiBzdHJ1Y3QgamNsYXNzIDoKICAgICAgICBwYXNzCiAgICBjdHlwZWRlZiBz
dHJ1Y3Qgam9iamVjdCA6CiAgICAgICAgcGFzcwogICAgY3R5cGVkZWYgc3RydWN0IEphdmFW
TSA6CiAgICAgICAgcGFzcwogICAgUkVUX2ppbnQgSk5JX1ZFUlNJT05fMV8yCgpjZGVmIGV4
dGVybiBmcm9tICJQeXRob24uaCIgOgogICAgdm9pZCBQeV9Jbml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iAgICBnbG9iYWwgbGFzdAogICAgY2RlZiBs
b25nIGlkZW50ID0gbGFzdAogICAgbGFzdCArPSAxCiAgICBfaW5zdGFuY2VzW2lkZW50XSA9
IGhlbGxvLkhlbGxvKDxpbnQ+YmFzZSkKICAgIHJldHVybiBsb25nX3RvUkVUKGlkZW50KQoK
Y2RlZiBwdWJsaWMgUkVUX2psb25nIEphdmFfSGVsbG9fcHlkZWwgKEpOSUVudiAqIGVudiwg
am9iamVjdCBvYmosIGpsb25nIGlkZW50KSA6CiAgICAiIiJGdW5jdGlvbiBjYWxsZWQgd2hl
biB0aGUgSmF2YSBvYmplY3QgaXMgZ2FyYmFnZSBjb2xsZWN0ZWQgaW4KICAgIG9yZGVyIHRv
IGRlbGV0ZSB0aGUgY29ycmVzcG9uZGluZyBQeXRob24gb2JqZWN0LgogICAgIiIiCiAgICBk
ZWwgX2luc3RhbmNlc1s8bG9uZz5pZGVudF0KICAgICNwcmludCAiKioqIEdDIHJlbW92ZWQg
b2JqZWN0ICMlcyIgJSAoPGxvbmc+aWRlbnQpCiAgICByZXR1cm4gbG9uZ190b1JFVCg8bG9u
Zz5pZGVudCkKCmNkZWYgcHVibGljIFJFVF9qaW50IEphdmFfSGVsbG9fcHlhZGQgKEpOSUVu
diAqIGVudiwgam9iamVjdCBvYmosIGpsb25nIGlkZW50LCBqaW50IG5icikgOgogICAgIiIi
V3JhcHBlciBmb3IgbWV0aG9kIGhlbGxvLkhlbGxvLmFkZAogICAgIiIiCiAgICBjZGVmIGlu
dCByZXQKICAgIHJldCA9IF9pbnN0YW5jZXNbPGxvbmc+aWRlbnRdLmFkZCg8aW50Pm5icikK
ICAgIHJldHVybiBpbnRfdG9SRVQocmV0KQo=
--------------050506090406000407080907
Content-Type: text/x-java;
name="Hello.java"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="Hello.java"
Y2xhc3MgSGVsbG8gewogICAgc3RhdGljIHtTeXN0ZW0ubG9hZCgiL2hvbWUvZnJhbmNrL3dv
cmsvdG9vbHMvc25ha2VzL29zYS9jbGFzc3dyYXAvX2hlbGxvLnNvIik7fQogICAgcHJpdmF0
ZSBsb25nIHB5b2JqOwogICAgcHJpdmF0ZSBzdGF0aWMgbmF0aXZlIGxvbmcgcHlpbml0IChp
bnQgYmFzZSk7CiAgICBwdWJsaWMgSGVsbG8gKGludCBiYXNlKSB7CglweW9iaiA9IHB5aW5p
dChiYXNlKTsKICAgIH0KICAgIHByaXZhdGUgbmF0aXZlIGludCBweWFkZCAobG9uZyBvYmos
IGludCBuYnIpOwogICAgcHVibGljIGludCBhZGQgKGludCBuYnIpIHsKCXJldHVybiBweWFk
ZChweW9iaiwgbmJyKTsKICAgIH0KICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmlu
Z1tdIGFyZ3MpIHsKCUhlbGxvIGggPSBuZXcgSGVsbG8oMyk7CglTeXN0ZW0ub3V0LnByaW50
bG4oIjMgKyA0ID0gIiArIGguYWRkKDQpKTsKCWggPSBudWxsOwoJU3lzdGVtLmdjKCk7CiAg
ICB9CiAgICBwcml2YXRlIG5hdGl2ZSBsb25nIHB5ZGVsIChsb25nIG9iaik7CiAgICBwcm90
ZWN0ZWQgdm9pZCBmaW5hbGl6ZSAoKSB7CglweWRlbChweW9iaik7CiAgICB9Cn0=
--------------050506090406000407080907
Content-Type: text/plain;
name="Makefile"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="Makefile"
YWxsOiBIZWxsby5jbGFzcyBfaGVsbG8uc28KCWphdmEgSGVsbG8KCkhlbGxvLmNsYXNzOiBI
ZWxsby5qYXZhCglqYXZhYyBIZWxsby5qYXZhCgpfaGVsbG8uc286IF9oZWxsby5jCglnY2Mg
LW8gX2hlbGxvLnNvIC1zaGFyZWQgLUkvdXNyL2xpYi9qdm0vamF2YS02LXN1bi0xLjYuMC4x
MC9pbmNsdWRlIC1JL3Vzci9saWIvanZtL2phdmEtNi1zdW4tMS42LjAuMTAvaW5jbHVkZS9s
aW51eCAtSS91c3IvaW5jbHVkZS9weXRob24yLjYgLWxweXRob24yLjYgX2hlbGxvLmMKCl9o
ZWxsby5jOiBfaGVsbG8ucHl4CgljeXRob24gX2hlbGxvLnB5eAo=
--------------050506090406000407080907
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
_______________________________________________
Pyrex mailing list
[email protected]
http://lists.copyleft.no/mailman/listinfo/pyrex
--------------050506090406000407080907--