OS X Externals

Frank D. Engel, Jr. fde101 at fjrhome.net
Wed Oct 13 17:02:29 EDT 2004


Unfortunately, there is still a bug somewhere that I can't seem to 
figure out.  Keeps happening... if programming were easy, why would 
anyone do it ;-)

My original Transcript code for dbBLOB is as follows:

function dbBLOB bdat
   put "'" into x
   set the cursor to watch
   repeat for each char c in bdat
     put format("\\\\%03o", charToNum(c)) after x
   end repeat

   return x & "'::bytea"
end dbBLOB


This simply takes each character and yields a zero-padded, three-octet 
number preceded by two backslash '\' characters.  My C equivalent 
reads:

void dbBLOB(char *args[], int nargs, char **retstring, Bool *pass, Bool 
*error)
{
	int retvalue;
	MCstring rdata;
     char *buffer;
	int i, j = 0;
	
	if(nargs != 1)
	{
	    *retstring = 0;
		*pass = False;
		*error = True;
		return;
	}
	
	GetVariableEx(args[0], "", &rdata, &retvalue);
	
	buffer = (char *)malloc(10 + (rdata.length * 5));
	*pass = False;
	*error = False;
	
	buffer[j++] = '\'';
	
	for(i = 0; i < rdata.length; i++)
	{
		buffer[j++] = '\\';
		buffer[j++] = '\\';
		sprintf(&(buffer[j]), "%03o", rdata.sptr[i]);
		j += 3;
	}
	
	buffer[j++] = '\'';
	buffer[j++] = ':';
	buffer[j++] = ':';
	buffer[j++] = 'b';
	buffer[j++] = 'y';
	buffer[j++] = 't';
	buffer[j++] = 'e';
	buffer[j++] = 'a';
	buffer[j] = 0;
	
	*retstring = buffer;
}


The same basic algorithm (except with better memory management to help 
boost the performance somewhat), right?

So why does the output from the Transcript version start with:

\\377\\330\\377\\341\\022\\277

While the output from the C version starts with:

\\377\\377\\377\\377\\022\\377


For the exact same input?

I can only guess that the data is being modified by Rev before it 
reaches the external C function.  Of course, this means that the 
Transcript version works, but the C version does not -- even though the 
C version is *much* faster (of course).  Any takers on how to handle 
this?


Oh, and the C version is called by the Transcript wrapper:

function dbBLOB adat
   put adat into res
   return dbxBLOB("res")
end dbBLOB

Which is designed to make the semantics of the call identical, so that 
I don't have to rework the rest of my code to use the external version 
(and because I like it better this way too).

Thank You!

On Oct 13, 2004, at 1:04 PM, Frank D. Engel, Jr. wrote:

> What I just finished doing is creating a small function in Transcript 
> which acts as a wrapper for the C function.  The C function returns 
> the value to the local variable in the Transcript function, which 
> returns the value to the caller in the program.
>
> Thank you everyone, this is working much better now.  Excellent!
>
> On Oct 13, 2004, at 1:00 PM, Dar Scott wrote:
>
>>
>> On Oct 13, 2004, at 10:41 AM, Frank D. Engel, Jr. wrote:
>>
>>> That looks doable, but I would have preferred to have the value 
>>> returned by the function (as a return value).  I guess I will use 
>>> (the below) unless someone could tell me how to provide a binary 
>>> return value?
>>
>> Because of this limitation (and others, such as the 64K limit), I now 
>> make my externals provide helper functions for a library that has the 
>> interface I want.  Since externals are associated with a stack, this 
>> works OK.
>>
>> I have proposed a couple backward compatible binary interfaces for 
>> external interface inhancement, but I don't expect anything to happen 
>> along this line.  (On the other hand, I have been Rip Van Winkle for 
>> a couple months, so what do I know?)
>>
>> Dar
>>
>> ****************************************
>>     Dar Scott Consulting
>>     http://www.swcp.com/dsc/
>>     Programming Services
>> ****************************************
>>
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>>
> -----------------------------------------------------------
> Frank D. Engel, Jr.  <fde101 at fjrhome.net>
>
> $ ln -s /usr/share/kjvbible /usr/manual
> $ true | cat /usr/manual | grep "John 3:16"
> John 3:16 For God so loved the world, that he gave his only begotten 
> Son, that whosoever believeth in him should not perish, but have 
> everlasting life.
> $
>
>
>
> ___________________________________________________________
> $0 Web Hosting with up to 120MB web space, 1000 MB Transfer
> 10 Personalized POP and Web E-mail Accounts, and much more.
> Signup at www.doteasy.com
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
-----------------------------------------------------------
Frank D. Engel, Jr.  <fde101 at fjrhome.net>

$ ln -s /usr/share/kjvbible /usr/manual
$ true | cat /usr/manual | grep "John 3:16"
John 3:16 For God so loved the world, that he gave his only begotten 
Son, that whosoever believeth in him should not perish, but have 
everlasting life.
$


More information about the use-livecode mailing list