From 170d47f92d03b81e74e8623cf15db9282957452d Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 22 May 2017 17:50:30 +0200 Subject: move everying into sources/shiboken2 in preparation for a subtree merge. this should not be necessary to do in a separate commit, but git is a tad stupid about following history correctly without it. --- sources/shiboken2/shibokenmodule/CMakeLists.txt | 40 +++++++ sources/shiboken2/shibokenmodule/nothing.h | 0 .../shiboken2/shibokenmodule/shibokenmodule.txt.in | 16 +++ .../shibokenmodule/typesystem_shiboken.xml | 120 +++++++++++++++++++++ 4 files changed, 176 insertions(+) create mode 100644 sources/shiboken2/shibokenmodule/CMakeLists.txt create mode 100644 sources/shiboken2/shibokenmodule/nothing.h create mode 100644 sources/shiboken2/shibokenmodule/shibokenmodule.txt.in create mode 100644 sources/shiboken2/shibokenmodule/typesystem_shiboken.xml (limited to 'sources/shiboken2/shibokenmodule') diff --git a/sources/shiboken2/shibokenmodule/CMakeLists.txt b/sources/shiboken2/shibokenmodule/CMakeLists.txt new file mode 100644 index 000000000..7e90b51ab --- /dev/null +++ b/sources/shiboken2/shibokenmodule/CMakeLists.txt @@ -0,0 +1,40 @@ +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}/shiboken2/shiboken2_module_wrapper.cpp +) + +add_custom_command(OUTPUT ${sample_SRC} +# Note: shiboken2 is an executable target. By not specifying its explicit +# path, CMAKE figures it out, itself! +# This fixes an issue with Visual Studio, see https://github.com/PySide/shiboken2/pull/11 +COMMAND shiboken2 --project-file=${CMAKE_CURRENT_BINARY_DIR}/shibokenmodule.txt ${GENERATOR_EXTRA_FLAGS} +WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +COMMENT "Running generator for 'shiboken2'..." +) + +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 "shiboken2") +if(WIN32) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set_property(TARGET shibokenmodule PROPERTY OUTPUT_NAME "shiboken2_d") + endif() + set_property(TARGET shibokenmodule PROPERTY SUFFIX ".pyd") +endif() +target_link_libraries(shibokenmodule + ${SBK_PYTHON_LIBRARIES} + libshiboken) + +add_dependencies(shibokenmodule shiboken2) + +install(TARGETS shibokenmodule DESTINATION ${PYTHON_SITE_PACKAGES}) \ No newline at end of file diff --git a/sources/shiboken2/shibokenmodule/nothing.h b/sources/shiboken2/shibokenmodule/nothing.h new file mode 100644 index 000000000..e69de29bb diff --git a/sources/shiboken2/shibokenmodule/shibokenmodule.txt.in b/sources/shiboken2/shibokenmodule/shibokenmodule.txt.in new file mode 100644 index 000000000..c5adc6091 --- /dev/null +++ b/sources/shiboken2/shibokenmodule/shibokenmodule.txt.in @@ -0,0 +1,16 @@ +[generator-project] + +generator-set = shiboken + +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/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml b/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml new file mode 100644 index 000000000..18ab52e80 --- /dev/null +++ b/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml @@ -0,0 +1,120 @@ + + + + + + + + + + bool isValid = Shiboken::Object::isValid(%1, false); + %PYARG_0 = %CONVERTTOPYTHON[bool](isValid); + + + + + + Shiboken::Object::invalidate(%1); + + + + + + 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."); + + + + + + 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."); + } + + + + + + if (Shiboken::Object::checkType(%1)) { + Shiboken::Object::callCppDestructors((SbkObject*)%1); + } else { + PyErr_SetString(PyExc_TypeError, "You need a shiboken-based type."); + } + + + + + + 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."); + } + + + + + + 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."); + } + + + + + + 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()); + } + + + + + + std::set<PyObject*> setAll = Shiboken::BindingManager::instance().getAllPyObjects(); + PyObject* listAll = PyList_New(0); + if (listAll == NULL) + return NULL; + + const std::set<PyObject*>::iterator end = setAll.end(); + for (std::set<PyObject*>::iterator iter = setAll.begin(); iter != end; ++iter) { + if (*iter != NULL) { + if (PyList_Append(listAll, *iter) != 0) { + Py_DECREF(listAll); + return NULL; + } + } + } + return listAll; + + + + + + + + // 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); + + -- cgit v1.2.3