You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/internals.Rmd
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -68,12 +68,12 @@ Alternatively many IDEs support automatically running `clang-format` every time
68
68
69
69
## Code organization
70
70
71
-
cpp11 is a header only library, so all source code exposed to users lives in [inst/include](https://github.com/r-lib/cpp11/tree/master/inst/include).
72
-
R code used to register functions and for `cpp11::cpp_source()` is in [R/](https://github.com/r-lib/cpp11/tree/master/R).
73
-
Tests for _only_ the code in `R/` is in [tests/testthat/](https://github.com/r-lib/cpp11/tree/master/tests/testthat)
74
-
The rest of the code is in a separate [cpp11test/](https://github.com/r-lib/cpp11/tree/master/cpp11test) package included in the source tree.
75
-
Inside [cpp11test/src](https://github.com/r-lib/cpp11/tree/master/cpp11test/src) the files that start with `test-` are C++ tests using the [Catch](https://testthat.r-lib.org/reference/use_catch.html) support in testthat.
76
-
In addition there are some regular R tests in [cpp11test/tests/testthat/](https://github.com/r-lib/cpp11/tree/master/cpp11test/tests/testthat).
71
+
cpp11 is a header only library, so all source code exposed to users lives in [inst/include](https://github.com/r-lib/cpp11/tree/main/inst/include).
72
+
R code used to register functions and for `cpp11::cpp_source()` is in [R/](https://github.com/r-lib/cpp11/tree/main/R).
73
+
Tests for _only_ the code in `R/` is in [tests/testthat/](https://github.com/r-lib/cpp11/tree/main/tests/testthat)
74
+
The rest of the code is in a separate [cpp11test/](https://github.com/r-lib/cpp11/tree/main/cpp11test) package included in the source tree.
75
+
Inside [cpp11test/src](https://github.com/r-lib/cpp11/tree/main/cpp11test/src) the files that start with `test-` are C++ tests using the [Catch](https://testthat.r-lib.org/reference/use_catch.html) support in testthat.
76
+
In addition there are some regular R tests in [cpp11test/tests/testthat/](https://github.com/r-lib/cpp11/tree/main/cpp11test/tests/testthat).
77
77
78
78
## Naming conventions
79
79
@@ -86,12 +86,12 @@ In addition there are some regular R tests in [cpp11test/tests/testthat/](https:
86
86
87
87
## Vector classes
88
88
89
-
All of the basic r_vector classes are class templates, the base template is defined in [cpp11/r_vector.hpp](https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/r_vector.hpp)
89
+
All of the basic r_vector classes are class templates, the base template is defined in [cpp11/r_vector.hpp](https://github.com/r-lib/cpp11/blob/main/inst/include/cpp11/r_vector.hpp)
90
90
The template parameter is the type of **value** the particular R vector stores, e.g. `double` for `cpp11::doubles`.
91
91
This differs from Rcpp, whose first template parameter is the R vector type, e.g. `REALSXP`.
92
92
93
93
The file first has the class declarations, then function definitions further down in the file.
94
-
Specializations for the various types are in separate files, e.g. [cpp11/doubles.hpp](https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/doubles.hpp), [cpp11/integers.hpp](https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/integers.hpp)
94
+
Specializations for the various types are in separate files, e.g. [cpp11/doubles.hpp](https://github.com/r-lib/cpp11/blob/main/inst/include/cpp11/doubles.hpp), [cpp11/integers.hpp](https://github.com/r-lib/cpp11/blob/main/inst/include/cpp11/integers.hpp)
95
95
96
96
## Coercion functions
97
97
@@ -100,7 +100,7 @@ There are two different coercion functions
100
100
`as_sexp()` takes a C++ object and coerces it to a SEXP object, so it can be used in R.
101
101
`as_cpp<>()` is a template function that takes a SEXP and creates a C++ object from it
102
102
103
-
The various methods for both functions are defined in [cpp11/as.hpp](https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/as.hpp)
103
+
The various methods for both functions are defined in [cpp11/as.hpp](https://github.com/r-lib/cpp11/blob/main/inst/include/cpp11/as.hpp)
104
104
105
105
This is definitely the most complex part of the cpp11 code, with extensive use of [template metaprogramming](https://en.wikipedia.org/wiki/Template_metaprogramming).
106
106
In particular the [substitution failure is not an error (SFINAE)](https://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error) technique is used to control overloading of the functions.
@@ -126,14 +126,14 @@ Calling `preserved.release()` on this returned token will release the protection
126
126
127
127
This scheme scales in O(1) time to release or insert an object vs O(N) or worse time with `R_PreserveObject()` / `R_ReleaseObject()`.
128
128
129
-
These functions are defined in [protect.hpp](https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/protect.hpp)
129
+
These functions are defined in [protect.hpp](https://github.com/r-lib/cpp11/blob/main/inst/include/cpp11/protect.hpp)
130
130
131
131
### Unwind Protect
132
132
133
133
In R 3.5+ cpp11 uses `R_UnwindProtect` to protect (most) calls to the R API that could fail.
134
134
These are usually those that allocate memory, though in truth most R API functions could error along some paths.
135
135
If an error happends under `R_UnwindProtect` cpp11 will throw a C++ exception.
136
-
This exception is caught by the try catch block defined in the `BEGIN_CPP11` macro in [cpp11/declarations.hpp](https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/declarations.hpp).
136
+
This exception is caught by the try catch block defined in the `BEGIN_CPP11` macro in [cpp11/declarations.hpp](https://github.com/r-lib/cpp11/blob/main/inst/include/cpp11/declarations.hpp).
137
137
The exception will cause any C++ destructors to run, freeing any resources held by C++ objects.
138
138
After the try catch block exits the R error unwinding is then continued by `R_ContinueUnwind()` and a normal R error results.
0 commit comments