wez             Wed Sep 18 06:15:40 2002 EDT

  Added files:                 
    /php4/ext/standard/tests/file       userstreams.phpt 

  Modified files:              
    /php4/main  user_streams.c 
  Log:
  Tidy up some user stream code.
  Add a small test case (not yet complete).
  
  
Index: php4/main/user_streams.c
diff -u php4/main/user_streams.c:1.18 php4/main/user_streams.c:1.19
--- php4/main/user_streams.c:1.18       Sat Sep  7 14:59:18 2002
+++ php4/main/user_streams.c    Wed Sep 18 06:15:40 2002
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: user_streams.c,v 1.18 2002/09/07 18:59:18 wez Exp $ */
+/* $Id: user_streams.c,v 1.19 2002/09/18 10:15:40 wez Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -164,7 +164,7 @@
                        4, args,
                        0, NULL TSRMLS_CC);
        
-       if (call_result == SUCCESS && zretval != NULL) {
+       if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) {
                /* the stream is now open! */
                stream = php_stream_alloc_rel(&php_stream_userspace_ops, us, 0, mode);
 
@@ -177,12 +177,15 @@
                stream->wrapperdata = us->object;
                zval_add_ref(&stream->wrapperdata);
        } else {
-               /* destroy the object */
-               zval_ptr_dtor(&us->object);
-               efree(us);
+               php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" 
+USERSTREAM_OPEN "\" call failed",
+                       us->wrapper->classname);
        }
        
        /* destroy everything else */
+       if (stream == NULL) {
+               zval_ptr_dtor(&us->object);
+               efree(us);
+       }
        if (zretval)
                zval_ptr_dtor(&zretval);
        
@@ -266,10 +269,11 @@
                        1, args,
                        0, NULL TSRMLS_CC);
 
-       if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_LONG)
+       didwrite = 0;
+       if (call_result == SUCCESS && retval != NULL) {
+               convert_to_long_ex(&retval);
                didwrite = Z_LVAL_P(retval);
-       else
-               didwrite = 0;
+       }
 
        /* don't allow strange buffer overruns due to bogus return */
        if (didwrite > count) {
@@ -326,7 +330,8 @@
                                1, args,
                                0, NULL TSRMLS_CC);
 
-               if (retval && Z_TYPE_P(retval) == IS_STRING) {
+               if (call_result == SUCCESS && retval != NULL) {
+                       convert_to_string_ex(&retval);
                        didread = Z_STRLEN_P(retval);
                        if (didread > count) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" 
USERSTREAM_READ " - read %d bytes more data than requested (%d read, %d max) - excess 
data will be lost",
@@ -464,6 +469,7 @@
        zval **args[2];
        size_t didread = 0;
        php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
+       int call_result;
 
        assert(us != NULL);
 
@@ -475,14 +481,15 @@
        ZVAL_LONG(zcount, size);
        args[0] = &zcount;
 
-       call_user_function_ex(NULL,
+       call_result = call_user_function_ex(NULL,
                        &us->object,
                        &func_name,
                        &retval,
                        1, args,
                        0, NULL TSRMLS_CC);
 
-       if (retval && Z_TYPE_P(retval) == IS_STRING) {
+       if (retval && call_result == SUCCESS) {
+               convert_to_string_ex(&retval);
                didread = Z_STRLEN_P(retval);
                if (didread > size) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" 
USERSTREAM_GETS " - read more data than requested; some data will be lost",

Index: php4/ext/standard/tests/file/userstreams.phpt
+++ php4/ext/standard/tests/file/userstreams.phpt
--TEST--
User-space streams
--FILE--
<?php
# vim600:syn=php:

class uselessstream {
}

class mystream {

        function mystream()
        {
                echo "MYSTREAM: constructor called!\n";
        }

        var $path;
        var $mode;
        var $options;

        function stream_open($path, $mode, $options, &$opened_path)
        {
                $this->path = $path;
                $this->mode = $mode;
                $this->options = $options;
                return true;
        }

}

if (@file_register_wrapper("bogus", "class_not_exist"))
        die("Registered a non-existant class!!!???");

if (!file_register_wrapper("test", "mystream"))
        die("test wrapper registration failed");
if (!file_register_wrapper("bogon", "uselessstream"))
        die("bogon wrapper registration failed");

echo "Registered\n";

$b = @fopen("bogon://url", "rb");
if (is_resource($b))
        die("Opened a bogon??");

$fp = fopen("test://url", "rb");
if (!is_resource($fp))
        die("Failed to open resource");

?>
--EXPECT--
Registered



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to