aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/libshiboken')
-rw-r--r--sources/shiboken2/libshiboken/basewrapper.cpp223
-rw-r--r--sources/shiboken2/libshiboken/basewrapper_p.h18
-rw-r--r--sources/shiboken2/libshiboken/bindingmanager.cpp27
-rw-r--r--sources/shiboken2/libshiboken/sbkconverter.cpp8
-rw-r--r--sources/shiboken2/libshiboken/sbkconverter_p.h6
-rw-r--r--sources/shiboken2/libshiboken/sbkenum.cpp21
-rw-r--r--sources/shiboken2/libshiboken/sbkpython.h30
-rw-r--r--sources/shiboken2/libshiboken/typespec.cpp44
-rw-r--r--sources/shiboken2/libshiboken/typespec.h2
9 files changed, 178 insertions, 201 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp
index ec705a421..9eb686ed0 100644
--- a/sources/shiboken2/libshiboken/basewrapper.cpp
+++ b/sources/shiboken2/libshiboken/basewrapper.cpp
@@ -118,20 +118,15 @@ static int SbkObject_traverse(PyObject* self, visitproc visit, void* arg)
//Visit children
Shiboken::ParentInfo* pInfo = sbkSelf->d->parentInfo;
if (pInfo) {
- std::set<SbkObject*>::const_iterator it = pInfo->children.begin();
- for(; it != pInfo->children.end(); ++it)
- Py_VISIT(*it);
+ for (SbkObject *c : pInfo->children)
+ Py_VISIT(c);
}
//Visit refs
Shiboken::RefCountMap* rInfo = sbkSelf->d->referredObjects;
if (rInfo) {
- Shiboken::RefCountMap::const_iterator it = rInfo->begin();
- for (; it != rInfo->end(); ++it) {
- std::list<PyObject*>::const_iterator ref = it->second.begin();
- for(; ref != it->second.end(); ++ref)
- Py_VISIT(*ref);
- }
+ for (auto it = rInfo->begin(), end = rInfo->end(); it != end; ++it)
+ Py_VISIT(it->second);
}
if (sbkSelf->ob_dict)
@@ -325,7 +320,7 @@ PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* k
Shiboken::ObjectType::initPrivateData(newType);
SbkObjectTypePrivate *sotp = PepType_SOTP(newType);
- std::list<SbkObjectType*> bases = Shiboken::getCppBaseClasses(reinterpret_cast<PyTypeObject*>(newType));
+ const auto bases = Shiboken::getCppBaseClasses(reinterpret_cast<PyTypeObject*>(newType));
if (bases.size() == 1) {
SbkObjectTypePrivate *parentType = PepType_SOTP(bases.front());
sotp->mi_offsets = parentType->mi_offsets;
@@ -352,10 +347,9 @@ PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* k
sotp->d_func = nullptr;
sotp->is_user_type = 1;
- std::list<SbkObjectType*>::const_iterator it = bases.begin();
- for (; it != bases.end(); ++it) {
- if (PepType_SOTP(*it)->subtype_init)
- PepType_SOTP(*it)->subtype_init(newType, args, kwds);
+ for (SbkObjectType *base : bases) {
+ if (PepType_SOTP(base)->subtype_init)
+ PepType_SOTP(base)->subtype_init(newType, args, kwds);
}
return reinterpret_cast<PyObject*>(newType);
@@ -453,9 +447,6 @@ void _destroyParentInfo(SbkObject* obj, bool keepReference)
namespace Shiboken
{
-
-static void decRefPyObjectList(const std::list<PyObject*> &pyObj, PyObject* skip = 0);
-
static void _walkThroughClassHierarchy(PyTypeObject* currentType, HierarchyVisitor* visitor)
{
PyObject* bases = currentType->tp_bases;
@@ -522,8 +513,7 @@ void DtorCallerVisitor::visit(SbkObjectType* node)
void DtorCallerVisitor::done()
{
- std::list<std::pair<void*, SbkObjectType*> >::const_iterator it = m_ptrs.begin();
- for (; it != m_ptrs.end(); ++it) {
+ for (auto it = m_ptrs.begin(), end = m_ptrs.end(); it != end; ++it) {
Shiboken::ThreadStateSaver threadSaver;
threadSaver.save();
PepType_SOTP(it->second)->cpp_dtor(it->first);
@@ -623,9 +613,9 @@ class FindBaseTypeVisitor : public HierarchyVisitor
PyTypeObject* m_typeToFind;
};
-std::list<SbkObject*> splitPyObject(PyObject* pyObj)
+std::vector<SbkObject *> splitPyObject(PyObject* pyObj)
{
- std::list<SbkObject*> result;
+ std::vector<SbkObject *> result;
if (PySequence_Check(pyObj)) {
AutoDecRef lst(PySequence_Fast(pyObj, "Invalid keep reference object."));
if (!lst.isNull()) {
@@ -641,14 +631,11 @@ std::list<SbkObject*> splitPyObject(PyObject* pyObj)
return result;
}
-static void decRefPyObjectList(const std::list<PyObject*>& lst, PyObject *skip)
+template <class Iterator>
+inline void decRefPyObjectList(Iterator i1, Iterator i2)
{
- std::list<PyObject*>::const_iterator iter = lst.begin();
- while(iter != lst.end()) {
- if (*iter != skip)
- Py_DECREF(*iter);
- ++iter;
- }
+ for (; i1 != i2; ++i1)
+ Py_DECREF(i1->second);
}
namespace ObjectType
@@ -842,12 +829,13 @@ static void setSequenceOwnership(PyObject* pyObj, bool owner)
if (PySequence_Check(pyObj) && has_length) {
Py_ssize_t size = PySequence_Size(pyObj);
if (size > 0) {
- std::list<SbkObject*> objs = splitPyObject(pyObj);
- for (auto it = objs.begin(), end = objs.end(); it != end; ++it) {
- if (owner)
- getOwnership(*it);
- else
- releaseOwnership(*it);
+ const auto objs = splitPyObject(pyObj);
+ if (owner) {
+ for (SbkObject *o : objs)
+ getOwnership(o);
+ } else {
+ for (SbkObject *o : objs)
+ releaseOwnership(o);
}
}
} else if (Object::checkType(pyObj)) {
@@ -975,10 +963,9 @@ void invalidate(SbkObject* self)
static void recursive_invalidate(PyObject* pyobj, std::set<SbkObject*>& seen)
{
- std::list<SbkObject*> objs = splitPyObject(pyobj);
- std::list<SbkObject*>::const_iterator it = objs.begin();
- for (; it != objs.end(); it++)
- recursive_invalidate(*it, seen);
+ const auto objs = splitPyObject(pyobj);
+ for (SbkObject *o : objs)
+ recursive_invalidate(o, seen);
}
static void recursive_invalidate(SbkObject* self, std::set<SbkObject*>& seen)
@@ -997,30 +984,22 @@ static void recursive_invalidate(SbkObject* self, std::set<SbkObject*>& seen)
if (self->d->parentInfo) {
// Create a copy because this list can be changed during the process
ChildrenList copy = self->d->parentInfo->children;
- ChildrenList::iterator it = copy.begin();
- for (; it != copy.end(); ++it) {
+ for (SbkObject *child : copy) {
// invalidate the child
- recursive_invalidate(*it, seen);
+ recursive_invalidate(child, seen);
// if the parent not is a wrapper class, then remove children from him, because We do not know when this object will be destroyed
if (!self->d->validCppObject)
- removeParent(*it, true, true);
+ removeParent(child, true, true);
}
}
// If has ref to other objects invalidate all
if (self->d->referredObjects) {
RefCountMap& refCountMap = *(self->d->referredObjects);
- RefCountMap::iterator iter;
- for (iter = refCountMap.begin(); iter != refCountMap.end(); ++iter) {
- const std::list<PyObject*> lst = iter->second;
- std::list<PyObject*>::const_iterator it = lst.begin();
- while(it != lst.end()) {
- recursive_invalidate(*it, seen);
- ++it;
- }
- }
+ for (auto it = refCountMap.begin(), end = refCountMap.end(); it != end; ++it)
+ recursive_invalidate(it->second, seen);
}
}
@@ -1035,23 +1014,17 @@ void makeValid(SbkObject* self)
// If it is a parent make all children valid
if (self->d->parentInfo) {
- ChildrenList::iterator it = self->d->parentInfo->children.begin();
- for (; it != self->d->parentInfo->children.end(); ++it)
- makeValid(*it);
+ for (SbkObject *child : self->d->parentInfo->children)
+ makeValid(child);
}
// If has ref to other objects make all valid again
if (self->d->referredObjects) {
RefCountMap& refCountMap = *(self->d->referredObjects);
RefCountMap::iterator iter;
- for (iter = refCountMap.begin(); iter != refCountMap.end(); ++iter) {
- const std::list<PyObject*> lst = iter->second;
- std::list<PyObject*>::const_iterator it = lst.begin();
- while(it != lst.end()) {
- if (Shiboken::Object::checkType(*it))
- makeValid(reinterpret_cast<SbkObject*>(*it));
- ++it;
- }
+ for (auto it = refCountMap.begin(), end = refCountMap.end(); it != end; ++it) {
+ if (Shiboken::Object::checkType(it->second))
+ makeValid(reinterpret_cast<SbkObject *>(it->second));
}
}
}
@@ -1166,15 +1139,14 @@ SbkObject *findColocatedChild(SbkObject *wrapper,
ChildrenList& children = pInfo->children;
- ChildrenList::iterator childrenEnd = children.end();
- for (ChildrenList::iterator iChild = children.begin(); iChild != childrenEnd; ++iChild) {
- if (!((*iChild)->d && (*iChild)->d->cptr))
+ for (SbkObject *child : children) {
+ if (!(child->d && child->d->cptr))
continue;
- if ((*iChild)->d->cptr[0] == wrapper->d->cptr[0]) {
- if (reinterpret_cast<const void *>(Py_TYPE(*iChild)) == reinterpret_cast<const void *>(instanceType))
- return const_cast<SbkObject *>((*iChild));
+ if (child->d->cptr[0] == wrapper->d->cptr[0]) {
+ if (reinterpret_cast<const void *>(Py_TYPE(child)) == reinterpret_cast<const void *>(instanceType))
+ return child;
else
- return findColocatedChild(const_cast<SbkObject *>(*iChild), instanceType);
+ return findColocatedChild(child, instanceType);
}
}
return 0;
@@ -1433,57 +1405,56 @@ void* getTypeUserData(SbkObject* wrapper)
return PepType_SOTP(Py_TYPE(wrapper))->user_data;
}
-void keepReference(SbkObject* self, const char* key, PyObject* referredObject, bool append)
+static inline bool isNone(const PyObject *o)
{
- bool isNone = (!referredObject || (referredObject == Py_None));
-
- if (!self->d->referredObjects)
- self->d->referredObjects = new Shiboken::RefCountMap;
-
- RefCountMap& refCountMap = *(self->d->referredObjects);
- RefCountMap::iterator iter = refCountMap.find(key);
- std::list<PyObject*> objects;
- if (iter != refCountMap.end()) {
- objects = (*iter).second;
- std::list<PyObject*>::const_iterator found = std::find(objects.begin(), objects.end(), referredObject);
-
- // skip if objects already exists
- if (found != objects.end())
- return;
- }
+ return o == nullptr || o == Py_None;
+}
- if (append && !isNone) {
- refCountMap[key].push_back(referredObject);
- Py_INCREF(referredObject);
- } else if (!append) {
- if (objects.size() > 0)
- decRefPyObjectList(objects, isNone ? 0 : referredObject);
- if (isNone) {
- if (iter != refCountMap.end())
- refCountMap.erase(iter);
- } else {
- objects.clear();
- objects.push_back(referredObject);
- refCountMap[key] = objects;
- Py_INCREF(referredObject);
+static void removeRefCountKey(SbkObject* self, const char *key)
+{
+ if (self->d->referredObjects) {
+ const auto iterPair = self->d->referredObjects->equal_range(key);
+ if (iterPair.first != iterPair.second) {
+ decRefPyObjectList(iterPair.first, iterPair.second);
+ self->d->referredObjects->erase(iterPair.first, iterPair.second);
}
}
}
-void removeReference(SbkObject* self, const char* key, PyObject* referredObject)
+void keepReference(SbkObject* self, const char* key, PyObject* referredObject, bool append)
{
- if (!referredObject || (referredObject == Py_None))
+ if (isNone(referredObject)) {
+ removeRefCountKey(self, key);
return;
+ }
- if (!self->d->referredObjects)
+ if (!self->d->referredObjects) {
+ self->d->referredObjects =
+ new Shiboken::RefCountMap{RefCountMap::value_type{key, referredObject}};
+ Py_INCREF(referredObject);
return;
+ }
RefCountMap& refCountMap = *(self->d->referredObjects);
- RefCountMap::iterator iter = refCountMap.find(key);
- if (iter != refCountMap.end()) {
- decRefPyObjectList(iter->second);
- refCountMap.erase(iter);
+ const auto iterPair = refCountMap.equal_range(key);
+ if (std::any_of(iterPair.first, iterPair.second,
+ [referredObject](const RefCountMap::value_type &v) { return v.second == referredObject; })) {
+ return;
}
+
+ if (!append && iterPair.first != iterPair.second) {
+ decRefPyObjectList(iterPair.first, iterPair.second);
+ refCountMap.erase(iterPair.first, iterPair.second);
+ }
+
+ refCountMap.insert(RefCountMap::value_type{key, referredObject});
+ Py_INCREF(referredObject);
+}
+
+void removeReference(SbkObject* self, const char* key, PyObject* referredObject)
+{
+ if (!isNone(referredObject))
+ removeRefCountKey(self, key);
}
void clearReferences(SbkObject* self)
@@ -1492,27 +1463,27 @@ void clearReferences(SbkObject* self)
return;
RefCountMap& refCountMap = *(self->d->referredObjects);
- RefCountMap::iterator iter;
- for (iter = refCountMap.begin(); iter != refCountMap.end(); ++iter)
- decRefPyObjectList(iter->second);
+ for (auto it = refCountMap.begin(), end = refCountMap.end(); it != end; ++it)
+ Py_DECREF(it->second);
self->d->referredObjects->clear();
}
std::string info(SbkObject* self)
{
std::ostringstream s;
- std::list<SbkObjectType*> bases;
if (self->d && self->d->cptr) {
+ std::vector<SbkObjectType *> bases;
if (ObjectType::isUserType(Py_TYPE(self)))
bases = getCppBaseClasses(Py_TYPE(self));
else
bases.push_back(reinterpret_cast<SbkObjectType*>(Py_TYPE(self)));
s << "C++ address....... ";
- std::list<SbkObjectType*>::const_iterator it = bases.begin();
- for (int i = 0; it != bases.end(); ++it, ++i)
- s << reinterpret_cast<PyTypeObject *>(*it)->tp_name << '/' << self->d->cptr[i] << ' ';
+ for (size_t i = 0, size = bases.size(); i < size; ++i) {
+ auto base = reinterpret_cast<PyTypeObject *>(bases[i]);
+ s << base->tp_name << '/' << self->d->cptr[i] << ' ';
+ }
s << "\n";
}
else {
@@ -1533,9 +1504,8 @@ std::string info(SbkObject* self)
if (self->d->parentInfo && self->d->parentInfo->children.size()) {
s << "children.......... ";
- ChildrenList& children = self->d->parentInfo->children;
- for (ChildrenList::const_iterator it = children.begin(); it != children.end(); ++it) {
- Shiboken::AutoDecRef child(PyObject_Str(reinterpret_cast<PyObject *>(*it)));
+ for (SbkObject *sbkChild : self->d->parentInfo->children) {
+ Shiboken::AutoDecRef child(PyObject_Str(reinterpret_cast<PyObject *>(sbkChild)));
s << String::toCString(child) << ' ';
}
s << '\n';
@@ -1544,17 +1514,16 @@ std::string info(SbkObject* self)
if (self->d->referredObjects && self->d->referredObjects->size()) {
Shiboken::RefCountMap& map = *self->d->referredObjects;
s << "referred objects.. ";
- Shiboken::RefCountMap::const_iterator it = map.begin();
- for (; it != map.end(); ++it) {
- if (it != map.begin())
- s << " ";
- s << '"' << it->first << "\" => ";
- std::list<PyObject*>::const_iterator j = it->second.begin();
- for (; j != it->second.end(); ++j) {
- Shiboken::AutoDecRef obj(PyObject_Str(*j));
- s << String::toCString(obj) << ' ';
+ std::string lastKey;
+ for (auto it = map.begin(), end = map.end(); it != end; ++it) {
+ if (it->first != lastKey) {
+ if (!lastKey.empty())
+ s << " ";
+ s << '"' << it->first << "\" => ";
+ lastKey = it->first;
}
- s << ' ';
+ Shiboken::AutoDecRef obj(PyObject_Str(it->second));
+ s << String::toCString(obj) << ' ';
}
s << '\n';
}
diff --git a/sources/shiboken2/libshiboken/basewrapper_p.h b/sources/shiboken2/libshiboken/basewrapper_p.h
index ebd2648e7..a61d5c947 100644
--- a/sources/shiboken2/libshiboken/basewrapper_p.h
+++ b/sources/shiboken2/libshiboken/basewrapper_p.h
@@ -43,10 +43,10 @@
#include "sbkpython.h"
#include "basewrapper.h"
-#include <list>
-#include <map>
+#include <unordered_map>
#include <set>
#include <string>
+#include <vector>
struct SbkObject;
struct SbkObjectType;
@@ -58,7 +58,7 @@ namespace Shiboken
* This mapping associates a method and argument of an wrapper object with the wrapper of
* said argument when it needs the binding to help manage its reference count.
*/
-typedef std::map<std::string, std::list<PyObject*> > RefCountMap;
+typedef std::unordered_multimap<std::string, PyObject *> RefCountMap;
/// Linked list of SbkBaseWrapper pointers
typedef std::set<SbkObject*> ChildrenList;
@@ -153,7 +153,7 @@ namespace Shiboken
/**
* Utility function used to transform a PyObject that implements sequence protocol into a std::list.
**/
-std::list<SbkObject*> splitPyObject(PyObject* pyObj);
+std::vector<SbkObject *> splitPyObject(PyObject* pyObj);
/**
* Visitor class used by walkOnClassHierarchy function.
@@ -189,6 +189,8 @@ private:
class BaseAccumulatorVisitor : public HierarchyVisitor
{
public:
+ typedef std::vector<SbkObjectType *> Result;
+
BaseAccumulatorVisitor() {}
void visit(SbkObjectType* node)
@@ -196,9 +198,9 @@ public:
m_bases.push_back(node);
}
- std::list<SbkObjectType*> bases() const { return m_bases; }
+ Result bases() const { return m_bases; }
private:
- std::list<SbkObjectType*> m_bases;
+ Result m_bases;
};
class GetIndexVisitor : public HierarchyVisitor
@@ -226,7 +228,7 @@ public:
void visit(SbkObjectType* node);
void done();
protected:
- std::list<std::pair<void*, SbkObjectType*> > m_ptrs;
+ std::vector<std::pair<void *, SbkObjectType *> > m_ptrs;
SbkObject* m_pyObj;
};
@@ -260,7 +262,7 @@ inline int getNumberOfCppBaseClasses(PyTypeObject* baseType)
return visitor.count();
}
-inline std::list<SbkObjectType*> getCppBaseClasses(PyTypeObject* baseType)
+inline std::vector<SbkObjectType *> getCppBaseClasses(PyTypeObject* baseType)
{
BaseAccumulatorVisitor visitor;
walkThroughClassHierarchy(baseType, &visitor);
diff --git a/sources/shiboken2/libshiboken/bindingmanager.cpp b/sources/shiboken2/libshiboken/bindingmanager.cpp
index 2cc7847a8..5978f3a37 100644
--- a/sources/shiboken2/libshiboken/bindingmanager.cpp
+++ b/sources/shiboken2/libshiboken/bindingmanager.cpp
@@ -57,7 +57,7 @@ typedef std::unordered_map<const void *, SbkObject *> WrapperMap;
class Graph
{
public:
- typedef std::list<SbkObjectType*> NodeList;
+ typedef std::vector<SbkObjectType *> NodeList;
typedef std::unordered_map<SbkObjectType *, NodeList> Edges;
Edges m_edges;
@@ -78,14 +78,13 @@ public:
file << "digraph D {\n";
- Edges::const_iterator i = m_edges.begin();
- for (; i != m_edges.end(); ++i) {
- SbkObjectType* node1 = i->first;
+ for (auto i = m_edges.begin(), end = m_edges.end(); i != end; ++i) {
+ auto node1 = reinterpret_cast<const PyTypeObject *>(i->first);
const NodeList& nodeList = i->second;
- NodeList::const_iterator j = nodeList.begin();
- for (; j != nodeList.end(); ++j) {
- file << '"' << reinterpret_cast<PyTypeObject *>(*j)->tp_name << "\" -> \""
- << reinterpret_cast<PyTypeObject *>(node1)->tp_name << "\"\n";
+ for (const SbkObjectType *o : nodeList) {
+ auto node2 = reinterpret_cast<const PyTypeObject *>(o);
+ file << '"' << node2->tp_name << "\" -> \""
+ << node1->tp_name << "\"\n";
}
}
file << "}\n";
@@ -97,9 +96,8 @@ public:
Edges::const_iterator edgesIt = m_edges.find(type);
if (edgesIt != m_edges.end()) {
const NodeList& adjNodes = m_edges.find(type)->second;
- NodeList::const_iterator i = adjNodes.begin();
- for (; i != adjNodes.end(); ++i) {
- SbkObjectType* newType = identifyType(cptr, *i, baseType);
+ for (SbkObjectType *node : adjNodes) {
+ SbkObjectType* newType = identifyType(cptr, node, baseType);
if (newType)
return newType;
}
@@ -128,10 +126,9 @@ static void showWrapperMap(const WrapperMap& wrapperMap)
if (Py_VerboseFlag > 0) {
fprintf(stderr, "-------------------------------\n");
fprintf(stderr, "WrapperMap: %p (size: %d)\n", &wrapperMap, (int) wrapperMap.size());
- WrapperMap::const_iterator iter;
- for (iter = wrapperMap.begin(); iter != wrapperMap.end(); ++iter) {
- const SbkObject *sbkObj = iter->second;
- fprintf(stderr, "key: %p, value: %p (%s, refcnt: %d)\n", iter->first,
+ for (auto it = wrapperMap.begin(), end = wrapperMap.end(); it != end; ++it) {
+ const SbkObject *sbkObj = it->second;
+ fprintf(stderr, "key: %p, value: %p (%s, refcnt: %d)\n", it->first,
static_cast<const void *>(sbkObj),
(Py_TYPE(sbkObj))->tp_name,
int(reinterpret_cast<const PyObject *>(sbkObj)->ob_refcnt));
diff --git a/sources/shiboken2/libshiboken/sbkconverter.cpp b/sources/shiboken2/libshiboken/sbkconverter.cpp
index a13222de6..65844151f 100644
--- a/sources/shiboken2/libshiboken/sbkconverter.cpp
+++ b/sources/shiboken2/libshiboken/sbkconverter.cpp
@@ -246,10 +246,8 @@ PythonToCppFunc isPythonToCppPointerConvertible(SbkObjectType *type, PyObject *p
static inline PythonToCppFunc IsPythonToCppConvertible(const SbkConverter *converter, PyObject *pyIn)
{
assert(pyIn);
- const ToCppConversionList& convs = converter->toCppConversions;
- for (ToCppConversionList::const_iterator conv = convs.begin(), end = convs.end(); conv != end; ++conv) {
- PythonToCppFunc toCppFunc = 0;
- if ((toCppFunc = (*conv).first(pyIn)))
+ for (const ToCppConversion &c : converter->toCppConversions) {
+ if (PythonToCppFunc toCppFunc = c.first(pyIn))
return toCppFunc;
}
return 0;
@@ -361,7 +359,7 @@ bool isImplicitConversion(SbkObjectType *type, PythonToCppFunc toCppFunc)
// Note that we don't check if the Python to C++ conversion is in
// the list of the type's conversions, for it is expected that the
// caller knows what he's doing.
- ToCppConversionList::iterator conv = PepType_SOTP(type)->converter->toCppConversions.begin();
+ const auto conv = PepType_SOTP(type)->converter->toCppConversions.cbegin();
return toCppFunc != (*conv).second;
}
diff --git a/sources/shiboken2/libshiboken/sbkconverter_p.h b/sources/shiboken2/libshiboken/sbkconverter_p.h
index f39608663..a4edfe81e 100644
--- a/sources/shiboken2/libshiboken/sbkconverter_p.h
+++ b/sources/shiboken2/libshiboken/sbkconverter_p.h
@@ -43,11 +43,11 @@
#include "sbkpython.h"
#include "sbkconverter.h"
#include "sbkstring.h"
-#include <list>
#include <limits>
#include <typeinfo>
#include <sstream>
#include <iostream>
+#include <vector>
#include "sbkdbg.h"
@@ -55,7 +55,7 @@ extern "C"
{
typedef std::pair<IsConvertibleToCppFunc, PythonToCppFunc> ToCppConversion;
-typedef std::list<ToCppConversion> ToCppConversionList;
+typedef std::vector<ToCppConversion> ToCppConversionVector;
/**
* \internal
@@ -104,7 +104,7 @@ struct SbkConverter
* For Object Types, that never have implicit conversions, this
* list is always empty.
*/
- ToCppConversionList toCppConversions;
+ ToCppConversionVector toCppConversions;
};
} // extern "C"
diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp
index bd007f079..fb55267d1 100644
--- a/sources/shiboken2/libshiboken/sbkenum.cpp
+++ b/sources/shiboken2/libshiboken/sbkenum.cpp
@@ -47,7 +47,7 @@
#include <string.h>
#include <cstring>
-#include <list>
+#include <vector>
#define SBK_ENUM(ENUM) reinterpret_cast<SbkEnumObject*>(ENUM)
@@ -347,7 +347,7 @@ public:
private:
DeclaredEnumTypes(const DeclaredEnumTypes&);
DeclaredEnumTypes& operator=(const DeclaredEnumTypes&);
- std::list<PyTypeObject*> m_enumTypes;
+ std::vector<PyTypeObject *> m_enumTypes;
};
namespace Enum {
@@ -524,13 +524,8 @@ copyNumberMethods(PyTypeObject *flagsType,
int *pidx)
{
int idx = *pidx;
-#ifdef IS_PY3K
-# define SLOT slot
-#else
-# define SLOT slot_
-#endif
#define PUT_SLOT(name) \
- number_slots[idx].SLOT = (name); \
+ number_slots[idx].slot = (name); \
number_slots[idx].pfunc = PyType_GetSlot(flagsType, (name)); \
++idx;
@@ -593,8 +588,8 @@ newTypeWithName(const char* name,
newspec->flags = SbkNewType_spec.flags;
// we must append all the number methods, so rebuild everything:
int idx = 0;
- while (SbkNewType_slots[idx].SLOT) {
- newslots[idx].SLOT = SbkNewType_slots[idx].SLOT;
+ while (SbkNewType_slots[idx].slot) {
+ newslots[idx].slot = SbkNewType_slots[idx].slot;
newslots[idx].pfunc = SbkNewType_slots[idx].pfunc;
++idx;
}
@@ -650,8 +645,6 @@ DeclaredEnumTypes::DeclaredEnumTypes()
DeclaredEnumTypes::~DeclaredEnumTypes()
{
- std::list<PyTypeObject*>::const_iterator it = m_enumTypes.begin();
- for (; it != m_enumTypes.end(); ++it) {
/*
* PYSIDE-595: This was "delete *it;" before introducing 'PyType_FromSpec'.
* XXX what should I do now?
@@ -660,8 +653,8 @@ DeclaredEnumTypes::~DeclaredEnumTypes()
* So right now I am doing nothing. Surely wrong but no crash.
* See also the comment in function 'createGlobalEnumItem'.
*/
- //fprintf(stderr, "ttt %d %s\n", Py_REFCNT(*it), *it->tp_name);
- }
+ // for (PyTypeObject *o : m_enumTypes)
+ // fprintf(stderr, "ttt %d %s\n", Py_REFCNT(o), o->tp_name);
m_enumTypes.clear();
}
diff --git a/sources/shiboken2/libshiboken/sbkpython.h b/sources/shiboken2/libshiboken/sbkpython.h
index 29e25605a..610e4a3c7 100644
--- a/sources/shiboken2/libshiboken/sbkpython.h
+++ b/sources/shiboken2/libshiboken/sbkpython.h
@@ -42,19 +42,37 @@
#include "sbkversion.h"
+// Qt's "slots" macro collides with the "slots" member variables
+// used in some Python structs. For compilers that support push_macro,
+// temporarily undefine it.
+#if defined(slots) && (defined(__GNUC__) || defined(_MSC_VER) || defined(__clang__))
+# pragma push_macro("slots")
+# undef slots
/*
* Python 2 has function _Py_Mangle directly in Python.h .
* This creates wrong language binding unless we define 'extern "C"' here.
*/
extern "C" {
-#include <Python.h>
+# include <Python.h>
}
-#include <structmember.h>
+# include <structmember.h>
// Now we have the usual variables from Python.h .
-#include "python25compat.h"
-#include "shibokenmacros.h"
-#include "pep384impl.h"
-#include "typespec.h"
+# include "python25compat.h"
+# include "shibokenmacros.h"
+# include "pep384impl.h"
+# include "typespec.h"
+# pragma pop_macro("slots")
+#else
+extern "C" {
+# include <Python.h>
+}
+# include <structmember.h>
+// Now we have the usual variables from Python.h .
+# include "python25compat.h"
+# include "shibokenmacros.h"
+# include "pep384impl.h"
+# include "typespec.h"
+#endif
#if PY_MAJOR_VERSION >= 3
#define IS_PY3K
diff --git a/sources/shiboken2/libshiboken/typespec.cpp b/sources/shiboken2/libshiboken/typespec.cpp
index d532c97ed..9123a09e0 100644
--- a/sources/shiboken2/libshiboken/typespec.cpp
+++ b/sources/shiboken2/libshiboken/typespec.cpp
@@ -514,7 +514,7 @@ best_base(PyObject *bases)
}
static const short slotoffsets[] = {
- -1, /* invalid slot_ */
+ -1, /* invalid slot */
/* Generated by typeslots.py */
0,
0,
@@ -603,7 +603,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
PyObject *modname;
char *s;
char *res_start = (char*)res;
- PyType_Slot *slot_;
+ PyType_Slot *slot;
/* Set the type name and qualname */
s = (char *)strrchr(spec->name, '.'); // C++11
@@ -632,11 +632,11 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
if (!bases) {
base = &PyBaseObject_Type;
/* See whether Py_tp_base(s) was specified */
- for (slot_ = spec->slots; slot_->slot_; slot_++) {
- if (slot_->slot_ == Py_tp_base)
- base = (PyTypeObject *)slot_->pfunc; // C++11
- else if (slot_->slot_ == Py_tp_bases) {
- bases = (PyObject *)slot_->pfunc; // C++11
+ for (slot = spec->slots; slot->slot; slot++) {
+ if (slot->slot == Py_tp_base)
+ base = (PyTypeObject *)slot->pfunc; // C++11
+ else if (slot->slot == Py_tp_bases) {
+ bases = (PyObject *)slot->pfunc; // C++11
Py_INCREF(bases);
}
}
@@ -676,23 +676,23 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
type->tp_basicsize = spec->basicsize;
type->tp_itemsize = spec->itemsize;
- for (slot_ = spec->slots; slot_->slot_; slot_++) {
- if (slot_->slot_ < 0
- || (size_t)slot_->slot_ >= Py_ARRAY_LENGTH(slotoffsets)) {
- PyErr_SetString(PyExc_RuntimeError, "invalid slot_ offset");
+ for (slot = spec->slots; slot->slot; slot++) {
+ if (slot->slot < 0
+ || (size_t)slot->slot >= Py_ARRAY_LENGTH(slotoffsets)) {
+ PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
goto fail;
}
- if (slot_->slot_ == Py_tp_base || slot_->slot_ == Py_tp_bases)
+ if (slot->slot == Py_tp_base || slot->slot == Py_tp_bases)
/* Processed above */
continue;
- *(void**)(res_start + slotoffsets[slot_->slot_]) = slot_->pfunc;
+ *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc;
- /* need to make a copy of the docstring slot_, which usually
+ /* need to make a copy of the docstring slot, which usually
points to a static string literal */
- if (slot_->slot_ == Py_tp_doc) {
+ if (slot->slot == Py_tp_doc) {
// No signature in Python 2
- // const char *old_doc = _PyType_DocWithoutSignature(type->tp_name, slot_->pfunc);
- const char *old_doc = (const char *)slot_->pfunc;
+ // const char *old_doc = _PyType_DocWithoutSignature(type->tp_name, slot->pfunc);
+ const char *old_doc = (const char *)slot->pfunc;
size_t len = strlen(old_doc)+1;
char *tp_doc = (char *)PyObject_MALLOC(len); // C++11
if (tp_doc == NULL) {
@@ -759,17 +759,17 @@ PyType_FromSpec(PyType_Spec *spec)
}
void *
-PyType_GetSlot(PyTypeObject *type, int slot_)
+PyType_GetSlot(PyTypeObject *type, int slot)
{
- if (!PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE) || slot_ < 0) {
+ if (!PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE) || slot < 0) {
PyErr_BadInternalCall();
return NULL;
}
- if ((size_t)slot_ >= Py_ARRAY_LENGTH(slotoffsets)) {
- /* Extension module requesting slot_ from a future version */
+ if ((size_t)slot >= Py_ARRAY_LENGTH(slotoffsets)) {
+ /* Extension module requesting slot from a future version */
return NULL;
}
- return *(void**)(((char*)type) + slotoffsets[slot_]);
+ return *(void**)(((char*)type) + slotoffsets[slot]);
}
} // extern "C"
diff --git a/sources/shiboken2/libshiboken/typespec.h b/sources/shiboken2/libshiboken/typespec.h
index 799fcb1b8..46e7dec89 100644
--- a/sources/shiboken2/libshiboken/typespec.h
+++ b/sources/shiboken2/libshiboken/typespec.h
@@ -48,7 +48,7 @@ extern "C"
{
typedef struct{
- int slot_; // slot is somehow reserved in Qt /* slot id, see below */
+ int slot; // slot is somehow reserved in Qt /* slot id, see below */
void *pfunc; /* function pointer */
} PyType_Slot;