summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/zlibmodule.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Modules/zlibmodule.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Modules/zlibmodule.c')
-rw-r--r--contrib/tools/python3/src/Modules/zlibmodule.c328
1 files changed, 164 insertions, 164 deletions
diff --git a/contrib/tools/python3/src/Modules/zlibmodule.c b/contrib/tools/python3/src/Modules/zlibmodule.c
index 4f48eec6378..4dfd4ae6722 100644
--- a/contrib/tools/python3/src/Modules/zlibmodule.c
+++ b/contrib/tools/python3/src/Modules/zlibmodule.c
@@ -6,7 +6,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
-#include "structmember.h" // PyMemberDef
+#include "structmember.h" // PyMemberDef
#include "zlib.h"
@@ -31,24 +31,24 @@
/* Initial buffer size. */
#define DEF_BUF_SIZE (16*1024)
-static PyModuleDef zlibmodule;
+static PyModuleDef zlibmodule;
-typedef struct {
- PyTypeObject *Comptype;
- PyTypeObject *Decomptype;
- PyObject *ZlibError;
-} _zlibstate;
+typedef struct {
+ PyTypeObject *Comptype;
+ PyTypeObject *Decomptype;
+ PyObject *ZlibError;
+} _zlibstate;
+
+static inline _zlibstate*
+get_zlib_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_zlibstate *)state;
+}
+
+#define _zlibstate_global ((_zlibstate *)PyModule_GetState(PyState_FindModule(&zlibmodule)))
-static inline _zlibstate*
-get_zlib_state(PyObject *module)
-{
- void *state = PyModule_GetState(module);
- assert(state != NULL);
- return (_zlibstate *)state;
-}
-
-#define _zlibstate_global ((_zlibstate *)PyModule_GetState(PyState_FindModule(&zlibmodule)))
-
typedef struct
{
PyObject_HEAD
@@ -85,9 +85,9 @@ zlib_error(z_stream zst, int err, const char *msg)
}
}
if (zmsg == Z_NULL)
- PyErr_Format(_zlibstate_global->ZlibError, "Error %d %s", err, msg);
+ PyErr_Format(_zlibstate_global->ZlibError, "Error %d %s", err, msg);
else
- PyErr_Format(_zlibstate_global->ZlibError, "Error %d %s: %.200s", err, msg, zmsg);
+ PyErr_Format(_zlibstate_global->ZlibError, "Error %d %s: %.200s", err, msg, zmsg);
}
/*[clinic input]
@@ -238,7 +238,7 @@ zlib_compress_impl(PyObject *module, Py_buffer *data, int level)
"Out of memory while compressing data");
goto error;
case Z_STREAM_ERROR:
- PyErr_SetString(_zlibstate_global->ZlibError, "Bad compression level");
+ PyErr_SetString(_zlibstate_global->ZlibError, "Bad compression level");
goto error;
default:
deflateEnd(&zst);
@@ -303,9 +303,9 @@ ssize_t_converter(PyObject *obj, void *ptr)
PyObject *long_obj;
Py_ssize_t val;
- /* XXX Should be replaced with PyNumber_AsSsize_t after the end of the
- deprecation period. */
- long_obj = _PyLong_FromNbIndexOrNbInt(obj);
+ /* XXX Should be replaced with PyNumber_AsSsize_t after the end of the
+ deprecation period. */
+ long_obj = _PyLong_FromNbIndexOrNbInt(obj);
if (long_obj == NULL) {
return 0;
}
@@ -474,7 +474,7 @@ zlib_compressobj_impl(PyObject *module, int level, int method, int wbits,
goto error;
}
- self = newcompobject(_zlibstate_global->Comptype);
+ self = newcompobject(_zlibstate_global->Comptype);
if (self == NULL)
goto error;
self->zst.opaque = NULL;
@@ -570,7 +570,7 @@ zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict)
return NULL;
}
- self = newcompobject(_zlibstate_global->Decomptype);
+ self = newcompobject(_zlibstate_global->Decomptype);
if (self == NULL)
return NULL;
self->zst.opaque = NULL;
@@ -593,7 +593,7 @@ zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict)
return NULL;
}
#else
- PyErr_Format(_zlibstate_global->ZlibError,
+ PyErr_Format(_zlibstate_global->ZlibError,
"zlib version %s does not allow raw inflate with dictionary",
ZLIB_VERSION);
Py_DECREF(self);
@@ -620,13 +620,13 @@ zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict)
static void
Dealloc(compobject *self)
{
- PyObject *type = (PyObject *)Py_TYPE(self);
+ PyObject *type = (PyObject *)Py_TYPE(self);
PyThread_free_lock(self->lock);
Py_XDECREF(self->unused_data);
Py_XDECREF(self->unconsumed_tail);
Py_XDECREF(self->zdict);
PyObject_Del(self);
- Py_DECREF(type);
+ Py_DECREF(type);
}
static void
@@ -667,8 +667,8 @@ zlib_Compress_compress_impl(compobject *self, Py_buffer *data)
Py_ssize_t ibuflen, obuflen = DEF_BUF_SIZE;
int err;
- ENTER_ZLIB(self);
-
+ ENTER_ZLIB(self);
+
self->zst.next_in = data->buf;
ibuflen = data->len;
@@ -785,8 +785,8 @@ zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
else
hard_limit = max_length;
- ENTER_ZLIB(self);
-
+ ENTER_ZLIB(self);
+
self->zst.next_in = data->buf;
ibuflen = data->len;
@@ -958,7 +958,7 @@ zlib_Compress_copy_impl(compobject *self)
compobject *retval = NULL;
int err;
- retval = newcompobject(_zlibstate_global->Comptype);
+ retval = newcompobject(_zlibstate_global->Comptype);
if (!retval) return NULL;
/* Copy the zstream state
@@ -1001,32 +1001,32 @@ error:
}
/*[clinic input]
-zlib.Compress.__copy__
-[clinic start generated code]*/
-
-static PyObject *
-zlib_Compress___copy___impl(compobject *self)
-/*[clinic end generated code: output=1875e6791975442e input=be97a05a788dfd83]*/
-{
- return zlib_Compress_copy_impl(self);
-}
-
-/*[clinic input]
-zlib.Compress.__deepcopy__
-
- memo: object
- /
-
-[clinic start generated code]*/
-
-static PyObject *
-zlib_Compress___deepcopy__(compobject *self, PyObject *memo)
-/*[clinic end generated code: output=f47a2213282c9eb0 input=a9a8b0b40d83388e]*/
-{
- return zlib_Compress_copy_impl(self);
-}
-
-/*[clinic input]
+zlib.Compress.__copy__
+[clinic start generated code]*/
+
+static PyObject *
+zlib_Compress___copy___impl(compobject *self)
+/*[clinic end generated code: output=1875e6791975442e input=be97a05a788dfd83]*/
+{
+ return zlib_Compress_copy_impl(self);
+}
+
+/*[clinic input]
+zlib.Compress.__deepcopy__
+
+ memo: object
+ /
+
+[clinic start generated code]*/
+
+static PyObject *
+zlib_Compress___deepcopy__(compobject *self, PyObject *memo)
+/*[clinic end generated code: output=f47a2213282c9eb0 input=a9a8b0b40d83388e]*/
+{
+ return zlib_Compress_copy_impl(self);
+}
+
+/*[clinic input]
zlib.Decompress.copy
Return a copy of the decompression object.
@@ -1039,7 +1039,7 @@ zlib_Decompress_copy_impl(compobject *self)
compobject *retval = NULL;
int err;
- retval = newcompobject(_zlibstate_global->Decomptype);
+ retval = newcompobject(_zlibstate_global->Decomptype);
if (!retval) return NULL;
/* Copy the zstream state
@@ -1081,33 +1081,33 @@ error:
Py_XDECREF(retval);
return NULL;
}
-
-/*[clinic input]
-zlib.Decompress.__copy__
-[clinic start generated code]*/
-
-static PyObject *
-zlib_Decompress___copy___impl(compobject *self)
-/*[clinic end generated code: output=80bae8bc43498ad4 input=efcb98b5472c13d2]*/
-{
- return zlib_Decompress_copy_impl(self);
-}
-
-/*[clinic input]
-zlib.Decompress.__deepcopy__
-
- memo: object
- /
-
-[clinic start generated code]*/
-
-static PyObject *
-zlib_Decompress___deepcopy__(compobject *self, PyObject *memo)
-/*[clinic end generated code: output=1f77286ab490124b input=6e99bd0ac4b9cd8b]*/
-{
- return zlib_Decompress_copy_impl(self);
-}
-
+
+/*[clinic input]
+zlib.Decompress.__copy__
+[clinic start generated code]*/
+
+static PyObject *
+zlib_Decompress___copy___impl(compobject *self)
+/*[clinic end generated code: output=80bae8bc43498ad4 input=efcb98b5472c13d2]*/
+{
+ return zlib_Decompress_copy_impl(self);
+}
+
+/*[clinic input]
+zlib.Decompress.__deepcopy__
+
+ memo: object
+ /
+
+[clinic start generated code]*/
+
+static PyObject *
+zlib_Decompress___deepcopy__(compobject *self, PyObject *memo)
+/*[clinic end generated code: output=1f77286ab490124b input=6e99bd0ac4b9cd8b]*/
+{
+ return zlib_Decompress_copy_impl(self);
+}
+
#endif
/*[clinic input]
@@ -1134,12 +1134,12 @@ zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length)
return NULL;
}
- ENTER_ZLIB(self);
-
- if (PyObject_GetBuffer(self->unconsumed_tail, &data, PyBUF_SIMPLE) == -1) {
- LEAVE_ZLIB(self);
+ ENTER_ZLIB(self);
+
+ if (PyObject_GetBuffer(self->unconsumed_tail, &data, PyBUF_SIMPLE) == -1) {
+ LEAVE_ZLIB(self);
return NULL;
- }
+ }
self->zst.next_in = data.buf;
ibuflen = data.len;
@@ -1210,8 +1210,8 @@ static PyMethodDef comp_methods[] =
ZLIB_COMPRESS_COMPRESS_METHODDEF
ZLIB_COMPRESS_FLUSH_METHODDEF
ZLIB_COMPRESS_COPY_METHODDEF
- ZLIB_COMPRESS___COPY___METHODDEF
- ZLIB_COMPRESS___DEEPCOPY___METHODDEF
+ ZLIB_COMPRESS___COPY___METHODDEF
+ ZLIB_COMPRESS___DEEPCOPY___METHODDEF
{NULL, NULL}
};
@@ -1220,8 +1220,8 @@ static PyMethodDef Decomp_methods[] =
ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF
ZLIB_DECOMPRESS_FLUSH_METHODDEF
ZLIB_DECOMPRESS_COPY_METHODDEF
- ZLIB_DECOMPRESS___COPY___METHODDEF
- ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
+ ZLIB_DECOMPRESS___COPY___METHODDEF
+ ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
{NULL, NULL}
};
@@ -1325,33 +1325,33 @@ static PyMethodDef zlib_methods[] =
{NULL, NULL}
};
-static PyType_Slot Comptype_slots[] = {
- {Py_tp_dealloc, Comp_dealloc},
- {Py_tp_methods, comp_methods},
- {0, 0},
-};
-
-static PyType_Spec Comptype_spec = {
+static PyType_Slot Comptype_slots[] = {
+ {Py_tp_dealloc, Comp_dealloc},
+ {Py_tp_methods, comp_methods},
+ {0, 0},
+};
+
+static PyType_Spec Comptype_spec = {
"zlib.Compress",
sizeof(compobject),
0,
- Py_TPFLAGS_DEFAULT,
- Comptype_slots
+ Py_TPFLAGS_DEFAULT,
+ Comptype_slots
};
-static PyType_Slot Decomptype_slots[] = {
- {Py_tp_dealloc, Decomp_dealloc},
- {Py_tp_methods, Decomp_methods},
- {Py_tp_members, Decomp_members},
- {0, 0},
-};
-
-static PyType_Spec Decomptype_spec = {
+static PyType_Slot Decomptype_slots[] = {
+ {Py_tp_dealloc, Decomp_dealloc},
+ {Py_tp_methods, Decomp_methods},
+ {Py_tp_members, Decomp_members},
+ {0, 0},
+};
+
+static PyType_Spec Decomptype_spec = {
"zlib.Decompress",
sizeof(compobject),
0,
- Py_TPFLAGS_DEFAULT,
- Decomptype_slots
+ Py_TPFLAGS_DEFAULT,
+ Decomptype_slots
};
PyDoc_STRVAR(zlib_module_documentation,
@@ -1363,78 +1363,78 @@ PyDoc_STRVAR(zlib_module_documentation,
"compressobj([level[, ...]]) -- Return a compressor object.\n"
"crc32(string[, start]) -- Compute a CRC-32 checksum.\n"
"decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.\n"
-"decompressobj([wbits[, zdict]]) -- Return a decompressor object.\n"
+"decompressobj([wbits[, zdict]]) -- Return a decompressor object.\n"
"\n"
"'wbits' is window buffer size and container format.\n"
"Compressor objects support compress() and flush() methods; decompressor\n"
"objects support decompress() and flush().");
-static int
-zlib_clear(PyObject *m)
-{
- _zlibstate *state = get_zlib_state(m);
- Py_CLEAR(state->Comptype);
- Py_CLEAR(state->Decomptype);
- Py_CLEAR(state->ZlibError);
- return 0;
-}
-
-static int
-zlib_traverse(PyObject *m, visitproc visit, void *arg)
-{
- _zlibstate *state = get_zlib_state(m);
- Py_VISIT(state->Comptype);
- Py_VISIT(state->Decomptype);
- Py_VISIT(state->ZlibError);
- return 0;
-}
-
-static void
-zlib_free(void *m)
-{
- zlib_clear((PyObject *)m);
-}
-
+static int
+zlib_clear(PyObject *m)
+{
+ _zlibstate *state = get_zlib_state(m);
+ Py_CLEAR(state->Comptype);
+ Py_CLEAR(state->Decomptype);
+ Py_CLEAR(state->ZlibError);
+ return 0;
+}
+
+static int
+zlib_traverse(PyObject *m, visitproc visit, void *arg)
+{
+ _zlibstate *state = get_zlib_state(m);
+ Py_VISIT(state->Comptype);
+ Py_VISIT(state->Decomptype);
+ Py_VISIT(state->ZlibError);
+ return 0;
+}
+
+static void
+zlib_free(void *m)
+{
+ zlib_clear((PyObject *)m);
+}
+
static struct PyModuleDef zlibmodule = {
PyModuleDef_HEAD_INIT,
"zlib",
zlib_module_documentation,
- sizeof(_zlibstate),
+ sizeof(_zlibstate),
zlib_methods,
NULL,
- zlib_traverse,
- zlib_clear,
- zlib_free,
+ zlib_traverse,
+ zlib_clear,
+ zlib_free,
};
PyMODINIT_FUNC
PyInit_zlib(void)
{
PyObject *m, *ver;
- m = PyState_FindModule(&zlibmodule);
- if (m != NULL) {
- Py_INCREF(m);
- return m;
- }
+ m = PyState_FindModule(&zlibmodule);
+ if (m != NULL) {
+ Py_INCREF(m);
+ return m;
+ }
m = PyModule_Create(&zlibmodule);
if (m == NULL)
return NULL;
- PyTypeObject *Comptype = (PyTypeObject *)PyType_FromSpec(&Comptype_spec);
- if (Comptype == NULL)
- return NULL;
- get_zlib_state(m)->Comptype = Comptype;
-
- PyTypeObject *Decomptype = (PyTypeObject *)PyType_FromSpec(&Decomptype_spec);
- if (Decomptype == NULL)
- return NULL;
- get_zlib_state(m)->Decomptype = Decomptype;
-
- PyObject *ZlibError = PyErr_NewException("zlib.error", NULL, NULL);
+ PyTypeObject *Comptype = (PyTypeObject *)PyType_FromSpec(&Comptype_spec);
+ if (Comptype == NULL)
+ return NULL;
+ get_zlib_state(m)->Comptype = Comptype;
+
+ PyTypeObject *Decomptype = (PyTypeObject *)PyType_FromSpec(&Decomptype_spec);
+ if (Decomptype == NULL)
+ return NULL;
+ get_zlib_state(m)->Decomptype = Decomptype;
+
+ PyObject *ZlibError = PyErr_NewException("zlib.error", NULL, NULL);
if (ZlibError != NULL) {
Py_INCREF(ZlibError);
PyModule_AddObject(m, "error", ZlibError);
- get_zlib_state(m)->ZlibError = ZlibError;
+ get_zlib_state(m)->ZlibError = ZlibError;
}
PyModule_AddIntMacro(m, MAX_WBITS);
PyModule_AddIntMacro(m, DEFLATED);
@@ -1477,6 +1477,6 @@ PyInit_zlib(void)
PyModule_AddStringConstant(m, "__version__", "1.0");
- PyState_AddModule(m, &zlibmodule);
+ PyState_AddModule(m, &zlibmodule);
return m;
}