Ticket #193 (assigned defect)

Opened 15 months ago

Last modified 3 months ago

NumberValueRangeProcessor_apply not working in the PHP-bindings

Reported by: daniel Owned by: olly
Priority: normal Milestone: 1.1.0
Component: Xapian-bindings Version: 1.0.2
Severity: normal Keywords:
Cc: richard Blocked By:
Operating System: All Blocking:

Description (last modified by richard) (diff)

The following returns an error, even though the right arguments have been passed:

$vrp = new XapianNumberValueRangeProcessor?(0, "\$", true); $vrp->apply((string)"240", (string)"500");

The error returned is: Fatal error: Type error in argument 2 of NumberValueRangeProcessor?_apply. Expected SWIGTYPE_p_stdstring in xapian.php on line 1217

line 1217 being: return NumberValueRangeProcessor?_apply($this->_cPtr,$begin,$end);

Have tried changing that line to say (string)$begin and (string)$end, same result.

Attachments

python-testcase-for-bug-193.patch (0.8 kB) - added by olly 14 months ago.
Patch to smoketest.py to show this bug for Python

Change History

Changed 15 months ago by olly

  • owner changed from richard to olly

SWIG isn't handling passing the string parameter by non-const reference.

I think this will need custom wrapping.

This may not work for some (or all) of the other bindings either...

Changed 15 months ago by olly

  • status changed from new to assigned

Changed 15 months ago by olly

  • blocking set to 154

We should try to fix this for 1.0.3 if possible.

Changed 14 months ago by olly

Fixed (for PHP at least) by patching SWIG and using the latest SWIG version to generate the bindings.

This is the regression testcase I added, which now passes:

$vrp = new XapianNumberValueRangeProcessor?(0, '$', true); $a = '$10'; $b = '20'; $vrp->apply($a, $b); if (Xapian::sortable_unserialise($a) != 10) {

print Xapian::sortable_unserialise($a)." != 10\n"; exit(1);

} if (Xapian::sortable_unserialise($b) != 20) {

print Xapian::sortable_unserialise($b)." != 20\n"; exit(1);

}

Leaving this bug open until I check if this works for all the other languages...

Changed 14 months ago by olly

Patch to smoketest.py to show this bug for Python

Changed 14 months ago by olly

  • cc richard@… added

Richard - this bug manifests for Python too. It looked to me like SWIG had suitable typemaps, but perhaps you need to %apply them or something. The fix for PHP was to add "in" and "argout" typemaps for string&.

I'll check the other languages tomorrow.

Changed 14 months ago by richard

Hmm. Unless I'm missing something, it's not possible for the python test you've written to work. In python, strings are immutable, so we can't change the value of the parameters "a" and "b" from inside the "vrp(a,b)" call, however we implement it.

We could make vrp() return the new values of a and b. Alternatively, we could just leave this as it is, since I'm not convinced it's actually useful to call a vrp() from Python.

Changed 14 months ago by olly

We shouldn't just leave it - if something doesn't work for a language, providing a wrapper for it is just a trap for API users.

But I think this has uses - if you wanted to write a VRP subclass in Python which was based on an existing VRP subclass then it's useful to be able to call operator() on the existing class.

In fact, if you want to write a VRP subclass in Python, you're probably going to want to be able to modify the strings passed in anyway...

Changed 14 months ago by richard

Committed a fix for python (call() now returns a 3-tuple, containing the slot num, the returned begin and the returned end).

Changed 14 months ago by olly

  • blocking changed from 154 to 200

Postponing what's left of this to 1.0.4 in the interests of actually making a release.

Changed 14 months ago by trac

  • platform set to All

Changed 7 months ago by richard

  • description modified (diff)
  • milestone set to 1.1

Changed 7 months ago by richard

  • milestone changed from 1.1.0 to 1.0.7

Changed 7 months ago by richard

  • blocking deleted

Changed 4 months ago by olly

  • milestone changed from 1.0.7 to 1.0.8

Changed 3 months ago by olly

  • milestone changed from 1.0.8 to 1.1.0

Since the use-case for this is to allow subclassing your own VRP in the language, and SWIG/PHP doesn't support such subclassing at present, I'm going to bump this to 1.1.0.

Note: See TracTickets for help on using tickets.