this repo has no description
at trunk 46 lines 1.4 kB view raw
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 2#include "builtins.h" 3#include "bytes-builtins.h" 4#include "frame.h" 5#include "globals.h" 6#include "marshal.h" 7#include "module-builtins.h" 8#include "modules.h" 9#include "objects.h" 10#include "runtime.h" 11#include "thread.h" 12 13namespace py { 14 15void FUNC(marshal, __init_module__)(Thread* thread, const Module& module, 16 View<byte> bytecode) { 17 HandleScope scope(thread); 18 19 // Add module variables 20 { 21 Object magic_number(&scope, SmallInt::fromWord(kPycMagic)); 22 moduleAtPutById(thread, module, ID(magic_number), magic_number); 23 } 24 25 executeFrozenModule(thread, module, bytecode); 26} 27 28RawObject FUNC(marshal, loads)(Thread* thread, Arguments args) { 29 HandleScope scope(thread); 30 Object bytes_obj(&scope, args.get(0)); 31 Runtime* runtime = thread->runtime(); 32 if (!runtime->isInstanceOfBytes(*bytes_obj)) { 33 // TODO(T38902048): Load from buffer protocol objects 34 UNIMPLEMENTED("marshal.loads with non-bytes objects"); 35 } 36 Bytes bytes(&scope, bytesUnderlying(*bytes_obj)); 37 word length = bytes.length(); 38 // TODO(T38902583): Use updated Marshal reader to read from Bytes object 39 // directly 40 std::unique_ptr<byte[]> buffer(new byte[length]); 41 bytes.copyTo(buffer.get(), length); 42 Marshal::Reader reader(&scope, thread, View<byte>(buffer.get(), length)); 43 return reader.readObject(); 44} 45 46} // namespace py