Mikael Johansson
2006-Feb-13 23:03 UTC
[Xapian-devel] Problem with overloading add type casts of numeric strings in PHP bindings
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. //Mikael
Olly Betts
2006-Feb-14 09:58 UTC
[Xapian-devel] Problem with overloading add type casts of numeric strings in PHP bindings
On Tue, Feb 14, 2006 at 12:03:48AM +0100, Mikael Johansson wrote:> 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.I've responded in bugzilla (short version: should be fixed in SVN): http://xapian.org/cgi-bin/bugzilla/show_bug.cgi?id=68> Other than that the new bindings with emulated overloads are great, much > kudos.All the credit is due to Kevin Ruland, who's recently taken on the role of SWIG PHP maintainer. Cheers, Olly
Seemingly Similar Threads
- [PATCH] Make com32 printf obey width-restriction on %s
- Problems with installing R packages from source and running C++ in R, even on fresh R installation
- [PATCH] php: restructure and expand tests
- [PATCH] nv50: initial support for IF, ELSE, ENDIF insns
- Problems with installing R packages from source and running C++ in R, even on fresh R installation