Re: svn: /pecl/cubrid/trunk/ src/Makefile.in src/config.m4 src/cubrid_err.msg src/cubrid_php4.h src/php_cubrid.c src/php_cubrid.h
src/php_cubrid_error.c src/php_cubrid_error.h src/php_cubrid_version.h

From: Date: Thu, 05 Aug 2010 21:44:35 +0000
Subject: Re: svn: /pecl/cubrid/trunk/ src/Makefile.in src/config.m4 src/cubrid_err.msg src/cubrid_php4.h src/php_cubrid.c src/php_cubrid.h
src/php_cubrid_error.c src/php_cubrid_error.h src/php_cubrid_version.h
References: 1  Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-14540@lists.php.net to get a copy of this message
Hi Esen, a few small comments about your code, no complete review though: On Thu, 2010-08-05 at 17:01 +0000, Esen Sagynov wrote: > Added: pecl/cubrid/trunk/src/Makefile.in > =================================================================== > --- pecl/cubrid/trunk/src/Makefile.in (rev > 0) > +++ pecl/cubrid/trunk/src/Makefile.in 2010-08-05 17:01:49 UTC (rev > 301905) > @@ -0,0 +1,8 @@ This file is generated by phpize and shouldn't be added to svn. > Added: pecl/cubrid/trunk/src/config.m4 > =================================================================== > --- pecl/cubrid/trunk/src/config.m4 (rev > 0) > +++ pecl/cubrid/trunk/src/config.m4 2010-08-05 17:01:49 UTC (rev > 301905) > + CFLAGS="$CFLAGS -Wall -Wextra" This will not work on other compilers. > + if test "$PHP_64BIT" != "no"; then > + CFLAGS="$CFLAGS -m64" > + else > + CFLAGS="$CFLAGS -m32" > + fi This should imo be left to the user who can override CFLAGS. Man linux users will use whatever the compiler's default is. > Added: pecl/cubrid/trunk/src/cubrid_php4.h > =================================================================== > --- pecl/cubrid/trunk/src/cubrid_php4.h (rev > 0) > +++ pecl/cubrid/trunk/src/cubrid_php4.h 2010-08-05 17:01:49 UTC (rev > 301905) > + * - Neither the name of the <ORGANIZATION> nor the names of its contributors This might need a tiny change (other files, too) > +#ifndef CUBRID_PHP4_COMPAT_HEADER > +#define CUBRID_PHP4_COMPAT_HEADER > + > +typedef zval *pzval; > + > +#define GET_ZVAL(zval) (*zval) > + > +#endif uh, PHP 4 is really old and dead. Better update the code. > Added: pecl/cubrid/trunk/src/php_cubrid.c > =================================================================== > --- pecl/cubrid/trunk/src/php_cubrid.c (rev > 0) > +++ pecl/cubrid/trunk/src/php_cubrid.c 2010-08-05 17:01:49 UTC (rev > 301905) > +#include "php.h" > +#include "cubrid_php4.h" > +#include "php_globals.h" > +#include "SAPI.h" > +#include "ext/standard/info.h" > +#include "ext/standard/php_string.h" > +#include <assert.h> I general we don't use asserts (terminating the web server can be ... painful for the admin) but try to recover as well as possible and throw an E_ERROR (which will zend_bailout(), which terminates the request) > +#ifndef TSRMLS_CC > +#define TSRMLS_CC > +#endif If tis is needed something is really broken (and including headers fromabove,which are using this macro) will fail. > +function_entry cubrid_functions[] = { this shoud be zend_function_entry. > +/* > + PHP_FE(cubrid_test, NULL) > +*/ > + PHP_FE (cubrid_version, NULL) > + PHP_FE (cubrid_connect, NULL) > + PHP_FE (cubrid_disconnect, NULL) > + PHP_FE (cubrid_prepare, NULL) ... Adding ARGINFO would be great. > +PHP_FUNCTION (cubrid_version) > +{ > + RETURN_STRING (PHP_CUBRID_VERSION, 1); > +} Adding a check using zend_parse_parameters_none() would be great to catch wrong calls, while this function is redundant, the same result cen be received via phpversion("cubrid") And as a general remark: RETURN_STRINGL might be better when the length can be calculated at compile time as easily as here. > +PHP_FUNCTION (cubrid_connect) > +{ > + switch (ARG_COUNT (ht)) > + { > + case 3: > + if (zend_get_parameters_ex (3, &host, &port, &dbname) == > FAILURE) > + { you should look into README.PARAMETER_PARSING in the PHP source and use zend_parse_parameters(). Makes the code way better to read and gives the user besser error messages. > + RETURN_FALSE; If parameter parsing fails we usually return NULL, see the note on http://php.net/manual/en/functions.internal.php > +PHP_FUNCTION (cubrid_execute) > + /* request handle ƴϴ. ߸ ޾Ҵ. */ > + zend_error (E_WARNING, "%s(): no %s resource supplied", > + get_active_function_name (TSRMLS_C), > + "CUBRID-Connect or CUBRID-Request"); You should use php_error_docref(), zend_error doesn't escape the output, and php_error_docref adds information about the current function to the error message. > +PHP_FUNCTION (cubrid_put) > + (char *) emalloc (sizeof (char) * (strlen (key) + 1)); You should use safe_emalloc to avoid overflow errors. > + strcpy (real_attr_name[i], key); You should calculate the length once and then use PHP's strlcpy(). (not std C's strncpy()) > +static char * > +str2obj (char *str) > +{ > + char buf[1024]; > + sprintf (buf, "@%d|%d|%d", page_id, slot_id, vol_id); > + return strdup (buf); Using PHP's spprint / snprintf gives you an emaloc'ed buffer which provides leak protection and might save additional copies. > Added: pecl/cubrid/trunk/src/php_cubrid.h > =================================================================== > --- pecl/cubrid/trunk/src/php_cubrid.h (rev > 0) > +++ pecl/cubrid/trunk/src/php_cubrid.h 2010-08-05 17:01:49 UTC (rev > 301905) > +#ifdef __ZTS > +#include "TSRM.h" > +#endif /* __ZTS */ This should be #ifdef ZTS not #ifdef __ZTS As said, no complete review. A few more general notes: It would be nice ifyou could add "proto" lines showing the prototype for the exported functions and ou don't fully comply to the PHP coding standards (always use {} with if conditions etc.) While we aren't too strict about that in PECL. johannes

« previous php.pecl.cvs (#14540) next »