Stefan Behnel <stefan_ml <at> behnel.de> writes:
> 
>     cdef class MyListSubType(PyListObject):
>         cdef int some_additional_int_field
>         cdef my_struct* some_struct
> 
>         def __init__(self):
>             self.some_struct = get_the_struct_pointer(...)
>             self.some_additional_int_field = 1

In your example, you could wrap the additional fields (additional_int_field and
some_struct) in a dedicated struct, and define a macro which gives a pointer to
this struct when given the address of the object. Once you have the pointer to
the struct, accessing additional fields is as simple as in the non-PyVarObject
case.

Something like (pseudocode):

#define MyStrSubType_FIELDS_ADDR(op) \
  ((struct MyStrSubType_subfields*) &((void*)op + PyString_Type->tp_basicsize \
      + op->size * PyString_Type->tp_itemsize))

It's not as trivially cheap as a straight field access, but much less expensive
than a dictionary lookup.

(perhaps this needs to be a bit more complicated if you want a specific
alignment for your fields)



_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to