Skip to content

Commit 2bb6a64

Browse files
committed
bindings: Fix random cryptic Python UnicodeDecodeErrors
If any of the python type wrapper functions are marked static, Python will randomly emit a cryptic UnicodeDecodeError when trying to import the resulting .so: Traceback (most recent call last): File "<python-input-0>", line 1, in <module> from bindings.python.lib import c_ray File "/home/vkoskiv/c-ray/bindings/python/lib/c_ray.py", line 5, in <module> from . import cray_wrap as _lib UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position 0: invalid start byte I haven't got the faintest clue why this happens, but this fix seems to work, at least for now.
1 parent dc2e013 commit 2bb6a64

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

bindings/python/py_types.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static PyMemberDef py_vector_members[] = {
1717
};
1818

1919
/*
20-
WTF. If I mark this specific function as static, Python throws a bizarre UnicodeDecodeError when trying to import the .so:
20+
WTF. If I mark these functions as static, Python randomly throws bizarre UnicodeDecodeErrors when trying to import the .so:
2121
Traceback (most recent call last):
2222
File "<python-input-0>", line 1, in <module>
2323
from bindings.python.lib import c_ray
@@ -30,7 +30,7 @@ Py_ssize_t py_vector_length(PyObject *o) {
3030
return 3;
3131
}
3232

33-
static PyObject *py_vector_subscript(PyObject *o, PyObject *key) {
33+
PyObject *py_vector_subscript(PyObject *o, PyObject *key) {
3434
py_vector *self = (py_vector *)o;
3535
if (PyLong_Check(key)) {
3636
long index = PyLong_AsLong(key);
@@ -63,7 +63,7 @@ static PyObject *py_vector_subscript(PyObject *o, PyObject *key) {
6363
return NULL;
6464
}
6565

66-
static int py_vector_ass_subscript(PyObject *o, PyObject *key, PyObject *value) {
66+
int py_vector_ass_subscript(PyObject *o, PyObject *key, PyObject *value) {
6767
py_vector *self = (py_vector *)o;
6868
if (PyLong_Check(key)) {
6969
long index = PyLong_AsLong(key);
@@ -84,7 +84,7 @@ static int py_vector_ass_subscript(PyObject *o, PyObject *key, PyObject *value)
8484
return -1;
8585
}
8686

87-
static PyMappingMethods py_vector_mapping_methods = {
87+
PyMappingMethods py_vector_mapping_methods = {
8888
.mp_length = py_vector_length,
8989
.mp_subscript = py_vector_subscript,
9090
.mp_ass_subscript = py_vector_ass_subscript,
@@ -102,17 +102,17 @@ PyTypeObject type_py_vector = {
102102
.tp_as_mapping = &py_vector_mapping_methods,
103103
};
104104

105-
static PyMemberDef py_coord_members[] = {
105+
PyMemberDef py_coord_members[] = {
106106
{ "u", T_FLOAT, offsetof(py_coord, val.u), 0, "u" },
107107
{ "v", T_FLOAT, offsetof(py_coord, val.v), 0, "v" },
108108
};
109109

110-
static Py_ssize_t py_coord_length(PyObject *o) {
110+
Py_ssize_t py_coord_length(PyObject *o) {
111111
(void)o;
112112
return 2;
113113
}
114114

115-
static PyObject *py_coord_subscript(PyObject *o, PyObject *key) {
115+
PyObject *py_coord_subscript(PyObject *o, PyObject *key) {
116116
py_coord *self = (py_coord *)o;
117117
if (PyLong_Check(key)) {
118118
long index = PyLong_AsLong(key);
@@ -145,7 +145,7 @@ static PyObject *py_coord_subscript(PyObject *o, PyObject *key) {
145145
return NULL;
146146
}
147147

148-
static int py_coord_ass_subscript(PyObject *o, PyObject *key, PyObject *value) {
148+
int py_coord_ass_subscript(PyObject *o, PyObject *key, PyObject *value) {
149149
py_coord *self = (py_coord *)o;
150150
if (PyLong_Check(key)) {
151151
long index = PyLong_AsLong(key);
@@ -166,7 +166,7 @@ static int py_coord_ass_subscript(PyObject *o, PyObject *key, PyObject *value) {
166166
return -1;
167167
}
168168

169-
static PyMappingMethods py_coord_mapping_methods = {
169+
PyMappingMethods py_coord_mapping_methods = {
170170
.mp_length = py_coord_length,
171171
.mp_subscript = py_coord_subscript,
172172
.mp_ass_subscript = py_coord_ass_subscript,
@@ -184,7 +184,7 @@ PyTypeObject type_py_coord = {
184184
.tp_as_mapping = &py_coord_mapping_methods,
185185
};
186186

187-
static void py_bitmap_dealloc(py_bitmap *self) {
187+
void py_bitmap_dealloc(py_bitmap *self) {
188188
Py_TYPE(self)->tp_free((PyObject *)self);
189189
}
190190

0 commit comments

Comments
 (0)