From anouar.lachheb at gmail.com Mon Oct 22 18:51:52 2007 From: anouar.lachheb at gmail.com (Anouar Lachheb) Date: Mon, 22 Oct 2007 18:51:52 +0200 Subject: [capi-sig] Unit tests of C functions with Python Message-ID: Hi, We have developed a C project and we want to write unit test for it. I used a sample VC++ project with Python using swig (to wrap a ".i" file). My C functions has a return value and formal parameters could be pointers or scalars, I need to pass some of them by reference to get the value back. Here's an example of a function of mine (functional test OK): S32 CALENDAR_RequestHandlerFunction (U32 U32RequestID, void* pArg1, void* pArg2, void* pArg3); pArg1 or pArg2 or pArg3 could point to anything and could be IN or OUT. I imported "ctypes" module in my "test.py" file, but Python complain from "pArg1" saying: "TypeError: in method CALENDAR_RequestHandlerFunction', argument 2 of type 'void *' Notice that I used the same proto in my ".i" file. Any help to test C functions using Python and avoid C types problems? Thank you. Best regards, AnL. From george at reilly.org Mon Oct 29 08:18:46 2007 From: george at reilly.org (George V. Reilly) Date: Sun, 28 Oct 2007 23:18:46 -0800 Subject: [capi-sig] Win64 Vim: sys.path not set correctly Message-ID: As you may know, Vim has offered an embedded Python for several years. I'm updating the Win64 port of Vim and decided to make the Python interface work too. I think I've fixed all the tedious Py_ssize_t issues, and the simple sanity test of :py print "hi" works. However, more complex examples fall over with ImportErrors. As far as I can tell, it's related to sys.path, which shows as: ['', 'd:\\Python25\\python25.zip', '.\\DLLs', '.\\lib', '.\\lib\\plat-win', '.\\lib\\lib-tk', 'D:\\vimsrc\\vim7\\src'] When I run python interactively, sys.path looks like: ['', 'd:\\Python25\\python25.zip', 'd:\\Python25\\DLLs', 'd:\\Python25\\lib', 'd:\\Python25\\lib\\plat-win', 'd:\\Python25\\lib\\lib-tk', 'd:\\Python25', 'd:\\Python25\\lib\\site-packages'] If I modify sys.path to use the fully qualified pathnames, things start working. If I build a 32-bit version of Vim, things work out of the box. I'm loading python25.dll; i.e., Vim was compiled with -DDYNAMIC_PYTHON. The python25.dll was installed by python-2.5.1.amd64.msi. My patches (and the complete if_python.c) can be found at http://www.georgevreilly.com/vim/vim-win64-20071028.zip Any ideas? Thanks. -- /George V. Reilly http://www.georgevreilly.com/blog From mhammond at skippinet.com.au Mon Oct 29 22:15:02 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 30 Oct 2007 08:15:02 +1100 Subject: [capi-sig] Win64 Vim: sys.path not set correctly In-Reply-To: References: Message-ID: <071a01c81a70$ca7e18e0$5f7a4aa0$@com.au> > I think I've fixed all the tedious Py_ssize_t issues, and the simple > sanity test of > :py print "hi" > works. However, more complex examples fall over with ImportErrors. As > far as I can tell, it's related to sys.path, which shows as: > ['', 'd:\\Python25\\python25.zip', '.\\DLLs', '.\\lib', > '.\\lib\\plat-win', '.\\lib\\lib-tk', 'D:\\vimsrc\\vim7\\src'] > > When I run python interactively, sys.path looks like: > ['', 'd:\\Python25\\python25.zip', 'd:\\Python25\\DLLs', > 'd:\\Python25\\lib', 'd:\\Python25\\lib\\plat-win', > 'd:\\Python25\\lib\\lib-tk', 'd:\\Python25', > 'd:\\Python25\\lib\\site-packages'] > > If I modify sys.path to use the fully qualified pathnames, things > start working. If I build a 32-bit version of Vim, things work out of > the box. > > I'm loading python25.dll; i.e., Vim was compiled with > -DDYNAMIC_PYTHON. The python25.dll was installed by > python-2.5.1.amd64.msi. This will be related to the registry entries being written into the 32bit part of the registry rather than the 64bit version. As a result, whenever Python is embedded in another application and needs to use the registry to locate its installation path, it fails, and uses the fallback relative values of ".\DLLs", ".\lib" etc. On the other hand, when Python is started normally, it can locate its library automatically, so the correct entries are used. If you search the python-dev archives, you will see a discussion on this issue, and also a new copy of the installer put together by Martin V Loewis to test the fix for this issue. It is expected that the fix will also appear in Python 2.5.2. Hope this helps, Mark From george at reilly.org Tue Oct 30 08:04:01 2007 From: george at reilly.org (George V. Reilly) Date: Mon, 29 Oct 2007 23:04:01 -0800 Subject: [capi-sig] Win64 Vim: sys.path not set correctly In-Reply-To: <071a01c81a70$ca7e18e0$5f7a4aa0$@com.au> References: <071a01c81a70$ca7e18e0$5f7a4aa0$@com.au> Message-ID: On 10/29/07, Mark Hammond wrote: > This will be related to the registry entries being written into the 32bit > part of the registry rather than the 64bit version. As a result, whenever > Python is embedded in another application and needs to use the registry to > locate its installation path, it fails, and uses the fallback relative > values of ".\DLLs", ".\lib" etc. On the other hand, when Python is started > normally, it can locate its library automatically, so the correct entries > are used. > > If you search the python-dev archives, you will see a discussion on this > issue, and also a new copy of the installer put together by Martin V Loewis > to test the fix for this issue. It is expected that the fix will also > appear in Python 2.5.2. > > Hope this helps, Thanks, Mark. The mail thread at http://mail.python.org/pipermail/python-dev/2007-July/073900.html describes the problem and points to a fixed installer. In short, the official Python 2.5.1 amd64 installer sets the 'reflected' registry keys at HKLM\Software\Wow6432node\Python, instead of HKLM\Software\Python. I installed Martin v. L?wis's private build and that fixed my problems. -- /George V. Reilly http://www.georgevreilly.com/blog