summaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-10-11 18:58:01 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-12-09 20:28:06 -0300
commit9bc3d8b776c00850391918ff03c376217e188a63 (patch)
tree8465d1cf7087d441573cadd2168dfbbcbbbd3310 /libshiboken
parentcd2cc9407e7849aeb21654d61a9e70fa6c18bc16 (diff)
downloadshiboken-9bc3d8b776c00850391918ff03c376217e188a63.tar.gz
shiboken-9bc3d8b776c00850391918ff03c376217e188a63.tar.xz
shiboken-9bc3d8b776c00850391918ff03c376217e188a63.zip
Shiboken's enums now have converters.
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/sbkenum.cpp39
-rw-r--r--libshiboken/sbkenum.h8
-rw-r--r--libshiboken/sbkenum_p.h38
3 files changed, 79 insertions, 6 deletions
diff --git a/libshiboken/sbkenum.cpp b/libshiboken/sbkenum.cpp
index 554618db..5810a41c 100644
--- a/libshiboken/sbkenum.cpp
+++ b/libshiboken/sbkenum.cpp
@@ -22,6 +22,8 @@
#include "sbkenum.h"
#include "sbkstring.h"
+#include "sbkenum_p.h"
+#include "sbkconverter.h"
#include "basewrapper.h"
#include "sbkdbg.h"
#include "autodecref.h"
@@ -290,12 +292,15 @@ static PyNumberMethods enum_as_number = {
/* nb_index */ enum_int
};
+static void SbkEnumTypeDealloc(PyObject* pyObj);
+static PyObject* SbkEnumTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds);
+
PyTypeObject SbkEnumType_Type = {
PyVarObject_HEAD_INIT(0, 0)
/*tp_name*/ "Shiboken.EnumType",
- /*tp_basicsize*/ sizeof(PyTypeObject),
+ /*tp_basicsize*/ sizeof(SbkEnumType),
/*tp_itemsize*/ 0,
- /*tp_dealloc*/ 0,
+ /*tp_dealloc*/ SbkEnumTypeDealloc,
/*tp_print*/ 0,
/*tp_getattr*/ 0,
/*tp_setattr*/ 0,
@@ -327,9 +332,9 @@ PyTypeObject SbkEnumType_Type = {
/*tp_descr_set*/ 0,
/*tp_dictoffset*/ 0,
/*tp_init*/ 0,
- /*tp_alloc*/ 0,
- /*tp_new*/ PyType_GenericNew,
- /*tp_free*/ 0,
+ /*tp_alloc*/ PyType_GenericAlloc,
+ /*tp_new*/ SbkEnumTypeTpNew,
+ /*tp_free*/ PyObject_GC_Del,
/*tp_is_gc*/ 0,
/*tp_bases*/ 0,
/*tp_mro*/ 0,
@@ -338,6 +343,30 @@ PyTypeObject SbkEnumType_Type = {
/*tp_weaklist*/ 0
};
+void SbkEnumTypeDealloc(PyObject* pyObj)
+{
+ SbkEnumType* sbkType = reinterpret_cast<SbkEnumType*>(pyObj);
+
+ PyObject_GC_UnTrack(pyObj);
+ Py_TRASHCAN_SAFE_BEGIN(pyObj);
+ if (sbkType->d) {
+ Shiboken::Conversions::deleteConverter(sbkType->d->converter);
+ delete sbkType->d;
+ sbkType->d = 0;
+ }
+ Py_TRASHCAN_SAFE_END(pyObj);
+}
+
+PyObject* SbkEnumTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds)
+{
+ SbkEnumType* newType = reinterpret_cast<SbkEnumType*>(PyType_Type.tp_new(metatype, args, kwds));
+ if (!newType)
+ return 0;
+ newType->d = new SbkEnumTypePrivate;
+ memset(newType->d, 0, sizeof(SbkEnumTypePrivate));
+ return reinterpret_cast<PyObject*>(newType);
+}
+
} // extern "C"
namespace Shiboken {
diff --git a/libshiboken/sbkenum.h b/libshiboken/sbkenum.h
index d6456a91..19250b4e 100644
--- a/libshiboken/sbkenum.h
+++ b/libshiboken/sbkenum.h
@@ -32,6 +32,13 @@ extern "C"
extern LIBSHIBOKEN_API PyTypeObject SbkEnumType_Type;
struct SbkObjectType;
+struct SbkEnumTypePrivate;
+struct LIBSHIBOKEN_API SbkEnumType
+{
+ PyHeapTypeObject super;
+ SbkEnumTypePrivate* d;
+};
+
} // extern "C"
namespace Shiboken
@@ -93,4 +100,3 @@ namespace Enum
} // namespace Shiboken
#endif // SKB_PYENUM_H
-
diff --git a/libshiboken/sbkenum_p.h b/libshiboken/sbkenum_p.h
new file mode 100644
index 00000000..c173f0b7
--- /dev/null
+++ b/libshiboken/sbkenum_p.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the Shiboken Python Bindings Generator project.
+ *
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * Contact: PySide team <contact@pyside.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SBKENUM_P_H
+#define SBKENUM_P_H
+
+struct SbkConverter;
+
+extern "C"
+{
+
+struct SbkEnumTypePrivate
+{
+ SbkConverter* converter;
+};
+
+} // extern "C"
+
+#endif // SKB_PYENUM_P_H