[Pyrex] Globals and wrapping Eiffel
Simon Frost
sdfrost at ucsd.edu
Thu Nov 13 18:32:30 CET 2003
Dear Pyrex list,
I'm trying to wrap some C code emitted from compiling Eiffel code using the
SmartEiffel compiler. All functions called have to have a pointer-to-void
eiffel_root_object, which is generated upon an initialization function
initialize_eiffel_runtime(argc,argv). This is not a problem when calling
functions, but I would like a more OO style. I have a factory function that
returns pointers to a struct, on which I can call functions. This pyx file
works:
#
# Pyrex wrapper for the episim_factory module
#
cdef extern from "eiffel_episim_factory.h":
ctypedef int T2
ctypedef double T5
void* eiffel_root_object
void episim_factory_make(void* C)
void* episim_new_sim(void* C)
void episim_init_sim(void* C,void* a1,T5 a2,T5 a3,T2 a4,T5 a5,T5 a6)
void episim_activate_sim(void* C, void* a1, T2 a2, T2 a3)
void episim_run_sim(void* C, void* a1)
void initialize_eiffel_runtime(int argc,char*argv[])
cdef class EpiSim:
cdef void* sim
def __new__(self,start_time,stop_time,seed,inf_prob,contact_rate):
initialize_eiffel_runtime(<int>NULL,<char**>NULL)
episim_factory_make(eiffel_root_object)
self.sim=episim_new_sim(eiffel_root_object)
episim_init_sim(eiffel_root_object,self.sim,start_time,stop_time,seed,inf_prob,contact_rate)
def activate(self,num_pop,num_inf):
episim_activate_sim(eiffel_root_object,self.sim,num_pop,num_inf)
def run_sim(self):
episim_run_sim(eiffel_root_object,self.sim)
However, all objects must have access to the eiffel_root_object in order to
run, and I don't want to have a separate Eiffel runtime for each class.
When I try the following, my module compiles, but crashes at run_sim: any
ideas on how to fix this?
Thanks
Simon
####This generates a sig11 when run_sim is called from Python
cdef class EpiSim:
cdef void* sim
cdef void* ero
def __new__(self,start_time,stop_time,seed,inf_prob,contact_rate):
global eiffel_root_object
self.ero=eiffel_root_object
self.sim=episim_new_sim(self.ero)
episim_init_sim(self.ero,self.sim,start_time,stop_time,seed,inf_prob,contact_rate)
def activate(self,num_pop,num_inf):
episim_activate_sim(self.ero,self.sim,num_pop,num_inf)
def run_sim(self):
episim_run_sim(self.ero,self.sim)
initialize_eiffel_runtime(<int>NULL,<char**>NULL)
episim_factory_make(eiffel_root_object)
More information about the Pyrex
mailing list