aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-06-07 15:18:37 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-06-07 15:18:37 +0200
commitd9f4a921ca88bf0bd340f42a874cf7c22b6b1a36 (patch)
tree3b4d20a6fc4ea61fa6b1eabe0e8a955dcec176c6
parent4c4fdca8ee3ee3807dd3d56876cfcc1ea1a8cac8 (diff)
parent41b864397ab9f999a7b140b12d2117b8492ed066 (diff)
Merge "Merge remote-tracking branch 'origin/5.12' into 5.13"
-rw-r--r--.gitignore2
-rw-r--r--CMakeLists.txt6
-rw-r--r--build_scripts/utils.py2
-rw-r--r--coin_test_instructions.py1
-rw-r--r--sources/pyside2/CMakeLists.txt2
-rw-r--r--sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py2
-rw-r--r--sources/pyside2/tests/support/voidptr_test.py7
-rw-r--r--sources/shiboken2/ApiExtractor/CMakeLists.txt2
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp24
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.cpp11
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.h1
-rw-r--r--sources/shiboken2/CMakeLists.txt13
-rw-r--r--sources/shiboken2/data/shiboken_helpers.cmake2
-rw-r--r--sources/shiboken2/generator/generator.cpp2
-rw-r--r--sources/shiboken2/generator/shiboken2/headergenerator.cpp7
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp5
-rw-r--r--sources/shiboken2/libshiboken/qapp_macro.cpp32
-rw-r--r--sources/shiboken2/libshiboken/signature.cpp106
-rw-r--r--sources/shiboken2/libshiboken/voidptr.cpp87
19 files changed, 266 insertions, 48 deletions
diff --git a/.gitignore b/.gitignore
index 84257ad33..b49ed94bc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -143,7 +143,7 @@ CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
-Testing
+#Testing Conflicts with the testing directory
Makefile
cmake_install.cmake
install_manifest.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f9a6edf2..595489dfa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,8 +1,10 @@
-project(pyside2_super_project)
-
cmake_minimum_required(VERSION 3.1)
cmake_policy(VERSION 3.1)
+set(CMAKE_BUILD_TYPE Release CACHE STRING "Build Type")
+
+project(pyside2_super_project)
+
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed.")
endif()
diff --git a/build_scripts/utils.py b/build_scripts/utils.py
index 460c1b21f..b34d37123 100644
--- a/build_scripts/utils.py
+++ b/build_scripts/utils.py
@@ -1148,7 +1148,7 @@ def run_instruction(instruction, error, initial_env=None):
def acceptCITestConfiguration(hostOS, hostOSVer, targetArch, compiler):
# Disable unsupported CI configs for now
# NOTE: String must match with QT CI's storagestruct thrift
- if hostOSVer in ["WinRT_10", "WebAssembly"]:
+ if hostOSVer in ["WinRT_10", "WebAssembly", "Ubuntu_18_04"]:
print("Disabled " + hostOSVer + " from Coin configuration")
return False
# With 5.11 CI will create two sets of release binaries, one with msvc 2015 and one with msvc 2017
diff --git a/coin_test_instructions.py b/coin_test_instructions.py
index 2a42ec677..acb27875d 100644
--- a/coin_test_instructions.py
+++ b/coin_test_instructions.py
@@ -61,7 +61,6 @@ _ci_features = option_value("features")
if _ci_features is not None:
for f in _ci_features.split(', '):
CI_FEATURES.append(f)
-
CI_RELEASE_CONF = has_option("packaging")
def call_testrunner(python_ver, buildnro):
diff --git a/sources/pyside2/CMakeLists.txt b/sources/pyside2/CMakeLists.txt
index e5e5ab4e7..c5dbc623c 100644
--- a/sources/pyside2/CMakeLists.txt
+++ b/sources/pyside2/CMakeLists.txt
@@ -62,7 +62,7 @@ endif()
find_package(Shiboken2 2.0.0 REQUIRED)
if(NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE ${SHIBOKEN_BUILD_TYPE})
+ set(CMAKE_BUILD_TYPE "${SHIBOKEN_BUILD_TYPE}" CACHE STRING "Build Type")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
diff --git a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
index b38cff68b..c58aba82e 100644
--- a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
+++ b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
@@ -40,7 +40,7 @@ class qAppMacroTest(unittest.TestCase):
except ImportError:
QtWidgets = QtGui = QtCore
# qApp is in the builtins
- qApp
+ self.assertEqual(bool(qApp), False)
# and also in certain PySide modules
QtCore.qApp, QtGui.qApp, QtWidgets.qApp
# and they are all the same
diff --git a/sources/pyside2/tests/support/voidptr_test.py b/sources/pyside2/tests/support/voidptr_test.py
index c04022489..f68217244 100644
--- a/sources/pyside2/tests/support/voidptr_test.py
+++ b/sources/pyside2/tests/support/voidptr_test.py
@@ -54,6 +54,11 @@ class PySide2Support(unittest.TestCase):
# Convert original and new to str
self.assertTrue(str(b), str(nba))
+ # Modify nba through a memoryview of vp
+ mv = memoryview(vp)
+ self.assertFalse(mv.readonly)
+ mv[6:11] = b'void*'
+ self.assertEqual(str(ba), str(b"Hello void*"))
+
if __name__ == '__main__':
unittest.main()
-
diff --git a/sources/shiboken2/ApiExtractor/CMakeLists.txt b/sources/shiboken2/ApiExtractor/CMakeLists.txt
index 760cc6985..c55dba973 100644
--- a/sources/shiboken2/ApiExtractor/CMakeLists.txt
+++ b/sources/shiboken2/ApiExtractor/CMakeLists.txt
@@ -63,6 +63,8 @@ if (NOT DISABLE_DOCSTRINGS)
endif()
endif()
+target_compile_definitions(apiextractor PRIVATE CMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}")
+
set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE)
if (BUILD_TESTS)
diff --git a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp
index d3d5c8da8..3196c824e 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp
+++ b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp
@@ -189,7 +189,7 @@ static LinuxDistribution linuxDistribution()
const QString &productType = QSysInfo::productType();
if (productType == QLatin1String("rhel"))
return LinuxDistribution::RedHat;
- if (productType == QLatin1String("centos"))
+ if (productType.compare(QLatin1String("centos"), Qt::CaseInsensitive) == 0)
return LinuxDistribution::CentOs;
return LinuxDistribution::Other;
}
@@ -207,7 +207,7 @@ static inline bool needsGppInternalHeaders()
switch (distro) {
case LinuxDistribution::RedHat:
case LinuxDistribution::CentOs:
- return checkProductVersion(QVersionNumber(7), QVersionNumber(8));
+ return checkProductVersion(QVersionNumber(6, 10), QVersionNumber(8));
case LinuxDistribution::Other:
break;
}
@@ -288,6 +288,18 @@ static QString findClangBuiltInIncludesDir()
}
#endif // NEED_CLANG_BUILTIN_INCLUDES
+#if defined(Q_CC_CLANG) || defined(Q_CC_GNU)
+static QString compilerFromCMake(const QString &defaultCompiler)
+{
+# ifdef CMAKE_CXX_COMPILER
+ Q_UNUSED(defaultCompiler)
+ return QString::fromLocal8Bit(CMAKE_CXX_COMPILER);
+#else
+ return defaultCompiler;
+# endif
+}
+#endif // Q_CC_CLANG, Q_CC_GNU
+
// Returns clang options needed for emulating the host compiler
QByteArrayList emulatedCompilerOptions()
{
@@ -297,7 +309,7 @@ QByteArrayList emulatedCompilerOptions()
result.append(QByteArrayLiteral("-fms-compatibility-version=19"));
result.append(QByteArrayLiteral("-Wno-microsoft-enum-value"));
#elif defined(Q_CC_CLANG)
- HeaderPaths headerPaths = gppInternalIncludePaths(QStringLiteral("clang++"));
+ HeaderPaths headerPaths = gppInternalIncludePaths(compilerFromCMake(QStringLiteral("clang++")));
result.append(noStandardIncludeOption());
#elif defined(Q_CC_GNU)
HeaderPaths headerPaths;
@@ -322,10 +334,12 @@ QByteArrayList emulatedCompilerOptions()
// A fix for this has been added to Clang 5.0, so, the code can be removed
// once Clang 5.0 is the minimum version.
if (needsGppInternalHeaders()) {
- const HeaderPaths gppPaths = gppInternalIncludePaths(QStringLiteral("g++"));
+ const HeaderPaths gppPaths = gppInternalIncludePaths(compilerFromCMake(QStringLiteral("g++")));
for (const HeaderPath &h : gppPaths) {
- if (h.path.contains("c++"))
+ if (h.path.contains("c++")
+ || h.path.contains("sysroot")) { // centOS
headerPaths.append(h);
+ }
}
}
#else
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
index eb0f44689..7bb7e0a83 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
@@ -353,6 +353,17 @@ bool TypeInfo::stripLeadingQualifier(const QString &qualifier, QString *s)
return true;
}
+// Strip all const/volatile/*/&
+void TypeInfo::stripQualifiers(QString *s)
+{
+ stripLeadingConst(s);
+ stripLeadingVolatile(s);
+ while (s->endsWith(QLatin1Char('&')) || s->endsWith(QLatin1Char('*'))
+ || s->endsWith(QLatin1Char(' '))) {
+ s->chop(1);
+ }
+}
+
// Helper functionality to simplify a raw standard type as returned by
// clang_getCanonicalType() for g++ standard containers from
// "std::__cxx11::list<int, std::allocator<int> >" or
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h
index 3bce5e216..6f3c17613 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.h
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h
@@ -213,6 +213,7 @@ public:
static bool stripLeadingConst(QString *s);
static bool stripLeadingVolatile(QString *s);
static bool stripLeadingQualifier(const QString &qualifier, QString *s);
+ static void stripQualifiers(QString *s);
void simplifyStdType();
diff --git a/sources/shiboken2/CMakeLists.txt b/sources/shiboken2/CMakeLists.txt
index 950aa6215..be1b4cd7f 100644
--- a/sources/shiboken2/CMakeLists.txt
+++ b/sources/shiboken2/CMakeLists.txt
@@ -1,10 +1,13 @@
Include(icecc.cmake)
-project(shiboken2)
-include(CheckIncludeFileCXX)
cmake_minimum_required(VERSION 3.1)
cmake_policy(VERSION 3.1)
+set(CMAKE_BUILD_TYPE Release CACHE STRING "Build Type")
+
+project(shiboken2)
+include(CheckIncludeFileCXX)
+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_helpers/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/data/")
@@ -404,11 +407,7 @@ execute_process(
OUTPUT_VARIABLE PYTHON_WITH_COUNT_ALLOCS
OUTPUT_STRIP_TRAILING_WHITESPACE)
-if(NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE Release)
-endif()
-
-set(SHIBOKEN_BUILD_TYPE "Release")
+set(SHIBOKEN_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(SHIBOKEN_BUILD_TYPE "Debug")
diff --git a/sources/shiboken2/data/shiboken_helpers.cmake b/sources/shiboken2/data/shiboken_helpers.cmake
index c55ee89fe..f4dd4d5dc 100644
--- a/sources/shiboken2/data/shiboken_helpers.cmake
+++ b/sources/shiboken2/data/shiboken_helpers.cmake
@@ -157,7 +157,7 @@ macro(shiboken_compute_python_libraries)
# If the resulting variable
# contains a "debug;X;optimized;Y" list like described in shiboken_check_if_limited_api,
# make sure to pick just one, so that the final generator expressions are valid.
- shiboken_get_library_for_current_config("${SHIBOKEN_PYTHON_LIBRARIES}" ${CMAKE_BUILD_TYPE} "SHIBOKEN_PYTHON_LIBRARIES")
+ shiboken_get_library_for_current_config("${SHIBOKEN_PYTHON_LIBRARIES}" "${CMAKE_BUILD_TYPE}" "SHIBOKEN_PYTHON_LIBRARIES")
if(APPLE)
set(SHIBOKEN_PYTHON_LIBRARIES "-undefined dynamic_lookup")
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp
index 87758e533..fe03d3489 100644
--- a/sources/shiboken2/generator/generator.cpp
+++ b/sources/shiboken2/generator/generator.cpp
@@ -28,6 +28,7 @@
#include "generator.h"
#include "abstractmetalang.h"
+#include "parser/codemodel.h"
#include "messages.h"
#include "reporthandler.h"
#include "fileout.h"
@@ -911,6 +912,7 @@ QString getClassTargetFullName(const AbstractMetaType *metaType, bool includePac
QString getFilteredCppSignatureString(QString signature)
{
+ TypeInfo::stripQualifiers(&signature); // for const refs to smart pointers
signature.replace(QLatin1String("::"), QLatin1String("_"));
signature.replace(QLatin1Char('<'), QLatin1Char('_'));
signature.replace(QLatin1Char('>'), QLatin1Char('_'));
diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
index 8881d71f4..17ebbcde9 100644
--- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
@@ -31,6 +31,7 @@
#include <typedatabase.h>
#include <reporthandler.h>
#include <fileout.h>
+#include "parser/codemodel.h"
#include <algorithm>
@@ -592,8 +593,10 @@ void HeaderGenerator::writeSbkTypeFunction(QTextStream& s, const AbstractMetaCla
void HeaderGenerator::writeSbkTypeFunction(QTextStream &s, const AbstractMetaType *metaType)
{
- s << "template<> inline PyTypeObject* SbkType< ::" << metaType->cppSignature() << " >() "
- << "{ return reinterpret_cast<PyTypeObject*>(" << cpythonTypeNameExt(metaType) << "); }\n";
+ QString signature = metaType->cppSignature();
+ TypeInfo::stripQualifiers(&signature); // for const refs to smart pointers
+ s << "template<> inline PyTypeObject *SbkType< ::" << signature << " >() "
+ << "{ return reinterpret_cast<PyTypeObject *>(" << cpythonTypeNameExt(metaType) << "); }\n";
}
void HeaderGenerator::writeInheritedOverloads(QTextStream& s)
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index 2b3b20c75..5d599fe95 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -2681,8 +2681,11 @@ QString ShibokenGenerator::getTypeIndexVariableName(const TypeEntry* type)
QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaType* type)
{
QString result = QLatin1String("SBK");
- if (type->typeEntry()->isContainer())
+ const auto *typeEntry = type->typeEntry();
+ if (typeEntry->isContainer()
+ || typeEntry->isSmartPointer()) { // PYSIDE-1024
result += QLatin1Char('_') + moduleName().toUpper();
+ }
result += processInstantiationsVariableName(type);
appendIndexSuffix(&result);
return result;
diff --git a/sources/shiboken2/libshiboken/qapp_macro.cpp b/sources/shiboken2/libshiboken/qapp_macro.cpp
index f69d0f937..19e985b20 100644
--- a/sources/shiboken2/libshiboken/qapp_macro.cpp
+++ b/sources/shiboken2/libshiboken/qapp_macro.cpp
@@ -67,7 +67,9 @@ qApp_module_index(PyObject *module)
return ret;
}
-#define Py_NONE_TYPE Py_TYPE(Py_None)
+#define PYTHON_IS_PYTHON3 (PY_VERSION_HEX >= 0x03000000)
+#define PYTHON_IS_PYTHON2 (!PYTHON_IS_PYTHON3)
+#define Py_NONE_TYPE Py_TYPE(Py_None)
#if PYTHON_IS_PYTHON3
# define BRACE_OPEN {
@@ -156,6 +158,31 @@ MakeSingletonQAppWrapper(PyTypeObject *type)
return qApp_content;
}
+#if PYTHON_IS_PYTHON2
+
+// Install support in Py_NONE_TYPE for Python 2: 'bool(qApp) == False'.
+static int
+none_bool(PyObject *v)
+{
+ return 0;
+}
+
+static PyNumberMethods none_as_number = {
+ nullptr, /* nb_add */
+ nullptr, /* nb_subtract */
+ nullptr, /* nb_multiply */
+ nullptr, /* nb_divide */
+ nullptr, /* nb_remainder */
+ nullptr, /* nb_divmod */
+ nullptr, /* nb_power */
+ nullptr, /* nb_negative */
+ nullptr, /* nb_positive */
+ nullptr, /* nb_absolute */
+ reinterpret_cast<inquiry>(none_bool), /* nb_nonzero */
+};
+
+#endif
+
static int
setup_qApp_var(PyObject *module)
{
@@ -163,6 +190,9 @@ setup_qApp_var(PyObject *module)
static int init_done = 0;
if (!init_done) {
+#if PYTHON_IS_PYTHON2
+ Py_NONE_TYPE->tp_as_number = &none_as_number;
+#endif
qApp_var = Py_BuildValue("s", "qApp");
if (qApp_var == NULL)
return -1;
diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp
index 3defca7d2..c83f90d64 100644
--- a/sources/shiboken2/libshiboken/signature.cpp
+++ b/sources/shiboken2/libshiboken/signature.cpp
@@ -71,6 +71,7 @@ typedef struct safe_globals_struc {
PyObject *helper_module;
PyObject *arg_dict;
PyObject *map_dict;
+ PyObject *value_dict; // for writing signatures
// init part 2: run module
PyObject *pyside_type_init_func;
PyObject *create_signature_func;
@@ -86,6 +87,7 @@ static PyObject *GetSignature_Function(PyObject *, const char *);
static PyObject *GetSignature_TypeMod(PyObject *, const char *);
static PyObject *GetSignature_Wrapper(PyObject *, const char *);
static PyObject *get_signature(PyObject *self, PyObject *args);
+static PyObject *get_signature_intern(PyObject *ob, const char *modifier);
static PyObject *PySide_BuildSignatureProps(PyObject *class_mod);
@@ -105,11 +107,36 @@ CreateSignature(PyObject *props, PyObject *key)
const_cast<char *>("(OO)"), props, key);
}
+typedef PyObject *(*signaturefunc)(PyObject *, const char *);
+
+static PyObject *
+_get_written_signature(signaturefunc sf, PyObject *ob, const char *modifier)
+{
+ /*
+ * Be a writable Attribute, but have a computed value.
+ *
+ * If a signature has not been written, call the signature function.
+ * If it has been written, return the written value.
+ * After __del__ was called, the function value re-appears.
+ *
+ * Note: This serves also for the new version that does not allow any
+ * assignment if we have a computed value. We only need to check if
+ * a computed value exists and then forbid writing.
+ * See pyside_set___signature
+ */
+ PyObject *ret = PyDict_GetItem(pyside_globals->value_dict, ob);
+ if (ret == nullptr) {
+ return ob == nullptr ? nullptr : sf(ob, modifier);
+ }
+ Py_INCREF(ret);
+ return ret;
+}
+
static PyObject *
pyside_cf_get___signature__(PyObject *func, const char *modifier)
{
init_module_2();
- return GetSignature_Function(func, modifier);
+ return _get_written_signature(GetSignature_Function, func, modifier);
}
static PyObject *
@@ -118,8 +145,8 @@ pyside_sm_get___signature__(PyObject *sm, const char *modifier)
init_module_2();
Shiboken::AutoDecRef func(PyObject_GetAttrString(sm, "__func__"));
if (Py_TYPE(func) == PepFunction_TypePtr)
- Py_RETURN_NONE;
- return GetSignature_Function(func, modifier);
+ return PyObject_GetAttrString(func, "__signature__");
+ return _get_written_signature(GetSignature_Function, func, modifier);
}
static PyObject *
@@ -270,14 +297,14 @@ static PyObject *
pyside_wd_get___signature__(PyObject *ob, const char *modifier)
{
init_module_2();
- return GetSignature_Wrapper(ob, modifier);
+ return _get_written_signature(GetSignature_Wrapper, ob, modifier);
}
static PyObject *
pyside_tp_get___signature__(PyObject *obtype_mod, const char *modifier)
{
init_module_2();
- return GetSignature_TypeMod(obtype_mod, modifier);
+ return _get_written_signature(GetSignature_TypeMod, obtype_mod, modifier);
}
// forward
@@ -510,6 +537,12 @@ init_phase_1(void)
if (p->arg_dict == nullptr
|| PyObject_SetAttrString(p->helper_module, "pyside_arg_dict", p->arg_dict) < 0)
goto error;
+
+ // build a dict for assigned signature values
+ p->value_dict = PyDict_New();
+ if (p->value_dict == nullptr)
+ goto error;
+
return p;
}
error:
@@ -682,33 +715,56 @@ pyside_wd_get___doc__(PyObject *wd) {
return handle_doc(wd, old_wd_doc_descr);
}
+// the default setter for all objects
+static int
+pyside_set___signature__(PyObject *op, PyObject *value)
+{
+ // By this additional check, this function refuses write access.
+ if (get_signature_intern(op, nullptr)) {
+ PyErr_Format(PyExc_AttributeError,
+ "Attribute '__signature__' of '%.50s' object is not writable",
+ Py_TYPE(op)->tp_name);
+ return -1;
+ }
+ int ret = value == nullptr
+ ? PyDict_DelItem(pyside_globals->value_dict, op)
+ : PyDict_SetItem(pyside_globals->value_dict, op, value);
+ Py_XINCREF(value);
+ return ret;
+}
+
static PyGetSetDef new_PyCFunction_getsets[] = {
- {const_cast<char *>("__signature__"), (getter)pyside_cf_get___signature__},
{const_cast<char *>("__doc__"), (getter)pyside_cf_get___doc__},
+ {const_cast<char *>("__signature__"), (getter)pyside_cf_get___signature__,
+ (setter)pyside_set___signature__},
{0}
};
static PyGetSetDef new_PyStaticMethod_getsets[] = {
- {const_cast<char *>("__signature__"), (getter)pyside_sm_get___signature__},
{const_cast<char *>("__doc__"), (getter)pyside_sm_get___doc__},
+ {const_cast<char *>("__signature__"), (getter)pyside_sm_get___signature__,
+ (setter)pyside_set___signature__},
{0}
};
static PyGetSetDef new_PyMethodDescr_getsets[] = {
- {const_cast<char *>("__signature__"), (getter)pyside_md_get___signature__},
{const_cast<char *>("__doc__"), (getter)pyside_md_get___doc__},
+ {const_cast<char *>("__signature__"), (getter)pyside_md_get___signature__,
+ (setter)pyside_set___signature__},
{0}
};
static PyGetSetDef new_PyType_getsets[] = {
- {const_cast<char *>("__signature__"), (getter)pyside_tp_get___signature__},
{const_cast<char *>("__doc__"), (getter)pyside_tp_get___doc__},
+ {const_cast<char *>("__signature__"), (getter)pyside_tp_get___signature__,
+ (setter)pyside_set___signature__},
{0}
};
static PyGetSetDef new_PyWrapperDescr_getsets[] = {
- {const_cast<char *>("__signature__"), (getter)pyside_wd_get___signature__},
{const_cast<char *>("__doc__"), (getter)pyside_wd_get___doc__},
+ {const_cast<char *>("__signature__"), (getter)pyside_wd_get___signature__,
+ (setter)pyside_set___signature__},
{0}
};
@@ -723,18 +779,8 @@ static PyGetSetDef new_PyWrapperDescr_getsets[] = {
//
static PyObject *
-get_signature(PyObject *self, PyObject *args)
+get_signature_intern(PyObject *ob, const char *modifier)
{
- PyObject *ob;
- const char *modifier = nullptr;
-
- init_module_1();
-
- if (!PyArg_ParseTuple(args, "O|s", &ob, &modifier))
- return nullptr;
- if (Py_TYPE(ob) == PepFunction_TypePtr)
- Py_RETURN_NONE;
-
if (PyType_IsSubtype(Py_TYPE(ob), &PyCFunction_Type))
return pyside_cf_get___signature__(ob, modifier);
if (Py_TYPE(ob) == PepStaticMethod_TypePtr)
@@ -745,6 +791,24 @@ get_signature(PyObject *self, PyObject *args)
return pyside_tp_get___signature__(ob, modifier);
if (Py_TYPE(ob) == &PyWrapperDescr_Type)
return pyside_wd_get___signature__(ob, modifier);
+ return nullptr;
+}
+
+static PyObject *
+get_signature(PyObject *self, PyObject *args)
+{
+ PyObject *ob;
+ const char *modifier = nullptr;
+
+ init_module_1();
+
+ if (!PyArg_ParseTuple(args, "O|s", &ob, &modifier))
+ return nullptr;
+ if (Py_TYPE(ob) == PepFunction_TypePtr)
+ Py_RETURN_NONE;
+ PyObject *ret = get_signature_intern(ob, modifier);
+ if (ret != nullptr)
+ return ret;
Py_RETURN_NONE;
}
diff --git a/sources/shiboken2/libshiboken/voidptr.cpp b/sources/shiboken2/libshiboken/voidptr.cpp
index e55ccfab5..5b0cb84ea 100644
--- a/sources/shiboken2/libshiboken/voidptr.cpp
+++ b/sources/shiboken2/libshiboken/voidptr.cpp
@@ -249,6 +249,83 @@ PyObject *SbkVoidPtrObject_str(PyObject *v)
}
+static int SbkVoidPtrObject_getbuffer(PyObject *obj, Py_buffer *view, int flags)
+{
+ if (view == NULL)
+ return -1;
+
+ SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(obj);
+ if (sbkObject->size < 0)
+ return -1;
+
+ int readonly = sbkObject->isWritable ? 0 : 1;
+ if (((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) &&
+ (readonly == 1)) {
+ PyErr_SetString(PyExc_BufferError,
+ "Object is not writable.");
+ return -1;
+ }
+
+ view->obj = obj;
+ if (obj)
+ Py_XINCREF(obj);
+ view->buf = sbkObject->cptr;
+ view->len = sbkObject->size;
+ view->readonly = readonly;
+ view->itemsize = 1;
+ view->format = NULL;
+ if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT)
+ view->format = "B";
+ view->ndim = 1;
+ view->shape = NULL;
+ if ((flags & PyBUF_ND) == PyBUF_ND)
+ view->shape = &(view->len);
+ view->strides = NULL;
+ if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES)
+ view->strides = &(view->itemsize);
+ view->suboffsets = NULL;
+ view->internal = NULL;
+ return 0;
+}
+
+#if PY_VERSION_HEX < 0x03000000
+
+static Py_ssize_t SbkVoidPtrObject_readbufferproc(PyObject* self, Py_ssize_t segment, void** ptrptr)
+{
+ if (segment || !Shiboken::Object::isValid(self))
+ return -1;
+
+ SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self);
+ *ptrptr = reinterpret_cast<void*>(sbkObject->cptr);
+ return sbkObject->size;
+}
+
+static Py_ssize_t SbkVoidPtrObject_segcountproc(PyObject* self, Py_ssize_t* lenp)
+{
+ if (lenp) {
+ SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self);
+ *lenp = sbkObject->size;
+ }
+ return 1;
+}
+
+PyBufferProcs SbkVoidPtrObjectBufferProc = {
+ &SbkVoidPtrObject_readbufferproc, // bf_getreadbuffer
+ (writebufferproc)&SbkVoidPtrObject_readbufferproc, // bf_getwritebuffer
+ &SbkVoidPtrObject_segcountproc, // bf_getsegcount
+ (charbufferproc)&SbkVoidPtrObject_readbufferproc, // bf_getcharbuffer
+ (getbufferproc)SbkVoidPtrObject_getbuffer, // bf_getbuffer
+};
+
+#else
+
+static PyBufferProcs SbkVoidPtrObjectBufferProc = {
+ (getbufferproc)SbkVoidPtrObject_getbuffer, // bf_getbuffer
+ (releasebufferproc)0 // bf_releasebuffer
+};
+
+#endif
+
// Void pointer type definition.
static PyType_Slot SbkVoidPtrType_slots[] = {
{Py_tp_repr, (void *)SbkVoidPtrObject_repr},
@@ -278,6 +355,14 @@ PyTypeObject *SbkVoidPtrTypeF(void)
static PyTypeObject *type = nullptr;
if (!type)
type = (PyTypeObject *)PyType_FromSpec(&SbkVoidPtrType_spec);
+
+#if PY_VERSION_HEX < 0x03000000
+ type->tp_as_buffer = &SbkVoidPtrObjectBufferProc;
+ type->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER;
+#else
+ PepType_AS_BUFFER(type) = &SbkVoidPtrObjectBufferProc;
+#endif
+
return type;
}
@@ -394,5 +479,3 @@ SbkConverter *createConverter()
}
} // namespace VoidPtr
-
-