-
-
Save qunaibit/efbf653995f77ef7b9f6625c70cc1422 to your computer and use it in GitHub Desktop.
HPy + CAPI
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 *classA_foo(PyObject *self, PyObject *arg) | |
{ | |
Py_INCREF(arg); | |
return arg; | |
} | |
HPyDef_METH(classA_bar, "bar", classA_bar_impl, HPyFunc_NOARGS) | |
static HPy classA_bar_impl(HPyContext *ctx, HPy self) | |
{ | |
return HPyLong_FromLong(ctx, 1234); | |
} | |
static PyMethodDef classA_methods[] = { | |
{"foo", classA_foo, METH_O}, | |
{NULL, NULL} /* Sentinel */ | |
}; | |
static PyType_Slot classA_type_slots[] = { | |
{Py_tp_methods, classA_methods}, | |
{0, 0}, | |
}; | |
static HPyDef *classA_type_defines[] = { | |
&classA_bar, | |
NULL | |
}; | |
static HPyType_Spec classA_type_spec = { | |
.name = "ClassA", | |
.legacy = true, | |
.legacy_slots = classA_type_slots, | |
.defines = classA_type_defines | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment