PureBasic vs. PowerBasic (Bob's Opinion)

Started by Bob Houle, February 16, 2016, 04:41:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bob Houle

Look... you said you thought you had found some buggy code and I said:
"Post it on the forum"

You then asked for a way to create a Main() program like PowerBASIC,
and I provided an answer.
--------------
QuoteDon't turn my words around, Bob.


Where is this coming from?  ???

It's obvious you don't like PureBasic. Or PBDev.

That's O.K.

Just move on.  :)

If you like things as they are with PowerBASIC... that's fine.

Just move on.  :)

But please stop bashing something you "think" you know (but don't)
  •  

Theo Gottwald

Sometimes i believe i have violett glases on, or the other person has green.
But thats the world.

You then asked for a way to create a Main() program like PowerBASIC,

Can you show me where i asked that?
So i can find out who has the glases on :-)

I have clearly stated where i see the shortcomings.
Point - by point.

That does not mean i don't like PureBasic. Thats just your opinion.
Why is it not OK, to clearly tell the shortcomings of a computer-program?

There should not be any reason to take thios personal.
As i see it, there is a difference between somebody writing

QuoteXY is just bad

and somebody writing

QuoteXY missing some features that i am used to, and the person working on XY doesn't like to add these features

Where do you see the "bashing"?
So please stop insulting my clear criticism of openly visible facts as bashing.

I will still use PureBasic and also closely watch its developement.


Bob Houle

QuoteCan you show me where i asked that?
So i can find out who has the glases on :-)


Here...
Quote from: Theo Gottwald on March 05, 2016, 07:07:49 PM

PS:Do you know a trick how i can make PureBasic to compile a "Main File" like it can be set in the PowerBasic IDE?


  •  

Patrice Terrier

He he.

This is like when Theo, spoke of Windows 10, compared to Windows 2000  ;D

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

Theo Gottwald

#19
Hahaha ... i guess we run from Missunderstanding to missunderstanding.
Have to say that the PureBasic IDE is very good even compared to any PowerBasic IDE.
(Other the Firefly or Phoenix because of the VD :-).

There is just one thing that i did not yet find out - but i think its in there.
In PureBasic I must currently first switch to the "main file" before i can press "Compile".
I believe this is my mistake - that was my question about "Main File".

You know i don't like Win 10 at all Patrice :-).

But i never said that i would not like PureBasic.

What do you think, do i  have "glasses on"?

It was in the year 2000 when i bought myself this so called C-Meter i guess it was about $400 or more.
In fact its some sort of "Lie detector".

It was the time when my last gf left me. When i got it, she was already gone.
Since then i had it in my cupboard.

This week i took it out and realized that it needs a "COM-Port" which no modern PC has.
And the Software was on a "Disk". But my Computer has no Disk drive.

Ok, so i got an RS232 to USB Adapter and also an old computer with Disc-Drive.
And funny enough - the thing still works. Even under Win 10.

And from what it shows, i would say that i speak the truth.

David Roberts

#20
I've had PureBasic for quite a while but I did not take to it. After reading through this thread I decided to have another go. There have been quite a few updates since my last look and was surprised to see a SHA3 plugin. What I embarked on stretched me no end but I got there in the end. Purists will no doubt frown at what I'm doing here but I am not a purist.

PureBasic dll saved to SHA3Hash.dll

UseSHA3Fingerprint()

ProcedureDLL.s SHA3_256( text$ )

  *Buffer = AllocateMemory( Len( text$ ) )
  If *Buffer
    PokeS(*Buffer, text$, -1, #PB_Ascii)
    SHA3$ = Fingerprint(*Buffer, MemoryStringLength(*Buffer, #PB_Ascii), #PB_Cipher_SHA3, 256)
    FreeMemory(*Buffer)
    ProcedureReturn SHA3$
  EndIf

EndProcedure

ProcedureDLL.s SHA3_512( text$ )

  *Buffer = AllocateMemory( Len( text$ ) )
  If *Buffer
    PokeS(*Buffer, text$, -1, #PB_Ascii)
    SHA3$ = Fingerprint(*Buffer, MemoryStringLength(*Buffer, #PB_Ascii), #PB_Cipher_SHA3, 512)
    FreeMemory(*Buffer)
    ProcedureReturn SHA3$
  EndIf

EndProcedure


PureBasic test

If OpenLibrary(0, "SHA3Hash.dll")
  Test$ = "Houses Of Parliament"
  MessageRequester("SHA3_256", PeekS(CallFunction(0, "SHA3_256", @Test$) ))
  MessageRequester("SHA3_512", PeekS(CallFunction(0, "SHA3_512", @Test$) ))
EndIf


PowerBASIC

#Compile Exe
#Dim All

Declare Function SHA3_256 Lib "SHA3Hash.dll" ( ByVal strText As WString ) As WString
Declare Function SHA3_512 Lib "SHA3Hash.dll" ( ByVal strText As WString ) As WString

Function PBMain
Local sText As WString

  sText = "Houses Of Parliament"
  MsgBox SHA3_256( sText )
  MsgBox SHA3_512( sText )

End Function


The PureBasic test and the PowerBASIC exe gave the same results. Just to be sure all was well I went to https://emn178.github.io/online-tools/ and got a confirmation on both SHA3-256 and SHA3-512.

So, PowerBASIC now has SHA3 without getting my hands dirty building a SHA3 engine.

Having got that working the next step will be a PureBasic library to create a hash, hash one or more blocks in and then finalize the hash. PureBASIC has the procedures to do that.

I then wrote a simple PowerBASIC dll with a view to using it in PureBasic. However, I am getting an 'Invalid memory access. (read error at address 0).

Would you look at it, Bob?

If I can get it to work there are a few other procedures that could be added to PB_String_Crunches.dll to give PureBasic a bit more 'oomph' in the string department.

PowerBASIC

#Compile DLL "PB_String_Crunches.dll"
#Dim All

Function PB_Remove_Any( ByVal MainString As String, ByVal MatchString As String ) Export As String

  Function = Remove$( MainString, Any MatchString )

End Function


PureBasic

Prototype.s ProtoPB_Remove_Any( param1$, param2$ )
If OpenLibrary( 0, "PB_String_Crunches.dll" )
  PB_Remove_Any.ProtoPB_Remove_Any = GetFunction( 0, "PB_Remove_Any" )
  s1$ = "Lo38ok2 Ma, n6o nu1mbe78rs!"
  s2$ = "0123456789"
  s3$ = PB_Remove_Any( s1$, s2$ )
  CloseLibrary(0)
EndIf



  •  

David Roberts

'Dependency Walker' says I should have used PB_REMOVE_ANY but I'm still getting a memory access violation.
  •  

David Roberts

OK, I managed PowerBASIC to PureBasic

I have managed it.

PowerBASIC code

#Compile DLL "PB_String_Crunches.dll"
#Dim All

Function RemoveAny( ByVal MainString As String, ByVal MatchString As String ) Export As WString
Local sText As WString

  sText = Remove$( MainString, Any MatchString )
  Function = sText

End Function


PureBasic code

Prototype.l ProtoRemoveAny( param1.p-bstr, param2.p-bstr )
If OpenLibrary( 0, "PB_String_Crunches.dll" )
  RemoveAny.ProtoRemoveAny = GetFunction( 0, "REMOVEANY" )
  s1$ = "Lo38ok2 Ma, n6o nu1mbe78rs!"
  s2$ = "0123456789"
  MessageRequester("", PeekS(RemoveAny( s1$, s2$ ) ))
  CloseLibrary(0)
EndIf


Resulting in: "Look Ma, no numbers!"


  •  

José Roca

> PeekS(RemoveAny( s1$, s2$ )

I smell memory leaks. When are the temporary BSTRings freed?
  •  

David Roberts

#24
I certainly cannot answer that.
  •  

José Roca

> There are no BSTRings in PeekS(RemoveAny( s1$, s2$ )

Yes, there are. THREE!

> RemoveAny( s1$, s2$ ) is a pointer to the PowerBASIC's Wstring export and PeekS simply reads it.

...and does not free it.
  •  

David Roberts

I gave it further thought and edited my last post before your last post.  :)

The PowerBASIC export is unicode to unicode so we only have two string format conversions; the parameters.

The ideal time to free up the bstr's is on receipt of the export as they are no longer needed then but how PureBasic does that I have no idea.

  •  

José Roca

In the code that you have posted it is not freed.

Rules for allocating and releasing memory allocated for BSTRs.

- When you call into a function that expects a BSTR argument, you must allocate the memory for the BSTR before the call and release it afterwards.

- When you call into a function that returns a BSTR, you must free the string yourself.

- When you implement a function that returns a BSTR, allocate the string but do not free it. The receiving the function releases the memory.

See: https://msdn.microsoft.com/en-us/library/xda6xzx7.aspx
  •  

José Roca

Don't know what kind of code will generate that compiler, but I don't think that PeekS will release the BSTR. If I were you, I would ask it in the Pure Basic forum.
  •  

David Roberts

QuoteIn the code that you have posted it is not freed.

It certainly isn't freed by me. I have no idea what PureBasic does but I should imagine that rule #1 applies.

I got the tip on 'p-bstr' from the PureBasic forums and I have seen the main coder, Fred as Theo refers to him, recommend it. It was my idea to use 'Export As WString'

QuoteI don't think that PeekS will release the BSTR

No, that is simply a reading function.

It seems to me that RemoveAny( s1$, s2$ ) by virtue of being prototyped is probably 'bracketed' by a conversion to bstr before and then a freeing up after as opposed to no 'bracketing' with no prototyping; but I am only guessing.
  •