Re: [PHP-DEV] * New Parameter Parsing Functions *

2001-07-24 Thread Markus Fischer

I see, this coming from PHP-GTK developing ?

Can you give an example for a function that takes some fixed
parameter (take a resource of some kind as an example) and the
next parameter being another resource OR an array of that other
resources ?

I'm just wondering if I can put this all into a single
zend_parse_parameters() or if I'ld need to use some kind of if()
statement for this one.

- Markus

On Tue, Jul 10, 2001 at 10:35:04AM -0500, Andrei Zmievski wrote : 
 New parameter parsing functions
 ===
 
 It should be easier to parse input parameters to an extension function.
 Hence, borrowing from Python's example, there are now a set of functions
 that given the string of type specifiers, can parse the input parameters
 and store the results in the user specified variables. This avoids most
 of the IS_* checks and convert_to_* conversions. The functions also
 check for the appropriate number of parameters, and try to output
 meaningful error messages.
 
 
 Prototypes
 --
 /* Implemented. */
 zend_parse_parameters(int num_args, char *type_spec, ...);
 zend_parse_parameters_ex(int flags, int num_args, char *type_spec, ...);
 
 /* Not implemented yet. */
 zend_parse_parameters_hash(HashTable *ht, char *type_spec, ...);
 zend_parse_parameters_hash_ex(int flags, HashTable *ht, char *type_spec, ...);
 
 
 The zend_parse_parameters() function takes the number of parameters
 passed to the extension function, the type specifier string, and the
 list of pointers to variables to store the results in. The _ex() version
 also takes 'flags' argument -- current only ZEND_PARSE_PARAMS_QUIET can
 be used as 'flags' to specify that the function should operate quietly
 and not output any error messages.
 
 The auto-conversions are performed as necessary. Arrays, objects, and
 resources cannot be autoconverted.
 
 
 Type specifiers
 ---
  l- long
  d- double
  s- string (with possible null bytes) and its length
  b- boolean, stored in zend_bool
  r- resource (stored in zval)
  a- array
  o- object (of any type)
  O- object (of specific type, specified by class entry)
  z- the actual zval
 
  The following characters also have a meaning in the specifier string:
  | - indicates that the remaining parameters are optional, they
should be initialized to default values by the extension since they
will not be touched by the parsing function if they are not
passed to it.
/ - use SEPARATE_ZVAL_IF_NOT_REF() on the parameter it follows
! - the parameter it follows can be of specified type or NULL (only applies
to 'a', 'o', 'O', 'r', and 'z'). If NULL is passed, the results
pointer is set to NULL as well.
 
 Examples
 
 /* Gets a long, a string and its length, and a zval */
 long l;
 char *s;
 int s_len;
 zval *param;
 zend_parse_parameters(ZEND_NUM_ARGS(), lsz, l, s, s_len, param);
 
 
 /* Gets an object of class specified by my_ce, and an optional double. */
 zval *obj;
 double d = 0.5;
 zend_parse_parameters(ZEND_NUM_ARGS(), O|d, obj, my_ce, d);
 
 
 /* Gets an object or null, and an array.
If null is passed for object, obj will be set to NULL. */
 zval *obj;
 zval *arr;
 zend_parse_parameters(ZEND_NUM_ARGS(), O!a, obj, arr);
 
 
 /* Gets a separated array. */
 zval *arr;
 zend_parse_parameters(ZEND_NUM_ARGS(), a/, arr));
 
 
 /* Get only the first three parameters (useful for varargs functions). */
 zval *z;
 zend_bool b;
 zval *r;
 zend_parse_parameters(2, zbr!, z, b, r);
 
 
 /* Get either a set of 3 longs or a string. */
 long l1, l2, l3;
 char *s;
 if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), lll, l1, 
l2, l3)) {
   /* manipulate longs */
 } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), s, 
s)) {
   /* manipulate string */
 } else {
   /* output error */
 }
 
 Comments and feedback are welcome.
 
 -Andrei
 * If it's never finished, you can't prove it doesn't work. *
 
 -- 
 PHP Development Mailing List http://www.php.net/
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 

-- 
Markus Fischer,  http://guru.josefine.at/~mfischer/
EMail: [EMAIL PROTECTED]
PGP Public  Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
PGP Fingerprint: D3B0 DD4F E12B F911 3CE1  C2B5 D674 B445 C227 2BD0

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] * New Parameter Parsing Functions *

2001-07-24 Thread Andrei Zmievski

On Tue, 24 Jul 2001, Markus Fischer wrote:
 I see, this coming from PHP-GTK developing ?
 
 Can you give an example for a function that takes some fixed
 parameter (take a resource of some kind as an example) and the
 next parameter being another resource OR an array of that other
 resources ?
 
 I'm just wondering if I can put this all into a single
 zend_parse_parameters() or if I'ld need to use some kind of if()
 statement for this one.

You will need to use something like this until [] specifiers are
implemented.

if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), rr, res1, 
res2) == FAILURE) {
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), ra, 
res1, res_arr) == FAILURE) {
// output error message here
}
}

-Andrei

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Fwd: [PHP-DEV] * New Parameter Parsing Functions *

2001-07-21 Thread Andi Gutmans

Guys,

Andrei sent this Email a while ago and I don't remember anyone giving 
feedback. We'd be happy to hear what people think about this new parameter 
API in the Zend Engine. I think it has good potential especially for 
simplifying functions which accept read-only arguments (which is the case 
for most functions) of pre-determined types.
Please take another look at what Andrei wrote and see what you think.
Andi


Date: Tue, 10 Jul 2001 10:35:04 -0500
From: Andrei Zmievski [EMAIL PROTECTED]
To: PHP Developers [EMAIL PROTECTED]
User-Agent: Mutt/1.2.5i
Subject: [PHP-DEV] * New Parameter Parsing Functions *

New parameter parsing functions
===

It should be easier to parse input parameters to an extension function.
Hence, borrowing from Python's example, there are now a set of functions
that given the string of type specifiers, can parse the input parameters
and store the results in the user specified variables. This avoids most
of the IS_* checks and convert_to_* conversions. The functions also
check for the appropriate number of parameters, and try to output
meaningful error messages.


Prototypes
--
/* Implemented. */
zend_parse_parameters(int num_args, char *type_spec, ...);
zend_parse_parameters_ex(int flags, int num_args, char *type_spec, ...);

/* Not implemented yet. */
zend_parse_parameters_hash(HashTable *ht, char *type_spec, ...);
zend_parse_parameters_hash_ex(int flags, HashTable *ht, char *type_spec, ...);


The zend_parse_parameters() function takes the number of parameters
passed to the extension function, the type specifier string, and the
list of pointers to variables to store the results in. The _ex() version
also takes 'flags' argument -- current only ZEND_PARSE_PARAMS_QUIET can
be used as 'flags' to specify that the function should operate quietly
and not output any error messages.

The auto-conversions are performed as necessary. Arrays, objects, and
resources cannot be autoconverted.


Type specifiers
---
  l  - long
  d  - double
  s  - string (with possible null bytes) and its length
  b  - boolean, stored in zend_bool
  r  - resource (stored in zval)
  a  - array
  o  - object (of any type)
  O  - object (of specific type, specified by class entry)
  z  - the actual zval

  The following characters also have a meaning in the specifier string:
  | - indicates that the remaining parameters are optional, they
 should be initialized to default values by the extension 
 since they
 will not be touched by the parsing function if they are not
 passed to it.
 / - use SEPARATE_ZVAL_IF_NOT_REF() on the parameter it follows
 ! - the parameter it follows can be of specified type or NULL 
 (only applies
  to 'a', 'o', 'O', 'r', and 'z'). If NULL is passed, the results
 pointer is set to NULL as well.

Examples

/* Gets a long, a string and its length, and a zval */
long l;
char *s;
int s_len;
zval *param;
zend_parse_parameters(ZEND_NUM_ARGS(), lsz, l, s, s_len, param);


/* Gets an object of class specified by my_ce, and an optional double. */
zval *obj;
double d = 0.5;
zend_parse_parameters(ZEND_NUM_ARGS(), O|d, obj, my_ce, d);


/* Gets an object or null, and an array.
If null is passed for object, obj will be set to NULL. */
zval *obj;
zval *arr;
zend_parse_parameters(ZEND_NUM_ARGS(), O!a, obj, arr);


/* Gets a separated array. */
zval *arr;
zend_parse_parameters(ZEND_NUM_ARGS(), a/, arr));


/* Get only the first three parameters (useful for varargs functions). */
zval *z;
zend_bool b;
zval *r;
zend_parse_parameters(2, zbr!, z, b, r);


/* Get either a set of 3 longs or a string. */
long l1, l2, l3;
char *s;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), 
lll, l1, l2, l3)) {
 /* manipulate longs */
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, 
ZEND_NUM_ARGS(), s, s)) {
 /* manipulate string */
} else {
 /* output error */
}

Comments and feedback are welcome.

-Andrei
* If it's never finished, you can't prove it doesn't work. *

--
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] * New Parameter Parsing Functions *

2001-07-10 Thread Andrei Zmievski

New parameter parsing functions
===

It should be easier to parse input parameters to an extension function.
Hence, borrowing from Python's example, there are now a set of functions
that given the string of type specifiers, can parse the input parameters
and store the results in the user specified variables. This avoids most
of the IS_* checks and convert_to_* conversions. The functions also
check for the appropriate number of parameters, and try to output
meaningful error messages.


Prototypes
--
/* Implemented. */
zend_parse_parameters(int num_args, char *type_spec, ...);
zend_parse_parameters_ex(int flags, int num_args, char *type_spec, ...);

/* Not implemented yet. */
zend_parse_parameters_hash(HashTable *ht, char *type_spec, ...);
zend_parse_parameters_hash_ex(int flags, HashTable *ht, char *type_spec, ...);


The zend_parse_parameters() function takes the number of parameters
passed to the extension function, the type specifier string, and the
list of pointers to variables to store the results in. The _ex() version
also takes 'flags' argument -- current only ZEND_PARSE_PARAMS_QUIET can
be used as 'flags' to specify that the function should operate quietly
and not output any error messages.

The auto-conversions are performed as necessary. Arrays, objects, and
resources cannot be autoconverted.


Type specifiers
---
 l  - long
 d  - double
 s  - string (with possible null bytes) and its length
 b  - boolean, stored in zend_bool
 r  - resource (stored in zval)
 a  - array
 o  - object (of any type)
 O  - object (of specific type, specified by class entry)
 z  - the actual zval

 The following characters also have a meaning in the specifier string:
 | - indicates that the remaining parameters are optional, they
 should be initialized to default values by the extension since they
 will not be touched by the parsing function if they are not
 passed to it.
 / - use SEPARATE_ZVAL_IF_NOT_REF() on the parameter it follows
 ! - the parameter it follows can be of specified type or NULL (only applies
 to 'a', 'o', 'O', 'r', and 'z'). If NULL is passed, the results
 pointer is set to NULL as well.

Examples

/* Gets a long, a string and its length, and a zval */
long l;
char *s;
int s_len;
zval *param;
zend_parse_parameters(ZEND_NUM_ARGS(), lsz, l, s, s_len, param);


/* Gets an object of class specified by my_ce, and an optional double. */
zval *obj;
double d = 0.5;
zend_parse_parameters(ZEND_NUM_ARGS(), O|d, obj, my_ce, d);


/* Gets an object or null, and an array.
   If null is passed for object, obj will be set to NULL. */
zval *obj;
zval *arr;
zend_parse_parameters(ZEND_NUM_ARGS(), O!a, obj, arr);


/* Gets a separated array. */
zval *arr;
zend_parse_parameters(ZEND_NUM_ARGS(), a/, arr));


/* Get only the first three parameters (useful for varargs functions). */
zval *z;
zend_bool b;
zval *r;
zend_parse_parameters(2, zbr!, z, b, r);


/* Get either a set of 3 longs or a string. */
long l1, l2, l3;
char *s;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), lll, l1, 
l2, l3)) {
/* manipulate longs */
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), s, 
s)) {
/* manipulate string */
} else {
/* output error */
}

Comments and feedback are welcome.

-Andrei
* If it's never finished, you can't prove it doesn't work. *

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]