[libvirt] [libvirt-php] Fix get_xml when xpath is null

Michal Novotny minovotn at redhat.com
Wed Apr 13 08:00:04 UTC 2011


On 04/13/2011 09:50 AM, Lyre wrote:
> 于 2011年04月13日 15:32, Michal Novotny 写道:
>> On 04/13/2011 06:10 AM, Lyre wrote:
>>> Hi all:
>>>
>>> 	To my surprise, it seems that passing null to php as a string parameter,
>>> will set the pointer which retrive it to an empty string "" , but not NULL.
>>> get_xml_from_xpath() doesn't work correctly since an empty string is
>>> passed as the xpath argument, and libxml will complain "Invalid expression"
>>>
>>> I know seldom about xpath, I'm not sure if it is the correct way to fix it.
>>>
>>> BTW, what xpath shall I pass to get the entire xml?
>>>
>> Hi Lyre,
>> thanks for the information however I was always using the NULL value as
>> second argument for the get_xml_desc(), like e.g.:
>>
>> $entire_xml = libvirt_domain_get_xml_desc($dom, NULL);
>>
>> My development and testing is done on Fedora 14 and
>> php-5.3.6-1.fc14.i686 version of the package and it's working fine for
>> me. However the patch you sent to the list seems better and it's working
>> fine so I've pushed it to the repository right now.
>>
>> Just for the record, what did you mean by passing NULL to php as a
>> string parameter? To pass as 'null' ? I'm using it the way described
>> above and 'null' is required only for libvirt_connect() since there are
>> some issues with passing NULL to libvirt_connect(). We still may need to
>> fix the libvirt_connect() function, that's true.
>>
>> Michal
>>
> Hi Michal:
>
> I'm testing it on sles 11 sp1 with php 5.2.6.
>
> Let's take libvirt_domains_get_xml_desc as an example:
>
> when I called  $entire_xml = libvirt_domain_get_xml_desc($dom, NULL);
>
> In the C code:
>
> PHP_FUNCTION(libvirt_domain_get_xml_desc)
> {
>      char *xpath = NULL;
>      int xpath_len;
>      /* ... */
>
>      GET_DOMAIN_FROM_ARGS("rs|l",&zdomain,&xpath,&xpath_len,&flags);
>
>      /* other stuff */
> }
>
> After fetching arguments, xpath point to an empty string "". So that it 
> was not NULL anymore.
>
> That's strange, or maybe I have misunderstood the argument passing 
> mechanism.
>
>
Hi Lyre,
I can see your point and since you're having different version of php
it's possible the version I'm having had a bug that xpath was not empty
string. I guess passing mechanism could change in next versions of PHP
so I'm not saying that it's bad or anything. I'm just saying I didn't
run into those issues myself but since your patch fixes the issue for
you and it didn't break anything on my setup, then I guess it's good and
I pushed it to the repository already.

Michal

-- 
Michal Novotny <minovotn at redhat.com>, RHCE
Virtualization Team (xen userspace), Red Hat




More information about the libvir-list mailing list