From 83fb70c5172b7fbbffa3bb848fa944d45e7bcf7e Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 7 Jun 2024 13:49:13 -0400 Subject: [PATCH 1/3] GH-41475: [PYTHON] build with py313 The private function `_Py_IsFinalizing` renamed to `Py_IsFinalizing` in Python 3.13.0a1 --- python/pyarrow/src/arrow/python/udf.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/python/pyarrow/src/arrow/python/udf.cc b/python/pyarrow/src/arrow/python/udf.cc index e9b72a2592738..65d38512a265d 100644 --- a/python/pyarrow/src/arrow/python/udf.cc +++ b/python/pyarrow/src/arrow/python/udf.cc @@ -28,6 +28,11 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/logging.h" +#if PY_VERSION_HEX >= 0x030D00A4 +#define __Py_IsFinalizing Py_IsFinalizing +#else +#define __Py_IsFinalizing _Py_IsFinalizing +#endif namespace arrow { using compute::ExecSpan; using compute::Grouper; @@ -47,7 +52,7 @@ struct PythonUdfKernelState : public compute::KernelState { // function needs to be destroyed at process exit // and Python may no longer be initialized. ~PythonUdfKernelState() { - if (_Py_IsFinalizing()) { + if (__Py_IsFinalizing()) { function->detach(); } } @@ -64,7 +69,7 @@ struct PythonUdfKernelInit { // function needs to be destroyed at process exit // and Python may no longer be initialized. ~PythonUdfKernelInit() { - if (_Py_IsFinalizing()) { + if (__Py_IsFinalizing()) { function->detach(); } } @@ -132,7 +137,7 @@ struct PythonTableUdfKernelInit { // function needs to be destroyed at process exit // and Python may no longer be initialized. ~PythonTableUdfKernelInit() { - if (_Py_IsFinalizing()) { + if (__Py_IsFinalizing()) { function_maker->detach(); } } @@ -173,7 +178,7 @@ struct PythonUdfScalarAggregatorImpl : public ScalarUdfAggregator { }; ~PythonUdfScalarAggregatorImpl() override { - if (_Py_IsFinalizing()) { + if (__Py_IsFinalizing()) { function->detach(); } } @@ -270,7 +275,7 @@ struct PythonUdfHashAggregatorImpl : public HashUdfAggregator { }; ~PythonUdfHashAggregatorImpl() override { - if (_Py_IsFinalizing()) { + if (__Py_IsFinalizing()) { function->detach(); } } From bfda913dc828292b930c47529031c800c957ae1d Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 10 Jun 2024 13:40:38 -0400 Subject: [PATCH 2/3] MNT: always use public name Co-authored-by: Sutou Kouhei --- python/pyarrow/src/arrow/python/udf.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/python/pyarrow/src/arrow/python/udf.cc b/python/pyarrow/src/arrow/python/udf.cc index 65d38512a265d..5db306f445044 100644 --- a/python/pyarrow/src/arrow/python/udf.cc +++ b/python/pyarrow/src/arrow/python/udf.cc @@ -28,10 +28,8 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/logging.h" -#if PY_VERSION_HEX >= 0x030D00A4 -#define __Py_IsFinalizing Py_IsFinalizing -#else -#define __Py_IsFinalizing _Py_IsFinalizing +#if PY_VERSION_HEX < 0x030D00A4 +#define Py_IsFinalizing() _Py_IsFinalizing() #endif namespace arrow { using compute::ExecSpan; @@ -52,7 +50,7 @@ struct PythonUdfKernelState : public compute::KernelState { // function needs to be destroyed at process exit // and Python may no longer be initialized. ~PythonUdfKernelState() { - if (__Py_IsFinalizing()) { + if (Py_IsFinalizing()) { function->detach(); } } @@ -69,7 +67,7 @@ struct PythonUdfKernelInit { // function needs to be destroyed at process exit // and Python may no longer be initialized. ~PythonUdfKernelInit() { - if (__Py_IsFinalizing()) { + if (Py_IsFinalizing()) { function->detach(); } } @@ -137,7 +135,7 @@ struct PythonTableUdfKernelInit { // function needs to be destroyed at process exit // and Python may no longer be initialized. ~PythonTableUdfKernelInit() { - if (__Py_IsFinalizing()) { + if (Py_IsFinalizing()) { function_maker->detach(); } } @@ -178,7 +176,7 @@ struct PythonUdfScalarAggregatorImpl : public ScalarUdfAggregator { }; ~PythonUdfScalarAggregatorImpl() override { - if (__Py_IsFinalizing()) { + if (Py_IsFinalizing()) { function->detach(); } } @@ -275,7 +273,7 @@ struct PythonUdfHashAggregatorImpl : public HashUdfAggregator { }; ~PythonUdfHashAggregatorImpl() override { - if (__Py_IsFinalizing()) { + if (Py_IsFinalizing()) { function->detach(); } } From 79c37cdcd89f472295a12f6dee7870d8230bfc41 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 11 Jun 2024 09:43:41 -0400 Subject: [PATCH 3/3] DOC: add comment explaining change Co-authored-by: Joris Van den Bossche --- python/pyarrow/src/arrow/python/udf.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/python/pyarrow/src/arrow/python/udf.cc b/python/pyarrow/src/arrow/python/udf.cc index 5db306f445044..b6a862af8ca07 100644 --- a/python/pyarrow/src/arrow/python/udf.cc +++ b/python/pyarrow/src/arrow/python/udf.cc @@ -28,6 +28,7 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/logging.h" +// Py_IsFinalizing added in Python 3.13.0a4 #if PY_VERSION_HEX < 0x030D00A4 #define Py_IsFinalizing() _Py_IsFinalizing() #endif