Skip to content

Commit 199ae78

Browse files
committed
new idea
1 parent a802c16 commit 199ae78

File tree

3 files changed

+0
-35
lines changed

3 files changed

+0
-35
lines changed

mypyc/codegen/emitmodule.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -990,22 +990,6 @@ def emit_module_exec_func(
990990
emitter.emit_lines(f"if (unlikely(!{type_struct}))", " goto fail;")
991991

992992
emitter.emit_lines("if (CPyGlobalsInit() < 0)", " goto fail;")
993-
# Patch async native functions so they're recognized as coroutines
994-
for fn in module.functions:
995-
if fn.decl.is_async and fn.class_name is None:
996-
temp_name = f"{fn.fullname.replace('.', '__')}_temp"
997-
emitter.emit_line(
998-
f'PyObject *{temp_name} = PyObject_GetAttrString({module_static}, "{fn.decl.name}");'
999-
)
1000-
emitter.emit_line(f"if (!{temp_name}) goto fail;")
1001-
emitter.emit_line(
1002-
"if (!CPyFunc_SetCoroFlag("
1003-
+ temp_name
1004-
+ ")) { Py_DECREF("
1005-
+ temp_name
1006-
+ "); goto fail; }"
1007-
)
1008-
emitter.emit_line(f"Py_DECREF({temp_name});")
1009993

1010994
self.generate_top_level_call(module, emitter)
1011995

mypyc/lib-rt/pythonsupport.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,4 @@ CPyLong_AsSsize_tAndOverflow_(PyObject *vv, int *overflow)
103103
}
104104

105105

106-
// CPy support for async functions: patch code object to include CO_COROUTINE
107-
PyObject* CPyFunc_SetCoroFlag(PyObject* func) {
108-
PyObject* code = PyObject_GetAttrString(func, "__code__");
109-
if (!code) {
110-
return NULL;
111-
}
112-
PyCodeObject* codeobj = (PyCodeObject*)code;
113-
codeobj->co_flags |= CO_COROUTINE;
114-
int res = PyObject_SetAttrString(func, "__code__", code);
115-
Py_DECREF(code);
116-
if (res < 0) {
117-
return NULL;
118-
}
119-
Py_INCREF(func);
120-
return func;
121-
}
122106
#endif

mypyc/lib-rt/pythonsupport.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,5 @@ CPyCoro_GetAwaitableIter(PyObject *o)
474474
return NULL;
475475
}
476476

477-
static PyObject *
478-
CPyFunc_SetCoroFlag(PyObject* func);
479-
480477

481478
#endif

0 commit comments

Comments
 (0)