diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-01-21 10:21:16 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:12:54 -0300 |
commit | b18a0f63b93a6ad9f047d10408d98d0fb548919d (patch) | |
tree | 148a8930207961cc11fb9f451dcb1a74e64b71c0 /libshiboken/sbkenum.cpp | |
parent | ea66e79f338202f473bc1e95e21c126bbb63756a (diff) |
Shiboken enums now have a tp_print representation.
This fixes the bug #611[1], and an unit test was also added.
[1] http://bugs.openbossa.org/show_bug.cgi?id=611
Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Reviewed by Renato Araújo <renato.filho@openbossa.org>
Diffstat (limited to 'libshiboken/sbkenum.cpp')
-rw-r--r-- | libshiboken/sbkenum.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libshiboken/sbkenum.cpp b/libshiboken/sbkenum.cpp index 34a4b7729..7aea88ad2 100644 --- a/libshiboken/sbkenum.cpp +++ b/libshiboken/sbkenum.cpp @@ -36,14 +36,27 @@ struct SbkEnumObject PyObject* ob_name; }; +#define SBKENUMOBJECT_REPR_STRING "<enum-item %s.%s (%ld)>" + static PyObject* SbkEnumObject_repr(PyObject* self) { - return PyString_FromFormat("<enum-item %s.%s (%ld)>", + return PyString_FromFormat(SBKENUMOBJECT_REPR_STRING, self->ob_type->tp_name, PyString_AS_STRING(((SbkEnumObject*)self)->ob_name), ((SbkEnumObject*)self)->ob_ival); } +static int SbkEnumObject_print(PyObject* self, FILE* fp, int) +{ + Py_BEGIN_ALLOW_THREADS + fprintf(fp, SBKENUMOBJECT_REPR_STRING, + self->ob_type->tp_name, + PyString_AS_STRING(((SbkEnumObject*)self)->ob_name), + ((SbkEnumObject*)self)->ob_ival); + Py_END_ALLOW_THREADS + return 0; +} + static PyObject* SbkEnumObject_name(PyObject* self, void*) { Py_INCREF(((SbkEnumObject*)self)->ob_name); @@ -169,6 +182,7 @@ PyTypeObject* newType(const char* name) ::memset(type, 0, sizeof(PyTypeObject)); type->ob_type = &SbkEnumType_Type; type->tp_basicsize = sizeof(SbkEnumObject); + type->tp_print = &SbkEnumObject_print; type->tp_repr = &SbkEnumObject_repr; type->tp_str = &SbkEnumObject_repr; type->tp_flags = Py_TPFLAGS_DEFAULT; |