Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 96ff4c2

Browse filesBrowse files
authored
GH-128682: Mark two more macros as escaping. (GH-129645)
Expand out SETLOCAL so that code generator can see the decref. Mark Py_CLEAR as escaping
1 parent 2effea4 commit 96ff4c2
Copy full SHA for 96ff4c2

File tree

Expand file treeCollapse file tree

6 files changed

+127
-46
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+127
-46
lines changed

‎Python/bytecodes.c

Copy file name to clipboardExpand all lines: Python/bytecodes.c
+18-7Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ dummy_func(
272272

273273
inst(LOAD_FAST_AND_CLEAR, (-- value)) {
274274
value = GETLOCAL(oparg);
275-
// do not use SETLOCAL here, it decrefs the old value
276275
GETLOCAL(oparg) = PyStackRef_NULL;
277276
}
278277

@@ -328,8 +327,10 @@ dummy_func(
328327
}
329328

330329
replicate(8) inst(STORE_FAST, (value --)) {
331-
SETLOCAL(oparg, value);
330+
_PyStackRef tmp = GETLOCAL(oparg);
331+
GETLOCAL(oparg) = value;
332332
DEAD(value);
333+
PyStackRef_XCLOSE(tmp);
333334
}
334335

335336
pseudo(STORE_FAST_MAYBE_NULL, (unused --)) = {
@@ -339,18 +340,24 @@ dummy_func(
339340
inst(STORE_FAST_LOAD_FAST, (value1 -- value2)) {
340341
uint32_t oparg1 = oparg >> 4;
341342
uint32_t oparg2 = oparg & 15;
342-
SETLOCAL(oparg1, value1);
343+
_PyStackRef tmp = GETLOCAL(oparg1);
344+
GETLOCAL(oparg1) = value1;
343345
DEAD(value1);
344346
value2 = PyStackRef_DUP(GETLOCAL(oparg2));
347+
PyStackRef_XCLOSE(tmp);
345348
}
346349

347350
inst(STORE_FAST_STORE_FAST, (value2, value1 --)) {
348351
uint32_t oparg1 = oparg >> 4;
349352
uint32_t oparg2 = oparg & 15;
350-
SETLOCAL(oparg1, value1);
353+
_PyStackRef tmp = GETLOCAL(oparg1);
354+
GETLOCAL(oparg1) = value1;
351355
DEAD(value1);
352-
SETLOCAL(oparg2, value2);
356+
PyStackRef_XCLOSE(tmp);
357+
tmp = GETLOCAL(oparg2);
358+
GETLOCAL(oparg2) = value2;
353359
DEAD(value2);
360+
PyStackRef_XCLOSE(tmp);
354361
}
355362

356363
pure inst(POP_TOP, (value --)) {
@@ -1775,7 +1782,9 @@ dummy_func(
17751782
);
17761783
ERROR_IF(1, error);
17771784
}
1778-
SETLOCAL(oparg, PyStackRef_NULL);
1785+
_PyStackRef tmp = GETLOCAL(oparg);
1786+
GETLOCAL(oparg) = PyStackRef_NULL;
1787+
PyStackRef_XCLOSE(tmp);
17791788
}
17801789

17811790
inst(MAKE_CELL, (--)) {
@@ -1786,7 +1795,9 @@ dummy_func(
17861795
if (cell == NULL) {
17871796
ERROR_NO_POP();
17881797
}
1789-
SETLOCAL(oparg, PyStackRef_FromPyObjectSteal(cell));
1798+
_PyStackRef tmp = GETLOCAL(oparg);
1799+
GETLOCAL(oparg) = PyStackRef_FromPyObjectSteal(cell);
1800+
PyStackRef_XCLOSE(tmp);
17901801
}
17911802

17921803
inst(DELETE_DEREF, (--)) {

‎Python/ceval.c

Copy file name to clipboardExpand all lines: Python/ceval.c
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ lltrace_instruction(_PyInterpreterFrame *frame,
194194
}
195195
fflush(stdout);
196196
}
197+
197198
static void
198199
lltrace_resume_frame(_PyInterpreterFrame *frame)
199200
{

‎Python/ceval_macros.h

Copy file name to clipboardExpand all lines: Python/ceval_macros.h
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,6 @@ GETITEM(PyObject *v, Py_ssize_t i) {
221221
#define LOCALS_ARRAY (frame->localsplus)
222222
#define GETLOCAL(i) (frame->localsplus[i])
223223

224-
/* The SETLOCAL() macro must not DECREF the local variable in-place and
225-
then store the new value; it must copy the old value to a temporary
226-
value, then store the new value, and then DECREF the temporary value.
227-
This is because it is possible that during the DECREF the frame is
228-
accessed by other code (e.g. a __del__ method or gc.collect()) and the
229-
variable would be pointing to already-freed memory. */
230-
#define SETLOCAL(i, value) do { _PyStackRef tmp = GETLOCAL(i); \
231-
GETLOCAL(i) = value; \
232-
PyStackRef_XCLOSE(tmp); } while (0)
233224

234225
#ifdef Py_STATS
235226
#define UPDATE_MISS_STATS(INSTNAME) \

‎Python/executor_cases.c.h

Copy file name to clipboardExpand all lines: Python/executor_cases.c.h
+57-12Lines changed: 57 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.