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.8 by root, Wed Feb 27 20:51:21 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
234 && SvTYPE(sv) != SVt_PVMG) /* mstore */
229 { 235 {
230 if (!storable_mstore) 236 if (!storable_mstore)
231 need_storable (); 237 need_storable ();
232 238
233 PUSHMARK (SP); 239 PUSHMARK (SP);
247 if (ix) /* compress */ 253 if (ix) /* compress */
248 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_CR, 0))); 254 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_CR, 0)));
249 else 255 else
250 XPUSHs (sv); 256 XPUSHs (sv);
251 } 257 }
252 else if (IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI)) 258 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 */ 259 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 1))); /* need to prefix only */
254 else if (ix == 2) /* compress always */ 260 else if (ix == 2) /* compress always */
255 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0))); 261 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0)));
256 else /* don't compress */ 262 else /* don't compress */
257 XPUSHs (sv_2mortal (SvREFCNT_inc (sv))); 263 XPUSHs (sv_2mortal (SvREFCNT_inc (sv)));
259void 265void
260sthaw(sv) 266sthaw(sv)
261 SV * sv 267 SV * sv
262 PROTOTYPE: $ 268 PROTOTYPE: $
263 PPCODE: 269 PPCODE:
264 char hdr = SvPVX (sv)[0];
265 270
266 if (IN_RANGE (hdr, MAGIC_LO, MAGIC_HI)) 271 SvGETMAGIC (sv);
272 if (SvPOK (sv) && IN_RANGE (SvPV_nolen (sv)[0], MAGIC_LO, MAGIC_HI))
267 { 273 {
268 switch (SvPVX (sv)[0]) 274 switch (SvPVX (sv)[0])
269 { 275 {
276 case MAGIC_undef:
277 XPUSHs (sv_2mortal (NEWSV (0, 0)));
278 break;
279
270 case MAGIC_U: 280 case MAGIC_U:
271 XPUSHs (sv_2mortal (decompress_sv (sv, 0))); 281 XPUSHs (sv_2mortal (decompress_sv (sv, 0)));
272 break; 282 break;
273 283
274 case MAGIC_C: 284 case MAGIC_C:
288 if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR)) 298 if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR))
289 croak ("Storable::mstore didn't return a single scalar"); 299 croak ("Storable::mstore didn't return a single scalar");
290 300
291 SPAGAIN; 301 SPAGAIN;
292 302
293 /*XPUSHs (POPs);*/ 303 /*XPUSHs (POPs); this is a nop, hopefully */
294 304
295 break; 305 break;
296 306
297 default: 307 default:
298 croak ("Compress::LZF::sthaw(): invalid data, maybe you need a newer version of Compress::LZF?"); 308 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