An error message in/before primitiveApply would be welcome (SDL progress)

Paul Dufresne dufrp at hotmail.com
Sat Jan 22 09:28:12 PST 2005


My problems with SDL code for polygons was mostly cut/paste bug.
I had:
---
SDLLib addSlot: #polygonRGBA valued: (SDLLib libSDLgfx functionNamed: 
'polygonRGBA').
SDLLib polygonColor argumentsFormat: {
---
where I wanted SDLLib polygonRGBA argumentsFormat: { ... .

The result was that in src/mobius/vm/platform/extprim.c,
at the beginning of applyExternalLibraryPrimitive function:
---
  if (argCount > MAX_ARG_COUNT || argCount != PSObject_arraySize ((struct 
Object *) argsFormat))
    return CurrentMemory -> NilObject;
---
made it returned Nil, while I was not testing for Nil.
So after some hunting the bug, I did change the previous for:
---
  if (argCount > MAX_ARG_COUNT || argCount != PSObject_arraySize ((struct 
Object *) argsFormat)){
    printf("Either the number of arguments > 12 or\n");
    printf(" argCount=%d != %d sizeof(argsFormat)\n", argCount,
      PSObject_arraySize((struct Object *) argsFormat) );
    return CurrentMemory -> NilObject;
    }
---
And from then, after remaking the VM, my bugs began to be clear to me.
Although I'd like to see this kind of help message, for me and others
like me in the future, maybe this test should be done in
src/lib/extlib.slate. Maybe
---
m@(ExternalMethod traits) applyTo: args
[
  m library primitiveApply: m handle accepting: m argumentsFormat 
callFormat: m callFormat returning: m resultFormat to: args
].
---
Should become:
---
m@(ExternalMethod traits) applyTo: args
[
  args size ~= m argumentsFormat size
  ifTrue: [ error: ('nbr of arguments to externalMethod (' ;;
    (Integer readNumber: args size a) ;; ') is ~= than the
    numbers of elements in its argumentsFormat (' ;;
    (Integer readNumber: m argumentsFormat size) ;; ')' ) ]
  ifFalse:
   [m library primitiveApply: m handle accepting: m argumentsFormat
    callFormat: m callFormat returning: m resultFormat to: args]
].
---
Watch out! I just wrote that without testing at all!

It is feeling like a new release soon, and I'll be glad to see something
like this to enter CVS before release.

--Paul Dufresne





More information about the Slate mailing list