Hi Wim,

On Wed, Jun 6, 2012 at 9:10 AM,  <wlavrij...@lbl.gov> wrote:
> If I understand correctly what you describe above, then perhaps giving
> the "PyPyObject by pointer" as payload to the PyObject could help, too.

Yes: so far, most PyObjects are small structures containing just the
refcount and the cpyext-ified type.  Note that for your use case you
don't need the latter, which would simplify things a lot.  If the goal
is "only" to pass around PyObjects as black boxes, as fast as
reasonably possible, then the easiest route would be to not use cpyext
at all, but instead try to come up with your own mapping logic.  This
looks quite easier for experimentation purposes.  And if you end up
with a good and fast solution we can always try later to reuse it in
cpyext.

Trying to think about the API to use: there is
pypy.rlib.rgc.malloc_nonmovable(TP), where TP is a GcStruct.  It
allocates a normal GC object but tries to make sure that it will never
move.  Raw pointers to that can be passed around to C++, but won't
keep the GcStruct alive by themselves, of couse.  I'm not sure if this
is the best suited API; maybe we can discuss and make a better one
too.  For example:

1) a pair of functions to register and unregister a GC pointer that
lives outside the GC

2) or maybe a way to register and unregister "external" GcStructs:
you'd still allocate and free raw bytes for the PyObject wrapper, but
making sure it has a GcStruct shape (i.e. some standard GC headers).
You would then register and unregister it to be considered by the GC.
This looks easy to implement: it is the same as we consider all the
prebuilt GcStructs that exist at translation time.  In other words,
they are a source of further GC pointers, but which live themselves
outside the scope managed by the GC.  The difference with 1) is that
the GC can still write flags in the header of these objects; it helps
a lot generational GCs.


A bientôt,

Armin.
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
http://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to