python27_sys/
methodobject.rs1use core::ptr;
2use libc::{c_char, c_int};
3
4use crate::object::{PyObject, PyTypeObject, Py_TYPE};
5
6#[cfg_attr(windows, link(name = "pythonXY"))]
7extern "C" {
8 pub static mut PyCFunction_Type: PyTypeObject;
9}
10
11#[inline(always)]
12pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int {
13 let u: *mut PyTypeObject = &mut PyCFunction_Type;
14 (Py_TYPE(op) == u) as c_int
15}
16
17pub type PyCFunction =
18 unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject) -> *mut PyObject;
19pub type PyCFunctionWithKeywords = unsafe extern "C" fn(
20 slf: *mut PyObject,
21 args: *mut PyObject,
22 kwds: *mut PyObject,
23) -> *mut PyObject;
24pub type PyNoArgsFunction = unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyObject;
25
26#[cfg_attr(windows, link(name = "pythonXY"))]
27extern "C" {
28 pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option<PyCFunction>;
29 pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject;
30 pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int;
31 pub fn PyCFunction_Call(
32 f: *mut PyObject,
33 args: *mut PyObject,
34 kwds: *mut PyObject,
35 ) -> *mut PyObject;
36}
37
38#[repr(C)]
39#[derive(Copy)]
40pub struct PyMethodDef {
41 pub ml_name: *const c_char,
42 pub ml_meth: Option<PyCFunction>,
43 pub ml_flags: c_int,
44 pub ml_doc: *const c_char,
45}
46
47impl Clone for PyMethodDef {
48 #[inline]
49 fn clone(&self) -> PyMethodDef {
50 *self
51 }
52}
53
54pub const METH_OLDARGS: c_int = 0x0000;
56pub const METH_VARARGS: c_int = 0x0001;
57pub const METH_KEYWORDS: c_int = 0x0002;
58pub const METH_NOARGS: c_int = 0x0004;
60pub const METH_O: c_int = 0x0008;
61
62pub const METH_CLASS: c_int = 0x0010;
66pub const METH_STATIC: c_int = 0x0020;
67
68pub const METH_COEXIST: c_int = 0x0040;
74
75#[repr(C)]
76#[derive(Copy, Clone)]
77pub struct PyMethodChain {
78 pub methods: *mut PyMethodDef,
79 pub link: *mut PyMethodChain,
80}
81
82#[cfg_attr(windows, link(name = "pythonXY"))]
99extern "C" {
100 pub fn Py_FindMethod(
101 methods: *mut PyMethodDef,
102 slf: *mut PyObject,
103 name: *const c_char,
104 ) -> *mut PyObject;
105 pub fn PyCFunction_NewEx(
106 ml: *mut PyMethodDef,
107 slf: *mut PyObject,
108 module: *mut PyObject,
109 ) -> *mut PyObject;
110 pub fn Py_FindMethodInChain(
111 chain: *mut PyMethodChain,
112 slf: *mut PyObject,
113 name: *const c_char,
114 ) -> *mut PyObject;
115 pub fn PyCFunction_ClearFreeList() -> c_int;
116}
117
118#[inline(always)]
119pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject {
120 PyCFunction_NewEx(ml, slf, ptr::null_mut())
121}