Hello,
I'm having trouble passing around a pointer between interpreted Squeak code and compiled plugin code. I have a primitive method that returns a pointer like this:
^ aPtr asOop: Unsigned
This seems to work fine; depending on the value, I get either a SmallInteger or a LargePositiveInteger. The problem arises when I try to pass this into another primitive method that looks like this:
primNeedPointer: aPtr
self primitive: 'primNeedPointer' parameters: #(Unsigned) "more stuff..."
The generated C code causing the failure is:
interpreterProxy->success(interpreterProxy->isKindOf(interpreterProxy->stackValue(0), "Unsigned"));
Looking at the code for isKindOf(), it is clear why it fails: the object (a SmallInteger or LargePositiveInteger) is not an instance of Unsigned or one of its subclasses.
I followed the directions on: http://minnow.cc.gatech.edu/squeak/850 as closely as possible. What am I doing wrong?
Thanks, Joshua
Somewhat late, since I'm sitting in a hotel (working outside and had big problems to connect...), but here are a few hints:
Joshua 'Schwa' Gargus wrote:
Hello,
I'm having trouble passing around a pointer between interpreted Squeak code and compiled plugin code. I have a primitive method that returns a pointer like this:
^ aPtr asOop: Unsigned
This seems to work fine; depending on the value, I get either a SmallInteger or a LargePositiveInteger. The problem arises when I try to pass this into another primitive method that looks like this:
primNeedPointer: aPtr
self primitive: 'primNeedPointer' parameters: #(Unsigned) "more stuff..."
The generated C code causing the failure is:
interpreterProxy->success(interpreterProxy->isKindOf(interpreterProxy->stackValue(0), "Unsigned"));
Looking at the code for isKindOf(), it is clear why it fails: the object (a SmallInteger or LargePositiveInteger) is not an instance of Unsigned or one of its subclasses.
You could use "Integer" here.
But there is another problem: if you have a LargeInteger as 'ptr' its oop may have changed between the calls of the two prims.
Greetings,
Stephan
I followed the directions on: http://minnow.cc.gatech.edu/squeak/850 as closely as possible. What am I doing wrong?
Thanks, Joshua
Hi Stephan,
Thanks for replying from your hotel,
On Wed, Jan 09, 2002 at 11:47:59PM +0100, Stephan Rudlof wrote:
Somewhat late, since I'm sitting in a hotel (working outside and had big problems to connect...), but here are a few hints:
Joshua 'Schwa' Gargus wrote:
Hello,
I'm having trouble passing around a pointer between interpreted Squeak code and compiled plugin code. I have a primitive method that returns a pointer like this:
^ aPtr asOop: Unsigned
This seems to work fine; depending on the value, I get either a SmallInteger or a LargePositiveInteger. The problem arises when I try to pass this into another primitive method that looks like this:
primNeedPointer: aPtr
self primitive: 'primNeedPointer' parameters: #(Unsigned) "more stuff..."
The generated C code causing the failure is:
interpreterProxy->success(interpreterProxy->isKindOf(interpreterProxy->stackValue(0), "Unsigned"));
Looking at the code for isKindOf(), it is clear why it fails: the object (a SmallInteger or LargePositiveInteger) is not an instance of Unsigned or one of its subclasses.
You could use "Integer" here.
But there is another problem: if you have a LargeInteger as 'ptr' its oop may have changed between the calls of the two prims.
I suppose that this is because of a possible garbage collection. However, I'm failing to see why this is a problem, since the value of the LargeInteger would be the same even if its oop changed. Could you clarify exactly what the problem is?
Thanks again, Joshua
Greetings,
Stephan
I followed the directions on: http://minnow.cc.gatech.edu/squeak/850 as closely as possible. What am I doing wrong?
Thanks, Joshua
-- Stephan Rudlof (sr@evolgo.de) "Genius doesn't work on an assembly line basis. You can't simply say, 'Today I will be brilliant.'" -- Kirk, "The Ultimate Computer", stardate 4731.3
Joshua,
Joshua 'Schwa' Gargus wrote:
Hi Stephan,
Thanks for replying from your hotel,
On Wed, Jan 09, 2002 at 11:47:59PM +0100, Stephan Rudlof wrote:
Somewhat late, since I'm sitting in a hotel (working outside and had big problems to connect...), but here are a few hints:
Joshua 'Schwa' Gargus wrote:
Hello,
I'm having trouble passing around a pointer between interpreted Squeak code and compiled plugin code. I have a primitive method that returns a pointer like this:
^ aPtr asOop: Unsigned
This seems to work fine; depending on the value, I get either a SmallInteger or a LargePositiveInteger. The problem arises when I try to pass this into another primitive method that looks like this:
primNeedPointer: aPtr
self primitive: 'primNeedPointer' parameters: #(Unsigned) "more stuff..."
The generated C code causing the failure is:
interpreterProxy->success(interpreterProxy->isKindOf(interpreterProxy->stackValue(0), "Unsigned"));
Looking at the code for isKindOf(), it is clear why it fails: the object (a SmallInteger or LargePositiveInteger) is not an instance of Unsigned or one of its subclasses.
You could use "Integer" here.
But there is another problem: if you have a LargeInteger as 'ptr' its oop may have changed between the calls of the two prims.
I suppose that this is because of a possible garbage collection.
Correct.
However, I'm failing to see why this is a problem, since the value of the LargeInteger would be the same even if its oop changed.
This is true.
Could you clarify exactly what the problem is?
I have to admit that I have seen the wrong ghosts here...
But there is another one: Your example has given the impression to me (this may be wrong) that you try to hold a C ptr as SmallInteger or LargePositiveInteger in ST between the calls of these two prims. If it is a SmallInteger you could use interpreterProxy->integerValueOf: oop to transform it back into the C ptr, because its oop is directly transformable into its value. For a LargePositiveInteger this wouldn't work, because its oop has nothing to do with its value.
Probably you know it yet.
Greetings,
Stephan
...
PS: Currently I don't *receive* any mail (problems with provider), so please be patient if there should be another question...
Let me know if the attached solves your problem. I seem to recall that this (simple typo) fix was posted and incorporated a long time ago, while we were working on the long integer arithmetic plugins. Since the changes were going in fast and furious at that time, it is possible that this fix was accidentally undone.
'From Squeak3.3alpha of 12 January 2002 [latest update: #4914] on 12 July 2002 at 10:18:43 pm'! "Change Set: acgRepairTestInterpreterPlugin Date: 12 July 2002 Author: acg
The Unsigned special behavior had two code generation methods mistakenly placed on the instance side, not the class side, which affected prologue conversions. This changeset merely moves them appropriately. I had thought the fix to this bug was posted and image-incorporated some time ago, but here it is again."!
On Friday, July 12, 2002, at 10:32 PM, Joshua 'Schwa' Gargus wrote:
primNeedPointer: aPtr
self primitive: 'primNeedPointer'
parameters: #(Unsigned) "more stuff..."
squeak-dev@lists.squeakfoundation.org