When you look in the Tailbite code, fred known this problem, because the +4-fix is mention by him. Why he doesn't fix it in the /commented - output?
When you look in the Readme.txt
When you want to return a string, you should use this function:
1) The function doesn't has string parameter
It's the easiest one, and you can use the SYS_GetOutputBuffer() funtion:.
char *Output = SYS_GetOutputBuffer(int Length, int PreviousPosition)
With this command you ask PureBasic to returns a string buffer of 'Length' (in characters, which means
than it's the same value in unicode or not) and store the pointer value in 'Output'. 'PreviousPosition' is a
value passed in the string function.
ex: Output = SYS_GetOutputBuffer(100, PreviousPosition);
Once you get this buffer, just write the string result in it and you're done.
Note: 'Length' should be the exact returned string length. It doesn't count the null terminating character
And only this function.
When you look in the ASM-Code, you find this
"CALL _SYS_FreeString@4"
That is not this function. It is a complete diffrent methode of returning a string. Thats why the trouble are here. Purebasic handles Userlibraries in a complete diffrent Method. You can test it.
Try it, userlib
Code: Select all
ProcedureDLL.s Dummy()
Protected Buffer.s = "bug"
ProcedureReturn Buffer
EndProcedure
mainprogram:
and
mainprogram2:
Code: Select all
ProcedureDLL.s Dummy2()
Protected Buffer.s = "bug"
ProcedureReturn Buffer
EndProcedure
c$= "no " + Dummy2()
debug c$
Now look at the assembler-Code of Mainprogram1 and mainprogram2
You will find diffrences, how Dummy() and Dummy2() are called. You don't need to understand Assembler to see, that there are differences! Why? Both procedures are identical (you can compare this part in Assembler too).
THAT is the Problem.
And sorry, do you understand why "RET+4" solve this problem? Did you understand *WHEN* it should added? Only on Strings? On Arrays? Or on every Routine? When?!!
Do you know what "RET+4" does? What is with 64Bit? Must you add here "RET+8" or you should leave it with "RET" and Why?
Sorry, only add a "RET+4" without knowing is really dangerous! Do you know what a stack is? What it is stored there? Why a corrupt stack is a really big problem? Did you know what "PUSH" does?
Did you understand, why when "RET+4" is added always by PBCompiler, it would create a DLL, which corrupt the stack and this dll will crash the calling programm? And in this case, we had here many Bug-Reports with DLLs!
The Big Problem is, that you don't understand what the ASM code does, you don't understand why this work and why this doesn't. Your answer is here "it work" - that is not enough.
The next step is: LEARNING ASSEMBLER! Than you can't answer my question without. Otherwise it is a Try-And-Error-Program without knowing when the error will happen. Otherwise you play "Russian roulette" with your stack and it will crash your Program. Not always of course.But it will crash on complete diffrent places in the code, it is difficult to find this kind of error.
What you here have is a big problem with Programming. The difference between an working code and understanding why it work. When you understand this, you can write a code, wich always work. Without you write a code which seems to work, but you can't guarantee it. It may work in 99%, but in the other 1% you will search for an eternity.