Skip to content

[mypyc] Simplify argument parsing in legacy wrapper functions #10234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f5f1e18
Remove some error checks to speed things up
JukkaL Dec 2, 2020
e38916e
Remove some format string checks
JukkaL Dec 2, 2020
ee6b96c
Remove support for most format string specifiers
JukkaL Dec 2, 2020
3bca905
Remove support for more unsupported format string features
JukkaL Dec 2, 2020
4117778
Get rid of unused stuff
JukkaL Dec 2, 2020
8191fbf
Fix issue
JukkaL Dec 2, 2020
60ff835
Remove unused code
JukkaL Dec 2, 2020
e63b082
Remove support for tuples
JukkaL Dec 2, 2020
e40bbe2
Minor simplification
JukkaL Dec 2, 2020
a7825d2
Remove unused code
JukkaL Dec 2, 2020
5aa1b7f
Remove unused code
JukkaL Dec 2, 2020
8116d8f
Minor simplification
JukkaL Dec 2, 2020
54d037c
Add some likely() and unlikely()
JukkaL Dec 2, 2020
950aa2a
Remove unused definitions
JukkaL Dec 2, 2020
cb8a44a
Minor optimization
JukkaL Dec 2, 2020
e3f2564
Minor simplification
JukkaL Dec 2, 2020
13dee40
Remove unused variable
JukkaL Dec 2, 2020
481bcc4
Remove unused arg + update comment
JukkaL Dec 4, 2020
d220b76
Remove unused code
JukkaL Dec 4, 2020
4aa2b0d
Simplify some more
JukkaL Dec 4, 2020
c9ab82a
Update comment
JukkaL Dec 5, 2020
a846967
Refactor a bit
JukkaL Dec 5, 2020
09edc8f
Remove cleanreturn as unnecessary
JukkaL Dec 5, 2020
1748fb5
Remove freelist handling as unnecessary
JukkaL Dec 5, 2020
f29b9d5
Pass function name as a separate argument
JukkaL Dec 5, 2020
1d7d13b
Remove unused defines
JukkaL Dec 5, 2020
667e1d7
Remove unnecessary check
JukkaL Dec 5, 2020
67d3065
Remove unused variable
JukkaL Dec 5, 2020
8d0dcea
Update comment
JukkaL Mar 21, 2021
d2801b1
Fix passing function name
JukkaL Mar 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions mypyc/codegen/emitwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def make_static_kwlist(args: List[RuntimeArg]) -> str:
return 'static const char * const kwlist[] = {{{}0}};'.format(arg_names)


def make_format_string(func_name: str, groups: List[List[RuntimeArg]]) -> str:
def make_format_string(func_name: Optional[str], groups: List[List[RuntimeArg]]) -> str:
"""Return a format string that specifies the accepted arguments.

The format string is an extended subset of what is supported by
Expand All @@ -103,17 +103,19 @@ def make_format_string(func_name: str, groups: List[List[RuntimeArg]]) -> str:

These are used by both vectorcall and legacy wrapper functions.
"""
main_format = ''
format = ''
if groups[ARG_STAR] or groups[ARG_STAR2]:
main_format += '%'
main_format += 'O' * len(groups[ARG_POS])
format += '%'
format += 'O' * len(groups[ARG_POS])
if groups[ARG_OPT] or groups[ARG_NAMED_OPT] or groups[ARG_NAMED]:
main_format += '|' + 'O' * len(groups[ARG_OPT])
format += '|' + 'O' * len(groups[ARG_OPT])
if groups[ARG_NAMED_OPT] or groups[ARG_NAMED]:
main_format += '$' + 'O' * len(groups[ARG_NAMED_OPT])
format += '$' + 'O' * len(groups[ARG_NAMED_OPT])
if groups[ARG_NAMED]:
main_format += '@' + 'O' * len(groups[ARG_NAMED])
return '{}:{}'.format(main_format, func_name)
format += '@' + 'O' * len(groups[ARG_NAMED])
if func_name is not None:
format += ':{}'.format(func_name)
return format


def generate_wrapper_function(fn: FuncIR,
Expand Down Expand Up @@ -237,8 +239,8 @@ def generate_legacy_wrapper_function(fn: FuncIR,
arg_ptrs += ['&obj_{}'.format(arg.name) for arg in reordered_args]

emitter.emit_lines(
'if (!CPyArg_ParseTupleAndKeywords(args, kw, "{}", kwlist{})) {{'.format(
make_format_string(fn.name, groups), ''.join(', ' + n for n in arg_ptrs)),
'if (!CPyArg_ParseTupleAndKeywords(args, kw, "{}", "{}", kwlist{})) {{'.format(
make_format_string(None, groups), fn.name, ''.join(', ' + n for n in arg_ptrs)),
'return NULL;',
'}')
traceback_code = generate_traceback_code(fn, emitter, source_path, module_name)
Expand Down
3 changes: 1 addition & 2 deletions mypyc/lib-rt/CPy.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ CPyTagged CPyTagged_Id(PyObject *o);
void CPyDebug_Print(const char *msg);
void CPy_Init(void);
int CPyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
const char *, const char * const *, ...);
const char *, const char *, const char * const *, ...);
int CPyArg_ParseStackAndKeywords(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames,
CPyArg_Parser *parser, ...);
int CPyArg_ParseStackAndKeywordsNoArgs(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames,
Expand All @@ -534,7 +534,6 @@ int CPyStatics_Initialize(PyObject **statics,
const double *complex_numbers,
const int *tuples);


#ifdef __cplusplus
}
#endif
Expand Down
Loading