Re: [PHP-DEV] Freeing memory

2002-11-09 Thread Tony Leake
Hi Wez,

I wrote a pecl extension called ecasound which interacts with an audio
processing library. Now the way that ecasound is written will change in
future versions and will have a fully interactive mode, all other
implementations (perl, python c++ etc) have been re-written so that they
open up a couple of pipes, fork and then exec ecasound in the child
process so using the interactive mode instead of  linking against the
librarys. What I would like to do is to make the PHP implementation work
in the same way as all of the others but of course PHP does not yet have
full 2 way communication with a child process. 

I agree that extending proc_open may be the best solution but while I
would be willing to do the work I'm not sure that I can at the moment. 
Working with processes etc in c is fairly new to me and so are PHP
extensions so trying to extend someone else's function that already
looks fairly complex may be beyond me at this time (also I do not know
anything about programming under win32).

Maybe I'll take another look though as If this would really be the best
way to implement the functionality I need then it may be a good learning
exercise :)

Tony


On Sat, 2002-11-09 at 19:52, Wez Furlong wrote:
> Hi Tony,
> 
> What kind of things are you planning to do?
> proc_open seems ideal to extend for this purpose, and works on win32.
> 
> --Wez.
> 
> On 09/11/02, "Tony Leake" <[EMAIL PROTECTED]> wrote:
> > The whole picture is that i want to control a child process completely 
> > from within php. A bit like popen or proc_open but with 2 independent
> > pipes to the child's stdin and stdout that I can read and write to. So
> > I'm basically wrapping the c functions pipe(), dup2() and friends. Once
> > I have it all working I will offer to add the functions into the pcntl
> > extension if they're wanted. 
> 
> 
> 
> 
> -- 
> PHP Development Mailing List 
> To unsubscribe, visit: http://www.php.net/unsub.php
> 



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




Re: [PHP-DEV] Freeing memory

2002-11-09 Thread Wez Furlong
Hi Tony,

What kind of things are you planning to do?
proc_open seems ideal to extend for this purpose, and works on win32.

--Wez.

On 09/11/02, "Tony Leake" <[EMAIL PROTECTED]> wrote:
> The whole picture is that i want to control a child process completely 
> from within php. A bit like popen or proc_open but with 2 independent
> pipes to the child's stdin and stdout that I can read and write to. So
> I'm basically wrapping the c functions pipe(), dup2() and friends. Once
> I have it all working I will offer to add the functions into the pcntl
> extension if they're wanted. 




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




Re: [PHP-DEV] Freeing memory

2002-11-09 Thread Tony Leake
The whole picture is that i want to control a child process completely 
from within php. A bit like popen or proc_open but with 2 independent
pipes to the child's stdin and stdout that I can read and write to. So
I'm basically wrapping the c functions pipe(), dup2() and friends. Once
I have it all working I will offer to add the functions into the pcntl
extension if they're wanted. 

Anyway the code in the pipe function that was giving me the warnings is
as follows:

PHP_FUNCTION(pipe)
{
pipe_r_le_struct *st_pipe_r;
pipe_w_le_struct *st_pipe_w;
zval *read;
zval *write;
int pipe_fd[2];

if( pipe(pipe_fd ) <0 ){
php_error( E_ERROR, "Could not create pipe" );
}

st_pipe_r = emalloc( sizeof( pipe_r_le_struct ) );
st_pipe_w = emalloc( sizeof( pipe_w_le_struct ) );

st_pipe_r->fd = pipe_fd[0];
st_pipe_w->fd = pipe_fd[1];

MAKE_STD_ZVAL( read );
MAKE_STD_ZVAL( write );

ZEND_REGISTER_RESOURCE( read, st_pipe_r, le_pipe_r )
ZEND_REGISTER_RESOURCE( write, st_pipe_w, le_pipe_w )


array_init( return_value );
add_assoc_resource( return_value, "read", Z_RESVAL_P( read ) );
add_assoc_resource( return_value, "write", Z_RESVAL_P( write ) );

}

If i use FREE_ZVAL() at the end of this function I can get rid of the
warnings but I would guess this is the wrong place and it should be
taken care of in a cleanup function when the request has finished.

Please excuse me if I am missing something obvious here, as you may
guess I'm still finding my feet writing PHP extensions.

Tony


On Sat, 2002-11-09 at 08:56, Andi Gutmans wrote:
> Actually zval_ptr_dtor() is probably more suitable.
> In any case, is this zval something you keep locally in your extension or 
> are you returning/adding it to the engine's symbol table? If so, the engine 
> should take care of the memory automatically as long as you've done 
> everything correctly.
> Maybe you should explain in more detail what you're doing.
> Andi
> 




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




Re: [PHP-DEV] Freeing memory

2002-11-09 Thread Andi Gutmans
Actually zval_ptr_dtor() is probably more suitable.
In any case, is this zval something you keep locally in your extension or 
are you returning/adding it to the engine's symbol table? If so, the engine 
should take care of the memory automatically as long as you've done 
everything correctly.
Maybe you should explain in more detail what you're doing.
Andi

At 12:45 AM 11/9/2002 -0800, Rasmus Lerdorf wrote:
Yup, you will need to FREE_ZVAL() it

On 9 Nov 2002, Tony Leake wrote:

>
> Hi,
>
> I am getting the following output from a php script that calls an
> extension I am writing (I have compiled the extension with
> --enable-debug)
>
>
> /home/phpcvs/php4_head/ext/pipe/pipe.c(245) :  Freeing 0x0822568C (12
> bytes), script=test.php
> /home/phpcvs/php4_head/ext/pipe/pipe.c(244) :  Freeing 0x0822564C (12
> bytes), script=test.php
>
> where lines lines 245 and 244 are:
> MAKE_STD_ZVAL(read);
> MAKE_STD_ZVAL(write);
>
> Does this mean that I need to free the memory from the zvals when the
> script exits, or is this just information?
>
> Thanks for your help
> Tony
>
>
>
> --
> PHP Development Mailing List 
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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



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




Re: [PHP-DEV] Freeing memory

2002-11-09 Thread Rasmus Lerdorf
Yup, you will need to FREE_ZVAL() it

On 9 Nov 2002, Tony Leake wrote:

>
> Hi,
>
> I am getting the following output from a php script that calls an
> extension I am writing (I have compiled the extension with
> --enable-debug)
>
>
> /home/phpcvs/php4_head/ext/pipe/pipe.c(245) :  Freeing 0x0822568C (12
> bytes), script=test.php
> /home/phpcvs/php4_head/ext/pipe/pipe.c(244) :  Freeing 0x0822564C (12
> bytes), script=test.php
>
> where lines lines 245 and 244 are:
> MAKE_STD_ZVAL(read);
> MAKE_STD_ZVAL(write);
>
> Does this mean that I need to free the memory from the zvals when the
> script exits, or is this just information?
>
> Thanks for your help
> Tony
>
>
>
> --
> PHP Development Mailing List 
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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




[PHP-DEV] Freeing memory

2002-11-09 Thread Tony Leake

Hi,

I am getting the following output from a php script that calls an
extension I am writing (I have compiled the extension with
--enable-debug)


/home/phpcvs/php4_head/ext/pipe/pipe.c(245) :  Freeing 0x0822568C (12
bytes), script=test.php
/home/phpcvs/php4_head/ext/pipe/pipe.c(244) :  Freeing 0x0822564C (12
bytes), script=test.php

where lines lines 245 and 244 are:
MAKE_STD_ZVAL(read);
MAKE_STD_ZVAL(write);

Does this mean that I need to free the memory from the zvals when the
script exits, or is this just information?

Thanks for your help
Tony



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