On Wed, Dec 24, 2014 at 7:53 PM, Xinchen Hui <larue...@php.net> wrote:
> On Wed, Dec 24, 2014 at 3:57 PM, Pierre Joye <pierre....@gmail.com> wrote:
>>
>> On Dec 24, 2014 2:38 PM, "Stanislav Malyshev" <smalys...@gmail.com> wrote:
>>>
>>> Hi!
>>>
>>> > But:  return 0 and return FAILURE... which is simpler?
>>>
>>> It's equally simple to write, but FAILURE of course is way simpler to
>>> understand when read.
>>
>> I totally agree.
>>
>> I do not care much about the value of failure or success but I am tired to
>> have to read the code to see if it is 0, 1, or -1 on failure.
>>
>> The kind of uniformization I would like to see for the php internals APIs.
>>
>> About the argument for the lack of info in function signature:
>>
>> A simple typedef will solve it, for the good:
>>
>> status php_foo();
>>
>> Or something along this line.
>>
>> Yes, it will mean yet another large set of changes for ext developers. But
>> at this point, it may be a good time to do it.
> hmm, okey
>
> so, make the functions which use SUCCESS/FAILURE return php_success type?
>
> and maybe also typedef php_success  php_status?

more like:

#include <stdio.h>
/* From http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_types.h#48 */
typedef enum {
   SUCCESS =  0,
   FAILURE = -1,     /* this MUST stay a negative number, or it may
affect functions! */
} ZEND_RESULT_CODE;

typedef enum ZEND_RESULT_CODE status;

status func (status s) {
   printf("%s\n", s == FAILURE ? "FAILURE" : "SUCCESS");
   return s;
}

int main (void) {
   status s;
   s = SUCCESS;
   func (s);
   s = FAILURE;
   func(s);
   return 0;
}

according to the current way FAILURE/SUCCESS are defined.

Cheers,
-- 
Pierre

@pierrejoye | http://www.libgd.org

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to