[pypy-dev] Translating PyPy on Windows

Johan Råde johan.rade at gmail.com
Sun Jan 26 16:25:31 CET 2014


Hi Maciej,

Here are the details of what I did when I tried using precompiled headers.

1. I checked out revision 68823

2. I translated PyPy.

3. I went to the directory with all (well most) of the sources.
On my machine it was
     C:\Users\Rade\AppData\Local\Temp\usession-default-0\testing_1

4. I added include guards to common_header.h and preimpl.h

5. I added a file stdafx.c with the single line

#include "stdafx.h"

6. I added a file stdafx.h with the the lines

#ifndef PYPY_STDAFX_H
#define PYPY_STDAFX_H
#include "common_header.h"
#include "structdef.h"
#include "forwarddecl.h"
#include "preimpl.h"
#endif

7. I revised the makefile so that it would created a precompiled header 
from stdafx.c and compile all the other source files with that 
precompiled header. The commands were essentially

     cl.exe stdafx.c $(CFLAGS) /Ycstdafx.h /Fpstdafx.pch $(INCLUDEDIRS)

     cl.exe <filename> $(CFLAGS) /Yustdafx.h /Fpstdafx.pch /FIstdafx.h 
$(INCLUDEDIRS)

Here
   /Yc = create precompiled header
   /Yu = use precompiled header
   /Fp = specify precompiled header name
   /FI = force inclusion of header file

Things would of course be different with gcc.

Then I ran the makefile.
Several files did not compile.

8. I revised the makefile so that the source files that did not compile 
in step 7 were compiled without the precompiled header.

I ran the makefile again.
It compiled and linked and the generated executable seemed to work.

----------------------------------

What should be done in addition:


1. The precompiled header should only be used with files that begin with

#include "common_header.h"
#include "structdef.h"
#include "forwarddecl.h"
#include "preimpl.h"

That seems to be the files with names that match one of the patterns
   data_*.h
   nonfuncnodes*.h
   implement*.h
   pypy_*.h
   rpython_*.h

The remaining files either include python.h or or just plain standard C 
lib headers.


2. The source files typically begin with something like

#define PYPY_FILE_NAME "rpython_rtyper_lltypesystem_rlist.c"
#include "common_header.h"
#include "structdef.h"
#include "forwarddecl.h"
#include "preimpl.h"
#include "src/g_include.h"

The first line is different in each file.
This seems to indicate that you can not use precompiled headers.
However, the macro  PYPY_FILE_NAME is only used in src/g_include.h.
Thus the files could, and should, be rewritten as

#include "common_header.h"
#include "structdef.h"
#include "forwarddecl.h"
#include "preimpl.h"
#define PYPY_FILE_NAME "rpython_rtyper_lltypesystem_rlist.c"
#include "src/g_include.h"

Now it becomes clear that you can put the first four lines in a 
precompiled header.


3. Optionally one could refactor src/g_include.h so it does not rely on 
the macro PYPY_FILE_NAME. Then you could add src/g_include.h to the 
precompiled header as well.
But I think the performance gain from that would be small.


Cheers,
Johan









More information about the pypy-dev mailing list