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 * * Comment printf in jfunc to resolve * * null pointer acces error * ********************************************* #include #include __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; }