Your extension will have its own peculiarities anyway, just because PHP
itself is responsible for memory management as opposed to C/C++.
Generally, a PHP extension can't have exactly the same API as a C/C++
library. (Especially, if it performs some kind of memory management.)

I suppose you'll provide some docs for the extension. I guess a
user will refer to _your_ docs, not the wxWidgets's C++ API. Then I
can't find any purpose for making exact copy of C++ API here in PHP.

On Sat, 08 Mar 2014 14:33:30 +0100
Johannes Schlüter <[email protected]> wrote:

> On Fri, 2014-03-07 at 16:16 -0400, JGM wrote:
> > I'm emulating the same behavior of wxWidgets since the code is
> > being auto generated and I want to keep compatibility as much as
> > possible with how wxWidgets works so people that comes from C++
> > world can use the extension with the same knowledge as that of
> > original implementation. wxPHP is almost a 1 on 1 binding except
> > for wxString which is a native php string and wxDateTime which is
> > just a timestamp on wxphp.
> 
> Still PHP is a different language with other paradigms. See fread():
> PHP for asic functions is a wrapper over C, by reading a C manual you
> can grasps many parts of PHP but still fread() uses a slightly
> different way.
> 
> > It is strange that the first call works and assings the buffer
> > reference properly but second call fails.
> 
> I haven't fully checked, but the suspicious part for me is
>    ZVAL_STRING(arguments[0], (char*) buffer, 0);
> I assume that on 
>    $buffer = fread($this->image, $bufsize);
> $buffer tries to free its contents in order to be overwritten, but the
> buffer passed to wxInputStream_php::OnSysRead may not be freed by
> PHP. I assume simply passing a NULL zval to the function would be
> enough.
> 
> 
> 
> Some other unrelated notes on things I saw: 
> 
> 
> You are calling zend_call_function(). this is no ZEND_API so depending
> on compiler flags etc. it is not exported and not callable from the
> extensions .so/.dll file.
> 
> The usage of static bool is_php_user_space_implemented is suspicious.
> Is there never a chance that the method at first does not exist and a
> user provides it lateron?
> 
> In memcpy ((void*) buffer, (void*) Z_STRVAL_P(arguments[0]),
> Z_STRLEN_P(arguments[0])); you assume that the arguments[0] zval will
> still be a string, if it is passed y ref this is not guaranteed. The
> user might do $buffer = NULL; (or an object with a __toString()). Also
> you don't verify that the buffer is large enough (the user might
> ignore $bufsize).
> 
> In return (size_t) Z_LVAL_P(return_value); you aren't verifying the
> type either. If the user by mistake returns a string with the
> contents this will misbehave. You also don't check whether the
> returned length matches the information from the return value. Thus
> the consumer of wxInputStream_php::OnSysRead can't rely on that size.
> 
> johannes
> 
> 
> 


-- 
Ruslan Osmanov

--
PECL development discussion Mailing List (http://pecl.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to