Skip to content

Commit 01fa565

Browse files
committed
change: error message
1 parent c6b079e commit 01fa565

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

zstd.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ ZEND_FUNCTION(zstd_uncompress)
422422

423423
if (ZSTD_IS_ERROR(result)) {
424424
zend_string_efree(output);
425-
ZSTD_WARNING("can not decompress stream");
425+
ZSTD_WARNING("%s", ZSTD_getErrorName(result));
426426
RETURN_FALSE;
427427
}
428428

@@ -434,15 +434,15 @@ ZEND_FUNCTION(zstd_uncompress)
434434
stream = ZSTD_createDStream();
435435
if (stream == NULL) {
436436
zend_string_efree(output);
437-
ZSTD_WARNING("can not create stream");
437+
ZSTD_WARNING("failed to can uncompress context");
438438
RETURN_FALSE;
439439
}
440440

441441
result = ZSTD_initDStream(stream);
442442
if (ZSTD_IS_ERROR(result)) {
443443
zend_string_efree(output);
444444
ZSTD_freeDStream(stream);
445-
ZSTD_WARNING("can not init stream");
445+
ZSTD_WARNING("%s", ZSTD_getErrorName(result));
446446
RETURN_FALSE;
447447
}
448448

@@ -465,7 +465,7 @@ ZEND_FUNCTION(zstd_uncompress)
465465
if (ZSTD_IS_ERROR(result)) {
466466
zend_string_efree(output);
467467
ZSTD_freeDStream(stream);
468-
ZSTD_WARNING("can not decompress stream");
468+
ZSTD_WARNING("%s", ZSTD_getErrorName(result));
469469
RETURN_FALSE;
470470
}
471471

@@ -504,15 +504,15 @@ ZEND_FUNCTION(zstd_compress_dict)
504504

505505
ZSTD_CCtx* const cctx = ZSTD_createCCtx();
506506
if (cctx == NULL) {
507-
ZSTD_WARNING("ZSTD_createCCtx() error");
507+
ZSTD_WARNING("failed to create compress context");
508508
RETURN_FALSE;
509509
}
510510
ZSTD_CDict* const cdict = ZSTD_createCDict(dict,
511511
dict_len,
512512
(int)level);
513513
if (!cdict) {
514514
ZSTD_freeCStream(cctx);
515-
ZSTD_WARNING("ZSTD_createCDict() error");
515+
ZSTD_WARNING("failed to load dictionary");
516516
RETURN_FALSE;
517517
}
518518

@@ -657,7 +657,7 @@ ZEND_FUNCTION(zstd_compress_init)
657657
ctx->cctx = ZSTD_createCCtx();
658658
if (ctx->cctx == NULL) {
659659
zval_ptr_dtor(return_value);
660-
ZSTD_WARNING("ZSTD_createCCtx() error");
660+
ZSTD_WARNING("failed to create compress context");
661661
RETURN_FALSE;
662662
}
663663
ctx->cdict = NULL;
@@ -700,8 +700,7 @@ ZEND_FUNCTION(zstd_compress_add)
700700
ctx = php_zstd_context_from_obj(Z_OBJ_P(obj));
701701
#endif
702702
if (ctx == NULL || ctx->cctx == NULL) {
703-
php_error_docref(NULL, E_WARNING,
704-
"ZStandard incremental compress resource failed");
703+
ZSTD_WARNING("failed to prepare incremental compress");
705704
RETURN_FALSE;
706705
}
707706

@@ -713,8 +712,7 @@ ZEND_FUNCTION(zstd_compress_add)
713712
res = ZSTD_compressStream2(ctx->cctx, &ctx->output,
714713
&in, end ? ZSTD_e_end : ZSTD_e_flush);
715714
if (ZSTD_isError(res)) {
716-
php_error_docref(NULL, E_WARNING,
717-
"libzstd error %s\n", ZSTD_getErrorName(res));
715+
ZSTD_WARNING("%s", ZSTD_getErrorName(res));
718716
smart_string_free(&out);
719717
RETURN_FALSE;
720718
}
@@ -732,7 +730,7 @@ ZEND_FUNCTION(zstd_uncompress_init)
732730
ctx->dctx = ZSTD_createDCtx();
733731
if (ctx->dctx == NULL) {
734732
zval_ptr_dtor(return_value);
735-
ZSTD_WARNING("ZSTD_createDCtx() error");
733+
ZSTD_WARNING("failed to create uncompress context");
736734
RETURN_FALSE;
737735
}
738736
ctx->cdict = NULL;
@@ -772,8 +770,7 @@ ZEND_FUNCTION(zstd_uncompress_add)
772770
ctx = php_zstd_context_from_obj(Z_OBJ_P(obj));
773771
#endif
774772
if (ctx == NULL || ctx->dctx == NULL) {
775-
php_error_docref(NULL, E_WARNING,
776-
"ZStandard incremental uncompress resource failed");
773+
ZSTD_WARNING("failed to prepare incremental uncompress");
777774
RETURN_FALSE;
778775
}
779776

@@ -790,8 +787,7 @@ ZEND_FUNCTION(zstd_uncompress_add)
790787
ctx->output.pos = 0;
791788
res = ZSTD_decompressStream(ctx->dctx, &ctx->output, &in);
792789
if (ZSTD_isError(res)) {
793-
php_error_docref(NULL, E_WARNING,
794-
"libzstd error %s\n", ZSTD_getErrorName(res));
790+
ZSTD_WARNING("%s", ZSTD_getErrorName(res));
795791
smart_string_free(&out);
796792
RETURN_FALSE;
797793
}
@@ -856,8 +852,7 @@ static int php_zstd_comp_flush_or_end(php_zstd_stream_data *self, int end)
856852
res = ZSTD_compressStream2(self->cctx, &self->output, &in,
857853
end ? ZSTD_e_end : ZSTD_e_flush);
858854
if (ZSTD_isError(res)) {
859-
php_error_docref(NULL, E_WARNING,
860-
"libzstd error %s\n", ZSTD_getErrorName(res));
855+
ZSTD_WARNING("zstd: %s", ZSTD_getErrorName(res));
861856
ret = EOF;
862857
}
863858
php_stream_write(self->stream, self->output.dst, self->output.pos);
@@ -938,8 +933,7 @@ static ssize_t php_zstd_decomp_read(php_stream *stream, char *buf, size_t count)
938933
res = ZSTD_decompressStream(self->dctx,
939934
&self->output, &self->input);
940935
if (ZSTD_IS_ERROR(res)) {
941-
php_error_docref(NULL, E_WARNING,
942-
"libzstd error %s\n", ZSTD_getErrorName(res));
936+
ZSTD_WARNING("zstd: %s", ZSTD_getErrorName(res));
943937
#if PHP_VERSION_ID >= 70400
944938
return -1;
945939
#endif
@@ -979,8 +973,7 @@ php_zstd_comp_write(php_stream *stream, const char *buf, size_t count)
979973
res = ZSTD_compressStream2(self->cctx, &self->output,
980974
&in, ZSTD_e_continue);
981975
if (ZSTD_isError(res)) {
982-
php_error_docref(NULL, E_WARNING,
983-
"libzstd error %s\n", ZSTD_getErrorName(res));
976+
ZSTD_WARNING("zstd: %s", ZSTD_getErrorName(res));
984977
#if PHP_VERSION_ID >= 70400
985978
return -1;
986979
#endif
@@ -1077,9 +1070,8 @@ php_stream_zstd_opener(
10771070
}
10781071

10791072
if (level > ZSTD_maxCLevel()) {
1080-
php_error_docref(NULL, E_WARNING,
1081-
"zstd: compression level (%d) must be less than %d",
1082-
level, ZSTD_maxCLevel());
1073+
ZSTD_WARNING("zstd: compression level (%d) must be less than %d",
1074+
level, ZSTD_maxCLevel());
10831075
level = ZSTD_maxCLevel();
10841076
}
10851077

@@ -1096,8 +1088,7 @@ php_stream_zstd_opener(
10961088
self->dctx = NULL;
10971089
self->cctx = ZSTD_createCCtx();
10981090
if (!self->cctx) {
1099-
php_error_docref(NULL, E_WARNING,
1100-
"zstd: compression context failed");
1091+
ZSTD_WARNING("zstd: compression context failed");
11011092
php_stream_close(self->stream);
11021093
efree(self);
11031094
return NULL;
@@ -1115,8 +1106,7 @@ php_stream_zstd_opener(
11151106
} else {
11161107
self->dctx = ZSTD_createDCtx();
11171108
if (!self->dctx) {
1118-
php_error_docref(NULL, E_WARNING,
1119-
"zstd: compression context failed");
1109+
ZSTD_WARNING("zstd: compression context failed");
11201110
php_stream_close(self->stream);
11211111
efree(self);
11221112
return NULL;

0 commit comments

Comments
 (0)