Python code crashes when running, but not when debugging (Ctypes) -
i running weird case little class involving ctypes writing. objective of class load matrix in proprietary format python structure had create (these matrices can have several cores/layers , each core/layer can have several indices refer few elements of matrix, forming submatrices).
the code test class this:
import numpy np reads_mtx import mtx import time mymatrix=mtx() mymatrix.load('d:\\mymatrix.mtx', true)
and class created this:
import os import numpy np ctypes import * import ctypes import time def main(): pass #a mydll mtx can have several cores #we need class define each core #and class hold whole file class mtx_core: def __init__(self): self.name=none #matrix core name self.rows=-1 #number of rows in matrix self.columns=-1 #number of columns in matrix self.type=-1 #data type of matrix self.indexcount=-1 #tuple number of indices each dimension self.rindex={} #dictionary indices rows self.cindex={} #dictionary indices columns self.basedata=none self.matrix=none def add_core(self, mydll,mat,core): namec=ctypes.create_string_buffer(50) mydll.matrix_getlabel(mat,0,namec) namec=repr(namec.value) namec=namec[1:len(namec)-1] #add information objects' methods self.name=repr(namec) self.rows= mydll.matrix_getbasenrows(mat) self.columns=mydll.matrix_getbasencols(mat) self.type=mydll.matrix_getdatatype(mat) self.indexcount=(mydll.matrix_getnindices(mat,0 ),mydll.matrix_getnindices(mat,0 )) #define data type numpy have according data type of matrix in question dt=np.float64 v=(self.columns*c_float)() if self.type==1: dt=np.int32 v=(self.columns*c_long)() if self.type==2: dt=np.int64 v=(self.columns*c_longlong)() #instantiate matrix time.sleep(5) self.basedata=np.zeros((self.rows,self.columns),dtype=dt) #read matrix , puts in numpy array in range(self.rows): mydll.matrix_getbasevector(mat,i,0,self.type,v) self.basedata[i,:]=v[:] #reads indices rows , put them in dictionary in range(self.indexcount[0]): mydll.matrix_setindex(mat, 0, i) v=(mydll.matrix_getnrows(mat)*c_long)() mydll.matrix_getids(mat,0, v) t=np.zeros(mydll.matrix_getnrows(mat),np.int64) t[:]=v[:] self.rindex[i]=t.copy() #do same columns in range(self.indexcount[1]): mydll.matrix_setindex(mat, 1, i) v=(mydll.matrix_getncols(mat)*c_long)() mydll.matrix_getids(mat,1, v) t=np.zeros(mydll.matrix_getncols(mat),np.int64) t[:]=v[:] self.cindex[i]=t.copy() class mtx: def __init__(self): self.data=none self.cores=-1 self.matrix={} mydll=none def load(self, filename, verbose=false): #we load dll , initiate mydll=cdll.loadlibrary('c:\\program files\\mysoftware\\matrixdll.dll') mydll.initmatdll() mat=mydll.matrix_loadfromfile(filename, true) if mat<>0: self.cores=mydll.matrix_getncores(mat) if verbose==true: print "matrix has ", self.cores, " cores" in range(self.cores): mydll.matrix_setcore(mat,i) namec=ctypes.create_string_buffer(50) mydll.matrix_getlabel(mat,i,namec) namec=repr(namec.value) namec=namec[1:len(namec)-1] #if verbose, list matrices being loaded if verbose==true: print " loading core: ", namec self.datafile=filename self.matrix[namec]=mtx_core() self.matrix[namec].add_core(mydll,mat,i) else: raise nameerror('not possible open file. trancad returned '+ str(tc_value)) mydll.matrix_closefile(filename) mydll.matrix_done(mat) if __name__ == '__main__': main()
when run test code in form (double clicking, python's idle or pyscripter) crashes familiar error "windowserror: exception: access violation writing 0x0000000000000246", when debug code using pyscripter stoping in inner loop, runs perfectly.
i'd appreciate insights.
edit
the dumpbin output dll:
file type: dll
section contains following exports calipermtx.dll
00000000 characteristics 52fb9f15 time date stamp wed feb 12 08:19:33 2014 0.00 version 1 ordinal base 81 number of functions 81 number of names ordinal hint rva name 1 0 0001e520 initmatdll 2 1 0001b140 matrix_addindex 3 2 0001aee0 matrix_clear 4 3 0001ae30 matrix_closefile 5 4 00007600 matrix_copy 6 5 000192a0 matrix_createcache 7 6 00019160 matrix_createcacheex 8 7 0001eb10 matrix_createsimple 9 8 0001ed20 matrix_createsimplelike 10 9 00016d40 matrix_destroycache 11 00016da0 matrix_disablecache 12 b 0001a880 matrix_done 13 c 0001b790 matrix_dropindex 14 d 00016d70 matrix_enablecache 15 e 00015b10 matrix_getbasencols 16 f 00015b00 matrix_getbasenrows 17 10 00015ff0 matrix_getbasevector 18 11 00015ce0 matrix_getcore 19 12 000164c0 matrix_getcurrentindexpos 20 13 00015b20 matrix_getdatatype 21 14 00015ee0 matrix_getelement 22 15 00015a30 matrix_getfilename 23 16 00007040 matrix_getids 24 17 00015b80 matrix_getinfo 25 18 00015a50 matrix_getlabel 26 19 00015ae0 matrix_getncols 27 1a 00015ab0 matrix_getncores 28 1b 00016ec0 matrix_getnindices 29 1c 00015ac0 matrix_getnrows 30 1d 00018af0 matrix_getvector 31 1e 00015b40 matrix_iscolmajor 32 1f 00015b60 matrix_isfilebased 33 20 000171a0 matrix_isreadonly 34 21 00015b30 matrix_issparse 35 22 0001ae10 matrix_loadfromfile 36 23 0001bae0 matrix_new 37 24 00017150 matrix_openfile 38 25 000192d0 matrix_refreshcache 39 26 00016340 matrix_setbasevector 40 27 00015c20 matrix_setcore 41 28 00016200 matrix_setelement 42 29 00016700 matrix_setindex 43 2a 0001afa0 matrix_setlabel 44 2b 00018e50 matrix_setvector 45 2c 00005da0 mat_access_create 46 2d 00005e40 mat_access_createfromcurrency 47 2e 00004b10 mat_access_done 48 2f 00005630 mat_access_fillrow 49 30 000056d0 mat_access_fillrowdouble 50 31 00005a90 mat_access_getcurrency 51 32 00004c30 mat_access_getdatatype 52 33 000058e0 mat_access_getdoublevalue 53 34 00004c40 mat_access_getids 54 35 00005aa0 mat_access_getmatrix 55 36 00004c20 mat_access_getncols 56 37 00004c10 mat_access_getnrows 57 38 000055a0 mat_access_getrowbuffer 58 39 00005570 mat_access_getrowid 59 3a 00005610 mat_access_gettoreadflag 60 3b 00005870 mat_access_getvalue 61 3c 00005ab0 mat_access_isvalidcurrency 62 3d 000055e0 mat_access_setdirty 63 3e 000059f0 mat_access_setdoublevalue 64 3f 00005620 mat_access_settoreadflag 65 40 00005960 mat_access_setvalue 66 41 00005460 mat_access_useids 67 42 00005010 mat_access_useidsex 68 43 00005490 mat_access_useownids 69 44 00004d10 mat_access_validateids 70 45 0001e500 mat_pafree 71 46 0001e4e0 mat_palloc 72 47 0001e4f0 mat_pfree 73 48 0001e510 mat_prealloc 74 49 00006290 ma_mgr_addma 75 4a 00006350 ma_mgr_addmas 76 4b 00005f90 ma_mgr_create 77 4c 00006050 ma_mgr_done 78 4d 000060d0 ma_mgr_registerthreads 79 4e 00006170 ma_mgr_setrow 80 4f 00006120 ma_mgr_unregisterthread 81 50 0001e490 unloadmatdll
summary
6000 .data 5000 .pdata c000 .rdata 1000 .reloc 1000 .rsrc 54000 .text
Comments
Post a Comment