Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setattr(tyobj, tp_as_name, tp_as_new_ptr)
tp_as = tp_as_ptr[0]
# find the C function type
for fname, ftype in struct_ty._fields_:
if fname == impl_method:
cfunc_t = ftype
cfunc = cfunc_t(wrapper)
tp_func_dict[(klass, attr)] = cfunc
setattr(tp_as, impl_method, cfunc)
else:
# find the C function type
for fname, ftype in PyTypeObject._fields_:
if fname == impl_method:
cfunc_t = ftype
if not (klass, attr) in tp_as_dict:
tp_as_dict[(klass, attr)] = ctypes.cast(getattr(tyobj, impl_method), cfunc_t)
# override function call
cfunc = cfunc_t(wrapper)
tp_func_dict[(klass, attr)] = cfunc
setattr(tyobj, impl_method, cfunc)
class PyMappingMethods(ctypes.Structure):
pass
class PyTypeObject(ctypes.Structure):
pass
class PyAsyncMethods(ctypes.Structure):
pass
PyObject._fields_ = [
('ob_refcnt', Py_ssize_t),
('ob_type', ctypes.POINTER(PyTypeObject)),
]
PyTypeObject._fields_ = [
# varhead
('ob_base', PyObject),
('ob_size', Py_ssize_t),
# declaration
('tp_name', ctypes.c_char_p),
('tp_basicsize', Py_ssize_t),
('tp_itemsize', Py_ssize_t),
('tp_dealloc', ctypes.CFUNCTYPE(None, PyObject_p)),
('printfunc', ctypes.CFUNCTYPE(ctypes.c_int, PyObject_p, FILE_p, ctypes.c_int)),
('getattrfunc', ctypes.CFUNCTYPE(PyObject_p, PyObject_p, ctypes.c_char_p)),
('setattrfunc', ctypes.CFUNCTYPE(ctypes.c_int, PyObject_p, ctypes.c_char_p, PyObject_p)),
('tp_as_async', ctypes.CFUNCTYPE(PyAsyncMethods)),
('tp_repr', ctypes.CFUNCTYPE(PyObject_p, PyObject_p)),
('tp_as_number', ctypes.POINTER(PyNumberMethods)),
('tp_as_sequence', ctypes.POINTER(PySequenceMethods)),
('tp_as_mapping', ctypes.POINTER(PyMappingMethods)),