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.2 by root, Thu Sep 27 19:24:55 2001 UTC vs.
Revision 1.7 by root, Fri Feb 22 00:15:52 2002 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
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)));
259void 264void
260sthaw(sv) 265sthaw(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 SvGETMAGIC (sv);
271 if (SvPOK (sv) && IN_RANGE (SvPV_nolen (sv)[0], MAGIC_LO, MAGIC_HI))
267 { 272 {
268 switch (SvPVX (sv)[0]) 273 switch (SvPVX (sv)[0])
269 { 274 {
275 case MAGIC_undef:
276 XPUSHs (sv_2mortal (NEWSV (0, 0)));
277 break;
278
270 case MAGIC_U: 279 case MAGIC_U:
271 XPUSHs (sv_2mortal (decompress_sv (sv, 0))); 280 XPUSHs (sv_2mortal (decompress_sv (sv, 0)));
272 break; 281 break;
273 282
274 case MAGIC_C: 283 case MAGIC_C:
288 if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR)) 297 if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR))
289 croak ("Storable::mstore didn't return a single scalar"); 298 croak ("Storable::mstore didn't return a single scalar");
290 299
291 SPAGAIN; 300 SPAGAIN;
292 301
293 /*XPUSHs (POPs);*/ 302 /*XPUSHs (POPs); this is a nop, hopefully */
294 303
295 break; 304 break;
296 305
297 default: 306 default:
298 croak ("Compress::LZF::sthaw(): invalid data, maybe you need a newer version of Compress::LZF?"); 307 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