> I wouldn't mind letting Cython special case subtypes of str (or unicode in
> Py3) *somehow*, as long as this "somewhow" proves to be a viable solution that
> only applies to exactly those types *and* can be done realiably for subtypes
> of subtypes. I'm just not aware of such a solution.

As people have pointed out: add new fields *after* the variable-sized
members. To access it, you need to compute the length of the base
object, and then cast the pointer to an extension struct.

That extends to further subtypes, too.

Access is slightly slower, i.e. it's not a compile-time constant, but

  base_address + base_address[ob_len]*elem_size - more_fields_size

This still compiles efficiently, e.g. on x86, gcc compiles a struct
field access to

  movl    20(%eax), %eax

and an access with a var-sized offset into

  movl    8(%eax), %edx; fetch length into edx
  movl    -20(%eax,%edx,2), %eax; access 20-byte sized struct, assuming
elements of size 2

> This does sound interesting, but I will have to look into the implications. As
> I said, it has to be a viable solution without (noticeable) impact on other
> types. I'm not sure how this would interact with subtypes of subtypes, and
> what the memory layout would be in that case.

See above.

Regards,
Martin
_______________________________________________
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