| 1 |
|
| /* -*- c-basic-offset: 4 -*- |
| 2 |
|
| * |
| 3 |
|
| * Fast store and retrieve mechanism. |
| 4 |
|
| * |
| 5 |
|
| * Copyright (c) 1995-2000, Raphael Manfredi |
| 6 |
|
| * Copyright (c) 2016, 2017 cPanel Inc |
| 7 |
|
| * Copyright (c) 2017 Reini Urban |
| 8 |
|
| * |
| 9 |
|
| * You may redistribute only under the same terms as Perl 5, as specified |
| 10 |
|
| * in the README file that comes with the distribution. |
| 11 |
|
| * |
| 12 |
|
| */ |
| 13 |
|
| |
| 14 |
|
| #define PERL_NO_GET_CONTEXT /* we want efficiency */ |
| 15 |
|
| #include <EXTERN.h> |
| 16 |
|
| #include <perl.h> |
| 17 |
|
| #include <XSUB.h> |
| 18 |
|
| |
| 19 |
|
| #define NEED_sv_2pv_flags |
| 20 |
|
| #define NEED_load_module |
| 21 |
|
| #define NEED_vload_module |
| 22 |
|
| #define NEED_newCONSTSUB |
| 23 |
|
| #define NEED_newSVpvn_flags |
| 24 |
|
| #define NEED_newRV_noinc |
| 25 |
|
| #define NEED_sv_vstring_get |
| 26 |
|
| #include "ppport.h" /* handle old perls */ |
| 27 |
|
| |
| 28 |
|
| #ifdef DEBUGGING |
| 29 |
|
| #define DEBUGME /* Debug mode, turns assertions on as well */ |
| 30 |
|
| #define DASSERT /* Assertion mode */ |
| 31 |
|
| #endif |
| 32 |
|
| |
| 33 |
|
| /* |
| 34 |
|
| * Earlier versions of perl might be used, we can't assume they have the latest! |
| 35 |
|
| */ |
| 36 |
|
| |
| 37 |
|
| /* perl <= 5.8.2 needs this */ |
| 38 |
|
| #ifndef SvIsCOW |
| 39 |
|
| # define SvIsCOW(sv) 0 |
| 40 |
|
| #endif |
| 41 |
|
| |
| 42 |
|
| #ifndef HvRITER_set |
| 43 |
|
| # define HvRITER_set(hv,r) (HvRITER(hv) = r) |
| 44 |
|
| #endif |
| 45 |
|
| #ifndef HvEITER_set |
| 46 |
|
| # define HvEITER_set(hv,r) (HvEITER(hv) = r) |
| 47 |
|
| #endif |
| 48 |
|
| |
| 49 |
|
| #ifndef HvRITER_get |
| 50 |
|
| # define HvRITER_get HvRITER |
| 51 |
|
| #endif |
| 52 |
|
| #ifndef HvEITER_get |
| 53 |
|
| # define HvEITER_get HvEITER |
| 54 |
|
| #endif |
| 55 |
|
| |
| 56 |
|
| #ifndef HvPLACEHOLDERS_get |
| 57 |
|
| # define HvPLACEHOLDERS_get HvPLACEHOLDERS |
| 58 |
|
| #endif |
| 59 |
|
| |
| 60 |
|
| #ifndef HvTOTALKEYS |
| 61 |
|
| # define HvTOTALKEYS(hv) HvKEYS(hv) |
| 62 |
|
| #endif |
| 63 |
|
| /* 5.6 */ |
| 64 |
|
| #ifndef HvUSEDKEYS |
| 65 |
|
| # define HvUSEDKEYS(hv) HvKEYS(hv) |
| 66 |
|
| #endif |
| 67 |
|
| |
| 68 |
|
| #ifdef SVf_IsCOW |
| 69 |
|
| # define SvTRULYREADONLY(sv) SvREADONLY(sv) |
| 70 |
|
| #else |
| 71 |
|
| # define SvTRULYREADONLY(sv) (SvREADONLY(sv) && !SvIsCOW(sv)) |
| 72 |
|
| #endif |
| 73 |
|
| |
| 74 |
|
| #ifndef strEQc |
| 75 |
|
| # define strEQc(s,c) memEQ(s, ("" c ""), sizeof(c)) |
| 76 |
|
| #endif |
| 77 |
|
| |
| 78 |
|
| #if defined(HAS_FLOCK) || defined(FCNTL_CAN_LOCK) && defined(HAS_LOCKF) |
| 79 |
|
| #define CAN_FLOCK &PL_sv_yes |
| 80 |
|
| #else |
| 81 |
|
| #define CAN_FLOCK &PL_sv_no |
| 82 |
|
| #endif |
| 83 |
|
| |
| 84 |
|
| #ifdef DEBUGME |
| 85 |
|
| |
| 86 |
|
| #ifndef DASSERT |
| 87 |
|
| #define DASSERT |
| 88 |
|
| #endif |
| 89 |
|
| |
| 90 |
|
| /* |
| 91 |
|
| * TRACEME() will only output things when the $Storable::DEBUGME is true, |
| 92 |
|
| * using the value traceme cached in the context. |
| 93 |
|
| * |
| 94 |
|
| * |
| 95 |
|
| * TRACEMED() directly looks at the variable, for use before traceme has been |
| 96 |
|
| * updated. |
| 97 |
|
| */ |
| 98 |
|
| |
| 99 |
|
| #define TRACEME(x) \ |
| 100 |
|
| STMT_START { \ |
| 101 |
|
| if (cxt->traceme) \ |
| 102 |
|
| { PerlIO_stdoutf x; PerlIO_stdoutf("\n"); } \ |
| 103 |
|
| } STMT_END |
| 104 |
|
| |
| 105 |
|
| #define TRACEMED(x) \ |
| 106 |
|
| STMT_START { \ |
| 107 |
|
| if (SvTRUE(get_sv("Storable::DEBUGME", GV_ADD))) \ |
| 108 |
|
| { PerlIO_stdoutf x; PerlIO_stdoutf("\n"); } \ |
| 109 |
|
| } STMT_END |
| 110 |
|
| |
| 111 |
|
| #define INIT_TRACEME \ |
| 112 |
|
| STMT_START { \ |
| 113 |
|
| cxt->traceme = SvTRUE(get_sv("Storable::DEBUGME", GV_ADD)); \ |
| 114 |
|
| } STMT_END |
| 115 |
|
| |
| 116 |
|
| #else |
| 117 |
|
| #define TRACEME(x) |
| 118 |
|
| #define TRACEMED(x) |
| 119 |
|
| #define INIT_TRACEME |
| 120 |
|
| #endif /* DEBUGME */ |
| 121 |
|
| |
| 122 |
|
| #ifdef DASSERT |
| 123 |
|
| #define ASSERT(x,y) \ |
| 124 |
|
| STMT_START { \ |
| 125 |
|
| if (!(x)) { \ |
| 126 |
|
| PerlIO_stdoutf("ASSERT FAILED (\"%s\", line %d): ", \ |
| 127 |
|
| __FILE__, (int)__LINE__); \ |
| 128 |
|
| PerlIO_stdoutf y; PerlIO_stdoutf("\n"); \ |
| 129 |
|
| } \ |
| 130 |
|
| } STMT_END |
| 131 |
|
| #else |
| 132 |
|
| #define ASSERT(x,y) |
| 133 |
|
| #endif |
| 134 |
|
| |
| 135 |
|
| /* |
| 136 |
|
| * Type markers. |
| 137 |
|
| */ |
| 138 |
|
| |
| 139 |
|
| #define C(x) ((char) (x)) /* For markers with dynamic retrieval handling */ |
| 140 |
|
| |
| 141 |
|
| #define SX_OBJECT C(0) /* Already stored object */ |
| 142 |
|
| #define SX_LSCALAR C(1) /* Scalar (large binary) follows (length, data) */ |
| 143 |
|
| #define SX_ARRAY C(2) /* Array forthcoming (size, item list) */ |
| 144 |
|
| #define SX_HASH C(3) /* Hash forthcoming (size, key/value pair list) */ |
| 145 |
|
| #define SX_REF C(4) /* Reference to object forthcoming */ |
| 146 |
|
| #define SX_UNDEF C(5) /* Undefined scalar */ |
| 147 |
|
| #define SX_INTEGER C(6) /* Integer forthcoming */ |
| 148 |
|
| #define SX_DOUBLE C(7) /* Double forthcoming */ |
| 149 |
|
| #define SX_BYTE C(8) /* (signed) byte forthcoming */ |
| 150 |
|
| #define SX_NETINT C(9) /* Integer in network order forthcoming */ |
| 151 |
|
| #define SX_SCALAR C(10) /* Scalar (binary, small) follows (length, data) */ |
| 152 |
|
| #define SX_TIED_ARRAY C(11) /* Tied array forthcoming */ |
| 153 |
|
| #define SX_TIED_HASH C(12) /* Tied hash forthcoming */ |
| 154 |
|
| #define SX_TIED_SCALAR C(13) /* Tied scalar forthcoming */ |
| 155 |
|
| #define SX_SV_UNDEF C(14) /* Perl's immortal PL_sv_undef */ |
| 156 |
|
| #define SX_SV_YES C(15) /* Perl's immortal PL_sv_yes */ |
| 157 |
|
| #define SX_SV_NO C(16) /* Perl's immortal PL_sv_no */ |
| 158 |
|
| #define SX_BLESS C(17) /* Object is blessed */ |
| 159 |
|
| #define SX_IX_BLESS C(18) /* Object is blessed, classname given by index */ |
| 160 |
|
| #define SX_HOOK C(19) /* Stored via hook, user-defined */ |
| 161 |
|
| #define SX_OVERLOAD C(20) /* Overloaded reference */ |
| 162 |
|
| #define SX_TIED_KEY C(21) /* Tied magic key forthcoming */ |
| 163 |
|
| #define SX_TIED_IDX C(22) /* Tied magic index forthcoming */ |
| 164 |
|
| #define SX_UTF8STR C(23) /* UTF-8 string forthcoming (small) */ |
| 165 |
|
| #define SX_LUTF8STR C(24) /* UTF-8 string forthcoming (large) */ |
| 166 |
|
| #define SX_FLAG_HASH C(25) /* Hash with flags forthcoming (size, flags, key/flags/value triplet list) */ |
| 167 |
|
| #define SX_CODE C(26) /* Code references as perl source code */ |
| 168 |
|
| #define SX_WEAKREF C(27) /* Weak reference to object forthcoming */ |
| 169 |
|
| #define SX_WEAKOVERLOAD C(28) /* Overloaded weak reference */ |
| 170 |
|
| #define SX_VSTRING C(29) /* vstring forthcoming (small) */ |
| 171 |
|
| #define SX_LVSTRING C(30) /* vstring forthcoming (large) */ |
| 172 |
|
| #define SX_SVUNDEF_ELEM C(31) /* array element set to &PL_sv_undef */ |
| 173 |
|
| #define SX_REGEXP C(32) /* Regexp */ |
| 174 |
|
| #define SX_LOBJECT C(33) /* Large object: string, array or hash (size >2G) */ |
| 175 |
|
| #define SX_BOOLEAN_TRUE C(34) /* Boolean true */ |
| 176 |
|
| #define SX_BOOLEAN_FALSE C(35) /* Boolean false */ |
| 177 |
|
| #define SX_LAST C(36) /* invalid. marker only */ |
| 178 |
|
| |
| 179 |
|
| /* |
| 180 |
|
| * Those are only used to retrieve "old" pre-0.6 binary images. |
| 181 |
|
| */ |
| 182 |
|
| #define SX_ITEM 'i' /* An array item introducer */ |
| 183 |
|
| #define SX_IT_UNDEF 'I' /* Undefined array item */ |
| 184 |
|
| #define SX_KEY 'k' /* A hash key introducer */ |
| 185 |
|
| #define SX_VALUE 'v' /* A hash value introducer */ |
| 186 |
|
| #define SX_VL_UNDEF 'V' /* Undefined hash value */ |
| 187 |
|
| |
| 188 |
|
| /* |
| 189 |
|
| * Those are only used to retrieve "old" pre-0.7 binary images |
| 190 |
|
| */ |
| 191 |
|
| |
| 192 |
|
| #define SX_CLASS 'b' /* Object is blessed, class name length <255 */ |
| 193 |
|
| #define SX_LG_CLASS 'B' /* Object is blessed, class name length >255 */ |
| 194 |
|
| #define SX_STORED 'X' /* End of object */ |
| 195 |
|
| |
| 196 |
|
| /* |
| 197 |
|
| * Limits between short/long length representation. |
| 198 |
|
| */ |
| 199 |
|
| |
| 200 |
|
| #define LG_SCALAR 255 /* Large scalar length limit */ |
| 201 |
|
| #define LG_BLESS 127 /* Large classname bless limit */ |
| 202 |
|
| |
| 203 |
|
| /* |
| 204 |
|
| * Operation types |
| 205 |
|
| */ |
| 206 |
|
| |
| 207 |
|
| #define ST_STORE 0x1 /* Store operation */ |
| 208 |
|
| #define ST_RETRIEVE 0x2 /* Retrieval operation */ |
| 209 |
|
| #define ST_CLONE 0x4 /* Deep cloning operation */ |
| 210 |
|
| |
| 211 |
|
| /* |
| 212 |
|
| * The following structure is used for hash table key retrieval. Since, when |
| 213 |
|
| * retrieving objects, we'll be facing blessed hash references, it's best |
| 214 |
|
| * to pre-allocate that buffer once and resize it as the need arises, never |
| 215 |
|
| * freeing it (keys will be saved away someplace else anyway, so even large |
| 216 |
|
| * keys are not enough a motivation to reclaim that space). |
| 217 |
|
| * |
| 218 |
|
| * This structure is also used for memory store/retrieve operations which |
| 219 |
|
| * happen in a fixed place before being malloc'ed elsewhere if persistence |
| 220 |
|
| * is required. Hence the aptr pointer. |
| 221 |
|
| */ |
| 222 |
|
| struct extendable { |
| 223 |
|
| char *arena; /* Will hold hash key strings, resized as needed */ |
| 224 |
|
| STRLEN asiz; /* Size of aforementioned buffer */ |
| 225 |
|
| char *aptr; /* Arena pointer, for in-place read/write ops */ |
| 226 |
|
| char *aend; /* First invalid address */ |
| 227 |
|
| }; |
| 228 |
|
| |
| 229 |
|
| /* |
| 230 |
|
| * At store time: |
| 231 |
|
| * A hash table records the objects which have already been stored. |
| 232 |
|
| * Those are referred to as SX_OBJECT in the file, and their "tag" (i.e. |
| 233 |
|
| * an arbitrary sequence number) is used to identify them. |
| 234 |
|
| * |
| 235 |
|
| * At retrieve time: |
| 236 |
|
| * An array table records the objects which have already been retrieved, |
| 237 |
|
| * as seen by the tag determined by counting the objects themselves. The |
| 238 |
|
| * reference to that retrieved object is kept in the table, and is returned |
| 239 |
|
| * when an SX_OBJECT is found bearing that same tag. |
| 240 |
|
| * |
| 241 |
|
| * The same processing is used to record "classname" for blessed objects: |
| 242 |
|
| * indexing by a hash at store time, and via an array at retrieve time. |
| 243 |
|
| */ |
| 244 |
|
| |
| 245 |
|
| typedef unsigned long stag_t; /* Used by pre-0.6 binary format */ |
| 246 |
|
| |
| 247 |
|
| /* |
| 248 |
|
| * Make the tag type 64-bit on 64-bit platforms. |
| 249 |
|
| * |
| 250 |
|
| * If the tag number is low enough it's stored as a 32-bit value, but |
| 251 |
|
| * with very large arrays and hashes it's possible to go over 2**32 |
| 252 |
|
| * scalars. |
| 253 |
|
| */ |
| 254 |
|
| |
| 255 |
|
| typedef STRLEN ntag_t; |
| 256 |
|
| |
| 257 |
|
| /* used for where_is_undef - marks an unset value */ |
| 258 |
|
| #define UNSET_NTAG_T (~(ntag_t)0) |
| 259 |
|
| |
| 260 |
|
| /* |
| 261 |
|
| * The following "thread-safe" related defines were contributed by |
| 262 |
|
| * Murray Nesbitt <murray@activestate.com> and integrated by RAM, who |
| 263 |
|
| * only renamed things a little bit to ensure consistency with surrounding |
| 264 |
|
| * code. -- RAM, 14/09/1999 |
| 265 |
|
| * |
| 266 |
|
| * The original patch suffered from the fact that the stcxt_t structure |
| 267 |
|
| * was global. Murray tried to minimize the impact on the code as much as |
| 268 |
|
| * possible. |
| 269 |
|
| * |
| 270 |
|
| * Starting with 0.7, Storable can be re-entrant, via the STORABLE_xxx hooks |
| 271 |
|
| * on objects. Therefore, the notion of context needs to be generalized, |
| 272 |
|
| * threading or not. |
| 273 |
|
| */ |
| 274 |
|
| |
| 275 |
|
| #define MY_VERSION "Storable(" XS_VERSION ")" |
| 276 |
|
| |
| 277 |
|
| |
| 278 |
|
| /* |
| 279 |
|
| * Conditional UTF8 support. |
| 280 |
|
| * |
| 281 |
|
| */ |
| 282 |
|
| #define STORE_UTF8STR(pv, len) STORE_PV_LEN(pv, len, SX_UTF8STR, SX_LUTF8STR) |
| 283 |
|
| #define HAS_UTF8_SCALARS |
| 284 |
|
| #ifdef HeKUTF8 |
| 285 |
|
| #define HAS_UTF8_HASHES |
| 286 |
|
| #define HAS_UTF8_ALL |
| 287 |
|
| #else |
| 288 |
|
| /* 5.6 perl has utf8 scalars but not hashes */ |
| 289 |
|
| #endif |
| 290 |
|
| #ifndef HAS_UTF8_ALL |
| 291 |
|
| #define UTF8_CROAK() CROAK(("Cannot retrieve UTF8 data in non-UTF8 perl")) |
| 292 |
|
| #endif |
| 293 |
|
| #ifndef SvWEAKREF |
| 294 |
|
| #define WEAKREF_CROAK() CROAK(("Cannot retrieve weak references in this perl")) |
| 295 |
|
| #endif |
| 296 |
|
| #ifndef SvVOK |
| 297 |
|
| #define VSTRING_CROAK() CROAK(("Cannot retrieve vstring in this perl")) |
| 298 |
|
| #endif |
| 299 |
|
| |
| 300 |
|
| #ifdef HvPLACEHOLDERS |
| 301 |
|
| #define HAS_RESTRICTED_HASHES |
| 302 |
|
| #else |
| 303 |
|
| #define HVhek_PLACEHOLD 0x200 |
| 304 |
|
| #define RESTRICTED_HASH_CROAK() CROAK(("Cannot retrieve restricted hash")) |
| 305 |
|
| #endif |
| 306 |
|
| |
| 307 |
|
| #ifdef HvHASKFLAGS |
| 308 |
|
| #define HAS_HASH_KEY_FLAGS |
| 309 |
|
| #endif |
| 310 |
|
| |
| 311 |
|
| #ifdef ptr_table_new |
| 312 |
|
| #define USE_PTR_TABLE |
| 313 |
|
| #endif |
| 314 |
|
| |
| 315 |
|
| /* do we need/want to clear padding on NVs? */ |
| 316 |
|
| #if defined(LONG_DOUBLEKIND) && defined(USE_LONG_DOUBLE) |
| 317 |
|
| # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \ |
| 318 |
|
| LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN |
| 319 |
|
| # define NV_PADDING (NVSIZE - 10) |
| 320 |
|
| # else |
| 321 |
|
| # define NV_PADDING 0 |
| 322 |
|
| # endif |
| 323 |
|
| #else |
| 324 |
|
| /* This is kind of a guess - it means we'll get an unneeded clear on 128-bit NV |
| 325 |
|
| but an upgraded perl will fix that |
| 326 |
|
| */ |
| 327 |
|
| # if NVSIZE > 8 |
| 328 |
|
| # define NV_CLEAR |
| 329 |
|
| # endif |
| 330 |
|
| # define NV_PADDING 0 |
| 331 |
|
| #endif |
| 332 |
|
| |
| 333 |
|
| typedef union { |
| 334 |
|
| NV nv; |
| 335 |
|
| U8 bytes[sizeof(NV)]; |
| 336 |
|
| } NV_bytes; |
| 337 |
|
| |
| 338 |
|
| /* Needed for 32bit with lengths > 2G - 4G, and 64bit */ |
| 339 |
|
| #if PTRSIZE > 4 |
| 340 |
|
| #define HAS_U64 |
| 341 |
|
| #endif |
| 342 |
|
| |
| 343 |
|
| /* |
| 344 |
|
| * Fields s_tainted and s_dirty are prefixed with s_ because Perl's include |
| 345 |
|
| * files remap tainted and dirty when threading is enabled. That's bad for |
| 346 |
|
| * perl to remap such common words. -- RAM, 29/09/00 |
| 347 |
|
| */ |
| 348 |
|
| |
| 349 |
|
| struct stcxt; |
| 350 |
|
| typedef struct stcxt { |
| 351 |
|
| int entry; /* flags recursion */ |
| 352 |
|
| int optype; /* type of traversal operation */ |
| 353 |
|
| /* which objects have been seen, store time. |
| 354 |
|
| tags are numbers, which are cast to (SV *) and stored directly */ |
| 355 |
|
| #ifdef USE_PTR_TABLE |
| 356 |
|
| /* use pseen if we have ptr_tables. We have to store tag+1, because |
| 357 |
|
| tag numbers start at 0, and we can't store (SV *) 0 in a ptr_table |
| 358 |
|
| without it being confused for a fetch lookup failure. */ |
| 359 |
|
| struct ptr_tbl *pseen; |
| 360 |
|
| /* Still need hseen for the 0.6 file format code. */ |
| 361 |
|
| #endif |
| 362 |
|
| HV *hseen; |
| 363 |
|
| AV *hook_seen; /* which SVs were returned by STORABLE_freeze() */ |
| 364 |
|
| AV *aseen; /* which objects have been seen, retrieve time */ |
| 365 |
|
| ntag_t where_is_undef; /* index in aseen of PL_sv_undef */ |
| 366 |
|
| HV *hclass; /* which classnames have been seen, store time */ |
| 367 |
|
| AV *aclass; /* which classnames have been seen, retrieve time */ |
| 368 |
|
| HV *hook; /* cache for hook methods per class name */ |
| 369 |
|
| IV tagnum; /* incremented at store time for each seen object */ |
| 370 |
|
| IV classnum; /* incremented at store time for each seen classname */ |
| 371 |
|
| int netorder; /* true if network order used */ |
| 372 |
|
| int s_tainted; /* true if input source is tainted, at retrieve time */ |
| 373 |
|
| int forgive_me; /* whether to be forgiving... */ |
| 374 |
|
| int deparse; /* whether to deparse code refs */ |
| 375 |
|
| SV *eval; /* whether to eval source code */ |
| 376 |
|
| int canonical; /* whether to store hashes sorted by key */ |
| 377 |
|
| #ifndef HAS_RESTRICTED_HASHES |
| 378 |
|
| int derestrict; /* whether to downgrade restricted hashes */ |
| 379 |
|
| #endif |
| 380 |
|
| #ifndef HAS_UTF8_ALL |
| 381 |
|
| int use_bytes; /* whether to bytes-ify utf8 */ |
| 382 |
|
| #endif |
| 383 |
|
| int accept_future_minor; /* croak immediately on future minor versions? */ |
| 384 |
|
| int s_dirty; /* context is dirty due to CROAK() -- can be cleaned */ |
| 385 |
|
| int membuf_ro; /* true means membuf is read-only and msaved is rw */ |
| 386 |
|
| struct extendable keybuf; /* for hash key retrieval */ |
| 387 |
|
| struct extendable membuf; /* for memory store/retrieve operations */ |
| 388 |
|
| struct extendable msaved; /* where potentially valid mbuf is saved */ |
| 389 |
|
| PerlIO *fio; /* where I/O are performed, NULL for memory */ |
| 390 |
|
| int ver_major; /* major of version for retrieved object */ |
| 391 |
|
| int ver_minor; /* minor of version for retrieved object */ |
| 392 |
|
| SV *(**retrieve_vtbl)(pTHX_ struct stcxt *, const char *); /* retrieve dispatch table */ |
| 393 |
|
| SV *prev; /* contexts chained backwards in real recursion */ |
| 394 |
|
| SV *my_sv; /* the blessed scalar who's SvPVX() I am */ |
| 395 |
|
| |
| 396 |
|
| /* recur_sv: |
| 397 |
|
| |
| 398 |
|
| A hashref of hashrefs or arrayref of arrayrefs is actually a |
| 399 |
|
| chain of four SVs, eg for an array ref containing an array ref: |
| 400 |
|
| |
| 401 |
|
| RV -> AV (element) -> RV -> AV |
| 402 |
|
| |
| 403 |
|
| To make this depth appear natural from a perl level we only |
| 404 |
|
| want to count this as two levels, so store_ref() stores it's RV |
| 405 |
|
| into recur_sv and store_array()/store_hash() will only count |
| 406 |
|
| that level if the AV/HV *isn't* recur_sv. |
| 407 |
|
| |
| 408 |
|
| We can't just have store_hash()/store_array() not count that |
| 409 |
|
| level, since it's possible for XS code to store an AV or HV |
| 410 |
|
| directly as an element (though perl code trying to access such |
| 411 |
|
| an object will generally croak.) |
| 412 |
|
| */ |
| 413 |
|
| SV *recur_sv; /* check only one recursive SV */ |
| 414 |
|
| int in_retrieve_overloaded; /* performance hack for retrieving overloaded objects */ |
| 415 |
|
| int flags; /* controls whether to bless or tie objects */ |
| 416 |
|
| IV recur_depth; /* avoid stack overflows RT #97526 */ |
| 417 |
|
| IV max_recur_depth; /* limit for recur_depth */ |
| 418 |
|
| IV max_recur_depth_hash; /* limit for recur_depth for hashes */ |
| 419 |
|
| #ifdef DEBUGME |
| 420 |
|
| int traceme; /* TRACEME() produces output */ |
| 421 |
|
| #endif |
| 422 |
|
| } stcxt_t; |
| 423 |
|
| |
| 424 |
|
| #define RECURSION_TOO_DEEP() \ |
| 425 |
|
| (cxt->max_recur_depth != -1 && ++cxt->recur_depth > cxt->max_recur_depth) |
| 426 |
|
| |
| 427 |
|
| /* There's cases where we need to check whether the hash recursion |
| 428 |
|
| limit has been reached without bumping the recursion levels, so the |
| 429 |
|
| hash check doesn't bump the depth. |
| 430 |
|
| */ |
| 431 |
|
| #define RECURSION_TOO_DEEP_HASH() \ |
| 432 |
|
| (cxt->max_recur_depth_hash != -1 && cxt->recur_depth > cxt->max_recur_depth_hash) |
| 433 |
|
| #define MAX_DEPTH_ERROR "Max. recursion depth with nested structures exceeded" |
| 434 |
|
| |
| 435 |
|
| static int storable_free(pTHX_ SV *sv, MAGIC* mg); |
| 436 |
|
| |
| 437 |
|
| static MGVTBL vtbl_storable = { |
| 438 |
|
| NULL, /* get */ |
| 439 |
|
| NULL, /* set */ |
| 440 |
|
| NULL, /* len */ |
| 441 |
|
| NULL, /* clear */ |
| 442 |
|
| storable_free, |
| 443 |
|
| #ifdef MGf_COPY |
| 444 |
|
| NULL, /* copy */ |
| 445 |
|
| #endif |
| 446 |
|
| #ifdef MGf_DUP |
| 447 |
|
| NULL, /* dup */ |
| 448 |
|
| #endif |
| 449 |
|
| #ifdef MGf_LOCAL |
| 450 |
|
| NULL /* local */ |
| 451 |
|
| #endif |
| 452 |
|
| }; |
| 453 |
|
| |
| 454 |
|
| /* From Digest::MD5. */ |
| 455 |
|
| #ifndef sv_magicext |
| 456 |
|
| # define sv_magicext(sv, obj, type, vtbl, name, namlen) \ |
| 457 |
|
| THX_sv_magicext(aTHX_ sv, obj, type, vtbl, name, namlen) |
| 458 |
|
| static MAGIC *THX_sv_magicext(pTHX_ |
| 459 |
|
| SV *sv, SV *obj, int type, |
| 460 |
|
| MGVTBL const *vtbl, char const *name, I32 namlen) |
| 461 |
|
| { |
| 462 |
|
| MAGIC *mg; |
| 463 |
|
| if (obj || namlen) |
| 464 |
|
| /* exceeded intended usage of this reserve implementation */ |
| 465 |
|
| return NULL; |
| 466 |
|
| Newxz(mg, 1, MAGIC); |
| 467 |
|
| mg->mg_virtual = (MGVTBL*)vtbl; |
| 468 |
|
| mg->mg_type = type; |
| 469 |
|
| mg->mg_ptr = (char *)name; |
| 470 |
|
| mg->mg_len = -1; |
| 471 |
|
| (void) SvUPGRADE(sv, SVt_PVMG); |
| 472 |
|
| mg->mg_moremagic = SvMAGIC(sv); |
| 473 |
|
| SvMAGIC_set(sv, mg); |
| 474 |
|
| SvMAGICAL_off(sv); |
| 475 |
|
| mg_magical(sv); |
| 476 |
|
| return mg; |
| 477 |
|
| } |
| 478 |
|
| #endif |
| 479 |
|
| |
| 480 |
|
| #define NEW_STORABLE_CXT_OBJ(cxt) \ |
| 481 |
|
| STMT_START { \ |
| 482 |
|
| SV *self = newSV(sizeof(stcxt_t) - 1); \ |
| 483 |
|
| SV *my_sv = newRV_noinc(self); \ |
| 484 |
|
| sv_magicext(self, NULL, PERL_MAGIC_ext, &vtbl_storable, NULL, 0); \ |
| 485 |
|
| cxt = (stcxt_t *)SvPVX(self); \ |
| 486 |
|
| Zero(cxt, 1, stcxt_t); \ |
| 487 |
|
| cxt->my_sv = my_sv; \ |
| 488 |
|
| } STMT_END |
| 489 |
|
| |
| 490 |
|
| #if defined(MULTIPLICITY) || defined(PERL_OBJECT) || defined(PERL_CAPI) |
| 491 |
|
| |
| 492 |
|
| #define dSTCXT_SV \ |
| 493 |
|
| SV *perinterp_sv = *hv_fetch(PL_modglobal, \ |
| 494 |
|
| MY_VERSION, sizeof(MY_VERSION)-1, TRUE) |
| 495 |
|
| |
| 496 |
|
| #define dSTCXT_PTR(T,name) \ |
| 497 |
|
| T name = ((perinterp_sv \ |
| 498 |
|
| && SvIOK(perinterp_sv) && SvIVX(perinterp_sv) \ |
| 499 |
|
| ? (T)SvPVX(SvRV(INT2PTR(SV*,SvIVX(perinterp_sv)))) : (T) 0)) |
| 500 |
|
| #define dSTCXT \ |
| 501 |
|
| dSTCXT_SV; \ |
| 502 |
|
| dSTCXT_PTR(stcxt_t *, cxt) |
| 503 |
|
| |
| 504 |
|
| #define INIT_STCXT \ |
| 505 |
|
| dSTCXT; \ |
| 506 |
|
| NEW_STORABLE_CXT_OBJ(cxt); \ |
| 507 |
|
| assert(perinterp_sv); \ |
| 508 |
|
| sv_setiv(perinterp_sv, PTR2IV(cxt->my_sv)) |
| 509 |
|
| |
| 510 |
|
| #define SET_STCXT(x) \ |
| 511 |
|
| STMT_START { \ |
| 512 |
|
| dSTCXT_SV; \ |
| 513 |
|
| sv_setiv(perinterp_sv, PTR2IV(x->my_sv)); \ |
| 514 |
|
| } STMT_END |
| 515 |
|
| |
| 516 |
|
| #else /* !MULTIPLICITY && !PERL_OBJECT && !PERL_CAPI */ |
| 517 |
|
| |
| 518 |
|
| static stcxt_t *Context_ptr = NULL; |
| 519 |
|
| #define dSTCXT stcxt_t *cxt = Context_ptr |
| 520 |
|
| #define SET_STCXT(x) Context_ptr = x |
| 521 |
|
| #define INIT_STCXT \ |
| 522 |
|
| dSTCXT; \ |
| 523 |
|
| NEW_STORABLE_CXT_OBJ(cxt); \ |
| 524 |
|
| SET_STCXT(cxt) |
| 525 |
|
| |
| 526 |
|
| |
| 527 |
|
| #endif /* MULTIPLICITY || PERL_OBJECT || PERL_CAPI */ |
| 528 |
|
| |
| 529 |
|
| /* |
| 530 |
|
| * KNOWN BUG: |
| 531 |
|
| * Croaking implies a memory leak, since we don't use setjmp/longjmp |
| 532 |
|
| * to catch the exit and free memory used during store or retrieve |
| 533 |
|
| * operations. This is not too difficult to fix, but I need to understand |
| 534 |
|
| * how Perl does it, and croaking is exceptional anyway, so I lack the |
| 535 |
|
| * motivation to do it. |
| 536 |
|
| * |
| 537 |
|
| * The current workaround is to mark the context as dirty when croaking, |
| 538 |
|
| * so that data structures can be freed whenever we renter Storable code |
| 539 |
|
| * (but only *then*: it's a workaround, not a fix). |
| 540 |
|
| * |
| 541 |
|
| * This is also imperfect, because we don't really know how far they trapped |
| 542 |
|
| * the croak(), and when we were recursing, we won't be able to clean anything |
| 543 |
|
| * but the topmost context stacked. |
| 544 |
|
| */ |
| 545 |
|
| |
| 546 |
|
| #define CROAK(x) STMT_START { cxt->s_dirty = 1; croak x; } STMT_END |
| 547 |
|
| |
| 548 |
|
| /* |
| 549 |
|
| * End of "thread-safe" related definitions. |
| 550 |
|
| */ |
| 551 |
|
| |
| 552 |
|
| /* |
| 553 |
|
| * LOW_32BITS |
| 554 |
|
| * |
| 555 |
|
| * Keep only the low 32 bits of a pointer (used for tags, which are not |
| 556 |
|
| * really pointers). |
| 557 |
|
| */ |
| 558 |
|
| |
| 559 |
|
| #if PTRSIZE <= 4 |
| 560 |
|
| #define LOW_32BITS(x) ((I32) (x)) |
| 561 |
|
| #else |
| 562 |
|
| #define LOW_32BITS(x) ((I32) ((STRLEN) (x) & 0xffffffffUL)) |
| 563 |
|
| #endif |
| 564 |
|
| |
| 565 |
|
| /* |
| 566 |
|
| * PTR2TAG(x) |
| 567 |
|
| * |
| 568 |
|
| * Convert a pointer into an ntag_t. |
| 569 |
|
| */ |
| 570 |
|
| |
| 571 |
|
| #define PTR2TAG(x) ((ntag_t)(x)) |
| 572 |
|
| |
| 573 |
|
| #define TAG2PTR(x, type) ((y)(x)) |
| 574 |
|
| |
| 575 |
|
| /* |
| 576 |
|
| * oI, oS, oC |
| 577 |
|
| * |
| 578 |
|
| * Hack for Crays, where sizeof(I32) == 8, and which are big-endians. |
| 579 |
|
| * Used in the WLEN and RLEN macros. |
| 580 |
|
| */ |
| 581 |
|
| |
| 582 |
|
| #if INTSIZE > 4 |
| 583 |
|
| #define oI(x) ((I32 *) ((char *) (x) + 4)) |
| 584 |
|
| #define oS(x) ((x) - 4) |
| 585 |
|
| #define oL(x) (x) |
| 586 |
|
| #define oC(x) (x = 0) |
| 587 |
|
| #define CRAY_HACK |
| 588 |
|
| #else |
| 589 |
|
| #define oI(x) (x) |
| 590 |
|
| #define oS(x) (x) |
| 591 |
|
| #define oL(x) (x) |
| 592 |
|
| #define oC(x) |
| 593 |
|
| #endif |
| 594 |
|
| |
| 595 |
|
| /* |
| 596 |
|
| * key buffer handling |
| 597 |
|
| */ |
| 598 |
|
| #define kbuf (cxt->keybuf).arena |
| 599 |
|
| #define ksiz (cxt->keybuf).asiz |
| 600 |
|
| #define KBUFINIT() \ |
| 601 |
|
| STMT_START { \ |
| 602 |
|
| if (!kbuf) { \ |
| 603 |
|
| TRACEME(("** allocating kbuf of 128 bytes")); \ |
| 604 |
|
| New(10003, kbuf, 128, char); \ |
| 605 |
|
| ksiz = 128; \ |
| 606 |
|
| } \ |
| 607 |
|
| } STMT_END |
| 608 |
|
| #define KBUFCHK(x) \ |
| 609 |
|
| STMT_START { \ |
| 610 |
|
| if (x >= ksiz) { \ |
| 611 |
|
| if (x >= I32_MAX) \ |
| 612 |
|
| CROAK(("Too large size > I32_MAX")); \ |
| 613 |
|
| TRACEME(("** extending kbuf to %d bytes (had %d)", \ |
| 614 |
|
| (int)(x+1), (int)ksiz)); \ |
| 615 |
|
| Renew(kbuf, x+1, char); \ |
| 616 |
|
| ksiz = x+1; \ |
| 617 |
|
| } \ |
| 618 |
|
| } STMT_END |
| 619 |
|
| |
| 620 |
|
| /* |
| 621 |
|
| * memory buffer handling |
| 622 |
|
| */ |
| 623 |
|
| #define mbase (cxt->membuf).arena |
| 624 |
|
| #define msiz (cxt->membuf).asiz |
| 625 |
|
| #define mptr (cxt->membuf).aptr |
| 626 |
|
| #define mend (cxt->membuf).aend |
| 627 |
|
| |
| 628 |
|
| #define MGROW (1 << 13) |
| 629 |
|
| #define MMASK (MGROW - 1) |
| 630 |
|
| |
| 631 |
|
| #define round_mgrow(x) \ |
| 632 |
|
| ((STRLEN) (((STRLEN) (x) + MMASK) & ~MMASK)) |
| 633 |
|
| #define trunc_int(x) \ |
| 634 |
|
| ((STRLEN) ((STRLEN) (x) & ~(sizeof(int)-1))) |
| 635 |
|
| #define int_aligned(x) \ |
| 636 |
|
| ((STRLEN)(x) == trunc_int(x)) |
| 637 |
|
| |
| 638 |
|
| #define MBUF_INIT(x) \ |
| 639 |
|
| STMT_START { \ |
| 640 |
|
| if (!mbase) { \ |
| 641 |
|
| TRACEME(("** allocating mbase of %d bytes", MGROW)); \ |
| 642 |
|
| New(10003, mbase, (int)MGROW, char); \ |
| 643 |
|
| msiz = (STRLEN)MGROW; \ |
| 644 |
|
| } \ |
| 645 |
|
| mptr = mbase; \ |
| 646 |
|
| if (x) \ |
| 647 |
|
| mend = mbase + x; \ |
| 648 |
|
| else \ |
| 649 |
|
| mend = mbase + msiz; \ |
| 650 |
|
| } STMT_END |
| 651 |
|
| |
| 652 |
|
| #define MBUF_TRUNC(x) mptr = mbase + x |
| 653 |
|
| #define MBUF_SIZE() (mptr - mbase) |
| 654 |
|
| |
| 655 |
|
| /* |
| 656 |
|
| * MBUF_SAVE_AND_LOAD |
| 657 |
|
| * MBUF_RESTORE |
| 658 |
|
| * |
| 659 |
|
| * Those macros are used in do_retrieve() to save the current memory |
| 660 |
|
| * buffer into cxt->msaved, before MBUF_LOAD() can be used to retrieve |
| 661 |
|
| * data from a string. |
| 662 |
|
| */ |
| 663 |
|
| #define MBUF_SAVE_AND_LOAD(in) \ |
| 664 |
|
| STMT_START { \ |
| 665 |
|
| ASSERT(!cxt->membuf_ro, ("mbase not already saved")); \ |
| 666 |
|
| cxt->membuf_ro = 1; \ |
| 667 |
|
| TRACEME(("saving mbuf")); \ |
| 668 |
|
| StructCopy(&cxt->membuf, &cxt->msaved, struct extendable); \ |
| 669 |
|
| MBUF_LOAD(in); \ |
| 670 |
|
| } STMT_END |
| 671 |
|
| |
| 672 |
|
| #define MBUF_RESTORE() \ |
| 673 |
|
| STMT_START { \ |
| 674 |
|
| ASSERT(cxt->membuf_ro, ("mbase is read-only")); \ |
| 675 |
|
| cxt->membuf_ro = 0; \ |
| 676 |
|
| TRACEME(("restoring mbuf")); \ |
| 677 |
|
| StructCopy(&cxt->msaved, &cxt->membuf, struct extendable); \ |
| 678 |
|
| } STMT_END |
| 679 |
|
| |
| 680 |
|
| /* |
| 681 |
|
| * Use SvPOKp(), because SvPOK() fails on tainted scalars. |
| 682 |
|
| * See store_scalar() for other usage of this workaround. |
| 683 |
|
| */ |
| 684 |
|
| #define MBUF_LOAD(v) \ |
| 685 |
|
| STMT_START { \ |
| 686 |
|
| ASSERT(cxt->membuf_ro, ("mbase is read-only")); \ |
| 687 |
|
| if (!SvPOKp(v)) \ |
| 688 |
|
| CROAK(("Not a scalar string")); \ |
| 689 |
|
| mptr = mbase = SvPV(v, msiz); \ |
| 690 |
|
| mend = mbase + msiz; \ |
| 691 |
|
| } STMT_END |
| 692 |
|
| |
| 693 |
|
| #define MBUF_XTEND(x) \ |
| 694 |
|
| STMT_START { \ |
| 695 |
|
| STRLEN nsz = (STRLEN) round_mgrow((x)+msiz); \ |
| 696 |
|
| STRLEN offset = mptr - mbase; \ |
| 697 |
|
| ASSERT(!cxt->membuf_ro, ("mbase is not read-only")); \ |
| 698 |
|
| TRACEME(("** extending mbase from %lu to %lu bytes (wants %lu new)", \ |
| 699 |
|
| (unsigned long)msiz, (unsigned long)nsz, (unsigned long)(x))); \ |
| 700 |
|
| Renew(mbase, nsz, char); \ |
| 701 |
|
| msiz = nsz; \ |
| 702 |
|
| mptr = mbase + offset; \ |
| 703 |
|
| mend = mbase + nsz; \ |
| 704 |
|
| } STMT_END |
| 705 |
|
| |
| 706 |
|
| #define MBUF_CHK(x) \ |
| 707 |
|
| STMT_START { \ |
| 708 |
|
| if ((mptr + (x)) > mend) \ |
| 709 |
|
| MBUF_XTEND(x); \ |
| 710 |
|
| } STMT_END |
| 711 |
|
| |
| 712 |
|
| #define MBUF_GETC(x) \ |
| 713 |
|
| STMT_START { \ |
| 714 |
|
| if (mptr < mend) \ |
| 715 |
|
| x = (int) (unsigned char) *mptr++; \ |
| 716 |
|
| else \ |
| 717 |
|
| return (SV *) 0; \ |
| 718 |
|
| } STMT_END |
| 719 |
|
| |
| 720 |
|
| #ifdef CRAY_HACK |
| 721 |
|
| #define MBUF_GETINT(x) \ |
| 722 |
|
| STMT_START { \ |
| 723 |
|
| oC(x); \ |
| 724 |
|
| if ((mptr + 4) <= mend) { \ |
| 725 |
|
| memcpy(oI(&x), mptr, 4); \ |
| 726 |
|
| mptr += 4; \ |
| 727 |
|
| } else \ |
| 728 |
|
| return (SV *) 0; \ |
| 729 |
|
| } STMT_END |
| 730 |
|
| #else |
| 731 |
|
| #define MBUF_GETINT(x) \ |
| 732 |
|
| STMT_START { \ |
| 733 |
|
| if ((mptr + sizeof(int)) <= mend) { \ |
| 734 |
|
| if (int_aligned(mptr)) \ |
| 735 |
|
| x = *(int *) mptr; \ |
| 736 |
|
| else \ |
| 737 |
|
| memcpy(&x, mptr, sizeof(int)); \ |
| 738 |
|
| mptr += sizeof(int); \ |
| 739 |
|
| } else \ |
| 740 |
|
| return (SV *) 0; \ |
| 741 |
|
| } STMT_END |
| 742 |
|
| #endif |
| 743 |
|
| |
| 744 |
|
| #define MBUF_READ(x,s) \ |
| 745 |
|
| STMT_START { \ |
| 746 |
|
| if ((mptr + (s)) <= mend) { \ |
| 747 |
|
| memcpy(x, mptr, s); \ |
| 748 |
|
| mptr += s; \ |
| 749 |
|
| } else \ |
| 750 |
|
| return (SV *) 0; \ |
| 751 |
|
| } STMT_END |
| 752 |
|
| |
| 753 |
|
| #define MBUF_SAFEREAD(x,s,z) \ |
| 754 |
|
| STMT_START { \ |
| 755 |
|
| if ((mptr + (s)) <= mend) { \ |
| 756 |
|
| memcpy(x, mptr, s); \ |
| 757 |
|
| mptr += s; \ |
| 758 |
|
| } else { \ |
| 759 |
|
| sv_free(z); \ |
| 760 |
|
| return (SV *) 0; \ |
| 761 |
|
| } \ |
| 762 |
|
| } STMT_END |
| 763 |
|
| |
| 764 |
|
| #define MBUF_SAFEPVREAD(x,s,z) \ |
| 765 |
|
| STMT_START { \ |
| 766 |
|
| if ((mptr + (s)) <= mend) { \ |
| 767 |
|
| memcpy(x, mptr, s); \ |
| 768 |
|
| mptr += s; \ |
| 769 |
|
| } else { \ |
| 770 |
|
| Safefree(z); \ |
| 771 |
|
| return (SV *) 0; \ |
| 772 |
|
| } \ |
| 773 |
|
| } STMT_END |
| 774 |
|
| |
| 775 |
|
| #define MBUF_PUTC(c) \ |
| 776 |
|
| STMT_START { \ |
| 777 |
|
| if (mptr < mend) \ |
| 778 |
|
| *mptr++ = (char) c; \ |
| 779 |
|
| else { \ |
| 780 |
|
| MBUF_XTEND(1); \ |
| 781 |
|
| *mptr++ = (char) c; \ |
| 782 |
|
| } \ |
| 783 |
|
| } STMT_END |
| 784 |
|
| |
| 785 |
|
| #ifdef CRAY_HACK |
| 786 |
|
| #define MBUF_PUTINT(i) \ |
| 787 |
|
| STMT_START { \ |
| 788 |
|
| MBUF_CHK(4); \ |
| 789 |
|
| memcpy(mptr, oI(&i), 4); \ |
| 790 |
|
| mptr += 4; \ |
| 791 |
|
| } STMT_END |
| 792 |
|
| #else |
| 793 |
|
| #define MBUF_PUTINT(i) \ |
| 794 |
|
| STMT_START { \ |
| 795 |
|
| MBUF_CHK(sizeof(int)); \ |
| 796 |
|
| if (int_aligned(mptr)) \ |
| 797 |
|
| *(int *) mptr = i; \ |
| 798 |
|
| else \ |
| 799 |
|
| memcpy(mptr, &i, sizeof(int)); \ |
| 800 |
|
| mptr += sizeof(int); \ |
| 801 |
|
| } STMT_END |
| 802 |
|
| #endif |
| 803 |
|
| |
| 804 |
|
| #define MBUF_PUTLONG(l) \ |
| 805 |
|
| STMT_START { \ |
| 806 |
|
| MBUF_CHK(8); \ |
| 807 |
|
| memcpy(mptr, &l, 8); \ |
| 808 |
|
| mptr += 8; \ |
| 809 |
|
| } STMT_END |
| 810 |
|
| #define MBUF_WRITE(x,s) \ |
| 811 |
|
| STMT_START { \ |
| 812 |
|
| MBUF_CHK(s); \ |
| 813 |
|
| memcpy(mptr, x, s); \ |
| 814 |
|
| mptr += s; \ |
| 815 |
|
| } STMT_END |
| 816 |
|
| |
| 817 |
|
| /* |
| 818 |
|
| * Possible return values for sv_type(). |
| 819 |
|
| */ |
| 820 |
|
| |
| 821 |
|
| #define svis_REF 0 |
| 822 |
|
| #define svis_SCALAR 1 |
| 823 |
|
| #define svis_ARRAY 2 |
| 824 |
|
| #define svis_HASH 3 |
| 825 |
|
| #define svis_TIED 4 |
| 826 |
|
| #define svis_TIED_ITEM 5 |
| 827 |
|
| #define svis_CODE 6 |
| 828 |
|
| #define svis_REGEXP 7 |
| 829 |
|
| #define svis_OTHER 8 |
| 830 |
|
| |
| 831 |
|
| /* |
| 832 |
|
| * Flags for SX_HOOK. |
| 833 |
|
| */ |
| 834 |
|
| |
| 835 |
|
| #define SHF_TYPE_MASK 0x03 |
| 836 |
|
| #define SHF_LARGE_CLASSLEN 0x04 |
| 837 |
|
| #define SHF_LARGE_STRLEN 0x08 |
| 838 |
|
| #define SHF_LARGE_LISTLEN 0x10 |
| 839 |
|
| #define SHF_IDX_CLASSNAME 0x20 |
| 840 |
|
| #define SHF_NEED_RECURSE 0x40 |
| 841 |
|
| #define SHF_HAS_LIST 0x80 |
| 842 |
|
| |
| 843 |
|
| /* |
| 844 |
|
| * Types for SX_HOOK (last 2 bits in flags). |
| 845 |
|
| */ |
| 846 |
|
| |
| 847 |
|
| #define SHT_SCALAR 0 |
| 848 |
|
| #define SHT_ARRAY 1 |
| 849 |
|
| #define SHT_HASH 2 |
| 850 |
|
| #define SHT_EXTRA 3 /* Read extra byte for type */ |
| 851 |
|
| |
| 852 |
|
| /* |
| 853 |
|
| * The following are held in the "extra byte"... |
| 854 |
|
| */ |
| 855 |
|
| |
| 856 |
|
| #define SHT_TSCALAR 4 /* 4 + 0 -- tied scalar */ |
| 857 |
|
| #define SHT_TARRAY 5 /* 4 + 1 -- tied array */ |
| 858 |
|
| #define SHT_THASH 6 /* 4 + 2 -- tied hash */ |
| 859 |
|
| |
| 860 |
|
| /* |
| 861 |
|
| * per hash flags for flagged hashes |
| 862 |
|
| */ |
| 863 |
|
| |
| 864 |
|
| #define SHV_RESTRICTED 0x01 |
| 865 |
|
| |
| 866 |
|
| /* |
| 867 |
|
| * per key flags for flagged hashes |
| 868 |
|
| */ |
| 869 |
|
| |
| 870 |
|
| #define SHV_K_UTF8 0x01 |
| 871 |
|
| #define SHV_K_WASUTF8 0x02 |
| 872 |
|
| #define SHV_K_LOCKED 0x04 |
| 873 |
|
| #define SHV_K_ISSV 0x08 |
| 874 |
|
| #define SHV_K_PLACEHOLDER 0x10 |
| 875 |
|
| |
| 876 |
|
| /* |
| 877 |
|
| * flags to allow blessing and/or tieing data the data we load |
| 878 |
|
| */ |
| 879 |
|
| #define FLAG_BLESS_OK 2 |
| 880 |
|
| #define FLAG_TIE_OK 4 |
| 881 |
|
| |
| 882 |
|
| /* |
| 883 |
|
| * Flags for SX_REGEXP. |
| 884 |
|
| */ |
| 885 |
|
| |
| 886 |
|
| #define SHR_U32_RE_LEN 0x01 |
| 887 |
|
| |
| 888 |
|
| /* |
| 889 |
|
| * Before 0.6, the magic string was "perl-store" (binary version number 0). |
| 890 |
|
| * |
| 891 |
|
| * Since 0.6 introduced many binary incompatibilities, the magic string has |
| 892 |
|
| * been changed to "pst0" to allow an old image to be properly retrieved by |
| 893 |
|
| * a newer Storable, but ensure a newer image cannot be retrieved with an |
| 894 |
|
| * older version. |
| 895 |
|
| * |
| 896 |
|
| * At 0.7, objects are given the ability to serialize themselves, and the |
| 897 |
|
| * set of markers is extended, backward compatibility is not jeopardized, |
| 898 |
|
| * so the binary version number could have remained unchanged. To correctly |
| 899 |
|
| * spot errors if a file making use of 0.7-specific extensions is given to |
| 900 |
|
| * 0.6 for retrieval, the binary version was moved to "2". And I'm introducing |
| 901 |
|
| * a "minor" version, to better track this kind of evolution from now on. |
| 902 |
|
| * |
| 903 |
|
| */ |
| 904 |
|
| static const char old_magicstr[] = "perl-store"; /* Magic number before 0.6 */ |
| 905 |
|
| static const char magicstr[] = "pst0"; /* Used as a magic number */ |
| 906 |
|
| |
| 907 |
|
| #define MAGICSTR_BYTES 'p','s','t','0' |
| 908 |
|
| #define OLDMAGICSTR_BYTES 'p','e','r','l','-','s','t','o','r','e' |
| 909 |
|
| |
| 910 |
|
| /* 5.6.x introduced the ability to have IVs as long long. |
| 911 |
|
| However, Configure still defined BYTEORDER based on the size of a long. |
| 912 |
|
| Storable uses the BYTEORDER value as part of the header, but doesn't |
| 913 |
|
| explicitly store sizeof(IV) anywhere in the header. Hence on 5.6.x built |
| 914 |
|
| with IV as long long on a platform that uses Configure (ie most things |
| 915 |
|
| except VMS and Windows) headers are identical for the different IV sizes, |
| 916 |
|
| despite the files containing some fields based on sizeof(IV) |
| 917 |
|
| Erk. Broken-ness. |
| 918 |
|
| 5.8 is consistent - the following redefinition kludge is only needed on |
| 919 |
|
| 5.6.x, but the interwork is needed on 5.8 while data survives in files |
| 920 |
|
| with the 5.6 header. |
| 921 |
|
| |
| 922 |
|
| */ |
| 923 |
|
| |
| 924 |
|
| #if defined (IVSIZE) && (IVSIZE == 8) && (LONGSIZE == 4) |
| 925 |
|
| #ifndef NO_56_INTERWORK_KLUDGE |
| 926 |
|
| #define USE_56_INTERWORK_KLUDGE |
| 927 |
|
| #endif |
| 928 |
|
| #if BYTEORDER == 0x1234 |
| 929 |
|
| #undef BYTEORDER |
| 930 |
|
| #define BYTEORDER 0x12345678 |
| 931 |
|
| #else |
| 932 |
|
| #if BYTEORDER == 0x4321 |
| 933 |
|
| #undef BYTEORDER |
| 934 |
|
| #define BYTEORDER 0x87654321 |
| 935 |
|
| #endif |
| 936 |
|
| #endif |
| 937 |
|
| #endif |
| 938 |
|
| |
| 939 |
|
| #if BYTEORDER == 0x1234 |
| 940 |
|
| #define BYTEORDER_BYTES '1','2','3','4' |
| 941 |
|
| #else |
| 942 |
|
| #if BYTEORDER == 0x12345678 |
| 943 |
|
| #define BYTEORDER_BYTES '1','2','3','4','5','6','7','8' |
| 944 |
|
| #ifdef USE_56_INTERWORK_KLUDGE |
| 945 |
|
| #define BYTEORDER_BYTES_56 '1','2','3','4' |
| 946 |
|
| #endif |
| 947 |
|
| #else |
| 948 |
|
| #if BYTEORDER == 0x87654321 |
| 949 |
|
| #define BYTEORDER_BYTES '8','7','6','5','4','3','2','1' |
| 950 |
|
| #ifdef USE_56_INTERWORK_KLUDGE |
| 951 |
|
| #define BYTEORDER_BYTES_56 '4','3','2','1' |
| 952 |
|
| #endif |
| 953 |
|
| #else |
| 954 |
|
| #if BYTEORDER == 0x4321 |
| 955 |
|
| #define BYTEORDER_BYTES '4','3','2','1' |
| 956 |
|
| #else |
| 957 |
|
| #error Unknown byteorder. Please append your byteorder to Storable.xs |
| 958 |
|
| #endif |
| 959 |
|
| #endif |
| 960 |
|
| #endif |
| 961 |
|
| #endif |
| 962 |
|
| |
| 963 |
|
| #ifndef INT32_MAX |
| 964 |
|
| # define INT32_MAX 2147483647 |
| 965 |
|
| #endif |
| 966 |
|
| #if IVSIZE > 4 && !defined(INT64_MAX) |
| 967 |
|
| # define INT64_MAX 9223372036854775807LL |
| 968 |
|
| #endif |
| 969 |
|
| |
| 970 |
|
| static const char byteorderstr[] = {BYTEORDER_BYTES, 0}; |
| 971 |
|
| #ifdef USE_56_INTERWORK_KLUDGE |
| 972 |
|
| static const char byteorderstr_56[] = {BYTEORDER_BYTES_56, 0}; |
| 973 |
|
| #endif |
| 974 |
|
| |
| 975 |
|
| #define STORABLE_BIN_MAJOR 2 /* Binary major "version" */ |
| 976 |
|
| #define STORABLE_BIN_MINOR 12 /* Binary minor "version" */ |
| 977 |
|
| |
| 978 |
|
| #if !defined (SvVOK) |
| 979 |
|
| /* |
| 980 |
|
| * Perl 5.6.0-5.8.0 can do weak references, but not vstring magic. |
| 981 |
|
| */ |
| 982 |
|
| #define STORABLE_BIN_WRITE_MINOR 8 |
| 983 |
|
| #elif PERL_VERSION_GE(5,19,0) |
| 984 |
|
| /* Perl 5.19 takes away the special meaning of PL_sv_undef in arrays. */ |
| 985 |
|
| /* With 3.x we added LOBJECT */ |
| 986 |
|
| #define STORABLE_BIN_WRITE_MINOR 11 |
| 987 |
|
| #else |
| 988 |
|
| #define STORABLE_BIN_WRITE_MINOR 9 |
| 989 |
|
| #endif |
| 990 |
|
| |
| 991 |
|
| #if PERL_VERSION_LT(5,8,1) |
| 992 |
|
| #define PL_sv_placeholder PL_sv_undef |
| 993 |
|
| #endif |
| 994 |
|
| |
| 995 |
|
| /* |
| 996 |
|
| * Useful store shortcuts... |
| 997 |
|
| */ |
| 998 |
|
| |
| 999 |
|
| /* |
| 1000 |
|
| * Note that if you put more than one mark for storing a particular |
| 1001 |
|
| * type of thing, *and* in the retrieve_foo() function you mark both |
| 1002 |
|
| * the thingy's you get off with SEEN(), you *must* increase the |
| 1003 |
|
| * tagnum with cxt->tagnum++ along with this macro! |
| 1004 |
|
| * - samv 20Jan04 |
| 1005 |
|
| */ |
| 1006 |
|
| #define PUTMARK(x) \ |
| 1007 |
|
| STMT_START { \ |
| 1008 |
|
| if (!cxt->fio) \ |
| 1009 |
|
| MBUF_PUTC(x); \ |
| 1010 |
|
| else if (PerlIO_putc(cxt->fio, x) == EOF) \ |
| 1011 |
|
| return -1; \ |
| 1012 |
|
| } STMT_END |
| 1013 |
|
| |
| 1014 |
|
| #define WRITE_I32(x) \ |
| 1015 |
|
| STMT_START { \ |
| 1016 |
|
| ASSERT(sizeof(x) == sizeof(I32), ("writing an I32")); \ |
| 1017 |
|
| if (!cxt->fio) \ |
| 1018 |
|
| MBUF_PUTINT(x); \ |
| 1019 |
|
| else if (PerlIO_write(cxt->fio, oI(&x), \ |
| 1020 |
|
| oS(sizeof(x))) != oS(sizeof(x))) \ |
| 1021 |
|
| return -1; \ |
| 1022 |
|
| } STMT_END |
| 1023 |
|
| |
| 1024 |
|
| #define WRITE_U64(x) \ |
| 1025 |
|
| STMT_START { \ |
| 1026 |
|
| ASSERT(sizeof(x) == sizeof(UV), ("writing an UV")); \ |
| 1027 |
|
| if (!cxt->fio) \ |
| 1028 |
|
| MBUF_PUTLONG(x); \ |
| 1029 |
|
| else if (PerlIO_write(cxt->fio, oL(&x), \ |
| 1030 |
|
| oS(sizeof(x))) != oS(sizeof(x))) \ |
| 1031 |
|
| return -1; \ |
| 1032 |
|
| } STMT_END |
| 1033 |
|
| |
| 1034 |
|
| #ifdef HAS_HTONL |
| 1035 |
|
| #define WLEN(x) \ |
| 1036 |
|
| STMT_START { \ |
| 1037 |
|
| ASSERT(sizeof(x) == sizeof(int), ("WLEN writing an int")); \ |
| 1038 |
|
| if (cxt->netorder) { \ |
| 1039 |
|
| int y = (int) htonl(x); \ |
| 1040 |
|
| if (!cxt->fio) \ |
| 1041 |
|
| MBUF_PUTINT(y); \ |
| 1042 |
|
| else if (PerlIO_write(cxt->fio,oI(&y),oS(sizeof(y))) != oS(sizeof(y))) \ |
| 1043 |
|
| return -1; \ |
| 1044 |
|
| } else { \ |
| 1045 |
|
| if (!cxt->fio) \ |
| 1046 |
|
| MBUF_PUTINT(x); \ |
| 1047 |
|
| else if (PerlIO_write(cxt->fio,oI(&x), \ |
| 1048 |
|
| oS(sizeof(x))) != oS(sizeof(x))) \ |
| 1049 |
|
| return -1; \ |
| 1050 |
|
| } \ |
| 1051 |
|
| } STMT_END |
| 1052 |
|
| |
| 1053 |
|
| # ifdef HAS_U64 |
| 1054 |
|
| |
| 1055 |
|
| #define W64LEN(x) \ |
| 1056 |
|
| STMT_START { \ |
| 1057 |
|
| ASSERT(sizeof(x) == 8, ("W64LEN writing a U64")); \ |
| 1058 |
|
| if (cxt->netorder) { \ |
| 1059 |
|
| U32 buf[2]; \ |
| 1060 |
|
| buf[1] = htonl(x & 0xffffffffUL); \ |
| 1061 |
|
| buf[0] = htonl(x >> 32); \ |
| 1062 |
|
| if (!cxt->fio) \ |
| 1063 |
|
| MBUF_PUTLONG(buf); \ |
| 1064 |
|
| else if (PerlIO_write(cxt->fio, buf, \ |
| 1065 |
|
| sizeof(buf)) != sizeof(buf)) \ |
| 1066 |
|
| return -1; \ |
| 1067 |
|
| } else { \ |
| 1068 |
|
| if (!cxt->fio) \ |
| 1069 |
|
| MBUF_PUTLONG(x); \ |
| 1070 |
|
| else if (PerlIO_write(cxt->fio,oI(&x), \ |
| 1071 |
|
| oS(sizeof(x))) != oS(sizeof(x))) \ |
| 1072 |
|
| return -1; \ |
| 1073 |
|
| } \ |
| 1074 |
|
| } STMT_END |
| 1075 |
|
| |
| 1076 |
|
| # else |
| 1077 |
|
| |
| 1078 |
|
| #define W64LEN(x) CROAK(("No 64bit UVs")) |
| 1079 |
|
| |
| 1080 |
|
| # endif |
| 1081 |
|
| |
| 1082 |
|
| #else |
| 1083 |
|
| #define WLEN(x) WRITE_I32(x) |
| 1084 |
|
| #ifdef HAS_U64 |
| 1085 |
|
| #define W64LEN(x) WRITE_U64(x) |
| 1086 |
|
| #else |
| 1087 |
|
| #define W64LEN(x) CROAK(("no 64bit UVs")) |
| 1088 |
|
| #endif |
| 1089 |
|
| #endif |
| 1090 |
|
| |
| 1091 |
|
| #define WRITE(x,y) \ |
| 1092 |
|
| STMT_START { \ |
| 1093 |
|
| if (!cxt->fio) \ |
| 1094 |
|
| MBUF_WRITE(x,y); \ |
| 1095 |
|
| else if (PerlIO_write(cxt->fio, x, y) != (SSize_t)y) \ |
| 1096 |
|
| return -1; \ |
| 1097 |
|
| } STMT_END |
| 1098 |
|
| |
| 1099 |
|
| #define STORE_PV_LEN(pv, len, small, large) \ |
| 1100 |
|
| STMT_START { \ |
| 1101 |
|
| if (len <= LG_SCALAR) { \ |
| 1102 |
|
| int ilen = (int) len; \ |
| 1103 |
|
| unsigned char clen = (unsigned char) len; \ |
| 1104 |
|
| PUTMARK(small); \ |
| 1105 |
|
| PUTMARK(clen); \ |
| 1106 |
|
| if (len) \ |
| 1107 |
|
| WRITE(pv, ilen); \ |
| 1108 |
|
| } else if (sizeof(len) > 4 && len > INT32_MAX) { \ |
| 1109 |
|
| PUTMARK(SX_LOBJECT); \ |
| 1110 |
|
| PUTMARK(large); \ |
| 1111 |
|
| W64LEN(len); \ |
| 1112 |
|
| WRITE(pv, len); \ |
| 1113 |
|
| } else { \ |
| 1114 |
|
| int ilen = (int) len; \ |
| 1115 |
|
| PUTMARK(large); \ |
| 1116 |
|
| WLEN(ilen); \ |
| 1117 |
|
| WRITE(pv, ilen); \ |
| 1118 |
|
| } \ |
| 1119 |
|
| } STMT_END |
| 1120 |
|
| |
| 1121 |
|
| #define STORE_SCALAR(pv, len) STORE_PV_LEN(pv, len, SX_SCALAR, SX_LSCALAR) |
| 1122 |
|
| |
| 1123 |
|
| /* |
| 1124 |
|
| * Store &PL_sv_undef in arrays without recursing through store(). We |
| 1125 |
|
| * actually use this to represent nonexistent elements, for historical |
| 1126 |
|
| * reasons. |
| 1127 |
|
| */ |
| 1128 |
|
| #define STORE_SV_UNDEF() \ |
| 1129 |
|
| STMT_START { \ |
| 1130 |
|
| cxt->tagnum++; \ |
| 1131 |
|
| PUTMARK(SX_SV_UNDEF); \ |
| 1132 |
|
| } STMT_END |
| 1133 |
|
| |
| 1134 |
|
| /* |
| 1135 |
|
| * Useful retrieve shortcuts... |
| 1136 |
|
| */ |
| 1137 |
|
| |
| 1138 |
|
| #define GETCHAR() \ |
| 1139 |
|
| (cxt->fio ? PerlIO_getc(cxt->fio) \ |
| 1140 |
|
| : (mptr >= mend ? EOF : (int) *mptr++)) |
| 1141 |
|
| |
| 1142 |
|
| #define GETMARK(x) \ |
| 1143 |
|
| STMT_START { \ |
| 1144 |
|
| if (!cxt->fio) \ |
| 1145 |
|
| MBUF_GETC(x); \ |
| 1146 |
|
| else if ((int) (x = PerlIO_getc(cxt->fio)) == EOF) \ |
| 1147 |
|
| return (SV *) 0; \ |
| 1148 |
|
| } STMT_END |
| 1149 |
|
| |
| 1150 |
|
| #define READ_I32(x) \ |
| 1151 |
|
| STMT_START { \ |
| 1152 |
|
| ASSERT(sizeof(x) == sizeof(I32), ("reading an I32")); \ |
| 1153 |
|
| oC(x); \ |
| 1154 |
|
| if (!cxt->fio) \ |
| 1155 |
|
| MBUF_GETINT(x); \ |
| 1156 |
|
| else if (PerlIO_read(cxt->fio, oI(&x), \ |
| 1157 |
|
| oS(sizeof(x))) != oS(sizeof(x))) \ |
| 1158 |
|
| return (SV *) 0; \ |
| 1159 |
|
| } STMT_END |
| 1160 |
|
| |
| 1161 |
|
| #ifdef HAS_NTOHL |
| 1162 |
|
| #define RLEN(x) \ |
| 1163 |
|
| STMT_START { \ |
| 1164 |
|
| oC(x); \ |
| 1165 |
|
| if (!cxt->fio) \ |
| 1166 |
|
| MBUF_GETINT(x); \ |
| 1167 |
|
| else if (PerlIO_read(cxt->fio, oI(&x), \ |
| 1168 |
|
| oS(sizeof(x))) != oS(sizeof(x))) \ |
| 1169 |
|
| return (SV *) 0; \ |
| 1170 |
|
| if (cxt->netorder) \ |
| 1171 |
|
| x = (int) ntohl(x); \ |
| 1172 |
|
| } STMT_END |
| 1173 |
|
| #else |
| 1174 |
|
| #define RLEN(x) READ_I32(x) |
| 1175 |
|
| #endif |
| 1176 |
|
| |
| 1177 |
|
| #define READ(x,y) \ |
| 1178 |
|
| STMT_START { \ |
| 1179 |
|
| if (!cxt->fio) \ |
| 1180 |
|
| MBUF_READ(x, y); \ |
| 1181 |
|
| else if (PerlIO_read(cxt->fio, x, y) != (SSize_t)y) \ |
| 1182 |
|
| return (SV *) 0; \ |
| 1183 |
|
| } STMT_END |
| 1184 |
|
| |
| 1185 |
|
| #define SAFEREAD(x,y,z) \ |
| 1186 |
|
| STMT_START { \ |
| 1187 |
|
| if (!cxt->fio) \ |
| 1188 |
|
| MBUF_SAFEREAD(x,y,z); \ |
| 1189 |
|
| else if (PerlIO_read(cxt->fio, x, y) != (SSize_t)y) { \ |
| 1190 |
|
| sv_free(z); \ |
| 1191 |
|
| return (SV *) 0; \ |
| 1192 |
|
| } \ |
| 1193 |
|
| } STMT_END |
| 1194 |
|
| |
| 1195 |
|
| #define SAFEPVREAD(x,y,z) \ |
| 1196 |
|
| STMT_START { \ |
| 1197 |
|
| if (!cxt->fio) \ |
| 1198 |
|
| MBUF_SAFEPVREAD(x,y,z); \ |
| 1199 |
|
| else if (PerlIO_read(cxt->fio, x, y) != y) { \ |
| 1200 |
|
| Safefree(z); \ |
| 1201 |
|
| return (SV *) 0; \ |
| 1202 |
|
| } \ |
| 1203 |
|
| } STMT_END |
| 1204 |
|
| |
| 1205 |
|
| #ifdef HAS_U64 |
| 1206 |
|
| |
| 1207 |
|
| # if defined(HAS_NTOHL) |
| 1208 |
|
| # define Sntohl(x) ntohl(x) |
| 1209 |
|
| # elif BYTEORDER == 0x87654321 || BYTEORDER == 0x4321 |
| 1210 |
|
| # define Sntohl(x) (x) |
| 1211 |
|
| # else |
| 1212 |
|
| static U32 Sntohl(U32 x) { |
| 1213 |
|
| return (((U8) x) << 24) + ((x & 0xFF00) << 8) |
| 1214 |
|
| + ((x & 0xFF0000) >> 8) + ((x & 0xFF000000) >> 24); |
| 1215 |
|
| } |
| 1216 |
|
| # endif |
| 1217 |
|
| |
| 1218 |
|
| # define READ_U64(x) \ |
| 1219 |
|
| STMT_START { \ |
| 1220 |
|
| ASSERT(sizeof(x) == 8, ("R64LEN reading a U64")); \ |
| 1221 |
|
| if (cxt->netorder) { \ |
| 1222 |
|
| U32 buf[2]; \ |
| 1223 |
|
| READ((void *)buf, sizeof(buf)); \ |
| 1224 |
|
| (x) = ((UV)Sntohl(buf[0]) << 32) + Sntohl(buf[1]); \ |
| 1225 |
|
| } \ |
| 1226 |
|
| else { \ |
| 1227 |
|
| READ(&(x), sizeof(x)); \ |
| 1228 |
|
| } \ |
| 1229 |
|
| } STMT_END |
| 1230 |
|
| |
| 1231 |
|
| #endif |
| 1232 |
|
| |
| 1233 |
|
| /* |
| 1234 |
|
| * SEEN() is used at retrieve time, to remember where object 'y', bearing a |
| 1235 |
|
| * given tag 'tagnum', has been retrieved. Next time we see an SX_OBJECT marker, |
| 1236 |
|
| * we'll therefore know where it has been retrieved and will be able to |
| 1237 |
|
| * share the same reference, as in the original stored memory image. |
| 1238 |
|
| * |
| 1239 |
|
| * We also need to bless objects ASAP for hooks (which may compute "ref $x" |
| 1240 |
|
| * on the objects given to STORABLE_thaw and expect that to be defined), and |
| 1241 |
|
| * also for overloaded objects (for which we might not find the stash if the |
| 1242 |
|
| * object is not blessed yet--this might occur for overloaded objects that |
| 1243 |
|
| * refer to themselves indirectly: if we blessed upon return from a sub |
| 1244 |
|
| * retrieve(), the SX_OBJECT marker we'd found could not have overloading |
| 1245 |
|
| * restored on it because the underlying object would not be blessed yet!). |
| 1246 |
|
| * |
| 1247 |
|
| * To achieve that, the class name of the last retrieved object is passed down |
| 1248 |
|
| * recursively, and the first SEEN() call for which the class name is not NULL |
| 1249 |
|
| * will bless the object. |
| 1250 |
|
| * |
| 1251 |
|
| * i should be true iff sv is immortal (ie PL_sv_yes, PL_sv_no or PL_sv_undef) |
| 1252 |
|
| * |
| 1253 |
|
| * SEEN0() is a short-cut where stash is always NULL. |
| 1254 |
|
| * |
| 1255 |
|
| * The _NN variants dont check for y being null |
| 1256 |
|
| */ |
| 1257 |
|
| #define SEEN0_NN(y,i) \ |
| 1258 |
|
| STMT_START { \ |
| 1259 |
|
| if (av_store(cxt->aseen, cxt->tagnum++, i ? (SV*)(y) \ |
| 1260 |
|
| : SvREFCNT_inc(y)) == 0) \ |
| 1261 |
|
| return (SV *) 0; \ |
| 1262 |
|
| TRACEME(("aseen(#%d) = 0x%" UVxf " (refcnt=%d)", \ |
| 1263 |
|
| (int)cxt->tagnum-1, \ |
| 1264 |
|
| PTR2UV(y), (int)SvREFCNT(y)-1)); \ |
| 1265 |
|
| } STMT_END |
| 1266 |
|
| |
| 1267 |
|
| #define SEEN0(y,i) \ |
| 1268 |
|
| STMT_START { \ |
| 1269 |
|
| if (!y) \ |
| 1270 |
|
| return (SV *) 0; \ |
| 1271 |
|
| SEEN0_NN(y,i); \ |
| 1272 |
|
| } STMT_END |
| 1273 |
|
| |
| 1274 |
|
| #define SEEN_NN(y,stash,i) \ |
| 1275 |
|
| STMT_START { \ |
| 1276 |
|
| SEEN0_NN(y,i); \ |
| 1277 |
|
| if (stash) \ |
| 1278 |
|
| BLESS((SV *)(y), (HV *)(stash)); \ |
| 1279 |
|
| } STMT_END |
| 1280 |
|
| |
| 1281 |
|
| #define SEEN(y,stash,i) \ |
| 1282 |
|
| STMT_START { \ |
| 1283 |
|
| if (!y) \ |
| 1284 |
|
| return (SV *) 0; \ |
| 1285 |
|
| SEEN_NN(y,stash, i); \ |
| 1286 |
|
| } STMT_END |
| 1287 |
|
| |
| 1288 |
|
| /* |
| 1289 |
|
| * Bless 's' in 'p', via a temporary reference, required by sv_bless(). |
| 1290 |
|
| * "A" magic is added before the sv_bless for overloaded classes, this avoids |
| 1291 |
|
| * an expensive call to S_reset_amagic in sv_bless. |
| 1292 |
|
| */ |
| 1293 |
|
| #define BLESS(s,stash) \ |
| 1294 |
|
| STMT_START { \ |
| 1295 |
|
| SV *ref; \ |
| 1296 |
|
| if (cxt->flags & FLAG_BLESS_OK) { \ |
| 1297 |
|
| TRACEME(("blessing 0x%" UVxf " in %s", PTR2UV(s), \ |
| 1298 |
|
| HvNAME_get(stash))); \ |
| 1299 |
|
| ref = newRV_noinc(s); \ |
| 1300 |
|
| if (cxt->in_retrieve_overloaded && Gv_AMG(stash)) { \ |
| 1301 |
|
| cxt->in_retrieve_overloaded = 0; \ |
| 1302 |
|
| SvAMAGIC_on(ref); \ |
| 1303 |
|
| } \ |
| 1304 |
|
| (void) sv_bless(ref, stash); \ |
| 1305 |
|
| SvRV_set(ref, NULL); \ |
| 1306 |
|
| SvREFCNT_dec(ref); \ |
| 1307 |
|
| } \ |
| 1308 |
|
| else { \ |
| 1309 |
|
| TRACEME(("not blessing 0x%" UVxf " in %s", PTR2UV(s), \ |
| 1310 |
|
| (HvNAME_get(stash)))); \ |
| 1311 |
|
| } \ |
| 1312 |
|
| } STMT_END |
| 1313 |
|
| /* |
| 1314 |
|
| * sort (used in store_hash) - conditionally use qsort when |
| 1315 |
|
| * sortsv is not available ( <= 5.6.1 ). |
| 1316 |
|
| */ |
| 1317 |
|
| |
| 1318 |
|
| #if PERL_VERSION_LT(5,7,0) |
| 1319 |
|
| |
| 1320 |
|
| #if defined(USE_ITHREADS) |
| 1321 |
|
| |
| 1322 |
|
| #define STORE_HASH_SORT \ |
| 1323 |
|
| ENTER; { \ |
| 1324 |
|
| PerlInterpreter *orig_perl = PERL_GET_CONTEXT; \ |
| 1325 |
|
| SAVESPTR(orig_perl); \ |
| 1326 |
|
| PERL_SET_CONTEXT(aTHX); \ |
| 1327 |
|
| qsort((char *) AvARRAY(av), len, sizeof(SV *), sortcmp);\ |
| 1328 |
|
| } LEAVE; |
| 1329 |
|
| |
| 1330 |
|
| #else /* ! USE_ITHREADS */ |
| 1331 |
|
| |
| 1332 |
|
| #define STORE_HASH_SORT \ |
| 1333 |
|
| qsort((char *) AvARRAY(av), len, sizeof(SV *), sortcmp); |
| 1334 |
|
| |
| 1335 |
|
| #endif /* USE_ITHREADS */ |
| 1336 |
|
| |
| 1337 |
|
| #else /* PERL >= 5.7.0 */ |
| 1338 |
|
| |
| 1339 |
|
| #define STORE_HASH_SORT \ |
| 1340 |
|
| sortsv(AvARRAY(av), len, Perl_sv_cmp); |
| 1341 |
|
| |
| 1342 |
|
| #endif /* PERL_VERSION_LT(5,7,0) */ |
| 1343 |
|
| |
| 1344 |
|
| static int store(pTHX_ stcxt_t *cxt, SV *sv); |
| 1345 |
|
| static SV *retrieve(pTHX_ stcxt_t *cxt, const char *cname); |
| 1346 |
|
| |
| 1347 |
|
| #define UNSEE() \ |
| 1348 |
|
| STMT_START { \ |
| 1349 |
|
| av_pop(cxt->aseen); \ |
| 1350 |
|
| cxt->tagnum--; \ |
| 1351 |
|
| } STMT_END |
| 1352 |
|
| |
| 1353 |
|
| /* |
| 1354 |
|
| * Dynamic dispatching table for SV store. |
| 1355 |
|
| */ |
| 1356 |
|
| |
| 1357 |
|
| static int store_ref(pTHX_ stcxt_t *cxt, SV *sv); |
| 1358 |
|
| static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv); |
| 1359 |
|
| static int store_array(pTHX_ stcxt_t *cxt, SV *av); |
| 1360 |
|
| static int store_hash(pTHX_ stcxt_t *cxt, SV *hv); |
| 1361 |
|
| static int store_tied(pTHX_ stcxt_t *cxt, SV *sv); |
| 1362 |
|
| static int store_tied_item(pTHX_ stcxt_t *cxt, SV *sv); |
| 1363 |
|
| static int store_code(pTHX_ stcxt_t *cxt, SV *cv); |
| 1364 |
|
| static int store_regexp(pTHX_ stcxt_t *cxt, SV *sv); |
| 1365 |
|
| static int store_other(pTHX_ stcxt_t *cxt, SV *sv); |
| 1366 |
|
| static int store_blessed(pTHX_ stcxt_t *cxt, SV *sv, int type, HV *pkg); |
| 1367 |
|
| |
| 1368 |
|
| typedef int (*sv_store_t)(pTHX_ stcxt_t *cxt, SV *sv); |
| 1369 |
|
| |
| 1370 |
|
| static const sv_store_t sv_store[] = { |
| 1371 |
|
| store_ref, /* svis_REF */ |
| 1372 |
|
| store_scalar, /* svis_SCALAR */ |
| 1373 |
|
| store_array, /* svis_ARRAY */ |
| 1374 |
|
| store_hash, /* svis_HASH */ |
| 1375 |
|
| store_tied, /* svis_TIED */ |
| 1376 |
|
| store_tied_item,/* svis_TIED_ITEM */ |
| 1377 |
|
| store_code, /* svis_CODE */ |
| 1378 |
|
| store_regexp, /* svis_REGEXP */ |
| 1379 |
|
| store_other, /* svis_OTHER */ |
| 1380 |
|
| }; |
| 1381 |
|
| |
| 1382 |
|
| #define SV_STORE(x) (*sv_store[x]) |
| 1383 |
|
| |
| 1384 |
|
| /* |
| 1385 |
|
| * Dynamic dispatching tables for SV retrieval. |
| 1386 |
|
| */ |
| 1387 |
|
| |
| 1388 |
|
| static SV *retrieve_lscalar(pTHX_ stcxt_t *cxt, const char *cname); |
| 1389 |
|
| static SV *retrieve_lutf8str(pTHX_ stcxt_t *cxt, const char *cname); |
| 1390 |
|
| static SV *old_retrieve_array(pTHX_ stcxt_t *cxt, const char *cname); |
| 1391 |
|
| static SV *old_retrieve_hash(pTHX_ stcxt_t *cxt, const char *cname); |
| 1392 |
|
| static SV *retrieve_ref(pTHX_ stcxt_t *cxt, const char *cname); |
| 1393 |
|
| static SV *retrieve_undef(pTHX_ stcxt_t *cxt, const char *cname); |
| 1394 |
|
| static SV *retrieve_integer(pTHX_ stcxt_t *cxt, const char *cname); |
| 1395 |
|
| static SV *retrieve_double(pTHX_ stcxt_t *cxt, const char *cname); |
| 1396 |
|
| static SV *retrieve_byte(pTHX_ stcxt_t *cxt, const char *cname); |
| 1397 |
|
| static SV *retrieve_netint(pTHX_ stcxt_t *cxt, const char *cname); |
| 1398 |
|
| static SV *retrieve_scalar(pTHX_ stcxt_t *cxt, const char *cname); |
| 1399 |
|
| static SV *retrieve_utf8str(pTHX_ stcxt_t *cxt, const char *cname); |
| 1400 |
|
| static SV *retrieve_tied_array(pTHX_ stcxt_t *cxt, const char *cname); |
| 1401 |
|
| static SV *retrieve_tied_hash(pTHX_ stcxt_t *cxt, const char *cname); |
| 1402 |
|
| static SV *retrieve_tied_scalar(pTHX_ stcxt_t *cxt, const char *cname); |
| 1403 |
|
| static SV *retrieve_other(pTHX_ stcxt_t *cxt, const char *cname); |
| 1404 |
|
| static SV *retrieve_lobject(pTHX_ stcxt_t *cxt, const char *cname); |
| 1405 |
|
| static SV *retrieve_regexp(pTHX_ stcxt_t *cxt, const char *cname); |
| 1406 |
|
| |
| 1407 |
|
| /* helpers for U64 lobjects */ |
| 1408 |
|
| |
| 1409 |
|
| static SV *get_lstring(pTHX_ stcxt_t *cxt, UV len, int isutf8, const char *cname); |
| 1410 |
|
| #ifdef HAS_U64 |
| 1411 |
|
| static SV *get_larray(pTHX_ stcxt_t *cxt, UV len, const char *cname); |
| 1412 |
|
| static SV *get_lhash(pTHX_ stcxt_t *cxt, UV len, int hash_flags, const char *cname); |
| 1413 |
|
| static int store_lhash(pTHX_ stcxt_t *cxt, HV *hv, unsigned char hash_flags); |
| 1414 |
|
| #endif |
| 1415 |
|
| static int store_hentry(pTHX_ stcxt_t *cxt, HV* hv, UV i, HEK *hek, SV *val, |
| 1416 |
|
| unsigned char hash_flags); |
| 1417 |
|
| |
| 1418 |
|
| typedef SV* (*sv_retrieve_t)(pTHX_ stcxt_t *cxt, const char *name); |
| 1419 |
|
| |
| 1420 |
|
| static const sv_retrieve_t sv_old_retrieve[] = { |
| 1421 |
|
| 0, /* SX_OBJECT -- entry unused dynamically */ |
| 1422 |
|
| (sv_retrieve_t)retrieve_lscalar, /* SX_LSCALAR */ |
| 1423 |
|
| (sv_retrieve_t)old_retrieve_array, /* SX_ARRAY -- for pre-0.6 binaries */ |
| 1424 |
|
| (sv_retrieve_t)old_retrieve_hash, /* SX_HASH -- for pre-0.6 binaries */ |
| 1425 |
|
| (sv_retrieve_t)retrieve_ref, /* SX_REF */ |
| 1426 |
|
| (sv_retrieve_t)retrieve_undef, /* SX_UNDEF */ |
| 1427 |
|
| (sv_retrieve_t)retrieve_integer, /* SX_INTEGER */ |
| 1428 |
|
| (sv_retrieve_t)retrieve_double, /* SX_DOUBLE */ |
| 1429 |
|
| (sv_retrieve_t)retrieve_byte, /* SX_BYTE */ |
| 1430 |
|
| (sv_retrieve_t)retrieve_netint, /* SX_NETINT */ |
| 1431 |
|
| (sv_retrieve_t)retrieve_scalar, /* SX_SCALAR */ |
| 1432 |
|
| (sv_retrieve_t)retrieve_tied_array, /* SX_TIED_ARRAY */ |
| 1433 |
|
| (sv_retrieve_t)retrieve_tied_hash, /* SX_TIED_HASH */ |
| 1434 |
|
| (sv_retrieve_t)retrieve_tied_scalar,/* SX_TIED_SCALAR */ |
| 1435 |
|
| (sv_retrieve_t)retrieve_other, /* SX_SV_UNDEF not supported */ |
| 1436 |
|
| (sv_retrieve_t)retrieve_other, /* SX_SV_YES not supported */ |
| 1437 |
|
| (sv_retrieve_t)retrieve_other, /* SX_SV_NO not supported */ |
| 1438 |
|
| (sv_retrieve_t)retrieve_other, /* SX_BLESS not supported */ |
| 1439 |
|
| (sv_retrieve_t)retrieve_other, /* SX_IX_BLESS not supported */ |
| 1440 |
|
| (sv_retrieve_t)retrieve_other, /* SX_HOOK not supported */ |
| 1441 |
|
| (sv_retrieve_t)retrieve_other, /* SX_OVERLOADED not supported */ |
| 1442 |
|
| (sv_retrieve_t)retrieve_other, /* SX_TIED_KEY not supported */ |
| 1443 |
|
| (sv_retrieve_t)retrieve_other, /* SX_TIED_IDX not supported */ |
| 1444 |
|
| (sv_retrieve_t)retrieve_other, /* SX_UTF8STR not supported */ |
| 1445 |
|
| (sv_retrieve_t)retrieve_other, /* SX_LUTF8STR not supported */ |
| 1446 |
|
| (sv_retrieve_t)retrieve_other, /* SX_FLAG_HASH not supported */ |
| 1447 |
|
| (sv_retrieve_t)retrieve_other, /* SX_CODE not supported */ |
| 1448 |
|
| (sv_retrieve_t)retrieve_other, /* SX_WEAKREF not supported */ |
| 1449 |
|
| (sv_retrieve_t)retrieve_other, /* SX_WEAKOVERLOAD not supported */ |
| 1450 |
|
| (sv_retrieve_t)retrieve_other, /* SX_VSTRING not supported */ |
| 1451 |
|
| (sv_retrieve_t)retrieve_other, /* SX_LVSTRING not supported */ |
| 1452 |
|
| (sv_retrieve_t)retrieve_other, /* SX_SVUNDEF_ELEM not supported */ |
| 1453 |
|
| (sv_retrieve_t)retrieve_other, /* SX_REGEXP */ |
| 1454 |
|
| (sv_retrieve_t)retrieve_other, /* SX_LOBJECT not supported */ |
| 1455 |
|
| (sv_retrieve_t)retrieve_other, /* SX_BOOLEAN_TRUE not supported */ |
| 1456 |
|
| (sv_retrieve_t)retrieve_other, /* SX_BOOLEAN_FALSE not supported */ |
| 1457 |
|
| (sv_retrieve_t)retrieve_other, /* SX_LAST */ |
| 1458 |
|
| }; |
| 1459 |
|
| |
| 1460 |
|
| static SV *retrieve_hook_common(pTHX_ stcxt_t *cxt, const char *cname, int large); |
| 1461 |
|
| |
| 1462 |
|
| static SV *retrieve_array(pTHX_ stcxt_t *cxt, const char *cname); |
| 1463 |
|
| static SV *retrieve_hash(pTHX_ stcxt_t *cxt, const char *cname); |
| 1464 |
|
| static SV *retrieve_sv_undef(pTHX_ stcxt_t *cxt, const char *cname); |
| 1465 |
|
| static SV *retrieve_sv_yes(pTHX_ stcxt_t *cxt, const char *cname); |
| 1466 |
|
| static SV *retrieve_sv_no(pTHX_ stcxt_t *cxt, const char *cname); |
| 1467 |
|
| static SV *retrieve_blessed(pTHX_ stcxt_t *cxt, const char *cname); |
| 1468 |
|
| static SV *retrieve_idx_blessed(pTHX_ stcxt_t *cxt, const char *cname); |
| 1469 |
|
| static SV *retrieve_hook(pTHX_ stcxt_t *cxt, const char *cname); |
| 1470 |
|
| static SV *retrieve_overloaded(pTHX_ stcxt_t *cxt, const char *cname); |
| 1471 |
|
| static SV *retrieve_tied_key(pTHX_ stcxt_t *cxt, const char *cname); |
| 1472 |
|
| static SV *retrieve_tied_idx(pTHX_ stcxt_t *cxt, const char *cname); |
| 1473 |
|
| static SV *retrieve_flag_hash(pTHX_ stcxt_t *cxt, const char *cname); |
| 1474 |
|
| static SV *retrieve_code(pTHX_ stcxt_t *cxt, const char *cname); |
| 1475 |
|
| static SV *retrieve_weakref(pTHX_ stcxt_t *cxt, const char *cname); |
| 1476 |
|
| static SV *retrieve_weakoverloaded(pTHX_ stcxt_t *cxt, const char *cname); |
| 1477 |
|
| static SV *retrieve_vstring(pTHX_ stcxt_t *cxt, const char *cname); |
| 1478 |
|
| static SV *retrieve_lvstring(pTHX_ stcxt_t *cxt, const char *cname); |
| 1479 |
|
| static SV *retrieve_svundef_elem(pTHX_ stcxt_t *cxt, const char *cname); |
| 1480 |
|
| static SV *retrieve_boolean_true(pTHX_ stcxt_t *cxt, const char *cname); |
| 1481 |
|
| static SV *retrieve_boolean_false(pTHX_ stcxt_t *cxt, const char *cname); |
| 1482 |
|
| |
| 1483 |
|
| static const sv_retrieve_t sv_retrieve[] = { |
| 1484 |
|
| 0, /* SX_OBJECT -- entry unused dynamically */ |
| 1485 |
|
| (sv_retrieve_t)retrieve_lscalar, /* SX_LSCALAR */ |
| 1486 |
|
| (sv_retrieve_t)retrieve_array, /* SX_ARRAY */ |
| 1487 |
|
| (sv_retrieve_t)retrieve_hash, /* SX_HASH */ |
| 1488 |
|
| (sv_retrieve_t)retrieve_ref, /* SX_REF */ |
| 1489 |
|
| (sv_retrieve_t)retrieve_undef, /* SX_UNDEF */ |
| 1490 |
|
| (sv_retrieve_t)retrieve_integer, /* SX_INTEGER */ |
| 1491 |
|
| (sv_retrieve_t)retrieve_double, /* SX_DOUBLE */ |
| 1492 |
|
| (sv_retrieve_t)retrieve_byte, /* SX_BYTE */ |
| 1493 |
|
| (sv_retrieve_t)retrieve_netint, /* SX_NETINT */ |
| 1494 |
|
| (sv_retrieve_t)retrieve_scalar, /* SX_SCALAR */ |
| 1495 |
|
| (sv_retrieve_t)retrieve_tied_array, /* SX_TIED_ARRAY */ |
| 1496 |
|
| (sv_retrieve_t)retrieve_tied_hash, /* SX_TIED_HASH */ |
| 1497 |
|
| (sv_retrieve_t)retrieve_tied_scalar,/* SX_TIED_SCALAR */ |
| 1498 |
|
| (sv_retrieve_t)retrieve_sv_undef, /* SX_SV_UNDEF */ |
| 1499 |
|
| (sv_retrieve_t)retrieve_sv_yes, /* SX_SV_YES */ |
| 1500 |
|
| (sv_retrieve_t)retrieve_sv_no, /* SX_SV_NO */ |
| 1501 |
|
| (sv_retrieve_t)retrieve_blessed, /* SX_BLESS */ |
| 1502 |
|
| (sv_retrieve_t)retrieve_idx_blessed,/* SX_IX_BLESS */ |
| 1503 |
|
| (sv_retrieve_t)retrieve_hook, /* SX_HOOK */ |
| 1504 |
|
| (sv_retrieve_t)retrieve_overloaded, /* SX_OVERLOAD */ |
| 1505 |
|
| (sv_retrieve_t)retrieve_tied_key, /* SX_TIED_KEY */ |
| 1506 |
|
| (sv_retrieve_t)retrieve_tied_idx, /* SX_TIED_IDX */ |
| 1507 |
|
| (sv_retrieve_t)retrieve_utf8str, /* SX_UTF8STR */ |
| 1508 |
|
| (sv_retrieve_t)retrieve_lutf8str, /* SX_LUTF8STR */ |
| 1509 |
|
| (sv_retrieve_t)retrieve_flag_hash, /* SX_HASH */ |
| 1510 |
|
| (sv_retrieve_t)retrieve_code, /* SX_CODE */ |
| 1511 |
|
| (sv_retrieve_t)retrieve_weakref, /* SX_WEAKREF */ |
| 1512 |
|
| (sv_retrieve_t)retrieve_weakoverloaded,/* SX_WEAKOVERLOAD */ |
| 1513 |
|
| (sv_retrieve_t)retrieve_vstring, /* SX_VSTRING */ |
| 1514 |
|
| (sv_retrieve_t)retrieve_lvstring, /* SX_LVSTRING */ |
| 1515 |
|
| (sv_retrieve_t)retrieve_svundef_elem,/* SX_SVUNDEF_ELEM */ |
| 1516 |
|
| (sv_retrieve_t)retrieve_regexp, /* SX_REGEXP */ |
| 1517 |
|
| (sv_retrieve_t)retrieve_lobject, /* SX_LOBJECT */ |
| 1518 |
|
| (sv_retrieve_t)retrieve_boolean_true, /* SX_BOOLEAN_TRUE */ |
| 1519 |
|
| (sv_retrieve_t)retrieve_boolean_false, /* SX_BOOLEAN_FALSE */ |
| 1520 |
|
| (sv_retrieve_t)retrieve_other, /* SX_LAST */ |
| 1521 |
|
| }; |
| 1522 |
|
| |
| 1523 |
|
| #define RETRIEVE(c,x) ((x) >= SX_LAST ? retrieve_other : *(c)->retrieve_vtbl[x]) |
| 1524 |
|
| |
| 1525 |
|
| static SV *mbuf2sv(pTHX); |
| 1526 |
|
| |
| 1527 |
|
| /*** |
| 1528 |
|
| *** Context management. |
| 1529 |
|
| ***/ |
| 1530 |
|
| |
| 1531 |
|
| /* |
| 1532 |
|
| * init_perinterp |
| 1533 |
|
| * |
| 1534 |
|
| * Called once per "thread" (interpreter) to initialize some global context. |
| 1535 |
|
| */ |
| 1536 |
46 |
| static void init_perinterp(pTHX) |
| 1537 |
|
| { |
| 1538 |
46 |
| INIT_STCXT; |
| 1539 |
|
| INIT_TRACEME; |
| 1540 |
46 |
| cxt->netorder = 0; /* true if network order used */ |
| 1541 |
46 |
| cxt->forgive_me = -1; /* whether to be forgiving... */ |
| 1542 |
46 |
| cxt->accept_future_minor = -1; /* would otherwise occur too late */ |
| 1543 |
46 |
| } |
| 1544 |
|
| |
| 1545 |
|
| /* |
| 1546 |
|
| * reset_context |
| 1547 |
|
| * |
| 1548 |
|
| * Called at the end of every context cleaning, to perform common reset |
| 1549 |
|
| * operations. |
| 1550 |
|
| */ |
| 1551 |
1353 |
| static void reset_context(stcxt_t *cxt) |
| 1552 |
|
| { |
| 1553 |
1353 |
| cxt->entry = 0; |
| 1554 |
1353 |
| cxt->s_dirty = 0; |
| 1555 |
1353 |
| cxt->recur_sv = NULL; |
| 1556 |
1353 |
| cxt->recur_depth = 0; |
| 1557 |
1353 |
| cxt->optype &= ~(ST_STORE|ST_RETRIEVE); /* Leave ST_CLONE alone */ |
| 1558 |
1353 |
| } |
| 1559 |
|
| |
| 1560 |
|
| /* |
| 1561 |
|
| * init_store_context |
| 1562 |
|
| * |
| 1563 |
|
| * Initialize a new store context for real recursion. |
| 1564 |
|
| */ |
| 1565 |
588 |
| static void init_store_context(pTHX_ |
| 1566 |
|
| stcxt_t *cxt, |
| 1567 |
|
| PerlIO *f, |
| 1568 |
|
| int optype, |
| 1569 |
|
| int network_order) |
| 1570 |
|
| { |
| 1571 |
|
| INIT_TRACEME; |
| 1572 |
|
| |
| 1573 |
|
| TRACEME(("init_store_context")); |
| 1574 |
|
| |
| 1575 |
588 |
| cxt->netorder = network_order; |
| 1576 |
588 |
| cxt->forgive_me = -1; /* Fetched from perl if needed */ |
| 1577 |
588 |
| cxt->deparse = -1; /* Idem */ |
| 1578 |
588 |
| cxt->eval = NULL; /* Idem */ |
| 1579 |
588 |
| cxt->canonical = -1; /* Idem */ |
| 1580 |
588 |
| cxt->tagnum = -1; /* Reset tag numbers */ |
| 1581 |
588 |
| cxt->classnum = -1; /* Reset class numbers */ |
| 1582 |
588 |
| cxt->fio = f; /* Where I/O are performed */ |
| 1583 |
588 |
| cxt->optype = optype; /* A store, or a deep clone */ |
| 1584 |
588 |
| cxt->entry = 1; /* No recursion yet */ |
| 1585 |
|
| |
| 1586 |
|
| /* |
| 1587 |
|
| * The 'hseen' table is used to keep track of each SV stored and their |
| 1588 |
|
| * associated tag numbers is special. It is "abused" because the |
| 1589 |
|
| * values stored are not real SV, just integers cast to (SV *), |
| 1590 |
|
| * which explains the freeing below. |
| 1591 |
|
| * |
| 1592 |
|
| * It is also one possible bottleneck to achieve good storing speed, |
| 1593 |
|
| * so the "shared keys" optimization is turned off (unlikely to be |
| 1594 |
|
| * of any use here), and the hash table is "pre-extended". Together, |
| 1595 |
|
| * those optimizations increase the throughput by 12%. |
| 1596 |
|
| */ |
| 1597 |
|
| |
| 1598 |
|
| #ifdef USE_PTR_TABLE |
| 1599 |
588 |
| cxt->pseen = ptr_table_new(); |
| 1600 |
588 |
| cxt->hseen = 0; |
| 1601 |
|
| #else |
| 1602 |
|
| cxt->hseen = newHV(); /* Table where seen objects are stored */ |
| 1603 |
|
| HvSHAREKEYS_off(cxt->hseen); |
| 1604 |
|
| #endif |
| 1605 |
|
| /* |
| 1606 |
|
| * The following does not work well with perl5.004_04, and causes |
| 1607 |
|
| * a core dump later on, in a completely unrelated spot, which |
| 1608 |
|
| * makes me think there is a memory corruption going on. |
| 1609 |
|
| * |
| 1610 |
|
| * Calling hv_ksplit(hseen, HBUCKETS) instead of manually hacking |
| 1611 |
|
| * it below does not make any difference. It seems to work fine |
| 1612 |
|
| * with perl5.004_68 but given the probable nature of the bug, |
| 1613 |
|
| * that does not prove anything. |
| 1614 |
|
| * |
| 1615 |
|
| * It's a shame because increasing the amount of buckets raises |
| 1616 |
|
| * store() throughput by 5%, but until I figure this out, I can't |
| 1617 |
|
| * allow for this to go into production. |
| 1618 |
|
| * |
| 1619 |
|
| * It is reported fixed in 5.005, hence the #if. |
| 1620 |
|
| */ |
| 1621 |
|
| #define HBUCKETS 4096 /* Buckets for %hseen */ |
| 1622 |
|
| #ifndef USE_PTR_TABLE |
| 1623 |
|
| HvMAX(cxt->hseen) = HBUCKETS - 1; /* keys %hseen = $HBUCKETS; */ |
| 1624 |
|
| #endif |
| 1625 |
|
| |
| 1626 |
|
| /* |
| 1627 |
|
| * The 'hclass' hash uses the same settings as 'hseen' above, but it is |
| 1628 |
|
| * used to assign sequential tags (numbers) to class names for blessed |
| 1629 |
|
| * objects. |
| 1630 |
|
| * |
| 1631 |
|
| * We turn the shared key optimization on. |
| 1632 |
|
| */ |
| 1633 |
|
| |
| 1634 |
588 |
| cxt->hclass = newHV(); /* Where seen classnames are stored */ |
| 1635 |
|
| |
| 1636 |
588 |
| HvMAX(cxt->hclass) = HBUCKETS - 1; /* keys %hclass = $HBUCKETS; */ |
| 1637 |
|
| |
| 1638 |
|
| /* |
| 1639 |
|
| * The 'hook' hash table is used to keep track of the references on |
| 1640 |
|
| * the STORABLE_freeze hook routines, when found in some class name. |
| 1641 |
|
| * |
| 1642 |
|
| * It is assumed that the inheritance tree will not be changed during |
| 1643 |
|
| * storing, and that no new method will be dynamically created by the |
| 1644 |
|
| * hooks. |
| 1645 |
|
| */ |
| 1646 |
|
| |
| 1647 |
588 |
| cxt->hook = newHV(); /* Table where hooks are cached */ |
| 1648 |
|
| |
| 1649 |
|
| /* |
| 1650 |
|
| * The 'hook_seen' array keeps track of all the SVs returned by |
| 1651 |
|
| * STORABLE_freeze hooks for us to serialize, so that they are not |
| 1652 |
|
| * reclaimed until the end of the serialization process. Each SV is |
| 1653 |
|
| * only stored once, the first time it is seen. |
| 1654 |
|
| */ |
| 1655 |
|
| |
| 1656 |
588 |
| cxt->hook_seen = newAV(); /* Lists SVs returned by STORABLE_freeze */ |
| 1657 |
|
| |
| 1658 |
588 |
| cxt->max_recur_depth = SvIV(get_sv("Storable::recursion_limit", GV_ADD)); |
| 1659 |
588 |
| cxt->max_recur_depth_hash = SvIV(get_sv("Storable::recursion_limit_hash", GV_ADD)); |
| 1660 |
588 |
| } |
| 1661 |
|
| |
| 1662 |
|
| /* |
| 1663 |
|
| * clean_store_context |
| 1664 |
|
| * |
| 1665 |
|
| * Clean store context by |
| 1666 |
|
| */ |
| 1667 |
584 |
| static void clean_store_context(pTHX_ stcxt_t *cxt) |
| 1668 |
|
| { |
| 1669 |
|
| HE *he; |
| 1670 |
|
| |
| 1671 |
|
| TRACEMED(("clean_store_context")); |
| 1672 |
|
| |
| 1673 |
|
| ASSERT(cxt->optype & ST_STORE, ("was performing a store()")); |
| 1674 |
|
| |
| 1675 |
|
| /* |
| 1676 |
|
| * Insert real values into hashes where we stored faked pointers. |
| 1677 |
|
| */ |
| 1678 |
|
| |
| 1679 |
|
| #ifndef USE_PTR_TABLE |
| 1680 |
|
| if (cxt->hseen) { |
| 1681 |
|
| hv_iterinit(cxt->hseen); |
| 1682 |
|
| while ((he = hv_iternext(cxt->hseen))) /* Extra () for -Wall */ |
| 1683 |
|
| HeVAL(he) = &PL_sv_undef; |
| 1684 |
|
| } |
| 1685 |
|
| #endif |
| 1686 |
|
| |
| 1687 |
584 |
▶ | if (cxt->hclass) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->hclass) { |
584 |
0 |
584 |
|
| 1688 |
584 |
| hv_iterinit(cxt->hclass); |
| 1689 |
805 |
▶ | while ((he = hv_iternext(cxt->hclass))) /* Extra () for -Wall */ |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(cxt->hclass))) /* Extra () for -Wall */ |
221 |
584 |
805 |
|
| 1690 |
221 |
| HeVAL(he) = &PL_sv_undef; |
| 1691 |
|
| } |
| 1692 |
|
| |
| 1693 |
|
| /* |
| 1694 |
|
| * And now dispose of them... |
| 1695 |
|
| * |
| 1696 |
|
| * The surrounding if() protection has been added because there might be |
| 1697 |
|
| * some cases where this routine is called more than once, during |
| 1698 |
|
| * exceptional events. This was reported by Marc Lehmann when Storable |
| 1699 |
|
| * is executed from mod_perl, and the fix was suggested by him. |
| 1700 |
|
| * -- RAM, 20/12/2000 |
| 1701 |
|
| */ |
| 1702 |
|
| |
| 1703 |
|
| #ifdef USE_PTR_TABLE |
| 1704 |
584 |
▶ | if (cxt->pseen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->pseen) { |
584 |
0 |
584 |
|
| 1705 |
584 |
| struct ptr_tbl *pseen = cxt->pseen; |
| 1706 |
584 |
| cxt->pseen = 0; |
| 1707 |
584 |
| ptr_table_free(pseen); |
| 1708 |
|
| } |
| 1709 |
|
| assert(!cxt->hseen); |
| 1710 |
|
| #else |
| 1711 |
|
| if (cxt->hseen) { |
| 1712 |
|
| HV *hseen = cxt->hseen; |
| 1713 |
|
| cxt->hseen = 0; |
| 1714 |
|
| hv_undef(hseen); |
| 1715 |
|
| sv_free((SV *) hseen); |
| 1716 |
|
| } |
| 1717 |
|
| #endif |
| 1718 |
|
| |
| 1719 |
584 |
▶ | if (cxt->hclass) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->hclass) { |
584 |
0 |
584 |
|
| 1720 |
584 |
| HV *hclass = cxt->hclass; |
| 1721 |
584 |
| cxt->hclass = 0; |
| 1722 |
584 |
| hv_undef(hclass); |
| 1723 |
584 |
| sv_free((SV *) hclass); |
| 1724 |
|
| } |
| 1725 |
|
| |
| 1726 |
584 |
▶ | if (cxt->hook) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->hook) { |
584 |
0 |
584 |
|
| 1727 |
584 |
| HV *hook = cxt->hook; |
| 1728 |
584 |
| cxt->hook = 0; |
| 1729 |
584 |
| hv_undef(hook); |
| 1730 |
584 |
| sv_free((SV *) hook); |
| 1731 |
|
| } |
| 1732 |
|
| |
| 1733 |
584 |
▶ | if (cxt->hook_seen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->hook_seen) { |
584 |
0 |
584 |
|
| 1734 |
584 |
| AV *hook_seen = cxt->hook_seen; |
| 1735 |
584 |
| cxt->hook_seen = 0; |
| 1736 |
584 |
| av_undef(hook_seen); |
| 1737 |
584 |
| sv_free((SV *) hook_seen); |
| 1738 |
|
| } |
| 1739 |
|
| |
| 1740 |
584 |
| cxt->forgive_me = -1; /* Fetched from perl if needed */ |
| 1741 |
584 |
| cxt->deparse = -1; /* Idem */ |
| 1742 |
584 |
▶ | if (cxt->eval) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->eval) { |
0 |
584 |
584 |
|
| 1743 |
0 |
| SvREFCNT_dec(cxt->eval); |
| 1744 |
|
| } |
| 1745 |
584 |
| cxt->eval = NULL; /* Idem */ |
| 1746 |
584 |
| cxt->canonical = -1; /* Idem */ |
| 1747 |
|
| |
| 1748 |
584 |
| reset_context(cxt); |
| 1749 |
584 |
| } |
| 1750 |
|
| |
| 1751 |
|
| /* |
| 1752 |
|
| * init_retrieve_context |
| 1753 |
|
| * |
| 1754 |
|
| * Initialize a new retrieve context for real recursion. |
| 1755 |
|
| */ |
| 1756 |
706 |
| static void init_retrieve_context(pTHX_ |
| 1757 |
|
| stcxt_t *cxt, int optype, int is_tainted) |
| 1758 |
|
| { |
| 1759 |
|
| INIT_TRACEME; |
| 1760 |
|
| |
| 1761 |
|
| TRACEME(("init_retrieve_context")); |
| 1762 |
|
| |
| 1763 |
|
| /* |
| 1764 |
|
| * The hook hash table is used to keep track of the references on |
| 1765 |
|
| * the STORABLE_thaw hook routines, when found in some class name. |
| 1766 |
|
| * |
| 1767 |
|
| * It is assumed that the inheritance tree will not be changed during |
| 1768 |
|
| * storing, and that no new method will be dynamically created by the |
| 1769 |
|
| * hooks. |
| 1770 |
|
| */ |
| 1771 |
|
| |
| 1772 |
706 |
| cxt->hook = newHV(); /* Caches STORABLE_thaw */ |
| 1773 |
|
| |
| 1774 |
|
| #ifdef USE_PTR_TABLE |
| 1775 |
706 |
| cxt->pseen = 0; |
| 1776 |
|
| #endif |
| 1777 |
|
| |
| 1778 |
|
| /* |
| 1779 |
|
| * If retrieving an old binary version, the cxt->retrieve_vtbl variable |
| 1780 |
|
| * was set to sv_old_retrieve. We'll need a hash table to keep track of |
| 1781 |
|
| * the correspondence between the tags and the tag number used by the |
| 1782 |
|
| * new retrieve routines. |
| 1783 |
|
| */ |
| 1784 |
|
| |
| 1785 |
1412 |
| cxt->hseen = (((void*)cxt->retrieve_vtbl == (void*)sv_old_retrieve) |
| 1786 |
706 |
▶ | ? newHV() : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| ? newHV() : 0); |
2 |
704 |
706 |
|
| 1787 |
|
| |
| 1788 |
706 |
| cxt->aseen = newAV(); /* Where retrieved objects are kept */ |
| 1789 |
706 |
| cxt->where_is_undef = UNSET_NTAG_T; /* Special case for PL_sv_undef */ |
| 1790 |
706 |
| cxt->aclass = newAV(); /* Where seen classnames are kept */ |
| 1791 |
706 |
| cxt->tagnum = 0; /* Have to count objects... */ |
| 1792 |
706 |
| cxt->classnum = 0; /* ...and class names as well */ |
| 1793 |
706 |
| cxt->optype = optype; |
| 1794 |
706 |
| cxt->s_tainted = is_tainted; |
| 1795 |
706 |
| cxt->entry = 1; /* No recursion yet */ |
| 1796 |
|
| #ifndef HAS_RESTRICTED_HASHES |
| 1797 |
|
| cxt->derestrict = -1; /* Fetched from perl if needed */ |
| 1798 |
|
| #endif |
| 1799 |
|
| #ifndef HAS_UTF8_ALL |
| 1800 |
|
| cxt->use_bytes = -1; /* Fetched from perl if needed */ |
| 1801 |
|
| #endif |
| 1802 |
706 |
| cxt->accept_future_minor = -1;/* Fetched from perl if needed */ |
| 1803 |
706 |
| cxt->in_retrieve_overloaded = 0; |
| 1804 |
|
| |
| 1805 |
706 |
| cxt->max_recur_depth = SvIV(get_sv("Storable::recursion_limit", GV_ADD)); |
| 1806 |
706 |
| cxt->max_recur_depth_hash = SvIV(get_sv("Storable::recursion_limit_hash", GV_ADD)); |
| 1807 |
706 |
| } |
| 1808 |
|
| |
| 1809 |
|
| /* |
| 1810 |
|
| * clean_retrieve_context |
| 1811 |
|
| * |
| 1812 |
|
| * Clean retrieve context by |
| 1813 |
|
| */ |
| 1814 |
696 |
| static void clean_retrieve_context(pTHX_ stcxt_t *cxt) |
| 1815 |
|
| { |
| 1816 |
|
| TRACEMED(("clean_retrieve_context")); |
| 1817 |
|
| |
| 1818 |
|
| ASSERT(cxt->optype & ST_RETRIEVE, ("was performing a retrieve()")); |
| 1819 |
|
| |
| 1820 |
696 |
▶ | if (cxt->aseen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->aseen) { |
696 |
0 |
696 |
|
| 1821 |
696 |
| AV *aseen = cxt->aseen; |
| 1822 |
696 |
| cxt->aseen = 0; |
| 1823 |
696 |
| av_undef(aseen); |
| 1824 |
696 |
| sv_free((SV *) aseen); |
| 1825 |
|
| } |
| 1826 |
696 |
| cxt->where_is_undef = UNSET_NTAG_T; |
| 1827 |
|
| |
| 1828 |
696 |
▶ | if (cxt->aclass) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->aclass) { |
696 |
0 |
696 |
|
| 1829 |
696 |
| AV *aclass = cxt->aclass; |
| 1830 |
696 |
| cxt->aclass = 0; |
| 1831 |
696 |
| av_undef(aclass); |
| 1832 |
696 |
| sv_free((SV *) aclass); |
| 1833 |
|
| } |
| 1834 |
|
| |
| 1835 |
696 |
▶ | if (cxt->hook) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->hook) { |
696 |
0 |
696 |
|
| 1836 |
696 |
| HV *hook = cxt->hook; |
| 1837 |
696 |
| cxt->hook = 0; |
| 1838 |
696 |
| hv_undef(hook); |
| 1839 |
696 |
| sv_free((SV *) hook); |
| 1840 |
|
| } |
| 1841 |
|
| |
| 1842 |
696 |
▶ | if (cxt->hseen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->hseen) { |
2 |
694 |
696 |
|
| 1843 |
2 |
| HV *hseen = cxt->hseen; |
| 1844 |
2 |
| cxt->hseen = 0; |
| 1845 |
2 |
| hv_undef(hseen); |
| 1846 |
2 |
| sv_free((SV *) hseen); /* optional HV, for backward compat. */ |
| 1847 |
|
| } |
| 1848 |
|
| |
| 1849 |
|
| #ifndef HAS_RESTRICTED_HASHES |
| 1850 |
|
| cxt->derestrict = -1; /* Fetched from perl if needed */ |
| 1851 |
|
| #endif |
| 1852 |
|
| #ifndef HAS_UTF8_ALL |
| 1853 |
|
| cxt->use_bytes = -1; /* Fetched from perl if needed */ |
| 1854 |
|
| #endif |
| 1855 |
696 |
| cxt->accept_future_minor = -1; /* Fetched from perl if needed */ |
| 1856 |
|
| |
| 1857 |
696 |
| cxt->in_retrieve_overloaded = 0; |
| 1858 |
696 |
| reset_context(cxt); |
| 1859 |
696 |
| } |
| 1860 |
|
| |
| 1861 |
|
| /* |
| 1862 |
|
| * clean_context |
| 1863 |
|
| * |
| 1864 |
|
| * A workaround for the CROAK bug: cleanup the last context. |
| 1865 |
|
| */ |
| 1866 |
108 |
| static void clean_context(pTHX_ stcxt_t *cxt) |
| 1867 |
|
| { |
| 1868 |
|
| TRACEMED(("clean_context")); |
| 1869 |
|
| |
| 1870 |
|
| ASSERT(cxt->s_dirty, ("dirty context")); |
| 1871 |
|
| |
| 1872 |
108 |
▶ | if (cxt->membuf_ro) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->membuf_ro) |
50 |
58 |
108 |
|
| 1873 |
50 |
| MBUF_RESTORE(); |
| 1874 |
|
| |
| 1875 |
|
| ASSERT(!cxt->membuf_ro, ("mbase is not read-only")); |
| 1876 |
|
| |
| 1877 |
108 |
▶ | if (cxt->optype & ST_RETRIEVE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->optype & ST_RETRIEVE) |
27 |
81 |
108 |
|
| 1878 |
27 |
| clean_retrieve_context(aTHX_ cxt); |
| 1879 |
81 |
▶ | else if (cxt->optype & ST_STORE) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (cxt->optype & ST_STORE) |
8 |
73 |
81 |
|
| 1880 |
8 |
| clean_store_context(aTHX_ cxt); |
| 1881 |
|
| else |
| 1882 |
73 |
| reset_context(cxt); |
| 1883 |
|
| |
| 1884 |
|
| ASSERT(!cxt->s_dirty, ("context is clean")); |
| 1885 |
|
| ASSERT(cxt->entry == 0, ("context is reset")); |
| 1886 |
108 |
| } |
| 1887 |
|
| |
| 1888 |
|
| /* |
| 1889 |
|
| * allocate_context |
| 1890 |
|
| * |
| 1891 |
|
| * Allocate a new context and push it on top of the parent one. |
| 1892 |
|
| * This new context is made globally visible via SET_STCXT(). |
| 1893 |
|
| */ |
| 1894 |
131 |
| static stcxt_t *allocate_context(pTHX_ stcxt_t *parent_cxt) |
| 1895 |
|
| { |
| 1896 |
|
| stcxt_t *cxt; |
| 1897 |
|
| |
| 1898 |
|
| ASSERT(!parent_cxt->s_dirty, ("parent context clean")); |
| 1899 |
|
| |
| 1900 |
131 |
| NEW_STORABLE_CXT_OBJ(cxt); |
| 1901 |
|
| TRACEMED(("allocate_context")); |
| 1902 |
|
| |
| 1903 |
131 |
| cxt->prev = parent_cxt->my_sv; |
| 1904 |
131 |
| SET_STCXT(cxt); |
| 1905 |
|
| |
| 1906 |
|
| ASSERT(!cxt->s_dirty, ("clean context")); |
| 1907 |
|
| |
| 1908 |
131 |
| return cxt; |
| 1909 |
|
| } |
| 1910 |
|
| |
| 1911 |
|
| /* |
| 1912 |
|
| * free_context |
| 1913 |
|
| * |
| 1914 |
|
| * Free current context, which cannot be the "root" one. |
| 1915 |
|
| * Make the context underneath globally visible via SET_STCXT(). |
| 1916 |
|
| */ |
| 1917 |
122 |
| static void free_context(pTHX_ stcxt_t *cxt) |
| 1918 |
|
| { |
| 1919 |
122 |
▶ | stcxt_t *prev = (stcxt_t *)(cxt->prev ? SvPVX(SvRV(cxt->prev)) : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| stcxt_t *prev = (stcxt_t *)(cxt->prev ? SvPVX(SvRV(cxt->prev)) : 0); |
122 |
0 |
122 |
|
| 1920 |
|
| |
| 1921 |
|
| TRACEMED(("free_context")); |
| 1922 |
|
| |
| 1923 |
|
| ASSERT(!cxt->s_dirty, ("clean context")); |
| 1924 |
|
| ASSERT(prev, ("not freeing root context")); |
| 1925 |
|
| assert(prev); |
| 1926 |
|
| |
| 1927 |
122 |
| SvREFCNT_dec(cxt->my_sv); |
| 1928 |
122 |
| SET_STCXT(prev); |
| 1929 |
|
| |
| 1930 |
|
| ASSERT(cxt, ("context not void")); |
| 1931 |
122 |
| } |
| 1932 |
|
| |
| 1933 |
|
| /*** |
| 1934 |
|
| *** Predicates. |
| 1935 |
|
| ***/ |
| 1936 |
|
| |
| 1937 |
|
| /* these two functions are currently only used within asserts */ |
| 1938 |
|
| #ifdef DASSERT |
| 1939 |
|
| /* |
| 1940 |
|
| * is_storing |
| 1941 |
|
| * |
| 1942 |
|
| * Tells whether we're in the middle of a store operation. |
| 1943 |
|
| */ |
| 1944 |
|
| static int is_storing(pTHX) |
| 1945 |
|
| { |
| 1946 |
|
| dSTCXT; |
| 1947 |
|
| |
| 1948 |
|
| return cxt->entry && (cxt->optype & ST_STORE); |
| 1949 |
|
| } |
| 1950 |
|
| |
| 1951 |
|
| /* |
| 1952 |
|
| * is_retrieving |
| 1953 |
|
| * |
| 1954 |
|
| * Tells whether we're in the middle of a retrieve operation. |
| 1955 |
|
| */ |
| 1956 |
|
| static int is_retrieving(pTHX) |
| 1957 |
|
| { |
| 1958 |
|
| dSTCXT; |
| 1959 |
|
| |
| 1960 |
|
| return cxt->entry && (cxt->optype & ST_RETRIEVE); |
| 1961 |
|
| } |
| 1962 |
|
| #endif |
| 1963 |
|
| |
| 1964 |
|
| /* |
| 1965 |
|
| * last_op_in_netorder |
| 1966 |
|
| * |
| 1967 |
|
| * Returns whether last operation was made using network order. |
| 1968 |
|
| * |
| 1969 |
|
| * This is typically out-of-band information that might prove useful |
| 1970 |
|
| * to people wishing to convert native to network order data when used. |
| 1971 |
|
| */ |
| 1972 |
5 |
| static int last_op_in_netorder(pTHX) |
| 1973 |
|
| { |
| 1974 |
5 |
| dSTCXT; |
| 1975 |
|
| |
| 1976 |
|
| assert(cxt); |
| 1977 |
5 |
| return cxt->netorder; |
| 1978 |
|
| } |
| 1979 |
|
| |
| 1980 |
|
| /*** |
| 1981 |
|
| *** Hook lookup and calling routines. |
| 1982 |
|
| ***/ |
| 1983 |
|
| |
| 1984 |
|
| /* |
| 1985 |
|
| * pkg_fetchmeth |
| 1986 |
|
| * |
| 1987 |
|
| * A wrapper on gv_fetchmethod_autoload() which caches results. |
| 1988 |
|
| * |
| 1989 |
|
| * Returns the routine reference as an SV*, or null if neither the package |
| 1990 |
|
| * nor its ancestors know about the method. |
| 1991 |
|
| */ |
| 1992 |
306 |
| static SV *pkg_fetchmeth(pTHX_ |
| 1993 |
|
| HV *cache, |
| 1994 |
|
| HV *pkg, |
| 1995 |
|
| const char *method) |
| 1996 |
|
| { |
| 1997 |
|
| GV *gv; |
| 1998 |
|
| SV *sv; |
| 1999 |
306 |
▶ | const char *hvname = HvNAME_get(pkg); |
Branch: 6 branches
| Branch | True | False | Total |
| const char *hvname = HvNAME_get(pkg); |
306 |
0 |
306 |
| const char *hvname = HvNAME_get(pkg); |
306 |
0 |
306 |
| const char *hvname = HvNAME_get(pkg); |
0 |
306 |
306 |
| const char *hvname = HvNAME_get(pkg); |
0 |
0 |
0 |
| const char *hvname = HvNAME_get(pkg); |
306 |
0 |
306 |
| const char *hvname = HvNAME_get(pkg); |
0 |
306 |
306 |
|
| 2000 |
|
| #ifdef DEBUGME |
| 2001 |
|
| dSTCXT; |
| 2002 |
|
| #endif |
| 2003 |
|
| |
| 2004 |
|
| /* |
| 2005 |
|
| * The following code is the same as the one performed by UNIVERSAL::can |
| 2006 |
|
| * in the Perl core. |
| 2007 |
|
| */ |
| 2008 |
|
| |
| 2009 |
306 |
| gv = gv_fetchmethod_autoload(pkg, method, FALSE); |
| 2010 |
306 |
▶ | if (gv && isGV(gv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (gv && isGV(gv)) { |
177 |
129 |
306 |
| if (gv && isGV(gv)) { |
177 |
0 |
177 |
|
| 2011 |
177 |
| sv = newRV_inc((SV*) GvCV(gv)); |
| 2012 |
|
| TRACEME(("%s->%s: 0x%" UVxf, hvname, method, PTR2UV(sv))); |
| 2013 |
|
| } else { |
| 2014 |
129 |
| sv = newSVsv(&PL_sv_undef); |
| 2015 |
|
| TRACEME(("%s->%s: not found", hvname, method)); |
| 2016 |
|
| } |
| 2017 |
|
| |
| 2018 |
|
| /* |
| 2019 |
|
| * Cache the result, ignoring failure: if we can't store the value, |
| 2020 |
|
| * it just won't be cached. |
| 2021 |
|
| */ |
| 2022 |
|
| |
| 2023 |
306 |
| (void) hv_store(cache, hvname, strlen(hvname), sv, 0); |
| 2024 |
|
| |
| 2025 |
306 |
▶ | return SvOK(sv) ? sv : (SV *) 0; |
Branch: 1 branch
| Branch | True | False | Total |
| return SvOK(sv) ? sv : (SV *) 0; |
177 |
129 |
306 |
|
| 2026 |
|
| } |
| 2027 |
|
| |
| 2028 |
|
| /* |
| 2029 |
|
| * pkg_hide |
| 2030 |
|
| * |
| 2031 |
|
| * Force cached value to be undef: hook ignored even if present. |
| 2032 |
|
| */ |
| 2033 |
5 |
| static void pkg_hide(pTHX_ |
| 2034 |
|
| HV *cache, |
| 2035 |
|
| HV *pkg, |
| 2036 |
|
| const char *method) |
| 2037 |
|
| { |
| 2038 |
5 |
▶ | const char *hvname = HvNAME_get(pkg); |
Branch: 6 branches
| Branch | True | False | Total |
| const char *hvname = HvNAME_get(pkg); |
5 |
0 |
5 |
| const char *hvname = HvNAME_get(pkg); |
5 |
0 |
5 |
| const char *hvname = HvNAME_get(pkg); |
0 |
5 |
5 |
| const char *hvname = HvNAME_get(pkg); |
0 |
0 |
0 |
| const char *hvname = HvNAME_get(pkg); |
5 |
0 |
5 |
| const char *hvname = HvNAME_get(pkg); |
0 |
5 |
5 |
|
| 2039 |
|
| PERL_UNUSED_ARG(method); |
| 2040 |
5 |
| (void) hv_store(cache, |
| 2041 |
|
| hvname, strlen(hvname), newSVsv(&PL_sv_undef), 0); |
| 2042 |
5 |
| } |
| 2043 |
|
| |
| 2044 |
|
| /* |
| 2045 |
|
| * pkg_uncache |
| 2046 |
|
| * |
| 2047 |
|
| * Discard cached value: a whole fetch loop will be retried at next lookup. |
| 2048 |
|
| */ |
| 2049 |
2 |
| static void pkg_uncache(pTHX_ |
| 2050 |
|
| HV *cache, |
| 2051 |
|
| HV *pkg, |
| 2052 |
|
| const char *method) |
| 2053 |
|
| { |
| 2054 |
2 |
▶ | const char *hvname = HvNAME_get(pkg); |
Branch: 6 branches
| Branch | True | False | Total |
| const char *hvname = HvNAME_get(pkg); |
2 |
0 |
2 |
| const char *hvname = HvNAME_get(pkg); |
2 |
0 |
2 |
| const char *hvname = HvNAME_get(pkg); |
0 |
2 |
2 |
| const char *hvname = HvNAME_get(pkg); |
0 |
0 |
0 |
| const char *hvname = HvNAME_get(pkg); |
2 |
0 |
2 |
| const char *hvname = HvNAME_get(pkg); |
0 |
2 |
2 |
|
| 2055 |
|
| PERL_UNUSED_ARG(method); |
| 2056 |
2 |
| (void) hv_delete(cache, hvname, strlen(hvname), G_DISCARD); |
| 2057 |
2 |
| } |
| 2058 |
|
| |
| 2059 |
|
| /* |
| 2060 |
|
| * pkg_can |
| 2061 |
|
| * |
| 2062 |
|
| * Our own "UNIVERSAL::can", which caches results. |
| 2063 |
|
| * |
| 2064 |
|
| * Returns the routine reference as an SV*, or null if the object does not |
| 2065 |
|
| * know about the method. |
| 2066 |
|
| */ |
| 2067 |
377 |
| static SV *pkg_can(pTHX_ |
| 2068 |
|
| HV *cache, |
| 2069 |
|
| HV *pkg, |
| 2070 |
|
| const char *method) |
| 2071 |
|
| { |
| 2072 |
|
| SV **svh; |
| 2073 |
|
| SV *sv; |
| 2074 |
377 |
▶ | const char *hvname = HvNAME_get(pkg); |
Branch: 6 branches
| Branch | True | False | Total |
| const char *hvname = HvNAME_get(pkg); |
377 |
0 |
377 |
| const char *hvname = HvNAME_get(pkg); |
377 |
0 |
377 |
| const char *hvname = HvNAME_get(pkg); |
0 |
377 |
377 |
| const char *hvname = HvNAME_get(pkg); |
0 |
0 |
0 |
| const char *hvname = HvNAME_get(pkg); |
377 |
0 |
377 |
| const char *hvname = HvNAME_get(pkg); |
0 |
377 |
377 |
|
| 2075 |
|
| #ifdef DEBUGME |
| 2076 |
|
| dSTCXT; |
| 2077 |
|
| #endif |
| 2078 |
|
| |
| 2079 |
|
| TRACEME(("pkg_can for %s->%s", hvname, method)); |
| 2080 |
|
| |
| 2081 |
|
| /* |
| 2082 |
|
| * Look into the cache to see whether we already have determined |
| 2083 |
|
| * where the routine was, if any. |
| 2084 |
|
| * |
| 2085 |
|
| * NOTA BENE: we don't use 'method' at all in our lookup, since we know |
| 2086 |
|
| * that only one hook (i.e. always the same) is cached in a given cache. |
| 2087 |
|
| */ |
| 2088 |
|
| |
| 2089 |
377 |
| svh = hv_fetch(cache, hvname, strlen(hvname), FALSE); |
| 2090 |
377 |
▶ | if (svh) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svh) { |
71 |
306 |
377 |
|
| 2091 |
71 |
| sv = *svh; |
| 2092 |
71 |
▶ | if (!SvOK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(sv)) { |
32 |
39 |
71 |
|
| 2093 |
|
| TRACEME(("cached %s->%s: not found", hvname, method)); |
| 2094 |
32 |
| return (SV *) 0; |
| 2095 |
|
| } else { |
| 2096 |
|
| TRACEME(("cached %s->%s: 0x%" UVxf, |
| 2097 |
|
| hvname, method, PTR2UV(sv))); |
| 2098 |
39 |
| return sv; |
| 2099 |
|
| } |
| 2100 |
|
| } |
| 2101 |
|
| |
| 2102 |
|
| TRACEME(("not cached yet")); |
| 2103 |
306 |
| return pkg_fetchmeth(aTHX_ cache, pkg, method); /* Fetch and cache */ |
| 2104 |
|
| } |
| 2105 |
|
| |
| 2106 |
|
| /* |
| 2107 |
|
| * scalar_call |
| 2108 |
|
| * |
| 2109 |
|
| * Call routine as obj->hook(av) in scalar context. |
| 2110 |
|
| * Propagates the single returned value if not called in void context. |
| 2111 |
|
| */ |
| 2112 |
113 |
| static SV *scalar_call(pTHX_ |
| 2113 |
|
| SV *obj, |
| 2114 |
|
| SV *hook, |
| 2115 |
|
| int cloning, |
| 2116 |
|
| AV *av, |
| 2117 |
|
| I32 flags) |
| 2118 |
|
| { |
| 2119 |
113 |
| dSP; |
| 2120 |
|
| int count; |
| 2121 |
113 |
| SV *sv = 0; |
| 2122 |
|
| #ifdef DEBUGME |
| 2123 |
|
| dSTCXT; |
| 2124 |
|
| #endif |
| 2125 |
|
| |
| 2126 |
|
| TRACEME(("scalar_call (cloning=%d)", cloning)); |
| 2127 |
|
| |
| 2128 |
113 |
| ENTER; |
| 2129 |
113 |
| SAVETMPS; |
| 2130 |
|
| |
| 2131 |
113 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
113 |
113 |
|
| 2132 |
113 |
▶ | XPUSHs(obj); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(obj); |
0 |
113 |
113 |
|
| 2133 |
113 |
▶ | XPUSHs(sv_2mortal(newSViv(cloning))); /* Cloning flag */ |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(cloning))); /* Cloning flag */ |
0 |
113 |
113 |
|
| 2134 |
113 |
▶ | if (av) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av) { |
113 |
0 |
113 |
|
| 2135 |
113 |
| SV **ary = AvARRAY(av); |
| 2136 |
113 |
| SSize_t cnt = AvFILLp(av) + 1; |
| 2137 |
|
| SSize_t i; |
| 2138 |
113 |
▶ | XPUSHs(ary[0]); /* Frozen string */ |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(ary[0]); /* Frozen string */ |
0 |
113 |
113 |
|
| 2139 |
216 |
▶ | for (i = 1; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < cnt; i++) { |
103 |
113 |
216 |
|
| 2140 |
|
| TRACEME(("pushing arg #%d (0x%" UVxf ")...", |
| 2141 |
|
| (int)i, PTR2UV(ary[i]))); |
| 2142 |
103 |
▶ | XPUSHs(sv_2mortal(newRV_inc(ary[i]))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newRV_inc(ary[i]))); |
0 |
103 |
103 |
|
| 2143 |
|
| } |
| 2144 |
|
| } |
| 2145 |
113 |
| PUTBACK; |
| 2146 |
|
| |
| 2147 |
|
| TRACEME(("calling...")); |
| 2148 |
113 |
| count = call_sv(hook, flags); /* Go back to Perl code */ |
| 2149 |
|
| TRACEME(("count = %d", count)); |
| 2150 |
|
| |
| 2151 |
107 |
| SPAGAIN; |
| 2152 |
|
| |
| 2153 |
107 |
▶ | if (count) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count) { |
17 |
90 |
107 |
|
| 2154 |
17 |
| sv = POPs; |
| 2155 |
17 |
| SvREFCNT_inc(sv); /* We're returning it, must stay alive! */ |
| 2156 |
|
| } |
| 2157 |
|
| |
| 2158 |
107 |
| PUTBACK; |
| 2159 |
107 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
107 |
0 |
107 |
|
| 2160 |
107 |
| LEAVE; |
| 2161 |
|
| |
| 2162 |
107 |
| return sv; |
| 2163 |
|
| } |
| 2164 |
|
| |
| 2165 |
|
| /* |
| 2166 |
|
| * array_call |
| 2167 |
|
| * |
| 2168 |
|
| * Call routine obj->hook(cloning) in list context. |
| 2169 |
|
| * Returns the list of returned values in an array. |
| 2170 |
|
| */ |
| 2171 |
119 |
| static AV *array_call(pTHX_ |
| 2172 |
|
| SV *obj, |
| 2173 |
|
| SV *hook, |
| 2174 |
|
| int cloning) |
| 2175 |
|
| { |
| 2176 |
119 |
| dSP; |
| 2177 |
|
| int count; |
| 2178 |
|
| AV *av; |
| 2179 |
|
| int i; |
| 2180 |
|
| #ifdef DEBUGME |
| 2181 |
|
| dSTCXT; |
| 2182 |
|
| #endif |
| 2183 |
|
| |
| 2184 |
|
| TRACEME(("array_call (cloning=%d)", cloning)); |
| 2185 |
|
| |
| 2186 |
119 |
| ENTER; |
| 2187 |
119 |
| SAVETMPS; |
| 2188 |
|
| |
| 2189 |
119 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
119 |
119 |
|
| 2190 |
119 |
▶ | XPUSHs(obj); /* Target object */ |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(obj); /* Target object */ |
0 |
119 |
119 |
|
| 2191 |
119 |
▶ | XPUSHs(sv_2mortal(newSViv(cloning))); /* Cloning flag */ |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(cloning))); /* Cloning flag */ |
0 |
119 |
119 |
|
| 2192 |
119 |
| PUTBACK; |
| 2193 |
|
| |
| 2194 |
119 |
| count = call_sv(hook, G_LIST); /* Go back to Perl code */ |
| 2195 |
|
| |
| 2196 |
115 |
| SPAGAIN; |
| 2197 |
|
| |
| 2198 |
115 |
| av = newAV(); |
| 2199 |
328 |
▶ | for (i = count - 1; i >= 0; i--) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = count - 1; i >= 0; i--) { |
213 |
115 |
328 |
|
| 2200 |
213 |
| SV *sv = POPs; |
| 2201 |
213 |
| av_store(av, i, SvREFCNT_inc(sv)); |
| 2202 |
|
| } |
| 2203 |
|
| |
| 2204 |
115 |
| PUTBACK; |
| 2205 |
115 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
115 |
0 |
115 |
|
| 2206 |
115 |
| LEAVE; |
| 2207 |
|
| |
| 2208 |
115 |
| return av; |
| 2209 |
|
| } |
| 2210 |
|
| |
| 2211 |
|
| #if PERL_VERSION_LT(5,15,0) |
| 2212 |
|
| static void |
| 2213 |
|
| cleanup_recursive_av(pTHX_ AV* av) { |
| 2214 |
|
| SSize_t i = AvFILLp(av); |
| 2215 |
|
| SV** arr = AvARRAY(av); |
| 2216 |
|
| if (SvMAGICAL(av)) return; |
| 2217 |
|
| while (i >= 0) { |
| 2218 |
|
| if (arr[i]) { |
| 2219 |
|
| #if PERL_VERSION_LT(5,14,0) |
| 2220 |
|
| arr[i] = NULL; |
| 2221 |
|
| #else |
| 2222 |
|
| SvREFCNT_dec(arr[i]); |
| 2223 |
|
| #endif |
| 2224 |
|
| } |
| 2225 |
|
| i--; |
| 2226 |
|
| } |
| 2227 |
|
| } |
| 2228 |
|
| |
| 2229 |
|
| #ifndef SvREFCNT_IMMORTAL |
| 2230 |
|
| #ifdef DEBUGGING |
| 2231 |
|
| /* exercise the immortal resurrection code in sv_free2() */ |
| 2232 |
|
| # define SvREFCNT_IMMORTAL 1000 |
| 2233 |
|
| #else |
| 2234 |
|
| # define SvREFCNT_IMMORTAL ((~(U32)0)/2) |
| 2235 |
|
| #endif |
| 2236 |
|
| #endif |
| 2237 |
|
| |
| 2238 |
|
| static void |
| 2239 |
|
| cleanup_recursive_hv(pTHX_ HV* hv) { |
| 2240 |
|
| SSize_t i = HvTOTALKEYS(hv); |
| 2241 |
|
| HE** arr = HvARRAY(hv); |
| 2242 |
|
| if (SvMAGICAL(hv)) return; |
| 2243 |
|
| while (i >= 0) { |
| 2244 |
|
| if (arr[i]) { |
| 2245 |
|
| SvREFCNT(HeVAL(arr[i])) = SvREFCNT_IMMORTAL; |
| 2246 |
|
| arr[i] = NULL; /* let it leak. too dangerous to clean it up here */ |
| 2247 |
|
| } |
| 2248 |
|
| i--; |
| 2249 |
|
| } |
| 2250 |
|
| #if PERL_VERSION_LT(5,8,0) |
| 2251 |
|
| ((XPVHV*)SvANY(hv))->xhv_array = NULL; |
| 2252 |
|
| #else |
| 2253 |
|
| HvARRAY(hv) = NULL; |
| 2254 |
|
| #endif |
| 2255 |
|
| HvTOTALKEYS(hv) = 0; |
| 2256 |
|
| } |
| 2257 |
|
| static void |
| 2258 |
|
| cleanup_recursive_rv(pTHX_ SV* sv) { |
| 2259 |
|
| if (sv && SvROK(sv)) |
| 2260 |
|
| SvREFCNT_dec(SvRV(sv)); |
| 2261 |
|
| } |
| 2262 |
|
| static void |
| 2263 |
|
| cleanup_recursive_data(pTHX_ SV* sv) { |
| 2264 |
|
| if (SvTYPE(sv) == SVt_PVAV) { |
| 2265 |
|
| cleanup_recursive_av(aTHX_ (AV*)sv); |
| 2266 |
|
| } |
| 2267 |
|
| else if (SvTYPE(sv) == SVt_PVHV) { |
| 2268 |
|
| cleanup_recursive_hv(aTHX_ (HV*)sv); |
| 2269 |
|
| } |
| 2270 |
|
| else { |
| 2271 |
|
| cleanup_recursive_rv(aTHX_ sv); |
| 2272 |
|
| } |
| 2273 |
|
| } |
| 2274 |
|
| #endif |
| 2275 |
|
| |
| 2276 |
|
| /* |
| 2277 |
|
| * known_class |
| 2278 |
|
| * |
| 2279 |
|
| * Lookup the class name in the 'hclass' table and either assign it a new ID |
| 2280 |
|
| * or return the existing one, by filling in 'classnum'. |
| 2281 |
|
| * |
| 2282 |
|
| * Return true if the class was known, false if the ID was just generated. |
| 2283 |
|
| */ |
| 2284 |
268 |
| static int known_class(pTHX_ |
| 2285 |
|
| stcxt_t *cxt, |
| 2286 |
|
| char *name, /* Class name */ |
| 2287 |
|
| int len, /* Name length */ |
| 2288 |
|
| I32 *classnum) |
| 2289 |
|
| { |
| 2290 |
|
| SV **svh; |
| 2291 |
268 |
| HV *hclass = cxt->hclass; |
| 2292 |
|
| |
| 2293 |
|
| TRACEME(("known_class (%s)", name)); |
| 2294 |
|
| |
| 2295 |
|
| /* |
| 2296 |
|
| * Recall that we don't store pointers in this hash table, but tags. |
| 2297 |
|
| * Therefore, we need LOW_32BITS() to extract the relevant parts. |
| 2298 |
|
| */ |
| 2299 |
|
| |
| 2300 |
268 |
| svh = hv_fetch(hclass, name, len, FALSE); |
| 2301 |
268 |
▶ | if (svh) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svh) { |
47 |
221 |
268 |
|
| 2302 |
47 |
| *classnum = LOW_32BITS(*svh); |
| 2303 |
47 |
| return TRUE; |
| 2304 |
|
| } |
| 2305 |
|
| |
| 2306 |
|
| /* |
| 2307 |
|
| * Unknown classname, we need to record it. |
| 2308 |
|
| */ |
| 2309 |
|
| |
| 2310 |
221 |
| cxt->classnum++; |
| 2311 |
221 |
▶ | if (!hv_store(hclass, name, len, INT2PTR(SV*, cxt->classnum), 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_store(hclass, name, len, INT2PTR(SV*, cxt->classnum), 0)) |
0 |
221 |
221 |
|
| 2312 |
0 |
| CROAK(("Unable to record new classname")); |
| 2313 |
|
| |
| 2314 |
221 |
| *classnum = cxt->classnum; |
| 2315 |
221 |
| return FALSE; |
| 2316 |
|
| } |
| 2317 |
|
| |
| 2318 |
|
| /*** |
| 2319 |
|
| *** Specific store routines. |
| 2320 |
|
| ***/ |
| 2321 |
|
| |
| 2322 |
|
| /* |
| 2323 |
|
| * store_ref |
| 2324 |
|
| * |
| 2325 |
|
| * Store a reference. |
| 2326 |
|
| * Layout is SX_REF <object> or SX_OVERLOAD <object>. |
| 2327 |
|
| */ |
| 2328 |
59745 |
| static int store_ref(pTHX_ stcxt_t *cxt, SV *sv) |
| 2329 |
|
| { |
| 2330 |
|
| int retval; |
| 2331 |
59745 |
| int is_weak = 0; |
| 2332 |
|
| TRACEME(("store_ref (0x%" UVxf ")", PTR2UV(sv))); |
| 2333 |
|
| |
| 2334 |
|
| /* |
| 2335 |
|
| * Follow reference, and check if target is overloaded. |
| 2336 |
|
| */ |
| 2337 |
|
| |
| 2338 |
|
| #ifdef SvWEAKREF |
| 2339 |
59745 |
▶ | if (SvWEAKREF(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvWEAKREF(sv)) |
17 |
59728 |
59745 |
|
| 2340 |
17 |
| is_weak = 1; |
| 2341 |
|
| TRACEME(("ref (0x%" UVxf ") is%s weak", PTR2UV(sv), |
| 2342 |
|
| is_weak ? "" : "n't")); |
| 2343 |
|
| #endif |
| 2344 |
59745 |
| sv = SvRV(sv); |
| 2345 |
|
| |
| 2346 |
59745 |
▶ | if (SvOBJECT(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOBJECT(sv)) { |
196 |
59549 |
59745 |
|
| 2347 |
196 |
| HV *stash = (HV *) SvSTASH(sv); |
| 2348 |
196 |
▶ | if (stash && Gv_AMG(stash)) { |
Branch: 9 branches
| Branch | True | False | Total |
| if (stash && Gv_AMG(stash)) { |
196 |
0 |
196 |
| if (stash && Gv_AMG(stash)) { |
196 |
0 |
196 |
| if (stash && Gv_AMG(stash)) { |
196 |
0 |
196 |
| if (stash && Gv_AMG(stash)) { |
0 |
196 |
196 |
| if (stash && Gv_AMG(stash)) { |
0 |
0 |
0 |
| if (stash && Gv_AMG(stash)) { |
196 |
0 |
196 |
| if (stash && Gv_AMG(stash)) { |
0 |
196 |
196 |
| if (stash && Gv_AMG(stash)) { |
196 |
0 |
196 |
| if (stash && Gv_AMG(stash)) { |
163 |
33 |
196 |
|
| 2349 |
|
| TRACEME(("ref (0x%" UVxf ") is overloaded", PTR2UV(sv))); |
| 2350 |
33 |
▶ | PUTMARK(is_weak ? SX_WEAKOVERLOAD : SX_OVERLOAD); |
Branch: 6 branches
| Branch | True | False | Total |
| PUTMARK(is_weak ? SX_WEAKOVERLOAD : SX_OVERLOAD); |
29 |
4 |
33 |
| PUTMARK(is_weak ? SX_WEAKOVERLOAD : SX_OVERLOAD); |
29 |
0 |
29 |
| PUTMARK(is_weak ? SX_WEAKOVERLOAD : SX_OVERLOAD); |
2 |
27 |
29 |
| PUTMARK(is_weak ? SX_WEAKOVERLOAD : SX_OVERLOAD); |
0 |
0 |
0 |
| PUTMARK(is_weak ? SX_WEAKOVERLOAD : SX_OVERLOAD); |
2 |
2 |
4 |
| PUTMARK(is_weak ? SX_WEAKOVERLOAD : SX_OVERLOAD); |
0 |
4 |
4 |
|
| 2351 |
|
| } else |
| 2352 |
163 |
▶ | PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
Branch: 6 branches
| Branch | True | False | Total |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
150 |
13 |
163 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
150 |
0 |
150 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
0 |
150 |
150 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
0 |
0 |
0 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
0 |
13 |
13 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
0 |
13 |
13 |
|
| 2353 |
|
| } else |
| 2354 |
59549 |
▶ | PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
Branch: 6 branches
| Branch | True | False | Total |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
59492 |
57 |
59549 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
59480 |
12 |
59492 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
7 |
59473 |
59480 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
0 |
12 |
12 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
6 |
51 |
57 |
| PUTMARK(is_weak ? SX_WEAKREF : SX_REF); |
0 |
57 |
57 |
|
| 2355 |
|
| |
| 2356 |
59745 |
| cxt->recur_sv = sv; |
| 2357 |
|
| |
| 2358 |
|
| TRACEME((">ref recur_depth %" IVdf ", recur_sv (0x%" UVxf ") max %" IVdf, cxt->recur_depth, |
| 2359 |
|
| PTR2UV(cxt->recur_sv), cxt->max_recur_depth)); |
| 2360 |
59745 |
▶ | if (RECURSION_TOO_DEEP()) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (RECURSION_TOO_DEEP()) { |
59745 |
0 |
59745 |
| if (RECURSION_TOO_DEEP()) { |
1 |
59744 |
59745 |
|
| 2361 |
|
| #if PERL_VERSION_LT(5,15,0) |
| 2362 |
|
| cleanup_recursive_data(aTHX_ (SV*)sv); |
| 2363 |
|
| #endif |
| 2364 |
1 |
| CROAK((MAX_DEPTH_ERROR)); |
| 2365 |
|
| } |
| 2366 |
|
| |
| 2367 |
59744 |
| retval = store(aTHX_ cxt, sv); |
| 2368 |
59692 |
▶ | if (cxt->max_recur_depth != -1 && cxt->recur_depth > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cxt->max_recur_depth != -1 && cxt->recur_depth > 0) { |
59692 |
0 |
59692 |
| if (cxt->max_recur_depth != -1 && cxt->recur_depth > 0) { |
59692 |
0 |
59692 |
|
| 2369 |
|
| TRACEME(("<ref recur_depth --%" IVdf, cxt->recur_depth)); |
| 2370 |
59692 |
| --cxt->recur_depth; |
| 2371 |
|
| } |
| 2372 |
59692 |
| return retval; |
| 2373 |
|
| } |
| 2374 |
|
| |
| 2375 |
|
| /* |
| 2376 |
|
| * store_scalar |
| 2377 |
|
| * |
| 2378 |
|
| * Store a scalar. |
| 2379 |
|
| * |
| 2380 |
|
| * Layout is SX_LSCALAR <length> <data>, SX_SCALAR <length> <data> or SX_UNDEF. |
| 2381 |
|
| * SX_LUTF8STR and SX_UTF8STR are used for UTF-8 strings. |
| 2382 |
|
| * The <data> section is omitted if <length> is 0. |
| 2383 |
|
| * |
| 2384 |
|
| * For vstrings, the vstring portion is stored first with |
| 2385 |
|
| * SX_LVSTRING <length> <data> or SX_VSTRING <length> <data>, followed by |
| 2386 |
|
| * SX_(L)SCALAR or SX_(L)UTF8STR with the actual PV. |
| 2387 |
|
| * |
| 2388 |
|
| * If integer or double, the layout is SX_INTEGER <data> or SX_DOUBLE <data>. |
| 2389 |
|
| * Small integers (within [-127, +127]) are stored as SX_BYTE <byte>. |
| 2390 |
|
| * |
| 2391 |
|
| * For huge strings use SX_LOBJECT SX_type SX_U64 <type> <data> |
| 2392 |
|
| */ |
| 2393 |
27058 |
| static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv) |
| 2394 |
|
| { |
| 2395 |
|
| IV iv; |
| 2396 |
|
| char *pv; |
| 2397 |
|
| STRLEN len; |
| 2398 |
27058 |
| U32 flags = SvFLAGS(sv); /* "cc -O" may put it in register */ |
| 2399 |
|
| |
| 2400 |
|
| TRACEME(("store_scalar (0x%" UVxf ")", PTR2UV(sv))); |
| 2401 |
|
| |
| 2402 |
|
| /* |
| 2403 |
|
| * For efficiency, break the SV encapsulation by peaking at the flags |
| 2404 |
|
| * directly without using the Perl macros to avoid dereferencing |
| 2405 |
|
| * sv->sv_flags each time we wish to check the flags. |
| 2406 |
|
| */ |
| 2407 |
|
| |
| 2408 |
27058 |
▶ | if (!(flags & SVf_OK)) { /* !SvOK(sv) */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(flags & SVf_OK)) { /* !SvOK(sv) */ |
5146 |
21912 |
27058 |
|
| 2409 |
5146 |
▶ | if (sv == &PL_sv_undef) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv == &PL_sv_undef) { |
5125 |
21 |
5146 |
|
| 2410 |
|
| TRACEME(("immortal undef")); |
| 2411 |
5125 |
▶ | PUTMARK(SX_SV_UNDEF); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_SV_UNDEF); |
5125 |
0 |
5125 |
| PUTMARK(SX_SV_UNDEF); |
5125 |
0 |
5125 |
| PUTMARK(SX_SV_UNDEF); |
0 |
0 |
0 |
|
| 2412 |
|
| } else { |
| 2413 |
|
| TRACEME(("undef at 0x%" UVxf, PTR2UV(sv))); |
| 2414 |
21 |
▶ | PUTMARK(SX_UNDEF); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_UNDEF); |
16 |
5 |
21 |
| PUTMARK(SX_UNDEF); |
16 |
0 |
16 |
| PUTMARK(SX_UNDEF); |
0 |
5 |
5 |
|
| 2415 |
|
| } |
| 2416 |
5146 |
| return 0; |
| 2417 |
|
| } |
| 2418 |
|
| |
| 2419 |
|
| /* |
| 2420 |
|
| * Always store the string representation of a scalar if it exists. |
| 2421 |
|
| * Gisle Aas provided me with this test case, better than a long speach: |
| 2422 |
|
| * |
| 2423 |
|
| * perl -MDevel::Peek -le '$a="abc"; $a+0; Dump($a)' |
| 2424 |
|
| * SV = PVNV(0x80c8520) |
| 2425 |
|
| * REFCNT = 1 |
| 2426 |
|
| * FLAGS = (NOK,POK,pNOK,pPOK) |
| 2427 |
|
| * IV = 0 |
| 2428 |
|
| * NV = 0 |
| 2429 |
|
| * PV = 0x80c83d0 "abc"\0 |
| 2430 |
|
| * CUR = 3 |
| 2431 |
|
| * LEN = 4 |
| 2432 |
|
| * |
| 2433 |
|
| * Write SX_SCALAR, length, followed by the actual data. |
| 2434 |
|
| * |
| 2435 |
|
| * Otherwise, write an SX_BYTE, SX_INTEGER or an SX_DOUBLE as |
| 2436 |
|
| * appropriate, followed by the actual (binary) data. A double |
| 2437 |
|
| * is written as a string if network order, for portability. |
| 2438 |
|
| * |
| 2439 |
|
| * NOTE: instead of using SvNOK(sv), we test for SvNOKp(sv). |
| 2440 |
|
| * The reason is that when the scalar value is tainted, the SvNOK(sv) |
| 2441 |
|
| * value is false. |
| 2442 |
|
| * |
| 2443 |
|
| * The test for a read-only scalar with both POK and NOK set is meant |
| 2444 |
|
| * to quickly detect &PL_sv_yes and &PL_sv_no without having to pay the |
| 2445 |
|
| * address comparison for each scalar we store. |
| 2446 |
|
| */ |
| 2447 |
|
| |
| 2448 |
|
| #define SV_MAYBE_IMMORTAL (SVf_READONLY|SVf_POK|SVf_NOK) |
| 2449 |
|
| |
| 2450 |
21912 |
▶ | if ((flags & SV_MAYBE_IMMORTAL) == SV_MAYBE_IMMORTAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((flags & SV_MAYBE_IMMORTAL) == SV_MAYBE_IMMORTAL) { |
8 |
21904 |
21912 |
|
| 2451 |
8 |
▶ | if (sv == &PL_sv_yes) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv == &PL_sv_yes) { |
4 |
4 |
8 |
|
| 2452 |
|
| TRACEME(("immortal yes")); |
| 2453 |
4 |
▶ | PUTMARK(SX_SV_YES); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_SV_YES); |
4 |
0 |
4 |
| PUTMARK(SX_SV_YES); |
4 |
0 |
4 |
| PUTMARK(SX_SV_YES); |
0 |
0 |
0 |
|
| 2454 |
4 |
▶ | } else if (sv == &PL_sv_no) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (sv == &PL_sv_no) { |
4 |
0 |
4 |
|
| 2455 |
|
| TRACEME(("immortal no")); |
| 2456 |
4 |
▶ | PUTMARK(SX_SV_NO); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_SV_NO); |
4 |
0 |
4 |
| PUTMARK(SX_SV_NO); |
4 |
0 |
4 |
| PUTMARK(SX_SV_NO); |
0 |
0 |
0 |
|
| 2457 |
|
| } else { |
| 2458 |
0 |
| pv = SvPV(sv, len); /* We know it's SvPOK */ |
| 2459 |
0 |
| goto string; /* Share code below */ |
| 2460 |
|
| } |
| 2461 |
|
| #ifdef SvIsBOOL |
| 2462 |
21904 |
▶ | } else if (SvIsBOOL(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvIsBOOL(sv)) { |
2 |
21902 |
21904 |
|
| 2463 |
|
| TRACEME(("mortal boolean")); |
| 2464 |
2 |
▶ | if (SvTRUE_nomg_NN(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE_nomg_NN(sv)) { |
1 |
1 |
2 |
|
| 2465 |
1 |
▶ | PUTMARK(SX_BOOLEAN_TRUE); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_BOOLEAN_TRUE); |
1 |
0 |
1 |
| PUTMARK(SX_BOOLEAN_TRUE); |
1 |
0 |
1 |
| PUTMARK(SX_BOOLEAN_TRUE); |
0 |
0 |
0 |
|
| 2466 |
|
| } |
| 2467 |
|
| else { |
| 2468 |
1 |
▶ | PUTMARK(SX_BOOLEAN_FALSE); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_BOOLEAN_FALSE); |
1 |
0 |
1 |
| PUTMARK(SX_BOOLEAN_FALSE); |
1 |
0 |
1 |
| PUTMARK(SX_BOOLEAN_FALSE); |
0 |
0 |
0 |
|
| 2469 |
|
| } |
| 2470 |
|
| #endif |
| 2471 |
21902 |
▶ | } else if (flags & SVf_POK) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (flags & SVf_POK) { |
21340 |
562 |
21902 |
|
| 2472 |
|
| /* public string - go direct to string read. */ |
| 2473 |
21340 |
| goto string_readlen; |
| 2474 |
562 |
| } else if ( |
| 2475 |
|
| #if PERL_VERSION_LT(5,7,0) |
| 2476 |
|
| /* For 5.6 and earlier NV flag trumps IV flag, so only use integer |
| 2477 |
|
| direct if NV flag is off. */ |
| 2478 |
|
| (flags & (SVf_NOK | SVf_IOK)) == SVf_IOK |
| 2479 |
|
| #else |
| 2480 |
|
| /* 5.7 rules are that if IV public flag is set, IV value is as |
| 2481 |
|
| good, if not better, than NV value. */ |
| 2482 |
562 |
▶ | flags & SVf_IOK |
Branch: 1 branch
| Branch | True | False | Total |
| flags & SVf_IOK |
532 |
30 |
562 |
|
| 2483 |
|
| #endif |
| 2484 |
|
| ) { |
| 2485 |
532 |
| iv = SvIV(sv); |
| 2486 |
|
| /* |
| 2487 |
|
| * Will come here from below with iv set if double is an integer. |
| 2488 |
|
| */ |
| 2489 |
537 |
| integer: |
| 2490 |
|
| |
| 2491 |
|
| /* Sorry. This isn't in 5.005_56 (IIRC) or earlier. */ |
| 2492 |
|
| #ifdef SVf_IVisUV |
| 2493 |
|
| /* Need to do this out here, else 0xFFFFFFFF becomes iv of -1 |
| 2494 |
|
| * (for example) and that ends up in the optimised small integer |
| 2495 |
|
| * case. |
| 2496 |
|
| */ |
| 2497 |
537 |
▶ | if ((flags & SVf_IVisUV) && SvUV(sv) > IV_MAX) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((flags & SVf_IVisUV) && SvUV(sv) > IV_MAX) { |
20 |
517 |
537 |
| if ((flags & SVf_IVisUV) && SvUV(sv) > IV_MAX) { |
20 |
0 |
20 |
|
| 2498 |
|
| TRACEME(("large unsigned integer as string, value = %" UVuf, |
| 2499 |
|
| SvUV(sv))); |
| 2500 |
20 |
| goto string_readlen; |
| 2501 |
|
| } |
| 2502 |
|
| #endif |
| 2503 |
|
| /* |
| 2504 |
|
| * Optimize small integers into a single byte, otherwise store as |
| 2505 |
|
| * a real integer (converted into network order if they asked). |
| 2506 |
|
| */ |
| 2507 |
|
| |
| 2508 |
878 |
▶ | if (iv >= -128 && iv <= 127) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (iv >= -128 && iv <= 127) { |
487 |
30 |
517 |
| if (iv >= -128 && iv <= 127) { |
361 |
126 |
487 |
|
| 2509 |
361 |
| unsigned char siv = (unsigned char) (iv + 128); /* [0,255] */ |
| 2510 |
361 |
▶ | PUTMARK(SX_BYTE); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_BYTE); |
326 |
35 |
361 |
| PUTMARK(SX_BYTE); |
326 |
0 |
326 |
| PUTMARK(SX_BYTE); |
0 |
35 |
35 |
|
| 2511 |
361 |
▶ | PUTMARK(siv); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(siv); |
326 |
35 |
361 |
| PUTMARK(siv); |
326 |
0 |
326 |
| PUTMARK(siv); |
0 |
35 |
35 |
|
| 2512 |
|
| TRACEME(("small integer stored as %d", (int)siv)); |
| 2513 |
156 |
▶ | } else if (cxt->netorder) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (cxt->netorder) { |
57 |
99 |
156 |
|
| 2514 |
|
| #ifndef HAS_HTONL |
| 2515 |
|
| TRACEME(("no htonl, fall back to string for integer")); |
| 2516 |
|
| goto string_readlen; |
| 2517 |
|
| #else |
| 2518 |
|
| I32 niv; |
| 2519 |
|
| |
| 2520 |
|
| |
| 2521 |
|
| #if IVSIZE > 4 |
| 2522 |
57 |
| if ( |
| 2523 |
|
| #ifdef SVf_IVisUV |
| 2524 |
|
| /* Sorry. This isn't in 5.005_56 (IIRC) or earlier. */ |
| 2525 |
57 |
▶ | ((flags & SVf_IVisUV) && SvUV(sv) > (UV)0x7FFFFFFF) || |
Branch: 2 branches
| Branch | True | False | Total |
| ((flags & SVf_IVisUV) && SvUV(sv) > (UV)0x7FFFFFFF) || |
0 |
57 |
57 |
| ((flags & SVf_IVisUV) && SvUV(sv) > (UV)0x7FFFFFFF) || |
0 |
0 |
0 |
|
| 2526 |
|
| #endif |
| 2527 |
57 |
▶ | (iv > (IV)0x7FFFFFFF) || (iv < -(IV)0x80000000)) { |
Branch: 2 branches
| Branch | True | False | Total |
| (iv > (IV)0x7FFFFFFF) || (iv < -(IV)0x80000000)) { |
41 |
16 |
57 |
| (iv > (IV)0x7FFFFFFF) || (iv < -(IV)0x80000000)) { |
6 |
35 |
41 |
|
| 2528 |
|
| /* Bigger than 32 bits. */ |
| 2529 |
|
| TRACEME(("large network order integer as string, value = %" IVdf, iv)); |
| 2530 |
22 |
| goto string_readlen; |
| 2531 |
|
| } |
| 2532 |
|
| #endif |
| 2533 |
|
| |
| 2534 |
35 |
| niv = (I32) htonl((I32) iv); |
| 2535 |
|
| TRACEME(("using network order")); |
| 2536 |
35 |
▶ | PUTMARK(SX_NETINT); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_NETINT); |
14 |
21 |
35 |
| PUTMARK(SX_NETINT); |
14 |
0 |
14 |
| PUTMARK(SX_NETINT); |
0 |
21 |
21 |
|
| 2537 |
35 |
▶ | WRITE_I32(niv); |
Branch: 4 branches
| Branch | True | False | Total |
| WRITE_I32(niv); |
14 |
21 |
35 |
| WRITE_I32(niv); |
0 |
14 |
14 |
| WRITE_I32(niv); |
0 |
14 |
14 |
| WRITE_I32(niv); |
0 |
21 |
21 |
|
| 2538 |
|
| #endif |
| 2539 |
|
| } else { |
| 2540 |
99 |
▶ | PUTMARK(SX_INTEGER); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_INTEGER); |
64 |
35 |
99 |
| PUTMARK(SX_INTEGER); |
64 |
0 |
64 |
| PUTMARK(SX_INTEGER); |
0 |
35 |
35 |
|
| 2541 |
99 |
▶ | WRITE(&iv, sizeof(iv)); |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(&iv, sizeof(iv)); |
64 |
35 |
99 |
| WRITE(&iv, sizeof(iv)); |
0 |
64 |
64 |
| WRITE(&iv, sizeof(iv)); |
0 |
35 |
35 |
|
| 2542 |
|
| } |
| 2543 |
|
| |
| 2544 |
|
| TRACEME(("ok (integer 0x%" UVxf ", value = %" IVdf ")", PTR2UV(sv), iv)); |
| 2545 |
30 |
▶ | } else if (flags & SVf_NOK) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (flags & SVf_NOK) { |
30 |
0 |
30 |
|
| 2546 |
|
| NV_bytes nv; |
| 2547 |
|
| #ifdef NV_CLEAR |
| 2548 |
|
| /* if we can't tell if there's padding, clear the whole NV and hope the |
| 2549 |
|
| compiler leaves the padding alone |
| 2550 |
|
| */ |
| 2551 |
|
| Zero(&nv, 1, NV_bytes); |
| 2552 |
|
| #endif |
| 2553 |
|
| #if PERL_VERSION_LT(5,7,0) |
| 2554 |
|
| nv.nv = SvNV(sv); |
| 2555 |
|
| /* |
| 2556 |
|
| * Watch for number being an integer in disguise. |
| 2557 |
|
| */ |
| 2558 |
|
| if (nv.nv == (NV) (iv = I_V(nv.nv))) { |
| 2559 |
|
| TRACEME(("double %" NVff " is actually integer %" IVdf, nv, iv)); |
| 2560 |
|
| goto integer; /* Share code above */ |
| 2561 |
|
| } |
| 2562 |
|
| #else |
| 2563 |
|
| |
| 2564 |
30 |
▶ | SvIV_please(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| SvIV_please(sv); |
26 |
4 |
30 |
| SvIV_please(sv); |
26 |
0 |
26 |
|
| 2565 |
30 |
▶ | if (SvIOK_notUV(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvIOK_notUV(sv)) { |
5 |
25 |
30 |
|
| 2566 |
5 |
| iv = SvIV(sv); |
| 2567 |
5 |
| goto integer; /* Share code above */ |
| 2568 |
|
| } |
| 2569 |
25 |
| nv.nv = SvNV(sv); |
| 2570 |
|
| #endif |
| 2571 |
|
| |
| 2572 |
25 |
▶ | if (cxt->netorder) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->netorder) { |
5 |
20 |
25 |
|
| 2573 |
|
| TRACEME(("double %" NVff " stored as string", nv.nv)); |
| 2574 |
5 |
| goto string_readlen; /* Share code below */ |
| 2575 |
|
| } |
| 2576 |
|
| #if NV_PADDING |
| 2577 |
|
| Zero(nv.bytes + NVSIZE - NV_PADDING, NV_PADDING, char); |
| 2578 |
|
| #endif |
| 2579 |
|
| |
| 2580 |
20 |
▶ | PUTMARK(SX_DOUBLE); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_DOUBLE); |
12 |
8 |
20 |
| PUTMARK(SX_DOUBLE); |
12 |
0 |
12 |
| PUTMARK(SX_DOUBLE); |
0 |
8 |
8 |
|
| 2581 |
20 |
▶ | WRITE(&nv, sizeof(nv)); |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(&nv, sizeof(nv)); |
12 |
8 |
20 |
| WRITE(&nv, sizeof(nv)); |
0 |
12 |
12 |
| WRITE(&nv, sizeof(nv)); |
0 |
8 |
8 |
|
| 2582 |
|
| |
| 2583 |
|
| TRACEME(("ok (double 0x%" UVxf ", value = %" NVff ")", PTR2UV(sv), nv.nv)); |
| 2584 |
|
| |
| 2585 |
0 |
▶ | } else if (flags & (SVp_POK | SVp_NOK | SVp_IOK)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (flags & (SVp_POK | SVp_NOK | SVp_IOK)) { |
0 |
0 |
0 |
|
| 2586 |
|
| #ifdef SvVOK |
| 2587 |
|
| const char *vstr_pv; |
| 2588 |
|
| STRLEN vstr_len; |
| 2589 |
|
| #endif |
| 2590 |
|
| UV wlen; /* For 64-bit machines */ |
| 2591 |
|
| |
| 2592 |
21387 |
| string_readlen: |
| 2593 |
21387 |
| pv = SvPV(sv, len); |
| 2594 |
|
| |
| 2595 |
|
| /* |
| 2596 |
|
| * Will come here from above if it was readonly, POK and NOK but |
| 2597 |
|
| * neither &PL_sv_yes nor &PL_sv_no. |
| 2598 |
|
| */ |
| 2599 |
21387 |
| string: |
| 2600 |
|
| |
| 2601 |
|
| #ifdef SvVOK |
| 2602 |
21387 |
▶ | if ((vstr_pv = SvVSTRING(sv, vstr_len))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((vstr_pv = SvVSTRING(sv, vstr_len))) { |
2 |
21385 |
21387 |
|
| 2603 |
|
| /* we no longer accept vstrings over I32_SIZE-1, so don't emit |
| 2604 |
|
| them, also, older Storables handle them badly. |
| 2605 |
|
| */ |
| 2606 |
2 |
▶ | if (vstr_len >= I32_MAX) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (vstr_len >= I32_MAX) { |
0 |
2 |
2 |
|
| 2607 |
0 |
| CROAK(("vstring too large to freeze")); |
| 2608 |
|
| } |
| 2609 |
2 |
▶ | STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
Branch: 43 branches
| Branch | True | False | Total |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
1 |
2 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
1 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
1 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
1 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
1 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
1 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
1 |
0 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
1 |
1 |
| STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING); |
0 |
0 |
0 |
|
| 2610 |
|
| } |
| 2611 |
|
| #endif |
| 2612 |
|
| |
| 2613 |
21387 |
| wlen = (Size_t)len; |
| 2614 |
21387 |
▶ | if (SvUTF8 (sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8 (sv)) |
12 |
21375 |
21387 |
|
| 2615 |
12 |
▶ | STORE_UTF8STR(pv, wlen); |
Branch: 43 branches
| Branch | True | False | Total |
| STORE_UTF8STR(pv, wlen); |
11 |
1 |
12 |
| STORE_UTF8STR(pv, wlen); |
11 |
0 |
11 |
| STORE_UTF8STR(pv, wlen); |
11 |
0 |
11 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
11 |
0 |
11 |
| STORE_UTF8STR(pv, wlen); |
11 |
0 |
11 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
11 |
0 |
11 |
| STORE_UTF8STR(pv, wlen); |
11 |
0 |
11 |
| STORE_UTF8STR(pv, wlen); |
0 |
11 |
11 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
1 |
1 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
1 |
0 |
1 |
| STORE_UTF8STR(pv, wlen); |
1 |
0 |
1 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
1 |
1 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
1 |
0 |
1 |
| STORE_UTF8STR(pv, wlen); |
0 |
1 |
1 |
| STORE_UTF8STR(pv, wlen); |
1 |
0 |
1 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
| STORE_UTF8STR(pv, wlen); |
1 |
0 |
1 |
| STORE_UTF8STR(pv, wlen); |
0 |
1 |
1 |
| STORE_UTF8STR(pv, wlen); |
0 |
0 |
0 |
|
| 2616 |
|
| else |
| 2617 |
21375 |
▶ | STORE_SCALAR(pv, wlen); |
Branch: 43 branches
| Branch | True | False | Total |
| STORE_SCALAR(pv, wlen); |
21375 |
0 |
21375 |
| STORE_SCALAR(pv, wlen); |
21316 |
59 |
21375 |
| STORE_SCALAR(pv, wlen); |
21316 |
0 |
21316 |
| STORE_SCALAR(pv, wlen); |
0 |
59 |
59 |
| STORE_SCALAR(pv, wlen); |
21316 |
59 |
21375 |
| STORE_SCALAR(pv, wlen); |
21316 |
0 |
21316 |
| STORE_SCALAR(pv, wlen); |
0 |
59 |
59 |
| STORE_SCALAR(pv, wlen); |
21372 |
3 |
21375 |
| STORE_SCALAR(pv, wlen); |
21315 |
57 |
21372 |
| STORE_SCALAR(pv, wlen); |
3 |
21312 |
21315 |
| STORE_SCALAR(pv, wlen); |
0 |
57 |
57 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
| STORE_SCALAR(pv, wlen); |
0 |
0 |
0 |
|
| 2618 |
|
| TRACEME(("ok (scalar 0x%" UVxf " '%s', length = %" UVuf ")", |
| 2619 |
|
| PTR2UV(sv), len >= 2048 ? "<string too long>" : SvPVX(sv), |
| 2620 |
|
| (UV)len)); |
| 2621 |
|
| } else { |
| 2622 |
0 |
| CROAK(("Can't determine type of %s(0x%" UVxf ")", |
| 2623 |
|
| sv_reftype(sv, FALSE), |
| 2624 |
|
| PTR2UV(sv))); |
| 2625 |
|
| } |
| 2626 |
21912 |
| return 0; /* Ok, no recursion on scalars */ |
| 2627 |
|
| } |
| 2628 |
|
| |
| 2629 |
|
| /* |
| 2630 |
|
| * store_array |
| 2631 |
|
| * |
| 2632 |
|
| * Store an array. |
| 2633 |
|
| * |
| 2634 |
|
| * Layout is SX_ARRAY <size> followed by each item, in increasing index order. |
| 2635 |
|
| * Each item is stored as <object>. |
| 2636 |
|
| */ |
| 2637 |
53459 |
| static int store_array(pTHX_ stcxt_t *cxt, SV *xsv) |
| 2638 |
|
| { |
| 2639 |
53459 |
| AV *av = (AV *)xsv; |
| 2640 |
|
| SV **sav; |
| 2641 |
53459 |
| UV len = av_len(av) + 1; |
| 2642 |
|
| UV i; |
| 2643 |
|
| int ret; |
| 2644 |
53459 |
| SV *const recur_sv = cxt->recur_sv; |
| 2645 |
|
| |
| 2646 |
|
| TRACEME(("store_array (0x%" UVxf ")", PTR2UV(av))); |
| 2647 |
|
| |
| 2648 |
|
| #ifdef HAS_U64 |
| 2649 |
53459 |
▶ | if (len > 0x7fffffffu) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 0x7fffffffu) { |
0 |
53459 |
53459 |
|
| 2650 |
|
| /* |
| 2651 |
|
| * Large array by emitting SX_LOBJECT 1 U64 data |
| 2652 |
|
| */ |
| 2653 |
0 |
▶ | PUTMARK(SX_LOBJECT); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
|
| 2654 |
0 |
▶ | PUTMARK(SX_ARRAY); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_ARRAY); |
0 |
0 |
0 |
| PUTMARK(SX_ARRAY); |
0 |
0 |
0 |
| PUTMARK(SX_ARRAY); |
0 |
0 |
0 |
|
| 2655 |
0 |
▶ | W64LEN(len); |
Branch: 7 branches
| Branch | True | False | Total |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
|
| 2656 |
|
| TRACEME(("lobject size = %lu", (unsigned long)len)); |
| 2657 |
|
| } else |
| 2658 |
|
| #endif |
| 2659 |
|
| { |
| 2660 |
|
| /* |
| 2661 |
|
| * Normal array by emitting SX_ARRAY, followed by the array length. |
| 2662 |
|
| */ |
| 2663 |
53459 |
| I32 l = (I32)len; |
| 2664 |
53459 |
▶ | PUTMARK(SX_ARRAY); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_ARRAY); |
53439 |
20 |
53459 |
| PUTMARK(SX_ARRAY); |
53439 |
0 |
53439 |
| PUTMARK(SX_ARRAY); |
0 |
20 |
20 |
|
| 2665 |
53459 |
▶ | WLEN(l); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(l); |
29 |
53430 |
53459 |
| WLEN(l); |
22 |
7 |
29 |
| WLEN(l); |
0 |
22 |
22 |
| WLEN(l); |
2 |
20 |
22 |
| WLEN(l); |
0 |
7 |
7 |
| WLEN(l); |
53417 |
13 |
53430 |
| WLEN(l); |
21 |
53396 |
53417 |
| WLEN(l); |
24173 |
29244 |
53417 |
| WLEN(l); |
0 |
13 |
13 |
|
| 2666 |
|
| TRACEME(("size = %d", (int)l)); |
| 2667 |
|
| } |
| 2668 |
|
| |
| 2669 |
|
| TRACEME((">array recur_depth %" IVdf ", recur_sv (0x%" UVxf ") max %" IVdf, cxt->recur_depth, |
| 2670 |
|
| PTR2UV(cxt->recur_sv), cxt->max_recur_depth)); |
| 2671 |
53459 |
▶ | if (recur_sv != (SV*)av) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (recur_sv != (SV*)av) { |
93 |
53366 |
53459 |
|
| 2672 |
93 |
▶ | if (RECURSION_TOO_DEEP()) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (RECURSION_TOO_DEEP()) { |
93 |
0 |
93 |
| if (RECURSION_TOO_DEEP()) { |
0 |
93 |
93 |
|
| 2673 |
|
| /* with <= 5.14 it recurses in the cleanup also, needing 2x stack size */ |
| 2674 |
|
| #if PERL_VERSION_LT(5,15,0) |
| 2675 |
|
| cleanup_recursive_data(aTHX_ (SV*)av); |
| 2676 |
|
| #endif |
| 2677 |
0 |
| CROAK((MAX_DEPTH_ERROR)); |
| 2678 |
|
| } |
| 2679 |
|
| } |
| 2680 |
|
| |
| 2681 |
|
| /* |
| 2682 |
|
| * Now store each item recursively. |
| 2683 |
|
| */ |
| 2684 |
|
| |
| 2685 |
122562 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
69135 |
53427 |
122562 |
|
| 2686 |
69135 |
| sav = av_fetch(av, i, 0); |
| 2687 |
69135 |
▶ | if (!sav) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sav) { |
3 |
69132 |
69135 |
|
| 2688 |
|
| TRACEME(("(#%d) nonexistent item", (int)i)); |
| 2689 |
3 |
▶ | STORE_SV_UNDEF(); |
Branch: 3 branches
| Branch | True | False | Total |
| STORE_SV_UNDEF(); |
3 |
0 |
3 |
| STORE_SV_UNDEF(); |
3 |
0 |
3 |
| STORE_SV_UNDEF(); |
0 |
0 |
0 |
|
| 2690 |
3 |
| continue; |
| 2691 |
|
| } |
| 2692 |
|
| #if PERL_VERSION_GE(5,19,0) |
| 2693 |
|
| /* In 5.19.3 and up, &PL_sv_undef can actually be stored in |
| 2694 |
|
| * an array; it no longer represents nonexistent elements. |
| 2695 |
|
| * Historically, we have used SX_SV_UNDEF in arrays for |
| 2696 |
|
| * nonexistent elements, so we use SX_SVUNDEF_ELEM for |
| 2697 |
|
| * &PL_sv_undef itself. */ |
| 2698 |
69132 |
▶ | if (*sav == &PL_sv_undef) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*sav == &PL_sv_undef) { |
0 |
69132 |
69132 |
|
| 2699 |
|
| TRACEME(("(#%d) undef item", (int)i)); |
| 2700 |
0 |
| cxt->tagnum++; |
| 2701 |
0 |
▶ | PUTMARK(SX_SVUNDEF_ELEM); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_SVUNDEF_ELEM); |
0 |
0 |
0 |
| PUTMARK(SX_SVUNDEF_ELEM); |
0 |
0 |
0 |
| PUTMARK(SX_SVUNDEF_ELEM); |
0 |
0 |
0 |
|
| 2702 |
0 |
| continue; |
| 2703 |
|
| } |
| 2704 |
|
| #endif |
| 2705 |
|
| TRACEME(("(#%d) item", (int)i)); |
| 2706 |
69132 |
▶ | if ((ret = store(aTHX_ cxt, *sav))) /* Extra () for -Wall */ |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, *sav))) /* Extra () for -Wall */ |
0 |
69100 |
69100 |
|
| 2707 |
0 |
| return ret; |
| 2708 |
|
| } |
| 2709 |
|
| |
| 2710 |
53427 |
▶ | if (recur_sv != (SV*)av) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (recur_sv != (SV*)av) { |
90 |
53337 |
53427 |
|
| 2711 |
|
| assert(cxt->max_recur_depth == -1 || cxt->recur_depth > 0); |
| 2712 |
90 |
▶ | if (cxt->max_recur_depth != -1 && cxt->recur_depth > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cxt->max_recur_depth != -1 && cxt->recur_depth > 0) { |
90 |
0 |
90 |
| if (cxt->max_recur_depth != -1 && cxt->recur_depth > 0) { |
90 |
0 |
90 |
|
| 2713 |
|
| TRACEME(("<array recur_depth --%" IVdf, cxt->recur_depth)); |
| 2714 |
90 |
| --cxt->recur_depth; |
| 2715 |
|
| } |
| 2716 |
|
| } |
| 2717 |
|
| TRACEME(("ok (array)")); |
| 2718 |
|
| |
| 2719 |
53427 |
| return 0; |
| 2720 |
|
| } |
| 2721 |
|
| |
| 2722 |
|
| |
| 2723 |
|
| #if PERL_VERSION_LT(5,7,0) |
| 2724 |
|
| |
| 2725 |
|
| /* |
| 2726 |
|
| * sortcmp |
| 2727 |
|
| * |
| 2728 |
|
| * Sort two SVs |
| 2729 |
|
| * Borrowed from perl source file pp_ctl.c, where it is used by pp_sort. |
| 2730 |
|
| */ |
| 2731 |
|
| static int |
| 2732 |
|
| sortcmp(const void *a, const void *b) |
| 2733 |
|
| { |
| 2734 |
|
| #if defined(USE_ITHREADS) |
| 2735 |
|
| dTHX; |
| 2736 |
|
| #endif /* USE_ITHREADS */ |
| 2737 |
|
| return sv_cmp(*(SV * const *) a, *(SV * const *) b); |
| 2738 |
|
| } |
| 2739 |
|
| |
| 2740 |
|
| #endif /* PERL_VERSION_LT(5,7,0) */ |
| 2741 |
|
| |
| 2742 |
|
| /* |
| 2743 |
|
| * store_hash |
| 2744 |
|
| * |
| 2745 |
|
| * Store a hash table. |
| 2746 |
|
| * |
| 2747 |
|
| * For a "normal" hash (not restricted, no utf8 keys): |
| 2748 |
|
| * |
| 2749 |
|
| * Layout is SX_HASH <size> followed by each key/value pair, in random order. |
| 2750 |
|
| * Values are stored as <object>. |
| 2751 |
|
| * Keys are stored as <length> <data>, the <data> section being omitted |
| 2752 |
|
| * if length is 0. |
| 2753 |
|
| * |
| 2754 |
|
| * For a "fancy" hash (restricted or utf8 keys): |
| 2755 |
|
| * |
| 2756 |
|
| * Layout is SX_FLAG_HASH <size> <hash flags> followed by each key/value pair, |
| 2757 |
|
| * in random order. |
| 2758 |
|
| * Values are stored as <object>. |
| 2759 |
|
| * Keys are stored as <flags> <length> <data>, the <data> section being omitted |
| 2760 |
|
| * if length is 0. |
| 2761 |
|
| * Currently the only hash flag is "restricted" |
| 2762 |
|
| * Key flags are as for hv.h |
| 2763 |
|
| */ |
| 2764 |
6236 |
| static int store_hash(pTHX_ stcxt_t *cxt, SV *xsv) |
| 2765 |
|
| { |
| 2766 |
6236 |
| HV *hv = (HV *)xsv; |
| 2767 |
|
| dVAR; |
| 2768 |
6236 |
| UV len = (UV)HvTOTALKEYS(hv); |
| 2769 |
|
| Size_t i; |
| 2770 |
6236 |
| int ret = 0; |
| 2771 |
|
| I32 riter; |
| 2772 |
|
| HE *eiter; |
| 2773 |
12472 |
| int flagged_hash = ((SvREADONLY(hv) |
| 2774 |
|
| #ifdef HAS_HASH_KEY_FLAGS |
| 2775 |
6124 |
| || HvHASKFLAGS(hv) |
| 2776 |
|
| #endif |
| 2777 |
6236 |
▶ | ) ? 1 : 0); |
Branch: 2 branches
| Branch | True | False | Total |
| ) ? 1 : 0); |
6124 |
112 |
6236 |
| ) ? 1 : 0); |
23 |
6101 |
6124 |
|
| 2778 |
6236 |
| unsigned char hash_flags = (SvREADONLY(hv) ? SHV_RESTRICTED : 0); |
| 2779 |
6236 |
| SV * const recur_sv = cxt->recur_sv; |
| 2780 |
|
| |
| 2781 |
|
| /* |
| 2782 |
|
| * Signal hash by emitting SX_HASH, followed by the table length. |
| 2783 |
|
| * Max number of keys per perl version: |
| 2784 |
|
| * IV - 5.12 |
| 2785 |
|
| * STRLEN 5.14 - 5.24 (size_t: U32/U64) |
| 2786 |
|
| * SSize_t 5.22c - 5.24c (I32/I64) |
| 2787 |
|
| * U32 5.25c - |
| 2788 |
|
| */ |
| 2789 |
|
| |
| 2790 |
6236 |
▶ | if (len > 0x7fffffffu) { /* keys > I32_MAX */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 0x7fffffffu) { /* keys > I32_MAX */ |
0 |
6236 |
6236 |
|
| 2791 |
|
| /* |
| 2792 |
|
| * Large hash: SX_LOBJECT type hashflags? U64 data |
| 2793 |
|
| * |
| 2794 |
|
| * Stupid limitation: |
| 2795 |
|
| * Note that perl5 can store more than 2G keys, but only iterate |
| 2796 |
|
| * over 2G max. (cperl can) |
| 2797 |
|
| * We need to manually iterate over it then, unsorted. |
| 2798 |
|
| * But until perl itself cannot do that, skip that. |
| 2799 |
|
| */ |
| 2800 |
|
| TRACEME(("lobject size = %lu", (unsigned long)len)); |
| 2801 |
|
| #ifdef HAS_U64 |
| 2802 |
0 |
▶ | PUTMARK(SX_LOBJECT); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
|
| 2803 |
0 |
▶ | if (flagged_hash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flagged_hash) { |
0 |
0 |
0 |
|
| 2804 |
0 |
▶ | PUTMARK(SX_FLAG_HASH); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_FLAG_HASH); |
0 |
0 |
0 |
| PUTMARK(SX_FLAG_HASH); |
0 |
0 |
0 |
| PUTMARK(SX_FLAG_HASH); |
0 |
0 |
0 |
|
| 2805 |
0 |
▶ | PUTMARK(hash_flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(hash_flags); |
0 |
0 |
0 |
| PUTMARK(hash_flags); |
0 |
0 |
0 |
| PUTMARK(hash_flags); |
0 |
0 |
0 |
|
| 2806 |
|
| } else { |
| 2807 |
0 |
▶ | PUTMARK(SX_HASH); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_HASH); |
0 |
0 |
0 |
| PUTMARK(SX_HASH); |
0 |
0 |
0 |
| PUTMARK(SX_HASH); |
0 |
0 |
0 |
|
| 2808 |
|
| } |
| 2809 |
0 |
▶ | W64LEN(len); |
Branch: 7 branches
| Branch | True | False | Total |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
| W64LEN(len); |
0 |
0 |
0 |
|
| 2810 |
0 |
| return store_lhash(aTHX_ cxt, hv, hash_flags); |
| 2811 |
|
| #else |
| 2812 |
|
| /* <5.12 you could store larger hashes, but cannot iterate over them. |
| 2813 |
|
| So we reject them, it's a bug. */ |
| 2814 |
|
| CROAK(("Cannot store large objects on a 32bit system")); |
| 2815 |
|
| #endif |
| 2816 |
|
| } else { |
| 2817 |
6236 |
| I32 l = (I32)len; |
| 2818 |
6236 |
▶ | if (flagged_hash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flagged_hash) { |
135 |
6101 |
6236 |
|
| 2819 |
|
| TRACEME(("store_hash (0x%" UVxf ") (flags %x)", PTR2UV(hv), |
| 2820 |
|
| (unsigned int)hash_flags)); |
| 2821 |
135 |
▶ | PUTMARK(SX_FLAG_HASH); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_FLAG_HASH); |
129 |
6 |
135 |
| PUTMARK(SX_FLAG_HASH); |
129 |
0 |
129 |
| PUTMARK(SX_FLAG_HASH); |
0 |
6 |
6 |
|
| 2822 |
135 |
▶ | PUTMARK(hash_flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(hash_flags); |
129 |
6 |
135 |
| PUTMARK(hash_flags); |
129 |
0 |
129 |
| PUTMARK(hash_flags); |
0 |
6 |
6 |
|
| 2823 |
|
| } else { |
| 2824 |
|
| TRACEME(("store_hash (0x%" UVxf ")", PTR2UV(hv))); |
| 2825 |
6101 |
▶ | PUTMARK(SX_HASH); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_HASH); |
6076 |
25 |
6101 |
| PUTMARK(SX_HASH); |
6076 |
0 |
6076 |
| PUTMARK(SX_HASH); |
0 |
25 |
25 |
|
| 2826 |
|
| } |
| 2827 |
6236 |
▶ | WLEN(l); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(l); |
25 |
6211 |
6236 |
| WLEN(l); |
11 |
14 |
25 |
| WLEN(l); |
0 |
11 |
11 |
| WLEN(l); |
5 |
6 |
11 |
| WLEN(l); |
0 |
14 |
14 |
| WLEN(l); |
6194 |
17 |
6211 |
| WLEN(l); |
2 |
6192 |
6194 |
| WLEN(l); |
5253 |
941 |
6194 |
| WLEN(l); |
0 |
17 |
17 |
|
| 2828 |
|
| TRACEME(("size = %d, used = %d", (int)l, (int)HvUSEDKEYS(hv))); |
| 2829 |
|
| } |
| 2830 |
|
| |
| 2831 |
|
| TRACEME((">hash recur_depth %" IVdf ", recur_sv (0x%" UVxf ") max %" IVdf, cxt->recur_depth, |
| 2832 |
|
| PTR2UV(cxt->recur_sv), cxt->max_recur_depth_hash)); |
| 2833 |
6236 |
▶ | if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1) { |
167 |
6069 |
6236 |
| if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1) { |
167 |
0 |
167 |
|
| 2834 |
167 |
| ++cxt->recur_depth; |
| 2835 |
|
| } |
| 2836 |
6236 |
▶ | if (RECURSION_TOO_DEEP_HASH()) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (RECURSION_TOO_DEEP_HASH()) { |
6236 |
0 |
6236 |
| if (RECURSION_TOO_DEEP_HASH()) { |
1 |
6235 |
6236 |
|
| 2837 |
|
| #if PERL_VERSION_LT(5,15,0) |
| 2838 |
|
| cleanup_recursive_data(aTHX_ (SV*)hv); |
| 2839 |
|
| #endif |
| 2840 |
1 |
| CROAK((MAX_DEPTH_ERROR)); |
| 2841 |
|
| } |
| 2842 |
|
| |
| 2843 |
|
| /* |
| 2844 |
|
| * Save possible iteration state via each() on that table. |
| 2845 |
|
| * |
| 2846 |
|
| * Note that perl as of 5.24 *can* store more than 2G keys, but *not* |
| 2847 |
|
| * iterate over it. |
| 2848 |
|
| * Lengths of hash keys are also limited to I32, which is good. |
| 2849 |
|
| */ |
| 2850 |
|
| |
| 2851 |
6235 |
▶ | riter = HvRITER_get(hv); |
Branch: 1 branch
| Branch | True | False | Total |
| riter = HvRITER_get(hv); |
763 |
5472 |
6235 |
|
| 2852 |
6235 |
▶ | eiter = HvEITER_get(hv); |
Branch: 1 branch
| Branch | True | False | Total |
| eiter = HvEITER_get(hv); |
763 |
5472 |
6235 |
|
| 2853 |
6235 |
| hv_iterinit(hv); |
| 2854 |
|
| |
| 2855 |
|
| /* |
| 2856 |
|
| * Now store each item recursively. |
| 2857 |
|
| * |
| 2858 |
|
| * If canonical is defined to some true value then store each |
| 2859 |
|
| * key/value pair in sorted order otherwise the order is random. |
| 2860 |
|
| * Canonical order is irrelevant when a deep clone operation is performed. |
| 2861 |
|
| * |
| 2862 |
|
| * Fetch the value from perl only once per store() operation, and only |
| 2863 |
|
| * when needed. |
| 2864 |
|
| */ |
| 2865 |
|
| |
| 2866 |
6235 |
| if ( |
| 2867 |
6235 |
▶ | !(cxt->optype & ST_CLONE) |
Branch: 1 branch
| Branch | True | False | Total |
| !(cxt->optype & ST_CLONE) |
947 |
5288 |
6235 |
|
| 2868 |
947 |
▶ | && (cxt->canonical == 1 |
Branch: 1 branch
| Branch | True | False | Total |
| && (cxt->canonical == 1 |
528 |
419 |
947 |
|
| 2869 |
528 |
▶ | || (cxt->canonical < 0 |
Branch: 1 branch
| Branch | True | False | Total |
| || (cxt->canonical < 0 |
86 |
442 |
528 |
|
| 2870 |
86 |
| && (cxt->canonical = |
| 2871 |
86 |
| (SvTRUE(get_sv("Storable::canonical", GV_ADD)) |
| 2872 |
86 |
▶ | ? 1 : 0)))) |
Branch: 1 branch
| Branch | True | False | Total |
| ? 1 : 0)))) |
19 |
67 |
86 |
|
| 2873 |
438 |
| ) { |
| 2874 |
|
| /* |
| 2875 |
|
| * Storing in order, sorted by key. |
| 2876 |
|
| * Run through the hash, building up an array of keys in a |
| 2877 |
|
| * mortal array, sort the array and then run through the |
| 2878 |
|
| * array. |
| 2879 |
|
| */ |
| 2880 |
438 |
| AV *av = newAV(); |
| 2881 |
438 |
| av_extend (av, len); |
| 2882 |
|
| |
| 2883 |
|
| TRACEME(("using canonical order")); |
| 2884 |
|
| |
| 2885 |
5644 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
5206 |
438 |
5644 |
|
| 2886 |
|
| #ifdef HAS_RESTRICTED_HASHES |
| 2887 |
5206 |
| HE *he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS); |
| 2888 |
|
| #else |
| 2889 |
|
| HE *he = hv_iternext(hv); |
| 2890 |
|
| #endif |
| 2891 |
5206 |
| av_store(av, i, hv_iterkeysv(he)); |
| 2892 |
|
| } |
| 2893 |
|
| |
| 2894 |
438 |
| STORE_HASH_SORT; |
| 2895 |
|
| |
| 2896 |
5644 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
5206 |
438 |
5644 |
|
| 2897 |
|
| #ifdef HAS_RESTRICTED_HASHES |
| 2898 |
5206 |
▶ | int placeholders = (int)HvPLACEHOLDERS_get(hv); |
Branch: 1 branch
| Branch | True | False | Total |
| int placeholders = (int)HvPLACEHOLDERS_get(hv); |
21 |
5185 |
5206 |
|
| 2899 |
|
| #endif |
| 2900 |
5206 |
| unsigned char flags = 0; |
| 2901 |
|
| char *keyval; |
| 2902 |
|
| STRLEN keylen_tmp; |
| 2903 |
|
| I32 keylen; |
| 2904 |
5206 |
| SV *key = av_shift(av); |
| 2905 |
|
| /* This will fail if key is a placeholder. |
| 2906 |
|
| Track how many placeholders we have, and error if we |
| 2907 |
|
| "see" too many. */ |
| 2908 |
5206 |
| HE *he = hv_fetch_ent(hv, key, 0, 0); |
| 2909 |
|
| SV *val; |
| 2910 |
|
| |
| 2911 |
5206 |
▶ | if (he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (he) { |
5188 |
18 |
5206 |
|
| 2912 |
5188 |
▶ | if (!(val = HeVAL(he))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(val = HeVAL(he))) { |
0 |
5188 |
5188 |
|
| 2913 |
|
| /* Internal error, not I/O error */ |
| 2914 |
0 |
| return 1; |
| 2915 |
|
| } |
| 2916 |
|
| } else { |
| 2917 |
|
| #ifdef HAS_RESTRICTED_HASHES |
| 2918 |
|
| /* Should be a placeholder. */ |
| 2919 |
18 |
▶ | if (placeholders-- < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (placeholders-- < 0) { |
0 |
18 |
18 |
|
| 2920 |
|
| /* This should not happen - number of |
| 2921 |
|
| retrieves should be identical to |
| 2922 |
|
| number of placeholders. */ |
| 2923 |
0 |
| return 1; |
| 2924 |
|
| } |
| 2925 |
|
| /* Value is never needed, and PL_sv_undef is |
| 2926 |
|
| more space efficient to store. */ |
| 2927 |
18 |
| val = &PL_sv_undef; |
| 2928 |
|
| ASSERT (flags == 0, |
| 2929 |
|
| ("Flags not 0 but %d", (int)flags)); |
| 2930 |
18 |
| flags = SHV_K_PLACEHOLDER; |
| 2931 |
|
| #else |
| 2932 |
|
| return 1; |
| 2933 |
|
| #endif |
| 2934 |
|
| } |
| 2935 |
|
| |
| 2936 |
|
| /* |
| 2937 |
|
| * Store value first. |
| 2938 |
|
| */ |
| 2939 |
|
| |
| 2940 |
|
| TRACEME(("(#%d) value 0x%" UVxf, (int)i, PTR2UV(val))); |
| 2941 |
|
| |
| 2942 |
5206 |
▶ | if ((ret = store(aTHX_ cxt, val))) /* Extra () for -Wall, grr... */ |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, val))) /* Extra () for -Wall, grr... */ |
0 |
5206 |
5206 |
|
| 2943 |
0 |
| goto out; |
| 2944 |
|
| |
| 2945 |
|
| /* |
| 2946 |
|
| * Write key string. |
| 2947 |
|
| * Keys are written after values to make sure retrieval |
| 2948 |
|
| * can be optimal in terms of memory usage, where keys are |
| 2949 |
|
| * read into a fixed unique buffer called kbuf. |
| 2950 |
|
| * See retrieve_hash() for details. |
| 2951 |
|
| */ |
| 2952 |
|
| |
| 2953 |
|
| /* Implementation of restricted hashes isn't nicely |
| 2954 |
|
| abstracted: */ |
| 2955 |
5206 |
▶ | if ((hash_flags & SHV_RESTRICTED) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((hash_flags & SHV_RESTRICTED) |
22 |
5184 |
5206 |
|
| 2956 |
22 |
▶ | && SvTRULYREADONLY(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTRULYREADONLY(val)) { |
20 |
2 |
22 |
|
| 2957 |
20 |
| flags |= SHV_K_LOCKED; |
| 2958 |
|
| } |
| 2959 |
|
| |
| 2960 |
5206 |
| keyval = SvPV(key, keylen_tmp); |
| 2961 |
5206 |
| keylen = keylen_tmp; |
| 2962 |
5206 |
▶ | if (SvUTF8(key)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(key)) { |
14 |
5192 |
5206 |
|
| 2963 |
|
| |
| 2964 |
|
| #ifdef utf8_to_bytes_overwrite |
| 2965 |
|
| |
| 2966 |
|
| /* If we are able to downgrade here; that means that we have a |
| 2967 |
|
| * key which only had chars 0-255, but was utf8 encoded. */ |
| 2968 |
14 |
▶ | if (utf8_to_bytes_overwrite( (U8**) &keyval, &keylen_tmp)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8_to_bytes_overwrite( (U8**) &keyval, &keylen_tmp)) { |
5 |
9 |
14 |
|
| 2969 |
5 |
| keylen = keylen_tmp; |
| 2970 |
5 |
| flags |= SHV_K_WASUTF8; |
| 2971 |
|
| } |
| 2972 |
|
| else { |
| 2973 |
9 |
| flags |= SHV_K_UTF8; |
| 2974 |
|
| } |
| 2975 |
|
| #else |
| 2976 |
|
| const char *keysave = keyval; |
| 2977 |
|
| bool is_utf8 = TRUE; |
| 2978 |
|
| |
| 2979 |
|
| /* Just casting the &klen to (STRLEN) won't work |
| 2980 |
|
| well if STRLEN and I32 are of different widths. |
| 2981 |
|
| --jhi */ |
| 2982 |
|
| keyval = (char*)bytes_from_utf8((U8*)keyval, |
| 2983 |
|
| &keylen_tmp, |
| 2984 |
|
| &is_utf8); |
| 2985 |
|
| |
| 2986 |
|
| /* If we were able to downgrade here, then than |
| 2987 |
|
| means that we have a key which only had chars |
| 2988 |
|
| 0-255, but was utf8 encoded. */ |
| 2989 |
|
| |
| 2990 |
|
| if (keyval != keysave) { |
| 2991 |
|
| keylen = keylen_tmp; |
| 2992 |
|
| flags |= SHV_K_WASUTF8; |
| 2993 |
|
| } else { |
| 2994 |
|
| /* keylen_tmp can't have changed, so no need |
| 2995 |
|
| to assign back to keylen. */ |
| 2996 |
|
| flags |= SHV_K_UTF8; |
| 2997 |
|
| } |
| 2998 |
|
| #endif |
| 2999 |
|
| } |
| 3000 |
|
| |
| 3001 |
5206 |
▶ | if (flagged_hash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flagged_hash) { |
48 |
5158 |
5206 |
|
| 3002 |
48 |
▶ | PUTMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flags); |
40 |
8 |
48 |
| PUTMARK(flags); |
40 |
0 |
40 |
| PUTMARK(flags); |
0 |
8 |
8 |
|
| 3003 |
|
| TRACEME(("(#%d) key '%s' flags %x %u", (int)i, keyval, flags, *keyval)); |
| 3004 |
|
| } else { |
| 3005 |
|
| /* This is a workaround for a bug in 5.8.0 |
| 3006 |
|
| that causes the HEK_WASUTF8 flag to be |
| 3007 |
|
| set on an HEK without the hash being |
| 3008 |
|
| marked as having key flags. We just |
| 3009 |
|
| cross our fingers and drop the flag. |
| 3010 |
|
| AMS 20030901 */ |
| 3011 |
|
| assert (flags == 0 || flags == SHV_K_WASUTF8); |
| 3012 |
|
| TRACEME(("(#%d) key '%s'", (int)i, keyval)); |
| 3013 |
|
| } |
| 3014 |
5206 |
▶ | WLEN(keylen); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(keylen); |
18 |
5188 |
5206 |
| WLEN(keylen); |
14 |
4 |
18 |
| WLEN(keylen); |
0 |
14 |
14 |
| WLEN(keylen); |
2 |
12 |
14 |
| WLEN(keylen); |
0 |
4 |
4 |
| WLEN(keylen); |
5184 |
4 |
5188 |
| WLEN(keylen); |
0 |
5184 |
5184 |
| WLEN(keylen); |
1443 |
3741 |
5184 |
| WLEN(keylen); |
0 |
4 |
4 |
|
| 3015 |
5206 |
▶ | if (keylen) |
Branch: 1 branch
| Branch | True | False | Total |
| if (keylen) |
5206 |
0 |
5206 |
|
| 3016 |
5206 |
▶ | WRITE(keyval, keylen); |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(keyval, keylen); |
5198 |
8 |
5206 |
| WRITE(keyval, keylen); |
0 |
5198 |
5198 |
| WRITE(keyval, keylen); |
0 |
8 |
8 |
|
| 3017 |
|
| |
| 3018 |
|
| #ifndef utf8_to_bytes_overwrite |
| 3019 |
|
| |
| 3020 |
|
| if (flags & SHV_K_WASUTF8) |
| 3021 |
|
| Safefree (keyval); |
| 3022 |
|
| #endif |
| 3023 |
|
| } |
| 3024 |
|
| |
| 3025 |
|
| /* |
| 3026 |
|
| * Free up the temporary array |
| 3027 |
|
| */ |
| 3028 |
|
| |
| 3029 |
438 |
| av_undef(av); |
| 3030 |
438 |
| sv_free((SV *) av); |
| 3031 |
|
| |
| 3032 |
|
| } else { |
| 3033 |
|
| |
| 3034 |
|
| /* |
| 3035 |
|
| * Storing in "random" order (in the order the keys are stored |
| 3036 |
|
| * within the hash). This is the default and will be faster! |
| 3037 |
|
| */ |
| 3038 |
|
| |
| 3039 |
17938 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
12162 |
5776 |
17938 |
|
| 3040 |
|
| #ifdef HV_ITERNEXT_WANTPLACEHOLDERS |
| 3041 |
12162 |
| HE *he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS); |
| 3042 |
|
| #else |
| 3043 |
|
| HE *he = hv_iternext(hv); |
| 3044 |
|
| #endif |
| 3045 |
12162 |
▶ | SV *val = (he ? hv_iterval(hv, he) : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *val = (he ? hv_iterval(hv, he) : 0); |
12162 |
0 |
12162 |
|
| 3046 |
|
| |
| 3047 |
12162 |
▶ | if (val == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (val == 0) |
0 |
12162 |
12162 |
|
| 3048 |
0 |
| return 1; /* Internal error, not I/O error */ |
| 3049 |
|
| |
| 3050 |
12162 |
▶ | if ((ret = store_hentry(aTHX_ cxt, hv, i, HeKEY_hek(he), val, hash_flags))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store_hentry(aTHX_ cxt, hv, i, HeKEY_hek(he), val, hash_flags))) |
0 |
12141 |
12141 |
|
| 3051 |
0 |
| goto out; |
| 3052 |
|
| } |
| 3053 |
|
| } |
| 3054 |
|
| |
| 3055 |
|
| TRACEME(("ok (hash 0x%" UVxf ")", PTR2UV(hv))); |
| 3056 |
|
| |
| 3057 |
5776 |
| out: |
| 3058 |
|
| assert(cxt->max_recur_depth_hash != -1 && cxt->recur_depth > 0); |
| 3059 |
|
| TRACEME(("<hash recur_depth --%" IVdf , cxt->recur_depth)); |
| 3060 |
6214 |
▶ | if (cxt->max_recur_depth_hash != -1 && recur_sv != (SV*)hv && cxt->recur_depth > 0) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (cxt->max_recur_depth_hash != -1 && recur_sv != (SV*)hv && cxt->recur_depth > 0) { |
6214 |
0 |
6214 |
| if (cxt->max_recur_depth_hash != -1 && recur_sv != (SV*)hv && cxt->recur_depth > 0) { |
165 |
6049 |
6214 |
| if (cxt->max_recur_depth_hash != -1 && recur_sv != (SV*)hv && cxt->recur_depth > 0) { |
165 |
0 |
165 |
|
| 3061 |
165 |
| --cxt->recur_depth; |
| 3062 |
|
| } |
| 3063 |
6214 |
| HvRITER_set(hv, riter); /* Restore hash iterator state */ |
| 3064 |
6214 |
| HvEITER_set(hv, eiter); |
| 3065 |
|
| |
| 3066 |
6214 |
| return ret; |
| 3067 |
|
| } |
| 3068 |
|
| |
| 3069 |
12162 |
| static int store_hentry(pTHX_ |
| 3070 |
|
| stcxt_t *cxt, HV* hv, UV i, HEK *hek, SV *val, unsigned char hash_flags) |
| 3071 |
|
| { |
| 3072 |
12162 |
| int ret = 0; |
| 3073 |
24324 |
| int flagged_hash = ((SvREADONLY(hv) |
| 3074 |
|
| #ifdef HAS_HASH_KEY_FLAGS |
| 3075 |
7046 |
| || HvHASKFLAGS(hv) |
| 3076 |
|
| #endif |
| 3077 |
12162 |
▶ | ) ? 1 : 0); |
Branch: 2 branches
| Branch | True | False | Total |
| ) ? 1 : 0); |
7046 |
5116 |
12162 |
| ) ? 1 : 0); |
31 |
7015 |
7046 |
|
| 3078 |
|
| /* Implementation of restricted hashes isn't nicely |
| 3079 |
|
| abstracted: */ |
| 3080 |
17278 |
▶ | unsigned char flags = (((hash_flags & SHV_RESTRICTED) |
Branch: 1 branch
| Branch | True | False | Total |
| unsigned char flags = (((hash_flags & SHV_RESTRICTED) |
5116 |
7046 |
12162 |
|
| 3081 |
5116 |
▶ | && SvTRULYREADONLY(val)) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTRULYREADONLY(val)) |
5110 |
6 |
5116 |
|
| 3082 |
|
| ? SHV_K_LOCKED : 0); |
| 3083 |
|
| #ifndef DEBUGME |
| 3084 |
|
| PERL_UNUSED_ARG(i); |
| 3085 |
|
| #endif |
| 3086 |
12162 |
▶ | if (val == &PL_sv_placeholder) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (val == &PL_sv_placeholder) { |
5104 |
7058 |
12162 |
|
| 3087 |
5104 |
| flags |= SHV_K_PLACEHOLDER; |
| 3088 |
5104 |
| val = &PL_sv_undef; |
| 3089 |
|
| } |
| 3090 |
|
| |
| 3091 |
|
| /* |
| 3092 |
|
| * Store value first. |
| 3093 |
|
| */ |
| 3094 |
|
| |
| 3095 |
|
| TRACEME(("(#%d) value 0x%" UVxf, (int)i, PTR2UV(val))); |
| 3096 |
|
| |
| 3097 |
|
| { |
| 3098 |
12162 |
| I32 len = HEK_LEN(hek); |
| 3099 |
12162 |
| SV *key_sv = NULL; |
| 3100 |
12162 |
| char *key = 0; |
| 3101 |
|
| |
| 3102 |
12162 |
▶ | if ((ret = store(aTHX_ cxt, val))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, val))) |
0 |
12141 |
12141 |
|
| 3103 |
0 |
| return ret; |
| 3104 |
12141 |
▶ | if (len == HEf_SVKEY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == HEf_SVKEY) { |
0 |
12141 |
12141 |
|
| 3105 |
|
| /* This is somewhat sick, but the internal APIs are |
| 3106 |
|
| * such that XS code could put one of these in |
| 3107 |
|
| * a regular hash. |
| 3108 |
|
| * Maybe we should be capable of storing one if |
| 3109 |
|
| * found. |
| 3110 |
|
| */ |
| 3111 |
0 |
| key_sv = (SV *)HEK_KEY(hek); |
| 3112 |
0 |
| flags |= SHV_K_ISSV; |
| 3113 |
|
| } else { |
| 3114 |
|
| /* Regular string key. */ |
| 3115 |
|
| #ifdef HAS_HASH_KEY_FLAGS |
| 3116 |
12141 |
▶ | if (HEK_UTF8(hek)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (HEK_UTF8(hek)) |
9 |
12132 |
12141 |
|
| 3117 |
9 |
| flags |= SHV_K_UTF8; |
| 3118 |
12141 |
▶ | if (HEK_WASUTF8(hek)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (HEK_WASUTF8(hek)) |
6 |
12135 |
12141 |
|
| 3119 |
6 |
| flags |= SHV_K_WASUTF8; |
| 3120 |
|
| #endif |
| 3121 |
12141 |
| key = HEK_KEY(hek); |
| 3122 |
|
| } |
| 3123 |
|
| /* |
| 3124 |
|
| * Write key string. |
| 3125 |
|
| * Keys are written after values to make sure retrieval |
| 3126 |
|
| * can be optimal in terms of memory usage, where keys are |
| 3127 |
|
| * read into a fixed unique buffer called kbuf. |
| 3128 |
|
| * See retrieve_hash() for details. |
| 3129 |
|
| */ |
| 3130 |
|
| |
| 3131 |
12141 |
▶ | if (flagged_hash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flagged_hash) { |
5147 |
6994 |
12141 |
|
| 3132 |
5147 |
▶ | PUTMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flags); |
5137 |
10 |
5147 |
| PUTMARK(flags); |
5137 |
0 |
5137 |
| PUTMARK(flags); |
0 |
10 |
10 |
|
| 3133 |
|
| TRACEME(("(#%d) key '%s' flags %x", (int)i, key, flags)); |
| 3134 |
|
| } else { |
| 3135 |
|
| /* This is a workaround for a bug in 5.8.0 |
| 3136 |
|
| that causes the HEK_WASUTF8 flag to be |
| 3137 |
|
| set on an HEK without the hash being |
| 3138 |
|
| marked as having key flags. We just |
| 3139 |
|
| cross our fingers and drop the flag. |
| 3140 |
|
| AMS 20030901 */ |
| 3141 |
|
| assert (flags == 0 || flags == SHV_K_WASUTF8); |
| 3142 |
|
| TRACEME(("(#%d) key '%s'", (int)i, key)); |
| 3143 |
|
| } |
| 3144 |
12141 |
▶ | if (flags & SHV_K_ISSV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHV_K_ISSV) { |
0 |
12141 |
12141 |
|
| 3145 |
0 |
▶ | if ((ret = store(aTHX_ cxt, key_sv))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, key_sv))) |
0 |
0 |
0 |
|
| 3146 |
0 |
| return ret; |
| 3147 |
|
| } else { |
| 3148 |
12141 |
▶ | WLEN(len); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(len); |
28 |
12113 |
12141 |
| WLEN(len); |
7 |
21 |
28 |
| WLEN(len); |
0 |
7 |
7 |
| WLEN(len); |
1 |
6 |
7 |
| WLEN(len); |
0 |
21 |
21 |
| WLEN(len); |
12087 |
26 |
12113 |
| WLEN(len); |
2 |
12085 |
12087 |
| WLEN(len); |
3031 |
9056 |
12087 |
| WLEN(len); |
0 |
26 |
26 |
|
| 3149 |
12141 |
▶ | if (len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len) |
12137 |
4 |
12141 |
|
| 3150 |
12137 |
▶ | WRITE(key, len); |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(key, len); |
12090 |
47 |
12137 |
| WRITE(key, len); |
3 |
12087 |
12090 |
| WRITE(key, len); |
0 |
47 |
47 |
|
| 3151 |
|
| } |
| 3152 |
|
| } |
| 3153 |
12141 |
| return ret; |
| 3154 |
|
| } |
| 3155 |
|
| |
| 3156 |
|
| |
| 3157 |
|
| #ifdef HAS_U64 |
| 3158 |
|
| /* |
| 3159 |
|
| * store_lhash |
| 3160 |
|
| * |
| 3161 |
|
| * Store a overlong hash table, with >2G keys, which we cannot iterate |
| 3162 |
|
| * over with perl5. xhv_eiter is only I32 there. (only cperl can) |
| 3163 |
|
| * and we also do not want to sort it. |
| 3164 |
|
| * So we walk the buckets and chains manually. |
| 3165 |
|
| * |
| 3166 |
|
| * type, len and flags are already written. |
| 3167 |
|
| */ |
| 3168 |
|
| |
| 3169 |
0 |
| static int store_lhash(pTHX_ stcxt_t *cxt, HV *hv, unsigned char hash_flags) |
| 3170 |
|
| { |
| 3171 |
|
| dVAR; |
| 3172 |
0 |
| int ret = 0; |
| 3173 |
|
| Size_t i; |
| 3174 |
0 |
| UV ix = 0; |
| 3175 |
|
| HE** array; |
| 3176 |
|
| #ifdef DEBUGME |
| 3177 |
|
| UV len = (UV)HvTOTALKEYS(hv); |
| 3178 |
|
| #endif |
| 3179 |
0 |
| SV * const recur_sv = cxt->recur_sv; |
| 3180 |
|
| if (hash_flags) { |
| 3181 |
|
| TRACEME(("store_lhash (0x%" UVxf ") (flags %x)", PTR2UV(hv), |
| 3182 |
|
| (int) hash_flags)); |
| 3183 |
|
| } else { |
| 3184 |
|
| TRACEME(("store_lhash (0x%" UVxf ")", PTR2UV(hv))); |
| 3185 |
|
| } |
| 3186 |
|
| TRACEME(("size = %" UVuf ", used = %" UVuf, len, (UV)HvUSEDKEYS(hv))); |
| 3187 |
|
| |
| 3188 |
|
| TRACEME(("recur_depth %" IVdf ", recur_sv (0x%" UVxf ")", cxt->recur_depth, |
| 3189 |
|
| PTR2UV(cxt->recur_sv))); |
| 3190 |
0 |
▶ | if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1) { |
0 |
0 |
0 |
| if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1) { |
0 |
0 |
0 |
|
| 3191 |
0 |
| ++cxt->recur_depth; |
| 3192 |
|
| } |
| 3193 |
0 |
▶ | if (RECURSION_TOO_DEEP_HASH()) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (RECURSION_TOO_DEEP_HASH()) { |
0 |
0 |
0 |
| if (RECURSION_TOO_DEEP_HASH()) { |
0 |
0 |
0 |
|
| 3194 |
|
| #if PERL_VERSION_LT(5,15,0) |
| 3195 |
|
| cleanup_recursive_data(aTHX_ (SV*)hv); |
| 3196 |
|
| #endif |
| 3197 |
0 |
| CROAK((MAX_DEPTH_ERROR)); |
| 3198 |
|
| } |
| 3199 |
|
| |
| 3200 |
0 |
| array = HvARRAY(hv); |
| 3201 |
0 |
▶ | for (i = 0; i <= (Size_t)HvMAX(hv); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= (Size_t)HvMAX(hv); i++) { |
0 |
0 |
0 |
|
| 3202 |
0 |
| HE* entry = array[i]; |
| 3203 |
|
| |
| 3204 |
0 |
▶ | while (entry) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (entry) { |
0 |
0 |
0 |
|
| 3205 |
0 |
| SV* val = hv_iterval(hv, entry); |
| 3206 |
0 |
▶ | if ((ret = store_hentry(aTHX_ cxt, hv, ix++, HeKEY_hek(entry), val, hash_flags))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store_hentry(aTHX_ cxt, hv, ix++, HeKEY_hek(entry), val, hash_flags))) |
0 |
0 |
0 |
|
| 3207 |
0 |
| return ret; |
| 3208 |
0 |
| entry = HeNEXT(entry); |
| 3209 |
|
| } |
| 3210 |
|
| } |
| 3211 |
0 |
▶ | if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1 && cxt->recur_depth > 0) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1 && cxt->recur_depth > 0) { |
0 |
0 |
0 |
| if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1 && cxt->recur_depth > 0) { |
0 |
0 |
0 |
| if (recur_sv != (SV*)hv && cxt->max_recur_depth_hash != -1 && cxt->recur_depth > 0) { |
0 |
0 |
0 |
|
| 3212 |
|
| TRACEME(("recur_depth --%" IVdf, cxt->recur_depth)); |
| 3213 |
0 |
| --cxt->recur_depth; |
| 3214 |
|
| } |
| 3215 |
|
| assert(ix == len); |
| 3216 |
0 |
| return ret; |
| 3217 |
|
| } |
| 3218 |
|
| #endif |
| 3219 |
|
| |
| 3220 |
|
| /* |
| 3221 |
|
| * store_code |
| 3222 |
|
| * |
| 3223 |
|
| * Store a code reference. |
| 3224 |
|
| * |
| 3225 |
|
| * Layout is SX_CODE <length> followed by a scalar containing the perl |
| 3226 |
|
| * source code of the code reference. |
| 3227 |
|
| */ |
| 3228 |
73 |
| static int store_code(pTHX_ stcxt_t *cxt, SV *xsv) |
| 3229 |
|
| { |
| 3230 |
73 |
| CV *cv = (CV *)xsv; |
| 3231 |
73 |
| dSP; |
| 3232 |
|
| STRLEN len; |
| 3233 |
|
| STRLEN count, reallen; |
| 3234 |
|
| SV *text, *bdeparse; |
| 3235 |
|
| |
| 3236 |
|
| TRACEME(("store_code (0x%" UVxf ")", PTR2UV(cv))); |
| 3237 |
|
| |
| 3238 |
73 |
| if ( |
| 3239 |
73 |
▶ | cxt->deparse == 0 || |
Branch: 1 branch
| Branch | True | False | Total |
| cxt->deparse == 0 || |
73 |
0 |
73 |
|
| 3240 |
73 |
▶ | (cxt->deparse < 0 && |
Branch: 1 branch
| Branch | True | False | Total |
| (cxt->deparse < 0 && |
41 |
32 |
73 |
|
| 3241 |
41 |
| !(cxt->deparse = |
| 3242 |
41 |
▶ | SvTRUE(get_sv("Storable::Deparse", GV_ADD)) ? 1 : 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| SvTRUE(get_sv("Storable::Deparse", GV_ADD)) ? 1 : 0)) |
3 |
38 |
41 |
|
| 3243 |
|
| ) { |
| 3244 |
3 |
| return store_other(aTHX_ cxt, (SV*)cv); |
| 3245 |
|
| } |
| 3246 |
|
| |
| 3247 |
|
| /* |
| 3248 |
|
| * Require B::Deparse. At least B::Deparse 0.61 is needed for |
| 3249 |
|
| * blessed code references. |
| 3250 |
|
| */ |
| 3251 |
|
| /* Ownership of both SVs is passed to load_module, which frees them. */ |
| 3252 |
70 |
| load_module(PERL_LOADMOD_NOIMPORT, newSVpvs("B::Deparse"), newSVnv(0.61)); |
| 3253 |
70 |
| SPAGAIN; |
| 3254 |
|
| |
| 3255 |
70 |
| ENTER; |
| 3256 |
70 |
| SAVETMPS; |
| 3257 |
|
| |
| 3258 |
|
| /* |
| 3259 |
|
| * create the B::Deparse object |
| 3260 |
|
| */ |
| 3261 |
|
| |
| 3262 |
70 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
70 |
70 |
|
| 3263 |
70 |
▶ | XPUSHs(newSVpvs_flags("B::Deparse", SVs_TEMP)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(newSVpvs_flags("B::Deparse", SVs_TEMP)); |
0 |
70 |
70 |
|
| 3264 |
70 |
| PUTBACK; |
| 3265 |
70 |
| count = call_method("new", G_SCALAR); |
| 3266 |
70 |
| SPAGAIN; |
| 3267 |
70 |
▶ | if (count != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count != 1) |
0 |
70 |
70 |
|
| 3268 |
0 |
| CROAK(("Unexpected return value from B::Deparse::new\n")); |
| 3269 |
70 |
| bdeparse = POPs; |
| 3270 |
|
| |
| 3271 |
|
| /* |
| 3272 |
|
| * call the coderef2text method |
| 3273 |
|
| */ |
| 3274 |
|
| |
| 3275 |
70 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
70 |
70 |
|
| 3276 |
70 |
▶ | XPUSHs(bdeparse); /* XXX is this already mortal? */ |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(bdeparse); /* XXX is this already mortal? */ |
0 |
70 |
70 |
|
| 3277 |
70 |
▶ | XPUSHs(sv_2mortal(newRV_inc((SV*)cv))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newRV_inc((SV*)cv))); |
0 |
70 |
70 |
|
| 3278 |
70 |
| PUTBACK; |
| 3279 |
70 |
| count = call_method("coderef2text", G_SCALAR); |
| 3280 |
70 |
| SPAGAIN; |
| 3281 |
70 |
▶ | if (count != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count != 1) |
0 |
70 |
70 |
|
| 3282 |
0 |
| CROAK(("Unexpected return value from B::Deparse::coderef2text\n")); |
| 3283 |
|
| |
| 3284 |
70 |
| text = POPs; |
| 3285 |
70 |
| PUTBACK; |
| 3286 |
70 |
| len = SvCUR(text); |
| 3287 |
70 |
| reallen = strlen(SvPV_nolen(text)); |
| 3288 |
|
| |
| 3289 |
|
| /* |
| 3290 |
|
| * Empty code references or XS functions are deparsed as |
| 3291 |
|
| * "(prototype) ;" or ";". |
| 3292 |
|
| */ |
| 3293 |
|
| |
| 3294 |
140 |
▶ | if (len == 0 || *(SvPV_nolen(text)+reallen-1) == ';') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (len == 0 || *(SvPV_nolen(text)+reallen-1) == ';') { |
70 |
0 |
70 |
| if (len == 0 || *(SvPV_nolen(text)+reallen-1) == ';') { |
1 |
69 |
70 |
|
| 3295 |
1 |
| CROAK(("The result of B::Deparse::coderef2text was empty - maybe you're trying to serialize an XS function?\n")); |
| 3296 |
|
| } |
| 3297 |
|
| |
| 3298 |
|
| /* |
| 3299 |
|
| * Signal code by emitting SX_CODE. |
| 3300 |
|
| */ |
| 3301 |
|
| |
| 3302 |
69 |
▶ | PUTMARK(SX_CODE); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_CODE); |
55 |
14 |
69 |
| PUTMARK(SX_CODE); |
55 |
0 |
55 |
| PUTMARK(SX_CODE); |
0 |
14 |
14 |
|
| 3303 |
69 |
| cxt->tagnum++; /* necessary, as SX_CODE is a SEEN() candidate */ |
| 3304 |
|
| TRACEME(("size = %d", (int)len)); |
| 3305 |
|
| TRACEME(("code = %s", SvPV_nolen(text))); |
| 3306 |
|
| |
| 3307 |
|
| /* |
| 3308 |
|
| * Now store the source code. |
| 3309 |
|
| */ |
| 3310 |
|
| |
| 3311 |
69 |
▶ | if(SvUTF8 (text)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvUTF8 (text)) |
8 |
61 |
69 |
|
| 3312 |
17 |
▶ | STORE_UTF8STR(SvPV_nolen(text), len); |
Branch: 43 branches
| Branch | True | False | Total |
| STORE_UTF8STR(SvPV_nolen(text), len); |
2 |
6 |
8 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
2 |
0 |
2 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
2 |
0 |
2 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
2 |
0 |
2 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
2 |
0 |
2 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
2 |
0 |
2 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
2 |
0 |
2 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
2 |
2 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
6 |
6 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
4 |
2 |
6 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
4 |
0 |
4 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
2 |
2 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
1 |
5 |
6 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
1 |
1 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
1 |
1 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
4 |
1 |
5 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
4 |
4 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
3 |
1 |
4 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
1 |
1 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
4 |
2 |
6 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
4 |
4 |
| STORE_UTF8STR(SvPV_nolen(text), len); |
0 |
2 |
2 |
|
| 3313 |
|
| else |
| 3314 |
122 |
▶ | STORE_SCALAR(SvPV_nolen(text), len); |
Branch: 43 branches
| Branch | True | False | Total |
| STORE_SCALAR(SvPV_nolen(text), len); |
58 |
3 |
61 |
| STORE_SCALAR(SvPV_nolen(text), len); |
46 |
12 |
58 |
| STORE_SCALAR(SvPV_nolen(text), len); |
46 |
0 |
46 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
12 |
12 |
| STORE_SCALAR(SvPV_nolen(text), len); |
46 |
12 |
58 |
| STORE_SCALAR(SvPV_nolen(text), len); |
46 |
0 |
46 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
12 |
12 |
| STORE_SCALAR(SvPV_nolen(text), len); |
58 |
0 |
58 |
| STORE_SCALAR(SvPV_nolen(text), len); |
46 |
12 |
58 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
46 |
46 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
12 |
12 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
3 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
3 |
0 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
3 |
0 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
3 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
3 |
0 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
3 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
3 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
| STORE_SCALAR(SvPV_nolen(text), len); |
3 |
0 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
3 |
3 |
| STORE_SCALAR(SvPV_nolen(text), len); |
0 |
0 |
0 |
|
| 3315 |
|
| |
| 3316 |
69 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
69 |
0 |
69 |
|
| 3317 |
69 |
| LEAVE; |
| 3318 |
|
| |
| 3319 |
|
| TRACEME(("ok (code)")); |
| 3320 |
|
| |
| 3321 |
69 |
| return 0; |
| 3322 |
|
| } |
| 3323 |
|
| |
| 3324 |
|
| #if PERL_VERSION_LT(5,8,0) |
| 3325 |
|
| # define PERL_MAGIC_qr 'r' /* precompiled qr// regex */ |
| 3326 |
|
| # define BFD_Svs_SMG_OR_RMG SVs_RMG |
| 3327 |
|
| #elif PERL_VERSION_GE(5,8,1) |
| 3328 |
|
| # define BFD_Svs_SMG_OR_RMG SVs_SMG |
| 3329 |
|
| # define MY_PLACEHOLDER PL_sv_placeholder |
| 3330 |
|
| #else |
| 3331 |
|
| # define BFD_Svs_SMG_OR_RMG SVs_RMG |
| 3332 |
|
| # define MY_PLACEHOLDER PL_sv_undef |
| 3333 |
|
| #endif |
| 3334 |
|
| |
| 3335 |
41 |
| static int get_regexp(pTHX_ stcxt_t *cxt, SV* sv, SV **re, SV **flags) { |
| 3336 |
41 |
| dSP; |
| 3337 |
|
| SV* rv; |
| 3338 |
|
| #if PERL_VERSION_GE(5,12,0) |
| 3339 |
41 |
| CV *cv = get_cv("re::regexp_pattern", 0); |
| 3340 |
|
| #else |
| 3341 |
|
| CV *cv = get_cv("Storable::_regexp_pattern", 0); |
| 3342 |
|
| #endif |
| 3343 |
|
| I32 count; |
| 3344 |
|
| |
| 3345 |
|
| assert(cv); |
| 3346 |
|
| |
| 3347 |
41 |
| ENTER; |
| 3348 |
41 |
| SAVETMPS; |
| 3349 |
41 |
| rv = sv_2mortal((SV*)newRV_inc(sv)); |
| 3350 |
41 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
41 |
41 |
|
| 3351 |
41 |
▶ | XPUSHs(rv); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(rv); |
0 |
41 |
41 |
|
| 3352 |
41 |
| PUTBACK; |
| 3353 |
|
| /* optimize to call the XS directly later */ |
| 3354 |
41 |
| count = call_sv((SV*)cv, G_LIST); |
| 3355 |
41 |
| SPAGAIN; |
| 3356 |
41 |
▶ | if (count < 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count < 2) |
0 |
41 |
41 |
|
| 3357 |
0 |
| CROAK(("re::regexp_pattern returned only %d results", (int)count)); |
| 3358 |
41 |
| *flags = POPs; |
| 3359 |
41 |
| SvREFCNT_inc(*flags); |
| 3360 |
41 |
| *re = POPs; |
| 3361 |
41 |
| SvREFCNT_inc(*re); |
| 3362 |
|
| |
| 3363 |
41 |
| PUTBACK; |
| 3364 |
41 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
41 |
0 |
41 |
|
| 3365 |
41 |
| LEAVE; |
| 3366 |
|
| |
| 3367 |
41 |
| return 1; |
| 3368 |
|
| } |
| 3369 |
|
| |
| 3370 |
41 |
| static int store_regexp(pTHX_ stcxt_t *cxt, SV *sv) { |
| 3371 |
41 |
| SV *re = NULL; |
| 3372 |
41 |
| SV *flags = NULL; |
| 3373 |
|
| const char *re_pv; |
| 3374 |
|
| const char *flags_pv; |
| 3375 |
|
| STRLEN re_len; |
| 3376 |
|
| STRLEN flags_len; |
| 3377 |
41 |
| U8 op_flags = 0; |
| 3378 |
|
| |
| 3379 |
41 |
▶ | if (!get_regexp(aTHX_ cxt, sv, &re, &flags)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!get_regexp(aTHX_ cxt, sv, &re, &flags)) |
0 |
41 |
41 |
|
| 3380 |
0 |
| return -1; |
| 3381 |
|
| |
| 3382 |
41 |
| re_pv = SvPV(re, re_len); |
| 3383 |
41 |
▶ | flags_pv = SvPV(flags, flags_len); |
Branch: 1 branch
| Branch | True | False | Total |
| flags_pv = SvPV(flags, flags_len); |
41 |
0 |
41 |
|
| 3384 |
|
| |
| 3385 |
41 |
▶ | if (re_len > 0xFF) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (re_len > 0xFF) { |
0 |
41 |
41 |
|
| 3386 |
0 |
| op_flags |= SHR_U32_RE_LEN; |
| 3387 |
|
| } |
| 3388 |
|
| |
| 3389 |
41 |
▶ | PUTMARK(SX_REGEXP); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_REGEXP); |
41 |
0 |
41 |
| PUTMARK(SX_REGEXP); |
41 |
0 |
41 |
| PUTMARK(SX_REGEXP); |
0 |
0 |
0 |
|
| 3390 |
41 |
▶ | PUTMARK(op_flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(op_flags); |
41 |
0 |
41 |
| PUTMARK(op_flags); |
41 |
0 |
41 |
| PUTMARK(op_flags); |
0 |
0 |
0 |
|
| 3391 |
41 |
▶ | if (op_flags & SHR_U32_RE_LEN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (op_flags & SHR_U32_RE_LEN) { |
0 |
41 |
41 |
|
| 3392 |
0 |
| U32 re_len32 = re_len; |
| 3393 |
0 |
▶ | WLEN(re_len32); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(re_len32); |
0 |
0 |
0 |
| WLEN(re_len32); |
0 |
0 |
0 |
| WLEN(re_len32); |
0 |
0 |
0 |
| WLEN(re_len32); |
0 |
0 |
0 |
| WLEN(re_len32); |
0 |
0 |
0 |
| WLEN(re_len32); |
0 |
0 |
0 |
| WLEN(re_len32); |
0 |
0 |
0 |
| WLEN(re_len32); |
0 |
0 |
0 |
| WLEN(re_len32); |
0 |
0 |
0 |
|
| 3394 |
|
| } |
| 3395 |
|
| else |
| 3396 |
41 |
▶ | PUTMARK(re_len); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(re_len); |
41 |
0 |
41 |
| PUTMARK(re_len); |
41 |
0 |
41 |
| PUTMARK(re_len); |
0 |
0 |
0 |
|
| 3397 |
41 |
▶ | WRITE(re_pv, re_len); |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(re_pv, re_len); |
41 |
0 |
41 |
| WRITE(re_pv, re_len); |
0 |
41 |
41 |
| WRITE(re_pv, re_len); |
0 |
0 |
0 |
|
| 3398 |
41 |
▶ | PUTMARK(flags_len); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flags_len); |
41 |
0 |
41 |
| PUTMARK(flags_len); |
41 |
0 |
41 |
| PUTMARK(flags_len); |
0 |
0 |
0 |
|
| 3399 |
41 |
▶ | WRITE(flags_pv, flags_len); |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(flags_pv, flags_len); |
41 |
0 |
41 |
| WRITE(flags_pv, flags_len); |
0 |
41 |
41 |
| WRITE(flags_pv, flags_len); |
0 |
0 |
0 |
|
| 3400 |
|
| |
| 3401 |
41 |
| return 0; |
| 3402 |
|
| } |
| 3403 |
|
| |
| 3404 |
|
| /* |
| 3405 |
|
| * store_tied |
| 3406 |
|
| * |
| 3407 |
|
| * When storing a tied object (be it a tied scalar, array or hash), we lay out |
| 3408 |
|
| * a special mark, followed by the underlying tied object. For instance, when |
| 3409 |
|
| * dealing with a tied hash, we store SX_TIED_HASH <hash object>, where |
| 3410 |
|
| * <hash object> stands for the serialization of the tied hash. |
| 3411 |
|
| */ |
| 3412 |
20 |
| static int store_tied(pTHX_ stcxt_t *cxt, SV *sv) |
| 3413 |
|
| { |
| 3414 |
|
| MAGIC *mg; |
| 3415 |
20 |
| SV *obj = NULL; |
| 3416 |
20 |
| int ret = 0; |
| 3417 |
20 |
| int svt = SvTYPE(sv); |
| 3418 |
20 |
| char mtype = 'P'; |
| 3419 |
|
| |
| 3420 |
|
| TRACEME(("store_tied (0x%" UVxf ")", PTR2UV(sv))); |
| 3421 |
|
| |
| 3422 |
|
| /* |
| 3423 |
|
| * We have a small run-time penalty here because we chose to factorise |
| 3424 |
|
| * all tieds objects into the same routine, and not have a store_tied_hash, |
| 3425 |
|
| * a store_tied_array, etc... |
| 3426 |
|
| * |
| 3427 |
|
| * Don't use a switch() statement, as most compilers don't optimize that |
| 3428 |
|
| * well for 2/3 values. An if() else if() cascade is just fine. We put |
| 3429 |
|
| * tied hashes first, as they are the most likely beasts. |
| 3430 |
|
| */ |
| 3431 |
|
| |
| 3432 |
20 |
▶ | if (svt == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svt == SVt_PVHV) { |
8 |
12 |
20 |
|
| 3433 |
|
| TRACEME(("tied hash")); |
| 3434 |
8 |
▶ | PUTMARK(SX_TIED_HASH); /* Introduces tied hash */ |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_TIED_HASH); /* Introduces tied hash */ |
8 |
0 |
8 |
| PUTMARK(SX_TIED_HASH); /* Introduces tied hash */ |
8 |
0 |
8 |
| PUTMARK(SX_TIED_HASH); /* Introduces tied hash */ |
0 |
0 |
0 |
|
| 3435 |
12 |
▶ | } else if (svt == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (svt == SVt_PVAV) { |
6 |
6 |
12 |
|
| 3436 |
|
| TRACEME(("tied array")); |
| 3437 |
6 |
▶ | PUTMARK(SX_TIED_ARRAY); /* Introduces tied array */ |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_TIED_ARRAY); /* Introduces tied array */ |
6 |
0 |
6 |
| PUTMARK(SX_TIED_ARRAY); /* Introduces tied array */ |
6 |
0 |
6 |
| PUTMARK(SX_TIED_ARRAY); /* Introduces tied array */ |
0 |
0 |
0 |
|
| 3438 |
|
| } else { |
| 3439 |
|
| TRACEME(("tied scalar")); |
| 3440 |
6 |
▶ | PUTMARK(SX_TIED_SCALAR); /* Introduces tied scalar */ |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_TIED_SCALAR); /* Introduces tied scalar */ |
6 |
0 |
6 |
| PUTMARK(SX_TIED_SCALAR); /* Introduces tied scalar */ |
6 |
0 |
6 |
| PUTMARK(SX_TIED_SCALAR); /* Introduces tied scalar */ |
0 |
0 |
0 |
|
| 3441 |
6 |
| mtype = 'q'; |
| 3442 |
|
| } |
| 3443 |
|
| |
| 3444 |
20 |
▶ | if (!(mg = mg_find(sv, mtype))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(mg = mg_find(sv, mtype))) |
0 |
20 |
20 |
|
| 3445 |
0 |
▶ | CROAK(("No magic '%c' found while storing tied %s", mtype, |
Branch: 2 branches
| Branch | True | False | Total |
| CROAK(("No magic '%c' found while storing tied %s", mtype, |
0 |
0 |
0 |
| CROAK(("No magic '%c' found while storing tied %s", mtype, |
0 |
0 |
0 |
|
| 3446 |
|
| (svt == SVt_PVHV) ? "hash" : |
| 3447 |
|
| (svt == SVt_PVAV) ? "array" : "scalar")); |
| 3448 |
|
| |
| 3449 |
|
| /* |
| 3450 |
|
| * The mg->mg_obj found by mg_find() above actually points to the |
| 3451 |
|
| * underlying tied Perl object implementation. For instance, if the |
| 3452 |
|
| * original SV was that of a tied array, then mg->mg_obj is an AV. |
| 3453 |
|
| * |
| 3454 |
|
| * Note that we store the Perl object as-is. We don't call its FETCH |
| 3455 |
|
| * method along the way. At retrieval time, we won't call its STORE |
| 3456 |
|
| * method either, but the tieing magic will be re-installed. In itself, |
| 3457 |
|
| * that ensures that the tieing semantics are preserved since further |
| 3458 |
|
| * accesses on the retrieved object will indeed call the magic methods... |
| 3459 |
|
| */ |
| 3460 |
|
| |
| 3461 |
|
| /* [#17040] mg_obj is NULL for scalar self-ties. AMS 20030416 */ |
| 3462 |
20 |
▶ | obj = mg->mg_obj ? mg->mg_obj : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| obj = mg->mg_obj ? mg->mg_obj : newSV(0); |
19 |
1 |
20 |
|
| 3463 |
20 |
▶ | if ((ret = store(aTHX_ cxt, obj))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, obj))) |
0 |
20 |
20 |
|
| 3464 |
0 |
| return ret; |
| 3465 |
|
| |
| 3466 |
|
| TRACEME(("ok (tied)")); |
| 3467 |
|
| |
| 3468 |
20 |
| return 0; |
| 3469 |
|
| } |
| 3470 |
|
| |
| 3471 |
|
| /* |
| 3472 |
|
| * store_tied_item |
| 3473 |
|
| * |
| 3474 |
|
| * Stores a reference to an item within a tied structure: |
| 3475 |
|
| * |
| 3476 |
|
| * . \$h{key}, stores both the (tied %h) object and 'key'. |
| 3477 |
|
| * . \$a[idx], stores both the (tied @a) object and 'idx'. |
| 3478 |
|
| * |
| 3479 |
|
| * Layout is therefore either: |
| 3480 |
|
| * SX_TIED_KEY <object> <key> |
| 3481 |
|
| * SX_TIED_IDX <object> <index> |
| 3482 |
|
| */ |
| 3483 |
2 |
| static int store_tied_item(pTHX_ stcxt_t *cxt, SV *sv) |
| 3484 |
|
| { |
| 3485 |
|
| MAGIC *mg; |
| 3486 |
|
| int ret; |
| 3487 |
|
| |
| 3488 |
|
| TRACEME(("store_tied_item (0x%" UVxf ")", PTR2UV(sv))); |
| 3489 |
|
| |
| 3490 |
2 |
▶ | if (!(mg = mg_find(sv, 'p'))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(mg = mg_find(sv, 'p'))) |
0 |
2 |
2 |
|
| 3491 |
0 |
| CROAK(("No magic 'p' found while storing reference to tied item")); |
| 3492 |
|
| |
| 3493 |
|
| /* |
| 3494 |
|
| * We discriminate between \$h{key} and \$a[idx] via mg_ptr. |
| 3495 |
|
| */ |
| 3496 |
|
| |
| 3497 |
2 |
▶ | if (mg->mg_ptr) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg->mg_ptr) { |
1 |
1 |
2 |
|
| 3498 |
|
| TRACEME(("store_tied_item: storing a ref to a tied hash item")); |
| 3499 |
1 |
▶ | PUTMARK(SX_TIED_KEY); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_TIED_KEY); |
1 |
0 |
1 |
| PUTMARK(SX_TIED_KEY); |
1 |
0 |
1 |
| PUTMARK(SX_TIED_KEY); |
0 |
0 |
0 |
|
| 3500 |
|
| TRACEME(("store_tied_item: storing OBJ 0x%" UVxf, PTR2UV(mg->mg_obj))); |
| 3501 |
|
| |
| 3502 |
1 |
▶ | if ((ret = store(aTHX_ cxt, mg->mg_obj))) /* Extra () for -Wall, grr... */ |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, mg->mg_obj))) /* Extra () for -Wall, grr... */ |
0 |
1 |
1 |
|
| 3503 |
0 |
| return ret; |
| 3504 |
|
| |
| 3505 |
|
| TRACEME(("store_tied_item: storing PTR 0x%" UVxf, PTR2UV(mg->mg_ptr))); |
| 3506 |
|
| |
| 3507 |
1 |
▶ | if ((ret = store(aTHX_ cxt, (SV *) mg->mg_ptr))) /* Idem, for -Wall */ |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, (SV *) mg->mg_ptr))) /* Idem, for -Wall */ |
0 |
1 |
1 |
|
| 3508 |
0 |
| return ret; |
| 3509 |
|
| } else { |
| 3510 |
1 |
| I32 idx = mg->mg_len; |
| 3511 |
|
| |
| 3512 |
|
| TRACEME(("store_tied_item: storing a ref to a tied array item ")); |
| 3513 |
1 |
▶ | PUTMARK(SX_TIED_IDX); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_TIED_IDX); |
1 |
0 |
1 |
| PUTMARK(SX_TIED_IDX); |
1 |
0 |
1 |
| PUTMARK(SX_TIED_IDX); |
0 |
0 |
0 |
|
| 3514 |
|
| TRACEME(("store_tied_item: storing OBJ 0x%" UVxf, PTR2UV(mg->mg_obj))); |
| 3515 |
|
| |
| 3516 |
1 |
▶ | if ((ret = store(aTHX_ cxt, mg->mg_obj))) /* Idem, for -Wall */ |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, mg->mg_obj))) /* Idem, for -Wall */ |
0 |
1 |
1 |
|
| 3517 |
0 |
| return ret; |
| 3518 |
|
| |
| 3519 |
|
| TRACEME(("store_tied_item: storing IDX %d", (int)idx)); |
| 3520 |
|
| |
| 3521 |
1 |
▶ | WLEN(idx); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(idx); |
0 |
1 |
1 |
| WLEN(idx); |
0 |
0 |
0 |
| WLEN(idx); |
0 |
0 |
0 |
| WLEN(idx); |
0 |
0 |
0 |
| WLEN(idx); |
0 |
0 |
0 |
| WLEN(idx); |
1 |
0 |
1 |
| WLEN(idx); |
0 |
1 |
1 |
| WLEN(idx); |
0 |
1 |
1 |
| WLEN(idx); |
0 |
0 |
0 |
|
| 3522 |
|
| } |
| 3523 |
|
| |
| 3524 |
|
| TRACEME(("ok (tied item)")); |
| 3525 |
|
| |
| 3526 |
2 |
| return 0; |
| 3527 |
|
| } |
| 3528 |
|
| |
| 3529 |
|
| /* |
| 3530 |
|
| * store_hook -- dispatched manually, not via sv_store[] |
| 3531 |
|
| * |
| 3532 |
|
| * The blessed SV is serialized by a hook. |
| 3533 |
|
| * |
| 3534 |
|
| * Simple Layout is: |
| 3535 |
|
| * |
| 3536 |
|
| * SX_HOOK <flags> <len> <classname> <len2> <str> [<len3> <object-IDs>] |
| 3537 |
|
| * |
| 3538 |
|
| * where <flags> indicates how long <len>, <len2> and <len3> are, whether |
| 3539 |
|
| * the trailing part [] is present, the type of object (scalar, array or hash). |
| 3540 |
|
| * There is also a bit which says how the classname is stored between: |
| 3541 |
|
| * |
| 3542 |
|
| * <len> <classname> |
| 3543 |
|
| * <index> |
| 3544 |
|
| * |
| 3545 |
|
| * and when the <index> form is used (classname already seen), the "large |
| 3546 |
|
| * classname" bit in <flags> indicates how large the <index> is. |
| 3547 |
|
| * |
| 3548 |
|
| * The serialized string returned by the hook is of length <len2> and comes |
| 3549 |
|
| * next. It is an opaque string for us. |
| 3550 |
|
| * |
| 3551 |
|
| * Those <len3> object IDs which are listed last represent the extra references |
| 3552 |
|
| * not directly serialized by the hook, but which are linked to the object. |
| 3553 |
|
| * |
| 3554 |
|
| * When recursion is mandated to resolve object-IDs not yet seen, we have |
| 3555 |
|
| * instead, with <header> being flags with bits set to indicate the object type |
| 3556 |
|
| * and that recursion was indeed needed: |
| 3557 |
|
| * |
| 3558 |
|
| * SX_HOOK <header> <object> <header> <object> <flags> |
| 3559 |
|
| * |
| 3560 |
|
| * that same header being repeated between serialized objects obtained through |
| 3561 |
|
| * recursion, until we reach flags indicating no recursion, at which point |
| 3562 |
|
| * we know we've resynchronized with a single layout, after <flags>. |
| 3563 |
|
| * |
| 3564 |
|
| * When storing a blessed ref to a tied variable, the following format is |
| 3565 |
|
| * used: |
| 3566 |
|
| * |
| 3567 |
|
| * SX_HOOK <flags> <extra> ... [<len3> <object-IDs>] <magic object> |
| 3568 |
|
| * |
| 3569 |
|
| * The first <flags> indication carries an object of type SHT_EXTRA, and the |
| 3570 |
|
| * real object type is held in the <extra> flag. At the very end of the |
| 3571 |
|
| * serialization stream, the underlying magic object is serialized, just like |
| 3572 |
|
| * any other tied variable. |
| 3573 |
|
| */ |
| 3574 |
120 |
| static int store_hook( |
| 3575 |
|
| pTHX_ |
| 3576 |
|
| stcxt_t *cxt, |
| 3577 |
|
| SV *sv, |
| 3578 |
|
| int type, |
| 3579 |
|
| HV *pkg, |
| 3580 |
|
| SV *hook) |
| 3581 |
|
| { |
| 3582 |
|
| I32 len; |
| 3583 |
|
| char *classname; |
| 3584 |
|
| STRLEN len2; |
| 3585 |
|
| SV *ref; |
| 3586 |
|
| AV *av; |
| 3587 |
|
| SV **ary; |
| 3588 |
|
| IV count; /* really len3 + 1 */ |
| 3589 |
|
| unsigned char flags; |
| 3590 |
|
| char *pv; |
| 3591 |
|
| int i; |
| 3592 |
120 |
| int recursed = 0; /* counts recursion */ |
| 3593 |
|
| int obj_type; /* object type, on 2 bits */ |
| 3594 |
|
| I32 classnum; |
| 3595 |
|
| int ret; |
| 3596 |
120 |
| int clone = cxt->optype & ST_CLONE; |
| 3597 |
120 |
| char mtype = '\0'; /* for blessed ref to tied structures */ |
| 3598 |
120 |
| unsigned char eflags = '\0'; /* used when object type is SHT_EXTRA */ |
| 3599 |
|
| #ifdef HAS_U64 |
| 3600 |
120 |
| int need_large_oids = 0; |
| 3601 |
|
| #endif |
| 3602 |
|
| |
| 3603 |
120 |
▶ | classname = HvNAME_get(pkg); |
Branch: 6 branches
| Branch | True | False | Total |
| classname = HvNAME_get(pkg); |
120 |
0 |
120 |
| classname = HvNAME_get(pkg); |
120 |
0 |
120 |
| classname = HvNAME_get(pkg); |
0 |
120 |
120 |
| classname = HvNAME_get(pkg); |
0 |
0 |
0 |
| classname = HvNAME_get(pkg); |
120 |
0 |
120 |
| classname = HvNAME_get(pkg); |
0 |
120 |
120 |
|
| 3604 |
120 |
| len = strlen(classname); |
| 3605 |
|
| |
| 3606 |
|
| TRACEME(("store_hook, classname \"%s\", tagged #%d", classname, (int)cxt->tagnum)); |
| 3607 |
|
| |
| 3608 |
|
| /* |
| 3609 |
|
| * Determine object type on 2 bits. |
| 3610 |
|
| */ |
| 3611 |
|
| |
| 3612 |
120 |
| switch (type) { |
| 3613 |
15 |
| case svis_REF: |
| 3614 |
|
| case svis_SCALAR: |
| 3615 |
|
| case svis_REGEXP: |
| 3616 |
15 |
| obj_type = SHT_SCALAR; |
| 3617 |
15 |
| break; |
| 3618 |
75 |
| case svis_ARRAY: |
| 3619 |
75 |
| obj_type = SHT_ARRAY; |
| 3620 |
75 |
| break; |
| 3621 |
28 |
| case svis_HASH: |
| 3622 |
28 |
| obj_type = SHT_HASH; |
| 3623 |
28 |
| break; |
| 3624 |
1 |
| case svis_TIED: |
| 3625 |
|
| /* |
| 3626 |
|
| * Produced by a blessed ref to a tied data structure, $o in the |
| 3627 |
|
| * following Perl code. |
| 3628 |
|
| * |
| 3629 |
|
| * my %h; |
| 3630 |
|
| * tie %h, 'FOO'; |
| 3631 |
|
| * my $o = bless \%h, 'BAR'; |
| 3632 |
|
| * |
| 3633 |
|
| * Signal the tie-ing magic by setting the object type as SHT_EXTRA |
| 3634 |
|
| * (since we have only 2 bits in <flags> to store the type), and an |
| 3635 |
|
| * <extra> byte flag will be emitted after the FIRST <flags> in the |
| 3636 |
|
| * stream, carrying what we put in 'eflags'. |
| 3637 |
|
| */ |
| 3638 |
1 |
| obj_type = SHT_EXTRA; |
| 3639 |
1 |
| switch (SvTYPE(sv)) { |
| 3640 |
1 |
| case SVt_PVHV: |
| 3641 |
1 |
| eflags = (unsigned char) SHT_THASH; |
| 3642 |
1 |
| mtype = 'P'; |
| 3643 |
1 |
| break; |
| 3644 |
0 |
| case SVt_PVAV: |
| 3645 |
0 |
| eflags = (unsigned char) SHT_TARRAY; |
| 3646 |
0 |
| mtype = 'P'; |
| 3647 |
0 |
| break; |
| 3648 |
0 |
| default: |
| 3649 |
0 |
| eflags = (unsigned char) SHT_TSCALAR; |
| 3650 |
0 |
| mtype = 'q'; |
| 3651 |
0 |
| break; |
| 3652 |
|
| } |
| 3653 |
1 |
| break; |
| 3654 |
1 |
| default: |
| 3655 |
|
| { |
| 3656 |
|
| /* pkg_can() always returns a ref to a CV on success */ |
| 3657 |
1 |
| CV *cv = (CV*)SvRV(hook); |
| 3658 |
1 |
| const GV * const gv = CvGV(cv); |
| 3659 |
1 |
| const char *gvname = GvNAME(gv); |
| 3660 |
1 |
| const HV * const stash = GvSTASH(gv); |
| 3661 |
1 |
▶ | const char *hvname = stash ? HvNAME(stash) : NULL; |
Branch: 7 branches
| Branch | True | False | Total |
| const char *hvname = stash ? HvNAME(stash) : NULL; |
1 |
0 |
1 |
| const char *hvname = stash ? HvNAME(stash) : NULL; |
1 |
0 |
1 |
| const char *hvname = stash ? HvNAME(stash) : NULL; |
1 |
0 |
1 |
| const char *hvname = stash ? HvNAME(stash) : NULL; |
0 |
1 |
1 |
| const char *hvname = stash ? HvNAME(stash) : NULL; |
0 |
0 |
0 |
| const char *hvname = stash ? HvNAME(stash) : NULL; |
1 |
0 |
1 |
| const char *hvname = stash ? HvNAME(stash) : NULL; |
0 |
1 |
1 |
|
| 3662 |
|
| |
| 3663 |
1 |
| CROAK(("Unexpected object type (%s) of class '%s' in store_hook() calling %s::%s", |
| 3664 |
|
| sv_reftype(sv, FALSE), classname, hvname, gvname)); |
| 3665 |
|
| } |
| 3666 |
|
| } |
| 3667 |
119 |
| flags = SHF_NEED_RECURSE | obj_type; |
| 3668 |
|
| |
| 3669 |
|
| /* |
| 3670 |
|
| * To call the hook, we need to fake a call like: |
| 3671 |
|
| * |
| 3672 |
|
| * $object->STORABLE_freeze($cloning); |
| 3673 |
|
| * |
| 3674 |
|
| * but we don't have the $object here. For instance, if $object is |
| 3675 |
|
| * a blessed array, what we have in 'sv' is the array, and we can't |
| 3676 |
|
| * call a method on those. |
| 3677 |
|
| * |
| 3678 |
|
| * Therefore, we need to create a temporary reference to the object and |
| 3679 |
|
| * make the call on that reference. |
| 3680 |
|
| */ |
| 3681 |
|
| |
| 3682 |
|
| TRACEME(("about to call STORABLE_freeze on class %s", classname)); |
| 3683 |
|
| |
| 3684 |
119 |
| ref = newRV_inc(sv); /* Temporary reference */ |
| 3685 |
119 |
| av = array_call(aTHX_ ref, hook, clone); /* @a = $object->STORABLE_freeze($c) */ |
| 3686 |
115 |
| SvREFCNT_dec(ref); /* Reclaim temporary reference */ |
| 3687 |
|
| |
| 3688 |
115 |
| count = AvFILLp(av) + 1; |
| 3689 |
|
| TRACEME(("store_hook, array holds %" IVdf " items", count)); |
| 3690 |
|
| |
| 3691 |
|
| /* |
| 3692 |
|
| * If they return an empty list, it means they wish to ignore the |
| 3693 |
|
| * hook for this class (and not just this instance -- that's for them |
| 3694 |
|
| * to handle if they so wish). |
| 3695 |
|
| * |
| 3696 |
|
| * Simply disable the cached entry for the hook (it won't be recomputed |
| 3697 |
|
| * since it's present in the cache) and recurse to store_blessed(). |
| 3698 |
|
| */ |
| 3699 |
|
| |
| 3700 |
115 |
▶ | if (!count) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!count) { |
5 |
110 |
115 |
|
| 3701 |
|
| /* free empty list returned by the hook */ |
| 3702 |
5 |
| av_undef(av); |
| 3703 |
5 |
| sv_free((SV *) av); |
| 3704 |
|
| |
| 3705 |
|
| /* |
| 3706 |
|
| * They must not change their mind in the middle of a serialization. |
| 3707 |
|
| */ |
| 3708 |
|
| |
| 3709 |
5 |
▶ | if (hv_fetch(cxt->hclass, classname, len, FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_fetch(cxt->hclass, classname, len, FALSE)) |
0 |
5 |
5 |
|
| 3710 |
0 |
▶ | CROAK(("Too late to ignore hooks for %s class \"%s\"", |
Branch: 1 branch
| Branch | True | False | Total |
| CROAK(("Too late to ignore hooks for %s class \"%s\"", |
0 |
0 |
0 |
|
| 3711 |
|
| (cxt->optype & ST_CLONE) ? "cloning" : "storing", |
| 3712 |
|
| classname)); |
| 3713 |
|
| |
| 3714 |
5 |
| pkg_hide(aTHX_ cxt->hook, pkg, "STORABLE_freeze"); |
| 3715 |
|
| |
| 3716 |
|
| ASSERT(!pkg_can(aTHX_ cxt->hook, pkg, "STORABLE_freeze"), |
| 3717 |
|
| ("hook invisible")); |
| 3718 |
|
| TRACEME(("ignoring STORABLE_freeze in class \"%s\"", classname)); |
| 3719 |
|
| |
| 3720 |
5 |
| return store_blessed(aTHX_ cxt, sv, type, pkg); |
| 3721 |
|
| } |
| 3722 |
|
| |
| 3723 |
|
| /* |
| 3724 |
|
| * Get frozen string. |
| 3725 |
|
| */ |
| 3726 |
|
| |
| 3727 |
110 |
| ary = AvARRAY(av); |
| 3728 |
110 |
| pv = SvPV(ary[0], len2); |
| 3729 |
|
| /* We can't use pkg_can here because it only caches one method per |
| 3730 |
|
| * package */ |
| 3731 |
|
| { |
| 3732 |
110 |
| GV* gv = gv_fetchmethod_autoload(pkg, "STORABLE_attach", FALSE); |
| 3733 |
110 |
▶ | if (gv && isGV(gv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (gv && isGV(gv)) { |
12 |
98 |
110 |
| if (gv && isGV(gv)) { |
12 |
0 |
12 |
|
| 3734 |
12 |
▶ | if (count > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 1) |
1 |
11 |
12 |
|
| 3735 |
1 |
| CROAK(("Freeze cannot return references if %s class is using STORABLE_attach", classname)); |
| 3736 |
11 |
| goto check_done; |
| 3737 |
|
| } |
| 3738 |
|
| } |
| 3739 |
|
| |
| 3740 |
|
| #ifdef HAS_U64 |
| 3741 |
98 |
▶ | if (count > I32_MAX) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > I32_MAX) { |
0 |
98 |
98 |
|
| 3742 |
0 |
| CROAK(("Too many references returned by STORABLE_freeze()")); |
| 3743 |
|
| } |
| 3744 |
|
| #endif |
| 3745 |
|
| |
| 3746 |
|
| /* |
| 3747 |
|
| * If they returned more than one item, we need to serialize some |
| 3748 |
|
| * extra references if not already done. |
| 3749 |
|
| * |
| 3750 |
|
| * Loop over the array, starting at position #1, and for each item, |
| 3751 |
|
| * ensure it is a reference, serialize it if not already done, and |
| 3752 |
|
| * replace the entry with the tag ID of the corresponding serialized |
| 3753 |
|
| * object. |
| 3754 |
|
| * |
| 3755 |
|
| * We CHEAT by not calling av_fetch() and read directly within the |
| 3756 |
|
| * array, for speed. |
| 3757 |
|
| */ |
| 3758 |
|
| |
| 3759 |
200 |
▶ | for (i = 1; i < count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < count; i++) { |
102 |
98 |
200 |
|
| 3760 |
|
| #ifdef USE_PTR_TABLE |
| 3761 |
|
| char *fake_tag; |
| 3762 |
|
| #else |
| 3763 |
|
| SV **svh; |
| 3764 |
|
| #endif |
| 3765 |
102 |
| SV *rsv = ary[i]; |
| 3766 |
|
| SV *xsv; |
| 3767 |
|
| SV *tag; |
| 3768 |
102 |
| AV *av_hook = cxt->hook_seen; |
| 3769 |
|
| |
| 3770 |
102 |
▶ | if (!SvROK(rsv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(rsv)) |
0 |
102 |
102 |
|
| 3771 |
0 |
| CROAK(("Item #%d returned by STORABLE_freeze " |
| 3772 |
|
| "for %s is not a reference", (int)i, classname)); |
| 3773 |
102 |
| xsv = SvRV(rsv); /* Follow ref to know what to look for */ |
| 3774 |
|
| |
| 3775 |
|
| /* |
| 3776 |
|
| * Look in hseen and see if we have a tag already. |
| 3777 |
|
| * Serialize entry if not done already, and get its tag. |
| 3778 |
|
| */ |
| 3779 |
|
| |
| 3780 |
|
| #ifdef USE_PTR_TABLE |
| 3781 |
|
| /* Fakery needed because ptr_table_fetch returns zero for a |
| 3782 |
|
| failure, whereas the existing code assumes that it can |
| 3783 |
|
| safely store a tag zero. So for ptr_tables we store tag+1 |
| 3784 |
|
| */ |
| 3785 |
102 |
▶ | if ((fake_tag = (char *)ptr_table_fetch(cxt->pseen, xsv))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((fake_tag = (char *)ptr_table_fetch(cxt->pseen, xsv))) |
79 |
23 |
102 |
|
| 3786 |
79 |
| goto sv_seen; /* Avoid moving code too far to the right */ |
| 3787 |
|
| #else |
| 3788 |
|
| if ((svh = hv_fetch(cxt->hseen, (char *) &xsv, sizeof(xsv), FALSE))) |
| 3789 |
|
| goto sv_seen; /* Avoid moving code too far to the right */ |
| 3790 |
|
| #endif |
| 3791 |
|
| |
| 3792 |
|
| TRACEME(("listed object %d at 0x%" UVxf " is unknown", i-1, |
| 3793 |
|
| PTR2UV(xsv))); |
| 3794 |
|
| |
| 3795 |
|
| /* |
| 3796 |
|
| * We need to recurse to store that object and get it to be known |
| 3797 |
|
| * so that we can resolve the list of object-IDs at retrieve time. |
| 3798 |
|
| * |
| 3799 |
|
| * The first time we do this, we need to emit the proper header |
| 3800 |
|
| * indicating that we recursed, and what the type of object is (the |
| 3801 |
|
| * object we're storing via a user-hook). Indeed, during retrieval, |
| 3802 |
|
| * we'll have to create the object before recursing to retrieve the |
| 3803 |
|
| * others, in case those would point back at that object. |
| 3804 |
|
| */ |
| 3805 |
|
| |
| 3806 |
|
| /* [SX_HOOK] <flags> [<extra>] <object>*/ |
| 3807 |
23 |
▶ | if (!recursed++) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!recursed++) { |
21 |
2 |
23 |
|
| 3808 |
|
| #ifdef HAS_U64 |
| 3809 |
21 |
▶ | if (len2 > INT32_MAX) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len2 > INT32_MAX) |
0 |
21 |
21 |
|
| 3810 |
0 |
▶ | PUTMARK(SX_LOBJECT); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
|
| 3811 |
|
| #endif |
| 3812 |
21 |
▶ | PUTMARK(SX_HOOK); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_HOOK); |
19 |
2 |
21 |
| PUTMARK(SX_HOOK); |
19 |
0 |
19 |
| PUTMARK(SX_HOOK); |
0 |
2 |
2 |
|
| 3813 |
21 |
▶ | PUTMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flags); |
19 |
2 |
21 |
| PUTMARK(flags); |
19 |
0 |
19 |
| PUTMARK(flags); |
0 |
2 |
2 |
|
| 3814 |
21 |
▶ | if (obj_type == SHT_EXTRA) |
Branch: 1 branch
| Branch | True | False | Total |
| if (obj_type == SHT_EXTRA) |
0 |
21 |
21 |
|
| 3815 |
0 |
▶ | PUTMARK(eflags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(eflags); |
0 |
0 |
0 |
| PUTMARK(eflags); |
0 |
0 |
0 |
| PUTMARK(eflags); |
0 |
0 |
0 |
|
| 3816 |
|
| } else |
| 3817 |
2 |
▶ | PUTMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flags); |
2 |
0 |
2 |
| PUTMARK(flags); |
2 |
0 |
2 |
| PUTMARK(flags); |
0 |
0 |
0 |
|
| 3818 |
|
| |
| 3819 |
23 |
▶ | if ((ret = store(aTHX_ cxt, xsv))) /* Given by hook for us to store */ |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, xsv))) /* Given by hook for us to store */ |
0 |
23 |
23 |
|
| 3820 |
0 |
| return ret; |
| 3821 |
|
| |
| 3822 |
|
| #ifdef USE_PTR_TABLE |
| 3823 |
23 |
| fake_tag = (char *)ptr_table_fetch(cxt->pseen, xsv); |
| 3824 |
23 |
▶ | if (!fake_tag) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!fake_tag) |
0 |
23 |
23 |
|
| 3825 |
0 |
| CROAK(("Could not serialize item #%d from hook in %s", |
| 3826 |
|
| (int)i, classname)); |
| 3827 |
|
| #else |
| 3828 |
|
| svh = hv_fetch(cxt->hseen, (char *) &xsv, sizeof(xsv), FALSE); |
| 3829 |
|
| if (!svh) |
| 3830 |
|
| CROAK(("Could not serialize item #%d from hook in %s", |
| 3831 |
|
| (int)i, classname)); |
| 3832 |
|
| #endif |
| 3833 |
|
| /* |
| 3834 |
|
| * It was the first time we serialized 'xsv'. |
| 3835 |
|
| * |
| 3836 |
|
| * Keep this SV alive until the end of the serialization: if we |
| 3837 |
|
| * disposed of it right now by decrementing its refcount, and it was |
| 3838 |
|
| * a temporary value, some next temporary value allocated during |
| 3839 |
|
| * another STORABLE_freeze might take its place, and we'd wrongly |
| 3840 |
|
| * assume that new SV was already serialized, based on its presence |
| 3841 |
|
| * in cxt->hseen. |
| 3842 |
|
| * |
| 3843 |
|
| * Therefore, push it away in cxt->hook_seen. |
| 3844 |
|
| */ |
| 3845 |
|
| |
| 3846 |
23 |
| av_store(av_hook, AvFILLp(av_hook)+1, SvREFCNT_inc(xsv)); |
| 3847 |
|
| |
| 3848 |
102 |
| sv_seen: |
| 3849 |
|
| /* |
| 3850 |
|
| * Dispose of the REF they returned. If we saved the 'xsv' away |
| 3851 |
|
| * in the array of returned SVs, that will not cause the underlying |
| 3852 |
|
| * referenced SV to be reclaimed. |
| 3853 |
|
| */ |
| 3854 |
|
| |
| 3855 |
|
| ASSERT(SvREFCNT(xsv) > 1, ("SV will survive disposal of its REF")); |
| 3856 |
102 |
| SvREFCNT_dec(rsv); /* Dispose of reference */ |
| 3857 |
|
| |
| 3858 |
|
| /* |
| 3859 |
|
| * Replace entry with its tag (not a real SV, so no refcnt increment) |
| 3860 |
|
| */ |
| 3861 |
|
| |
| 3862 |
|
| #ifdef USE_PTR_TABLE |
| 3863 |
102 |
| tag = (SV *)--fake_tag; |
| 3864 |
|
| #else |
| 3865 |
|
| tag = *svh; |
| 3866 |
|
| #endif |
| 3867 |
102 |
| ary[i] = tag; |
| 3868 |
|
| TRACEME(("listed object %d at 0x%" UVxf " is tag #%" UVuf, |
| 3869 |
|
| i-1, PTR2UV(xsv), PTR2UV(tag))); |
| 3870 |
|
| #ifdef HAS_U64 |
| 3871 |
102 |
▶ | if ((U32)PTR2TAG(tag) != PTR2TAG(tag)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((U32)PTR2TAG(tag) != PTR2TAG(tag)) |
0 |
102 |
102 |
|
| 3872 |
0 |
| need_large_oids = 1; |
| 3873 |
|
| #endif |
| 3874 |
|
| } |
| 3875 |
|
| |
| 3876 |
|
| /* |
| 3877 |
|
| * Allocate a class ID if not already done. |
| 3878 |
|
| * |
| 3879 |
|
| * This needs to be done after the recursion above, since at retrieval |
| 3880 |
|
| * time, we'll see the inner objects first. Many thanks to |
| 3881 |
|
| * Salvador Ortiz Garcia <sog@msg.com.mx> who spot that bug and |
| 3882 |
|
| * proposed the right fix. -- RAM, 15/09/2000 |
| 3883 |
|
| */ |
| 3884 |
|
| |
| 3885 |
98 |
| check_done: |
| 3886 |
109 |
▶ | if (!known_class(aTHX_ cxt, classname, len, &classnum)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!known_class(aTHX_ cxt, classname, len, &classnum)) { |
89 |
20 |
109 |
|
| 3887 |
|
| TRACEME(("first time we see class %s, ID = %d", classname, (int)classnum)); |
| 3888 |
89 |
| classnum = -1; /* Mark: we must store classname */ |
| 3889 |
|
| } else { |
| 3890 |
|
| TRACEME(("already seen class %s, ID = %d", classname, (int)classnum)); |
| 3891 |
|
| } |
| 3892 |
|
| |
| 3893 |
|
| /* |
| 3894 |
|
| * Compute leading flags. |
| 3895 |
|
| */ |
| 3896 |
|
| |
| 3897 |
109 |
| flags = obj_type; |
| 3898 |
109 |
▶ | if (((classnum == -1) ? len : classnum) > LG_SCALAR) |
Branch: 2 branches
| Branch | True | False | Total |
| if (((classnum == -1) ? len : classnum) > LG_SCALAR) |
89 |
20 |
109 |
| if (((classnum == -1) ? len : classnum) > LG_SCALAR) |
0 |
109 |
109 |
|
| 3899 |
0 |
| flags |= SHF_LARGE_CLASSLEN; |
| 3900 |
109 |
▶ | if (classnum != -1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (classnum != -1) |
20 |
89 |
109 |
|
| 3901 |
20 |
| flags |= SHF_IDX_CLASSNAME; |
| 3902 |
109 |
▶ | if (len2 > LG_SCALAR) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len2 > LG_SCALAR) |
24 |
85 |
109 |
|
| 3903 |
24 |
| flags |= SHF_LARGE_STRLEN; |
| 3904 |
109 |
▶ | if (count > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 1) |
84 |
25 |
109 |
|
| 3905 |
84 |
| flags |= SHF_HAS_LIST; |
| 3906 |
109 |
▶ | if (count > (LG_SCALAR + 1)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > (LG_SCALAR + 1)) |
0 |
109 |
109 |
|
| 3907 |
0 |
| flags |= SHF_LARGE_LISTLEN; |
| 3908 |
|
| #ifdef HAS_U64 |
| 3909 |
109 |
▶ | if (need_large_oids) |
Branch: 1 branch
| Branch | True | False | Total |
| if (need_large_oids) |
0 |
109 |
109 |
|
| 3910 |
0 |
| flags |= SHF_LARGE_LISTLEN; |
| 3911 |
|
| #endif |
| 3912 |
|
| |
| 3913 |
|
| /* |
| 3914 |
|
| * We're ready to emit either serialized form: |
| 3915 |
|
| * |
| 3916 |
|
| * SX_HOOK <flags> <len> <classname> <len2> <str> [<len3> <object-IDs>] |
| 3917 |
|
| * SX_HOOK <flags> <index> <len2> <str> [<len3> <object-IDs>] |
| 3918 |
|
| * |
| 3919 |
|
| * If we recursed, the SX_HOOK has already been emitted. |
| 3920 |
|
| */ |
| 3921 |
|
| |
| 3922 |
|
| TRACEME(("SX_HOOK (recursed=%d) flags=0x%x " |
| 3923 |
|
| "class=%" IVdf " len=%" IVdf " len2=%" IVdf " len3=%" IVdf, |
| 3924 |
|
| recursed, flags, (IV)classnum, (IV)len, (IV)len2, count-1)); |
| 3925 |
|
| |
| 3926 |
|
| /* SX_HOOK <flags> [<extra>] */ |
| 3927 |
109 |
▶ | if (!recursed) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!recursed) { |
88 |
21 |
109 |
|
| 3928 |
|
| #ifdef HAS_U64 |
| 3929 |
88 |
▶ | if (len2 > INT32_MAX) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len2 > INT32_MAX) |
0 |
88 |
88 |
|
| 3930 |
0 |
▶ | PUTMARK(SX_LOBJECT); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
|
| 3931 |
|
| #endif |
| 3932 |
88 |
▶ | PUTMARK(SX_HOOK); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_HOOK); |
87 |
1 |
88 |
| PUTMARK(SX_HOOK); |
87 |
0 |
87 |
| PUTMARK(SX_HOOK); |
0 |
1 |
1 |
|
| 3933 |
88 |
▶ | PUTMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flags); |
87 |
1 |
88 |
| PUTMARK(flags); |
87 |
0 |
87 |
| PUTMARK(flags); |
0 |
1 |
1 |
|
| 3934 |
88 |
▶ | if (obj_type == SHT_EXTRA) |
Branch: 1 branch
| Branch | True | False | Total |
| if (obj_type == SHT_EXTRA) |
1 |
87 |
88 |
|
| 3935 |
1 |
▶ | PUTMARK(eflags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(eflags); |
1 |
0 |
1 |
| PUTMARK(eflags); |
1 |
0 |
1 |
| PUTMARK(eflags); |
0 |
0 |
0 |
|
| 3936 |
|
| } else |
| 3937 |
21 |
▶ | PUTMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flags); |
19 |
2 |
21 |
| PUTMARK(flags); |
19 |
0 |
19 |
| PUTMARK(flags); |
0 |
2 |
2 |
|
| 3938 |
|
| |
| 3939 |
|
| /* <len> <classname> or <index> */ |
| 3940 |
109 |
▶ | if (flags & SHF_IDX_CLASSNAME) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_IDX_CLASSNAME) { |
20 |
89 |
109 |
|
| 3941 |
20 |
▶ | if (flags & SHF_LARGE_CLASSLEN) |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_LARGE_CLASSLEN) |
0 |
20 |
20 |
|
| 3942 |
0 |
▶ | WLEN(classnum); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
|
| 3943 |
|
| else { |
| 3944 |
20 |
| unsigned char cnum = (unsigned char) classnum; |
| 3945 |
20 |
▶ | PUTMARK(cnum); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(cnum); |
20 |
0 |
20 |
| PUTMARK(cnum); |
20 |
0 |
20 |
| PUTMARK(cnum); |
0 |
0 |
0 |
|
| 3946 |
|
| } |
| 3947 |
|
| } else { |
| 3948 |
89 |
▶ | if (flags & SHF_LARGE_CLASSLEN) |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_LARGE_CLASSLEN) |
0 |
89 |
89 |
|
| 3949 |
0 |
▶ | WLEN(len); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(len); |
0 |
0 |
0 |
| WLEN(len); |
0 |
0 |
0 |
| WLEN(len); |
0 |
0 |
0 |
| WLEN(len); |
0 |
0 |
0 |
| WLEN(len); |
0 |
0 |
0 |
| WLEN(len); |
0 |
0 |
0 |
| WLEN(len); |
0 |
0 |
0 |
| WLEN(len); |
0 |
0 |
0 |
| WLEN(len); |
0 |
0 |
0 |
|
| 3950 |
|
| else { |
| 3951 |
89 |
| unsigned char clen = (unsigned char) len; |
| 3952 |
89 |
▶ | PUTMARK(clen); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(clen); |
86 |
3 |
89 |
| PUTMARK(clen); |
86 |
0 |
86 |
| PUTMARK(clen); |
0 |
3 |
3 |
|
| 3953 |
|
| } |
| 3954 |
89 |
▶ | WRITE(classname, len); /* Final \0 is omitted */ |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(classname, len); /* Final \0 is omitted */ |
86 |
3 |
89 |
| WRITE(classname, len); /* Final \0 is omitted */ |
0 |
86 |
86 |
| WRITE(classname, len); /* Final \0 is omitted */ |
0 |
3 |
3 |
|
| 3955 |
|
| } |
| 3956 |
|
| |
| 3957 |
|
| /* <len2> <frozen-str> */ |
| 3958 |
|
| #ifdef HAS_U64 |
| 3959 |
109 |
▶ | if (len2 > INT32_MAX) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len2 > INT32_MAX) { |
0 |
109 |
109 |
|
| 3960 |
0 |
▶ | W64LEN(len2); |
Branch: 7 branches
| Branch | True | False | Total |
| W64LEN(len2); |
0 |
0 |
0 |
| W64LEN(len2); |
0 |
0 |
0 |
| W64LEN(len2); |
0 |
0 |
0 |
| W64LEN(len2); |
0 |
0 |
0 |
| W64LEN(len2); |
0 |
0 |
0 |
| W64LEN(len2); |
0 |
0 |
0 |
| W64LEN(len2); |
0 |
0 |
0 |
|
| 3961 |
|
| } |
| 3962 |
|
| else |
| 3963 |
|
| #endif |
| 3964 |
109 |
▶ | if (flags & SHF_LARGE_STRLEN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_LARGE_STRLEN) { |
24 |
85 |
109 |
|
| 3965 |
24 |
| U32 wlen2 = len2; /* STRLEN might be 8 bytes */ |
| 3966 |
24 |
▶ | WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
0 |
24 |
24 |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
0 |
0 |
0 |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
0 |
0 |
0 |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
0 |
0 |
0 |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
0 |
0 |
0 |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
24 |
0 |
24 |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
0 |
24 |
24 |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
0 |
24 |
24 |
| WLEN(wlen2); /* Must write an I32 for 64-bit machines */ |
0 |
0 |
0 |
|
| 3967 |
|
| } else { |
| 3968 |
85 |
| unsigned char clen = (unsigned char) len2; |
| 3969 |
85 |
▶ | PUTMARK(clen); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(clen); |
82 |
3 |
85 |
| PUTMARK(clen); |
82 |
0 |
82 |
| PUTMARK(clen); |
0 |
3 |
3 |
|
| 3970 |
|
| } |
| 3971 |
109 |
▶ | if (len2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len2) |
74 |
35 |
109 |
|
| 3972 |
74 |
▶ | WRITE(pv, (SSize_t)len2); /* Final \0 is omitted */ |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(pv, (SSize_t)len2); /* Final \0 is omitted */ |
72 |
2 |
74 |
| WRITE(pv, (SSize_t)len2); /* Final \0 is omitted */ |
0 |
72 |
72 |
| WRITE(pv, (SSize_t)len2); /* Final \0 is omitted */ |
0 |
2 |
2 |
|
| 3973 |
|
| |
| 3974 |
|
| /* [<len3> <object-IDs>] */ |
| 3975 |
109 |
▶ | if (flags & SHF_HAS_LIST) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_HAS_LIST) { |
84 |
25 |
109 |
|
| 3976 |
84 |
| int len3 = count - 1; |
| 3977 |
84 |
▶ | if (flags & SHF_LARGE_LISTLEN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_LARGE_LISTLEN) { |
0 |
84 |
84 |
|
| 3978 |
|
| #ifdef HAS_U64 |
| 3979 |
0 |
▶ | int tlen3 = need_large_oids ? -len3 : len3; |
Branch: 1 branch
| Branch | True | False | Total |
| int tlen3 = need_large_oids ? -len3 : len3; |
0 |
0 |
0 |
|
| 3980 |
0 |
▶ | WLEN(tlen3); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(tlen3); |
0 |
0 |
0 |
| WLEN(tlen3); |
0 |
0 |
0 |
| WLEN(tlen3); |
0 |
0 |
0 |
| WLEN(tlen3); |
0 |
0 |
0 |
| WLEN(tlen3); |
0 |
0 |
0 |
| WLEN(tlen3); |
0 |
0 |
0 |
| WLEN(tlen3); |
0 |
0 |
0 |
| WLEN(tlen3); |
0 |
0 |
0 |
| WLEN(tlen3); |
0 |
0 |
0 |
|
| 3981 |
|
| #else |
| 3982 |
|
| WLEN(len3); |
| 3983 |
|
| #endif |
| 3984 |
|
| } |
| 3985 |
|
| else { |
| 3986 |
84 |
| unsigned char clen = (unsigned char) len3; |
| 3987 |
84 |
▶ | PUTMARK(clen); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(clen); |
82 |
2 |
84 |
| PUTMARK(clen); |
82 |
0 |
82 |
| PUTMARK(clen); |
0 |
2 |
2 |
|
| 3988 |
|
| } |
| 3989 |
|
| |
| 3990 |
|
| /* |
| 3991 |
|
| * NOTA BENE, for 64-bit machines: the ary[i] below does not yield a |
| 3992 |
|
| * real pointer, rather a tag number, well under the 32-bit limit. |
| 3993 |
|
| * Which is wrong... if we have more than 2**32 SVs we can get ids over |
| 3994 |
|
| * the 32-bit limit. |
| 3995 |
|
| */ |
| 3996 |
|
| |
| 3997 |
186 |
▶ | for (i = 1; i < count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < count; i++) { |
102 |
84 |
186 |
|
| 3998 |
|
| #ifdef HAS_U64 |
| 3999 |
102 |
▶ | if (need_large_oids) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (need_large_oids) { |
0 |
102 |
102 |
|
| 4000 |
0 |
| ntag_t tag = PTR2TAG(ary[i]); |
| 4001 |
0 |
▶ | W64LEN(tag); |
Branch: 7 branches
| Branch | True | False | Total |
| W64LEN(tag); |
0 |
0 |
0 |
| W64LEN(tag); |
0 |
0 |
0 |
| W64LEN(tag); |
0 |
0 |
0 |
| W64LEN(tag); |
0 |
0 |
0 |
| W64LEN(tag); |
0 |
0 |
0 |
| W64LEN(tag); |
0 |
0 |
0 |
| W64LEN(tag); |
0 |
0 |
0 |
|
| 4002 |
|
| TRACEME(("object %d, tag #%" UVuf, i-1, (UV)tag)); |
| 4003 |
|
| } |
| 4004 |
|
| else |
| 4005 |
|
| #endif |
| 4006 |
|
| { |
| 4007 |
102 |
| I32 tagval = htonl(LOW_32BITS(ary[i])); |
| 4008 |
102 |
▶ | WRITE_I32(tagval); |
Branch: 4 branches
| Branch | True | False | Total |
| WRITE_I32(tagval); |
100 |
2 |
102 |
| WRITE_I32(tagval); |
0 |
100 |
100 |
| WRITE_I32(tagval); |
21 |
79 |
100 |
| WRITE_I32(tagval); |
0 |
2 |
2 |
|
| 4009 |
|
| TRACEME(("object %d, tag #%d", i-1, ntohl(tagval))); |
| 4010 |
|
| } |
| 4011 |
|
| } |
| 4012 |
|
| } |
| 4013 |
|
| |
| 4014 |
|
| /* |
| 4015 |
|
| * Free the array. We need extra care for indices after 0, since they |
| 4016 |
|
| * don't hold real SVs but integers cast. |
| 4017 |
|
| */ |
| 4018 |
|
| |
| 4019 |
109 |
▶ | if (count > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 1) |
84 |
25 |
109 |
|
| 4020 |
84 |
| AvFILLp(av) = 0; /* Cheat, nothing after 0 interests us */ |
| 4021 |
109 |
| av_undef(av); |
| 4022 |
109 |
| sv_free((SV *) av); |
| 4023 |
|
| |
| 4024 |
|
| /* |
| 4025 |
|
| * If object was tied, need to insert serialization of the magic object. |
| 4026 |
|
| */ |
| 4027 |
|
| |
| 4028 |
109 |
▶ | if (obj_type == SHT_EXTRA) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (obj_type == SHT_EXTRA) { |
1 |
108 |
109 |
|
| 4029 |
|
| MAGIC *mg; |
| 4030 |
|
| |
| 4031 |
1 |
▶ | if (!(mg = mg_find(sv, mtype))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(mg = mg_find(sv, mtype))) { |
0 |
1 |
1 |
|
| 4032 |
0 |
| int svt = SvTYPE(sv); |
| 4033 |
0 |
▶ | CROAK(("No magic '%c' found while storing ref to tied %s with hook", |
Branch: 2 branches
| Branch | True | False | Total |
| CROAK(("No magic '%c' found while storing ref to tied %s with hook", |
0 |
0 |
0 |
| CROAK(("No magic '%c' found while storing ref to tied %s with hook", |
0 |
0 |
0 |
|
| 4034 |
|
| mtype, (svt == SVt_PVHV) ? "hash" : |
| 4035 |
|
| (svt == SVt_PVAV) ? "array" : "scalar")); |
| 4036 |
|
| } |
| 4037 |
|
| |
| 4038 |
|
| TRACEME(("handling the magic object 0x%" UVxf " part of 0x%" UVxf, |
| 4039 |
|
| PTR2UV(mg->mg_obj), PTR2UV(sv))); |
| 4040 |
|
| |
| 4041 |
|
| /* |
| 4042 |
|
| * [<magic object>] |
| 4043 |
|
| */ |
| 4044 |
1 |
▶ | if ((ret = store(aTHX_ cxt, mg->mg_obj))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((ret = store(aTHX_ cxt, mg->mg_obj))) |
0 |
1 |
1 |
|
| 4045 |
0 |
| return ret; |
| 4046 |
|
| } |
| 4047 |
|
| |
| 4048 |
109 |
| return 0; |
| 4049 |
|
| } |
| 4050 |
|
| |
| 4051 |
|
| /* |
| 4052 |
|
| * store_blessed -- dispatched manually, not via sv_store[] |
| 4053 |
|
| * |
| 4054 |
|
| * Check whether there is a STORABLE_xxx hook defined in the class or in one |
| 4055 |
|
| * of its ancestors. If there is, then redispatch to store_hook(); |
| 4056 |
|
| * |
| 4057 |
|
| * Otherwise, the blessed SV is stored using the following layout: |
| 4058 |
|
| * |
| 4059 |
|
| * SX_BLESS <flag> <len> <classname> <object> |
| 4060 |
|
| * |
| 4061 |
|
| * where <flag> indicates whether <len> is stored on 0 or 4 bytes, depending |
| 4062 |
|
| * on the high-order bit in flag: if 1, then length follows on 4 bytes. |
| 4063 |
|
| * Otherwise, the low order bits give the length, thereby giving a compact |
| 4064 |
|
| * representation for class names less than 127 chars long. |
| 4065 |
|
| * |
| 4066 |
|
| * Each <classname> seen is remembered and indexed, so that the next time |
| 4067 |
|
| * an object in the blessed in the same <classname> is stored, the following |
| 4068 |
|
| * will be emitted: |
| 4069 |
|
| * |
| 4070 |
|
| * SX_IX_BLESS <flag> <index> <object> |
| 4071 |
|
| * |
| 4072 |
|
| * where <index> is the classname index, stored on 0 or 4 bytes depending |
| 4073 |
|
| * on the high-order bit in flag (same encoding as above for <len>). |
| 4074 |
|
| */ |
| 4075 |
279 |
| static int store_blessed( |
| 4076 |
|
| pTHX_ |
| 4077 |
|
| stcxt_t *cxt, |
| 4078 |
|
| SV *sv, |
| 4079 |
|
| int type, |
| 4080 |
|
| HV *pkg) |
| 4081 |
|
| { |
| 4082 |
|
| SV *hook; |
| 4083 |
|
| char *classname; |
| 4084 |
|
| I32 len; |
| 4085 |
|
| I32 classnum; |
| 4086 |
|
| |
| 4087 |
|
| TRACEME(("store_blessed, type %d, class \"%s\"", type, HvNAME_get(pkg))); |
| 4088 |
|
| |
| 4089 |
|
| /* |
| 4090 |
|
| * Look for a hook for this blessed SV and redirect to store_hook() |
| 4091 |
|
| * if needed. |
| 4092 |
|
| */ |
| 4093 |
|
| |
| 4094 |
279 |
| hook = pkg_can(aTHX_ cxt->hook, pkg, "STORABLE_freeze"); |
| 4095 |
279 |
▶ | if (hook) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hook) |
120 |
159 |
279 |
|
| 4096 |
120 |
| return store_hook(aTHX_ cxt, sv, type, pkg, hook); |
| 4097 |
|
| |
| 4098 |
|
| /* |
| 4099 |
|
| * This is a blessed SV without any serialization hook. |
| 4100 |
|
| */ |
| 4101 |
|
| |
| 4102 |
159 |
▶ | classname = HvNAME_get(pkg); |
Branch: 6 branches
| Branch | True | False | Total |
| classname = HvNAME_get(pkg); |
159 |
0 |
159 |
| classname = HvNAME_get(pkg); |
159 |
0 |
159 |
| classname = HvNAME_get(pkg); |
0 |
159 |
159 |
| classname = HvNAME_get(pkg); |
0 |
0 |
0 |
| classname = HvNAME_get(pkg); |
159 |
0 |
159 |
| classname = HvNAME_get(pkg); |
0 |
159 |
159 |
|
| 4103 |
159 |
| len = strlen(classname); |
| 4104 |
|
| |
| 4105 |
|
| TRACEME(("blessed 0x%" UVxf " in %s, no hook: tagged #%d", |
| 4106 |
|
| PTR2UV(sv), classname, (int)cxt->tagnum)); |
| 4107 |
|
| |
| 4108 |
|
| /* |
| 4109 |
|
| * Determine whether it is the first time we see that class name (in which |
| 4110 |
|
| * case it will be stored in the SX_BLESS form), or whether we already |
| 4111 |
|
| * saw that class name before (in which case the SX_IX_BLESS form will be |
| 4112 |
|
| * used). |
| 4113 |
|
| */ |
| 4114 |
|
| |
| 4115 |
159 |
▶ | if (known_class(aTHX_ cxt, classname, len, &classnum)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (known_class(aTHX_ cxt, classname, len, &classnum)) { |
27 |
132 |
159 |
|
| 4116 |
|
| TRACEME(("already seen class %s, ID = %d", classname, (int)classnum)); |
| 4117 |
27 |
▶ | PUTMARK(SX_IX_BLESS); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_IX_BLESS); |
27 |
0 |
27 |
| PUTMARK(SX_IX_BLESS); |
27 |
0 |
27 |
| PUTMARK(SX_IX_BLESS); |
0 |
0 |
0 |
|
| 4118 |
27 |
▶ | if (classnum <= LG_BLESS) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (classnum <= LG_BLESS) { |
27 |
0 |
27 |
|
| 4119 |
27 |
| unsigned char cnum = (unsigned char) classnum; |
| 4120 |
27 |
▶ | PUTMARK(cnum); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(cnum); |
27 |
0 |
27 |
| PUTMARK(cnum); |
27 |
0 |
27 |
| PUTMARK(cnum); |
0 |
0 |
0 |
|
| 4121 |
|
| } else { |
| 4122 |
0 |
| unsigned char flag = (unsigned char) 0x80; |
| 4123 |
0 |
▶ | PUTMARK(flag); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flag); |
0 |
0 |
0 |
| PUTMARK(flag); |
0 |
0 |
0 |
| PUTMARK(flag); |
0 |
0 |
0 |
|
| 4124 |
0 |
▶ | WLEN(classnum); |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
| WLEN(classnum); |
0 |
0 |
0 |
|
| 4125 |
|
| } |
| 4126 |
|
| } else { |
| 4127 |
|
| TRACEME(("first time we see class %s, ID = %d", classname, |
| 4128 |
|
| (int)classnum)); |
| 4129 |
132 |
▶ | PUTMARK(SX_BLESS); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_BLESS); |
119 |
13 |
132 |
| PUTMARK(SX_BLESS); |
119 |
0 |
119 |
| PUTMARK(SX_BLESS); |
0 |
13 |
13 |
|
| 4130 |
132 |
▶ | if (len <= LG_BLESS) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len <= LG_BLESS) { |
131 |
1 |
132 |
|
| 4131 |
131 |
| unsigned char clen = (unsigned char) len; |
| 4132 |
131 |
▶ | PUTMARK(clen); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(clen); |
118 |
13 |
131 |
| PUTMARK(clen); |
118 |
0 |
118 |
| PUTMARK(clen); |
0 |
13 |
13 |
|
| 4133 |
|
| } else { |
| 4134 |
1 |
| unsigned char flag = (unsigned char) 0x80; |
| 4135 |
1 |
▶ | PUTMARK(flag); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(flag); |
1 |
0 |
1 |
| PUTMARK(flag); |
1 |
0 |
1 |
| PUTMARK(flag); |
0 |
0 |
0 |
|
| 4136 |
1 |
▶ | WLEN(len); /* Don't BER-encode, this should be rare */ |
Branch: 9 branches
| Branch | True | False | Total |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
0 |
1 |
1 |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
0 |
0 |
0 |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
0 |
0 |
0 |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
0 |
0 |
0 |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
0 |
0 |
0 |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
1 |
0 |
1 |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
0 |
1 |
1 |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
0 |
1 |
1 |
| WLEN(len); /* Don't BER-encode, this should be rare */ |
0 |
0 |
0 |
|
| 4137 |
|
| } |
| 4138 |
132 |
▶ | WRITE(classname, len); /* Final \0 is omitted */ |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE(classname, len); /* Final \0 is omitted */ |
119 |
13 |
132 |
| WRITE(classname, len); /* Final \0 is omitted */ |
0 |
119 |
119 |
| WRITE(classname, len); /* Final \0 is omitted */ |
0 |
13 |
13 |
|
| 4139 |
|
| } |
| 4140 |
|
| |
| 4141 |
|
| /* |
| 4142 |
|
| * Now emit the <object> part. |
| 4143 |
|
| */ |
| 4144 |
|
| |
| 4145 |
159 |
| return SV_STORE(type)(aTHX_ cxt, sv); |
| 4146 |
|
| } |
| 4147 |
|
| |
| 4148 |
|
| /* |
| 4149 |
|
| * store_other |
| 4150 |
|
| * |
| 4151 |
|
| * We don't know how to store the item we reached, so return an error condition. |
| 4152 |
|
| * (it's probably a GLOB, some CODE reference, etc...) |
| 4153 |
|
| * |
| 4154 |
|
| * If they defined the 'forgive_me' variable at the Perl level to some |
| 4155 |
|
| * true value, then don't croak, just warn, and store a placeholder string |
| 4156 |
|
| * instead. |
| 4157 |
|
| */ |
| 4158 |
5 |
| static int store_other(pTHX_ stcxt_t *cxt, SV *sv) |
| 4159 |
|
| { |
| 4160 |
|
| STRLEN len; |
| 4161 |
|
| char buf[80]; |
| 4162 |
|
| |
| 4163 |
|
| TRACEME(("store_other")); |
| 4164 |
|
| |
| 4165 |
|
| /* |
| 4166 |
|
| * Fetch the value from perl only once per store() operation. |
| 4167 |
|
| */ |
| 4168 |
|
| |
| 4169 |
5 |
| if ( |
| 4170 |
5 |
▶ | cxt->forgive_me == 0 || |
Branch: 1 branch
| Branch | True | False | Total |
| cxt->forgive_me == 0 || |
5 |
0 |
5 |
|
| 4171 |
5 |
▶ | (cxt->forgive_me < 0 && |
Branch: 1 branch
| Branch | True | False | Total |
| (cxt->forgive_me < 0 && |
5 |
0 |
5 |
|
| 4172 |
5 |
| !(cxt->forgive_me = SvTRUE |
| 4173 |
5 |
▶ | (get_sv("Storable::forgive_me", GV_ADD)) ? 1 : 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| (get_sv("Storable::forgive_me", GV_ADD)) ? 1 : 0)) |
3 |
2 |
5 |
|
| 4174 |
|
| ) |
| 4175 |
3 |
| CROAK(("Can't store %s items", sv_reftype(sv, FALSE))); |
| 4176 |
|
| |
| 4177 |
2 |
| warn("Can't store item %s(0x%" UVxf ")", |
| 4178 |
|
| sv_reftype(sv, FALSE), PTR2UV(sv)); |
| 4179 |
|
| |
| 4180 |
|
| /* |
| 4181 |
|
| * Store placeholder string as a scalar instead... |
| 4182 |
|
| */ |
| 4183 |
|
| |
| 4184 |
2 |
| (void) sprintf(buf, "You lost %s(0x%" UVxf ")%c", sv_reftype(sv, FALSE), |
| 4185 |
|
| PTR2UV(sv), (char) 0); |
| 4186 |
|
| |
| 4187 |
2 |
| len = strlen(buf); |
| 4188 |
2 |
▶ | if (len < 80) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 80) |
2 |
0 |
2 |
|
| 4189 |
2 |
▶ | STORE_SCALAR(buf, len); |
Branch: 43 branches
| Branch | True | False | Total |
| STORE_SCALAR(buf, len); |
2 |
0 |
2 |
| STORE_SCALAR(buf, len); |
1 |
1 |
2 |
| STORE_SCALAR(buf, len); |
1 |
0 |
1 |
| STORE_SCALAR(buf, len); |
0 |
1 |
1 |
| STORE_SCALAR(buf, len); |
1 |
1 |
2 |
| STORE_SCALAR(buf, len); |
1 |
0 |
1 |
| STORE_SCALAR(buf, len); |
0 |
1 |
1 |
| STORE_SCALAR(buf, len); |
2 |
0 |
2 |
| STORE_SCALAR(buf, len); |
1 |
1 |
2 |
| STORE_SCALAR(buf, len); |
0 |
1 |
1 |
| STORE_SCALAR(buf, len); |
0 |
1 |
1 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
| STORE_SCALAR(buf, len); |
0 |
0 |
0 |
|
| 4190 |
|
| TRACEME(("ok (dummy \"%s\", length = %" IVdf ")", buf, (IV) len)); |
| 4191 |
|
| |
| 4192 |
2 |
| return 0; |
| 4193 |
|
| } |
| 4194 |
|
| |
| 4195 |
|
| /*** |
| 4196 |
|
| *** Store driving routines |
| 4197 |
|
| ***/ |
| 4198 |
|
| |
| 4199 |
|
| /* |
| 4200 |
|
| * sv_type |
| 4201 |
|
| * |
| 4202 |
|
| * WARNING: partially duplicates Perl's sv_reftype for speed. |
| 4203 |
|
| * |
| 4204 |
|
| * Returns the type of the SV, identified by an integer. That integer |
| 4205 |
|
| * may then be used to index the dynamic routine dispatch table. |
| 4206 |
|
| */ |
| 4207 |
141737 |
| static int sv_type(pTHX_ SV *sv) |
| 4208 |
|
| { |
| 4209 |
141737 |
| switch (SvTYPE(sv)) { |
| 4210 |
149 |
| case SVt_NULL: |
| 4211 |
|
| #if PERL_VERSION_LT(5,11,0) |
| 4212 |
|
| case SVt_IV: |
| 4213 |
|
| #endif |
| 4214 |
|
| case SVt_NV: |
| 4215 |
|
| /* |
| 4216 |
|
| * No need to check for ROK, that can't be set here since there |
| 4217 |
|
| * is no field capable of hodling the xrv_rv reference. |
| 4218 |
|
| */ |
| 4219 |
149 |
| return svis_SCALAR; |
| 4220 |
81621 |
| case SVt_PV: |
| 4221 |
|
| #if PERL_VERSION_LT(5,11,0) |
| 4222 |
|
| case SVt_RV: |
| 4223 |
|
| #else |
| 4224 |
|
| case SVt_IV: |
| 4225 |
|
| #endif |
| 4226 |
|
| case SVt_PVIV: |
| 4227 |
|
| case SVt_PVNV: |
| 4228 |
|
| /* |
| 4229 |
|
| * Starting from SVt_PV, it is possible to have the ROK flag |
| 4230 |
|
| * set, the pointer to the other SV being either stored in |
| 4231 |
|
| * the xrv_rv (in the case of a pure SVt_RV), or as the |
| 4232 |
|
| * xpv_pv field of an SVt_PV and its heirs. |
| 4233 |
|
| * |
| 4234 |
|
| * However, those SV cannot be magical or they would be an |
| 4235 |
|
| * SVt_PVMG at least. |
| 4236 |
|
| */ |
| 4237 |
81621 |
| return SvROK(sv) ? svis_REF : svis_SCALAR; |
| 4238 |
37 |
| case SVt_PVMG: |
| 4239 |
|
| #if PERL_VERSION_LT(5,11,0) |
| 4240 |
|
| if ((SvFLAGS(sv) & (SVs_OBJECT|SVf_OK|SVs_GMG|SVs_SMG|SVs_RMG)) |
| 4241 |
|
| == (SVs_OBJECT|BFD_Svs_SMG_OR_RMG) |
| 4242 |
|
| && mg_find(sv, PERL_MAGIC_qr)) { |
| 4243 |
|
| return svis_REGEXP; |
| 4244 |
|
| } |
| 4245 |
|
| #endif |
| 4246 |
|
| case SVt_PVLV: /* Workaround for perl5.004_04 "LVALUE" bug */ |
| 4247 |
37 |
▶ | if ((SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) == |
Branch: 1 branch
| Branch | True | False | Total |
| if ((SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) == |
8 |
29 |
37 |
|
| 4248 |
8 |
▶ | (SVs_GMG|SVs_SMG|SVs_RMG) && |
Branch: 1 branch
| Branch | True | False | Total |
| (SVs_GMG|SVs_SMG|SVs_RMG) && |
2 |
6 |
8 |
|
| 4249 |
8 |
| (mg_find(sv, 'p'))) |
| 4250 |
2 |
| return svis_TIED_ITEM; |
| 4251 |
|
| /* FALL THROUGH */ |
| 4252 |
|
| #if PERL_VERSION_LT(5,9,0) |
| 4253 |
|
| case SVt_PVBM: |
| 4254 |
|
| #endif |
| 4255 |
35 |
▶ | if ((SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) == |
Branch: 1 branch
| Branch | True | False | Total |
| if ((SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) == |
6 |
29 |
35 |
|
| 4256 |
6 |
▶ | (SVs_GMG|SVs_SMG|SVs_RMG) && |
Branch: 1 branch
| Branch | True | False | Total |
| (SVs_GMG|SVs_SMG|SVs_RMG) && |
6 |
0 |
6 |
|
| 4257 |
6 |
| (mg_find(sv, 'q'))) |
| 4258 |
6 |
| return svis_TIED; |
| 4259 |
29 |
| return SvROK(sv) ? svis_REF : svis_SCALAR; |
| 4260 |
53540 |
| case SVt_PVAV: |
| 4261 |
53540 |
▶ | if (SvRMAGICAL(sv) && (mg_find(sv, 'P'))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvRMAGICAL(sv) && (mg_find(sv, 'P'))) |
12 |
53528 |
53540 |
| if (SvRMAGICAL(sv) && (mg_find(sv, 'P'))) |
6 |
6 |
12 |
|
| 4262 |
6 |
| return svis_TIED; |
| 4263 |
53534 |
| return svis_ARRAY; |
| 4264 |
6272 |
| case SVt_PVHV: |
| 4265 |
6272 |
▶ | if (SvRMAGICAL(sv) && (mg_find(sv, 'P'))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvRMAGICAL(sv) && (mg_find(sv, 'P'))) |
117 |
6155 |
6272 |
| if (SvRMAGICAL(sv) && (mg_find(sv, 'P'))) |
9 |
108 |
117 |
|
| 4266 |
9 |
| return svis_TIED; |
| 4267 |
6263 |
| return svis_HASH; |
| 4268 |
73 |
| case SVt_PVCV: |
| 4269 |
73 |
| return svis_CODE; |
| 4270 |
|
| #if PERL_VERSION_GE(5,9,0) |
| 4271 |
|
| /* case SVt_INVLIST: */ |
| 4272 |
|
| #endif |
| 4273 |
|
| #if PERL_VERSION_GE(5,11,0) |
| 4274 |
42 |
| case SVt_REGEXP: |
| 4275 |
42 |
| return svis_REGEXP; |
| 4276 |
|
| #endif |
| 4277 |
3 |
| default: |
| 4278 |
3 |
| break; |
| 4279 |
|
| } |
| 4280 |
|
| |
| 4281 |
3 |
| return svis_OTHER; |
| 4282 |
|
| } |
| 4283 |
|
| |
| 4284 |
|
| /* |
| 4285 |
|
| * store |
| 4286 |
|
| * |
| 4287 |
|
| * Recursively store objects pointed to by the sv to the specified file. |
| 4288 |
|
| * |
| 4289 |
|
| * Layout is <content> or SX_OBJECT <tagnum> if we reach an already stored |
| 4290 |
|
| * object (one for which storage has started -- it may not be over if we have |
| 4291 |
|
| * a self-referenced structure). This data set forms a stored <object>. |
| 4292 |
|
| */ |
| 4293 |
146879 |
| static int store(pTHX_ stcxt_t *cxt, SV *sv) |
| 4294 |
|
| { |
| 4295 |
|
| SV **svh; |
| 4296 |
|
| int ret; |
| 4297 |
|
| int type; |
| 4298 |
|
| #ifdef USE_PTR_TABLE |
| 4299 |
146879 |
| struct ptr_tbl *pseen = cxt->pseen; |
| 4300 |
|
| #else |
| 4301 |
|
| HV *hseen = cxt->hseen; |
| 4302 |
|
| #endif |
| 4303 |
|
| |
| 4304 |
|
| TRACEME(("store (0x%" UVxf ")", PTR2UV(sv))); |
| 4305 |
|
| |
| 4306 |
|
| /* |
| 4307 |
|
| * If object has already been stored, do not duplicate data. |
| 4308 |
|
| * Simply emit the SX_OBJECT marker followed by its tag data. |
| 4309 |
|
| * The tag is always written in network order. |
| 4310 |
|
| * |
| 4311 |
|
| * NOTA BENE, for 64-bit machines: the "*svh" below does not yield a |
| 4312 |
|
| * real pointer, rather a tag number (watch the insertion code below). |
| 4313 |
|
| * That means it probably safe to assume it is well under the 32-bit |
| 4314 |
|
| * limit, and makes the truncation safe. |
| 4315 |
|
| * -- RAM, 14/09/1999 |
| 4316 |
|
| */ |
| 4317 |
|
| |
| 4318 |
|
| #ifdef USE_PTR_TABLE |
| 4319 |
146879 |
| svh = (SV **)ptr_table_fetch(pseen, sv); |
| 4320 |
|
| #else |
| 4321 |
|
| svh = hv_fetch(hseen, (char *) &sv, sizeof(sv), FALSE); |
| 4322 |
|
| #endif |
| 4323 |
146879 |
▶ | if (svh) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svh) { |
5142 |
141737 |
146879 |
|
| 4324 |
|
| ntag_t tagval; |
| 4325 |
5142 |
▶ | if (sv == &PL_sv_undef) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv == &PL_sv_undef) { |
5014 |
128 |
5142 |
|
| 4326 |
|
| /* We have seen PL_sv_undef before, but fake it as |
| 4327 |
|
| if we have not. |
| 4328 |
|
| |
| 4329 |
|
| Not the simplest solution to making restricted |
| 4330 |
|
| hashes work on 5.8.0, but it does mean that |
| 4331 |
|
| repeated references to the one true undef will |
| 4332 |
|
| take up less space in the output file. |
| 4333 |
|
| */ |
| 4334 |
|
| /* Need to jump past the next hv_store, because on the |
| 4335 |
|
| second store of undef the old hash value will be |
| 4336 |
|
| SvREFCNT_dec()ed, and as Storable cheats horribly |
| 4337 |
|
| by storing non-SVs in the hash a SEGV will ensure. |
| 4338 |
|
| Need to increase the tag number so that the |
| 4339 |
|
| receiver has no idea what games we're up to. This |
| 4340 |
|
| special casing doesn't affect hooks that store |
| 4341 |
|
| undef, as the hook routine does its own lookup into |
| 4342 |
|
| hseen. Also this means that any references back |
| 4343 |
|
| to PL_sv_undef (from the pathological case of hooks |
| 4344 |
|
| storing references to it) will find the seen hash |
| 4345 |
|
| entry for the first time, as if we didn't have this |
| 4346 |
|
| hackery here. (That hseen lookup works even on 5.8.0 |
| 4347 |
|
| because it's a key of &PL_sv_undef and a value |
| 4348 |
|
| which is a tag number, not a value which is |
| 4349 |
|
| PL_sv_undef.) */ |
| 4350 |
5014 |
| cxt->tagnum++; |
| 4351 |
5014 |
| type = svis_SCALAR; |
| 4352 |
5014 |
| goto undef_special_case; |
| 4353 |
|
| } |
| 4354 |
|
| |
| 4355 |
|
| #ifdef USE_PTR_TABLE |
| 4356 |
128 |
| tagval = PTR2TAG(((char *)svh)-1); |
| 4357 |
|
| #else |
| 4358 |
|
| tagval = PTR2TAG(*svh); |
| 4359 |
|
| #endif |
| 4360 |
|
| #ifdef HAS_U64 |
| 4361 |
|
| |
| 4362 |
|
| /* older versions of Storable streat the tag as a signed value |
| 4363 |
|
| used in an array lookup, corrupting the data structure. |
| 4364 |
|
| Ensure only a newer Storable will be able to parse this tag id |
| 4365 |
|
| if it's over the 2G mark. |
| 4366 |
|
| */ |
| 4367 |
128 |
▶ | if (tagval > I32_MAX) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tagval > I32_MAX) { |
0 |
128 |
128 |
|
| 4368 |
|
| |
| 4369 |
|
| TRACEME(("object 0x%" UVxf " seen as #%" UVuf, PTR2UV(sv), |
| 4370 |
|
| (UV)tagval)); |
| 4371 |
|
| |
| 4372 |
128 |
▶ | PUTMARK(SX_LOBJECT); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_LOBJECT); |
0 |
0 |
0 |
|
| 4373 |
0 |
▶ | PUTMARK(SX_OBJECT); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_OBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_OBJECT); |
0 |
0 |
0 |
| PUTMARK(SX_OBJECT); |
0 |
0 |
0 |
|
| 4374 |
0 |
▶ | W64LEN(tagval); |
Branch: 7 branches
| Branch | True | False | Total |
| W64LEN(tagval); |
0 |
0 |
0 |
| W64LEN(tagval); |
0 |
0 |
0 |
| W64LEN(tagval); |
0 |
0 |
0 |
| W64LEN(tagval); |
0 |
0 |
0 |
| W64LEN(tagval); |
0 |
0 |
0 |
| W64LEN(tagval); |
0 |
0 |
0 |
| W64LEN(tagval); |
0 |
0 |
0 |
|
| 4375 |
0 |
| return 0; |
| 4376 |
|
| } |
| 4377 |
|
| else |
| 4378 |
|
| #endif |
| 4379 |
|
| { |
| 4380 |
|
| I32 ltagval; |
| 4381 |
|
| |
| 4382 |
128 |
| ltagval = htonl((I32)tagval); |
| 4383 |
|
| |
| 4384 |
|
| TRACEME(("object 0x%" UVxf " seen as #%d", PTR2UV(sv), |
| 4385 |
|
| ntohl(ltagval))); |
| 4386 |
|
| |
| 4387 |
128 |
▶ | PUTMARK(SX_OBJECT); |
Branch: 3 branches
| Branch | True | False | Total |
| PUTMARK(SX_OBJECT); |
106 |
22 |
128 |
| PUTMARK(SX_OBJECT); |
106 |
0 |
106 |
| PUTMARK(SX_OBJECT); |
0 |
22 |
22 |
|
| 4388 |
128 |
▶ | WRITE_I32(ltagval); |
Branch: 4 branches
| Branch | True | False | Total |
| WRITE_I32(ltagval); |
106 |
22 |
128 |
| WRITE_I32(ltagval); |
0 |
106 |
106 |
| WRITE_I32(ltagval); |
29 |
77 |
106 |
| WRITE_I32(ltagval); |
0 |
22 |
22 |
|
| 4389 |
128 |
| return 0; |
| 4390 |
|
| } |
| 4391 |
|
| } |
| 4392 |
|
| |
| 4393 |
|
| /* |
| 4394 |
|
| * Allocate a new tag and associate it with the address of the sv being |
| 4395 |
|
| * stored, before recursing... |
| 4396 |
|
| * |
| 4397 |
|
| * In order to avoid creating new SvIVs to hold the tagnum we just |
| 4398 |
|
| * cast the tagnum to an SV pointer and store that in the hash. This |
| 4399 |
|
| * means that we must clean up the hash manually afterwards, but gives |
| 4400 |
|
| * us a 15% throughput increase. |
| 4401 |
|
| * |
| 4402 |
|
| */ |
| 4403 |
|
| |
| 4404 |
141737 |
| cxt->tagnum++; |
| 4405 |
|
| #ifdef USE_PTR_TABLE |
| 4406 |
141737 |
| ptr_table_store(pseen, sv, INT2PTR(SV*, 1 + cxt->tagnum)); |
| 4407 |
|
| #else |
| 4408 |
|
| if (!hv_store(hseen, |
| 4409 |
|
| (char *) &sv, sizeof(sv), INT2PTR(SV*, cxt->tagnum), 0)) |
| 4410 |
|
| return -1; |
| 4411 |
|
| #endif |
| 4412 |
|
| |
| 4413 |
|
| /* |
| 4414 |
|
| * Store 'sv' and everything beneath it, using appropriate routine. |
| 4415 |
|
| * Abort immediately if we get a non-zero status back. |
| 4416 |
|
| */ |
| 4417 |
|
| |
| 4418 |
141737 |
| type = sv_type(aTHX_ sv); |
| 4419 |
|
| |
| 4420 |
146751 |
| undef_special_case: |
| 4421 |
|
| TRACEME(("storing 0x%" UVxf " tag #%d, type %d...", |
| 4422 |
|
| PTR2UV(sv), (int)cxt->tagnum, (int)type)); |
| 4423 |
|
| |
| 4424 |
146751 |
▶ | if (SvOBJECT(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOBJECT(sv)) { |
274 |
146477 |
146751 |
|
| 4425 |
274 |
| HV *pkg = SvSTASH(sv); |
| 4426 |
274 |
| ret = store_blessed(aTHX_ cxt, sv, type, pkg); |
| 4427 |
|
| } else |
| 4428 |
146477 |
| ret = SV_STORE(type)(aTHX_ cxt, sv); |
| 4429 |
|
| |
| 4430 |
|
| TRACEME(("%s (stored 0x%" UVxf ", refcnt=%d, %s)", |
| 4431 |
|
| ret ? "FAILED" : "ok", PTR2UV(sv), |
| 4432 |
|
| (int)SvREFCNT(sv), sv_reftype(sv, FALSE))); |
| 4433 |
|
| |
| 4434 |
146634 |
| return ret; |
| 4435 |
|
| } |
| 4436 |
|
| |
| 4437 |
|
| /* |
| 4438 |
|
| * magic_write |
| 4439 |
|
| * |
| 4440 |
|
| * Write magic number and system information into the file. |
| 4441 |
|
| * Layout is <magic> <network> [<len> <byteorder> <sizeof int> <sizeof long> |
| 4442 |
|
| * <sizeof ptr>] where <len> is the length of the byteorder hexa string. |
| 4443 |
|
| * All size and lengths are written as single characters here. |
| 4444 |
|
| * |
| 4445 |
|
| * Note that no byte ordering info is emitted when <network> is true, since |
| 4446 |
|
| * integers will be emitted in network order in that case. |
| 4447 |
|
| */ |
| 4448 |
588 |
| static int magic_write(pTHX_ stcxt_t *cxt) |
| 4449 |
|
| { |
| 4450 |
|
| /* |
| 4451 |
|
| * Starting with 0.6, the "use_network_order" byte flag is also used to |
| 4452 |
|
| * indicate the version number of the binary image, encoded in the upper |
| 4453 |
|
| * bits. The bit 0 is always used to indicate network order. |
| 4454 |
|
| */ |
| 4455 |
|
| /* |
| 4456 |
|
| * Starting with 0.7, a full byte is dedicated to the minor version of |
| 4457 |
|
| * the binary format, which is incremented only when new markers are |
| 4458 |
|
| * introduced, for instance, but when backward compatibility is preserved. |
| 4459 |
|
| */ |
| 4460 |
|
| |
| 4461 |
|
| /* Make these at compile time. The WRITE() macro is sufficiently complex |
| 4462 |
|
| that it saves about 200 bytes doing it this way and only using it |
| 4463 |
|
| once. */ |
| 4464 |
|
| static const unsigned char network_file_header[] = { |
| 4465 |
|
| MAGICSTR_BYTES, |
| 4466 |
|
| (STORABLE_BIN_MAJOR << 1) | 1, |
| 4467 |
|
| STORABLE_BIN_WRITE_MINOR |
| 4468 |
|
| }; |
| 4469 |
|
| static const unsigned char file_header[] = { |
| 4470 |
|
| MAGICSTR_BYTES, |
| 4471 |
|
| (STORABLE_BIN_MAJOR << 1) | 0, |
| 4472 |
|
| STORABLE_BIN_WRITE_MINOR, |
| 4473 |
|
| /* sizeof the array includes the 0 byte at the end: */ |
| 4474 |
|
| (char) sizeof (byteorderstr) - 1, |
| 4475 |
|
| BYTEORDER_BYTES, |
| 4476 |
|
| (unsigned char) sizeof(int), |
| 4477 |
|
| (unsigned char) sizeof(long), |
| 4478 |
|
| (unsigned char) sizeof(char *), |
| 4479 |
|
| (unsigned char) sizeof(NV) |
| 4480 |
|
| }; |
| 4481 |
|
| #ifdef USE_56_INTERWORK_KLUDGE |
| 4482 |
|
| static const unsigned char file_header_56[] = { |
| 4483 |
|
| MAGICSTR_BYTES, |
| 4484 |
|
| (STORABLE_BIN_MAJOR << 1) | 0, |
| 4485 |
|
| STORABLE_BIN_WRITE_MINOR, |
| 4486 |
|
| /* sizeof the array includes the 0 byte at the end: */ |
| 4487 |
|
| (char) sizeof (byteorderstr_56) - 1, |
| 4488 |
|
| BYTEORDER_BYTES_56, |
| 4489 |
|
| (unsigned char) sizeof(int), |
| 4490 |
|
| (unsigned char) sizeof(long), |
| 4491 |
|
| (unsigned char) sizeof(char *), |
| 4492 |
|
| (unsigned char) sizeof(NV) |
| 4493 |
|
| }; |
| 4494 |
|
| #endif |
| 4495 |
|
| const unsigned char *header; |
| 4496 |
|
| SSize_t length; |
| 4497 |
|
| |
| 4498 |
|
| TRACEME(("magic_write on fd=%d", cxt->fio ? PerlIO_fileno(cxt->fio) : -1)); |
| 4499 |
|
| |
| 4500 |
588 |
▶ | if (cxt->netorder) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->netorder) { |
92 |
496 |
588 |
|
| 4501 |
92 |
| header = network_file_header; |
| 4502 |
92 |
| length = sizeof (network_file_header); |
| 4503 |
|
| } else { |
| 4504 |
|
| #ifdef USE_56_INTERWORK_KLUDGE |
| 4505 |
|
| if (SvTRUE(get_sv("Storable::interwork_56_64bit", GV_ADD))) { |
| 4506 |
|
| header = file_header_56; |
| 4507 |
|
| length = sizeof (file_header_56); |
| 4508 |
|
| } else |
| 4509 |
|
| #endif |
| 4510 |
|
| { |
| 4511 |
496 |
| header = file_header; |
| 4512 |
496 |
| length = sizeof (file_header); |
| 4513 |
|
| } |
| 4514 |
|
| } |
| 4515 |
|
| |
| 4516 |
588 |
▶ | if (!cxt->fio) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!cxt->fio) { |
484 |
104 |
588 |
|
| 4517 |
|
| /* sizeof the array includes the 0 byte at the end. */ |
| 4518 |
484 |
| header += sizeof (magicstr) - 1; |
| 4519 |
484 |
| length -= sizeof (magicstr) - 1; |
| 4520 |
|
| } |
| 4521 |
|
| |
| 4522 |
588 |
▶ | WRITE( (unsigned char*) header, length); |
Branch: 3 branches
| Branch | True | False | Total |
| WRITE( (unsigned char*) header, length); |
484 |
104 |
588 |
| WRITE( (unsigned char*) header, length); |
0 |
484 |
484 |
| WRITE( (unsigned char*) header, length); |
0 |
104 |
104 |
|
| 4523 |
|
| |
| 4524 |
588 |
| if (!cxt->netorder) { |
| 4525 |
|
| TRACEME(("ok (magic_write byteorder = 0x%lx [%d], I%d L%d P%d D%d)", |
| 4526 |
|
| (unsigned long) BYTEORDER, (int) sizeof (byteorderstr) - 1, |
| 4527 |
|
| (int) sizeof(int), (int) sizeof(long), |
| 4528 |
|
| (int) sizeof(char *), (int) sizeof(NV))); |
| 4529 |
|
| } |
| 4530 |
588 |
| return 0; |
| 4531 |
|
| } |
| 4532 |
|
| |
| 4533 |
|
| /* |
| 4534 |
|
| * do_store |
| 4535 |
|
| * |
| 4536 |
|
| * Common code for store operations. |
| 4537 |
|
| * |
| 4538 |
|
| * When memory store is requested (f = NULL) and a non null SV* is given in |
| 4539 |
|
| * 'res', it is filled with a new SV created out of the memory buffer. |
| 4540 |
|
| * |
| 4541 |
|
| * It is required to provide a non-null 'res' when the operation type is not |
| 4542 |
|
| * dclone() and store() is performed to memory. |
| 4543 |
|
| */ |
| 4544 |
588 |
| static int do_store(pTHX_ |
| 4545 |
|
| PerlIO *f, |
| 4546 |
|
| SV *sv, |
| 4547 |
|
| int optype, |
| 4548 |
|
| int network_order, |
| 4549 |
|
| SV **res) |
| 4550 |
|
| { |
| 4551 |
588 |
| dSTCXT; |
| 4552 |
|
| int status; |
| 4553 |
|
| |
| 4554 |
|
| ASSERT(!(f == 0 && !(optype & ST_CLONE)) || res, |
| 4555 |
|
| ("must supply result SV pointer for real recursion to memory")); |
| 4556 |
|
| |
| 4557 |
|
| TRACEMED(("do_store (optype=%d, netorder=%d)", |
| 4558 |
|
| optype, network_order)); |
| 4559 |
|
| |
| 4560 |
588 |
| optype |= ST_STORE; |
| 4561 |
|
| |
| 4562 |
|
| /* |
| 4563 |
|
| * Workaround for CROAK leak: if they enter with a "dirty" context, |
| 4564 |
|
| * free up memory for them now. |
| 4565 |
|
| */ |
| 4566 |
|
| |
| 4567 |
|
| assert(cxt); |
| 4568 |
588 |
▶ | if (cxt->s_dirty) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->s_dirty) |
16 |
572 |
588 |
|
| 4569 |
16 |
| clean_context(aTHX_ cxt); |
| 4570 |
|
| |
| 4571 |
|
| /* |
| 4572 |
|
| * Now that STORABLE_xxx hooks exist, it is possible that they try to |
| 4573 |
|
| * re-enter store() via the hooks. We need to stack contexts. |
| 4574 |
|
| */ |
| 4575 |
|
| |
| 4576 |
588 |
▶ | if (cxt->entry) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->entry) |
85 |
503 |
588 |
|
| 4577 |
85 |
| cxt = allocate_context(aTHX_ cxt); |
| 4578 |
|
| |
| 4579 |
|
| INIT_TRACEME; |
| 4580 |
|
| |
| 4581 |
588 |
| cxt->entry++; |
| 4582 |
|
| |
| 4583 |
|
| ASSERT(cxt->entry == 1, ("starting new recursion")); |
| 4584 |
|
| ASSERT(!cxt->s_dirty, ("clean context")); |
| 4585 |
|
| |
| 4586 |
|
| /* |
| 4587 |
|
| * Ensure sv is actually a reference. From perl, we called something |
| 4588 |
|
| * like: |
| 4589 |
|
| * pstore(aTHX_ FILE, \@array); |
| 4590 |
|
| * so we must get the scalar value behind that reference. |
| 4591 |
|
| */ |
| 4592 |
|
| |
| 4593 |
588 |
▶ | if (!SvROK(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(sv)) |
0 |
588 |
588 |
|
| 4594 |
0 |
| CROAK(("Not a reference")); |
| 4595 |
588 |
| sv = SvRV(sv); /* So follow it to know what to store */ |
| 4596 |
|
| |
| 4597 |
|
| /* |
| 4598 |
|
| * If we're going to store to memory, reset the buffer. |
| 4599 |
|
| */ |
| 4600 |
|
| |
| 4601 |
588 |
▶ | if (!f) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) |
484 |
104 |
588 |
|
| 4602 |
484 |
▶ | MBUF_INIT(0); |
Branch: 1 branch
| Branch | True | False | Total |
| MBUF_INIT(0); |
112 |
372 |
484 |
|
| 4603 |
|
| |
| 4604 |
|
| /* |
| 4605 |
|
| * Prepare context and emit headers. |
| 4606 |
|
| */ |
| 4607 |
|
| |
| 4608 |
588 |
| init_store_context(aTHX_ cxt, f, optype, network_order); |
| 4609 |
|
| |
| 4610 |
588 |
▶ | if (-1 == magic_write(aTHX_ cxt)) /* Emit magic and ILP info */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (-1 == magic_write(aTHX_ cxt)) /* Emit magic and ILP info */ |
0 |
588 |
588 |
|
| 4611 |
0 |
| return 0; /* Error */ |
| 4612 |
|
| |
| 4613 |
|
| /* |
| 4614 |
|
| * Recursively store object... |
| 4615 |
|
| */ |
| 4616 |
|
| |
| 4617 |
|
| ASSERT(is_storing(aTHX), ("within store operation")); |
| 4618 |
|
| |
| 4619 |
588 |
| status = store(aTHX_ cxt, sv); /* Just do it! */ |
| 4620 |
|
| |
| 4621 |
|
| /* |
| 4622 |
|
| * If they asked for a memory store and they provided an SV pointer, |
| 4623 |
|
| * make an SV string out of the buffer and fill their pointer. |
| 4624 |
|
| * |
| 4625 |
|
| * When asking for ST_REAL, it's MANDATORY for the caller to provide |
| 4626 |
|
| * an SV, since context cleanup might free the buffer if we did recurse. |
| 4627 |
|
| * (unless caller is dclone(), which is aware of that). |
| 4628 |
|
| */ |
| 4629 |
|
| |
| 4630 |
576 |
▶ | if (!cxt->fio && res) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cxt->fio && res) |
475 |
101 |
576 |
| if (!cxt->fio && res) |
273 |
202 |
475 |
|
| 4631 |
273 |
| *res = mbuf2sv(aTHX); |
| 4632 |
|
| |
| 4633 |
|
| TRACEME(("do_store returns %d", status)); |
| 4634 |
|
| |
| 4635 |
|
| /* |
| 4636 |
|
| * Final cleanup. |
| 4637 |
|
| * |
| 4638 |
|
| * The "root" context is never freed, since it is meant to be always |
| 4639 |
|
| * handy for the common case where no recursion occurs at all (i.e. |
| 4640 |
|
| * we enter store() outside of any Storable code and leave it, period). |
| 4641 |
|
| * We know it's the "root" context because there's nothing stacked |
| 4642 |
|
| * underneath it. |
| 4643 |
|
| * |
| 4644 |
|
| * OPTIMIZATION: |
| 4645 |
|
| * |
| 4646 |
|
| * When deep cloning, we don't free the context: doing so would force |
| 4647 |
|
| * us to copy the data in the memory buffer. Sicne we know we're |
| 4648 |
|
| * about to enter do_retrieve... |
| 4649 |
|
| */ |
| 4650 |
|
| |
| 4651 |
576 |
| clean_store_context(aTHX_ cxt); |
| 4652 |
576 |
▶ | if (cxt->prev && !(cxt->optype & ST_CLONE)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (cxt->prev && !(cxt->optype & ST_CLONE)) |
82 |
494 |
576 |
| if (cxt->prev && !(cxt->optype & ST_CLONE)) |
44 |
38 |
82 |
|
| 4653 |
44 |
| free_context(aTHX_ cxt); |
| 4654 |
|
| |
| 4655 |
576 |
| return status == 0; |
| 4656 |
|
| } |
| 4657 |
|
| |
| 4658 |
|
| /*** |
| 4659 |
|
| *** Memory stores. |
| 4660 |
|
| ***/ |
| 4661 |
|
| |
| 4662 |
|
| /* |
| 4663 |
|
| * mbuf2sv |
| 4664 |
|
| * |
| 4665 |
|
| * Build a new SV out of the content of the internal memory buffer. |
| 4666 |
|
| */ |
| 4667 |
273 |
| static SV *mbuf2sv(pTHX) |
| 4668 |
|
| { |
| 4669 |
273 |
| dSTCXT; |
| 4670 |
|
| |
| 4671 |
|
| assert(cxt); |
| 4672 |
273 |
| return newSVpv(mbase, MBUF_SIZE()); |
| 4673 |
|
| } |
| 4674 |
|
| |
| 4675 |
|
| /*** |
| 4676 |
|
| *** Specific retrieve callbacks. |
| 4677 |
|
| ***/ |
| 4678 |
|
| |
| 4679 |
|
| /* |
| 4680 |
|
| * retrieve_other |
| 4681 |
|
| * |
| 4682 |
|
| * Return an error via croak, since it is not possible that we get here |
| 4683 |
|
| * under normal conditions, when facing a file produced via pstore(). |
| 4684 |
|
| */ |
| 4685 |
10 |
| static SV *retrieve_other(pTHX_ stcxt_t *cxt, const char *cname) |
| 4686 |
|
| { |
| 4687 |
|
| PERL_UNUSED_ARG(cname); |
| 4688 |
10 |
| if ( |
| 4689 |
10 |
▶ | cxt->ver_major != STORABLE_BIN_MAJOR && |
Branch: 1 branch
| Branch | True | False | Total |
| cxt->ver_major != STORABLE_BIN_MAJOR && |
2 |
8 |
10 |
|
| 4690 |
2 |
▶ | cxt->ver_minor != STORABLE_BIN_MINOR |
Branch: 1 branch
| Branch | True | False | Total |
| cxt->ver_minor != STORABLE_BIN_MINOR |
2 |
0 |
2 |
|
| 4691 |
|
| ) { |
| 4692 |
2 |
▶ | CROAK(("Corrupted storable %s (binary v%d.%d), current is v%d.%d", |
Branch: 1 branch
| Branch | True | False | Total |
| CROAK(("Corrupted storable %s (binary v%d.%d), current is v%d.%d", |
2 |
0 |
2 |
|
| 4693 |
|
| cxt->fio ? "file" : "string", |
| 4694 |
|
| cxt->ver_major, cxt->ver_minor, |
| 4695 |
|
| STORABLE_BIN_MAJOR, STORABLE_BIN_MINOR)); |
| 4696 |
|
| } else { |
| 4697 |
8 |
▶ | CROAK(("Corrupted storable %s (binary v%d.%d)", |
Branch: 1 branch
| Branch | True | False | Total |
| CROAK(("Corrupted storable %s (binary v%d.%d)", |
4 |
4 |
8 |
|
| 4698 |
|
| cxt->fio ? "file" : "string", |
| 4699 |
|
| cxt->ver_major, cxt->ver_minor)); |
| 4700 |
|
| } |
| 4701 |
|
| |
| 4702 |
|
| return (SV *) 0; /* Just in case */ |
| 4703 |
|
| } |
| 4704 |
|
| |
| 4705 |
|
| /* |
| 4706 |
|
| * retrieve_idx_blessed |
| 4707 |
|
| * |
| 4708 |
|
| * Layout is SX_IX_BLESS <index> <object> with SX_IX_BLESS already read. |
| 4709 |
|
| * <index> can be coded on either 1 or 5 bytes. |
| 4710 |
|
| */ |
| 4711 |
19 |
| static SV *retrieve_idx_blessed(pTHX_ stcxt_t *cxt, const char *cname) |
| 4712 |
|
| { |
| 4713 |
|
| I32 idx; |
| 4714 |
|
| const char *classname; |
| 4715 |
|
| SV **sva; |
| 4716 |
|
| SV *sv; |
| 4717 |
|
| |
| 4718 |
|
| PERL_UNUSED_ARG(cname); |
| 4719 |
|
| TRACEME(("retrieve_idx_blessed (#%d)", (int)cxt->tagnum)); |
| 4720 |
|
| ASSERT(!cname, ("no bless-into class given here, got %s", cname)); |
| 4721 |
|
| |
| 4722 |
19 |
▶ | GETMARK(idx); /* Index coded on a single char? */ |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(idx); /* Index coded on a single char? */ |
19 |
0 |
19 |
| GETMARK(idx); /* Index coded on a single char? */ |
19 |
0 |
19 |
| GETMARK(idx); /* Index coded on a single char? */ |
0 |
0 |
0 |
|
| 4723 |
19 |
▶ | if (idx & 0x80) |
Branch: 1 branch
| Branch | True | False | Total |
| if (idx & 0x80) |
0 |
19 |
19 |
|
| 4724 |
0 |
▶ | RLEN(idx); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(idx); |
0 |
0 |
0 |
| RLEN(idx); |
0 |
0 |
0 |
| RLEN(idx); |
0 |
0 |
0 |
| RLEN(idx); |
0 |
0 |
0 |
| RLEN(idx); |
0 |
0 |
0 |
|
| 4725 |
|
| |
| 4726 |
|
| /* |
| 4727 |
|
| * Fetch classname in 'aclass' |
| 4728 |
|
| */ |
| 4729 |
|
| |
| 4730 |
19 |
| sva = av_fetch(cxt->aclass, idx, FALSE); |
| 4731 |
19 |
▶ | if (!sva) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sva) |
0 |
19 |
19 |
|
| 4732 |
0 |
| CROAK(("Class name #%" IVdf " should have been seen already", |
| 4733 |
|
| (IV) idx)); |
| 4734 |
|
| |
| 4735 |
19 |
| classname = SvPVX(*sva); /* We know it's a PV, by construction */ |
| 4736 |
|
| |
| 4737 |
|
| TRACEME(("class ID %d => %s", (int)idx, classname)); |
| 4738 |
|
| |
| 4739 |
|
| /* |
| 4740 |
|
| * Retrieve object and bless it. |
| 4741 |
|
| */ |
| 4742 |
|
| |
| 4743 |
19 |
| sv = retrieve(aTHX_ cxt, classname); /* First SV which is SEEN |
| 4744 |
|
| will be blessed */ |
| 4745 |
|
| |
| 4746 |
19 |
| return sv; |
| 4747 |
|
| } |
| 4748 |
|
| |
| 4749 |
|
| /* |
| 4750 |
|
| * retrieve_blessed |
| 4751 |
|
| * |
| 4752 |
|
| * Layout is SX_BLESS <len> <classname> <object> with SX_BLESS already read. |
| 4753 |
|
| * <len> can be coded on either 1 or 5 bytes. |
| 4754 |
|
| */ |
| 4755 |
130 |
| static SV *retrieve_blessed(pTHX_ stcxt_t *cxt, const char *cname) |
| 4756 |
|
| { |
| 4757 |
|
| U32 len; |
| 4758 |
|
| SV *sv; |
| 4759 |
|
| char buf[LG_BLESS + 1]; /* Avoid malloc() if possible */ |
| 4760 |
130 |
| char *classname = buf; |
| 4761 |
130 |
| char *malloced_classname = NULL; |
| 4762 |
|
| |
| 4763 |
|
| PERL_UNUSED_ARG(cname); |
| 4764 |
|
| TRACEME(("retrieve_blessed (#%d)", (int)cxt->tagnum)); |
| 4765 |
|
| ASSERT(!cname, ("no bless-into class given here, got %s", cname)); |
| 4766 |
|
| |
| 4767 |
|
| /* |
| 4768 |
|
| * Decode class name length and read that name. |
| 4769 |
|
| * |
| 4770 |
|
| * Short classnames have two advantages: their length is stored on one |
| 4771 |
|
| * single byte, and the string can be read on the stack. |
| 4772 |
|
| */ |
| 4773 |
|
| |
| 4774 |
130 |
▶ | GETMARK(len); /* Length coded on a single char? */ |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(len); /* Length coded on a single char? */ |
117 |
13 |
130 |
| GETMARK(len); /* Length coded on a single char? */ |
117 |
0 |
117 |
| GETMARK(len); /* Length coded on a single char? */ |
0 |
13 |
13 |
|
| 4775 |
130 |
▶ | if (len & 0x80) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len & 0x80) { |
2 |
128 |
130 |
|
| 4776 |
2 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
2 |
0 |
2 |
| RLEN(len); |
2 |
0 |
2 |
| RLEN(len); |
0 |
2 |
2 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
2 |
2 |
|
| 4777 |
|
| TRACEME(("** allocating %ld bytes for class name", (long)len+1)); |
| 4778 |
2 |
▶ | if (len > I32_MAX) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > I32_MAX) |
1 |
1 |
2 |
|
| 4779 |
1 |
| CROAK(("Corrupted classname length %lu", (long)len)); |
| 4780 |
1 |
| PL_nomemok = TRUE; /* handle error by ourselves */ |
| 4781 |
1 |
| New(10003, classname, len+1, char); |
| 4782 |
1 |
| PL_nomemok = FALSE; |
| 4783 |
1 |
▶ | if (!classname) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!classname) |
0 |
1 |
1 |
|
| 4784 |
0 |
| CROAK(("Out of memory with len %ld", (long)len)); |
| 4785 |
1 |
| PL_nomemok = FALSE; |
| 4786 |
1 |
| malloced_classname = classname; |
| 4787 |
|
| } |
| 4788 |
129 |
▶ | SAFEPVREAD(classname, (I32)len, malloced_classname); |
Branch: 3 branches
| Branch | True | False | Total |
| SAFEPVREAD(classname, (I32)len, malloced_classname); |
116 |
13 |
129 |
| SAFEPVREAD(classname, (I32)len, malloced_classname); |
116 |
0 |
116 |
| SAFEPVREAD(classname, (I32)len, malloced_classname); |
0 |
13 |
13 |
|
| 4789 |
129 |
| classname[len] = '\0'; /* Mark string end */ |
| 4790 |
|
| |
| 4791 |
|
| /* |
| 4792 |
|
| * It's a new classname, otherwise it would have been an SX_IX_BLESS. |
| 4793 |
|
| */ |
| 4794 |
|
| |
| 4795 |
|
| TRACEME(("new class name \"%s\" will bear ID = %d", classname, |
| 4796 |
|
| (int)cxt->classnum)); |
| 4797 |
|
| |
| 4798 |
129 |
▶ | if (!av_store(cxt->aclass, cxt->classnum++, newSVpvn(classname, len))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!av_store(cxt->aclass, cxt->classnum++, newSVpvn(classname, len))) { |
0 |
129 |
129 |
|
| 4799 |
0 |
| Safefree(malloced_classname); |
| 4800 |
0 |
| return (SV *) 0; |
| 4801 |
|
| } |
| 4802 |
|
| |
| 4803 |
|
| /* |
| 4804 |
|
| * Retrieve object and bless it. |
| 4805 |
|
| */ |
| 4806 |
|
| |
| 4807 |
129 |
| sv = retrieve(aTHX_ cxt, classname); /* First SV which is SEEN will be blessed */ |
| 4808 |
128 |
▶ | if (malloced_classname) |
Branch: 1 branch
| Branch | True | False | Total |
| if (malloced_classname) |
1 |
127 |
128 |
|
| 4809 |
1 |
| Safefree(malloced_classname); |
| 4810 |
|
| |
| 4811 |
128 |
| return sv; |
| 4812 |
|
| } |
| 4813 |
|
| |
| 4814 |
|
| /* |
| 4815 |
|
| * retrieve_hook |
| 4816 |
|
| * |
| 4817 |
|
| * Layout: SX_HOOK <flags> <len> <classname> <len2> <str> [<len3> <object-IDs>] |
| 4818 |
|
| * with leading mark already read, as usual. |
| 4819 |
|
| * |
| 4820 |
|
| * When recursion was involved during serialization of the object, there |
| 4821 |
|
| * is an unknown amount of serialized objects after the SX_HOOK mark. Until |
| 4822 |
|
| * we reach a <flags> marker with the recursion bit cleared. |
| 4823 |
|
| * |
| 4824 |
|
| * If the first <flags> byte contains a type of SHT_EXTRA, then the real type |
| 4825 |
|
| * is held in the <extra> byte, and if the object is tied, the serialized |
| 4826 |
|
| * magic object comes at the very end: |
| 4827 |
|
| * |
| 4828 |
|
| * SX_HOOK <flags> <extra> ... [<len3> <object-IDs>] <magic object> |
| 4829 |
|
| * |
| 4830 |
|
| * This means the STORABLE_thaw hook will NOT get a tied variable during its |
| 4831 |
|
| * processing (since we won't have seen the magic object by the time the hook |
| 4832 |
|
| * is called). See comments below for why it was done that way. |
| 4833 |
|
| */ |
| 4834 |
116 |
| static SV *retrieve_hook_common(pTHX_ stcxt_t *cxt, const char *cname, int large) |
| 4835 |
|
| { |
| 4836 |
|
| U32 len; |
| 4837 |
|
| char buf[LG_BLESS + 1]; /* Avoid malloc() if possible */ |
| 4838 |
116 |
| char *classname = buf; |
| 4839 |
|
| unsigned int flags; |
| 4840 |
|
| STRLEN len2; |
| 4841 |
|
| SV *frozen; |
| 4842 |
116 |
| I32 len3 = 0; |
| 4843 |
116 |
| AV *av = 0; |
| 4844 |
|
| SV *hook; |
| 4845 |
|
| SV *sv; |
| 4846 |
|
| SV *rv; |
| 4847 |
|
| GV *attach; |
| 4848 |
|
| HV *stash; |
| 4849 |
|
| int obj_type; |
| 4850 |
116 |
| int clone = cxt->optype & ST_CLONE; |
| 4851 |
116 |
| char mtype = '\0'; |
| 4852 |
116 |
| unsigned int extra_type = 0; |
| 4853 |
|
| #ifdef HAS_U64 |
| 4854 |
116 |
| int has_large_oids = 0; |
| 4855 |
|
| #endif |
| 4856 |
|
| |
| 4857 |
|
| PERL_UNUSED_ARG(cname); |
| 4858 |
|
| TRACEME(("retrieve_hook (#%d)", (int)cxt->tagnum)); |
| 4859 |
|
| ASSERT(!cname, ("no bless-into class given here, got %s", cname)); |
| 4860 |
|
| |
| 4861 |
|
| #ifndef HAS_U64 |
| 4862 |
|
| assert(!large); |
| 4863 |
|
| PERL_UNUSED_ARG(large); |
| 4864 |
|
| #endif |
| 4865 |
|
| |
| 4866 |
|
| /* |
| 4867 |
|
| * Read flags, which tell us about the type, and whether we need |
| 4868 |
|
| * to recurse. |
| 4869 |
|
| */ |
| 4870 |
|
| |
| 4871 |
116 |
▶ | GETMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(flags); |
110 |
6 |
116 |
| GETMARK(flags); |
110 |
0 |
110 |
| GETMARK(flags); |
0 |
6 |
6 |
|
| 4872 |
|
| |
| 4873 |
|
| /* |
| 4874 |
|
| * Create the (empty) object, and mark it as seen. |
| 4875 |
|
| * |
| 4876 |
|
| * This must be done now, because tags are incremented, and during |
| 4877 |
|
| * serialization, the object tag was affected before recursion could |
| 4878 |
|
| * take place. |
| 4879 |
|
| */ |
| 4880 |
|
| |
| 4881 |
116 |
| obj_type = flags & SHF_TYPE_MASK; |
| 4882 |
116 |
| switch (obj_type) { |
| 4883 |
9 |
| case SHT_SCALAR: |
| 4884 |
9 |
| sv = newSV(0); |
| 4885 |
9 |
| break; |
| 4886 |
75 |
| case SHT_ARRAY: |
| 4887 |
75 |
| sv = (SV *) newAV(); |
| 4888 |
75 |
| break; |
| 4889 |
31 |
| case SHT_HASH: |
| 4890 |
31 |
| sv = (SV *) newHV(); |
| 4891 |
31 |
| break; |
| 4892 |
1 |
| case SHT_EXTRA: |
| 4893 |
|
| /* |
| 4894 |
|
| * Read <extra> flag to know the type of the object. |
| 4895 |
|
| * Record associated magic type for later. |
| 4896 |
|
| */ |
| 4897 |
1 |
▶ | GETMARK(extra_type); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(extra_type); |
1 |
0 |
1 |
| GETMARK(extra_type); |
1 |
0 |
1 |
| GETMARK(extra_type); |
0 |
0 |
0 |
|
| 4898 |
1 |
| switch (extra_type) { |
| 4899 |
0 |
| case SHT_TSCALAR: |
| 4900 |
0 |
| sv = newSV(0); |
| 4901 |
0 |
| mtype = 'q'; |
| 4902 |
0 |
| break; |
| 4903 |
0 |
| case SHT_TARRAY: |
| 4904 |
0 |
| sv = (SV *) newAV(); |
| 4905 |
0 |
| mtype = 'P'; |
| 4906 |
0 |
| break; |
| 4907 |
1 |
| case SHT_THASH: |
| 4908 |
1 |
| sv = (SV *) newHV(); |
| 4909 |
1 |
| mtype = 'P'; |
| 4910 |
1 |
| break; |
| 4911 |
0 |
| default: |
| 4912 |
0 |
| return retrieve_other(aTHX_ cxt, 0);/* Let it croak */ |
| 4913 |
|
| } |
| 4914 |
1 |
| break; |
| 4915 |
0 |
| default: |
| 4916 |
0 |
| return retrieve_other(aTHX_ cxt, 0); /* Let it croak */ |
| 4917 |
|
| } |
| 4918 |
116 |
▶ | SEEN0_NN(sv, 0); /* Don't bless yet */ |
Branch: 1 branch
| Branch | True | False | Total |
| SEEN0_NN(sv, 0); /* Don't bless yet */ |
0 |
116 |
116 |
|
| 4919 |
|
| |
| 4920 |
|
| /* |
| 4921 |
|
| * Whilst flags tell us to recurse, do so. |
| 4922 |
|
| * |
| 4923 |
|
| * We don't need to remember the addresses returned by retrieval, because |
| 4924 |
|
| * all the references will be obtained through indirection via the object |
| 4925 |
|
| * tags in the object-ID list. |
| 4926 |
|
| * |
| 4927 |
|
| * We need to decrement the reference count for these objects |
| 4928 |
|
| * because, if the user doesn't save a reference to them in the hook, |
| 4929 |
|
| * they must be freed when this context is cleaned. |
| 4930 |
|
| */ |
| 4931 |
|
| |
| 4932 |
141 |
▶ | while (flags & SHF_NEED_RECURSE) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (flags & SHF_NEED_RECURSE) { |
25 |
116 |
141 |
|
| 4933 |
|
| TRACEME(("retrieve_hook recursing...")); |
| 4934 |
25 |
| rv = retrieve(aTHX_ cxt, 0); |
| 4935 |
25 |
▶ | if (!rv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rv) |
0 |
25 |
25 |
|
| 4936 |
0 |
| return (SV *) 0; |
| 4937 |
25 |
| SvREFCNT_dec(rv); |
| 4938 |
|
| TRACEME(("retrieve_hook back with rv=0x%" UVxf, |
| 4939 |
|
| PTR2UV(rv))); |
| 4940 |
25 |
▶ | GETMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(flags); |
21 |
4 |
25 |
| GETMARK(flags); |
21 |
0 |
21 |
| GETMARK(flags); |
0 |
4 |
4 |
|
| 4941 |
|
| } |
| 4942 |
|
| |
| 4943 |
116 |
▶ | if (flags & SHF_IDX_CLASSNAME) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_IDX_CLASSNAME) { |
20 |
96 |
116 |
|
| 4944 |
|
| SV **sva; |
| 4945 |
|
| I32 idx; |
| 4946 |
|
| |
| 4947 |
|
| /* |
| 4948 |
|
| * Fetch index from 'aclass' |
| 4949 |
|
| */ |
| 4950 |
|
| |
| 4951 |
20 |
▶ | if (flags & SHF_LARGE_CLASSLEN) |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_LARGE_CLASSLEN) |
0 |
20 |
20 |
|
| 4952 |
0 |
▶ | RLEN(idx); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(idx); |
0 |
0 |
0 |
| RLEN(idx); |
0 |
0 |
0 |
| RLEN(idx); |
0 |
0 |
0 |
| RLEN(idx); |
0 |
0 |
0 |
| RLEN(idx); |
0 |
0 |
0 |
|
| 4953 |
|
| else |
| 4954 |
20 |
▶ | GETMARK(idx); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(idx); |
20 |
0 |
20 |
| GETMARK(idx); |
20 |
0 |
20 |
| GETMARK(idx); |
0 |
0 |
0 |
|
| 4955 |
|
| |
| 4956 |
20 |
| sva = av_fetch(cxt->aclass, idx, FALSE); |
| 4957 |
20 |
▶ | if (!sva) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sva) |
0 |
20 |
20 |
|
| 4958 |
0 |
| CROAK(("Class name #%" IVdf " should have been seen already", |
| 4959 |
|
| (IV) idx)); |
| 4960 |
|
| |
| 4961 |
20 |
| classname = SvPVX(*sva); /* We know it's a PV, by construction */ |
| 4962 |
|
| TRACEME(("class ID %d => %s", (int)idx, classname)); |
| 4963 |
|
| |
| 4964 |
|
| } else { |
| 4965 |
|
| /* |
| 4966 |
|
| * Decode class name length and read that name. |
| 4967 |
|
| * |
| 4968 |
|
| * NOTA BENE: even if the length is stored on one byte, we don't read |
| 4969 |
|
| * on the stack. Just like retrieve_blessed(), we limit the name to |
| 4970 |
|
| * LG_BLESS bytes. This is an arbitrary decision. |
| 4971 |
|
| */ |
| 4972 |
96 |
| char *malloced_classname = NULL; |
| 4973 |
|
| |
| 4974 |
96 |
▶ | if (flags & SHF_LARGE_CLASSLEN) |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_LARGE_CLASSLEN) |
2 |
94 |
96 |
|
| 4975 |
2 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
1 |
1 |
2 |
| RLEN(len); |
1 |
0 |
1 |
| RLEN(len); |
0 |
1 |
1 |
| RLEN(len); |
0 |
1 |
1 |
| RLEN(len); |
0 |
2 |
2 |
|
| 4976 |
|
| else |
| 4977 |
94 |
▶ | GETMARK(len); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(len); |
89 |
5 |
94 |
| GETMARK(len); |
89 |
0 |
89 |
| GETMARK(len); |
0 |
5 |
5 |
|
| 4978 |
|
| |
| 4979 |
|
| TRACEME(("** allocating %ld bytes for class name", (long)len+1)); |
| 4980 |
96 |
▶ | if (len > I32_MAX) /* security */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > I32_MAX) /* security */ |
2 |
94 |
96 |
|
| 4981 |
2 |
| CROAK(("Corrupted classname length %lu", (long)len)); |
| 4982 |
94 |
▶ | else if (len > LG_BLESS) { /* security: signed len */ |
Branch: 1 branch
| Branch | True | False | Total |
| else if (len > LG_BLESS) { /* security: signed len */ |
1 |
93 |
94 |
|
| 4983 |
1 |
| PL_nomemok = TRUE; /* handle error by ourselves */ |
| 4984 |
1 |
| New(10003, classname, len+1, char); |
| 4985 |
1 |
| PL_nomemok = FALSE; |
| 4986 |
1 |
▶ | if (!classname) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!classname) |
0 |
1 |
1 |
|
| 4987 |
0 |
| CROAK(("Out of memory with len %u", (unsigned)len+1)); |
| 4988 |
1 |
| malloced_classname = classname; |
| 4989 |
|
| } |
| 4990 |
|
| |
| 4991 |
94 |
▶ | SAFEPVREAD(classname, (I32)len, malloced_classname); |
Branch: 3 branches
| Branch | True | False | Total |
| SAFEPVREAD(classname, (I32)len, malloced_classname); |
89 |
5 |
94 |
| SAFEPVREAD(classname, (I32)len, malloced_classname); |
89 |
0 |
89 |
| SAFEPVREAD(classname, (I32)len, malloced_classname); |
0 |
5 |
5 |
|
| 4992 |
94 |
| classname[len] = '\0'; /* Mark string end */ |
| 4993 |
|
| |
| 4994 |
|
| /* |
| 4995 |
|
| * Record new classname. |
| 4996 |
|
| */ |
| 4997 |
|
| |
| 4998 |
94 |
▶ | if (!av_store(cxt->aclass, cxt->classnum++, |
Branch: 1 branch
| Branch | True | False | Total |
| if (!av_store(cxt->aclass, cxt->classnum++, |
0 |
94 |
94 |
|
| 4999 |
|
| newSVpvn(classname, len))) { |
| 5000 |
0 |
| Safefree(malloced_classname); |
| 5001 |
0 |
| return (SV *) 0; |
| 5002 |
|
| } |
| 5003 |
|
| } |
| 5004 |
|
| |
| 5005 |
|
| TRACEME(("class name: %s", classname)); |
| 5006 |
|
| |
| 5007 |
|
| /* |
| 5008 |
|
| * Decode user-frozen string length and read it in an SV. |
| 5009 |
|
| * |
| 5010 |
|
| * For efficiency reasons, we read data directly into the SV buffer. |
| 5011 |
|
| * To understand that code, read retrieve_scalar() |
| 5012 |
|
| */ |
| 5013 |
|
| |
| 5014 |
|
| #ifdef HAS_U64 |
| 5015 |
114 |
▶ | if (large) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (large) { |
0 |
114 |
114 |
|
| 5016 |
0 |
▶ | READ_U64(len2); |
Branch: 7 branches
| Branch | True | False | Total |
| READ_U64(len2); |
0 |
0 |
0 |
| READ_U64(len2); |
0 |
0 |
0 |
| READ_U64(len2); |
0 |
0 |
0 |
| READ_U64(len2); |
0 |
0 |
0 |
| READ_U64(len2); |
0 |
0 |
0 |
| READ_U64(len2); |
0 |
0 |
0 |
| READ_U64(len2); |
0 |
0 |
0 |
|
| 5017 |
|
| } |
| 5018 |
|
| else |
| 5019 |
|
| #endif |
| 5020 |
114 |
▶ | if (flags & SHF_LARGE_STRLEN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_LARGE_STRLEN) { |
24 |
90 |
114 |
|
| 5021 |
|
| U32 len32; |
| 5022 |
24 |
▶ | RLEN(len32); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len32); |
24 |
0 |
24 |
| RLEN(len32); |
24 |
0 |
24 |
| RLEN(len32); |
0 |
24 |
24 |
| RLEN(len32); |
0 |
0 |
0 |
| RLEN(len32); |
0 |
24 |
24 |
|
| 5023 |
24 |
| len2 = len32; |
| 5024 |
|
| } |
| 5025 |
|
| else |
| 5026 |
90 |
▶ | GETMARK(len2); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(len2); |
85 |
5 |
90 |
| GETMARK(len2); |
85 |
0 |
85 |
| GETMARK(len2); |
0 |
5 |
5 |
|
| 5027 |
|
| |
| 5028 |
114 |
▶ | frozen = NEWSV(10002, len2 ? len2 : 1); |
Branch: 1 branch
| Branch | True | False | Total |
| frozen = NEWSV(10002, len2 ? len2 : 1); |
73 |
41 |
114 |
|
| 5029 |
114 |
▶ | if (len2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len2) { |
73 |
41 |
114 |
|
| 5030 |
73 |
▶ | SAFEREAD(SvPVX(frozen), len2, frozen); |
Branch: 3 branches
| Branch | True | False | Total |
| SAFEREAD(SvPVX(frozen), len2, frozen); |
69 |
4 |
73 |
| SAFEREAD(SvPVX(frozen), len2, frozen); |
69 |
0 |
69 |
| SAFEREAD(SvPVX(frozen), len2, frozen); |
0 |
4 |
4 |
|
| 5031 |
|
| } |
| 5032 |
114 |
| SvCUR_set(frozen, len2); |
| 5033 |
114 |
| *SvEND(frozen) = '\0'; |
| 5034 |
114 |
| (void) SvPOK_only(frozen); /* Validates string pointer */ |
| 5035 |
114 |
▶ | if (cxt->s_tainted) /* Is input source tainted? */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->s_tainted) /* Is input source tainted? */ |
5 |
109 |
114 |
|
| 5036 |
5 |
▶ | SvTAINT(frozen); |
Branch: 2 branches
| Branch | True | False | Total |
| SvTAINT(frozen); |
0 |
5 |
5 |
| SvTAINT(frozen); |
0 |
0 |
0 |
|
| 5037 |
|
| |
| 5038 |
|
| TRACEME(("frozen string: %d bytes", (int)len2)); |
| 5039 |
|
| |
| 5040 |
|
| /* |
| 5041 |
|
| * Decode object-ID list length, if present. |
| 5042 |
|
| */ |
| 5043 |
|
| |
| 5044 |
114 |
▶ | if (flags & SHF_HAS_LIST) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_HAS_LIST) { |
86 |
28 |
114 |
|
| 5045 |
86 |
▶ | if (flags & SHF_LARGE_LISTLEN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHF_LARGE_LISTLEN) { |
0 |
86 |
86 |
|
| 5046 |
0 |
▶ | RLEN(len3); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len3); |
0 |
0 |
0 |
| RLEN(len3); |
0 |
0 |
0 |
| RLEN(len3); |
0 |
0 |
0 |
| RLEN(len3); |
0 |
0 |
0 |
| RLEN(len3); |
0 |
0 |
0 |
|
| 5047 |
0 |
▶ | if (len3 < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len3 < 0) { |
0 |
0 |
0 |
|
| 5048 |
|
| #ifdef HAS_U64 |
| 5049 |
0 |
| ++has_large_oids; |
| 5050 |
0 |
| len3 = -len3; |
| 5051 |
|
| #else |
| 5052 |
|
| CROAK(("Large object ids in hook data not supported on 32-bit platforms")); |
| 5053 |
|
| #endif |
| 5054 |
|
| |
| 5055 |
|
| } |
| 5056 |
|
| } |
| 5057 |
|
| else |
| 5058 |
86 |
▶ | GETMARK(len3); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(len3); |
82 |
4 |
86 |
| GETMARK(len3); |
82 |
0 |
82 |
| GETMARK(len3); |
0 |
4 |
4 |
|
| 5059 |
86 |
▶ | if (len3 == I32_MAX) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len3 == I32_MAX) |
0 |
86 |
86 |
|
| 5060 |
|
| /* If len3 is exactly I32_MAX it will upset av_extend below */ |
| 5061 |
0 |
| CROAK(("Invalid count of hook data items")); |
| 5062 |
86 |
▶ | else if (len3) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (len3) { |
86 |
0 |
86 |
|
| 5063 |
86 |
| av = newAV(); |
| 5064 |
86 |
| av_extend(av, len3 + 1); /* Leave room for [0] */ |
| 5065 |
86 |
| AvFILLp(av) = len3; /* About to be filled anyway */ |
| 5066 |
|
| } |
| 5067 |
|
| } |
| 5068 |
|
| |
| 5069 |
|
| TRACEME(("has %d object IDs to link", (int)len3)); |
| 5070 |
|
| |
| 5071 |
|
| /* |
| 5072 |
|
| * Read object-ID list into array. |
| 5073 |
|
| * Because we pre-extended it, we can cheat and fill it manually. |
| 5074 |
|
| * |
| 5075 |
|
| * We read object tags and we can convert them into SV* on the fly |
| 5076 |
|
| * because we know all the references listed in there (as tags) |
| 5077 |
|
| * have been already serialized, hence we have a valid correspondence |
| 5078 |
|
| * between each of those tags and the recreated SV. |
| 5079 |
|
| */ |
| 5080 |
|
| |
| 5081 |
114 |
▶ | if (av) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av) { |
86 |
28 |
114 |
|
| 5082 |
86 |
| SV **ary = AvARRAY(av); |
| 5083 |
|
| int i; |
| 5084 |
190 |
▶ | for (i = 1; i <= len3; i++) { /* We leave [0] alone */ |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i <= len3; i++) { /* We leave [0] alone */ |
104 |
86 |
190 |
|
| 5085 |
|
| ntag_t tag; |
| 5086 |
|
| SV **svh; |
| 5087 |
|
| SV *xsv; |
| 5088 |
|
| |
| 5089 |
|
| #ifdef HAS_U64 |
| 5090 |
104 |
▶ | if (has_large_oids) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (has_large_oids) { |
0 |
104 |
104 |
|
| 5091 |
0 |
▶ | READ_U64(tag); |
Branch: 7 branches
| Branch | True | False | Total |
| READ_U64(tag); |
0 |
0 |
0 |
| READ_U64(tag); |
0 |
0 |
0 |
| READ_U64(tag); |
0 |
0 |
0 |
| READ_U64(tag); |
0 |
0 |
0 |
| READ_U64(tag); |
0 |
0 |
0 |
| READ_U64(tag); |
0 |
0 |
0 |
| READ_U64(tag); |
0 |
0 |
0 |
|
| 5092 |
|
| } |
| 5093 |
|
| else { |
| 5094 |
|
| U32 tmp; |
| 5095 |
104 |
▶ | READ_I32(tmp); |
Branch: 4 branches
| Branch | True | False | Total |
| READ_I32(tmp); |
100 |
4 |
104 |
| READ_I32(tmp); |
100 |
0 |
100 |
| READ_I32(tmp); |
21 |
79 |
100 |
| READ_I32(tmp); |
0 |
4 |
4 |
|
| 5096 |
104 |
| tag = ntohl(tmp); |
| 5097 |
|
| } |
| 5098 |
|
| #else |
| 5099 |
|
| READ_I32(tag); |
| 5100 |
|
| tag = ntohl(tag); |
| 5101 |
|
| #endif |
| 5102 |
|
| |
| 5103 |
104 |
| svh = av_fetch(cxt->aseen, tag, FALSE); |
| 5104 |
104 |
▶ | if (!svh) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!svh) { |
0 |
104 |
104 |
|
| 5105 |
0 |
▶ | if (tag == cxt->where_is_undef) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag == cxt->where_is_undef) { |
0 |
0 |
0 |
|
| 5106 |
|
| /* av_fetch uses PL_sv_undef internally, hence this |
| 5107 |
|
| somewhat gruesome hack. */ |
| 5108 |
0 |
| xsv = &PL_sv_undef; |
| 5109 |
0 |
| svh = &xsv; |
| 5110 |
|
| } else { |
| 5111 |
0 |
| CROAK(("Object #%" IVdf |
| 5112 |
|
| " should have been retrieved already", |
| 5113 |
|
| (IV) tag)); |
| 5114 |
|
| } |
| 5115 |
|
| } |
| 5116 |
104 |
| xsv = *svh; |
| 5117 |
104 |
| ary[i] = SvREFCNT_inc(xsv); |
| 5118 |
|
| } |
| 5119 |
|
| } |
| 5120 |
|
| |
| 5121 |
|
| /* |
| 5122 |
|
| * Look up the STORABLE_attach hook |
| 5123 |
|
| * If blessing is disabled, just return what we've got. |
| 5124 |
|
| */ |
| 5125 |
114 |
▶ | if (!(cxt->flags & FLAG_BLESS_OK)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(cxt->flags & FLAG_BLESS_OK)) { |
0 |
114 |
114 |
|
| 5126 |
|
| TRACEME(("skipping bless because flags is %d", cxt->flags)); |
| 5127 |
0 |
| return sv; |
| 5128 |
|
| } |
| 5129 |
|
| |
| 5130 |
|
| /* |
| 5131 |
|
| * Bless the object and look up the STORABLE_thaw hook. |
| 5132 |
|
| */ |
| 5133 |
114 |
| stash = gv_stashpv(classname, GV_ADD); |
| 5134 |
|
| |
| 5135 |
|
| /* Handle attach case; again can't use pkg_can because it only |
| 5136 |
|
| * caches one method */ |
| 5137 |
114 |
| attach = gv_fetchmethod_autoload(stash, "STORABLE_attach", FALSE); |
| 5138 |
114 |
▶ | if (attach && isGV(attach)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (attach && isGV(attach)) { |
18 |
96 |
114 |
| if (attach && isGV(attach)) { |
18 |
0 |
18 |
|
| 5139 |
|
| SV* attached; |
| 5140 |
18 |
| SV* attach_hook = newRV_inc((SV*) GvCV(attach)); |
| 5141 |
|
| |
| 5142 |
18 |
▶ | if (av) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av) |
1 |
17 |
18 |
|
| 5143 |
1 |
| CROAK(("STORABLE_attach called with unexpected references")); |
| 5144 |
17 |
| av = newAV(); |
| 5145 |
17 |
| av_extend(av, 1); |
| 5146 |
17 |
| AvFILLp(av) = 0; |
| 5147 |
17 |
| AvARRAY(av)[0] = SvREFCNT_inc(frozen); |
| 5148 |
17 |
| rv = newSVpv(classname, 0); |
| 5149 |
17 |
| attached = scalar_call(aTHX_ rv, attach_hook, clone, av, G_SCALAR); |
| 5150 |
|
| /* Free memory after a call */ |
| 5151 |
17 |
| SvREFCNT_dec(rv); |
| 5152 |
17 |
| SvREFCNT_dec(frozen); |
| 5153 |
17 |
| av_undef(av); |
| 5154 |
17 |
| sv_free((SV *) av); |
| 5155 |
17 |
| SvREFCNT_dec(attach_hook); |
| 5156 |
17 |
▶ | if (attached && |
Branch: 1 branch
| Branch | True | False | Total |
| if (attached && |
17 |
0 |
17 |
|
| 5157 |
31 |
| SvROK(attached) && |
| 5158 |
14 |
| sv_derived_from(attached, classname) |
| 5159 |
|
| ) { |
| 5160 |
10 |
| UNSEE(); |
| 5161 |
|
| /* refcnt of unneeded sv is 2 at this point |
| 5162 |
|
| (one from newHV, second from SEEN call) */ |
| 5163 |
10 |
| SvREFCNT_dec(sv); |
| 5164 |
10 |
| SvREFCNT_dec(sv); |
| 5165 |
|
| /* we need to free RV but preserve value that RV point to */ |
| 5166 |
10 |
| sv = SvRV(attached); |
| 5167 |
10 |
▶ | SEEN0_NN(sv, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| SEEN0_NN(sv, 0); |
0 |
10 |
10 |
|
| 5168 |
10 |
| SvRV_set(attached, NULL); |
| 5169 |
10 |
| SvREFCNT_dec(attached); |
| 5170 |
10 |
▶ | if (!(flags & SHF_IDX_CLASSNAME) && classname != buf) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(flags & SHF_IDX_CLASSNAME) && classname != buf) |
9 |
1 |
10 |
| if (!(flags & SHF_IDX_CLASSNAME) && classname != buf) |
0 |
9 |
9 |
|
| 5171 |
0 |
| Safefree(classname); |
| 5172 |
10 |
| return sv; |
| 5173 |
|
| } |
| 5174 |
7 |
| CROAK(("STORABLE_attach did not return a %s object", classname)); |
| 5175 |
|
| } |
| 5176 |
|
| |
| 5177 |
|
| /* |
| 5178 |
|
| * Bless the object and look up the STORABLE_thaw hook. |
| 5179 |
|
| */ |
| 5180 |
|
| |
| 5181 |
96 |
▶ | BLESS(sv, stash); |
Branch: 11 branches
| Branch | True | False | Total |
| BLESS(sv, stash); |
96 |
0 |
96 |
| BLESS(sv, stash); |
0 |
96 |
96 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
|
| 5182 |
|
| |
| 5183 |
96 |
| hook = pkg_can(aTHX_ cxt->hook, stash, "STORABLE_thaw"); |
| 5184 |
96 |
▶ | if (!hook) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hook) { |
2 |
94 |
96 |
|
| 5185 |
|
| /* |
| 5186 |
|
| * Hook not found. Maybe they did not require the module where this |
| 5187 |
|
| * hook is defined yet? |
| 5188 |
|
| * |
| 5189 |
|
| * If the load below succeeds, we'll be able to find the hook. |
| 5190 |
|
| * Still, it only works reliably when each class is defined in a |
| 5191 |
|
| * file of its own. |
| 5192 |
|
| */ |
| 5193 |
|
| |
| 5194 |
|
| TRACEME(("No STORABLE_thaw defined for objects of class %s", classname)); |
| 5195 |
|
| TRACEME(("Going to load module '%s'", classname)); |
| 5196 |
2 |
| load_module(PERL_LOADMOD_NOIMPORT, newSVpv(classname, 0), Nullsv); |
| 5197 |
|
| |
| 5198 |
|
| /* |
| 5199 |
|
| * We cache results of pkg_can, so we need to uncache before attempting |
| 5200 |
|
| * the lookup again. |
| 5201 |
|
| */ |
| 5202 |
|
| |
| 5203 |
2 |
| pkg_uncache(aTHX_ cxt->hook, SvSTASH(sv), "STORABLE_thaw"); |
| 5204 |
2 |
| hook = pkg_can(aTHX_ cxt->hook, SvSTASH(sv), "STORABLE_thaw"); |
| 5205 |
|
| |
| 5206 |
2 |
▶ | if (!hook) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hook) |
0 |
2 |
2 |
|
| 5207 |
0 |
| CROAK(("No STORABLE_thaw defined for objects of class %s " |
| 5208 |
|
| "(even after a \"require %s;\")", classname, classname)); |
| 5209 |
|
| } |
| 5210 |
|
| |
| 5211 |
|
| /* |
| 5212 |
|
| * If we don't have an 'av' yet, prepare one. |
| 5213 |
|
| * Then insert the frozen string as item [0]. |
| 5214 |
|
| */ |
| 5215 |
|
| |
| 5216 |
96 |
▶ | if (!av) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!av) { |
11 |
85 |
96 |
|
| 5217 |
11 |
| av = newAV(); |
| 5218 |
11 |
| av_extend(av, 1); |
| 5219 |
11 |
| AvFILLp(av) = 0; |
| 5220 |
|
| } |
| 5221 |
96 |
| AvARRAY(av)[0] = SvREFCNT_inc(frozen); |
| 5222 |
|
| |
| 5223 |
|
| /* |
| 5224 |
|
| * Call the hook as: |
| 5225 |
|
| * |
| 5226 |
|
| * $object->STORABLE_thaw($cloning, $frozen, @refs); |
| 5227 |
|
| * |
| 5228 |
|
| * where $object is our blessed (empty) object, $cloning is a boolean |
| 5229 |
|
| * telling whether we're running a deep clone, $frozen is the frozen |
| 5230 |
|
| * string the user gave us in his serializing hook, and @refs, which may |
| 5231 |
|
| * be empty, is the list of extra references he returned along for us |
| 5232 |
|
| * to serialize. |
| 5233 |
|
| * |
| 5234 |
|
| * In effect, the hook is an alternate creation routine for the class, |
| 5235 |
|
| * the object itself being already created by the runtime. |
| 5236 |
|
| */ |
| 5237 |
|
| |
| 5238 |
|
| TRACEME(("calling STORABLE_thaw on %s at 0x%" UVxf " (%" IVdf " args)", |
| 5239 |
|
| classname, PTR2UV(sv), (IV) AvFILLp(av) + 1)); |
| 5240 |
|
| |
| 5241 |
96 |
| rv = newRV_inc(sv); |
| 5242 |
96 |
| (void) scalar_call(aTHX_ rv, hook, clone, av, G_SCALAR|G_DISCARD); |
| 5243 |
90 |
| SvREFCNT_dec(rv); |
| 5244 |
|
| |
| 5245 |
|
| /* |
| 5246 |
|
| * Final cleanup. |
| 5247 |
|
| */ |
| 5248 |
|
| |
| 5249 |
90 |
| SvREFCNT_dec(frozen); |
| 5250 |
90 |
| av_undef(av); |
| 5251 |
90 |
| sv_free((SV *) av); |
| 5252 |
90 |
▶ | if (!(flags & SHF_IDX_CLASSNAME) && classname != buf) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(flags & SHF_IDX_CLASSNAME) && classname != buf) |
71 |
19 |
90 |
| if (!(flags & SHF_IDX_CLASSNAME) && classname != buf) |
1 |
70 |
71 |
|
| 5253 |
1 |
| Safefree(classname); |
| 5254 |
|
| |
| 5255 |
|
| /* |
| 5256 |
|
| * If we had an <extra> type, then the object was not as simple, and |
| 5257 |
|
| * we need to restore extra magic now. |
| 5258 |
|
| */ |
| 5259 |
|
| |
| 5260 |
90 |
▶ | if (!extra_type) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!extra_type) |
89 |
1 |
90 |
|
| 5261 |
89 |
| return sv; |
| 5262 |
|
| |
| 5263 |
|
| TRACEME(("retrieving magic object for 0x%" UVxf "...", PTR2UV(sv))); |
| 5264 |
|
| |
| 5265 |
1 |
| rv = retrieve(aTHX_ cxt, 0); /* Retrieve <magic object> */ |
| 5266 |
|
| |
| 5267 |
|
| TRACEME(("restoring the magic object 0x%" UVxf " part of 0x%" UVxf, |
| 5268 |
|
| PTR2UV(rv), PTR2UV(sv))); |
| 5269 |
|
| |
| 5270 |
1 |
| switch (extra_type) { |
| 5271 |
0 |
| case SHT_TSCALAR: |
| 5272 |
0 |
| sv_upgrade(sv, SVt_PVMG); |
| 5273 |
0 |
| break; |
| 5274 |
0 |
| case SHT_TARRAY: |
| 5275 |
0 |
| sv_upgrade(sv, SVt_PVAV); |
| 5276 |
0 |
| AvREAL_off((AV *)sv); |
| 5277 |
0 |
| break; |
| 5278 |
1 |
| case SHT_THASH: |
| 5279 |
1 |
| sv_upgrade(sv, SVt_PVHV); |
| 5280 |
1 |
| break; |
| 5281 |
0 |
| default: |
| 5282 |
0 |
| CROAK(("Forgot to deal with extra type %d", extra_type)); |
| 5283 |
|
| break; |
| 5284 |
|
| } |
| 5285 |
|
| |
| 5286 |
|
| /* |
| 5287 |
|
| * Adding the magic only now, well after the STORABLE_thaw hook was called |
| 5288 |
|
| * means the hook cannot know it deals with an object whose variable is |
| 5289 |
|
| * tied. But this is happening when retrieving $o in the following case: |
| 5290 |
|
| * |
| 5291 |
|
| * my %h; |
| 5292 |
|
| * tie %h, 'FOO'; |
| 5293 |
|
| * my $o = bless \%h, 'BAR'; |
| 5294 |
|
| * |
| 5295 |
|
| * The 'BAR' class is NOT the one where %h is tied into. Therefore, as |
| 5296 |
|
| * far as the 'BAR' class is concerned, the fact that %h is not a REAL |
| 5297 |
|
| * hash but a tied one should not matter at all, and remain transparent. |
| 5298 |
|
| * This means the magic must be restored by Storable AFTER the hook is |
| 5299 |
|
| * called. |
| 5300 |
|
| * |
| 5301 |
|
| * That looks very reasonable to me, but then I've come up with this |
| 5302 |
|
| * after a bug report from David Nesting, who was trying to store such |
| 5303 |
|
| * an object and caused Storable to fail. And unfortunately, it was |
| 5304 |
|
| * also the easiest way to retrofit support for blessed ref to tied objects |
| 5305 |
|
| * into the existing design. -- RAM, 17/02/2001 |
| 5306 |
|
| */ |
| 5307 |
|
| |
| 5308 |
1 |
| sv_magic(sv, rv, mtype, (char *)NULL, 0); |
| 5309 |
1 |
| SvREFCNT_dec(rv); /* Undo refcnt inc from sv_magic() */ |
| 5310 |
|
| |
| 5311 |
1 |
| return sv; |
| 5312 |
|
| } |
| 5313 |
|
| |
| 5314 |
116 |
| static SV *retrieve_hook(pTHX_ stcxt_t *cxt, const char *cname) { |
| 5315 |
116 |
| return retrieve_hook_common(aTHX_ cxt, cname, FALSE); |
| 5316 |
|
| } |
| 5317 |
|
| |
| 5318 |
|
| /* |
| 5319 |
|
| * retrieve_ref |
| 5320 |
|
| * |
| 5321 |
|
| * Retrieve reference to some other scalar. |
| 5322 |
|
| * Layout is SX_REF <object>, with SX_REF already read. |
| 5323 |
|
| */ |
| 5324 |
58570 |
| static SV *retrieve_ref(pTHX_ stcxt_t *cxt, const char *cname) |
| 5325 |
|
| { |
| 5326 |
|
| SV *rv; |
| 5327 |
|
| SV *sv; |
| 5328 |
|
| HV *stash; |
| 5329 |
|
| |
| 5330 |
|
| TRACEME(("retrieve_ref (#%d)", (int)cxt->tagnum)); |
| 5331 |
|
| |
| 5332 |
|
| /* |
| 5333 |
|
| * We need to create the SV that holds the reference to the yet-to-retrieve |
| 5334 |
|
| * object now, so that we may record the address in the seen table. |
| 5335 |
|
| * Otherwise, if the object to retrieve references us, we won't be able |
| 5336 |
|
| * to resolve the SX_OBJECT we'll see at that point! Hence we cannot |
| 5337 |
|
| * do the retrieve first and use rv = newRV(sv) since it will be too late |
| 5338 |
|
| * for SEEN() recording. |
| 5339 |
|
| */ |
| 5340 |
|
| |
| 5341 |
58570 |
| rv = NEWSV(10002, 0); |
| 5342 |
58570 |
▶ | if (cname) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cname) |
2 |
58568 |
58570 |
|
| 5343 |
2 |
| stash = gv_stashpv(cname, GV_ADD); |
| 5344 |
|
| else |
| 5345 |
58568 |
| stash = 0; |
| 5346 |
58570 |
▶ | SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
58570 |
58570 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
2 |
58568 |
58570 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
2 |
0 |
2 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
2 |
2 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
|
| 5347 |
58570 |
| sv = retrieve(aTHX_ cxt, 0);/* Retrieve <object> */ |
| 5348 |
58568 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
58568 |
58568 |
|
| 5349 |
0 |
| return (SV *) 0; /* Failed */ |
| 5350 |
|
| |
| 5351 |
|
| /* |
| 5352 |
|
| * WARNING: breaks RV encapsulation. |
| 5353 |
|
| * |
| 5354 |
|
| * Now for the tricky part. We have to upgrade our existing SV, so that |
| 5355 |
|
| * it is now an RV on sv... Again, we cheat by duplicating the code |
| 5356 |
|
| * held in newSVrv(), since we already got our SV from retrieve(). |
| 5357 |
|
| * |
| 5358 |
|
| * We don't say: |
| 5359 |
|
| * |
| 5360 |
|
| * SvRV(rv) = SvREFCNT_inc(sv); |
| 5361 |
|
| * |
| 5362 |
|
| * here because the reference count we got from retrieve() above is |
| 5363 |
|
| * already correct: if the object was retrieved from the file, then |
| 5364 |
|
| * its reference count is one. Otherwise, if it was retrieved via |
| 5365 |
|
| * an SX_OBJECT indication, a ref count increment was done. |
| 5366 |
|
| */ |
| 5367 |
|
| |
| 5368 |
58568 |
▶ | if (cname) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cname) { |
58566 |
2 |
58568 |
|
| 5369 |
|
| /* No need to do anything, as rv will already be PVMG. */ |
| 5370 |
|
| assert (SvTYPE(rv) == SVt_RV || SvTYPE(rv) >= SVt_PV); |
| 5371 |
|
| } else { |
| 5372 |
58566 |
| sv_upgrade(rv, SVt_RV); |
| 5373 |
|
| } |
| 5374 |
|
| |
| 5375 |
58568 |
| SvRV_set(rv, sv); /* $rv = \$sv */ |
| 5376 |
58568 |
| SvROK_on(rv); |
| 5377 |
|
| /*if (cxt->entry && ++cxt->ref_cnt > MAX_REF_CNT) { |
| 5378 |
|
| CROAK(("Max. recursion depth with nested refs exceeded")); |
| 5379 |
|
| }*/ |
| 5380 |
|
| |
| 5381 |
|
| TRACEME(("ok (retrieve_ref at 0x%" UVxf ")", PTR2UV(rv))); |
| 5382 |
|
| |
| 5383 |
58568 |
| return rv; |
| 5384 |
|
| } |
| 5385 |
|
| |
| 5386 |
|
| /* |
| 5387 |
|
| * retrieve_weakref |
| 5388 |
|
| * |
| 5389 |
|
| * Retrieve weak reference to some other scalar. |
| 5390 |
|
| * Layout is SX_WEAKREF <object>, with SX_WEAKREF already read. |
| 5391 |
|
| */ |
| 5392 |
13 |
| static SV *retrieve_weakref(pTHX_ stcxt_t *cxt, const char *cname) |
| 5393 |
|
| { |
| 5394 |
|
| SV *sv; |
| 5395 |
|
| |
| 5396 |
|
| TRACEME(("retrieve_weakref (#%d)", (int)cxt->tagnum)); |
| 5397 |
|
| |
| 5398 |
13 |
| sv = retrieve_ref(aTHX_ cxt, cname); |
| 5399 |
13 |
▶ | if (sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv) { |
13 |
0 |
13 |
|
| 5400 |
|
| #ifdef SvWEAKREF |
| 5401 |
13 |
| sv_rvweaken(sv); |
| 5402 |
|
| #else |
| 5403 |
|
| WEAKREF_CROAK(); |
| 5404 |
|
| #endif |
| 5405 |
|
| } |
| 5406 |
13 |
| return sv; |
| 5407 |
|
| } |
| 5408 |
|
| |
| 5409 |
|
| /* |
| 5410 |
|
| * retrieve_overloaded |
| 5411 |
|
| * |
| 5412 |
|
| * Retrieve reference to some other scalar with overloading. |
| 5413 |
|
| * Layout is SX_OVERLOAD <object>, with SX_OVERLOAD already read. |
| 5414 |
|
| */ |
| 5415 |
34 |
| static SV *retrieve_overloaded(pTHX_ stcxt_t *cxt, const char *cname) |
| 5416 |
|
| { |
| 5417 |
|
| SV *rv; |
| 5418 |
|
| SV *sv; |
| 5419 |
|
| HV *stash; |
| 5420 |
|
| |
| 5421 |
|
| TRACEME(("retrieve_overloaded (#%d)", (int)cxt->tagnum)); |
| 5422 |
|
| |
| 5423 |
|
| /* |
| 5424 |
|
| * Same code as retrieve_ref(), duplicated to avoid extra call. |
| 5425 |
|
| */ |
| 5426 |
|
| |
| 5427 |
34 |
| rv = NEWSV(10002, 0); |
| 5428 |
34 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
1 |
33 |
34 |
|
| 5429 |
34 |
▶ | SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
34 |
34 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
1 |
33 |
34 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
1 |
0 |
1 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
1 |
1 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(rv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
|
| 5430 |
34 |
| cxt->in_retrieve_overloaded = 1; /* so sv_bless doesn't call S_reset_amagic */ |
| 5431 |
34 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve <object> */ |
| 5432 |
34 |
| cxt->in_retrieve_overloaded = 0; |
| 5433 |
34 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
34 |
34 |
|
| 5434 |
0 |
| return (SV *) 0; /* Failed */ |
| 5435 |
|
| |
| 5436 |
|
| /* |
| 5437 |
|
| * WARNING: breaks RV encapsulation. |
| 5438 |
|
| */ |
| 5439 |
|
| |
| 5440 |
34 |
▶ | SvUPGRADE(rv, SVt_RV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(rv, SVt_RV); |
33 |
1 |
34 |
|
| 5441 |
34 |
| SvRV_set(rv, sv); /* $rv = \$sv */ |
| 5442 |
34 |
| SvROK_on(rv); |
| 5443 |
|
| |
| 5444 |
|
| /* |
| 5445 |
|
| * Restore overloading magic. |
| 5446 |
|
| */ |
| 5447 |
|
| |
| 5448 |
34 |
▶ | stash = SvTYPE(sv) ? (HV *) SvSTASH (sv) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = SvTYPE(sv) ? (HV *) SvSTASH (sv) : 0; |
34 |
0 |
34 |
|
| 5449 |
34 |
▶ | if (!stash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!stash) { |
0 |
34 |
34 |
|
| 5450 |
0 |
| CROAK(("Cannot restore overloading on %s(0x%" UVxf |
| 5451 |
|
| ") (package <unknown>)", |
| 5452 |
|
| sv_reftype(sv, FALSE), |
| 5453 |
|
| PTR2UV(sv))); |
| 5454 |
|
| } |
| 5455 |
34 |
▶ | if (!Gv_AMG(stash)) { |
Branch: 9 branches
| Branch | True | False | Total |
| if (!Gv_AMG(stash)) { |
34 |
0 |
34 |
| if (!Gv_AMG(stash)) { |
34 |
0 |
34 |
| if (!Gv_AMG(stash)) { |
0 |
34 |
34 |
| if (!Gv_AMG(stash)) { |
0 |
0 |
0 |
| if (!Gv_AMG(stash)) { |
34 |
0 |
34 |
| if (!Gv_AMG(stash)) { |
0 |
34 |
34 |
| if (!Gv_AMG(stash)) { |
34 |
0 |
34 |
| if (!Gv_AMG(stash)) { |
1 |
33 |
34 |
| if (!Gv_AMG(stash)) { |
1 |
33 |
34 |
|
| 5456 |
1 |
▶ | const char *package = HvNAME_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| const char *package = HvNAME_get(stash); |
1 |
0 |
1 |
| const char *package = HvNAME_get(stash); |
1 |
0 |
1 |
| const char *package = HvNAME_get(stash); |
0 |
1 |
1 |
| const char *package = HvNAME_get(stash); |
0 |
0 |
0 |
| const char *package = HvNAME_get(stash); |
1 |
0 |
1 |
| const char *package = HvNAME_get(stash); |
0 |
1 |
1 |
|
| 5457 |
|
| TRACEME(("No overloading defined for package %s", package)); |
| 5458 |
|
| TRACEME(("Going to load module '%s'", package)); |
| 5459 |
1 |
| load_module(PERL_LOADMOD_NOIMPORT, newSVpv(package, 0), Nullsv); |
| 5460 |
1 |
▶ | if (!Gv_AMG(stash)) { |
Branch: 9 branches
| Branch | True | False | Total |
| if (!Gv_AMG(stash)) { |
1 |
0 |
1 |
| if (!Gv_AMG(stash)) { |
1 |
0 |
1 |
| if (!Gv_AMG(stash)) { |
0 |
1 |
1 |
| if (!Gv_AMG(stash)) { |
0 |
0 |
0 |
| if (!Gv_AMG(stash)) { |
1 |
0 |
1 |
| if (!Gv_AMG(stash)) { |
0 |
1 |
1 |
| if (!Gv_AMG(stash)) { |
1 |
0 |
1 |
| if (!Gv_AMG(stash)) { |
0 |
1 |
1 |
| if (!Gv_AMG(stash)) { |
0 |
1 |
1 |
|
| 5461 |
0 |
| CROAK(("Cannot restore overloading on %s(0x%" UVxf |
| 5462 |
|
| ") (package %s) (even after a \"require %s;\")", |
| 5463 |
|
| sv_reftype(sv, FALSE), |
| 5464 |
|
| PTR2UV(sv), |
| 5465 |
|
| package, package)); |
| 5466 |
|
| } |
| 5467 |
|
| } |
| 5468 |
|
| |
| 5469 |
34 |
| SvAMAGIC_on(rv); |
| 5470 |
|
| |
| 5471 |
|
| TRACEME(("ok (retrieve_overloaded at 0x%" UVxf ")", PTR2UV(rv))); |
| 5472 |
|
| |
| 5473 |
34 |
| return rv; |
| 5474 |
|
| } |
| 5475 |
|
| |
| 5476 |
|
| /* |
| 5477 |
|
| * retrieve_weakoverloaded |
| 5478 |
|
| * |
| 5479 |
|
| * Retrieve weak overloaded reference to some other scalar. |
| 5480 |
|
| * Layout is SX_WEAKOVERLOADED <object>, with SX_WEAKOVERLOADED already read. |
| 5481 |
|
| */ |
| 5482 |
4 |
| static SV *retrieve_weakoverloaded(pTHX_ stcxt_t *cxt, const char *cname) |
| 5483 |
|
| { |
| 5484 |
|
| SV *sv; |
| 5485 |
|
| |
| 5486 |
|
| TRACEME(("retrieve_weakoverloaded (#%d)", (int)cxt->tagnum)); |
| 5487 |
|
| |
| 5488 |
4 |
| sv = retrieve_overloaded(aTHX_ cxt, cname); |
| 5489 |
4 |
▶ | if (sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv) { |
4 |
0 |
4 |
|
| 5490 |
|
| #ifdef SvWEAKREF |
| 5491 |
4 |
| sv_rvweaken(sv); |
| 5492 |
|
| #else |
| 5493 |
|
| WEAKREF_CROAK(); |
| 5494 |
|
| #endif |
| 5495 |
|
| } |
| 5496 |
4 |
| return sv; |
| 5497 |
|
| } |
| 5498 |
|
| |
| 5499 |
|
| /* |
| 5500 |
|
| * retrieve_tied_array |
| 5501 |
|
| * |
| 5502 |
|
| * Retrieve tied array |
| 5503 |
|
| * Layout is SX_TIED_ARRAY <object>, with SX_TIED_ARRAY already read. |
| 5504 |
|
| */ |
| 5505 |
4 |
| static SV *retrieve_tied_array(pTHX_ stcxt_t *cxt, const char *cname) |
| 5506 |
|
| { |
| 5507 |
|
| SV *tv; |
| 5508 |
|
| SV *sv; |
| 5509 |
|
| HV *stash; |
| 5510 |
|
| |
| 5511 |
|
| TRACEME(("retrieve_tied_array (#%d)", (int)cxt->tagnum)); |
| 5512 |
|
| |
| 5513 |
4 |
▶ | if (!(cxt->flags & FLAG_TIE_OK)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(cxt->flags & FLAG_TIE_OK)) { |
0 |
4 |
4 |
|
| 5514 |
0 |
| CROAK(("Tying is disabled.")); |
| 5515 |
|
| } |
| 5516 |
|
| |
| 5517 |
4 |
| tv = NEWSV(10002, 0); |
| 5518 |
4 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
1 |
3 |
4 |
|
| 5519 |
4 |
▶ | SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
4 |
4 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
1 |
3 |
4 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
1 |
0 |
1 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
1 |
1 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
|
| 5520 |
4 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve <object> */ |
| 5521 |
4 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
4 |
4 |
|
| 5522 |
0 |
| return (SV *) 0; /* Failed */ |
| 5523 |
|
| |
| 5524 |
4 |
| sv_upgrade(tv, SVt_PVAV); |
| 5525 |
4 |
| sv_magic(tv, sv, 'P', (char *)NULL, 0); |
| 5526 |
4 |
| SvREFCNT_dec(sv); /* Undo refcnt inc from sv_magic() */ |
| 5527 |
|
| |
| 5528 |
|
| TRACEME(("ok (retrieve_tied_array at 0x%" UVxf ")", PTR2UV(tv))); |
| 5529 |
|
| |
| 5530 |
4 |
| return tv; |
| 5531 |
|
| } |
| 5532 |
|
| |
| 5533 |
|
| /* |
| 5534 |
|
| * retrieve_tied_hash |
| 5535 |
|
| * |
| 5536 |
|
| * Retrieve tied hash |
| 5537 |
|
| * Layout is SX_TIED_HASH <object>, with SX_TIED_HASH already read. |
| 5538 |
|
| */ |
| 5539 |
6 |
| static SV *retrieve_tied_hash(pTHX_ stcxt_t *cxt, const char *cname) |
| 5540 |
|
| { |
| 5541 |
|
| SV *tv; |
| 5542 |
|
| SV *sv; |
| 5543 |
|
| HV *stash; |
| 5544 |
|
| |
| 5545 |
|
| TRACEME(("retrieve_tied_hash (#%d)", (int)cxt->tagnum)); |
| 5546 |
|
| |
| 5547 |
6 |
▶ | if (!(cxt->flags & FLAG_TIE_OK)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(cxt->flags & FLAG_TIE_OK)) { |
0 |
6 |
6 |
|
| 5548 |
0 |
| CROAK(("Tying is disabled.")); |
| 5549 |
|
| } |
| 5550 |
|
| |
| 5551 |
6 |
| tv = NEWSV(10002, 0); |
| 5552 |
6 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
1 |
5 |
6 |
|
| 5553 |
6 |
▶ | SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
6 |
6 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
1 |
5 |
6 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
1 |
0 |
1 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
1 |
1 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
|
| 5554 |
6 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve <object> */ |
| 5555 |
6 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
6 |
6 |
|
| 5556 |
0 |
| return (SV *) 0; /* Failed */ |
| 5557 |
|
| |
| 5558 |
6 |
| sv_upgrade(tv, SVt_PVHV); |
| 5559 |
6 |
| sv_magic(tv, sv, 'P', (char *)NULL, 0); |
| 5560 |
6 |
| SvREFCNT_dec(sv); /* Undo refcnt inc from sv_magic() */ |
| 5561 |
|
| |
| 5562 |
|
| TRACEME(("ok (retrieve_tied_hash at 0x%" UVxf ")", PTR2UV(tv))); |
| 5563 |
|
| |
| 5564 |
6 |
| return tv; |
| 5565 |
|
| } |
| 5566 |
|
| |
| 5567 |
|
| /* |
| 5568 |
|
| * retrieve_tied_scalar |
| 5569 |
|
| * |
| 5570 |
|
| * Retrieve tied scalar |
| 5571 |
|
| * Layout is SX_TIED_SCALAR <object>, with SX_TIED_SCALAR already read. |
| 5572 |
|
| */ |
| 5573 |
4 |
| static SV *retrieve_tied_scalar(pTHX_ stcxt_t *cxt, const char *cname) |
| 5574 |
|
| { |
| 5575 |
|
| SV *tv; |
| 5576 |
4 |
| SV *sv, *obj = NULL; |
| 5577 |
|
| HV *stash; |
| 5578 |
|
| |
| 5579 |
|
| TRACEME(("retrieve_tied_scalar (#%d)", (int)cxt->tagnum)); |
| 5580 |
|
| |
| 5581 |
4 |
▶ | if (!(cxt->flags & FLAG_TIE_OK)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(cxt->flags & FLAG_TIE_OK)) { |
0 |
4 |
4 |
|
| 5582 |
0 |
| CROAK(("Tying is disabled.")); |
| 5583 |
|
| } |
| 5584 |
|
| |
| 5585 |
4 |
| tv = NEWSV(10002, 0); |
| 5586 |
4 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
1 |
3 |
4 |
|
| 5587 |
4 |
▶ | SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
4 |
4 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
1 |
3 |
4 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
1 |
0 |
1 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
1 |
1 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if rv is null */ |
0 |
0 |
0 |
|
| 5588 |
4 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve <object> */ |
| 5589 |
4 |
▶ | if (!sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) { |
0 |
4 |
4 |
|
| 5590 |
0 |
| return (SV *) 0; /* Failed */ |
| 5591 |
|
| } |
| 5592 |
4 |
▶ | else if (SvTYPE(sv) != SVt_NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (SvTYPE(sv) != SVt_NULL) { |
3 |
1 |
4 |
|
| 5593 |
3 |
| obj = sv; |
| 5594 |
|
| } |
| 5595 |
|
| |
| 5596 |
4 |
| sv_upgrade(tv, SVt_PVMG); |
| 5597 |
4 |
| sv_magic(tv, obj, 'q', (char *)NULL, 0); |
| 5598 |
|
| |
| 5599 |
4 |
▶ | if (obj) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (obj) { |
3 |
1 |
4 |
|
| 5600 |
|
| /* Undo refcnt inc from sv_magic() */ |
| 5601 |
3 |
| SvREFCNT_dec(obj); |
| 5602 |
|
| } |
| 5603 |
|
| |
| 5604 |
|
| TRACEME(("ok (retrieve_tied_scalar at 0x%" UVxf ")", PTR2UV(tv))); |
| 5605 |
|
| |
| 5606 |
4 |
| return tv; |
| 5607 |
|
| } |
| 5608 |
|
| |
| 5609 |
|
| /* |
| 5610 |
|
| * retrieve_tied_key |
| 5611 |
|
| * |
| 5612 |
|
| * Retrieve reference to value in a tied hash. |
| 5613 |
|
| * Layout is SX_TIED_KEY <object> <key>, with SX_TIED_KEY already read. |
| 5614 |
|
| */ |
| 5615 |
1 |
| static SV *retrieve_tied_key(pTHX_ stcxt_t *cxt, const char *cname) |
| 5616 |
|
| { |
| 5617 |
|
| SV *tv; |
| 5618 |
|
| SV *sv; |
| 5619 |
|
| SV *key; |
| 5620 |
|
| HV *stash; |
| 5621 |
|
| |
| 5622 |
|
| TRACEME(("retrieve_tied_key (#%d)", (int)cxt->tagnum)); |
| 5623 |
|
| |
| 5624 |
1 |
▶ | if (!(cxt->flags & FLAG_TIE_OK)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(cxt->flags & FLAG_TIE_OK)) { |
0 |
1 |
1 |
|
| 5625 |
0 |
| CROAK(("Tying is disabled.")); |
| 5626 |
|
| } |
| 5627 |
|
| |
| 5628 |
1 |
| tv = NEWSV(10002, 0); |
| 5629 |
1 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
1 |
1 |
|
| 5630 |
1 |
▶ | SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
1 |
1 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
1 |
1 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
|
| 5631 |
1 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve <object> */ |
| 5632 |
1 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
1 |
1 |
|
| 5633 |
0 |
| return (SV *) 0; /* Failed */ |
| 5634 |
|
| |
| 5635 |
1 |
| key = retrieve(aTHX_ cxt, 0); /* Retrieve <key> */ |
| 5636 |
1 |
▶ | if (!key) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!key) |
0 |
1 |
1 |
|
| 5637 |
0 |
| return (SV *) 0; /* Failed */ |
| 5638 |
|
| |
| 5639 |
1 |
| sv_upgrade(tv, SVt_PVMG); |
| 5640 |
1 |
| sv_magic(tv, sv, 'p', (char *)key, HEf_SVKEY); |
| 5641 |
1 |
| SvREFCNT_dec(key); /* Undo refcnt inc from sv_magic() */ |
| 5642 |
1 |
| SvREFCNT_dec(sv); /* Undo refcnt inc from sv_magic() */ |
| 5643 |
|
| |
| 5644 |
1 |
| return tv; |
| 5645 |
|
| } |
| 5646 |
|
| |
| 5647 |
|
| /* |
| 5648 |
|
| * retrieve_tied_idx |
| 5649 |
|
| * |
| 5650 |
|
| * Retrieve reference to value in a tied array. |
| 5651 |
|
| * Layout is SX_TIED_IDX <object> <idx>, with SX_TIED_IDX already read. |
| 5652 |
|
| */ |
| 5653 |
3 |
| static SV *retrieve_tied_idx(pTHX_ stcxt_t *cxt, const char *cname) |
| 5654 |
|
| { |
| 5655 |
|
| SV *tv; |
| 5656 |
|
| SV *sv; |
| 5657 |
|
| HV *stash; |
| 5658 |
|
| I32 idx; |
| 5659 |
|
| |
| 5660 |
|
| TRACEME(("retrieve_tied_idx (#%d)", (int)cxt->tagnum)); |
| 5661 |
|
| |
| 5662 |
3 |
▶ | if (!(cxt->flags & FLAG_TIE_OK)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(cxt->flags & FLAG_TIE_OK)) { |
0 |
3 |
3 |
|
| 5663 |
0 |
| CROAK(("Tying is disabled.")); |
| 5664 |
|
| } |
| 5665 |
|
| |
| 5666 |
3 |
| tv = NEWSV(10002, 0); |
| 5667 |
3 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
3 |
3 |
|
| 5668 |
3 |
▶ | SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
3 |
3 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
3 |
3 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
| SEEN_NN(tv, stash, 0); /* Will return if tv is null */ |
0 |
0 |
0 |
|
| 5669 |
3 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve <object> */ |
| 5670 |
1 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
1 |
1 |
|
| 5671 |
0 |
| return (SV *) 0; /* Failed */ |
| 5672 |
|
| |
| 5673 |
1 |
▶ | RLEN(idx); /* Retrieve <idx> */ |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(idx); /* Retrieve <idx> */ |
1 |
0 |
1 |
| RLEN(idx); /* Retrieve <idx> */ |
1 |
0 |
1 |
| RLEN(idx); /* Retrieve <idx> */ |
0 |
1 |
1 |
| RLEN(idx); /* Retrieve <idx> */ |
0 |
0 |
0 |
| RLEN(idx); /* Retrieve <idx> */ |
0 |
1 |
1 |
|
| 5674 |
|
| |
| 5675 |
1 |
| sv_upgrade(tv, SVt_PVMG); |
| 5676 |
1 |
| sv_magic(tv, sv, 'p', (char *)NULL, idx); |
| 5677 |
1 |
| SvREFCNT_dec(sv); /* Undo refcnt inc from sv_magic() */ |
| 5678 |
|
| |
| 5679 |
1 |
| return tv; |
| 5680 |
|
| } |
| 5681 |
|
| |
| 5682 |
|
| /* |
| 5683 |
|
| * get_lstring |
| 5684 |
|
| * |
| 5685 |
|
| * Helper to read a string |
| 5686 |
|
| */ |
| 5687 |
3349 |
| static SV *get_lstring(pTHX_ stcxt_t *cxt, UV len, int isutf8, const char *cname) |
| 5688 |
|
| { |
| 5689 |
|
| SV *sv; |
| 5690 |
|
| HV *stash; |
| 5691 |
|
| |
| 5692 |
|
| TRACEME(("get_lstring (#%d), len = %" UVuf, (int)cxt->tagnum, len)); |
| 5693 |
|
| |
| 5694 |
|
| /* |
| 5695 |
|
| * Allocate an empty scalar of the suitable length. |
| 5696 |
|
| */ |
| 5697 |
|
| |
| 5698 |
3349 |
| sv = NEWSV(10002, len); |
| 5699 |
3349 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
12 |
3337 |
3349 |
|
| 5700 |
3349 |
▶ | SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
3349 |
3349 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
12 |
3337 |
3349 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
12 |
0 |
12 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
1 |
11 |
12 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
1 |
0 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
1 |
0 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
1 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
1 |
0 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
1 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
1 |
0 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
1 |
0 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
1 |
1 |
|
| 5701 |
|
| |
| 5702 |
3349 |
▶ | if (len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) { |
4 |
3345 |
3349 |
|
| 5703 |
4 |
| SvPVCLEAR(sv); |
| 5704 |
4 |
| return sv; |
| 5705 |
|
| } |
| 5706 |
|
| |
| 5707 |
|
| /* |
| 5708 |
|
| * WARNING: duplicates parts of sv_setpv and breaks SV data encapsulation. |
| 5709 |
|
| * |
| 5710 |
|
| * Now, for efficiency reasons, read data directly inside the SV buffer, |
| 5711 |
|
| * and perform the SV final settings directly by duplicating the final |
| 5712 |
|
| * work done by sv_setpv. Since we're going to allocate lots of scalars |
| 5713 |
|
| * this way, it's worth the hassle and risk. |
| 5714 |
|
| */ |
| 5715 |
|
| |
| 5716 |
3345 |
▶ | SAFEREAD(SvPVX(sv), len, sv); |
Branch: 3 branches
| Branch | True | False | Total |
| SAFEREAD(SvPVX(sv), len, sv); |
3240 |
105 |
3345 |
| SAFEREAD(SvPVX(sv), len, sv); |
3230 |
10 |
3240 |
| SAFEREAD(SvPVX(sv), len, sv); |
11 |
94 |
105 |
|
| 5717 |
3324 |
| SvCUR_set(sv, len); /* Record C string length */ |
| 5718 |
3324 |
| *SvEND(sv) = '\0'; /* Ensure it's null terminated anyway */ |
| 5719 |
3324 |
| (void) SvPOK_only(sv); /* Validate string pointer */ |
| 5720 |
3324 |
▶ | if (cxt->s_tainted) /* Is input source tainted? */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->s_tainted) /* Is input source tainted? */ |
94 |
3230 |
3324 |
|
| 5721 |
94 |
▶ | SvTAINT(sv); /* External data cannot be trusted */ |
Branch: 2 branches
| Branch | True | False | Total |
| SvTAINT(sv); /* External data cannot be trusted */ |
0 |
94 |
94 |
| SvTAINT(sv); /* External data cannot be trusted */ |
0 |
0 |
0 |
|
| 5722 |
|
| |
| 5723 |
|
| /* Check for CVE-215-1592 */ |
| 5724 |
3324 |
▶ | if (cname && len == 13 && strEQc(cname, "CGITempFile") |
Branch: 3 branches
| Branch | True | False | Total |
| if (cname && len == 13 && strEQc(cname, "CGITempFile") |
11 |
3313 |
3324 |
| if (cname && len == 13 && strEQc(cname, "CGITempFile") |
1 |
10 |
11 |
| if (cname && len == 13 && strEQc(cname, "CGITempFile") |
1 |
0 |
1 |
|
| 5725 |
1 |
▶ | && strEQc(SvPVX(sv), "mt-config.cgi")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && strEQc(SvPVX(sv), "mt-config.cgi")) { |
1 |
0 |
1 |
|
| 5726 |
|
| #if defined(USE_CPERL) && defined(WARN_SECURITY) |
| 5727 |
|
| Perl_warn_security(aTHX_ |
| 5728 |
|
| "Movable-Type CVE-2015-1592 Storable metasploit attack"); |
| 5729 |
|
| #else |
| 5730 |
1 |
| Perl_warn(aTHX_ |
| 5731 |
|
| "SECURITY: Movable-Type CVE-2015-1592 Storable metasploit attack"); |
| 5732 |
|
| #endif |
| 5733 |
|
| } |
| 5734 |
|
| |
| 5735 |
3324 |
▶ | if (isutf8) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isutf8) { |
28 |
3296 |
3324 |
|
| 5736 |
|
| TRACEME(("large utf8 string len %" UVuf " '%s'", len, |
| 5737 |
|
| len >= 2048 ? "<string too long>" : SvPVX(sv))); |
| 5738 |
|
| #ifdef HAS_UTF8_SCALARS |
| 5739 |
28 |
| SvUTF8_on(sv); |
| 5740 |
|
| #else |
| 5741 |
|
| if (cxt->use_bytes < 0) |
| 5742 |
|
| cxt->use_bytes |
| 5743 |
|
| = (SvTRUE(get_sv("Storable::drop_utf8", GV_ADD)) |
| 5744 |
|
| ? 1 : 0); |
| 5745 |
|
| if (cxt->use_bytes == 0) |
| 5746 |
|
| UTF8_CROAK(); |
| 5747 |
|
| #endif |
| 5748 |
|
| } else { |
| 5749 |
|
| TRACEME(("large string len %" UVuf " '%s'", len, |
| 5750 |
|
| len >= 2048 ? "<string too long>" : SvPVX(sv))); |
| 5751 |
|
| } |
| 5752 |
|
| TRACEME(("ok (get_lstring at 0x%" UVxf ")", PTR2UV(sv))); |
| 5753 |
|
| |
| 5754 |
3324 |
| return sv; |
| 5755 |
|
| } |
| 5756 |
|
| |
| 5757 |
|
| /* |
| 5758 |
|
| * retrieve_lscalar |
| 5759 |
|
| * |
| 5760 |
|
| * Retrieve defined long (string) scalar. |
| 5761 |
|
| * |
| 5762 |
|
| * Layout is SX_LSCALAR <length> <data>, with SX_LSCALAR already read. |
| 5763 |
|
| * The scalar is "long" in that <length> is larger than LG_SCALAR so it |
| 5764 |
|
| * was not stored on a single byte, but in 4 bytes. For strings longer than |
| 5765 |
|
| * 4 byte (>2GB) see retrieve_lobject. |
| 5766 |
|
| */ |
| 5767 |
4 |
| static SV *retrieve_lscalar(pTHX_ stcxt_t *cxt, const char *cname) |
| 5768 |
|
| { |
| 5769 |
|
| U32 len; |
| 5770 |
4 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
3 |
1 |
4 |
| RLEN(len); |
3 |
0 |
3 |
| RLEN(len); |
0 |
3 |
3 |
| RLEN(len); |
0 |
1 |
1 |
| RLEN(len); |
1 |
3 |
4 |
|
| 5771 |
4 |
| return get_lstring(aTHX_ cxt, len, 0, cname); |
| 5772 |
|
| } |
| 5773 |
|
| |
| 5774 |
|
| /* |
| 5775 |
|
| * retrieve_scalar |
| 5776 |
|
| * |
| 5777 |
|
| * Retrieve defined short (string) scalar. |
| 5778 |
|
| * |
| 5779 |
|
| * Layout is SX_SCALAR <length> <data>, with SX_SCALAR already read. |
| 5780 |
|
| * The scalar is "short" so <length> is single byte. If it is 0, there |
| 5781 |
|
| * is no <data> section. |
| 5782 |
|
| */ |
| 5783 |
3321 |
| static SV *retrieve_scalar(pTHX_ stcxt_t *cxt, const char *cname) |
| 5784 |
|
| { |
| 5785 |
|
| int len; |
| 5786 |
|
| /*SV *sv; |
| 5787 |
|
| HV *stash;*/ |
| 5788 |
|
| |
| 5789 |
3321 |
▶ | GETMARK(len); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(len); |
3214 |
107 |
3321 |
| GETMARK(len); |
3212 |
2 |
3214 |
| GETMARK(len); |
2 |
105 |
107 |
|
| 5790 |
|
| TRACEME(("retrieve_scalar (#%d), len = %d", (int)cxt->tagnum, len)); |
| 5791 |
3317 |
| return get_lstring(aTHX_ cxt, (UV)len, 0, cname); |
| 5792 |
|
| } |
| 5793 |
|
| |
| 5794 |
|
| /* |
| 5795 |
|
| * retrieve_utf8str |
| 5796 |
|
| * |
| 5797 |
|
| * Like retrieve_scalar(), but tag result as utf8. |
| 5798 |
|
| * If we're retrieving UTF8 data in a non-UTF8 perl, croaks. |
| 5799 |
|
| */ |
| 5800 |
20 |
| static SV *retrieve_utf8str(pTHX_ stcxt_t *cxt, const char *cname) |
| 5801 |
|
| { |
| 5802 |
|
| int len; |
| 5803 |
|
| /*SV *sv;*/ |
| 5804 |
|
| |
| 5805 |
|
| TRACEME(("retrieve_utf8str")); |
| 5806 |
20 |
▶ | GETMARK(len); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(len); |
20 |
0 |
20 |
| GETMARK(len); |
20 |
0 |
20 |
| GETMARK(len); |
0 |
0 |
0 |
|
| 5807 |
20 |
| return get_lstring(aTHX_ cxt, (UV)len, 1, cname); |
| 5808 |
|
| } |
| 5809 |
|
| |
| 5810 |
|
| /* |
| 5811 |
|
| * retrieve_lutf8str |
| 5812 |
|
| * |
| 5813 |
|
| * Like retrieve_lscalar(), but tag result as utf8. |
| 5814 |
|
| * If we're retrieving UTF8 data in a non-UTF8 perl, croaks. |
| 5815 |
|
| */ |
| 5816 |
8 |
| static SV *retrieve_lutf8str(pTHX_ stcxt_t *cxt, const char *cname) |
| 5817 |
|
| { |
| 5818 |
|
| U32 len; |
| 5819 |
|
| |
| 5820 |
|
| TRACEME(("retrieve_lutf8str")); |
| 5821 |
|
| |
| 5822 |
8 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
6 |
2 |
8 |
| RLEN(len); |
6 |
0 |
6 |
| RLEN(len); |
3 |
3 |
6 |
| RLEN(len); |
0 |
2 |
2 |
| RLEN(len); |
3 |
5 |
8 |
|
| 5823 |
8 |
| return get_lstring(aTHX_ cxt, (UV)len, 1, cname); |
| 5824 |
|
| } |
| 5825 |
|
| |
| 5826 |
|
| /* |
| 5827 |
|
| * retrieve_vstring |
| 5828 |
|
| * |
| 5829 |
|
| * Retrieve a vstring, and then retrieve the stringy scalar following it, |
| 5830 |
|
| * attaching the vstring to the scalar via magic. |
| 5831 |
|
| * If we're retrieving a vstring in a perl without vstring magic, croaks. |
| 5832 |
|
| * |
| 5833 |
|
| * The vstring layout mirrors an SX_SCALAR string: |
| 5834 |
|
| * SX_VSTRING <length> <data> with SX_VSTRING already read. |
| 5835 |
|
| */ |
| 5836 |
1 |
| static SV *retrieve_vstring(pTHX_ stcxt_t *cxt, const char *cname) |
| 5837 |
|
| { |
| 5838 |
|
| #ifdef SvVOK |
| 5839 |
|
| char s[256]; |
| 5840 |
|
| int len; |
| 5841 |
|
| SV *sv; |
| 5842 |
|
| |
| 5843 |
1 |
▶ | GETMARK(len); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(len); |
1 |
0 |
1 |
| GETMARK(len); |
1 |
0 |
1 |
| GETMARK(len); |
0 |
0 |
0 |
|
| 5844 |
|
| TRACEME(("retrieve_vstring (#%d), len = %d", (int)cxt->tagnum, len)); |
| 5845 |
|
| |
| 5846 |
1 |
▶ | READ(s, len); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(s, len); |
1 |
0 |
1 |
| READ(s, len); |
1 |
0 |
1 |
| READ(s, len); |
0 |
0 |
0 |
|
| 5847 |
1 |
| sv = retrieve(aTHX_ cxt, cname); |
| 5848 |
1 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
1 |
1 |
|
| 5849 |
0 |
| return (SV *) 0; /* Failed */ |
| 5850 |
1 |
| sv_magic(sv,NULL,PERL_MAGIC_vstring,s,len); |
| 5851 |
|
| /* 5.10.0 and earlier seem to need this */ |
| 5852 |
1 |
| SvRMAGICAL_on(sv); |
| 5853 |
|
| |
| 5854 |
|
| TRACEME(("ok (retrieve_vstring at 0x%" UVxf ")", PTR2UV(sv))); |
| 5855 |
1 |
| return sv; |
| 5856 |
|
| #else |
| 5857 |
|
| VSTRING_CROAK(); |
| 5858 |
|
| return Nullsv; |
| 5859 |
|
| #endif |
| 5860 |
|
| } |
| 5861 |
|
| |
| 5862 |
|
| /* |
| 5863 |
|
| * retrieve_lvstring |
| 5864 |
|
| * |
| 5865 |
|
| * Like retrieve_vstring, but for longer vstrings. |
| 5866 |
|
| */ |
| 5867 |
1 |
| static SV *retrieve_lvstring(pTHX_ stcxt_t *cxt, const char *cname) |
| 5868 |
|
| { |
| 5869 |
|
| #ifdef SvVOK |
| 5870 |
|
| char *s; |
| 5871 |
|
| U32 len; |
| 5872 |
|
| SV *sv; |
| 5873 |
|
| |
| 5874 |
1 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
1 |
0 |
1 |
| RLEN(len); |
1 |
0 |
1 |
| RLEN(len); |
0 |
1 |
1 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
1 |
1 |
|
| 5875 |
|
| TRACEME(("retrieve_lvstring (#%d), len = %" UVuf, |
| 5876 |
|
| (int)cxt->tagnum, (UV)len)); |
| 5877 |
|
| |
| 5878 |
|
| /* Since we'll no longer produce such large vstrings, reject them |
| 5879 |
|
| here too. |
| 5880 |
|
| */ |
| 5881 |
1 |
▶ | if (len >= I32_MAX) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len >= I32_MAX) { |
0 |
1 |
1 |
|
| 5882 |
0 |
| CROAK(("vstring too large to fetch")); |
| 5883 |
|
| } |
| 5884 |
|
| |
| 5885 |
1 |
| New(10003, s, len+1, char); |
| 5886 |
1 |
▶ | SAFEPVREAD(s, (I32)len, s); |
Branch: 3 branches
| Branch | True | False | Total |
| SAFEPVREAD(s, (I32)len, s); |
1 |
0 |
1 |
| SAFEPVREAD(s, (I32)len, s); |
1 |
0 |
1 |
| SAFEPVREAD(s, (I32)len, s); |
0 |
0 |
0 |
|
| 5887 |
|
| |
| 5888 |
1 |
| sv = retrieve(aTHX_ cxt, cname); |
| 5889 |
1 |
▶ | if (!sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) { |
0 |
1 |
1 |
|
| 5890 |
0 |
| Safefree(s); |
| 5891 |
0 |
| return (SV *) 0; /* Failed */ |
| 5892 |
|
| } |
| 5893 |
1 |
| sv_magic(sv,NULL,PERL_MAGIC_vstring,s,len); |
| 5894 |
|
| /* 5.10.0 and earlier seem to need this */ |
| 5895 |
1 |
| SvRMAGICAL_on(sv); |
| 5896 |
|
| |
| 5897 |
1 |
| Safefree(s); |
| 5898 |
|
| |
| 5899 |
|
| TRACEME(("ok (retrieve_lvstring at 0x%" UVxf ")", PTR2UV(sv))); |
| 5900 |
1 |
| return sv; |
| 5901 |
|
| #else |
| 5902 |
|
| VSTRING_CROAK(); |
| 5903 |
|
| return Nullsv; |
| 5904 |
|
| #endif |
| 5905 |
|
| } |
| 5906 |
|
| |
| 5907 |
|
| /* |
| 5908 |
|
| * retrieve_integer |
| 5909 |
|
| * |
| 5910 |
|
| * Retrieve defined integer. |
| 5911 |
|
| * Layout is SX_INTEGER <data>, whith SX_INTEGER already read. |
| 5912 |
|
| */ |
| 5913 |
93 |
| static SV *retrieve_integer(pTHX_ stcxt_t *cxt, const char *cname) |
| 5914 |
|
| { |
| 5915 |
|
| SV *sv; |
| 5916 |
|
| HV *stash; |
| 5917 |
|
| IV iv; |
| 5918 |
|
| |
| 5919 |
|
| TRACEME(("retrieve_integer (#%d)", (int)cxt->tagnum)); |
| 5920 |
|
| |
| 5921 |
93 |
▶ | READ(&iv, sizeof(iv)); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(&iv, sizeof(iv)); |
58 |
35 |
93 |
| READ(&iv, sizeof(iv)); |
58 |
0 |
58 |
| READ(&iv, sizeof(iv)); |
0 |
35 |
35 |
|
| 5922 |
93 |
| sv = newSViv(iv); |
| 5923 |
93 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
93 |
93 |
|
| 5924 |
93 |
▶ | SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
93 |
93 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
93 |
93 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
|
| 5925 |
|
| |
| 5926 |
|
| TRACEME(("integer %" IVdf, iv)); |
| 5927 |
|
| TRACEME(("ok (retrieve_integer at 0x%" UVxf ")", PTR2UV(sv))); |
| 5928 |
|
| |
| 5929 |
93 |
| return sv; |
| 5930 |
|
| } |
| 5931 |
|
| |
| 5932 |
|
| /* |
| 5933 |
|
| * retrieve_boolean_true |
| 5934 |
|
| * |
| 5935 |
|
| * Retrieve boolean true copy. |
| 5936 |
|
| */ |
| 5937 |
1 |
| static SV *retrieve_boolean_true(pTHX_ stcxt_t *cxt, const char *cname) |
| 5938 |
|
| { |
| 5939 |
|
| SV *sv; |
| 5940 |
|
| HV *stash; |
| 5941 |
|
| |
| 5942 |
|
| TRACEME(("retrieve_boolean_true (#%d)", (int)cxt->tagnum)); |
| 5943 |
|
| |
| 5944 |
1 |
| sv = newSVsv(&PL_sv_yes); |
| 5945 |
1 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
1 |
1 |
|
| 5946 |
1 |
▶ | SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
1 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
1 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
|
| 5947 |
|
| |
| 5948 |
|
| TRACEME(("boolean true")); |
| 5949 |
|
| TRACEME(("ok (retrieve_boolean_true at 0x%" UVxf ")", PTR2UV(sv))); |
| 5950 |
|
| |
| 5951 |
1 |
| return sv; |
| 5952 |
|
| } |
| 5953 |
|
| |
| 5954 |
|
| /* |
| 5955 |
|
| * retrieve_boolean_false |
| 5956 |
|
| * |
| 5957 |
|
| * Retrieve boolean false copy. |
| 5958 |
|
| */ |
| 5959 |
1 |
| static SV *retrieve_boolean_false(pTHX_ stcxt_t *cxt, const char *cname) |
| 5960 |
|
| { |
| 5961 |
|
| SV *sv; |
| 5962 |
|
| HV *stash; |
| 5963 |
|
| |
| 5964 |
|
| TRACEME(("retrieve_boolean_false (#%d)", (int)cxt->tagnum)); |
| 5965 |
|
| |
| 5966 |
1 |
| sv = newSVsv(&PL_sv_no); |
| 5967 |
1 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
1 |
1 |
|
| 5968 |
1 |
▶ | SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
1 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
1 |
1 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
|
| 5969 |
|
| |
| 5970 |
|
| TRACEME(("boolean false")); |
| 5971 |
|
| TRACEME(("ok (retrieve_boolean_false at 0x%" UVxf ")", PTR2UV(sv))); |
| 5972 |
|
| |
| 5973 |
1 |
| return sv; |
| 5974 |
|
| } |
| 5975 |
|
| |
| 5976 |
|
| /* |
| 5977 |
|
| * retrieve_lobject |
| 5978 |
|
| * |
| 5979 |
|
| * Retrieve overlong scalar, array or hash. |
| 5980 |
|
| * Layout is SX_LOBJECT type U64_len ... |
| 5981 |
|
| */ |
| 5982 |
0 |
| static SV *retrieve_lobject(pTHX_ stcxt_t *cxt, const char *cname) |
| 5983 |
|
| { |
| 5984 |
|
| int type; |
| 5985 |
|
| #ifdef HAS_U64 |
| 5986 |
|
| UV len; |
| 5987 |
|
| SV *sv; |
| 5988 |
0 |
| int hash_flags = 0; |
| 5989 |
|
| #endif |
| 5990 |
|
| |
| 5991 |
|
| TRACEME(("retrieve_lobject (#%d)", (int)cxt->tagnum)); |
| 5992 |
|
| |
| 5993 |
0 |
▶ | GETMARK(type); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(type); |
0 |
0 |
0 |
| GETMARK(type); |
0 |
0 |
0 |
| GETMARK(type); |
0 |
0 |
0 |
|
| 5994 |
|
| TRACEME(("object type %d", type)); |
| 5995 |
|
| #ifdef HAS_U64 |
| 5996 |
|
| |
| 5997 |
0 |
▶ | if (type == SX_FLAG_HASH) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (type == SX_FLAG_HASH) { |
0 |
0 |
0 |
|
| 5998 |
|
| /* we write the flags immediately after the op. I could have |
| 5999 |
|
| changed the writer, but this may allow someone to recover |
| 6000 |
|
| data they're already frozen, though such a very large hash |
| 6001 |
|
| seems unlikely. |
| 6002 |
|
| */ |
| 6003 |
0 |
▶ | GETMARK(hash_flags); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(hash_flags); |
0 |
0 |
0 |
| GETMARK(hash_flags); |
0 |
0 |
0 |
| GETMARK(hash_flags); |
0 |
0 |
0 |
|
| 6004 |
|
| } |
| 6005 |
0 |
▶ | else if (type == SX_HOOK) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (type == SX_HOOK) { |
0 |
0 |
0 |
|
| 6006 |
0 |
| return retrieve_hook_common(aTHX_ cxt, cname, TRUE); |
| 6007 |
|
| } |
| 6008 |
|
| |
| 6009 |
0 |
▶ | READ_U64(len); |
Branch: 7 branches
| Branch | True | False | Total |
| READ_U64(len); |
0 |
0 |
0 |
| READ_U64(len); |
0 |
0 |
0 |
| READ_U64(len); |
0 |
0 |
0 |
| READ_U64(len); |
0 |
0 |
0 |
| READ_U64(len); |
0 |
0 |
0 |
| READ_U64(len); |
0 |
0 |
0 |
| READ_U64(len); |
0 |
0 |
0 |
|
| 6010 |
|
| TRACEME(("wlen %" UVuf, len)); |
| 6011 |
0 |
| switch (type) { |
| 6012 |
0 |
| case SX_OBJECT: |
| 6013 |
|
| { |
| 6014 |
|
| /* not a large object, just a large index */ |
| 6015 |
0 |
| SV **svh = av_fetch(cxt->aseen, len, FALSE); |
| 6016 |
0 |
▶ | if (!svh) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!svh) |
0 |
0 |
0 |
|
| 6017 |
0 |
| CROAK(("Object #%" UVuf " should have been retrieved already", |
| 6018 |
|
| len)); |
| 6019 |
0 |
| sv = *svh; |
| 6020 |
|
| TRACEME(("had retrieved #%" UVuf " at 0x%" UVxf, len, PTR2UV(sv))); |
| 6021 |
0 |
| SvREFCNT_inc(sv); |
| 6022 |
|
| } |
| 6023 |
0 |
| break; |
| 6024 |
0 |
| case SX_LSCALAR: |
| 6025 |
0 |
| sv = get_lstring(aTHX_ cxt, len, 0, cname); |
| 6026 |
0 |
| break; |
| 6027 |
0 |
| case SX_LUTF8STR: |
| 6028 |
0 |
| sv = get_lstring(aTHX_ cxt, len, 1, cname); |
| 6029 |
0 |
| break; |
| 6030 |
0 |
| case SX_ARRAY: |
| 6031 |
0 |
| sv = get_larray(aTHX_ cxt, len, cname); |
| 6032 |
0 |
| break; |
| 6033 |
|
| /* <5.12 you could store larger hashes, but cannot iterate over them. |
| 6034 |
|
| So we reject them, it's a bug. */ |
| 6035 |
0 |
| case SX_FLAG_HASH: |
| 6036 |
0 |
| sv = get_lhash(aTHX_ cxt, len, hash_flags, cname); |
| 6037 |
0 |
| break; |
| 6038 |
0 |
| case SX_HASH: |
| 6039 |
0 |
| sv = get_lhash(aTHX_ cxt, len, 0, cname); |
| 6040 |
0 |
| break; |
| 6041 |
0 |
| default: |
| 6042 |
0 |
| CROAK(("Unexpected type %d in retrieve_lobject\n", type)); |
| 6043 |
|
| } |
| 6044 |
|
| |
| 6045 |
|
| TRACEME(("ok (retrieve_lobject at 0x%" UVxf ")", PTR2UV(sv))); |
| 6046 |
0 |
| return sv; |
| 6047 |
|
| #else |
| 6048 |
|
| PERL_UNUSED_ARG(cname); |
| 6049 |
|
| |
| 6050 |
|
| /* previously this (brokenly) checked the length value and only failed if |
| 6051 |
|
| the length was over 4G. |
| 6052 |
|
| Since this op should only occur with objects over 4GB (or 2GB) we can just |
| 6053 |
|
| reject it. |
| 6054 |
|
| */ |
| 6055 |
|
| CROAK(("Invalid large object op for this 32bit system")); |
| 6056 |
|
| #endif |
| 6057 |
|
| } |
| 6058 |
|
| |
| 6059 |
|
| /* |
| 6060 |
|
| * retrieve_netint |
| 6061 |
|
| * |
| 6062 |
|
| * Retrieve defined integer in network order. |
| 6063 |
|
| * Layout is SX_NETINT <data>, whith SX_NETINT already read. |
| 6064 |
|
| */ |
| 6065 |
34 |
| static SV *retrieve_netint(pTHX_ stcxt_t *cxt, const char *cname) |
| 6066 |
|
| { |
| 6067 |
|
| SV *sv; |
| 6068 |
|
| HV *stash; |
| 6069 |
|
| I32 iv; |
| 6070 |
|
| |
| 6071 |
|
| TRACEME(("retrieve_netint (#%d)", (int)cxt->tagnum)); |
| 6072 |
|
| |
| 6073 |
34 |
▶ | READ_I32(iv); |
Branch: 4 branches
| Branch | True | False | Total |
| READ_I32(iv); |
13 |
21 |
34 |
| READ_I32(iv); |
13 |
0 |
13 |
| READ_I32(iv); |
0 |
13 |
13 |
| READ_I32(iv); |
0 |
21 |
21 |
|
| 6074 |
|
| #ifdef HAS_NTOHL |
| 6075 |
34 |
| sv = newSViv((int) ntohl(iv)); |
| 6076 |
|
| TRACEME(("network integer %d", (int) ntohl(iv))); |
| 6077 |
|
| #else |
| 6078 |
|
| sv = newSViv(iv); |
| 6079 |
|
| TRACEME(("network integer (as-is) %d", iv)); |
| 6080 |
|
| #endif |
| 6081 |
34 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
34 |
34 |
|
| 6082 |
34 |
▶ | SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
34 |
34 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
34 |
34 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
|
| 6083 |
|
| |
| 6084 |
|
| TRACEME(("ok (retrieve_netint at 0x%" UVxf ")", PTR2UV(sv))); |
| 6085 |
|
| |
| 6086 |
34 |
| return sv; |
| 6087 |
|
| } |
| 6088 |
|
| |
| 6089 |
|
| /* |
| 6090 |
|
| * retrieve_double |
| 6091 |
|
| * |
| 6092 |
|
| * Retrieve defined double. |
| 6093 |
|
| * Layout is SX_DOUBLE <data>, whith SX_DOUBLE already read. |
| 6094 |
|
| */ |
| 6095 |
16 |
| static SV *retrieve_double(pTHX_ stcxt_t *cxt, const char *cname) |
| 6096 |
|
| { |
| 6097 |
|
| SV *sv; |
| 6098 |
|
| HV *stash; |
| 6099 |
|
| NV nv; |
| 6100 |
|
| |
| 6101 |
|
| TRACEME(("retrieve_double (#%d)", (int)cxt->tagnum)); |
| 6102 |
|
| |
| 6103 |
16 |
▶ | READ(&nv, sizeof(nv)); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(&nv, sizeof(nv)); |
8 |
8 |
16 |
| READ(&nv, sizeof(nv)); |
8 |
0 |
8 |
| READ(&nv, sizeof(nv)); |
0 |
8 |
8 |
|
| 6104 |
16 |
| sv = newSVnv(nv); |
| 6105 |
16 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
16 |
16 |
|
| 6106 |
16 |
▶ | SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
16 |
16 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
16 |
16 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
|
| 6107 |
|
| |
| 6108 |
|
| TRACEME(("double %" NVff, nv)); |
| 6109 |
|
| TRACEME(("ok (retrieve_double at 0x%" UVxf ")", PTR2UV(sv))); |
| 6110 |
|
| |
| 6111 |
16 |
| return sv; |
| 6112 |
|
| } |
| 6113 |
|
| |
| 6114 |
|
| /* |
| 6115 |
|
| * retrieve_byte |
| 6116 |
|
| * |
| 6117 |
|
| * Retrieve defined byte (small integer within the [-128, +127] range). |
| 6118 |
|
| * Layout is SX_BYTE <data>, whith SX_BYTE already read. |
| 6119 |
|
| */ |
| 6120 |
182 |
| static SV *retrieve_byte(pTHX_ stcxt_t *cxt, const char *cname) |
| 6121 |
|
| { |
| 6122 |
|
| SV *sv; |
| 6123 |
|
| HV *stash; |
| 6124 |
|
| int siv; |
| 6125 |
|
| #ifdef _MSC_VER |
| 6126 |
|
| /* MSVC 2017 doesn't handle the AIX workaround well */ |
| 6127 |
|
| int tmp; |
| 6128 |
|
| #else |
| 6129 |
|
| signed char tmp; /* Workaround for AIX cc bug --H.Merijn Brand */ |
| 6130 |
|
| #endif |
| 6131 |
|
| |
| 6132 |
|
| TRACEME(("retrieve_byte (#%d)", (int)cxt->tagnum)); |
| 6133 |
|
| |
| 6134 |
182 |
▶ | GETMARK(siv); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(siv); |
146 |
36 |
182 |
| GETMARK(siv); |
146 |
0 |
146 |
| GETMARK(siv); |
0 |
36 |
36 |
|
| 6135 |
|
| TRACEME(("small integer read as %d", (unsigned char) siv)); |
| 6136 |
182 |
| tmp = (unsigned char) siv - 128; |
| 6137 |
182 |
| sv = newSViv(tmp); |
| 6138 |
182 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
182 |
182 |
|
| 6139 |
182 |
▶ | SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
182 |
182 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
182 |
182 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); /* Associate this new scalar with tag "tagnum" */ |
0 |
0 |
0 |
|
| 6140 |
|
| |
| 6141 |
|
| TRACEME(("byte %d", tmp)); |
| 6142 |
|
| TRACEME(("ok (retrieve_byte at 0x%" UVxf ")", PTR2UV(sv))); |
| 6143 |
|
| |
| 6144 |
182 |
| return sv; |
| 6145 |
|
| } |
| 6146 |
|
| |
| 6147 |
|
| /* |
| 6148 |
|
| * retrieve_undef |
| 6149 |
|
| * |
| 6150 |
|
| * Return the undefined value. |
| 6151 |
|
| */ |
| 6152 |
21 |
| static SV *retrieve_undef(pTHX_ stcxt_t *cxt, const char *cname) |
| 6153 |
|
| { |
| 6154 |
|
| SV *sv; |
| 6155 |
|
| HV *stash; |
| 6156 |
|
| |
| 6157 |
|
| TRACEME(("retrieve_undef")); |
| 6158 |
|
| |
| 6159 |
21 |
| sv = newSV(0); |
| 6160 |
21 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
2 |
19 |
21 |
|
| 6161 |
21 |
▶ | SEEN_NN(sv, stash, 0); |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); |
0 |
21 |
21 |
| SEEN_NN(sv, stash, 0); |
2 |
19 |
21 |
| SEEN_NN(sv, stash, 0); |
2 |
0 |
2 |
| SEEN_NN(sv, stash, 0); |
0 |
2 |
2 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
|
| 6162 |
|
| |
| 6163 |
21 |
| return sv; |
| 6164 |
|
| } |
| 6165 |
|
| |
| 6166 |
|
| /* |
| 6167 |
|
| * retrieve_sv_undef |
| 6168 |
|
| * |
| 6169 |
|
| * Return the immortal undefined value. |
| 6170 |
|
| */ |
| 6171 |
5135 |
| static SV *retrieve_sv_undef(pTHX_ stcxt_t *cxt, const char *cname) |
| 6172 |
|
| { |
| 6173 |
5135 |
| SV *sv = &PL_sv_undef; |
| 6174 |
|
| HV *stash; |
| 6175 |
|
| |
| 6176 |
|
| TRACEME(("retrieve_sv_undef")); |
| 6177 |
|
| |
| 6178 |
|
| /* Special case PL_sv_undef, as av_fetch uses it internally to mark |
| 6179 |
|
| deleted elements, and will return NULL (fetch failed) whenever it |
| 6180 |
|
| is fetched. */ |
| 6181 |
5135 |
▶ | if (cxt->where_is_undef == UNSET_NTAG_T) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->where_is_undef == UNSET_NTAG_T) { |
120 |
5015 |
5135 |
|
| 6182 |
120 |
| cxt->where_is_undef = cxt->tagnum; |
| 6183 |
|
| } |
| 6184 |
5135 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
5135 |
5135 |
|
| 6185 |
5135 |
▶ | SEEN_NN(sv, stash, 1); |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 1); |
0 |
5135 |
5135 |
| SEEN_NN(sv, stash, 1); |
0 |
5135 |
5135 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
|
| 6186 |
5135 |
| return sv; |
| 6187 |
|
| } |
| 6188 |
|
| |
| 6189 |
|
| /* |
| 6190 |
|
| * retrieve_sv_yes |
| 6191 |
|
| * |
| 6192 |
|
| * Return the immortal yes value. |
| 6193 |
|
| */ |
| 6194 |
4 |
| static SV *retrieve_sv_yes(pTHX_ stcxt_t *cxt, const char *cname) |
| 6195 |
|
| { |
| 6196 |
4 |
| SV *sv = &PL_sv_yes; |
| 6197 |
|
| HV *stash; |
| 6198 |
|
| |
| 6199 |
|
| TRACEME(("retrieve_sv_yes")); |
| 6200 |
|
| |
| 6201 |
4 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
4 |
4 |
|
| 6202 |
4 |
▶ | SEEN_NN(sv, stash, 1); |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 1); |
0 |
4 |
4 |
| SEEN_NN(sv, stash, 1); |
0 |
4 |
4 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
|
| 6203 |
4 |
| return sv; |
| 6204 |
|
| } |
| 6205 |
|
| |
| 6206 |
|
| /* |
| 6207 |
|
| * retrieve_sv_no |
| 6208 |
|
| * |
| 6209 |
|
| * Return the immortal no value. |
| 6210 |
|
| */ |
| 6211 |
4 |
| static SV *retrieve_sv_no(pTHX_ stcxt_t *cxt, const char *cname) |
| 6212 |
|
| { |
| 6213 |
4 |
| SV *sv = &PL_sv_no; |
| 6214 |
|
| HV *stash; |
| 6215 |
|
| |
| 6216 |
|
| TRACEME(("retrieve_sv_no")); |
| 6217 |
|
| |
| 6218 |
4 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
4 |
4 |
|
| 6219 |
4 |
▶ | SEEN_NN(sv, stash, 1); |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 1); |
0 |
4 |
4 |
| SEEN_NN(sv, stash, 1); |
0 |
4 |
4 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 1); |
0 |
0 |
0 |
|
| 6220 |
4 |
| return sv; |
| 6221 |
|
| } |
| 6222 |
|
| |
| 6223 |
|
| /* |
| 6224 |
|
| * retrieve_svundef_elem |
| 6225 |
|
| * |
| 6226 |
|
| * Return &PL_sv_placeholder, representing &PL_sv_undef in an array. This |
| 6227 |
|
| * is a bit of a hack, but we already use SX_SV_UNDEF to mean a nonexistent |
| 6228 |
|
| * element, for historical reasons. |
| 6229 |
|
| */ |
| 6230 |
0 |
| static SV *retrieve_svundef_elem(pTHX_ stcxt_t *cxt, const char *cname) |
| 6231 |
|
| { |
| 6232 |
|
| TRACEME(("retrieve_svundef_elem")); |
| 6233 |
|
| |
| 6234 |
|
| /* SEEN reads the contents of its SV argument, which we are not |
| 6235 |
|
| supposed to do with &PL_sv_placeholder. */ |
| 6236 |
0 |
▶ | SEEN_NN(&PL_sv_undef, cname, 1); |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
| SEEN_NN(&PL_sv_undef, cname, 1); |
0 |
0 |
0 |
|
| 6237 |
|
| |
| 6238 |
0 |
| return &PL_sv_placeholder; |
| 6239 |
|
| } |
| 6240 |
|
| |
| 6241 |
|
| /* |
| 6242 |
|
| * retrieve_array |
| 6243 |
|
| * |
| 6244 |
|
| * Retrieve a whole array. |
| 6245 |
|
| * Layout is SX_ARRAY <size> followed by each item, in increasing index order. |
| 6246 |
|
| * Each item is stored as <object>. |
| 6247 |
|
| * |
| 6248 |
|
| * When we come here, SX_ARRAY has been read already. |
| 6249 |
|
| */ |
| 6250 |
53222 |
| static SV *retrieve_array(pTHX_ stcxt_t *cxt, const char *cname) |
| 6251 |
|
| { |
| 6252 |
|
| I32 len, i; |
| 6253 |
|
| AV *av; |
| 6254 |
|
| SV *sv; |
| 6255 |
|
| HV *stash; |
| 6256 |
53222 |
| bool seen_null = FALSE; |
| 6257 |
|
| |
| 6258 |
|
| TRACEME(("retrieve_array (#%d)", (int)cxt->tagnum)); |
| 6259 |
|
| |
| 6260 |
|
| /* |
| 6261 |
|
| * Read length, and allocate array, then pre-extend it. |
| 6262 |
|
| */ |
| 6263 |
|
| |
| 6264 |
53222 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
53202 |
20 |
53222 |
| RLEN(len); |
53202 |
0 |
53202 |
| RLEN(len); |
24108 |
29094 |
53202 |
| RLEN(len); |
0 |
20 |
20 |
| RLEN(len); |
16 |
53206 |
53222 |
|
| 6265 |
|
| TRACEME(("size = %d", (int)len)); |
| 6266 |
53222 |
| av = newAV(); |
| 6267 |
53222 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
42 |
53180 |
53222 |
|
| 6268 |
53222 |
▶ | SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
53222 |
53222 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
42 |
53180 |
53222 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
42 |
0 |
42 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
17 |
25 |
42 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
17 |
0 |
17 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
17 |
0 |
17 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
17 |
17 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
17 |
0 |
17 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
17 |
17 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
17 |
0 |
17 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
17 |
17 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
17 |
0 |
17 |
|
| 6269 |
53222 |
▶ | if (len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len) |
37186 |
16036 |
53222 |
|
| 6270 |
37186 |
| av_extend(av, len); |
| 6271 |
|
| else |
| 6272 |
16036 |
| return (SV *) av; /* No data follow if array is empty */ |
| 6273 |
|
| |
| 6274 |
|
| /* |
| 6275 |
|
| * Now get each item in turn... |
| 6276 |
|
| */ |
| 6277 |
|
| |
| 6278 |
97121 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
59936 |
37185 |
97121 |
|
| 6279 |
|
| TRACEME(("(#%d) item", (int)i)); |
| 6280 |
59936 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve item */ |
| 6281 |
59935 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
59935 |
59935 |
|
| 6282 |
0 |
| return (SV *) 0; |
| 6283 |
59935 |
▶ | if (sv == &PL_sv_undef) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv == &PL_sv_undef) { |
2 |
59933 |
59935 |
|
| 6284 |
2 |
| seen_null = TRUE; |
| 6285 |
2 |
| continue; |
| 6286 |
|
| } |
| 6287 |
59933 |
▶ | if (sv == &PL_sv_placeholder) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv == &PL_sv_placeholder) |
0 |
59933 |
59933 |
|
| 6288 |
0 |
| sv = &PL_sv_undef; |
| 6289 |
59933 |
▶ | if (av_store(av, i, sv) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_store(av, i, sv) == 0) |
0 |
59933 |
59933 |
|
| 6290 |
0 |
| return (SV *) 0; |
| 6291 |
|
| } |
| 6292 |
37185 |
▶ | if (seen_null) av_fill(av, len-1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (seen_null) av_fill(av, len-1); |
1 |
37184 |
37185 |
|
| 6293 |
|
| |
| 6294 |
|
| TRACEME(("ok (retrieve_array at 0x%" UVxf ")", PTR2UV(av))); |
| 6295 |
|
| |
| 6296 |
37185 |
| return (SV *) av; |
| 6297 |
|
| } |
| 6298 |
|
| |
| 6299 |
|
| #ifdef HAS_U64 |
| 6300 |
|
| |
| 6301 |
|
| /* internal method with len already read */ |
| 6302 |
|
| |
| 6303 |
0 |
| static SV *get_larray(pTHX_ stcxt_t *cxt, UV len, const char *cname) |
| 6304 |
|
| { |
| 6305 |
|
| UV i; |
| 6306 |
|
| AV *av; |
| 6307 |
|
| SV *sv; |
| 6308 |
|
| HV *stash; |
| 6309 |
0 |
| bool seen_null = FALSE; |
| 6310 |
|
| |
| 6311 |
|
| TRACEME(("get_larray (#%d) %lu", (int)cxt->tagnum, (unsigned long)len)); |
| 6312 |
|
| |
| 6313 |
|
| /* |
| 6314 |
|
| * allocate array, then pre-extend it. |
| 6315 |
|
| */ |
| 6316 |
|
| |
| 6317 |
0 |
| av = newAV(); |
| 6318 |
0 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
0 |
0 |
|
| 6319 |
0 |
▶ | SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
| SEEN_NN(av, stash, 0); /* Will return if array not allocated nicely */ |
0 |
0 |
0 |
|
| 6320 |
|
| assert(len); |
| 6321 |
0 |
| av_extend(av, len); |
| 6322 |
|
| |
| 6323 |
|
| /* |
| 6324 |
|
| * Now get each item in turn... |
| 6325 |
|
| */ |
| 6326 |
|
| |
| 6327 |
0 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
0 |
0 |
0 |
|
| 6328 |
|
| TRACEME(("(#%d) item", (int)i)); |
| 6329 |
0 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve item */ |
| 6330 |
0 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
0 |
0 |
|
| 6331 |
0 |
| return (SV *) 0; |
| 6332 |
0 |
▶ | if (sv == &PL_sv_undef) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv == &PL_sv_undef) { |
0 |
0 |
0 |
|
| 6333 |
0 |
| seen_null = TRUE; |
| 6334 |
0 |
| continue; |
| 6335 |
|
| } |
| 6336 |
0 |
▶ | if (sv == &PL_sv_placeholder) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv == &PL_sv_placeholder) |
0 |
0 |
0 |
|
| 6337 |
0 |
| sv = &PL_sv_undef; |
| 6338 |
0 |
▶ | if (av_store(av, i, sv) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_store(av, i, sv) == 0) |
0 |
0 |
0 |
|
| 6339 |
0 |
| return (SV *) 0; |
| 6340 |
|
| } |
| 6341 |
0 |
▶ | if (seen_null) av_fill(av, len-1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (seen_null) av_fill(av, len-1); |
0 |
0 |
0 |
|
| 6342 |
|
| |
| 6343 |
|
| TRACEME(("ok (get_larray at 0x%" UVxf ")", PTR2UV(av))); |
| 6344 |
|
| |
| 6345 |
0 |
| return (SV *) av; |
| 6346 |
|
| } |
| 6347 |
|
| |
| 6348 |
|
| /* |
| 6349 |
|
| * get_lhash |
| 6350 |
|
| * |
| 6351 |
|
| * Retrieve a overlong hash table. |
| 6352 |
|
| * <len> is already read. What follows is each key/value pair, in random order. |
| 6353 |
|
| * Keys are stored as <length> <data>, the <data> section being omitted |
| 6354 |
|
| * if length is 0. |
| 6355 |
|
| * Values are stored as <object>. |
| 6356 |
|
| * |
| 6357 |
|
| */ |
| 6358 |
0 |
| static SV *get_lhash(pTHX_ stcxt_t *cxt, UV len, int hash_flags, const char *cname) |
| 6359 |
|
| { |
| 6360 |
|
| UV size; |
| 6361 |
|
| UV i; |
| 6362 |
|
| HV *hv; |
| 6363 |
|
| SV *sv; |
| 6364 |
|
| HV *stash; |
| 6365 |
|
| |
| 6366 |
|
| TRACEME(("get_lhash (#%d)", (int)cxt->tagnum)); |
| 6367 |
|
| |
| 6368 |
|
| #ifdef HAS_RESTRICTED_HASHES |
| 6369 |
|
| PERL_UNUSED_ARG(hash_flags); |
| 6370 |
|
| #else |
| 6371 |
|
| if (hash_flags & SHV_RESTRICTED) { |
| 6372 |
|
| if (cxt->derestrict < 0) |
| 6373 |
|
| cxt->derestrict = (SvTRUE |
| 6374 |
|
| (get_sv("Storable::downgrade_restricted", GV_ADD)) |
| 6375 |
|
| ? 1 : 0); |
| 6376 |
|
| if (cxt->derestrict == 0) |
| 6377 |
|
| RESTRICTED_HASH_CROAK(); |
| 6378 |
|
| } |
| 6379 |
|
| #endif |
| 6380 |
|
| |
| 6381 |
|
| TRACEME(("size = %lu", (unsigned long)len)); |
| 6382 |
0 |
| hv = newHV(); |
| 6383 |
0 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
0 |
0 |
0 |
|
| 6384 |
0 |
▶ | SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
|
| 6385 |
0 |
▶ | if (len == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) |
0 |
0 |
0 |
|
| 6386 |
0 |
| return (SV *) hv; /* No data follow if table empty */ |
| 6387 |
|
| TRACEME(("split %lu", (unsigned long)len+1)); |
| 6388 |
0 |
| hv_ksplit(hv, len+1); /* pre-extend hash to save multiple splits */ |
| 6389 |
|
| |
| 6390 |
|
| /* |
| 6391 |
|
| * Now get each key/value pair in turn... |
| 6392 |
|
| */ |
| 6393 |
|
| |
| 6394 |
0 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
0 |
0 |
0 |
|
| 6395 |
|
| /* |
| 6396 |
|
| * Get value first. |
| 6397 |
|
| */ |
| 6398 |
|
| |
| 6399 |
|
| TRACEME(("(#%d) value", (int)i)); |
| 6400 |
0 |
| sv = retrieve(aTHX_ cxt, 0); |
| 6401 |
0 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
0 |
0 |
|
| 6402 |
0 |
| return (SV *) 0; |
| 6403 |
|
| |
| 6404 |
|
| /* |
| 6405 |
|
| * Get key. |
| 6406 |
|
| * Since we're reading into kbuf, we must ensure we're not |
| 6407 |
|
| * recursing between the read and the hv_store() where it's used. |
| 6408 |
|
| * Hence the key comes after the value. |
| 6409 |
|
| */ |
| 6410 |
|
| |
| 6411 |
0 |
▶ | RLEN(size); /* Get key size */ |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
|
| 6412 |
0 |
▶ | KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
Branch: 2 branches
| Branch | True | False | Total |
| KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
0 |
0 |
0 |
| KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
0 |
0 |
0 |
|
| 6413 |
0 |
▶ | if (size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (size) |
0 |
0 |
0 |
|
| 6414 |
0 |
▶ | READ(kbuf, size); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(kbuf, size); |
0 |
0 |
0 |
| READ(kbuf, size); |
0 |
0 |
0 |
| READ(kbuf, size); |
0 |
0 |
0 |
|
| 6415 |
0 |
| kbuf[size] = '\0'; /* Mark string end, just in case */ |
| 6416 |
|
| TRACEME(("(#%d) key '%s'", (int)i, kbuf)); |
| 6417 |
|
| |
| 6418 |
|
| /* |
| 6419 |
|
| * Enter key/value pair into hash table. |
| 6420 |
|
| */ |
| 6421 |
|
| |
| 6422 |
0 |
▶ | if (hv_store(hv, kbuf, (U32) size, sv, 0) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_store(hv, kbuf, (U32) size, sv, 0) == 0) |
0 |
0 |
0 |
|
| 6423 |
0 |
| return (SV *) 0; |
| 6424 |
|
| } |
| 6425 |
|
| |
| 6426 |
|
| TRACEME(("ok (get_lhash at 0x%" UVxf ")", PTR2UV(hv))); |
| 6427 |
0 |
| return (SV *) hv; |
| 6428 |
|
| } |
| 6429 |
|
| #endif |
| 6430 |
|
| |
| 6431 |
|
| /* |
| 6432 |
|
| * retrieve_hash |
| 6433 |
|
| * |
| 6434 |
|
| * Retrieve a whole hash table. |
| 6435 |
|
| * Layout is SX_HASH <size> followed by each key/value pair, in random order. |
| 6436 |
|
| * Keys are stored as <length> <data>, the <data> section being omitted |
| 6437 |
|
| * if length is 0. |
| 6438 |
|
| * Values are stored as <object>. |
| 6439 |
|
| * |
| 6440 |
|
| * When we come here, SX_HASH has been read already. |
| 6441 |
|
| */ |
| 6442 |
5238 |
| static SV *retrieve_hash(pTHX_ stcxt_t *cxt, const char *cname) |
| 6443 |
|
| { |
| 6444 |
|
| I32 len; |
| 6445 |
|
| I32 size; |
| 6446 |
|
| I32 i; |
| 6447 |
|
| HV *hv; |
| 6448 |
|
| SV *sv; |
| 6449 |
|
| HV *stash; |
| 6450 |
|
| |
| 6451 |
|
| TRACEME(("retrieve_hash (#%d)", (int)cxt->tagnum)); |
| 6452 |
|
| |
| 6453 |
|
| /* |
| 6454 |
|
| * Read length, allocate table. |
| 6455 |
|
| */ |
| 6456 |
|
| |
| 6457 |
5238 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
5213 |
25 |
5238 |
| RLEN(len); |
5213 |
0 |
5213 |
| RLEN(len); |
5058 |
155 |
5213 |
| RLEN(len); |
0 |
25 |
25 |
| RLEN(len); |
16 |
5222 |
5238 |
|
| 6458 |
|
| TRACEME(("size = %d", (int)len)); |
| 6459 |
5238 |
| hv = newHV(); |
| 6460 |
5238 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
39 |
5199 |
5238 |
|
| 6461 |
5238 |
▶ | SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
5238 |
5238 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
39 |
5199 |
5238 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
37 |
2 |
39 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
37 |
37 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
|
| 6462 |
5238 |
▶ | if (len == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) |
5017 |
221 |
5238 |
|
| 6463 |
5017 |
| return (SV *) hv; /* No data follow if table empty */ |
| 6464 |
|
| TRACEME(("split %d", (int)len+1)); |
| 6465 |
221 |
| hv_ksplit(hv, len+1); /* pre-extend hash to save multiple splits */ |
| 6466 |
|
| |
| 6467 |
|
| /* |
| 6468 |
|
| * Now get each key/value pair in turn... |
| 6469 |
|
| */ |
| 6470 |
|
| |
| 6471 |
2081 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
1862 |
219 |
2081 |
|
| 6472 |
|
| /* |
| 6473 |
|
| * Get value first. |
| 6474 |
|
| */ |
| 6475 |
|
| |
| 6476 |
|
| TRACEME(("(#%d) value", (int)i)); |
| 6477 |
1862 |
| sv = retrieve(aTHX_ cxt, 0); |
| 6478 |
1860 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
1860 |
1860 |
|
| 6479 |
0 |
| return (SV *) 0; |
| 6480 |
|
| |
| 6481 |
|
| /* |
| 6482 |
|
| * Get key. |
| 6483 |
|
| * Since we're reading into kbuf, we must ensure we're not |
| 6484 |
|
| * recursing between the read and the hv_store() where it's used. |
| 6485 |
|
| * Hence the key comes after the value. |
| 6486 |
|
| */ |
| 6487 |
|
| |
| 6488 |
1860 |
▶ | RLEN(size); /* Get key size */ |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(size); /* Get key size */ |
1822 |
38 |
1860 |
| RLEN(size); /* Get key size */ |
1822 |
0 |
1822 |
| RLEN(size); /* Get key size */ |
462 |
1360 |
1822 |
| RLEN(size); /* Get key size */ |
0 |
38 |
38 |
| RLEN(size); /* Get key size */ |
30 |
1830 |
1860 |
|
| 6489 |
1860 |
▶ | KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
Branch: 2 branches
| Branch | True | False | Total |
| KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
0 |
1860 |
1860 |
| KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
0 |
0 |
0 |
|
| 6490 |
1860 |
▶ | if (size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (size) |
1856 |
4 |
1860 |
|
| 6491 |
1856 |
▶ | READ(kbuf, size); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(kbuf, size); |
1818 |
38 |
1856 |
| READ(kbuf, size); |
1818 |
0 |
1818 |
| READ(kbuf, size); |
0 |
38 |
38 |
|
| 6492 |
1860 |
| kbuf[size] = '\0'; /* Mark string end, just in case */ |
| 6493 |
|
| TRACEME(("(#%d) key '%s'", (int)i, kbuf)); |
| 6494 |
|
| |
| 6495 |
|
| /* |
| 6496 |
|
| * Enter key/value pair into hash table. |
| 6497 |
|
| */ |
| 6498 |
|
| |
| 6499 |
1860 |
▶ | if (hv_store(hv, kbuf, (U32) size, sv, 0) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_store(hv, kbuf, (U32) size, sv, 0) == 0) |
0 |
1860 |
1860 |
|
| 6500 |
0 |
| return (SV *) 0; |
| 6501 |
|
| } |
| 6502 |
|
| |
| 6503 |
|
| TRACEME(("ok (retrieve_hash at 0x%" UVxf ")", PTR2UV(hv))); |
| 6504 |
|
| |
| 6505 |
219 |
| return (SV *) hv; |
| 6506 |
|
| } |
| 6507 |
|
| |
| 6508 |
|
| /* |
| 6509 |
|
| * retrieve_hash |
| 6510 |
|
| * |
| 6511 |
|
| * Retrieve a whole hash table. |
| 6512 |
|
| * Layout is SX_HASH <size> followed by each key/value pair, in random order. |
| 6513 |
|
| * Keys are stored as <length> <data>, the <data> section being omitted |
| 6514 |
|
| * if length is 0. |
| 6515 |
|
| * Values are stored as <object>. |
| 6516 |
|
| * |
| 6517 |
|
| * When we come here, SX_HASH has been read already. |
| 6518 |
|
| */ |
| 6519 |
245 |
| static SV *retrieve_flag_hash(pTHX_ stcxt_t *cxt, const char *cname) |
| 6520 |
|
| { |
| 6521 |
|
| dVAR; |
| 6522 |
|
| I32 len; |
| 6523 |
|
| I32 size; |
| 6524 |
|
| I32 i; |
| 6525 |
|
| HV *hv; |
| 6526 |
|
| SV *sv; |
| 6527 |
|
| HV *stash; |
| 6528 |
|
| int hash_flags; |
| 6529 |
|
| |
| 6530 |
245 |
▶ | GETMARK(hash_flags); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(hash_flags); |
191 |
54 |
245 |
| GETMARK(hash_flags); |
189 |
2 |
191 |
| GETMARK(hash_flags); |
2 |
52 |
54 |
|
| 6531 |
|
| TRACEME(("retrieve_flag_hash (#%d)", (int)cxt->tagnum)); |
| 6532 |
|
| /* |
| 6533 |
|
| * Read length, allocate table. |
| 6534 |
|
| */ |
| 6535 |
|
| |
| 6536 |
|
| #ifndef HAS_RESTRICTED_HASHES |
| 6537 |
|
| if (hash_flags & SHV_RESTRICTED) { |
| 6538 |
|
| if (cxt->derestrict < 0) |
| 6539 |
|
| cxt->derestrict = (SvTRUE |
| 6540 |
|
| (get_sv("Storable::downgrade_restricted", GV_ADD)) |
| 6541 |
|
| ? 1 : 0); |
| 6542 |
|
| if (cxt->derestrict == 0) |
| 6543 |
|
| RESTRICTED_HASH_CROAK(); |
| 6544 |
|
| } |
| 6545 |
|
| #endif |
| 6546 |
|
| |
| 6547 |
241 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
189 |
52 |
241 |
| RLEN(len); |
181 |
8 |
189 |
| RLEN(len); |
37 |
144 |
181 |
| RLEN(len); |
8 |
44 |
52 |
| RLEN(len); |
59 |
166 |
225 |
|
| 6548 |
|
| TRACEME(("size = %d, flags = %d", (int)len, hash_flags)); |
| 6549 |
225 |
| hv = newHV(); |
| 6550 |
225 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
6 |
219 |
225 |
|
| 6551 |
225 |
▶ | SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
225 |
225 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
6 |
219 |
225 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
6 |
0 |
6 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
6 |
6 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
| SEEN_NN(hv, stash, 0); /* Will return if table not allocated properly */ |
0 |
0 |
0 |
|
| 6552 |
225 |
▶ | if (len == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) |
0 |
225 |
225 |
|
| 6553 |
0 |
| return (SV *) hv; /* No data follow if table empty */ |
| 6554 |
|
| TRACEME(("split %d", (int)len+1)); |
| 6555 |
225 |
| hv_ksplit(hv, len+1); /* pre-extend hash to save multiple splits */ |
| 6556 |
|
| |
| 6557 |
|
| /* |
| 6558 |
|
| * Now get each key/value pair in turn... |
| 6559 |
|
| */ |
| 6560 |
|
| |
| 6561 |
5458 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
5299 |
159 |
5458 |
|
| 6562 |
|
| int flags; |
| 6563 |
5299 |
| int store_flags = 0; |
| 6564 |
|
| /* |
| 6565 |
|
| * Get value first. |
| 6566 |
|
| */ |
| 6567 |
|
| |
| 6568 |
|
| TRACEME(("(#%d) value", (int)i)); |
| 6569 |
5299 |
| sv = retrieve(aTHX_ cxt, 0); |
| 6570 |
5298 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
28 |
5270 |
5298 |
|
| 6571 |
28 |
| return (SV *) 0; |
| 6572 |
|
| |
| 6573 |
5270 |
▶ | GETMARK(flags); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(flags); |
5229 |
41 |
5270 |
| GETMARK(flags); |
5227 |
2 |
5229 |
| GETMARK(flags); |
2 |
39 |
41 |
|
| 6574 |
|
| #ifdef HAS_RESTRICTED_HASHES |
| 6575 |
5266 |
▶ | if ((hash_flags & SHV_RESTRICTED) && (flags & SHV_K_LOCKED)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((hash_flags & SHV_RESTRICTED) && (flags & SHV_K_LOCKED)) |
5166 |
100 |
5266 |
| if ((hash_flags & SHV_RESTRICTED) && (flags & SHV_K_LOCKED)) |
5150 |
16 |
5166 |
|
| 6576 |
5150 |
| SvREADONLY_on(sv); |
| 6577 |
|
| #endif |
| 6578 |
|
| |
| 6579 |
5266 |
▶ | if (flags & SHV_K_ISSV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHV_K_ISSV) { |
1 |
5265 |
5266 |
|
| 6580 |
|
| /* XXX you can't set a placeholder with an SV key. |
| 6581 |
|
| Then again, you can't get an SV key. |
| 6582 |
|
| Without messing around beyond what the API is supposed to do. |
| 6583 |
|
| */ |
| 6584 |
|
| SV *keysv; |
| 6585 |
|
| TRACEME(("(#%d) keysv, flags=%d", (int)i, flags)); |
| 6586 |
1 |
| keysv = retrieve(aTHX_ cxt, 0); |
| 6587 |
0 |
▶ | if (!keysv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!keysv) |
0 |
0 |
0 |
|
| 6588 |
0 |
| return (SV *) 0; |
| 6589 |
|
| |
| 6590 |
0 |
▶ | if (!hv_store_ent(hv, keysv, sv, 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_store_ent(hv, keysv, sv, 0)) |
0 |
0 |
0 |
|
| 6591 |
0 |
| return (SV *) 0; |
| 6592 |
|
| } else { |
| 6593 |
|
| /* |
| 6594 |
|
| * Get key. |
| 6595 |
|
| * Since we're reading into kbuf, we must ensure we're not |
| 6596 |
|
| * recursing between the read and the hv_store() where it's used. |
| 6597 |
|
| * Hence the key comes after the value. |
| 6598 |
|
| */ |
| 6599 |
|
| |
| 6600 |
5265 |
▶ | if (flags & SHV_K_PLACEHOLDER) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHV_K_PLACEHOLDER) { |
5130 |
135 |
5265 |
|
| 6601 |
5130 |
| SvREFCNT_dec (sv); |
| 6602 |
5130 |
| sv = &PL_sv_placeholder; |
| 6603 |
5130 |
| store_flags |= HVhek_PLACEHOLD; |
| 6604 |
|
| } |
| 6605 |
5265 |
▶ | if (flags & SHV_K_UTF8) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHV_K_UTF8) { |
20 |
5245 |
5265 |
|
| 6606 |
|
| #ifdef HAS_UTF8_HASHES |
| 6607 |
20 |
| store_flags |= HVhek_UTF8; |
| 6608 |
|
| #else |
| 6609 |
|
| if (cxt->use_bytes < 0) |
| 6610 |
|
| cxt->use_bytes |
| 6611 |
|
| = (SvTRUE(get_sv("Storable::drop_utf8", GV_ADD)) |
| 6612 |
|
| ? 1 : 0); |
| 6613 |
|
| if (cxt->use_bytes == 0) |
| 6614 |
|
| UTF8_CROAK(); |
| 6615 |
|
| #endif |
| 6616 |
|
| } |
| 6617 |
|
| #ifdef HAS_UTF8_HASHES |
| 6618 |
5265 |
▶ | if (flags & SHV_K_WASUTF8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & SHV_K_WASUTF8) |
12 |
5253 |
5265 |
|
| 6619 |
12 |
| store_flags |= HVhek_WASUTF8; |
| 6620 |
|
| #endif |
| 6621 |
|
| |
| 6622 |
5265 |
▶ | RLEN(size); /* Get key size */ |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(size); /* Get key size */ |
5227 |
38 |
5265 |
| RLEN(size); /* Get key size */ |
5219 |
8 |
5227 |
| RLEN(size); /* Get key size */ |
1285 |
3934 |
5219 |
| RLEN(size); /* Get key size */ |
8 |
30 |
38 |
| RLEN(size); /* Get key size */ |
54 |
5195 |
5249 |
|
| 6623 |
5249 |
▶ | KBUFCHK((STRLEN)size);/* Grow hash key read pool if needed */ |
Branch: 2 branches
| Branch | True | False | Total |
| KBUFCHK((STRLEN)size);/* Grow hash key read pool if needed */ |
0 |
5249 |
5249 |
| KBUFCHK((STRLEN)size);/* Grow hash key read pool if needed */ |
0 |
0 |
0 |
|
| 6624 |
5249 |
▶ | if (size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (size) |
5249 |
0 |
5249 |
|
| 6625 |
5249 |
▶ | READ(kbuf, size); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(kbuf, size); |
5219 |
30 |
5249 |
| READ(kbuf, size); |
5211 |
8 |
5219 |
| READ(kbuf, size); |
8 |
22 |
30 |
|
| 6626 |
5233 |
| kbuf[size] = '\0'; /* Mark string end, just in case */ |
| 6627 |
|
| TRACEME(("(#%d) key '%s' flags %X store_flags %X", (int)i, kbuf, |
| 6628 |
|
| flags, store_flags)); |
| 6629 |
|
| |
| 6630 |
|
| /* |
| 6631 |
|
| * Enter key/value pair into hash table. |
| 6632 |
|
| */ |
| 6633 |
|
| |
| 6634 |
|
| #ifdef HAS_RESTRICTED_HASHES |
| 6635 |
5233 |
▶ | if (hv_store_flags(hv, kbuf, size, sv, 0, store_flags) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_store_flags(hv, kbuf, size, sv, 0, store_flags) == 0) |
0 |
5233 |
5233 |
|
| 6636 |
0 |
| return (SV *) 0; |
| 6637 |
|
| #else |
| 6638 |
|
| if (!(store_flags & HVhek_PLACEHOLD)) |
| 6639 |
|
| if (hv_store(hv, kbuf, size, sv, 0) == 0) |
| 6640 |
|
| return (SV *) 0; |
| 6641 |
|
| #endif |
| 6642 |
|
| } |
| 6643 |
|
| } |
| 6644 |
|
| #ifdef HAS_RESTRICTED_HASHES |
| 6645 |
159 |
▶ | if (hash_flags & SHV_RESTRICTED) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hash_flags & SHV_RESTRICTED) |
129 |
30 |
159 |
|
| 6646 |
129 |
| SvREADONLY_on(hv); |
| 6647 |
|
| #endif |
| 6648 |
|
| |
| 6649 |
|
| TRACEME(("ok (retrieve_hash at 0x%" UVxf ")", PTR2UV(hv))); |
| 6650 |
|
| |
| 6651 |
159 |
| return (SV *) hv; |
| 6652 |
|
| } |
| 6653 |
|
| |
| 6654 |
|
| /* |
| 6655 |
|
| * retrieve_code |
| 6656 |
|
| * |
| 6657 |
|
| * Return a code reference. |
| 6658 |
|
| */ |
| 6659 |
63 |
| static SV *retrieve_code(pTHX_ stcxt_t *cxt, const char *cname) |
| 6660 |
|
| { |
| 6661 |
63 |
| dSP; |
| 6662 |
|
| I32 type, count; |
| 6663 |
|
| IV tagnum; |
| 6664 |
|
| SV *cv; |
| 6665 |
|
| SV *sv, *text, *sub, *errsv; |
| 6666 |
|
| HV *stash; |
| 6667 |
|
| |
| 6668 |
|
| TRACEME(("retrieve_code (#%d)", (int)cxt->tagnum)); |
| 6669 |
|
| |
| 6670 |
|
| /* |
| 6671 |
|
| * Insert dummy SV in the aseen array so that we don't screw |
| 6672 |
|
| * up the tag numbers. We would just make the internal |
| 6673 |
|
| * scalar an untagged item in the stream, but |
| 6674 |
|
| * retrieve_scalar() calls SEEN(). So we just increase the |
| 6675 |
|
| * tag number. |
| 6676 |
|
| */ |
| 6677 |
63 |
| tagnum = cxt->tagnum; |
| 6678 |
63 |
| sv = newSViv(0); |
| 6679 |
63 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
5 |
58 |
63 |
|
| 6680 |
63 |
▶ | SEEN_NN(sv, stash, 0); |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); |
0 |
63 |
63 |
| SEEN_NN(sv, stash, 0); |
5 |
58 |
63 |
| SEEN_NN(sv, stash, 0); |
5 |
0 |
5 |
| SEEN_NN(sv, stash, 0); |
0 |
5 |
5 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
|
| 6681 |
|
| |
| 6682 |
|
| /* |
| 6683 |
|
| * Retrieve the source of the code reference |
| 6684 |
|
| * as a small or large scalar |
| 6685 |
|
| */ |
| 6686 |
|
| |
| 6687 |
63 |
▶ | GETMARK(type); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(type); |
48 |
15 |
63 |
| GETMARK(type); |
48 |
0 |
48 |
| GETMARK(type); |
0 |
15 |
15 |
|
| 6688 |
63 |
| switch (type) { |
| 6689 |
53 |
| case SX_SCALAR: |
| 6690 |
53 |
| text = retrieve_scalar(aTHX_ cxt, cname); |
| 6691 |
53 |
| break; |
| 6692 |
3 |
| case SX_LSCALAR: |
| 6693 |
3 |
| text = retrieve_lscalar(aTHX_ cxt, cname); |
| 6694 |
3 |
| break; |
| 6695 |
2 |
| case SX_UTF8STR: |
| 6696 |
2 |
| text = retrieve_utf8str(aTHX_ cxt, cname); |
| 6697 |
2 |
| break; |
| 6698 |
5 |
| case SX_LUTF8STR: |
| 6699 |
5 |
| text = retrieve_lutf8str(aTHX_ cxt, cname); |
| 6700 |
5 |
| break; |
| 6701 |
0 |
| default: |
| 6702 |
0 |
| CROAK(("Unexpected type %d in retrieve_code\n", (int)type)); |
| 6703 |
|
| } |
| 6704 |
|
| |
| 6705 |
63 |
▶ | if (!text) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!text) { |
1 |
62 |
63 |
|
| 6706 |
1 |
| CROAK(("Unable to retrieve code\n")); |
| 6707 |
|
| } |
| 6708 |
|
| |
| 6709 |
|
| /* |
| 6710 |
|
| * prepend "sub " to the source |
| 6711 |
|
| */ |
| 6712 |
|
| |
| 6713 |
62 |
| sub = newSVpvs("sub "); |
| 6714 |
62 |
▶ | if (SvUTF8(text)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(text)) |
7 |
55 |
62 |
|
| 6715 |
7 |
| SvUTF8_on(sub); |
| 6716 |
62 |
| sv_catpv(sub, SvPV_nolen(text)); /* XXX no sv_catsv! */ |
| 6717 |
62 |
| SvREFCNT_dec(text); |
| 6718 |
|
| |
| 6719 |
|
| /* |
| 6720 |
|
| * evaluate the source to a code reference and use the CV value |
| 6721 |
|
| */ |
| 6722 |
|
| |
| 6723 |
62 |
▶ | if (cxt->eval == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->eval == NULL) { |
37 |
25 |
62 |
|
| 6724 |
37 |
| cxt->eval = get_sv("Storable::Eval", GV_ADD); |
| 6725 |
37 |
| SvREFCNT_inc(cxt->eval); |
| 6726 |
|
| } |
| 6727 |
62 |
▶ | if (!SvTRUE(cxt->eval)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvTRUE(cxt->eval)) { |
7 |
55 |
62 |
|
| 6728 |
7 |
▶ | if (cxt->forgive_me == 0 || |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->forgive_me == 0 || |
7 |
0 |
7 |
|
| 6729 |
7 |
▶ | (cxt->forgive_me < 0 && |
Branch: 1 branch
| Branch | True | False | Total |
| (cxt->forgive_me < 0 && |
7 |
0 |
7 |
|
| 6730 |
7 |
| !(cxt->forgive_me = SvTRUE |
| 6731 |
7 |
▶ | (get_sv("Storable::forgive_me", GV_ADD)) ? 1 : 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| (get_sv("Storable::forgive_me", GV_ADD)) ? 1 : 0)) |
2 |
5 |
7 |
|
| 6732 |
|
| ) { |
| 6733 |
2 |
| CROAK(("Can't eval, please set $Storable::Eval to a true value")); |
| 6734 |
|
| } else { |
| 6735 |
5 |
| sv = newSVsv(sub); |
| 6736 |
|
| /* fix up the dummy entry... */ |
| 6737 |
5 |
| av_store(cxt->aseen, tagnum, SvREFCNT_inc(sv)); |
| 6738 |
5 |
| return sv; |
| 6739 |
|
| } |
| 6740 |
|
| } |
| 6741 |
|
| |
| 6742 |
55 |
| ENTER; |
| 6743 |
55 |
| SAVETMPS; |
| 6744 |
|
| |
| 6745 |
55 |
| errsv = get_sv("@", GV_ADD); |
| 6746 |
55 |
| SvPVCLEAR(errsv); /* clear $@ */ |
| 6747 |
55 |
▶ | if (SvROK(cxt->eval) && SvTYPE(SvRV(cxt->eval)) == SVt_PVCV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(cxt->eval) && SvTYPE(SvRV(cxt->eval)) == SVt_PVCV) { |
11 |
44 |
55 |
| if (SvROK(cxt->eval) && SvTYPE(SvRV(cxt->eval)) == SVt_PVCV) { |
11 |
0 |
11 |
|
| 6748 |
11 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
11 |
11 |
|
| 6749 |
11 |
▶ | XPUSHs(sv_2mortal(newSVsv(sub))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVsv(sub))); |
0 |
11 |
11 |
|
| 6750 |
11 |
| PUTBACK; |
| 6751 |
11 |
| count = call_sv(cxt->eval, G_SCALAR); |
| 6752 |
11 |
▶ | if (count != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count != 1) |
0 |
11 |
11 |
|
| 6753 |
0 |
| CROAK(("Unexpected return value from $Storable::Eval callback\n")); |
| 6754 |
|
| } else { |
| 6755 |
44 |
| eval_sv(sub, G_SCALAR); |
| 6756 |
|
| } |
| 6757 |
55 |
| SPAGAIN; |
| 6758 |
55 |
| cv = POPs; |
| 6759 |
55 |
| PUTBACK; |
| 6760 |
|
| |
| 6761 |
55 |
▶ | if (SvTRUE(errsv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(errsv)) { |
2 |
53 |
55 |
|
| 6762 |
6 |
▶ | CROAK(("code %s caused an error: %s", |
Branch: 1 branch
| Branch | True | False | Total |
| CROAK(("code %s caused an error: %s", |
2 |
0 |
2 |
|
| 6763 |
|
| SvPV_nolen(sub), SvPV_nolen(errsv))); |
| 6764 |
|
| } |
| 6765 |
|
| |
| 6766 |
53 |
▶ | if (cv && SvROK(cv) && SvTYPE(SvRV(cv)) == SVt_PVCV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (cv && SvROK(cv) && SvTYPE(SvRV(cv)) == SVt_PVCV) { |
53 |
0 |
53 |
| if (cv && SvROK(cv) && SvTYPE(SvRV(cv)) == SVt_PVCV) { |
53 |
0 |
53 |
| if (cv && SvROK(cv) && SvTYPE(SvRV(cv)) == SVt_PVCV) { |
53 |
0 |
53 |
|
| 6767 |
53 |
| sv = SvRV(cv); |
| 6768 |
|
| } else { |
| 6769 |
0 |
| CROAK(("code %s did not evaluate to a subroutine reference\n", |
| 6770 |
|
| SvPV_nolen(sub))); |
| 6771 |
|
| } |
| 6772 |
|
| |
| 6773 |
53 |
| SvREFCNT_inc(sv); /* XXX seems to be necessary */ |
| 6774 |
53 |
| SvREFCNT_dec(sub); |
| 6775 |
|
| |
| 6776 |
53 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
53 |
0 |
53 |
|
| 6777 |
53 |
| LEAVE; |
| 6778 |
|
| /* fix up the dummy entry... */ |
| 6779 |
53 |
| av_store(cxt->aseen, tagnum, SvREFCNT_inc(sv)); |
| 6780 |
|
| |
| 6781 |
53 |
| return sv; |
| 6782 |
|
| } |
| 6783 |
|
| |
| 6784 |
41 |
| static SV *retrieve_regexp(pTHX_ stcxt_t *cxt, const char *cname) { |
| 6785 |
|
| #if PERL_VERSION_GE(5,8,0) |
| 6786 |
|
| int op_flags; |
| 6787 |
|
| U32 re_len; |
| 6788 |
|
| STRLEN flags_len; |
| 6789 |
|
| SV *re; |
| 6790 |
|
| SV *flags; |
| 6791 |
|
| SV *re_ref; |
| 6792 |
|
| SV *sv; |
| 6793 |
41 |
| dSP; |
| 6794 |
|
| I32 count; |
| 6795 |
|
| HV *stash; |
| 6796 |
|
| |
| 6797 |
41 |
| ENTER; |
| 6798 |
41 |
| SAVETMPS; |
| 6799 |
|
| |
| 6800 |
41 |
▶ | GETMARK(op_flags); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(op_flags); |
41 |
0 |
41 |
| GETMARK(op_flags); |
41 |
0 |
41 |
| GETMARK(op_flags); |
0 |
0 |
0 |
|
| 6801 |
41 |
▶ | if (op_flags & SHR_U32_RE_LEN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (op_flags & SHR_U32_RE_LEN) { |
0 |
41 |
41 |
|
| 6802 |
0 |
▶ | RLEN(re_len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(re_len); |
0 |
0 |
0 |
| RLEN(re_len); |
0 |
0 |
0 |
| RLEN(re_len); |
0 |
0 |
0 |
| RLEN(re_len); |
0 |
0 |
0 |
| RLEN(re_len); |
0 |
0 |
0 |
|
| 6803 |
|
| } |
| 6804 |
|
| else |
| 6805 |
41 |
▶ | GETMARK(re_len); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(re_len); |
41 |
0 |
41 |
| GETMARK(re_len); |
41 |
0 |
41 |
| GETMARK(re_len); |
0 |
0 |
0 |
|
| 6806 |
|
| |
| 6807 |
41 |
▶ | re = sv_2mortal(NEWSV(10002, re_len ? re_len : 1)); |
Branch: 1 branch
| Branch | True | False | Total |
| re = sv_2mortal(NEWSV(10002, re_len ? re_len : 1)); |
39 |
2 |
41 |
|
| 6808 |
41 |
▶ | READ(SvPVX(re), re_len); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(SvPVX(re), re_len); |
41 |
0 |
41 |
| READ(SvPVX(re), re_len); |
41 |
0 |
41 |
| READ(SvPVX(re), re_len); |
0 |
0 |
0 |
|
| 6809 |
41 |
| SvCUR_set(re, re_len); |
| 6810 |
41 |
| *SvEND(re) = '\0'; |
| 6811 |
41 |
| SvPOK_only(re); |
| 6812 |
|
| |
| 6813 |
41 |
▶ | GETMARK(flags_len); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(flags_len); |
41 |
0 |
41 |
| GETMARK(flags_len); |
41 |
0 |
41 |
| GETMARK(flags_len); |
0 |
0 |
0 |
|
| 6814 |
41 |
▶ | flags = sv_2mortal(NEWSV(10002, flags_len ? flags_len : 1)); |
Branch: 1 branch
| Branch | True | False | Total |
| flags = sv_2mortal(NEWSV(10002, flags_len ? flags_len : 1)); |
23 |
18 |
41 |
|
| 6815 |
41 |
▶ | READ(SvPVX(flags), flags_len); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(SvPVX(flags), flags_len); |
41 |
0 |
41 |
| READ(SvPVX(flags), flags_len); |
41 |
0 |
41 |
| READ(SvPVX(flags), flags_len); |
0 |
0 |
0 |
|
| 6816 |
41 |
| SvCUR_set(flags, flags_len); |
| 6817 |
41 |
| *SvEND(flags) = '\0'; |
| 6818 |
41 |
| SvPOK_only(flags); |
| 6819 |
|
| |
| 6820 |
41 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
41 |
41 |
|
| 6821 |
|
| |
| 6822 |
41 |
▶ | XPUSHs(re); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(re); |
0 |
41 |
41 |
|
| 6823 |
41 |
▶ | XPUSHs(flags); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(flags); |
0 |
41 |
41 |
|
| 6824 |
|
| |
| 6825 |
41 |
| PUTBACK; |
| 6826 |
|
| |
| 6827 |
41 |
| count = call_pv("Storable::_make_re", G_SCALAR); |
| 6828 |
|
| |
| 6829 |
40 |
| SPAGAIN; |
| 6830 |
|
| |
| 6831 |
40 |
▶ | if (count != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count != 1) |
0 |
40 |
40 |
|
| 6832 |
0 |
| CROAK(("Bad count %d calling _make_re", (int)count)); |
| 6833 |
|
| |
| 6834 |
40 |
| re_ref = POPs; |
| 6835 |
|
| |
| 6836 |
40 |
| PUTBACK; |
| 6837 |
|
| |
| 6838 |
40 |
▶ | if (!SvROK(re_ref)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(re_ref)) |
0 |
40 |
40 |
|
| 6839 |
0 |
| CROAK(("_make_re didn't return a reference")); |
| 6840 |
|
| |
| 6841 |
40 |
| sv = SvRV(re_ref); |
| 6842 |
40 |
| SvREFCNT_inc(sv); |
| 6843 |
40 |
▶ | stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| stash = cname ? gv_stashpv(cname, GV_ADD) : 0; |
40 |
0 |
40 |
|
| 6844 |
40 |
▶ | SEEN_NN(sv, stash, 0); |
Branch: 13 branches
| Branch | True | False | Total |
| SEEN_NN(sv, stash, 0); |
0 |
40 |
40 |
| SEEN_NN(sv, stash, 0); |
40 |
0 |
40 |
| SEEN_NN(sv, stash, 0); |
40 |
0 |
40 |
| SEEN_NN(sv, stash, 0); |
0 |
40 |
40 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
| SEEN_NN(sv, stash, 0); |
0 |
0 |
0 |
|
| 6845 |
|
| |
| 6846 |
40 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
40 |
0 |
40 |
|
| 6847 |
40 |
| LEAVE; |
| 6848 |
|
| |
| 6849 |
40 |
| return sv; |
| 6850 |
|
| #else |
| 6851 |
|
| CROAK(("retrieve_regexp does not work with 5.6 or earlier")); |
| 6852 |
|
| #endif |
| 6853 |
|
| } |
| 6854 |
|
| |
| 6855 |
|
| /* |
| 6856 |
|
| * old_retrieve_array |
| 6857 |
|
| * |
| 6858 |
|
| * Retrieve a whole array in pre-0.6 binary format. |
| 6859 |
|
| * |
| 6860 |
|
| * Layout is SX_ARRAY <size> followed by each item, in increasing index order. |
| 6861 |
|
| * Each item is stored as SX_ITEM <object> or SX_IT_UNDEF for "holes". |
| 6862 |
|
| * |
| 6863 |
|
| * When we come here, SX_ARRAY has been read already. |
| 6864 |
|
| */ |
| 6865 |
1 |
| static SV *old_retrieve_array(pTHX_ stcxt_t *cxt, const char *cname) |
| 6866 |
|
| { |
| 6867 |
|
| I32 len; |
| 6868 |
|
| I32 i; |
| 6869 |
|
| AV *av; |
| 6870 |
|
| SV *sv; |
| 6871 |
|
| int c; |
| 6872 |
|
| |
| 6873 |
|
| PERL_UNUSED_ARG(cname); |
| 6874 |
|
| TRACEME(("old_retrieve_array (#%d)", (int)cxt->tagnum)); |
| 6875 |
|
| |
| 6876 |
|
| /* |
| 6877 |
|
| * Read length, and allocate array, then pre-extend it. |
| 6878 |
|
| */ |
| 6879 |
|
| |
| 6880 |
1 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
0 |
1 |
1 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
1 |
1 |
| RLEN(len); |
1 |
0 |
1 |
|
| 6881 |
|
| TRACEME(("size = %d", (int)len)); |
| 6882 |
1 |
| av = newAV(); |
| 6883 |
1 |
▶ | SEEN0_NN(av, 0); /* Will return if array not allocated nicely */ |
Branch: 1 branch
| Branch | True | False | Total |
| SEEN0_NN(av, 0); /* Will return if array not allocated nicely */ |
0 |
1 |
1 |
|
| 6884 |
1 |
▶ | if (len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len) |
1 |
0 |
1 |
|
| 6885 |
1 |
| av_extend(av, len); |
| 6886 |
|
| else |
| 6887 |
0 |
| return (SV *) av; /* No data follow if array is empty */ |
| 6888 |
|
| |
| 6889 |
|
| /* |
| 6890 |
|
| * Now get each item in turn... |
| 6891 |
|
| */ |
| 6892 |
|
| |
| 6893 |
1 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
1 |
0 |
1 |
|
| 6894 |
1 |
▶ | GETMARK(c); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(c); |
0 |
1 |
1 |
| GETMARK(c); |
0 |
0 |
0 |
| GETMARK(c); |
0 |
1 |
1 |
|
| 6895 |
1 |
▶ | if (c == SX_IT_UNDEF) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == SX_IT_UNDEF) { |
0 |
1 |
1 |
|
| 6896 |
|
| TRACEME(("(#%d) undef item", (int)i)); |
| 6897 |
0 |
| continue; /* av_extend() already filled us with undef */ |
| 6898 |
|
| } |
| 6899 |
1 |
▶ | if (c != SX_ITEM) |
Branch: 1 branch
| Branch | True | False | Total |
| if (c != SX_ITEM) |
1 |
0 |
1 |
|
| 6900 |
1 |
| (void) retrieve_other(aTHX_ cxt, 0);/* Will croak out */ |
| 6901 |
|
| TRACEME(("(#%d) item", (int)i)); |
| 6902 |
0 |
| sv = retrieve(aTHX_ cxt, 0); /* Retrieve item */ |
| 6903 |
0 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
0 |
0 |
|
| 6904 |
0 |
| return (SV *) 0; |
| 6905 |
0 |
▶ | if (av_store(av, i, sv) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_store(av, i, sv) == 0) |
0 |
0 |
0 |
|
| 6906 |
0 |
| return (SV *) 0; |
| 6907 |
|
| } |
| 6908 |
|
| |
| 6909 |
|
| TRACEME(("ok (old_retrieve_array at 0x%" UVxf ")", PTR2UV(av))); |
| 6910 |
|
| |
| 6911 |
0 |
| return (SV *) av; |
| 6912 |
|
| } |
| 6913 |
|
| |
| 6914 |
|
| /* |
| 6915 |
|
| * old_retrieve_hash |
| 6916 |
|
| * |
| 6917 |
|
| * Retrieve a whole hash table in pre-0.6 binary format. |
| 6918 |
|
| * |
| 6919 |
|
| * Layout is SX_HASH <size> followed by each key/value pair, in random order. |
| 6920 |
|
| * Keys are stored as SX_KEY <length> <data>, the <data> section being omitted |
| 6921 |
|
| * if length is 0. |
| 6922 |
|
| * Values are stored as SX_VALUE <object> or SX_VL_UNDEF for "holes". |
| 6923 |
|
| * |
| 6924 |
|
| * When we come here, SX_HASH has been read already. |
| 6925 |
|
| */ |
| 6926 |
1 |
| static SV *old_retrieve_hash(pTHX_ stcxt_t *cxt, const char *cname) |
| 6927 |
|
| { |
| 6928 |
|
| I32 len; |
| 6929 |
|
| I32 size; |
| 6930 |
|
| I32 i; |
| 6931 |
|
| HV *hv; |
| 6932 |
1 |
| SV *sv = (SV *) 0; |
| 6933 |
|
| int c; |
| 6934 |
1 |
| SV *sv_h_undef = (SV *) 0; /* hv_store() bug */ |
| 6935 |
|
| |
| 6936 |
|
| PERL_UNUSED_ARG(cname); |
| 6937 |
|
| TRACEME(("old_retrieve_hash (#%d)", (int)cxt->tagnum)); |
| 6938 |
|
| |
| 6939 |
|
| /* |
| 6940 |
|
| * Read length, allocate table. |
| 6941 |
|
| */ |
| 6942 |
|
| |
| 6943 |
1 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
0 |
1 |
1 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
1 |
1 |
| RLEN(len); |
1 |
0 |
1 |
|
| 6944 |
|
| TRACEME(("size = %d", (int)len)); |
| 6945 |
1 |
| hv = newHV(); |
| 6946 |
1 |
▶ | SEEN0_NN(hv, 0); /* Will return if table not allocated properly */ |
Branch: 1 branch
| Branch | True | False | Total |
| SEEN0_NN(hv, 0); /* Will return if table not allocated properly */ |
0 |
1 |
1 |
|
| 6947 |
1 |
▶ | if (len == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) |
0 |
1 |
1 |
|
| 6948 |
0 |
| return (SV *) hv; /* No data follow if table empty */ |
| 6949 |
|
| TRACEME(("split %d", (int)len+1)); |
| 6950 |
1 |
| hv_ksplit(hv, len+1); /* pre-extend hash to save multiple splits */ |
| 6951 |
|
| |
| 6952 |
|
| /* |
| 6953 |
|
| * Now get each key/value pair in turn... |
| 6954 |
|
| */ |
| 6955 |
|
| |
| 6956 |
1 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
1 |
0 |
1 |
|
| 6957 |
|
| /* |
| 6958 |
|
| * Get value first. |
| 6959 |
|
| */ |
| 6960 |
|
| |
| 6961 |
1 |
▶ | GETMARK(c); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(c); |
0 |
1 |
1 |
| GETMARK(c); |
0 |
0 |
0 |
| GETMARK(c); |
0 |
1 |
1 |
|
| 6962 |
1 |
▶ | if (c == SX_VL_UNDEF) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == SX_VL_UNDEF) { |
0 |
1 |
1 |
|
| 6963 |
|
| TRACEME(("(#%d) undef value", (int)i)); |
| 6964 |
|
| /* |
| 6965 |
|
| * Due to a bug in hv_store(), it's not possible to pass |
| 6966 |
|
| * &PL_sv_undef to hv_store() as a value, otherwise the |
| 6967 |
|
| * associated key will not be creatable any more. -- RAM, 14/01/97 |
| 6968 |
|
| */ |
| 6969 |
0 |
▶ | if (!sv_h_undef) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_h_undef) |
0 |
0 |
0 |
|
| 6970 |
0 |
| sv_h_undef = newSVsv(&PL_sv_undef); |
| 6971 |
0 |
| sv = SvREFCNT_inc(sv_h_undef); |
| 6972 |
1 |
▶ | } else if (c == SX_VALUE) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == SX_VALUE) { |
0 |
1 |
1 |
|
| 6973 |
|
| TRACEME(("(#%d) value", (int)i)); |
| 6974 |
0 |
| sv = retrieve(aTHX_ cxt, 0); |
| 6975 |
0 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
0 |
0 |
|
| 6976 |
0 |
| return (SV *) 0; |
| 6977 |
|
| } else |
| 6978 |
1 |
| (void) retrieve_other(aTHX_ cxt, 0); /* Will croak out */ |
| 6979 |
|
| |
| 6980 |
|
| /* |
| 6981 |
|
| * Get key. |
| 6982 |
|
| * Since we're reading into kbuf, we must ensure we're not |
| 6983 |
|
| * recursing between the read and the hv_store() where it's used. |
| 6984 |
|
| * Hence the key comes after the value. |
| 6985 |
|
| */ |
| 6986 |
|
| |
| 6987 |
0 |
▶ | GETMARK(c); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(c); |
0 |
0 |
0 |
| GETMARK(c); |
0 |
0 |
0 |
| GETMARK(c); |
0 |
0 |
0 |
|
| 6988 |
0 |
▶ | if (c != SX_KEY) |
Branch: 1 branch
| Branch | True | False | Total |
| if (c != SX_KEY) |
0 |
0 |
0 |
|
| 6989 |
0 |
| (void) retrieve_other(aTHX_ cxt, 0); /* Will croak out */ |
| 6990 |
0 |
▶ | RLEN(size); /* Get key size */ |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
| RLEN(size); /* Get key size */ |
0 |
0 |
0 |
|
| 6991 |
0 |
▶ | KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
Branch: 2 branches
| Branch | True | False | Total |
| KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
0 |
0 |
0 |
| KBUFCHK((STRLEN)size); /* Grow hash key read pool if needed */ |
0 |
0 |
0 |
|
| 6992 |
0 |
▶ | if (size) |
Branch: 1 branch
| Branch | True | False | Total |
| if (size) |
0 |
0 |
0 |
|
| 6993 |
0 |
▶ | READ(kbuf, size); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(kbuf, size); |
0 |
0 |
0 |
| READ(kbuf, size); |
0 |
0 |
0 |
| READ(kbuf, size); |
0 |
0 |
0 |
|
| 6994 |
0 |
| kbuf[size] = '\0'; /* Mark string end, just in case */ |
| 6995 |
|
| TRACEME(("(#%d) key '%s'", (int)i, kbuf)); |
| 6996 |
|
| |
| 6997 |
|
| /* |
| 6998 |
|
| * Enter key/value pair into hash table. |
| 6999 |
|
| */ |
| 7000 |
|
| |
| 7001 |
0 |
▶ | if (hv_store(hv, kbuf, (U32) size, sv, 0) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_store(hv, kbuf, (U32) size, sv, 0) == 0) |
0 |
0 |
0 |
|
| 7002 |
0 |
| return (SV *) 0; |
| 7003 |
|
| } |
| 7004 |
|
| |
| 7005 |
|
| TRACEME(("ok (retrieve_hash at 0x%" UVxf ")", PTR2UV(hv))); |
| 7006 |
|
| |
| 7007 |
0 |
| return (SV *) hv; |
| 7008 |
|
| } |
| 7009 |
|
| |
| 7010 |
|
| /*** |
| 7011 |
|
| *** Retrieval engine. |
| 7012 |
|
| ***/ |
| 7013 |
|
| |
| 7014 |
|
| /* |
| 7015 |
|
| * magic_check |
| 7016 |
|
| * |
| 7017 |
|
| * Make sure the stored data we're trying to retrieve has been produced |
| 7018 |
|
| * on an ILP compatible system with the same byteorder. It croaks out in |
| 7019 |
|
| * case an error is detected. [ILP = integer-long-pointer sizes] |
| 7020 |
|
| * Returns null if error is detected, &PL_sv_undef otherwise. |
| 7021 |
|
| * |
| 7022 |
|
| * Note that there's no byte ordering info emitted when network order was |
| 7023 |
|
| * used at store time. |
| 7024 |
|
| */ |
| 7025 |
779 |
| static SV *magic_check(pTHX_ stcxt_t *cxt) |
| 7026 |
|
| { |
| 7027 |
|
| /* The worst case for a malicious header would be old magic (which is |
| 7028 |
|
| longer), major, minor, byteorder length byte of 255, 255 bytes of |
| 7029 |
|
| garbage, sizeof int, long, pointer, NV. |
| 7030 |
|
| So the worse of that we can read is 255 bytes of garbage plus 4. |
| 7031 |
|
| Err, I am assuming 8 bit bytes here. Please file a bug report if you're |
| 7032 |
|
| compiling perl on a system with chars that are larger than 8 bits. |
| 7033 |
|
| (Even Crays aren't *that* perverse). |
| 7034 |
|
| */ |
| 7035 |
|
| unsigned char buf[4 + 255]; |
| 7036 |
|
| unsigned char *current; |
| 7037 |
|
| int c; |
| 7038 |
|
| int length; |
| 7039 |
|
| int use_network_order; |
| 7040 |
|
| int use_NV_size; |
| 7041 |
779 |
| int old_magic = 0; |
| 7042 |
|
| int version_major; |
| 7043 |
779 |
| int version_minor = 0; |
| 7044 |
|
| |
| 7045 |
|
| TRACEME(("magic_check")); |
| 7046 |
|
| |
| 7047 |
|
| /* |
| 7048 |
|
| * The "magic number" is only for files, not when freezing in memory. |
| 7049 |
|
| */ |
| 7050 |
|
| |
| 7051 |
779 |
▶ | if (cxt->fio) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->fio) { |
201 |
578 |
779 |
|
| 7052 |
|
| /* This includes the '\0' at the end. I want to read the extra byte, |
| 7053 |
|
| which is usually going to be the major version number. */ |
| 7054 |
201 |
| STRLEN len = sizeof(magicstr); |
| 7055 |
|
| STRLEN old_len; |
| 7056 |
|
| |
| 7057 |
201 |
▶ | READ(buf, (SSize_t)(len)); /* Not null-terminated */ |
Branch: 3 branches
| Branch | True | False | Total |
| READ(buf, (SSize_t)(len)); /* Not null-terminated */ |
0 |
201 |
201 |
| READ(buf, (SSize_t)(len)); /* Not null-terminated */ |
0 |
0 |
0 |
| READ(buf, (SSize_t)(len)); /* Not null-terminated */ |
11 |
190 |
201 |
|
| 7058 |
|
| |
| 7059 |
|
| /* Point at the byte after the byte we read. */ |
| 7060 |
190 |
| current = buf + --len; /* Do the -- outside of macros. */ |
| 7061 |
|
| |
| 7062 |
190 |
▶ | if (memNE(buf, magicstr, len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (memNE(buf, magicstr, len)) { |
2 |
188 |
190 |
|
| 7063 |
|
| /* |
| 7064 |
|
| * Try to read more bytes to check for the old magic number, which |
| 7065 |
|
| * was longer. |
| 7066 |
|
| */ |
| 7067 |
|
| |
| 7068 |
|
| TRACEME(("trying for old magic number")); |
| 7069 |
|
| |
| 7070 |
2 |
| old_len = sizeof(old_magicstr) - 1; |
| 7071 |
2 |
▶ | READ(current + 1, (SSize_t)(old_len - len)); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(current + 1, (SSize_t)(old_len - len)); |
0 |
2 |
2 |
| READ(current + 1, (SSize_t)(old_len - len)); |
0 |
0 |
0 |
| READ(current + 1, (SSize_t)(old_len - len)); |
0 |
2 |
2 |
|
| 7072 |
|
| |
| 7073 |
2 |
▶ | if (memNE(buf, old_magicstr, old_len)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (memNE(buf, old_magicstr, old_len)) |
2 |
0 |
2 |
|
| 7074 |
2 |
| CROAK(("File is not a perl storable")); |
| 7075 |
0 |
| old_magic++; |
| 7076 |
0 |
| current = buf + old_len; |
| 7077 |
|
| } |
| 7078 |
188 |
| use_network_order = *current; |
| 7079 |
|
| } else { |
| 7080 |
578 |
▶ | GETMARK(use_network_order); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(use_network_order); |
578 |
0 |
578 |
| GETMARK(use_network_order); |
576 |
2 |
578 |
| GETMARK(use_network_order); |
0 |
0 |
0 |
|
| 7081 |
|
| } |
| 7082 |
|
| |
| 7083 |
|
| /* |
| 7084 |
|
| * Starting with 0.6, the "use_network_order" byte flag is also used to |
| 7085 |
|
| * indicate the version number of the binary, and therefore governs the |
| 7086 |
|
| * setting of sv_retrieve_vtbl. See magic_write(). |
| 7087 |
|
| */ |
| 7088 |
764 |
▶ | if (old_magic && use_network_order > 1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (old_magic && use_network_order > 1) { |
0 |
764 |
764 |
| if (old_magic && use_network_order > 1) { |
0 |
0 |
0 |
|
| 7089 |
|
| /* 0.1 dump - use_network_order is really byte order length */ |
| 7090 |
0 |
| version_major = -1; |
| 7091 |
|
| } |
| 7092 |
|
| else { |
| 7093 |
764 |
| version_major = use_network_order >> 1; |
| 7094 |
|
| } |
| 7095 |
764 |
▶ | cxt->retrieve_vtbl = (SV*(**)(pTHX_ stcxt_t *cxt, const char *cname)) (version_major > 0 ? sv_retrieve : sv_old_retrieve); |
Branch: 1 branch
| Branch | True | False | Total |
| cxt->retrieve_vtbl = (SV*(**)(pTHX_ stcxt_t *cxt, const char *cname)) (version_major > 0 ? sv_retrieve : sv_old_retrieve); |
762 |
2 |
764 |
|
| 7096 |
|
| |
| 7097 |
|
| TRACEME(("magic_check: netorder = 0x%x", use_network_order)); |
| 7098 |
|
| |
| 7099 |
|
| |
| 7100 |
|
| /* |
| 7101 |
|
| * Starting with 0.7 (binary major 2), a full byte is dedicated to the |
| 7102 |
|
| * minor version of the protocol. See magic_write(). |
| 7103 |
|
| */ |
| 7104 |
|
| |
| 7105 |
764 |
▶ | if (version_major > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (version_major > 1) |
761 |
3 |
764 |
|
| 7106 |
761 |
▶ | GETMARK(version_minor); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(version_minor); |
575 |
186 |
761 |
| GETMARK(version_minor); |
573 |
2 |
575 |
| GETMARK(version_minor); |
2 |
184 |
186 |
|
| 7107 |
|
| |
| 7108 |
760 |
| cxt->ver_major = version_major; |
| 7109 |
760 |
| cxt->ver_minor = version_minor; |
| 7110 |
|
| |
| 7111 |
|
| TRACEME(("binary image version is %d.%d", version_major, version_minor)); |
| 7112 |
|
| |
| 7113 |
|
| /* |
| 7114 |
|
| * Inter-operability sanity check: we can't retrieve something stored |
| 7115 |
|
| * using a format more recent than ours, because we have no way to |
| 7116 |
|
| * know what has changed, and letting retrieval go would mean a probable |
| 7117 |
|
| * failure reporting a "corrupted" storable file. |
| 7118 |
|
| */ |
| 7119 |
|
| |
| 7120 |
760 |
▶ | if ( |
Branch: 1 branch
| Branch | True | False | Total |
| if ( |
750 |
10 |
760 |
|
| 7121 |
750 |
▶ | version_major > STORABLE_BIN_MAJOR || |
Branch: 1 branch
| Branch | True | False | Total |
| version_major > STORABLE_BIN_MAJOR || |
747 |
3 |
750 |
|
| 7122 |
747 |
▶ | (version_major == STORABLE_BIN_MAJOR && |
Branch: 1 branch
| Branch | True | False | Total |
| (version_major == STORABLE_BIN_MAJOR && |
16 |
731 |
747 |
|
| 7123 |
|
| version_minor > STORABLE_BIN_MINOR) |
| 7124 |
|
| ) { |
| 7125 |
26 |
| int croak_now = 1; |
| 7126 |
|
| TRACEME(("but I am version is %d.%d", STORABLE_BIN_MAJOR, |
| 7127 |
|
| STORABLE_BIN_MINOR)); |
| 7128 |
|
| |
| 7129 |
26 |
▶ | if (version_major == STORABLE_BIN_MAJOR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (version_major == STORABLE_BIN_MAJOR) { |
16 |
10 |
26 |
|
| 7130 |
|
| TRACEME(("cxt->accept_future_minor is %d", |
| 7131 |
|
| cxt->accept_future_minor)); |
| 7132 |
16 |
▶ | if (cxt->accept_future_minor < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->accept_future_minor < 0) |
16 |
0 |
16 |
|
| 7133 |
|
| cxt->accept_future_minor |
| 7134 |
16 |
| = (SvTRUE(get_sv("Storable::accept_future_minor", |
| 7135 |
|
| GV_ADD)) |
| 7136 |
16 |
| ? 1 : 0); |
| 7137 |
16 |
▶ | if (cxt->accept_future_minor == 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->accept_future_minor == 1) |
8 |
8 |
16 |
|
| 7138 |
8 |
| croak_now = 0; /* Don't croak yet. */ |
| 7139 |
|
| } |
| 7140 |
26 |
▶ | if (croak_now) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (croak_now) { |
18 |
8 |
26 |
|
| 7141 |
18 |
| CROAK(("Storable binary image v%d.%d more recent than I am (v%d.%d)", |
| 7142 |
|
| version_major, version_minor, |
| 7143 |
|
| STORABLE_BIN_MAJOR, STORABLE_BIN_MINOR)); |
| 7144 |
|
| } |
| 7145 |
|
| } |
| 7146 |
|
| |
| 7147 |
|
| /* |
| 7148 |
|
| * If they stored using network order, there's no byte ordering |
| 7149 |
|
| * information to check. |
| 7150 |
|
| */ |
| 7151 |
|
| |
| 7152 |
742 |
▶ | if ((cxt->netorder = (use_network_order & 0x1))) /* Extra () for -Wall */ |
Branch: 1 branch
| Branch | True | False | Total |
| if ((cxt->netorder = (use_network_order & 0x1))) /* Extra () for -Wall */ |
167 |
575 |
742 |
|
| 7153 |
167 |
| return &PL_sv_undef; /* No byte ordering info */ |
| 7154 |
|
| |
| 7155 |
|
| /* In C truth is 1, falsehood is 0. Very convenient. */ |
| 7156 |
575 |
▶ | use_NV_size = version_major >= 2 && version_minor >= 2; |
Branch: 2 branches
| Branch | True | False | Total |
| use_NV_size = version_major >= 2 && version_minor >= 2; |
575 |
0 |
575 |
| use_NV_size = version_major >= 2 && version_minor >= 2; |
575 |
0 |
575 |
|
| 7157 |
|
| |
| 7158 |
575 |
▶ | if (version_major >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (version_major >= 0) { |
575 |
0 |
575 |
|
| 7159 |
575 |
▶ | GETMARK(c); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(c); |
470 |
105 |
575 |
| GETMARK(c); |
469 |
1 |
470 |
| GETMARK(c); |
1 |
104 |
105 |
|
| 7160 |
|
| } |
| 7161 |
|
| else { |
| 7162 |
0 |
| c = use_network_order; |
| 7163 |
|
| } |
| 7164 |
573 |
| length = c + 3 + use_NV_size; |
| 7165 |
573 |
▶ | READ(buf, length); /* Not null-terminated */ |
Branch: 3 branches
| Branch | True | False | Total |
| READ(buf, length); /* Not null-terminated */ |
469 |
104 |
573 |
| READ(buf, length); /* Not null-terminated */ |
457 |
12 |
469 |
| READ(buf, length); /* Not null-terminated */ |
12 |
92 |
104 |
|
| 7166 |
|
| |
| 7167 |
|
| TRACEME(("byte order '%.*s' %d", c, buf, c)); |
| 7168 |
|
| |
| 7169 |
|
| #ifdef USE_56_INTERWORK_KLUDGE |
| 7170 |
|
| /* No point in caching this in the context as we only need it once per |
| 7171 |
|
| retrieve, and we need to recheck it each read. */ |
| 7172 |
|
| if (SvTRUE(get_sv("Storable::interwork_56_64bit", GV_ADD))) { |
| 7173 |
|
| if ((c != (sizeof (byteorderstr_56) - 1)) |
| 7174 |
|
| || memNE(buf, byteorderstr_56, c)) |
| 7175 |
|
| CROAK(("Byte order is not compatible")); |
| 7176 |
|
| } else |
| 7177 |
|
| #endif |
| 7178 |
|
| { |
| 7179 |
549 |
▶ | if ((c != (sizeof (byteorderstr) - 1)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((c != (sizeof (byteorderstr) - 1)) |
549 |
0 |
549 |
|
| 7180 |
549 |
▶ | || memNE(buf, byteorderstr, c)) |
Branch: 1 branch
| Branch | True | False | Total |
| || memNE(buf, byteorderstr, c)) |
2 |
547 |
549 |
|
| 7181 |
2 |
| CROAK(("Byte order is not compatible")); |
| 7182 |
|
| } |
| 7183 |
|
| |
| 7184 |
547 |
| current = buf + c; |
| 7185 |
|
| |
| 7186 |
|
| /* sizeof(int) */ |
| 7187 |
547 |
▶ | if ((int) *current++ != sizeof(int)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((int) *current++ != sizeof(int)) |
2 |
545 |
547 |
|
| 7188 |
2 |
| CROAK(("Integer size is not compatible")); |
| 7189 |
|
| |
| 7190 |
|
| /* sizeof(long) */ |
| 7191 |
545 |
▶ | if ((int) *current++ != sizeof(long)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((int) *current++ != sizeof(long)) |
2 |
543 |
545 |
|
| 7192 |
2 |
| CROAK(("Long integer size is not compatible")); |
| 7193 |
|
| |
| 7194 |
|
| /* sizeof(char *) */ |
| 7195 |
543 |
▶ | if ((int) *current != sizeof(char *)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((int) *current != sizeof(char *)) |
2 |
541 |
543 |
|
| 7196 |
2 |
| CROAK(("Pointer size is not compatible")); |
| 7197 |
|
| |
| 7198 |
541 |
▶ | if (use_NV_size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (use_NV_size) { |
541 |
0 |
541 |
|
| 7199 |
|
| /* sizeof(NV) */ |
| 7200 |
541 |
▶ | if ((int) *++current != sizeof(NV)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((int) *++current != sizeof(NV)) |
2 |
539 |
541 |
|
| 7201 |
2 |
| CROAK(("Double size is not compatible")); |
| 7202 |
|
| } |
| 7203 |
|
| |
| 7204 |
539 |
| return &PL_sv_undef; /* OK */ |
| 7205 |
|
| } |
| 7206 |
|
| |
| 7207 |
|
| /* |
| 7208 |
|
| * retrieve |
| 7209 |
|
| * |
| 7210 |
|
| * Recursively retrieve objects from the specified file and return their |
| 7211 |
|
| * root SV (which may be an AV or an HV for what we care). |
| 7212 |
|
| * Returns null if there is a problem. |
| 7213 |
|
| */ |
| 7214 |
126603 |
| static SV *retrieve(pTHX_ stcxt_t *cxt, const char *cname) |
| 7215 |
|
| { |
| 7216 |
|
| int type; |
| 7217 |
|
| SV **svh; |
| 7218 |
|
| SV *sv; |
| 7219 |
|
| |
| 7220 |
|
| TRACEME(("retrieve")); |
| 7221 |
|
| |
| 7222 |
|
| /* |
| 7223 |
|
| * Grab address tag which identifies the object if we are retrieving |
| 7224 |
|
| * an older format. Since the new binary format counts objects and no |
| 7225 |
|
| * longer explicitly tags them, we must keep track of the correspondence |
| 7226 |
|
| * ourselves. |
| 7227 |
|
| * |
| 7228 |
|
| * The following section will disappear one day when the old format is |
| 7229 |
|
| * no longer supported, hence the final "goto" in the "if" block. |
| 7230 |
|
| */ |
| 7231 |
|
| |
| 7232 |
126603 |
▶ | if (cxt->hseen) { /* Retrieving old binary */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->hseen) { /* Retrieving old binary */ |
2 |
126601 |
126603 |
|
| 7233 |
|
| stag_t tag; |
| 7234 |
2 |
▶ | if (cxt->netorder) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->netorder) { |
2 |
0 |
2 |
|
| 7235 |
|
| I32 nettag; |
| 7236 |
2 |
▶ | READ(&nettag, sizeof(I32)); /* Ordered sequence of I32 */ |
Branch: 3 branches
| Branch | True | False | Total |
| READ(&nettag, sizeof(I32)); /* Ordered sequence of I32 */ |
0 |
2 |
2 |
| READ(&nettag, sizeof(I32)); /* Ordered sequence of I32 */ |
0 |
0 |
0 |
| READ(&nettag, sizeof(I32)); /* Ordered sequence of I32 */ |
0 |
2 |
2 |
|
| 7237 |
2 |
| tag = (stag_t) nettag; |
| 7238 |
|
| } else |
| 7239 |
0 |
▶ | READ(&tag, sizeof(stag_t)); /* Original address of the SV */ |
Branch: 3 branches
| Branch | True | False | Total |
| READ(&tag, sizeof(stag_t)); /* Original address of the SV */ |
0 |
0 |
0 |
| READ(&tag, sizeof(stag_t)); /* Original address of the SV */ |
0 |
0 |
0 |
| READ(&tag, sizeof(stag_t)); /* Original address of the SV */ |
0 |
0 |
0 |
|
| 7240 |
|
| |
| 7241 |
2 |
▶ | GETMARK(type); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(type); |
0 |
2 |
2 |
| GETMARK(type); |
0 |
0 |
0 |
| GETMARK(type); |
0 |
2 |
2 |
|
| 7242 |
2 |
▶ | if (type == SX_OBJECT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (type == SX_OBJECT) { |
0 |
2 |
2 |
|
| 7243 |
|
| I32 tagn; |
| 7244 |
0 |
| svh = hv_fetch(cxt->hseen, (char *) &tag, sizeof(tag), FALSE); |
| 7245 |
0 |
▶ | if (!svh) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!svh) |
0 |
0 |
0 |
|
| 7246 |
0 |
| CROAK(("Old tag 0x%" UVxf " should have been mapped already", |
| 7247 |
|
| (UV) tag)); |
| 7248 |
0 |
| tagn = SvIV(*svh); /* Mapped tag number computed earlier below */ |
| 7249 |
|
| |
| 7250 |
|
| /* |
| 7251 |
|
| * The following code is common with the SX_OBJECT case below. |
| 7252 |
|
| */ |
| 7253 |
|
| |
| 7254 |
0 |
| svh = av_fetch(cxt->aseen, tagn, FALSE); |
| 7255 |
0 |
▶ | if (!svh) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!svh) |
0 |
0 |
0 |
|
| 7256 |
0 |
| CROAK(("Object #%" IVdf " should have been retrieved already", |
| 7257 |
|
| (IV) tagn)); |
| 7258 |
0 |
| sv = *svh; |
| 7259 |
|
| TRACEME(("has retrieved #%d at 0x%" UVxf, (int)tagn, PTR2UV(sv))); |
| 7260 |
0 |
| SvREFCNT_inc(sv); /* One more reference to this same sv */ |
| 7261 |
0 |
| return sv; /* The SV pointer where object was retrieved */ |
| 7262 |
|
| } |
| 7263 |
|
| |
| 7264 |
|
| /* |
| 7265 |
|
| * Map new object, but don't increase tagnum. This will be done |
| 7266 |
|
| * by each of the retrieve_* functions when they call SEEN(). |
| 7267 |
|
| * |
| 7268 |
|
| * The mapping associates the "tag" initially present with a unique |
| 7269 |
|
| * tag number. See test for SX_OBJECT above to see how this is perused. |
| 7270 |
|
| */ |
| 7271 |
|
| |
| 7272 |
2 |
▶ | if (!hv_store(cxt->hseen, (char *) &tag, sizeof(tag), |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_store(cxt->hseen, (char *) &tag, sizeof(tag), |
0 |
2 |
2 |
|
| 7273 |
|
| newSViv(cxt->tagnum), 0)) |
| 7274 |
0 |
| return (SV *) 0; |
| 7275 |
|
| |
| 7276 |
2 |
| goto first_time; |
| 7277 |
|
| } |
| 7278 |
|
| |
| 7279 |
|
| /* |
| 7280 |
|
| * Regular post-0.6 binary format. |
| 7281 |
|
| */ |
| 7282 |
|
| |
| 7283 |
126601 |
▶ | GETMARK(type); |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(type); |
126160 |
441 |
126601 |
| GETMARK(type); |
126156 |
4 |
126160 |
| GETMARK(type); |
4 |
437 |
441 |
|
| 7284 |
|
| |
| 7285 |
|
| TRACEME(("retrieve type = %d", type)); |
| 7286 |
|
| |
| 7287 |
|
| /* |
| 7288 |
|
| * Are we dealing with an object we should have already retrieved? |
| 7289 |
|
| */ |
| 7290 |
|
| |
| 7291 |
126593 |
▶ | if (type == SX_OBJECT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (type == SX_OBJECT) { |
102 |
126491 |
126593 |
|
| 7292 |
|
| I32 tag; |
| 7293 |
102 |
▶ | READ_I32(tag); |
Branch: 4 branches
| Branch | True | False | Total |
| READ_I32(tag); |
80 |
22 |
102 |
| READ_I32(tag); |
80 |
0 |
80 |
| READ_I32(tag); |
25 |
55 |
80 |
| READ_I32(tag); |
0 |
22 |
22 |
|
| 7294 |
102 |
| tag = ntohl(tag); |
| 7295 |
|
| #ifndef HAS_U64 |
| 7296 |
|
| /* A 32-bit system can't have over 2**31 objects anyway */ |
| 7297 |
|
| if (tag < 0) |
| 7298 |
|
| CROAK(("Object #%" IVdf " out of range", (IV)tag)); |
| 7299 |
|
| #endif |
| 7300 |
|
| /* Older versions of Storable on with 64-bit support on 64-bit |
| 7301 |
|
| systems can produce values above the 2G boundary (or wrapped above |
| 7302 |
|
| the 4G boundary, which we can't do much about), treat those as |
| 7303 |
|
| unsigned. |
| 7304 |
|
| This same commit stores tag ids over the 2G boundary as long tags |
| 7305 |
|
| since older Storables will mis-handle them as short tags. |
| 7306 |
|
| */ |
| 7307 |
102 |
| svh = av_fetch(cxt->aseen, (U32)tag, FALSE); |
| 7308 |
102 |
▶ | if (!svh) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!svh) |
0 |
102 |
102 |
|
| 7309 |
0 |
| CROAK(("Object #%" IVdf " should have been retrieved already", |
| 7310 |
|
| (IV) tag)); |
| 7311 |
102 |
| sv = *svh; |
| 7312 |
|
| TRACEME(("had retrieved #%d at 0x%" UVxf, (int)tag, PTR2UV(sv))); |
| 7313 |
102 |
| SvREFCNT_inc(sv); /* One more reference to this same sv */ |
| 7314 |
102 |
| return sv; /* The SV pointer where object was retrieved */ |
| 7315 |
126491 |
▶ | } else if (type >= SX_LAST && cxt->ver_minor > STORABLE_BIN_MINOR) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (type >= SX_LAST && cxt->ver_minor > STORABLE_BIN_MINOR) { |
12 |
126479 |
126491 |
| } else if (type >= SX_LAST && cxt->ver_minor > STORABLE_BIN_MINOR) { |
8 |
4 |
12 |
|
| 7316 |
4 |
▶ | if (cxt->accept_future_minor < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->accept_future_minor < 0) |
4 |
0 |
4 |
|
| 7317 |
|
| cxt->accept_future_minor |
| 7318 |
4 |
| = (SvTRUE(get_sv("Storable::accept_future_minor", |
| 7319 |
|
| GV_ADD)) |
| 7320 |
4 |
| ? 1 : 0); |
| 7321 |
4 |
▶ | if (cxt->accept_future_minor == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->accept_future_minor == 1) { |
0 |
4 |
4 |
|
| 7322 |
4 |
| CROAK(("Storable binary image v%d.%d contains data of type %d. " |
| 7323 |
|
| "This Storable is v%d.%d and can only handle data types up to %d", |
| 7324 |
|
| cxt->ver_major, cxt->ver_minor, type, |
| 7325 |
|
| STORABLE_BIN_MAJOR, STORABLE_BIN_MINOR, SX_LAST - 1)); |
| 7326 |
|
| } |
| 7327 |
|
| } |
| 7328 |
|
| |
| 7329 |
126487 |
| first_time: /* Will disappear when support for old format is dropped */ |
| 7330 |
|
| |
| 7331 |
|
| /* |
| 7332 |
|
| * Okay, first time through for this one. |
| 7333 |
|
| */ |
| 7334 |
|
| |
| 7335 |
126489 |
▶ | sv = RETRIEVE(cxt, type)(aTHX_ cxt, cname); |
Branch: 1 branch
| Branch | True | False | Total |
| sv = RETRIEVE(cxt, type)(aTHX_ cxt, cname); |
126481 |
8 |
126489 |
|
| 7336 |
126446 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
108 |
126338 |
126446 |
|
| 7337 |
108 |
| return (SV *) 0; /* Failed */ |
| 7338 |
|
| |
| 7339 |
|
| /* |
| 7340 |
|
| * Old binary formats (pre-0.7). |
| 7341 |
|
| * |
| 7342 |
|
| * Final notifications, ended by SX_STORED may now follow. |
| 7343 |
|
| * Currently, the only pertinent notification to apply on the |
| 7344 |
|
| * freshly retrieved object is either: |
| 7345 |
|
| * SX_CLASS <char-len> <classname> for short classnames. |
| 7346 |
|
| * SX_LG_CLASS <int-len> <classname> for larger one (rare!). |
| 7347 |
|
| * Class name is then read into the key buffer pool used by |
| 7348 |
|
| * hash table key retrieval. |
| 7349 |
|
| */ |
| 7350 |
|
| |
| 7351 |
126338 |
▶ | if (cxt->ver_major < 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->ver_major < 2) { |
38 |
126300 |
126338 |
|
| 7352 |
45 |
▶ | while ((type = GETCHAR()) != SX_STORED) { |
Branch: 3 branches
| Branch | True | False | Total |
| while ((type = GETCHAR()) != SX_STORED) { |
0 |
45 |
45 |
| while ((type = GETCHAR()) != SX_STORED) { |
45 |
0 |
45 |
| while ((type = GETCHAR()) != SX_STORED) { |
7 |
38 |
45 |
|
| 7353 |
|
| I32 len; |
| 7354 |
|
| HV* stash; |
| 7355 |
7 |
| switch (type) { |
| 7356 |
7 |
| case SX_CLASS: |
| 7357 |
7 |
▶ | GETMARK(len); /* Length coded on a single char */ |
Branch: 3 branches
| Branch | True | False | Total |
| GETMARK(len); /* Length coded on a single char */ |
7 |
0 |
7 |
| GETMARK(len); /* Length coded on a single char */ |
7 |
0 |
7 |
| GETMARK(len); /* Length coded on a single char */ |
0 |
0 |
0 |
|
| 7358 |
7 |
| break; |
| 7359 |
0 |
| case SX_LG_CLASS: /* Length coded on a regular integer */ |
| 7360 |
0 |
▶ | RLEN(len); |
Branch: 5 branches
| Branch | True | False | Total |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
0 |
0 |
| RLEN(len); |
0 |
0 |
0 |
|
| 7361 |
0 |
| break; |
| 7362 |
0 |
| case EOF: |
| 7363 |
|
| default: |
| 7364 |
0 |
| return (SV *) 0; /* Failed */ |
| 7365 |
|
| } |
| 7366 |
7 |
▶ | KBUFCHK((STRLEN)len); /* Grow buffer as necessary */ |
Branch: 2 branches
| Branch | True | False | Total |
| KBUFCHK((STRLEN)len); /* Grow buffer as necessary */ |
0 |
7 |
7 |
| KBUFCHK((STRLEN)len); /* Grow buffer as necessary */ |
0 |
0 |
0 |
|
| 7367 |
7 |
▶ | if (len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len) |
7 |
0 |
7 |
|
| 7368 |
7 |
▶ | READ(kbuf, len); |
Branch: 3 branches
| Branch | True | False | Total |
| READ(kbuf, len); |
7 |
0 |
7 |
| READ(kbuf, len); |
7 |
0 |
7 |
| READ(kbuf, len); |
0 |
0 |
0 |
|
| 7369 |
7 |
| kbuf[len] = '\0'; /* Mark string end */ |
| 7370 |
7 |
| stash = gv_stashpvn(kbuf, len, GV_ADD); |
| 7371 |
7 |
▶ | BLESS(sv, stash); |
Branch: 11 branches
| Branch | True | False | Total |
| BLESS(sv, stash); |
7 |
0 |
7 |
| BLESS(sv, stash); |
0 |
7 |
7 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
| BLESS(sv, stash); |
0 |
0 |
0 |
|
| 7372 |
|
| } |
| 7373 |
|
| } |
| 7374 |
|
| |
| 7375 |
|
| TRACEME(("ok (retrieved 0x%" UVxf ", refcnt=%d, %s)", PTR2UV(sv), |
| 7376 |
|
| (int)SvREFCNT(sv) - 1, sv_reftype(sv, FALSE))); |
| 7377 |
|
| |
| 7378 |
126338 |
| return sv; /* Ok */ |
| 7379 |
|
| } |
| 7380 |
|
| |
| 7381 |
|
| /* |
| 7382 |
|
| * do_retrieve |
| 7383 |
|
| * |
| 7384 |
|
| * Retrieve data held in file and return the root object. |
| 7385 |
|
| * Common routine for pretrieve and mretrieve. |
| 7386 |
|
| */ |
| 7387 |
780 |
| static SV *do_retrieve( |
| 7388 |
|
| pTHX_ |
| 7389 |
|
| PerlIO *f, |
| 7390 |
|
| SV *in, |
| 7391 |
|
| int optype, |
| 7392 |
|
| int flags) |
| 7393 |
|
| { |
| 7394 |
780 |
| dSTCXT; |
| 7395 |
|
| SV *sv; |
| 7396 |
|
| int is_tainted; /* Is input source tainted? */ |
| 7397 |
780 |
| int pre_06_fmt = 0; /* True with pre Storable 0.6 formats */ |
| 7398 |
|
| |
| 7399 |
|
| TRACEMED(("do_retrieve (optype = 0x%x, flags=0x%x)", |
| 7400 |
|
| (unsigned)optype, (unsigned)flags)); |
| 7401 |
|
| |
| 7402 |
780 |
| optype |= ST_RETRIEVE; |
| 7403 |
780 |
| cxt->flags = flags; |
| 7404 |
|
| |
| 7405 |
|
| /* |
| 7406 |
|
| * Sanity assertions for retrieve dispatch tables. |
| 7407 |
|
| */ |
| 7408 |
|
| |
| 7409 |
|
| ASSERT(sizeof(sv_old_retrieve) == sizeof(sv_retrieve), |
| 7410 |
|
| ("old and new retrieve dispatch table have same size")); |
| 7411 |
|
| ASSERT(sv_old_retrieve[(int)SX_LAST] == retrieve_other, |
| 7412 |
|
| ("SX_LAST entry correctly initialized in old dispatch table")); |
| 7413 |
|
| ASSERT(sv_retrieve[(int)SX_LAST] == retrieve_other, |
| 7414 |
|
| ("SX_LAST entry correctly initialized in new dispatch table")); |
| 7415 |
|
| |
| 7416 |
|
| /* |
| 7417 |
|
| * Workaround for CROAK leak: if they enter with a "dirty" context, |
| 7418 |
|
| * free up memory for them now. |
| 7419 |
|
| */ |
| 7420 |
|
| |
| 7421 |
|
| assert(cxt); |
| 7422 |
780 |
▶ | if (cxt->s_dirty) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->s_dirty) |
89 |
691 |
780 |
|
| 7423 |
89 |
| clean_context(aTHX_ cxt); |
| 7424 |
|
| |
| 7425 |
|
| /* |
| 7426 |
|
| * Now that STORABLE_xxx hooks exist, it is possible that they try to |
| 7427 |
|
| * re-enter retrieve() via the hooks. |
| 7428 |
|
| */ |
| 7429 |
|
| |
| 7430 |
780 |
▶ | if (cxt->entry) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->entry) { |
46 |
734 |
780 |
|
| 7431 |
46 |
| cxt = allocate_context(aTHX_ cxt); |
| 7432 |
46 |
| cxt->flags = flags; |
| 7433 |
|
| } |
| 7434 |
|
| INIT_TRACEME; |
| 7435 |
|
| |
| 7436 |
780 |
| cxt->entry++; |
| 7437 |
|
| |
| 7438 |
|
| ASSERT(cxt->entry == 1, ("starting new recursion")); |
| 7439 |
|
| ASSERT(!cxt->s_dirty, ("clean context")); |
| 7440 |
|
| |
| 7441 |
|
| /* |
| 7442 |
|
| * Prepare context. |
| 7443 |
|
| * |
| 7444 |
|
| * Data is loaded into the memory buffer when f is NULL, unless 'in' is |
| 7445 |
|
| * also NULL, in which case we're expecting the data to already lie |
| 7446 |
|
| * in the buffer (dclone case). |
| 7447 |
|
| */ |
| 7448 |
|
| |
| 7449 |
780 |
▶ | KBUFINIT(); /* Allocate hash key reading pool once */ |
Branch: 1 branch
| Branch | True | False | Total |
| KBUFINIT(); /* Allocate hash key reading pool once */ |
119 |
661 |
780 |
|
| 7450 |
|
| |
| 7451 |
780 |
▶ | if (!f && in) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!f && in) { |
579 |
201 |
780 |
| if (!f && in) { |
377 |
202 |
579 |
|
| 7452 |
|
| #ifdef SvUTF8_on |
| 7453 |
377 |
▶ | if (SvUTF8(in)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(in)) { |
2 |
375 |
377 |
|
| 7454 |
|
| STRLEN length; |
| 7455 |
2 |
| const char *orig = SvPV(in, length); |
| 7456 |
|
| char *asbytes; |
| 7457 |
|
| /* This is quite deliberate. I want the UTF8 routines |
| 7458 |
|
| to encounter the '\0' which perl adds at the end |
| 7459 |
|
| of all scalars, so that any new string also has |
| 7460 |
|
| this. |
| 7461 |
|
| */ |
| 7462 |
2 |
| STRLEN klen_tmp = length + 1; |
| 7463 |
2 |
| bool is_utf8 = TRUE; |
| 7464 |
|
| |
| 7465 |
|
| /* Just casting the &klen to (STRLEN) won't work |
| 7466 |
|
| well if STRLEN and I32 are of different widths. |
| 7467 |
|
| --jhi */ |
| 7468 |
2 |
| asbytes = (char*)bytes_from_utf8((U8*)orig, |
| 7469 |
|
| &klen_tmp, |
| 7470 |
|
| &is_utf8); |
| 7471 |
2 |
▶ | if (is_utf8) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_utf8) { |
1 |
1 |
2 |
|
| 7472 |
1 |
| CROAK(("Frozen string corrupt - contains characters outside 0-255")); |
| 7473 |
|
| } |
| 7474 |
1 |
▶ | if (asbytes != orig) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (asbytes != orig) { |
1 |
0 |
1 |
|
| 7475 |
|
| /* String has been converted. |
| 7476 |
|
| There is no need to keep any reference to |
| 7477 |
|
| the old string. */ |
| 7478 |
1 |
| in = sv_newmortal(); |
| 7479 |
|
| /* We donate the SV the malloc()ed string |
| 7480 |
|
| bytes_from_utf8 returned us. */ |
| 7481 |
1 |
▶ | SvUPGRADE(in, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(in, SVt_PV); |
1 |
0 |
1 |
|
| 7482 |
1 |
| SvPOK_on(in); |
| 7483 |
1 |
| SvPV_set(in, asbytes); |
| 7484 |
1 |
| SvLEN_set(in, klen_tmp); |
| 7485 |
1 |
| SvCUR_set(in, klen_tmp - 1); |
| 7486 |
|
| } |
| 7487 |
|
| } |
| 7488 |
|
| #endif |
| 7489 |
752 |
▶ | MBUF_SAVE_AND_LOAD(in); |
Branch: 1 branch
| Branch | True | False | Total |
| MBUF_SAVE_AND_LOAD(in); |
0 |
376 |
376 |
|
| 7490 |
|
| } |
| 7491 |
|
| |
| 7492 |
|
| /* |
| 7493 |
|
| * Magic number verifications. |
| 7494 |
|
| * |
| 7495 |
|
| * This needs to be done before calling init_retrieve_context() |
| 7496 |
|
| * since the format indication in the file are necessary to conduct |
| 7497 |
|
| * some of the initializations. |
| 7498 |
|
| */ |
| 7499 |
|
| |
| 7500 |
779 |
| cxt->fio = f; /* Where I/O are performed */ |
| 7501 |
|
| |
| 7502 |
779 |
▶ | if (!magic_check(aTHX_ cxt)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!magic_check(aTHX_ cxt)) |
43 |
706 |
749 |
|
| 7503 |
43 |
▶ | CROAK(("Magic number checking on storable %s failed", |
Branch: 1 branch
| Branch | True | False | Total |
| CROAK(("Magic number checking on storable %s failed", |
26 |
17 |
43 |
|
| 7504 |
|
| cxt->fio ? "file" : "string")); |
| 7505 |
|
| |
| 7506 |
|
| TRACEME(("data stored in %s format", |
| 7507 |
|
| cxt->netorder ? "net order" : "native")); |
| 7508 |
|
| |
| 7509 |
|
| /* |
| 7510 |
|
| * Check whether input source is tainted, so that we don't wrongly |
| 7511 |
|
| * taint perfectly good values... |
| 7512 |
|
| * |
| 7513 |
|
| * We assume file input is always tainted. If both 'f' and 'in' are |
| 7514 |
|
| * NULL, then we come from dclone, and tainted is already filled in |
| 7515 |
|
| * the context. That's a kludge, but the whole dclone() thing is |
| 7516 |
|
| * already quite a kludge anyway! -- RAM, 15/09/2000. |
| 7517 |
|
| */ |
| 7518 |
|
| |
| 7519 |
706 |
▶ | is_tainted = f ? 1 : (in ? SvTAINTED(in) : cxt->s_tainted); |
Branch: 4 branches
| Branch | True | False | Total |
| is_tainted = f ? 1 : (in ? SvTAINTED(in) : cxt->s_tainted); |
546 |
160 |
706 |
| is_tainted = f ? 1 : (in ? SvTAINTED(in) : cxt->s_tainted); |
344 |
202 |
546 |
| is_tainted = f ? 1 : (in ? SvTAINTED(in) : cxt->s_tainted); |
0 |
344 |
344 |
| is_tainted = f ? 1 : (in ? SvTAINTED(in) : cxt->s_tainted); |
0 |
0 |
0 |
|
| 7520 |
|
| TRACEME(("input source is %s", is_tainted ? "tainted" : "trusted")); |
| 7521 |
706 |
| init_retrieve_context(aTHX_ cxt, optype, is_tainted); |
| 7522 |
|
| |
| 7523 |
|
| ASSERT(is_retrieving(aTHX), ("within retrieve operation")); |
| 7524 |
|
| |
| 7525 |
706 |
| sv = retrieve(aTHX_ cxt, 0); /* Recursively retrieve object, get root SV */ |
| 7526 |
|
| |
| 7527 |
|
| /* |
| 7528 |
|
| * Final cleanup. |
| 7529 |
|
| */ |
| 7530 |
|
| |
| 7531 |
669 |
▶ | if (!f && in) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!f && in) |
523 |
146 |
669 |
| if (!f && in) |
322 |
201 |
523 |
|
| 7532 |
322 |
| MBUF_RESTORE(); |
| 7533 |
|
| |
| 7534 |
669 |
| pre_06_fmt = cxt->hseen != NULL; /* Before we clean context */ |
| 7535 |
|
| |
| 7536 |
|
| /* |
| 7537 |
|
| * The "root" context is never freed. |
| 7538 |
|
| */ |
| 7539 |
|
| |
| 7540 |
669 |
| clean_retrieve_context(aTHX_ cxt); |
| 7541 |
669 |
▶ | if (cxt->prev) /* This context was stacked */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->prev) /* This context was stacked */ |
78 |
591 |
669 |
|
| 7542 |
78 |
| free_context(aTHX_ cxt); /* It was not the "root" context */ |
| 7543 |
|
| |
| 7544 |
|
| /* |
| 7545 |
|
| * Prepare returned value. |
| 7546 |
|
| */ |
| 7547 |
|
| |
| 7548 |
669 |
▶ | if (!sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) { |
88 |
581 |
669 |
|
| 7549 |
|
| TRACEMED(("retrieve ERROR")); |
| 7550 |
88 |
| return &PL_sv_undef; /* Something went wrong, return undef */ |
| 7551 |
|
| } |
| 7552 |
|
| |
| 7553 |
|
| TRACEMED(("retrieve got %s(0x%" UVxf ")", |
| 7554 |
|
| sv_reftype(sv, FALSE), PTR2UV(sv))); |
| 7555 |
|
| |
| 7556 |
|
| /* |
| 7557 |
|
| * Backward compatibility with Storable-0.5@9 (which we know we |
| 7558 |
|
| * are retrieving if hseen is non-null): don't create an extra RV |
| 7559 |
|
| * for objects since we special-cased it at store time. |
| 7560 |
|
| * |
| 7561 |
|
| * Build a reference to the SV returned by pretrieve even if it is |
| 7562 |
|
| * already one and not a scalar, for consistency reasons. |
| 7563 |
|
| */ |
| 7564 |
|
| |
| 7565 |
581 |
▶ | if (pre_06_fmt) { /* Was not handling overloading by then */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (pre_06_fmt) { /* Was not handling overloading by then */ |
0 |
581 |
581 |
|
| 7566 |
|
| SV *rv; |
| 7567 |
|
| TRACEMED(("fixing for old formats -- pre 0.6")); |
| 7568 |
0 |
▶ | if (sv_type(aTHX_ sv) == svis_REF && (rv = SvRV(sv)) && SvOBJECT(rv)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (sv_type(aTHX_ sv) == svis_REF && (rv = SvRV(sv)) && SvOBJECT(rv)) { |
0 |
0 |
0 |
| if (sv_type(aTHX_ sv) == svis_REF && (rv = SvRV(sv)) && SvOBJECT(rv)) { |
0 |
0 |
0 |
| if (sv_type(aTHX_ sv) == svis_REF && (rv = SvRV(sv)) && SvOBJECT(rv)) { |
0 |
0 |
0 |
|
| 7569 |
|
| TRACEME(("ended do_retrieve() with an object -- pre 0.6")); |
| 7570 |
0 |
| return sv; |
| 7571 |
|
| } |
| 7572 |
|
| } |
| 7573 |
|
| |
| 7574 |
|
| /* |
| 7575 |
|
| * If reference is overloaded, restore behaviour. |
| 7576 |
|
| * |
| 7577 |
|
| * NB: minor glitch here: normally, overloaded refs are stored specially |
| 7578 |
|
| * so that we can croak when behaviour cannot be re-installed, and also |
| 7579 |
|
| * avoid testing for overloading magic at each reference retrieval. |
| 7580 |
|
| * |
| 7581 |
|
| * Unfortunately, the root reference is implicitly stored, so we must |
| 7582 |
|
| * check for possible overloading now. Furthermore, if we don't restore |
| 7583 |
|
| * overloading, we cannot croak as if the original ref was, because we |
| 7584 |
|
| * have no way to determine whether it was an overloaded ref or not in |
| 7585 |
|
| * the first place. |
| 7586 |
|
| * |
| 7587 |
|
| * It's a pity that overloading magic is attached to the rv, and not to |
| 7588 |
|
| * the underlying sv as blessing is. |
| 7589 |
|
| */ |
| 7590 |
|
| |
| 7591 |
581 |
▶ | if (SvOBJECT(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOBJECT(sv)) { |
111 |
470 |
581 |
|
| 7592 |
111 |
| HV *stash = (HV *) SvSTASH(sv); |
| 7593 |
111 |
| SV *rv = newRV_noinc(sv); |
| 7594 |
111 |
▶ | if (stash && Gv_AMG(stash)) { |
Branch: 10 branches
| Branch | True | False | Total |
| if (stash && Gv_AMG(stash)) { |
111 |
0 |
111 |
| if (stash && Gv_AMG(stash)) { |
111 |
0 |
111 |
| if (stash && Gv_AMG(stash)) { |
111 |
0 |
111 |
| if (stash && Gv_AMG(stash)) { |
0 |
111 |
111 |
| if (stash && Gv_AMG(stash)) { |
0 |
0 |
0 |
| if (stash && Gv_AMG(stash)) { |
111 |
0 |
111 |
| if (stash && Gv_AMG(stash)) { |
0 |
111 |
111 |
| if (stash && Gv_AMG(stash)) { |
111 |
0 |
111 |
| if (stash && Gv_AMG(stash)) { |
109 |
2 |
111 |
| if (stash && Gv_AMG(stash)) { |
2 |
109 |
111 |
|
| 7595 |
2 |
| SvAMAGIC_on(rv); |
| 7596 |
|
| TRACEMED(("restored overloading on root reference")); |
| 7597 |
|
| } |
| 7598 |
|
| TRACEMED(("ended do_retrieve() with an object")); |
| 7599 |
111 |
| return rv; |
| 7600 |
|
| } |
| 7601 |
|
| |
| 7602 |
|
| TRACEMED(("regular do_retrieve() end")); |
| 7603 |
|
| |
| 7604 |
470 |
| return newRV_noinc(sv); |
| 7605 |
|
| } |
| 7606 |
|
| |
| 7607 |
|
| /* |
| 7608 |
|
| * pretrieve |
| 7609 |
|
| * |
| 7610 |
|
| * Retrieve data held in file and return the root object, undef on error. |
| 7611 |
|
| */ |
| 7612 |
201 |
| static SV *pretrieve(pTHX_ PerlIO *f, IV flag) |
| 7613 |
|
| { |
| 7614 |
|
| TRACEMED(("pretrieve")); |
| 7615 |
201 |
| return do_retrieve(aTHX_ f, Nullsv, 0, (int)flag); |
| 7616 |
|
| } |
| 7617 |
|
| |
| 7618 |
|
| /* |
| 7619 |
|
| * mretrieve |
| 7620 |
|
| * |
| 7621 |
|
| * Retrieve data held in scalar and return the root object, undef on error. |
| 7622 |
|
| */ |
| 7623 |
377 |
| static SV *mretrieve(pTHX_ SV *sv, IV flag) |
| 7624 |
|
| { |
| 7625 |
|
| TRACEMED(("mretrieve")); |
| 7626 |
377 |
| return do_retrieve(aTHX_ (PerlIO*) 0, sv, 0, (int)flag); |
| 7627 |
|
| } |
| 7628 |
|
| |
| 7629 |
|
| /*** |
| 7630 |
|
| *** Deep cloning |
| 7631 |
|
| ***/ |
| 7632 |
|
| |
| 7633 |
|
| /* |
| 7634 |
|
| * dclone |
| 7635 |
|
| * |
| 7636 |
|
| * Deep clone: returns a fresh copy of the original referenced SV tree. |
| 7637 |
|
| * |
| 7638 |
|
| * This is achieved by storing the object in memory and restoring from |
| 7639 |
|
| * there. Not that efficient, but it should be faster than doing it from |
| 7640 |
|
| * pure perl anyway. |
| 7641 |
|
| */ |
| 7642 |
204 |
| static SV *dclone(pTHX_ SV *sv) |
| 7643 |
|
| { |
| 7644 |
204 |
| dSTCXT; |
| 7645 |
|
| STRLEN size; |
| 7646 |
|
| stcxt_t *real_context; |
| 7647 |
|
| SV *out; |
| 7648 |
|
| |
| 7649 |
|
| TRACEMED(("dclone")); |
| 7650 |
|
| |
| 7651 |
|
| /* |
| 7652 |
|
| * Workaround for CROAK leak: if they enter with a "dirty" context, |
| 7653 |
|
| * free up memory for them now. |
| 7654 |
|
| */ |
| 7655 |
|
| |
| 7656 |
|
| assert(cxt); |
| 7657 |
204 |
▶ | if (cxt->s_dirty) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->s_dirty) |
3 |
201 |
204 |
|
| 7658 |
3 |
| clean_context(aTHX_ cxt); |
| 7659 |
|
| |
| 7660 |
|
| /* |
| 7661 |
|
| * Tied elements seem to need special handling. |
| 7662 |
|
| */ |
| 7663 |
|
| |
| 7664 |
204 |
▶ | if ((SvTYPE(sv) == SVt_PVLV |
Branch: 1 branch
| Branch | True | False | Total |
| if ((SvTYPE(sv) == SVt_PVLV |
2 |
202 |
204 |
|
| 7665 |
|
| #if PERL_VERSION_LT(5,8,0) |
| 7666 |
|
| || SvTYPE(sv) == SVt_PVMG |
| 7667 |
|
| #endif |
| 7668 |
2 |
▶ | ) && (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) == |
Branch: 1 branch
| Branch | True | False | Total |
| ) && (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) == |
2 |
0 |
2 |
|
| 7669 |
2 |
▶ | (SVs_GMG|SVs_SMG|SVs_RMG) && |
Branch: 1 branch
| Branch | True | False | Total |
| (SVs_GMG|SVs_SMG|SVs_RMG) && |
2 |
0 |
2 |
|
| 7670 |
2 |
| mg_find(sv, 'p')) { |
| 7671 |
2 |
| mg_get(sv); |
| 7672 |
|
| } |
| 7673 |
|
| |
| 7674 |
|
| /* |
| 7675 |
|
| * do_store() optimizes for dclone by not freeing its context, should |
| 7676 |
|
| * we need to allocate one because we're deep cloning from a hook. |
| 7677 |
|
| */ |
| 7678 |
|
| |
| 7679 |
204 |
▶ | if (!do_store(aTHX_ (PerlIO*) 0, sv, ST_CLONE, FALSE, (SV**) 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!do_store(aTHX_ (PerlIO*) 0, sv, ST_CLONE, FALSE, (SV**) 0)) |
0 |
202 |
202 |
|
| 7680 |
0 |
| return &PL_sv_undef; /* Error during store */ |
| 7681 |
|
| |
| 7682 |
|
| /* |
| 7683 |
|
| * Because of the above optimization, we have to refresh the context, |
| 7684 |
|
| * since a new one could have been allocated and stacked by do_store(). |
| 7685 |
|
| */ |
| 7686 |
|
| |
| 7687 |
202 |
| { dSTCXT; real_context = cxt; } /* Sub-block needed for macro */ |
| 7688 |
202 |
| cxt = real_context; /* And we need this temporary... */ |
| 7689 |
|
| |
| 7690 |
|
| /* |
| 7691 |
|
| * Now, 'cxt' may refer to a new context. |
| 7692 |
|
| */ |
| 7693 |
|
| |
| 7694 |
|
| assert(cxt); |
| 7695 |
|
| ASSERT(!cxt->s_dirty, ("clean context")); |
| 7696 |
|
| ASSERT(!cxt->entry, ("entry will not cause new context allocation")); |
| 7697 |
|
| |
| 7698 |
202 |
| size = MBUF_SIZE(); |
| 7699 |
|
| TRACEME(("dclone stored %ld bytes", (long)size)); |
| 7700 |
202 |
▶ | MBUF_INIT(size); |
Branch: 2 branches
| Branch | True | False | Total |
| MBUF_INIT(size); |
0 |
202 |
202 |
| MBUF_INIT(size); |
202 |
0 |
202 |
|
| 7701 |
|
| |
| 7702 |
|
| /* |
| 7703 |
|
| * Since we're passing do_retrieve() both a NULL file and sv, we need |
| 7704 |
|
| * to pre-compute the taintedness of the input by setting cxt->tainted |
| 7705 |
|
| * to whatever state our own input string was. -- RAM, 15/09/2000 |
| 7706 |
|
| * |
| 7707 |
|
| * do_retrieve() will free non-root context. |
| 7708 |
|
| */ |
| 7709 |
|
| |
| 7710 |
202 |
▶ | cxt->s_tainted = SvTAINTED(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| cxt->s_tainted = SvTAINTED(sv); |
2 |
200 |
202 |
| cxt->s_tainted = SvTAINTED(sv); |
0 |
2 |
2 |
|
| 7711 |
202 |
| out = do_retrieve(aTHX_ (PerlIO*) 0, Nullsv, ST_CLONE, FLAG_BLESS_OK | FLAG_TIE_OK); |
| 7712 |
|
| |
| 7713 |
|
| TRACEMED(("dclone returns 0x%" UVxf, PTR2UV(out))); |
| 7714 |
|
| |
| 7715 |
201 |
| return out; |
| 7716 |
|
| } |
| 7717 |
|
| |
| 7718 |
|
| /*** |
| 7719 |
|
| *** Glue with perl. |
| 7720 |
|
| ***/ |
| 7721 |
|
| |
| 7722 |
|
| /* |
| 7723 |
|
| * The Perl IO GV object distinguishes between input and output for sockets |
| 7724 |
|
| * but not for plain files. To allow Storable to transparently work on |
| 7725 |
|
| * plain files and sockets transparently, we have to ask xsubpp to fetch the |
| 7726 |
|
| * right object for us. Hence the OutputStream and InputStream declarations. |
| 7727 |
|
| * |
| 7728 |
|
| * Before perl 5.004_05, those entries in the standard typemap are not |
| 7729 |
|
| * defined in perl include files, so we do that here. |
| 7730 |
|
| */ |
| 7731 |
|
| |
| 7732 |
|
| #ifndef OutputStream |
| 7733 |
|
| #define OutputStream PerlIO * |
| 7734 |
|
| #define InputStream PerlIO * |
| 7735 |
|
| #endif /* !OutputStream */ |
| 7736 |
|
| |
| 7737 |
|
| static int |
| 7738 |
122 |
| storable_free(pTHX_ SV *sv, MAGIC* mg) { |
| 7739 |
122 |
| stcxt_t *cxt = (stcxt_t *)SvPVX(sv); |
| 7740 |
|
| |
| 7741 |
|
| PERL_UNUSED_ARG(mg); |
| 7742 |
|
| #ifdef USE_PTR_TABLE |
| 7743 |
122 |
▶ | if (cxt->pseen) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxt->pseen) |
0 |
122 |
122 |
|
| 7744 |
0 |
| ptr_table_free(cxt->pseen); |
| 7745 |
|
| #endif |
| 7746 |
122 |
▶ | if (kbuf) |
Branch: 1 branch
| Branch | True | False | Total |
| if (kbuf) |
78 |
44 |
122 |
|
| 7747 |
78 |
| Safefree(kbuf); |
| 7748 |
122 |
▶ | if (!cxt->membuf_ro && mbase) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cxt->membuf_ro && mbase) |
122 |
0 |
122 |
| if (!cxt->membuf_ro && mbase) |
80 |
42 |
122 |
|
| 7749 |
80 |
| Safefree(mbase); |
| 7750 |
122 |
▶ | if (cxt->membuf_ro && (cxt->msaved).arena) |
Branch: 2 branches
| Branch | True | False | Total |
| if (cxt->membuf_ro && (cxt->msaved).arena) |
0 |
122 |
122 |
| if (cxt->membuf_ro && (cxt->msaved).arena) |
0 |
0 |
0 |
|
| 7751 |
0 |
| Safefree((cxt->msaved).arena); |
| 7752 |
122 |
| return 0; |
| 7753 |
|
| } |
| 7754 |
|
| |
| 7755 |
|
| MODULE = Storable PACKAGE = Storable |
| 7756 |
|
| |
| 7757 |
|
| PROTOTYPES: ENABLE |
| 7758 |
|
| |
| 7759 |
|
| BOOT: |
| 7760 |
|
| { |
| 7761 |
46 |
| HV *stash = gv_stashpvn("Storable", 8, GV_ADD); |
| 7762 |
46 |
| newCONSTSUB(stash, "BIN_MAJOR", newSViv(STORABLE_BIN_MAJOR)); |
| 7763 |
46 |
| newCONSTSUB(stash, "BIN_MINOR", newSViv(STORABLE_BIN_MINOR)); |
| 7764 |
46 |
| newCONSTSUB(stash, "BIN_WRITE_MINOR", newSViv(STORABLE_BIN_WRITE_MINOR)); |
| 7765 |
|
| |
| 7766 |
46 |
| newCONSTSUB(stash, "CAN_FLOCK", CAN_FLOCK); |
| 7767 |
|
| |
| 7768 |
46 |
| init_perinterp(aTHX); |
| 7769 |
46 |
| gv_fetchpv("Storable::drop_utf8", GV_ADDMULTI, SVt_PV); |
| 7770 |
|
| #ifdef DEBUGME |
| 7771 |
|
| /* Only disable the used only once warning if we are in debugging mode. */ |
| 7772 |
|
| gv_fetchpv("Storable::DEBUGME", GV_ADDMULTI, SVt_PV); |
| 7773 |
|
| #endif |
| 7774 |
|
| #ifdef USE_56_INTERWORK_KLUDGE |
| 7775 |
|
| gv_fetchpv("Storable::interwork_56_64bit", GV_ADDMULTI, SVt_PV); |
| 7776 |
|
| #endif |
| 7777 |
|
| } |
| 7778 |
|
| |
| 7779 |
|
| void |
| 7780 |
|
| init_perinterp() |
| 7781 |
|
| CODE: |
| 7782 |
0 |
| init_perinterp(aTHX); |
| 7783 |
|
| |
| 7784 |
|
| # pstore |
| 7785 |
|
| # |
| 7786 |
|
| # Store the transitive data closure of given object to disk. |
| 7787 |
|
| # Returns undef on error, a true value otherwise. |
| 7788 |
|
| |
| 7789 |
|
| # net_pstore |
| 7790 |
|
| # |
| 7791 |
|
| # Same as pstore(), but network order is used for integers and doubles are |
| 7792 |
|
| # emitted as strings. |
| 7793 |
|
| |
| 7794 |
|
| SV * |
| 7795 |
|
| pstore(f,obj) |
| 7796 |
|
| OutputStream f |
| 7797 |
|
| SV* obj |
| 7798 |
|
| ALIAS: |
| 7799 |
|
| net_pstore = 1 |
| 7800 |
|
| PPCODE: |
| 7801 |
104 |
▶ | RETVAL = do_store(aTHX_ f, obj, 0, ix, (SV **)0) ? &PL_sv_yes : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = do_store(aTHX_ f, obj, 0, ix, (SV **)0) ? &PL_sv_yes : &PL_sv_undef; |
101 |
0 |
101 |
|
| 7802 |
|
| /* do_store() can reallocate the stack, so need a sequence point to ensure |
| 7803 |
|
| that ST(0) knows about it. Hence using two statements. */ |
| 7804 |
101 |
| ST(0) = RETVAL; |
| 7805 |
101 |
| XSRETURN(1); |
| 7806 |
|
| |
| 7807 |
|
| # mstore |
| 7808 |
|
| # |
| 7809 |
|
| # Store the transitive data closure of given object to memory. |
| 7810 |
|
| # Returns undef on error, a scalar value containing the data otherwise. |
| 7811 |
|
| |
| 7812 |
|
| # net_mstore |
| 7813 |
|
| # |
| 7814 |
|
| # Same as mstore(), but network order is used for integers and doubles are |
| 7815 |
|
| # emitted as strings. |
| 7816 |
|
| |
| 7817 |
|
| SV * |
| 7818 |
|
| mstore(obj) |
| 7819 |
|
| SV* obj |
| 7820 |
|
| ALIAS: |
| 7821 |
|
| net_mstore = 1 |
| 7822 |
|
| CODE: |
| 7823 |
280 |
| RETVAL = &PL_sv_undef; |
| 7824 |
280 |
▶ | if (!do_store(aTHX_ (PerlIO*) 0, obj, 0, ix, &RETVAL)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!do_store(aTHX_ (PerlIO*) 0, obj, 0, ix, &RETVAL)) |
0 |
273 |
273 |
|
| 7825 |
0 |
| RETVAL = &PL_sv_undef; |
| 7826 |
|
| OUTPUT: |
| 7827 |
|
| RETVAL |
| 7828 |
|
| |
| 7829 |
|
| SV * |
| 7830 |
|
| pretrieve(f, flag = 6) |
| 7831 |
|
| InputStream f |
| 7832 |
|
| IV flag |
| 7833 |
|
| CODE: |
| 7834 |
201 |
| RETVAL = pretrieve(aTHX_ f, flag); |
| 7835 |
|
| OUTPUT: |
| 7836 |
|
| RETVAL |
| 7837 |
|
| |
| 7838 |
|
| SV * |
| 7839 |
|
| mretrieve(sv, flag = 6) |
| 7840 |
|
| SV* sv |
| 7841 |
|
| IV flag |
| 7842 |
|
| CODE: |
| 7843 |
377 |
| RETVAL = mretrieve(aTHX_ sv, flag); |
| 7844 |
|
| OUTPUT: |
| 7845 |
|
| RETVAL |
| 7846 |
|
| |
| 7847 |
|
| SV * |
| 7848 |
|
| dclone(sv) |
| 7849 |
|
| SV* sv |
| 7850 |
|
| CODE: |
| 7851 |
204 |
| RETVAL = dclone(aTHX_ sv); |
| 7852 |
|
| OUTPUT: |
| 7853 |
|
| RETVAL |
| 7854 |
|
| |
| 7855 |
|
| SV* |
| 7856 |
|
| last_op_in_netorder() |
| 7857 |
|
| ALIAS: |
| 7858 |
|
| is_storing = ST_STORE |
| 7859 |
|
| is_retrieving = ST_RETRIEVE |
| 7860 |
|
| PREINIT: |
| 7861 |
|
| bool result; |
| 7862 |
|
| CODE: |
| 7863 |
9 |
▶ | if (ix) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix) { |
4 |
5 |
9 |
|
| 7864 |
4 |
| dSTCXT; |
| 7865 |
|
| assert(cxt); |
| 7866 |
4 |
▶ | result = cxt->entry && (cxt->optype & ix) ? TRUE : FALSE; |
Branch: 2 branches
| Branch | True | False | Total |
| result = cxt->entry && (cxt->optype & ix) ? TRUE : FALSE; |
2 |
2 |
4 |
| result = cxt->entry && (cxt->optype & ix) ? TRUE : FALSE; |
2 |
0 |
2 |
|
| 7867 |
|
| } else { |
| 7868 |
5 |
| result = cBOOL(last_op_in_netorder(aTHX)); |
| 7869 |
|
| } |
| 7870 |
9 |
▶ | RETVAL = boolSV(result); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = boolSV(result); |
5 |
4 |
9 |
|
| 7871 |
|
| OUTPUT: RETVAL |
| 7872 |
|
| |
| 7873 |
|
| |
| 7874 |
|
| IV |
| 7875 |
|
| stack_depth() |
| 7876 |
|
| CODE: |
| 7877 |
6 |
| RETVAL = SvIV(get_sv("Storable::recursion_limit", GV_ADD)); |
| 7878 |
|
| OUTPUT: |
| 7879 |
|
| RETVAL |
| 7880 |
|
| |
| 7881 |
|
| IV |
| 7882 |
|
| stack_depth_hash() |
| 7883 |
|
| CODE: |
| 7884 |
3 |
| RETVAL = SvIV(get_sv("Storable::recursion_limit_hash", GV_ADD)); |
| 7885 |
|
| OUTPUT: |
| 7886 |
|
| RETVAL |