forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 50
/
integer.go
142 lines (115 loc) · 4.85 KB
/
integer.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 MIT 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"
)
//Long : https://docs.python.org/3/c-api/long.html#c.PyLong_Type
var Long = togo((*C.PyObject)(unsafe.Pointer(&C.PyLong_Type)))
//PyLong_Check : https://docs.python.org/3/c-api/long.html#c.PyLong_Check
func PyLong_Check(p *PyObject) bool {
return C._go_PyLong_Check(toc(p)) != 0
}
//PyLong_CheckExact : https://docs.python.org/3/c-api/long.html#c.PyLong_CheckExact
func PyLong_CheckExact(p *PyObject) bool {
return C._go_PyLong_CheckExact(toc(p)) != 0
}
//PyLong_FromLong : https://docs.python.org/3/c-api/long.html#c.PyLong_FromLong
func PyLong_FromLong(v int) *PyObject {
return togo(C.PyLong_FromLong(C.long(v)))
}
//PyLong_FromUnsignedLong : https://docs.python.org/3/c-api/long.html#c.PyLong_FromUnsignedLong
func PyLong_FromUnsignedLong(v uint) *PyObject {
return togo(C.PyLong_FromUnsignedLong(C.ulong(v)))
}
//PyLong_FromLongLong : https://docs.python.org/3/c-api/long.html#c.PyLong_FromLongLong
func PyLong_FromLongLong(v int64) *PyObject {
return togo(C.PyLong_FromLongLong(C.longlong(v)))
}
//PyLong_FromUnsignedLongLong : https://docs.python.org/3/c-api/long.html#c.PyLong_FromUnsignedLongLong
func PyLong_FromUnsignedLongLong(v uint64) *PyObject {
return togo(C.PyLong_FromUnsignedLongLong(C.ulonglong(v)))
}
//PyLong_FromDouble : https://docs.python.org/3/c-api/long.html#c.PyLong_FromDouble
func PyLong_FromDouble(v float64) *PyObject {
return togo(C.PyLong_FromDouble(C.double(v)))
}
//PyLong_FromString : https://docs.python.org/3/c-api/long.html#c.PyLong_FromString
func PyLong_FromString(str string, base int) *PyObject {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
return togo(C.PyLong_FromString(cstr, nil, C.int(base)))
}
//PyLong_FromUnicodeObject : https://docs.python.org/3/c-api/long.html#c.PyLong_FromUnicodeObject
func PyLong_FromUnicodeObject(u *PyObject, base int) *PyObject {
return togo(C.PyLong_FromUnicodeObject(toc(u), C.int(base)))
}
//PyLong_FromGoInt ensures the go integer type does not overflow
func PyLong_FromGoInt(v int) *PyObject {
return togo(C.PyLong_FromLongLong(C.longlong(v)))
}
//PyLong_FromGoUint ensures the go integer type does not overflow
func PyLong_FromGoUint(v uint) *PyObject {
return togo(C.PyLong_FromUnsignedLongLong(C.ulonglong(v)))
}
//PyLong_FromGoInt64 ensures the go integer type does not overflow
func PyLong_FromGoInt64(v int64) *PyObject {
return togo(C.PyLong_FromLongLong(C.longlong(v)))
}
//PyLong_FromGoUint64 ensures the go integer type does not overflow
func PyLong_FromGoUint64(v uint64) *PyObject {
return togo(C.PyLong_FromUnsignedLongLong(C.ulonglong(v)))
}
//PyLong_FromGoFloat64 ensures the go integer type does not overflow
func PyLong_FromGoFloat64(v float64) *PyObject {
return togo(C.PyLong_FromDouble(C.double(v)))
}
//PyLong_AsLong : https://docs.python.org/3/c-api/long.html#c.PyLong_AsLong
func PyLong_AsLong(obj *PyObject) int {
return int(C.PyLong_AsLong(toc(obj)))
}
//PyLong_AsLongAndOverflow : https://docs.python.org/3/c-api/long.html#c.PyLong_AsLongAndOverflow
func PyLong_AsLongAndOverflow(obj *PyObject) (int, int) {
overflow := C.int(0)
ret := C.PyLong_AsLongAndOverflow(toc(obj), &overflow)
return int(ret), int(overflow)
}
//PyLong_AsLongLong : https://docs.python.org/3/c-api/long.html#c.PyLong_AsLongLong
func PyLong_AsLongLong(obj *PyObject) int64 {
return int64(C.PyLong_AsLongLong(toc(obj)))
}
//PyLong_AsLongLongAndOverflow : https://docs.python.org/3/c-api/long.html#c.PyLong_AsLongLongAndOverflow
func PyLong_AsLongLongAndOverflow(obj *PyObject) (int64, int) {
overflow := C.int(0)
ret := C.PyLong_AsLongLongAndOverflow(toc(obj), &overflow)
return int64(ret), int(overflow)
}
//PyLong_AsUnsignedLong : https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLong
func PyLong_AsUnsignedLong(obj *PyObject) uint {
return uint(C.PyLong_AsUnsignedLong(toc(obj)))
}
//PyLong_AsUnsignedLongLong : https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLongLong
func PyLong_AsUnsignedLongLong(obj *PyObject) uint64 {
return uint64(C.PyLong_AsUnsignedLongLong(toc(obj)))
}
//PyLong_AsUnsignedLongMask : https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLongMask
func PyLong_AsUnsignedLongMask(obj *PyObject) uint {
return uint(C.PyLong_AsUnsignedLongMask(toc(obj)))
}
//PyLong_AsUnsignedLongLongMask : https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLongLongMask
func PyLong_AsUnsignedLongLongMask(obj *PyObject) uint64 {
return uint64(C.PyLong_AsUnsignedLongLongMask(toc(obj)))
}
//PyLong_AsDouble : https://docs.python.org/3/c-api/long.html#c.PyLong_AsDouble
func PyLong_AsDouble(obj *PyObject) float64 {
return float64(C.PyLong_AsDouble(toc(obj)))
}