Python: add opcodes for safe py-drivers

The following opcodes have been added, see [0] for details:

- LIST_TO_TUPLE: convert a list to a tuple,
  use for constructing lists/tuples in some cases.

- LIST_EXTEND: use for constructing lists with unpacking.

- SET_UPDATE: use for constructing sets with unpacking.

- CONTAINS_OP: check if `a in b` generally useful.

When writing tests these op-codes where needed for basic operations
and can be safely supported.

Add note why dictionary manipulation op-codes have been left out.

Also restrict namsepace access to anything with an underscore prefix
since these may be undocumented.

[0]: https://docs.python.org/3.10/library/dis.html
This commit is contained in:
2022-07-12 16:05:13 +10:00
parent 2a1d12d7a0
commit 00c7e760b3
2 changed files with 83 additions and 25 deletions

View File

@@ -10,6 +10,8 @@
extern "C" {
#endif
#include <stdbool.h>
/**
* For faster execution we keep a special dictionary for py-drivers, with
* the needed modules and aliases.
@@ -21,6 +23,14 @@ int bpy_pydriver_create_dict(void);
*/
extern PyObject *bpy_pydriver_Dict;
extern bool BPY_driver_secure_bytecode_test_ex(PyObject *expr_code,
PyObject *namespace_array[],
const bool verbose,
const char *error_prefix);
extern bool BPY_driver_secure_bytecode_test(PyObject *expr_code,
PyObject *namespace,
const bool verbose);
#ifdef __cplusplus
}
#endif