Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zlib_into
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dataAnalysis
zlib_into
Commits
9ecabdb4
Commit
9ecabdb4
authored
2 months ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Better error messages
parent
281ed3f6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
zlib_into.c
+33
-4
33 additions, 4 deletions
zlib_into.c
with
33 additions
and
4 deletions
zlib_into.c
+
33
−
4
View file @
9ecabdb4
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#define DEF_MEM_LEVEL 8
#define DEF_MEM_LEVEL 8
// malloc & free copied from CPython
// malloc & free
functions
copied from CPython
static
void
*
static
void
*
PyZlib_Malloc
(
voidpf
ctx
,
uInt
items
,
uInt
size
)
PyZlib_Malloc
(
voidpf
ctx
,
uInt
items
,
uInt
size
)
{
{
...
@@ -28,6 +28,36 @@ PyZlib_Free(voidpf ctx, void *ptr)
...
@@ -28,6 +28,36 @@ PyZlib_Free(voidpf ctx, void *ptr)
free
(
ptr
);
free
(
ptr
);
}
}
// zlib_error copied from CPython
static
void
zlib_error
(
z_stream
zst
,
int
err
,
const
char
*
msg
)
{
const
char
*
zmsg
=
Z_NULL
;
/* In case of a version mismatch, zst.msg won't be initialized.
Check for this case first, before looking at zst.msg. */
if
(
err
==
Z_VERSION_ERROR
)
zmsg
=
"library version mismatch"
;
if
(
zmsg
==
Z_NULL
)
zmsg
=
zst
.
msg
;
if
(
zmsg
==
Z_NULL
)
{
switch
(
err
)
{
case
Z_BUF_ERROR
:
zmsg
=
"incomplete or truncated stream"
;
break
;
case
Z_STREAM_ERROR
:
zmsg
=
"inconsistent stream state"
;
break
;
case
Z_DATA_ERROR
:
zmsg
=
"invalid input data"
;
break
;
}
}
if
(
zmsg
==
Z_NULL
)
PyErr_Format
(
PyExc_RuntimeError
,
"Error %d %s"
,
err
,
msg
);
else
PyErr_Format
(
PyExc_RuntimeError
,
"Error %d %s: %.200s"
,
err
,
msg
,
zmsg
);
}
static
PyObject
*
static
PyObject
*
compress_into
(
PyObject
*
module
,
PyObject
*
args
)
{
compress_into
(
PyObject
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
PyObject
*
return_value
=
NULL
;
...
@@ -67,8 +97,7 @@ compress_into(PyObject *module, PyObject *args) {
...
@@ -67,8 +97,7 @@ compress_into(PyObject *module, PyObject *args) {
goto
done
;
goto
done
;
default:
default:
deflateEnd
(
&
zst
);
deflateEnd
(
&
zst
);
PyErr_SetString
(
PyExc_RuntimeError
,
"Other error"
);
zlib_error
(
zst
,
err
,
"while compressing data"
);
//zlib_error(state, zst, err, "while compressing data");
goto
done
;
goto
done
;
}
}
...
@@ -86,7 +115,7 @@ compress_into(PyObject *module, PyObject *args) {
...
@@ -86,7 +115,7 @@ compress_into(PyObject *module, PyObject *args) {
goto
done
;
goto
done
;
default:
default:
deflateEnd
(
&
zst
);
deflateEnd
(
&
zst
);
PyErr_SetString
(
PyExc_RuntimeError
,
"Other error
"
);
zlib_error
(
zst
,
err
,
"while compressing data
"
);
goto
done
;
goto
done
;
}
}
bytes_written
=
output
.
len
-
zst
.
avail_out
;
bytes_written
=
output
.
len
-
zst
.
avail_out
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment