Skip to content

Commit

Permalink
return the zlib return value for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed May 3, 2019
1 parent f204eb4 commit 86a0dea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ savejson.m
info: (optional) a struct storing additional info regarding the input data, may have
'type': the class of the input array
'size': the dimensions of the input array
'status': the zlib function return value, including potential error codes (<0)
example:
Expand Down
12 changes: 8 additions & 4 deletions src/zmat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ unsigned char * base64_decode(const unsigned char *src, size_t len,


enum TZipMethod {zmZlib, zmGzip, zmBase64};
const char *metadata[]={"type","size"};
const char *metadata[]={"type","size","status"};

/** @brief Mex function for the zmat - an interface to compress/decompress binary data
* This is the master function to interface for zipping and unzipping a char/int8 buffer
Expand Down Expand Up @@ -113,7 +113,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
ret=deflate(&zs, Z_FINISH);
outputsize=zs.total_out;
if(ret!=Z_STREAM_END && ret!=Z_OK)
mexErrMsgTxt("invalid input buffer");
mexErrMsgTxt("zlib error, see info.status for error flag");
deflateEnd(&zs);
}
}else{
Expand All @@ -140,7 +140,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
outputsize=zs.total_out;

if(ret!=Z_STREAM_END && ret!=Z_OK)
mexErrMsgTxt("invalid input buffer");
mexErrMsgTxt("zlib error, see info.status for error flag");
inflateEnd(&zs);
}
}
Expand All @@ -153,14 +153,18 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
}
if(nlhs>1){
dimtype inputdim[2]={1,0};
plhs[1]=mxCreateStructMatrix(1,1,2,metadata);
plhs[1]=mxCreateStructMatrix(1,1,3,metadata);
mxArray *val = mxCreateString(mxGetClassName(prhs[0]));
mxSetFieldByNumber(plhs[1],0,0, val);

inputdim[1]=mxGetNumberOfDimensions(prhs[0]);
val = mxCreateNumericArray(2, inputdim, mxUINT32_CLASS, mxREAL);
memcpy(mxGetPr(val),mxGetDimensions(prhs[0]),inputdim[1]*sizeof(dimtype));
mxSetFieldByNumber(plhs[1],0,1, val);

val = mxCreateDoubleMatrix(1,1,mxREAL);
*mxGetPr(val) = ret;
mxSetFieldByNumber(plhs[1],0,2, val);
}
}else{
mexErrMsgTxt("the input must be in char or int8/uint8 format");
Expand Down
3 changes: 2 additions & 1 deletion zmat.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
% info: (optional) a struct storing additional info regarding the input data, may have
% 'type': the class of the input array
% 'size': the dimensions of the input array
% 'status': the zlib function return value, including potential error codes (<0)
%
% example:
%
Expand All @@ -32,5 +33,5 @@
% ss=char(zmat('zmat test',1,'base64'))
% orig=char(zmat(ss,0,'base64'))
%
% -- this function is part of the ZMAT toolbox (http://iso2mesh.sf.net/jsonlab)
% -- this function is part of the ZMAT toolbox (http://github.com/fangq/zmat)
%

0 comments on commit 86a0dea

Please sign in to comment.