|
136 | 136 | /* |
137 | 137 | * The shared things need an interpreter to live in ... |
138 | 138 | */ |
139 | | -PerlInterpreter *PL_sharedsv_space; /* The shared sv space */ |
| 139 | +static PerlInterpreter *PL_sharedsv_space; /* The shared sv space */ |
140 | 140 | /* To access shared space we fake aTHX in this scope and thread's context */ |
141 | 141 |
|
142 | 142 | /* Bug #24255: We include ENTER+SAVETMPS/FREETMPS+LEAVE with |
@@ -177,7 +177,7 @@ typedef struct { |
177 | 177 | #endif |
178 | 178 | } recursive_lock_t; |
179 | 179 |
|
180 | | -recursive_lock_t PL_sharedsv_lock; /* Mutex protecting the shared sv space */ |
| 180 | +static recursive_lock_t PL_sharedsv_lock; /* Mutex protecting the shared sv space */ |
181 | 181 |
|
182 | 182 | void |
183 | 183 | recursive_lock_init(pTHX_ recursive_lock_t *lock) |
@@ -291,7 +291,7 @@ sharedsv_userlock_free(pTHX_ SV *sv, MAGIC *mg) |
291 | 291 | return (0); |
292 | 292 | } |
293 | 293 |
|
294 | | -MGVTBL sharedsv_userlock_vtbl = { |
| 294 | +static const MGVTBL sharedsv_userlock_vtbl = { |
295 | 295 | 0, /* get */ |
296 | 296 | 0, /* set */ |
297 | 297 | 0, /* len */ |
@@ -332,10 +332,10 @@ MGVTBL sharedsv_userlock_vtbl = { |
332 | 332 | the shared thing. |
333 | 333 | */ |
334 | 334 |
|
335 | | -extern MGVTBL sharedsv_scalar_vtbl; /* Scalars have this vtable */ |
336 | | -extern MGVTBL sharedsv_array_vtbl; /* Hashes and arrays have this |
| 335 | +extern const MGVTBL sharedsv_scalar_vtbl; /* Scalars have this vtable */ |
| 336 | +extern const MGVTBL sharedsv_array_vtbl; /* Hashes and arrays have this |
337 | 337 | - like 'tie' */ |
338 | | -extern MGVTBL sharedsv_elem_vtbl; /* Elements of hashes and arrays have |
| 338 | +extern const MGVTBL sharedsv_elem_vtbl; /* Elements of hashes and arrays have |
339 | 339 | this _AS WELL AS_ the scalar magic: |
340 | 340 | The sharedsv_elem_vtbl associates the element with the array/hash and |
341 | 341 | the sharedsv_scalar_vtbl associates it with the value |
@@ -878,7 +878,7 @@ sharedsv_scalar_mg_local(pTHX_ SV* nsv, MAGIC *mg) |
878 | 878 | } |
879 | 879 | #endif |
880 | 880 |
|
881 | | -MGVTBL sharedsv_scalar_vtbl = { |
| 881 | +const MGVTBL sharedsv_scalar_vtbl = { |
882 | 882 | sharedsv_scalar_mg_get, /* get */ |
883 | 883 | sharedsv_scalar_mg_set, /* set */ |
884 | 884 | 0, /* len */ |
@@ -1039,7 +1039,7 @@ sharedsv_elem_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param) |
1039 | 1039 | return (0); |
1040 | 1040 | } |
1041 | 1041 |
|
1042 | | -MGVTBL sharedsv_elem_vtbl = { |
| 1042 | +const MGVTBL sharedsv_elem_vtbl = { |
1043 | 1043 | sharedsv_elem_mg_FETCH, /* get */ |
1044 | 1044 | sharedsv_elem_mg_STORE, /* set */ |
1045 | 1045 | 0, /* len */ |
@@ -1152,7 +1152,7 @@ sharedsv_array_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param) |
1152 | 1152 | return (0); |
1153 | 1153 | } |
1154 | 1154 |
|
1155 | | -MGVTBL sharedsv_array_vtbl = { |
| 1155 | +const MGVTBL sharedsv_array_vtbl = { |
1156 | 1156 | 0, /* get */ |
1157 | 1157 | 0, /* set */ |
1158 | 1158 | sharedsv_array_mg_FETCHSIZE,/* len */ |
@@ -1371,9 +1371,29 @@ void |
1371 | 1371 | STORESIZE(SV *obj,IV count) |
1372 | 1372 | CODE: |
1373 | 1373 | dTHXc; |
1374 | | - SV *sobj = SHAREDSV_FROM_OBJ(obj); |
| 1374 | + SV *ssv = SHAREDSV_FROM_OBJ(obj); |
| 1375 | + |
1375 | 1376 | SHARED_EDIT; |
1376 | | - av_fill((AV*) sobj, count); |
| 1377 | + assert(SvTYPE(ssv) == SVt_PVAV); |
| 1378 | + if (!PL_dirty) { |
| 1379 | + SV **svp = AvARRAY((AV *)ssv); |
| 1380 | + I32 ix = AvFILLp((AV *)ssv); |
| 1381 | + for (;ix >= count; ix--) { |
| 1382 | + SV *sv = svp[ix]; |
| 1383 | + if (!sv) |
| 1384 | + continue; |
| 1385 | + if ( (SvOBJECT(sv) || (SvROK(sv) && (sv = SvRV(sv)))) |
| 1386 | + && SvREFCNT(sv) == 1 ) |
| 1387 | + { |
| 1388 | + SV *tmp = Perl_sv_newmortal(caller_perl); |
| 1389 | + PERL_SET_CONTEXT((aTHX = caller_perl)); |
| 1390 | + sv_upgrade(tmp, SVt_RV); |
| 1391 | + get_RV(tmp, sv); |
| 1392 | + PERL_SET_CONTEXT((aTHX = PL_sharedsv_space)); |
| 1393 | + } |
| 1394 | + } |
| 1395 | + } |
| 1396 | + av_fill((AV*) ssv, count - 1); |
1377 | 1397 | SHARED_RELEASE; |
1378 | 1398 |
|
1379 | 1399 |
|
|
0 commit comments