On May 7, 2013, at 14:51 , Nick Wellnhofer <[email protected]> wrote:

> On 30/04/2013 02:35, Marvin Humphrey wrote:
>> One more implementation note: Clownfish-generated host bindings cannot wrap
>> host values for parameters which are marked as `decremented`, e.g, such as 
>> the
>> `element` parameter passed to VA_Push():
>> 
>>     /** Push an item onto the end of a VArray.
>>      */
>>     void
>>     Push(VArray *self, decremented Obj *element = NULL);
>> 
>> The implementation copies the passed-in pointer directly, so it's up to the
>> caller to manage reference counting:
>> 
>>     void
>>     VA_push(VArray *self, Obj *element) {
>>         if (self->size == self->cap) {
>>             VA_Grow(self, Memory_oversize(self->size + 1, sizeof(Obj*)));
>>         }
>>         self->elems[self->size] = element; // <-------------------- HERE
>>         self->size++;
>>     }
> 
> Good point. But it goes even further than that. What if a wrapped host 
> language string is passed as a decremented parameter *at a later point*? It 
> will result in the same problem, but it can't be worked around in the host 
> bindings.

Thinking more about it, this shouldn't be a problem. Only objects that can 
safely be decref'd should ever be passed as 'decremented' argument. So if a 
caller wants to pass a string which might be a wrapped host language string, it 
must be incref'd anyway. Only the following would be unsafe:

    some_func(..., String *string, ...) {
        ...
        String *captured = (String*)CAPTURE(string);
        // Should pass 'captured', not 'string'
        VA_Push(array, string);
        ...
    }

I think it should be clear that 'captured' must be passed instead of 'string'.

Nick

Reply via email to