Skip to content

Commit 4702d58

Browse files
committed
Use macros on Windows
1 parent c501175 commit 4702d58

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Include/internal/pycore_stackref.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ PyStackRef_AsStrongReference(_PyStackRef stackref)
370370
} \
371371
} while (0)
372372

373+
373374
#else // Py_GIL_DISABLED
374375

375376
// With GIL
@@ -418,6 +419,12 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
418419

419420
#endif
420421

422+
#ifdef _WIN32
423+
#define PyStackRef_IsUncountedMortal(REF) (((REF).bits & Py_TAG_BITS) == 0)
424+
#define PyStackRef_IsCountedMortal(REF) (((REF).bits & Py_TAG_BITS) == Py_TAG_REFCNT)
425+
#define PyStackRef_IsMortal(REF) (((REF).bits & Py_TAG_BITS) != Py_TAG_IMMORTAL)
426+
#define PyStackRef_AsPyObjectBorrow BITS_TO_PTR_MASKED
427+
#else
421428
/* Does this ref not have an embedded refcount and refer to a mortal object? */
422429
static inline int
423430
PyStackRef_IsUncountedMortal(_PyStackRef ref)
@@ -444,6 +451,7 @@ PyStackRef_AsPyObjectBorrow(_PyStackRef ref)
444451
{
445452
return BITS_TO_PTR_MASKED(ref);
446453
}
454+
#endif
447455

448456
static inline PyObject *
449457
PyStackRef_AsPyObjectSteal(_PyStackRef ref)
@@ -508,6 +516,10 @@ PyStackRef_FromPyObjectImmortal(PyObject *obj)
508516
return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_IMMORTAL};
509517
}
510518

519+
#ifdef _WIN32
520+
#define PyStackRef_DUP(REF) \
521+
(PyStackRef_IsUncountedMortal(REF) ? Py_INCREF_MORTAL(BITS_TO_PTR(ref)) : (REF))
522+
#else
511523
static inline _PyStackRef
512524
PyStackRef_DUP(_PyStackRef ref)
513525
{
@@ -517,6 +529,7 @@ PyStackRef_DUP(_PyStackRef ref)
517529
}
518530
return ref;
519531
}
532+
#endif
520533

521534
static inline bool
522535
PyStackRef_IsHeapSafe(_PyStackRef ref)
@@ -537,6 +550,12 @@ PyStackRef_MakeHeapSafe(_PyStackRef ref)
537550
return ref;
538551
}
539552

553+
#ifdef _WIN32
554+
#define PyStackRef_CLOSE(REF) \
555+
do { \
556+
if (PyStackRef_IsUncountedMortal(REF)) Py_DECREF_MORTAL(BITS_TO_PTR(ref)); \
557+
} while (0)
558+
#else
540559
static inline void
541560
PyStackRef_CLOSE(_PyStackRef ref)
542561
{
@@ -545,6 +564,7 @@ PyStackRef_CLOSE(_PyStackRef ref)
545564
Py_DECREF_MORTAL(BITS_TO_PTR(ref));
546565
}
547566
}
567+
#endif
548568

549569
static inline void
550570
PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct)
@@ -555,6 +575,9 @@ PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct)
555575
}
556576
}
557577

578+
#ifdef _WIN32
579+
#define PyStackRef_XCLOSE PyStackRef_CLOSE
580+
#else
558581
static inline void
559582
PyStackRef_XCLOSE(_PyStackRef ref)
560583
{
@@ -564,6 +587,7 @@ PyStackRef_XCLOSE(_PyStackRef ref)
564587
Py_DECREF_MORTAL(BITS_TO_PTR(ref));
565588
}
566589
}
590+
#endif
567591

568592
#define PyStackRef_CLEAR(REF) \
569593
do { \

0 commit comments

Comments
 (0)