@@ -12,23 +12,23 @@ static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-built
12
12
static const xmlChar * NOKOGIRI_BUILTIN_URI = (const xmlChar * )"https://www.nokogiri.org/default_ns/ruby/builtins" ;
13
13
14
14
static void
15
- xml_xpath_context_deallocate (void * data )
15
+ _noko_xml_xpath_context_dfree (void * data )
16
16
{
17
17
xmlXPathContextPtr c_context = data ;
18
18
xmlXPathFreeContext (c_context );
19
19
}
20
20
21
- static const rb_data_type_t xml_xpath_context_type = {
21
+ static const rb_data_type_t _noko_xml_xpath_context_type = {
22
22
.wrap_struct_name = "xmlXPathContext" ,
23
23
.function = {
24
- .dfree = xml_xpath_context_deallocate ,
24
+ .dfree = _noko_xml_xpath_context_dfree ,
25
25
},
26
26
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED ,
27
27
};
28
28
29
29
/* find a CSS class in an HTML element's `class` attribute */
30
30
static const xmlChar *
31
- builtin_css_class (const xmlChar * str , const xmlChar * val )
31
+ _noko_xml_xpath_context__css_class (const xmlChar * str , const xmlChar * val )
32
32
{
33
33
int val_len ;
34
34
@@ -62,9 +62,9 @@ builtin_css_class(const xmlChar *str, const xmlChar *val)
62
62
return (NULL );
63
63
}
64
64
65
- /* xmlXPathFunction to wrap builtin_css_class () */
65
+ /* xmlXPathFunction to wrap _noko_xml_xpath_context__css_class () */
66
66
static void
67
- xpath_builtin_css_class (xmlXPathParserContextPtr ctxt , int nargs )
67
+ noko_xml_xpath_context_xpath_func_css_class (xmlXPathParserContextPtr ctxt , int nargs )
68
68
{
69
69
xmlXPathObjectPtr hay , needle ;
70
70
@@ -85,7 +85,7 @@ xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
85
85
XP_ERROR (XPATH_INVALID_TYPE );
86
86
}
87
87
88
- if (builtin_css_class (hay -> stringval , needle -> stringval )) {
88
+ if (_noko_xml_xpath_context__css_class (hay -> stringval , needle -> stringval )) {
89
89
valuePush (ctxt , xmlXPathNewBoolean (1 ));
90
90
} else {
91
91
valuePush (ctxt , xmlXPathNewBoolean (0 ));
@@ -99,7 +99,7 @@ xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
99
99
/* xmlXPathFunction to select nodes whose local name matches, for HTML5 CSS queries that should
100
100
* ignore namespaces */
101
101
static void
102
- xpath_builtin_local_name_is (xmlXPathParserContextPtr ctxt , int nargs )
102
+ noko_xml_xpath_context_xpath_func_local_name_is (xmlXPathParserContextPtr ctxt , int nargs )
103
103
{
104
104
xmlXPathObjectPtr element_name ;
105
105
@@ -129,12 +129,12 @@ xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
129
129
* [Returns] +self+
130
130
*/
131
131
static VALUE
132
- rb_xml_xpath_context_register_ns (VALUE rb_context , VALUE prefix , VALUE uri )
132
+ noko_xml_xpath_context_register_ns (VALUE rb_context , VALUE prefix , VALUE uri )
133
133
{
134
134
xmlXPathContextPtr c_context ;
135
135
const xmlChar * ns_uri ;
136
136
137
- TypedData_Get_Struct (rb_context , xmlXPathContext , & xml_xpath_context_type , c_context );
137
+ TypedData_Get_Struct (rb_context , xmlXPathContext , & _noko_xml_xpath_context_type , c_context );
138
138
139
139
if (NIL_P (uri )) {
140
140
ns_uri = NULL ;
@@ -164,12 +164,12 @@ rb_xml_xpath_context_register_ns(VALUE rb_context, VALUE prefix, VALUE uri)
164
164
* [Returns] +self+
165
165
*/
166
166
static VALUE
167
- rb_xml_xpath_context_register_variable (VALUE rb_context , VALUE name , VALUE value )
167
+ noko_xml_xpath_context_register_variable (VALUE rb_context , VALUE name , VALUE value )
168
168
{
169
169
xmlXPathContextPtr c_context ;
170
170
xmlXPathObjectPtr xmlValue ;
171
171
172
- TypedData_Get_Struct (rb_context , xmlXPathContext , & xml_xpath_context_type , c_context );
172
+ TypedData_Get_Struct (rb_context , xmlXPathContext , & _noko_xml_xpath_context_type , c_context );
173
173
174
174
if (NIL_P (value )) {
175
175
xmlValue = NULL ;
@@ -195,7 +195,7 @@ rb_xml_xpath_context_register_variable(VALUE rb_context, VALUE name, VALUE value
195
195
* returns Qundef if no conversion was possible.
196
196
*/
197
197
static VALUE
198
- xpath2ruby (xmlXPathObjectPtr c_xpath_object , xmlXPathContextPtr c_context )
198
+ _noko_xml_xpath_context__xpath2ruby (xmlXPathObjectPtr c_xpath_object , xmlXPathContextPtr c_context )
199
199
{
200
200
VALUE rb_retval ;
201
201
@@ -249,7 +249,7 @@ Nokogiri_marshal_xpath_funcall_and_return_values(
249
249
250
250
for (int j = argc - 1 ; j >= 0 ; -- j ) {
251
251
c_xpath_object = valuePop (ctxt );
252
- argv [j ] = xpath2ruby (c_xpath_object , ctxt -> context );
252
+ argv [j ] = _noko_xml_xpath_context__xpath2ruby (c_xpath_object , ctxt -> context );
253
253
if (argv [j ] == Qundef ) {
254
254
argv [j ] = NOKOGIRI_STR_NEW2 (xmlXPathCastToString (c_xpath_object ));
255
255
}
@@ -305,7 +305,7 @@ Nokogiri_marshal_xpath_funcall_and_return_values(
305
305
}
306
306
307
307
static void
308
- method_caller (xmlXPathParserContextPtr ctxt , int argc )
308
+ _noko_xml_xpath_context__handler_invoker (xmlXPathParserContextPtr ctxt , int argc )
309
309
{
310
310
VALUE rb_xpath_handler = Qnil ;
311
311
const char * method_name = NULL ;
@@ -327,23 +327,23 @@ method_caller(xmlXPathParserContextPtr ctxt, int argc)
327
327
}
328
328
329
329
static xmlXPathFunction
330
- handler_lookup (void * data , const xmlChar * c_name , const xmlChar * c_ns_uri )
330
+ _noko_xml_xpath_context_handler_lookup (void * data , const xmlChar * c_name , const xmlChar * c_ns_uri )
331
331
{
332
332
VALUE rb_handler = (VALUE )data ;
333
333
if (rb_respond_to (rb_handler , rb_intern ((const char * )c_name ))) {
334
334
if (c_ns_uri == NULL ) {
335
335
NOKO_WARN_DEPRECATION ("A custom XPath or CSS handler function named '%s' is being invoked without a namespace. Please update your query to reference this function as 'nokogiri:%s'. Invoking custom handler functions without a namespace is deprecated and will become an error in Nokogiri v1.17.0." ,
336
- c_name , c_name ); // deprecated in v1.15.0, remove in v1.17 .0
336
+ c_name , c_name ); // TODO deprecated in v1.15.0, remove in v1.19 .0
337
337
}
338
- return method_caller ;
338
+ return _noko_xml_xpath_context__handler_invoker ;
339
339
}
340
340
341
341
return NULL ;
342
342
}
343
343
344
344
PRINTFLIKE_DECL (2 , 3 )
345
345
static void
346
- generic_exception_pusher (void * data , const char * msg , ...)
346
+ _noko_xml_xpath_context__generic_exception_pusher (void * data , const char * msg , ...)
347
347
{
348
348
VALUE rb_errors = (VALUE )data ;
349
349
VALUE rb_message ;
@@ -354,7 +354,7 @@ generic_exception_pusher(void *data, const char *msg, ...)
354
354
#ifdef TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
355
355
/* It is not currently possible to pass var args from native
356
356
functions to sulong, so we work around the issue here. */
357
- rb_message = rb_sprintf ("generic_exception_pusher : %s" , msg );
357
+ rb_message = rb_sprintf ("_noko_xml_xpath_context__generic_exception_pusher : %s" , msg );
358
358
#else
359
359
va_list args ;
360
360
va_start (args , msg );
@@ -376,59 +376,54 @@ generic_exception_pusher(void *data, const char *msg, ...)
376
376
* a +Float+, or a boolean.
377
377
*/
378
378
static VALUE
379
- rb_xml_xpath_context_evaluate (int argc , VALUE * argv , VALUE rb_context )
379
+ noko_xml_xpath_context_evaluate (int argc , VALUE * argv , VALUE rb_context )
380
380
{
381
- VALUE search_path , xpath_handler ;
382
- VALUE retval = Qnil ;
383
381
xmlXPathContextPtr c_context ;
384
- xmlXPathObjectPtr xpath ;
385
- xmlChar * query ;
386
- VALUE errors = rb_ary_new ();
387
-
388
- TypedData_Get_Struct (
389
- rb_context ,
390
- xmlXPathContext ,
391
- & xml_xpath_context_type ,
392
- c_context
393
- );
382
+ VALUE rb_expression = Qnil ;
383
+ VALUE rb_function_lookup_handler = Qnil ;
384
+ xmlChar * c_expression_str = NULL ;
385
+ VALUE rb_errors = rb_ary_new ();
386
+ xmlXPathObjectPtr c_xpath_object ;
387
+ VALUE rb_xpath_object = Qnil ;
394
388
395
- if (rb_scan_args (argc , argv , "11" , & search_path , & xpath_handler ) == 1 ) {
396
- xpath_handler = Qnil ;
397
- }
389
+ TypedData_Get_Struct (rb_context , xmlXPathContext , & _noko_xml_xpath_context_type , c_context );
398
390
399
- query = ( xmlChar * ) StringValueCStr ( search_path );
391
+ rb_scan_args ( argc , argv , "11" , & rb_expression , & rb_function_lookup_handler );
400
392
401
- if (Qnil != xpath_handler ) {
393
+ c_expression_str = (xmlChar * )StringValueCStr (rb_expression );
394
+
395
+ if (Qnil != rb_function_lookup_handler ) {
402
396
/* FIXME: not sure if this is the correct place to shove private data. */
403
- c_context -> userData = (void * )xpath_handler ;
397
+ c_context -> userData = (void * )rb_function_lookup_handler ;
404
398
xmlXPathRegisterFuncLookup (
405
399
c_context ,
406
- handler_lookup ,
407
- (void * )xpath_handler
400
+ _noko_xml_xpath_context_handler_lookup ,
401
+ (void * )rb_function_lookup_handler
408
402
);
409
403
}
410
404
411
- xmlSetStructuredErrorFunc ((void * )errors , noko__error_array_pusher );
412
- xmlSetGenericErrorFunc ((void * )errors , generic_exception_pusher );
405
+ xmlSetStructuredErrorFunc ((void * )rb_errors , noko__error_array_pusher );
406
+ xmlSetGenericErrorFunc ((void * )rb_errors , _noko_xml_xpath_context__generic_exception_pusher );
413
407
414
- xpath = xmlXPathEvalExpression (query , c_context );
408
+ c_xpath_object = xmlXPathEvalExpression (c_expression_str , c_context );
415
409
416
410
xmlSetStructuredErrorFunc (NULL , NULL );
417
411
xmlSetGenericErrorFunc (NULL , NULL );
412
+
418
413
xmlXPathRegisterFuncLookup (c_context , NULL , NULL );
419
414
420
- if (xpath == NULL ) {
421
- rb_exc_raise (rb_ary_entry (errors , 0 ));
415
+ if (c_xpath_object == NULL ) {
416
+ rb_exc_raise (rb_ary_entry (rb_errors , 0 ));
422
417
}
423
418
424
- retval = xpath2ruby ( xpath , c_context );
425
- if (retval == Qundef ) {
426
- retval = noko_xml_node_set_wrap (NULL , DOC_RUBY_OBJECT (c_context -> doc ));
419
+ rb_xpath_object = _noko_xml_xpath_context__xpath2ruby ( c_xpath_object , c_context );
420
+ if (rb_xpath_object == Qundef ) {
421
+ rb_xpath_object = noko_xml_node_set_wrap (NULL , DOC_RUBY_OBJECT (c_context -> doc ));
427
422
}
428
423
429
- xmlXPathFreeNodeSetList (xpath );
424
+ xmlXPathFreeNodeSetList (c_xpath_object );
430
425
431
- return retval ;
426
+ return rb_xpath_object ;
432
427
}
433
428
434
429
/*
@@ -438,7 +433,7 @@ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE rb_context)
438
433
* Create a new XPathContext with +node+ as the context node.
439
434
*/
440
435
static VALUE
441
- rb_xml_xpath_context_new (VALUE klass , VALUE rb_node )
436
+ noko_xml_xpath_context_new (VALUE klass , VALUE rb_node )
442
437
{
443
438
xmlNodePtr c_node ;
444
439
xmlXPathContextPtr c_context ;
@@ -447,8 +442,7 @@ rb_xml_xpath_context_new(VALUE klass, VALUE rb_node)
447
442
Noko_Node_Get_Struct (rb_node , xmlNode , c_node );
448
443
449
444
#if LIBXML_VERSION < 21000
450
- /* deprecated in 40483d0 */
451
- xmlXPathInit ();
445
+ xmlXPathInit (); /* deprecated in 40483d0 */
452
446
#endif
453
447
454
448
c_context = xmlXPathNewContext (c_node -> doc );
@@ -459,16 +453,12 @@ rb_xml_xpath_context_new(VALUE klass, VALUE rb_node)
459
453
460
454
xmlXPathRegisterFuncNS (c_context ,
461
455
(const xmlChar * )"css-class" , NOKOGIRI_BUILTIN_URI ,
462
- xpath_builtin_css_class );
456
+ noko_xml_xpath_context_xpath_func_css_class );
463
457
xmlXPathRegisterFuncNS (c_context ,
464
458
(const xmlChar * )"local-name-is" , NOKOGIRI_BUILTIN_URI ,
465
- xpath_builtin_local_name_is );
459
+ noko_xml_xpath_context_xpath_func_local_name_is );
466
460
467
- rb_context = TypedData_Wrap_Struct (
468
- klass ,
469
- & xml_xpath_context_type ,
470
- c_context
471
- );
461
+ rb_context = TypedData_Wrap_Struct (klass , & _noko_xml_xpath_context_type , c_context );
472
462
473
463
rb_iv_set (rb_context , "@registered_namespaces" , rb_hash_new ());
474
464
rb_iv_set (rb_context , "@registered_variables" , rb_hash_new ());
@@ -479,12 +469,12 @@ rb_xml_xpath_context_new(VALUE klass, VALUE rb_node)
479
469
480
470
/* :nodoc: */
481
471
static VALUE
482
- rb_xml_xpath_context_set_node (VALUE rb_context , VALUE rb_node )
472
+ noko_xml_xpath_context_set_node (VALUE rb_context , VALUE rb_node )
483
473
{
484
474
xmlNodePtr c_node ;
485
475
xmlXPathContextPtr c_context ;
486
476
487
- TypedData_Get_Struct (rb_context , xmlXPathContext , & xml_xpath_context_type , c_context );
477
+ TypedData_Get_Struct (rb_context , xmlXPathContext , & _noko_xml_xpath_context_type , c_context );
488
478
Noko_Node_Get_Struct (rb_node , xmlNode , c_node );
489
479
490
480
c_context -> doc = c_node -> doc ;
@@ -503,10 +493,10 @@ noko_init_xml_xpath_context(void)
503
493
504
494
rb_undef_alloc_func (cNokogiriXmlXpathContext );
505
495
506
- rb_define_singleton_method (cNokogiriXmlXpathContext , "new" , rb_xml_xpath_context_new , 1 );
496
+ rb_define_singleton_method (cNokogiriXmlXpathContext , "new" , noko_xml_xpath_context_new , 1 );
507
497
508
- rb_define_method (cNokogiriXmlXpathContext , "evaluate" , rb_xml_xpath_context_evaluate , -1 );
509
- rb_define_method (cNokogiriXmlXpathContext , "register_variable" , rb_xml_xpath_context_register_variable , 2 );
510
- rb_define_method (cNokogiriXmlXpathContext , "register_ns" , rb_xml_xpath_context_register_ns , 2 );
511
- rb_define_method (cNokogiriXmlXpathContext , "node=" , rb_xml_xpath_context_set_node , 1 );
498
+ rb_define_method (cNokogiriXmlXpathContext , "evaluate" , noko_xml_xpath_context_evaluate , -1 );
499
+ rb_define_method (cNokogiriXmlXpathContext , "register_variable" , noko_xml_xpath_context_register_variable , 2 );
500
+ rb_define_method (cNokogiriXmlXpathContext , "register_ns" , noko_xml_xpath_context_register_ns , 2 );
501
+ rb_define_method (cNokogiriXmlXpathContext , "node=" , noko_xml_xpath_context_set_node , 1 );
512
502
}
0 commit comments