[Cython] On forking CCodeWriters

Stefan Behnel stefan_ml at behnel.de
Tue Jul 29 20:00:38 CEST 2008


Hi Dag,

Dag Sverre Seljebotn wrote:
> I just implemented forking codewriters. I'll use them for temporaries, 
> but they have other usecases as well (I used it to clean up 
> ModuleNode.generate_c_code as well, and I might want to add (in 
> addition) utility code registration in the code writer).
> 
> The concept is this: Whenever you have a codewriter, you can call fork() 
> on it:
> 
> declarations_code = code.fork()
> 
> and that will "drop off" a codewriter at the current location (there 
> shouldn't be any perforamance hit compared with what is in Cython today, 
> everything was buffered anyway and buffers are never copied). One can go 
> on writing to code, and once one is done, one can write to 
> declarations_code to insert something at the point it was forked off.

If I understand this correctly, "forking" isn't the right word (and it got me
very confused when I read your description). It's rather a kind of stub
mechanism or a placeholder, something that keeps an insertion point alive and
allows you to add code at this point even if you have already continued
appending code after that point.

This reminds me more of a cone, or a Deferred in Twisted terminology.

Is there any other use case besides the header-/c-file overlap?

Stefan



More information about the Cython-dev mailing list