diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-08-04 16:10:34 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:17:13 -0300 |
commit | 784a4bbb707d132b26bcb177521745575dc0823f (patch) | |
tree | f637ef4134445b1cfdd0c33878b7a1ce46f02145 /shibokenmodule | |
parent | 8b1ddcd3ef711bab70bb7cdebc26558a26f42df9 (diff) |
Implements PSEP-0106 and fixes bug 902 - "Expose Shiboken functionality through a Python module".
Diffstat (limited to 'shibokenmodule')
-rw-r--r-- | shibokenmodule/CMakeLists.txt | 32 | ||||
-rw-r--r-- | shibokenmodule/nothing.h | 0 | ||||
-rw-r--r-- | shibokenmodule/shibokenmodule.txt.in | 16 | ||||
-rw-r--r-- | shibokenmodule/typesystem_shiboken.xml | 73 |
4 files changed, 121 insertions, 0 deletions
diff --git a/shibokenmodule/CMakeLists.txt b/shibokenmodule/CMakeLists.txt new file mode 100644 index 000000000..6c97b478a --- /dev/null +++ b/shibokenmodule/CMakeLists.txt @@ -0,0 +1,32 @@ +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}) +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..20ca22031 --- /dev/null +++ b/shibokenmodule/typesystem_shiboken.xml @@ -0,0 +1,73 @@ +<?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> + %PYARG_0 = %CONVERTTOPYTHON[bool](Shiboken::Object::isValid(%1, false)); + </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<void*> ptrs = Shiboken::Object::cppPointers((SbkObject*)%1); + %PYARG_0 = PyTuple_New(ptrs.size()); + for (std::size_t i = 0; i < 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="isOwnedByPython(PyObject*)" return-type="bool"> + <inject-code> + if (Shiboken::Object::checkType(%1)) { + %PYARG_0 = %CONVERTTOPYTHON[bool](Shiboken::Object::hasOwnership((SbkObject*)%1)); + } else { + PyErr_SetString(PyExc_TypeError, "You need a shiboken-based type."); + } + </inject-code> + </add-function> + + <add-function signature="wasCreatedByPython(PyObject*)" return-type="bool"> + <inject-code> + if (Shiboken::Object::checkType(%1)) { + %PYARG_0 = %CONVERTTOPYTHON[bool](Shiboken::Object::wasCreatedByPython((SbkObject*)%1)); + } 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 = PyString_FromString("Ordinary Python type."); + } else { + std::string str = Shiboken::Object::info((SbkObject*)%1); + %PYARG_0 = PyString_FromString(str.c_str()); + } + </inject-code> + </add-function> +</typesystem> |