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.6 by root, Thu Sep 27 20:09:02 2001 UTC vs.
Revision 1.9 by root, Sun Mar 3 04:45:18 2002 UTC

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 */ 24#define MAGIC_undef 2 /* the special value undef */
25#define MAGIC_CR 3 /* storable (reference, freeze), compressed */ 25#define MAGIC_CR 3 /* storable (reference, freeze), compressed */
26#define MAGIC_R 4 /* storable (reference, freeze) */ 26#define MAGIC_R 4 /* storable (reference, freeze) */
27#define MAGIC_CR_deref 5 /* storable (NO reference, freeze), compressed */
28#define MAGIC_R_deref 6 /* storable NO (reference, freeze) */
27#define MAGIC_HI 7 /* room for one higher storable major */ 29#define MAGIC_HI 7 /* room for one higher storable major */
28 30
29#define IN_RANGE(v,l,h) ((unsigned int)((unsigned)(v) - (unsigned)(l)) <= (unsigned)(h) - (unsigned)(l)) 31#define IN_RANGE(v,l,h) ((unsigned int)((unsigned)(v) - (unsigned)(l)) <= (unsigned)(h) - (unsigned)(l))
30 32
31static CV *storable_mstore, *storable_mretrieve; 33static CV *storable_mstore, *storable_mretrieve;
230 XPUSHs (sv_2mortal (newSVpvn ("\02", 1))); /* 02 == MAGIC_undef */ 232 XPUSHs (sv_2mortal (newSVpvn ("\02", 1))); /* 02 == MAGIC_undef */
231 else if (SvTYPE(sv) != SVt_IV 233 else if (SvTYPE(sv) != SVt_IV
232 && SvTYPE(sv) != SVt_NV 234 && SvTYPE(sv) != SVt_NV
233 && SvTYPE(sv) != SVt_PV) /* mstore */ 235 && SvTYPE(sv) != SVt_PV) /* mstore */
234 { 236 {
237 int deref = !SvROK (sv);
238
235 if (!storable_mstore) 239 if (!storable_mstore)
236 need_storable (); 240 need_storable ();
241
242 if (deref)
243 sv = newRV_noinc (sv);
237 244
238 PUSHMARK (SP); 245 PUSHMARK (SP);
239 XPUSHs (sv); 246 XPUSHs (sv);
240 PUTBACK; 247 PUTBACK;
241 248
248 255
249 if (SvPVX (sv)[0] != MAGIC_R) 256 if (SvPVX (sv)[0] != MAGIC_R)
250 croak ("Storable format changed, need newer version of Compress::LZF"); 257 croak ("Storable format changed, need newer version of Compress::LZF");
251 258
252 if (ix) /* compress */ 259 if (ix) /* compress */
253 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_CR, 0))); 260 XPUSHs (sv_2mortal (compress_sv (sv, deref ? MAGIC_CR_deref : MAGIC_CR, 0)));
254 else 261 else
262 {
263 if (deref)
264 SvPVX (sv)[0] = MAGIC_R_deref;
265
255 XPUSHs (sv); 266 XPUSHs (sv);
267 }
256 } 268 }
257 else if (sv && IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI)) 269 else if (sv && IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI))
258 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 1))); /* need to prefix only */ 270 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 1))); /* need to prefix only */
259 else if (ix == 2) /* compress always */ 271 else if (ix == 2) /* compress always */
260 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0))); 272 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0)));
265sthaw(sv) 277sthaw(sv)
266 SV * sv 278 SV * sv
267 PROTOTYPE: $ 279 PROTOTYPE: $
268 PPCODE: 280 PPCODE:
269 281
282 int deref = 0;
283
284 SvGETMAGIC (sv);
270 if (SvPOK (sv) && IN_RANGE (SvPV_nolen (sv)[0], MAGIC_LO, MAGIC_HI)) 285 if (SvPOK (sv) && IN_RANGE (SvPV_nolen (sv)[0], MAGIC_LO, MAGIC_HI))
271 { 286 {
272 switch (SvPVX (sv)[0]) 287 switch (SvPVX (sv)[0])
273 { 288 {
274 case MAGIC_undef: 289 case MAGIC_undef:
281 296
282 case MAGIC_C: 297 case MAGIC_C:
283 XPUSHs (sv_2mortal (decompress_sv (sv, 1))); 298 XPUSHs (sv_2mortal (decompress_sv (sv, 1)));
284 break; 299 break;
285 300
301 case MAGIC_CR_deref:
302 deref = 1;
286 case MAGIC_CR: 303 case MAGIC_CR:
287 sv = sv_2mortal (decompress_sv (sv, 1)); /* mortal could be optimized */ 304 sv = sv_2mortal (decompress_sv (sv, 1)); /* mortal could be optimized */
305 case MAGIC_R_deref:
306 if (SvPVX (sv)[0] == MAGIC_R_deref)
307 {
308 deref = 1;
309 SvPVX (sv)[0] = MAGIC_R;
310 }
288 case MAGIC_R: 311 case MAGIC_R:
289 if (!storable_mstore) 312 if (!storable_mstore)
290 need_storable (); 313 need_storable ();
291 314
292 PUSHMARK (SP); 315 PUSHMARK (SP);
296 if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR)) 319 if (1 != call_sv ((SV *)storable_mretrieve, G_SCALAR))
297 croak ("Storable::mstore didn't return a single scalar"); 320 croak ("Storable::mstore didn't return a single scalar");
298 321
299 SPAGAIN; 322 SPAGAIN;
300 323
324 if (deref)
325 {
326 SV *ref = SvREFCNT_inc (SvRV (TOPs));
327
328 SvREFCNT_dec (TOPs); /* destroy superfluous ref */
329 SETs (ref);
330
331 if (SvPVX (sv)[0] == MAGIC_R)
332 SvPVX (sv)[0] = MAGIC_R;
333 }
334
301 /*XPUSHs (POPs); this is a nop, hopefully */ 335 XPUSHs (POPs); /* this is a nop, hopefully */
302 336
303 break; 337 break;
304 338
305 default: 339 default:
306 croak ("Compress::LZF::sthaw(): invalid data, maybe you need a newer version of Compress::LZF?"); 340 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