[PHP-DEV] linking against ststic librarys

2003-01-18 Thread Tony Leake
Hi,

is it possible to create an extension that links against a static
library.

If it is could someone point me to an extension that does this, or
explain how to do it.

Thanks
Tony




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




[PHP-DEV] updating php_error messages

2002-11-12 Thread Tony Leake
Hi,

I have noticed in the TODO file in head one of the items is:

* Change PHP error messages, so that they point to pages or sections
in the PHP Manual.

I have a few weeks of spare evenings coming up so if anyone wants me to 
I'm happy to wade through and make the changes. As far as I can see it's
just a case of changing php_error to php_error_docref and adding 
NULL TSRMLS_CC as the first argument.

I don't have karma to do this so either I would need it or I could
supply patches. 

Tony


-- 
PHP Development Mailing List http://www.php.net/
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 http://www.php.net/
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 http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




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 http://www.php.net/
 To unsubscribe, visit: http://www.php.net/unsub.php
 



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




Re: [PHP-DEV] newbie: url parms

2002-11-05 Thread Tony Leake
On Tue, 2002-11-05 at 09:32, Geert Arts wrote:
 Hi,
 
 I just seem not to be able to pass variables from a URL to a PHP script.
 When I do something like http://localhost/test.php?variablex=valuex  variablex is 
empty (or does even not 
 exist?)
 
 I'm running php 4.2.3 and apache 1.3.27 under Windows.

You will find your answer on this page of the fine manual
http://www.php.net/manual/en/reserved.variables.php

Please note that this is not the correct forum for this question. This
forum deals with writing the PHP language in 'c' not writing scripts
with PHP.

The correct forum is php-general.details of which you can find here:

http://www.php.net/mailing-lists.php

Tony


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




Re: [PHP-DEV] Global HashTables access violations

2002-10-21 Thread Tony Leake
On Mon, 2002-10-21 at 20:19, Brian 'Bex' Huff wrote:

 Ive written an extension to PHP that (among other things) uses a global 
 HashTable object for a mini cache.  I fill it, and then have a simple 
 PHP function to pull a string out of the cache, and return it.  However, 
 I keep getting wierd internal access violations whenever I try to use it.
 
Hi Brian,

I can't help with your specific problems but there are a couple of
shortcuts you can use in your module. 

You can get the string length of your arguments as they are passes in,
see below.

Also there are macros for returning values which I believe are the
preferred way of doing things. I have made the change in your code below
to show how to get the string length passed in.

you have 2 functions for returning strings :
RETURN_STRING(char *s, int dup) 
and 
RETURN_STRINGL(char *s, int l, int dup) if you know the length of the
string.
int dup, should be 1 unless you estrdup or emalloc the string.

these 2 functions seem to have aliases RETVAL_STRING and RETVAL_STRINGL
I'm not sure which version is preferred.

see for further info
http://zend.com/apidoc/zend.returning.php


HTH
Tony


 PHP_FUNCTION(idc_env)
 {
HashTable *env = IDC_G(server_environment);
zval **value = NULL;
char *valueStr = NULL;
int argc = ZEND_NUM_ARGS();
char *name = NULL;
 /* NEW LINE, and line below modified */
 long name_length; 
if (zend_parse_parameters(argc TSRMLS_CC, s, name, name_length) == FAILURE)
  return;
 
if (zend_hash_find(env, name, strlen(name) + 1,
   (void **) value) == SUCCESS)
{
  if ((*value)-type == IS_STRING)
  {
valueStr = Z_STRVAL_PP(value);
return_value-type = IS_STRING;
return_value-value.str.len = Z_STRLEN_PP(value);
return_value-value.str.val = estrdup(valueStr);
 
/* previous 3 lines can be replaced with */
RETURN_STRINGL(valueStr, Z_STRLEN_PP(value), 1 );
  }
}
 }
 



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




[PHP-DEV] library calls from within php functions

2002-10-20 Thread Tony Leake
Hi, 

I am working on an extension that makes use of the pipe, read and write 
library calls on a linux platform. 

When I try to put this line 
read(fd, buf, 1024);
inside a php function ( PHP_FUNCTION(read_pipe) ) it fails to compile
with the following warning:
called object is not a function.

If I move the same line into a standard c function it compiles without
error. 

So my question is, is there some problem trying to make library calls
from within php functions? although other calls seem to work fine.

Thanks for any help
Tony 


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




Re: [PHP-DEV] library calls from within php functions

2002-10-20 Thread Tony Leake
On Sun, 2002-10-20 at 09:34, Wez Furlong wrote:

Thanks for the fast reply Wez,

 There's not much we can tell you about this unless you post the
 rest of the lines of that function.

See below for the code

 
 Perhaps you did not include php.h ?

Yep thats there, I used exec_skel to create the basic module.
 
 Note:  always prefer this:
 
   read(fd, buf, sizeof(buf));
 
 to this:
 
   read(fd, buf, 1024);

Thanks, done that.

OK, what I'm trying to achieve is basically wrapping pipe, read and
write so in a php script I can create 2 pipes, fork the process using 
pcntl_fork() and have 2 way non blocking communication with more control
than proc_open()

I have so far written this function that creates the pipe and returns an
array of the pipes descriptors:

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));

}
This function appears to work as expected

and now I'm trying to write functions that will read and write from the
pipe. So far I have this, it isn't finished as you will see.

PHP_FUNCTION(pipe_read)
{
pipe_r_le_struct *st_pipe_r;
zval *read;
zval * res;
char buf[1024];

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r, res) ==
FAILURE) {
return;
}

ZEND_FETCH_RESOURCE(st_pipe_r, pipe_r_le_struct *, res, -1,
pipe_r, le_pipe_r);

if(!st_pipe_r) RETURN_FALSE;

read(fd, buf, sizeof(buf));
}

I was just testing that it still compiles and it fails on the 
read(fd, buf, sizeof(buf)); line. with the error  
called object is not a function

As I mentioned if I move that line into a c function it compiles fine.

Thanks
Tony 


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




Re: [PHP-DEV] library calls from within php functions

2002-10-20 Thread Tony Leake
On Sun, 2002-10-20 at 10:07, Wez Furlong wrote:

 Aside from that, I can't see any obvious mistakes.
 

Ok, I solved it. I declared a zval called read, then tried to call the
read function. DOH !

Thanks for your help anyway
Tony


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




[PHP-DEV] help needed with config.m4 script

2002-09-25 Thread Tony Leake

Hello, 

I am having problems with an extension, I think with the config.m4
script.

If I build the extension into the php source tree it works fine and
links correctly. If I build it as a shared object either within the
source tree as --with-audio=shared or outside the source tree running
phpize the .so file builds but it doesn't link to the external lib. 

If I run ldd on the .so it doesn't seem to be trying to link.

Can anyone see what I'm doing wrong?

thanks 
Tony

contents of config.m4

PHP_ARG_WITH(audio, for audio support,
[  --with-audio Include audio support])


if test $PHP_AUDIO != no; then

SEARCH_PATH=/usr/local /usr
SEARCH_FOR=/include/ecasound/ecasoundc.h
if test -r $PHP_AUDIO/; then # path given as parameter
  AUDIO_DIR=$PHP_AUDIO
else # search default path list
  AC_MSG_CHECKING([for ecasound files in default path])
  for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
  AUDIO_DIR=$i
  AC_MSG_RESULT(found in $i)
fi
  done
fi

if test -z $AUDIO_DIR; then
  AC_MSG_RESULT([Ecasound header files not found])
  AC_MSG_ERROR([Please reinstall the ecasound distribution])
fi

  PHP_ADD_LIBRARY_WITH_PATH(ecasoundc, $AUDIO_DIR/lib,
AUDIO_SHARED_LIBADD)

  PHP_EXTENSION(audio, $ext_shared)
fi


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




Re: [PHP-DEV] help needed with config.m4 script

2002-09-25 Thread Tony Leake

On Wed, 2002-09-25 at 22:48, Jani Taskinen wrote:
 
   The 2nd last line I added should take care of it.
   You also might want to add the include path with 'PHP_ADD_INCLUDE'
   macro..in case the header files are not in /usr/include.. :)
 
   --Jani
   
Thanks a lot Jani, problem solved :)

Tony
 



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




[PHP-DEV] CVS Account Request: tony

2002-09-22 Thread Tony Leake

To put audio extension into PECL (details at 
http://www.webwise-data.co.uk/php_audio/php_audio_extension.html )

And to develop/maintain that extension. Also to work with DJ Anubis to develop a 
unified audio/multimedia extension.

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




Re: [PHP-DEV] Sound Extension proposed API

2002-09-11 Thread Tony Leake

 Hi,
 
 Great, sound media systems come to PHP. Wrapping ecasound is a good
idea.
 Maybe I'll try to have XMMS module follow it too ;-)
 Would be nice to have a unified sound wrapper in PHP, say a metaclass
which
 could control other systems (xmms, eca, xine...).
 
 DJ Anubis

Hi,

A unified wrapper is a great idea, ecasound is a little over the top for
all of the stuff that xmms excels at.

I'm away from friday for just over a week, lets put our heads together
then and see what ideas we can come up with.

Regards
Tony


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




[PHP-DEV] Sound Extension proposed API

2002-09-10 Thread Tony Leake



Hi, 

Following my posts last week I have now written up my proposed API for
my sound extension. There is too much to post here so I have made it
available at:
http://www.webwise-data.co.uk/ecasound.html and would welcome any
comments. 

If there are no objections I will apply for a cvs account in a couple of
weeks when I am ready to go alpa with this to place it into PECL.

Regards
Tony Leake 


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




Re: [PHP-DEV] Sound API for php

2002-09-08 Thread Tony Leake

On Sun, 2002-09-08 at 11:00, Wez Furlong wrote:
 
 That fits with our naming conventions; however, I think that Andi
 was hoping you would post a little bit info about the parameters
 of the main functions that you expect people to use; something like
 this:
 
   bool audio_play_file(string filename);
   Plays an audio file to the default sound output device
 
I haven't yet worked out what the parameters will be, I haven't even
worked out what all of the functions will be. The only functions I have
written so far are the ones that wrap the standard ecasound
instructions. Give me a couple of days and I'll post again with a full
proposed api for my first release, params and all, taking into account
yours and Andi's suggestions. 


 I don't think there is a need to make this into two separate extensions
 (it just makes things harder for the end user) - you can link to as many
 libs as you like from your extension.

Ok


 
 You can use any license you like when your code is in pear/PECL (so long
 as it allows joe public to download your code from the php.net server).
 The license incompatibility only affects whether your extension can be
 bundled/distributed with the PHP core. (as was the case with my mailparse
 extension...)
 
Cool, I have also noted Andi's comment in reply to this, I will contact
the author as I feel that even if it's not required I should do it as a
matter of courtesy.

Regards
Tony



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




Re: [PHP-DEV] Sound API for php

2002-09-07 Thread Tony Leake


 For the 'web-side' of things - could these conversion function be
used,
 to convert files on the webserver? Or even something like:
 song.wav - convert_to_mp3 - stream_on_socket
 song.mp3 - convert_to_windows_media - stream_on_socket

There's no reason why you couldn't convert files on the webserver, 
it will convert files that it sees on it's local file system. 

Ecasound will not stream over a socket (AFAIK). It's standard out 
is a soundcard via either ALSA or OSS drivers. It's an interesting
point though and the guy who wrote and maintains the library is pretty
good at adding functionality. 

As far as windows media goes, it's not a supported format and I would
guess it never will be.

 
 And can it read mp3 or whatever 'about' information is stored in the
 audio file?
 

Ecasound doesn't have this functionality, although this is something I
have thought about and would be looking to implement it at some point. 
I'm sure it can't be that hard to read in the file headers.

If you would like further information about ecasound, you can find it at
http://www.wakkanet.fi/~kaiv/ecasound/welcome.html

regards
Tony


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




Re: [PHP-DEV] Sound API for php

2002-09-07 Thread Tony Leake


Andi Gutmans wrote:
 You might want to put this into Pear. In any case, if you want to post
the 
 API just to get people's input (naming conventions of functions and so
on) 
 feel free to post here.
 
Thanks for the suggestion to put this into Pear. I have subscribed to
the dev list and I'll see what they think :)

Regarding the API, I am planning 3 sets of functions. 

1) Ecasound functions that simply wrap the Ecasound Control Interface. 
I have named these:

eci_init();
eci_command();
eci_error();
etc, I really want to use this naming convention as it is exactly the
same as the interface available in perl, python etc. 

2) Higher level functions for manipulating sound files. These are what I
would expect to be of most interest to others. As I mentioned before
scripting ecasound is tricky so simple functions to play or convert
files would be useful.

I am planning to name these with the audio_ prefix, ie
audio_playfile();
audio_convert_file();
audio_new_chain();

Is this a good idea, I thought of the audio_ prefix to clear up any
confusion with other functions, but it will mean some function names
will be a little long for example, audio_chain_set_position(); is this
too long?

3) will be midi functions,this is a long way off yet so I haven't given
it too much thought yet. Also it is likely to be a separate module as it
will need to link against a separate library and I can't think of any
PHP modules that link against 2 libs.

One last question. I'm sure I read somewhere that the PHP licence is not
compatible with the GPL. Is this true? If so what do I need to do is a
simple agreement from the ecasound maintainer enough or will he need to
release it under the PHP licence as well?

Regards
Tony Leake  


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




[PHP-DEV] Patch for bug/feature request 16119

2002-08-27 Thread Tony Leake

Hi, 

I have written a patch for the above feature request to implement an
array_swap function. 

array_swap($array, $key1, $key2), where keys can be either index or
assoc and array content can be any combination of string, long, array
and object. 

This is my first patch and I am hoping to contribute more to php in the
future so if you don't want to use the patch for any reason, I would be
grateful for any pointers or comments on the code. 

Regards 
Tony Leake 



diff -Nur php-4.2.2/ext/standard/array.c php-4.2.2_devel/ext/standard/array.c
--- php-4.2.2/ext/standard/array.c	2002-04-24 16:29:38.0 +0100
+++ php-4.2.2_devel/ext/standard/array.c	2002-08-27 19:09:16.0 +0100
 -3366,6 +3366,89 
 }
 /* }}} */
 
+
+/* {{{ proto bool  array_swap(array input_array, int index1, int index2)
+   swaps 2 elements in an array */
+PHP_FUNCTION( array_swap )
+{
+	zval *input_arr, *temp_arr;
+	zval **tmp1, **tmp2;
+	zval *key1;
+	zval *key2;
+
+	if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, azz, input_arr, key1, key2 ) !=SUCCESS ){
+		RETURN_FALSE;
+	}
+	
+
+	MAKE_STD_ZVAL( temp_arr );
+	*temp_arr = *input_arr;
+	SEPARATE_ZVAL( temp_arr );
+	
+if ( Z_TYPE_P(key1)==IS_LONG  Z_TYPE_P(key2)==IS_LONG ){
+		
+		if ( zend_hash_index_find( Z_ARRVAL_P( temp_arr ), Z_LVAL_P( key1 ), (void**)tmp1 )!=SUCCESS){
+			php_error( E_WARNING, Key 1 does not exist );
+			return;
+		}
+		
+		if ( zend_hash_index_find( Z_ARRVAL_P( temp_arr ), Z_LVAL_P( key2 ), (void**)tmp2 )!=SUCCESS){
+			php_error( E_WARNING, Key 2 does not exist );
+			return;
+		}
+		
+		add_index_zval( input_arr, Z_LVAL_P( key1 ), *tmp2 );
+		add_index_zval( input_arr, Z_LVAL_P( key2 ), *tmp1 );
+
+	} else if ( Z_TYPE_P( key1 )==IS_LONG  Z_TYPE_P( key2 )==IS_STRING ){
+		
+		if ( zend_hash_index_find( Z_ARRVAL_P( temp_arr ), Z_LVAL_P( key1 ), (void**)tmp1 )!=SUCCESS){
+			php_error( E_WARNING, Key 1 does not exist );
+			return;
+		}
+		
+		if ( zend_hash_find( Z_ARRVAL_P( temp_arr ), Z_STRVAL_P( key2 ), Z_STRLEN_P( key2 )+1, (void**)tmp2 )!=SUCCESS){
+			php_error( E_WARNING, Key 2 does not exist );
+			return;
+		}
+		
+		add_index_zval( input_arr, Z_LVAL_P( key1 ), *tmp2 );
+		add_assoc_zval( input_arr, Z_STRVAL_P( key2 ), *tmp1);
+
+	} else if ( Z_TYPE_P( key1 )==IS_STRING  Z_TYPE_P( key2 )==IS_LONG){
+		
+		if ( zend_hash_find( Z_ARRVAL_P( temp_arr ), Z_STRVAL_P(key1), Z_STRLEN_P( key1 )+1, (void**)tmp1 )!=SUCCESS){
+			php_error( E_WARNING, Key 1 does not exist );
+			return;
+		}
+		
+		if ( zend_hash_index_find( Z_ARRVAL_P( temp_arr ), Z_LVAL_P( key2 ), (void**)tmp2 )!=SUCCESS){
+			php_error( E_WARNING, Key 2 does not exist );
+			return;
+		}
+		
+		add_assoc_zval( input_arr, Z_STRVAL_P( key1 ), *tmp2);
+		add_index_zval( input_arr, Z_LVAL_P( key2 ), *tmp1 );
+		
+	}else{
+		
+		if ( zend_hash_find( Z_ARRVAL_P( temp_arr ), Z_STRVAL_P( key1 ), Z_STRLEN_P( key1 )+1, (void**)tmp1 )!=SUCCESS){
+			php_error( E_WARNING, Key 1 does not exist );
+			return;
+		}
+		
+		if ( zend_hash_find( Z_ARRVAL_P( temp_arr ), Z_STRVAL_P(key2), Z_STRLEN_P( key2 )+1, (void**)tmp2 )!=SUCCESS){
+			php_error( E_WARNING, Key 2 does not exist );
+			return;
+		}
+		
+		add_assoc_zval( input_arr, Z_STRVAL_P( key1 ), *tmp2);
+		add_assoc_zval( input_arr, Z_STRVAL_P( key2 ), *tmp1);
+	}
+	
+	RETURN_TRUE;
+}
+/* }}} */
 /*
  * Local variables:
  * tab-width: 4
diff -Nur php-4.2.2/ext/standard/basic_functions.c php-4.2.2_devel/ext/standard/basic_functions.c
--- php-4.2.2/ext/standard/basic_functions.c	2002-05-11 20:23:05.0 +0100
+++ php-4.2.2_devel/ext/standard/basic_functions.c	2002-08-27 19:11:34.0 +0100
 -793,6 +793,7 
 	PHP_FE(array_map,		NULL)
 	PHP_FE(array_chunk,		NULL)
 	PHP_FE(array_key_exists,		NULL)
+	PHP_FE(array_swap,first_arg_force_ref)
 
 	/* aliases from array.c */
 	PHP_FALIAS(pos, current,  first_arg_force_ref)
diff -Nur php-4.2.2/ext/standard/php_array.h php-4.2.2_devel/ext/standard/php_array.h
--- php-4.2.2/ext/standard/php_array.h	2001-12-11 15:30:34.0 +
+++ php-4.2.2_devel/ext/standard/php_array.h	2002-08-27 19:09:39.0 +0100
 -81,6 +81,7 
 PHP_FUNCTION(array_map);
 PHP_FUNCTION(array_key_exists);
 PHP_FUNCTION(array_chunk);
+PHP_FUNCTION(array_swap);
 
 HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **);
 PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive);



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


[PHP-DEV] help with duplicate flag in string functions

2002-07-25 Thread Tony Leake

Hi, 

I'm just starting out writing modules by reading api docs on zend.com
and reading source code of existing modules. 

Several functions (example:) 
add_next_index_string(zval *array, char *str, int duplicate)  

have the int duplicate flag, the docs say,  The flag duplicate specifies
whether the string contents have to be copied to Zend internal memory.

but how do I know if the string should be copied to memory, in the
simple functions I'm writing it seams to make no difference whether I
set this to 1 or 0 but it must do something?

Thanks for your time
Tony


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