static int tns_render_unicode(const tns_ops *ops, void *val, tns_outbuf *outbuf) { PyObject *bytes; char* encoding = ((tns_ops_with_encoding*)ops)->encoding; if(PyUnicode_Check(val)) { bytes = PyUnicode_Encode(PyUnicode_AS_UNICODE(val), PyUnicode_GET_SIZE(val), encoding, NULL); if(bytes == NULL) { return -1; } if(tns_render_string(ops, bytes, outbuf) == -1) { return -1; } Py_DECREF(bytes); return 0; } if(PyString_Check(val)) { return tns_render_string(ops, val, outbuf); } return -1; }
static inline int tns_render_number(void *val, tns_outbuf *outbuf) { PyObject *string; if(PyFloat_Check((PyObject*)val)) { string = PyObject_Repr(val); } else { string = PyObject_Str(val); } if(string == NULL) { return -1; } return tns_render_string(string, outbuf); }
static int tns_render_float(const tns_ops *ops, void *val, tns_outbuf *outbuf) { PyObject *string; int res = 0; string = PyObject_Repr(val); if(string == NULL) { return -1; } res = tns_render_string(ops, string, outbuf); Py_DECREF(string); return res; }