This repository has been archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytes.go
58 lines (47 loc) · 1.77 KB
/
bytes.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
package gocpy
/*
#include "Python.h"
#include "macro.h"
*/
import "C"
import "unsafe"
//Bytes : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Type
var Bytes = togo((*C.PyObject)(unsafe.Pointer(&C.PyBytes_Type)))
//PyBytes_Check : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Check
func PyBytes_Check(o *PyObject) bool {
return C._go_PyBytes_Check(toc(o)) != 0
}
//PyBytes_CheckExact : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_CheckExact
func PyBytes_CheckExact(o *PyObject) bool {
return C._go_PyBytes_CheckExact(toc(o)) != 0
}
//PyBytes_FromString : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_FromString
func PyBytes_FromString(str string) *PyObject {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
return togo(C.PyBytes_FromString(cstr))
}
//PyBytes_FromObject : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_FromObject
func PyBytes_FromObject(o *PyObject) *PyObject {
return togo(C.PyBytes_FromObject(toc(o)))
}
//PyBytes_Size : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Size
func PyBytes_Size(o *PyObject) int {
return int(C.PyBytes_Size(toc(o)))
}
//PyBytes_AsString : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString
func PyBytes_AsString(o *PyObject) string {
return C.GoStringN(C.PyBytes_AsString(toc(o)), C.int(C.PyBytes_Size(toc(o))))
}
//PyBytes_Concat : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Concat
func PyBytes_Concat(bytes, newpart *PyObject) *PyObject {
cbytes := toc(bytes)
C.PyBytes_Concat(&cbytes, toc(newpart))
return togo(cbytes)
}
//PyBytes_ConcatAndDel : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_ConcatAndDel
func PyBytes_ConcatAndDel(bytes, newpart *PyObject) *PyObject {
cbytes := toc(bytes)
C.PyBytes_ConcatAndDel(&cbytes, toc(newpart))
return togo(cbytes)
}