remobjects / pascalscript

pascalscript
Other
447 stars 178 forks source link

Problems with events on Linux 64 bit with FPC #251

Closed BranDougherty closed 3 years ago

BranDougherty commented 3 years ago

When events are called from FPC on Linux 64 bit, the arguments are passed according to the System V x86-64 ABI. However MyAllMethodsHandler seems to only implement the Windows x64 calling convention. So the arguments are passed all wrong.

What are my options for working around this? Is there a way to call PascalScript procedures assigned via RegisterEventPropertyHelper without passing through MyAllMethodsHandler, perhaps instead via RunProc? Otherwise is the only option to implement an understanding of the System V x86-64 ABI in MyAllMethodsHandler?

pult commented 3 years ago

You can try other alternative forks: Vizit0r: https://github.com/Vizit0r/pascalscript/ pult: https://github.com/pult/pascalscript/

carlokok commented 3 years ago

Might it make sense to merge them together? We've always been open to a few good PRS to get the important things merged in main.

pult commented 3 years ago

I once tried but failed. I suggested(gave) my changes in too big blocks and you refused me ( and you were right :) ). At the moment there are too many changes and too little time :(

BranDougherty commented 3 years ago

Thank you both for your quick replies. I had already tried both of those forks to no avail (possible I'm missing some relevant {$DEFINE}, so I can double check). My understanding is that neither of those forks attempt to solve my specific problem with calling from FPC on Linux x64 to PascalScript. Previously I started down the path of implementing the System V ABI, but it seems like too much work for me. Getting simple ints/pointers and floats passed or returned in registers isn't that bad but at some point I would have to think seriously about alignment and storage class of structures, and I don't trust myself to write that code and check it in here.

In the last hour I just made the definition of TScriptMethodInfo public, and accessed the ProcNo from the Data pointer on the event. Then I was able to run the procedure just fine with TPSExec.RunProcP. This way I don't have to go through MyAllMethodsHandler. Its an ugly hack but it will work for my use case.

Edit: I'll leave this open in case anyone has something to add here, or a nicer way to do this. But otherwise I'll close this in a day or two.