Commit 1133c6d5 authored by Stefan Behnel's avatar Stefan Behnel

refactor duplicated code in utility function

parent d82956a9
...@@ -736,10 +736,7 @@ static CYTHON_INLINE int __Pyx_PyByteArray_AppendObject(PyObject* bytearray, PyO ...@@ -736,10 +736,7 @@ static CYTHON_INLINE int __Pyx_PyByteArray_AppendObject(PyObject* bytearray, PyO
ival = 0; ival = 0;
} else { } else {
ival = ((PyLongObject*)value)->ob_digit[0]; ival = ((PyLongObject*)value)->ob_digit[0];
if (unlikely(ival > 255)) { if (unlikely(ival > 255)) goto bad_range;
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
return -1;
}
} }
} else } else
#endif #endif
...@@ -750,11 +747,13 @@ static CYTHON_INLINE int __Pyx_PyByteArray_AppendObject(PyObject* bytearray, PyO ...@@ -750,11 +747,13 @@ static CYTHON_INLINE int __Pyx_PyByteArray_AppendObject(PyObject* bytearray, PyO
if (unlikely((ival < 0) | (ival > 255))) { if (unlikely((ival < 0) | (ival > 255))) {
if (ival == -1 && PyErr_Occurred()) if (ival == -1 && PyErr_Occurred())
return -1; return -1;
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); goto bad_range;
return -1;
} }
} }
return __Pyx_PyByteArray_Append(bytearray, ival); return __Pyx_PyByteArray_Append(bytearray, ival);
bad_range:
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
return -1;
} }
//////////////////// ByteArrayAppend.proto //////////////////// //////////////////// ByteArrayAppend.proto ////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment