[pypy-commit] pypy hpy: Bah, fix the update_vendored script and really update everything to 56a54e1
arigo
pypy.commits at gmail.com
Mon Nov 18 07:09:44 EST 2019
Author: Armin Rigo <arigo at tunes.org>
Branch: hpy
Changeset: r98112:0e8678278177
Date: 2019-11-18 13:03 +0100
http://bitbucket.org/pypy/pypy/changeset/0e8678278177/
Log: Bah, fix the update_vendored script and really update everything to
56a54e1
diff --git a/pypy/module/hpy_universal/_vendored/include/cpython/hpy.h b/pypy/module/hpy_universal/_vendored/include/cpython/hpy.h
--- a/pypy/module/hpy_universal/_vendored/include/cpython/hpy.h
+++ b/pypy/module/hpy_universal/_vendored/include/cpython/hpy.h
@@ -6,7 +6,7 @@
/* XXX: it would be nice if we could include hpy.h WITHOUT bringing in all the
stuff from Python.h, to make sure that people don't use the CPython API by
- mistake. How to achieve it, though? */
+ mistake. How to achieve it, though? Is defining Py_LIMITED_API enough? */
/* XXX: should we:
* - enforce PY_SSIZE_T_CLEAN in hpy
@@ -24,12 +24,7 @@
typedef struct { PyObject *_o; } HPy;
-typedef long HPyContext;
-
-HPyAPI_FUNC(HPyContext)
-_HPyGetContext(void) {
- return 42;
-}
+typedef Py_ssize_t HPy_ssize_t;
/* For internal usage only. These should be #undef at the end of this header.
If you need to convert HPy to PyObject* and vice-versa, you should use the
@@ -38,6 +33,24 @@
#define _h2py(x) (x._o)
#define _py2h(o) ((HPy){o})
+typedef struct _HPyContext_s {
+ HPy h_None;
+ HPy h_True;
+ HPy h_False;
+} *HPyContext;
+
+/* XXX! should be defined only once, not once for every .c! */
+static struct _HPyContext_s _global_ctx = {
+ .h_None = _py2h(Py_None),
+ .h_True = _py2h(Py_True),
+ .h_False = _py2h(Py_False),
+};
+
+HPyAPI_FUNC(HPyContext)
+_HPyGetContext(void) {
+ return &_global_ctx;
+}
+
#define HPy_NULL ((HPy){NULL})
#define HPy_IsNull(x) ((x)._o == NULL)
@@ -85,23 +98,63 @@
/* function declaration */
-#define HPy_FUNCTION(NAME) \
+#define HPy_METH_NOARGS(NAME) \
+ static HPy NAME##_impl(HPyContext, HPy); \
+ static PyObject* NAME(PyObject *self, PyObject *noargs) \
+ { \
+ return _h2py(NAME##_impl(_HPyGetContext(), _py2h(self))); \
+ }
+
+#define HPy_METH_O(NAME) \
static HPy NAME##_impl(HPyContext, HPy, HPy); \
+ static PyObject* NAME(PyObject *self, PyObject *arg) \
+ { \
+ return _h2py(NAME##_impl(_HPyGetContext(), _py2h(self), _py2h(arg)));\
+ }
+
+#define HPy_METH_VARARGS(NAME) \
+ static HPy NAME##_impl(HPyContext, HPy, HPy *, Py_ssize_t); \
static PyObject* NAME(PyObject *self, PyObject *args) \
{ \
- return _h2py(NAME##_impl(_HPyGetContext(), _py2h(self), _py2h(args)));\
+ /* get the tuple elements as an array of "PyObject *", which */ \
+ /* is equivalent to an array of "HPy" with enough casting... */ \
+ HPy *items = (HPy *)&PyTuple_GET_ITEM(args, 0); \
+ Py_ssize_t nargs = PyTuple_GET_SIZE(args); \
+ return _h2py(NAME##_impl(_HPyGetContext(), _py2h(self), items, nargs));\
}
HPyAPI_FUNC(int)
-HPyArg_ParseTuple(HPyContext ctx, HPy args, const char *fmt, ...)
+HPyArg_Parse(HPyContext ctx, HPy *args, Py_ssize_t nargs, const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
- int res = PyArg_VaParse(_h2py(args), fmt, vl);
+ const char *fmt1 = fmt;
+ Py_ssize_t i = 0;
+
+ while (*fmt1 != 0) {
+ if (i >= nargs) {
+ abort(); // XXX
+ }
+ switch (*fmt1++) {
+ case 'l': {
+ long *output = va_arg(vl, long *);
+ long value = PyLong_AsLong(_h2py(args[i]));
+ // XXX check for exceptions
+ *output = value;
+ break;
+ }
+ default:
+ abort(); // XXX
+ }
+ i++;
+ }
+ if (i != nargs) {
+ abort(); // XXX
+ }
+
va_end(vl);
- /* XXX incref all returned 'PyObject*' */
- return res;
+ return 1;
}
diff --git a/pypy/module/hpy_universal/_vendored/include/universal/autogen_ctx.h b/pypy/module/hpy_universal/_vendored/include/universal/autogen_ctx.h
--- a/pypy/module/hpy_universal/_vendored/include/universal/autogen_ctx.h
+++ b/pypy/module/hpy_universal/_vendored/include/universal/autogen_ctx.h
@@ -10,16 +10,18 @@
struct _HPyContext_s {
int ctx_version;
+ HPy h_None;
+ HPy h_True;
+ HPy h_False;
HPy (*ctx_Module_Create)(HPyContext ctx, HPyModuleDef *def);
- HPy (*ctx_None_Get)(HPyContext ctx);
HPy (*ctx_Dup)(HPyContext ctx, HPy h);
void (*ctx_Close)(HPyContext ctx, HPy h);
HPy (*ctx_Long_FromLong)(HPyContext ctx, long value);
long (*ctx_Long_AsLong)(HPyContext ctx, HPy h);
- int (*ctx_Arg_ParseTuple)(HPyContext ctx, HPy args, const char *fmt, va_list _vl);
+ int (*ctx_Arg_Parse)(HPyContext ctx, HPy *args, HPy_ssize_t nargs, const char *fmt, va_list _vl);
HPy (*ctx_Number_Add)(HPyContext ctx, HPy x, HPy y);
HPy (*ctx_Unicode_FromString)(HPyContext ctx, const char *utf8);
HPy (*ctx_FromPyObject)(HPyContext ctx, struct _object *obj);
struct _object *(*ctx_AsPyObject)(HPyContext ctx, HPy h);
- struct _object *(*ctx_CallRealFunctionFromTrampoline)(HPyContext ctx, struct _object *self, struct _object *args, HPyCFunction func);
+ struct _object *(*ctx_CallRealFunctionFromTrampoline)(HPyContext ctx, struct _object *self, struct _object *args, void *func, int ml_flags);
};
diff --git a/pypy/module/hpy_universal/_vendored/include/universal/autogen_func.h b/pypy/module/hpy_universal/_vendored/include/universal/autogen_func.h
--- a/pypy/module/hpy_universal/_vendored/include/universal/autogen_func.h
+++ b/pypy/module/hpy_universal/_vendored/include/universal/autogen_func.h
@@ -12,10 +12,6 @@
return ctx->ctx_Module_Create ( ctx, def );
}
-static inline HPy HPyNone_Get(HPyContext ctx) {
- return ctx->ctx_None_Get ( ctx );
-}
-
static inline HPy HPy_Dup(HPyContext ctx, HPy h) {
return ctx->ctx_Dup ( ctx, h );
}
@@ -32,8 +28,8 @@
return ctx->ctx_Long_AsLong ( ctx, h );
}
-static inline int HPyArg_ParseTuple(HPyContext ctx, HPy args, const char *fmt, ...) {
- va_list _vl; va_start(_vl, fmt); int _res = ctx->ctx_Arg_ParseTuple ( ctx, args, fmt, _vl ); va_end(_vl); return _res;
+static inline int HPyArg_Parse(HPyContext ctx, HPy *args, HPy_ssize_t nargs, const char *fmt, ...) {
+ va_list _vl; va_start(_vl, fmt); int _res = ctx->ctx_Arg_Parse ( ctx, args, nargs, fmt, _vl ); va_end(_vl); return _res;
}
static inline HPy HPyNumber_Add(HPyContext ctx, HPy x, HPy y) {
@@ -52,7 +48,7 @@
return ctx->ctx_AsPyObject ( ctx, h );
}
-static inline struct _object *_HPy_CallRealFunctionFromTrampoline(HPyContext ctx, struct _object *self, struct _object *args, HPyCFunction func) {
- return ctx->ctx_CallRealFunctionFromTrampoline ( ctx, self, args, func );
+static inline struct _object *_HPy_CallRealFunctionFromTrampoline(HPyContext ctx, struct _object *self, struct _object *args, void *func, int ml_flags) {
+ return ctx->ctx_CallRealFunctionFromTrampoline ( ctx, self, args, func, ml_flags );
}
diff --git a/pypy/module/hpy_universal/_vendored/include/universal/hpy.h b/pypy/module/hpy_universal/_vendored/include/universal/hpy.h
--- a/pypy/module/hpy_universal/_vendored/include/universal/hpy.h
+++ b/pypy/module/hpy_universal/_vendored/include/universal/hpy.h
@@ -9,7 +9,6 @@
typedef struct { HPy_ssize_t _i; } HPy;
typedef struct _HPyContext_s *HPyContext;
-typedef HPy (*HPyCFunction)(HPyContext, HPy self, HPy args);
struct _object; /* that's PyObject inside CPython */
typedef struct _object *(*_HPy_CPyCFunction)(struct _object *self,
struct _object *args);
@@ -17,7 +16,7 @@
#define HPy_NULL ((HPy){0})
#define HPy_IsNull(x) ((x)._i == 0)
-typedef void (*_HPyMethodPairFunc)(HPyCFunction *out_func,
+typedef void (*_HPyMethodPairFunc)(void **out_func,
_HPy_CPyCFunction *out_trampoline);
typedef struct {
@@ -55,16 +54,46 @@
extern HPyContext _ctx_for_trampolines;
-#define HPy_FUNCTION(fnname) \
- static HPy fnname##_impl(HPyContext ctx, HPy self, HPy args); \
+#define HPy_METH_NOARGS(fnname) \
+ static HPy fnname##_impl(HPyContext ctx, HPy self); \
+ static struct _object * \
+ fnname##_trampoline(struct _object *self, struct _object *noargs) \
+ { \
+ return _HPy_CallRealFunctionFromTrampoline( \
+ _ctx_for_trampolines, self, NULL, fnname##_impl, METH_NOARGS); \
+ } \
+ static void \
+ fnname(void **out_func, _HPy_CPyCFunction *out_trampoline) \
+ { \
+ *out_func = fnname##_impl; \
+ *out_trampoline = fnname##_trampoline; \
+ }
+
+#define HPy_METH_O(fnname) \
+ static HPy fnname##_impl(HPyContext ctx, HPy self, HPy arg); \
+ static struct _object * \
+ fnname##_trampoline(struct _object *self, struct _object *arg) \
+ { \
+ return _HPy_CallRealFunctionFromTrampoline( \
+ _ctx_for_trampolines, self, arg, fnname##_impl, METH_O); \
+ } \
+ static void \
+ fnname(void **out_func, _HPy_CPyCFunction *out_trampoline) \
+ { \
+ *out_func = fnname##_impl; \
+ *out_trampoline = fnname##_trampoline; \
+ }
+
+#define HPy_METH_VARARGS(fnname) \
+ static HPy fnname##_impl(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t);\
static struct _object * \
fnname##_trampoline(struct _object *self, struct _object *args) \
{ \
return _HPy_CallRealFunctionFromTrampoline( \
- _ctx_for_trampolines, self, args, fnname##_impl); \
+ _ctx_for_trampolines, self, args, fnname##_impl, METH_VARARGS); \
} \
static void \
- fnname(HPyCFunction *out_func, _HPy_CPyCFunction *out_trampoline) \
+ fnname(void **out_func, _HPy_CPyCFunction *out_trampoline) \
{ \
*out_func = fnname##_impl; \
*out_trampoline = fnname##_trampoline; \
diff --git a/pypy/module/hpy_universal/update_vendored.sh b/pypy/module/hpy_universal/update_vendored.sh
--- a/pypy/module/hpy_universal/update_vendored.sh
+++ b/pypy/module/hpy_universal/update_vendored.sh
@@ -15,7 +15,7 @@
git -C "$HPY" --no-pager log --oneline -n 1
git -C "$HPY" --no-pager diff --stat
-#cp -R "$HPY"/hpy-api/hpy_devel/include/* "$VENDORED/include"
+cp -R "$HPY"/hpy-api/hpy_devel/include/* "$VENDORED/include"
cp -R "$HPY"/test/* "$VENDORED/test"
echo
More information about the pypy-commit
mailing list