Stefan Behnel, 06.12.2010 08:33:
> Vitja Makarov, 05.12.2010 20:12:
>> I have problem with closures and generators.
>>
>> Now I want to implement closure structure this way:
>> struct abstract_generator {
>> PY_OBJECT_HEAD
>> /* generator internal vars */
>> PyObject *(*body)(struct closure *, PyObject *, int);
>> int resume_label;
>> }
>
> I hope you're not trying to do it manually at that level, are you?
> Declaring the fields on the closure class should just work.
>
>
>> struct closure {
>> /* abstract_generator */
>> PY_OBJECT_HEAD
>> /* generator internal vars */
>> PyObject *(*body)(struct closure *, PyObject *, int);
>> int resume_label;
>> ,,,,
>> /* Closure stuff */
>> } ;
>>
>> and generator utility function will work like this:
>>
>> PyObject *abstract_generator_next(PyObject *self, PyObject *args)
>> {
>> struct abstract_generator *generator = (struct abstract_generator *)
>> self;
>> PyObject *retval;
>> // check running
>> retval = generator->body(self, None, 0);
>> // unlock running
>> return retval;
>> }
>>
>> But this way should be much better, don't know if that is possible btw.
>>
>> struct closure {
>> struct abstract_generator generator;
>> /* closure stuff here */
>> ...
>> } ;
>
> That's called inheritance in Cython. Just declare a subtype of the specific
> closure class.
Erm, sorry, the other way round. Yes, I think it's a good idea to let the
closure class inherit from the abstract generator.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev