forked from APrioriInvestments/typed_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonSubclassType.cpp
More file actions
37 lines (26 loc) · 992 Bytes
/
Copy pathPythonSubclassType.cpp
File metadata and controls
37 lines (26 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "AllTypes.hpp"
bool PythonSubclass::isBinaryCompatibleWithConcrete(Type* other) {
Type* nonPyBase = m_base;
while (nonPyBase->getTypeCategory() == TypeCategory::catPythonSubclass) {
nonPyBase = nonPyBase->getBaseType();
}
Type* otherNonPyBase = other;
while (otherNonPyBase->getTypeCategory() == TypeCategory::catPythonSubclass) {
otherNonPyBase = otherNonPyBase->getBaseType();
}
return nonPyBase->isBinaryCompatibleWith(otherNonPyBase);
}
// static
PythonSubclass* PythonSubclass::Make(Type* base, PyTypeObject* pyType) {
static std::mutex guard;
std::lock_guard<std::mutex> lock(guard);
typedef std::pair<Type*, PyTypeObject*> keytype;
static std::map<keytype, PythonSubclass*> m;
auto it = m.find(keytype(base, pyType));
if (it == m.end()) {
it = m.insert(
std::make_pair(keytype(base,pyType), new PythonSubclass(base, pyType))
).first;
}
return it->second;
}