Skip to content

change: error message #83

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 1 commit into from
Jun 10, 2025
Merged
Changes from all commits
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
48 changes: 19 additions & 29 deletions zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ ZEND_FUNCTION(zstd_uncompress)

if (ZSTD_IS_ERROR(result)) {
zend_string_efree(output);
ZSTD_WARNING("can not decompress stream");
ZSTD_WARNING("%s", ZSTD_getErrorName(result));
RETURN_FALSE;
}

Expand All @@ -434,15 +434,15 @@ ZEND_FUNCTION(zstd_uncompress)
stream = ZSTD_createDStream();
if (stream == NULL) {
zend_string_efree(output);
ZSTD_WARNING("can not create stream");
ZSTD_WARNING("failed to create uncompress context");
RETURN_FALSE;
}

result = ZSTD_initDStream(stream);
if (ZSTD_IS_ERROR(result)) {
zend_string_efree(output);
ZSTD_freeDStream(stream);
ZSTD_WARNING("can not init stream");
ZSTD_WARNING("%s", ZSTD_getErrorName(result));
RETURN_FALSE;
}

Expand All @@ -465,7 +465,7 @@ ZEND_FUNCTION(zstd_uncompress)
if (ZSTD_IS_ERROR(result)) {
zend_string_efree(output);
ZSTD_freeDStream(stream);
ZSTD_WARNING("can not decompress stream");
ZSTD_WARNING("%s", ZSTD_getErrorName(result));
RETURN_FALSE;
}

Expand Down Expand Up @@ -504,15 +504,15 @@ ZEND_FUNCTION(zstd_compress_dict)

ZSTD_CCtx* const cctx = ZSTD_createCCtx();
if (cctx == NULL) {
ZSTD_WARNING("ZSTD_createCCtx() error");
ZSTD_WARNING("failed to create compress context");
RETURN_FALSE;
}
ZSTD_CDict* const cdict = ZSTD_createCDict(dict,
dict_len,
(int)level);
if (!cdict) {
ZSTD_freeCStream(cctx);
ZSTD_WARNING("ZSTD_createCDict() error");
ZSTD_WARNING("failed to load dictionary");
RETURN_FALSE;
}

Expand Down Expand Up @@ -657,7 +657,7 @@ ZEND_FUNCTION(zstd_compress_init)
ctx->cctx = ZSTD_createCCtx();
if (ctx->cctx == NULL) {
zval_ptr_dtor(return_value);
ZSTD_WARNING("ZSTD_createCCtx() error");
ZSTD_WARNING("failed to create compress context");
RETURN_FALSE;
}
ctx->cdict = NULL;
Expand Down Expand Up @@ -700,8 +700,7 @@ ZEND_FUNCTION(zstd_compress_add)
ctx = php_zstd_context_from_obj(Z_OBJ_P(obj));
#endif
if (ctx == NULL || ctx->cctx == NULL) {
php_error_docref(NULL, E_WARNING,
"ZStandard incremental compress resource failed");
ZSTD_WARNING("failed to prepare incremental compress");
RETURN_FALSE;
}

Expand All @@ -713,8 +712,7 @@ ZEND_FUNCTION(zstd_compress_add)
res = ZSTD_compressStream2(ctx->cctx, &ctx->output,
&in, end ? ZSTD_e_end : ZSTD_e_flush);
if (ZSTD_isError(res)) {
php_error_docref(NULL, E_WARNING,
"libzstd error %s\n", ZSTD_getErrorName(res));
ZSTD_WARNING("%s", ZSTD_getErrorName(res));
smart_string_free(&out);
RETURN_FALSE;
}
Expand All @@ -732,7 +730,7 @@ ZEND_FUNCTION(zstd_uncompress_init)
ctx->dctx = ZSTD_createDCtx();
if (ctx->dctx == NULL) {
zval_ptr_dtor(return_value);
ZSTD_WARNING("ZSTD_createDCtx() error");
ZSTD_WARNING("failed to create uncompress context");
RETURN_FALSE;
}
ctx->cdict = NULL;
Expand Down Expand Up @@ -772,8 +770,7 @@ ZEND_FUNCTION(zstd_uncompress_add)
ctx = php_zstd_context_from_obj(Z_OBJ_P(obj));
#endif
if (ctx == NULL || ctx->dctx == NULL) {
php_error_docref(NULL, E_WARNING,
"ZStandard incremental uncompress resource failed");
ZSTD_WARNING("failed to prepare incremental uncompress");
RETURN_FALSE;
}

Expand All @@ -790,8 +787,7 @@ ZEND_FUNCTION(zstd_uncompress_add)
ctx->output.pos = 0;
res = ZSTD_decompressStream(ctx->dctx, &ctx->output, &in);
if (ZSTD_isError(res)) {
php_error_docref(NULL, E_WARNING,
"libzstd error %s\n", ZSTD_getErrorName(res));
ZSTD_WARNING("%s", ZSTD_getErrorName(res));
smart_string_free(&out);
RETURN_FALSE;
}
Expand Down Expand Up @@ -856,8 +852,7 @@ static int php_zstd_comp_flush_or_end(php_zstd_stream_data *self, int end)
res = ZSTD_compressStream2(self->cctx, &self->output, &in,
end ? ZSTD_e_end : ZSTD_e_flush);
if (ZSTD_isError(res)) {
php_error_docref(NULL, E_WARNING,
"libzstd error %s\n", ZSTD_getErrorName(res));
ZSTD_WARNING("zstd: %s", ZSTD_getErrorName(res));
ret = EOF;
}
php_stream_write(self->stream, self->output.dst, self->output.pos);
Expand Down Expand Up @@ -938,8 +933,7 @@ static ssize_t php_zstd_decomp_read(php_stream *stream, char *buf, size_t count)
res = ZSTD_decompressStream(self->dctx,
&self->output, &self->input);
if (ZSTD_IS_ERROR(res)) {
php_error_docref(NULL, E_WARNING,
"libzstd error %s\n", ZSTD_getErrorName(res));
ZSTD_WARNING("zstd: %s", ZSTD_getErrorName(res));
#if PHP_VERSION_ID >= 70400
return -1;
#endif
Expand Down Expand Up @@ -979,8 +973,7 @@ php_zstd_comp_write(php_stream *stream, const char *buf, size_t count)
res = ZSTD_compressStream2(self->cctx, &self->output,
&in, ZSTD_e_continue);
if (ZSTD_isError(res)) {
php_error_docref(NULL, E_WARNING,
"libzstd error %s\n", ZSTD_getErrorName(res));
ZSTD_WARNING("zstd: %s", ZSTD_getErrorName(res));
#if PHP_VERSION_ID >= 70400
return -1;
#endif
Expand Down Expand Up @@ -1077,9 +1070,8 @@ php_stream_zstd_opener(
}

if (level > ZSTD_maxCLevel()) {
php_error_docref(NULL, E_WARNING,
"zstd: compression level (%d) must be less than %d",
level, ZSTD_maxCLevel());
ZSTD_WARNING("zstd: compression level (%d) must be less than %d",
level, ZSTD_maxCLevel());
level = ZSTD_maxCLevel();
}

Expand All @@ -1096,8 +1088,7 @@ php_stream_zstd_opener(
self->dctx = NULL;
self->cctx = ZSTD_createCCtx();
if (!self->cctx) {
php_error_docref(NULL, E_WARNING,
"zstd: compression context failed");
ZSTD_WARNING("zstd: compression context failed");
php_stream_close(self->stream);
efree(self);
return NULL;
Expand All @@ -1115,8 +1106,7 @@ php_stream_zstd_opener(
} else {
self->dctx = ZSTD_createDCtx();
if (!self->dctx) {
php_error_docref(NULL, E_WARNING,
"zstd: compression context failed");
ZSTD_WARNING("zstd: compression context failed");
php_stream_close(self->stream);
efree(self);
return NULL;
Expand Down
Loading