Skip to content

Commit 6e97420

Browse files
committed
[GR-13396] fix code constructor
PullRequest: graalpython/362
2 parents 28c3d5e + 14cf874 commit 6e97420

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

graalpython/com.oracle.graal.python.cext/src/codeobject.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -52,7 +52,6 @@ PyCodeObject* PyCode_New(int argcount, int kwonlyargcount,
5252
return UPCALL_CEXT_O(_jls_PyCode_New, argcount, kwonlyargcount,
5353
nlocals, stacksize, flags,
5454
native_to_java(code), native_to_java(consts), native_to_java(names),
55-
native_to_java(varnames), native_to_java(freevars), native_to_java(cellvars),
56-
native_to_java(filename), native_to_java(name), firstlineno,
57-
native_to_java(lnotab));
55+
native_to_java(varnames), native_to_java(filename), native_to_java(name), firstlineno,
56+
native_to_java(lnotab), native_to_java(freevars), native_to_java(cellvars));
5857
}

graalpython/com.oracle.graal.python.test/src/tests/test_code.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -95,3 +95,41 @@ def test_code_attributes():
9595
# assert code.co_lnotab == b'\x00\x01\x0c\x01\x0c\x01\x06\x02\x15\x03\x03\x01\x0e\x01\r\x01\x05\x02'
9696
assert set(code.co_freevars) == {'values'}
9797
assert set(code.co_cellvars) == {'kwarg_other', 'loc_2'}
98+
99+
100+
def test_code_copy():
101+
import types
102+
103+
code = wrapper().__code__
104+
code2 = types.CodeType(
105+
code.co_argcount,
106+
code.co_kwonlyargcount,
107+
code.co_nlocals,
108+
code.co_stacksize,
109+
code.co_flags,
110+
code.co_code,
111+
code.co_consts,
112+
code.co_names,
113+
code.co_varnames,
114+
code.co_filename,
115+
code.co_name,
116+
code.co_firstlineno,
117+
code.co_lnotab,
118+
code.co_freevars,
119+
code.co_cellvars)
120+
121+
assert code.co_argcount == code2.co_argcount
122+
assert code.co_kwonlyargcount == code2.co_kwonlyargcount
123+
assert code.co_nlocals == code2.co_nlocals
124+
assert code.co_stacksize == code2.co_stacksize
125+
assert code.co_flags == code2.co_flags
126+
assert code.co_code == code2.co_code
127+
assert code.co_consts == code2.co_consts
128+
assert set(code.co_names) == set(code2.co_names)
129+
assert set(code.co_varnames) == set(code2.co_varnames)
130+
assert code.co_filename == code2.co_filename
131+
assert code.co_name == code2.co_name
132+
assert code.co_firstlineno == code2.co_firstlineno
133+
assert code.co_lnotab == code2.co_lnotab
134+
assert set(code.co_freevars) == set(code2.co_freevars)
135+
assert set(code.co_cellvars) == set(code2.co_cellvars)

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,9 @@ public abstract static class CodeTypeNode extends PythonBuiltinNode {
23412341
Object call(PythonClass cls, int argcount, int kwonlyargcount,
23422342
int nlocals, int stacksize, int flags,
23432343
String codestring, PTuple constants, PTuple names,
2344-
PTuple varnames, PTuple freevars, PTuple cellvars,
2345-
Object filename, Object name, int firstlineno,
2346-
String lnotab) {
2344+
PTuple varnames, Object filename, Object name,
2345+
int firstlineno, String lnotab,
2346+
PTuple freevars, PTuple cellvars) {
23472347
return factory().createCode(cls, argcount, kwonlyargcount,
23482348
nlocals, stacksize, flags,
23492349
toBytes(codestring), constants.getArray(), names.getArray(),
@@ -2356,9 +2356,9 @@ Object call(PythonClass cls, int argcount, int kwonlyargcount,
23562356
Object call(PythonClass cls, int argcount, int kwonlyargcount,
23572357
int nlocals, int stacksize, int flags,
23582358
PBytes codestring, PTuple constants, PTuple names,
2359-
PTuple varnames, PTuple freevars, PTuple cellvars,
2360-
Object filename, Object name, int firstlineno,
2361-
PBytes lnotab,
2359+
PTuple varnames, Object filename, Object name,
2360+
int firstlineno, PBytes lnotab,
2361+
PTuple freevars, PTuple cellvars,
23622362
@Cached("create()") SequenceStorageNodes.ToByteArrayNode toByteArrayNode) {
23632363
byte[] codeBytes = toByteArrayNode.execute(codestring.getSequenceStorage());
23642364
byte[] lnotabBytes = toByteArrayNode.execute(lnotab.getSequenceStorage());
@@ -2376,9 +2376,9 @@ Object call(PythonClass cls, int argcount, int kwonlyargcount,
23762376
Object call(Object cls, Object argcount, Object kwonlyargcount,
23772377
Object nlocals, Object stacksize, Object flags,
23782378
Object codestring, Object constants, Object names,
2379-
Object varnames, Object freevars, Object cellvars,
2380-
Object filename, Object name, Object firstlineno,
2381-
Object lnotab) {
2379+
Object varnames, Object filename, Object name,
2380+
Object firstlineno, Object lnotab,
2381+
Object freevars, Object cellvars) {
23822382
throw raise(SystemError, "bad argument to internal function");
23832383
}
23842384

0 commit comments

Comments
 (0)