<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div style="RIGHT: auto">Dear list,</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">I am developping since 2 years a library for photometry in Python. Everything is here: <A style="RIGHT: auto" href="http://www.aspylib.com">www.aspylib.com</A></div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">At the moment I have a very strange bug and no idea how to solve it, so I am asking for some help... or recommendations about a better place to ask for help (a different list ?)</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">My OS is Windows XP. The Python script is calling a few dll (written in C++) that are interfaced with ctypes. </div>
<div style="RIGHT: auto">Looking at the messages in the Python console the error occurs when calling one of these dll (this particular dll is called several hundreds of thousands of times without error just before, and this time there is an error..). The error message is something like:</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">File "C:\Documents and Settings\jerome caron\My Documents\Python2\aspylib\astro\transform.py", line 35, in translate_Bspline<BR> cdll.Bspline.Translate(dim,dim_x,dim_y,indata,dxy,spline_degree,outdata)<BR>WindowsError: exception: access violation reading 0x4158B870</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">The Python code that calls the dll is (I changed it many time without resolving the error)</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">if len(images.shape)==2:<BR> dim = 1<BR> dim_x, dim_y = images.shape<BR>else:<BR> dim, dim_x, dim_y = images.shape <BR>indata = np.ascontiguousarray(np.array(images, dtype = np.float32))<BR>dxy = np.ascontiguousarray(np.array(shift, dtype = np.float32))<BR>outdata = np.ascontiguousarray(np.empty(images.shape, dtype = np.float32))<BR>cdll.Bspline.Translate.argtypes = [c_long, c_long, c_long, ndpointer(dtype=np.float32), ndpointer(dtype=np.float32), c_long, ndpointer(dtype=np.float32)]<BR>cdll.Bspline.Translate(dim,dim_x,dim_y,indata,dxy,spline_degree,outdata)<BR></div>
<div style="RIGHT: auto">The dll prototype in C is</div>
<div style="RIGHT: auto">int Translate(int dim, int dim_x, int dim_y, float* a, float* shifts, int spline_degree, float* b);</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">So everything looks ok and I would suspect an error in the C++ code. But here comes the nasty thing.</div>
<div style="RIGHT: auto">The code in the dll is very basic and clean. Actually it does not throw any exception as I checked by inserting a try..catch statement</div>
<div style="RIGHT: auto">try{ all the dll code here} catch(...){printf("there was an error ni the dll!");}</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">Investigating further, the error occurs when executing a free() instruction. I don't see how this could create an error ! The piece of C code looks like</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> Line = (double *)malloc((size_t)(Width * (long)sizeof(double)));<BR> if (Line == (double *)NULL) {<BR> printf("Row allocation failed\n");<BR> return(1);<BR> }<BR> for (y = 0L; y < Height; y++) {<BR> GetRow(Image, y, Line, Width);<BR> ConvertToInterpolationCoefficients(Line, Width, Pole, NbPoles, DBL_EPSILON);<BR> PutRow(Image, y, Line, Width);<BR> }<BR> free(Line);</div>
<div style="RIGHT: auto">And the error occurs at the statement free(Line).</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">I am starting to suspect something nasty happening with ctypes. Or maybe I am missing something very basic ? Any suggestion ? I am sure there are experienced programmers on this list, who could advice me.</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">Many thanks for your help and patience reading me<VAR id=yui-ie-cursor></VAR></div>
<div style="RIGHT: auto">Kind regards</div>
<div style="RIGHT: auto">Jerome Caron</div>
<div style="RIGHT: auto"> </div></div></body></html>