Skip to content

GH-53951: [R] ExtensionType$new() crashes on non-R extension types such as arrow.opaque - #54458

Draft
thisisnic wants to merge 4 commits into
apache:mainfrom
thisisnic:GH-53951-extension-type-crash
Draft

thisisnic wants to merge 4 commits into
apache:mainfrom
thisisnic:GH-53951-extension-type-crash

Conversation

@thisisnic

@thisisnic thisisnic commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

Creating non instances of non-R extension types segfaulted

What changes are included in this PR?

Plumb in machinery to allow non-R extension types, including using the right kind of pointer

Are these changes tested?

Yup

Are there any user-facing changes?

Nah

Was AI used for this PR?

Used AI to generate code, asked lots of questions. Also manually ran code before/after to confirm segfault with the code but no segfault without it.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@thisisnic
thisisnic marked this pull request as ready for review October 18, 2026 17:28
@thisisnic
thisisnic requested a review from jonkeane as a code owner October 18, 2026 17:28
Copilot AI balanced review requested due to automatic review settings October 18, 2026 17:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Native wrapping can still abort R, and nested conversions can lose nulls or produce inconsistent element types.

3 open issues
What changed in this PR

Addresses GH-53951 by allowing R bindings to handle extension types defined outside R without unsafe casts.

Changes:

  • Adds native-type detection and R class/string fallbacks.
  • Converts non-R extension arrays through their storage types.
  • Adds regression coverage for native types, slices, chunks, and nested columns.
File Description
r/​tests/​testthat/​test-extension.R Tests native extension handling and conversion.
r/​src/​extension-impl.cpp Guards casts and detects R-defined types.
r/​src/​arrowExports.cpp Registers the new native helper.
r/​src/​array_to_vector.cpp Adds storage-based conversion fallback.
r/​R/​extension.R Handles native class dispatch and formatting.
r/​R/​arrowExports.R Exposes the type-detection helper to R.

Review effort: Balanced

Comment thread r/R/extension.R
# Not created from R (e.g., a canonical extension type registered by
# libarrow such as arrow.uuid), so there is no R6 subclass to
# dispatch to: fall back to this class
ExtensionType
Comment thread r/src/array_to_vector.cpp
// such as arrow.uuid registered by libarrow itself), so there is no R-level
// as_vector() to call: convert the storage arrays instead, which is what
// the default ExtensionType$as_vector() does.
return ConvertStorage();
Comment thread r/src/array_to_vector.cpp
extension_type.storage_type());
// The outer conversion's task group isn't reachable from Allocate(), so the
// storage is converted serially here, as RExtensionType::Convert() does
return Converter::Convert(storage, false);
@thisisnic
thisisnic marked this pull request as draft October 18, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants