Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bda9b43

Browse files
authored
Merge branch 'main' into isolate-io/poc
2 parents 4e64198 + 84181c1 commit bda9b43

19 files changed

Lines changed: 276 additions & 187 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ jobs:
154154
needs: check_source
155155
if: needs.check_source.outputs.run_tests == 'true'
156156
env:
157+
HOMEBREW_NO_ANALYTICS: 1
158+
HOMEBREW_NO_AUTO_UPDATE: 1
159+
HOMEBREW_NO_INSTALL_CLEANUP: 1
157160
PYTHONSTRICTEXTENSIONBUILD: 1
158161
steps:
159162
- uses: actions/checkout@v3

Doc/library/importlib.resources.abc.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@
8989

9090
.. class:: Traversable
9191

92-
An object with a subset of pathlib.Path methods suitable for
92+
An object with a subset of :class:`pathlib.Path` methods suitable for
9393
traversing directories and opening files.
9494

95+
For a representation of the object on the file-system, use
96+
:meth:`importlib.resources.as_file`.
97+
9598
.. versionadded:: 3.9
9699

97100
.. deprecated-removed:: 3.12 3.14

Doc/library/zipfile.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ The module defines the following items:
5555
.. class:: Path
5656
:noindex:
5757

58-
A pathlib-compatible wrapper for zip files. See section
59-
:ref:`path-objects` for details.
58+
Class that implements a subset of the interface provided by
59+
:class:`pathlib.Path`, including the full
60+
:class:`importlib.resources.abc.Traversable` interface.
6061

6162
.. versionadded:: 3.8
6263

Include/cpython/code.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,35 @@ extern "C" {
1919
typedef union {
2020
uint16_t cache;
2121
struct {
22-
uint8_t opcode;
23-
uint8_t oparg;
24-
};
22+
uint8_t code;
23+
uint8_t arg;
24+
} op;
2525
} _Py_CODEUNIT;
2626

27-
#define _Py_OPCODE(word) ((word).opcode)
28-
#define _Py_OPARG(word) ((word).oparg)
27+
28+
/* These macros only remain defined for compatibility. */
29+
#define _Py_OPCODE(word) ((word).op.code)
30+
#define _Py_OPARG(word) ((word).op.arg)
31+
32+
static inline _Py_CODEUNIT
33+
_py_make_codeunit(uint8_t opcode, uint8_t oparg)
34+
{
35+
// No designated initialisers because of C++ compat
36+
_Py_CODEUNIT word;
37+
word.op.code = opcode;
38+
word.op.arg = oparg;
39+
return word;
40+
}
2941

3042
static inline void
3143
_py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
3244
{
33-
word->opcode = opcode;
45+
word->op.code = opcode;
3446
}
3547

36-
#define _Py_SET_OPCODE(word, opcode) _py_set_opocde(&(word), opcode)
48+
#define _Py_MAKE_CODEUNIT(opcode, oparg) _py_make_codeunit((opcode), (oparg))
49+
#define _Py_SET_OPCODE(word, opcode) _py_set_opcode(&(word), (opcode))
50+
3751

3852
typedef struct {
3953
PyObject *_co_code;

Lib/test/test_zipfile/test_core.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,5 +3010,67 @@ def test_cli_with_metadata_encoding_extract(self):
30103010
self.assertIn(name, listing)
30113011

30123012

3013+
class StripExtraTests(unittest.TestCase):
3014+
# Note: all of the "z" characters are technically invalid, but up
3015+
# to 3 bytes at the end of the extra will be passed through as they
3016+
# are too short to encode a valid extra.
3017+
3018+
ZIP64_EXTRA = 1
3019+
3020+
def test_no_data(self):
3021+
s = struct.Struct("<HH")
3022+
a = s.pack(self.ZIP64_EXTRA, 0)
3023+
b = s.pack(2, 0)
3024+
c = s.pack(3, 0)
3025+
3026+
self.assertEqual(b'', zipfile._strip_extra(a, (self.ZIP64_EXTRA,)))
3027+
self.assertEqual(b, zipfile._strip_extra(b, (self.ZIP64_EXTRA,)))
3028+
self.assertEqual(
3029+
b+b"z", zipfile._strip_extra(b+b"z", (self.ZIP64_EXTRA,)))
3030+
3031+
self.assertEqual(b+c, zipfile._strip_extra(a+b+c, (self.ZIP64_EXTRA,)))
3032+
self.assertEqual(b+c, zipfile._strip_extra(b+a+c, (self.ZIP64_EXTRA,)))
3033+
self.assertEqual(b+c, zipfile._strip_extra(b+c+a, (self.ZIP64_EXTRA,)))
3034+
3035+
def test_with_data(self):
3036+
s = struct.Struct("<HH")
3037+
a = s.pack(self.ZIP64_EXTRA, 1) + b"a"
3038+
b = s.pack(2, 2) + b"bb"
3039+
c = s.pack(3, 3) + b"ccc"
3040+
3041+
self.assertEqual(b"", zipfile._strip_extra(a, (self.ZIP64_EXTRA,)))
3042+
self.assertEqual(b, zipfile._strip_extra(b, (self.ZIP64_EXTRA,)))
3043+
self.assertEqual(
3044+
b+b"z", zipfile._strip_extra(b+b"z", (self.ZIP64_EXTRA,)))
3045+
3046+
self.assertEqual(b+c, zipfile._strip_extra(a+b+c, (self.ZIP64_EXTRA,)))
3047+
self.assertEqual(b+c, zipfile._strip_extra(b+a+c, (self.ZIP64_EXTRA,)))
3048+
self.assertEqual(b+c, zipfile._strip_extra(b+c+a, (self.ZIP64_EXTRA,)))
3049+
3050+
def test_multiples(self):
3051+
s = struct.Struct("<HH")
3052+
a = s.pack(self.ZIP64_EXTRA, 1) + b"a"
3053+
b = s.pack(2, 2) + b"bb"
3054+
3055+
self.assertEqual(b"", zipfile._strip_extra(a+a, (self.ZIP64_EXTRA,)))
3056+
self.assertEqual(b"", zipfile._strip_extra(a+a+a, (self.ZIP64_EXTRA,)))
3057+
self.assertEqual(
3058+
b"z", zipfile._strip_extra(a+a+b"z", (self.ZIP64_EXTRA,)))
3059+
self.assertEqual(
3060+
b+b"z", zipfile._strip_extra(a+a+b+b"z", (self.ZIP64_EXTRA,)))
3061+
3062+
self.assertEqual(b, zipfile._strip_extra(a+a+b, (self.ZIP64_EXTRA,)))
3063+
self.assertEqual(b, zipfile._strip_extra(a+b+a, (self.ZIP64_EXTRA,)))
3064+
self.assertEqual(b, zipfile._strip_extra(b+a+a, (self.ZIP64_EXTRA,)))
3065+
3066+
def test_too_short(self):
3067+
self.assertEqual(b"", zipfile._strip_extra(b"", (self.ZIP64_EXTRA,)))
3068+
self.assertEqual(b"z", zipfile._strip_extra(b"z", (self.ZIP64_EXTRA,)))
3069+
self.assertEqual(
3070+
b"zz", zipfile._strip_extra(b"zz", (self.ZIP64_EXTRA,)))
3071+
self.assertEqual(
3072+
b"zzz", zipfile._strip_extra(b"zzz", (self.ZIP64_EXTRA,)))
3073+
3074+
30133075
if __name__ == "__main__":
30143076
unittest.main()

Lib/zipfile/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ def _strip_extra(extra, xids):
207207
i = j
208208
if not modified:
209209
return extra
210+
if start != len(extra):
211+
buffer.append(extra[start:])
210212
return b''.join(buffer)
211213

212214
def _check_zipfile(fp):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removes use of non-standard C++ extension in public header files.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Correctly preserve "extra" fields in ``zipfile`` regardless of their
2+
ordering relative to a zip64 "extra."

Objects/codeobject.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
413413
PyBytes_GET_SIZE(con->code));
414414
int entry_point = 0;
415415
while (entry_point < Py_SIZE(co) &&
416-
_Py_OPCODE(_PyCode_CODE(co)[entry_point]) != RESUME) {
416+
_PyCode_CODE(co)[entry_point].op.code != RESUME) {
417417
entry_point++;
418418
}
419419
co->_co_firsttraceable = entry_point;
@@ -1505,12 +1505,12 @@ deopt_code(_Py_CODEUNIT *instructions, Py_ssize_t len)
15051505
{
15061506
for (int i = 0; i < len; i++) {
15071507
_Py_CODEUNIT instruction = instructions[i];
1508-
int opcode = _PyOpcode_Deopt[_Py_OPCODE(instruction)];
1508+
int opcode = _PyOpcode_Deopt[instruction.op.code];
15091509
int caches = _PyOpcode_Caches[opcode];
1510-
instructions[i].opcode = opcode;
1510+
instructions[i].op.code = opcode;
15111511
while (caches--) {
1512-
instructions[++i].opcode = CACHE;
1513-
instructions[i].oparg = 0;
1512+
instructions[++i].op.code = CACHE;
1513+
instructions[i].op.arg = 0;
15141514
}
15151515
}
15161516
}
@@ -1763,13 +1763,13 @@ code_richcompare(PyObject *self, PyObject *other, int op)
17631763
for (int i = 0; i < Py_SIZE(co); i++) {
17641764
_Py_CODEUNIT co_instr = _PyCode_CODE(co)[i];
17651765
_Py_CODEUNIT cp_instr = _PyCode_CODE(cp)[i];
1766-
co_instr.opcode = _PyOpcode_Deopt[_Py_OPCODE(co_instr)];
1767-
cp_instr.opcode =_PyOpcode_Deopt[_Py_OPCODE(cp_instr)];
1766+
co_instr.op.code = _PyOpcode_Deopt[co_instr.op.code];
1767+
cp_instr.op.code = _PyOpcode_Deopt[cp_instr.op.code];
17681768
eq = co_instr.cache == cp_instr.cache;
17691769
if (!eq) {
17701770
goto unequal;
17711771
}
1772-
i += _PyOpcode_Caches[_Py_OPCODE(co_instr)];
1772+
i += _PyOpcode_Caches[co_instr.op.code];
17731773
}
17741774

17751775
/* compare constants */
@@ -1848,9 +1848,9 @@ code_hash(PyCodeObject *co)
18481848
SCRAMBLE_IN(co->co_firstlineno);
18491849
SCRAMBLE_IN(Py_SIZE(co));
18501850
for (int i = 0; i < Py_SIZE(co); i++) {
1851-
int deop = _PyOpcode_Deopt[_Py_OPCODE(_PyCode_CODE(co)[i])];
1851+
int deop = _PyOpcode_Deopt[_PyCode_CODE(co)[i].op.code];
18521852
SCRAMBLE_IN(deop);
1853-
SCRAMBLE_IN(_Py_OPARG(_PyCode_CODE(co)[i]));
1853+
SCRAMBLE_IN(_PyCode_CODE(co)[i].op.arg);
18541854
i += _PyOpcode_Caches[deop];
18551855
}
18561856
if ((Py_hash_t)uhash == -1) {

Objects/frameobject.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ static unsigned int
111111
get_arg(const _Py_CODEUNIT *codestr, Py_ssize_t i)
112112
{
113113
_Py_CODEUNIT word;
114-
unsigned int oparg = _Py_OPARG(codestr[i]);
115-
if (i >= 1 && _Py_OPCODE(word = codestr[i-1]) == EXTENDED_ARG) {
116-
oparg |= _Py_OPARG(word) << 8;
117-
if (i >= 2 && _Py_OPCODE(word = codestr[i-2]) == EXTENDED_ARG) {
118-
oparg |= _Py_OPARG(word) << 16;
119-
if (i >= 3 && _Py_OPCODE(word = codestr[i-3]) == EXTENDED_ARG) {
120-
oparg |= _Py_OPARG(word) << 24;
114+
unsigned int oparg = codestr[i].op.arg;
115+
if (i >= 1 && (word = codestr[i-1]).op.code == EXTENDED_ARG) {
116+
oparg |= word.op.arg << 8;
117+
if (i >= 2 && (word = codestr[i-2]).op.code == EXTENDED_ARG) {
118+
oparg |= word.op.arg << 16;
119+
if (i >= 3 && (word = codestr[i-3]).op.code == EXTENDED_ARG) {
120+
oparg |= word.op.arg << 24;
121121
}
122122
}
123123
}
@@ -304,7 +304,7 @@ mark_stacks(PyCodeObject *code_obj, int len)
304304
if (next_stack == UNINITIALIZED) {
305305
continue;
306306
}
307-
opcode = _Py_OPCODE(code[i]);
307+
opcode = code[i].op.code;
308308
switch (opcode) {
309309
case JUMP_IF_FALSE_OR_POP:
310310
case JUMP_IF_TRUE_OR_POP:
@@ -610,7 +610,7 @@ _PyFrame_GetState(PyFrameObject *frame)
610610
if (_PyInterpreterFrame_LASTI(frame->f_frame) < 0) {
611611
return FRAME_CREATED;
612612
}
613-
switch (_Py_OPCODE(*frame->f_frame->prev_instr))
613+
switch (frame->f_frame->prev_instr->op.code)
614614
{
615615
case COPY_FREE_VARS:
616616
case MAKE_CELL:
@@ -1092,8 +1092,8 @@ _PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg)
10921092
for (_Py_CODEUNIT *instruction = _PyCode_CODE(frame->f_code);
10931093
instruction < frame->prev_instr; instruction++)
10941094
{
1095-
int check_opcode = _PyOpcode_Deopt[_Py_OPCODE(*instruction)];
1096-
check_oparg |= _Py_OPARG(*instruction);
1095+
int check_opcode = _PyOpcode_Deopt[instruction->op.code];
1096+
check_oparg |= instruction->op.arg;
10971097
if (check_opcode == opcode && check_oparg == oparg) {
10981098
return 1;
10991099
}
@@ -1117,7 +1117,7 @@ frame_init_get_vars(_PyInterpreterFrame *frame)
11171117
// here:
11181118
PyCodeObject *co = frame->f_code;
11191119
int lasti = _PyInterpreterFrame_LASTI(frame);
1120-
if (!(lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS
1120+
if (!(lasti < 0 && _PyCode_CODE(co)->op.code == COPY_FREE_VARS
11211121
&& PyFunction_Check(frame->f_funcobj)))
11221122
{
11231123
/* Free vars are initialized */

0 commit comments

Comments
 (0)