blitz-research / monkey

Blitz Research Monkey Source
225 stars 59 forks source link

Dll creation support for Trans #58

Closed Pharmhaus-2 closed 10 years ago

Pharmhaus-2 commented 10 years ago

This patch allows transcc to create dlls using the C++ Tool target. It introduces the new keyword "dllfunction" which triggers Dll creation when used. dllfunctions are excluded from deadcode elimination and a new flag disguises them from functions. dllfunctions have raw names and are therefore not 'munged' this is necessary to satisfy plugin interfaces for third-party applications. when a dll function is used the corresponding file will be a *.dll instead of an exe. The GC_MODE automatically changes to Mode 2 when a dllfunction is used. There is one remaining quirk: dllfunctions are still exported to the glfw target even if it makes no sense and could break something. I simply don't know how to check for the corresponding target (very likely easy for you?).

You can find a small code + dll example here: http://pharmhaus-software.de/public-domain/Dll_example.zip

It would be nice if you could take a look.

Thank you.

blitz-research commented 10 years ago

Haven't had a close look at this, but I am concerned about memory management issues eg:

1) Exe calls Dll

2) Dll allocates and returns an object.

3) Exe stores a reference to returned object.

4) Dll performs GC, decides object is 'dead' and frees it.

5) Exe tries to use freed object and all hell breaks loose.

The problem is both the exe and the dll have their own memory management code that are unaware of each other, which makes passing objects between the exe and dll dangerous.

Pharmhaus-2 commented 9 years ago

Well, I found some other bugs so its not as ready as i though anyway. PureBasic enforces the usage of global variables and the Garbage Collector of the D Programming Language "Connects" to the GC of the Dll. It would be nice if you could provide any specific 'guidelines' so I can fix this.