This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: g++ compilation error of Module/python.c with ./configure --with-cxx_main
Type: Stage:
Components: Build Versions: Python 3.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, georg.brandl, loewis, pgurumur, vstinner
Priority: normal Keywords:

Created on 2010-11-08 06:52 by pgurumur, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (12)
msg120714 - (view) Author: Prabhu Gurumurthy (pgurumur) Date: 2010-11-08 06:52
When manually building on OpenBSD 4.8 using gcc 4.2.1, I got the following error:

g++ -pthread -c -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I/usr/home/pgurumur/temp/Python-3.1.2/Include -DTHREAD_STACK_SIZE=0x20000 -fPIC -I/usr/include  -DPy_BUILD_CORE -o Modules/python.o /usr/home/pgurumur/temp/Python-3.1.2/Modules/python.ccc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++/usr/home/pgurumur/temp/Python-3.1.2/Modules/python.c: In function 'wchar_t* char2wchar(char*)':/usr/home/pgurumur/temp/Python-3.1.2/Modules/python.c:60: error: invalid conversion from 'void*' to 'wchar_t*'*** Error code 1

I changed line 60 from:
res = PyMem_Malloc(argsize*sizeof(wchar_t));

to:
res = (wchar_t *)PyMem_Malloc(argsize*sizeof(wchar_t));

I was able to compile it successfully, another thing you would notice is that, -Wstrict-prototypes is not a valid option with g++, (just a warning though)

My configure options:

 /usr/home/pgurumur/temp/Python-3.1.2/configure --with-fpectl --with-threads --srcdir=/usr/home/pgurumur/temp/Python-3.1.2 --enable-ipv6 --enable-shared --with-cxx_main --with-signal-module --prefix=/opt/local
msg120716 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-11-08 07:58
Out of curiosity: why are you building with --with-cxx_main?
msg120799 - (view) Author: Prabhu Gurumurthy (pgurumur) Date: 2010-11-08 19:54
I was building it just the way python2.x is being built, should I try it without cxx-main? But, does it solve the actual problem?
msg120812 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-11-08 22:06
It should certainly work around the problem you are reporting.
msg120813 - (view) Author: Prabhu Gurumurthy (pgurumur) Date: 2010-11-08 22:20
You may be correct, (since I have not tested it), but isn't the error that gcc complains about, an issue? a minor one I am sure.  I have gotten around it by just updating the file. Correct me if I am wrong here please, --with-cxx_main is not a supported option for compiling in OpenBSD? Ill test it without cxx_main option tonight.

Thanks!
msg120815 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-11-08 22:26
I wasn't really discussing (yet) whether this is a bug. I was just trying to find out what specifically made you use this configure option. The need for it should have gone away ten years ago or so.
msg120816 - (view) Author: Prabhu Gurumurthy (pgurumur) Date: 2010-11-08 22:35
I understand, Ill run it without cxx_main option tonight.
msg120843 - (view) Author: Prabhu Gurumurthy (pgurumur) Date: 2010-11-09 06:44
I ran the build "without" cxx_main, I did _not_ see the same error.
msg121619 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-11-20 12:06
This is the old issue of casting the result of malloc() -- frowned upon in C, but required in C++.  Looking at the Python sources, most uses of PyMem_Malloc seem to have the cast, so it doesn't seem wrong to add one here (where it actually can be configured to be compiled with a C++ compiler).
msg228007 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-09-30 21:38
Is this out of date as the only buildbot I could find is running OpenBSD 5.5?
msg228015 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-30 22:30
> g++ (...)
> Modules/python.c:60: error: invalid conversion from 'void*' to 'wchar_t*'*** Error code 1

This line was part of the function char2wchar() which was moved to Python/fileutils.c (and renamed to _Py_char2wchar).

Since "configure --with-cxx_main" only changes the compiler for python.c (and _testembed.c), calls to PyMem_Malloc() in fileutils.c are not more an issue.

In short: the issue has already been fixed since the creation of fileutils.c.

changeset:   65162:39014f0abc32
user:        Victor Stinner <victor.stinner@haypocalc.com>
date:        Thu Oct 07 21:45:39 2010 +0000
files:       Include/Python.h Include/fileutils.h Makefile.pre.in Modules/getpath.c Modules/main.c PCbuild/pythoncore.vcproj Python/fileutils.c Python/im
description:
Create fileutils.c/.h
msg228017 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-30 22:31
> Is this out of date as the only buildbot I could find is running OpenBSD 5.5?

The issue is not related to OpenBSD.
History
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54558
2014-09-30 22:31:24vstinnersetmessages: + msg228017
2014-09-30 22:31:05vstinnersettitle: Error in Module/python.c when building on OpenBSD 4.8 -> g++ compilation error of Module/python.c with ./configure --with-cxx_main
2014-09-30 22:30:05vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg228015

resolution: fixed
2014-09-30 21:38:01BreamoreBoysetnosy: + BreamoreBoy
messages: + msg228007
2010-11-20 12:06:00georg.brandlsetnosy: + georg.brandl
messages: + msg121619
2010-11-09 06:44:40pgurumursetmessages: + msg120843
2010-11-08 22:35:31pgurumursetmessages: + msg120816
2010-11-08 22:26:42loewissetmessages: + msg120815
2010-11-08 22:21:00pgurumursetmessages: + msg120813
2010-11-08 22:06:55loewissetmessages: + msg120812
2010-11-08 19:54:57pgurumursetmessages: + msg120799
2010-11-08 07:58:57loewissetnosy: + loewis
messages: + msg120716
2010-11-08 06:52:21pgurumurcreate