[New-bugs-announce] [issue8275] callback function on win64 results in bad behavior. mem leak?
Jasmit
report at bugs.python.org
Wed Mar 31 20:53:45 CEST 2010
New submission from Jasmit <jsingh at roguewave.com>:
I am testing a wrapper on Windows 64 and it seems to result in an null pointer access error ONLY when I insert a print statement in the C code. I have tested the wrapper with Python 2.6 and Python 2.7a4. In addition, I have compiled Python 2.6.5 source code and ONLY the release version results in an error. I think the issue is with memcpy(obj->b_ptr, *pArgs, dict->size) (callbacks.c). pArgs seem to be corrupted. However, I am only looking at the code for the first time and I might be off base.
The following is Python and C code to reproduce the bug. To resolve, please comment printf statement in jfunc (C function).
Python Code:
from ctypes import *
def fcn(m,n,x,f):
print "IN Python function fcn ................"
print f[0]
m=3
n=1
pydlltest=cdll.pydlltest
pydlltest.jfunc.restype = POINTER(c_double)
evalstring = 'pydlltest.jfunc('
TMP_FCN=CFUNCTYPE(None,c_int,c_int,POINTER(c_double),POINTER(c_double))
tmp_fcn=TMP_FCN(fcn)
state=[TMP_FCN,tmp_fcn]
evalstring += 'tmp_fcn'
evalstring +=','
evalstring +='c_int(m)'
evalstring +=','
evalstring +='c_int(n)'
evalstring += ')'
print "evalstring=",evalstring
result = eval(evalstring)
C code:
#include <stdio.h>
__declspec(dllexport) double *jfunc(void (*fcn) (int,int,double [],double[]),int m,int n);
double *jfunc(void (*fcn) (int,int,double [],double []),int m,int n)
{
double *fvec=NULL;
double *xguess = NULL;
int i = 0;
int j = 0;
/* comment the line below to fix the resulting null pointer access error */
printf("In j func .................\n");
fvec = (double *) malloc (m * sizeof (double));
xguess = (double *) malloc (n * sizeof (double));
for (i = 0; i < n; i++){
xguess[i] = 0.123;
}
(*fcn) (m, n, xguess, fvec);
return fvec;
}
----------
assignee: theller
components: ctypes
files: ctype_win64.txt
messages: 102028
nosy: ocrush, theller
severity: normal
status: open
title: callback function on win64 results in bad behavior. mem leak?
type: behavior
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file16708/ctype_win64.txt
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8275>
_______________________________________
More information about the New-bugs-announce
mailing list