Skip to content

Commit 970ff1f

Browse files
Rename py_ref_tmpl to py_ref_t.
1 parent daab4c1 commit 970ff1f

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

dynd/include/utility_functions.hpp

+29-29
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ inline void decref_if_owned<false, false>(PyObject *obj) noexcept
124124
}
125125

126126
template <bool owns_ref = true, bool not_null = true>
127-
class py_ref_tmpl {
127+
class py_ref_t {
128128
PyObject *o;
129129

130130
public:
131131
// All versions default-initialize to null.
132132
// This allows the smart pointer class to be moved from.
133133
// Whether or not the class is allowed to be null only changes
134134
// when zerochecks/exceptions may occur and when assertions are used.
135-
py_ref_tmpl() noexcept : o(nullptr){};
135+
py_ref_t() noexcept : o(nullptr){};
136136

137137
// First define an accessor to get the PyObject pointer from
138138
// the wrapper class.
@@ -151,11 +151,11 @@ class py_ref_tmpl {
151151
/* If:
152152
* This type allows null or the input type does not,
153153
* Then:
154-
* Conversions from the other py_ref_tmpl type to this type do not raise exceptions.
154+
* Conversions from the other py_ref_t type to this type do not raise exceptions.
155155
*/
156156
template <bool other_owns_ref, bool other_not_null,
157157
typename std::enable_if_t<other_not_null || !not_null> * = nullptr>
158-
py_ref_tmpl(const py_ref_tmpl<other_owns_ref, other_not_null> &other) noexcept
158+
py_ref_t(const py_ref_t<other_owns_ref, other_not_null> &other) noexcept
159159
{
160160
// If the input is not null, assert that it isn't.
161161
PYDYND_ASSERT_IF(other_not_null, other.o != nullptr);
@@ -175,7 +175,7 @@ class py_ref_tmpl {
175175
*/
176176
template <bool other_owns_ref, bool other_not_null,
177177
typename std::enable_if_t<!other_not_null && not_null> * = nullptr>
178-
py_ref_tmpl(const py_ref_tmpl<other_owns_ref, other_not_null> &other)
178+
py_ref_t(const py_ref_t<other_owns_ref, other_not_null> &other)
179179
{
180180
if (other.o != nullptr) {
181181
// Assert that the input reference is valid.
@@ -199,7 +199,7 @@ class py_ref_tmpl {
199199
* a move operation is defined and will not raise an exception.
200200
*/
201201
template <bool other_not_null, typename std::enable_if_t<other_not_null || !not_null> * = nullptr>
202-
py_ref_tmpl(py_ref_tmpl<true, other_not_null> &&other) noexcept
202+
py_ref_t(py_ref_t<true, other_not_null> &&other) noexcept
203203
{
204204
// If this type is a non-null type, the assigned value should not be null.
205205
// If the other type is a non-null type, the provided value should not be null,
@@ -227,7 +227,7 @@ class py_ref_tmpl {
227227
* a move may be performed, but may also raise an exception.
228228
*/
229229
template <bool other_not_null, typename std::enable_if_t<!other_not_null && not_null> * = nullptr>
230-
py_ref_tmpl(py_ref_tmpl<true, other_not_null> &&other)
230+
py_ref_t(py_ref_t<true, other_not_null> &&other)
231231
{
232232
if (other.o != nullptr) {
233233
// Assert that the input reference is valid.
@@ -256,7 +256,7 @@ class py_ref_tmpl {
256256
* specify `consume_ref` as false regardless of whether or not you
257257
* own the reference represented in the PyObject* you pass in.
258258
*/
259-
explicit py_ref_tmpl(PyObject *obj, bool consume_ref) noexcept
259+
explicit py_ref_t(PyObject *obj, bool consume_ref) noexcept
260260
{
261261
o = obj;
262262
if (consume_ref) {
@@ -270,7 +270,7 @@ class py_ref_tmpl {
270270
PYDYND_ASSERT_IF(obj != null, Py_REFCNT(obj) > 0);
271271
}
272272

273-
~py_ref_tmpl()
273+
~py_ref_t()
274274
{
275275
// A smart pointer wrapping a PyObject* still needs to be safe to
276276
// destruct after it has been moved from.
@@ -288,11 +288,11 @@ class py_ref_tmpl {
288288
/* If:
289289
* This type allows null or the input type does not,
290290
* Then:
291-
* Assignment from the other py_ref_tmpl type to this type may not raise an exception.
291+
* Assignment from the other py_ref_t type to this type may not raise an exception.
292292
*/
293293
template <bool other_owns_ref, bool other_not_null,
294294
typename std::enable_if_t<other_not_null || !not_null> * = nullptr>
295-
py_ref_tmpl<owns_ref, not_null> &operator=(const py_ref_tmpl<other_owns_ref, other_not_null> &other) noexcept
295+
py_ref_t<owns_ref, not_null> &operator=(const py_ref_t<other_owns_ref, other_not_null> &other) noexcept
296296
{
297297
// Assert that the input reference is not null if the input type does not allow nulls.
298298
PYDYND_ASSERT_IF(other_not_null, other.o != nullptr);
@@ -310,11 +310,11 @@ class py_ref_tmpl {
310310
* this type does not allow null,
311311
* and the other type does,
312312
* Then:
313-
* Assignment from the other py_ref_tmpl type to this type may raise an exception.
313+
* Assignment from the other py_ref_t type to this type may raise an exception.
314314
*/
315315
template <bool other_owns_ref, bool other_not_null,
316316
typename std::enable_if_t<!other_not_null && not_null> * = nullptr>
317-
py_ref_tmpl<owns_ref, not_null> &operator=(const py_ref_tmpl<other_owns_ref, other_not_null> &other) noexcept
317+
py_ref_t<owns_ref, not_null> &operator=(const py_ref_t<other_owns_ref, other_not_null> &other) noexcept
318318
{
319319
if (other.o != nullptr) {
320320
// Assert that the input reference is valid.
@@ -339,11 +339,11 @@ class py_ref_tmpl {
339339
* this type doesn't allow null
340340
* and the input type doesn't allow null,
341341
* Then:
342-
* Assignment from the other py_ref_tmpl type to this type may not raise an exception.
342+
* Assignment from the other py_ref_t type to this type may not raise an exception.
343343
*/
344344
template <bool other_owns_ref, bool other_not_null,
345345
typename std::enable_if_t<other_not_null || !not_null> * = nullptr>
346-
py_ref_tmpl<owns_ref, not_null> &operator=(py_ref_tmpl<other_owns_ref, other_not_null> &&other) noexcept
346+
py_ref_t<owns_ref, not_null> &operator=(py_ref_t<other_owns_ref, other_not_null> &&other) noexcept
347347
{
348348
// If the input reference should not be null, assert that that is the case.
349349
PYDYND_ASSERT_IF(other_not_null, other.o != nullptr);
@@ -362,11 +362,11 @@ class py_ref_tmpl {
362362
* this type does not allow null,
363363
* and the other type does,
364364
* Then:
365-
* Assignment from the other py_ref_tmpl type to this type may raise an exception.
365+
* Assignment from the other py_ref_t type to this type may raise an exception.
366366
*/
367367
template <bool other_owns_ref, bool other_not_null,
368368
typename std::enable_if_t<!other_not_null && not_null> * = nullptr>
369-
py_ref_tmpl<owns_ref, not_null> &operator=(py_ref_tmpl<other_owns_ref, other_not_null> &&other) noexcept
369+
py_ref_t<owns_ref, not_null> &operator=(py_ref_t<other_owns_ref, other_not_null> &&other) noexcept
370370
{
371371
if (other.o != nullptr) {
372372
// Assert that the input reference is valid.
@@ -384,13 +384,13 @@ class py_ref_tmpl {
384384
}
385385
}
386386

387-
py_ref_tmpl<false, not_null> borrow() noexcept { return py_ref<false, not_null>(o, false); }
387+
py_ref_t<false, not_null> borrow() noexcept { return py_ref<false, not_null>(o, false); }
388388

389389
// Return a reference to the encapsulated PyObject as a raw pointer.
390390
// Set the encapsulated pointer to NULL.
391391
// If this is a type that owns its reference, an owned reference is returned.
392392
// If this is a type that wraps a borrowed reference, a borrowed reference is returned.
393-
static PyObject *release(py_ref_tmpl<owns_ref, not_null> &&ref) noexcept
393+
static PyObject *release(py_ref_t<owns_ref, not_null> &&ref) noexcept
394394
{
395395
// If the contained reference should not be null, assert that it isn't.
396396
PYDYND_ASSERT_IF(not_null, ref.o != nullptr);
@@ -404,18 +404,18 @@ class py_ref_tmpl {
404404

405405
// Convenience aliases for the templated smart pointer classes.
406406

407-
using py_ref = py_ref_tmpl<true, true>;
407+
using py_ref = py_ref_t<true, true>;
408408

409-
using py_ref_with_null = py_ref_tmpl<true, false>;
409+
using py_ref_with_null = py_ref_t<true, false>;
410410

411-
using py_borref = py_ref_tmpl<false, true>;
411+
using py_borref = py_ref_t<false, true>;
412412

413-
using py_borref_with_null = py_ref_tmpl<false, false>;
413+
using py_borref_with_null = py_ref_t<false, false>;
414414

415415
template <bool owns_ref, bool not_null>
416-
PyObject *release(py_ref_tmpl<owns_ref, not_null> &&ref)
416+
PyObject *release(py_ref_t<owns_ref, not_null> &&ref)
417417
{
418-
return py_ref_tmpl<owns_ref, not_null>::release(std::forward<py_ref_tmpl<owns_ref, not_null>>(ref));
418+
return py_ref_t<owns_ref, not_null>::release(std::forward<py_ref_t<owns_ref, not_null>>(ref));
419419
}
420420

421421
/* Capture a new reference if it is not null.
@@ -435,10 +435,10 @@ inline py_ref capture_if_not_null(PyObject *o)
435435
* only checks for via an assert statement in debug builds.
436436
*/
437437
template <bool owns_ref, bool not_null>
438-
inline py_ref_tmpl<owns_ref, true> nullcheck(py_ref_tmpl<owns_ref, not_null> &&obj) noexcept(not_null)
438+
inline py_ref_t<owns_ref, true> nullcheck(py_ref_t<owns_ref, not_null> &&obj) noexcept(not_null)
439439
{
440440
// Route this through the assignment operator since the semantics are the same.
441-
py_ref_tmpl<owns_ref, true> out = obj;
441+
py_ref_t<owns_ref, true> out = obj;
442442
return out;
443443
}
444444

@@ -447,13 +447,13 @@ inline py_ref_tmpl<owns_ref, true> nullcheck(py_ref_tmpl<owns_ref, not_null> &&o
447447
* This should be used when the pointer is already known to not be null.
448448
*/
449449
template <bool owns_ref, bool not_null>
450-
inline py_ref_tmpl<owns_ref, true> disallow_null(py_ref_tmpl<owns_ref, not_null> &&obj) noexcept
450+
inline py_ref_t<owns_ref, true> disallow_null(py_ref_t<owns_ref, not_null> &&obj) noexcept
451451
{
452452
// Assert that the wrapped pointer is actually not null.
453453
assert(obj.get() != nullptr);
454454
// Assert that the wrapped reference is valid if it is not null.
455455
PYDYND_ASSERT_IF(obj.get() != nullptr, Py_REFCNT(obj.get()) > 0);
456-
return py_ref_tmpl<owns_ref, true>(obj.release(), owns_ref);
456+
return py_ref_t<owns_ref, true>(obj.release(), owns_ref);
457457
}
458458

459459
// RAII class to acquire GIL.

0 commit comments

Comments
 (0)