pytorch/torch/csrc/deploy/interpreter/register_frozenpython.cpp
Sahan Chanuka Paliskara 9de0888891 Move the registration of CPython builtin modules to BuiltinRegistry (#67085)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/67085

leverages BuiltinRegistry to register the CPython standard C modules. The standard C modules moved are in the FOR_EACH macro

Test Plan:
buck test mode/opt //caffe2/torch/csrc/deploy/interpreter:test_builtin_registry

buck test mode/opt //caffe2/torch/csrc/deploy:test_deploy

Reviewed By: shunting314

Differential Revision: D31848547

fbshipit-source-id: 7eb49d222eaaccb2b8ca5c984b05bf54cc233f25
2021-10-25 11:12:07 -07:00

83 lines
2.3 KiB
C++

#include <Python.h>
#include <torch/csrc/deploy/interpreter/builtin_registry.h>
#define FOREACH_LIBRARY(_) \
_(array) \
_(_asyncio) \
_(audioop) \
_(binascii) \
_(_bisect) \
_(_blake2) \
_(_bz2) \
_(cmath) \
_(_codecs_cn) \
_(_codecs_hk) \
_(_codecs_iso2022) \
_(_codecs_jp) \
_(_codecs_kr) \
_(_codecs_tw) \
_(_contextvars) \
_(_crypt) \
_(_csv) \
_(_ctypes) \
_(_ctypes_test) \
_(_curses) \
_(_curses_panel) \
_(_datetime) \
_(_decimal) \
_(_elementtree) \
_(fcntl) \
_(grp) \
_(_hashlib) \
_(_heapq) \
_(_json) \
_(_lsprof) \
_(_lzma) \
_(math) \
_(_md5) \
_(mmap) \
_(_multibytecodec) \
_(_multiprocessing) \
_(nis) \
_(_opcode) \
_(ossaudiodev) \
_(parser) \
_(_pickle) \
_(_posixsubprocess) \
_(pyexpat) \
_(_queue) \
_(_random) \
_(readline) \
_(resource) \
_(select) \
_(_sha1) \
_(_sha256) \
_(_sha3) \
_(_sha512) \
_(_socket) \
_(spwd) \
_(_ssl) \
_(_struct) \
_(syslog) \
_(termios) \
_(_testbuffer) \
_(_testcapi) \
_(_testimportmultiple) \
_(_testmultiphase) \
_(unicodedata) \
_(xxlimited) \
_(_xxtestfuzz) \
_(zlib)
#define DECLARE_LIBRARY_INIT(name) extern "C" PyObject* PyInit_##name(void);
FOREACH_LIBRARY(DECLARE_LIBRARY_INIT)
#undef DECLARE_LIBRARY_INIT
extern "C" struct _frozen _PyImport_FrozenModules[];
#define STD_LIBARY_PARMS(name) , #name, PyInit_##name
REGISTER_TORCH_DEPLOY_BUILTIN(
frozenpython,
_PyImport_FrozenModules FOREACH_LIBRARY(STD_LIBARY_PARMS));
#undef STD_LIBARY_PARMS