[PHP-CVS] cvs: php-src /ext/sockets php_sockets.h php_sockets_win.c php_sockets_win.h sockets.c
jason Sat Aug 16 02:34:36 2003 EDT Modified files: /php-src/ext/socketsphp_sockets.h php_sockets_win.c php_sockets_win.h sockets.c Log: Remove all vector based functions for the following reasons: - This solves alot of platform compatibility problems - The possible security issue of allocating an incredibly large vector pool is prevented - They are of little to no benefit in a high level language - 99% of all things done with these functions can be done using sendto/recvfrom Index: php-src/ext/sockets/php_sockets.h diff -u php-src/ext/sockets/php_sockets.h:1.32 php-src/ext/sockets/php_sockets.h:1.33 --- php-src/ext/sockets/php_sockets.h:1.32 Tue Jun 17 00:44:30 2003 +++ php-src/ext/sockets/php_sockets.h Sat Aug 16 02:34:36 2003 @@ -22,7 +22,7 @@ #ifndef PHP_SOCKETS_H #define PHP_SOCKETS_H -/* $Id: php_sockets.h,v 1.32 2003/06/17 04:44:30 sterling Exp $ */ +/* $Id: php_sockets.h,v 1.33 2003/08/16 06:34:36 jason Exp $ */ #if HAVE_SOCKETS @@ -44,12 +44,6 @@ PHP_RINIT_FUNCTION(sockets); PHP_RSHUTDOWN_FUNCTION(sockets); -PHP_FUNCTION(socket_iovec_alloc); -PHP_FUNCTION(socket_iovec_free); -PHP_FUNCTION(socket_iovec_set); -PHP_FUNCTION(socket_iovec_fetch); -PHP_FUNCTION(socket_iovec_add); -PHP_FUNCTION(socket_iovec_delete); PHP_FUNCTION(socket_select); PHP_FUNCTION(socket_create_listen); PHP_FUNCTION(socket_create_pair); @@ -70,22 +64,11 @@ PHP_FUNCTION(socket_send); PHP_FUNCTION(socket_recvfrom); PHP_FUNCTION(socket_sendto); -#ifdef HAVE_CMSGHDR -PHP_FUNCTION(socket_recvmsg); -#endif -PHP_FUNCTION(socket_sendmsg); -PHP_FUNCTION(socket_readv); -PHP_FUNCTION(socket_writev); PHP_FUNCTION(socket_get_option); PHP_FUNCTION(socket_set_option); PHP_FUNCTION(socket_shutdown); PHP_FUNCTION(socket_last_error); PHP_FUNCTION(socket_clear_error); - -typedef struct php_iovec { - struct iovec*iov_array; - unsigned intcount; -} php_iovec_t; #ifndef PHP_WIN32 typedef int PHP_SOCKET; Index: php-src/ext/sockets/php_sockets_win.c diff -u php-src/ext/sockets/php_sockets_win.c:1.9 php-src/ext/sockets/php_sockets_win.c:1.10 --- php-src/ext/sockets/php_sockets_win.c:1.9 Sat Jul 19 14:32:04 2003 +++ php-src/ext/sockets/php_sockets_win.c Sat Aug 16 02:34:36 2003 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: php_sockets_win.c,v 1.9 2003/07/19 18:32:04 andrey Exp $ */ +/* $Id: php_sockets_win.c,v 1.10 2003/08/16 06:34:36 jason Exp $ */ #ifdef PHP_WIN32 @@ -30,78 +30,6 @@ #include php.h #include php_sockets.h #include php_sockets_win.h - -ssize_t readv(SOCKET sock, const struct iovec *iov, int iovcnt) { - size_t bytes, remain, len, pos = 0; - ssize_t retval; - int i; - char *buffer = NULL; - - for(bytes=0, i=0; iiovcnt; i++) { - bytes += iov[i].iov_len; - } - - buffer = (char*)emalloc(bytes); - if (buffer == NULL) { - return -1; - } - - retval = recv(sock, buffer, bytes, 0); - - if(retval 0) { - efree(buffer); - return retval; - } - - remain = bytes = (size_t) retval; - - for(i=0; iiovcnt; i++) { - len = ((unsigned int)iov[i].iov_len remain) ? iov[i].iov_len : remain; - memcpy(iov[i].iov_base, buffer+pos, len); - pos += len; - remain -= len; - } - - efree(buffer); - return bytes; -} - -ssize_t writev(SOCKET sock, const struct iovec *iov, int iovcnt) { - size_t bytes, pos = 0; - ssize_t retval; - int i; - char *buffer = NULL; - - for(bytes=0, i=0; iiovcnt; i++) { - bytes += iov[i].iov_len; - } - - buffer = (char*)emalloc(bytes); - - if(buffer == NULL) { - return -1; - } - - for(i=0; iiovcnt; i++) { - memcpy(buffer+pos, iov[i].iov_base, iov[i].iov_len); - pos += iov[i].iov_len; - } - - retval = send(sock, buffer, bytes, 0); - efree(buffer); - - return retval; -} - -ssize_t recvmsg(SOCKET sock, struct msghdr *msg, int flags) { - set_errno(WSAEOPNOTSUPP); - return -1; -} - -ssize_t sendmsg(SOCKET sock, struct msghdr *msg, int flags) { - set_errno(WSAEOPNOTSUPP); - return -1; -} int socketpair(int domain, int type, int protocol, SOCKET sock[2]) { struct sockaddr_in address; Index: php-src/ext/sockets/php_sockets_win.h diff -u php-src/ext/sockets/php_sockets_win.h:1.8 php-src/ext/sockets/php_sockets_win.h:1.9 --- php-src/ext/sockets/php_sockets_win.h:1.8 Sat Jul 19 14:32:04 2003 +++ php-src/ext/sockets/php_sockets_win.h Sat Aug 16 02:34:36 2003 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: php_sockets_win.h,v 1.8 2003/07/19 18:32:04 andrey
[PHP-CVS] cvs: php-src(PHP_4_3) /ext/sockets sockets.c
jason Thu Jul 24 21:50:09 2003 EDT Modified files: (Branch: PHP_4_3) /php-src/ext/socketssockets.c Log: MFH: fix for #24629 Index: php-src/ext/sockets/sockets.c diff -u php-src/ext/sockets/sockets.c:1.125.2.17 php-src/ext/sockets/sockets.c:1.125.2.18 --- php-src/ext/sockets/sockets.c:1.125.2.17Thu Jun 5 19:48:17 2003 +++ php-src/ext/sockets/sockets.c Thu Jul 24 21:50:09 2003 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: sockets.c,v 1.125.2.17 2003/06/05 23:48:17 iliaa Exp $ */ +/* $Id: sockets.c,v 1.125.2.18 2003/07/25 01:50:09 jason Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -592,8 +592,16 @@ convert_to_long(tmp); sec = tmp; } - tv.tv_sec = Z_LVAL_P(sec); - tv.tv_usec = usec; + + /* Solaris + BSD do not like microsecond values which are = 1 sec */ + if (usec 99) { + tv.tv_sec = Z_LVAL_P(sec) + (usec / 100); + tv.tv_usec = usec % 100; + } else { + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = usec; + } + tv_p = tv; if (sec == tmp) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/sockets sockets.c /ext/standard streamsfuncs.c
jason Tue Jul 22 03:20:56 2003 EDT Modified files: /php-src/ext/socketssockets.c /php-src/ext/standard streamsfuncs.c Log: Fix EINVAL errors for OS's (Solaris + BSD) that do not appreciate microseconds = 1 second Patch submitted from [EMAIL PROTECTED] Index: php-src/ext/sockets/sockets.c diff -u php-src/ext/sockets/sockets.c:1.146 php-src/ext/sockets/sockets.c:1.147 --- php-src/ext/sockets/sockets.c:1.146 Tue Jul 8 01:00:13 2003 +++ php-src/ext/sockets/sockets.c Tue Jul 22 03:20:55 2003 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: sockets.c,v 1.146 2003/07/08 05:00:13 pollita Exp $ */ +/* $Id: sockets.c,v 1.147 2003/07/22 07:20:55 jason Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -641,8 +641,16 @@ convert_to_long(tmp); sec = tmp; } - tv.tv_sec = Z_LVAL_P(sec); - tv.tv_usec = usec; + + /* Solaris + BSD do not like microsecond values which are = 1 sec */ + if (usec 99) { + tv.tv_sec = Z_LVAL_P(sec) + (usec / 100); + tv.tv_usec = usec % 100; + } else { + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = usec; + } + tv_p = tv; if (sec == tmp) { Index: php-src/ext/standard/streamsfuncs.c diff -u php-src/ext/standard/streamsfuncs.c:1.24 php-src/ext/standard/streamsfuncs.c:1.25 --- php-src/ext/standard/streamsfuncs.c:1.24Sat Jun 28 07:24:46 2003 +++ php-src/ext/standard/streamsfuncs.c Tue Jul 22 03:20:55 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: streamsfuncs.c,v 1.24 2003/06/28 11:24:46 wez Exp $ */ +/* $Id: streamsfuncs.c,v 1.25 2003/07/22 07:20:55 jason Exp $ */ #include php.h #include php_globals.h @@ -563,8 +563,16 @@ /* If seconds is not set to null, build the timeval, else we wait indefinitely */ if (sec != NULL) { convert_to_long_ex(sec); - tv.tv_sec = Z_LVAL_P(sec); - tv.tv_usec = usec; + + /* Solaris + BSD do not like microsecond values which are = 1 sec */ + if (usec 99) { + tv.tv_sec = Z_LVAL_P(sec) + (usec / 100); + tv.tv_usec = usec % 100; + } else { + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = usec; + } + tv_p = tv; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/sockets sockets.c
This is correct. -Jason On Mon, 2003-07-07 at 19:51, Jani Taskinen wrote: And you're sure getaddrinfo() is always available (whenever IPV6 is) ?? --Jani On Mon, 7 Jul 2003, Sara Golemon wrote: pollita Mon Jul 7 18:27:32 2003 EDT Modified files: /php-src/ext/sockets sockets.c Log: Fix non-GNU build. Use getaddrinfo() rather than gethostbyname2() Index: php-src/ext/sockets/sockets.c diff -u php-src/ext/sockets/sockets.c:1.143 php-src/ext/sockets/sockets.c:1.144 --- php-src/ext/sockets/sockets.c:1.143 Tue Jun 17 00:44:30 2003 +++ php-src/ext/sockets/sockets.cMon Jul 7 18:27:32 2003 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: sockets.c,v 1.143 2003/06/17 04:44:30 sterling Exp $ */ +/* $Id: sockets.c,v 1.144 2003/07/07 22:27:32 pollita Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -378,12 +378,16 @@ static int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock TSRMLS_DC) { struct in6_addr tmp; -struct hostent *host_entry; +struct addrinfo hints; +struct addrinfo *addrinfo = NULL; if (inet_pton(AF_INET6, string, tmp)) { memcpy((sin6-sin6_addr.s6_addr), (tmp.s6_addr), sizeof(struct in6_addr)); } else { -if (! (host_entry = gethostbyname2(string, AF_INET6))) { +memset(hints, 0, sizeof(struct addrinfo)); +hints.ai_family = PF_INET6; +getaddrinfo(string, NULL, hints, addrinfo); +if (!addrinfo) { #ifdef PHP_WIN32 PHP_SOCKET_ERROR(php_sock, Host lookup failed, WSAGetLastError()); #else @@ -391,11 +395,14 @@ #endif return 0; } -if (host_entry-h_addrtype != AF_INET6) { +if (addrinfo-ai_family != PF_INET6 || addrinfo-ai_addrlen != sizeof(struct sockaddr_in6)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, Host lookup failed: Non AF_INET6 domain returned on AF_INET6 socket); +freeaddrinfo(addrinfo); return 0; } -memcpy((sin6-sin6_addr.s6_addr), host_entry-h_addr_list[0], host_entry-h_length); + +memcpy((sin6-sin6_addr.s6_addr), ((struct sockaddr_in6*)(addrinfo-ai_addr))-sin6_addr.s6_addr, sizeof(struct in6_addr)); +freeaddrinfo(addrinfo); } return 1; -- https://www.paypal.com/xclick/[EMAIL PROTECTED]no_note=1tax=0currency_code=EUR -- Jason Greene [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/sockets sockets.c
On Tue, 2003-07-08 at 08:15, Sascha Schumann wrote: On Tue, 8 Jul 2003, Jason Greene wrote: If the platform supports gethostbyname_r(most i know do), that is thread safe. Note the 2 in the name. - Sascha I should have been more specific, we should change the ipv4 resolver code in sockets to use either getaddrinfo or gethostbyname_r, as it is currently not thread safe. The Ipv6 resolver code should just always use getaddrinfo -Jason -- Jason Greene [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/sockets sockets.c
On Tue, 2003-07-08 at 08:59, Wez Furlong wrote: FYI: gethostbyname() is thread-safe under win32. I thought so but wasn't sure I have some code hanging around in my libwstreams repository that implements getaddrinfo() using all the possible variations of gethostbyname() or gethostbyname_r() (there are 3 possible prototypes accepting 3, 5 or 6 parameters respectively!) for IPV4 only systems. I will be merging it into PHP once I've tidied it up fully, and it should make for some nice readable resolving code at last. sounds good -Jason --Wez. - Original Message - From: Jason Greene [EMAIL PROTECTED] To: Sascha Schumann [EMAIL PROTECTED] Cc: Sara Golemon [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, July 08, 2003 2:22 PM Subject: Re: [PHP-CVS] cvs: php-src /ext/sockets sockets.c On Tue, 2003-07-08 at 08:15, Sascha Schumann wrote: On Tue, 8 Jul 2003, Jason Greene wrote: If the platform supports gethostbyname_r(most i know do), that is thread safe. Note the 2 in the name. - Sascha I should have been more specific, we should change the ipv4 resolver code in sockets to use either getaddrinfo or gethostbyname_r, as it is currently not thread safe. The Ipv6 resolver code should just always use getaddrinfo -Jason -- Jason Greene [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: spl / spl_foreach.c
Actually, I double checked C99, and // was added, however C89 does not. -Jason On Tue, 2003-07-08 at 21:48, Jason Greene wrote: jason Tue Jul 8 22:48:25 2003 EDT Modified files: /spl spl_foreach.c Log: Convert C++ comments to C (violates C99, and breaks several compilers) Index: spl/spl_foreach.c diff -u spl/spl_foreach.c:1.15 spl/spl_foreach.c:1.16 --- spl/spl_foreach.c:1.15Tue Jul 8 19:11:14 2003 +++ spl/spl_foreach.c Tue Jul 8 22:48:25 2003 @@ -151,10 +151,10 @@ if (proxy-is_a SPL_IS_A_SEQUENCE) { spl_begin_method_call_no_retval(obj, proxy-obj_ce, proxy-funcs.rewind, rewind, sizeof(rewind)-1 TSRMLS_CC); } - // now this is an optimization trick: - // ZEND_SWITCH_FREE receives the array copy or the spl object in op1 and has an unused op2 - // We have to check for op1 being an object that implements spl_forwar... Or we simply set - // op2 and know we can safely free the object as needed, which is waht we do. + /* now this is an optimization trick: +ZEND_SWITCH_FREE receives the array copy or the spl object in op1 and has an unused op2 +We have to check for op1 being an object that implements spl_forwar... Or we simply set +op2 and know we can safely free the object as needed, which is waht we do. */ op_array-opcodes[EX(opline)-op2.u.opline_num].op2 = *op1; } @@ -242,7 +242,7 @@ /* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_SWITCH_FREE) */ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_SWITCH_FREE) { - // See not in ZEND_FE_FETCH on setting op2 + /* See not in ZEND_FE_FETCH on setting op2 */ znode *op2 = EX(opline)-op2; zval *tmp, **obj = spl_get_zval_ptr_ptr(op2, EX(Ts) TSRMLS_CC); spl_foreach_proxy *proxy; -- Jason Greene [EMAIL PROTECTED] [EMAIL PROTECTED] Children's talent to endure stems from their ignorance of alternatives. -- Maya Angelou, I Know Why the Caged Bird Sings -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /build buildcheck.sh
jason Mon Jun 30 23:08:16 2003 EDT Modified files: /php-src/build buildcheck.sh Log: Prevent lines following the version output from confusing the version test Index: php-src/build/buildcheck.sh diff -u php-src/build/buildcheck.sh:1.27 php-src/build/buildcheck.sh:1.28 --- php-src/build/buildcheck.sh:1.27Thu Jun 26 20:19:43 2003 +++ php-src/build/buildcheck.sh Mon Jun 30 23:08:16 2003 @@ -16,7 +16,7 @@ # | Sascha Schumann [EMAIL PROTECTED]| # +--+ # -# $Id: buildcheck.sh,v 1.27 2003/06/27 00:19:43 sas Exp $ +# $Id: buildcheck.sh,v 1.28 2003/07/01 03:08:16 jason Exp $ # echo buildconf: checking installation... @@ -53,7 +53,7 @@ # libtoolize 1.4.3 or newer # Prefer glibtoolize over libtoolize for Mac OS X compatibility libtoolize=`./build/shtool path glibtoolize libtoolize 2 /dev/null` -lt_pversion=`$libtoolize --version 2/dev/null|sed -e 's/^[^0-9]*//'` +lt_pversion=`$libtoolize --version 2/dev/null|head -1|sed -e 's/^[^0-9]*//'` if test $lt_pversion = ; then echo buildconf: libtool not found. echoYou need libtool version 1.4.3 or newer installed -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /build buildcheck.sh
On Mon, 2003-06-30 at 22:59, Sascha Schumann wrote: On Tue, 1 Jul 2003, Jason Greene wrote: jason Mon Jun 30 23:08:16 2003 EDT Modified files: /php-src/build buildcheck.sh Log: Prevent lines following the version output from confusing the version test Just for the record, what kind of libtoolize do you have and what does it output? Sure, I have just the standard gnu libtool version 1.5 (linux-i686). I have attached the output (to prevent my mua from wrapping). -Jason -- Jason Greene [EMAIL PROTECTED] [EMAIL PROTECTED] Under every stone lurks a politician. -- Aristophanes libtoolize (GNU libtool) 1.5 Copyright (C) 2003 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /ext/sockets php_sockets_win.c
jason Tue Dec 3 00:46:53 2002 EDT Modified files: (Branch: PHP_4_3) /php4/ext/sockets php_sockets_win.c Log: MFH Index: php4/ext/sockets/php_sockets_win.c diff -u php4/ext/sockets/php_sockets_win.c:1.5 php4/ext/sockets/php_sockets_win.c:1.5.4.1 --- php4/ext/sockets/php_sockets_win.c:1.5 Sat Jun 15 12:04:59 2002 +++ php4/ext/sockets/php_sockets_win.c Tue Dec 3 00:46:53 2002 @@ -44,7 +44,7 @@ } retval = recv(sock, buffer, bytes, 0); - SleepEx(1, TRUE); + if(retval 0) { efree(buffer); return retval; @@ -175,4 +175,4 @@ va_end(va); return retval; } -#endif \ No newline at end of file +#endif -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/sockets sockets.c
Ya, I was hoping on redoing this because it greatly abuses the kernels network buffering. -Jason On Sun, 2002-10-27 at 21:05, Sterling Hughes wrote: sterling Sun Oct 27 22:05:05 2002 EDT Modified files: /php4/ext/sockets sockets.c Log: make one-line read work on win32... # The implementation of this function is brain-dead, but at least # now its brain-dead on win32 too... ;-) Index: php4/ext/sockets/sockets.c diff -u php4/ext/sockets/sockets.c:1.124 php4/ext/sockets/sockets.c:1.125 --- php4/ext/sockets/sockets.c:1.124 Fri Oct 4 14:01:52 2002 +++ php4/ext/sockets/sockets.cSun Oct 27 22:05:04 2002 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: sockets.c,v 1.124 2002/10/04 18:01:52 rasmus Exp $ */ +/* $Id: sockets.c,v 1.125 2002/10/28 03:05:04 sterling Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -272,7 +272,7 @@ } /* {{{ php_read -- wrapper around read() so that it only reads to a \r or \n. */ -int php_read(int bsd_socket, void *buf, int maxlen) +int php_read(int bsd_socket, void *buf, size_t maxlen, int flags) { int m = 0, n = 0; int no_read = 0; @@ -309,7 +309,7 @@ } if (n maxlen) { - m = read(bsd_socket, (void *) t, 1); + m = recv(bsd_socket, (void *) t, 1, flags); } if (errno != 0 errno != ESPIPE errno != EAGAIN) { @@ -766,7 +766,7 @@ } /* }}} */ -typedef int (*read_func)(int, void *, int); +typedef int (*read_func)(int, void *, size_t, int); /* {{{ proto string socket_read(resource socket, int length [, int type]) Reads a maximum of length bytes from socket */ @@ -774,7 +774,7 @@ { zval*arg1; php_socket *php_sock; - read_func read_function = (read_func) read; + read_func read_function = (read_func) recv; char*tmpbuf; int retval, length, type = PHP_BINARY_READ; @@ -789,12 +789,7 @@ tmpbuf = emalloc(length + 1); -#ifndef PHP_WIN32 - retval = (*read_function)(php_sock-bsd_socket, tmpbuf, length); -#else - retval = recv(php_sock-bsd_socket, tmpbuf, length, 0); -#endif - + retval = (*read_function)(php_sock-bsd_socket, tmpbuf, length, 0); if (retval == -1) { PHP_SOCKET_ERROR(php_sock, unable to read from socket, errno); efree(tmpbuf); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jason Greene [EMAIL PROTECTED] [EMAIL PROTECTED] People seem to think that the blanket phrase, I only work here, absolves them utterly from any moral obligation in terms of the public -- but this was precisely Eichmann's excuse for his job in the concentration camps. -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard/tests/math log.phpt
jason Sun Nov 10 22:45:04 2002 EDT Added files: /php4/ext/standard/tests/math log.phpt Log: add test function for log() # It is difficult to test an approximation of an approximation, but I # believe this test should be close enough to verify the function is working # correctly. Index: php4/ext/standard/tests/math/log.phpt +++ php4/ext/standard/tests/math/log.phpt --TEST-- log() tests --POST-- --GET-- --FILE-- ?php // $Id: log.phpt,v 1.1 2002/11/11 03:45:04 jason Exp $ echo On failure, please mail result to [EMAIL PROTECTED]\n; for ($x=0, $count=0; $x 200; $x++) { $x2 = (int) exp(log($x)); // e ^ log(x) should be close in range to x if (($x2 ($x + 2)) ($x2 ($x - 2))) { $count++; } else { print $x : $x2\n; } } print $count . \n; --EXPECT-- On failure, please mail result to [EMAIL PROTECTED] 200 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard math.c /ext/standard/tests/math log.phpt
jason Mon Nov 11 00:21:35 2002 EDT Modified files: /php4/ext/standard math.c /php4/ext/standard/tests/math log.phpt Log: Add the ability to take the logarithm of any base by adding a base parameter to log() Added regression tests for the new form Index: php4/ext/standard/math.c diff -u php4/ext/standard/math.c:1.93 php4/ext/standard/math.c:1.94 --- php4/ext/standard/math.c:1.93 Thu Oct 24 15:15:40 2002 +++ php4/ext/standard/math.cMon Nov 11 00:21:35 2002 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: math.c,v 1.93 2002/10/24 19:15:40 helly Exp $ */ +/* $Id: math.c,v 1.94 2002/11/11 05:21:35 jason Exp $ */ #include php.h #include php_math.h @@ -520,19 +520,35 @@ /* }}} */ #endif -/* {{{ proto float log(float number) - Returns the natural logarithm of the number */ +/* {{{ proto float log(float number, [float base]) + Returns the natural logarithm of the number, or the base log if base is specified +*/ PHP_FUNCTION(log) { - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, num) == FAILURE) { - WRONG_PARAM_COUNT; + zval **num, **base; + + switch (ZEND_NUM_ARGS()) { + case 1: + if (zend_get_parameters_ex(1, num) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_double_ex(num); + RETURN_DOUBLE(log(Z_DVAL_PP(num))); + case 2: + if (zend_get_parameters_ex(2, num, base) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_double_ex(num); + convert_to_double_ex(base); + + if (Z_DVAL_PP(base) = 0.0) { + php_error(E_WARNING, base must be greater than 0, +Z_DVAL_PP(base)); + RETURN_FALSE; + } + RETURN_DOUBLE(log(Z_DVAL_PP(num)) / log(Z_DVAL_PP(base))); + default: + WRONG_PARAM_COUNT; } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = log(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; } /* }}} */ Index: php4/ext/standard/tests/math/log.phpt diff -u php4/ext/standard/tests/math/log.phpt:1.1 php4/ext/standard/tests/math/log.phpt:1.2 --- php4/ext/standard/tests/math/log.phpt:1.1 Sun Nov 10 22:45:04 2002 +++ php4/ext/standard/tests/math/log.phpt Mon Nov 11 00:21:35 2002 @@ -3,19 +3,42 @@ --POST-- --GET-- --FILE-- -?php // $Id: log.phpt,v 1.1 2002/11/11 03:45:04 jason Exp $ +?php // $Id: log.phpt,v 1.2 2002/11/11 05:21:35 jason Exp $ echo On failure, please mail result to [EMAIL PROTECTED]\n; -for ($x=0, $count=0; $x 200; $x++) { +for ($x = 0, $count= 0; $x 200; $x++) { $x2 = (int) exp(log($x)); // e ^ log(x) should be close in range to x if (($x2 ($x + 2)) ($x2 ($x - 2))) { $count++; -} -else { +} else { print $x : $x2\n; } } print $count . \n; + +// Now test the base form of log +for ($base = 2; $base 11; $base++) { +for ($x = 0, $count= 0; $x 50; $x++) { +$x2 = (int) pow($base, log($x, $base)); +// base ^ log(x) should be close in range to x +if (($x2 ($x + 2)) ($x2 ($x - 2))) { +$count++; +} else { + print base $base: $x : $x2\n; +} +} +print $count . \n; +} +? --EXPECT-- On failure, please mail result to [EMAIL PROTECTED] 200 +50 +50 +50 +50 +50 +50 +50 +50 +50 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard math.c
jason Mon Nov 11 00:35:05 2002 EDT Modified files: /php4/ext/standard math.c Log: Report function name when log() triggers a base warning Index: php4/ext/standard/math.c diff -u php4/ext/standard/math.c:1.94 php4/ext/standard/math.c:1.95 --- php4/ext/standard/math.c:1.94 Mon Nov 11 00:21:35 2002 +++ php4/ext/standard/math.cMon Nov 11 00:35:04 2002 -19,7 +19,7 +--+ */ -/* $Id: math.c,v 1.94 2002/11/11 05:21:35 jason Exp $ */ +/* $Id: math.c,v 1.95 2002/11/11 05:35:04 jason Exp $ */ #include php.h #include php_math.h -542,7 +542,7 convert_to_double_ex(base); if (Z_DVAL_PP(base) = 0.0) { - php_error(E_WARNING, base must be greater than 0, Z_DVAL_PP(base)); + php_error(E_WARNING, log(): base must be greater than +0, Z_DVAL_PP(base)); RETURN_FALSE; } RETURN_DOUBLE(log(Z_DVAL_PP(num)) / log(Z_DVAL_PP(base))); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/sockets php_sockets.h sockets.c
jason Sun Sep 29 22:09:43 2002 EDT Modified files: /php4/ext/sockets php_sockets.h sockets.c Log: Fix thread safety issue Index: php4/ext/sockets/php_sockets.h diff -u php4/ext/sockets/php_sockets.h:1.24 php4/ext/sockets/php_sockets.h:1.25 --- php4/ext/sockets/php_sockets.h:1.24 Wed May 1 07:08:08 2002 +++ php4/ext/sockets/php_sockets.h Sun Sep 29 22:09:42 2002 -22,7 +22,7 #ifndef PHP_SOCKETS_H #define PHP_SOCKETS_H -/* $Id: php_sockets.h,v 1.24 2002/05/01 11:08:08 mfischer Exp $ */ +/* $Id: php_sockets.h,v 1.25 2002/09/30 02:09:42 jason Exp $ */ #if HAVE_SOCKETS -41,6 +41,8 PHP_MINIT_FUNCTION(sockets); PHP_MINFO_FUNCTION(sockets); +PHP_RINIT_FUNCTION(sockets); +PHP_RSHUTDOWN_FUNCTION(sockets); PHP_FUNCTION(socket_iovec_alloc); PHP_FUNCTION(socket_iovec_free); -103,7 +105,8 int php_read(int bsd_socket, void *buf, int maxlen); ZEND_BEGIN_MODULE_GLOBALS(sockets) -int last_error; + int last_error; + char *strerror_buf; ZEND_END_MODULE_GLOBALS(sockets) #ifdef ZTS Index: php4/ext/sockets/sockets.c diff -u php4/ext/sockets/sockets.c:1.122 php4/ext/sockets/sockets.c:1.123 --- php4/ext/sockets/sockets.c:1.122Sun Sep 22 23:34:21 2002 +++ php4/ext/sockets/sockets.c Sun Sep 29 22:09:42 2002 -19,7 +19,7 +--+ */ -/* $Id: sockets.c,v 1.122 2002/09/23 03:34:21 jason Exp $ */ +/* $Id: sockets.c,v 1.123 2002/09/30 02:09:42 jason Exp $ */ #ifdef HAVE_CONFIG_H #include config.h -86,7 +86,7 #define PHP_SOCKET_ERROR(socket,msg,errn) socket-error = errn; \ SOCKETS_G(last_error) = errn; \ php_error(E_WARNING, %s() %s [%d]: %s, \ - get_active_function_name(TSRMLS_C), msg, errn, php_strerror(errn)) + + get_active_function_name(TSRMLS_C), msg, errn, php_strerror(errn +TSRMLS_CC)) static int le_iov; #define le_iov_name Socket I/O vector -111,11 +111,6 static unsigned char third_through_seventh_args_force_ref[] = {7, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE}; -/* Global buffer for php_strerror() */ -#if defined(PHP_WIN32) || (! defined(HAVE_HSTRERROR)) -static char php_strerror_buf[1]; -#endif - /* {{{ sockets_functions[] */ function_entry sockets_functions[] = { -169,8 +164,8 sockets_functions, PHP_MINIT(sockets), NULL, - NULL, - NULL, + PHP_RINIT(sockets), + PHP_RSHUTDOWN(sockets), PHP_MINFO(sockets), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES -207,7 +202,7 efree(php_sock); } -static char *php_strerror(int error); +static char *php_strerror(int error TSRMLS_DC); int open_listen_sock(php_socket **php_sock, int port, int backlog TSRMLS_DC) { -337,7 +332,7 } /* }}} */ -static char *php_strerror(int error) { +static char *php_strerror(int error TSRMLS_DC) { const char *buf; #ifndef PHP_WIN32 -348,8 +343,8 buf = hstrerror(error); #else { - sprintf(php_strerror_buf, Host lookup error %d, error); - buf = php_strerror_buf; + sprintf(SOCKETS_G(strerror_buf), Host lookup error %d, +error); + buf = SOCKETS_G(strerror_buf); } #endif } else { -362,10 +357,10 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) tmp, 0, NULL); - strlcpy(php_strerror_buf, (char *) tmp, 1); + strlcpy(SOCKETS_G(strerror_buf), (char *) tmp, 1); LocalFree(tmp); - buf = php_strerror_buf; + buf = SOCKETS_G(strerror_buf); } #endif -403,6 +398,7 static void php_sockets_init_globals(zend_sockets_globals *sockets_globals TSRMLS_DC) { sockets_globals-last_error = 0; + sockets_globals-strerror_buf = NULL; } /* {{{ PHP_MINIT_FUNCTION -475,6 +471,25 } /* }}} */ +/* {{{ PHP_RINIT_FUNCTION */ +PHP_RINIT_FUNCTION(sockets) +{ + if (SOCKETS_G(strerror_buf) = emalloc(16384)) + return SUCCESS; + + return FAILURE; +} +/* }}} */ + +/* {{{ PHP_RSHUTDOWN_FUNCTION */ +PHP_RSHUTDOWN_FUNCTION(sockets) +{ + efree(SOCKETS_G(strerror_buf)); + + return SUCCESS; +} +/* }}} */ + int php_sock_array_to_fd_set(zval *sock_array,