Skip to content

Commit

Permalink
Return None for .name of enum if no name for value.
Browse files Browse the repository at this point in the history
This fixes segfaults when trying to get the name of a dead key
from a qt key event.

Change-Id: Ie631e2245bca0a3fee8616854f6479d3dec0c2bb
Reviewed-by: Roman Lacko <[email protected]>
Reviewed-by: John Cummings <[email protected]>
  • Loading branch information
jpe authored and jcummings2 committed Jul 12, 2013
1 parent 1d8690a commit fddf371
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libshiboken/sbkenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ static int SbkEnumObject_print(PyObject* self, FILE* fp, int)

static PyObject* SbkEnumObject_name(PyObject* self, void*)
{
Py_INCREF(((SbkEnumObject*)self)->ob_name);
return ((SbkEnumObject*)self)->ob_name;
SbkEnumObject* enum_self = (SbkEnumObject*)self;

if (enum_self->ob_name == NULL)
Py_RETURN_NONE;

Py_INCREF(enum_self->ob_name);
return enum_self->ob_name;
}

static PyObject* SbkEnum_tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
Expand Down
5 changes: 5 additions & 0 deletions tests/samplebinding/enum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def testValue(self):
e = MyEvent()
self.assertEqual(repr(e.eventType()), 'sample.Event.EventType(999)')

def testNoneName(self):
e = MyEvent()
t = e.eventType()
self.assertEqual(t.name, None)

class EnumOverloadTest(unittest.TestCase):
'''Test case for overloads involving enums'''

Expand Down

0 comments on commit fddf371

Please sign in to comment.