/** * Close the unpickler and frees the resources such as the unpickle stack and memo table. */ public void close() { if (stack != null) { stack.clear(); } if (memo != null) { memo.Clear(); } }
public void testClear() { UnpickleStack s=new UnpickleStack(); s.add("x"); s.add("y"); Assert.AreEqual(2, s.size()); s.clear(); Assert.AreEqual(0, s.size()); }
public object Load() { byte key = 0; while ((key = input.ReadByte()) != Opcodes.STOP) { Dispatch(key); } object value = stack.pop(); stack.clear(); unpickler.memo.Clear(); return(value); // final result value }
/** * Process a single pickle stream opcode. */ protected object dispatch(short key) { switch (key) { case Opcodes.MARK: load_mark(); break; case Opcodes.STOP: object value = stack.pop(); stack.clear(); return(value); // final result value case Opcodes.POP: load_pop(); break; case Opcodes.POP_MARK: load_pop_mark(); break; case Opcodes.DUP: load_dup(); break; case Opcodes.FLOAT: load_float(); break; case Opcodes.INT: load_int(); break; case Opcodes.BININT: load_binint(); break; case Opcodes.BININT1: load_binint1(); break; case Opcodes.LONG: load_long(); break; case Opcodes.BININT2: load_binint2(); break; case Opcodes.NONE: load_none(); break; case Opcodes.PERSID: load_persid(); break; case Opcodes.BINPERSID: load_binpersid(); break; case Opcodes.REDUCE: load_reduce(); break; case Opcodes.STRING: load_string(); break; case Opcodes.BINSTRING: load_binstring(); break; case Opcodes.SHORT_BINSTRING: load_short_binstring(); break; case Opcodes.UNICODE: load_unicode(); break; case Opcodes.BINUNICODE: load_binunicode(); break; case Opcodes.APPEND: load_append(); break; case Opcodes.BUILD: load_build(); break; case Opcodes.GLOBAL: load_global(); break; case Opcodes.DICT: load_dict(); break; case Opcodes.EMPTY_DICT: load_empty_dictionary(); break; case Opcodes.APPENDS: load_appends(); break; case Opcodes.GET: load_get(); break; case Opcodes.BINGET: load_binget(); break; case Opcodes.INST: load_inst(); break; case Opcodes.LONG_BINGET: load_long_binget(); break; case Opcodes.LIST: load_list(); break; case Opcodes.EMPTY_LIST: load_empty_list(); break; case Opcodes.OBJ: load_obj(); break; case Opcodes.PUT: load_put(); break; case Opcodes.BINPUT: load_binput(); break; case Opcodes.LONG_BINPUT: load_long_binput(); break; case Opcodes.SETITEM: load_setitem(); break; case Opcodes.TUPLE: load_tuple(); break; case Opcodes.EMPTY_TUPLE: load_empty_tuple(); break; case Opcodes.SETITEMS: load_setitems(); break; case Opcodes.BINFLOAT: load_binfloat(); break; // protocol 2 case Opcodes.PROTO: load_proto(); break; case Opcodes.NEWOBJ: load_newobj(); break; case Opcodes.EXT1: case Opcodes.EXT2: case Opcodes.EXT4: throw new PickleException("Unimplemented opcode EXT1/EXT2/EXT4 encountered. Don't use extension codes when pickling via copyreg.add_extension() to avoid this error."); case Opcodes.TUPLE1: load_tuple1(); break; case Opcodes.TUPLE2: load_tuple2(); break; case Opcodes.TUPLE3: load_tuple3(); break; case Opcodes.NEWTRUE: load_true(); break; case Opcodes.NEWFALSE: load_false(); break; case Opcodes.LONG1: load_long1(); break; case Opcodes.LONG4: load_long4(); break; // Protocol 3 (Python 3.x) case Opcodes.BINBYTES: load_binbytes(); break; case Opcodes.SHORT_BINBYTES: load_short_binbytes(); break; // Protocol 4 (Python 3.4+) case Opcodes.BINUNICODE8: load_binunicode8(); break; case Opcodes.SHORT_BINUNICODE: load_short_binunicode(); break; case Opcodes.BINBYTES8: load_binbytes8(); break; case Opcodes.EMPTY_SET: load_empty_set(); break; case Opcodes.ADDITEMS: load_additems(); break; case Opcodes.FROZENSET: load_frozenset(); break; case Opcodes.MEMOIZE: load_memoize(); break; case Opcodes.FRAME: load_frame(); break; case Opcodes.NEWOBJ_EX: load_newobj_ex(); break; case Opcodes.STACK_GLOBAL: load_stack_global(); break; default: throw new InvalidOpcodeException("invalid pickle opcode: " + key); } return(NO_RETURN_VALUE); }
/** * Close the unpickler and frees the resources such as the unpickle stack and memo table. */ public void close() { stack?.clear(); memo?.Clear(); input?.Close(); }