
[saving this for my own reference]
===========================================================================

To: gmcm@hypernet.com, MHammond@skippinet.com.au, tismer@appliedbiometrics.com
CC: guido@cnri.reston.va.us, rushing@nightmare.com
Subject: calldll, SaveThread, RestoreThread
FCC: c:/users/rushing/mail-archive
--text follows this line--
Ok, I've read over the documentation for this stuff a couple
of times, and I'll try to describe it as I understand it, you
guys correct me if I'm wrong:

The requirement for per-thread state means that when we call a
foreign function, we must use PyEval_SaveThread() and keep a copy of
the pointer that is returned. (let's call it 'Jim', for fun).

When the foreign function calls a gencb 'trampoline'
(http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=trampoline), it
needs to call PyEval_RestoreThread with the value of 'Jim'.

In order to be re-entrant, we must have some way of communicating
the value of 'Jim' to the trampoline.


			   ---------------
 Python	      +           /		  \
--------------|-----------|---------------|--------------------------------
              |		  |		  |		     |
	      V		  ^   CALLBACK	  V		     ^
	      |		  |   	       	  | 		     |
       	    save       restore          save		  restore
	      |		  |		  |		     |
	      V		  ^		  V		     ^
	      |		  |		  |		     |
--------------|-----------|---------------|--------------------------------
 Foreign      |		  |		  |		     |
	       \----------/ - - - - - - - \------------------/

The difficulty here is in making 'Jim' available to all these instances
of save/restore.

I'm thinking that maybe we can use 'thread local storage', or is there
an easier way?

-Sam
