[New-bugs-announce] [issue23603] MinGW-64
Ashish Sadanandan
report at bugs.python.org
Sat Mar 7 21:02:06 CET 2015
New submission from Ashish Sadanandan:
I'm trying to embed Python 3.4.3 (x64) in a program compiled using MinGW-W64 g++ 4.9.2 (output from "g++ -v" attached) and Boost.Python 1.57.0. A simple example kept crashing at runtime and I managed to track it down to this testcase (which is not using Boost.Python but demonstrates why a check in Boost is failing). `python34.zip` in the `Py_SetPath()` call is a zip archive containing the entire contents of the `Lib` directory in my Python3.4 installation.
#include <Python.h>
#include <iostream>
int main()
{
Py_SetPath(L"python34.zip");
Py_Initialize();
PyObject *s = PyUnicode_FromString("Hello World");
std::cout << PyUnicode_Check(s) << std::endl;
std::cout << PyUnicode_CheckExact(s) << std::endl;
std::cout << PyUnicode_AsUTF8(s) << std::endl;
PyRun_SimpleString("from time import time, ctime\n"
"print('Today is', ctime(time())\n)");
Py_Finalize();
}
I compile this using
g++ -ID:/Tools/Python/3.4/x64/include -O0 -g3 -pedantic -Wall -Wextra -std=c++14 test.cpp -LD:/Tools/Python/3.4/x64/libs -lpython34 -o test.exe
Running test.exe results in
0
1
Hello World
Today is Sat Mar 7 12:06:53 2015
The problem is the first line of output. Creating a `PyObject` using `PyUnicode_FromString()` and then calling `PyUnicode_Check()` on the earlier result is returning `0`. The cause of this is that the `tp_flags` field somewhere within `PyObject` is `0` and `PyUnicode_Check()` performs a bitand with that and returns `0`. If I understand the docs correctly, when `PyUnicode_CheckExact()` returns true, `PyUnicode_Check()` should also return true because the former is a more stringent check than the latter.
Additional details that may or may not be relevant. I followed these steps to create `libpython34.a` for linking with g++. From an MSYS prompt
$ gendef.exe /C/Windows/System32/python34.dll
$ dlltool --dllname /C/Windows/System32/python34.dll --def python34.def --output-lib libpython34.a
I also tried downloading libpython34.a from Christoph Gohlke's website (http://www.lfd.uci.edu/~gohlke/pythonlibs/#libpython) but that produces the same result.
Is this a bug, or do I not understand what `PyUnicode_Check()` is supposed to do?
----------
components: Extension Modules
files: g++dashv.txt
messages: 237472
nosy: Ashish Sadanandan
priority: normal
severity: normal
status: open
title: MinGW-64
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file38381/g++dashv.txt
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23603>
_______________________________________
More information about the New-bugs-announce
mailing list