[webkit-dev] gdom_x_path_evaluator_create_ns_resolver [was: webkit #16401]

Luke Kenneth Casson Leighton lkcl at lkcl.net
Mon Jun 8 04:45:48 PDT 2009


On 6/8/09, Leon Winter <lwi at ring0.de> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
>  Hash: SHA1
>
>
> Leon Winter wrote:
>  > Hi,
>  >> GdomXPathNSResolver *resolver =
>  >> gdom_x_path_evaluator_create_ns_resolver(doc, body);
>  >
>  >> l.
>  > Yeah minor mistake from my side (sorry for that), anyway it
>  > segfaults since we cannot initialize GdomXPathEvaluator (as told
>  > before).
>  >
>  > Regards, Leon Winter
>
> Hi,
>
>  I just checked the header-files and I found out, that it was not my
>  mistake actually, since there are two functions:
>
>  WEBKIT_API GdomXPathNSResolver *
>  gdom_x_path_evaluator_create_ns_resolver (GdomXPathEvaluator *thiz,
>  GdomNode * node_resolver);
>
>
>  WEBKIT_API GdomXPathNSResolver *
>  gdom_document_create_ns_resolver (GdomDocument *thiz, GdomNode *
>  node_resolver);
>
>
> Anyway we cannot use XPath at the moment because we need a
>  (GdomXPathEvaluator object:
>
>  WEBKIT_API GdomXPathResult *
>  gdom_x_path_evaluator_evaluate (GdomXPathEvaluator *thiz, gchar *
>  expression, GdomNode * context_node, GdomXPathNSResolver * resolver,
>  gushort type, GdomXPathResult * in_result);

 not being funny or anything, but are you _sure_ you need a
GdomXPathEvaluator object?

 if you look in GdomDocument.h, yo can see this:

WEBKIT_API GdomXPathResult *
gdom_document_evaluate (GdomDocument *thiz, gchar * expression,
GdomNode * context_node, GdomXPathNSResolver * resolver, gushort type,
GdomXPathResult * in_result);

which again looks pretty damn similar to the [isolated and
inaccessible] gdom_x_path_evaluator_evaluate function, to me :)

cut/pasting in another [relevant] discussion into this one thread:

> [....]

>  Erm, nope.
>  The initial code was:
>
>     GdomXPathResult *res;
>     GdomXPathEvaluator evaluator;
>     char *exp = "//html:select";
>     GdomDocument *doc = get_dom_document();
>     GdomNodeList *els = gdom_document_get_elements_by_tag_name(doc,
>  "body");
>     GdomNode *body = gdom_node_list_item(els, 0);
>     GdomXPathNSResolver *resolver =
>  gdom_x_path_evaluator_create_ns_resolver(&evaluator, body); //
>  segfaults because we cannot init evaluator
>
>  And I quote myself (mail from 2009-06-07 01:18 in my UTC+1 timezone)
>
>  "segfaults right at the last line. I found new creation methid for
>  GdomXPathEvaluator, perhaps there should be one."
>
>  I mentioned GdomXPathEvaluator :)

 ok, let me try and walk it through.

 in GdomXPathEvaluator.h, you have this:

WEBKIT_API GdomXPathNSResolver *
gdom_x_path_evaluator_create_ns_resolver (GdomXPathEvaluator *thiz,
GdomNode * node_resolver);

and in GdomDocument, mark indirectly points out that you have this:

WEBKIT_API GdomXPathNSResolver *
gdom_document_create_ns_resolver (GdomDocument *thiz, GdomNode * node_resolver);

so - uhnnn.. oh.  ah.  oops.

ok - can anyone explain what the difference between an XPathNSResolver
return result from Document.createNSResolver and from
XPathEvaluator.createNSResolver is?

can leon just use gdom_document_create_ns_resolver() and basically
completely ignore the (self-contained and apparently isolated)
XPathNSEvaluator class and (inaccessible) functions?

     GdomXPathResult *res;
     char *exp = "//html:select";
     GdomDocument *doc = get_dom_document();
     GdomNodeList *els = gdom_document_get_elements_by_tag_name(doc,
  "body");
     GdomNode *body = gdom_node_list_item(els, 0);
     GdomXPathNSResolver *resolver =
  gdom_document_create_ns_resolver(doc, body);

   /* now you use this */
   res =    gdom_document_evaluate (doc, expression, GDOM_NODE(context_node),
                          resolver, gushort type, in_result);
   */

btw leon, it's worth reiterating: you really must use pointers to glib
objects, they get refcounted and automatically freed etc. etc. if you
put stuff on the stack like this:

   GdomXPathEvaluator evaluator;

you will get into an awful mess.

l.


More information about the webkit-dev mailing list