On Tue, 2007-05-22 at 12:26 -0600, Alan Silverstein wrote:
> > Ok, sorry ..  found the bug.  Set uses void** but others use void*.
> 
> Yeah, undeniably the asymmetries at the function level have confused
> people over time.  That's why Doug created the macro layer.  I believe
> the signatures are "correct" in a philosophical sense, but since care
> must be taken to use them properly, it IS an obstacle to using the
> library successfully.
> 
> Hey, does the use of PPvoid_t and Pvoid_t for clarity help prevent
> problems, through compile-time warnings?  Or are compilers "helpful
> enough" that they figure void ** = void * and they don't tell you?

void* isn't = to void** :)

A void* parameter will accept a void** argument, but not
the other way around.

In C but not C++, a void* will implicitly convert to any
pointer (including void**).

For Judy1Array, the right choice in the interface is probably:

        typedef struct _dummy_J1A *Judy1Array;

I'll have to think on this. Generally, Judy arrays cannot
be passed by value. However, the 'top level' of the data 
structure happens to be a pointer, and provided the operation
isn't a mutator, passing it is safe and marginally more
efficient.

Unfortunately, if you allow this there is a danger
that someone will do this:

        void myfunc(Judy1Array a) { // pass by value
                Judy1Set(&a); // WOOPS!!!
        }

Here the user modified the local copy of 'a' but
not the original .. however the balance of the
array data structure is shared and the result
is that the original array is now corrupted.

That's why in my Felix binding I use this:

  type J1Array = "void**";
  gen _ctor_J1Array: 1 -> J1Array = "_mkj1()" requires body 
   """
     void **_mkj1(){
       void **m =(void**)malloc(sizeof(void*));
       *m=0;
       return m;
     }
   """;

  proc Judy1UnSet: J1Array * word * JError_t * ptr[int] = 
    "*$4=Judy1UnSet($1,$2,$3);";

  proc Judy1Test: J1Array * word * JError_t * ptr[int] = 
    "*$4=Judy1Test(*$1,$2,$3);";


Notice the call to Judy1Test dereferences argument 1,
whereas that to Judy1Set does not.

In the Felix code, the J1Array type is a reference
to an array, not an array value, but it is safe to
pass about anywhere (except for the usual problems
freeing storage which I can fix later using a 
garbage collected type).

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Judy-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/judy-devel

Reply via email to