Author Topic: SBT  (Read 35400 times)

0 Members and 2 Guests are viewing this topic.

JRS

  • Guest
Re: SBT
« Reply #45 on: April 29, 2015, 12:47:43 PM »
Hi Charles,

I think I have some progress to report.  8)

It seems my seg fault issue is returning back to the hosting SB. On a positive note it's getting through the scriba_CallArgEx without error. (passing long/double only)
« Last Edit: April 29, 2015, 04:25:00 PM by John »

JRS

  • Guest
Re: SBT
« Reply #46 on: April 29, 2015, 09:38:09 PM »
I got it working mostly but as you remember assigning  C strings to ArgData was a trick you mastered. I have the return value working but it's currently hard coded to allow LONG values only.

That is my two remaining issues I could use your help with.

(See All BASIC for details)
« Last Edit: April 30, 2015, 12:09:13 AM by John »

Charles Pegge

  • Guest
Re: SBT
« Reply #47 on: April 30, 2015, 06:17:40 AM »
Hi John,

you just need to switch instead of select, and remember to break at the end of each case.

Otherwise, you know more about this stuff than I do :)

JRS

  • Guest
Re: SBT
« Reply #48 on: April 30, 2015, 08:04:12 AM »
Not sure how to respond to that.  :-\

I worked with you on DLLC trying solve this issue of passing C string references to an ArgData array. All I'm asking is how did you end up resolving it?


Charles Pegge

  • Guest
Re: SBT
« Reply #49 on: April 30, 2015, 08:30:02 AM »
John, I don't have your test environment though I'm hoping to get tooled-up for C again fairly soon

Reading returned string data was never a problem. You should be able to see it as a regular char*, using printf

JRS

  • Guest
Re: SBT
« Reply #50 on: April 30, 2015, 09:05:04 AM »
I have no problems getting the passed argument string(s) from the SB host. My problem (seg faults) is assigning the passed C string to an ArgData array structure. (.v.s). I remember something about SB defaults to multi-threaded support mode which means that SB is using Peter Verhas's MyAlloc memory manager. Where I left off with you on this was showing you how the scriba_CallArg() function had no problems passing C strings. The next thing I remember is you resolved your issue and DLLC was born.

Quote
I don't have your test environment

This is core SB API and you should be able to (re)test this in O2, MinGW-TDM, or just about anything that can call a C library. (remember SB embedded code challenge?) In this round I'm using SB itself as the host. What better way to show how the Script BASIC API works than using SB itself?
« Last Edit: April 30, 2015, 09:14:06 AM by John »

Charles Pegge

  • Guest
Re: SBT
« Reply #51 on: April 30, 2015, 09:38:07 AM »
You won't be able to make an arg structure,insert a string pointer into it, and get away with it, whereas it is okay to do this with ints and doubles.

Have you tried inserting some string literals?:

Forcing values is a very useful diagnostic.

Code: [Select]
  args=scriba_NewSbArgs(pProgram,"s s s s",s[0],"one","two","three","four")
  count=4
  iError=scriba_CallArgEx(pProgram, sbfun, @ReturnData, count, args)

JRS

  • Guest
Re: SBT
« Reply #52 on: April 30, 2015, 09:59:00 AM »
My issue is dynamically (at runtime) assigning one of the eight reserved ArgData structures ([zero] through [seven]) with either a LONG, DOUBLE (real), STRING/ZSTR or SB Array definition. I tried to use  scriba_NewSbArgs to created a single ArgData array string  element and assign it to my predefined ArgData array but it didn't work for me. (pSbData vs. SbData mismatch)

Charles Pegge

  • Guest
Re: SBT
« Reply #53 on: April 30, 2015, 10:11:57 AM »
scriba_NewSbArgs creates the Arg block, and returns the Args pointer to you for direct use. There must be some extra invisible pointers, or positional sensitivity, which make any copies of the Arg block invalid.

JRS

  • Guest
Re: SBT
« Reply #54 on: April 30, 2015, 10:26:54 AM »
How did you get around this issue in DLLC?

Charles Pegge

  • Guest
Re: SBT
« Reply #55 on: April 30, 2015, 10:49:13 AM »

I've just checked: DLLC only supports integer arguments for its  SBcallback relays.

Code: OxygenBasic
  1.   function SbCallBackRelay(...) as sys,external
  2.   =============================================
  3.   indexbase 1
  4.   sys          i,n,v,er
  5.   v=pdata[2] 'eax/rax register.
  6.  SbCallBackInfo c at (@sbcb[v])
  7.   sbData ReturnData
  8.   sbData ArgData at (c.idat+v*8*sizeof SbData)
  9.   n=c.nParams
  10.   for i=1 to n 'max 8
  11.    ArgData[i].typ =SBT_LONG
  12.     ArgData[i].lng =param[i]
  13.   next
  14.   if c.proc
  15.     er=call c.ArgEx  c.pProgram, c.Proc, @ReturnData, n, @ArgData
  16.     return ArgData.lng
  17.   else
  18.     return c.Return
  19.   end if
  20.   end function
  21.  

JRS

  • Guest
Re: SBT
« Reply #56 on: April 30, 2015, 11:12:37 AM »
Quote
I've just checked: DLLC only supports integer arguments for its  SBcallback relays.

So you're not a wizard after all.  ;)

There has to be a way ... SB does it fine as long as it's part of the loaded script.  ::)

I think the answer is hidden within scriba_NewSbArgs and how strings are assigned to ArgData structues.
« Last Edit: April 30, 2015, 11:57:40 AM by John »

Charles Pegge

  • Guest
Re: SBT
« Reply #57 on: April 30, 2015, 11:56:56 AM »
No, I'm a Vulcan, like Spock.

It looks like a design flaw. ArgData blocks not completely inedependent

JRS

  • Guest
Re: SBT
« Reply #58 on: April 30, 2015, 11:59:15 AM »
Quote
No, I'm a Vulcan, like Spock.

That explains it. No obvious logic to this.  :-*

Please look at this previous post by me in this thread.
« Last Edit: April 30, 2015, 12:06:38 PM by John »

JRS

  • Guest
Re: SBT
« Reply #59 on: April 30, 2015, 02:22:04 PM »
It seems I was correct about assigning strings to ArgData structures.
scriba.c
Code: C
  1.       case 'S': /* string argument */
  2.       case 's':
  3.         p[i].type = SBT_STRING;
  4.         arg = va_arg(marker, char *);
  5.         if( arg == NULL )arg = "";
  6.         p[i].size = strlen(arg);
  7.         if( p[i].size ){
  8.           p[i].v.s = alloc_Alloc(p[i].size,pProgram->pMEM);
  9.           if( p[i].v.s == NULL ){
  10.             while( i ){
  11.               if( p[i].type == SBT_STRING && p[i].v.s )alloc_Free(p[i].v.s,pProgram->pMEM);
  12.               i--;
  13.               }
  14.             alloc_Free(p,pProgram->pMEM);
  15.             return NULL;
  16.             }
  17.           memcpy(p[i].v.s,arg,p[i].size);
  18.           }else{
  19.           p[i].v.s = NULL;
  20.           }
  21.         i++;
  22.         break;
  23.  

I'm wondering if scriba_NewSbString() is the proper way for the embedding API to create the SBT_STRING ArgData structure pointer.

« Last Edit: April 30, 2015, 03:31:12 PM by John »