[cffi-devel] Type Translators and Callbacks

Luís Oliveira luismbo at gmail.com
Tue Nov 15 22:57:04 UTC 2005


On 2005-nov-15, at 15:34, James Bielman wrote:
> Well, I don't see the point of using a separate translator for  
> callback
> return values versus setting foreign variables.  If I understand :TO-C
> correctly, it is used when we have a Lisp value we need to convert  
> to a
> C value with indefinite extent, which is the situation in both those
> cases.

Good point, that was the purpose of separating :TO-C from :TO-C-DYNAMIC.


> The more I think about it, the more I like just specifying the  
> built-in
> type translators for aggregate objects (which is just :STRING, right?)
> allocate their memory using malloc in the :TO-C case.  I can't see any
> real good reason not to.

Right. Must not forget to document this well.


> If I had an existing string I wanted to pass from a callback I would
> just declare it to return :POINTER instead.  (What happens if you  
> return
> a pointer from a function with a result-type of :STRING?  Should it  
> pass
> it unmodified or malloc a copy?)

Good question. My gut feeling is that it should be passed unmodified  
since if you're passing a pointer it probably means that you want to  
bypass the translator. But I'm not sure.

-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt




More information about the cffi-devel mailing list