Re: [polyml] CInterface.setFinal pointer mismatch
Phil, Thanks for providing a compact example. I ran the test and found out what was happening. Essentially, if two pointers contained the same value but the finaliser was associated with the later entry in the vol table it was possible that the internal memory used to hold the pointer value could have been freed before the finaliser was called. The value used in the finaliser would then be the contents of the freed memory which may well be nonsense. I've fixed this so that finalisers are called before any internal memory is freed. Your example seems to work now at least on X86/32. Regards, David On 13/11/2011 13:41, Phil Clayton wrote: I am using setFinal to free a string (char *) whose pointer is returned via a parameter (char **) with address/deref to construct/destruct the char ** parameter. Unfortunately, I cannot get this to work. It seems that a function registered with setFinal is not always passed the C pointer (of the vol) that it was registered with, in particular, when the vol supplied to setFinal is derived from address/deref. E.g. setFinal mycfun (deref (address v)) does not call mycfun with the same C pointer as for setFinal mycfun v This seems like an issue to me but perhaps I have misunderstood something. ___ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
Re: [polyml] CInterface.setFinal pointer mismatch
David, Thanks - I have checked the example on x86_64 and can confirm that it works there too. Phil On 18/11/11 11:48, David Matthews wrote: Phil, Thanks for providing a compact example. I ran the test and found out what was happening. Essentially, if two pointers contained the same value but the finaliser was associated with the later entry in the vol table it was possible that the internal memory used to hold the pointer value could have been freed before the finaliser was called. The value used in the finaliser would then be the contents of the freed memory which may well be nonsense. I've fixed this so that finalisers are called before any internal memory is freed. Your example seems to work now at least on X86/32. Regards, David On 13/11/2011 13:41, Phil Clayton wrote: I am using setFinal to free a string (char *) whose pointer is returned via a parameter (char **) with address/deref to construct/destruct the char ** parameter. Unfortunately, I cannot get this to work. It seems that a function registered with setFinal is not always passed the C pointer (of the vol) that it was registered with, in particular, when the vol supplied to setFinal is derived from address/deref. E.g. setFinal mycfun (deref (address v)) does not call mycfun with the same C pointer as for setFinal mycfun v This seems like an issue to me but perhaps I have misunderstood something. ___ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml ___ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
[polyml] CInterface.setFinal pointer mismatch
I am using setFinal to free a string (char *) whose pointer is returned via a parameter (char **) with address/deref to construct/destruct the char ** parameter. Unfortunately, I cannot get this to work. It seems that a function registered with setFinal is not always passed the C pointer (of the vol) that it was registered with, in particular, when the vol supplied to setFinal is derived from address/deref. E.g. setFinal mycfun (deref (address v)) does not call mycfun with the same C pointer as for setFinal mycfun v This seems like an issue to me but perhaps I have misunderstood something. The attached example in eg1.tar.gz demonstrates this. After unpacking, cd eg1/ make bin # build eg1.so LD_LIBRARY_PATH=.: poly eg1.sml # change glibc name if req. See eg1.sml for details. I have tried Poly/ML versions as follows: 5.4 x86_64 5.4.1 x86_64 5.4 i386 r1352 i386 and all have this pointer mismatch. (With i386, the pointer passed to the C function is null whereas it is some nearby pointer with x86_64.) Phil eg1.tar.gz Description: GNU Zip compressed data ___ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml