Skip to content

bpo-1635741: Port _lzma module to multiphase initialization #19382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
bpo-1635741: Apply Victor's review
  • Loading branch information
corona10 committed Jun 22, 2020
commit f60b5912f610401af5f1fa2185104ead376c8ff7
33 changes: 16 additions & 17 deletions Modules/_lzmamodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
typedef struct {
PyTypeObject *lzma_compressor_type;
PyTypeObject *lzma_decompressor_type;
PyObject *error_type;
PyObject *error;
PyObject *empty_tuple;
} _lzma_state;

Expand Down Expand Up @@ -82,31 +82,31 @@ catch_lzma_error(_lzma_state *state, lzma_ret lzret)
case LZMA_STREAM_END:
return 0;
case LZMA_UNSUPPORTED_CHECK:
PyErr_SetString(state->error_type, "Unsupported integrity check");
PyErr_SetString(state->error, "Unsupported integrity check");
return 1;
case LZMA_MEM_ERROR:
PyErr_NoMemory();
return 1;
case LZMA_MEMLIMIT_ERROR:
PyErr_SetString(state->error_type, "Memory usage limit exceeded");
PyErr_SetString(state->error, "Memory usage limit exceeded");
return 1;
case LZMA_FORMAT_ERROR:
PyErr_SetString(state->error_type, "Input format not supported by decoder");
PyErr_SetString(state->error, "Input format not supported by decoder");
return 1;
case LZMA_OPTIONS_ERROR:
PyErr_SetString(state->error_type, "Invalid or unsupported options");
PyErr_SetString(state->error, "Invalid or unsupported options");
return 1;
case LZMA_DATA_ERROR:
PyErr_SetString(state->error_type, "Corrupt input data");
PyErr_SetString(state->error, "Corrupt input data");
return 1;
case LZMA_BUF_ERROR:
PyErr_SetString(state->error_type, "Insufficient buffer space");
PyErr_SetString(state->error, "Insufficient buffer space");
return 1;
case LZMA_PROG_ERROR:
PyErr_SetString(state->error_type, "Internal error");
PyErr_SetString(state->error, "Internal error");
return 1;
default:
PyErr_Format(state->error_type, "Unrecognized error from liblzma: %d", lzret);
PyErr_Format(state->error, "Unrecognized error from liblzma: %d", lzret);
return 1;
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ parse_filter_spec_lzma(_lzma_state *state, PyObject *spec)

if (lzma_lzma_preset(options, preset)) {
PyMem_Free(options);
PyErr_Format(state->error_type, "Invalid compression preset: %u", preset);
PyErr_Format(state->error, "Invalid compression preset: %u", preset);
return NULL;
}

Expand Down Expand Up @@ -648,7 +648,7 @@ Compressor_init_alone(_lzma_state *state, lzma_stream *lzs, uint32_t preset, PyO
lzma_options_lzma options;

if (lzma_lzma_preset(&options, preset)) {
PyErr_Format(state->error_type, "Invalid compression preset: %u", preset);
PyErr_Format(state->error, "Invalid compression preset: %u", preset);
return -1;
}
lzret = lzma_alone_encoder(lzs, &options);
Expand Down Expand Up @@ -1568,13 +1568,12 @@ lzma_exec(PyObject *module)
ADD_INT_PREFIX_MACRO(module, PRESET_DEFAULT);
ADD_INT_PREFIX_MACRO(module, PRESET_EXTREME);


state->error_type = PyErr_NewExceptionWithDoc("_lzma.LZMAError", "Call to liblzma failed.", NULL, NULL);
if (state->error_type == NULL) {
state->error = PyErr_NewExceptionWithDoc("_lzma.LZMAError", "Call to liblzma failed.", NULL, NULL);
if (state->error == NULL) {
return -1;
}

if (PyModule_AddType(module, (PyTypeObject *)state->error_type) < 0) {
if (PyModule_AddType(module, (PyTypeObject *)state->error) < 0) {
return -1;
}

Expand Down Expand Up @@ -1620,7 +1619,7 @@ lzma_traverse(PyObject *module, visitproc visit, void *arg)
_lzma_state *state = get_lzma_state(module);
Py_VISIT(state->lzma_compressor_type);
Py_VISIT(state->lzma_decompressor_type);
Py_VISIT(state->error_type);
Py_VISIT(state->error);
Py_VISIT(state->empty_tuple);
return 0;
}
Expand All @@ -1631,7 +1630,7 @@ lzma_clear(PyObject *module)
_lzma_state *state = get_lzma_state(module);
Py_CLEAR(state->lzma_compressor_type);
Py_CLEAR(state->lzma_decompressor_type);
Py_CLEAR(state->error_type);
Py_CLEAR(state->error);
Py_CLEAR(state->empty_tuple);
return 0;
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy