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.3 by root, Thu Sep 27 19:51:26 2001 UTC vs.
Revision 1.4 by root, Thu Sep 27 20:05:38 2001 UTC

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
30static CV *storable_mstore, *storable_mretrieve; 31static 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
229 if (!SvOK (sv))
230 XPUSHs (sv_2mortal (newSVpvn ("\02", 1))); /* 02 == MAGIC_undef */
228 if (SvTYPE(sv) != SVt_IV 231 else if (SvTYPE(sv) != SVt_IV
229 && SvTYPE(sv) != SVt_NV 232 && SvTYPE(sv) != SVt_NV
230 && SvTYPE(sv) != SVt_PV) /* mstore */ 233 && SvTYPE(sv) != SVt_PV) /* mstore */
231 { 234 {
232 if (!storable_mstore) 235 if (!storable_mstore)
233 need_storable (); 236 need_storable ();
249 if (ix) /* compress */ 252 if (ix) /* compress */
250 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_CR, 0))); 253 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_CR, 0)));
251 else 254 else
252 XPUSHs (sv); 255 XPUSHs (sv);
253 } 256 }
254 else if (IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI)) 257 else if (sv && IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI))
255 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 */
256 else if (ix == 2) /* compress always */ 259 else if (ix == 2) /* compress always */
257 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0))); 260 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0)));
258 else /* don't compress */ 261 else /* don't compress */
259 XPUSHs (sv_2mortal (SvREFCNT_inc (sv))); 262 XPUSHs (sv_2mortal (SvREFCNT_inc (sv)));
261void 264void
262sthaw(sv) 265sthaw(sv)
263 SV * sv 266 SV * sv
264 PROTOTYPE: $ 267 PROTOTYPE: $
265 PPCODE: 268 PPCODE:
266 char hdr = SvPVX (sv)[0];
267 269
268 if (IN_RANGE (hdr, MAGIC_LO, MAGIC_HI)) 270 if (IN_RANGE (SvPV_nolen (sv)[0], MAGIC_LO, MAGIC_HI))
269 { 271 {
270 switch (SvPVX (sv)[0]) 272 switch (SvPVX (sv)[0])
271 { 273 {
274 case MAGIC_undef:
275 XPUSHs (sv_2mortal (NEWSV (0, 0)));
276 break;
277
272 case MAGIC_U: 278 case MAGIC_U:
273 XPUSHs (sv_2mortal (decompress_sv (sv, 0))); 279 XPUSHs (sv_2mortal (decompress_sv (sv, 0)));
274 break; 280 break;
275 281
276 case MAGIC_C: 282 case MAGIC_C:
290 if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR)) 296 if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR))
291 croak ("Storable::mstore didn't return a single scalar"); 297 croak ("Storable::mstore didn't return a single scalar");
292 298
293 SPAGAIN; 299 SPAGAIN;
294 300
295 /*XPUSHs (POPs);*/ 301 XPUSHs (POPs); /* this is a nop, hope the compiler also knows this */
296 302
297 break; 303 break;
298 304
299 default: 305 default:
300 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?");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines