Date: Tue, 13 May 2003 09:34:17 -0700 From: Seva Tonkonoh <seva3@pacbell.net> To: freebsd-newbies@freebsd.org Subject: python gives memory fault with my .so library Message-ID: <OMEMLKGOIJPDJBNMEIJJMEANCBAA.seva3@pacbell.net>
next in thread | raw e-mail | index | archive | help
When I try to run my extension shared library for Python, it gives me "Memory fault(coredump)". I am running FreeBSD 4.7 on VMWare 4 on Dell 4100 workstation. I tried 2 versions of Python: 2.2.1 and 2.1.3. They both give the same error message, which makes me think I didn't create .so file correctly. Here is how I compiled my .so file: hello.so: hello.c gcc hello.c -g -I/usr/local/include/python2.1 -fpic -shared -o hello.so I tried hello.c from Lutz's O'Rei;;y book "Programming Python" because I had the same problem before with a more complex DLL, so I decided I have to try something simple first to narrow the problem. hello.c code is at the bottom of this email, just in case. What I tried to do with Python is: -start python interpreter in the directory where .so file resides. -do ">>> import hello". That runs fine. -do ">>> hello.message('bla')". That gives "Memory fault(coredump)". Please, cc me as I am not on the list. Thanks in advance, seva /***************************************************** hello.c ****************************************************/ #include <Python.h> #include <string.h> /* module functions */ static PyObject * /* returns object */ message(PyObject *self, PyObject *args) /* self unused in modules */ { /* args from python call */ char *fromPython, result[64]; if (! PyArg_Parse(args, "(s)", &fromPython)) /* convert Python -> C */ return NULL; /* null=raise exception */ else { strcpy(result, "Hello, "); /* build up C string */ strcat(result, fromPython); /* add passed Python string */ return Py_BuildValue("s", result); /* convert C -> Python */ } } /* registration table */ static struct PyMethodDef hello_methods[] = { {"message", message, 1}, /* method name, C func ptr, always-tuple */ {NULL, NULL} /* end of table marker */ }; , /* module initializer */ void inithello() /* called on first import */ { /* name matters if loaded dynamically */ (void) Py_InitModule("hello", hello_methods); /* mod name, table ptr */ }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?OMEMLKGOIJPDJBNMEIJJMEANCBAA.seva3>