From: Keith M. <kei...@to...> - 2005-10-10 14:03:58
|
Michael Gerdau wrote, quoting me: > [fixing M$'s broken exec() implementation by a POSIXish wrapper] > >> Do you really think it a bad idea to do this? After all, if a >> programmer *really* wants the definitively different behaviour of >> Windoze exec(), IMO he should ideally be using _exec() anyway, or >> perhaps better still CreateProcess(), so that the distinction is >> made obvious, in the source code. > > While I'm one of those that have suffered from this behavior and > found out the hard way I don't think it is a good idea to make > POSIXish behavior the default. And, it was never my suggestion that it should be made so :-) > That would doubtlessly lead to many support requests along the > line "my program behaves differently when I compile it with MSVC > or MinGW". > > Since MinGW is not trying to provide POSIX in the first place I'd > suggest to leave the default (as broken as it may be) as is and > create another exec_posix() (or so) that behaves as suggested. This is essentially what my set of wrapper functions do. For each of the spawn() and exec() family functions, I create a wrapper function, e.g. spawnvp_wrapper() for _spawnvp(), with a prototype which exactly conforms to that of the wrapped function. For convenience, I declare these prototypes in winexec.h, where I also alias the *generic* name to the wrapper name, e.g. `#define spawnvp spawnvp_wrapper', and I also `#include <process.h>' at the top of winexec.h. Notice that this means that any program which simply includes process.h, rather that explicitly including winexec.h in its place, will continue to exhibit the default [broken] behaviour. Even when winexec.h *is* included in place of process.h, it is only the *generic* function names which are redirected through the wrappers; the default behaviour is still available by directly calling the function by its Microsoft specific name, e.g. _spawnvp(), with the leading underscore. Furthermore, any user who prefers to use the generic function names, but still have the wrappers available, while having default behaviour for the generic functions, is free to either `#undef' the aliases from winexec.h, or to modify winexec.h itself, so that they are never defined -- indeed, perhaps I should modify winexec.h, such that it does something like: #ifndef USE_EXEC_FUNCTION_WRAPPERS # define USE_EXEC_FUNCTION_WRAPPERS 1 #endif #if USE_EXEC_FUNCTION_WRAPPERS # define execv execv_wrapper : etc. #endif and similarly for USE_SPAWN_FUNCTION_WRAPPERS, then the user could disable the aliases, while still retaining *explicit* access to the prototyped wrapper functions, by: #define USE_EXEC_FUNCTION_WRAPPERS 0 #include "winexec.h" In any case, I'm not suggesting that these wrappers should be made default behaviour for MinGW. I'm offering them as a GPL option, for anyone who would like to use them; the fact that they are GPL does preclude integration as a MinGW default. Earnie Boyd wrote: > As far as I remember, the document you signed to give Copyright to > FSF leaves you with Copyright as well. You are free to redistribute > with a different license as Copyright owner if you desire. The > redistributed license would then be a fork of the FSF version. I'll need to check that. If this is indeed the case, then I *could* offer them as a public domain add-on option for MinGW users. (I'd need to think about that; I wouldn't be generally happy at the possibility of my code potentially lining someone else's pocket). But even if I were to make it available in this manner, it would probably still be best to view it as an optional add on feature, rather than integrating it as a MinGW default. Best regards, Keith. |