Skip to content

Commit

Permalink
[build] Filter methods from the newly found defs.
Browse files Browse the repository at this point in the history
cStringIO.c, readline.c, and resource.c

Fix a bug in PrettyPrint().

- ovm-opt.stripped is now 941 KB.
- there are now 2449 symbols according to metrics/native-code.sh.

All spec tests pass.
  • Loading branch information
Andy Chu committed Oct 24, 2018
1 parent d7fd2eb commit 6a78be5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build/cpython-defs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ show-oil() {
methods-audit() {
mkdir -p $METRICS_DIR
cat $BASE_DIR/preprocessed.txt | cpython-defs audit $PY_NAMES \
| grep $'\t\t' | tee _tmp/methods.txt
| tee _tmp/methods.txt

wc -l _tmp/methods.txt
}
Expand Down
16 changes: 8 additions & 8 deletions build/cpython_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ def out(msg, *args):
stats['num_filtered'] += 1
continue

# Reprint the definition, but omit the docstring.
out(' {"%s", ', entry_name)
# Strip off the docstring.
out(', '.join(vals[:-1]))
out(vals[0]) # The C function
out(', ')
out(vals[1]) # The flags
out('},\n')
out('};\n')

Expand Down Expand Up @@ -247,6 +249,7 @@ def out(msg, *args):

# "Data types"
#'boolobject.c', # No defs
'cStringIO.c',
'dictobject.c',
'fileobject.c',
'floatobject.c',
Expand All @@ -269,6 +272,8 @@ def out(msg, *args):
'fcntlmodule.c',
'posixmodule.c',
'pwdmodule.c',
'readline.c',
'resource.c',
'signalmodule.c',
'timemodule.c',
]
Expand Down Expand Up @@ -378,21 +383,16 @@ def main(argv):
files = p.ParseStream()
for rel_path, defs in files:
basename = os.path.basename(rel_path)
# We will implement a shim for set(), using dict.
if basename in ('libc.c', 'fastlex.c', 'setobject.c'):
continue

print(rel_path)
for def_name, entries in defs:
print('\t' + def_name)
for method_name, vals in entries:
if method_name is None:
continue
if method_name in ('__length_hint__',):
continue
if not method_filter(rel_path, def_name, method_name):
continue
print('\t\t' + method_name)
print('\t\t%s %s' % (method_name, vals))

elif action == 'filter': # for slimming the build down
out_dir = argv[3]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ static PyMethodDef I_methods[] = {
{"isatty", (PyCFunction)IO_isatty, METH_NOARGS},
{"read", (PyCFunction)IO_read, METH_VARARGS},
{"readline", (PyCFunction)IO_readline, METH_VARARGS},
{"readlines", (PyCFunction)IO_readlines, METH_VARARGS},
{"reset", (PyCFunction)IO_reset, METH_NOARGS},
{"seek", (PyCFunction)IO_seek, METH_VARARGS},
{"tell", (PyCFunction)IO_tell, METH_NOARGS},
{"truncate", (PyCFunction)IO_truncate, METH_VARARGS},
{"close", (PyCFunction)I_close, METH_NOARGS},
{0},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ static PyMethodDef O_methods[] = {
{"isatty", (PyCFunction)IO_isatty, METH_NOARGS},
{"read", (PyCFunction)IO_read, METH_VARARGS},
{"readline", (PyCFunction)IO_readline, METH_VARARGS},
{"readlines", (PyCFunction)IO_readlines, METH_VARARGS},
{"reset", (PyCFunction)IO_reset, METH_NOARGS},
{"seek", (PyCFunction)IO_seek, METH_VARARGS},
{"tell", (PyCFunction)IO_tell, METH_NOARGS},
{"truncate", (PyCFunction)IO_truncate, METH_VARARGS},
{"close", (PyCFunction)O_close, METH_NOARGS},
{"write", (PyCFunction)O_write, METH_VARARGS},
{"writelines", (PyCFunction)O_writelines, METH_O},
{0},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@
static PyMethodDef readline_methods[] = {
{"parse_and_bind", parse_and_bind, METH_VARARGS},
{"get_line_buffer", get_line_buffer, METH_NOARGS},
{"insert_text", insert_text, METH_VARARGS},
{"redisplay", redisplay, METH_NOARGS},
{"read_init_file", read_init_file, METH_VARARGS},
{"read_history_file", read_history_file, METH_VARARGS},
{"write_history_file", write_history_file, METH_VARARGS},
{"get_history_item", get_history_item, METH_VARARGS},
{"get_current_history_length", (PyCFunction)get_current_history_length, METH_NOARGS},
{"set_history_length", set_history_length, METH_VARARGS},
{"get_history_length", get_history_length, METH_NOARGS},
{"set_completer", set_completer, METH_VARARGS},
{"get_completer", get_completer, METH_NOARGS},
{"get_completion_type", get_completion_type, METH_NOARGS},
{"get_begidx", get_begidx, METH_NOARGS},
{"get_endidx", get_endidx, METH_NOARGS},
{"set_completer_delims", set_completer_delims, METH_VARARGS},
{"add_history", py_add_history, METH_VARARGS},
{"remove_history_item", py_remove_history, METH_VARARGS},
{"replace_history_item", py_replace_history, METH_VARARGS},
{"get_completer_delims", get_completer_delims, METH_NOARGS},
{"set_completion_display_matches_hook", set_completion_display_matches_hook, METH_VARARGS},
{"set_startup_hook", set_startup_hook, METH_VARARGS},
{0},
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Python-2.7.13/Modules/resource.c

static PyMethodDef resource_methods[] = {
{"getrusage", resource_getrusage},
{"getrlimit", resource_getrlimit},
{"setrlimit", resource_setrlimit},
{"getpagesize", resource_getpagesize},
{"getrusage", resource_getrusage, METH_VARARGS},
{0},
};

0 comments on commit 6a78be5

Please sign in to comment.