Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README/ReleaseNotes/v632/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,48 @@ Please use the higher-level functions `RooAbsPdf::createNLL()` and `RooAbsPdf::c
## PROOF Libraries


## PyROOT


### Rebase of PyROOT on the current cppyy

PyROOT was rebased on the latest version of the [cppyy library](https://cppyy.readthedocs.io/en/latest/).
This means PyROOT benefits from many upstream improvements and fixes, for example related to the conversion of NumPy arrays to vectors, implicit conversion from nested Python tuples to nested initializer lists, and improved overload resolution.

Related to this cppyy upgrade, there is one change in PyROOT behavior.
A static size character buffer of type `char[n]` is not converted to a Python string anymore.
The reason for this: since it was previously assumed the string was
null-terminated, there was no way to get the bytes after a `null`, even if you
wanted to.

```
import ROOT

ROOT.gInterpreter.Declare("""
struct Struct { char char_buffer[5] {}; }; // struct with char[n]
void fill_char_buffer(Struct & st) {
std::string foo{"foo"};
std::memcpy(st.char_buffer, foo.data(), foo.size());
}
""")

struct = ROOT.Struct()
ROOT.fill_char_buffer(struct)
char_buffer = struct.char_buffer

# With thew new cppyy, you get access to the lower level buffer instead of a
# Python string:
print("struct.char_buffer : ", char_buffer)

# However, you can turn the buffer into a string very easily with as_string():
print("struct.char_buffer.as_string(): ", char_buffer.as_string())
```
The output of this script with ROOT 6.32:
```
struct.char_buffer : <cppyy.LowLevelView object at 0x74c7a2682fb0>
struct.char_buffer.as_string(): foo
```

## Language Bindings


Expand Down
3 changes: 3 additions & 0 deletions bindings/pyroot/cppyy/CPyCppyy/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
# build products
dist
*.egg-info
__pycache__
.cache
.pytest_cache
.vscode
build
28 changes: 17 additions & 11 deletions bindings/pyroot/cppyy/CPyCppyy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# For the list of contributors see $ROOTSYS/README/CREDITS.

set(headers
inc/CPyCppyy/API.h
inc/CPyCppyy/Reflex.h
inc/CPyCppyy/PyResult.h
inc/CPyCppyy/CommonDefs.h
inc/CPyCppyy/PyException.h
inc/CPyCppyy/DispatchPtr.h
include/CPyCppyy/API.h
include/CPyCppyy/Reflex.h
include/CPyCppyy/PyResult.h
include/CPyCppyy/CommonDefs.h
include/CPyCppyy/PyException.h
include/CPyCppyy/DispatchPtr.h
)

set(sources
Expand All @@ -20,10 +20,12 @@ set(sources
src/CPPClassMethod.cxx
src/CPPConstructor.cxx
src/CPPDataMember.cxx
src/CPPEnum.cxx
src/CPPExcInstance.cxx
src/CPPFunction.cxx
src/CPPInstance.cxx
src/CPPMethod.cxx
src/CPPOperator.cxx
src/CPPOverload.cxx
src/CPPScope.cxx
src/CPPGetSetItem.cxx
Expand Down Expand Up @@ -64,8 +66,7 @@ else()
endif()

if(NOT MSVC)
target_compile_options(${libname} PRIVATE
-Wno-shadow -Wno-strict-aliasing)
target_compile_options(${libname} PRIVATE -Wno-strict-aliasing)
endif()
if(NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND NOT MSVC)
target_compile_options(${libname} PRIVATE
Expand All @@ -77,19 +78,24 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION} V
target_compile_options(${libname} PRIVATE -Wno-cast-function-type)
endif()

# Disables warnings due to new field tp_vectorcall in Python 3.8
if(NOT MSVC AND PYTHON_VERSION_STRING VERSION_GREATER_EQUAL 3.8)
# Disables warnings in Python 3.8 caused by the temporary extra filed for tp_print compatibility
# (see https://github.com/python/cpython/blob/3.8/Include/cpython/object.h#L260).
# Note that Python 3.8 is the lowers Python version that is still supported by
# ROOT, so this compile option can be completely removed soon.
if(NOT MSVC AND PYTHON_VERSION_STRING VERSION_LESS 3.9)
target_compile_options(${libname} PRIVATE -Wno-missing-field-initializers)
endif()

target_compile_definitions(${libname} PRIVATE NO_CPPYY_LEGACY_NAMESPACE)

target_include_directories(${libname}
SYSTEM PUBLIC ${PYTHON_INCLUDE_DIRS})

target_include_directories(${libname}
PRIVATE
${CMAKE_BINARY_DIR}/ginclude
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

set_property(GLOBAL APPEND PROPERTY ROOT_EXPORTED_TARGETS ${libname})
Expand Down
10 changes: 8 additions & 2 deletions bindings/pyroot/cppyy/CPyCppyy/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2002-2019, The Regents of the University of California,
Copyright (c) 2002-2021, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of
any required approvals from the U.S. Dept. of Energy). All rights
reserved. Redistribution and use in source and binary forms, with or
Expand Down Expand Up @@ -48,5 +48,11 @@ the same conditions (except for some compatible licenses as retained in the
source code):

CERN
Toby StClere-Smithe
Lucio Asnaghi
Torok Attila
Simone Bacchio
Niko Fink
Aaron Jomy
Mac Kolin
Baidyanath Kundu
Toby StClere-Smithe
2 changes: 1 addition & 1 deletion bindings/pyroot/cppyy/CPyCppyy/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Change log:
https://cppyy.readthedocs.io/en/latest/changelog.html

Bug reports/feedback:
https://bitbucket.org/wlav/cppyy/issues?status=new&status=open
https://github.com/wlav/cppyy/issues
29 changes: 0 additions & 29 deletions bindings/pyroot/cppyy/CPyCppyy/inc/CPyCppyy/Reflex.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#ifndef CPYCPPYY_TPYTHON
#define CPYCPPYY_TPYTHON
#ifndef CPYCPPYY_API_H
#define CPYCPPYY_API_H

//////////////////////////////////////////////////////////////////////////////
// //
// TPython //
// //
// Access to the python interpreter and API onto CPyCppyy. //
// //
//////////////////////////////////////////////////////////////////////////////
//
// Access to the python interpreter and API onto CPyCppyy.
//

// Python
#ifdef _WIN32
Expand All @@ -29,6 +25,8 @@
#endif
#include "Python.h"

#define CPYCPPYY_VERSION_HEX 0x010c10

// Cppyy types
namespace Cppyy {
typedef size_t TCppScope_t;
Expand Down Expand Up @@ -86,6 +84,25 @@ struct Parameter {
// CallContext is not currently exposed
struct CallContext;

// Dimensions class not currently exposed
#ifndef CPYCPPYY_DIMENSIONS_H
#define CPYCPPYY_DIMENSIONS_H
typedef Py_ssize_t dim_t;

class Dimensions { // Windows note: NOT exported/imported
dim_t* fDims;

public:
Dimensions(dim_t /*ndim*/ = 0, dim_t* /*dims*/ = nullptr) : fDims(nullptr) {}
~Dimensions() { delete [] fDims; }

public:
operator bool() const { return (bool)fDims; }
};

typedef Dimensions dims_t;
typedef const dims_t& cdims_t;
#endif // !CPYCPPYY_DIMENSIONS_H

// type converter base class
class CPYCPPYY_CLASS_EXTERN Converter {
Expand All @@ -106,13 +123,13 @@ class CPYCPPYY_CLASS_EXTERN Converter {
};

// create a converter based on its full type name and dimensions
CPYCPPYY_EXTERN Converter* CreateConverter(const std::string& name, Py_ssize_t* dims = nullptr);
CPYCPPYY_EXTERN Converter* CreateConverter(const std::string& name, cdims_t = 0);

// delete a previously created converter
CPYCPPYY_EXTERN void DestroyConverter(Converter* p);

// register a custom converter
typedef Converter* (*ConverterFactory_t)(Py_ssize_t* dims);
typedef Converter* (*ConverterFactory_t)(cdims_t);
CPYCPPYY_EXTERN bool RegisterConverter(const std::string& name, ConverterFactory_t);

// remove a custom converter
Expand All @@ -133,13 +150,13 @@ class CPYCPPYY_CLASS_EXTERN Executor {
};

// create an executor based on its full type name
CPYCPPYY_EXTERN Executor* CreateExecutor(const std::string& name);
CPYCPPYY_EXTERN Executor* CreateExecutor(const std::string& name, cdims_t = 0);

// delete a previously created executor
CPYCPPYY_EXTERN void DestroyConverter(Converter* p);

// register a custom executor
typedef Executor* (*ExecutorFactory_t)();
typedef Executor* (*ExecutorFactory_t)(cdims_t);
CPYCPPYY_EXTERN bool RegisterExecutor(const std::string& name, ExecutorFactory_t);

// remove a custom executor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CPYCPPYY_CLASS_EXTERN DispatchPtr {
// Conversion constructor: called with C++ object construction when the PyObject
// is known (eg. when instantiating from Python), with pyobj the Python-side
// representation of the C++ object.
explicit DispatchPtr(PyObject* pyobj);
explicit DispatchPtr(PyObject* pyobj, bool strong = false);

// Copy constructor: only ever called from C++. The Python object needs to be
// copied, in case it has added state, and rebound to the new C++ instance.
Expand All @@ -47,10 +47,7 @@ class CPYCPPYY_CLASS_EXTERN DispatchPtr {
DispatchPtr& operator=(const DispatchPtr& other) = delete;

// lifetime is directly bound to the lifetime of the dispatcher object
~DispatchPtr() {
Py_XDECREF(fPyWeakRef);
Py_XDECREF(fPyHardRef);
}
~DispatchPtr();

// either C++ owns the Python object through a reference count (on fPyHardRef) or
// Python owns the C++ object and we only have a weak reference (through fPyWeakRef)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

// Standard
#include <exception>
#include <string>

// Bindings
#include "CPyCppyy/CommonDefs.h"
Expand All @@ -42,6 +43,12 @@ class CPYCPPYY_CLASS_EXTERN PyException : public std::exception {

// give reason for raised exception
virtual const char* what() const noexcept;

// clear Python error, to allow full error handling C++ side
void clear() const noexcept;

private:
std::string fMsg;
};

} // namespace CPyCppyy
Expand Down
30 changes: 30 additions & 0 deletions bindings/pyroot/cppyy/CPyCppyy/include/CPyCppyy/Reflex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef CPYCPPYY_REFLEX_H
#define CPYCPPYY_REFLEX_H

//
// Access to the C++ reflection information
//

namespace Cppyy {

namespace Reflex {

typedef int RequestId_t;

const RequestId_t IS_NAMESPACE = 1;
const RequestId_t IS_AGGREGATE = 2;

const RequestId_t OFFSET = 16;
const RequestId_t RETURN_TYPE = 17;
const RequestId_t TYPE = 18;

typedef int FormatId_t;
const FormatId_t OPTIMAL = 1;
const FormatId_t AS_TYPE = 2;
const FormatId_t AS_STRING = 3;

} // namespace Reflex

} // namespace Cppyy

#endif // !CPYCPPYY_REFLEX_H
2 changes: 2 additions & 0 deletions bindings/pyroot/cppyy/CPyCppyy/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build-system]
requires = ["cppyy-cling==6.30.0", "cppyy-backend==1.15.2", "setuptools", "wheel"]
2 changes: 1 addition & 1 deletion bindings/pyroot/cppyy/CPyCppyy/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
universal=0

[metadata]
license_file = LICENSE.txt
license_files = LICENSE.txt
Loading