Allow detaching handles

This commit is contained in:
Kovid Goyal 2020-10-15 21:28:13 +05:30
parent 40de844650
commit f5f7a44a47
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -55,6 +55,13 @@ Handle_dealloc(Handle *self) {
Py_CLEAR(self->associated_name);
}
static PyObject*
Handle_detach(Handle *self) {
void *h = self->handle;
self->handle = NULL;
return PyLong_FromVoidPtr(h);
}
static PyObject*
Handle_as_int(Handle * self) {
return PyLong_FromVoidPtr(self->handle);
@ -128,6 +135,7 @@ Handle_close(Handle *self) {
#define M(name, args) {#name, (PyCFunction)Handle_##name, args, ""}
static PyMethodDef Handle_methods[] = {
M(close, METH_NOARGS),
M(detach, METH_NOARGS),
{NULL, NULL, 0, NULL}
};
#undef M