#include <babeltrace2/func-status.h>
#undef __BT_IN_BABELTRACE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct auto_source_discovery {
/* Array of `struct auto_source_discovery_result *`. */
GPtrArray *results;
struct auto_source_discovery *auto_disc,
const bt_interrupter *interrupter);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* BABELTRACE_AUTODISC_AUTODISC_H */
# Non-generated files built into the native library.
STATIC_NATIVE_LIB_SRCS = \
- bt2/logging.c \
- bt2/logging.h
+ bt2/logging.cpp \
+ bt2/logging.hpp
STATIC_BINDINGS_DEPS = \
bt2/__init__.py \
$(top_builddir)/src/string-format/libstring-format.la
GENERATED_BINDINGS_DEPS = \
- bt2/native_bt.c \
+ bt2/native_bt.cpp \
bt2/version.py \
setup.py
# have renamed this global to `Swig_This_global`.
#
# Disable -Wshadow for that file.
-WARN_CFLAGS = -Wno-shadow
+WARN_CXXFLAGS = -Wno-shadow
-WARN_CFLAGS += -Wno-null-dereference
+WARN_CXXFLAGS += -Wno-null-dereference
# Python 3.8 with SWIG 4.0.2 generates a deprecated warning for 'tp_print'
# and in general there is not much we can do about deprecations in generated
# code.
-WARN_CFLAGS += -Wno-deprecated-declarations
+WARN_CXXFLAGS += -Wno-deprecated-declarations
# Python 3.11 + gcc 12.2.0 gave warnings of this kind in Python.h.
-WARN_CFLAGS += -Wno-redundant-decls
+WARN_CXXFLAGS += -Wno-redundant-decls
# For SWIG generated code
-WARN_CFLAGS += -Wno-missing-field-initializers
-WARN_CFLAGS += -Wno-unused-parameter
+WARN_CXXFLAGS += -Wno-missing-field-initializers
+WARN_CXXFLAGS += -Wno-unused-parameter
-# SWIG 4.2.0 generates:
-#
-# #if __cplusplus >=201103L
-#
-# ... leading to some `-Wundef` warnings when building the extension as C, where
-# `__cplusplus` is not defined.
-WARN_CFLAGS += -Wno-undef
-
-BUILD_FLAGS=CC="$(CC)" \
- CFLAGS="$(GLIB_CFLAGS) $(AM_CFLAGS) $(CFLAGS) $(WARN_CFLAGS)" \
- CPPFLAGS="$(AM_CPPFLAGS) $(CPPFLAGS) -I$(srcdir)/bt2" \
- LDFLAGS="$(AM_LDFLAGS) $(LDFLAGS) $(GLIB_LIBS) $(PYTHON_LDFLAGS) $(LIBS)"
+BUILD_FLAGS= \
+ CC="$(CC)" \
+ CXX="$(CXX)" \
+ CXXFLAGS="$(GLIB_CFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(WARN_CXXFLAGS)" \
+ CPPFLAGS="$(AM_CPPFLAGS) $(CPPFLAGS) -I$(srcdir)/bt2" \
+ LDFLAGS="$(AM_LDFLAGS) $(LDFLAGS) $(GLIB_LIBS) $(PYTHON_LDFLAGS) $(LIBS)"
SETUP_PY=$(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py
swig_verbose_ = $(swig_verbose_@AM_DEFAULT_V@)
swig_verbose_0 = @echo " SWIG " $@;
-$(builddir)/bt2/native_bt.c: $(SWIG_INTERFACE_FILES)
- $(swig_verbose)$(SWIG) -MD -python -I"$(top_srcdir)/include" -o "$@" "$<"
+$(builddir)/bt2/native_bt.cpp: $(SWIG_INTERFACE_FILES)
+ $(swig_verbose)$(SWIG) -c++ -MD -python -I"$(top_srcdir)/include" -o "$@" "$<"
-include bt2/native_bt.d
# clean: generated C and Python files (by SWIG)
CLEANFILES = \
build-python-bindings.stamp \
- bt2/native_bt.c \
+ bt2/native_bt.cpp \
bt2/native_bt.d \
bt2/native_bt.py \
copy-static-deps.stamp
+++ /dev/null
-/*
- * SPDX-License-Identifier: MIT
- *
- * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
- */
-
-#define BT_LOG_OUTPUT_LEVEL bt_python_bindings_bt2_log_level
-#include "logging/log.h"
-
-BT_LOG_INIT_LOG_LEVEL(bt_python_bindings_bt2_log_level,
- "BABELTRACE_PYTHON_BT2_LOG_LEVEL");
--- /dev/null
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_python_bindings_bt2_log_level
+#include "logging/log.h"
+
+BT_LOG_INIT_LOG_LEVEL(bt_python_bindings_bt2_log_level, "BABELTRACE_PYTHON_BT2_LOG_LEVEL");
+++ /dev/null
-/*
- * SPDX-License-Identifier: MIT
- *
- * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
- */
-
-#ifndef BABELTRACE_BINDINGS_PYTHON_BT2_BT2_LOGGING_H
-#define BABELTRACE_BINDINGS_PYTHON_BT2_BT2_LOGGING_H
-
-#define BT_LOG_OUTPUT_LEVEL bt_python_bindings_bt2_log_level
-#include "logging/log.h"
-
-BT_LOG_LEVEL_EXTERN_SYMBOL(bt_python_bindings_bt2_log_level);
-
-#endif /* BABELTRACE_BINDINGS_PYTHON_BT2_BT2_LOGGING_H */
--- /dev/null
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+ */
+
+#ifndef BABELTRACE_BINDINGS_PYTHON_BT2_BT2_LOGGING_HPP
+#define BABELTRACE_BINDINGS_PYTHON_BT2_BT2_LOGGING_HPP
+
+#define BT_LOG_OUTPUT_LEVEL bt_python_bindings_bt2_log_level
+#include "logging/log.h"
+
+BT_LOG_LEVEL_EXTERN_SYMBOL(bt_python_bindings_bt2_log_level);
+
+#endif /* BABELTRACE_BINDINGS_PYTHON_BT2_BT2_LOGGING_HPP */
%{
#define BT_LOG_TAG "BT2-PY"
-#include "logging.h"
+#include "logging.hpp"
/*
* Include before `<babeltrace2/func-status.h>` because
* functions on which we apply this typemap don't guarantee that the value of
* `temp_value` will be unchanged or valid.
*/
-%typemap(in, numinputs=0) (const char **) (char *temp_value = (void *) 1) {
+%typemap(in, numinputs=0) (const char **) (char *temp_value = reinterpret_cast<char *>(1)) {
$1 = &temp_value;
}
* This function is defined by SWIG. Declare here to avoid a
* -Wmissing-prototypes warning.
*/
-PyObject *SWIG_init(void);
+extern "C" {
+ PyObject *SWIG_init(void);
+}
%}
}
for (i = 0; i < auto_disc.results->len; i++) {
- struct auto_source_discovery_result *autodisc_result =
- g_ptr_array_index(auto_disc.results, i);
+ const auto autodisc_result = static_cast<auto_source_discovery_result*>(
+ g_ptr_array_index(auto_disc.results, i));
bt_value_array_append_element_status append_element_status;
component_info = bt_value_array_create();
BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING, log_level, self_component,
"Failed to call Python class's _bt_init_from_native() method: "
"py-cls-addr=%p", py_cls);
- status = py_exc_to_status_component_clear(self_component);
+ status = static_cast<bt_component_class_initialize_method_status>(
+ py_exc_to_status_component_clear(self_component));
goto end;
}
(enum bt_log_level) log_level, BT_LOG_TAG,
"Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: "
"py-cls-addr=%p", py_cls);
- status = py_exc_to_status_component_class_clear(self_component_class,
- log_level);
+ status = static_cast<bt_component_class_get_supported_mip_versions_method_status>(
+ py_exc_to_status_component_class_clear(self_component_class, log_level));
goto end;
}
* (PyLong) containing the address of a BT unsigned integer
* range set object (new reference).
*/
- ret_range_set = PyLong_AsVoidPtr(py_range_set_addr);
+ ret_range_set = static_cast<bt_integer_range_set_unsigned *>(
+ PyLong_AsVoidPtr(py_range_set_addr));
BT_ASSERT(!PyErr_Occurred());
BT_ASSERT(ret_range_set);
static
void component_class_finalize(bt_self_component *self_component)
{
- PyObject *py_comp = bt_self_component_get_data(self_component);
+ const auto py_comp = static_cast<PyObject *>(
+ bt_self_component_get_data(self_component));
PyObject *py_method_result;
BT_ASSERT(py_comp);
component_class_can_seek_beginning(
bt_self_message_iterator *self_message_iterator, bt_bool *can_seek)
{
- PyObject *py_iter;
PyObject *py_result = NULL;
bt_message_iterator_class_can_seek_beginning_method_status status;
- py_iter = bt_self_message_iterator_get_data(self_message_iterator);
+ const auto py_iter = static_cast<PyObject *>(
+ bt_self_message_iterator_get_data(self_message_iterator));
BT_ASSERT(py_iter);
py_result = PyObject_CallMethod(py_iter,
"_bt_can_seek_beginning_from_native", NULL);
if (!py_result) {
- status = py_exc_to_status_message_iterator_clear(self_message_iterator);
+ status = static_cast<bt_message_iterator_class_can_seek_beginning_method_status>(
+ py_exc_to_status_message_iterator_clear(self_message_iterator));
goto end;
}
bt_message_iterator_class_seek_beginning_method_status
component_class_seek_beginning(bt_self_message_iterator *self_message_iterator)
{
- PyObject *py_iter;
PyObject *py_result;
bt_message_iterator_class_seek_beginning_method_status status;
+ const auto py_iter = static_cast<PyObject *>(
+ bt_self_message_iterator_get_data(self_message_iterator));
- py_iter = bt_self_message_iterator_get_data(self_message_iterator);
BT_ASSERT(py_iter);
py_result = PyObject_CallMethod(py_iter,
"_bt_seek_beginning_from_native",
NULL);
if (!py_result) {
- status = py_exc_to_status_message_iterator_clear(self_message_iterator);
+ status = static_cast<bt_message_iterator_class_seek_beginning_method_status>(
+ py_exc_to_status_message_iterator_clear(self_message_iterator));
goto end;
}
bt_self_message_iterator *self_message_iterator,
int64_t ns_from_origin, bt_bool *can_seek)
{
- PyObject *py_iter;
PyObject *py_result = NULL;
bt_message_iterator_class_can_seek_ns_from_origin_method_status status;
+ const auto py_iter = static_cast<PyObject *>(
+ bt_self_message_iterator_get_data(self_message_iterator));
- py_iter = bt_self_message_iterator_get_data(self_message_iterator);
BT_ASSERT(py_iter);
py_result = PyObject_CallMethod(py_iter,
"_bt_can_seek_ns_from_origin_from_native", "L", ns_from_origin);
if (!py_result) {
- status = py_exc_to_status_message_iterator_clear(self_message_iterator);
+ status = static_cast<bt_message_iterator_class_can_seek_ns_from_origin_method_status>(
+ py_exc_to_status_message_iterator_clear(self_message_iterator));
goto end;
}
bt_self_message_iterator *self_message_iterator,
int64_t ns_from_origin)
{
- PyObject *py_iter;
PyObject *py_result;
bt_message_iterator_class_seek_ns_from_origin_method_status status;
+ const auto py_iter = static_cast<PyObject *>(
+ bt_self_message_iterator_get_data(self_message_iterator));
- py_iter = bt_self_message_iterator_get_data(self_message_iterator);
BT_ASSERT(py_iter);
py_result = PyObject_CallMethod(py_iter,
"_bt_seek_ns_from_origin_from_native", "L", ns_from_origin);
if (!py_result) {
- status = py_exc_to_status_message_iterator_clear(self_message_iterator);
+ status = static_cast<bt_message_iterator_class_seek_ns_from_origin_method_status>(
+ py_exc_to_status_message_iterator_clear(self_message_iterator));
goto end;
}
swig_type_info *other_port_swig_type)
{
bt_component_class_port_connected_method_status status;
- PyObject *py_comp = NULL;
PyObject *py_self_port_ptr = NULL;
PyObject *py_other_port_ptr = NULL;
PyObject *py_method_result = NULL;
bt_logging_level log_level = get_self_component_log_level(
self_component);
+ const auto py_comp = static_cast<PyObject *>(
+ bt_self_component_get_data(self_component));
- py_comp = bt_self_component_get_data(self_component);
BT_ASSERT(py_comp);
py_self_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port),
self_component_port_swig_type, 0);
if (!py_self_port_ptr) {
BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_component,
BT_FMT_SWIG_ALLOC_FAILED);
- status = __BT_FUNC_STATUS_MEMORY_ERROR;
+ status = BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_MEMORY_ERROR;
goto end;
}
if (!py_other_port_ptr) {
BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_component,
BT_FMT_SWIG_ALLOC_FAILED);
- status = __BT_FUNC_STATUS_MEMORY_ERROR;
+ status = BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_MEMORY_ERROR;
goto end;
}
"_bt_port_connected_from_native", "(OiO)", py_self_port_ptr,
self_component_port_type, py_other_port_ptr);
if (!py_method_result) {
- status = py_exc_to_status_component_clear(self_component);
+ status = static_cast<bt_component_class_port_connected_method_status>(
+ py_exc_to_status_component_clear(self_component));
goto end;
}
component_class_sink_graph_is_configured(
bt_self_component_sink *self_component_sink)
{
- PyObject *py_comp = NULL;
PyObject *py_method_result = NULL;
bt_component_class_sink_graph_is_configured_method_status status;
bt_self_component *self_component = bt_self_component_sink_as_self_component(self_component_sink);
-
- py_comp = bt_self_component_get_data(self_component);
+ const auto py_comp = static_cast<PyObject *>(
+ bt_self_component_get_data(self_component));
py_method_result = PyObject_CallMethod(py_comp,
"_bt_graph_is_configured_from_native", NULL);
if (!py_method_result) {
- status = py_exc_to_status_component_clear(self_component);
+ status = static_cast<bt_component_class_sink_graph_is_configured_method_status>(
+ py_exc_to_status_component_clear(self_component));
goto end;
}
PyObject *py_query_func = NULL;
PyObject *py_object = NULL;
PyObject *py_results_addr = NULL;
- bt_component_class_query_method_status status = __BT_FUNC_STATUS_OK;
+ bt_component_class_query_method_status status =
+ BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK;
const bt_query_executor *query_exec =
bt_private_query_executor_as_query_executor_const(
priv_query_executor);
py_object, py_params_ptr,
method_data ? method_data : Py_None);
if (!py_results_addr) {
- status = py_exc_to_status_component_class_clear(self_component_class,
- log_level);
+ status = static_cast<bt_component_class_query_method_status>(
+ py_exc_to_status_component_class_clear(self_component_class, log_level));
if (status < 0) {
#define BT_FMT "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p"
BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_WARNING,
* (PyLong) containing the address of a BT value object (new
* reference).
*/
- *result = PyLong_AsVoidPtr(py_results_addr);
+ *result = static_cast<const bt_value *>(PyLong_AsVoidPtr(py_results_addr));
BT_ASSERT(!PyErr_Occurred());
BT_ASSERT(*result);
goto end;
error:
PyErr_Clear();
- status = __BT_FUNC_STATUS_ERROR;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
end:
Py_XDECREF(py_params_ptr);
bt_self_message_iterator_configuration *config,
bt_self_component_port_output *self_component_port_output)
{
- bt_message_iterator_class_initialize_method_status status = __BT_FUNC_STATUS_OK;
+ bt_message_iterator_class_initialize_method_status status =
+ BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK;
PyObject *py_comp_cls = NULL;
PyObject *py_iter_cls = NULL;
PyObject *py_iter_ptr = NULL;
PyObject *py_component_port_output_ptr = NULL;
PyObject *py_init_method_result = NULL;
PyObject *py_iter = NULL;
- PyObject *py_comp;
bt_self_component *self_component =
bt_self_message_iterator_borrow_component(
self_message_iterator);
bt_logging_level log_level = get_self_component_log_level(
self_component);
-
- py_comp = bt_self_component_get_data(self_component);
+ const auto py_comp = static_cast<PyObject *>(
+ bt_self_component_get_data(self_component));
/* Find user's Python message iterator class */
py_comp_cls = PyObject_GetAttrString(py_comp, "__class__");
python_error:
/* Handling of errors that cause a Python exception to be set. */
- status = py_exc_to_status_message_iterator_clear(self_message_iterator);
+ status = static_cast<bt_message_iterator_class_initialize_method_status>(
+ py_exc_to_status_message_iterator_clear(self_message_iterator));
goto end;
error:
/* Handling of errors that don't cause a Python exception to be set. */
- status = __BT_FUNC_STATUS_ERROR;
+ status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
end:
BT_ASSERT(!PyErr_Occurred());
void component_class_message_iterator_finalize(
bt_self_message_iterator *message_iterator)
{
- PyObject *py_message_iter = bt_self_message_iterator_get_data(
- message_iterator);
+ const auto py_message_iter = static_cast<PyObject *>(
+ bt_self_message_iterator_get_data(message_iterator));
PyObject *py_method_result = NULL;
BT_ASSERT(py_message_iter);
uint64_t *count)
{
bt_message_iterator_class_next_method_status status;
- PyObject *py_message_iter = bt_self_message_iterator_get_data(message_iterator);
+ const auto py_message_iter = static_cast<PyObject *>(
+ bt_self_message_iterator_get_data(message_iterator));
PyObject *py_method_result = NULL;
BT_ASSERT_DBG(py_message_iter);
py_method_result = PyObject_CallMethod(py_message_iter,
"_bt_next_from_native", NULL);
if (!py_method_result) {
- status = py_exc_to_status_message_iterator_clear(message_iterator);
+ status = static_cast<bt_message_iterator_class_next_method_status>(
+ py_exc_to_status_message_iterator_clear(message_iterator));
goto end;
}
* (PyLong) containing the address of a native message
* object (which is now ours).
*/
- msgs[0] = PyLong_AsVoidPtr(py_method_result);
+ msgs[0] = static_cast<const bt_message *>(PyLong_AsVoidPtr(py_method_result));
*count = 1;
/* Overflow errors should never happen. */
component_class_sink_consume(bt_self_component_sink *self_component_sink)
{
bt_self_component *self_component = bt_self_component_sink_as_self_component(self_component_sink);
- PyObject *py_comp = bt_self_component_get_data(self_component);
+ const auto py_comp = static_cast<PyObject *>(bt_self_component_get_data(self_component));
PyObject *py_method_result = NULL;
bt_component_class_sink_consume_method_status status;
py_method_result = PyObject_CallMethod(py_comp,
"_user_consume", NULL);
if (!py_method_result) {
- status = py_exc_to_status_component_clear(self_component);
+ status = static_cast<bt_component_class_sink_consume_method_status>(
+ py_exc_to_status_component_clear(self_component));
goto end;
}
*/
%typemap(in, numinputs=0)
(bt_event_class_log_level *)
- (bt_event_class_log_level temp = -1) {
+ (bt_event_class_log_level temp = static_cast<bt_event_class_log_level>(-1)) {
$1 = &temp;
}
py_component_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(component), component_swig_type, 0);
if (!py_component_ptr) {
BT_LOGF_STR("Failed to create component SWIG pointer object.");
- status = __BT_FUNC_STATUS_MEMORY_ERROR;
+ status = BT_GRAPH_LISTENER_FUNC_STATUS_MEMORY_ERROR;
goto end;
}
py_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(port), port_swig_type, 0);
if (!py_port_ptr) {
BT_LOGF_STR("Failed to create port SWIG pointer object.");
- status = __BT_FUNC_STATUS_MEMORY_ERROR;
+ status = BT_GRAPH_LISTENER_FUNC_STATUS_MEMORY_ERROR;
goto end;
}
- py_res = PyObject_CallFunction(py_callable, "(OiOi)",
+ py_res = PyObject_CallFunction(static_cast<PyObject *>(py_callable), "(OiOi)",
py_component_ptr, component_class_type, py_port_ptr, port_type);
if (!py_res) {
loge_exception_append_cause_clear(
"Graph's port added listener (Python)",
BT_LOG_OUTPUT_LEVEL);
- status = __BT_FUNC_STATUS_ERROR;
+ status = BT_GRAPH_LISTENER_FUNC_STATUS_ERROR;
goto end;
}
BT_ASSERT(py_res == Py_None);
- status = __BT_FUNC_STATUS_OK;
+ status = BT_GRAPH_LISTENER_FUNC_STATUS_OK;
end:
Py_XDECREF(py_res);
bt_self_message_iterator *self_message_iterator)
{
bt_self_component *self_component = bt_self_message_iterator_borrow_component(self_message_iterator);
- PyObject *py_comp;
BT_ASSERT_DBG(self_component);
- py_comp = bt_self_component_get_data(self_component);
+
+ const auto py_comp = static_cast<PyObject *>(
+ bt_self_component_get_data(self_component));
+
BT_ASSERT_DBG(py_comp);
/* Return new reference */
%typemap(out) void * {
Py_INCREF($1);
- $result = $1;
+ $result = static_cast<PyObject *>($1);
}
%include <babeltrace2/graph/port.h>
bt_common_abort();
}
- py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_ptr);
+ py_res = PyObject_CallFunction(static_cast<PyObject *>(py_callable), "(O)",
+ py_trace_ptr);
if (!py_res) {
logw_exception_clear(BT_LOG_OUTPUT_LEVEL);
goto end;
bt_common_abort();
}
- py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_class_ptr);
+ py_res = PyObject_CallFunction(static_cast<PyObject *>(py_callable), "(O)",
+ py_trace_class_ptr);
if (!py_res) {
logw_exception_clear(BT_LOG_OUTPUT_LEVEL);
goto end;
static bt_value_map_foreach_entry_const_func_status bt_value_map_get_keys_cb(
const char *key, const struct bt_value *object, void *data)
{
- int status;
- struct bt_value_map_get_keys_data *priv_data = data;
+ const auto priv_data = static_cast<bt_value_map_get_keys_data *>(data);
+ bt_value_array_append_element_status status =
+ bt_value_array_append_string_element(priv_data->keys, key);
- status = bt_value_array_append_string_element(priv_data->keys, key);
- BT_ASSERT(status == __BT_FUNC_STATUS_OK ||
- status == __BT_FUNC_STATUS_MEMORY_ERROR);
- return status;
+ BT_ASSERT(status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK ||
+ status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR);
+ return static_cast<bt_value_map_foreach_entry_const_func_status>(status);
}
static struct bt_value *bt_value_map_get_keys(const struct bt_value *map_obj)
# Distutils was removed in Python 3.12, use setuptools as an alternative.
if sys.version_info >= (3, 12):
from setuptools import setup, Extension
+ from setuptools.command.build_ext import build_ext
else:
from distutils.core import setup, Extension
+ from distutils.command.build_ext import build_ext
+
# Starting with Debian's Python 3.10, the default install scheme is
# 'posix_local' which is a Debian specific scheme based on 'posix_prefix' but
return value
-def get_cflags():
- return getenv_assert("CFLAGS")
-
-
# distutils performs a similar transformation step on LDSHARED on
# darwin to use the overridden CC as the default command for LDSHARED
# (see distutils' customize_compiler() step in the sysconfig module).
def our_get_config_vars(*args):
overridden_config_vars_funcs = {
- "CFLAGS": get_cflags,
"LDSHARED": get_ldshared,
}
return path
-# On MinGW systems, check CFLAGS and CPPFLAGS for absolute include paths
-# (starts with '-I/') and convert them to valid Windows paths using cygpath.
-if is_mingw():
- for flagvar in ["CFLAGS", "CPPFLAGS"]:
- cur_flags = getenv_assert(flagvar)
- new_flags = ""
- for flag in cur_flags.split():
- if flag.startswith("-I/"):
- flag = "-I{}".format(cygpath_m(flag[2:]))
+# On MinGW systems, convert absolute include paths (starting with '-I/')
+# in 'flags' to valid Windows paths using cygpath. On other systems,
+# return 'flags' as-is.
+def transform_include_paths_if_mingw(flags: str):
+ if not is_mingw():
+ return flags
+
+ return " ".join(
+ (
+ "-I{}".format(cygpath_m(flag[2:])) if flag.startswith("-I/") else flag
+ for flag in flags.split()
+ )
+ )
- new_flags += " {}".format(flag)
- os.environ[flagvar] = new_flags
+class custom_build_ext(build_ext):
+ def build_extensions(self):
+ # There are multiple issues handled simultaneously here:
+ #
+ # - distutils (at least before setuptools 72.2.0) doesn't
+ # handle well building shared objects from C++ source files.
+ # It will attempt to compile them using the C compiler. Set
+ # the executable used to compile C++ source files that will
+ # end up in shared objects so that it uses the C++ compiler
+ # defined by the `CXX` environment variable.
+ #
+ # - The CPPFLAGS and CXXFLAGS provided by sysconfig may not
+ # work with the compiler we tell distutils to use. We
+ # therefore also force our own flags (the call to
+ # `set_executable()` below overrides any flags previously
+ # found by distutils).
+ #
+ # - On MSYS2, some include paths need to be converted from
+ # Unix to Windows form.
+
+ cxxflags = transform_include_paths_if_mingw(getenv_assert("CXXFLAGS"))
+ cppflags = transform_include_paths_if_mingw(getenv_assert("CPPFLAGS"))
+ cxx = getenv_assert("CXX")
+
+ self.compiler.set_executable(
+ (
+ # setuptools >= 72.2.0 uses the `compiler_so_cxx`
+ # attribute:
+ #
+ # https://github.com/pypa/setuptools/commit/2c937116cc0dcd9b26b6070e89a3dc5dcbedc2ae
+ #
+ # This version of setuptools seems to have better support
+ # for building shared objects from C++ source files, but
+ # we override the executable anyway, for consistency.
+ "compiler_so_cxx"
+ if hasattr(self.compiler, "compiler_so_cxx")
+ else "compiler_so"
+ ),
+ "{} {} {} {}".format(
+ cxx, sysconfig.get_config_var("CCSHARED"), cxxflags, cppflags
+ ),
+ )
+
+ super().build_extensions()
def main():
babeltrace_ext = Extension(
"bt2._native_bt",
sources=[
- "bt2/native_bt.c",
- cygpath_m("@srcdir@/bt2/logging.c"),
+ "bt2/native_bt.cpp",
+ cygpath_m("@srcdir@/bt2/logging.cpp"),
],
libraries=["babeltrace2", "glib-2.0"],
extra_objects=[
"License :: OSI Approved :: The MIT License",
"Programming Language :: Python :: 3" "Topic :: System :: Logging",
],
+ cmdclass={"build_ext": custom_build_ext},
)
# After the installation, we check that the install directory is included in
#include "common/macros.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Formats the Python traceback `py_exc_tb` using traceback.format_tb, from the
* Python standard library, and return it as a Gstring.
*/
GString *bt_py_common_format_current_exception(int log_level);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* BABELTRACE_PY_COMMON_PY_COMMON_H */
#include <common/macros.h>
#include <glib.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
gchar *format_bt_error_cause(
const bt_error_cause *error_cause,
unsigned int columns,
bt_logging_level log_level,
enum bt_common_color_when use_colors);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* BABELTRACE_STRING_FORMAT_FORMAT_ERROR_H */