Skip to content

Commit e1cf78f

Browse files
committed
Add PyCode_NewEmpty
1 parent 75c5f3a commit e1cf78f

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242

4343
PyTypeObject PyCode_Type = PY_TRUFFLE_TYPE("code", &PyType_Type, Py_TPFLAGS_DEFAULT, sizeof(PyTypeObject));
4444

45+
UPCALL_ID(PyCode_NewEmpty)
46+
PyCodeObject* PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) {
47+
return (PyCodeObject*)UPCALL_CEXT_O(_jls_PyCode_NewEmpty, polyglot_from_string(filename, SRC_CS), polyglot_from_string(funcname, SRC_CS), firstlineno);
48+
}
49+
4550
UPCALL_ID(PyCode_New);
4651
PyCodeObject* PyCode_New(int argcount, int kwonlyargcount,
4752
int nlocals, int stacksize, int flags,

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_codeobject.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ def compile_module(self, name):
6262

6363
testmod = type(sys)("foo")
6464

65+
test_PyCode_NewEmpty = CPyExtFunction(
66+
lambda args: args,
67+
lambda: (
68+
("file.c", "myfunc", 54),
69+
),
70+
resultspec="O",
71+
argspec="ssi",
72+
arguments=["char* filename", "char* funcname", "int firstlineno"],
73+
cmpfunc=lambda cr, pr: pr[0] == cr.co_filename and pr[1] == cr.co_name and pr[2] == cr.co_firstlineno,
74+
)
75+
6576
test_PyCode_New = CPyExtFunction(
6677
lambda args: args,
6778
lambda: (

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,17 +1540,28 @@ int tbHere(PFrame frame,
15401540
}
15411541
}
15421542

1543+
@Builtin(name = "PyCode_NewEmpty", minNumOfPositionalArgs = 3)
1544+
@GenerateNodeFactory
1545+
abstract static class PyCodeNewEmpty extends PythonTernaryBuiltinNode {
1546+
public abstract PCode execute(String filename, String funcname, int lineno);
1547+
1548+
@Specialization
1549+
static PCode newEmpty(String filename, String funcname, int lineno,
1550+
@Cached CodeNodes.CreateCodeNode createCodeNode) {
1551+
return createCodeNode.execute(null, 0, 0, 0, 0, 0, 0,
1552+
EMPTY_BYTE_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY,
1553+
filename, funcname, lineno, EMPTY_BYTE_ARRAY);
1554+
}
1555+
}
1556+
15431557
@Builtin(name = "_PyTraceback_Add", minNumOfPositionalArgs = 1)
15441558
@GenerateNodeFactory
15451559
abstract static class PyTracebackAdd extends PythonTernaryBuiltinNode {
15461560
@Specialization
15471561
Object tbHere(String funcname, String filename, int lineno,
1548-
@Cached CodeNodes.CreateCodeNode createCodeNode,
1562+
@Cached PyCodeNewEmpty newCode,
15491563
@Cached PyTraceBackHereNode pyTraceBackHereNode) {
1550-
PCode code = createCodeNode.execute(null, 0, 0, 0, 0, 0, 0,
1551-
EMPTY_BYTE_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY,
1552-
filename, funcname, lineno, EMPTY_BYTE_ARRAY);
1553-
PFrame frame = factory().createPFrame(null, code, factory().createDict(), factory().createDict());
1564+
PFrame frame = factory().createPFrame(null, newCode.execute(filename, funcname, lineno), factory().createDict(), factory().createDict());
15541565
pyTraceBackHereNode.execute(null, frame);
15551566
return PNone.NONE;
15561567
}

0 commit comments

Comments
 (0)