PyDrivers: update bytecode check for Python3.6
authorCampbell Barton <ideasman42@gmail.com>
Fri, 6 Jul 2018 17:31:00 +0000 (19:31 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 6 Jul 2018 17:31:00 +0000 (19:31 +0200)
source/blender/python/intern/bpy_driver.c

index bc81eb8ee2474c2910715135d0edb57d7e46231a..f6ff1b3f36b224abd4a00154697d28beed576cba 100644 (file)
@@ -253,7 +253,6 @@ static void pydriver_error(ChannelDriver *driver)
 #define OK_OP(op) [op] = 1
 
 const char secure_opcodes[255] = {
-       OK_OP(0),
        OK_OP(POP_TOP),
        OK_OP(ROT_TWO),
        OK_OP(ROT_THREE),
@@ -347,15 +346,14 @@ static bool bpy_driver_secure_bytecode_validate(PyObject *expr_code, PyObject *d
 
        /* Check opcodes. */
        {
-               const char *codestr;
+               const _Py_CODEUNIT *codestr;
                Py_ssize_t  code_len;
 
                PyBytes_AsStringAndSize(py_code->co_code, (char **)&codestr, &code_len);
+               code_len /= sizeof(*codestr);
 
-#define CODESIZE(op) (HAS_ARG(op) ? 3 : 1)
-
-               for (Py_ssize_t i = 0; i < code_len; i += CODESIZE(codestr[i])) {
-                       const int opcode = codestr[i];
+               for (Py_ssize_t i = 0; i < code_len; i++) {
+                       const int opcode = _Py_OPCODE(codestr[i]);
                        if (secure_opcodes[opcode] == 0) {
                                fprintf(stderr, "\tBPY_driver_eval() - restructed access disallows opcode '%d', "
                                                "enable auto-execution to support\n", opcode);