[Python-Dev] wchar_t (was Adventures with x64, VS7 and VS8) on Windows

Mark Hammond mhammond at skippinet.com.au
Mon May 21 13:46:53 CEST 2007


Kristján Valur Jónsson quoting me:
> > hrm - as above, I'm more concerned with the definition of 
> > WCHAR - which
> > means my problem is related more to the Platform SDK version rather
> > than the
> > compiler.  This is unfortunate - on one hand we do consider
> > 'platform=Windows API', and WCHAR is very much an API concept.  I'll
> > need to
> > dig some more into this, but at least I know I'm not 
> > wasting my time :)
> 
> Mark, your problem may be related to a setting in the "c/c++ 
> -> language"
> tab in the settings, where "treat wchar_t as a builtin type" 
> default has
> changed.  I recommend that we do treat it as a builtin, but the VS2003
> default was "no" and the 2005 is "yes".  Could this be contributing to
> your problem?

Thanks for the suggestion and for introducing me to that option - but it
made no difference.  I'm guessing its related to C++ - code such as the
following:

static PyObject *TestIBuild()
{
    // obviously nonsense - the point is to test if it compiles.
    WCHAR *wval = PyUnicode_AS_UNICODE(Py_None);
    return PyUnicode_FromUnicode(wval, wcslen(wval));
}

works everywhere - except in a pywin32 .cpp file built on x64:)  That code
results in:

win32/src/win32apimodule.cpp(81) : error C2440: 'initializing' : cannot
convert from 'Py_UNICODE *' to 'WCHAR *'
        Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
win32/src/win32apimodule.cpp(82) : error C2664: 'PyUnicodeUCS2_FromUnicode'
: cannot convert parameter 1 from 'WCHAR *' to 'const Py_UNICODE *'
        Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast

Unfortunately I don't have pywin32 building under vc8 on x32, but expect it
to happen there too.  pywin32 uses distutils, but I inspected the options
passed and can't find anything to make a difference.  /Zc:wchar_t and/or
/Zc:wchar_t- seem to be the command-line settings for this flag and it also
makes no difference.  I'm out of time to confirm is is simply "c++ with
vs8", but did confirm that the patch below appears to solve the problem, and
given Martin's previous +1, I decided to stop there.  I failed in a quick
attempt at replacing the literal 2 with something involving sizeof.  Does
this look reasonable?

Cheers,

Mark

Index: pyconfig.h
===================================================================
--- pyconfig.h  (revision 55487)
+++ pyconfig.h  (working copy)
@@ -492,10 +492,10 @@
 #define Py_USING_UNICODE

 /* Define as the integral type used for Unicode representation. */
-#define PY_UNICODE_TYPE unsigned short
+#define PY_UNICODE_TYPE wchar_t

 /* Define as the size of the unicode type. */
-#define Py_UNICODE_SIZE SIZEOF_SHORT
+#define Py_UNICODE_SIZE 2

 /* Define if you have a useable wchar_t type defined in wchar.h; useable
    means wchar_t must be 16-bit unsigned type. (see


-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3260 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-dev/attachments/20070521/12f28bf0/attachment.bin 


More information about the Python-Dev mailing list