Skip to content

Commit

Permalink
Sync declaration and implementation signatures (#1827)
Browse files Browse the repository at this point in the history
And rename `class` to `cls` to avoid clashes with C++ keyword
  • Loading branch information
MichaelChirico authored Apr 14, 2023
1 parent af29ad7 commit 77f5622
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 56 deletions.
10 changes: 5 additions & 5 deletions src/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ bool needs_vec_c_fallback(r_obj* ptype) {
}

// Suboptimal: Prevent infinite recursion through `vctrs_vctr` method
r_obj* class = r_attrib_get(ptype, syms_fallback_class);
class = r_chr_get(class, r_length(class) - 1);
r_obj* cls = r_attrib_get(ptype, syms_fallback_class);
cls = r_chr_get(cls, r_length(cls) - 1);

return class != strings_vctrs_vctr;
return cls != strings_vctrs_vctr;
}

bool needs_vec_c_homogeneous_fallback(r_obj* xs, r_obj* ptype) {
Expand Down Expand Up @@ -272,8 +272,8 @@ r_obj* vec_c_fallback(r_obj* ptype,
const struct name_repair_opts* name_repair,
struct vctrs_arg* p_error_arg,
struct r_lazy error_call) {
r_obj* class = KEEP(r_attrib_get(ptype, syms_fallback_class));
bool implements_c = class_implements_base_c(class);
r_obj* cls = KEEP(r_attrib_get(ptype, syms_fallback_class));
bool implements_c = class_implements_base_c(cls);
FREE(1);

if (implements_c) {
Expand Down
2 changes: 1 addition & 1 deletion src/decl/utils-dispatch-decl.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
enum vctrs_class_type class_type(r_obj* x);

static
enum vctrs_class_type class_type_impl(r_obj* class);
enum vctrs_class_type class_type_impl(r_obj* cls);

static
const char* class_type_as_str(enum vctrs_class_type type);
8 changes: 4 additions & 4 deletions src/proxy-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ r_obj* vec_restore_default(r_obj* x, r_obj* to, enum vctrs_owned owned) {
// Shouldn't matter for GNU R but other R implementations might have checks.
// Also record class to set it later with `r_attrib_poke()`. This restores
// the OBJECT bit and is likely more compatible with other implementations.
r_obj* class = r_null;
r_obj* cls = r_null;

{
r_obj* node = attrib;
Expand All @@ -94,7 +94,7 @@ r_obj* vec_restore_default(r_obj* x, r_obj* to, enum vctrs_owned owned) {
tag == r_syms.dim_names || tag == r_syms.class_ ||
tag == r_syms.row_names) {
if (tag == r_syms.class_) {
class = r_node_car(node);
cls = r_node_car(node);
}

if (prev == r_null) {
Expand Down Expand Up @@ -144,8 +144,8 @@ r_obj* vec_restore_default(r_obj* x, r_obj* to, enum vctrs_owned owned) {
FREE(1);
}

if (class != r_null) {
r_attrib_poke(x, r_syms.class_, class);
if (cls != r_null) {
r_attrib_poke(x, r_syms.class_, cls);
}

if (is_s4) {
Expand Down
12 changes: 6 additions & 6 deletions src/utils-dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ enum vctrs_class_type class_type(r_obj* x) {
return VCTRS_CLASS_none;
}

r_obj* class = KEEP(r_class(x));
r_obj* cls = KEEP(r_class(x));

// Avoid corrupt objects where `x` is an object, but the class is NULL
if (class == r_null) {
if (cls == r_null) {
FREE(1);
return VCTRS_CLASS_none;
}

enum vctrs_class_type type = class_type_impl(class);
enum vctrs_class_type type = class_type_impl(cls);

FREE(1);
return type;
}

static
enum vctrs_class_type class_type_impl(r_obj* class) {
int n = r_length(class);
r_obj* const* p = r_chr_cbegin(class);
enum vctrs_class_type class_type_impl(r_obj* cls) {
int n = r_length(cls);
r_obj* const* p = r_chr_cbegin(cls);

// First check for bare types for which we know how many strings are
// the classes composed of
Expand Down
74 changes: 37 additions & 37 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static SEXP syms_as_data_frame2 = NULL;
static SEXP fns_as_data_frame2 = NULL;


static SEXP vctrs_eval_mask_n_impl(SEXP fn_sym, SEXP fn, SEXP* syms, SEXP* args, SEXP mask);
static SEXP vctrs_eval_mask_n_impl(SEXP fn_sym, SEXP fn, SEXP* syms, SEXP* args, SEXP env);

/**
* Evaluate with masked arguments
Expand Down Expand Up @@ -440,27 +440,27 @@ inline void never_reached(const char* fn) {

static char s3_buf[200];

SEXP s3_paste_method_sym(const char* generic, const char* class) {
SEXP s3_paste_method_sym(const char* generic, const char* cls) {
int gen_len = strlen(generic);
int class_len = strlen(class);
int cls_len = strlen(cls);
int dot_len = 1;
if (gen_len + class_len + dot_len >= sizeof(s3_buf)) {
if (gen_len + cls_len + dot_len >= sizeof(s3_buf)) {
r_stop_internal("Generic or class name is too long.");
}

char* buf = s3_buf;

memcpy(buf, generic, gen_len); buf += gen_len;
*buf = '.'; ++buf;
memcpy(buf, class, class_len); buf += class_len;
memcpy(buf, cls, cls_len); buf += cls_len;
*buf = '\0';

return Rf_install(s3_buf);
}

// First check in global env, then in method table
SEXP s3_get_method(const char* generic, const char* class, SEXP table) {
SEXP sym = s3_paste_method_sym(generic, class);
SEXP s3_get_method(const char* generic, const char* cls, SEXP table) {
SEXP sym = s3_paste_method_sym(generic, cls);
return s3_sym_get_method(sym, table);
}
SEXP s3_sym_get_method(SEXP sym, SEXP table) {
Expand All @@ -483,15 +483,15 @@ SEXP vctrs_s3_find_method(SEXP generic, SEXP x, SEXP table) {
}

// [[ register() ]]
r_obj* ffi_s3_get_method(r_obj* generic, r_obj* class, r_obj* table) {
r_obj* ffi_s3_get_method(r_obj* generic, r_obj* cls, r_obj* table) {
if (!r_is_string(generic)) {
r_stop_internal("`generic` must be a string");
}
if (!r_is_string(class)) {
r_stop_internal("`class` must be a string");
if (!r_is_string(cls)) {
r_stop_internal("`cls` must be a string");
}
return s3_get_method(r_chr_get_c_string(generic, 0),
r_chr_get_c_string(class, 0),
r_chr_get_c_string(cls, 0),
table);
}

Expand All @@ -501,25 +501,25 @@ SEXP s3_find_method(const char* generic, SEXP x, SEXP table) {
return R_NilValue;
}

SEXP class = PROTECT(Rf_getAttrib(x, R_ClassSymbol));
SEXP method = s3_class_find_method(generic, class, table);
SEXP cls = PROTECT(Rf_getAttrib(x, R_ClassSymbol));
SEXP method = s3_class_find_method(generic, cls, table);

UNPROTECT(1);
return method;
}

// [[ include("utils.h") ]]
SEXP s3_class_find_method(const char* generic, SEXP class, SEXP table) {
SEXP s3_class_find_method(const char* generic, SEXP cls, SEXP table) {
// Avoid corrupt objects where `x` is an OBJECT(), but the class is NULL
if (class == R_NilValue) {
if (cls == R_NilValue) {
return R_NilValue;
}

SEXP const* p_class = STRING_PTR_RO(class);
int n_class = Rf_length(class);
SEXP const* p_cls = STRING_PTR_RO(cls);
int n_cls = Rf_length(cls);

for (int i = 0; i < n_class; ++i) {
SEXP method = s3_get_method(generic, CHAR(p_class[i]), table);
for (int i = 0; i < n_cls; ++i) {
SEXP method = s3_get_method(generic, CHAR(p_cls[i]), table);
if (method != R_NilValue) {
return method;
}
Expand All @@ -530,28 +530,28 @@ SEXP s3_class_find_method(const char* generic, SEXP class, SEXP table) {

// [[ include("utils.h") ]]
SEXP s3_get_class(SEXP x) {
SEXP class = R_NilValue;
SEXP cls = R_NilValue;

if (OBJECT(x)) {
class = Rf_getAttrib(x, R_ClassSymbol);
cls = Rf_getAttrib(x, R_ClassSymbol);
}

// This handles unclassed objects as well as gremlins objects where
// `x` is an OBJECT(), but the class is NULL
if (class == R_NilValue) {
class = s3_bare_class(x);
if (cls == R_NilValue) {
cls = s3_bare_class(x);
}

if (!Rf_length(class)) {
if (!Rf_length(cls)) {
r_stop_internal("Class must have length.");
}

return class;
return cls;
}

SEXP s3_get_class0(SEXP x) {
SEXP class = PROTECT(s3_get_class(x));
SEXP out = STRING_ELT(class, 0);
SEXP cls = PROTECT(s3_get_class(x));
SEXP out = STRING_ELT(cls, 0);
UNPROTECT(1);
return out;
}
Expand Down Expand Up @@ -586,9 +586,9 @@ SEXP s3_find_method2(const char* generic,
SEXP x,
SEXP table,
SEXP* method_sym_out) {
SEXP class = PROTECT(s3_get_class0(x));
SEXP cls = PROTECT(s3_get_class0(x));

SEXP method_sym = s3_paste_method_sym(generic, CHAR(class));
SEXP method_sym = s3_paste_method_sym(generic, CHAR(cls));
SEXP method = s3_sym_get_method(method_sym, table);

if (method == R_NilValue) {
Expand Down Expand Up @@ -621,8 +621,8 @@ SEXP s3_bare_class(SEXP x) {
}
}

static SEXP s4_get_method(const char* class, SEXP table) {
SEXP sym = Rf_install(class);
static SEXP s4_get_method(const char* cls, SEXP table) {
SEXP sym = Rf_install(cls);

SEXP method = r_env_get(table, sym);
if (r_is_function(method)) {
Expand All @@ -638,20 +638,20 @@ SEXP s4_find_method(SEXP x, SEXP table) {
return R_NilValue;
}

SEXP class = PROTECT(Rf_getAttrib(x, R_ClassSymbol));
SEXP out = s4_class_find_method(class, table);
SEXP cls = PROTECT(Rf_getAttrib(x, R_ClassSymbol));
SEXP out = s4_class_find_method(cls, table);

UNPROTECT(1);
return out;
}
SEXP s4_class_find_method(SEXP class, SEXP table) {
SEXP s4_class_find_method(SEXP cls, SEXP table) {
// Avoid corrupt objects where `x` is an OBJECT(), but the class is NULL
if (class == R_NilValue) {
if (cls == R_NilValue) {
return R_NilValue;
}

SEXP const* p_class = STRING_PTR_RO(class);
int n_class = Rf_length(class);
SEXP const* p_class = STRING_PTR_RO(cls);
int n_class = Rf_length(cls);

for (int i = 0; i < n_class; ++i) {
SEXP method = s4_get_method(CHAR(p_class[i]), table);
Expand Down
6 changes: 3 additions & 3 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ SEXP chr_resize(SEXP x, r_ssize x_size, r_ssize size);
SEXP s3_get_method(const char* generic, const char* cls, SEXP table);
SEXP s3_sym_get_method(SEXP sym, SEXP table);
SEXP s3_find_method(const char* generic, SEXP x, SEXP table);
SEXP s3_class_find_method(const char* generic, SEXP class, SEXP table);
SEXP s3_class_find_method(const char* generic, SEXP cls, SEXP table);
SEXP s3_get_class(SEXP x);
SEXP s3_find_method_xy(const char* generic,
SEXP x,
Expand All @@ -151,7 +151,7 @@ SEXP s3_find_method2(const char* generic,
SEXP s3_paste_method_sym(const char* generic, const char* cls);
SEXP s3_bare_class(SEXP x);
SEXP s4_find_method(SEXP x, SEXP table);
SEXP s4_class_find_method(SEXP class, SEXP table);
SEXP s4_class_find_method(SEXP cls, SEXP table);
bool vec_implements_ptype2(SEXP x);

SEXP r_env_get(SEXP env, SEXP sym);
Expand All @@ -166,7 +166,7 @@ SEXP list_first_non_null(SEXP xs, R_len_t* non_null_i);
bool list_is_homogeneously_classed(SEXP xs);

// Destructive compacting
SEXP node_compact_d(SEXP xs);
SEXP node_compact_d(SEXP node);

void never_reached(const char* fn) __attribute__((noreturn));

Expand Down

0 comments on commit 77f5622

Please sign in to comment.