Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8f810d

Browse files
authored
Vendor in getargs.c from CPython (mypyc/mypyc#605)
Copy in a stripped-down version of getargs.c containing just `PyArg_ParseTupleAndKeywords` and its support code. The goal of this is that we will then extend getargs to support required kwonly args and *args/**kwargs.
1 parent 248ae51 commit c8f810d

7 files changed

Lines changed: 1591 additions & 8 deletions

File tree

LICENSE

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ DEALINGS IN THE SOFTWARE.
2626

2727
= = = = =
2828

29-
Portions of mypyc are licensed under different licenses. The file
30-
lib-rt/pythonsupport.h is licensed under the PSF 2 License, reproduced below.
29+
Portions of mypyc are licensed under different licenses. The files
30+
mypyc/lib-rt/pythonsupport.h and mypyc/lib-rt/getargs.c are licensed
31+
under the PSF 2 License, reproduced below.
3132

3233
= = = = =
3334

mypyc/build.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,10 @@ def mypycify(paths: List[str],
418418
]
419419

420420
# Copy the runtime library in
421-
rt_file = os.path.join(build_dir, 'CPy.c')
422-
shutil.copyfile(os.path.join(include_dir(), 'CPy.c'), rt_file)
423-
cfilenames.append(rt_file)
421+
for name in ['CPy.c', 'getargs.c']:
422+
rt_file = os.path.join(build_dir, name)
423+
shutil.copyfile(os.path.join(include_dir(), name), rt_file)
424+
cfilenames.append(rt_file)
424425

425426
if use_shared_lib:
426427
assert lib_name

mypyc/emitwrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def generate_wrapper_function(fn: FuncIR, emitter: Emitter) -> None:
4646
)
4747
arg_ptrs = ''.join(', &obj_{}'.format(arg.name) for arg in real_args)
4848
emitter.emit_lines(
49-
'if (!PyArg_ParseTupleAndKeywords(args, kw, "{}", kwlist{})) {{'.format(
49+
'if (!CPyArg_ParseTupleAndKeywords(args, kw, "{}", kwlist{})) {{'.format(
5050
arg_format, arg_ptrs),
5151
'return NULL;',
5252
'}')

mypyc/lib-rt/CPy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,8 @@ static int CPy_YieldFromErrorHandle(PyObject *iter, PyObject **outp)
11781178
return 2;
11791179
}
11801180

1181+
int CPyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
1182+
const char *, char **, ...);
11811183

11821184
#ifdef __cplusplus
11831185
}

0 commit comments

Comments
 (0)