[Cython] On forking CCodeWriters

Robert Bradshaw robertwb at math.washington.edu
Wed Jul 30 06:05:38 CEST 2008


On Jul 29, 2008, at 12:16 PM, Dag Sverre Seljebotn wrote:

> Dag Sverre Seljebotn wrote:
>> Stefan Behnel wrote:
>>> 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.
>>
>> You're probably right. It is a concept that developed and what I  
>> started
>> with was more like a fork than this :-)
>>
>> Hmm. It is kind of similar though .. a lot of state is copied in ways
>> similar to process forking. But I see that the name is not good.
>>
>> Suggestions about the exact call name very welcome .. I'll leave  
>> it for
>> a few days and see what feels natural before I go changing it.
>
> This is no longer true, it started irritating me incredibly when I
> started thinking about it. It is now code.delayed_writing(). But I can
> change it again.

I think the idea of forking the code writer is a great one. In terms  
of naming, perhaps "code.insertion_point()" or something like that.  
I'm not sure with delayed_writing() because it's unclear whether or  
not the returned object is delayed, or the current object is delayed.

- Robert



More information about the Cython-dev mailing list