GeezerVison is showing github.com — Use strong reference APIs. · boostorg/python@cabb466
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/dict.cpp +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -68,8 +68,16 @@ object dict_base::get(object_cref k) const |
68 | 68 | { |
69 | 69 | if (check_exact(this)) |
70 | 70 | { |
| 71 | +#ifdef Py_GIL_DISABLED |
| 72 | + PyObject* result; |
| 73 | + if (PyDict_GetItemRef(this->ptr(),k.ptr(),&result) < 0) { |
| 74 | + throw_error_already_set(); |
| 75 | + } |
| 76 | + return object(detail::new_reference(result ? result : Py_None)); |
| 77 | +#else |
71 | 78 | PyObject* result = PyDict_GetItem(this->ptr(),k.ptr()); |
72 | 79 | return object(detail::borrowed_reference(result ? result : Py_None)); |
| 80 | +#endif |
73 | 81 | } |
74 | 82 | else |
75 | 83 | { |
|
Collapse file
Copy file name to clipboardExpand all lines: src/object/function_doc_signature.cpp +13-2Lines changed: 13 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -135,7 +135,15 @@ namespace boost { namespace python { namespace objects { |
135 | 135 | str name(get_qualname(py_type)); |
136 | 136 | if ( py_type->tp_flags & Py_TPFLAGS_HEAPTYPE ) { |
137 | 137 | // Qualify the type name if it is defined in a different module. |
138 | | - PyObject *type_module_name = PyDict_GetItemString(py_type->tp_dict, "__module__"); |
| 138 | + PyObject *type_module_name; |
| 139 | +#if PY_VERSION_HEX >= 0x030D0000 |
| 140 | + if (PyDict_GetItemStringRef(py_type->tp_dict, "__module__", &type_module_name) < 0) { |
| 141 | + throw_error_already_set(); |
| 142 | + } |
| 143 | +#else |
| 144 | + type_module_name = PyDict_GetItemString(py_type->tp_dict, "__module__"); |
| 145 | + Py_XINCREF(type_module_name); |
| 146 | +#endif |
139 | 147 | if ( |
140 | 148 | type_module_name |
141 | 149 | && PyObject_RichCompareBool( |
@@ -144,8 +152,11 @@ namespace boost { namespace python { namespace objects { |
144 | 152 | Py_NE |
145 | 153 | ) != 0 |
146 | 154 | ) { |
147 | | - return str("%s.%s" % make_tuple(handle<>(borrowed(type_module_name)), name)); |
| 155 | + str result = str("%s.%s" % make_tuple(handle<>(type_module_name), name)); |
| 156 | + return result; |
148 | 157 | } |
| 158 | + // Clean up the strong reference if we didn't use it |
| 159 | + Py_XDECREF(type_module_name); |
149 | 160 | } |
150 | 161 | return name; |
151 | 162 | } else { |
|
Collapse file
Copy file name to clipboardExpand all lines: src/wrapper.cpp +14-6Lines changed: 14 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,20 +21,28 @@ namespace detail |
21 | 21 | this->m_self, const_cast<char*>(name)))) |
22 | 22 | ) |
23 | 23 | { |
24 | | - PyObject* borrowed_f = 0; |
25 | | - |
| 24 | + PyObject* class_f = 0; |
| 25 | + |
26 | 26 | if ( |
27 | 27 | PyMethod_Check(m.get()) |
28 | 28 | && PyMethod_GET_SELF(m.get()) == this->m_self |
29 | 29 | && class_object->tp_dict != 0 |
30 | 30 | ) |
31 | 31 | { |
32 | | - borrowed_f = ::PyDict_GetItemString( |
| 32 | +#if PY_VERSION_HEX >= 0x030D0000 |
| 33 | + if (::PyDict_GetItemStringRef( |
| 34 | + class_object->tp_dict, const_cast<char*>(name), &class_f) < 0) { |
| 35 | + throw_error_already_set(); |
| 36 | + } |
| 37 | +#else |
| 38 | + class_f = ::PyDict_GetItemString( |
33 | 39 | class_object->tp_dict, const_cast<char*>(name)); |
34 | | - |
35 | | - |
| 40 | + Py_XINCREF(class_f); |
| 41 | +#endif |
36 | 42 | } |
37 | | - if (borrowed_f != PyMethod_GET_FUNCTION(m.get())) |
| 43 | + bool is_override = (class_f != PyMethod_GET_FUNCTION(m.get())); |
| 44 | + Py_XDECREF(class_f); |
| 45 | + if (is_override) |
38 | 46 | return override(m); |
39 | 47 | } |
40 | 48 | } |
|