[pypy-dev] Newb questions about ext module writing

Scott Dial scott+pypy-dev at scottdial.com
Sat Jul 22 02:31:57 CEST 2006


Greetings everyone,

I'm relatively new to PyPy. I've been aware of it for a while, but never 
really got into poking around at all. But recently I decided this is a 
project that I would like to get involved in. I think at the time I 
planned on doing something big, like addding a JVM backend or something 
like that.. maybe I'll get back to that eventually. I realized I was 
fairly clueless with the codebase and decided to jump on writing a 
module as a type of introductory project.

The independent-project-ideas went out of its way to mention readline, 
so boom, readline is what I had/have chosen to finish. Things were going 
well until I started having to deal with making callback functions.

I have become stuck on the need to setup_readline with some callback 
functions which are capable of accessing the State of the module. I'm 
pretty lost on how to go about getting the state. Within the 
interp_readline, I do the "space.fromcache(State)" deal to get ahold of 
the State, but how do I do this from within the "c_readline" component. 
Perhaps this is completely the wrong way to go about this? My first 
thought is to import the "getstate" function from interp_readline, but I 
can't find anywhere else this is done in the codebase off-hand.

Furthermore, my callback functions from readline will not be passed any 
sort of "state", so how do I get that from within my callback function? 
Again, I thought a poor kludge was to tag reference to "state" onto the 
function during setup_readline.

def setup_readline(state, w_module):
     ...
     cfunc = CFUNCTYPE(POINTER(c_char_p), c_char_p, c_int, c_int)
     c_rl_attempted_completion_function = cfunc(space.flex_complete)
     space.flex_complete.space = space
     ...

def flex_complete(text, start, end):
     from pypy.module.readline.interp_readline import getstate
     getstate(flex_complete).begidx = start
     getstate(flex_complete).endidx = end
     ...

Some ugly stuff like that.. help? :) Thanks.

-- 
Scott Dial
scott at scottdial.com
scodial at indiana.edu



More information about the Pypy-dev mailing list