… | |
… | |
12 | #endif |
12 | #endif |
13 | #if PATCHLEVEL < 6 |
13 | #if PATCHLEVEL < 6 |
14 | # define call_sv perl_call_sv |
14 | # define call_sv perl_call_sv |
15 | #endif |
15 | #endif |
16 | |
16 | |
|
|
17 | #define LZF_STANDALONE 1 |
|
|
18 | #define LZF_STATE_ARG 1 |
|
|
19 | |
17 | #include "lzf_c.c" |
20 | #include "lzf_c.c" |
18 | #include "lzf_d.c" |
21 | #include "lzf_d.c" |
19 | |
22 | |
20 | /* we re-use the storable header for our purposes */ |
23 | /* we re-use the storable header for our purposes */ |
21 | #define MAGIC_LO 0 |
24 | #define MAGIC_LO 0 |
… | |
… | |
41 | #endif |
44 | #endif |
42 | |
45 | |
43 | static SV * |
46 | static SV * |
44 | compress_sv (SV *data, char cprepend, int uprepend) |
47 | compress_sv (SV *data, char cprepend, int uprepend) |
45 | { |
48 | { |
|
|
49 | LZF_STATE *state; |
46 | STRLEN usize, csize; |
50 | STRLEN usize, csize; |
47 | char *src = (char *)SvPV (data, usize); |
51 | char *src = (char *)SvPV (data, usize); |
48 | |
52 | |
49 | if (usize) |
53 | if (usize) |
50 | { |
54 | { |
… | |
… | |
98 | dst[skip++] = (( usize & 0x3f) | 0x80); |
102 | dst[skip++] = (( usize & 0x3f) | 0x80); |
99 | } |
103 | } |
100 | else |
104 | else |
101 | croak ("compress can only compress up to %ld bytes", 0x7fffffffL); |
105 | croak ("compress can only compress up to %ld bytes", 0x7fffffffL); |
102 | |
106 | |
|
|
107 | New (0, state, 1, LZF_STATE); |
|
|
108 | if (!state) |
|
|
109 | croak ("Compress::LZF unable to allocate memory for compression state"); |
|
|
110 | |
103 | /* 11 bytes is the smallest compressible string */ |
111 | /* 11 bytes is the smallest compressible string */ |
104 | csize = usize < 11 ? 0 : |
112 | csize = usize < 11 ? 0 : |
105 | lzf_compress (src, usize, |
113 | lzf_compress (src, usize, dst + skip, usize - skip, *state); |
106 | dst + skip, |
114 | |
107 | usize - skip); |
115 | Safefree (state); |
108 | |
116 | |
109 | if (csize) |
117 | if (csize) |
110 | { |
118 | { |
111 | SvCUR_set (ret, csize + skip); |
119 | SvCUR_set (ret, csize + skip); |
112 | } |
120 | } |