@@ -124,15 +124,15 @@ inline void decref_if_owned<false, false>(PyObject *obj) noexcept
124
124
}
125
125
126
126
template <bool owns_ref = true , bool not_null = true >
127
- class py_ref_tmpl {
127
+ class py_ref_t {
128
128
PyObject *o;
129
129
130
130
public:
131
131
// All versions default-initialize to null.
132
132
// This allows the smart pointer class to be moved from.
133
133
// Whether or not the class is allowed to be null only changes
134
134
// when zerochecks/exceptions may occur and when assertions are used.
135
- py_ref_tmpl () noexcept : o(nullptr ){};
135
+ py_ref_t () noexcept : o(nullptr ){};
136
136
137
137
// First define an accessor to get the PyObject pointer from
138
138
// the wrapper class.
@@ -151,11 +151,11 @@ class py_ref_tmpl {
151
151
/* If:
152
152
* This type allows null or the input type does not,
153
153
* 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.
155
155
*/
156
156
template <bool other_owns_ref, bool other_not_null,
157
157
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
159
159
{
160
160
// If the input is not null, assert that it isn't.
161
161
PYDYND_ASSERT_IF (other_not_null, other.o != nullptr );
@@ -175,7 +175,7 @@ class py_ref_tmpl {
175
175
*/
176
176
template <bool other_owns_ref, bool other_not_null,
177
177
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)
179
179
{
180
180
if (other.o != nullptr ) {
181
181
// Assert that the input reference is valid.
@@ -199,7 +199,7 @@ class py_ref_tmpl {
199
199
* a move operation is defined and will not raise an exception.
200
200
*/
201
201
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
203
203
{
204
204
// If this type is a non-null type, the assigned value should not be null.
205
205
// If the other type is a non-null type, the provided value should not be null,
@@ -227,7 +227,7 @@ class py_ref_tmpl {
227
227
* a move may be performed, but may also raise an exception.
228
228
*/
229
229
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)
231
231
{
232
232
if (other.o != nullptr ) {
233
233
// Assert that the input reference is valid.
@@ -256,7 +256,7 @@ class py_ref_tmpl {
256
256
* specify `consume_ref` as false regardless of whether or not you
257
257
* own the reference represented in the PyObject* you pass in.
258
258
*/
259
- explicit py_ref_tmpl (PyObject *obj, bool consume_ref) noexcept
259
+ explicit py_ref_t (PyObject *obj, bool consume_ref) noexcept
260
260
{
261
261
o = obj;
262
262
if (consume_ref) {
@@ -270,7 +270,7 @@ class py_ref_tmpl {
270
270
PYDYND_ASSERT_IF (obj != null, Py_REFCNT (obj) > 0 );
271
271
}
272
272
273
- ~py_ref_tmpl ()
273
+ ~py_ref_t ()
274
274
{
275
275
// A smart pointer wrapping a PyObject* still needs to be safe to
276
276
// destruct after it has been moved from.
@@ -288,11 +288,11 @@ class py_ref_tmpl {
288
288
/* If:
289
289
* This type allows null or the input type does not,
290
290
* 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.
292
292
*/
293
293
template <bool other_owns_ref, bool other_not_null,
294
294
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
296
296
{
297
297
// Assert that the input reference is not null if the input type does not allow nulls.
298
298
PYDYND_ASSERT_IF (other_not_null, other.o != nullptr );
@@ -310,11 +310,11 @@ class py_ref_tmpl {
310
310
* this type does not allow null,
311
311
* and the other type does,
312
312
* 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.
314
314
*/
315
315
template <bool other_owns_ref, bool other_not_null,
316
316
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
318
318
{
319
319
if (other.o != nullptr ) {
320
320
// Assert that the input reference is valid.
@@ -339,11 +339,11 @@ class py_ref_tmpl {
339
339
* this type doesn't allow null
340
340
* and the input type doesn't allow null,
341
341
* 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.
343
343
*/
344
344
template <bool other_owns_ref, bool other_not_null,
345
345
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
347
347
{
348
348
// If the input reference should not be null, assert that that is the case.
349
349
PYDYND_ASSERT_IF (other_not_null, other.o != nullptr );
@@ -362,11 +362,11 @@ class py_ref_tmpl {
362
362
* this type does not allow null,
363
363
* and the other type does,
364
364
* 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.
366
366
*/
367
367
template <bool other_owns_ref, bool other_not_null,
368
368
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
370
370
{
371
371
if (other.o != nullptr ) {
372
372
// Assert that the input reference is valid.
@@ -384,13 +384,13 @@ class py_ref_tmpl {
384
384
}
385
385
}
386
386
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 ); }
388
388
389
389
// Return a reference to the encapsulated PyObject as a raw pointer.
390
390
// Set the encapsulated pointer to NULL.
391
391
// If this is a type that owns its reference, an owned reference is returned.
392
392
// 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
394
394
{
395
395
// If the contained reference should not be null, assert that it isn't.
396
396
PYDYND_ASSERT_IF (not_null, ref.o != nullptr );
@@ -404,18 +404,18 @@ class py_ref_tmpl {
404
404
405
405
// Convenience aliases for the templated smart pointer classes.
406
406
407
- using py_ref = py_ref_tmpl <true , true >;
407
+ using py_ref = py_ref_t <true , true >;
408
408
409
- using py_ref_with_null = py_ref_tmpl <true , false >;
409
+ using py_ref_with_null = py_ref_t <true , false >;
410
410
411
- using py_borref = py_ref_tmpl <false , true >;
411
+ using py_borref = py_ref_t <false , true >;
412
412
413
- using py_borref_with_null = py_ref_tmpl <false , false >;
413
+ using py_borref_with_null = py_ref_t <false , false >;
414
414
415
415
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)
417
417
{
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));
419
419
}
420
420
421
421
/* Capture a new reference if it is not null.
@@ -435,10 +435,10 @@ inline py_ref capture_if_not_null(PyObject *o)
435
435
* only checks for via an assert statement in debug builds.
436
436
*/
437
437
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)
439
439
{
440
440
// 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;
442
442
return out;
443
443
}
444
444
@@ -447,13 +447,13 @@ inline py_ref_tmpl<owns_ref, true> nullcheck(py_ref_tmpl<owns_ref, not_null> &&o
447
447
* This should be used when the pointer is already known to not be null.
448
448
*/
449
449
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
451
451
{
452
452
// Assert that the wrapped pointer is actually not null.
453
453
assert (obj.get () != nullptr );
454
454
// Assert that the wrapped reference is valid if it is not null.
455
455
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);
457
457
}
458
458
459
459
// RAII class to acquire GIL.
0 commit comments