ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Compress-LZF/LZF.xs
(Generate patch)

Comparing Compress-LZF/LZF.xs (file contents):
Revision 1.32 by root, Sat Jun 27 19:52:44 2015 UTC vs.
Revision 1.34 by root, Mon Jun 29 23:51:28 2015 UTC

35#endif 35#endif
36 36
37static SV * 37static SV *
38compress_sv (SV *data, char cprepend, int uprepend, int best) 38compress_sv (SV *data, char cprepend, int uprepend, int best)
39{ 39{
40 LZF_STATE *state; 40 void *state;
41 STRLEN usize, csize; 41 STRLEN usize, csize;
42 char *src = (char *)SvPVbyte (data, usize); 42 char *src = (char *)SvPVbyte (data, usize);
43 43
44 if (usize) 44 if (usize)
45 { 45 {
93 dst[skip++] = (( usize & 0x3f) | 0x80); 93 dst[skip++] = (( usize & 0x3f) | 0x80);
94 } 94 }
95 else 95 else
96 croak ("compress can only compress up to %ld bytes", 0x7fffffffL); 96 croak ("compress can only compress up to %ld bytes", 0x7fffffffL);
97 97
98 New (0, state, 1, LZF_STATE); 98 if (usize > 2000) perlinterp_release ();
99
100 state = malloc (best ? sizeof (LZF_STATE_BEST) : sizeof (LZF_STATE));
99 if (!state) 101 if (!state)
102 {
103 if (usize > 2000) perlinterp_acquire ();
100 croak ("Compress::LZF unable to allocate memory for compression state"); 104 croak ("Compress::LZF unable to allocate memory for compression state");
105 }
101 106
102 if (usize > 1000) perlinterp_release ();
103 /* 11 bytes is the smallest compressible string */ 107 /* 11 bytes is the smallest compressible string */
104 csize = usize < 11 ? 0 : 108 csize = usize < 11 ? 0 :
105 (best ? lzf_compress_best (src, usize, dst + skip, usize - skip) 109 (best ? lzf_compress_best (src, usize, dst + skip, usize - skip, *(LZF_STATE_BEST *)state)
106 : lzf_compress (src, usize, dst + skip, usize - skip, *state)); 110 : lzf_compress (src, usize, dst + skip, usize - skip, *(LZF_STATE *)state));
111
112 free (state);
113
107 if (usize > 1000) perlinterp_acquire (); 114 if (usize > 2000) perlinterp_acquire ();
108
109 Safefree (state);
110 115
111 if (csize) 116 if (csize)
112 { 117 {
113 SvCUR_set (ret, csize + skip); 118 SvCUR_set (ret, csize + skip);
114 } 119 }
201 206
202 ret = NEWSV (0, usize); 207 ret = NEWSV (0, usize);
203 SvPOK_only (ret); 208 SvPOK_only (ret);
204 dst = SvPVX (ret); 209 dst = SvPVX (ret);
205 210
206 if (usize > 2000) perlinterp_release (); 211 if (usize > 4000) perlinterp_release ();
207 res = lzf_decompress (src, csize, dst, usize) != usize; 212 res = lzf_decompress (src, csize, dst, usize) != usize;
208 if (usize > 2000) perlinterp_acquire (); 213 if (usize > 4000) perlinterp_acquire ();
209 214
210 if (res) 215 if (res)
211 { 216 {
212 SvREFCNT_dec (ret); 217 SvREFCNT_dec (ret);
213 croak ("compressed data corrupted (size mismatch)", csize, skip, usize); 218 croak ("compressed data corrupted (size mismatch)", csize, skip, usize);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines