Skip to content

Commit d1e8e45

Browse files
committed
Make the default build work
1 parent 1f5cfcd commit d1e8e45

File tree

4 files changed

+19
-39
lines changed

4 files changed

+19
-39
lines changed

Include/internal/pycore_stackref.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
425425
assert(!_Py_IsStaticImmortal(obj));
426426
break;
427427
case Py_TAG_REFCNT:
428-
assert(obj == NULL || _Py_IsImmortal(obj));
429428
break;
430429
default:
431430
assert(0);
@@ -438,24 +437,29 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
438437

439438
#endif
440439

441-
#define PyStackRef_Borrow(ref) PyStackRef_DUP(ref)
442-
443440
#ifdef _WIN32
444-
#define PyStackRef_RefcountOnObject(REF) (((REF).bits & Py_TAG_BITS) == 0)
441+
#define PyStackRef_RefcountOnObject(REF) (((REF).bits & Py_TAG_REFCNT) == 0)
445442
#define PyStackRef_AsPyObjectBorrow BITS_TO_PTR_MASKED
443+
#define PyStackRef_Borrow(REF) (_PyStackRef){ .bits = ((REF).bits) | Py_TAG_REFCNT};
446444
#else
447445
/* Does this ref not have an embedded refcount and thus not refer to a declared immmortal object? */
448446
static inline int
449447
PyStackRef_RefcountOnObject(_PyStackRef ref)
450448
{
451-
return (ref.bits & Py_TAG_BITS) == 0;
449+
return (ref.bits & Py_TAG_REFCNT) == 0;
452450
}
453451

454452
static inline PyObject *
455453
PyStackRef_AsPyObjectBorrow(_PyStackRef ref)
456454
{
457455
return BITS_TO_PTR_MASKED(ref);
458456
}
457+
458+
static inline _PyStackRef
459+
PyStackRef_Borrow(_PyStackRef ref)
460+
{
461+
return (_PyStackRef){ .bits = ref.bits | Py_TAG_REFCNT };
462+
}
459463
#endif
460464

461465
static inline PyObject *

Objects/floatobject.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -134,44 +134,13 @@ PyFloat_FromDouble(double fval)
134134
return (PyObject *) op;
135135
}
136136

137-
#ifdef Py_GIL_DISABLED
138-
139137
_PyStackRef _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value)
140138
{
141139
PyStackRef_CLOSE_SPECIALIZED(left, _PyFloat_ExactDealloc);
142140
PyStackRef_CLOSE_SPECIALIZED(right, _PyFloat_ExactDealloc);
143141
return PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(value));
144142
}
145143

146-
#else // Py_GIL_DISABLED
147-
148-
_PyStackRef _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value)
149-
{
150-
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
151-
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
152-
if (Py_REFCNT(left_o) == 1) {
153-
((PyFloatObject *)left_o)->ob_fval = value;
154-
PyStackRef_CLOSE_SPECIALIZED(right, _PyFloat_ExactDealloc);
155-
return left;
156-
}
157-
else if (Py_REFCNT(right_o) == 1) {
158-
((PyFloatObject *)right_o)->ob_fval = value;
159-
PyStackRef_CLOSE_SPECIALIZED(left, _PyFloat_ExactDealloc);
160-
return right;
161-
}
162-
else {
163-
PyObject *result = PyFloat_FromDouble(value);
164-
PyStackRef_CLOSE_SPECIALIZED(left, _PyFloat_ExactDealloc);
165-
PyStackRef_CLOSE_SPECIALIZED(right, _PyFloat_ExactDealloc);
166-
if (result == NULL) {
167-
return PyStackRef_NULL;
168-
}
169-
return PyStackRef_FromPyObjectStealMortal(result);
170-
}
171-
}
172-
173-
#endif // Py_GIL_DISABLED
174-
175144
static PyObject *
176145
float_from_string_inner(const char *s, Py_ssize_t len, void *obj)
177146
{

Python/gc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,12 @@ visit_decref(PyObject *op, void *parent)
543543
int
544544
_PyGC_VisitStackRef(_PyStackRef *ref, visitproc visit, void *arg)
545545
{
546+
// This is a bit tricky! We want to ignore stackrefs with embedded
547+
// refcounts when computing the incoming references, but otherwise treat
548+
// them like normal.
549+
if (!PyStackRef_RefcountOnObject(*ref) && (visit == visit_decref)) {
550+
return 0;
551+
}
546552
Py_VISIT(PyStackRef_AsPyObjectBorrow(*ref));
547553
return 0;
548554
}
@@ -553,7 +559,7 @@ _PyGC_VisitFrameStack(_PyInterpreterFrame *frame, visitproc visit, void *arg)
553559
_PyStackRef *ref = _PyFrame_GetLocalsArray(frame);
554560
/* locals and stack */
555561
for (; ref < frame->stackpointer; ref++) {
556-
Py_VISIT(PyStackRef_AsPyObjectBorrow(*ref));
562+
_Py_VISIT_STACKREF(*ref);
557563
}
558564
return 0;
559565
}

Python/marshal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,12 @@ w_ref(PyObject *v, char *flag, WFILE *p)
382382
if (p->version < 3 || p->hashtable == NULL)
383383
return 0; /* not writing object references */
384384

385-
/* If it has only one reference, it definitely isn't shared.
386-
* But we use TYPE_REF always for interned string, to PYC file stable
385+
/* If it has only one reference, it definitely isn't shared. But we use
386+
* TYPE_REF always for interned string and code objects, to PYC file stable
387387
* as possible.
388388
*/
389389
if (Py_REFCNT(v) == 1 &&
390+
!PyCode_Check(v) &&
390391
!(PyUnicode_CheckExact(v) && PyUnicode_CHECK_INTERNED(v))) {
391392
return 0;
392393
}

0 commit comments

Comments
 (0)