Ticket #68 (closed defect: released)

Opened 3 years ago

Last modified 3 years ago

Problem with overloading and type casts of numeric strings in PHP bindings

Reported by: mikael Owned by: olly
Priority: high Milestone:
Component: Xapian-bindings Version: SVN trunk
Severity: normal Keywords:
Cc: Blocked By:
Operating System: Linux Blocking:

Description

Overloaded methods are mapped in PHP to their implementation (_SWIG_0, _SWIG_1, ..) based on the types and number of arguments the user supplies. However, if one overload accept a string and another an integer the bindings fail to separate them since PHP treats numeric strings much the same as integers.

The problem is illustrated in WritableDatabase?_replace_document() which takes either the docid or an unique term found in the document, ie the same number of arguments. The check for a number if implemented as IS_STRING in the sence of a numeric string which effectivly prevents the application from reaching the next section which checks for IS_STRING in the sence of a term and executes the intended overload. The solution would be to change the integer test from

_v = (Z_TYPE_PP(argv[1]) == IS_LONG

Z_TYPE_PP(argv[1]) == IS_DOUBLE Z_TYPE_PP(argv[1]) == IS_STRING) ? 1 : 0;

to

_v = (Z_TYPE_PP(argv[1]) == IS_LONG

Z_TYPE_PP(argv[1]) == IS_DOUBLE) ? 1 : 0;

Thus forcing the user to typecast his parameters when in doubt (PHP does support casts), before invoking the Xapian methods, to ensure that the correct overload is executed. For example

WritableDatabase?_replace_document($handle, (int)$docid, $document); // Replace

by docid

WritableDatabase?_replace_document($handle, (string)$uniqueterm, $document); //

Replace by term

Other than that the new bindings with emulated overloads are great, much kudos.

Change History

Changed 3 years ago by olly

  • status changed from new to closed
  • resolution set to fixed

This is a bug in SWIG which has effectively been latent (because overloading wasn't supported). I'll chase it upstream, but meanwhile I've checked in a workaround for xapian-bindings. Can you confirm it's fixed?

Changed 3 years ago by olly

Fixed in release 0.9.3.

Changed 3 years ago by olly

  • resolution changed from fixed to released

Changed 3 years ago by trac

  • platform set to Linux

Changed 3 years ago by mikael

The new release works nicely, both replace_document() and delete_document() by unique term functions as expected

Note: See TracTickets for help on using tickets.