forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dict.go
142 lines (114 loc) · 4.38 KB
/
dict.go
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
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the $license_for_repo License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
package python3
/*
#include "Python.h"
#include "macro.h"
*/
import "C"
import (
"unsafe"
)
//Dict : https://docs.python.org/3/c-api/dict.html#c.PyDict_Type
var Dict = togo((*C.PyObject)(unsafe.Pointer(&C.PyDict_Type)))
//PyDict_Check : https://docs.python.org/3/c-api/dict.html#c.PyDict_Check
func PyDict_Check(p *PyObject) bool {
return C._go_PyDict_Check(toc(p)) != 0
}
//PyDict_CheckExact : https://docs.python.org/3/c-api/dict.html#c.PyDict_CheckExact
func PyDict_CheckExact(p *PyObject) bool {
return C._go_PyDict_CheckExact(toc(p)) != 0
}
//PyDict_New : https://docs.python.org/3/c-api/dict.html#c.PyDict_New
func PyDict_New() *PyObject {
return togo(C.PyDict_New())
}
//PyDictProxy_New : https://docs.python.org/3/c-api/dict.html#c.PyDictProxy_New
func PyDictProxy_New(mapping *PyObject) *PyObject {
return togo(C.PyDictProxy_New(toc(mapping)))
}
//PyDict_Clear : https://docs.python.org/3/c-api/dict.html#c.PyDict_Clear
func PyDict_Clear(p *PyObject) {
C.PyDict_Clear(toc(p))
}
//PyDict_Contains : https://docs.python.org/3/c-api/dict.html#c.PyDict_Contains
func PyDict_Contains(p, key *PyObject) int {
return int(C.PyDict_Contains(toc(p), toc(key)))
}
//PyDict_Copy : https://docs.python.org/3/c-api/dict.html#c.PyDict_Copy
func PyDict_Copy(p *PyObject) *PyObject {
return togo(C.PyDict_Copy(toc(p)))
}
//PyDict_SetItem : https://docs.python.org/3/c-api/dict.html#c.PyDict_SetItem
func PyDict_SetItem(p, key, val *PyObject) int {
return int(C.PyDict_SetItem(toc(p), toc(key), toc(val)))
}
//PyDict_SetItemString : https://docs.python.org/3/c-api/dict.html#c.PyDict_SetItemString
func PyDict_SetItemString(p *PyObject, key string, val *PyObject) int {
ckey := C.CString(key)
defer C.free(unsafe.Pointer(ckey))
return int(C.PyDict_SetItemString(toc(p), ckey, toc(val)))
}
//PyDict_DelItem : https://docs.python.org/3/c-api/dict.html#c.PyDict_DelItem
func PyDict_DelItem(p, key *PyObject) int {
return int(C.PyDict_DelItem(toc(p), toc(key)))
}
//PyDict_DelItemString : https://docs.python.org/3/c-api/dict.html#c.PyDict_DelItemString
func PyDict_DelItemString(p *PyObject, key string) int {
ckey := C.CString(key)
defer C.free(unsafe.Pointer(ckey))
return int(C.PyDict_DelItemString(toc(p), ckey))
}
//PyDict_GetItem : https://docs.python.org/3/c-api/dict.html#c.PyDict_GetItem
func PyDict_GetItem(p, key *PyObject) *PyObject {
return togo(C.PyDict_GetItem(toc(p), toc(key)))
}
//PyDict_GetItemWithError : https://docs.python.org/3/c-api/dict.html#c.PyDict_GetItemWithError
func PyDict_GetItemWithError(p, key *PyObject) *PyObject {
return togo(C.PyDict_GetItemWithError(toc(p), toc(key)))
}
//PyDict_GetItemString : https://docs.python.org/3/c-api/dict.html#c.PyDict_GetItemString
func PyDict_GetItemString(p *PyObject, key string) *PyObject {
ckey := C.CString(key)
defer C.free(unsafe.Pointer(ckey))
return togo(C.PyDict_GetItemString(toc(p), ckey))
}
//PyDict_SetDefault : https://docs.python.org/3/c-api/dict.html#c.PyDict_SetDefault
func PyDict_SetDefault(p, key, pyDefault *PyObject) *PyObject {
return togo(C.PyDict_SetDefault(toc(p), toc(key), toc(pyDefault)))
}
//PyDict_Items : https://docs.python.org/3/c-api/dict.html#c.PyDict_Items
func PyDict_Items(p *PyObject) *PyObject {
return togo(C.PyDict_Items(toc(p)))
}
//PyDict_Keys : https://docs.python.org/3/c-api/dict.html#c.PyDict_Keys
func PyDict_Keys(p *PyObject) *PyObject {
return togo(C.PyDict_Keys(toc(p)))
}
//PyDict_Values : https://docs.python.org/3/c-api/dict.html#c.PyDict_Values
func PyDict_Values(p *PyObject) *PyObject {
return togo(C.PyDict_Values(toc(p)))
}
//PyDict_Size : https://docs.python.org/3/c-api/dict.html#c.PyDict_Size
func PyDict_Size(p *PyObject) int {
return int(C.PyDict_Size(toc(p)))
}
//PyDict_Next : https://docs.python.org/3/c-api/dict.html#c.PyDict_Next
func PyDict_Next(p *PyObject, ppos *int, pkey, pvalue **PyObject) bool {
cpos := C.Py_ssize_t(*ppos)
ckey := toc(*pkey)
cvalue := toc(*pvalue)
res := C.PyDict_Next(toc(p), &cpos, &ckey, &cvalue) != 0
*ppos = int(cpos)
*pkey = togo(ckey)
*pvalue = togo(cvalue)
return res
}
//PyDict_ClearFreeList : https://docs.python.org/3/c-api/dict.html#c.PyDict_ClearFreeList
func PyDict_ClearFreeList() int {
return int(C.PyDict_ClearFreeList())
}