Skip to content

Commit a0a6d68

Browse files
committed
[GR-31036][GR-9149] Reduce diff with CPython
PullRequest: graalpython/1778
2 parents 7507f10 + 7a4d757 commit a0a6d68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+200
-265
lines changed

graalpython/com.oracle.graal.python.test/src/graalpytest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
# test_import tests various behaviors related to __pycache__ directory,
5858
# it can interfere with other tests that generate code
5959
'test_import',
60+
'test_subprocess',
61+
'test_posix',
6062
]
6163

6264

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_call.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,3 @@
6262
*graalpython.lib-python.3.test.test_call.FastCallTests.test_vectorcall
6363
*graalpython.lib-python.3.test.test_call.FastCallTests.test_vectorcall_dict
6464
*graalpython.lib-python.3.test.test_call.FunctionCalls.test_kwargs_order
65-
*graalpython.lib-python.3.test.test_call.TestPEP590.test_method_descriptor_flag
66-
*graalpython.lib-python.3.test.test_call.TestPEP590.test_vectorcall
67-
*graalpython.lib-python.3.test.test_call.TestPEP590.test_vectorcall_flag
68-
*graalpython.lib-python.3.test.test_call.TestPEP590.test_vectorcall_override

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_importlib.txt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@
629629
*test.test_importlib.test_abc.Frozen_InspectLoader.test_subclasses
630630
*test.test_importlib.test_abc.Frozen_InspectLoader.test_superclasses
631631
*test.test_importlib.test_abc.Frozen_InspectLoaderDefaultsTests.test_get_source
632+
*test.test_importlib.test_abc.Frozen_InspectLoaderDefaultsTests.test_get_source
633+
*test.test_importlib.test_abc.Frozen_InspectLoaderDefaultsTests.test_is_package
632634
*test.test_importlib.test_abc.Frozen_InspectLoaderDefaultsTests.test_is_package
633635
*test.test_importlib.test_abc.Frozen_InspectLoaderGetCodeTests.test_get_code
634636
*test.test_importlib.test_abc.Frozen_InspectLoaderGetCodeTests.test_get_code_source_is_None
@@ -695,6 +697,8 @@
695697
*test.test_importlib.test_abc.Source_InspectLoader.test_subclasses
696698
*test.test_importlib.test_abc.Source_InspectLoader.test_superclasses
697699
*test.test_importlib.test_abc.Source_InspectLoaderDefaultsTests.test_get_source
700+
*test.test_importlib.test_abc.Source_InspectLoaderDefaultsTests.test_get_source
701+
*test.test_importlib.test_abc.Source_InspectLoaderDefaultsTests.test_is_package
698702
*test.test_importlib.test_abc.Source_InspectLoaderDefaultsTests.test_is_package
699703
*test.test_importlib.test_abc.Source_InspectLoaderGetCodeTests.test_get_code
700704
*test.test_importlib.test_abc.Source_InspectLoaderGetCodeTests.test_get_code_source_is_None
@@ -825,11 +829,32 @@
825829
*test.test_importlib.test_lazy.LazyLoaderTests.test_mutated_attr
826830
*test.test_importlib.test_lazy.LazyLoaderTests.test_mutated_preexisting_attr
827831
*test.test_importlib.test_lazy.LazyLoaderTests.test_new_attr
828-
*test.test_importlib.test_locks.Frozen_LifetimeTests.test_all_locks
829-
*test.test_importlib.test_locks.Frozen_LifetimeTests.test_lock_lifetime
832+
*test.test_importlib.test_locks.Frozen_DeadlockAvoidanceTests.test_deadlock
833+
*test.test_importlib.test_locks.Frozen_DeadlockAvoidanceTests.test_no_deadlock
834+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_acquire_contended
835+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_acquire_destroy
836+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_acquire_release
837+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_constructor
838+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_different_thread
839+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_reacquire
840+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_release_unacquired
841+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_thread_leak
842+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_weakref_deleted
843+
*test.test_importlib.test_locks.Frozen_ModuleLockAsRLockTests.test_weakref_exists
844+
*test.test_importlib.test_locks.Source_DeadlockAvoidanceTests.test_deadlock
845+
*test.test_importlib.test_locks.Source_DeadlockAvoidanceTests.test_no_deadlock
830846
*test.test_importlib.test_locks.Source_LifetimeTests.test_all_locks
831847
*test.test_importlib.test_locks.Source_LifetimeTests.test_lock_lifetime
832-
*test.test_importlib.test_locks.TestMain.test_main
848+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_acquire_contended
849+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_acquire_destroy
850+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_acquire_release
851+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_constructor
852+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_different_thread
853+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_reacquire
854+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_release_unacquired
855+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_thread_leak
856+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_weakref_deleted
857+
*test.test_importlib.test_locks.Source_ModuleLockAsRLockTests.test_weakref_exists
833858
*test.test_importlib.test_main.BasicTests.test_for_name_does_not_exist
834859
*test.test_importlib.test_main.BasicTests.test_new_style_classes
835860
*test.test_importlib.test_main.BasicTests.test_retrieves_version_of_self

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,12 @@ long doPointer(PInt n,
21812181
return n.longValueExact();
21822182
} catch (OverflowException e) {
21832183
overflowProfile.enter();
2184-
throw raise(OverflowError);
2184+
try {
2185+
throw raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
2186+
} catch (PException pe) {
2187+
ensureTransformExcNode().execute(pe);
2188+
return 0;
2189+
}
21852190
}
21862191
}
21872192

@@ -2197,12 +2202,14 @@ long doGeneric(Object n) {
21972202
asPrimitiveNode = insert(ConvertPIntToPrimitiveNodeGen.create());
21982203
}
21992204
try {
2200-
return asPrimitiveNode.executeLong(n, 0, Long.BYTES);
2201-
} catch (UnexpectedResultException e) {
2202-
throw CompilerDirectives.shouldNotReachHere();
2205+
try {
2206+
return asPrimitiveNode.executeLong(n, 0, Long.BYTES);
2207+
} catch (UnexpectedResultException e) {
2208+
throw raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
2209+
}
22032210
} catch (PException e) {
22042211
ensureTransformExcNode().execute(e);
2205-
return -1;
2212+
return 0;
22062213
}
22072214
}
22082215

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,12 @@ Object repr(VirtualFrame frame, PBuffered self,
389389
if (!getContext().reprEnter(self)) {
390390
throw raise(RuntimeError, "reentrant call inside %s.__repr__", clazz);
391391
} else {
392-
Object name = repr.executeObject(frame, nameobj);
393-
getContext().reprLeave(self);
394-
return PythonUtils.format("<%s name=%s>", clazz, name);
392+
try {
393+
Object name = repr.executeObject(frame, nameobj);
394+
return PythonUtils.format("<%s name=%s>", clazz, name);
395+
} finally {
396+
getContext().reprLeave(self);
397+
}
395398
}
396399
}
397400
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,9 +1025,12 @@ Object doit(VirtualFrame frame, PFileIO self,
10251025
if (!getContext().reprEnter(self)) {
10261026
throw raise(RuntimeError, "reentrant call inside %p.__repr__", self);
10271027
} else {
1028-
Object name = repr.executeObject(frame, nameobj);
1029-
getContext().reprLeave(self);
1030-
return PythonUtils.format("<_io.FileIO name=%s mode='%s' closefd=%s>", name, mode, closefd);
1028+
try {
1029+
Object name = repr.executeObject(frame, nameobj);
1030+
return PythonUtils.format("<_io.FileIO name=%s mode='%s' closefd=%s>", name, mode, closefd);
1031+
} finally {
1032+
getContext().reprLeave(self);
1033+
}
10311034
}
10321035
}
10331036
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,9 +1148,9 @@ Object doit(VirtualFrame frame, PTextIO self,
11481148
if (!getContext().reprEnter(self)) {
11491149
throw raise(RuntimeError, "reentrant call inside %p.__repr__", self);
11501150
} else {
1151-
StringBuilder sb = PythonUtils.newStringBuilder();
1152-
PythonUtils.append(sb, "<_io.TextIOWrapper");
11531151
try {
1152+
StringBuilder sb = PythonUtils.newStringBuilder();
1153+
PythonUtils.append(sb, "<_io.TextIOWrapper");
11541154
Object nameobj = PNone.NO_VALUE;
11551155
try {
11561156
nameobj = libSelf.lookupAttributeStrict(self, frame, NAME);
@@ -1167,11 +1167,9 @@ Object doit(VirtualFrame frame, PTextIO self,
11671167
PythonUtils.append(sb, PythonUtils.format(" mode='%s'", toString.execute(modeobj)));
11681168
}
11691169
PythonUtils.append(sb, PythonUtils.format(" encoding='%s'>", self.getEncoding()));
1170-
getContext().reprLeave(self);
11711170
return PythonUtils.sbToString(sb);
1172-
} catch (PException e) {
1171+
} finally {
11731172
getContext().reprLeave(self);
1174-
throw e;
11751173
}
11761174
}
11771175
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictReprBuiltin.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,15 @@ public static Object repr(PDict dict,
235235
if (!ctxt.reprEnter(dict)) {
236236
return "{...}";
237237
}
238-
StringBuilder sb = PythonUtils.newStringBuilder("{");
239-
HashingStorage dictStorage = dict.getDictStorage();
240-
lib.forEach(dictStorage, consumerNode, new ReprState(dict, dictStorage, sb));
241-
PythonUtils.append(sb, "}");
242-
ctxt.reprLeave(dict);
243-
return PythonUtils.sbToString(sb);
238+
try {
239+
StringBuilder sb = PythonUtils.newStringBuilder("{");
240+
HashingStorage dictStorage = dict.getDictStorage();
241+
lib.forEach(dictStorage, consumerNode, new ReprState(dict, dictStorage, sb));
242+
PythonUtils.append(sb, "}");
243+
return PythonUtils.sbToString(sb);
244+
} finally {
245+
ctxt.reprLeave(dict);
246+
}
244247
}
245248

246249
@Specialization// use same limit as for EachRepr nodes library

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,31 +172,33 @@ public Object repr(VirtualFrame frame, PList self,
172172
if (!ctxt.reprEnter(self)) {
173173
return "[...]";
174174
}
175-
176-
StringBuilder result = PythonUtils.newStringBuilder();
177-
PythonUtils.append(result, "[");
178-
boolean initial = true;
179-
Object value;
180-
Object reprString;
181-
for (int index = 0; index < length; index++) {
182-
value = getItem.execute(frame, storage, index);
183-
reprString = repr.executeObject(frame, value);
184-
if (reprString instanceof PString) {
185-
reprString = ((PString) reprString).getValue();
186-
}
187-
if (reprString instanceof String) {
188-
if (initial) {
189-
initial = false;
175+
try {
176+
StringBuilder result = PythonUtils.newStringBuilder();
177+
PythonUtils.append(result, "[");
178+
boolean initial = true;
179+
Object value;
180+
Object reprString;
181+
for (int index = 0; index < length; index++) {
182+
value = getItem.execute(frame, storage, index);
183+
reprString = repr.executeObject(frame, value);
184+
if (reprString instanceof PString) {
185+
reprString = ((PString) reprString).getValue();
186+
}
187+
if (reprString instanceof String) {
188+
if (initial) {
189+
initial = false;
190+
} else {
191+
PythonUtils.append(result, ", ");
192+
}
193+
PythonUtils.append(result, (String) reprString);
190194
} else {
191-
PythonUtils.append(result, ", ");
195+
raise(PythonErrorType.TypeError, ErrorMessages.RETURNED_NON_STRING, "__repr__", reprString);
192196
}
193-
PythonUtils.append(result, (String) reprString);
194-
} else {
195-
raise(PythonErrorType.TypeError, ErrorMessages.RETURNED_NON_STRING, "__repr__", reprString);
196197
}
198+
return PythonUtils.sbToString(PythonUtils.append(result, "]"));
199+
} finally {
200+
ctxt.reprLeave(self);
197201
}
198-
ctxt.reprLeave(self);
199-
return PythonUtils.sbToString(PythonUtils.append(result, "]"));
200202
}
201203
}
202204

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/BaseSetBuiltins.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.util.Iterator;
5656
import java.util.List;
5757

58+
import com.oracle.graal.python.PythonLanguage;
5859
import com.oracle.graal.python.builtins.Builtin;
5960
import com.oracle.graal.python.builtins.CoreFunctions;
6061
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -79,10 +80,12 @@
7980
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
8081
import com.oracle.graal.python.nodes.object.GetClassNode;
8182
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
83+
import com.oracle.graal.python.runtime.PythonContext;
8284
import com.oracle.graal.python.runtime.exception.PException;
8385
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
8486
import com.oracle.graal.python.util.PythonUtils;
8587
import com.oracle.truffle.api.dsl.Cached;
88+
import com.oracle.truffle.api.dsl.CachedContext;
8689
import com.oracle.truffle.api.dsl.Fallback;
8790
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8891
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -123,27 +126,39 @@ private static void fillItems(VirtualFrame frame, StringBuilder sb, LookupAndCal
123126

124127
@Specialization(limit = "3")
125128
public static Object repr(VirtualFrame frame, PBaseSet self,
126-
@Cached IsBuiltinClassProfile isBuiltinClass,
129+
@CachedContext(PythonLanguage.class) PythonContext ctxt,
127130
@Cached("create(__REPR__)") LookupAndCallUnaryNode repr,
128131
@Cached TypeNodes.GetNameNode getNameNode,
129132
@Cached GetClassNode getClassNode,
130133
@CachedLibrary("self.getDictStorage()") HashingStorageLibrary hlib) {
131134
StringBuilder sb = PythonUtils.newStringBuilder();
132-
int len = hlib.length(self.getDictStorage());
133-
HashingStorageLibrary.HashingStorageIterator<Object> iter = hlib.keys(self.getDictStorage()).iterator();
134135
Object clazz = getClassNode.execute(self);
135-
if (len > 0 && clazz == PythonBuiltinClassType.PSet && isBuiltinClass.profileIsAnyBuiltinClass(clazz)) {
136-
fillItems(frame, sb, repr, iter);
136+
int len = hlib.length(self.getDictStorage());
137+
if (len == 0) {
138+
PythonUtils.append(sb, getNameNode.execute(clazz));
139+
PythonUtils.append(sb, "()");
140+
return PythonUtils.sbToString(sb);
141+
}
142+
if (!ctxt.reprEnter(self)) {
143+
PythonUtils.append(sb, getNameNode.execute(clazz));
144+
PythonUtils.append(sb, "(...)");
137145
return PythonUtils.sbToString(sb);
138146
}
139-
String typeName = getNameNode.execute(clazz);
140-
PythonUtils.append(sb, typeName);
141-
PythonUtils.append(sb, "(");
142-
if (len > 0) {
147+
try {
148+
HashingStorageLibrary.HashingStorageIterator<Object> iter = hlib.keys(self.getDictStorage()).iterator();
149+
boolean showType = clazz != PythonBuiltinClassType.PSet;
150+
if (showType) {
151+
PythonUtils.append(sb, getNameNode.execute(clazz));
152+
PythonUtils.append(sb, '(');
153+
}
143154
fillItems(frame, sb, repr, iter);
155+
if (showType) {
156+
PythonUtils.append(sb, ')');
157+
}
158+
return PythonUtils.sbToString(sb);
159+
} finally {
160+
ctxt.reprLeave(self);
144161
}
145-
PythonUtils.append(sb, ")");
146-
return PythonUtils.sbToString(sb);
147162
}
148163
}
149164

0 commit comments

Comments
 (0)