diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-18 19:22:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-18 19:22:29 (GMT) |
commit | 79d1c2e6c9d1bc1cf41ec3041801ca1a2b9a995b (patch) | |
tree | 024dfc74ad7bd5290180638b1290301ef928426f /Programs | |
parent | 4ba3b50bfe6d50cd82d208023ea23e203ab50589 (diff) | |
download | cpython-79d1c2e6c9d1bc1cf41ec3041801ca1a2b9a995b.zip cpython-79d1c2e6c9d1bc1cf41ec3041801ca1a2b9a995b.tar.gz cpython-79d1c2e6c9d1bc1cf41ec3041801ca1a2b9a995b.tar.bz2 |
bpo-25711: Rewrite zipimport in pure Python. (GH-6809)
Diffstat (limited to 'Programs')
-rw-r--r-- | Programs/_freeze_importlib.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/Programs/_freeze_importlib.c b/Programs/_freeze_importlib.c index 8830d13..3f43757 100644 --- a/Programs/_freeze_importlib.c +++ b/Programs/_freeze_importlib.c @@ -27,28 +27,30 @@ static const struct _frozen _PyImport_FrozenModules[] = { const struct _frozen *PyImport_FrozenModules; #endif -const char header[] = "/* Auto-generated by Programs/_freeze_importlib.c */"; +static const char header[] = + "/* Auto-generated by Programs/_freeze_importlib.c */"; int main(int argc, char *argv[]) { - char *inpath, *outpath, *code_name; + const char *name, *inpath, *outpath; + char buf[100]; FILE *infile = NULL, *outfile = NULL; struct _Py_stat_struct status; - size_t text_size, data_size, n; + size_t text_size, data_size, i, n; char *text = NULL; unsigned char *data; PyObject *code = NULL, *marshalled = NULL; - int is_bootstrap = 1; PyImport_FrozenModules = _PyImport_FrozenModules; - if (argc != 3) { - fprintf(stderr, "need to specify input and output paths\n"); + if (argc != 4) { + fprintf(stderr, "need to specify the name, input and output paths\n"); return 2; } - inpath = argv[1]; - outpath = argv[2]; + name = argv[1]; + inpath = argv[2]; + outpath = argv[3]; infile = fopen(inpath, "rb"); if (infile == NULL) { fprintf(stderr, "cannot open '%s' for reading\n", inpath); @@ -90,14 +92,8 @@ main(int argc, char *argv[]) _Py_FatalInitError(err); } - if (strstr(inpath, "_external") != NULL) { - is_bootstrap = 0; - } - - code_name = is_bootstrap ? - "<frozen importlib._bootstrap>" : - "<frozen importlib._bootstrap_external>"; - code = Py_CompileStringExFlags(text, code_name, Py_file_input, NULL, 0); + sprintf(buf, "<frozen %s>", name); + code = Py_CompileStringExFlags(text, buf, Py_file_input, NULL, 0); if (code == NULL) goto error; free(text); @@ -120,11 +116,13 @@ main(int argc, char *argv[]) goto error; } fprintf(outfile, "%s\n", header); - if (is_bootstrap) - fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n"); - else - fprintf(outfile, - "const unsigned char _Py_M__importlib_external[] = {\n"); + for (i = n = 0; name[i] != '\0'; i++) { + if (name[i] != '.') { + buf[n++] = name[i]; + } + } + buf[n] = '\0'; + fprintf(outfile, "const unsigned char _Py_M__%s[] = {\n", buf); for (n = 0; n < data_size; n += 16) { size_t i, end = Py_MIN(n + 16, data_size); fprintf(outfile, " "); |