-
Notifications
You must be signed in to change notification settings - Fork 0
/
sv.c
8378 lines (7495 loc) · 185 KB
/
sv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* sv.c
*
* Copyright (c) 1991-2000, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
/*
* "I wonder what the Entish is for 'yes' and 'no'," he thought.
*/
#include "EXTERN.h"
#define PERL_IN_SV_C
#include "perl.h"
#define FCALL *f
#define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) sv_force_normal(sv)
static void do_report_used(pTHXo_ SV *sv);
static void do_clean_objs(pTHXo_ SV *sv);
#ifndef DISABLE_DESTRUCTOR_KLUDGE
static void do_clean_named_objs(pTHXo_ SV *sv);
#endif
static void do_clean_all(pTHXo_ SV *sv);
/*
* "A time to plant, and a time to uproot what was planted..."
*/
#define plant_SV(p) \
STMT_START { \
SvANY(p) = (void *)PL_sv_root; \
SvFLAGS(p) = SVTYPEMASK; \
PL_sv_root = (p); \
--PL_sv_count; \
} STMT_END
/* sv_mutex must be held while calling uproot_SV() */
#define uproot_SV(p) \
STMT_START { \
(p) = PL_sv_root; \
PL_sv_root = (SV*)SvANY(p); \
++PL_sv_count; \
} STMT_END
#define new_SV(p) \
STMT_START { \
LOCK_SV_MUTEX; \
if (PL_sv_root) \
uproot_SV(p); \
else \
(p) = more_sv(); \
UNLOCK_SV_MUTEX; \
SvANY(p) = 0; \
SvREFCNT(p) = 1; \
SvFLAGS(p) = 0; \
} STMT_END
#ifdef DEBUGGING
#define del_SV(p) \
STMT_START { \
LOCK_SV_MUTEX; \
if (PL_debug & 32768) \
del_sv(p); \
else \
plant_SV(p); \
UNLOCK_SV_MUTEX; \
} STMT_END
STATIC void
S_del_sv(pTHX_ SV *p)
{
if (PL_debug & 32768) {
SV* sva;
SV* sv;
SV* svend;
int ok = 0;
for (sva = PL_sv_arenaroot; sva; sva = (SV *) SvANY(sva)) {
sv = sva + 1;
svend = &sva[SvREFCNT(sva)];
if (p >= sv && p < svend)
ok = 1;
}
if (!ok) {
if (ckWARN_d(WARN_INTERNAL))
Perl_warner(aTHX_ WARN_INTERNAL,
"Attempt to free non-arena SV: 0x%"UVxf,
PTR2UV(p));
return;
}
}
plant_SV(p);
}
#else /* ! DEBUGGING */
#define del_SV(p) plant_SV(p)
#endif /* DEBUGGING */
void
Perl_sv_add_arena(pTHX_ char *ptr, U32 size, U32 flags)
{
SV* sva = (SV*)ptr;
register SV* sv;
register SV* svend;
Zero(ptr, size, char);
/* The first SV in an arena isn't an SV. */
SvANY(sva) = (void *) PL_sv_arenaroot; /* ptr to next arena */
SvREFCNT(sva) = size / sizeof(SV); /* number of SV slots */
SvFLAGS(sva) = flags; /* FAKE if not to be freed */
PL_sv_arenaroot = sva;
PL_sv_root = sva + 1;
svend = &sva[SvREFCNT(sva) - 1];
sv = sva + 1;
while (sv < svend) {
SvANY(sv) = (void *)(SV*)(sv + 1);
SvFLAGS(sv) = SVTYPEMASK;
sv++;
}
SvANY(sv) = 0;
SvFLAGS(sv) = SVTYPEMASK;
}
/* sv_mutex must be held while calling more_sv() */
STATIC SV*
S_more_sv(pTHX)
{
register SV* sv;
if (PL_nice_chunk) {
sv_add_arena(PL_nice_chunk, PL_nice_chunk_size, 0);
PL_nice_chunk = Nullch;
}
else {
char *chunk; /* must use New here to match call to */
New(704,chunk,1008,char); /* Safefree() in sv_free_arenas() */
sv_add_arena(chunk, 1008, 0);
}
uproot_SV(sv);
return sv;
}
STATIC void
S_visit(pTHX_ SVFUNC_t f)
{
SV* sva;
SV* sv;
register SV* svend;
for (sva = PL_sv_arenaroot; sva; sva = (SV*)SvANY(sva)) {
svend = &sva[SvREFCNT(sva)];
for (sv = sva + 1; sv < svend; ++sv) {
if (SvTYPE(sv) != SVTYPEMASK)
(FCALL)(aTHXo_ sv);
}
}
}
void
Perl_sv_report_used(pTHX)
{
visit(do_report_used);
}
void
Perl_sv_clean_objs(pTHX)
{
PL_in_clean_objs = TRUE;
visit(do_clean_objs);
#ifndef DISABLE_DESTRUCTOR_KLUDGE
/* some barnacles may yet remain, clinging to typeglobs */
visit(do_clean_named_objs);
#endif
PL_in_clean_objs = FALSE;
}
void
Perl_sv_clean_all(pTHX)
{
PL_in_clean_all = TRUE;
visit(do_clean_all);
PL_in_clean_all = FALSE;
}
void
Perl_sv_free_arenas(pTHX)
{
SV* sva;
SV* svanext;
XPV *arena, *arenanext;
/* Free arenas here, but be careful about fake ones. (We assume
contiguity of the fake ones with the corresponding real ones.) */
for (sva = PL_sv_arenaroot; sva; sva = svanext) {
svanext = (SV*) SvANY(sva);
while (svanext && SvFAKE(svanext))
svanext = (SV*) SvANY(svanext);
if (!SvFAKE(sva))
Safefree((void *)sva);
}
for (arena = PL_xiv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xiv_arenaroot = 0;
for (arena = PL_xnv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xnv_arenaroot = 0;
for (arena = PL_xrv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xrv_arenaroot = 0;
for (arena = PL_xpv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpv_arenaroot = 0;
for (arena = (XPV*)PL_xpviv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpviv_arenaroot = 0;
for (arena = (XPV*)PL_xpvnv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpvnv_arenaroot = 0;
for (arena = (XPV*)PL_xpvcv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpvcv_arenaroot = 0;
for (arena = (XPV*)PL_xpvav_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpvav_arenaroot = 0;
for (arena = (XPV*)PL_xpvhv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpvhv_arenaroot = 0;
for (arena = (XPV*)PL_xpvmg_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpvmg_arenaroot = 0;
for (arena = (XPV*)PL_xpvlv_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpvlv_arenaroot = 0;
for (arena = (XPV*)PL_xpvbm_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_xpvbm_arenaroot = 0;
for (arena = (XPV*)PL_he_arenaroot; arena; arena = arenanext) {
arenanext = (XPV*)arena->xpv_pv;
Safefree(arena);
}
PL_he_arenaroot = 0;
if (PL_nice_chunk)
Safefree(PL_nice_chunk);
PL_nice_chunk = Nullch;
PL_nice_chunk_size = 0;
PL_sv_arenaroot = 0;
PL_sv_root = 0;
}
void
Perl_report_uninit(pTHX)
{
if (PL_op)
Perl_warner(aTHX_ WARN_UNINITIALIZED, PL_warn_uninit,
" in ", PL_op_desc[PL_op->op_type]);
else
Perl_warner(aTHX_ WARN_UNINITIALIZED, PL_warn_uninit, "", "");
}
STATIC XPVIV*
S_new_xiv(pTHX)
{
IV* xiv;
LOCK_SV_MUTEX;
if (!PL_xiv_root)
more_xiv();
xiv = PL_xiv_root;
/*
* See comment in more_xiv() -- RAM.
*/
PL_xiv_root = *(IV**)xiv;
UNLOCK_SV_MUTEX;
return (XPVIV*)((char*)xiv - STRUCT_OFFSET(XPVIV, xiv_iv));
}
STATIC void
S_del_xiv(pTHX_ XPVIV *p)
{
IV* xiv = (IV*)((char*)(p) + STRUCT_OFFSET(XPVIV, xiv_iv));
LOCK_SV_MUTEX;
*(IV**)xiv = PL_xiv_root;
PL_xiv_root = xiv;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xiv(pTHX)
{
register IV* xiv;
register IV* xivend;
XPV* ptr;
New(705, ptr, 1008/sizeof(XPV), XPV);
ptr->xpv_pv = (char*)PL_xiv_arenaroot; /* linked list of xiv arenas */
PL_xiv_arenaroot = ptr; /* to keep Purify happy */
xiv = (IV*) ptr;
xivend = &xiv[1008 / sizeof(IV) - 1];
xiv += (sizeof(XPV) - 1) / sizeof(IV) + 1; /* fudge by size of XPV */
PL_xiv_root = xiv;
while (xiv < xivend) {
*(IV**)xiv = (IV *)(xiv + 1);
xiv++;
}
*(IV**)xiv = 0;
}
STATIC XPVNV*
S_new_xnv(pTHX)
{
NV* xnv;
LOCK_SV_MUTEX;
if (!PL_xnv_root)
more_xnv();
xnv = PL_xnv_root;
PL_xnv_root = *(NV**)xnv;
UNLOCK_SV_MUTEX;
return (XPVNV*)((char*)xnv - STRUCT_OFFSET(XPVNV, xnv_nv));
}
STATIC void
S_del_xnv(pTHX_ XPVNV *p)
{
NV* xnv = (NV*)((char*)(p) + STRUCT_OFFSET(XPVNV, xnv_nv));
LOCK_SV_MUTEX;
*(NV**)xnv = PL_xnv_root;
PL_xnv_root = xnv;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xnv(pTHX)
{
register NV* xnv;
register NV* xnvend;
XPV *ptr;
New(711, ptr, 1008/sizeof(XPV), XPV);
ptr->xpv_pv = (char*)PL_xnv_arenaroot;
PL_xnv_arenaroot = ptr;
xnv = (NV*) ptr;
xnvend = &xnv[1008 / sizeof(NV) - 1];
xnv += (sizeof(XPVIV) - 1) / sizeof(NV) + 1; /* fudge by sizeof XPVIV */
PL_xnv_root = xnv;
while (xnv < xnvend) {
*(NV**)xnv = (NV*)(xnv + 1);
xnv++;
}
*(NV**)xnv = 0;
}
STATIC XRV*
S_new_xrv(pTHX)
{
XRV* xrv;
LOCK_SV_MUTEX;
if (!PL_xrv_root)
more_xrv();
xrv = PL_xrv_root;
PL_xrv_root = (XRV*)xrv->xrv_rv;
UNLOCK_SV_MUTEX;
return xrv;
}
STATIC void
S_del_xrv(pTHX_ XRV *p)
{
LOCK_SV_MUTEX;
p->xrv_rv = (SV*)PL_xrv_root;
PL_xrv_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xrv(pTHX)
{
register XRV* xrv;
register XRV* xrvend;
XPV *ptr;
New(712, ptr, 1008/sizeof(XPV), XPV);
ptr->xpv_pv = (char*)PL_xrv_arenaroot;
PL_xrv_arenaroot = ptr;
xrv = (XRV*) ptr;
xrvend = &xrv[1008 / sizeof(XRV) - 1];
xrv += (sizeof(XPV) - 1) / sizeof(XRV) + 1;
PL_xrv_root = xrv;
while (xrv < xrvend) {
xrv->xrv_rv = (SV*)(xrv + 1);
xrv++;
}
xrv->xrv_rv = 0;
}
STATIC XPV*
S_new_xpv(pTHX)
{
XPV* xpv;
LOCK_SV_MUTEX;
if (!PL_xpv_root)
more_xpv();
xpv = PL_xpv_root;
PL_xpv_root = (XPV*)xpv->xpv_pv;
UNLOCK_SV_MUTEX;
return xpv;
}
STATIC void
S_del_xpv(pTHX_ XPV *p)
{
LOCK_SV_MUTEX;
p->xpv_pv = (char*)PL_xpv_root;
PL_xpv_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpv(pTHX)
{
register XPV* xpv;
register XPV* xpvend;
New(713, xpv, 1008/sizeof(XPV), XPV);
xpv->xpv_pv = (char*)PL_xpv_arenaroot;
PL_xpv_arenaroot = xpv;
xpvend = &xpv[1008 / sizeof(XPV) - 1];
PL_xpv_root = ++xpv;
while (xpv < xpvend) {
xpv->xpv_pv = (char*)(xpv + 1);
xpv++;
}
xpv->xpv_pv = 0;
}
STATIC XPVIV*
S_new_xpviv(pTHX)
{
XPVIV* xpviv;
LOCK_SV_MUTEX;
if (!PL_xpviv_root)
more_xpviv();
xpviv = PL_xpviv_root;
PL_xpviv_root = (XPVIV*)xpviv->xpv_pv;
UNLOCK_SV_MUTEX;
return xpviv;
}
STATIC void
S_del_xpviv(pTHX_ XPVIV *p)
{
LOCK_SV_MUTEX;
p->xpv_pv = (char*)PL_xpviv_root;
PL_xpviv_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpviv(pTHX)
{
register XPVIV* xpviv;
register XPVIV* xpvivend;
New(714, xpviv, 1008/sizeof(XPVIV), XPVIV);
xpviv->xpv_pv = (char*)PL_xpviv_arenaroot;
PL_xpviv_arenaroot = xpviv;
xpvivend = &xpviv[1008 / sizeof(XPVIV) - 1];
PL_xpviv_root = ++xpviv;
while (xpviv < xpvivend) {
xpviv->xpv_pv = (char*)(xpviv + 1);
xpviv++;
}
xpviv->xpv_pv = 0;
}
STATIC XPVNV*
S_new_xpvnv(pTHX)
{
XPVNV* xpvnv;
LOCK_SV_MUTEX;
if (!PL_xpvnv_root)
more_xpvnv();
xpvnv = PL_xpvnv_root;
PL_xpvnv_root = (XPVNV*)xpvnv->xpv_pv;
UNLOCK_SV_MUTEX;
return xpvnv;
}
STATIC void
S_del_xpvnv(pTHX_ XPVNV *p)
{
LOCK_SV_MUTEX;
p->xpv_pv = (char*)PL_xpvnv_root;
PL_xpvnv_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpvnv(pTHX)
{
register XPVNV* xpvnv;
register XPVNV* xpvnvend;
New(715, xpvnv, 1008/sizeof(XPVNV), XPVNV);
xpvnv->xpv_pv = (char*)PL_xpvnv_arenaroot;
PL_xpvnv_arenaroot = xpvnv;
xpvnvend = &xpvnv[1008 / sizeof(XPVNV) - 1];
PL_xpvnv_root = ++xpvnv;
while (xpvnv < xpvnvend) {
xpvnv->xpv_pv = (char*)(xpvnv + 1);
xpvnv++;
}
xpvnv->xpv_pv = 0;
}
STATIC XPVCV*
S_new_xpvcv(pTHX)
{
XPVCV* xpvcv;
LOCK_SV_MUTEX;
if (!PL_xpvcv_root)
more_xpvcv();
xpvcv = PL_xpvcv_root;
PL_xpvcv_root = (XPVCV*)xpvcv->xpv_pv;
UNLOCK_SV_MUTEX;
return xpvcv;
}
STATIC void
S_del_xpvcv(pTHX_ XPVCV *p)
{
LOCK_SV_MUTEX;
p->xpv_pv = (char*)PL_xpvcv_root;
PL_xpvcv_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpvcv(pTHX)
{
register XPVCV* xpvcv;
register XPVCV* xpvcvend;
New(716, xpvcv, 1008/sizeof(XPVCV), XPVCV);
xpvcv->xpv_pv = (char*)PL_xpvcv_arenaroot;
PL_xpvcv_arenaroot = xpvcv;
xpvcvend = &xpvcv[1008 / sizeof(XPVCV) - 1];
PL_xpvcv_root = ++xpvcv;
while (xpvcv < xpvcvend) {
xpvcv->xpv_pv = (char*)(xpvcv + 1);
xpvcv++;
}
xpvcv->xpv_pv = 0;
}
STATIC XPVAV*
S_new_xpvav(pTHX)
{
XPVAV* xpvav;
LOCK_SV_MUTEX;
if (!PL_xpvav_root)
more_xpvav();
xpvav = PL_xpvav_root;
PL_xpvav_root = (XPVAV*)xpvav->xav_array;
UNLOCK_SV_MUTEX;
return xpvav;
}
STATIC void
S_del_xpvav(pTHX_ XPVAV *p)
{
LOCK_SV_MUTEX;
p->xav_array = (char*)PL_xpvav_root;
PL_xpvav_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpvav(pTHX)
{
register XPVAV* xpvav;
register XPVAV* xpvavend;
New(717, xpvav, 1008/sizeof(XPVAV), XPVAV);
xpvav->xav_array = (char*)PL_xpvav_arenaroot;
PL_xpvav_arenaroot = xpvav;
xpvavend = &xpvav[1008 / sizeof(XPVAV) - 1];
PL_xpvav_root = ++xpvav;
while (xpvav < xpvavend) {
xpvav->xav_array = (char*)(xpvav + 1);
xpvav++;
}
xpvav->xav_array = 0;
}
STATIC XPVHV*
S_new_xpvhv(pTHX)
{
XPVHV* xpvhv;
LOCK_SV_MUTEX;
if (!PL_xpvhv_root)
more_xpvhv();
xpvhv = PL_xpvhv_root;
PL_xpvhv_root = (XPVHV*)xpvhv->xhv_array;
UNLOCK_SV_MUTEX;
return xpvhv;
}
STATIC void
S_del_xpvhv(pTHX_ XPVHV *p)
{
LOCK_SV_MUTEX;
p->xhv_array = (char*)PL_xpvhv_root;
PL_xpvhv_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpvhv(pTHX)
{
register XPVHV* xpvhv;
register XPVHV* xpvhvend;
New(718, xpvhv, 1008/sizeof(XPVHV), XPVHV);
xpvhv->xhv_array = (char*)PL_xpvhv_arenaroot;
PL_xpvhv_arenaroot = xpvhv;
xpvhvend = &xpvhv[1008 / sizeof(XPVHV) - 1];
PL_xpvhv_root = ++xpvhv;
while (xpvhv < xpvhvend) {
xpvhv->xhv_array = (char*)(xpvhv + 1);
xpvhv++;
}
xpvhv->xhv_array = 0;
}
STATIC XPVMG*
S_new_xpvmg(pTHX)
{
XPVMG* xpvmg;
LOCK_SV_MUTEX;
if (!PL_xpvmg_root)
more_xpvmg();
xpvmg = PL_xpvmg_root;
PL_xpvmg_root = (XPVMG*)xpvmg->xpv_pv;
UNLOCK_SV_MUTEX;
return xpvmg;
}
STATIC void
S_del_xpvmg(pTHX_ XPVMG *p)
{
LOCK_SV_MUTEX;
p->xpv_pv = (char*)PL_xpvmg_root;
PL_xpvmg_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpvmg(pTHX)
{
register XPVMG* xpvmg;
register XPVMG* xpvmgend;
New(719, xpvmg, 1008/sizeof(XPVMG), XPVMG);
xpvmg->xpv_pv = (char*)PL_xpvmg_arenaroot;
PL_xpvmg_arenaroot = xpvmg;
xpvmgend = &xpvmg[1008 / sizeof(XPVMG) - 1];
PL_xpvmg_root = ++xpvmg;
while (xpvmg < xpvmgend) {
xpvmg->xpv_pv = (char*)(xpvmg + 1);
xpvmg++;
}
xpvmg->xpv_pv = 0;
}
STATIC XPVLV*
S_new_xpvlv(pTHX)
{
XPVLV* xpvlv;
LOCK_SV_MUTEX;
if (!PL_xpvlv_root)
more_xpvlv();
xpvlv = PL_xpvlv_root;
PL_xpvlv_root = (XPVLV*)xpvlv->xpv_pv;
UNLOCK_SV_MUTEX;
return xpvlv;
}
STATIC void
S_del_xpvlv(pTHX_ XPVLV *p)
{
LOCK_SV_MUTEX;
p->xpv_pv = (char*)PL_xpvlv_root;
PL_xpvlv_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpvlv(pTHX)
{
register XPVLV* xpvlv;
register XPVLV* xpvlvend;
New(720, xpvlv, 1008/sizeof(XPVLV), XPVLV);
xpvlv->xpv_pv = (char*)PL_xpvlv_arenaroot;
PL_xpvlv_arenaroot = xpvlv;
xpvlvend = &xpvlv[1008 / sizeof(XPVLV) - 1];
PL_xpvlv_root = ++xpvlv;
while (xpvlv < xpvlvend) {
xpvlv->xpv_pv = (char*)(xpvlv + 1);
xpvlv++;
}
xpvlv->xpv_pv = 0;
}
STATIC XPVBM*
S_new_xpvbm(pTHX)
{
XPVBM* xpvbm;
LOCK_SV_MUTEX;
if (!PL_xpvbm_root)
more_xpvbm();
xpvbm = PL_xpvbm_root;
PL_xpvbm_root = (XPVBM*)xpvbm->xpv_pv;
UNLOCK_SV_MUTEX;
return xpvbm;
}
STATIC void
S_del_xpvbm(pTHX_ XPVBM *p)
{
LOCK_SV_MUTEX;
p->xpv_pv = (char*)PL_xpvbm_root;
PL_xpvbm_root = p;
UNLOCK_SV_MUTEX;
}
STATIC void
S_more_xpvbm(pTHX)
{
register XPVBM* xpvbm;
register XPVBM* xpvbmend;
New(721, xpvbm, 1008/sizeof(XPVBM), XPVBM);
xpvbm->xpv_pv = (char*)PL_xpvbm_arenaroot;
PL_xpvbm_arenaroot = xpvbm;
xpvbmend = &xpvbm[1008 / sizeof(XPVBM) - 1];
PL_xpvbm_root = ++xpvbm;
while (xpvbm < xpvbmend) {
xpvbm->xpv_pv = (char*)(xpvbm + 1);
xpvbm++;
}
xpvbm->xpv_pv = 0;
}
#ifdef LEAKTEST
# define my_safemalloc(s) (void*)safexmalloc(717,s)
# define my_safefree(p) safexfree((char*)p)
#else
# define my_safemalloc(s) (void*)safemalloc(s)
# define my_safefree(p) safefree((char*)p)
#endif
#ifdef PURIFY
#define new_XIV() my_safemalloc(sizeof(XPVIV))
#define del_XIV(p) my_safefree(p)
#define new_XNV() my_safemalloc(sizeof(XPVNV))
#define del_XNV(p) my_safefree(p)
#define new_XRV() my_safemalloc(sizeof(XRV))
#define del_XRV(p) my_safefree(p)
#define new_XPV() my_safemalloc(sizeof(XPV))
#define del_XPV(p) my_safefree(p)
#define new_XPVIV() my_safemalloc(sizeof(XPVIV))
#define del_XPVIV(p) my_safefree(p)
#define new_XPVNV() my_safemalloc(sizeof(XPVNV))
#define del_XPVNV(p) my_safefree(p)
#define new_XPVCV() my_safemalloc(sizeof(XPVCV))
#define del_XPVCV(p) my_safefree(p)
#define new_XPVAV() my_safemalloc(sizeof(XPVAV))
#define del_XPVAV(p) my_safefree(p)
#define new_XPVHV() my_safemalloc(sizeof(XPVHV))
#define del_XPVHV(p) my_safefree(p)
#define new_XPVMG() my_safemalloc(sizeof(XPVMG))
#define del_XPVMG(p) my_safefree(p)
#define new_XPVLV() my_safemalloc(sizeof(XPVLV))
#define del_XPVLV(p) my_safefree(p)
#define new_XPVBM() my_safemalloc(sizeof(XPVBM))
#define del_XPVBM(p) my_safefree(p)
#else /* !PURIFY */
#define new_XIV() (void*)new_xiv()
#define del_XIV(p) del_xiv((XPVIV*) p)
#define new_XNV() (void*)new_xnv()
#define del_XNV(p) del_xnv((XPVNV*) p)
#define new_XRV() (void*)new_xrv()
#define del_XRV(p) del_xrv((XRV*) p)
#define new_XPV() (void*)new_xpv()
#define del_XPV(p) del_xpv((XPV *)p)
#define new_XPVIV() (void*)new_xpviv()
#define del_XPVIV(p) del_xpviv((XPVIV *)p)
#define new_XPVNV() (void*)new_xpvnv()
#define del_XPVNV(p) del_xpvnv((XPVNV *)p)
#define new_XPVCV() (void*)new_xpvcv()
#define del_XPVCV(p) del_xpvcv((XPVCV *)p)
#define new_XPVAV() (void*)new_xpvav()
#define del_XPVAV(p) del_xpvav((XPVAV *)p)
#define new_XPVHV() (void*)new_xpvhv()
#define del_XPVHV(p) del_xpvhv((XPVHV *)p)
#define new_XPVMG() (void*)new_xpvmg()
#define del_XPVMG(p) del_xpvmg((XPVMG *)p)
#define new_XPVLV() (void*)new_xpvlv()
#define del_XPVLV(p) del_xpvlv((XPVLV *)p)
#define new_XPVBM() (void*)new_xpvbm()
#define del_XPVBM(p) del_xpvbm((XPVBM *)p)
#endif /* PURIFY */
#define new_XPVGV() my_safemalloc(sizeof(XPVGV))
#define del_XPVGV(p) my_safefree(p)
#define new_XPVFM() my_safemalloc(sizeof(XPVFM))
#define del_XPVFM(p) my_safefree(p)
#define new_XPVIO() my_safemalloc(sizeof(XPVIO))
#define del_XPVIO(p) my_safefree(p)
/*
=for apidoc sv_upgrade
Upgrade an SV to a more complex form. Use C<SvUPGRADE>. See
C<svtype>.
=cut
*/
bool
Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt)
{
char* pv;
U32 cur;
U32 len;
IV iv;
NV nv;
MAGIC* magic;
HV* stash;
if (SvTYPE(sv) == mt)
return TRUE;
if (mt < SVt_PVIV)
(void)SvOOK_off(sv);
switch (SvTYPE(sv)) {
case SVt_NULL:
pv = 0;
cur = 0;
len = 0;
iv = 0;
nv = 0.0;
magic = 0;
stash = 0;
break;
case SVt_IV:
pv = 0;
cur = 0;
len = 0;
iv = SvIVX(sv);
nv = (NV)SvIVX(sv);
del_XIV(SvANY(sv));
magic = 0;
stash = 0;
if (mt == SVt_NV)
mt = SVt_PVNV;
else if (mt < SVt_PVIV)
mt = SVt_PVIV;
break;
case SVt_NV:
pv = 0;
cur = 0;
len = 0;
nv = SvNVX(sv);
iv = I_V(nv);
magic = 0;
stash = 0;
del_XNV(SvANY(sv));
SvANY(sv) = 0;
if (mt < SVt_PVNV)
mt = SVt_PVNV;
break;
case SVt_RV:
pv = (char*)SvRV(sv);
cur = 0;
len = 0;
iv = PTR2IV(pv);
nv = PTR2NV(pv);
del_XRV(SvANY(sv));
magic = 0;
stash = 0;
break;
case SVt_PV:
pv = SvPVX(sv);
cur = SvCUR(sv);
len = SvLEN(sv);
iv = 0;
nv = 0.0;
magic = 0;
stash = 0;
del_XPV(SvANY(sv));
if (mt <= SVt_IV)
mt = SVt_PVIV;
else if (mt == SVt_NV)
mt = SVt_PVNV;
break;
case SVt_PVIV:
pv = SvPVX(sv);
cur = SvCUR(sv);
len = SvLEN(sv);
iv = SvIVX(sv);
nv = 0.0;
magic = 0;
stash = 0;
del_XPVIV(SvANY(sv));
break;
case SVt_PVNV:
pv = SvPVX(sv);
cur = SvCUR(sv);
len = SvLEN(sv);
iv = SvIVX(sv);
nv = SvNVX(sv);
magic = 0;
stash = 0;