Open
Description
Currently, a nullptr
but not an R_NilValue
can be assigned to an external_ptr<>
object. This is inconsistent and surprising, in particular because the roundtrip works correctly the other way. Should we support this?
library(cpp11)
# Works
cpp_source(
code = '
#include "cpp11/external_pointer.hpp"
#include "cpp11/strings.hpp"
[[cpp11::register]]
cpp11::external_pointer<int> test() {
return cpp11::external_pointer<int>(nullptr);
}
'
)
test()
#> NULL
# Fails, but perhaps shouldn't
cpp_source(
code = '
#include "cpp11/external_pointer.hpp"
#include "cpp11/strings.hpp"
[[cpp11::register]]
cpp11::external_pointer<int> test() {
return cpp11::external_pointer<int>(R_NilValue);
}
'
)
test()
#> Error: Invalid input type, expected 'externalptr' actual 'NULL'
Created on 2023-04-02 with reprex v2.0.2
Metadata
Metadata
Assignees
Labels
No labels