[MLton] Temporary directories on MinGW / mlnlffigen

Matthew Fluet fluet at tti-c.org
Tue Apr 24 12:08:33 PDT 2007


>> Hmm... I just noticed the GetTempPath function:
>>
>>   http://msdn2.microsoft.com/en-us/library/aa364992.aspx
> [...]
> 
> Below is a patch (excluding generated files) using GetTempPath.  It
> introduces a new MinGW specific function MinGW_getTempPath that
> returns the result of GetTempPath as a freshly malloced C string.
> The C string is freed on the ML side after converting it to a ML
> string.  I wonder whether there is some other technique used in
> MLton for such functions.

Rather than malloc on the C side, we would normally split this into two 
functions.  One imported C function would return the desired length. 
Then, in ML, we would allocate a char array of the desired size.  Then, 
a second imported C function would fill in the char array.  Finally, in 
ML, we would extract a string from the char array.  Garbage collection 
would then take care of recovering the char array.

Without too much chance of failure, one could probably also 
conservatively just pass over a 1024 element array, assuming that that 
has enough space.  Looking at the documentation, if that fails, we would 
get back a number > 1024, which would tell us how big an array to try.

In any case, I would avoid _import "free" and calling free from the ML side.





More information about the MLton mailing list