Skip to content
Merged
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
12 changes: 6 additions & 6 deletions ext/rubydex/declaration.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ static VALUE declaration_definitions_yield(VALUE args) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);

int64_t id = 0;
uint32_t id = 0;
DefinitionKind kind;
while (rdx_definitions_iter_next(iter, &id, &kind)) {
VALUE argv[] = {data->graph_obj, LL2NUM(id)};
VALUE argv[] = {data->graph_obj, UINT2NUM(id)};
VALUE defn_class = rdxi_definition_class_for_kind(kind);
VALUE handle = rb_class_new_instance(2, argv, defn_class);
rb_yield(handle);
Expand Down Expand Up @@ -120,14 +120,14 @@ static VALUE rdxr_declaration_member(VALUE self, VALUE name) {
rb_raise(rb_eTypeError, "expected String");
}

const int64_t *id_ptr = rdx_declaration_member(graph, data->id, StringValueCStr(name));
const uint32_t *id_ptr = rdx_declaration_member(graph, data->id, StringValueCStr(name));
if (id_ptr == NULL) {
return Qnil;
}

int64_t id = *id_ptr;
free_i64(id_ptr);
VALUE argv[] = {data->graph_obj, LL2NUM(id)};
uint32_t id = *id_ptr;
free_u32(id_ptr);
VALUE argv[] = {data->graph_obj, UINT2NUM(id)};

return rb_class_new_instance(2, argv, cDeclaration);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/rubydex/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ static VALUE document_definitions_yield(VALUE args) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);

int64_t id = 0;
uint32_t id = 0;
DefinitionKind kind;
while (rdx_definitions_iter_next(iter, &id, &kind)) {
VALUE argv[] = {data->graph_obj, LL2NUM(id)};
VALUE argv[] = {data->graph_obj, UINT2NUM(id)};
VALUE defn_class = rdxi_definition_class_for_kind(kind);
VALUE handle = rb_class_new_instance(2, argv, defn_class);
rb_yield(handle);
Expand Down
28 changes: 14 additions & 14 deletions ext/rubydex/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ static VALUE graph_declarations_yield(VALUE args) {
VALUE self = rb_ary_entry(args, 0);
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));

int64_t id = 0;
uint32_t id = 0;
while (rdx_graph_declarations_iter_next(iter, &id)) {
VALUE argv[] = {self, LL2NUM(id)};
VALUE argv[] = {self, UINT2NUM(id)};
VALUE handle = rb_class_new_instance(2, argv, cDeclaration);
rb_yield(handle);
}
Expand Down Expand Up @@ -141,9 +141,9 @@ static VALUE graph_documents_yield(VALUE args) {
VALUE self = rb_ary_entry(args, 0);
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));

int64_t id = 0;
uint32_t id = 0;
while (rdx_graph_documents_iter_next(iter, &id)) {
VALUE argv[] = {self, LL2NUM(id)};
VALUE argv[] = {self, UINT2NUM(id)};
VALUE handle = rb_class_new_instance(2, argv, cDocument);
rb_yield(handle);
}
Expand Down Expand Up @@ -198,14 +198,14 @@ static VALUE rdxr_graph_aref(VALUE self, VALUE key) {
rb_raise(rb_eTypeError, "expected String");
}

const int64_t *id_ptr = rdx_graph_get_declaration(graph, StringValueCStr(key));
const uint32_t *id_ptr = rdx_graph_get_declaration(graph, StringValueCStr(key));
if (id_ptr == NULL) {
return Qnil;
}

int64_t id = *id_ptr;
free_i64(id_ptr);
VALUE argv[] = {self, LL2NUM(id)};
uint32_t id = *id_ptr;
free_u32(id_ptr);
VALUE argv[] = {self, UINT2NUM(id)};

return rb_class_new_instance(2, argv, cDeclaration);
}
Expand All @@ -215,11 +215,11 @@ static VALUE graph_references_yield(VALUE args) {
VALUE self = rb_ary_entry(args, 0);
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));

int64_t id = 0;
uint32_t id = 0;
ReferenceKind kind;
while (rdx_references_iter_next(iter, &id, &kind)) {
VALUE ref_class = rdxi_reference_class_for_kind(kind);
VALUE argv[] = {self, LL2NUM(id)};
VALUE argv[] = {self, UINT2NUM(id)};
VALUE obj = rb_class_new_instance(2, argv, ref_class);
rb_yield(obj);
}
Expand Down Expand Up @@ -333,7 +333,7 @@ static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nes
void *graph;
TypedData_Get_Struct(self, void *, &graph_type, graph);

const int64_t *id_ptr =
const uint32_t *id_ptr =
rdx_graph_resolve_constant(graph, StringValueCStr(const_name), (const char **)converted_file_paths, length);

for (size_t i = 0; i < length; i++) {
Expand All @@ -345,9 +345,9 @@ static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nes
return Qnil;
}

int64_t id = *id_ptr;
free_i64(id_ptr);
VALUE argv[] = {self, LL2NUM(id)};
uint32_t id = *id_ptr;
free_u32(id_ptr);
VALUE argv[] = {self, UINT2NUM(id)};

return rb_class_new_instance(2, argv, cDeclaration);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/rubydex/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

typedef struct {
VALUE graph_obj; // Ruby Graph object to keep it alive
int64_t id; // Canonical ID (i64) mapping to a DeclarationId, DefinitionId, UriId, etc. See `ids.rs`.
uint32_t id; // Canonical ID mapping to a DeclarationId, DefinitionId, UriId, etc. See `ids.rs`.
} HandleData;

static void handle_mark(void *ptr) {
Expand Down Expand Up @@ -36,7 +36,7 @@ static VALUE rdxr_handle_initialize(VALUE self, VALUE graph_obj, VALUE id_val) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);
data->graph_obj = graph_obj;
data->id = NUM2LL(id_val);
data->id = NUM2UINT(id_val);

return self;
}
Expand Down
12 changes: 6 additions & 6 deletions rust/rubydex-sys/src/declaration_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rubydex::model::ids::{DeclarationId, StringId};
///
/// This function will panic if the name pointer is invalid.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_declaration_name(pointer: GraphPointer, name_id: i64) -> *const c_char {
pub unsafe extern "C" fn rdx_declaration_name(pointer: GraphPointer, name_id: u32) -> *const c_char {
with_graph(pointer, |graph| {
let name_id = DeclarationId::new(name_id);
if let Some(decl) = graph.declarations().get(&name_id) {
Expand All @@ -40,9 +40,9 @@ pub unsafe extern "C" fn rdx_declaration_name(pointer: GraphPointer, name_id: i6
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_declaration_member(
pointer: GraphPointer,
name_id: i64,
name_id: u32,
member: *const c_char,
) -> *const i64 {
) -> *const u32 {
let Ok(member_str) = (unsafe { utils::convert_char_ptr_to_string(member) }) else {
return ptr::null();
};
Expand Down Expand Up @@ -72,7 +72,7 @@ pub unsafe extern "C" fn rdx_declaration_member(
///
/// This function will panic if the name pointer is invalid.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_declaration_unqualified_name(pointer: GraphPointer, name_id: i64) -> *const c_char {
pub unsafe extern "C" fn rdx_declaration_unqualified_name(pointer: GraphPointer, name_id: u32) -> *const c_char {
with_graph(pointer, |graph| {
let name_id = DeclarationId::new(name_id);
if let Some(decl) = graph.declarations().get(&name_id) {
Expand All @@ -96,15 +96,15 @@ pub unsafe extern "C" fn rdx_declaration_unqualified_name(pointer: GraphPointer,
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_declaration_definitions_iter_new(
pointer: GraphPointer,
decl_id: i64,
decl_id: u32,
) -> *mut DefinitionsIter {
// Snapshot the IDs and kinds at iterator creation to avoid borrowing across FFI calls
with_graph(pointer, |graph| {
let decl_id = DeclarationId::new(decl_id);
if let Some(decl) = graph.declarations().get(&decl_id) {
rdx_definitions_iter_new_from_ids(graph, decl.definitions())
} else {
DefinitionsIter::new(Vec::<(i64, DefinitionKind)>::new().into_boxed_slice())
DefinitionsIter::new(Vec::<(u32, DefinitionKind)>::new().into_boxed_slice())
}
})
}
20 changes: 10 additions & 10 deletions rust/rubydex-sys/src/definition_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn map_definition_to_kind(defn: &Definition) -> DefinitionKind {
///
/// This function will panic if the definition cannot be found.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_definition_kind(pointer: GraphPointer, definition_id: i64) -> DefinitionKind {
pub unsafe extern "C" fn rdx_definition_kind(pointer: GraphPointer, definition_id: u32) -> DefinitionKind {
with_graph(pointer, |graph| {
let definition_id = DefinitionId::new(definition_id);
if let Some(defn) = graph.definitions().get(&definition_id) {
Expand All @@ -79,7 +79,7 @@ pub unsafe extern "C" fn rdx_definition_kind(pointer: GraphPointer, definition_i
///
/// This function will panic if the definition cannot be found.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_definition_name(pointer: GraphPointer, definition_id: i64) -> *const c_char {
pub unsafe extern "C" fn rdx_definition_name(pointer: GraphPointer, definition_id: u32) -> *const c_char {
with_graph(pointer, |graph| {
let def_id = DefinitionId::new(definition_id);
if let Some(defn) = graph.definitions().get(&def_id) {
Expand All @@ -99,13 +99,13 @@ pub unsafe extern "C" fn rdx_definition_name(pointer: GraphPointer, definition_i
/// Shared iterator over definition (id, kind) pairs
#[derive(Debug)]
pub struct DefinitionsIter {
pub entries: Box<[(i64, DefinitionKind)]>,
pub entries: Box<[(u32, DefinitionKind)]>,
pub index: usize,
}

impl DefinitionsIter {
#[must_use]
pub fn new(entries: Box<[(i64, DefinitionKind)]>) -> *mut DefinitionsIter {
pub fn new(entries: Box<[(u32, DefinitionKind)]>) -> *mut DefinitionsIter {
Box::into_raw(Box::new(DefinitionsIter { entries, index: 0 }))
}
}
Expand All @@ -131,7 +131,7 @@ pub unsafe extern "C" fn rdx_definitions_iter_len(iter: *const DefinitionsIter)
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_definitions_iter_next(
iter: *mut DefinitionsIter,
out_id: *mut i64,
out_id: *mut u32,
out_kind: *mut DefinitionKind,
) -> bool {
if iter.is_null() || out_id.is_null() || out_kind.is_null() {
Expand Down Expand Up @@ -191,7 +191,7 @@ pub struct CommentArray {
/// # Panics
/// This function will panic if a definition or document cannot be found.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_definition_comments(pointer: GraphPointer, definition_id: i64) -> *mut CommentArray {
pub unsafe extern "C" fn rdx_definition_comments(pointer: GraphPointer, definition_id: u32) -> *mut CommentArray {
with_graph(pointer, |graph| {
let def_id = DefinitionId::new(definition_id);
let Some(defn) = graph.definitions().get(&def_id) else {
Expand Down Expand Up @@ -265,7 +265,7 @@ pub unsafe extern "C" fn rdx_definition_comments_free(ptr: *mut CommentArray) {
///
/// This function will panic if a definition or document cannot be found.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_definition_location(pointer: GraphPointer, definition_id: i64) -> *mut Location {
pub unsafe extern "C" fn rdx_definition_location(pointer: GraphPointer, definition_id: u32) -> *mut Location {
with_graph(pointer, |graph| {
let def_id = DefinitionId::new(definition_id);
let Some(defn) = graph.definitions().get(&def_id) else {
Expand Down Expand Up @@ -299,7 +299,7 @@ where
.map_or_else(|| panic!("Definition not found: {id:?}"), map_definition_to_kind);
(id, kind)
})
.collect::<Vec<(i64, DefinitionKind)>>()
.collect::<Vec<(u32, DefinitionKind)>>()
.into_boxed_slice();

DefinitionsIter::new(entries)
Expand All @@ -314,7 +314,7 @@ where
/// # Panics
/// This function will panic if a definition cannot be found.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_definition_is_deprecated(pointer: GraphPointer, definition_id: i64) -> bool {
pub unsafe extern "C" fn rdx_definition_is_deprecated(pointer: GraphPointer, definition_id: u32) -> bool {
with_graph(pointer, |graph| {
let def_id = DefinitionId::new(definition_id);
let defn = graph.definitions().get(&def_id).expect("definition not found");
Expand All @@ -335,7 +335,7 @@ pub unsafe extern "C" fn rdx_definition_is_deprecated(pointer: GraphPointer, def
/// # Panics
/// Panics if the definition's document does not exist in the graph.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_definition_name_location(pointer: GraphPointer, definition_id: i64) -> *mut Location {
pub unsafe extern "C" fn rdx_definition_name_location(pointer: GraphPointer, definition_id: u32) -> *mut Location {
with_graph(pointer, |graph| {
let def_id = DefinitionId::new(definition_id);
let Some(defn) = graph.definitions().get(&def_id) else {
Expand Down
6 changes: 3 additions & 3 deletions rust/rubydex-sys/src/document_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rubydex::model::ids::UriId;
///
/// This function will panic if the URI pointer is invalid.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_document_uri(pointer: GraphPointer, uri_id: i64) -> *const c_char {
pub unsafe extern "C" fn rdx_document_uri(pointer: GraphPointer, uri_id: u32) -> *const c_char {
with_graph(pointer, |graph| {
let uri_id = UriId::new(uri_id);
if let Some(doc) = graph.documents().get(&uri_id) {
Expand All @@ -41,14 +41,14 @@ pub unsafe extern "C" fn rdx_document_uri(pointer: GraphPointer, uri_id: i64) ->
/// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
/// - The returned pointer must be freed with `rdx_document_definitions_iter_free`.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rdx_document_definitions_iter_new(pointer: GraphPointer, uri_id: i64) -> *mut DefinitionsIter {
pub unsafe extern "C" fn rdx_document_definitions_iter_new(pointer: GraphPointer, uri_id: u32) -> *mut DefinitionsIter {
// Snapshot the IDs and kinds at iterator creation to avoid borrowing across FFI calls
with_graph(pointer, |graph| {
let uri_id = UriId::new(uri_id);
if let Some(doc) = graph.documents().get(&uri_id) {
rdx_definitions_iter_new_from_ids(graph, doc.definitions())
} else {
DefinitionsIter::new(Vec::<(i64, DefinitionKind)>::new().into_boxed_slice())
DefinitionsIter::new(Vec::<(u32, DefinitionKind)>::new().into_boxed_slice())
}
})
}
Loading
Loading