Skip to content

Instantly share code, notes, and snippets.

@jepler
Created June 3, 2021 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jepler/891799c7dfabc3bfd76e708324a86bd8 to your computer and use it in GitHub Desktop.
Save jepler/891799c7dfabc3bfd76e708324a86bd8 to your computer and use it in GitHub Desktop.
diff --git a/src/hal/halmodule.cc b/src/hal/halmodule.cc
index c4cb1ac2e..5fe1c5d54 100644
--- a/src/hal/halmodule.cc
+++ b/src/hal/halmodule.cc
@@ -90,10 +90,12 @@ bool from_python(PyObject *o, double *d) {
bool from_python(PyObject *o, uint32_t *u) {
PyObject *tmp = 0;
long long l;
+#if !IS_PY3
if(PyInt_Check(o)) {
l = PyInt_AsLong(o);
goto got_value;
}
+#endif
tmp = PyLong_Check(o) ? o : PyNumber_Long(o);
if(!tmp) goto fail;
@@ -101,7 +103,9 @@ bool from_python(PyObject *o, uint32_t *u) {
l = PyLong_AsLongLong(tmp);
if(PyErr_Occurred()) goto fail;
+#if !IS_PY3
got_value:
+#endif
if(l < 0 || l != (uint32_t)l) {
PyErr_Format(PyExc_OverflowError, "Value %lld out of range", l);
goto fail;
@@ -118,10 +122,12 @@ fail:
bool from_python(PyObject *o, int32_t *i) {
PyObject *tmp = 0;
long long l;
+#if !IS_PY3
if(PyInt_Check(o)) {
l = PyInt_AsLong(o);
goto got_value;
}
+#endif
tmp = PyLong_Check(o) ? o : PyNumber_Long(o);
if(!tmp) goto fail;
@@ -129,7 +135,9 @@ bool from_python(PyObject *o, int32_t *i) {
l = PyLong_AsLongLong(tmp);
if(PyErr_Occurred()) goto fail;
+#if 0
got_value:
+#endif
if(l != (int32_t)l) {
PyErr_Format(PyExc_OverflowError, "Value %lld out of range", l);
goto fail;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment