Skip to content

Commit be4a234

Browse files
committed
Add static read-only properties to Python function record type: PYBIND11_DETAIL_FUNCTION_RECORD_ABI_ID, PYBIND11_INTERNALS_ID
1 parent f54e2c7 commit be4a234

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

include/pybind11/detail/function_record_pyobject.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ constexpr char tp_name_impl[]
5656
= "pybind11_detail_function_record_" PYBIND11_DETAIL_FUNCTION_RECORD_ABI_ID
5757
"_" PYBIND11_PLATFORM_ABI_ID;
5858

59+
inline PyObject *get_property_pybind11_detail_function_record_abi_id(PyObject *, void *) {
60+
return PyUnicode_FromString(PYBIND11_DETAIL_FUNCTION_RECORD_ABI_ID);
61+
}
62+
63+
inline PyObject *get_property_pybind11_platform_abi_id(PyObject *, void *) {
64+
return PyUnicode_FromString(PYBIND11_PLATFORM_ABI_ID);
65+
}
66+
67+
static PyGetSetDef tp_getset_impl[] = {
68+
{"PYBIND11_DETAIL_FUNCTION_RECORD_ABI_ID",
69+
get_property_pybind11_detail_function_record_abi_id,
70+
nullptr,
71+
nullptr,
72+
nullptr},
73+
{"PYBIND11_PLATFORM_ABI_ID", get_property_pybind11_platform_abi_id, nullptr, nullptr, nullptr},
74+
{nullptr, nullptr, nullptr, nullptr, nullptr}};
75+
5976
PYBIND11_NAMESPACE_END(function_record_PyTypeObject_methods)
6077

6178
// Designated initializers are a C++20 feature:
@@ -96,7 +113,7 @@ static PyTypeObject function_record_PyTypeObject = {
96113
/* iternextfunc tp_iternext */ nullptr,
97114
/* struct PyMethodDef *tp_methods */ function_record_PyTypeObject_methods::tp_methods_impl,
98115
/* struct PyMemberDef *tp_members */ nullptr,
99-
/* struct PyGetSetDef *tp_getset */ nullptr,
116+
/* struct PyGetSetDef *tp_getset */ function_record_PyTypeObject_methods::tp_getset_impl,
100117
/* struct _typeobject *tp_base */ nullptr,
101118
/* PyObject *tp_dict */ nullptr,
102119
/* descrgetfunc tp_descr_get */ nullptr,

tests/test_scipy_low_level_callable.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
import pybind11_tests
56
from pybind11_tests import scipy_low_level_callable as m
67

78

@@ -16,6 +17,12 @@ def _m_square21_self():
1617
pytest.skip(f"{str(e)}")
1718

1819

20+
def test_python_function_record_static_properties():
21+
func_rec = _m_square21_self()
22+
assert func_rec.PYBIND11_DETAIL_FUNCTION_RECORD_ABI_ID == "v1"
23+
assert func_rec.PYBIND11_PLATFORM_ABI_ID in pybind11_tests.PYBIND11_INTERNALS_ID
24+
25+
1926
def test_get_capsule_for_scipy_LowLevelCallable():
2027
cap = (
2128
_m_square21_self().get_capsule_for_scipy_LowLevelCallable_NO_ABI_OR_TYPE_SAFETY(

0 commit comments

Comments
 (0)