[Xapian-discuss] Query::Query() in PHP, also QueryParser::prefixes

Sam Liddicott sam@liddicott.com
Fri, 28 May 2004 14:37:13 +0100


If the original xapian method has an extra parameter then the swig-php
wrapped method is bound to follow.

Sam
----- Original Message ----- 
From: "Francis Irving" <francis@flourish.org>
To: <xapian-discuss@lists.xapian.org>
Sent: Friday, May 28, 2004 12:34 PM
Subject: Re: [Xapian-discuss] Query::Query() in PHP, also
QueryParser::prefixes


> On Fri, May 28, 2004 at 12:25:01PM +0100, Sam Liddicott wrote:
> > > > It's now called %name, I think. I've managed to get it working for
> > > > constructors in the past, but admittedly not for a while.
> > >
> > > Aha!  Thank you.  Much more success.  I've tried this.
> > >
> > > %name(QueryCombine) Xapian::Query::Query(Xapian::Query::Query::op op_,
> > > %const Xapian::Query::Query & left, const Xapian::Query::Query &
> > > %right);
> > >
> > > It makes a PHP function called query_querycombine.  Unfortunately,
> > > the function takes a spurious extra Query argument as its first
> > > parameter.  SWIG thinks it is a member function, rather than a
> > > constructor.
> >
> > Is this observation based on the C++ code that swig generates?
>
> It wasn't, but checking the code it looks like this.  There is an extra
self
> parameter which isn't used by the function:
>
> Xapian::Query *Xapian_Query_QueryCombine(Xapian::Query
*self,Xapian::Query::op op_,Xapian::Query const &left,Xapian::Query const
&right){
>                 return new Xapian::Query(op_, left, right);
>             }
>
> The wrappers for the real constructor and the new one look like this:
>         ZEND_NAMED_FE(new_query,
>                 _wrap_new_Query, NULL)
>         ZEND_NAMED_FE(query_querycombine,
>                 _wrap_Query_QueryCombine, NULL)
>
> Looking at the code for _wrap_new_Query, it does some extra fancy stuff,
> checking parameters and wrapping the returned new object in some other
object.  I
> suspect we need this to avoid memory leaks.
>
> How can I persuade swig to generate this for our renamed constructor?
>
>     result = (Xapian::Query *)new Xapian::Query((std::string const
&)*arg1,arg2,arg3);
> ...
>
>     SWIG_SetPointerZval(return_value, (void *)result,
SWIGTYPE_p_Xapian__Query, 1);
>
>     /* Wrap this return value */
>     {
>         /* ALTERNATIVE Constructor, make an object wrapper */
>         zval *obj, *_cPtr;
>         MAKE_STD_ZVAL(obj);
>         MAKE_STD_ZVAL(_cPtr);
>         *_cPtr = *return_value;
>         INIT_ZVAL(*return_value);
>         *return_value=*_cPtr;
>     }
>
> Francis
>
> _______________________________________________
> Xapian-discuss mailing list
> Xapian-discuss@lists.xapian.org
> http://lists.xapian.org/mailman/listinfo/xapian-discuss
>
>