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.33 by root, Sun Jun 28 18:18:03 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 > 2000) 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 > 2000) 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 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines