Skip to content

Commit 858821d

Browse files
authored
Bootstrap changes from 3.4 (#1628)
* Bootstrap changes from 3.4 * Fix test_imp failure * Disable weakref test on Mono
1 parent 3d8987b commit 858821d

4 files changed

Lines changed: 27 additions & 77 deletions

File tree

Src/IronPython/Modules/_fileio.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public FileIO(CodeContext/*!*/ context, int fd, string mode = "r", bool closefd
9595

9696
public FileIO(CodeContext/*!*/ context, string name, string mode = "r", bool closefd = true, object opener = null)
9797
: base(context) {
98+
if (name.Contains('\0')) {
99+
throw PythonOps.ValueError("embedded null character");
100+
}
98101
if (!closefd) {
99102
throw PythonOps.ValueError("Cannot use closefd=False with file name");
100103
}
@@ -610,6 +613,9 @@ private void SeekToEnd() {
610613
private static void Write(this Stream stream, ReadOnlySpan<byte> buffer) {
611614
stream.Write(buffer.ToArray(), 0, buffer.Length);
612615
}
616+
617+
private static bool Contains(this string str, char value)
618+
=> str.IndexOf(value) != -1;
613619
#endif
614620
}
615621
}

Src/StdLib/Lib/importlib/_bootstrap.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,13 @@ def _get_module_lock(name):
162162

163163
_imp.acquire_lock()
164164
try:
165-
try:
166-
lock = _module_locks[name]()
167-
except KeyError:
165+
# ironpython: optimization to avoid KeyError exception
166+
_unspecified = _bootstrap_external._unspecified
167+
lock_fn = _module_locks.get(name, _unspecified)
168+
if lock_fn is _unspecified:
168169
lock = None
170+
else:
171+
lock = lock_fn()
169172

170173
if lock is None:
171174
if _thread is None:
@@ -402,11 +405,6 @@ def __eq__(self, other):
402405

403406
@property
404407
def cached(self):
405-
if self._cached is None:
406-
if self.origin is not None and self._set_fileattr:
407-
if _bootstrap_external is None:
408-
raise NotImplementedError
409-
self._cached = _bootstrap_external._get_cached(self.origin)
410408
return self._cached
411409

412410
@cached.setter
@@ -479,10 +477,7 @@ def _spec_from_module(module, loader=None, origin=None):
479477
location = None
480478
if origin is None:
481479
if location is None:
482-
try:
483-
origin = loader._ORIGIN
484-
except AttributeError:
485-
origin = None
480+
origin = getattr(loader, '_ORIGIN', None) # ironpython: optimization to avoid KeyError exception
486481
else:
487482
origin = location
488483
try:

Src/StdLib/Lib/importlib/_bootstrap_external.py

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
_CASE_INSENSITIVE_PLATFORMS = (_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY
2727
+ _CASE_INSENSITIVE_PLATFORMS_STR_KEY)
2828

29+
_unspecified = object() # ironpython: default value for dict.get
2930

3031
def _make_relax_case():
3132
if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS):
@@ -358,18 +359,6 @@ def _get_sourcefile(bytecode_path):
358359
return source_path if _path_isfile(source_path) else bytecode_path
359360

360361

361-
def _get_cached(filename):
362-
if filename.endswith(tuple(SOURCE_SUFFIXES)):
363-
try:
364-
return cache_from_source(filename)
365-
except NotImplementedError:
366-
pass
367-
elif filename.endswith(tuple(BYTECODE_SUFFIXES)):
368-
return filename
369-
else:
370-
return None
371-
372-
373362
def _calc_mode(path):
374363
"""Calculate the mode permissions for a bytecode file."""
375364
try:
@@ -749,46 +738,9 @@ def get_code(self, fullname):
749738
"""
750739
source_path = self.get_filename(fullname)
751740
source_mtime = None
752-
try:
753-
bytecode_path = cache_from_source(source_path)
754-
except NotImplementedError:
755-
bytecode_path = None
756-
else:
757-
try:
758-
st = self.path_stats(source_path)
759-
except IOError:
760-
pass
761-
else:
762-
source_mtime = int(st['mtime'])
763-
try:
764-
data = self.get_data(bytecode_path)
765-
except OSError:
766-
pass
767-
else:
768-
try:
769-
bytes_data = _validate_bytecode_header(data,
770-
source_stats=st, name=fullname,
771-
path=bytecode_path)
772-
except (ImportError, EOFError):
773-
pass
774-
else:
775-
_bootstrap._verbose_message('{} matches {}', bytecode_path,
776-
source_path)
777-
return _compile_bytecode(bytes_data, name=fullname,
778-
bytecode_path=bytecode_path,
779-
source_path=source_path)
780741
source_bytes = self.get_data(source_path)
781742
code_object = self.source_to_code(source_bytes, source_path)
782743
_bootstrap._verbose_message('code object from {}', source_path)
783-
if (not sys.dont_write_bytecode and bytecode_path is not None and
784-
source_mtime is not None):
785-
data = _code_to_bytecode(code_object, source_mtime,
786-
len(source_bytes))
787-
try:
788-
self._cache_bytecode(source_path, bytecode_path, data)
789-
_bootstrap._verbose_message('wrote {!r}', bytecode_path)
790-
except NotImplementedError:
791-
pass
792744
return code_object
793745

794746

@@ -1092,9 +1044,9 @@ def _path_importer_cache(cls, path):
10921044
# Don't cache the failure as the cwd can easily change to
10931045
# a valid directory later on.
10941046
return None
1095-
try:
1096-
finder = sys.path_importer_cache[path]
1097-
except KeyError:
1047+
# ironpython: optimization to avoid KeyError exception
1048+
finder = sys.path_importer_cache.get(path, _unspecified)
1049+
if finder is _unspecified:
10981050
finder = cls._path_hooks(path)
10991051
sys.path_importer_cache[path] = finder
11001052
return finder
@@ -1361,10 +1313,8 @@ def _get_supported_file_loaders():
13611313
13621314
Each item is a tuple (loader, suffixes).
13631315
"""
1364-
extensions = ExtensionFileLoader, _imp.extension_suffixes()
13651316
source = SourceFileLoader, SOURCE_SUFFIXES
1366-
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
1367-
return [extensions, source, bytecode]
1317+
return [source]
13681318

13691319

13701320
def _setup(_bootstrap_module):
@@ -1390,6 +1340,7 @@ def _setup(_bootstrap_module):
13901340

13911341
# Directly load the os module (needed during bootstrap).
13921342
os_details = ('posix', ['/']), ('nt', ['\\', '/'])
1343+
if sys.platform == 'win32': os_details = reversed(os_details) # ironpython: optimization to avoid ImportError exception
13931344
for builtin_os, path_separators in os_details:
13941345
# Assumption made in _path_join()
13951346
assert all(len(sep) == 1 for sep in path_separators)
@@ -1421,18 +1372,9 @@ def _setup(_bootstrap_module):
14211372
weakref_module = _bootstrap._builtin_from_name('_weakref')
14221373
setattr(self_module, '_weakref', weakref_module)
14231374

1424-
# Directly load the winreg module (needed during bootstrap).
1425-
if builtin_os == 'nt':
1426-
winreg_module = _bootstrap._builtin_from_name('winreg')
1427-
setattr(self_module, '_winreg', winreg_module)
1428-
14291375
# Constants
14301376
setattr(self_module, '_relax_case', _make_relax_case())
14311377
EXTENSION_SUFFIXES.extend(_imp.extension_suffixes())
1432-
if builtin_os == 'nt':
1433-
SOURCE_SUFFIXES.append('.pyw')
1434-
if '_d.pyd' in EXTENSION_SUFFIXES:
1435-
WindowsRegistryFinder.DEBUG_BUILD = True
14361378

14371379

14381380
def _install(_bootstrap_module):

Tests/test_ordered_dict_stdlib.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## Run selected tests from test_ordered_dict from StdLib
77
##
88

9-
from iptest import is_ironpython, generate_suite, run_test
9+
from iptest import is_ironpython, generate_suite, run_test, is_mono
1010

1111
import test.test_ordered_dict
1212

@@ -54,6 +54,13 @@ def load_tests(loader, standard_tests, pattern):
5454
test.test_ordered_dict.PurePythonOrderedDictSubclassTests('test_highly_nested_subclass'), # intermittent AssertionError - GC related?
5555
test.test_ordered_dict.PurePythonOrderedDictTests('test_highly_nested_subclass'), # intermittent AssertionError - GC related?
5656
]
57+
if is_mono: # maybe https://github.com/IronLanguages/ironpython3/issues/544
58+
skip_tests += [
59+
test.test_ordered_dict.PurePythonOrderedDictSubclassTests('test_reference_loop'),
60+
test.test_ordered_dict.PurePythonOrderedDictTests('test_reference_loop'),
61+
test.test_ordered_dict.CPythonOrderedDictSubclassTests('test_reference_loop'),
62+
test.test_ordered_dict.CPythonOrderedDictTests('test_reference_loop'),
63+
]
5764

5865
return generate_suite(tests, failing_tests, skip_tests)
5966

0 commit comments

Comments
 (0)