@@ -1366,10 +1366,11 @@ static SEXP cbind(SEXP call, SEXP args, SEXPTYPE mode, SEXP rho,
13661366 if (isMatrix (u ) || length (u ) >= lenmin ) {
13671367 R_xlen_t k = xlength (u ); /* use xlength since u can be NULL */
13681368 R_xlen_t idx = (!isMatrix (u )) ? rows : k ;
1369- if (TYPEOF (u ) <= INTSXP ) { /* NILSXP or INT or LGL */
1369+ if (idx > 0 && TYPEOF (u ) <= INTSXP ) {
1370+ /* NILSXP or INT or LGL
13701371 /* taking INTERER(NILSXP) should segfault, and
1371- * sometimes does. But if cbinding a NULL, there
1372- * are zero rows so nothing to do. */
1372+ * sometimes does. But if cbind-ing a NULL, there
1373+ * are zero rows and u is not a matrix, so nothing to do. */
13731374 if (mode <= INTSXP ) {
13741375 xcopyIntegerWithRecycle (INTEGER (result ), INTEGER (u ),
13751376 n , idx , k );
@@ -1618,46 +1619,47 @@ static SEXP rbind(SEXP call, SEXP args, SEXPTYPE mode, SEXP rho,
16181619 }
16191620 }
16201621 }
1621- else { /* everything else, currently NILSXP, REALSXP, INTSXP, LGLSXP */
1622+ else if ( mode == INTSXP ) {
16221623 for (t = args ; t != R_NilValue ; t = CDR (t )) {
1623- u = PRVALUE (CAR (t )); /* type of u can be any of: RAW, LGL, INT, REAL */
1624+ u = PRVALUE (CAR (t ));
16241625 if (isMatrix (u ) || length (u ) >= lenmin ) {
1626+ u = coerceVector (u , INTSXP );
16251627 R_xlen_t k = XLENGTH (u );
16261628 R_xlen_t idx = (isMatrix (u )) ? nrows (u ) : (k > 0 );
1627- if (TYPEOF (u ) <= INTSXP ) {
1628- /* taking INTERER(NILSXP) should segfault, and
1629- * sometimes does. But if rbinding a NULL, there
1630- * are zero cols so nothing to do. */
1631- if (mode <= INTSXP ) {
1632- xfillIntegerMatrixWithRecycle (INTEGER (result ),
1633- INTEGER (u ), n , rows ,
1634- idx , cols , k );
1635- n += idx ;
1636- }
1637- else {
1638- FILL_MATRIX_ITERATE (n , rows , idx , cols , k )
1639- REAL (result )[didx ]
1640- = (INTEGER (u )[sidx ]) == NA_INTEGER ? NA_REAL : INTEGER (u )[sidx ];
1641- n += idx ;
1642- }
1643- }
1644- else if (TYPEOF (u ) == REALSXP ) {
1645- xfillRealMatrixWithRecycle (REAL (result ), REAL (u ), n ,
1646- rows , idx , cols , k );
1647- n += idx ;
1648- }
1649- else { /* RAWSXP */
1650- if (mode == LGLSXP ) {
1651- FILL_MATRIX_ITERATE (n , rows , idx , cols , k )
1652- LOGICAL (result )[didx ] = RAW (u )[sidx ] ? TRUE : FALSE;
1653- }
1654- else // cbind covers INTSXP and RAWSXP, so this is incomplete
1655- FILL_MATRIX_ITERATE (n , rows , idx , cols , k )
1656- INTEGER (result )[didx ] = (unsigned char ) RAW (u )[sidx ];
1657- }
1629+ xfillIntegerMatrixWithRecycle (INTEGER (result ), INTEGER (u ), n , rows , idx ,
1630+ cols , k );
1631+ n += idx ;
16581632 }
16591633 }
16601634 }
1635+ else if (mode == LGLSXP ) {
1636+ for (t = args ; t != R_NilValue ; t = CDR (t )) {
1637+ u = PRVALUE (CAR (t ));
1638+ if (isMatrix (u ) || length (u ) >= lenmin ) {
1639+ u = coerceVector (u , LGLSXP );
1640+ R_xlen_t k = XLENGTH (u );
1641+ R_xlen_t idx = (isMatrix (u )) ? nrows (u ) : (k > 0 );
1642+ xfillLogicalMatrixWithRecycle (LOGICAL (result ), LOGICAL (u ), n , rows , idx ,
1643+ cols , k );
1644+ n += idx ;
1645+ }
1646+ }
1647+ }
1648+ else if (mode == REALSXP ) {
1649+ for (t = args ; t != R_NilValue ; t = CDR (t )) {
1650+ u = PRVALUE (CAR (t ));
1651+ if (isMatrix (u ) || length (u ) >= lenmin ) {
1652+ u = coerceVector (u , REALSXP );
1653+ R_xlen_t k = XLENGTH (u );
1654+ R_xlen_t idx = (isMatrix (u )) ? nrows (u ) : (k > 0 );
1655+ xfillRealMatrixWithRecycle (REAL (result ), REAL (u ), n , rows , idx ,
1656+ cols , k );
1657+ n += idx ;
1658+ }
1659+ }
1660+ }
1661+ else { /* everything else, currently NILSXP so do nothing */
1662+ }
16611663
16621664 /* Adjustment of dimnames attributes. */
16631665 if (have_rnames || have_cnames ) {
0 commit comments