Crash in PyImport_Import()
Geert Van Muylem
Geert.Van.Muylem at skynet.be
Mon Dec 18 16:50:44 EST 2006
Hi,
The following script works fine when I call it from the python interpreter
but not when I call it from a c application (embedded python)
It crashes in the PyImport_Import()
import ldap
import distutils.sysconfig
def TestInit():
l = ldap.open("192.168.1.2")
l.simple_bind_s("","")
l.search_s("c=BE", ldap.SCOPE_SUBTREE, "objectclass=*")
s = distutils.sysconfig.get_config_var('LINKFORSHARED')
-> Python (2.5) and python-ldap (2.2.1) are recompiled for my environment
(hardened linux.)
Here is part of my makefile:
VERSION = Python-2.5
VERSION_LDAP = python-ldap-2.2.1
compile: .python .python-ldap
.python: makefile.python .glibc $(VERSION).Setup.local
$(EXTRACT_PACKAGE) && \
$(CP) ../$(VERSION).Setup.local Modules/Setup.local
&& \
./configure --prefix=/usr --enable-shared=no && \
make && \
make install
cp $(VERSION)/libpython2.5.a /usr/lib/libpython.a
(cd /usr/include; $(LN) -sf python2.5 python )
touch .python
.python-ldap: makefile.python .python .sasl .glibc .openldap
python-ldap.setup.cfg
(rm -rf $(VERSION_LDAP) || /bin/true) && \
tar xjf $(ARCHIVE_PACKAGES)/$(VERSION_LDAP).tar.bz2 && \
cd $(VERSION_LDAP) && \
$(CP) ../python-ldap.setup.cfg setup.cfg && \
python setup.py build && \
python setup.py install
rm -rf $(VERSION_LDAP)
touch .python-ldap
And my setup.cfg
# Example for setup.cfg
# You have to edit this file to reflect your system configuation
# $Id: setup.cfg.suse-linux,v 1.1 2003/08/20 10:04:34 stroeder Exp $
[_ldap]
# Section for compiling the C extension module
# for wrapping OpenLDAP 2 libs
library_dirs = /usr/lib/ /usr/lib/sasl2/
include_dirs = /usr/include/sasl/ /usr/include/sasl2/
extra_compile_args =
extra_objects =
# Example for full-featured SuSE build:
# Support for StartTLS/LDAPS, SASL bind and reentrant libldap_r.
# This needs recent OpenLDAP 2.0.26+ or 2.1.3+ built with
#./configure --with-cyrus-sasl --with-tls
libs = python ldap_r lber sasl2 ssl crypto resolv dl db m util pthread
[install]
# Installation options
compile = 1
optimize = 1
Everything is done in a chroot-ed environment...when building python-ldap,
it uses
the newly installed python includes....
The test application is linked against the static version libpython.a
int
CPyLDAP::Init()
{
m_iPython = 1;
printf ("Before Py_Initialize...\n");
Py_Initialize();
printf ("After Py_Initialize...\n");
PyObject *pName = PyString_FromString("PyTest");
if ( pName != NULL )
{
// Load the Python module
printf ("Before Import...\n");
m_pModule = PyImport_Import(pName);
printf ("After Import...\n");
if (m_pModule != NULL)
{
m_iPython = 0;
m_pDictionary = PyModule_GetDict(m_pModule);
}
}
return (m_iPython);
}
Hope someone can give me a hint?
thanks,
Geert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061218/e7e426c4/attachment.html>
More information about the Python-list
mailing list