• Welcome to Theos PowerBasic Museum 2017.

The compiler advantage

Started by John Spikowski, August 11, 2013, 07:20:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

John

May be i was in a bad day, in my good days i did applaud you several times, and i smite you once.

The funny thing is, that most of those smiting are also those who never post contributions.

It would be nice, if instead of karma, we could use something similar to the code project, where people have to explain why they post a low or high rating for a contribution, that would be more fair for sure, but the current karma is the way it works on most forum.

My definition of a useful contribution, is something more like those found on the Code Project.

...

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

John Spikowski

Patrice,

I agree that Code Projects is a great site and well managed. Each topic is a project and it would be senseless to pollute the subject matter with anything other than related content.  José has opened his forum to a wide verity of topics with the intent of being a valuable resource to compliment his include files.

I also agree we shouldn't turn this forum into a social network and respect José's intent.

John

Theo Gottwald

#107
Its like this. "How you shout out - thats how it comes back to you".


We have soon elections in germany, and many friends tell me that if they post things critical about Mrs. Angela Merkel or her CDU Party on the "CDU Forums" or on her Facebook site, that its alltogether deleted.
Even in the forums of the bigger medie, newspapers cirtical voices are ging to be removed.

Reading some posts from John there is often bad speach on PB and people get the impression that he does not like PB possibly because of private reasons that are not our bussiness.
So think a moment. If you go to Party A Forum and say that you do not like Party A, you will be kicked.
I don't know what John will do if he get people into the Scriptbasic Forum who will constantly post about the shortcomings and bad sides of Scriptbasic. Will he provide them with lots of good karma?
If i would post here the mails from people who asked me remove "John", others would say "never post private mails".
And in this case i will not do it. But Jose is my withness he got these mails also.
They exist and thats why i ask people from time to time to read their "contributions" two times before promoting that they do not like PB and at the same time tell that they can not offer PB code because they do not know about PB.


John Spikowski

I already know I wouldn't be a good politician. I don't waste my time thinking I'm going to make everyone happy with everything I do and say. I don't have to worry about covering up lies and don't wear knee pads as my standard attire. If you don't like what I have to say, move on, I won't chase you.



Chris Holbrook

Funny how discussions get more interesting as they approach the outer limits of the host forum.

My suggestion for a long life. Noodles. And, "respect your hosts, read their mission statement".




John Spikowski

#110
I have fallen into the trap of folks seeing ScriptBasic as a console mode interpreter rather than an embeddable scripting API. (author's intent) I created a BaCon (BASIC to C translator) example showing some of the basic API interface calls to ScriptBasic from a host language. This could just as easily have been done in PowerBASIC as I have demonstrated in a previous post.

sbembed.bac

' BaCon embedding ScriptBasic example

PRAGMA OPTIONS -I/home/jrs/sb/source
PRAGMA LDFLAGS scriba pthread
PRAGMA INCLUDE scriba.h getopt.h

PROTO scriba_destroy scriba_DestroySbArgs

DECLARE pProgram TYPE pSbProgram
DECLARE ReturnData TYPE SbData
DECLARE ArgData TYPE pSbData
DECLARE bob TYPE pSbData

' Create ScriptBasic object and load script
pProgram = scriba_new(malloc, free)
ok = scriba_LoadConfiguration(pProgram, "/home/jrs/sb/sb22/bin/basic.conf")
ok = scriba_SetFileName(pProgram, "sbembed.sb")
ok = scriba_LoadSourceProgram(pProgram)
ok = scriba_Run(pProgram,"")

' Call SUB pass no arguments
t_sub_1 = scriba_LookupFunctionByName(pProgram, "main::t_sub_1")
ok = scriba_Call(pProgram, t_sub_1)
PRINT

' Retrieve SB global variable
vsn = scriba_LookupVariableByName(pProgram, "main::bob")
ok = scriba_GetVariable(pProgram, vsn, &bob)
PRINT "bob var type: ", bob[0].type
PRINT "bob var size: ", bob[0].size
PRINT "bob var value: ", bob[0].v.l
PRINT

' Call SUB pass SB global as an argument
t_sub_2 = scriba_LookupFunctionByName(pProgram, "main::t_sub_2")
ok = scriba_CallArg(pProgram, t_sub_2, "i", bob[0].v.l)
PRINT

' Call script FUNCTION passing arguments and returning a result
sb_long = 123
sb_real = .321
sb_str$ = "ScriptBasic"
t_func_3 = scriba_LookupFunctionByName(pProgram, "main::t_func_3")
ArgData = scriba_NewSbArgs(pProgram, "i r s", sb_long, sb_real, sb_str$)
ok = scriba_CallArgEx(pProgram, t_func_3, &ReturnData, 3, ArgData)
scriba_DestroySbArgs(pProgram, ArgData, 3)
PRINT "Arguments Passed: ", ReturnData.v.l

scriba_destroy(pProgram)


sbembed.sb

' Embed test script

bob = 99

SUB t_sub_1
  PRINT "SUB with no arguments passed.\n"
END SUB

SUB t_sub_2(this_bob)
  PRINT this_bob," bottles of beer on the wall.\n"
  this_bob -= 1
  PRINT "Take one down, pass it around, ",this_bob," bottles of beer on the wall.\n"
END SUB

FUNCTION t_func_3(longarg, realarg, strarg)
  PRINT longarg,"\n"
  PRINT FORMAT("%g",realarg),"\n"
  PRINT strarg,"\n"
  t_func_3 = 3
END FUNCTION


Results

jrs@laptop:~/BaCon/2302$ ./sbembed
SUB with no arguments passed.

bob var type: 2
bob var size: 0
bob var value: 99

99 bottles of beer on the wall.
Take one down, pass it around, 98 bottles of beer on the wall.

123
0.321
ScriptBasic
Arguments Passed: 3
jrs@laptop:~/BaCon/2302$

Charles mentioned in this thread about scripting languages needing a variant type variable storage system. I think ScriptBasic's SbData structure emulates that well. (memory manager was designed to be thread safe)


typedef struct _SbData {
  unsigned char type;
  unsigned long size;
  union {
    double d;
    long   l;
    unsigned char *s;
    } v;
  } SbData, *pSbData;

// ScriptBasic data TYPE

#define SBT_UNDEF  0
#define SBT_DOUBLE 1
#define SBT_LONG   2
#define SBT_STRING 3
#define SBT_ZCHAR  4

John Spikowski

I'm trying to convert the example above to PBCC 5 and having a problem getting by this function. (missing argument) The function allows a variable number of arguments after the argument definition string. How do I declare this in PB?


ArgData = scriba_NewSbArgs(pProgram, "i r s", sb_long, sb_real, sb_str$)



John Spikowski

Should I assume that the reason for a no response to this issue is PowerBASIC is unable to handle functions with a variable number of arguments? This ability is also required if PowerBASIC is to interface with IUP.

I hope that the reason no one replied is due to my karma rating and I'm not worth a response rather than a fatal flaw with PB.



José Roca

You haven't said how many parameters do you need. If limited, add as many OPTIONAL BYREF AS ANY as you need, up to a maximum of 32 total parameters; if unlimited, it can't be done.

BTW I don't see any need to interface PB with IUP.

James C. Fuller

Quote from: José Roca on August 28, 2013, 06:23:54 PM
BTW I don't see any need to interface PB with IUP.

Me either.
Been there done that just on a whim.

James

John Spikowski

#115
scriba_NewSbArgs is how SB sets up its embedded arguments to call a script function. I need to declare it once and be able to pass a variable number of various type arguments depending on what the requirements of the script function. These aren't optional arguments they are based on the function argument definition string. This isn't uncommon and used in many C libraries. (Variadic Function)

QuoteBTW I don't see any need to interface PB with IUP.

What cross platform GUI tool kit do you recommend?  You would have to be a fool to develop any new GUI apps that uses a proprietary single platform solution. (like DDT) It's a new day and people aren't blindly trusting companies that think they own the market and set the standards.

José Roca

Quote
scriba_NewSbArgs is how SB sets up its embedded arguments to call a script function. I need to declare it once and be able to pass a variable number of various type arguments depending on what the requirements of the script function. These aren't optional arguments they are based on the function argument definition string. This isn't uncommon and used in many C libraries. (Variadic Function)

And a source of endless security holes. M$ no longer uses it, now that it is concerned about security.

Quote
What cross platform GUI tool kit do you recommend?  You would have to be a fool to develop any new GUI apps that uses a proprietary single platform solution. (like DDT) It's a new day and people aren't blindly trusting companies that think they own the market and set the standards.

None. Since PB only works with Windows, use the Windows SDK. If you want cross platform, use something else.

But you already know that, so why don't you stop posting malicious questions? I'm getting tired or your behavior.



John Spikowski

#117
QuoteAnd a source of endless security holes. M$ no longer uses it, now that it is concerned about security.

Thanks! I'll e-mail the author of IUP and tell him that his IUP 3.8 release is flawed and using variable number of argument functions doesn't work in Windows and therefore all the Windows libraries that seem to compile successfully won't work. (even though I haven't notice this with my use of the IUP libraries in SB)

How would adding arguments to a function call that the function ignores be a security risk? I would think it would be easier to find a DIM directive in PB and change it to a REDIM and use the extra buffers space to inject my code and GOTO (jump) to it.

If this forum is based on solutions that don't work with the tools I use, I'm wasting my time here.

Thanks for the reply and I'll take PowerBASIC off the compatibility list of ANSI C supported high level languages.

My take from your comment is if you use anything other than Windows and PB, you are running software with by design security holes.

I hear there is an opening as the leader of Zale's Zombies and you have been selected to be one of the final candidates.

Feel free to remove my account.


José Roca

You don't even read the links you post, do you?

Quote
Variadic functions can expose type-safety problems in some languages. For instance, C's printf, if used incautiously, can give rise to a class of security holes known as format string attacks. The attack is possible because the language support for variadic functions is not type-safe; it permits the function to attempt to pop more arguments off the stack than were placed there—corrupting the stack and leading to unexpected behavior.

> If this forum is based on solutions that don't work with the tools I use, I'm wasting my time here.

And ours too.

> My take from your comment is if you use anything other than Windows and PB, you are running software with by design security holes.

No, if you use safe code, but Variadic functions are unsafe.

> Feel free to remove my account.

Bye.

Charles Pegge

#119
All things are possible with a little assembly code hacking.

What you need to do is declare scribaNewSbArgs as a function without arguments.

To make the call:

First record the stack pointer value.

Push the args onto the stack in reverse order.

Call the function

Store the returned value

Restore the prior stack pointer value.


You will also need to build some logic around this to interpret the string for formatting args (long, double, string or charbyte). So it is quite a lot of baggage if you require a generic system for handling this type of call. Using variants with a wrapper function is a possibility.

With Assembler, nothing is type-safe :)