[Vm-dev] a problem with alien, primitive fail (primFFICallResult:withArguments:)

Igor Stasenko siguctua at gmail.com
Tue Dec 28 14:06:20 UTC 2010


hmm i should probably check the code by myself,
because in given context it doesn't makes too much sense to me.

if you need to convert from integer object to unsigned 32-bit integer,
then any negative integer passed from smalltalk should raise and error
(a primitive failure)
which actually positive32BitValueOf() does.

But if you don't care about sign of integer value, and care only that
it  should fit in 32-bit word,
then of course, you could do like you did:
> if (argClass == (interpreterProxy->classLargePositiveInteger())) {
> v = interpreterProxy->positive32BitValueOf(arg);
> } else {
> v = interpreterProxy->signed32BitValueOf(arg);
> }
>

Squeak integer -> C unsigned long
use positive32BitValueOf()

Squeak integer -> C signed long
use signed32BitValueOf()

in any case, a caller of callout should state explicitly, which value
type (signed or unsigned)
he wants to pass as argument, not "i don't care". :)


On 28 December 2010 14:45, Esteban Lorenzano <estebanlm at gmail.com> wrote:
>
> Hi,
> so in dabusiness.h I changed
> } else {
> long v = interpreterProxy->signed32BitValueOf(arg);
> if (interpreterProxy->failed())
> return PrimErrBadArgument;
> *(long *)argvec = v;
> argvec += sizeof(long);
> }
> for
> } else {
> long v;
> sqInt argClass = interpreterProxy->fetchClassOf(arg);
> if (argClass == (interpreterProxy->classLargePositiveInteger())) {
> v = interpreterProxy->positive32BitValueOf(arg);
> } else {
> v = interpreterProxy->signed32BitValueOf(arg);
> }
>
> if (interpreterProxy->failed())
> return PrimErrBadArgument;
> *(long *)argvec = v;
> argvec += sizeof(long);
> }
> now it seems to be working... maybe I need extend this for other integer possible values? well, one problem at a time... for now is working, but the Alien Bridge still don't, so I'll continue hacking that :)
> Cheers and thanks
> Esteban
>
> El 28/12/2010, a las 5:37a.m., Igor Stasenko escribió:
>
> On 28 December 2010 01:54, Esteban Lorenzano <estebanlm at gmail.com> wrote:
>
> Hi,
>
> I'm trying to get the Alien ObjectiveC bridge to work, and I'm having a problem (right now no cog, just cocoa vm 5.7 with "regular" alien, NewspeakI32ABIPlugin), and I'm having a problem on sending a message with this form:
>
> someAlien
>
> primFFICallResult: resultAlien
>
> withArguments: {anAlien. aLargePositiveInteger}
>
> so... it is answering primitiveFail (code 3), because the third argument is bad taken when converting... the primitive does this path:
>
> callIA32IntegralReturn,
>
> ...
>
> long v = interpreterProxy->signed32BitValueOf(arg);
>
> ...
>
> value = (((byteAt((oop + (BASE_HEADER_SIZE)) + 0)) + ((byteAt((oop + (BASE_HEADER_SIZE)) + 1)) << 8)) + ((byteAt((oop + (BASE_HEADER_SIZE)) + 2)) << 16)) + ((byteAt((oop + (BASE_HEADER_SIZE)) + 3)) << 24);
>
> value here is negative, and of course, it throws an error.
>
> So... anybody has a clue of whats wrong? I know the number is actually a LargePositiveInteger, so it should be ok, and pass... so any idea?
>
> sure, if your largePositiveInteger, which is 32bit unsigned integer,
> then
>
> long v = interpreterProxy->signed32BitValueOf(arg);
>
> should be
>
> unsigned long v = interpreterProxy->positive32BitValueOf(arg);
>
> Cheers,
>
> Esteban
>
>
>
>
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.


More information about the Vm-dev mailing list