Author: Devin Jeanpierre <jeanpierr...@gmail.com>
Branch: seperate-strucmember_h
Changeset: r82134:66d60a554284
Date: 2016-01-31 02:30 -0800
http://bitbucket.org/pypy/pypy/changeset/66d60a554284/

Log:    Unrefactor code that was really better as it was.

        I didn't realize I'd end up sharing, well, basically nothing.

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -960,47 +960,27 @@
     pypy_macros_h = udir.join('pypy_macros.h')
     pypy_macros_h.write('\n'.join(pypy_macros))
 
-def _header_to_guard(header_name):
-    return '_PYPY_' + header_name.replace('.', '_').upper()
-
-def _decl_header_top(header_name):
-    guard = _header_to_guard(header_name)
-    header = [
-        "#ifndef %s\n" % guard,
-        "#define %s\n" % guard,
-        "#ifndef PYPY_STANDALONE\n",
-        "#ifdef __cplusplus",
-        "extern \"C\" {",
-        "#endif\n",
-        '#define Signed   long           /* xxx temporary fix */\n',
-        '#define Unsigned unsigned long  /* xxx temporary fix */\n'
-    ]
-    if header_name == 'pypy_decl.h': # XXX don't send for code review unless 
I'm sure this is necessary
-        for decl in FORWARD_DECLS:
-            header.append("%s;" % (decl,))
-    return header
-
-def _decl_header_bottom(header_name):
-    return [
-        '#undef Signed    /* xxx temporary fix */\n',
-        '#undef Unsigned  /* xxx temporary fix */\n',
-        "#ifdef __cplusplus",
-        "}",
-        "#endif",
-        "#endif /*PYPY_STANDALONE*/\n",
-        "#endif /*%s*/\n" % _header_to_guard(header_name),
-    ]
-
 def generate_decls_and_callbacks(db, export_symbols, api_struct=True):
     "NOT_RPYTHON"
     # implement function callbacks and generate function decls
     functions = []
     decls = {}
+    pypy_decls = decls['pypy_decl.h'] = []
+    pypy_decls.append("#ifndef _PYPY_PYPY_DECL_H\n")
+    pypy_decls.append("#define _PYPY_PYPY_DECL_H\n")
+    pypy_decls.append("#ifndef PYPY_STANDALONE\n")
+    pypy_decls.append("#ifdef __cplusplus")
+    pypy_decls.append("extern \"C\" {")
+    pypy_decls.append("#endif\n")
+    pypy_decls.append('#define Signed   long           /* xxx temporary fix 
*/\n')
+    pypy_decls.append('#define Unsigned unsigned long  /* xxx temporary fix 
*/\n')
+
+    for decl in FORWARD_DECLS:
+        pypy_decls.append("%s;" % (decl,))
 
     for header_name, header_functions in FUNCTIONS_BY_HEADER.iteritems():
         if header_name not in decls:
-            decls[header_name] = header = []
-            header.extend(_decl_header_top(header_name))
+            header = decls[header_name] = []
         else:
             header = decls[header_name]
 
@@ -1015,7 +995,6 @@
                 else:
                     body = "{ return _pypyAPI.%s(%s); }" % (name, callargs)
                 functions.append('%s %s(%s)\n%s' % (restype, name, args, body))
-    pypy_decls = decls['pypy_decl.h']
     for name in VA_TP_LIST:
         name_no_star = process_va_name(name)
         header = ('%s pypy_va_get_%s(va_list* vp)' %
@@ -1031,9 +1010,15 @@
             typ = 'PyObject*'
         pypy_decls.append('PyAPI_DATA(%s) %s;' % (typ, name))
 
+    pypy_decls.append('#undef Signed    /* xxx temporary fix */\n')
+    pypy_decls.append('#undef Unsigned  /* xxx temporary fix */\n')
+    pypy_decls.append("#ifdef __cplusplus")
+    pypy_decls.append("}")
+    pypy_decls.append("#endif")
+    pypy_decls.append("#endif /*PYPY_STANDALONE*/\n")
+    pypy_decls.append("#endif /*_PYPY_PYPY_DECL_H*/\n")
+
     for header_name, header_decls in decls.iteritems():
-        header_decls.extend(_decl_header_bottom(header_name))
-
         decl_h = udir.join(header_name)
         decl_h.write('\n'.join(header_decls))
     return functions
diff --git a/pypy/module/cpyext/include/structmember.h 
b/pypy/module/cpyext/include/structmember.h
--- a/pypy/module/cpyext/include/structmember.h
+++ b/pypy/module/cpyext/include/structmember.h
@@ -50,11 +50,18 @@
 #define PY_WRITE_RESTRICTED 4
 #define RESTRICTED    (READ_RESTRICTED | PY_WRITE_RESTRICTED)
 
+#define Signed   long           /* xxx temporary fix */
+#define Unsigned unsigned long  /* xxx temporary fix */
+
+/* API functions. */
+#include "pypy_structmember_decl.h"
+
+#undef Signed    /* xxx temporary fix */
+#undef Unsigned  /* xxx temporary fix */
 
 #ifdef __cplusplus
 }
 #endif
 #endif /* !Py_STRUCTMEMBER_H */
 
-/* API functions. */
-#include "pypy_structmember_decl.h"
+
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to