Re: [PHP-DEV] Functions for getting long / double from zval with casts

2012-11-19 Thread Nikita Popov
On Mon, Nov 19, 2012 at 5:09 AM, Stas Malyshev smalys...@sugarcrm.comwrote:

 Hi!

  Hi internals!
 
  It happens quite often that you need to extract an integer from a zval
 and
  you also want it to work for integers in strings, etc. In order to do so
  you currently have to cast the zval to integer. This is always rather
  complicated because you often don't want to actually change the passed

 Where it happens quite often outside of function arguments (where it is
 covered by parameter parsing APIs)?


It's just something that crops up every now and again. E.g. when you take
it from an array or something like that.


 Should it handle all conversions the engine performs or only from string?


Should be the normal casting behavior.


 We could probably expose zendi_convert_to_long() and similar ones, but
 I'm not sure what the use case for these would be. Could you give more
 background on this?


zendi_convert_to_long() isn't really what I'm looking for. All the current
convert functions convert a zval, which is not what you normally need, at
least that's the feeling that I got. So what you end up doing is something
like this:

 long result;
 Z_ADDREF_P(zval);
 convert_to_long_ex(zval);
 result = Z_LVAL_P(zval);
 zval_ptr_dtor(zval);

Which seems overly complicated to me. What I'm looking for is something
like this:

long result = zval_get_long_with_cast(zval);

Or maybe I'm missing something about how to easily get an integer from a
value?

Nikita


Re: [PHP-DEV] Functions for getting long / double from zval with casts

2012-11-18 Thread Stas Malyshev
Hi!

 Hi internals!
 
 It happens quite often that you need to extract an integer from a zval and
 you also want it to work for integers in strings, etc. In order to do so
 you currently have to cast the zval to integer. This is always rather
 complicated because you often don't want to actually change the passed

Where it happens quite often outside of function arguments (where it is
covered by parameter parsing APIs)?

Should it handle all conversions the engine performs or only from string?

We could probably expose zendi_convert_to_long() and similar ones, but
I'm not sure what the use case for these would be. Could you give more
background on this?
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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



[PHP-DEV] Functions for getting long / double from zval with casts

2012-11-17 Thread Nikita Popov
Hi internals!

It happens quite often that you need to extract an integer from a zval and
you also want it to work for integers in strings, etc. In order to do so
you currently have to cast the zval to integer. This is always rather
complicated because you often don't want to actually change the passed
zval. So you end up allocating / separating zvals and stuff like that. And
I'm always confused just which exactly of the 50 different ways to cast a
zval one should use in a particular situation.

What I'd like to propose is a set of two new functions, which castingly get
an integer or a float from a zval. The functions could look like this:

long zval_get_long_with_cast(zval *value)
double zval_get_double_with_cast(zval *value)

What do you think?

Nikita


Re: [PHP-DEV] Functions for getting long / double from zval with casts

2012-11-17 Thread Levi Morrison
On Sat, Nov 17, 2012 at 8:15 AM, Nikita Popov nikita@gmail.com wrote:
 Hi internals!

 It happens quite often that you need to extract an integer from a zval and
 you also want it to work for integers in strings, etc. In order to do so
 you currently have to cast the zval to integer. This is always rather
 complicated because you often don't want to actually change the passed
 zval. So you end up allocating / separating zvals and stuff like that. And
 I'm always confused just which exactly of the 50 different ways to cast a
 zval one should use in a particular situation.

 What I'd like to propose is a set of two new functions, which castingly get
 an integer or a float from a zval. The functions could look like this:

 long zval_get_long_with_cast(zval *value)
 double zval_get_double_with_cast(zval *value)

 What do you think?

 Nikita

I'm new to internals but this is one thing I've dealt with.  I would
certain vote for it.

Question: how does this handle objects, arrays and resources?  For a
particular use-case I need something that works on integers and
integers in strings only.

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