[Python-Dev] Python as a Metro-style App

"Martin v. Löwis" martin at v.loewis.de
Sat Jan 7 18:57:41 CET 2012


I just tried porting Python as a Metro (Windows 8) App, and failed.

Metro Apps use a variant of the Windows API called WinRT that still
allows to write native applications in C++, but restricts various APIs
to a subset of the full Win32 functionality. For example, everything
related to subprocess creation would not work; none of the
byte-oriented file API seems to be present, and a number of file
operation functions are absent as well (such as MoveFile).

Regardless, porting Python ought to be feasible, except that it fails
fundamentally with the preview release of Visual Studio.

The problem is that compilation of C code is apparently not
supported/tested in that preview release. When compiling a trivial
C file in a Metro app, the compiler complains that a temporary file
ending with "md" could not be found, most likely because the C
compiler failed to generate it, whereas the C++ compiler would.

I tried compiling the Python sources as C++, but that produced
hundreds of compilation errors. Most of them are either about missing
casts (e.g. from int to enum types, or from void * to other pointer
types), or about the "static forward" declarations of type objects.

For the latter, anonymous namespaces should be used. While it is
feasible to replace

static PyTypeObject foo;
...
static PyTypeObject foo = {
...
};

with

Py_BEGIN_STATIC
PyTypeObject foo;
Py_END_STATIC
...
Py_BEGIN_STATIC
PyTypeObject foo = {
...
};
Py_END_STATIC

I'm not sure whether such a change would be accepted, in particular as
Microsoft might fix the bug in the compiler until the final release
of Windows 8.

Regards,
Martin


More information about the Python-Dev mailing list