You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucy.apache.org by "Marvin Humphrey (JIRA)" <ji...@apache.org> on 2009/12/25 02:07:29 UTC

[jira] Updated: (LUCY-89) Tighten Clownfish method invocation type checking

     [ https://issues.apache.org/jira/browse/LUCY-89?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Marvin Humphrey updated LUCY-89:
--------------------------------

    Attachment: tighten_types.diff

The first patch, "tighten_types.diff", changes the Clownfish code generator to
avoid the cast to "const void*".  

Before:

{code:none}
static CHY_INLINE lucy_Obj*
Lucy_PriQ_Pop(const void *vself)
{
    lucy_PriorityQueue *const self = (lucy_PriorityQueue*)vself;
    char *const method_address = *(char**)self + Lucy_PriQ_Pop_OFFSET;
    const lucy_PriQ_pop_t method = *((lucy_PriQ_pop_t*)method_address);
    return method(self);
}
{code}

After:

{code:none}
static CHY_INLINE lucy_Obj*
Lucy_PriQ_Pop(const lucy_PriorityQueue *self)
{
    char *const method_address = *(char**)self + Lucy_PriQ_Pop_OFFSET;
    const lucy_PriQ_pop_t method = *((lucy_PriQ_pop_t*)method_address);
    return method((lucy_PriorityQueue*)self);
}
{code}

The "const" cast has been left in place, even though it is wrong quite a lot
-- whenever a method modifies the object.  This is mildly dangerous, because
you can e.g. invoke CB_Cat_Str(charbuf, "foo", 3) on an constant CharBuf and
the compiler will not complain.  However, in order to fix that problem, we
would need to audit all methods to determine which are safe to call on "const"
objects and modify their method signatures -- a cure which is worse than the
disease.

> Tighten Clownfish method invocation type checking
> -------------------------------------------------
>
>                 Key: LUCY-89
>                 URL: https://issues.apache.org/jira/browse/LUCY-89
>             Project: Lucy
>          Issue Type: Improvement
>          Components: Clownfish, Core, Perl bindings
>            Reporter: Marvin Humphrey
>            Assignee: Marvin Humphrey
>         Attachments: tighten_types.diff
>
>
> Clownfish method invocation is implemented using C static inline functions. 
> The first argument to these functions is the object itself, which up till now 
> has been cast to "const void*".  It is better to have the first argument match 
> the type of the invoker, so that the C compiler will issue warnings if you try 
> to invoke a method on an inappropriate object, e.g. "PriQ_Pop(hash)".

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.