Re: [Rd] R_ext/Altrep.h should be more C++-friendly

2018-10-10 Thread Tierney, Luke
Thanks for the suggestion. Committed in R_devel.

Best,

luke

On Mon, 8 Oct 2018, Michael Sannella wrote:

> I am not able to #include "R_ext/Altrep.h" from a C++ file.  I think
> it needs two changes:
> 
> 1. add the same __cplusplus check as most of the other header files:
>     #ifdef  __cplusplus
>     extern "C" {
>     #endif
>         ...
>     #ifdef  __cplusplus
>     }
>     #endif
> 
> 2. change the line
>     R_new_altrep(R_altrep_class_t class, SEXP data1, SEXP data2);
>  to
>     R_new_altrep(R_altrep_class_t cls, SEXP data1, SEXP data2);
>  since C++ doesn't like an argument named 'class'
> 
>   ~~ Michael Sannella
> 
> 
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R_ext/Altrep.h should be more C++-friendly

2018-10-10 Thread Romain Francois
Thank you, 

I updated my example package so that it works with both. 
https://github.com/romainfrancois/altrepisode/blob/96af0548a9ecc08701d119ea427e16940a82882b/src/altrepisode.h
 


We have to do something like this unless we depend on R 3.6.0: 

#if R_VERSION < R_Version(3, 6, 0)
  #define class klass
  extern "C" {
#include 
  }
  #undef class
#else
  #include 
#endif

Romain

> Le 9 oct. 2018 à 05:09, Tierney, Luke  a écrit :
> 
> Thanks for the suggestion. Committed in R_devel.
> 
> Best,
> 
> luke
> 
> On Mon, 8 Oct 2018, Michael Sannella wrote:
> 
>> I am not able to #include "R_ext/Altrep.h" from a C++ file.  I think
>> it needs two changes:
>> 
>> 1. add the same __cplusplus check as most of the other header files:
>> #ifdef  __cplusplus
>> extern "C" {
>> #endif
>> ...
>> #ifdef  __cplusplus
>> }
>> #endif
>> 
>> 2. change the line
>> R_new_altrep(R_altrep_class_t class, SEXP data1, SEXP data2);
>>  to
>> R_new_altrep(R_altrep_class_t cls, SEXP data1, SEXP data2);
>>  since C++ doesn't like an argument named 'class'
>> 
>>   ~~ Michael Sannella
>> 
>> 
>> 
> 
> -- 
> Luke Tierney
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa  Phone: 319-335-3386
> Department of Statistics andFax:   319-335-3017
>Actuarial Science
> 241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
> Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] unlockEnvironment()?

2018-10-10 Thread William Dunlap via R-devel
R lets one lock an environment with both an R function,
base::lockEnvironment, and a C function, R_LockEnvironment, but, as far as
I can tell, no corresponding function to unlock an environment.  Is this
omission on principle or just something that has not been done yet?

I ask because several packages, including the well-used R6 and rlang
packages, fiddle with some bits in with SET_ENVFLAGS and ENVFLAGS to unlock
an environment.  (See grep output below.)

About 5000 (1/3 of CRAN) packages depend on R6 or rlang.  Should R supply a
more disciplined way of unlocking an environment?

Bill Dunlap
TIBCO Software
wdunlap tibco.com

$ { find . -type f -print0 | xargs -0 grep -n -C 2 ENVFLAGS ; } 2>/dev/null
./R6/tests/manual/encapsulation.R-5-unlockEnvironment <-
cfunction(signature(env = "environment"), body = '
./R6/tests/manual/encapsulation.R-6-  #define FRAME_LOCK_MASK (1<<14)
./R6/tests/manual/encapsulation.R:7:  #define FRAME_IS_LOCKED(e)
(ENVFLAGS(e) & FRAME_LOCK_MASK)
./R6/tests/manual/encapsulation.R:8:  #define UNLOCK_FRAME(e)
SET_ENVFLAGS(e, ENVFLAGS(e) & (~ FRAME_LOCK_MASK))
./R6/tests/manual/encapsulation.R-9-
./R6/tests/manual/encapsulation.R-10-  if (TYPEOF(env) == NILSXP)
./BMA/R/iBMA.glm.R-21-*/
./BMA/R/iBMA.glm.R-22-#define FRAME_LOCK_MASK (1<<14)
./BMA/R/iBMA.glm.R:23:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
FRAME_LOCK_MASK)
./BMA/R/iBMA.glm.R:24:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) &
(~ FRAME_LOCK_MASK))
./BMA/R/iBMA.glm.R-25-'
./BMA/R/iBMA.glm.R-26-
--
./BMA/R/iBMA.surv.R-22-*/
./BMA/R/iBMA.surv.R-23-#define FRAME_LOCK_MASK (1<<14)
./BMA/R/iBMA.surv.R:24:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
FRAME_LOCK_MASK)
./BMA/R/iBMA.surv.R:25:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e)
& (~ FRAME_LOCK_MASK))
./BMA/R/iBMA.surv.R-26-'
./BMA/R/iBMA.surv.R-27-
./pkgload/src/unlock.c-20-*/
./pkgload/src/unlock.c-21-#define FRAME_LOCK_MASK (1 << 14)
./pkgload/src/unlock.c:22:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
FRAME_LOCK_MASK)
./pkgload/src/unlock.c:23:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e,
ENVFLAGS(e) & (~FRAME_LOCK_MASK))
./pkgload/src/unlock.c-24-
./pkgload/src/unlock.c-25-extern SEXP R_TrueValue;
./SOD/src/tmp.cpp-11394-SEXP (ENCLOS)(SEXP x);
./SOD/src/tmp.cpp-11395-SEXP (HASHTAB)(SEXP x);
./SOD/src/tmp.cpp:11396:int (ENVFLAGS)(SEXP x);
./SOD/src/tmp.cpp:11397:void (SET_ENVFLAGS)(SEXP x, int v);
./SOD/src/tmp.cpp-11398-void SET_FRAME(SEXP x, SEXP v);
./SOD/src/tmp.cpp-11399-void SET_ENCLOS(SEXP x, SEXP v);
--
./SOD/src/tmp.h-11393-SEXP (ENCLOS)(SEXP x);
./SOD/src/tmp.h-11394-SEXP (HASHTAB)(SEXP x);
./SOD/src/tmp.h:11395:int (ENVFLAGS)(SEXP x);
./SOD/src/tmp.h:11396:void (SET_ENVFLAGS)(SEXP x, int v);
./SOD/src/tmp.h-11397-void SET_FRAME(SEXP x, SEXP v);
./SOD/src/tmp.h-11398-void SET_ENCLOS(SEXP x, SEXP v);

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] unlockEnvironment()?

2018-10-10 Thread Tierney, Luke
On Wed, 10 Oct 2018, William Dunlap via R-devel wrote:

> R lets one lock an environment with both an R function,
> base::lockEnvironment, and a C function, R_LockEnvironment, but, as far as
> I can tell, no corresponding function to unlock an environment.  Is this
> omission on principle or just something that has not been done yet?

Absolutely on principle!

Best,

luke

>
> I ask because several packages, including the well-used R6 and rlang
> packages, fiddle with some bits in with SET_ENVFLAGS and ENVFLAGS to unlock
> an environment.  (See grep output below.)
>
> About 5000 (1/3 of CRAN) packages depend on R6 or rlang.  Should R supply a
> more disciplined way of unlocking an environment?
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> $ { find . -type f -print0 | xargs -0 grep -n -C 2 ENVFLAGS ; } 2>/dev/null
> ./R6/tests/manual/encapsulation.R-5-unlockEnvironment <-
> cfunction(signature(env = "environment"), body = '
> ./R6/tests/manual/encapsulation.R-6-  #define FRAME_LOCK_MASK (1<<14)
> ./R6/tests/manual/encapsulation.R:7:  #define FRAME_IS_LOCKED(e)
> (ENVFLAGS(e) & FRAME_LOCK_MASK)
> ./R6/tests/manual/encapsulation.R:8:  #define UNLOCK_FRAME(e)
> SET_ENVFLAGS(e, ENVFLAGS(e) & (~ FRAME_LOCK_MASK))
> ./R6/tests/manual/encapsulation.R-9-
> ./R6/tests/manual/encapsulation.R-10-  if (TYPEOF(env) == NILSXP)
> ./BMA/R/iBMA.glm.R-21-*/
> ./BMA/R/iBMA.glm.R-22-#define FRAME_LOCK_MASK (1<<14)
> ./BMA/R/iBMA.glm.R:23:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
> FRAME_LOCK_MASK)
> ./BMA/R/iBMA.glm.R:24:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) &
> (~ FRAME_LOCK_MASK))
> ./BMA/R/iBMA.glm.R-25-'
> ./BMA/R/iBMA.glm.R-26-
> --
> ./BMA/R/iBMA.surv.R-22-*/
> ./BMA/R/iBMA.surv.R-23-#define FRAME_LOCK_MASK (1<<14)
> ./BMA/R/iBMA.surv.R:24:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
> FRAME_LOCK_MASK)
> ./BMA/R/iBMA.surv.R:25:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e)
> & (~ FRAME_LOCK_MASK))
> ./BMA/R/iBMA.surv.R-26-'
> ./BMA/R/iBMA.surv.R-27-
> ./pkgload/src/unlock.c-20-*/
> ./pkgload/src/unlock.c-21-#define FRAME_LOCK_MASK (1 << 14)
> ./pkgload/src/unlock.c:22:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
> FRAME_LOCK_MASK)
> ./pkgload/src/unlock.c:23:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e,
> ENVFLAGS(e) & (~FRAME_LOCK_MASK))
> ./pkgload/src/unlock.c-24-
> ./pkgload/src/unlock.c-25-extern SEXP R_TrueValue;
> ./SOD/src/tmp.cpp-11394-SEXP (ENCLOS)(SEXP x);
> ./SOD/src/tmp.cpp-11395-SEXP (HASHTAB)(SEXP x);
> ./SOD/src/tmp.cpp:11396:int (ENVFLAGS)(SEXP x);
> ./SOD/src/tmp.cpp:11397:void (SET_ENVFLAGS)(SEXP x, int v);
> ./SOD/src/tmp.cpp-11398-void SET_FRAME(SEXP x, SEXP v);
> ./SOD/src/tmp.cpp-11399-void SET_ENCLOS(SEXP x, SEXP v);
> --
> ./SOD/src/tmp.h-11393-SEXP (ENCLOS)(SEXP x);
> ./SOD/src/tmp.h-11394-SEXP (HASHTAB)(SEXP x);
> ./SOD/src/tmp.h:11395:int (ENVFLAGS)(SEXP x);
> ./SOD/src/tmp.h:11396:void (SET_ENVFLAGS)(SEXP x, int v);
> ./SOD/src/tmp.h-11397-void SET_FRAME(SEXP x, SEXP v);
> ./SOD/src/tmp.h-11398-void SET_ENCLOS(SEXP x, SEXP v);
>
>   [[alternative HTML version deleted]]
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel