[AstroPy] Re : Re : strange error with ctypes

Jerome Caron jerome_caron_astro@ymail....
Mon Feb 20 08:39:53 CST 2012

Dear list,
Finally I resolved the error.
I am not sure what happened. I found that some numpy arrays sent to the dll had very large size (due to indexing like x[0:-5]), which was not my intention so I corrected it. The dll is now called a large amount of times (>1e6), but only with small arrays (20*20), and it works fine.
I don't like it very much, to correct something that I don't understand so I still have an eye on this problem.
In any case, the error was detected and managed cleanly by Python (try... except...). Another solution I had in mind was to re-program the dll without dynamic allocation, by oversizing the only dynamic array (variable called "Line") used in the dll.
At the moment my library works only with WinXP 32 bits. In the next months I will make it compatible with Win 7 32 bits, and Ubuntu. Then I will present it on the list (I believe there is a majority of Linux users..)
Thanks for your help

De : Jerome Caron <jerome_caron_astro@ymail.com>
À : "astropy@scipy.org" <astropy@scipy.org> 
Envoyé le : Jeudi 16 février 2012 20h47
Objet : [AstroPy] Re : strange error with ctypes

Dear James,
>I believe it could cause an error if either the pointer Line has been
>changed, so you are trying to free the wrong memory, or something has
>inadvertently overwritten the memory you're trying to free 
Thanks for the suggestion ! You're right, this could be a possibility. I checked carefully the code, but the only instructions with Line are assignments and arithmetic operations with Line[i], i varying from 0 to Width-1. There is not a single operation with the pointer itself. So I don't see what could be wrong...
This piece of code in my dll is a third party library (http://bigwww.epfl.ch/thevenaz/interpolation/). The code is nicely written, and it's clear than the author knows what he's doing.
I am a bit puzzled, I am sure if there was such error there would be an exception thrown by the dll. But there's no exception: Python reports an error in the dll, and the dll does not see any error. It looks like Python and C++ do not understand each other. Might this be something wrong with my Python code, a bad usage of ctypes ??


AstroPy mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/astropy/attachments/20120220/836128b1/attachment.html 

More information about the AstroPy mailing list