--- Compress-LZF/LZF.xs 2001/09/27 19:51:26 1.3 +++ Compress-LZF/LZF.xs 2001/09/27 20:05:38 1.4 @@ -21,8 +21,9 @@ #define MAGIC_LO 0 #define MAGIC_U 0 /* uncompressed data follows */ #define MAGIC_C 1 /* compressed data follows */ -#define MAGIC_R 4 /* storable (reference, freeze) */ +#define MAGIC_undef 2 /* the special value undef */ #define MAGIC_CR 3 /* storable (reference, freeze), compressed */ +#define MAGIC_R 4 /* storable (reference, freeze) */ #define MAGIC_HI 7 /* room for one higher storable major */ #define IN_RANGE(v,l,h) ((unsigned int)((unsigned)(v) - (unsigned)(l)) <= (unsigned)(h) - (unsigned)(l)) @@ -225,7 +226,9 @@ PROTOTYPE: $ PPCODE: - if (SvTYPE(sv) != SVt_IV + if (!SvOK (sv)) + XPUSHs (sv_2mortal (newSVpvn ("\02", 1))); /* 02 == MAGIC_undef */ + else if (SvTYPE(sv) != SVt_IV && SvTYPE(sv) != SVt_NV && SvTYPE(sv) != SVt_PV) /* mstore */ { @@ -251,7 +254,7 @@ else XPUSHs (sv); } - else if (IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI)) + else if (sv && IN_RANGE (SvPVX (sv)[0], MAGIC_LO, MAGIC_HI)) XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 1))); /* need to prefix only */ else if (ix == 2) /* compress always */ XPUSHs (sv_2mortal (compress_sv (sv, MAGIC_C, 0))); @@ -263,12 +266,15 @@ SV * sv PROTOTYPE: $ PPCODE: - char hdr = SvPVX (sv)[0]; - if (IN_RANGE (hdr, MAGIC_LO, MAGIC_HI)) + if (IN_RANGE (SvPV_nolen (sv)[0], MAGIC_LO, MAGIC_HI)) { switch (SvPVX (sv)[0]) { + case MAGIC_undef: + XPUSHs (sv_2mortal (NEWSV (0, 0))); + break; + case MAGIC_U: XPUSHs (sv_2mortal (decompress_sv (sv, 0))); break; @@ -292,7 +298,7 @@ SPAGAIN; - /*XPUSHs (POPs);*/ + XPUSHs (POPs); /* this is a nop, hope the compiler also knows this */ break;