Commit cd6298fb authored by Manuel Günther's avatar Manuel Günther
Browse files

Fixed Py3 issues with __repr__ functions

parent 68200670
......@@ -306,19 +306,7 @@ static PyMethodDef PyBoostBinomial_methods[] = {
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static PyObject* scalar_to_bytes(PyObject* s) {
if (!s) return s;
# if PY_VERSION_HEX >= 0x03000000
PyObject* b = PyObject_Bytes(s);
# else
PyObject* b = PyObject_Str(s);
# endif
Py_DECREF(s);
return b;
}
extern PyObject* scalar_to_bytes(PyObject* s);
/**
* String representation and print out
......
......@@ -341,12 +341,6 @@ static PyMethodDef PyBoostDiscrete_methods[] = {
};
#if PY_VERSION_HEX >= 0x03000000
# define PYOBJECT_STR PyObject_Str
#else
# define PYOBJECT_STR PyObject_Unicode
#endif
/**
* String representation and print out
*/
......@@ -355,26 +349,16 @@ static PyObject* PyBoostDiscrete_Repr(PyBoostDiscreteObject* self) {
PyObject* probabilities = PyBoostDiscrete_GetProbabilities(self);
if (!probabilities) return 0;
auto probabilities_ = make_safe(probabilities);
PyObject* prob_str = PYOBJECT_STR(probabilities);
PyObject* prob_str = PyObject_Str(probabilities);
if (!prob_str) return 0;
auto prob_str_ = make_safe(prob_str);
PyObject* retval = PyUnicode_FromFormat(
return PyString_FromFormat(
"%s(dtype='%s' , probabilities=%U)",
Py_TYPE(self)->tp_name,
PyBlitzArray_TypenumAsString(self->type_num),
prob_str
);
#if PYTHON_VERSION_HEX < 0x03000000
if (!retval) return 0;
PyObject* tmp = PyObject_Str(retval);
Py_DECREF(retval);
retval = tmp;
#endif
return retval;
}
PyTypeObject PyBoostDiscrete_Type = {
......
......@@ -264,19 +264,7 @@ static PyMethodDef PyBoostGamma_methods[] = {
{0} /* Sentinel */
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static PyObject* scalar_to_bytes(PyObject* s) {
if (!s) return s;
# if PY_VERSION_HEX >= 0x03000000
PyObject* b = PyObject_Bytes(s);
# else
PyObject* b = PyObject_Str(s);
# endif
Py_DECREF(s);
return b;
}
extern PyObject* scalar_to_bytes(PyObject* s);
/**
* String representation and print out
......
......@@ -303,19 +303,7 @@ static PyMethodDef PyBoostLogNormal_methods[] = {
{0} /* Sentinel */
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static PyObject* scalar_to_bytes(PyObject* s) {
if (!s) return s;
# if PY_VERSION_HEX >= 0x03000000
PyObject* b = PyObject_Bytes(s);
# else
PyObject* b = PyObject_Str(s);
# endif
Py_DECREF(s);
return b;
}
extern PyObject* scalar_to_bytes(PyObject* s);
/**
* String representation and print out
......
......@@ -18,6 +18,18 @@ static PyMethodDef module_methods[] = {
{0} /* Sentinel */
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
* This function will be used in the bindings of all Boost classes
*/
PyObject* scalar_to_bytes(PyObject* s) {
if (!s) return s;
auto s_ = make_safe(s);
PyObject* b = PyObject_Str(s);
return b;
}
PyDoc_STRVAR(module_docstr,
"boost::random classes and methods"
);
......
......@@ -301,19 +301,7 @@ static PyMethodDef PyBoostNormal_methods[] = {
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static PyObject* scalar_to_bytes(PyObject* s) {
if (!s) return s;
# if PY_VERSION_HEX >= 0x03000000
PyObject* b = PyObject_Bytes(s);
# else
PyObject* b = PyObject_Str(s);
# endif
Py_DECREF(s);
return b;
}
extern PyObject* scalar_to_bytes(PyObject* s);
/**
* String representation and print out
......
......@@ -492,20 +492,8 @@ static PyMethodDef PyBoostUniform_methods[] = {
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static PyObject* scalar_to_bytes(PyObject* s) {
if (!s) return s;
# if PY_VERSION_HEX >= 0x03000000
PyObject* b = PyObject_Bytes(s);
# else
PyObject* b = PyObject_Str(s);
# endif
Py_DECREF(s);
return b;
}
extern PyObject* scalar_to_bytes(PyObject* s);
/**
* String representation and print out
......
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