-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.v
82 lines (73 loc) · 2.87 KB
/
object.v
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
module py
pub struct C.PyObject { }
const (
py_not_implemented = &C.PyObject(C.Py_NotImplemented)
)
// Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or Py_GE
pub enum PyRichCompareOp {
lt = C.Py_LT
le = C.Py_LE
eq = C.Py_EQ
ne = C.Py_NE
gt = C.Py_GT
ge = C.Py_GE
}
// object protocol
pub fn C.PyObject_Str(&C.PyObject) &C.PyObject
pub fn C.PyObject_Repr(&C.PyObject) &C.PyObject
pub fn C.PyObject_IsInstance(&C.PyObject, &C.PyObject) int
pub fn C.PyObject_GetAttrString(&C.PyObject, &char) &C.PyObject
pub fn C.PyObject_ASCII(&C.PyObject) &C.PyObject
pub fn C.PyObject_Bytes(&C.PyObject) &C.PyObject
pub fn C.PyObject_RichCompare(&C.PyObject, &C.PyObject, int) &C.PyObject
pub fn C.PyObject_RichCompareBool(&C.PyObject, &C.PyObject, int) int
pub fn C.PyObject_SetAttrString(&C.PyObject, &char, &C.PyObject) int
pub fn C.PyObject_HasAttrString(&C.PyObject, &char) int
pub fn C.PyObject_GetAttr(&C.PyObject, &C.PyObject) &C.PyObject
pub fn C.PyObject_SetAttr(&C.PyObject, &C.PyObject, &C.PyObject) int
pub fn C.PyObject_HasAttr(&C.PyObject, &C.PyObject) int
pub fn C.PyObject_SelfIter(&C.PyObject) &C.PyObject
pub fn C.PyObject_GenericGetAttr(&C.PyObject, &C.PyObject) &C.PyObject
pub fn C.PyObject_GenericSetAttr(&C.PyObject, &C.PyObject, &C.PyObject) int
pub fn C.PyObject_GenericSetDict(&C.PyObject, &C.PyObject, voidptr) int
pub fn C.PyObject_Hash(&C.PyObject) &C.Py_hash_t
pub fn C.PyObject_HashNotImplemented(&C.PyObject) &C.Py_hash_t
pub fn C.PyObject_IsTrue(&C.PyObject) int
pub fn C.PyObject_Not(&C.PyObject) int
// call protcol
pub fn C.PyObject_CallObject(&C.PyObject, &C.PyObject) &C.PyObject
pub fn C.PyObject_CallFunctionObjArgs(&C.PyObject, ...&C.PyObject) &C.PyObject
pub fn C.PyObject_CallMethodObjArgs(&C.PyObject, &C.PyObject, ...&C.PyObject) &C.PyObject
pub fn C.PyObject_CallMethod(&C.PyObject, &char, &char, ...&C.PyObject) &C.PyObject
pub fn C.PyObject_CallMethodNoArgs(&C.PyObject, &C.PyObject) &C.PyObject
[inline]
pub fn py_not_implemented_ret() &C.PyObject {
C.Py_INCREF(C.Py_NotImplemented)
return &C.PyObject(C.Py_NotImplemented)
}
[inline]
pub fn (o &C.PyObject) ptr() voidptr {
return voidptr(o)
}
fn (o &C.PyObject) str() string {
str_p := C.PyObject_Str(o)
$if py_limited_api {
encoded := C.PyUnicode_AsEncodedString(str_p, c'utf-8', c'strict')
str_c := C.PyBytes_AsString(encoded)
return unsafe{cstring_to_vstring(str_c).trim_space()}
} $else {
str_c := C.PyUnicode_AsUTF8(str_p)
return unsafe{cstring_to_vstring(str_c).trim_space()}
}
}
fn (o &C.PyObject) repr() string {
str_p := C.PyObject_Repr(o)
$if py_limited_api {
encoded := C.PyUnicode_AsEncodedString(str_p, c'utf-8', c'strict')
str_c := C.PyBytes_AsString(encoded)
return unsafe{cstring_to_vstring(str_c).trim_space()}
} $else {
str_c := C.PyUnicode_AsUTF8(str_p)
return unsafe{cstring_to_vstring(str_c).trim_space()}
}
}