From Kurt.Hornik@ci.tuwien.ac.at  Fri Aug 11 06:54:32 2000
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Fri, 11 Aug 2000 07:54:32 +0200
Subject: [Rd] GenGC changes
In-Reply-To: <14737.41175.808404.687281@aragorn.ci.tuwien.ac.at>
References: <14737.41175.808404.687281@aragorn.ci.tuwien.ac.at>
Message-ID: <200008110554.HAA20812@aragorn.ci.tuwien.ac.at>

>>>>> Kurt Hornik writes:

> As most R developers maybe are already aware of, R version 1.2.0
> introduced a new `generational' garbage collector which means that
> strings and vectors (and language objects) are handled differently
> from the numerical atomic types.

>> From ``Writing R Extensions'':

>        Earlier code was written in a style like.
>            VECTOR(dimnames)[0] = getAttrib(x, R_NamesSymbol);
    
>     but that is no longer allowed.  The functions `VECTOR_ELT' and
>     `SET_VECTOR_ELT' must now be used to access and set elements of a
>     generic vector.  There are analogous functions `STRING_ELT' and
>     `SET_STRING_ELT' for character vectors.
    
>        To convert existing code, use the following replacements.
    
>          original                 replacement
>          `foo = VECTOR(bar)[i]'   `foo = VECTOR_ELT(bar, i)'
>          `VECTOR(foo)[j] = bar'   `SET_VECTOR_ELT(foo, j, bar)'
>          `foo = STRING(bar)[i]'   `foo = STRING_ELT(bar, i)'
>          `STRING(foo)[j] = bar'   `SET_STRING_ELT(foo, j, bar)'

> The changes were committed to the r-devel true this Monday, and imply
> that add-on packages using the original coding style will no longer
> work with current versions of r-devel.  One possible solution for
> having packages with sources which work for compilation under both 1.1
> and 1.2 is to use conditionals of the form

>     #if R_VERSION >= R_Version(1, 2, 0)
> 	new-style-code
>     #else
> 	old-style-code
>     #endif

> I would like to ask add-on package maintainers of packages which are
> affected by the change to produce updated versions of their packages
> which work under both 1.1 and 1.2.  It seems that the following ones
> require action:

> 	Java
> 	Matrix
> 	RMySQL
> 	RODBC
> 	foreign
> 	hdf5
> 	netCDF
> 	stataread

> (Note that [currently], there is binary incompatibility between 1.1
> and 1.2.)

As indicated, the above is only one possible solution.  Another, and
maybe the preferred one in order to avoid unnecessarily duplicating
code, is the use of a *PRIVATE* header file containing the following
code:

#if R_VERSION < R_Version(1, 2, 0)
# define STRING_ELT(x,i)	(STRING(x)[i])
# define VECTOR_ELT(x,i)        (VECTOR(x)[i])
# define SET_STRING_ELT(x,i,v)	(STRING(x)[i] = (v))
# define SET_VECTOR_ELT(x,i,v)	(VECTOR(x)[i] = (v))
#endif

(Note that in order to achieve maximal source compatibility in the 1.x
series, it is preferable to have add-on packages modified, as we cannot
easily control the `old' (pre-1.1.1) R versions included in various
distributions.)

-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] GenGC changes
Kurt Hornik