Last active
July 21, 2022 13:07
-
-
Save steve-s/225d54f9e8d85e024c2c57605be36b34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Python.h" | |
static PyObject *myabs(PyObject *self, PyObject *arg) { | |
return Py_Absolute(arg); | |
} | |
static PyMethodDef methods[] = { | |
{"myabs", myabs, METH_O, ""}, | |
{NULL, NULL, 0, NULL} | |
}; | |
static struct PyModuleDef module = { | |
.m_methods = methods | |
// ... | |
}; | |
// ------------------------------------------- | |
// The same with HPy: | |
#include "hpy.h" | |
HPyDef_METH(myabs, "myabs", myabs_impl, HPyFunc_O) | |
static HPy myabs_impl(HPyContext *ctx, HPy self, HPy arg) { | |
return HPy_Absolute(ctx, arg); | |
} | |
static HPyDef *methods[] = { &myabs, NULL }; | |
static HPyModuleDef module = { | |
.defines = methods, | |
// ... | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used in a medium blog post about HPy