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.13 by root, Sat May 18 21:48:39 2002 UTC vs.
Revision 1.19 by pcg, Tue Aug 3 15:07:51 2004 UTC

28#define MAGIC_R_deref 6 /* storable (NO reference, freeze) */ 28#define MAGIC_R_deref 6 /* storable (NO reference, freeze) */
29#define MAGIC_HI 7 /* room for one higher storable major */ 29#define MAGIC_HI 7 /* room for one higher storable major */
30 30
31#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))
32 32
33static SV *serializer_package, *serializer_mstore, *serializer_mretrieve;
33static CV *storable_mstore, *storable_mretrieve; 34static CV *storable_mstore, *storable_mretrieve;
34 35
35static SV * 36static SV *
36compress_sv (SV *data, char cprepend, int uprepend) 37compress_sv (SV *data, char cprepend, int uprepend)
37{ 38{
192 193
193static void 194static void
194need_storable(void) 195need_storable(void)
195{ 196{
196#if PATCHLEVEL < 6 197#if PATCHLEVEL < 6
198 char req[8192];
199 sprintf (req, "require %s;", SvPV_nolen (serializer_package));
197 perl_eval_pv ("require Storable;", 1); 200 perl_eval_pv (req, 1);
198#else 201#else
199 load_module (PERL_LOADMOD_NOIMPORT, newSVpv ("Storable", 0), Nullsv); 202 load_module (PERL_LOADMOD_NOIMPORT, serializer_package, Nullsv);
200#endif 203#endif
201 204
202 storable_mstore = GvCV (gv_fetchpv ("Storable::mstore" , TRUE, SVt_PVCV)); 205 storable_mstore = GvCV (gv_fetchpv (SvPV_nolen (serializer_mstore ), TRUE, SVt_PVCV));
203 storable_mretrieve = GvCV (gv_fetchpv ("Storable::mretrieve", TRUE, SVt_PVCV)); 206 storable_mretrieve = GvCV (gv_fetchpv (SvPV_nolen (serializer_mretrieve), TRUE, SVt_PVCV));
204} 207}
205 208
206MODULE = Compress::LZF PACKAGE = Compress::LZF 209MODULE = Compress::LZF PACKAGE = Compress::LZF
210
211BOOT:
212 serializer_package = newSVpv ("Storable", 0);
213 serializer_mstore = newSVpv ("Storable::mstore", 0);
214 serializer_mretrieve = newSVpv ("Storable::mretrieve", 0);
215
216void
217set_serializer(package, mstore, mretrieve)
218 SV * package
219 SV * mstore
220 SV * mretrieve
221 PROTOTYPE: $$$
222 PPCODE:
223 SvSetSV (serializer_package , package );
224 SvSetSV (serializer_mstore , mstore );
225 SvSetSV (serializer_mretrieve, mretrieve);
226 storable_mstore =
227 storable_mretrieve = 0;
207 228
208void 229void
209compress(data) 230compress(data)
210 SV * data 231 SV * data
211 PROTOTYPE: $ 232 PROTOTYPE: $
234 XPUSHs (sv_2mortal (newSVpvn ("\02", 1))); /* 02 == MAGIC_undef */ 255 XPUSHs (sv_2mortal (newSVpvn ("\02", 1))); /* 02 == MAGIC_undef */
235 else if (SvROK (sv) 256 else if (SvROK (sv)
236 || (SvTYPE(sv) != SVt_IV 257 || (SvTYPE(sv) != SVt_IV
237 && SvTYPE(sv) != SVt_NV 258 && SvTYPE(sv) != SVt_NV
238 && SvTYPE(sv) != SVt_PV 259 && SvTYPE(sv) != SVt_PV
260 && SvTYPE(sv) != SVt_PVIV
261 && SvTYPE(sv) != SVt_PVNV
239 && SvTYPE(sv) != SVt_PVMG)) /* mstore */ 262 && SvTYPE(sv) != SVt_PVMG)) /* mstore */
240 { 263 {
241 int deref = !SvROK (sv); 264 int deref = !SvROK (sv);
242 265
243 if (!storable_mstore) 266 if (!storable_mstore)
270 } 293 }
271 else if (SvPOKp (sv) && IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI)) 294 else if (SvPOKp (sv) && IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI))
272 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, MAGIC_U))); /* need to prefix only */ 295 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, MAGIC_U))); /* need to prefix only */
273 else if (ix == 2) /* compress always */ 296 else if (ix == 2) /* compress always */
274 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, -1))); 297 XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, -1)));
298 else if (SvNIOK (sv)) /* don't compress */
299 {
300 STRLEN len;
301 char *s = SvPV (sv, len);
302 XPUSHs (sv_2mortal (newSVpvn (s, len)));
303 }
275 else /* don't compress */ 304 else /* don't compress */
276 XPUSHs (sv_2mortal (SvREFCNT_inc (sv))); 305 XPUSHs (sv_2mortal (newSVsv (sv)));
277 306
278void 307void
279sthaw(sv) 308sthaw(sv)
280 SV * sv 309 SV * sv
281 PROTOTYPE: $ 310 PROTOTYPE: $
335 364
336 if (SvPVX (sv)[0] == MAGIC_R) 365 if (SvPVX (sv)[0] == MAGIC_R)
337 SvPVX (sv)[0] = MAGIC_R_deref; 366 SvPVX (sv)[0] = MAGIC_R_deref;
338 } 367 }
339 else 368 else
340 XPUSHs (POPs); /* this is a nop, hopefully */ 369 SETs (sv_2mortal (newSVsv (TOPs)));
341 370
342 break; 371 break;
343 372
344 default: 373 default:
345 croak ("Compress::LZF::sthaw(): invalid data, maybe you need a newer version of Compress::LZF?"); 374 croak ("Compress::LZF::sthaw(): invalid data, maybe you need a newer version of Compress::LZF?");
346 } 375 }
347 } 376 }
348 else 377 else
349 XPUSHs (sv_2mortal (newSVsv (sv))); 378 XPUSHs (sv_2mortal (newSVsv (sv)));
379

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines