Skip to content

Commit

Permalink
zlib memory tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Aug 20, 2022
1 parent ccf0546 commit b914a67
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
Binary file modified private/zipmat.mexa64
Binary file not shown.
2 changes: 1 addition & 1 deletion src/zmat.cpp
Expand Up @@ -215,7 +215,7 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
} catch (const std::exception& err) {
mexPrintf("C++ Error: %s\n", err.what());
} catch (...) {
mexPrintf("Unknown Exception");
mexPrintf("Unknown Exception\n");
}

return;
Expand Down
4 changes: 3 additions & 1 deletion src/zmatlib.c
Expand Up @@ -190,6 +190,7 @@ int zmat_run(const size_t inputsize, unsigned char* inputstr, size_t* outputsize
*outputsize = zs.total_out;

if (*ret != Z_STREAM_END && *ret != Z_OK) {
deflateEnd(&zs);
return -3;
}

Expand Down Expand Up @@ -268,7 +269,7 @@ int zmat_run(const size_t inputsize, unsigned char* inputstr, size_t* outputsize

zs.next_out = (Bytef*)(*outputbuf); /*(Bytef *)(); // output char array*/

while ((*ret = inflate(&zs, Z_SYNC_FLUSH)) != Z_STREAM_END && count <= 10) {
while ((*ret = inflate(&zs, Z_SYNC_FLUSH)) != Z_STREAM_END && *ret != Z_DATA_ERROR && count <= 10) {
*outputbuf = (unsigned char*)realloc(*outputbuf, (buflen[0] << count));
zs.next_out = (Bytef*)(*outputbuf + (buflen[0] << (count - 1)));
zs.avail_out = (buflen[0] << (count - 1)); /* size of output*/
Expand All @@ -278,6 +279,7 @@ int zmat_run(const size_t inputsize, unsigned char* inputstr, size_t* outputsize
*outputsize = zs.total_out;

if (*ret != Z_STREAM_END && *ret != Z_OK) {
inflateEnd(&zs);
return -3;
}

Expand Down
6 changes: 5 additions & 1 deletion zmat.m
Expand Up @@ -112,6 +112,10 @@
end

if (exist('inputinfo', 'var') && isfield(inputinfo, 'type'))
varargout{1} = typecast(varargout{1}, inputinfo.type);
if(strcmp(inputinfo.type,'logical'))
varargout{1} = logical(varargout{1});
else
varargout{1} = typecast(varargout{1}, inputinfo.type);
end
varargout{1} = reshape(varargout{1}, inputinfo.size);
end

0 comments on commit b914a67

Please sign in to comment.