1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
From f296d7929db60390944821f2fbedf35f2c7bbcd6 Mon Sep 17 00:00:00 2001
From: Stuart Archibald <stuartarchibald@users.noreply.github.com>
Origin: https://github.com/numba/numba/pull/8639
Date: Fri, 25 Nov 2022 16:55:21 +0000
Subject: [PATCH 10/20] Fix issue with EXTENDED_ARG test and update test
support for code obj.
As title.
---
numba/tests/support.py | 10 +++++++++-
numba/tests/test_extended_arg.py | 11 ++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/numba/tests/support.py b/numba/tests/support.py
index d71afc48c44..493a6b3b6ca 100644
--- a/numba/tests/support.py
+++ b/numba/tests/support.py
@@ -685,7 +685,15 @@ def tweak_code(func, codestring=None, consts=None):
codestring = co.co_code
if consts is None:
consts = co.co_consts
- if utils.PYVERSION >= (3, 8):
+ if utils.PYVERSION >= (3, 11):
+ new_code = tp(co.co_argcount, co.co_posonlyargcount,
+ co.co_kwonlyargcount, co.co_nlocals,
+ co.co_stacksize, co.co_flags, codestring,
+ consts, co.co_names, co.co_varnames,
+ co.co_filename, co.co_name, co.co_qualname,
+ co.co_firstlineno, co.co_lnotab, co.co_exceptiontable,
+ co.co_freevars, co.co_cellvars)
+ elif utils.PYVERSION >= (3, 8):
new_code = tp(co.co_argcount, co.co_posonlyargcount,
co.co_kwonlyargcount, co.co_nlocals,
co.co_stacksize, co.co_flags, codestring,
diff --git a/numba/tests/test_extended_arg.py b/numba/tests/test_extended_arg.py
index 11f7a249974..3a4607b36a6 100644
--- a/numba/tests/test_extended_arg.py
+++ b/numba/tests/test_extended_arg.py
@@ -5,6 +5,7 @@
import sys
from numba import jit
+from numba.core import utils
from numba.tests.support import TestCase, tweak_code
@@ -26,7 +27,15 @@ def f():
bytecode_len = 0xff
bytecode_format = "<BB"
consts = consts + (None,) * bytecode_len + (42,)
- b[:0] = struct.pack(bytecode_format, dis.EXTENDED_ARG, 1)
+ if utils.PYVERSION >= (3, 11):
+ # Python 3.11 has a RESUME op code at the start of a function, need
+ # to inject the EXTENDED_ARG after this to influence the LOAD_CONST
+ offset = 2 # 2 byte op code
+ else:
+ offset = 0
+
+ packed_extend_arg = struct.pack(bytecode_format, dis.EXTENDED_ARG, 1)
+ b[:] = b[:offset] + packed_extend_arg + b[offset:]
tweak_code(f, codestring=bytes(b), consts=consts)
return f
|