File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed
com.oracle.graal.python.test/src/tests
com.oracle.graal.python/src/com/oracle/graal/python/builtins Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change 37
37
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
38
# SOFTWARE.
39
39
40
- from posix import *
41
40
import sys
41
+ from posix import *
42
+
42
43
sys .path .append (sys ._getframe ().f_code .co_filename .rpartition ("/" )[0 ])
43
44
44
45
def test_relative_import ():
45
- import package
46
+ pass
46
47
47
48
48
49
def test_dotted_import ():
49
- import package . moduleY
50
+ pass
50
51
51
52
52
53
def test_recursive_import ():
53
- import package . moduleRecursive
54
+ pass
54
55
55
56
56
57
def test_recursive_import2 ():
57
- import package . moduleRecursive2
58
+ pass
58
59
59
60
60
61
def test_import_star_has_to_be_module ():
@@ -91,3 +92,15 @@ def test_import_error():
91
92
def test_import_some_star ():
92
93
import posix
93
94
assert stat == posix .stat
95
+
96
+
97
+ def test_imp_fix_co_filename ():
98
+ import _imp
99
+
100
+ def func (x ):
101
+ return x + x
102
+
103
+ code = func .__code__
104
+ old_name = code .co_filename
105
+ _imp ._fix_co_filename (code , old_name + '_more_path' )
106
+ assert code .co_filename == old_name + '_more_path'
Original file line number Diff line number Diff line change 57
57
import com .oracle .graal .python .builtins .modules .TruffleCextBuiltins .CheckFunctionResultNode ;
58
58
import com .oracle .graal .python .builtins .objects .PNone ;
59
59
import com .oracle .graal .python .builtins .objects .cext .CExtNodes .AsPythonObjectNode ;
60
+ import com .oracle .graal .python .builtins .objects .code .PCode ;
60
61
import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes .SetItemNode ;
61
62
import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes ;
62
63
import com .oracle .graal .python .builtins .objects .dict .PDict ;
69
70
import com .oracle .graal .python .nodes .call .special .CallUnaryMethodNode ;
70
71
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
71
72
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
73
+ import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
72
74
import com .oracle .graal .python .runtime .PythonContext ;
73
75
import com .oracle .graal .python .runtime .PythonCore ;
74
76
import com .oracle .graal .python .runtime .PythonOptions ;
@@ -385,4 +387,19 @@ public Object run(String path, PythonModule mod) {
385
387
}
386
388
}
387
389
390
+ @ Builtin (name = "_fix_co_filename" , fixedNumOfPositionalArgs = 2 )
391
+ @ GenerateNodeFactory
392
+ public abstract static class FixCoFilename extends PythonBinaryBuiltinNode {
393
+ @ Specialization
394
+ public Object run (PCode code , PString path ) {
395
+ code .setFilename (path .getValue ());
396
+ return PNone .NONE ;
397
+ }
398
+
399
+ @ Specialization
400
+ public Object run (PCode code , String path ) {
401
+ code .setFilename (path );
402
+ return PNone .NONE ;
403
+ }
404
+ }
388
405
}
Original file line number Diff line number Diff line change @@ -313,6 +313,10 @@ public Object[] getCellVars() {
313
313
return cellvars ;
314
314
}
315
315
316
+ public void setFilename (String filename ) {
317
+ this .filename = filename ;
318
+ }
319
+
316
320
public String getFilename () {
317
321
if (filename == null && rootNode != null ) {
318
322
filename = extractFileName (rootNode );
You can’t perform that action at this time.
0 commit comments