Skip to content

Commit b784974

Browse files
committed
Sync PyCallable, PyException and PyStrings
1 parent 243d9ad commit b784974

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/PyCallable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef CPYCPPYY_PYCALLABLE_H
22
#define CPYCPPYY_PYCALLABLE_H
33

4+
#include <climits>
5+
46
// Bindings
57
#include "CPyCppyy/Reflex.h"
68
#include "CallContext.h"
@@ -38,6 +40,8 @@ class PyCallable {
3840

3941
virtual PyCallable* Clone() = 0;
4042

43+
virtual int GetArgMatchScore(PyObject* /* args_tuple */) { return INT_MAX; }
44+
4145
public:
4246
virtual PyObject* Call(CPPInstance*& self,
4347
CPyCppyy_PyArgs_t args, size_t nargsf, PyObject* kwds, CallContext* ctxt = nullptr) = 0;

src/PyException.cxx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,18 @@ CPyCppyy::PyException::PyException()
9393
if (fMsg.empty())
9494
fMsg = "python exception";
9595

96-
// only keeping the filename, not the full path
97-
if (!locFile.empty())
96+
if (!locFile.empty()) {
97+
98+
// only keeping the filename, not the full path
9899
locFile = locFile.substr(locFile.find_last_of("/\\") + 1);
99100

100-
fMsg += " (at " + locFile + ":" + std::to_string(locLine);
101+
fMsg += " (at " + locFile + ":" + std::to_string(locLine);
101102

102-
if (locName != "<module>")
103-
fMsg += " in " + locName;
103+
if (locName != "<module>")
104+
fMsg += " in " + locName;
104105

105-
fMsg += ")";
106+
fMsg += ")";
107+
}
106108

107109
#ifdef WITH_THREAD
108110
PyGILState_Release(state);

src/PyStrings.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
PyObject* CPyCppyy::PyStrings::gAssign = nullptr;
88
PyObject* CPyCppyy::PyStrings::gBases = nullptr;
99
PyObject* CPyCppyy::PyStrings::gBase = nullptr;
10+
PyObject* CPyCppyy::PyStrings::gCppBool = nullptr;
1011
PyObject* CPyCppyy::PyStrings::gCppName = nullptr;
1112
PyObject* CPyCppyy::PyStrings::gAnnotations = nullptr;
1213
PyObject* CPyCppyy::PyStrings::gCastCpp = nullptr;
@@ -86,6 +87,11 @@ bool CPyCppyy::CreatePyStrings() {
8687
CPPYY_INITIALIZE_STRING(gAssign, __assign__);
8788
CPPYY_INITIALIZE_STRING(gBases, __bases__);
8889
CPPYY_INITIALIZE_STRING(gBase, __base__);
90+
#if PY_VERSION_HEX < 0x03000000
91+
CPPYY_INITIALIZE_STRING(gCppBool, __cpp_nonzero__);
92+
#else
93+
CPPYY_INITIALIZE_STRING(gCppBool, __cpp_bool__);
94+
#endif
8995
CPPYY_INITIALIZE_STRING(gCppName, __cpp_name__);
9096
CPPYY_INITIALIZE_STRING(gAnnotations, __annotations__);
9197
CPPYY_INITIALIZE_STRING(gCastCpp, __cast_cpp__);
@@ -163,6 +169,7 @@ PyObject* CPyCppyy::DestroyPyStrings() {
163169
// Remove all cached python strings.
164170
Py_DECREF(PyStrings::gBases); PyStrings::gBases = nullptr;
165171
Py_DECREF(PyStrings::gBase); PyStrings::gBase = nullptr;
172+
Py_DECREF(PyStrings::gCppBool); PyStrings::gCppBool = nullptr;
166173
Py_DECREF(PyStrings::gCppName); PyStrings::gCppName = nullptr;
167174
Py_DECREF(PyStrings::gAnnotations); PyStrings::gAnnotations = nullptr;
168175
Py_DECREF(PyStrings::gCType); PyStrings::gCType = nullptr;

src/PyStrings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace PyStrings {
1010
extern PyObject* gAssign;
1111
extern PyObject* gBases;
1212
extern PyObject* gBase;
13+
extern PyObject* gCppBool;
1314
extern PyObject* gCppName;
1415
extern PyObject* gAnnotations;
1516
extern PyObject* gCastCpp;

0 commit comments

Comments
 (0)