ctypes help for "array of character pointers" as an output parameter
I'm wrapping a C function exists in a shared library. Its prototype looks like as follows int getFileNames(int aSize, char **names); The documentation says that the asSize is the number of entries to be returned and names is output array of character pointers of at least aSize elements. So, I defined a function prototype in python, follow ctypes tutorial, and try to run it. The following code section shows what I did. _getNames = TheLib.getNames _getNames.restype = c_int _getNames.argtypes = [ c_int, POINTER(c_char_p) ] def getNames(): aSize = 1024 names = (c_char_p * arraySize)() rc = _getNames(aSize, names) After that, I make a call to getNames() in my python program and, unfortunately, either TypeError or Segmentation fault. Sigh... I wonder that whether the _getNames prototype definition in my code section is correct?? If it isn't, I guess so, how do I do a right one? Another, whether the usage in getNames() is correct?? Appreciate for any reply or recommendation. -- http://mail.python.org/mailman/listinfo/python-list
decorator and signal handler
Hi all, I wrote the following code since I want to try using a decorator to install signal handler: ## The test.py script # import os import time import signal def sigHandler(sid): def handler(f): signal.signal(sid, f) return f return handler class Test(object): @sigHandler(signal.SIGTERM) def _sigHandler(self, signalId, currentFrame): print "Received:", signalId if __name__ == "__main__": print "pid:", os.getpid() t = Test() time.sleep(300) # From terminal, say A $ python test.py pid: 1234 # From terminal, say B ### $ kill -TERM 1234 After issuing the kill command from terminal B, the process of test.py from terminal A is terminated. Python print out some exception message as following: Traceback (most recent call last): File "a.py", line 22, in time.sleep(300) TypeError: _sigHandler() takes exactly 3 arguments (2 given) At a guess, I think the decorator I defined did not pass the 'self' as the first argument to _sigHandler() method, did it? And I have no idea of how to write a correct one. Any suggestion? -- http://mail.python.org/mailman/listinfo/python-list
Py_GetPath() C API in python 3
Hi all, I want to build a new, requires total control, python interpreter. So I implement my own version of Py_GetPath(), Py_GetPrefix(), Py_GetExecPrefix() and Py_GetProgramFullPath(). When compiling, I always get error messages, for each API function, look like followings: /opt/python-3.0/lib/python3.0/config/libpython3.0.a(getpath.o)(.text +0x211c): In function `Py_GetPath': ./Modules/getpath.c:739: multiple definition of `Py_GetPath' myApp.o(.text+0x0):/home/alex/workspace/develop/src/myApp.c:11: first defined here /usr/bin/ld: Warning: size of symbol `Py_GetPath' changed from 126 in system.o to 32 in /opt/python-3.0/lib/python3.0/config/libpython3.0.a (getpath.o) collect2: ld returned 1 exit status If I compile my application with python 2.x, everything's just okay and my application as well. Any ideas on how to get this working for python 3? -- http://mail.python.org/mailman/listinfo/python-list
Re: Py_GetPath() C API in python 3
On 12月11日, 下午5時53分, stalex wrote: > Hi all, > > I want to build a new, requires total control, python interpreter. So > I implement my own version of Py_GetPath(), Py_GetPrefix(), > Py_GetExecPrefix() and Py_GetProgramFullPath(). When compiling, I > always get error messages, for each API function, look like > followings: > > /opt/python-3.0/lib/python3.0/config/libpython3.0.a(getpath.o)(.text > +0x211c): In function `Py_GetPath': > ./Modules/getpath.c:739: multiple definition of `Py_GetPath' > myApp.o(.text+0x0):/home/alex/workspace/develop/src/myApp.c:11: first > defined here > /usr/bin/ld: Warning: size of symbol `Py_GetPath' changed from 126 in > system.o to 32 in /opt/python-3.0/lib/python3.0/config/libpython3.0.a > (getpath.o) > collect2: ld returned 1 exit status > > If I compile my application with python 2.x, everything's just okay > and my application as well. Any ideas on how to get this working for > python 3? Nobody could answer this question? -- http://mail.python.org/mailman/listinfo/python-list
Re: Py_GetPath() C API in python 3
On 12月13日, 上午9�r55分, "Gabriel Genellina" wrote: > En Fri, 12 Dec 2008 04:50:06 -0200, stalex escribió: > > >> I want to build a new, requires total control, python interpreter. So > >> I implement my own version of Py_GetPath(), Py_GetPrefix(), > >> Py_GetExecPrefix() and Py_GetProgramFullPath(). When compiling, I > >> always get error messages, for each API function, look like > >> followings: > > >> /opt/python-3.0/lib/python3.0/config/libpython3.0.a(getpath.o)(.text > >> +0x211c): In function `Py_GetPath': > >> ./Modules/getpath.c:739: multiple definition of `Py_GetPath' > >> myApp.o(.text+0x0):/home/alex/workspace/develop/src/myApp.c:11: first > >> defined here > >> /usr/bin/ld: Warning: size of symbol `Py_GetPath' changed from 126 in > >> system.o to 32 in /opt/python-3.0/lib/python3.0/config/libpython3.0.a > >> (getpath.o) > >> collect2: ld returned 1 exit status > > Looks like you added your own implementation of those functions > (/home/alex/...myApp.c) but forgot to remove the original one > (Modules/getpath.c) > > -- > Gabriel Genellina No, I didn't remvoe the original one. But, why do I need to do that? I just want to extend my application, based on the original python installed by administrator, not to build/install another one python interpreter. And by studing python api documentations, Py_GetPath() is a public interface python itself provides. So I could achieve my goal via implementating my own Py_GetPath() version as well as other Py_GetXXX(). By the way, my application is stable and runs well since 2 years ago. I do this just because I want to release, in the near future, a new version. And I want to migrate its kernel from python2.5 to python3. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
