Skip to content

Commit d749430

Browse files
authored
Merge branch 'python:main' into windows-aarch64-runners
2 parents c2de8d8 + 49fb75c commit d749430

29 files changed

+249
-169
lines changed

Include/internal/pycore_gc.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,6 @@ union _PyStackRef;
352352
extern int _PyGC_VisitFrameStack(_PyInterpreterFrame *frame, visitproc visit, void *arg);
353353
extern int _PyGC_VisitStackRef(union _PyStackRef *ref, visitproc visit, void *arg);
354354

355-
// Like Py_VISIT but for _PyStackRef fields
356-
#define _Py_VISIT_STACKREF(ref) \
357-
do { \
358-
if (!PyStackRef_IsNull(ref)) { \
359-
int vret = _PyGC_VisitStackRef(&(ref), visit, arg); \
360-
if (vret) \
361-
return vret; \
362-
} \
363-
} while (0)
364-
365355
#ifdef Py_GIL_DISABLED
366356
extern void _PyGC_VisitObjectsWorldStopped(PyInterpreterState *interp,
367357
gcvisitobjects_t callback, void *arg);

Include/internal/pycore_genobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include "pycore_interpframe.h" // _PyInterpreterFrame
1211
#include "pycore_interpframe_structs.h" // _PyGenObject
1312

13+
#include <stddef.h> // offsetof()
14+
1415

1516
static inline
1617
PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)

Include/internal/pycore_setobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ PyAPI_FUNC(int) _PySet_Contains(PySetObject *so, PyObject *key);
3333
// Clears the set without acquiring locks. Used by _PyCode_Fini.
3434
extern void _PySet_ClearInternal(PySetObject *so);
3535

36+
PyAPI_FUNC(int) _PySet_AddTakeRef(PySetObject *so, PyObject *key);
37+
3638
#ifdef __cplusplus
3739
}
3840
#endif

Include/internal/pycore_stackref.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,16 @@ _Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, _PyStackRef *out)
658658

659659
#endif
660660

661+
// Like Py_VISIT but for _PyStackRef fields
662+
#define _Py_VISIT_STACKREF(ref) \
663+
do { \
664+
if (!PyStackRef_IsNull(ref)) { \
665+
int vret = _PyGC_VisitStackRef(&(ref), visit, arg); \
666+
if (vret) \
667+
return vret; \
668+
} \
669+
} while (0)
670+
661671
#ifdef __cplusplus
662672
}
663673
#endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Set to 'True' if the tests are run against the pathlib-abc PyPI package.
2+
is_pypi = False

Lib/test/test_pathlib/support/lexical_path.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
import ntpath
66
import os.path
7-
import pathlib.types
87
import posixpath
98

9+
from . import is_pypi
1010

11-
class LexicalPath(pathlib.types._JoinablePath):
11+
if is_pypi:
12+
from pathlib_abc import _JoinablePath
13+
else:
14+
from pathlib.types import _JoinablePath
15+
16+
17+
class LexicalPath(_JoinablePath):
1218
__slots__ = ('_segments',)
1319
parser = os.path
1420

Lib/test/test_pathlib/support/local_path.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,36 @@
77
"""
88

99
import os
10-
import pathlib.types
1110

12-
from test.support import os_helper
13-
from test.test_pathlib.support.lexical_path import LexicalPath
11+
from . import is_pypi
12+
from .lexical_path import LexicalPath
13+
14+
if is_pypi:
15+
from shutil import rmtree
16+
from pathlib_abc import PathInfo, _ReadablePath, _WritablePath
17+
can_symlink = True
18+
testfn = "TESTFN"
19+
else:
20+
from pathlib.types import PathInfo, _ReadablePath, _WritablePath
21+
from test.support import os_helper
22+
can_symlink = os_helper.can_symlink()
23+
testfn = os_helper.TESTFN
24+
rmtree = os_helper.rmtree
1425

1526

1627
class LocalPathGround:
17-
can_symlink = os_helper.can_symlink()
28+
can_symlink = can_symlink
1829

1930
def __init__(self, path_cls):
2031
self.path_cls = path_cls
2132

2233
def setup(self, local_suffix=""):
23-
root = self.path_cls(os_helper.TESTFN + local_suffix)
34+
root = self.path_cls(testfn + local_suffix)
2435
os.mkdir(root)
2536
return root
2637

2738
def teardown(self, root):
28-
os_helper.rmtree(root)
39+
rmtree(root)
2940

3041
def create_file(self, p, data=b''):
3142
with open(p, 'wb') as f:
@@ -79,7 +90,7 @@ def readbytes(self, p):
7990
return f.read()
8091

8192

82-
class LocalPathInfo(pathlib.types.PathInfo):
93+
class LocalPathInfo(PathInfo):
8394
"""
8495
Simple implementation of PathInfo for a local path
8596
"""
@@ -123,7 +134,7 @@ def is_symlink(self):
123134
return self._is_symlink
124135

125136

126-
class ReadableLocalPath(pathlib.types._ReadablePath, LexicalPath):
137+
class ReadableLocalPath(_ReadablePath, LexicalPath):
127138
"""
128139
Simple implementation of a ReadablePath class for local filesystem paths.
129140
"""
@@ -146,7 +157,7 @@ def readlink(self):
146157
return self.with_segments(os.readlink(self))
147158

148159

149-
class WritableLocalPath(pathlib.types._WritablePath, LexicalPath):
160+
class WritableLocalPath(_WritablePath, LexicalPath):
150161
"""
151162
Simple implementation of a WritablePath class for local filesystem paths.
152163
"""

Lib/test/test_pathlib/support/zip_path.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88

99
import errno
1010
import io
11-
import pathlib.types
1211
import posixpath
1312
import stat
1413
import zipfile
1514
from stat import S_IFMT, S_ISDIR, S_ISREG, S_ISLNK
1615

16+
from . import is_pypi
17+
18+
if is_pypi:
19+
from pathlib_abc import PathInfo, _ReadablePath, _WritablePath
20+
else:
21+
from pathlib.types import PathInfo, _ReadablePath, _WritablePath
22+
1723

1824
class ZipPathGround:
1925
can_symlink = True
@@ -31,7 +37,10 @@ def create_file(self, path, data=b''):
3137
path.zip_file.writestr(str(path), data)
3238

3339
def create_dir(self, path):
34-
path.zip_file.mkdir(str(path))
40+
zip_info = zipfile.ZipInfo(str(path) + '/')
41+
zip_info.external_attr |= stat.S_IFDIR << 16
42+
zip_info.external_attr |= stat.FILE_ATTRIBUTE_DIRECTORY
43+
path.zip_file.writestr(zip_info, '')
3544

3645
def create_symlink(self, path, target):
3746
zip_info = zipfile.ZipInfo(str(path))
@@ -80,7 +89,7 @@ def islink(self, p):
8089
return stat.S_ISLNK(info.external_attr >> 16)
8190

8291

83-
class MissingZipPathInfo:
92+
class MissingZipPathInfo(PathInfo):
8493
"""
8594
PathInfo implementation that is used when a zip file member is missing.
8695
"""
@@ -105,7 +114,7 @@ def resolve(self):
105114
missing_zip_path_info = MissingZipPathInfo()
106115

107116

108-
class ZipPathInfo:
117+
class ZipPathInfo(PathInfo):
109118
"""
110119
PathInfo implementation for an existing zip file member.
111120
"""
@@ -216,7 +225,7 @@ def append(self, item):
216225
self.tree.resolve(item.filename, create=True).zip_info = item
217226

218227

219-
class ReadableZipPath(pathlib.types._ReadablePath):
228+
class ReadableZipPath(_ReadablePath):
220229
"""
221230
Simple implementation of a ReadablePath class for .zip files.
222231
"""
@@ -279,7 +288,7 @@ def readlink(self):
279288
return self.with_segments(self.zip_file.read(info.zip_info).decode())
280289

281290

282-
class WritableZipPath(pathlib.types._WritablePath):
291+
class WritableZipPath(_WritablePath):
283292
"""
284293
Simple implementation of a WritablePath class for .zip files.
285294
"""
@@ -314,10 +323,13 @@ def __open_wb__(self, buffering=-1):
314323
return self.zip_file.open(str(self), 'w')
315324

316325
def mkdir(self, mode=0o777):
317-
self.zip_file.mkdir(str(self), mode)
326+
zinfo = zipfile.ZipInfo(str(self) + '/')
327+
zinfo.external_attr |= stat.S_IFDIR << 16
328+
zinfo.external_attr |= stat.FILE_ATTRIBUTE_DIRECTORY
329+
self.zip_file.writestr(zinfo, '')
318330

319331
def symlink_to(self, target, target_is_directory=False):
320-
zinfo = zipfile.ZipInfo(str(self))._for_archive(self.zip_file)
332+
zinfo = zipfile.ZipInfo(str(self))
321333
zinfo.external_attr = stat.S_IFLNK << 16
322334
if target_is_directory:
323335
zinfo.external_attr |= 0x10

Lib/test/test_pathlib/test_copy.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import contextlib
66
import unittest
77

8-
from pathlib import Path
9-
10-
from test.test_pathlib.support.local_path import LocalPathGround, WritableLocalPath
11-
from test.test_pathlib.support.zip_path import ZipPathGround, ReadableZipPath, WritableZipPath
8+
from .support import is_pypi
9+
from .support.local_path import LocalPathGround
10+
from .support.zip_path import ZipPathGround, ReadableZipPath, WritableZipPath
1211

1312

1413
class CopyTestBase:
@@ -53,7 +52,7 @@ def test_copy_file_to_existing_file(self):
5352
self.target_ground.readbytes(result))
5453

5554
def test_copy_file_to_directory(self):
56-
if not isinstance(self.target_root, WritableLocalPath):
55+
if isinstance(self.target_root, WritableZipPath):
5756
self.skipTest('needs local target')
5857
source = self.source_root / 'fileA'
5958
target = self.target_root / 'copyA'
@@ -113,7 +112,7 @@ def test_copy_dir_follow_symlinks_false(self):
113112
self.assertEqual(self.target_ground.readlink(target / 'linkD'), 'dirD')
114113

115114
def test_copy_dir_to_existing_directory(self):
116-
if not isinstance(self.target_root, WritableLocalPath):
115+
if isinstance(self.target_root, WritableZipPath):
117116
self.skipTest('needs local target')
118117
source = self.source_root / 'dirC'
119118
target = self.target_root / 'copyC'
@@ -153,19 +152,22 @@ class ZipToZipPathCopyTest(CopyTestBase, unittest.TestCase):
153152
target_ground = ZipPathGround(WritableZipPath)
154153

155154

156-
class ZipToLocalPathCopyTest(CopyTestBase, unittest.TestCase):
157-
source_ground = ZipPathGround(ReadableZipPath)
158-
target_ground = LocalPathGround(Path)
155+
if not is_pypi:
156+
from pathlib import Path
159157

158+
class ZipToLocalPathCopyTest(CopyTestBase, unittest.TestCase):
159+
source_ground = ZipPathGround(ReadableZipPath)
160+
target_ground = LocalPathGround(Path)
160161

161-
class LocalToZipPathCopyTest(CopyTestBase, unittest.TestCase):
162-
source_ground = LocalPathGround(Path)
163-
target_ground = ZipPathGround(WritableZipPath)
162+
163+
class LocalToZipPathCopyTest(CopyTestBase, unittest.TestCase):
164+
source_ground = LocalPathGround(Path)
165+
target_ground = ZipPathGround(WritableZipPath)
164166

165167

166-
class LocalToLocalPathCopyTest(CopyTestBase, unittest.TestCase):
167-
source_ground = LocalPathGround(Path)
168-
target_ground = LocalPathGround(Path)
168+
class LocalToLocalPathCopyTest(CopyTestBase, unittest.TestCase):
169+
source_ground = LocalPathGround(Path)
170+
target_ground = LocalPathGround(Path)
169171

170172

171173
if __name__ == "__main__":

Lib/test/test_pathlib/test_join.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
import unittest
66

7-
from pathlib import PurePath, Path
8-
from pathlib.types import _PathParser, _JoinablePath
9-
from test.test_pathlib.support.lexical_path import LexicalPath
7+
from .support import is_pypi
8+
from .support.lexical_path import LexicalPath
9+
10+
if is_pypi:
11+
from pathlib_abc import _PathParser, _JoinablePath
12+
else:
13+
from pathlib.types import _PathParser, _JoinablePath
1014

1115

1216
class JoinTestBase:
@@ -355,12 +359,14 @@ class LexicalPathJoinTest(JoinTestBase, unittest.TestCase):
355359
cls = LexicalPath
356360

357361

358-
class PurePathJoinTest(JoinTestBase, unittest.TestCase):
359-
cls = PurePath
362+
if not is_pypi:
363+
from pathlib import PurePath, Path
360364

365+
class PurePathJoinTest(JoinTestBase, unittest.TestCase):
366+
cls = PurePath
361367

362-
class PathJoinTest(JoinTestBase, unittest.TestCase):
363-
cls = Path
368+
class PathJoinTest(JoinTestBase, unittest.TestCase):
369+
cls = Path
364370

365371

366372
if __name__ == "__main__":

0 commit comments

Comments
 (0)