C to Python interface - Trying to pass structs -


i'm working on interface between c , python , detected problem i'm not able solve: want pass struct python. sounds simple, somehow keep getting segfault. prepared object returned usable python. if create instance of in python works fine somehow can't use when returned function. here's corresponding code:

typedef struct{     pyobject_head     op *grid;     double beta, *umatrix, *energies, weight;     int nflavours, opcount;  } segmenttrace;   typedef struct{     pyobject_head     double ratio; } seginsert;   static pyobject *segtr_insert(segmenttrace *self, pyobject *args) {     seginsert *res = (seginsert*)malloc(sizeof(seginsert));     return py_buildvalue("o", (pyobject*)res); } 

with these definitions (and corresponding type definitions) i'm able following:

import cs  obj_1 = cs.segmenttrace(0., mat_a, mat_b) obj_2 = cs.seginsert()  print obj_2.ratio 

but not:

import cs  obj_1 = cs.segmenttrace(0., mat_a, mat_b) obj_3 = obj_1.insert()  print obj_3.ratio 

for reason segfault popping - know why?

thanks, lukas.

alright, figured out - @ least workaround trick. anyway, sake of completeness: possible pass self-created python-c-objects out of python c-routines , use data there. is, instead of

obj_1 = cs.segmenttrace(0., mat_a, mat_b) obj_3 = obj_1.insert() 

use:

obj_1 = cs.segmenttrace(0., mat_a, mat_b) obj_3 = cs.seginsert(obj) 

works fine ;) l.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -