… | |
… | |
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 | |
|
|
33 | static SV *serializer_package, *serializer_mstore, *serializer_mretrieve; |
33 | static CV *storable_mstore, *storable_mretrieve; |
34 | static CV *storable_mstore, *storable_mretrieve; |
34 | |
35 | |
35 | static SV * |
36 | static SV * |
36 | compress_sv (SV *data, char cprepend, int uprepend) |
37 | compress_sv (SV *data, char cprepend, int uprepend) |
37 | { |
38 | { |
… | |
… | |
192 | |
193 | |
193 | static void |
194 | static void |
194 | need_storable(void) |
195 | need_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 | |
206 | MODULE = Compress::LZF PACKAGE = Compress::LZF |
209 | MODULE = Compress::LZF PACKAGE = Compress::LZF |
|
|
210 | |
|
|
211 | BOOT: |
|
|
212 | serializer_package = newSVpv ("Storable", 0); |
|
|
213 | serializer_mstore = newSVpv ("Storable::mstore", 0); |
|
|
214 | serializer_mretrieve = newSVpv ("Storable::mretrieve", 0); |
|
|
215 | |
|
|
216 | void |
|
|
217 | set_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 | |
208 | void |
229 | void |
209 | compress(data) |
230 | compress(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 | |
278 | void |
307 | void |
279 | sthaw(sv) |
308 | sthaw(sv) |
280 | SV * sv |
309 | SV * sv |
281 | PROTOTYPE: $ |
310 | PROTOTYPE: $ |
… | |
… | |
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 | |