[pypy-commit] pypy hpy: resolve an XXX and use the proper way to include src/getargs.c as a separate compiled module

antocuni pypy.commits at gmail.com
Fri Nov 22 19:09:37 EST 2019


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: hpy
Changeset: r98147:05f41db32719
Date: 2019-11-23 01:08 +0100
http://bitbucket.org/pypy/pypy/changeset/05f41db32719/

Log:	resolve an XXX and use the proper way to include src/getargs.c as a
	separate compiled module

diff --git a/pypy/module/hpy_universal/llapi.py b/pypy/module/hpy_universal/llapi.py
--- a/pypy/module/hpy_universal/llapi.py
+++ b/pypy/module/hpy_universal/llapi.py
@@ -1,6 +1,7 @@
 import py
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.translator import cdir
 from pypy import pypydir
 from pypy.module.hpy_universal import _vendored
 
@@ -8,30 +9,27 @@
 INCLUDE_DIR = PYPYDIR.join('module', 'hpy_universal', '_vendored', 'include')
 SRC_DIR = PYPYDIR.join('module', 'hpy_universal', 'src')
 
-# XXX I don't understand what is going on here: if I put getargs.c as
-# separate_module_files, then ll2ctypes can't find it. I need to #include t in
-# separate_module_sources for now...
-eci = ExternalCompilationInfo(includes=["universal/hpy.h"],
-                              include_dirs=[INCLUDE_DIR],
-                              ## separate_module_files=[
-                              ##     SRC_DIR.join('getargs.c'),
-                              ##     ],
-                              post_include_bits=["""
-RPY_EXTERN void *_HPy_GetGlobalCtx(void);
-RPY_EXTERN int ctx_Arg_Parse(HPyContext ctx, HPy *args, HPy_ssize_t nargs,
-                             const char *fmt, va_list vl);
-"""],
-                              separate_module_sources=["""
+eci = ExternalCompilationInfo(
+    includes=["universal/hpy.h", "getargs.h"],
+    include_dirs=[
+        cdir,        # for precommondefs.h
+        INCLUDE_DIR, # for universal/hpy.h
+        SRC_DIR,     # for getargs.h
+    ],
+    separate_module_files=[
+        SRC_DIR.join('getargs.c'),
+    ],
+    post_include_bits=["""
+        RPY_EXTERN void *_HPy_GetGlobalCtx(void);
+    """],
+    separate_module_sources=["""
+        struct _HPyContext_s hpy_global_ctx;
+        void *_HPy_GetGlobalCtx(void)
+        {
+            return &hpy_global_ctx;
+        }
+    """])
 
-#include "%s"
-
-struct _HPyContext_s hpy_global_ctx;
-void *_HPy_GetGlobalCtx(void)
-{
-    return &hpy_global_ctx;
-}
-
-""" % SRC_DIR.join('getargs.c')])
 
 HPy_ssize_t = lltype.Signed # XXXXXXXXX?
 
diff --git a/pypy/module/hpy_universal/src/getargs.c b/pypy/module/hpy_universal/src/getargs.c
--- a/pypy/module/hpy_universal/src/getargs.c
+++ b/pypy/module/hpy_universal/src/getargs.c
@@ -1,6 +1,5 @@
 #include "universal/hpy.h"
-
-#include <stdio.h>
+#include "getargs.h"
 
 /* XXX: this function is copied&pasted THREE times:
  *     hpy_devel/include/hpy.h
diff --git a/pypy/module/hpy_universal/src/getargs.h b/pypy/module/hpy_universal/src/getargs.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/hpy_universal/src/getargs.h
@@ -0,0 +1,6 @@
+#include <stdarg.h>
+#include "universal/hpy.h"
+#include "src/precommondefs.h"
+
+RPY_EXTERN int ctx_Arg_Parse(HPyContext ctx, HPy *args, HPy_ssize_t nargs,
+                             const char *fmt, va_list vl);


More information about the pypy-commit mailing list