Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/r.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
ulimit -c unlimited
# Setting a non-default and non-probable Marquesas French Polynesia time
# it has both with a .45 offset and very very few people who live there.
archery docker run -e TZ=MART -e ARROW_R_FORCE_TESTS=${{ matrix.force-tests }} ubuntu-r
archery docker run -e TZ=MART -e ARROW_R_FORCE_TESTS=${{ matrix.force-tests }} -e ARROW_EXTRA_ERROR_CONTEXT=ON ubuntu-r
- name: Dump install logs
run: cat r/check/arrow.Rcheck/00install.out
if: always()
Expand Down
3 changes: 3 additions & 0 deletions ci/scripts/r_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ fi
# Make sure we aren't writing to the home dir (CRAN _hates_ this but there is no official check)
BEFORE=$(ls -alh ~/)

# Install dev duckdb
${R_BIN} -e 'install.packages("remotes"); remotes::install_github("duckdb/duckdb/tools/rpkg#4712", build = FALSE)'

SCRIPT="as_cran <- !identical(tolower(Sys.getenv('NOT_CRAN')), 'true')
if (as_cran) {
args <- '--as-cran'
Expand Down
20 changes: 10 additions & 10 deletions r/src/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ const char* r6_class_name<arrow::Array>::get(const std::shared_ptr<arrow::Array>

void arrow::r::validate_slice_offset(R_xlen_t offset, int64_t len) {
if (offset == NA_INTEGER) {
cpp11::stop("Slice 'offset' cannot be NA");
arrow::arrow_stop("Slice 'offset' cannot be NA");
}
if (offset < 0) {
cpp11::stop("Slice 'offset' cannot be negative");
arrow::arrow_stop("Slice 'offset' cannot be negative");
}
if (offset > len) {
cpp11::stop("Slice 'offset' greater than array length");
arrow::arrow_stop("Slice 'offset' greater than array length");
}
}

void arrow::r::validate_slice_length(R_xlen_t length, int64_t available) {
if (length == NA_INTEGER) {
cpp11::stop("Slice 'length' cannot be NA");
arrow::arrow_stop("Slice 'length' cannot be NA");
}
if (length < 0) {
cpp11::stop("Slice 'length' cannot be negative");
arrow::arrow_stop("Slice 'length' cannot be negative");
}
if (length > available) {
cpp11::warning("Slice 'length' greater than available length");
Expand All @@ -90,10 +90,10 @@ std::shared_ptr<arrow::Array> Array__Slice2(const std::shared_ptr<arrow::Array>&

void arrow::r::validate_index(int i, int len) {
if (i == NA_INTEGER) {
cpp11::stop("'i' cannot be NA");
arrow::arrow_stop("'i' cannot be NA");
}
if (i < 0 || i >= len) {
cpp11::stop("subscript out of bounds");
arrow::arrow_stop("subscript out of bounds");
}
}

Expand Down Expand Up @@ -162,13 +162,13 @@ bool Array__RangeEquals(const std::shared_ptr<arrow::Array>& self,
const std::shared_ptr<arrow::Array>& other, R_xlen_t start_idx,
R_xlen_t end_idx, R_xlen_t other_start_idx) {
if (start_idx == NA_INTEGER) {
cpp11::stop("'start_idx' cannot be NA");
arrow::arrow_stop("'start_idx' cannot be NA");
}
if (end_idx == NA_INTEGER) {
cpp11::stop("'end_idx' cannot be NA");
arrow::arrow_stop("'end_idx' cannot be NA");
}
if (other_start_idx == NA_INTEGER) {
cpp11::stop("'other_start_idx' cannot be NA");
arrow::arrow_stop("'other_start_idx' cannot be NA");
}
return self->RangeEquals(*other, start_idx, end_idx, other_start_idx);
}
Expand Down
6 changes: 3 additions & 3 deletions r/src/array_to_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ class Converter_Dictionary : public Converter {
// TODO: also add int64, uint32, uint64 downcasts, if possible
break;
default:
cpp11::stop("Cannot convert Dictionary Array of type `%s` to R",
dict_type.ToString().c_str());
arrow::arrow_stop("Cannot convert Dictionary Array of type `%s` to R",
dict_type.ToString().c_str());
}

if (chunked_array->num_chunks() > 0) {
Expand Down Expand Up @@ -1352,7 +1352,7 @@ std::shared_ptr<Converter> Converter::Make(
break;
}

cpp11::stop("cannot handle Array of type <%s>", type->name().c_str());
arrow::arrow_stop("cannot handle Array of type <%s>", type->name().c_str());
}

std::shared_ptr<ChunkedArray> to_chunks(const std::shared_ptr<Array>& array) {
Expand Down
32 changes: 26 additions & 6 deletions r/src/arrow_cpp11.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@
#endif

namespace arrow {

class RException : public std::runtime_error {
public:
explicit RException(const char* msg) : std::runtime_error(msg) {}
};

__attribute__((noreturn)) static inline void arrow_stop(const char* fmt, ...) {
char message[8096];
memset(message, 0, sizeof(message));

va_list args;
va_start(args, fmt);
vsnprintf(message, sizeof(message), fmt, args);
va_end(args);

throw RException(message);
}

namespace r {

template <typename T>
Expand All @@ -64,14 +82,14 @@ struct Pointer {
// User passed a character representation of the pointer address
SEXP char0 = STRING_ELT(x, 0);
if (char0 == NA_STRING) {
cpp11::stop("Can't convert NA_character_ to pointer");
arrow::arrow_stop("Can't convert NA_character_ to pointer");
}

const char* input_chars = CHAR(char0);
char* endptr;
uint64_t ptr_value = strtoull(input_chars, &endptr, 0);
if (endptr != (input_chars + strlen(input_chars))) {
cpp11::stop("Can't parse '%s' as a 64-bit integer address", input_chars);
arrow::arrow_stop("Can't parse '%s' as a 64-bit integer address", input_chars);
}

ptr_ = reinterpret_cast<T*>(static_cast<uintptr_t>(ptr_value));
Expand All @@ -90,7 +108,7 @@ struct Pointer {
// User passed a double(1) of the static-casted pointer address.
ptr_ = reinterpret_cast<T*>(static_cast<uintptr_t>(REAL(x)[0]));
} else {
cpp11::stop("Can't convert input object to pointer");
arrow::arrow_stop("Can't convert input object to pointer");
}
}

Expand Down Expand Up @@ -207,12 +225,14 @@ Pointer r6_to_pointer(SEXP self) {
if (!Rf_inherits(self, "ArrowObject")) {
std::string type_name = arrow::util::nameof<
cpp11::decay_t<typename std::remove_pointer<Pointer>::type>>();
cpp11::stop("Invalid R object for %s, must be an ArrowObject", type_name.c_str());
arrow::arrow_stop("Invalid R object for %s, must be an ArrowObject",
type_name.c_str());
}
void* p = R_ExternalPtrAddr(Rf_findVarInFrame(self, arrow::r::symbols::xp));
if (p == nullptr) {
SEXP klass = Rf_getAttrib(self, R_ClassSymbol);
cpp11::stop("Invalid <%s>, external pointer to null", CHAR(STRING_ELT(klass, 0)));
arrow::arrow_stop("Invalid <%s>, external pointer to null",
CHAR(STRING_ELT(klass, 0)));
}
return reinterpret_cast<Pointer>(p);
}
Expand Down Expand Up @@ -357,7 +377,7 @@ SEXP to_r6(const std::shared_ptr<T>& ptr, const char* r6_class_name) {
SEXP r6_class = Rf_install(r6_class_name);

if (Rf_findVarInFrame3(arrow::r::ns::arrow, r6_class, FALSE) == R_UnboundValue) {
cpp11::stop("No arrow R6 class named '%s'", r6_class_name);
arrow::arrow_stop("No arrow R6 class named '%s'", r6_class_name);
}

// make call: <symbol>$new(<x>)
Expand Down
19 changes: 15 additions & 4 deletions r/src/arrow_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,33 @@ class UnwindProtectDetail : public StatusDetail {
virtual std::string ToString() const { return "R code execution error"; }
};

static inline Status StatusUnwindProtect(SEXP token) {
return Status::Invalid("R code execution error")
static inline Status StatusUnwindProtect(SEXP token, std::string message) {
return Status::Invalid("R code execution error (", message, ")")
.WithDetail(std::make_shared<UnwindProtectDetail>(token));
}

class MoreUsefulUnwindException : public cpp11::unwind_exception {
public:
explicit MoreUsefulUnwindException(SEXP token, std::string message = "")
: cpp11::unwind_exception(token) {}

const char* what() const noexcept { return message_.c_str(); }

private:
std::string message_;
};

static inline void StopIfNotOk(const Status& status) {
if (!status.ok()) {
auto detail = status.detail();
const UnwindProtectDetail* unwind_detail =
dynamic_cast<const UnwindProtectDetail*>(detail.get());
if (unwind_detail) {
throw cpp11::unwind_exception(unwind_detail->token);
throw MoreUsefulUnwindException(unwind_detail->token);
} else {
// ARROW-13039: be careful not to interpret our error message as a %-format string
std::string s = status.ToString();
cpp11::stop("%s", s.c_str());
throw RException(s.c_str());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion r/src/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ std::shared_ptr<arrow::Buffer> r___RBuffer__initialize(SEXP x) {
default:
break;
}
cpp11::stop("R object of type <%s> not supported", Rf_type2char(TYPEOF(x)));
arrow::arrow_stop("R object of type <%s> not supported", Rf_type2char(TYPEOF(x)));
}

// [[arrow::export]]
Expand Down
2 changes: 1 addition & 1 deletion r/src/chunkedarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ std::shared_ptr<arrow::ChunkedArray> ChunkedArray__from_list(cpp11::list chunks,
std::shared_ptr<arrow::DataType> type;
if (type_inferred) {
if (n == 0) {
cpp11::stop("type must be specified for empty list");
arrow::arrow_stop("type must be specified for empty list");
}
type = arrow::r::InferArrowType(VECTOR_ELT(chunks, 0));
} else {
Expand Down
2 changes: 1 addition & 1 deletion r/src/compute-exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ std::shared_ptr<compute::ExecNode> ExecNode_Join(
} else if (type == 7) {
join_type = compute::JoinType::FULL_OUTER;
} else {
cpp11::stop("todo");
arrow::arrow_stop("todo");
}

return MakeExecNodeOrStop(
Expand Down
16 changes: 8 additions & 8 deletions r/src/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ arrow::Datum as_cpp<arrow::Datum>(SEXP x) {

// This assumes that R objects have already been converted to Arrow objects;
// that seems right but should we do the wrapping here too/instead?
cpp11::stop("to_datum: Not implemented for type %s", Rf_type2char(TYPEOF(x)));
arrow::arrow_stop("to_datum: Not implemented for type %s", Rf_type2char(TYPEOF(x)));
}
} // namespace cpp11

Expand All @@ -123,7 +123,7 @@ SEXP from_datum(arrow::Datum datum) {
break;
}

cpp11::stop("from_datum: Not implemented for Datum %s", datum.ToString().c_str());
arrow::arrow_stop("from_datum: Not implemented for Datum %s", datum.ToString().c_str());
}

std::shared_ptr<arrow::compute::FunctionOptions> make_compute_options(
Expand Down Expand Up @@ -632,7 +632,7 @@ arrow::Result<arrow::TypeHolder> ResolveScalarUDFOutputType(

cpp11::sexp output_type_sexp = state->resolver_(input_types_sexp);
if (!Rf_inherits(output_type_sexp, "DataType")) {
cpp11::stop(
arrow::arrow_stop(
"Function specified as arrow_scalar_function() out_type argument must "
"return a DataType");
}
Expand Down Expand Up @@ -681,7 +681,7 @@ arrow::Status CallRScalarUDF(arrow::compute::KernelContext* context,

// Error for an Array result of the wrong type
if (!result->type()->Equals(array->type())) {
return cpp11::stop(
return arrow::arrow_stop(
"Expected return Array or Scalar with type '%s' from user-defined "
"function but got Array with type '%s'",
result->type()->ToString().c_str(), array->type()->ToString().c_str());
Expand All @@ -693,7 +693,7 @@ arrow::Status CallRScalarUDF(arrow::compute::KernelContext* context,

// handle a Scalar result of the wrong type
if (!result->type()->Equals(scalar->type)) {
return cpp11::stop(
return arrow::arrow_stop(
"Expected return Array or Scalar with type '%s' from user-defined "
"function but got Scalar with type '%s'",
result->type()->ToString().c_str(), scalar->type->ToString().c_str());
Expand All @@ -703,7 +703,7 @@ arrow::Status CallRScalarUDF(arrow::compute::KernelContext* context,
arrow::MakeArrayFromScalar(*scalar, span.length, context->memory_pool()));
result->value = std::move(array->data());
} else {
cpp11::stop("arrow_scalar_function must return an Array or Scalar");
arrow::arrow_stop("arrow_scalar_function must return an Array or Scalar");
}
},
"execute scalar user-defined function");
Expand All @@ -716,7 +716,7 @@ void RegisterScalarUDF(std::string name, cpp11::list func_sexp) {
R_xlen_t n_kernels = in_type_r.size();

if (n_kernels == 0) {
cpp11::stop("Can't register user-defined function with zero kernels");
arrow::arrow_stop("Can't register user-defined function with zero kernels");
}

// Compute the Arity from the list of input kernels. We don't currently handle
Expand All @@ -726,7 +726,7 @@ void RegisterScalarUDF(std::string name, cpp11::list func_sexp) {
for (R_xlen_t i = 1; i < n_kernels; i++) {
auto in_types = cpp11::as_cpp<std::shared_ptr<arrow::Schema>>(in_type_r[i]);
if (in_types->num_fields() != n_args) {
cpp11::stop(
arrow::arrow_stop(
"Kernels for user-defined function must accept the same number of arguments");
}
}
Expand Down
2 changes: 1 addition & 1 deletion r/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::vector<std::string> runtime_info() {
void set_timezone_database(cpp11::strings path) {
auto paths = cpp11::as_cpp<std::vector<std::string>>(path);
if (path.size() != 1) {
cpp11::stop("Must provide a single path to the timezone database.");
arrow::arrow_stop("Must provide a single path to the timezone database.");
}

arrow::GlobalOptions options;
Expand Down
4 changes: 2 additions & 2 deletions r/src/csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ std::shared_ptr<arrow::csv::ConvertOptions> csv___ConvertOptions__initialize(
timestamp_parsers.push_back(
cpp11::as_cpp<std::shared_ptr<arrow::TimestampParser>>(x));
} else {
cpp11::stop(
arrow::arrow_stop(
"unsupported timestamp parser, must be a scalar string or a "
"<TimestampParser> object");
}
}

} else {
cpp11::stop(
arrow::arrow_stop(
"unsupported timestamp parser, must be character vector of strptime "
"specifications, or a list of <TimestampParser> objects");
}
Expand Down
2 changes: 1 addition & 1 deletion r/src/dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ ds::SegmentEncoding GetSegmentEncoding(const std::string& segment_encoding) {
} else if (segment_encoding == "uri") {
return ds::SegmentEncoding::Uri;
}
cpp11::stop("invalid segment encoding: " + segment_encoding);
arrow::arrow_stop("invalid segment encoding: %s", segment_encoding.c_str());
return ds::SegmentEncoding::None;
}

Expand Down
Loading