diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 11:35:35 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 11:35:35 +0300 |
commit | 5a515b0afe6a2bc273211ba47fd8fe04c56517c7 (patch) | |
tree | 3ad22d25ea8682901b955112ac4531c88e779c41 /Python/wordcode_helpers.h | |
parent | ddf00b0a227950067b93a1bc828477b59aa4f78c (diff) | |
parent | 759f8db1106193b1a15bfd442eccde9522301023 (diff) | |
download | cpython-5a515b0afe6a2bc273211ba47fd8fe04c56517c7.tar.gz |
Issue #17711: Fixed unpickling by the persistent ID with protocol 0.
Original patch by Alexandre Vassalotti.
Diffstat (limited to 'Python/wordcode_helpers.h')
-rw-r--r-- | Python/wordcode_helpers.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Python/wordcode_helpers.h b/Python/wordcode_helpers.h new file mode 100644 index 0000000000..b61ba33d8f --- /dev/null +++ b/Python/wordcode_helpers.h @@ -0,0 +1,38 @@ +/* This file contains code shared by the compiler and the peephole + optimizer. + */ + +/* Minimum number of bytes necessary to encode instruction with EXTENDED_ARGs */ +static int +instrsize(unsigned int oparg) +{ + return oparg <= 0xff ? 2 : + oparg <= 0xffff ? 4 : + oparg <= 0xffffff ? 6 : + 8; +} + +/* Spits out op/oparg pair using ilen bytes. codestr should be pointed at the + desired location of the first EXTENDED_ARG */ +static void +write_op_arg(unsigned char *codestr, unsigned char opcode, + unsigned int oparg, int ilen) +{ + switch (ilen) { + case 8: + *codestr++ = EXTENDED_ARG; + *codestr++ = (oparg >> 24) & 0xff; + case 6: + *codestr++ = EXTENDED_ARG; + *codestr++ = (oparg >> 16) & 0xff; + case 4: + *codestr++ = EXTENDED_ARG; + *codestr++ = (oparg >> 8) & 0xff; + case 2: + *codestr++ = opcode; + *codestr++ = oparg & 0xff; + break; + default: + assert(0); + } +} |