Skip to content

External pointers and attributes #308

Description

@krlmlr

Invoking the move constructor of external_pointer<> clears attributes on an external pointer object.

I would expect the third and fourth output to be identical to the second output. A possible fix is duckdb/duckdb@12f6f10 (this project uses a vendored version of cpp11).

library(cpp11)

cpp_source(
  code = '
  #include "cpp11/external_pointer.hpp"
  #include "cpp11/strings.hpp"

  template <class X>
  cpp11::external_pointer<int> test_int() {
    X a = 0;
    auto p = cpp11::external_pointer<X>(&a, false);
    Rf_PrintValue(p);
    Rf_setAttrib(p, R_ClassSymbol, cpp11::writable::strings({"foo"}));
    Rf_PrintValue(p);

    return std::move(p);
  }

  [[cpp11::register]]
  SEXP test() {
    auto p = cpp11::sexp(test_int<int>());
    Rf_PrintValue(p);
    return p;
  }
  '
)

out <- test()
#> <pointer: 0x16f0af42c>
#> <pointer: 0x16f0af42c>
#> attr(,"class")
#> [1] "foo"
#> <pointer: 0x16f0af42c>
out
#> <pointer: 0x16f0af42c>

Created on 2023-03-02 with reprex v2.0.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions