Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-12-02 Thread J Smith

That's what I was thinking. The new patch updates skeleton.c a bit and fixes 
ext_skel to either add extern C stuff to skeleton.c or get rid of it. I 
think it would be simpler for extension first-timers to not worry about 
what __cplusplus means, or why extern C is there in the first place, etc. 

J


Sterling Hughes wrote:

 Is there any reason the ifdef __cplusplus doesn't work?  There shouldn't
 be any need for extra processing or config options.

 
 well, i think c++ code might confuse people just starting out writing a C
 extension...
 
 -Sterling
 


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




Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-12-02 Thread George Schlossnagle
J Smith wrote:


That's what I was thinking. The new patch updates skeleton.c a bit and fixes 
ext_skel to either add extern C stuff to skeleton.c or get rid of it. I 
think it would be simpler for extension first-timers to not worry about 
what __cplusplus means, or why extern C is there in the first place, etc. 


It could always be (horror of horrors) comemented in the code.


/* if we're using c++, we need some 'glue' */

#ifdef __cplusplus




J


Sterling Hughes wrote:


Is there any reason the ifdef __cplusplus doesn't work?  There shouldn't
be any need for extra processing or config options.


well, i think c++ code might confuse people just starting out writing a C
extension...

-Sterling









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




Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-12-02 Thread J Smith

Or it could just not be there at all? 

What the big deal here? It's four extra lines in ext_skel to get rid of it. 

Besides, you can comment the hell out of it, write six pages of 
documentation surrounded in /* */ if you want, you know there will be 
people asking why there's C++ code in their C code. If my vision of the 
future is in any way accurate, at least, which it may very well not be.

J


George Schlossnagle wrote:

 J Smith wrote:
 
That's what I was thinking. The new patch updates skeleton.c a bit and
fixes ext_skel to either add extern C stuff to skeleton.c or get rid of
it. I think it would be simpler for extension first-timers to not worry
about what __cplusplus means, or why extern C is there in the first
place, etc.

 
 It could always be (horror of horrors) comemented in the code.
 


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




Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-11-30 Thread Shane Caraveo
Is there any reason the ifdef __cplusplus doesn't work?  There shouldn't 
be any need for extra processing or config options.

J Smith wrote:
How about adding something like this to skeleton.c:

/* __begin_extern_c__ */
/* __end_extern_c__ */

And having the sed script in ext_skel replace them with the proper extern 
C stuff? That way there's no need for skeleton.cpp and just a few changes 
need to be made in skeleton.c.

J


Sascha Schumann wrote:


On Fri, 29 Nov 2002, J Smith wrote:



Attached is a patch to ext_skel that adds an optional argument (--cpp)
that will create a PHP extension in C++ rather than C. Also attached is
skeleton.cpp, which basically mirrors ext/skeleton/skeleton.c with a few
modifications for using C++. I could've just made some changes to
skeleton.c and done some sed work in the ext_skel script, but I think
it's clearer to have them separated into two files.


   I'm reluctant to duplicate the contents of the .c file for
   maintenance reason.  Cannot you just put the C++ specific
   code into a

   /* Remove this part, if this is not a C++ extension */
   #ifdef __cplusplus

   #endif

   section?

   - Sascha








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




Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-11-30 Thread Sterling Hughes
 Is there any reason the ifdef __cplusplus doesn't work?  There shouldn't 
 be any need for extra processing or config options.


well, i think c++ code might confuse people just starting out writing a C
extension...

-Sterling

 J Smith wrote:
 How about adding something like this to skeleton.c:
 
 /* __begin_extern_c__ */
 /* __end_extern_c__ */
 
 And having the sed script in ext_skel replace them with the proper extern 
 C stuff? That way there's no need for skeleton.cpp and just a few 
 changes need to be made in skeleton.c.
 
 J
 
 
 Sascha Schumann wrote:
 
 
 On Fri, 29 Nov 2002, J Smith wrote:
 
 
 Attached is a patch to ext_skel that adds an optional argument (--cpp)
 that will create a PHP extension in C++ rather than C. Also attached is
 skeleton.cpp, which basically mirrors ext/skeleton/skeleton.c with a few
 modifications for using C++. I could've just made some changes to
 skeleton.c and done some sed work in the ext_skel script, but I think
 it's clearer to have them separated into two files.
 
I'm reluctant to duplicate the contents of the .c file for
maintenance reason.  Cannot you just put the C++ specific
code into a
 
/* Remove this part, if this is not a C++ extension */
#ifdef __cplusplus
 
#endif
 
section?
 
- Sascha
 
 
 
 
 
 
 -- 
 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] [PATCH] Changes to ext_skel for C++

2002-11-30 Thread Marcus Börger
At 18:07 30.11.2002, Sterling Hughes wrote:

 Is there any reason the ifdef __cplusplus doesn't work?  There shouldn't
 be any need for extra processing or config options.


well, i think c++ code might confuse people just starting out writing a C
extension...

-Sterling


But there are more thinks they will not understand. So why making it more 
complex
and harder to understand the whole stuff for all of us?


 J Smith wrote:
 How about adding something like this to skeleton.c:
 
 /* __begin_extern_c__ */
 /* __end_extern_c__ */
 
 And having the sed script in ext_skel replace them with the proper extern
 C stuff? That way there's no need for skeleton.cpp and just a few
 changes need to be made in skeleton.c.
 
 J
 
 
 Sascha Schumann wrote:
 
 
 On Fri, 29 Nov 2002, J Smith wrote:
 
 
 Attached is a patch to ext_skel that adds an optional argument (--cpp)
 that will create a PHP extension in C++ rather than C. Also attached is
 skeleton.cpp, which basically mirrors ext/skeleton/skeleton.c with a few
 modifications for using C++. I could've just made some changes to
 skeleton.c and done some sed work in the ext_skel script, but I think
 it's clearer to have them separated into two files.
 
I'm reluctant to duplicate the contents of the .c file for
maintenance reason.  Cannot you just put the C++ specific
code into a
 
/* Remove this part, if this is not a C++ extension */
#ifdef __cplusplus
 
#endif
 
section?
 
- Sascha
 
 
 



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



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




[PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-11-29 Thread J Smith

Attached is a patch to ext_skel that adds an optional argument (--cpp) that 
will create a PHP extension in C++ rather than C. Also attached is 
skeleton.cpp, which basically mirrors ext/skeleton/skeleton.c with a few 
modifications for using C++. I could've just made some changes to 
skeleton.c and done some sed work in the ext_skel script, but I think it's 
clearer to have them separated into two files. 

The ext_skel patch is based on the current HEAD.

Comments?

J
Index: ext_skel
===
RCS file: /repository/php4/ext/ext_skel,v
retrieving revision 1.44
diff -u -3 -p -r1.44 ext_skel
--- ext_skel	18 Nov 2002 15:55:07 -	1.44
+++ ext_skel	29 Nov 2002 18:20:40 -
@@ -7,7 +7,7 @@ givup() {
 
 usage() {
 echo $0 --extname=module [--proto=file] [--stubs=file] [--xml[=file]]
-echo[--skel=dir] [--full-xml] [--no-help]
+echo[--skel=dir] [--full-xml] [--no-help] [--cpp]
 echo 
 echo   --extname=module   module is the name of your extension
 echo   --proto=file   file contains prototypes of functions to create
@@ -18,6 +18,7 @@ echo   --full-xml generate xml 
 echo  (not yet implemented)
 echo   --no-help  don't try to be nice and create comments in the code
 echo  and helper functions to test if the module compiled
+echo   --cpp  create a C++ extension
 exit 1
 }
 
@@ -58,6 +59,9 @@ while test $# -gt 0; do
 --skel=?*)
 	skel_dir=$optarg
 	;;
+--cpp)
+cpp=yes
+;;
 *)
 	usage
 	;;
@@ -94,7 +98,7 @@ if test -z $stubs; then
 fi
 
 if test -n $proto; then
-  cat $proto | awk -v extname=$extname -v stubs=$stubs -v stubfile=$stubfile -v xml=$xml -v full_xml=$full_xml -v i_know_what_to_do_shut_up_i_dont_need_your_help_mode=$no_help -f $skel_dir/create_stubs
+  cat $proto | awk -v extname=$extname -v stubs=$stubs -v stubfile=$stubfile -v xml=$xml -v full_xml=$full_xml -v i_know_what_to_do_shut_up_i_dont_need_your_help_mode=$no_help -v cpp=$cpp -f $skel_dir/create_stubs
 fi
 
 if test -z $stubs; then
@@ -165,11 +169,16 @@ if test \$PHP_$EXTNAME != no; then
   dnl ])
   dnl
   dnl PHP_SUBST(${EXTNAME}_SHARED_LIBADD)
+eof
 
-  PHP_NEW_EXTENSION($extname, $extname.c, \$ext_shared)
+if test $cpp = yes; then
+  echo   PHP_REQUIRE_CXX() config.m4
+  echo   PHP_NEW_EXTENSION($extname, $extname.cpp, \$ext_shared) config.m4
+else
+  echo   PHP_NEW_EXTENSION($extname, $extname.c, \$ext_shared) config.m4
 fi
-eof
 
+echo fi config.m4
 
 $ECHO_N  .cvsignore$ECHO_C
 cat .cvsignore eof
@@ -178,7 +187,11 @@ cat .cvsignore eof
 *.la
 eof
 
-$ECHO_N  $extname.c$ECHO_C
+if test $cpp = yes; then
+$ECHO_N  $extname.cpp$ECHO_C
+else
+$ECHO_N  $extname.c$ECHO_C
+fi
 echo s/extname/$extname/g  sedscript
 echo s/EXTNAME/$EXTNAME/g   sedscript
 echo '/__function_entries_here__/r function_entries'   sedscript
@@ -189,6 +202,7 @@ echo '/__function_entries_here__/D'   
 echo '/__function_stubs_here__/D'   sedscript
 echo '/__header_here__/D'   sedscript
 echo '/__footer_here__/D'   sedscript
+
 if [ ! -z $no_help ]; then
 echo /confirm_$extname_compiled/D  sedscript
 echo '/Remove the following/,/^\*\//D'  sedscript
@@ -197,7 +211,11 @@ if [ ! -z $no_help ]; then
 echo '/^[[:space:]]*\/\*/,/^[[:space:]]*\*\//D'  sedscript
 fi
 
-sed -f sedscript  $skel_dir/skeleton.c  $extname.c
+if test $cpp = yes; then
+sed -f sedscript  $skel_dir/skeleton.cpp  $extname.cpp
+else
+sed -f sedscript  $skel_dir/skeleton.c  $extname.c
+fi
 
 
 $ECHO_N  php_$extname.h$ECHO_C
@@ -273,7 +291,15 @@ To use your new extension, you will have
 4.  $ ./configure --[with|enable]-$extname
 5.  $ make
 6.  $ ./php -f ext/$extname/$extname.php
-7.  $ vi ext/$extname/$extname.c
+eof
+
+  if test $cpp = yes; then
+  echo 7.  $ vi ext/$extname/$extname.cpp
+  else
+  echo 7.  $ vi ext/$extname/$extname.c
+  fi
+
+  cat eof
 8.  $ make
 
 Repeat steps 3-6 until you are satisfied with ext/$extname/config.m4 and

/* __header_here__ */

#ifdef HAVE_CONFIG_H
#include config.h
#endif

extern C {
#include php.h
#include php_ini.h
#include ext/standard/info.h
}

#include php_extname.h

// C++ header...

#include string

using namespace std;

/* If you declare any globals in php_extname.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(extname)
*/

/* True global resources - no need for thread safety here */
static int le_extname;

/* {{{ extname_functions[]
 *
 * Every user visible function must have an entry in extname_functions[].
 */
function_entry extname_functions[] = {
	PHP_FE(confirm_extname_compiled,	NULL)		/* For testing, remove later. */
	/* __function_entries_here__ */
	{NULL, NULL, NULL}	/* Must be the last line in extname_functions[] */
};
/* }}} */

/* {{{ extname_module_entry
 */
zend_module_entry extname_module_entry = {
#if ZEND_MODULE_API_NO = 20010901
	STANDARD_MODULE_HEADER,
#endif
	extname,
	extname_functions,
	PHP_MINIT(extname),
	PHP_MSHUTDOWN(extname),
	

Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-11-29 Thread Shane Caraveo
J Smith wrote:

Attached is a patch to ext_skel that adds an optional argument (--cpp) that 
will create a PHP extension in C++ rather than C. Also attached is 
skeleton.cpp, which basically mirrors ext/skeleton/skeleton.c with a few 
modifications for using C++. I could've just made some changes to 
skeleton.c and done some sed work in the ext_skel script, but I think it's 
clearer to have them separated into two files. 

The ext_skel patch is based on the current HEAD.

Comments?

J

skeleton.h also needs to be dealt with.  If you do not, visual studio 
will export symbols as c++ symbols and the extension will not work. 
Simple solution is to have

#ifdef __cplusplus
extern C {
#endif

at the top of skeleton.h, and close it at the bottom.

Shane




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



Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-11-29 Thread Sascha Schumann
On Fri, 29 Nov 2002, J Smith wrote:


 Attached is a patch to ext_skel that adds an optional argument (--cpp) that
 will create a PHP extension in C++ rather than C. Also attached is
 skeleton.cpp, which basically mirrors ext/skeleton/skeleton.c with a few
 modifications for using C++. I could've just made some changes to
 skeleton.c and done some sed work in the ext_skel script, but I think it's
 clearer to have them separated into two files.

I'm reluctant to duplicate the contents of the .c file for
maintenance reason.  Cannot you just put the C++ specific
code into a

/* Remove this part, if this is not a C++ extension */
#ifdef __cplusplus

#endif

section?

- Sascha

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




Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-11-29 Thread J Smith

Is this a problem with VS.net or something? I've never done that with any of 
my C++ extensions and they've all worked fine on VC++ 6.

If it is a problem, though, I'll make the changes.

J

Shane Caraveo wrote:

 J Smith wrote:
 Attached is a patch to ext_skel that adds an optional argument (--cpp)
 that will create a PHP extension in C++ rather than C. Also attached is
 skeleton.cpp, which basically mirrors ext/skeleton/skeleton.c with a few
 modifications for using C++. I could've just made some changes to
 skeleton.c and done some sed work in the ext_skel script, but I think
 it's clearer to have them separated into two files.
 
 The ext_skel patch is based on the current HEAD.
 
 Comments?
 
 J
 
 skeleton.h also needs to be dealt with.  If you do not, visual studio
 will export symbols as c++ symbols and the extension will not work.
 Simple solution is to have
 
 #ifdef __cplusplus
 extern C {
 #endif
 
 at the top of skeleton.h, and close it at the bottom.
 
 Shane


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




Re: [PHP-DEV] [PATCH] Changes to ext_skel for C++

2002-11-29 Thread J Smith

How about adding something like this to skeleton.c:

/* __begin_extern_c__ */
/* __end_extern_c__ */

And having the sed script in ext_skel replace them with the proper extern 
C stuff? That way there's no need for skeleton.cpp and just a few changes 
need to be made in skeleton.c.

J


Sascha Schumann wrote:

 On Fri, 29 Nov 2002, J Smith wrote:
 

 Attached is a patch to ext_skel that adds an optional argument (--cpp)
 that will create a PHP extension in C++ rather than C. Also attached is
 skeleton.cpp, which basically mirrors ext/skeleton/skeleton.c with a few
 modifications for using C++. I could've just made some changes to
 skeleton.c and done some sed work in the ext_skel script, but I think
 it's clearer to have them separated into two files.
 
 I'm reluctant to duplicate the contents of the .c file for
 maintenance reason.  Cannot you just put the C++ specific
 code into a
 
 /* Remove this part, if this is not a C++ extension */
 #ifdef __cplusplus
 
 #endif
 
 section?
 
 - Sascha


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