@@ -348,10 +348,19 @@ static SEXP duplicate1(SEXP s, Rboolean deep)
348348 case CPLXSXP : DUPLICATE_ATOMIC_VECTOR (Rcomplex , COMPLEX , COMPLEX_RO , t , s , deep ); break ;
349349 case RAWSXP : DUPLICATE_ATOMIC_VECTOR (Rbyte , RAW , RAW_RO , t , s , deep ); break ;
350350 case STRSXP :
351- /* direct copying and bypassing the write barrier is OK since
352- t was just allocated and so it cannot be older than any of
353- the elements in s. LT */
354- DUPLICATE_ATOMIC_VECTOR (SEXP , STRING_PTR , STRING_PTR_RO , t , s , deep );
351+ /* Direct copying and bypassing the write barrier would be OK
352+ since t was just allocated and so it cannot be older than
353+ any of the elements in s. But it does not increment the
354+ reference counts, so use a loop with SET_STRING_ELT. LT */
355+ //DUPLICATE_ATOMIC_VECTOR(SEXP, STRING_PTR, STRING_PTR_RO, t, s, deep);
356+ n = XLENGTH (s );
357+ PROTECT (s );
358+ PROTECT (t = allocVector (TYPEOF (s ), n ));
359+ for (i = 0 ; i < n ; i ++ )
360+ SET_STRING_ELT (t , i , STRING_ELT (s , i ));
361+ DUPLICATE_ATTRIB (t , s , deep );
362+ COPY_TRUELENGTH (t , s );
363+ UNPROTECT (2 );
355364 break ;
356365 case PROMSXP :
357366 return s ;
0 commit comments