Skip to content

Commit 369a183

Browse files
committed
[Python] Sync cppyy and CPyCppyy with current master branches
Sync `cppyy` and `CPyCppyy` with current master branches to start validating recent fixes in cppyy for the next ROOT release.
1 parent 6917757 commit 369a183

25 files changed

+294
-36
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[build-system]
2-
requires = ["cppyy-cling==6.30.0", "cppyy-backend==1.15.2", "setuptools", "wheel"]
2+
requires = ["cppyy-cling==6.32.8", "cppyy-backend==1.15.3", "setuptools", "wheel"]

bindings/pyroot/cppyy/CPyCppyy/src/CPPClassMethod.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ PyObject* CPyCppyy::CPPClassMethod::Call(CPPInstance*&
4848
// execute function
4949
return this->Execute(nullptr, 0, ctxt);
5050
}
51+
52+
//----------------------------------------------------------------------------
53+
PyObject* CPyCppyy::CPPClassMethod::GetTypeName()
54+
{
55+
PyObject* cppname = CPyCppyy_PyText_FromString((GetReturnTypeName() + " (*)").c_str());
56+
CPyCppyy_PyText_AppendAndDel(&cppname, GetSignature(false /* show_formalargs */));
57+
return cppname;
58+
}

bindings/pyroot/cppyy/CPyCppyy/src/CPPClassMethod.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class CPPClassMethod : public CPPMethod {
1111
public:
1212
using CPPMethod::CPPMethod;
1313

14+
public:
15+
virtual PyObject* GetTypeName();
16+
17+
public:
1418
virtual PyCallable* Clone() { return new CPPClassMethod(*this); }
1519
virtual PyObject* Call(CPPInstance*& self,
1620
CPyCppyy_PyArgs_t args, size_t nargsf, PyObject* kwds, CallContext* ctxt = nullptr);

bindings/pyroot/cppyy/CPyCppyy/src/CPPEnum.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,13 @@ CPyCppyy::CPPEnum* CPyCppyy::CPPEnum_New(const std::string& name, Cppyy::TCppSco
204204
values_ok = false;
205205
break;
206206
}
207-
PyObject* pydname = CPyCppyy_PyText_FromString(Cppyy::GetEnumDataName(etype, idata).c_str());
207+
const std::string& dname = Cppyy::GetEnumDataName(etype, idata);
208+
PyObject* pydname = CPyCppyy_PyText_FromString(dname.c_str());
208209
PyObject_SetAttr(pyenum, pydname, val);
209-
PyObject_SetAttr(val, PyStrings::gCppName, pydname);
210210
Py_DECREF(pydname);
211+
PyObject* pydcppname = CPyCppyy_PyText_FromString((ename.empty() ? dname : (ename+"::"+dname)).c_str());
212+
PyObject_SetAttr(val, PyStrings::gCppName, pydcppname);
213+
Py_DECREF(pydcppname);
211214
Py_DECREF(val);
212215
}
213216

bindings/pyroot/cppyy/CPyCppyy/src/CPPFunction.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ PyObject* CPyCppyy::CPPFunction::Call(CPPInstance*& self,
102102
return result;
103103
}
104104

105+
//----------------------------------------------------------------------------
106+
PyObject* CPyCppyy::CPPFunction::GetTypeName()
107+
{
108+
PyObject* cppname = CPyCppyy_PyText_FromString((GetReturnTypeName() + " (*)").c_str());
109+
CPyCppyy_PyText_AppendAndDel(&cppname, GetSignature(false /* show_formalargs */));
110+
return cppname;
111+
}
112+
105113

106114
//- CPPReverseBinary private helper ---------------------------------------------
107115
bool CPyCppyy::CPPReverseBinary::ProcessArgs(PyCallArgs& cargs)

bindings/pyroot/cppyy/CPyCppyy/src/CPPFunction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class CPPFunction : public CPPMethod {
1212
public:
1313
using CPPMethod::CPPMethod;
1414

15+
public:
16+
virtual PyObject* GetTypeName();
17+
18+
public:
1519
virtual PyCallable* Clone() { return new CPPFunction(*this); }
1620
virtual PyObject* Call(CPPInstance*& self,
1721
CPyCppyy_PyArgs_t args, size_t nargsf, PyObject* kwds, CallContext* ctxt = nullptr);

bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ PyObject* CPyCppyy::CPPMethod::GetPrototype(bool fa)
410410
//----------------------------------------------------------------------------
411411
PyObject* CPyCppyy::CPPMethod::GetTypeName()
412412
{
413-
PyObject* cppname = CPyCppyy_PyText_FromString((GetReturnTypeName() + " (*)").c_str());
413+
PyObject* cppname = CPyCppyy_PyText_FromString(
414+
(GetReturnTypeName() + \
415+
" (" + (fScope ? Cppyy::GetScopedFinalName(fScope) + "::*)" : "*)")).c_str());
414416
CPyCppyy_PyText_AppendAndDel(&cppname, GetSignature(false /* show_formalargs */));
415417
return cppname;
416418
}
@@ -644,6 +646,10 @@ PyObject* CPyCppyy::CPPMethod::GetArgDefault(int iarg, bool silent)
644646
if (2 < defvalue.size() && defvalue[defvalue.size()-2] == 'U')
645647
offset = 2;
646648
defvalue = defvalue.substr(0, defvalue.size()-offset);
649+
} else if (defvalue == "true") {
650+
defvalue = "True";
651+
} else if (defvalue == "false") {
652+
defvalue = "False";
647653
}
648654
}
649655

bindings/pyroot/cppyy/CPyCppyy/src/Converters.cxx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <regex>
2727
#include <utility>
2828
#include <sstream>
29-
#if __cplusplus > 201402L
29+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
3030
#include <cstddef>
3131
#include <string_view>
3232
#endif
@@ -58,7 +58,7 @@ namespace CPyCppyy {
5858
extern PyObject* gDefaultObject;
5959

6060
// regular expression for matching function pointer
61-
static std::regex s_fnptr("\\(:*\\*&*\\)");
61+
static std::regex s_fnptr("\\((\\w*:*)*\\*&*\\)");
6262
}
6363

6464
#if PY_VERSION_HEX < 0x03000000
@@ -1749,7 +1749,7 @@ bool CPyCppyy::name##ArrayConverter::ToMemory( \
17491749
CPPYY_IMPL_ARRAY_CONVERTER(Bool, c_bool, bool, '?', )
17501750
CPPYY_IMPL_ARRAY_CONVERTER(SChar, c_char, signed char, 'b', )
17511751
CPPYY_IMPL_ARRAY_CONVERTER(UChar, c_ubyte, unsigned char, 'B', )
1752-
#if __cplusplus > 201402L
1752+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
17531753
CPPYY_IMPL_ARRAY_CONVERTER(Byte, c_ubyte, std::byte, 'B', )
17541754
#endif
17551755
CPPYY_IMPL_ARRAY_CONVERTER(Int8, c_byte, int8_t, 'b', _i8)
@@ -2001,7 +2001,7 @@ bool CPyCppyy::STLWStringConverter::ToMemory(PyObject* value, void* address, PyO
20012001
}
20022002

20032003

2004-
#if __cplusplus > 201402L
2004+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
20052005
CPyCppyy::STLStringViewConverter::STLStringViewConverter(bool keepControl) :
20062006
InstanceConverter(Cppyy::GetScope("std::string_view"), keepControl) {}
20072007

@@ -2238,7 +2238,11 @@ bool CPyCppyy::InstanceConverter::ToMemory(PyObject* value, void* address, PyObj
22382238
{
22392239
// assign value to C++ instance living at <address> through assignment operator
22402240
PyObject* pyobj = BindCppObjectNoCast(address, fClass);
2241+
#if PY_VERSION_HEX >= 0x03080000
2242+
PyObject* result = PyObject_CallMethodOneArg(pyobj, PyStrings::gAssign, value);
2243+
#else
22412244
PyObject* result = PyObject_CallMethod(pyobj, (char*)"__assign__", (char*)"O", value);
2245+
#endif
22422246
Py_DECREF(pyobj);
22432247

22442248
if (result) {
@@ -2957,6 +2961,25 @@ PyObject* CPyCppyy::SmartPtrConverter::FromMemory(void* address)
29572961
return BindCppObjectNoCast(address, fSmartPtrType);
29582962
}
29592963

2964+
bool CPyCppyy::SmartPtrConverter::ToMemory(PyObject* value, void* address, PyObject*)
2965+
{
2966+
// assign value to C++ instance living at <address> through assignment operator (this
2967+
// is similar to InstanceConverter::ToMemory, but prevents wrapping the smart ptr)
2968+
PyObject* pyobj = BindCppObjectNoCast(address, fSmartPtrType, CPPInstance::kNoWrapConv);
2969+
#if PY_VERSION_HEX >= 0x03080000
2970+
PyObject* result = PyObject_CallMethodOneArg(pyobj, PyStrings::gAssign, value);
2971+
#else
2972+
PyObject* result = PyObject_CallMethod(pyobj, (char*)"__assign__", (char*)"O", value);
2973+
#endif
2974+
Py_DECREF(pyobj);
2975+
2976+
if (result) {
2977+
Py_DECREF(result);
2978+
return true;
2979+
}
2980+
return false;
2981+
}
2982+
29602983

29612984
//----------------------------------------------------------------------------
29622985
namespace {
@@ -3497,7 +3520,7 @@ static struct InitConvFactories_t {
34973520
gf["SCharAsInt[]"] = gf["signed char ptr"];
34983521
gf["UCharAsInt*"] = gf["unsigned char ptr"];
34993522
gf["UCharAsInt[]"] = gf["unsigned char ptr"];
3500-
#if __cplusplus > 201402L
3523+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
35013524
gf["std::byte ptr"] = (cf_t)+[](cdims_t d) { return new ByteArrayConverter{d}; };
35023525
#endif
35033526
gf["int8_t ptr"] = (cf_t)+[](cdims_t d) { return new Int8ArrayConverter{d}; };
@@ -3520,7 +3543,7 @@ static struct InitConvFactories_t {
35203543
// aliases
35213544
gf["signed char"] = gf["char"];
35223545
gf["const signed char&"] = gf["const char&"];
3523-
#if __cplusplus > 201402L
3546+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
35243547
gf["std::byte"] = gf["uint8_t"];
35253548
gf["byte"] = gf["uint8_t"];
35263549
gf["const std::byte&"] = gf["const uint8_t&"];
@@ -3584,7 +3607,7 @@ static struct InitConvFactories_t {
35843607
gf["const string&"] = gf["std::string"];
35853608
gf["std::string&&"] = (cf_t)+[](cdims_t) { return new STLStringMoveConverter{}; };
35863609
gf["string&&"] = gf["std::string&&"];
3587-
#if __cplusplus > 201402L
3610+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
35883611
gf["std::string_view"] = (cf_t)+[](cdims_t) { return new STLStringViewConverter{}; };
35893612
gf[STRINGVIEW] = gf["std::string_view"];
35903613
gf["std::string_view&"] = gf["std::string_view"];

bindings/pyroot/cppyy/CPyCppyy/src/DeclareConverters.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class CString32Converter : public Converter {
210210
CPPYY_DECLARE_ARRAY_CONVERTER(Bool);
211211
CPPYY_DECLARE_ARRAY_CONVERTER(SChar);
212212
CPPYY_DECLARE_ARRAY_CONVERTER(UChar);
213-
#if __cplusplus > 201402L
213+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
214214
CPPYY_DECLARE_ARRAY_CONVERTER(Byte);
215215
#endif
216216
CPPYY_DECLARE_ARRAY_CONVERTER(Int8);
@@ -376,7 +376,7 @@ protected: \
376376
CPPYY_DECLARE_STRING_CONVERTER(TString, TString);
377377
CPPYY_DECLARE_STRING_CONVERTER(STLString, std::string);
378378
CPPYY_DECLARE_STRING_CONVERTER(STLWString, std::wstring);
379-
#if __cplusplus > 201402L
379+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
380380
CPPYY_DECLARE_STRING_CONVERTER(STLStringView, std::string_view);
381381
#endif
382382

@@ -438,7 +438,7 @@ class SmartPtrConverter : public Converter {
438438
public:
439439
virtual bool SetArg(PyObject*, Parameter&, CallContext* = nullptr);
440440
virtual PyObject* FromMemory(void* address);
441-
//virtual bool ToMemory(PyObject*, void*, PyObject* = nullptr);
441+
virtual bool ToMemory(PyObject*, void*, PyObject* = nullptr);
442442
virtual bool HasState() { return true; }
443443

444444
protected:

bindings/pyroot/cppyy/CPyCppyy/src/DeclareExecutors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "Dimensions.h"
88

99
// Standard
10-
#if __cplusplus > 201402L
10+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
1111
#include <cstddef>
1212
#endif
1313

@@ -65,7 +65,7 @@ CPPYY_ARRAY_DECL_EXEC(Void);
6565
CPPYY_ARRAY_DECL_EXEC(Bool);
6666
CPPYY_ARRAY_DECL_EXEC(SChar);
6767
CPPYY_ARRAY_DECL_EXEC(UChar);
68-
#if __cplusplus > 201402L
68+
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
6969
CPPYY_ARRAY_DECL_EXEC(Byte);
7070
#endif
7171
CPPYY_ARRAY_DECL_EXEC(Int8);

0 commit comments

Comments
 (0)