Re: Better type than void* for primitiveFunctionPointer?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Better type than void* for primitiveFunctionPointer?

Andreas.Raab
 
I think only Ian knows what "this stupidity" is. Also, I'm not fond of
profanity in code in general and would consequently just remove the
comment until an actual criticism / improvement is offered. This kind of
comment is not helpful and should be expunged whenever one is found.

Cheers,
   - Andreas

tim Rowledge wrote:

>
> In Interpreter>declareCVarsIn: we currently have:-
>         declareC: 'void *primitiveFunctionPointer'                
> .        "xxxx FIX THIS STUPIDITY xxxx - ikp. What he means is use a
> better type than void *, apparently - tpr"
>
> Anyone care to offer the better type than void* ? Speak now or stop
> whining later.
>
> tim
> --
> tim Rowledge; [hidden email]; http://www.rowledge.org/tim
> Fractured Idiom:- QUE SERA SERF - Life is feudal
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Better type than void* for primitiveFunctionPointer?

Ian Piumarta
 

On Apr 15, 2008, at 12:41 PM, Andreas Raab wrote:

> I think only Ian knows what "this stupidity" is.

Casting a function pointer to a void * is not guaranteed to yield a  
pointer with the same address, nor does casting it back.  The  
stupidity was the (imposed?) use void * where a pointer to function  
was required.

> Also, I'm not fond of profanity in code in general and would  
> consequently just remove the comment

The comment was a note from me to me.  Go ahead and remove it; it's  
unlikely I'll ever get around to fixing it.  Can't say anything about  
any other comments you don't like and choose to delete unilaterally.

Cheers,
Ian

Reply | Threaded
Open this post in threaded view
|

Re: Better type than void* for primitiveFunctionPointer?

timrowledge
 

On 15-Apr-08, at 1:05 PM, Ian Piumarta wrote:

>
> On Apr 15, 2008, at 12:41 PM, Andreas Raab wrote:
>
>> I think only Ian knows what "this stupidity" is.
>
> Casting a function pointer to a void * is not guaranteed to yield a  
> pointer with the same address, nor does casting it back.  The  
> stupidity was the (imposed?) use void * where a pointer to function  
> was required.

So what ought to be there is...... ?


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
C++ is history repeated as tragedy. Java is history repeated as farce.


Reply | Threaded
Open this post in threaded view
|

Re: Better type than void* for primitiveFunctionPointer?

Ian Piumarta
In reply to this post by Ian Piumarta
 
On Apr 15, 2008, at 1:09 PM, tim Rowledge wrote:

>
> On 15-Apr-08, at 1:05 PM, Ian Piumarta wrote:
>
>>
>> On Apr 15, 2008, at 12:41 PM, Andreas Raab wrote:
>>
>>> I think only Ian knows what "this stupidity" is.
>>
>> Casting a function pointer to a void * is not guaranteed to yield  
>> a pointer with the same address, nor does casting it back.  The  
>> stupidity was the (imposed?) use void * where a pointer to  
>> function was required.
>
> So what ought to be there is...... ?


returnType (*functionName)(arg1type, arg2type, ..., argNtype)


>
>
> tim
> --
> tim Rowledge; [hidden email]; http://www.rowledge.org/tim
> C++ is history repeated as tragedy. Java is history repeated as farce.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Better type than void* for primitiveFunctionPointer?

Andreas.Raab
In reply to this post by Ian Piumarta
 
Ian Piumarta wrote:
> The comment was a note from me to me.  Go ahead and remove it; it's
> unlikely I'll ever get around to fixing it.  Can't say anything about
> any other comments you don't like and choose to delete unilaterally.

Fortunately it's a rare occurrence to find such comments in the code.

Cheers,
   - Andreas
Reply | Threaded
Open this post in threaded view
|

Re: Better type than void* for primitiveFunctionPointer?

Igor Stasenko
 
In Hydra, i added declaration of primitive function type:

typedef sqInt (*PrimitiveFn)(struct Interpreter *) __attribute__((cdecl));

So, later in code its using this type:

        PrimitiveFn primitiveFunctionPointer;
        PrimitiveFn externalPrimitiveTable[4097];
sqInt callExternalPrimitive(struct Interpreter *intr, PrimitiveFn functionID);

and so on..

Note about cdecl attribute. It was placed explicitly to make sure that
primitive functions always get called using cdecl calling convention.
We need this to not make difference between calling 'legacy'
primitives and primitives which expect additional argument
(interpreter instance).
A cdecl calling convention helping us to call functions which not
expecting any arguments as function which expects one. In this case
argument just ignored, and what is important, since with cdecl calling
convention only a caller responsive from cleaning a stack after call,
there is no stack corruption.

2008/4/16 Andreas Raab <[hidden email]>:

>
>  Ian Piumarta wrote:
>
> > The comment was a note from me to me.  Go ahead and remove it; it's
> unlikely I'll ever get around to fixing it.  Can't say anything about any
> other comments you don't like and choose to delete unilaterally.
> >
>
>  Fortunately it's a rare occurrence to find such comments in the code.
>
>  Cheers,
>   - Andreas
>



--
Best regards,
Igor Stasenko AKA sig.