aboutsummaryrefslogtreecommitdiffstats
path: root/shibokenmodule
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-12-09 19:00:11 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:18:26 -0300
commitcd110ab3f4f912e2f9e400909f2d3d90abbb9d60 (patch)
treeeca46f03cda305638ee154bba1bca81fbe26f49a /shibokenmodule
parent26e008d9b3135cdeedfb6cd2f36b3369d1fc7c71 (diff)
Implemented PSEP 0106.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Paulo Alcantra <pcacjr@gmail.com>
Diffstat (limited to 'shibokenmodule')
-rw-r--r--shibokenmodule/CMakeLists.txt33
-rw-r--r--shibokenmodule/nothing.h0
-rw-r--r--shibokenmodule/shibokenmodule.txt.in16
-rw-r--r--shibokenmodule/typesystem_shiboken.xml97
4 files changed, 146 insertions, 0 deletions
diff --git a/shibokenmodule/CMakeLists.txt b/shibokenmodule/CMakeLists.txt
new file mode 100644
index 000000000..df5040fdc
--- /dev/null
+++ b/shibokenmodule/CMakeLists.txt
@@ -0,0 +1,33 @@
+project(shibokenmodule)
+
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/shibokenmodule.txt.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/shibokenmodule.txt" @ONLY)
+
+
+set(sample_SRC
+${CMAKE_CURRENT_BINARY_DIR}/shiboken/shiboken_module_wrapper.cpp
+)
+
+add_custom_command(OUTPUT ${sample_SRC}
+COMMAND ${GENERATORRUNNER_BINARY} --project-file=${CMAKE_CURRENT_BINARY_DIR}/shibokenmodule.txt ${GENERATOR_EXTRA_FLAGS}
+WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+COMMENT "Running generator for 'shiboken'..."
+)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}
+ ${SBK_PYTHON_INCLUDE_DIR}
+ ${libshiboken_SOURCE_DIR}
+ ${libshiboken_BINARY_DIR})
+add_library(shibokenmodule MODULE ${sample_SRC})
+set_property(TARGET shibokenmodule PROPERTY PREFIX "")
+set_property(TARGET shibokenmodule PROPERTY OUTPUT_NAME "shiboken")
+if(WIN32)
+ set_property(TARGET shibokenmodule PROPERTY SUFFIX ".pyd")
+endif()
+target_link_libraries(shibokenmodule
+ ${SBK_PYTHON_LIBRARIES}
+ libshiboken)
+
+add_dependencies(shibokenmodule shiboken_generator)
+
diff --git a/shibokenmodule/nothing.h b/shibokenmodule/nothing.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/shibokenmodule/nothing.h
diff --git a/shibokenmodule/shibokenmodule.txt.in b/shibokenmodule/shibokenmodule.txt.in
new file mode 100644
index 000000000..6ef8c4d4c
--- /dev/null
+++ b/shibokenmodule/shibokenmodule.txt.in
@@ -0,0 +1,16 @@
+[generator-project]
+
+generator-set = @generators_BINARY_DIR@/shiboken_generator@CMAKE_RELEASE_POSTFIX@@CMAKE_DEBUG_POSTFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@
+
+header-file = @CMAKE_CURRENT_SOURCE_DIR@/nothing.h
+typesystem-file = @CMAKE_CURRENT_SOURCE_DIR@/typesystem_shiboken.xml
+
+output-directory = @CMAKE_CURRENT_BINARY_DIR@
+
+# include-path = @libsample_SOURCE_DIR@
+
+typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@
+
+avoid-protected-hack
+#enable-parent-ctor-heuristic
+#use-isnull-as-nb_nonzero
diff --git a/shibokenmodule/typesystem_shiboken.xml b/shibokenmodule/typesystem_shiboken.xml
new file mode 100644
index 000000000..e25a450c3
--- /dev/null
+++ b/shibokenmodule/typesystem_shiboken.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" ?>
+<typesystem package="shiboken">
+ <primitive-type name="bool" />
+ <primitive-type name="unsigned long" />
+ <add-function signature="isValid(PyObject*)" return-type="bool">
+ <inject-code>
+ bool isValid = Shiboken::Object::isValid(%1, false);
+ %PYARG_0 = %CONVERTTOPYTHON[bool](isValid);
+ </inject-code>
+ </add-function>
+
+ <add-function signature="invalidate(PyObject*)">
+ <inject-code>
+ Shiboken::Object::invalidate(%1);
+ </inject-code>
+ </add-function>
+
+ <add-function signature="wrapInstance(unsigned long, PyType)" return-type="PyObject*">
+ <inject-code>
+ if (Shiboken::ObjectType::checkType((PyTypeObject*)%2))
+ %PYARG_0 = Shiboken::Object::newObject((SbkObjectType*)%2, (void*)%1, false, true);
+ else
+ PyErr_SetString(PyExc_TypeError, "You need a shiboken-based type.");
+ </inject-code>
+ </add-function>
+
+ <add-function signature="getCppPointer(PyObject*)" return-type="PyObject*">
+ <inject-code>
+ if (Shiboken::Object::checkType(%1)) {
+ std::vector&lt;void*> ptrs = Shiboken::Object::cppPointers((SbkObject*)%1);
+ %PYARG_0 = PyTuple_New(ptrs.size());
+ for (std::size_t i = 0; i &lt; ptrs.size(); ++i)
+ PyTuple_SET_ITEM(%PYARG_0, i, PyLong_FromVoidPtr(ptrs[i]));
+ } else {
+ PyErr_SetString(PyExc_TypeError, "You need a shiboken-based type.");
+ }
+ </inject-code>
+ </add-function>
+
+ <add-function signature="delete(PyObject*)">
+ <inject-code>
+ if (Shiboken::Object::checkType(%1)) {
+ Shiboken::Object::callCppDestructors((SbkObject*)%1);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "You need a shiboken-based type.");
+ }
+ </inject-code>
+ </add-function>
+
+ <add-function signature="ownedByPython(PyObject*)" return-type="bool">
+ <inject-code>
+ if (Shiboken::Object::checkType(%1)) {
+ bool hasOwnership = Shiboken::Object::hasOwnership((SbkObject*)%1);
+ %PYARG_0 = %CONVERTTOPYTHON[bool](hasOwnership);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "You need a shiboken-based type.");
+ }
+ </inject-code>
+ </add-function>
+
+ <add-function signature="createdByPython(PyObject*)" return-type="bool">
+ <inject-code>
+ if (Shiboken::Object::checkType(%1)) {
+ bool wasCreatedByPython = Shiboken::Object::wasCreatedByPython((SbkObject*)%1);
+ %PYARG_0 = %CONVERTTOPYTHON[bool](wasCreatedByPython);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "You need a shiboken-based type.");
+ }
+ </inject-code>
+ </add-function>
+
+ <add-function signature="dump(PyObject*)" return-type="PyObject*">
+ <inject-code>
+ if (!Shiboken::Object::checkType(%1)) {
+ %PYARG_0 = Shiboken::String::fromCString("Ordinary Python type.");
+ } else {
+ std::string str = Shiboken::Object::info((SbkObject*)%1);
+ %PYARG_0 = Shiboken::String::fromCString(str.c_str());
+ }
+ </inject-code>
+ </add-function>
+
+ <extra-includes>
+ <include file-name="sbkversion.h" location="local"/>
+ </extra-includes>
+ <inject-code position="end">
+ // Add __version__ and __version_info__ attributes to the module
+ PyObject* version = PyTuple_New(5);
+ PyTuple_SET_ITEM(version, 0, PyInt_FromLong(SHIBOKEN_MAJOR_VERSION));
+ PyTuple_SET_ITEM(version, 1, PyInt_FromLong(SHIBOKEN_MINOR_VERSION));
+ PyTuple_SET_ITEM(version, 2, PyInt_FromLong(SHIBOKEN_MICRO_VERSION));
+ PyTuple_SET_ITEM(version, 3, Shiboken::String::fromCString(SHIBOKEN_RELEASE_LEVEL));
+ PyTuple_SET_ITEM(version, 4, PyInt_FromLong(SHIBOKEN_SERIAL));
+ PyModule_AddObject(module, "__version_info__", version);
+ PyModule_AddStringConstant(module, "__version__", SHIBOKEN_VERSION);
+ </inject-code>
+</typesystem>