@@ -93,17 +93,17 @@ typedef struct
93
93
size_t yajl_bytes_consumed ;
94
94
} scan_ctx ;
95
95
96
- inline size_t scan_ctx_get_bytes_consumed (scan_ctx * ctx )
96
+ static inline size_t scan_ctx_get_bytes_consumed (scan_ctx * ctx )
97
97
{
98
98
return ctx -> yajl_bytes_consumed + yajl_get_bytes_consumed (ctx -> handle );
99
99
}
100
100
101
- inline void scan_ctx_save_bytes_consumed (scan_ctx * ctx )
101
+ static inline void scan_ctx_save_bytes_consumed (scan_ctx * ctx )
102
102
{
103
103
ctx -> yajl_bytes_consumed += yajl_get_bytes_consumed (ctx -> handle );
104
104
}
105
105
106
- void scan_ctx_debug (scan_ctx * ctx )
106
+ static void scan_ctx_debug (scan_ctx * ctx )
107
107
{
108
108
// actually might have been cleared by GC already, be careful, debug only when in valid state
109
109
VALUE points_list_inspect = ctx -> points_list == Qundef ? rb_str_new_cstr ("undef" ) : rb_sprintf ("%" PRIsVALUE , rb_inspect (ctx -> points_list ));
@@ -176,7 +176,7 @@ void scan_ctx_debug(scan_ctx *ctx)
176
176
177
177
// FIXME: This will cause memory leak if ruby_xmalloc raises
178
178
// path_ary must be RB_GC_GUARD-ed by the caller
179
- VALUE scan_ctx_init (scan_ctx * ctx , VALUE path_ary , VALUE string_keys )
179
+ static VALUE scan_ctx_init (scan_ctx * ctx , VALUE path_ary , VALUE string_keys )
180
180
{
181
181
int path_ary_len ;
182
182
paths_t * paths ;
@@ -313,7 +313,7 @@ VALUE scan_ctx_init(scan_ctx *ctx, VALUE path_ary, VALUE string_keys)
313
313
}
314
314
315
315
// resets temporary values in the config
316
- void scan_ctx_reset (scan_ctx * ctx , VALUE points_list , VALUE roots_info_list , int with_path , int symbolize_path_keys )
316
+ static void scan_ctx_reset (scan_ctx * ctx , VALUE points_list , VALUE roots_info_list , int with_path , int symbolize_path_keys )
317
317
{
318
318
// TODO: reset matched_depth if implemented
319
319
ctx -> current_path_len = 0 ;
@@ -326,7 +326,7 @@ void scan_ctx_reset(scan_ctx *ctx, VALUE points_list, VALUE roots_info_list, int
326
326
ctx -> symbolize_path_keys = symbolize_path_keys ;
327
327
}
328
328
329
- void scan_ctx_free (scan_ctx * ctx )
329
+ static void scan_ctx_free (scan_ctx * ctx )
330
330
{
331
331
// fprintf(stderr, "scan_ctx_free\n");
332
332
if (!ctx )
@@ -343,7 +343,7 @@ void scan_ctx_free(scan_ctx *ctx)
343
343
}
344
344
345
345
// noexcept
346
- inline void increment_arr_index (scan_ctx * sctx )
346
+ static inline void increment_arr_index (scan_ctx * sctx )
347
347
{
348
348
// remember - any value can be root
349
349
// TODO: Maybe make current_path_len 1 shorter and get rid of -1; need to change all compares
@@ -364,7 +364,7 @@ typedef enum
364
364
} value_type ;
365
365
366
366
// noexcept
367
- VALUE create_point (scan_ctx * sctx , value_type type , size_t length )
367
+ static VALUE create_point (scan_ctx * sctx , value_type type , size_t length )
368
368
{
369
369
VALUE values [3 ], point ;
370
370
size_t curr_pos = scan_ctx_get_bytes_consumed (sctx );
@@ -405,7 +405,7 @@ VALUE create_point(scan_ctx *sctx, value_type type, size_t length)
405
405
}
406
406
407
407
// noexcept
408
- VALUE create_path (scan_ctx * sctx )
408
+ static VALUE create_path (scan_ctx * sctx )
409
409
{
410
410
VALUE path = rb_ary_new_capa (sctx -> current_path_len );
411
411
for (int i = 0 ; i < sctx -> current_path_len ; i ++ )
@@ -431,7 +431,7 @@ VALUE create_path(scan_ctx *sctx)
431
431
}
432
432
433
433
// noexcept
434
- inline void save_root_info (scan_ctx * sctx , VALUE type )
434
+ static inline void save_root_info (scan_ctx * sctx , VALUE type )
435
435
{
436
436
if (sctx -> roots_info_list != Qundef && sctx -> current_path_len == 0 )
437
437
{
@@ -440,7 +440,7 @@ inline void save_root_info(scan_ctx *sctx, VALUE type)
440
440
}
441
441
442
442
// noexcept
443
- void save_point (scan_ctx * sctx , value_type type , size_t length )
443
+ static void save_point (scan_ctx * sctx , value_type type , size_t length )
444
444
{
445
445
// TODO: Abort parsing if all paths are matched and no more mathces are possible: only trivial key/index matchers at the current level
446
446
// TODO: Don't re-compare already matched prefixes; hard to invalidate, though
@@ -501,7 +501,7 @@ void save_point(scan_ctx *sctx, value_type type, size_t length)
501
501
}
502
502
503
503
// noexcept
504
- int scan_on_null (void * ctx )
504
+ static int scan_on_null (void * ctx )
505
505
{
506
506
scan_ctx * sctx = (scan_ctx * )ctx ;
507
507
save_root_info (sctx , null_sym );
@@ -513,7 +513,7 @@ int scan_on_null(void *ctx)
513
513
}
514
514
515
515
// noexcept
516
- int scan_on_boolean (void * ctx , int bool_val )
516
+ static int scan_on_boolean (void * ctx , int bool_val )
517
517
{
518
518
scan_ctx * sctx = (scan_ctx * )ctx ;
519
519
save_root_info (sctx , boolean_sym );
@@ -525,7 +525,7 @@ int scan_on_boolean(void *ctx, int bool_val)
525
525
}
526
526
527
527
// noexcept
528
- int scan_on_number (void * ctx , const char * val , size_t len )
528
+ static int scan_on_number (void * ctx , const char * val , size_t len )
529
529
{
530
530
scan_ctx * sctx = (scan_ctx * )ctx ;
531
531
save_root_info (sctx , number_sym );
@@ -537,7 +537,7 @@ int scan_on_number(void *ctx, const char *val, size_t len)
537
537
}
538
538
539
539
// noexcept
540
- int scan_on_string (void * ctx , const unsigned char * val , size_t len )
540
+ static int scan_on_string (void * ctx , const unsigned char * val , size_t len )
541
541
{
542
542
scan_ctx * sctx = (scan_ctx * )ctx ;
543
543
save_root_info (sctx , string_sym );
@@ -549,7 +549,7 @@ int scan_on_string(void *ctx, const unsigned char *val, size_t len)
549
549
}
550
550
551
551
// noexcept
552
- int scan_on_start_object (void * ctx )
552
+ static int scan_on_start_object (void * ctx )
553
553
{
554
554
scan_ctx * sctx = (scan_ctx * )ctx ;
555
555
// Save in the beginning in case of a partial value
@@ -568,7 +568,7 @@ int scan_on_start_object(void *ctx)
568
568
}
569
569
570
570
// noexcept
571
- int scan_on_key (void * ctx , const unsigned char * key , size_t len )
571
+ static int scan_on_key (void * ctx , const unsigned char * key , size_t len )
572
572
{
573
573
scan_ctx * sctx = (scan_ctx * )ctx ;
574
574
if (sctx -> current_path_len > sctx -> max_path_len )
@@ -581,7 +581,7 @@ int scan_on_key(void *ctx, const unsigned char *key, size_t len)
581
581
}
582
582
583
583
// noexcept
584
- int scan_on_end_object (void * ctx )
584
+ static int scan_on_end_object (void * ctx )
585
585
{
586
586
scan_ctx * sctx = (scan_ctx * )ctx ;
587
587
sctx -> current_path_len -- ;
@@ -591,7 +591,7 @@ int scan_on_end_object(void *ctx)
591
591
}
592
592
593
593
// noexcept
594
- int scan_on_start_array (void * ctx )
594
+ static int scan_on_start_array (void * ctx )
595
595
{
596
596
scan_ctx * sctx = (scan_ctx * )ctx ;
597
597
// Save in the beginning in case of a partial value
@@ -613,7 +613,7 @@ int scan_on_start_array(void *ctx)
613
613
}
614
614
615
615
// noexcept
616
- int scan_on_end_array (void * ctx )
616
+ static int scan_on_end_array (void * ctx )
617
617
{
618
618
scan_ctx * sctx = (scan_ctx * )ctx ;
619
619
sctx -> current_path_len -- ;
@@ -622,13 +622,13 @@ int scan_on_end_array(void *ctx)
622
622
return true;
623
623
}
624
624
625
- void config_free (void * data )
625
+ static void config_free (void * data )
626
626
{
627
627
scan_ctx_free ((scan_ctx * )data );
628
628
ruby_xfree (data );
629
629
}
630
630
631
- size_t config_size (const void * data )
631
+ static size_t config_size (const void * data )
632
632
{
633
633
// see ObjectSpace.memsize_of
634
634
scan_ctx * ctx = (scan_ctx * )data ;
@@ -659,7 +659,7 @@ static const rb_data_type_t config_type = {
659
659
.flags = RUBY_TYPED_FREE_IMMEDIATELY ,
660
660
};
661
661
662
- VALUE config_alloc (VALUE self )
662
+ static VALUE config_alloc (VALUE self )
663
663
{
664
664
scan_ctx * ctx = ruby_xmalloc (sizeof (scan_ctx ));
665
665
ctx -> paths = NULL ;
@@ -671,7 +671,7 @@ VALUE config_alloc(VALUE self)
671
671
return TypedData_Wrap_Struct (self , & config_type , ctx );
672
672
}
673
673
674
- VALUE config_m_initialize (VALUE self , VALUE path_ary )
674
+ static VALUE config_m_initialize (VALUE self , VALUE path_ary )
675
675
{
676
676
scan_ctx * ctx ;
677
677
VALUE scan_ctx_init_err , string_keys ;
@@ -686,7 +686,7 @@ VALUE config_m_initialize(VALUE self, VALUE path_ary)
686
686
return self ;
687
687
}
688
688
689
- VALUE config_m_inspect (VALUE self )
689
+ static VALUE config_m_inspect (VALUE self )
690
690
{
691
691
scan_ctx * ctx ;
692
692
VALUE res ;
@@ -738,10 +738,10 @@ static yajl_callbacks scan_callbacks = {
738
738
739
739
// def scan(json_str, path_arr, opts)
740
740
// opts
741
- // with_path: false, verbose_error: false,
741
+ // with_path: false, verbose_error: false, symbolize_path_keys: false, with_roots_info: false
742
742
// the following opts converted to bool and passed to yajl_config if provided, ignored if not provided
743
743
// allow_comments, dont_validate_strings, allow_trailing_garbage, allow_multiple_values, allow_partial_values
744
- VALUE scan (int argc , VALUE * argv , VALUE self )
744
+ static VALUE scan (int argc , VALUE * argv , VALUE self )
745
745
{
746
746
VALUE json_str , path_ary , with_path_flag , kwargs ;
747
747
VALUE kwargs_values [SCAN_KWARGS_SIZE ];
0 commit comments