99#include "utils.h"
1010
1111static VALUE cGraph ;
12+ static VALUE mRubydex ;
1213
1314// Free function for the custom Graph allocator. We always have to call into Rust to free data allocated by it
1415static void graph_free (void * ptr ) {
@@ -449,6 +450,32 @@ static VALUE rdxr_graph_require_paths(VALUE self, VALUE load_path) {
449450 return array ;
450451}
451452
453+ // Graph#check_integrity: () -> Array[Rubydex::IntegrityFailure]
454+ // Returns an array of IntegrityFailure objects, empty if no issues found
455+ static VALUE rdxr_graph_check_integrity (VALUE self ) {
456+ void * graph ;
457+ TypedData_Get_Struct (self , void * , & graph_type , graph );
458+
459+ size_t error_count = 0 ;
460+ const char * const * errors = rdx_check_integrity (graph , & error_count );
461+
462+ if (errors == NULL ) {
463+ return rb_ary_new ();
464+ }
465+
466+ VALUE cIntegrityError = rb_const_get (mRubydex , rb_intern ("IntegrityFailure" ));
467+ VALUE array = rb_ary_new_capa ((long )error_count );
468+
469+ for (size_t i = 0 ; i < error_count ; i ++ ) {
470+ VALUE argv [] = {rb_utf8_str_new_cstr (errors [i ])};
471+ VALUE error = rb_class_new_instance (1 , argv , cIntegrityError );
472+ rb_ary_push (array , error );
473+ }
474+
475+ free_c_string_array (errors , error_count );
476+ return array ;
477+ }
478+
452479// Graph#diagnostics -> Array[Rubydex::Diagnostic]
453480static VALUE rdxr_graph_diagnostics (VALUE self ) {
454481 void * graph ;
@@ -482,7 +509,8 @@ static VALUE rdxr_graph_diagnostics(VALUE self) {
482509 return diagnostics ;
483510}
484511
485- void rdxi_initialize_graph (VALUE mRubydex ) {
512+ void rdxi_initialize_graph (VALUE moduleRubydex ) {
513+ mRubydex = moduleRubydex ;
486514 cGraph = rb_define_class_under (mRubydex , "Graph" , rb_cObject );
487515 rb_define_alloc_func (cGraph , rdxr_graph_alloc );
488516 rb_define_method (cGraph , "index_all" , rdxr_graph_index_all , 1 );
@@ -495,6 +523,7 @@ void rdxi_initialize_graph(VALUE mRubydex) {
495523 rb_define_method (cGraph , "constant_references" , rdxr_graph_constant_references , 0 );
496524 rb_define_method (cGraph , "method_references" , rdxr_graph_method_references , 0 );
497525 rb_define_method (cGraph , "diagnostics" , rdxr_graph_diagnostics , 0 );
526+ rb_define_method (cGraph , "check_integrity" , rdxr_graph_check_integrity , 0 );
498527 rb_define_method (cGraph , "[]" , rdxr_graph_aref , 1 );
499528 rb_define_method (cGraph , "search" , rdxr_graph_search , 1 );
500529 rb_define_method (cGraph , "encoding=" , rdxr_graph_set_encoding , 1 );
0 commit comments