This repository was archived by the owner on Jan 20, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change 4
4
PyObject * red (PyObject * );
5
5
6
6
/* To shim go's missing variadic function support */
7
- int PyArg_ParseTuple_U (PyObject * args , PyObject * * obj ) {
8
- return PyArg_ParseTuple (args , "U " , obj );
7
+ int PyArg_ParseTuple_s (PyObject * args , char * * obj ) {
8
+ return PyArg_ParseTuple (args , "s " , obj );
9
9
}
10
10
11
11
static struct PyMethodDef methods [] = {
Original file line number Diff line number Diff line change @@ -2,25 +2,22 @@ package main
2
2
3
3
// #include <stdlib.h>
4
4
// #include <Python.h>
5
- // int PyArg_ParseTuple_U (PyObject*, PyObject **);
5
+ // int PyArg_ParseTuple_s (PyObject*, char **);
6
6
import "C"
7
7
import "unsafe"
8
8
import "github.com/mgutz/ansi"
9
9
10
10
//export red
11
11
func red (self * C.PyObject , args * C.PyObject ) * C.PyObject {
12
- var obj * C.PyObject
13
- if C .PyArg_ParseTuple_U (args , & obj ) == 0 {
12
+ var cstr * C.char
13
+ if C .PyArg_ParseTuple_s (args , & cstr ) == 0 {
14
14
return nil
15
15
}
16
- bytes := C .PyUnicode_AsUTF8String (obj )
17
- cstr := C .PyBytes_AsString (bytes )
18
16
red := ansi .Color (C .GoString (cstr ), "red" )
19
- cstr = C .CString (red )
20
- ret := C .PyUnicode_FromString (cstr )
21
17
22
- C .free (unsafe .Pointer (cstr ))
23
- C .Py_DecRef (bytes )
18
+ gocstr := C .CString (red )
19
+ ret := C .PyUnicode_FromString (gocstr )
20
+ C .free (unsafe .Pointer (gocstr ))
24
21
25
22
return ret
26
23
}
You can’t perform that action at this time.
0 commit comments