From: David P. <dpi...@me...> - 2008-05-15 22:32:13
|
> I havn't much time atm and havn't looked at the patch, but I'll apply it > shortly and see what it does. Having read the comments in #1818642, do > you think it would make more sense to use a different language module > for the CF? It seems that the CF is quite limited in what it can do (and > broken IMHO, eg not supporting HandleRef). I'll be surprised if you > havn't had some stability issues using IntPtr instead of HandleRef as > HandleRef was specifically designed to overcome the problems with > IntPtr, problems which I have seen myself. So, I'm not keen on seeing > the re-emergence of IntPtr as it has known problems. With regard to > Unicode string handling, I'm not really sure what works and what > doesn't, but would like platform independence as the default and would > like to see some more testcases for unicode handling, then I can test it > for you on Linux if you don't have access. Maybe we can add in some > platform specific typemap libraries which can be applied if needed? > Anyway, I'm sure we can sort something out, but apologise for slow > attention on this as I'm short on time and supporting proprietary > platforms is low in priority for me. There are only 130 pdd bug reports > to deal with on SF! You can certainly help me by sending patches with > comprehensive documented test cases which run in the test-suite. > > William Firstly, I should mention that the patch is incomplete; it doesn't 1. Update the string typemaps to use Unicode (and BSTRs) for all string passing 2. Update floating-point typemaps to pass by reference 3. Use IntPtr instead of HandleRef. 4. Use a thread-local storage slot instead of a [ThreadStatic] field for SWIGPendingException.pendingException. In my project I have extra .i files that do these things for me (Except for #4. I don't bother with thread-local storage because my app is single-threaded.) I don't think a separate language module is warranted, as the necessary changes are mostly typemap changes. Compact Framework's P/Invoke can do most of what the desktop framework can do, notable exceptions include: - It can't pass single-byte strings - It can't pass floating-point by value - It can't pass or return structures by value - It doesn't have HandleRef On the other hand, it can do some "advanced" stuff, e.g. you can pass a C# delegate to C++ (apparently with an undocumented limitation here and there, which I hit once so far), so the exception system still works and directors could work theoretically. And you can marshal structures by reference. It's worth noting that whatever works in Compact Framework also works in Desktop Framework. In my project I have desktop and mobile versions of the same software, based on the same source code. I use the same SWIG output for both my WinCE and WinXP versions. However, SWIG users other than me probably wouldn't want to use the WinCE mode for WinXP code because e.g. passing floating-point by reference would look silly to desktop coders :) I think SWIG's various .i files should just have some #ifdef UNDER_CE blocks to cover the differences between .NET and .NETCF; then one just needs to invoke SWIG with the argument -DUNDER_CE to use Compact Framework mode. To use IntPtrs safely requires numerous calls to GC.KeepAlive(); this is the only change that would require help from the language module. One would think that using IntPtr would cause instability, and I'm sure it does if circumstances are right--at least on the desktop (it is possible that the problem doesn't occur in the Compact Framework because the garbage collector works differently). However, in my particular codebase I haven't had a crash I could attribute to my use of IntPtr, either on WinCE or WinXP. Perhaps this is because my code is single-threaded and finalizers are not invoked often. You'd like me to make some test cases, eh? Hmm. I know nothing about how test suite works. How do I run it. The test suite is in the "Examples" folder right? Oh, and no, I don't have Linux. I would like your help to test it with Mono on Linux. |