cvs: php4 /ext/standard rand.c

From: Date: Wed, 05 Sep 2001 21:38:49 +0000
Subject: cvs: php4 /ext/standard rand.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-7229@lists.php.net to get a copy of this message
sterling Wed Sep 5 17:38:49 2001 EDT Modified files: /php4/ext/standard rand.c Log: Straight out da bronx, I be using zend_parse_parameters() # Word out to my peeps on Connor st. Index: php4/ext/standard/rand.c diff -u php4/ext/standard/rand.c:1.42 php4/ext/standard/rand.c:1.43 --- php4/ext/standard/rand.c:1.42 Wed Sep 5 17:04:30 2001 +++ php4/ext/standard/rand.c Wed Sep 5 17:38:49 2001 @@ -19,7 +19,7 @@ | Based on code from: Shawn Cokus <Cokus@math.washington.edu> | +----------------------------------------------------------------------+ */ -/* $Id: rand.c,v 1.42 2001/09/05 21:04:30 sterling Exp $ */ +/* $Id: rand.c,v 1.43 2001/09/05 21:38:49 sterling Exp $ */ #include <stdlib.h> @@ -194,15 +194,12 @@ Seeds random number generator */ PHP_FUNCTION(srand) { - zval **seed; + long seed; - if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &seed) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(seed); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &seed) == FAILURE) + return; - php_srand(Z_LVAL_PP(seed)); + php_srand(seed); } /* }}} */ @@ -210,15 +207,12 @@ Seeds Mersenne Twister random number generator */ PHP_FUNCTION(mt_srand) { - zval **seed; + long seed; - if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &seed) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(seed); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &seed) == FAILURE) + return; - seedMT(Z_LVAL_PP(seed) TSRMLS_CC); + seedMT(seed TSRMLS_CC); } /* }}} */ @@ -255,19 +249,17 @@ Returns a random number */ PHP_FUNCTION(rand) { - zval **min; - zval **max; - long number; - int argc = ZEND_NUM_ARGS(); - - if (argc != 0 && argc != 2 || - zend_get_parameters_ex(argc, &min, &max) == FAILURE) { - WRONG_PARAM_COUNT; - } + long min; + long max; + long number; + int argc = ZEND_NUM_ARGS(); + + if (argc != 0 && zend_parse_parameters(argc, "ll", &min, &max) == FAILURE) + return; number = php_rand(); if (argc == 2) { - RAND_RANGE(number, Z_LVAL_PP(min), Z_LVAL_PP(max)); + RAND_RANGE(number, min, max); } RETURN_LONG(number); @@ -278,15 +270,13 @@ Returns a random number from Mersenne Twister */ PHP_FUNCTION(mt_rand) { - zval **min; - zval **max; - long number; - int argc = ZEND_NUM_ARGS(); - - if (argc != 0 && argc != 2 || - zend_get_parameters_ex(argc, &min, &max) == FAILURE) { - WRONG_PARAM_COUNT; - } + long min; + long max; + long number; + int argc = ZEND_NUM_ARGS(); + + if (argc != 0 && zend_parse_parameters(argc, "ll", &min, &max) == FAILURE) + return; /* * Melo: hmms.. randomMT() returns 32 random bits... @@ -298,7 +288,7 @@ */ number = (long) (randomMT(TSRMLS_C) >> 1); if (argc == 2) { - RAND_RANGE(number, Z_LVAL_PP(min), Z_LVAL_PP(max)); + RAND_RANGE(number, min, max); } RETURN_LONG(number);

« previous php.cvs (#7229) next »