La parte di Person è quasi uguale a quella che cè sulla Documentation di cython la queue.pyx
Allora avendo:
un file.h ,un Private_file.h e un Person.c ho creato il
Person.pyx
cdef extern from "Person.h":
cdef struct Person_TAG:
pass
ctypedef Person_TAG* Person_ptr
Person_ptr Person_create(char* name)
void Person_destroy(Person_ptr self)
char* Person_get_name(Person_ptr self)
int Person_get_age(Person_ptr self)
void Person_birthday(Person_ptr self)
cdef class Person:
cdef Person_ptr P_create
def __cinit__(self, char* name):
self.P_create = Person_create(name)
if self.P_create is NULL:
raise MemoryError
print "Person %s created" % name
return
def __dealloc__(self):
if self.P_create is not NULL:
print "Destroying Person %s" % self.name
Person_destroy(self.P_create)
pass
return
property name:
def __get__(self):
return Person_get_name(self.P_create)
property age:
def __get__(self):
return Person_get_age(self.P_create)
def birthday(self):
Person_birthday(self.P_create)
poi devo creare un Student.pyx che eredita da Person.pyx
e anche per Student ho il file.h,Private_file.h e Student.c
quello che ho fatto io su Student.pyx è:
Student.pyx
from Personpy cimport Person
from Personpy cimport Person_ptr
cdef class Student (Person):
cdef extern from "Student.h":
ctypedef struct Student_TAG:
pass
ctypedef Student_TAG* Student_ptr
Student_ptr Student_create(char* name, int age)
void Student_destroy(Student_ptr self)
double Student_get_average(Student_ptr self)
void Student_sit_exam(Student_ptr self, double exam_result)
def __cinit__(self, char* name,int age): #----->qua cè il problema
self.obj = <Person_ptr> Student_create(name, age)
if self.obj is NULL:
raise MemoryError
print "Student %s created %d" % name % age
return
def __dealloc__(self):
if self.obj is not NULL:
print "Destroying Student %s" % self.name
Student_destroy( <Student_ptr> self.obj)
pass
return
property average:
def __get__(self):
return Student_get_average( <Student_ptr> self.obj)
def Student_sit_exam(self,double exam_result):
Student_sit_exam( <Student_ptr> self.obj, exam_result)
e nel Student.pyx succede quello che ho descritto sopra,
il cinit della Person si chiama automaticamente e di conseguenza quando io faccio:
>import Studentpy #che è la libreria dinamica Studentpy.so
>s = Studentpy.Student()
mi dice che cinit prende un solo parametro,ovvio perche è il cinit di Person
cosa che io non voglio che succeda,perche voglio creare un Student che prende 2 prametri.
ps: grazie del benvenuto
, già lette le regole