sbinet / go-python

naive go bindings to the CPython2 C-API
Other
1.53k stars 138 forks source link

Allow access to python bytearrays as []byte #26

Closed tcriess closed 9 years ago

tcriess commented 9 years ago

With the existing functions I could not find a way to handle python bytearrays that contain zeros - PyByteArray_AsString always cuts the string off at the first zero byte (I guess C.GoString is responsible). Hence I've added the two functions to create []bytes from bytearrays. I'm not sure if that creates a memory leak though.

sbinet commented 9 years ago

LGTM modulo the minor comments above.

thanks!

tcriess commented 9 years ago

Ok, I've changed the docstring and the length type to uint64 + check the given length argument vs. the bytearray length (panic if it is out of range).

sbinet commented 9 years ago

you should keep length as an int. that's what Go uses to index slices.

tcriess commented 9 years ago

Ah, ok. length is back to int (+ check if >= 0)

sbinet commented 9 years ago

thanks.