Heap allocated type objects from C
I've been messing around with dynamically generating type objects from C. In particular, I made a module to generate structseq type objects. See sourceforge bug 624827 and patch 980098. I ran into a fair amount of difficulty in doing this. There doesn't appear to be a direct C API for doing this. One possible method is calling PyType_Type.tp_new() and then updating the returned type object as needed, but that seemed a little dirty. First, could someone tell me if I took the correct route for creating a type object on the heap (based on my patch). Second, shouldn't there be a more direct API for doing this? Perhaps a more generalized interface to type_new(), or maybe something completely new?? -Eric
Eric Huss wrote:
First, could someone tell me if I took the correct route for creating a type object on the heap (based on my patch).
Second, shouldn't there be a more direct API for doing this? Perhaps a more generalized interface to type_new(), or maybe something completely new??
I don't understand why the patch needs to be so complicated. Why can't you just make a global function that returns new type objects which are struct seqs? IOW, why do you need the factory type? Type objects are callable themselves, so they act as factories. Regards, Martin
On Sat, 26 Jun 2004, [ISO-8859-1] "Martin v. L�wis" wrote:
Eric Huss wrote:
First, could someone tell me if I took the correct route for creating a type object on the heap (based on my patch).
Second, shouldn't there be a more direct API for doing this? Perhaps a more generalized interface to type_new(), or maybe something completely new??
I don't understand why the patch needs to be so complicated. Why can't you just make a global function that returns new type objects which are struct seqs? IOW, why do you need the factory type? Type objects are callable themselves, so they act as factories.
Yes, that is a better route to take. Let me rework it to do that. The question is, would that live in __builtins__ or in the new module as Fred suggests? -Eric
participants (2)
-
"Martin v. Löwis" -
Eric Huss