… | |
… | |
19 | |
19 | |
20 | /* we re-use the storable header for our purposes */ |
20 | /* we re-use the storable header for our purposes */ |
21 | #define MAGIC_LO 0 |
21 | #define MAGIC_LO 0 |
22 | #define MAGIC_U 0 /* uncompressed data follows */ |
22 | #define MAGIC_U 0 /* uncompressed data follows */ |
23 | #define MAGIC_C 1 /* compressed data follows */ |
23 | #define MAGIC_C 1 /* compressed data follows */ |
|
|
24 | #define MAGIC_undef 2 /* the special value undef */ |
|
|
25 | #define MAGIC_CR 3 /* storable (reference, freeze), compressed */ |
24 | #define MAGIC_R 4 /* storable (reference, freeze) */ |
26 | #define MAGIC_R 4 /* storable (reference, freeze) */ |
25 | #define MAGIC_CR 3 /* storable (reference, freeze), compressed */ |
|
|
26 | #define MAGIC_HI 7 /* room for one higher storable major */ |
27 | #define MAGIC_HI 7 /* room for one higher storable major */ |
27 | |
28 | |
28 | #define IN_RANGE(v,l,h) ((unsigned int)((unsigned)(v) - (unsigned)(l)) <= (unsigned)(h) - (unsigned)(l)) |
29 | #define IN_RANGE(v,l,h) ((unsigned int)((unsigned)(v) - (unsigned)(l)) <= (unsigned)(h) - (unsigned)(l)) |
29 | |
30 | |
30 | static CV *storable_mstore, *storable_mretrieve; |
31 | static CV *storable_mstore, *storable_mretrieve; |
… | |
… | |
223 | sfreeze_cr = 1 |
224 | sfreeze_cr = 1 |
224 | sfreeze_c = 2 |
225 | sfreeze_c = 2 |
225 | PROTOTYPE: $ |
226 | PROTOTYPE: $ |
226 | PPCODE: |
227 | PPCODE: |
227 | |
228 | |
228 | if (SvROK (sv)) /* mstore */ |
229 | if (!SvOK (sv)) |
|
|
230 | XPUSHs (sv_2mortal (newSVpvn ("\02", 1))); /* 02 == MAGIC_undef */ |
|
|
231 | else if (SvTYPE(sv) != SVt_IV |
|
|
232 | && SvTYPE(sv) != SVt_NV |
|
|
233 | && SvTYPE(sv) != SVt_PV) /* mstore */ |
229 | { |
234 | { |
230 | if (!storable_mstore) |
235 | if (!storable_mstore) |
231 | need_storable (); |
236 | need_storable (); |
232 | |
237 | |
233 | PUSHMARK (SP); |
238 | PUSHMARK (SP); |
… | |
… | |
247 | if (ix) /* compress */ |
252 | if (ix) /* compress */ |
248 | XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_CR, 0))); |
253 | XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_CR, 0))); |
249 | else |
254 | else |
250 | XPUSHs (sv); |
255 | XPUSHs (sv); |
251 | } |
256 | } |
252 | else if (IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI)) |
257 | else if (sv && IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI)) |
253 | XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 1))); /* need to prefix only */ |
258 | XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 1))); /* need to prefix only */ |
254 | else if (ix == 2) /* compress always */ |
259 | else if (ix == 2) /* compress always */ |
255 | XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0))); |
260 | XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0))); |
256 | else /* don't compress */ |
261 | else /* don't compress */ |
257 | XPUSHs (sv_2mortal (SvREFCNT_inc (sv))); |
262 | XPUSHs (sv_2mortal (SvREFCNT_inc (sv))); |
… | |
… | |
259 | void |
264 | void |
260 | sthaw(sv) |
265 | sthaw(sv) |
261 | SV * sv |
266 | SV * sv |
262 | PROTOTYPE: $ |
267 | PROTOTYPE: $ |
263 | PPCODE: |
268 | PPCODE: |
264 | char hdr = SvPVX (sv)[0]; |
|
|
265 | |
269 | |
266 | if (IN_RANGE (hdr, MAGIC_LO, MAGIC_HI)) |
270 | if (SvPOK (sv) && IN_RANGE (SvPV_nolen (sv)[0], MAGIC_LO, MAGIC_HI)) |
267 | { |
271 | { |
268 | switch (SvPVX (sv)[0]) |
272 | switch (SvPVX (sv)[0]) |
269 | { |
273 | { |
|
|
274 | case MAGIC_undef: |
|
|
275 | XPUSHs (sv_2mortal (NEWSV (0, 0))); |
|
|
276 | break; |
|
|
277 | |
270 | case MAGIC_U: |
278 | case MAGIC_U: |
271 | XPUSHs (sv_2mortal (decompress_sv (sv, 0))); |
279 | XPUSHs (sv_2mortal (decompress_sv (sv, 0))); |
272 | break; |
280 | break; |
273 | |
281 | |
274 | case MAGIC_C: |
282 | case MAGIC_C: |
… | |
… | |
288 | if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR)) |
296 | if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR)) |
289 | croak ("Storable::mstore didn't return a single scalar"); |
297 | croak ("Storable::mstore didn't return a single scalar"); |
290 | |
298 | |
291 | SPAGAIN; |
299 | SPAGAIN; |
292 | |
300 | |
293 | /*XPUSHs (POPs);*/ |
301 | /*XPUSHs (POPs); this is a nop, hopefully */ |
294 | |
302 | |
295 | break; |
303 | break; |
296 | |
304 | |
297 | default: |
305 | default: |
298 | croak ("Compress::LZF::sthaw(): invalid data, maybe you need a newer version of Compress::LZF?"); |
306 | croak ("Compress::LZF::sthaw(): invalid data, maybe you need a newer version of Compress::LZF?"); |