Skip to content

Instantly share code, notes, and snippets.

@qunaibit
Last active June 3, 2022 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qunaibit/fd69a3055e3ed0d10dafcf02cfc041e1 to your computer and use it in GitHub Desktop.
Save qunaibit/fd69a3055e3ed0d10dafcf02cfc041e1 to your computer and use it in GitHub Desktop.
Example of simple port to HPy for mpl
// src/_c_internal_utils.c
+ static HPy 
- static PyObject* 
mpl_SetCurrentProcessExplicitAppUserModelID(
+    HPyContext *ctx, 
+    HPy module,
-    PyObject* module,
+    HPy arg
-    PyObject* arg
) {
#ifdef _WIN32
+    wchar_t* appid = HPyUnicode_AsWideCharString(ctx, arg, NULL); 
-    wchar_t* appid = PyUnicode_AsWideCharString(arg, NULL);
    ...
}
// src/qhull_wrap.c
+ static HPy 
- static PyObject*
delaunay(
+    HPyContext *ctx, 
+    HPy h_self,
-    PyObject *self,
+    HPy* args, 
+    HPy_ssize_t nargs
-    PyObject *args
) {
    HPy xarg;
    HPy yarg;
    ...
+    if (!HPyArg_Parse(ctx, NULL, args, nargs, "OO", &xarg, &yarg)) {
-    if (!PyArg_ParseTuple(args, "OO", &xarg, &yarg)) {
+        HPyErr_SetString(ctx, ctx->h_ValueError, "expecting x and y arrays");
-        PyErr_SetString(PyExc_ValueError, "expecting x and y arrays");
+        return HPy_NULL;
-        return NULL;
    }
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment