Bizarre hapenning in my plugin

John M McIntosh johnmci at smalltalkconsulting.com
Sun Jan 22 01:57:31 UTC 2006


It's the

self cCode: 'return value'

Really all you are returning is the value to the primitive calling  
interface, 5hat of course is ignored.
What you really want to do is stick an object onto the smalltalk  
stack so it can be returned as expected.
You can manual push/pop things to the stack, but I prefer to use the  
smart syntax.

So lets look at an example of the mac spelling plugin

primitiveGetIgnoredWordsListLengthWithTag: aTag
	"Get ignored word list"
	| length |

	self primitive: 'primitiveGetIgnoredWordsListLengthWithTag'   
parameters:#(SmallInteger).
	length := self sqSpellingGetIgnoredWordsListLengthWithTag: aTag.
	^length asSmallIntegerObj

First I use the smart syntax to setup the primitive name and the  
parameters.
self primitive:parameters:

Then we return the smalltalk object we expect to
	^length asSmallIntegerObj

So for that I do length asSmallIntegerObj
or I could say
^length asOop: SmallInteger
or
^frames asPositiveIntegerObj
^rate asFloatObj

or much more complex things like
	interpreterProxy pushRemappableOop: (right asOop: Float).
	interpreterProxy pushRemappableOop: (left asOop: Float).
	interpreterProxy pushRemappableOop: (interpreterProxy  
instantiateClass: (interpreterProxy classArray) indexableSize: 2).
	results := interpreterProxy popRemappableOop.
	interpreterProxy storePointer: 0 ofObject: results withValue:  
interpreterProxy popRemappableOop.
	interpreterProxy storePointer: 1 ofObject: results withValue:  
interpreterProxy popRemappableOop.
	^ results

the length asSmallIntegerObj  turns into this C code, which converts  
the C object into a Smalltalk object, checks the conversion, then does
the pop  & push to setup the return value on the smalltalk stack, and  
returns null to the C caller...

	_return_value = interpreterProxy->integerObjectOf(length);
	if (interpreterProxy->failed()) {
		return null;
	}
	interpreterProxy->popthenPush(2, _return_value);
	return null;




On 21-Jan-06, at 1:57 PM, Cowdery, Bob [UK] wrote:

> I have some bizarre happenings in my plugin. It must be me, but I  
> have no idea what’s going on.
>
>
> Firstly, the plugin does actually work and is not trivial because  
> it uses PortAudio which it streams through a little signal  
> processing function. I can start it and stop it and it all behaves  
> properly. The start() and stop() take no parameters. The problems  
> start when I try and pass parameters to the other functions.
>
>
> I tried a test function:
>
>
> answerValue: value
>
>
>             <primitive: 'answerValue' module:'SDRPhasingDSPPlugin'>
>
>             Transcript show: 'Primitive answerValue failed'.
>
>             ^ false
>
>
>
> As far as I know you can just do this:
>
>
> answerValue: value
>
>
>             self export: true.
>
>
>             (self cCode: 'return value')
>
>
> This translated to:
>
>
> EXPORT(int) answerValue(int value) {
>
>             return value;
>
> }
>
>
> When I tried this it appeared to work. No failures and I got back  
> what I entered. Then I realised I could put anything as a parameter :
>
>
> x answerValue: ‘abc’ ‘abc’
>
>
> Whatever parameter I gave it got echoed back regardless of whether  
> it was an int or not. I could even say.
>
>
> x answerValue: x a SDRPhasingDSP
>
>
> To prove this I changed the code to
>
>
> answerValue: value
>
>
>             self export: true.
>
>
>             (self cCode: 'return 100’)
>
>
> and still got back what I entered.
>
>
> Incidentally:
>
>
> x getModuleName a SDRPhasingDSP
>
>
> also answers the type of x and not the plugin name.
>
>
> Please put me on the right track someone before I go completely mad.
>
>
> Thanks
>
> Bob
>
> *** Confidentiality Notice *** Proprietary/Confidential
> Information belonging to CGI Group Inc. and its affiliates
> may be contained in this message. If you are not a recipient
> indicated or intended in this message (or responsible for
> delivery of this message to such person), or you think for
> any reason that this message may have been addressed to you
> in error, you may not use or copy or deliver this message
> to anyone else.  In such case, you should destroy this
> message and are asked to notify the sender by reply email.
>
>

--
======================================================================== 
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
======================================================================== 
===




More information about the Squeak-dev mailing list