Debian Codegraph @

pypy/module/_cffi_backend/copy_includes.py

raw symbols SCIP
1 import os
2 import shutil
3 import sys
4 import textwrap
5
6 from os.path import dirname, join, exists
7
8 from pypy.module.sys import version
9
10 if sys.platform == 'win32':
11 include = join(dirname(__file__), '..', '..', '..', 'include')
12 else:
13 cpyver = 'pypy{}.{}'.format(*version.CPYTHON_VERSION[:2])
14 include = join(dirname(__file__), '..', '..', '..', 'include', cpyver)
15 if not exists(include):
16 os.mkdir(include)
17 assert exists(include)
18 cpyext_include = join(dirname(__file__), '..', 'cpyext', 'include')
19
20 def main():
21 """Copy/create just enough header information to allow cffi to compile c-extension modules
22 """
23 python_h = textwrap.dedent("""
24 /* Partial C-API headers to allow CFFI C-compiled modules to work with PyPy */
25 #include <sys/types.h>
26 #include <stdarg.h>
27
28 #ifdef __GNUC__
29 #define _GNU_SOURCE 1
30 #endif
31 #ifndef _WIN32
32 # define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
33 # define PyAPI_FUNC(RTYPE) __attribute__((visibility("default"))) RTYPE
34 # define PyAPI_DATA(RTYPE) extern PyAPI_FUNC(RTYPE)
35 # define Py_LOCAL_INLINE(type) static inline type
36 #else
37 # define Py_DEPRECATED(VERSION_UNUSED)
38 # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
39 # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
40 # define Py_LOCAL_INLINE(type) static __inline type __fastcall
41 #endif
42
43 typedef void PyObject;
44 /* CPython sets Py_ssize_t in pyport.h, PyPy in cpyext_object.h */
45 #ifdef _WIN64
46 typedef long long Py_ssize_t;
47 #else
48 typedef long Py_ssize_t;
49 #endif
50
51 #include <patchlevel.h>
52 #include <modsupport.h>
53
54 #include <stdarg.h>
55 #include <stdio.h>
56 #include <string.h>
57 #include <assert.h>
58 #include <locale.h>
59 #include <ctype.h>
60
61 /* normally defined in "pythread.h", but we can't include that */
62 #define WITH_THREAD
63 """)
64 if exists(join(include, 'Python.h')):
65 return
66 with open(join(include, 'Python.h'), 'wt') as fid:
67 fid.write(python_h)
68 for header in ('patchlevel.h', 'modsupport.h', 'pyconfig.h'):
69 shutil.copy(join(cpyext_include, header), join(include, header))
70
71
72 if __name__ == '__main__':
73 main()
74