Use GoStringN inside _AsString functions for bytes as they may contain NULLs

master
Christopher Schmitt 2019-07-22 13:18:28 -06:00 committed by maxime mouial
parent 0b25cc5505
commit 0ae938000d
2 changed files with 2 additions and 2 deletions

View File

@ -52,7 +52,7 @@ func PyByteArray_Size(o *PyObject) int {
//PyByteArray_AsString : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString //PyByteArray_AsString : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString
func PyByteArray_AsString(o *PyObject) string { func PyByteArray_AsString(o *PyObject) string {
return C.GoString(C.PyByteArray_AsString(toc(o))) return C.GoStringN(C.PyByteArray_AsString(toc(o)), C.int(C.PyByteArray_Size(toc(o))))
} }
//PyByteArray_Resize : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Resize //PyByteArray_Resize : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Resize

View File

@ -47,7 +47,7 @@ func PyBytes_Size(o *PyObject) int {
//PyBytes_AsString : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString //PyBytes_AsString : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString
func PyBytes_AsString(o *PyObject) string { func PyBytes_AsString(o *PyObject) string {
return C.GoString(C.PyBytes_AsString(toc(o))) 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 //PyBytes_Concat : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Concat