[win32] Killing MSVC's _alloca
Trying to get around to my mingw32 port again. I currently don't have Visual C++ installed, but why is this nonstandard _alloca needed? Can't it simply be replaced by alloca? Doesn't MSVC have alloca? For the moment, I'm as far as building posixmodule.c, which I succeeded by doing a #define _alloca alloca If there's a way to kill MSVC peculiarities, could this please be done? -- Gerhard
Trying to get around to my mingw32 port again. I currently don't have Visual C++ installed, but why is this nonstandard _alloca needed? Can't it simply be replaced by alloca? Doesn't MSVC have alloca?
It seems that it does. But I guess _alloca is more politically correct, since alloca is not standard C.
For the moment, I'm as far as building posixmodule.c, which I succeeded by doing a
#define _alloca alloca
If there's a way to kill MSVC peculiarities, could this please be done?
I'd be happy to do a global subst of _alloca -> alloca. Mark, do you see any reason why this might *not* work? Could it break other compilers? A conservative approach would be to add #ifdef CYGWIN around the #define you propose. --Guido van Rossum (home page: http://www.python.org/~guido/)
* Guido van Rossum
Trying to get around to my mingw32 port again. I currently don't have Visual C++ installed, but why is this nonstandard _alloca needed? Can't it simply be replaced by alloca? Doesn't MSVC have alloca?
It seems that it does. But I guess _alloca is more politically correct, since alloca is not standard C.
I don't see how this applies, as neither form is standard C, but in practise, alloca is supported by all compilers I use, be it Windows or Linux. And I don't care about P. C. ;-)
For the moment, I'm as far as building posixmodule.c, which I succeeded by doing a
#define _alloca alloca
If there's a way to kill MSVC peculiarities, could this please be done?
I'd be happy to do a global subst of _alloca -> alloca.
Mark, do you see any reason why this might *not* work?
Could it break other compilers?
No, as it's only used in platform-specific code as seen below: $ find . -name *.[ch]|xargs grep -w _alloca ./Modules/posixmodule.c: s1 = (char *)_alloca(i); ./Modules/posixmodule.c: s2 = (char *)_alloca(x); ./Modules/posixmodule.c: s2 = (char *)_alloca(x); ./Python/pythonrun.c: /* _alloca throws a stack overflow exception if there's ./Python/pythonrun.c: _alloca(PYOS_STACK_MARGIN * sizeof(void*)); $ find . -name *.[ch]|xargs grep -w alloca ./Modules/mpzmodule.c:** alloca with arg < 0 (when casted to a signed ./PC/_winreg.c:#include "malloc.h" /* for alloca */ ./PC/_winreg.c: retBuf = (char *)alloca(len); ./PC/_winreg.c: retValueBuf = (char *)alloca(retValueSize); ./PC/_winreg.c: retDataBuf = (char *)alloca(retDataSize); ./PC/_winreg.c: retBuf = (char *)alloca(bufSize); ./PC/_winreg.c: retBuf = (char *)alloca(bufSize); ./PC/import_nt.c:#include "malloc.h" /* for alloca */ ./PC/import_nt.c: /* alloca == no free required, but memory only local to fn, ./PC/import_nt.c: moduleKey = alloca(bufSize); ./PC/os2vacpp/getpathp.c:#include "malloc.h" // for alloca - see comments below! ./PC/os2vacpp/getpathp.c: // alloca == no free required, but memory only local to fn. ./PC/os2vacpp/getpathp.c: keyBuf = alloca(sizeof(keyPrefix)-1 + versionLen + sizeof(keySuffix)); // chars only, plus 1 NULL. So, alloca and _alloca are only used in platform specific Windows and OS/2 code. The MSVC specific code is a little inconsistent, it uses both _alloca and alloca forms depending on the source file.
A conservative approach would be to add #ifdef CYGWIN around the #define you propose.
Not even more #ifdefs, please. I'd suggest the global replace _alloca -> alloca. -- Gerhard
Not even more #ifdefs, please. I'd suggest the global replace _alloca -> alloca.
Submit a patch. --Guido van Rossum (home page: http://www.python.org/~guido/)
Guido van Rossum
Doesn't MSVC have alloca?
It seems that it does.
Without checking: It probably has this only if __STDC__ is not defined. MSVC hides all non-standard symbols if __STDC__ is defined - either by compiler switches, or in some application header. In that sense, _alloca is the Microsoft name for this extension. They may have been misguided by using that scheme, though, since _alloca isn't any more reserved than alloca. However, all uses of _alloca in posixmodule.c are MS specific, so I really see no reason to change that. Regards, Martin
Martin v. Loewis wrote:
Guido van Rossum
writes: Doesn't MSVC have alloca?
It seems that it does.
Without checking: It probably has this only if __STDC__ is not defined. MSVC hides all non-standard symbols if __STDC__ is defined - either by compiler switches, or in some application header.
Hmm. I had this problem (no alloca, no idea why) and defined it by a macro in this case. Is it cleaner to undefine __STDC__ instead? -- Christian Tismer :^) mailto:tismer@tismer.com Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/
* Christian Tismer
Martin v. Loewis wrote:
Guido van Rossum
writes: Doesn't MSVC have alloca?
It seems that it does.
Without checking: It probably has this only if __STDC__ is not defined. MSVC hides all non-standard symbols if __STDC__ is defined - either by compiler switches, or in some application header.
Hmm. I had this problem (no alloca, no idea why) and defined it by a macro in this case.
I've now installed MSVC6SP4 and verified that with my patch Python still builds ok. Obviously, Python's compiler options for MSVC don't define __STDC__.
Is it cleaner to undefine __STDC__ instead?
It'd be cleaner to use either _alloca or alloca, but not both like the current M$VC specific code does. -- Gerhard
Christian Tismer
Hmm. I had this problem (no alloca, no idea why) and defined it by a macro in this case. Is it cleaner to undefine __STDC__ instead?
No. I would always go with the Microsoft name. If the code also needs to work on Unix, add a define for the functions you need. Regards, Martin
Trying to get around to my mingw32 port again. I currently don't have Visual C++ installed, but why is this nonstandard _alloca needed? Can't it simply be replaced by alloca? Doesn't MSVC have alloca?
It seems that it does. But I guess _alloca is more politically correct, since alloca is not standard C.
For the moment, I'm as far as building posixmodule.c, which I succeeded by doing a
#define _alloca alloca
If there's a way to kill MSVC peculiarities, could this please be done?
I'd be happy to do a global subst of _alloca -> alloca.
Mark, do you see any reason why this might *not* work?
None at all. Mark.
* Mark Hammond
[me: change _alloca to alloca] [Guido:] Mark, do you see any reason why this might *not* work?
None at all.
As per suggestion of Guido, I've submitted a patch. The patch, however, doesn't make any sense standalone, so it's part of #1 of many mingw related patches. These will ultimately make it possible to build Python on win32 using the autoconf/make toolchain. See http://python.org/sf/618791 I've assigned it to Guido for no good reason except being not sure if Mark knows about autoconf/makesetup, which my patch touches. But I'd also be glad if anybody else applies it ;-) -- Gerhard
As per suggestion of Guido, I've submitted a patch. The patch, however, doesn't make any sense standalone, so it's part of #1 of many mingw related patches.
So I should ignore the patch until you're done submitting those other patches?
These will ultimately make it possible to build Python on win32 using the autoconf/make toolchain.
I don't understand. How many Unix emulations on Windows do we need? We've already absorbed a sheer endless set of patches to make it work on CYGWIN. How does Mingw differ?
See http://python.org/sf/618791
I've assigned it to Guido for no good reason except being not sure if Mark knows about autoconf/makesetup, which my patch touches.
But I'd also be glad if anybody else applies it ;-)
Me too. I may reduce the priority. --Guido van Rossum (home page: http://www.python.org/~guido/)
* Guido van Rossum
As per suggestion of Guido, I've submitted a patch. The patch, however, doesn't make any sense standalone, so it's part of #1 of many mingw related patches.
So I should ignore the patch until you're done submitting those other patches?
No, this can go in now. That's the point of my plan to submit several isolated patches. I don't want to fork a Python tree, work several months on it, and then submit one gigantic patch, that will probably never be applied because there are problems reviewing it.
These will ultimately make it possible to build Python on win32 using the autoconf/make toolchain.
I don't understand. How many Unix emulations on Windows do we need?
mingw is _not_ a Unix emulation. It is the GNU Compiler suite targetting _native_ Windows. The point is to be able to build Python on Windows with the autoconf toolchain. And _without_ needing to buy Visual C++ just to do build Python or to do serious Python extension development on Windows.
We've already absorbed a sheer endless set of patches to make it work on CYGWIN. How does Mingw differ?
mingw produces native win32 executables. No emulation whatsoever.
See http://python.org/sf/618791
I've assigned it to Guido for no good reason except being not sure if Mark knows about autoconf/makesetup, which my patch touches.
But I'd also be glad if anybody else applies it ;-)
Me too. I may reduce the priority.
The reason for setting a higher priority was that I hoped this could be applied rather sooner than later, as I hoped this wasn't a controversial patch. -- Gerhard
[Guido]
We've already absorbed a sheer endless set of patches to make it work on CYGWIN.
[Jason Tishler]
Ouch! :,)
Nevertheless, the Cygwin community appreciates the continued support.
The Python community appreciates your support too, Jason! Guido wasn't being pejorative there, just objectively accurate: "sheer endless" is Dutch for "about 12" <wink>.
[Guido]
I'd be happy to do a global subst of _alloca -> alloca.
Mark, do you see any reason why this might *not* work?
[Mark]
None at all.
In the interest of universal harmony, I've done this and will check it in soon (when the tests complete). no-point-arguing-over-non-issues-ly y'rs - tim
participants (8)
-
Christian Tismer
-
Gerhard Haering
-
Gerhard Haering
-
Guido van Rossum
-
Jason Tishler
-
Mark Hammond
-
martin@v.loewis.de
-
Tim Peters