-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathinstancemethod_gen.go
More file actions
206 lines (176 loc) · 5.48 KB
/
instancemethod_gen.go
File metadata and controls
206 lines (176 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Code generated by gen_types. DO NOT EDIT.
package py
// #include "utils.h"
import "C"
import (
"unsafe"
)
// InstanceMethod represents objects of the InstanceMethodType (or PyInstanceMethod_Type
// in the Python API) type.
type InstanceMethod struct {
o C.PyInstanceMethodObject
}
var _ Object = (*InstanceMethod)(nil)
// InstanceMethodType is the Type object that represents the InstanceMethod type.
var InstanceMethodType = newType(&C.PyInstanceMethod_Type)
func instanceMethodCheck(obj Object) bool {
if obj == nil {
return false
}
return C.instanceMethodCheck(c(obj)) != 0
}
// AsInstanceMethod casts the given obj to a InstanceMethod (i.e. the underlying
// Python Object is the same, just the type is changed). If the value cannot be
// cast to a InstanceMethod, then nil is returned.
//
// Return value: Borrowed Reference.
func AsInstanceMethod(obj Object) *InstanceMethod {
if obj == nil {
return nil
}
o := c(obj)
if C.instanceMethodCheck(o) == 0 {
return nil
}
return (*InstanceMethod)(unsafe.Pointer(o))
}
func newInstanceMethod(obj *C.PyObject) *InstanceMethod {
return (*InstanceMethod)(unsafe.Pointer(obj))
}
func (i *InstanceMethod) c() *C.PyInstanceMethodObject {
return (*C.PyInstanceMethodObject)(unsafe.Pointer(i))
}
// Base returns a BaseObject pointer that gives access to the generic methods on
// that type for this object.
func (i *InstanceMethod) Base() *BaseObject {
return (*BaseObject)(unsafe.Pointer(i))
}
// Type returns a pointer to the Type that represents the type of this object in
// Python.
func (i *InstanceMethod) Type() *Type {
return newType(c(i).ob_type)
}
// Decref decrements i's reference count, i may not be nil.
func (i *InstanceMethod) Decref() {
obj := (*C.PyObject)(unsafe.Pointer(i))
refcnt := (*int)(unsafe.Pointer(&obj.anon0[0]))
if *refcnt == C._Py_IMMORTAL_REFCNT {
return
}
*refcnt--
if *refcnt == 0 {
C._Py_Dealloc(obj)
}
}
// Incref increments i's reference count, i may not be nil.
func (i *InstanceMethod) Incref() {
refcnt := (*int)(unsafe.Pointer(&(*C.PyObject)(unsafe.Pointer(i)).anon0[0]))
if *refcnt == C._Py_IMMORTAL_REFCNT {
return
}
*refcnt++
}
// Repr returns a String representation of "i". This is equivalent to the
// Python "repr(i)".
//
// Return value: New Reference.
func (i *InstanceMethod) Repr() (*Unicode, error) {
ret := C.PyObject_Repr(c(i))
if ret == nil {
return nil, exception()
}
return newObject(ret).(*Unicode), nil
}
// Call calls i with the given args and kwds. kwds may be nil, args may not
// (an empty Tuple must be used if no arguments are wanted). Returns the result
// of the call, or an Error on failure. This is equivalent to
// "i(*args, **kwds)" in Python.
//
// Return value: New Reference.
func (i *InstanceMethod) Call(args *Tuple, kwds *Dict) (Object, error) {
ret := C.PyObject_Call(c(i), c(args), c(kwds))
return obj2ObjErr(ret)
}
// CallGo calls i with the given args and kwds, either may be nil. Returns the
// result of the call, or an Error on failure. This is equivalent to
// "i(*args, **kwds)" in Python.
//
// The values are converted to Objects using NewValue. A TypeError will be
// returned if a value cannot be converted.
//
// Return value: New Reference.
func (i *InstanceMethod) CallGo(args []any, kwds map[string]any) (Object, error) {
obj1, err := NewTupleFromValues(args...)
if err != nil {
return nil, err
}
defer obj1.Decref()
obj2, err := NewDictFromValuesString(kwds)
if err != nil {
return nil, err
}
defer obj2.Decref()
ret := C.PyObject_Call(c(i), c(obj1), c(obj2))
return obj2ObjErr(ret)
}
// HasAttr returns true if "i" has the attribute "name". This is equivalent
// to the Python "hasattr(i, name)".
func (i *InstanceMethod) HasAttr(name Object) bool {
ret := C.PyObject_HasAttr(c(i), c(name))
return ret == 1
}
// GetAttr returns the attribute of "i" with the name "name". This is
// equivalent to the Python "i.name".
//
// Return value: New Reference.
func (i *InstanceMethod) GetAttr(name Object) (Object, error) {
ret := C.PyObject_GetAttr(c(i), c(name))
return obj2ObjErr(ret)
}
// SetAttr sets the attribute of "i" with the name "name" to "value". This is
// equivalent to the Python "i.name = value".
func (i *InstanceMethod) SetAttr(name, value Object) error {
ret := C.PyObject_SetAttr(c(i), c(name), c(value))
return int2Err(ret)
}
// DelAttr deletes the attribute with the name "name" from "i". This is
// equivalent to the Python "del i.name".
func (i *InstanceMethod) DelAttr(name, value Object) error {
ret := C.PyObject_SetAttr(c(i), c(name), nil)
return int2Err(ret)
}
// RichCompare compares "i" with "obj" using the specified operation (LE, GE
// etc.), and returns the result. The equivalent Python is "i op obj", where
// op is the corresponding Python operator for op.
//
// Return value: New Reference.
func (i *InstanceMethod) RichCompare(obj Object, op Op) (Object, error) {
ret := C.PyObject_RichCompare(c(i), c(obj), C.int(op))
return obj2ObjErr(ret)
}
// RichCompare compares "i" with "obj" using the specified operation (LE, GE
// etc.), and returns true or false. The equivalent Python is "i op obj",
// where op is the corresponding Python operator for op.
func (i *InstanceMethod) RichCompareBool(obj Object, op Op) (bool, error) {
ret := C.PyObject_RichCompareBool(c(i), c(obj), C.int(op))
return int2BoolErr(ret)
}
/*
set fields:
ob_base
tp_basicsize
tp_call
tp_dealloc
tp_descr_get
tp_doc
tp_flags
tp_getattro
tp_getset
tp_members
tp_name
tp_new
tp_repr
tp_richcompare
tp_setattro
tp_traverse
*/