diff options
| author | Damien George <damien.p.george@gmail.com> | 2015-06-19 12:49:10 +0000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2015-06-20 16:39:39 +0100 |
| commit | 06593fb0f23dfc12f482561fbec1717dca0d4db4 (patch) | |
| tree | 0e078b9ec3b5889505396e230d97d62cb2486ad4 /py/mpconfig.h | |
| parent | a193ced7fa543763cf331be9baf534b9f8ae1822 (diff) | |
py: Use a wrapper to explicitly check self argument of builtin methods.
Previous to this patch a call such as list.append(1, 2) would lead to a
seg fault. This is because list.append is a builtin method and the first
argument to such methods is always assumed to have the correct type.
Now, when a builtin method is extracted like this it is wrapped in a
checker object which checks the the type of the first argument before
calling the builtin function.
This feature is contrelled by MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG and
is enabled by default.
See issue #1216.
Diffstat (limited to 'py/mpconfig.h')
| -rw-r--r-- | py/mpconfig.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h index 2d9288f32..9f541ef70 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -393,6 +393,15 @@ typedef double mp_float_t; #define MICROPY_CAN_OVERRIDE_BUILTINS (0) #endif +// Whether to check that the "self" argument of a builtin method has the +// correct type. Such an explicit check is only needed if a builtin +// method escapes to Python land without a first argument, eg +// list.append([], 1). Without this check such calls will have undefined +// behaviour (usually segfault) if the first argument is the wrong type. +#ifndef MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG +#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (1) +#endif + /*****************************************************************************/ /* Fine control over Python builtins, classes, modules, etc */ |
