Embeding Python & Dynamic Callbacks

Stuart D. Gathman stuart at bmsi.com
Wed Sep 26 18:47:05 CEST 2001

In article <916a2aab.0109260249.318d156f at posting.google.com>, "Paul Tate"
<paulypoos at hotmail.com> wrote:

> I can dynamically create the method table, but I cannot dynamically
> create a C callback function.  If I use the same callback for each
> dynamically loaded function, I do not know how to find out which token
> caused the callback to be called.

idea 1 - provide an extension object(s)  through which dynamic C code is
called.  Calls to methods of built-in types go through the get_attr call,
so you know which token was used.  get_attr also provides the python code
with a current list of attributes and methods - so that python can call C
code loaded *after* the module is initialized.

idea 2 - Dynamically create the C callback functions.  GNU C will generate
the trampoline code on the stack for nested functions. (Not an ANSI C
feature.)  There should be a way to leverage this for malloced dynamic
functions.  A trampoline is a tiny  function introducer that simply adds
an additional argument and jumps to a regular C function.  It is trivial
enough to generate the 2 or 3 machine instructions, but some CPUs require
flushing the instruction cache as well. 

Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - Mozart background
song for the Microsoft "Where do you want to go from here?" commercial.

More information about the Python-list mailing list