388
440
FileErrorDisplay(configm4);
389
441
SWIG_exit(EXIT_FAILURE);
392
Printf(f_extra,"dnl $Id: php4.cxx,v 1.34 2006/03/20 00:24:39 marcelomatus Exp $\n");
393
Printf(f_extra,"dnl ***********************************************************************\n");
394
Printf(f_extra,"dnl ** THIS config.m4 is provided for PHPIZE and PHP's consumption NOT\n");
395
Printf(f_extra,"dnl ** for any part of the rest of the %s build system\n",module);
396
Printf(f_extra,"dnl ***********************************************************************\n\n");
399
if (! with) { // must be enable then
400
Printf(f_extra,"PHP_ARG_ENABLE(%s, whether to enable %s support,\n",module,module);
401
Printf(f_extra,"[ --enable-%s Enable %s support])\n\n",module,module);
444
Printf(f_extra, "dnl $Id: php4.cxx,v 1.68 2006/11/01 23:54:52 wsfulton Exp $\n");
445
Printf(f_extra, "dnl ***********************************************************************\n");
446
Printf(f_extra, "dnl ** THIS config.m4 is provided for PHPIZE and PHP's consumption NOT\n");
447
Printf(f_extra, "dnl ** for any part of the rest of the %s build system\n", module);
448
Printf(f_extra, "dnl ***********************************************************************\n\n");
451
if (!with) { // must be enable then
452
Printf(f_extra, "PHP_ARG_ENABLE(%s, whether to enable %s support,\n", module, module);
453
Printf(f_extra, "[ --enable-%s Enable %s support])\n\n", module, module);
403
Printf(f_extra,"PHP_ARG_WITH(%s, for %s support,\n",module,module);
404
Printf(f_extra,"[ --with-%s[=DIR] Include %s support.])\n\n",module,module);
455
Printf(f_extra, "PHP_ARG_WITH(%s, for %s support,\n", module, module);
456
Printf(f_extra, "[ --with-%s[=DIR] Include %s support.])\n\n", module, module);
405
457
// These tests try and file the library we need
406
Printf(f_extra,"dnl THESE TESTS try and find the library and header files\n");
407
Printf(f_extra,"dnl your new php module needs. YOU MAY NEED TO EDIT THEM\n");
408
Printf(f_extra,"dnl as written they assume your header files are all in the same place\n\n");
410
Printf(f_extra,"dnl ** are we looking for %s_lib.h or something else?\n",module);
458
Printf(f_extra, "dnl THESE TESTS try and find the library and header files\n");
459
Printf(f_extra, "dnl your new php module needs. YOU MAY NEED TO EDIT THEM\n");
460
Printf(f_extra, "dnl as written they assume your header files are all in the same place\n\n");
462
Printf(f_extra, "dnl ** are we looking for %s_lib.h or something else?\n", module);
412
Printf(f_extra,"HNAMES=\"%s\"\n\n",withincs);
464
Printf(f_extra, "HNAMES=\"%s\"\n\n", withincs);
414
Printf(f_extra,"HNAMES=\"\"; # %s_lib.h ?\n\n",module);
416
Printf(f_extra,"dnl ** Are we looking for lib%s.a or lib%s.so or something else?\n",module,module);
466
Printf(f_extra, "HNAMES=\"\"; # %s_lib.h ?\n\n", module);
468
Printf(f_extra, "dnl ** Are we looking for lib%s.a or lib%s.so or something else?\n", module, module);
419
Printf(f_extra,"LIBNAMES=\"%s\"\n\n",withlibs);
471
Printf(f_extra, "LIBNAMES=\"%s\"\n\n", withlibs);
421
Printf(f_extra,"LIBNAMES=\"\"; # lib_%s.so ?\n\n",withlibs);
423
Printf(f_extra,"dnl IF YOU KNOW one of the symbols in the library and you\n");
424
Printf(f_extra,"dnl specify it below then we can have a link test to see if it works\n");
425
Printf(f_extra,"LIBSYMBOL=\"\"\n\n");
473
Printf(f_extra, "LIBNAMES=\"\"; # lib%s.so ?\n\n", module);
475
Printf(f_extra, "dnl IF YOU KNOW one of the symbols in the library and you\n");
476
Printf(f_extra, "dnl specify it below then we can have a link test to see if it works\n");
477
Printf(f_extra, "LIBSYMBOL=\"\"\n\n");
428
480
// Now write out tests to find thing.. they may need to extend tests
429
Printf(f_extra,"if test \"$PHP_%(upper)s\" != \"no\"; then\n\n",module);
481
Printf(f_extra, "if test \"$PHP_%s\" != \"no\"; then\n\n", cap_module);
431
483
// Ready for when we add libraries as we find them
432
Printf(f_extra," PHP_SUBST(%(upper)s_SHARED_LIBADD)\n\n",module);
434
if (withlibs) { // find more than one library
435
Printf(f_extra," for LIBNAME in $LIBNAMES ; do\n");
436
Printf(f_extra," LIBDIR=\"\"\n");
484
Printf(f_extra, " PHP_SUBST(%s_SHARED_LIBADD)\n\n", cap_module);
486
if (withlibs) { // find more than one library
487
Printf(f_extra, " for LIBNAME in $LIBNAMES ; do\n");
488
Printf(f_extra, " LIBDIR=\"\"\n");
437
489
// For each path element to try...
438
Printf(f_extra," for i in $PHP_%(upper)s $PHP_%(upper)s/lib /usr/lib /usr/local/lib ; do\n",module,module);
439
Printf(f_extra," if test -r $i/lib$LIBNAME.a -o -r $i/lib$LIBNAME.so ; then\n");
440
Printf(f_extra," LIBDIR=\"$i\"\n");
441
Printf(f_extra," break\n");
442
Printf(f_extra," fi\n");
443
Printf(f_extra," done\n\n");
444
Printf(f_extra," dnl ** and $LIBDIR should be the library path\n");
445
Printf(f_extra," if test \"$LIBNAME\" != \"\" -a -z \"$LIBDIR\" ; then\n");
446
Printf(f_extra," AC_MSG_RESULT(Library files $LIBNAME not found)\n");
447
Printf(f_extra," AC_MSG_ERROR(Is the %s distribution installed properly?)\n",module);
448
Printf(f_extra," else\n");
449
Printf(f_extra," AC_MSG_RESULT(Library files $LIBNAME found in $LIBDIR)\n");
450
Printf(f_extra," PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBDIR, %(upper)s_SHARED_LIBADD)\n",module);
451
Printf(f_extra," fi\n");
452
Printf(f_extra," done\n\n");
490
Printf(f_extra, " for i in $PHP_%s $PHP_%s/lib /usr/lib /usr/local/lib ; do\n", cap_module, cap_module);
491
Printf(f_extra, " if test -r $i/lib$LIBNAME.a -o -r $i/lib$LIBNAME.so ; then\n");
492
Printf(f_extra, " LIBDIR=\"$i\"\n");
493
Printf(f_extra, " break\n");
494
Printf(f_extra, " fi\n");
495
Printf(f_extra, " done\n\n");
496
Printf(f_extra, " dnl ** and $LIBDIR should be the library path\n");
497
Printf(f_extra, " if test \"$LIBNAME\" != \"\" -a -z \"$LIBDIR\" ; then\n");
498
Printf(f_extra, " AC_MSG_RESULT(Library files $LIBNAME not found)\n");
499
Printf(f_extra, " AC_MSG_ERROR(Is the %s distribution installed properly?)\n", module);
500
Printf(f_extra, " else\n");
501
Printf(f_extra, " AC_MSG_RESULT(Library files $LIBNAME found in $LIBDIR)\n");
502
Printf(f_extra, " PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBDIR, %s_SHARED_LIBADD)\n", cap_module);
503
Printf(f_extra, " fi\n");
504
Printf(f_extra, " done\n\n");
455
if (withincs) { // Find more than once include
456
Printf(f_extra," for HNAME in $HNAMES ; do\n");
457
Printf(f_extra," INCDIR=\"\"\n");
507
if (withincs) { // Find more than once include
508
Printf(f_extra, " for HNAME in $HNAMES ; do\n");
509
Printf(f_extra, " INCDIR=\"\"\n");
458
510
// For each path element to try...
459
Printf(f_extra," for i in $PHP_%(upper)s $PHP_%(upper)s/include $PHP_%(upper)s/includes $PHP_%(upper)s/inc $PHP_%(upper)s/incs /usr/local/include /usr/include; do\n",module,module,module,module,module);
511
Printf(f_extra, " for i in $PHP_%s $PHP_%s/include $PHP_%s/includes $PHP_%s/inc $PHP_%s/incs /usr/local/include /usr/include; do\n", cap_module,
512
cap_module, cap_module, cap_module, cap_module);
460
513
// Try and find header files
461
Printf(f_extra," if test \"$HNAME\" != \"\" -a -r $i/$HNAME ; then\n");
462
Printf(f_extra," INCDIR=\"$i\"\n");
463
Printf(f_extra," break\n");
464
Printf(f_extra," fi\n");
465
Printf(f_extra," done\n\n");
467
Printf(f_extra," dnl ** Now $INCDIR should be the include file path\n");
468
Printf(f_extra," if test \"$HNAME\" != \"\" -a -z \"$INCDIR\" ; then\n");
469
Printf(f_extra," AC_MSG_RESULT(Include files $HNAME not found)\n");
470
Printf(f_extra," AC_MSG_ERROR(Is the %s distribution installed properly?)\n",module);
471
Printf(f_extra," else\n");
472
Printf(f_extra," AC_MSG_RESULT(Include files $HNAME found in $INCDIR)\n");
473
Printf(f_extra," PHP_ADD_INCLUDE($INCDIR)\n");
474
Printf(f_extra," fi\n\n");
475
Printf(f_extra," done\n\n");
514
Printf(f_extra, " if test \"$HNAME\" != \"\" -a -r $i/$HNAME ; then\n");
515
Printf(f_extra, " INCDIR=\"$i\"\n");
516
Printf(f_extra, " break\n");
517
Printf(f_extra, " fi\n");
518
Printf(f_extra, " done\n\n");
520
Printf(f_extra, " dnl ** Now $INCDIR should be the include file path\n");
521
Printf(f_extra, " if test \"$HNAME\" != \"\" -a -z \"$INCDIR\" ; then\n");
522
Printf(f_extra, " AC_MSG_RESULT(Include files $HNAME not found)\n");
523
Printf(f_extra, " AC_MSG_ERROR(Is the %s distribution installed properly?)\n", module);
524
Printf(f_extra, " else\n");
525
Printf(f_extra, " AC_MSG_RESULT(Include files $HNAME found in $INCDIR)\n");
526
Printf(f_extra, " PHP_ADD_INCLUDE($INCDIR)\n");
527
Printf(f_extra, " fi\n\n");
528
Printf(f_extra, " done\n\n");
479
Printf(f_extra," # As this is a C++ module..\n");
532
Printf(f_extra, " # As this is a C++ module..\n");
482
Printf(f_extra," PHP_REQUIRE_CXX\n");
483
Printf(f_extra," AC_CHECK_LIB(stdc++, cin)\n");
535
Printf(f_extra, " PHP_REQUIRE_CXX\n");
536
Printf(f_extra, " AC_CHECK_LIB(stdc++, cin)\n");
486
Printf(f_extra," if test \"$LIBSYMBOL\" != \"\" ; then\n");
487
Printf(f_extra," old_LIBS=\"$LIBS\"\n");
488
Printf(f_extra," LIBS=\"$LIBS -L$TEST_DIR/lib -lm -ldl\"\n");
489
Printf(f_extra," AC_CHECK_LIB($LIBNAME, $LIBSYMBOL, [AC_DEFINE(HAVE_TESTLIB,1, [ ])],\n");
490
Printf(f_extra," [AC_MSG_ERROR(wrong test lib version or lib not found)])\n");
491
Printf(f_extra," LIBS=\"$old_LIBS\"\n");
492
Printf(f_extra," fi\n\n");
539
Printf(f_extra, " if test \"$LIBSYMBOL\" != \"\" ; then\n");
540
Printf(f_extra, " old_LIBS=\"$LIBS\"\n");
541
Printf(f_extra, " LIBS=\"$LIBS -L$TEST_DIR/lib -lm -ldl\"\n");
542
Printf(f_extra, " AC_CHECK_LIB($LIBNAME, $LIBSYMBOL, [AC_DEFINE(HAVE_TESTLIB,1, [ ])],\n");
543
Printf(f_extra, " [AC_MSG_ERROR(wrong test lib version or lib not found)])\n");
544
Printf(f_extra, " LIBS=\"$old_LIBS\"\n");
545
Printf(f_extra, " fi\n\n");
495
Printf(f_extra," AC_DEFINE(HAVE_%(upper)s, 1, [ ])\n",module);
496
Printf(f_extra,"dnl AC_DEFINE_UNQUOTED(PHP_%(upper)s_DIR, \"$%(upper)s_DIR\", [ ])\n",module,module);
497
Printf(f_extra," PHP_EXTENSION(%s, $ext_shared)\n",module);
548
Printf(f_extra, " AC_DEFINE(HAVE_%s, 1, [ ])\n", cap_module);
549
Printf(f_extra, "dnl AC_DEFINE_UNQUOTED(PHP_%s_DIR, \"$%s_DIR\", [ ])\n", cap_module, cap_module);
550
Printf(f_extra, " PHP_EXTENSION(%s, $ext_shared)\n", module);
499
552
// and thats all!
500
Printf(f_extra,"fi\n");
553
Printf(f_extra, "fi\n");
505
558
f_extra = NewFile(credits, "w");
539
592
r_shutdown = NewString("/* rshutdown section */\n");
540
593
s_header = NewString("/* header section */\n");
541
594
s_wrappers = NewString("/* wrapper section */\n");
542
s_type = NewString("");
595
s_type = NewStringEmpty();
543
596
/* subsections of the init section */
544
597
s_vinit = NewString("/* vinit subsection */\n");
545
598
s_vdecl = NewString("/* vdecl subsection */\n");
546
599
s_cinit = NewString("/* cinit subsection */\n");
547
600
s_oinit = NewString("/* oinit subsection */\n");
548
pragma_phpinfo = NewString("");
601
pragma_phpinfo = NewStringEmpty();
602
s_phpclasses = NewString("/* PHP Proxy Classes */\n");
550
604
/* Register file targets with the SWIG file handler */
551
Swig_register_filebyname("runtime",f_runtime);
552
Swig_register_filebyname("init",s_init);
553
Swig_register_filebyname("rinit",r_init);
554
Swig_register_filebyname("shutdown",s_shutdown);
555
Swig_register_filebyname("rshutdown",r_shutdown);
556
Swig_register_filebyname("header",s_header);
557
Swig_register_filebyname("wrapper",s_wrappers);
605
Swig_register_filebyname("runtime", f_runtime);
606
Swig_register_filebyname("init", s_init);
607
Swig_register_filebyname("rinit", r_init);
608
Swig_register_filebyname("shutdown", s_shutdown);
609
Swig_register_filebyname("rshutdown", r_shutdown);
610
Swig_register_filebyname("header", s_header);
611
Swig_register_filebyname("wrapper", s_wrappers);
559
613
/* Set the module name */
560
module = Copy(Getattr(n,"name"));
561
cap_module = NewStringf("%(upper)s",module);
565
#if defined(_WIN32) || defined(__WIN32__)
566
dlname = NewStringf("php_%s.dll", module);
568
dlname = NewStringf("php_%s.so", module);
614
module = Copy(Getattr(n, "name"));
615
cap_module = NewStringf("%(upper)s", module);
617
prefix = NewStringEmpty();
572
619
/* PHP module file */
573
filen = NewString("");
620
filen = NewStringEmpty();
574
621
Printv(filen, SWIG_output_directory(), module, ".php", NIL);
575
622
phpfilename = NewString(filen);
577
624
f_phpcode = NewFile(filen, "w");
578
625
if (!f_phpcode) {
579
626
FileErrorDisplay(filen);
580
627
SWIG_exit(EXIT_FAILURE);
583
630
Printf(f_phpcode, "<?php\n\n");
585
632
Swig_banner(f_phpcode);
587
Printf(f_phpcode,"global $%s_LOADED__;\n", cap_module);
588
Printf(f_phpcode,"if ($%s_LOADED__) return;\n", cap_module);
589
Printf(f_phpcode,"$%s_LOADED__ = true;\n\n", cap_module);
590
Printf(f_phpcode,"/* if our extension has not been loaded, do what we can */\n");
591
Printf(f_phpcode,"if (!extension_loaded(\"php_%s\")) {\n", module);
592
Printf(f_phpcode," if (!dl(\"%s\")) return;\n", dlname);
593
Printf(f_phpcode,"}\n\n");
634
Printf(f_phpcode, "// Try to load our extension if it's not already loaded.\n");
635
Printf(f_phpcode, "if (!extension_loaded(\"%s\")) {\n", module);
636
Printf(f_phpcode, " if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {\n");
637
Printf(f_phpcode, " if (!dl('php_%s.dll')) return;\n", module);
638
Printf(f_phpcode, " } else {\n");
639
Printf(f_phpcode, " // PHP_SHLIB_SUFFIX is available as of PHP 4.3.0, for older PHP assume 'so'.\n");
640
Printf(f_phpcode, " // It gives 'dylib' on MacOS X which is for libraries, modules are 'so'.\n");
641
Printf(f_phpcode, " if (PHP_SHLIB_SUFFIX === 'PHP_SHLIB_SUFFIX' || PHP_SHLIB_SUFFIX === 'dylib') {\n");
642
Printf(f_phpcode, " if (!dl('%s.so')) return;\n", module);
643
Printf(f_phpcode, " } else {\n");
644
Printf(f_phpcode, " if (!dl('%s.'.PHP_SHLIB_SUFFIX)) return;\n", module);
645
Printf(f_phpcode, " }\n");
646
Printf(f_phpcode, " }\n");
647
Printf(f_phpcode, "}\n\n");
596
649
/* sub-sections of the php file */
597
pragma_code = NewString("");
598
pragma_incl = NewString("");
650
pragma_code = NewStringEmpty();
651
pragma_incl = NewStringEmpty();
600
653
/* Initialize the rest of the module */
602
Printf(s_oinit, "ZEND_INIT_MODULE_GLOBALS(%s, %s_init_globals, %s_destroy_globals);\n",module,module,module);
655
Printf(s_oinit, "ZEND_INIT_MODULE_GLOBALS(%s, %s_init_globals, %s_destroy_globals);\n", module, module, module);
604
657
/* start the header section */
605
658
Printf(s_header, php_header);
606
659
Printf(s_header, "ZEND_BEGIN_MODULE_GLOBALS(%s)\n", module);
607
660
Printf(s_header, "char *error_msg;\n");
608
661
Printf(s_header, "int error_code;\n");
609
Printf(s_header, "ZEND_END_MODULE_GLOBALS(%s)\n", module );
610
Printf(s_header, "ZEND_DECLARE_MODULE_GLOBALS(%s)\n",module );
611
Printf(s_header, "#ifdef ZTS\n" );
612
Printf(s_header, "#define ErrorMsg() TSRMG(%s_globals_id, zend_%s_globals *, error_msg )\n",module,module);
613
Printf(s_header, "#define ErrorCode() TSRMG(%s_globals_id, zend_%s_globals *, error_code )\n",module,module);
614
Printf(s_header, "#else\n" );
615
Printf(s_header, "#define ErrorMsg() (%s_globals.error_msg)\n",module);
616
Printf(s_header, "#define ErrorCode() (%s_globals.error_code)\n",module);
617
Printf(s_header, "#endif\n\n" );
619
Printf(s_header, "static void %s_init_globals(zend_%s_globals *%s_globals ) {\n",module,module,module);
620
Printf(s_header, " %s_globals->error_msg = default_error_msg;\n", module);
621
Printf(s_header, " %s_globals->error_code = default_error_code;\n",module);
662
Printf(s_header, "ZEND_END_MODULE_GLOBALS(%s)\n", module);
663
Printf(s_header, "ZEND_DECLARE_MODULE_GLOBALS(%s)\n", module);
664
Printf(s_header, "#ifdef ZTS\n");
665
Printf(s_header, "#define SWIG_ErrorMsg() TSRMG(%s_globals_id, zend_%s_globals *, error_msg )\n", module, module);
666
Printf(s_header, "#define SWIG_ErrorCode() TSRMG(%s_globals_id, zend_%s_globals *, error_code )\n", module, module);
667
Printf(s_header, "#else\n");
668
Printf(s_header, "#define SWIG_ErrorMsg() (%s_globals.error_msg)\n", module);
669
Printf(s_header, "#define SWIG_ErrorCode() (%s_globals.error_code)\n", module);
670
Printf(s_header, "#endif\n\n");
672
Printf(s_header, "static void %s_init_globals(zend_%s_globals *globals ) {\n", module, module);
673
Printf(s_header, " globals->error_msg = default_error_msg;\n");
674
Printf(s_header, " globals->error_code = default_error_code;\n");
622
675
Printf(s_header, "}\n");
624
Printf(s_header, "static void %s_destroy_globals(zend_%s_globals *%s_globals) { }\n",module,module,module);
677
Printf(s_header, "static void %s_destroy_globals(zend_%s_globals * globals) { (void)globals; }\n", module, module);
626
679
Printf(s_header, "\n");
627
Printf(s_header, "void SWIG_ResetError() {\n");
680
Printf(s_header, "static void SWIG_ResetError() {\n");
628
681
Printf(s_header, " TSRMLS_FETCH();\n");
629
Printf(s_header, " ErrorMsg() = default_error_msg;\n");
630
Printf(s_header, " ErrorCode() = default_error_code;\n");
682
Printf(s_header, " SWIG_ErrorMsg() = default_error_msg;\n");
683
Printf(s_header, " SWIG_ErrorCode() = default_error_code;\n");
631
684
Printf(s_header, "}\n");
633
Printf(s_header,"#define SWIG_name \"%s\"\n", module);
686
Printf(s_header, "#define SWIG_name \"%s\"\n", module);
634
687
/* Printf(s_header,"#ifdef HAVE_CONFIG_H\n");
635
Printf(s_header,"#include \"config.h\"\n");
636
Printf(s_header,"#endif\n\n");
638
Printf(s_header,"#ifdef __cplusplus\n");
639
Printf(s_header,"extern \"C\" {\n");
640
Printf(s_header,"#endif\n");
641
Printf(s_header,"#include \"php.h\"\n");
642
Printf(s_header,"#include \"php_ini.h\"\n");
643
Printf(s_header,"#include \"ext/standard/info.h\"\n");
644
Printf(s_header,"#include \"php_%s.h\"\n", module);
645
Printf(s_header,"#ifdef __cplusplus\n");
646
Printf(s_header,"}\n");
647
Printf(s_header,"#endif\n\n");
688
Printf(s_header,"#include \"config.h\"\n");
689
Printf(s_header,"#endif\n\n");
691
Printf(s_header, "#ifdef __cplusplus\n");
692
Printf(s_header, "extern \"C\" {\n");
693
Printf(s_header, "#endif\n");
694
Printf(s_header, "#include \"php.h\"\n");
695
Printf(s_header, "#include \"php_ini.h\"\n");
696
Printf(s_header, "#include \"ext/standard/info.h\"\n");
697
Printf(s_header, "#include \"php_%s.h\"\n", module);
698
Printf(s_header, "#ifdef __cplusplus\n");
699
Printf(s_header, "}\n");
700
Printf(s_header, "#endif\n\n");
649
702
/* Create the .h file too */
650
filen = NewString("");
703
filen = NewStringEmpty();
651
704
Printv(filen, SWIG_output_directory(), "php_", module, ".h", NIL);
652
705
f_h = NewFile(filen, "w");
654
707
FileErrorDisplay(filen);
655
708
SWIG_exit(EXIT_FAILURE);
658
711
Swig_banner(f_h);
659
712
Printf(f_h, php_header);
661
714
Printf(f_h, "\n\n");
662
Printf(f_h, "#ifndef PHP_%s_H\n", cap_module );
663
Printf(f_h, "#define PHP_%s_H\n\n", cap_module );
664
Printf(f_h, "extern zend_module_entry %s_module_entry;\n", module );
665
Printf(f_h, "#define phpext_%s_ptr &%s_module_entry\n\n", module, module );
666
Printf(f_h, "#ifdef PHP_WIN32\n" );
667
Printf(f_h, "# define PHP_%s_API __declspec(dllexport)\n", cap_module );
668
Printf(f_h, "#else\n" );
669
Printf(f_h, "# define PHP_%s_API\n", cap_module );
670
Printf(f_h, "#endif\n\n" );
671
Printf(f_h, "#ifdef ZTS\n" );
672
Printf(f_h, "#include \"TSRM.h\"\n" );
673
Printf(f_h, "#endif\n\n" );
674
Printf(f_h, "PHP_MINIT_FUNCTION(%s);\n", module );
675
Printf(f_h, "PHP_MSHUTDOWN_FUNCTION(%s);\n", module );
676
Printf(f_h, "PHP_RINIT_FUNCTION(%s);\n", module );
677
Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module );
678
Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n\n", module );
715
Printf(f_h, "#ifndef PHP_%s_H\n", cap_module);
716
Printf(f_h, "#define PHP_%s_H\n\n", cap_module);
717
Printf(f_h, "extern zend_module_entry %s_module_entry;\n", module);
718
Printf(f_h, "#define phpext_%s_ptr &%s_module_entry\n\n", module, module);
719
Printf(f_h, "#ifdef PHP_WIN32\n");
720
Printf(f_h, "# define PHP_%s_API __declspec(dllexport)\n", cap_module);
721
Printf(f_h, "#else\n");
722
Printf(f_h, "# define PHP_%s_API\n", cap_module);
723
Printf(f_h, "#endif\n\n");
724
Printf(f_h, "#ifdef ZTS\n");
725
Printf(f_h, "#include \"TSRM.h\"\n");
726
Printf(f_h, "#endif\n\n");
727
Printf(f_h, "PHP_MINIT_FUNCTION(%s);\n", module);
728
Printf(f_h, "PHP_MSHUTDOWN_FUNCTION(%s);\n", module);
729
Printf(f_h, "PHP_RINIT_FUNCTION(%s);\n", module);
730
Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module);
731
Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n\n", module);
680
733
/* start the function entry section */
681
734
s_entry = NewString("/* entry subsection */\n");
683
736
/* holds all the per-class function entry sections */
684
737
all_cs_entry = NewString("/* class entry subsection */\n");
687
Printf(s_entry,"/* Every non-class user visible function must have an entry here */\n");
688
Printf(s_entry,"function_entry %s_functions[] = {\n", module);
740
Printf(s_entry, "/* Every non-class user visible function must have an entry here */\n");
741
Printf(s_entry, "static function_entry %s_functions[] = {\n", module);
690
743
/* start the init section */
692
Printf(s_init,"#ifdef COMPILE_DL_%s\n", cap_module);
694
Printf(s_init,"#ifdef __cplusplus\n");
695
Printf(s_init,"extern \"C\" {\n");
696
Printf(s_init,"#endif\n");
697
Printf(s_init,"ZEND_GET_MODULE(%s)\n",module);
698
Printf(s_init,"#ifdef __cplusplus\n");
699
Printf(s_init,"}\n");
700
Printf(s_init,"#endif\n\n");
703
Printf(s_init,"#endif\n\n");
744
Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n" "#if ZEND_MODULE_API_NO > 20010900\n" " STANDARD_MODULE_HEADER,\n" "#endif\n", NIL);
745
Printf(s_init, " \"%s\",\n", module);
746
Printf(s_init, " %s_functions,\n", module);
747
Printf(s_init, " PHP_MINIT(%s),\n", module);
748
Printf(s_init, " PHP_MSHUTDOWN(%s),\n", module);
749
Printf(s_init, " PHP_RINIT(%s),\n", module);
750
Printf(s_init, " PHP_RSHUTDOWN(%s),\n", module);
751
Printf(s_init, " PHP_MINFO(%s),\n", module);
752
Printf(s_init, "#if ZEND_MODULE_API_NO > 20010900\n");
753
Printf(s_init, " NO_VERSION_YET,\n");
754
Printf(s_init, "#endif\n");
755
Printf(s_init, " STANDARD_MODULE_PROPERTIES\n");
756
Printf(s_init, "};\n");
757
Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module);
760
Printf(s_init, "#ifdef COMPILE_DL_%s\n", cap_module);
762
Printf(s_init, "#ifdef __cplusplus\n");
763
Printf(s_init, "extern \"C\" {\n");
764
Printf(s_init, "#endif\n");
765
// We want to write "SWIGEXPORT ZEND_GET_MODULE(%s)" but ZEND_GET_MODULE
766
// in PHP5 has "extern "C" { ... }" around it so we can't do that.
767
Printf(s_init, "SWIGEXPORT zend_module_entry *get_module(void) { return &%s_module_entry; }\n", module);
768
Printf(s_init, "#ifdef __cplusplus\n");
769
Printf(s_init, "}\n");
770
Printf(s_init, "#endif\n\n");
773
Printf(s_init, "#endif\n\n");
706
776
/* We have to register the constants before they are (possibly) used
707
777
* by the pointer typemaps. This all needs re-arranging really as
708
778
* things are being called in the wrong order
711
Printf(s_init,"#define SWIG_php_minit PHP_MINIT_FUNCTION(%s)\n", module);
780
Printf(s_init, "#define SWIG_php_minit PHP_MINIT_FUNCTION(%s)\n", module);
713
782
/* Emit all of the code */
714
783
Language::top(n);
716
SwigPHP_emit_resource_registrations();
785
SwigPHP_emit_resource_registrations();
717
786
// Printv(s_init,s_resourcetypes,NIL);
718
787
/* We need this after all classes written out by ::top */
719
Printf(s_oinit, "CG(active_class_entry) = NULL;\n");
788
Printf(s_oinit, "CG(active_class_entry) = NULL;\n");
720
789
Printf(s_oinit, "/* end oinit subsection */\n");
721
790
Printf(s_init, "%s\n", s_oinit);
723
792
/* Constants generated during top call */
724
// But save them for RINIT
725
793
Printf(s_cinit, "/* end cinit subsection */\n");
794
Printf(s_init, "%s\n", s_cinit);
798
Printf(s_init, " return SUCCESS;\n");
799
Printf(s_init, "}\n\n");
801
// Now do REQUEST init which holds any user specified %rinit, and also vinit
802
Printf(s_init, "PHP_RINIT_FUNCTION(%s)\n{\n", module);
803
Printf(s_init, "%s\n", r_init);
727
805
/* finish our init section which will have been used by class wrappers */
728
806
Printf(s_vinit, "/* end vinit subsection */\n");
730
Printf(s_init, " return SUCCESS;\n");
731
Printf(s_init,"}\n");
733
// Now do REQUEST init which holds cinit and vinit
734
Printf(s_init,"PHP_RINIT_FUNCTION(%s)\n{\n",module);
735
Printf(s_init,"%s\n",r_init);
736
Printf(s_init,"%s\n",s_cinit);
740
807
Printf(s_init, "%s\n", s_vinit);
744
Printf(s_init," return SUCCESS;\n");
745
Printf(s_init,"}\n");
748
Printf(s_init,"PHP_MSHUTDOWN_FUNCTION(%s)\n{\n",module);
749
Printf(s_init,"%s\n",s_shutdown);
750
Printf(s_init," return SUCCESS;\n");
751
Printf(s_init,"}\n");
753
Printf(s_init,"PHP_RSHUTDOWN_FUNCTION(%s)\n{\n",module);
754
Printf(s_init,"%s\n",r_shutdown);
755
Printf(s_init," return SUCCESS;\n");
756
Printf(s_init,"}\n");
759
Printf(s_init,"PHP_MINFO_FUNCTION(%s)\n{\n",module);
760
Printf(s_init,"%s", pragma_phpinfo);
761
Printf(s_init,"}\n");
762
Printf(s_init,"/* end init section */\n");
764
Printf(f_h, "#endif /* PHP_%s_H */\n", cap_module);
811
Printf(s_init, " return SUCCESS;\n");
812
Printf(s_init, "}\n\n");
814
Printf(s_init, "PHP_MSHUTDOWN_FUNCTION(%s)\n{\n", module);
815
Printf(s_init, "%s\n", s_shutdown);
816
Printf(s_init, " return SUCCESS;\n");
817
Printf(s_init, "}\n\n");
819
Printf(s_init, "PHP_RSHUTDOWN_FUNCTION(%s)\n{\n", module);
820
Printf(s_init, "%s\n", r_shutdown);
821
Printf(s_init, " return SUCCESS;\n");
822
Printf(s_init, "}\n\n");
824
Printf(s_init, "PHP_MINFO_FUNCTION(%s)\n{\n", module);
825
Printf(s_init, "%s", pragma_phpinfo);
826
Printf(s_init, "}\n");
827
Printf(s_init, "/* end init section */\n");
829
Printf(f_h, "#endif /* PHP_%s_H */\n", cap_module);
768
Printf(s_header, "%s\n\n",all_cs_entry);
769
Printf(s_header, "%s {NULL, NULL, NULL}\n};\n\n",s_entry);
770
Printf(s_header, "zend_module_entry %s_module_entry = {\n", module );
771
Printf(s_header, "#if ZEND_MODULE_API_NO > 20010900\n" );
772
Printf(s_header, " STANDARD_MODULE_HEADER,\n");
773
Printf(s_header, "#endif\n");
774
Printf(s_header, " \"%s\",\n", module);
775
Printf(s_header, " %s_functions,\n", module);
776
Printf(s_header, " PHP_MINIT(%s),\n", module);
777
Printf(s_header, " PHP_MSHUTDOWN(%s),\n", module);
778
Printf(s_header, " PHP_RINIT(%s),\n", module);
779
Printf(s_header, " PHP_RSHUTDOWN(%s),\n", module);
780
Printf(s_header, " PHP_MINFO(%s),\n",module);
781
Printf(s_header, "#if ZEND_MODULE_API_NO > 20010900\n");
782
Printf(s_header, " NO_VERSION_YET,\n");
783
Printf(s_header, "#endif\n");
784
Printf(s_header, " STANDARD_MODULE_PROPERTIES\n");
785
Printf(s_header, "};\nzend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n",module);
787
String *type_table = NewString("");
788
SwigType_emit_type_table(f_runtime,type_table);
789
Printf(s_header,"%s",type_table);
833
String *type_table = NewStringEmpty();
834
SwigType_emit_type_table(f_runtime, type_table);
835
Printf(s_header, "%s", type_table);
790
836
Delete(type_table);
792
838
/* Oh dear, more things being called in the wrong order. This whole
793
839
* function really needs totally redoing.
796
842
Printf(s_header, "/* end header section */\n");
797
843
Printf(s_wrappers, "/* end wrapper section */\n");
798
844
Printf(s_vdecl, "/* end vdecl subsection */\n");
800
Printv(f_runtime, s_header, s_vdecl, s_wrappers, s_init, NIL);
846
Printv(f_runtime, s_header, s_vdecl, s_wrappers, NIL);
847
Printv(f_runtime, all_cs_entry, "\n\n", s_entry, "{NULL, NULL, NULL}\n};\n\n", NIL);
848
Printv(f_runtime, s_init, NIL);
801
849
Delete(s_header);
802
850
Delete(s_wrappers);
853
Delete(all_cs_entry);
805
855
Close(f_runtime);
806
Printf(f_phpcode, "%s\n%s\n?>\n", pragma_incl, pragma_code);
857
Printf(f_phpcode, "%s\n%s\n", pragma_incl, pragma_code);
858
if (s_fakeoowrappers) {
859
Printf(f_phpcode, "abstract class %s {", Len(prefix) ? prefix : module);
860
Printf(f_phpcode, "%s", s_fakeoowrappers);
861
Printf(f_phpcode, "}\n\n");
862
Delete(s_fakeoowrappers);
863
s_fakeoowrappers = NULL;
865
Printf(f_phpcode, "%s\n?>\n", s_phpclasses);
810
869
create_extra_files(outfile);
812
else if( gen_make ) {
870
} else if (gen_make) {
813
871
create_simple_make();
819
/* Just need to append function names to function table to register with
877
/* Just need to append function names to function table to register with PHP. */
823
878
void create_command(String *cname, String *iname) {
879
// This is for the single main function_entry record
880
if (shadow && php_version == 4) {
881
if (wrapperType != standard)
825
884
Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", iname);
827
// This is for the single main function_entry record
829
Printf(cs_entry," ZEND_NAMED_FE(%(lower)s,%s, NULL)\n", cname,iname );
886
Printf(cs_entry, " ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname);
831
Printf(s_entry," ZEND_NAMED_FE(%(lower)s,%s, NULL)\n", cname,iname );
888
Printf(s_entry, " ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname);
834
892
/* ------------------------------------------------------------
835
893
* dispatchFunction()
836
894
* ------------------------------------------------------------ */
892
946
* functionWrapper()
893
947
* ------------------------------------------------------------ */
949
/* Helper method for PHP::functionWrapper */
950
bool is_class(SwigType *t) {
951
Node *n = classLookup(t);
953
String *r = Getattr(n, "php:proxy"); // Set by classDeclaration()
955
r = Getattr(n, "sym:name"); // Not seen by classDeclaration yet, but this is the name
895
962
virtual int functionWrapper(Node *n) {
896
String *name = GetChar(n,"name");
897
String *iname = GetChar(n,"sym:name");
898
SwigType *d = Getattr(n,"type");
899
ParmList *l = Getattr(n,"parms");
963
String *name = GetChar(n, "name");
964
String *iname = GetChar(n, "sym:name");
965
SwigType *d = Getattr(n, "type");
966
ParmList *l = Getattr(n, "parms");
900
967
String *nodeType = Getattr(n, "nodeType");
901
int newobject = GetFlag(n,"feature:new");
968
int newobject = GetFlag(n, "feature:new");
910
bool mvr=(shadow && wrapperType == membervar);
911
bool mvrset=(mvr && (Strcmp(iname, Swig_name_set(Swig_name_member(shadow_classname, name)))==0) );
974
bool mvr = (shadow && php_version == 4 && wrapperType == membervar);
975
bool mvrset = (mvr && (Strcmp(iname, Swig_name_set(Swig_name_member(shadow_classname, name))) == 0));
914
978
int overloaded = 0;
915
979
String *overname = 0;
917
int destructor = ( Cmp(nodeType, "destructor") == 0 );
919
// We only generate the Zend List Destructor. Have
920
// Zend manage the reference counting.
981
if (Cmp(nodeType, "destructor") == 0) {
982
// We just generate the Zend List Destructor and let Zend manage the
983
// reference counting. There's no explicit destructor, but the user can
984
// just do `$obj = null;' to remove a reference to an object.
921
985
return CreateZendListDestructor(n);
924
//If a script accessible destructor is desired/required, this code needs to be
925
//put back into play.
926
// Then we modify the wrap_action so it nulls out the self variable.
927
String *del = Getattr(n,"wrap:action");
928
Printf(del,"\nRETVAL_NULL();\n");
929
Setattr(n,"wrap:action",del);
933
987
// Test for overloading;
934
if (Getattr(n,"sym:overloaded")) {
988
if (Getattr(n, "sym:overloaded")) {
936
overname = Getattr(n,"sym:overname");
990
overname = Getattr(n, "sym:overname");
938
if (!addSymbol(iname,n))
992
if (!addSymbol(iname, n))
942
strcpy(wname,Char(Swig_name_wrapper(iname)));
996
wname = Swig_name_wrapper(iname);
944
strcat(wname,Char(overname));
998
Printf(wname, "%s", overname);
947
// if shadow and variable wrapper we want to snag the main contents
948
// of this function to stick in to the property handler....
1000
// if PHP4, shadow and variable wrapper we want to snag the main contents
1001
// of this function to stick in to the property handler...
950
1003
String *php_function_name = NewString(iname);
951
if( Strcmp( iname, Swig_name_set(Swig_name_member(shadow_classname, name)))== 0) {
952
Setattr(shadow_set_vars, php_function_name, name);
1004
if (Strcmp(iname, Swig_name_set(Swig_name_member(shadow_classname, name))) == 0) {
1005
Setattr(shadow_set_vars, php_function_name, name);
954
if( Strcmp(iname, Swig_name_get(Swig_name_member(shadow_classname, name))) == 0) {
955
Setattr(shadow_get_vars, php_function_name, name);
1007
if (Strcmp(iname, Swig_name_get(Swig_name_member(shadow_classname, name))) == 0) {
1008
Setattr(shadow_get_vars, php_function_name, name);
958
1011
Delete(php_function_name);
964
String *outarg = NewString("");
965
String *cleanup = NewString("");
967
if (mvr) { // do prop[gs]et header
1017
String *outarg = NewStringEmpty();
1018
String *cleanup = NewStringEmpty();
1020
if (mvr) { // do prop[gs]et header
969
Printf(f->def, "static int _wrap_%s(zend_property_reference *property_reference, pval *value) {\n",iname);
972
Printf(f->def, "static pval _wrap_%s(zend_property_reference *property_reference) {\n",iname);
1022
Printf(f->def, "static int _wrap_%s(zend_property_reference *property_reference, pval *value) {\n", iname);
1024
Printf(f->def, "static pval _wrap_%s(zend_property_reference *property_reference) {\n", iname);
975
1027
// regular header
976
// We don't issue these for overloaded functions.
977
// destructors when using shadows.
978
// And for static member variables
980
!(destructor && shadow) &&
981
wrapperType != staticmembervar ) {
982
create_command( iname, wname );
1028
// Not issued for overloaded functions or static member variables.
1029
if (!overloaded && wrapperType != staticmembervar) {
1030
create_command(iname, wname);
984
Printv(f->def, "ZEND_NAMED_FUNCTION(" , wname, ") {\n", NIL);
1032
Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL);
987
1035
emit_args(d, l, f);
988
1036
/* Attach standard typemaps */
990
emit_attach_parmmaps(l,f);
1038
emit_attach_parmmaps(l, f);
992
1040
// wrap:parms is used by overload resolution.
993
Setattr(n,"wrap:parms",l);
1041
Setattr(n, "wrap:parms", l);
995
1043
int num_arguments = emit_num_arguments(l);
996
int num_required = emit_num_required(l);
1044
int num_required = emit_num_required(l);
997
1045
numopt = num_arguments - num_required;
999
int has_this_ptr = (wrapperType==memberfn)?shadow:0;
1001
sprintf(args, "%s[%d]", "zval **args", num_arguments-has_this_ptr);
1003
Wrapper_add_local(f, "args",args);
1005
// This generated code may be called
1047
int has_this_ptr = (wrapperType == memberfn && shadow && php_version == 4);
1049
if (num_arguments - has_this_ptr > 0) {
1050
String *args = NewStringf("zval **args[%d]", num_arguments - has_this_ptr);
1051
Wrapper_add_local(f, "args", args);
1055
// This generated code may be called:
1006
1056
// 1) as an object method, or
1007
1057
// 2) as a class-method/function (without a "this_ptr")
1008
1058
// Option (1) has "this_ptr" for "this", option (2) needs it as
1016
1066
Printf(f->code, "/* This function uses a this_ptr*/\n");
1018
1068
if (native_constructor) {
1019
if (native_constructor==NATIVE_CONSTRUCTOR) {
1020
Printf(f->code, "/* NATIVE Constructor */\n");
1023
Printf(f->code, "/* ALTERNATIVE Constructor */\n");
1069
if (native_constructor == NATIVE_CONSTRUCTOR) {
1070
Printf(f->code, "/* NATIVE Constructor */\n");
1072
Printf(f->code, "/* ALTERNATIVE Constructor */\n");
1027
if (mvr && ! mvrset) {
1076
if (mvr && !mvrset) {
1028
1077
Wrapper_add_local(f, "_return_value", "zval _return_value");
1029
1078
Wrapper_add_local(f, "return_value", "zval *return_value=&_return_value");
1032
if(numopt > 0) { // membervariable wrappers do not have optional args
1081
if (numopt > 0) { // membervariable wrappers do not have optional args
1033
1082
Wrapper_add_local(f, "arg_count", "int arg_count");
1034
Printf(f->code,"arg_count = ZEND_NUM_ARGS();\n");
1035
Printf(f->code,"if(arg_count<%d || arg_count>%d)\n",num_required, num_arguments);
1036
Printf(f->code,"\tWRONG_PARAM_COUNT;\n\n");
1039
/* Verified args, retrieve them... */
1040
Printf(f->code,"if(zend_get_parameters_array_ex(arg_count,args)!=SUCCESS)\n");
1041
Printf(f->code,"\t\tWRONG_PARAM_COUNT;\n\n");
1083
Printf(f->code, "arg_count = ZEND_NUM_ARGS();\n");
1084
Printf(f->code, "if(arg_count<%d || arg_count>%d ||\n", num_required, num_arguments);
1085
Printf(f->code, " zend_get_parameters_array_ex(arg_count,args)!=SUCCESS)\n");
1086
Printf(f->code, "\tWRONG_PARAM_COUNT;\n\n");
1043
1087
} else if (!mvr) {
1044
Printf(f->code, "if(((ZEND_NUM_ARGS() )!= %d) || (zend_get_parameters_array_ex(%d, args)",
1045
num_arguments-has_this_ptr, num_arguments-has_this_ptr);
1046
Printf(f->code, "!= SUCCESS)) {\n");
1047
Printf(f->code, "WRONG_PARAM_COUNT;\n}\n\n");
1088
int num = num_arguments - has_this_ptr;
1090
Printf(f->code, "if(ZEND_NUM_ARGS() != 0) {\n");
1092
Printf(f->code, "if(ZEND_NUM_ARGS() != %d || zend_get_parameters_array_ex(%d, args) != SUCCESS) {\n", num, num);
1094
Printf(f->code, "WRONG_PARAM_COUNT;\n}\n\n");
1050
1097
/* Now convert from php to C variables */
1051
// At this point, argcount if used is the number of deliberatly passed args
1098
// At this point, argcount if used is the number of deliberately passed args
1052
1099
// not including this_ptr even if it is used.
1053
1100
// It means error messages may be out by argbase with error
1054
// reports. We can either take argbase into account when raising
1055
// errors, or find a better way of dealing with _thisptr
1101
// reports. We can either take argbase into account when raising
1102
// errors, or find a better way of dealing with _thisptr.
1056
1103
// I would like, if objects are wrapped, to assume _thisptr is always
1057
// _this and the and not the first argument
1058
// This may mean looking at Lang::memberfunctionhandler
1104
// _this and not the first argument.
1105
// This may mean looking at Language::memberfunctionHandler
1060
1107
for (i = 0, p = l; i < num_arguments; i++) {
1061
1110
/* Skip ignored arguments */
1062
1111
//while (Getattr(p,"tmap:ignore")) { p = Getattr(p,"tmap:ignore:next");}
1063
while (checkAttribute(p,"tmap:in:numinputs","0")) {
1064
p = Getattr(p,"tmap:in:next");
1067
SwigType *pt = Getattr(p,"type");
1069
if (mvr) { // do we assert that numargs=2, that i<2
1071
sprintf(source,"&(property_reference->object)");
1074
sprintf(source,"&value");
1077
if (i==0 && has_this_ptr ) {
1078
sprintf(source,"&this_ptr");
1080
sprintf(source, "args[%d]", i-has_this_ptr);
1084
String *ln = Getattr(p,"lname");
1085
sprintf(argnum, "%d", i+1);
1087
/* Check if optional */
1089
if(i>= (num_required)) {
1090
Printf(f->code,"\tif(arg_count > %d) {\n", i);
1093
if ((tm = Getattr(p,"tmap:in"))) {
1094
Replaceall(tm,"$source",source);
1095
Replaceall(tm,"$target",ln);
1096
Replaceall(tm,"$input", source);
1097
Setattr(p,"emit:input", source);
1098
Printf(f->code,"%s\n",tm);
1099
p = Getattr(p,"tmap:in:next");
1100
if (i >= num_required) {
1101
Printf(f->code,"}\n");
1105
Printf(stderr,"%s : Line %d, Unable to use type %s as a function argument.\n",
1106
input_file, line_number, SwigType_str(pt,0));
1108
if (i>= num_required) {
1109
Printf(f->code,"\t}\n");
1112
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
1113
p = Getattr(p, "tmap:in:next");
1116
SwigType *pt = Getattr(p, "type");
1118
if (mvr) { // do we assert that numargs=2, that i<2
1120
source = NewString("&(property_reference->object)");
1122
source = NewString("&value");
1125
if (i == 0 && has_this_ptr) {
1126
source = NewString("&this_ptr");
1128
source = NewStringf("args[%d]", i - has_this_ptr);
1132
String *ln = Getattr(p, "lname");
1134
/* Check if optional */
1135
if (i >= num_required) {
1136
Printf(f->code, "\tif(arg_count > %d) {\n", i);
1139
if ((tm = Getattr(p, "tmap:in"))) {
1140
Replaceall(tm, "$source", source);
1141
Replaceall(tm, "$target", ln);
1142
Replaceall(tm, "$input", source);
1143
Setattr(p, "emit:input", source);
1144
Printf(f->code, "%s\n", tm);
1145
if (i == 0 && HashGetAttr(p, k_self)) {
1146
Printf(f->code, "\tif(!arg1) SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");\n");
1148
p = Getattr(p, "tmap:in:next");
1149
if (i >= num_required) {
1150
Printf(f->code, "}\n");
1154
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
1156
if (i >= num_required) {
1157
Printf(f->code, "\t}\n");
1113
1162
/* Insert constraint checking code */
1114
1163
for (p = l; p;) {
1115
if ((tm = Getattr(p,"tmap:check"))) {
1116
Replaceall(tm,"$target",Getattr(p,"lname"));
1117
Printv(f->code,tm,"\n",NIL);
1118
p = Getattr(p,"tmap:check:next");
1164
if ((tm = Getattr(p, "tmap:check"))) {
1165
Replaceall(tm, "$target", Getattr(p, "lname"));
1166
Printv(f->code, tm, "\n", NIL);
1167
p = Getattr(p, "tmap:check:next");
1124
1173
/* Insert cleanup code */
1125
1174
for (i = 0, p = l; p; i++) {
1126
if ((tm = Getattr(p,"tmap:freearg"))) {
1127
Replaceall(tm,"$source",Getattr(p,"lname"));
1128
Printv(cleanup,tm,"\n",NIL);
1129
p = Getattr(p,"tmap:freearg:next");
1175
if ((tm = Getattr(p, "tmap:freearg"))) {
1176
Replaceall(tm, "$source", Getattr(p, "lname"));
1177
Printv(cleanup, tm, "\n", NIL);
1178
p = Getattr(p, "tmap:freearg:next");
1135
1184
/* Insert argument output code */
1136
for (i=0,p = l; p;i++) {
1137
if ((tm = Getattr(p,"tmap:argout"))) {
1138
Replaceall(tm,"$source",Getattr(p,"lname"));
1139
// Replaceall(tm,"$input",Getattr(p,"lname"));
1140
Replaceall(tm,"$target","return_value");
1141
Replaceall(tm,"$result","return_value");
1142
Replaceall(tm,"$arg", Getattr(p,"emit:input"));
1143
Replaceall(tm,"$input", Getattr(p,"emit:input"));
1144
Printv(outarg,tm,"\n",NIL);
1145
p = Getattr(p,"tmap:argout:next");
1185
for (i = 0, p = l; p; i++) {
1186
if ((tm = Getattr(p, "tmap:argout"))) {
1187
Replaceall(tm, "$source", Getattr(p, "lname"));
1188
// Replaceall(tm,"$input",Getattr(p,"lname"));
1189
Replaceall(tm, "$target", "return_value");
1190
Replaceall(tm, "$result", "return_value");
1191
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
1192
Replaceall(tm, "$input", Getattr(p, "emit:input"));
1193
Printv(outarg, tm, "\n", NIL);
1194
p = Getattr(p, "tmap:argout:next");
1151
/* emit function call*/
1154
if((tm = Swig_typemap_lookup_new("out",n,"result",0))) {
1200
/* emit function call */
1203
if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) {
1155
1204
Replaceall(tm, "$input", "result");
1156
1205
Replaceall(tm, "$source", "result");
1157
1206
Replaceall(tm, "$target", "return_value");
1158
1207
Replaceall(tm, "$result", "return_value");
1159
Replaceall(tm,"$owner", newobject ? "1" : "0");
1208
Replaceall(tm, "$owner", newobject ? "1" : "0");
1160
1209
Printf(f->code, "%s\n", tm);
1161
1210
// are we returning a wrapable object?
1162
// I don't know if this test is comlete, I nicked it
1163
if(is_shadow(d) && (SwigType_type(d) != T_ARRAY)) {
1164
Printf(f->code,"/* Wrap this return value */\n");
1165
if (native_constructor==NATIVE_CONSTRUCTOR) {
1166
Printf(f->code, "if (this_ptr) {\n");
1167
Printf(f->code, "/* NATIVE Constructor, use this_ptr */\n");
1168
Printf(f->code, "zval *_cPtr; MAKE_STD_ZVAL(_cPtr);\n");
1169
Printf(f->code, "*_cPtr = *return_value;\n");
1170
Printf(f->code, "INIT_ZVAL(*return_value);\n");
1171
Printf(f->code, "add_property_zval(this_ptr,\"_cPtr\",_cPtr);\n");
1172
Printf(f->code, "} else if (! this_ptr) ");
1174
{ // THIS CODE only really needs writing out if the object to be returned
1175
// Is being shadow-wrap-thingied
1176
Printf(f->code, "{\n/* ALTERNATIVE Constructor, make an object wrapper */\n");
1178
String *shadowrettype = NewString("");
1179
SwigToPhpType(d, iname, shadowrettype, shadow);
1181
Printf(f->code,"zval *obj, *_cPtr;\n");
1182
Printf(f->code,"MAKE_STD_ZVAL(obj);\n");
1183
Printf(f->code,"MAKE_STD_ZVAL(_cPtr);\n");
1184
Printf(f->code,"*_cPtr = *return_value;\n");
1185
Printf(f->code,"INIT_ZVAL(*return_value);\n");
1188
Printf(f->code,"*return_value=*_cPtr;\n");
1190
Printf(f->code,"object_init_ex(obj,ptr_ce_swig_%s);\n",shadowrettype);
1191
Printf(f->code,"add_property_zval(obj,\"_cPtr\",_cPtr);\n");
1192
Printf(f->code,"*return_value=*obj;\n");
1195
Printf(f->code, "}\n");
1197
} // end of if-shadow lark
1211
// I don't know if this test is complete, I nicked it
1212
if (is_shadow(d) && (SwigType_type(d) != T_ARRAY)) {
1213
Printf(f->code, "/* Wrap this return value */\n");
1214
if (native_constructor == NATIVE_CONSTRUCTOR) {
1215
Printf(f->code, "if (this_ptr) {\n");
1216
Printf(f->code, "/* NATIVE Constructor, use this_ptr */\n");
1217
Printf(f->code, "zval *_cPtr; MAKE_STD_ZVAL(_cPtr);\n");
1218
Printf(f->code, "*_cPtr = *return_value;\n");
1219
Printf(f->code, "INIT_ZVAL(*return_value);\n");
1220
Printf(f->code, "add_property_zval(this_ptr,\"" SWIG_PTR "\",_cPtr);\n");
1221
Printf(f->code, "} else if (! this_ptr) ");
1223
{ // THIS CODE only really needs writing out if the object to be returned
1224
// Is being shadow-wrap-thingied
1225
Printf(f->code, "{\n/* ALTERNATIVE Constructor, make an object wrapper */\n");
1227
String *shadowrettype = NewStringEmpty();
1228
SwigToPhpType(d, iname, shadowrettype, (shadow && php_version == 4));
1230
Printf(f->code, "zval *obj, *_cPtr;\n");
1231
Printf(f->code, "MAKE_STD_ZVAL(obj);\n");
1232
Printf(f->code, "MAKE_STD_ZVAL(_cPtr);\n");
1233
Printf(f->code, "*_cPtr = *return_value;\n");
1234
Printf(f->code, "INIT_ZVAL(*return_value);\n");
1236
if (shadow && php_version == 4) {
1237
Printf(f->code, "object_init_ex(obj,ptr_ce_swig_%s);\n", shadowrettype);
1238
Printf(f->code, "add_property_zval(obj,\"" SWIG_PTR "\",_cPtr);\n");
1239
Printf(f->code, "*return_value=*obj;\n");
1241
Printf(f->code, "*return_value=*_cPtr;\n");
1243
Printf(f->code, "}\n");
1245
} // end of if-shadow lark
1199
Printf(stderr,"%s: Line %d, Unable to use return type %s in function %s.\n",
1200
input_file, line_number, SwigType_str(d,0), name);
1204
Printv(f->code,outarg,NIL);
1208
Printv(f->code,cleanup,NIL);
1211
// Whats this bit for?
1212
if((tm = Swig_typemap_lookup_new("ret",n,"result",0))) {
1213
Printf(f->code,"%s\n", tm);
1247
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
1251
Printv(f->code, outarg, NIL);
1255
Printv(f->code, cleanup, NIL);
1257
// What's this bit for?
1258
if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) {
1259
Printf(f->code, "%s\n", tm);
1218
Printf(f->code,"return _return_value;\n");
1221
Printf(f->code,"return SUCCESS;\n");
1225
Printf(f->code,"return;\n");
1264
Printf(f->code, "return _return_value;\n");
1266
Printf(f->code, "return SUCCESS;\n");
1269
Printf(f->code, "return;\n");
1228
1272
/* Error handling code */
1229
Printf(f->code,"fail:\n");
1230
Printv(f->code,cleanup,NIL);
1231
Printv(f->code,"zend_error(ErrorCode(),ErrorMsg());",NIL);
1233
Printf(f->code, "}\n");
1235
// These were cribbed from python.cxx
1236
Replaceall(f->code,"$cleanup",cleanup);
1237
Replaceall(f->code,"$symname",iname);
1239
Wrapper_print(f,s_wrappers);
1273
Printf(f->code, "fail:\n");
1274
Printv(f->code, cleanup, NIL);
1275
Printv(f->code, "zend_error(SWIG_ErrorCode(),SWIG_ErrorMsg());", NIL);
1277
Printf(f->code, "}\n");
1279
Replaceall(f->code, "$cleanup", cleanup);
1280
Replaceall(f->code, "$symname", iname);
1282
Wrapper_print(f, s_wrappers);
1241
1284
// wrap:name is used by overload resolution
1242
Setattr(n,"wrap:name",wname);
1243
if (overloaded && !Getattr(n,"sym:nextSibling")) {
1285
Setattr(n, "wrap:name", wname);
1286
if (overloaded && !Getattr(n, "sym:nextSibling")) {
1244
1287
dispatchFunction(n);
1293
if (!(shadow && php_version == 5))
1296
// Handle getters and setters.
1297
if (wrapperType == membervar) {
1298
const char *p = Char(iname);
1299
if (strlen(p) > 4) {
1301
String *varname = Getattr(n, "membervariableHandler:sym:name");
1302
if (strcmp(p, "_get") == 0) {
1303
Setattr(shadow_get_vars, varname, iname);
1304
} else if (strcmp(p, "_set") == 0) {
1305
Setattr(shadow_set_vars, varname, iname);
1309
// Only look at non-overloaded methods and the last entry in each overload
1310
// chain (we check the last so that wrap:parms and wrap:name have been set
1312
if (overloaded && Getattr(n, "sym:nextSibling") != 0)
1316
s_oowrappers = NewStringEmpty();
1317
if (newobject || wrapperType == memberfn || wrapperType == staticmemberfn || wrapperType == standard) {
1318
bool handle_as_overload = false;
1320
String **arg_values;
1321
bool *arg_case = NULL;
1322
// Method or static method or plain function.
1323
const char *methodname = 0;
1324
String *output = s_oowrappers;
1326
class_has_ctor = true;
1327
methodname = "__construct";
1328
} else if (wrapperType == memberfn) {
1329
methodname = Char(Getattr(n, "memberfunctionHandler:sym:name"));
1330
} else if (wrapperType == staticmemberfn) {
1331
methodname = Char(Getattr(n, "staticmemberfunctionHandler:sym:name"));
1332
} else { // wrapperType == standard
1333
methodname = Char(iname);
1334
if (!s_fakeoowrappers)
1335
s_fakeoowrappers = NewStringEmpty();
1336
output = s_fakeoowrappers;
1339
bool really_overloaded = overloaded ? true : false;
1340
int min_num_of_arguments = emit_num_required(l);
1341
int max_num_of_arguments = emit_num_arguments(l);
1342
// For a function with default arguments, we end up with the fullest
1343
// parmlist in full_parmlist.
1344
ParmList *full_parmlist = l;
1345
Hash *ret_types = NewHash();
1346
Setattr(ret_types, d, d);
1349
// Look at all the overloaded versions of this method in turn to
1350
// decide if it's really an overloaded method, or just one where some
1351
// parameters have default values.
1352
Node *o = Getattr(n, "sym:overloaded");
1355
o = Getattr(o, "sym:nextSibling");
1359
SwigType *d2 = Getattr(o, "type");
1361
assert(constructor);
1362
} else if (!Getattr(ret_types, d2)) {
1363
Setattr(ret_types, d2, d2);
1366
ParmList *l2 = Getattr(o, "wrap:parms");
1367
int num_arguments = emit_num_arguments(l2);
1368
int num_required = emit_num_required(l2);
1369
if (num_required < min_num_of_arguments)
1370
min_num_of_arguments = num_required;
1372
if (num_arguments > max_num_of_arguments) {
1373
max_num_of_arguments = num_arguments;
1376
o = Getattr(o, "sym:nextSibling");
1379
o = Getattr(n, "sym:overloaded");
1382
o = Getattr(o, "sym:nextSibling");
1386
ParmList *l2 = Getattr(o, "wrap:parms");
1387
Parm *p = l, *p2 = l2;
1388
if (wrapperType == memberfn) {
1390
p2 = nextSibling(p2);
1393
if (Cmp(Getattr(p, "type"), Getattr(p2, "type")) != 0)
1395
if (Cmp(Getattr(p, "name"), Getattr(p2, "name")) != 0)
1397
String *value = Getattr(p, "value");
1398
String *value2 = Getattr(p2, "value");
1399
if (value && !value2)
1401
if (!value && value2)
1404
if (Cmp(value, value2) != 0)
1408
p2 = nextSibling(p2);
1412
// One parameter list is a prefix of the other, so check that all
1413
// remaining parameters of the longer list are optional.
1416
while (p && Getattr(p, "value"))
1420
o = Getattr(o, "sym:nextSibling");
1423
// This "overloaded method" is really just one with default args.
1424
really_overloaded = false;
1425
if (l != full_parmlist) {
1427
if (wrapperType == memberfn)
1432
arg_case = (bool *) malloc(max_num_of_arguments * sizeof(bool));
1434
/* FIXME: How should this be handled? The rest of SWIG just seems
1435
* to not bother checking for malloc failing! */
1436
fprintf(stderr, "Malloc failed!\n");
1439
for (int i = 0; i < max_num_of_arguments; ++i) {
1440
arg_case[i] = false;
1443
o = Getattr(n, "sym:overloaded");
1445
ParmList *l2 = Getattr(o, "wrap:parms");
1446
int num_arguments = emit_num_arguments(l2);
1447
int num_required = emit_num_required(l2);
1448
if (wrapperType == memberfn) {
1452
for (int i = num_required; i <= num_arguments; ++i) {
1455
o = Getattr(o, "sym:nextSibling");
1459
if (wrapperType == memberfn) {
1460
// Allow for the "this" pointer.
1461
--min_num_of_arguments;
1462
--max_num_of_arguments;
1465
arg_names = (String **) malloc(max_num_of_arguments * sizeof(String *));
1467
/* FIXME: How should this be handled? The rest of SWIG just seems
1468
* to not bother checking for malloc failing! */
1469
fprintf(stderr, "Malloc failed!\n");
1472
for (int i = 0; i < max_num_of_arguments; ++i) {
1473
arg_names[i] = NULL;
1476
arg_values = (String **) malloc(max_num_of_arguments * sizeof(String *));
1478
/* FIXME: How should this be handled? The rest of SWIG just seems
1479
* to not bother checking for malloc failing! */
1480
fprintf(stderr, "Malloc failed!\n");
1483
for (int i = 0; i < max_num_of_arguments; ++i) {
1484
arg_values[i] = NULL;
1489
o = Getattr(n, "sym:overloaded");
1495
Parm *p = Getattr(o, "wrap:parms");
1496
if (wrapperType == memberfn)
1499
assert(0 <= argno && argno < max_num_of_arguments);
1500
String *&pname = arg_names[argno];
1501
const char *pname_cstr = GetChar(p, "name");
1503
// Unnamed parameter, e.g. int foo(int);
1504
} else if (pname == NULL) {
1505
pname = NewString(pname_cstr);
1507
size_t len = strlen(pname_cstr);
1509
size_t len_pname = strlen(Char(pname));
1510
while (spc + len <= len_pname) {
1511
if (strncmp(pname_cstr, Char(pname) + spc, len) == 0) {
1512
char ch = ((char *) Char(pname))[spc + len];
1513
if (ch == '\0' || ch == ' ') {
1514
// Already have this pname_cstr.
1519
char *p = strchr(Char(pname) + spc, ' ');
1522
spc = (p + 4) - Char(pname);
1525
Printf(pname, " or_%s", pname_cstr);
1528
const char *value = GetChar(p, "value");
1530
/* Check that value is a valid constant in PHP (and adjust it if
1531
* necessary, or replace it with "?" if it's just not valid). */
1532
SwigType *type = Getattr(p, "type");
1533
switch (SwigType_type(type)) {
1535
if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0)
1539
int n = strtol(Char(value), &p, 0);
1555
(void) strtol(Char(value), &p, 0);
1566
(void) strtoul(Char(value), &p, 0);
1575
/* FIXME: strtod is locale dependent... */
1576
(void) strtod(Char(value), &p);
1587
if (Len(value) < 2) {
1588
// How can a string (including "" be less than 2 characters?)
1591
const char *v = Char(value);
1592
if (v[0] != '"' || v[Len(value) - 1] != '"')
1594
// Strings containing "$" require special handling, but we do that later.
1601
const char *v = value;
1603
// Handle "(void*)0", "(TYPE*)0", "(char*)NULL", etc.
1604
v += strcspn(v + 1, "*()") + 1;
1608
v += strspn(v, " \t");
1609
} while (*v == '*');
1611
v += strspn(v, " \t");
1616
if (strcmp(value, "NULL") == 0 || strcmp(value, "0") == 0 || strcmp(value, "0L") == 0) {
1625
if (!arg_values[argno]) {
1626
arg_values[argno] = NewString(value);
1627
} else if (Cmp(arg_values[argno], value) != 0) {
1628
// If a parameter has two different default values in
1629
// different overloaded forms of the function, we can't
1630
// set its default in PHP. Flag this by setting its
1632
Delete(arg_values[argno]);
1633
arg_values[argno] = NewString("?");
1639
if (!really_overloaded)
1641
o = Getattr(o, "sym:nextSibling");
1644
/* Clean up any parameters which haven't yet got names, or whose
1646
Hash *seen = NewHash();
1647
/* We need $this to refer to the current class, so can't allow it
1648
* to be used as a parameter. */
1649
Setattr(seen, "this", seen);
1650
/* We use $r to store the return value, so disallow that as a parameter
1651
* name in case the user uses the "call-time pass-by-reference" feature
1652
* (it's deprecated and off by default in PHP5 and even later PHP4
1653
* versions apparently, but we want to be maximally portable).
1655
Setattr(seen, "r", seen);
1657
for (int argno = 0; argno < max_num_of_arguments; ++argno) {
1658
String *&pname = arg_names[argno];
1660
Replaceall(pname, " ", "_");
1662
/* We get here if the SWIG .i file has "int foo(int);" */
1663
pname = NewStringEmpty();
1664
Printf(pname, "arg%d", argno + 1);
1666
// Check if we've already used this parameter name.
1667
while (Getattr(seen, pname)) {
1668
// Append "_" to clashing names until they stop clashing...
1671
Setattr(seen, Char(pname), seen);
1673
if (arg_values[argno] && Cmp(arg_values[argno], "?") == 0) {
1674
handle_as_overload = true;
1680
String *invoke = NewStringEmpty();
1681
String *prepare = NewStringEmpty();
1682
String *args = NewStringEmpty();
1684
if (!handle_as_overload && !(really_overloaded && max_num_of_arguments > min_num_of_arguments)) {
1685
Printf(invoke, "%s(", iname);
1686
if (wrapperType == memberfn) {
1687
Printf(invoke, "$this->%s", SWIG_PTR);
1689
for (int i = 0; i < max_num_of_arguments; ++i) {
1692
if (i || wrapperType == memberfn)
1693
Printf(invoke, ",");
1694
String *value = arg_values[i];
1696
const char *v = Char(value);
1698
/* In a PHP double quoted string, $ needs to be escaped as \$. */
1699
Replaceall(value, "$", "\\$");
1701
Printf(args, "$%s=%s", arg_names[i], value);
1703
Printf(args, "$%s", arg_names[i]);
1705
Printf(invoke, "$%s", arg_names[i]);
1707
Printf(invoke, ")");
1710
for (i = 0; i < min_num_of_arguments; ++i) {
1713
Printf(args, "$%s", arg_names[i]);
1715
String *invoke_args = NewStringEmpty();
1716
if (wrapperType == memberfn) {
1717
Printf(invoke_args, "$this->%s", SWIG_PTR);
1718
if (min_num_of_arguments > 0)
1719
Printf(invoke_args, ",");
1721
Printf(invoke_args, "%s", args);
1722
bool had_a_case = false;
1723
int last_handled_i = i - 1;
1724
for (; i < max_num_of_arguments; ++i) {
1727
const char *value = Char(arg_values[i]);
1728
bool non_php_default = (!value || strcmp(value, "?") == 0);
1729
if (non_php_default)
1731
Printf(args, "$%s=%s", arg_names[i], value);
1732
if (non_php_default) {
1734
Printf(prepare, "\t\tswitch (func_num_args()) {\n");
1737
Printf(prepare, "\t\t");
1738
while (last_handled_i < i) {
1739
Printf(prepare, "case %d: ", ++last_handled_i);
1741
if (Cmp(d, "void") != 0)
1742
Printf(prepare, "$r=");
1743
Printf(prepare, "%s(%s); break;\n", iname, invoke_args);
1745
if (i || wrapperType == memberfn)
1746
Printf(invoke_args, ",");
1747
Printf(invoke_args, "$%s", arg_names[i]);
1749
Printf(prepare, "\t\t");
1751
Printf(prepare, "default: ");
1752
if (Cmp(d, "void") != 0)
1753
Printf(prepare, "$r=");
1754
Printf(prepare, "%s(%s);\n", iname, invoke_args);
1756
Printf(prepare, "\t\t}\n");
1757
Delete(invoke_args);
1758
Printf(invoke, "$r");
1761
Printf(output, "\n");
1762
if (wrapperType == memberfn || newobject) {
1763
Printf(output, "\tfunction %s(%s) {\n", methodname, args);
1764
// We don't need this code if the wrapped class has a copy ctor
1765
// since the flat function new_CLASSNAME will handle it for us.
1766
if (newobject && !Getattr(current_class, "allocate:copy_constructor")) {
1767
SwigType *t = Getattr(current_class, "classtype");
1768
String *mangled_type = SwigType_manglestr(SwigType_ltype(t));
1769
Printf(s_oowrappers, "\t\tif (is_resource($%s) && get_resource_type($%s) == \"_p%s\") {\n", arg_names[0], arg_names[0], mangled_type);
1770
Printf(s_oowrappers, "\t\t\t$this->%s=$%s;\n", SWIG_PTR, arg_names[0]);
1771
Printf(s_oowrappers, "\t\t\treturn;\n");
1772
Printf(s_oowrappers, "\t\t}\n");
1775
Printf(output, "\tstatic function %s(%s) {\n", methodname, args);
1780
for (int i = 0; i < max_num_of_arguments; ++i) {
1781
Delete(arg_names[i]);
1786
Printf(output, "%s", prepare);
1788
Printf(output, "\t\t$this->%s=%s;\n", SWIG_PTR, invoke);
1789
} else if (Cmp(d, "void") == 0) {
1790
if (Cmp(invoke, "$r") != 0)
1791
Printf(output, "\t\t%s;\n", invoke);
1792
} else if (is_class(d)) {
1793
if (Cmp(invoke, "$r") != 0)
1794
Printf(output, "\t\t$r=%s;\n", invoke);
1795
if (Len(ret_types) == 1) {
1796
Printf(output, "\t\treturn is_resource($r) ? new %s%s($r) : $r;\n", prefix, Getattr(classLookup(d), "sym:name"));
1798
Printf(output, "\t\tif (!is_resource($r)) return $r;\n");
1799
Printf(output, "\t\tswitch (get_resource_type($r)) {\n");
1800
Iterator i = First(ret_types);
1802
SwigType *ret_type = i.item;
1804
Printf(output, "\t\t");
1805
String *mangled = NewString("_p");
1806
Printf(mangled, "%s", SwigType_manglestr(ret_type));
1807
Node *class_node = Getattr(zend_types, mangled);
1809
Printf(output, "case \"%s\": ", mangled);
1811
Printf(output, "default: ", mangled);
1813
const char *classname = GetChar(class_node, "sym:name");
1815
classname = GetChar(class_node, "name");
1816
Printf(output, "return new %s%s($r);\n", prefix, classname);
1819
Printf(output, "\t\t}\n");
1822
Printf(output, "\t\treturn %s;\n", invoke);
1824
Printf(output, "\t}\n");
1247
1829
return SWIG_OK;
1250
1832
/* ------------------------------------------------------------
1251
1833
* globalvariableHandler()
1252
1834
* ------------------------------------------------------------ */
1254
1836
virtual int globalvariableHandler(Node *n) {
1255
char *name = GetChar(n,"name");
1256
char *iname = GetChar(n,"sym:name");
1257
SwigType *t = Getattr(n,"type");
1837
char *name = GetChar(n, "name");
1838
char *iname = GetChar(n, "sym:name");
1839
SwigType *t = Getattr(n, "type");
1260
1842
/* First do the wrappers such as name_set(), name_get()
1261
1843
* as provided by the baseclass's implementation of variableWrapper
1263
if (Language::globalvariableHandler(n) == SWIG_NOWRAP ) {
1845
if (Language::globalvariableHandler(n) == SWIG_NOWRAP) {
1264
1846
return SWIG_NOWRAP;
1267
if (!addSymbol(iname,n))
1849
if (!addSymbol(iname, n))
1268
1850
return SWIG_ERROR;
1270
1852
SwigType_remember(t);
1272
1854
/* First link C variables to PHP */
1274
1856
tm = Swig_typemap_lookup_new("varinit", n, name, 0);
1276
1858
Replaceall(tm, "$target", name);
1277
1859
Printf(s_vinit, "%s\n", tm);
1279
Printf(stderr,"%s: Line %d, Unable to link with type %s\n",
1280
input_file, line_number, SwigType_str(t,0), name);
1861
Printf(stderr, "%s: Line %d, Unable to link with type %s\n", input_file, line_number, SwigType_str(t, 0), name);
1283
1864
/* Now generate PHP -> C sync blocks */
1285
tm = Swig_typemap_lookup_new("varin", n, name, 0);
1287
Replaceall(tm, "$symname", iname);
1288
Printf(f_c->code, "%s\n", tm);
1290
Printf(stderr,"%s: Line %d, Unable to link with type %s\n",
1291
input_file, line_number, SwigType_str(t, 0), name);
1866
tm = Swig_typemap_lookup_new("varin", n, name, 0);
1868
Replaceall(tm, "$symname", iname);
1869
Printf(f_c->code, "%s\n", tm);
1871
Printf(stderr,"%s: Line %d, Unable to link with type %s\n",
1872
input_file, line_number, SwigType_str(t, 0), name);
1294
1875
/* Now generate C -> PHP sync blocks */
1296
if(!GetFlag(n,"feature:immutable")) {
1298
tm = Swig_typemap_lookup_new("varout", n, name, 0);
1300
Replaceall(tm, "$symname", iname);
1301
Printf(f_php->code, "%s\n", tm);
1303
Printf(stderr,"%s: Line %d, Unable to link with type %s\n",
1304
input_file, line_number, SwigType_str(t, 0), name);
1877
if(!GetFlag(n,"feature:immutable")) {
1879
tm = Swig_typemap_lookup_new("varout", n, name, 0);
1881
Replaceall(tm, "$symname", iname);
1882
Printf(f_php->code, "%s\n", tm);
1884
Printf(stderr,"%s: Line %d, Unable to link with type %s\n",
1885
input_file, line_number, SwigType_str(t, 0), name);
1308
1889
return SWIG_OK;
1311
1892
/* ------------------------------------------------------------
1312
1893
* constantWrapper()
1313
1894
* ------------------------------------------------------------ */
1315
1896
virtual int constantWrapper(Node *n) {
1316
String *name = GetChar(n,"name");
1317
String *iname = GetChar(n,"sym:name");
1318
SwigType *type = Getattr(n,"type");
1319
String *rawval = Getattr(n,"rawval");
1320
String *value = rawval ? rawval : Getattr(n,"value");
1897
String *name = GetChar(n, "name");
1898
String *iname = GetChar(n, "sym:name");
1899
SwigType *type = Getattr(n, "type");
1900
String *rawval = Getattr(n, "rawval");
1901
String *value = rawval ? rawval : Getattr(n, "value");
1323
if (!addSymbol(iname,n)) return SWIG_ERROR;
1904
if (!addSymbol(iname, n))
1325
1907
SwigType_remember(type);
1327
if((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) {
1909
if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) {
1328
1910
Replaceall(tm, "$source", value);
1329
1911
Replaceall(tm, "$target", name);
1330
1912
Replaceall(tm, "$value", value);
1331
1913
Printf(s_cinit, "%s\n", tm);
1916
if (shadow && php_version == 5) {
1917
if (wrapping_member_constant) {
1919
s_oowrappers = NewStringEmpty();
1920
Printf(s_oowrappers, "\n\tconst %s = %s;\n", wrapping_member_constant, iname);
1922
if (!s_fakeoowrappers)
1923
s_fakeoowrappers = NewStringEmpty();
1924
Printf(s_fakeoowrappers, "\n\tconst %s = %s;\n", name, iname);
1333
1928
return SWIG_OK;
1339
1934
* Pragma directive.
1341
1936
* %pragma(php4) code="String" # Includes a string in the .php file
1342
1937
* %pragma(php4) include="file.pl" # Includes a file in the .php file
1345
1940
virtual int pragmaDirective(Node *n) {
1346
1941
if (!ImportMode) {
1347
String *lang = Getattr(n,"lang");
1348
String *type = Getattr(n,"name");
1349
String *value = Getattr(n,"value");
1942
String *lang = Getattr(n, "lang");
1943
String *type = Getattr(n, "name");
1944
String *value = Getattr(n, "value");
1351
if (Strcmp(lang,"php4") == 0) {
1353
if (Strcmp(type, "code") == 0) {
1355
Printf(pragma_code, "%s\n", value);
1357
} else if (Strcmp(type, "include") == 0) {
1359
Printf(pragma_incl, "include \"%s\";\n", value);
1361
} else if (Strcmp(type, "phpinfo") == 0) {
1363
Printf(pragma_phpinfo, "%s\n", value);
1366
Printf(stderr, "%s : Line %d. Unrecognized pragma.\n",
1367
input_file, line_number);
1946
if (Strcmp(lang, "php4") == 0) {
1947
if (Strcmp(type, "code") == 0) {
1949
Printf(pragma_code, "%s\n", value);
1951
} else if (Strcmp(type, "include") == 0) {
1953
Printf(pragma_incl, "include \"%s\";\n", value);
1955
} else if (Strcmp(type, "phpinfo") == 0) {
1957
Printf(pragma_phpinfo, "%s\n", value);
1960
Swig_warning(WARN_PHP4_UNKNOWN_PRAGMA, input_file, line_number, "Unrecognized pragma <%s>.\n", type);
1371
1964
return Language::pragmaDirective(n);
1376
1969
* ------------------------------------------------------------ */
1378
1971
virtual int classDeclaration(Node *n) {
1379
if (!Getattr(n,"feature:onlychildren")) {
1380
String *symname = Getattr(n,"sym:name");
1381
Setattr(n,"php:proxy",symname);
1972
if (!Getattr(n, "feature:onlychildren")) {
1973
String *symname = Getattr(n, "sym:name");
1974
Setattr(n, "php:proxy", symname);
1384
1977
return Language::classDeclaration(n);
1387
1980
/* ------------------------------------------------------------
1388
1981
* classHandler()
1389
1982
* ------------------------------------------------------------ */
1391
1984
virtual int classHandler(Node *n) {
1393
1986
//SwigType *t = Getattr(n, "classtype");
1394
class_name = Getattr(n, "sym:name");
1395
1988
// String *use_class_name=SwigType_manglestr(SwigType_ltype(t));
1990
if (shadow && php_version == 4) {
1398
1991
char *rename = GetChar(n, "sym:name");
1400
if (!addSymbol(rename,n)) return SWIG_ERROR;
1401
shadow_classname = Swig_copy_string(rename);
1402
cs_entry = NewString("");
1403
Printf(cs_entry,"/* Function entries for %s */\n",shadow_classname);
1404
Printf(cs_entry,"static zend_function_entry %s_functions[] = {\n", shadow_classname);
1993
if (!addSymbol(rename, n))
1995
shadow_classname = NewString(rename);
1996
cs_entry = NewStringEmpty();
1997
Printf(cs_entry, "/* Function entries for %s */\n", shadow_classname);
1998
Printf(cs_entry, "static zend_function_entry %s_functions[] = {\n", shadow_classname);
1406
if(Strcmp(shadow_classname, module) == 0) {
1407
Printf(stderr, "class name cannot be equal to module name: %s\n", shadow_classname);
2000
if (Strcmp(shadow_classname, module) == 0) {
2001
Printf(stderr, "class name cannot be equal to module name: %s\n", module);
1411
2005
shadow_get_vars = NewHash();
1412
2006
shadow_set_vars = NewHash();
1414
2008
/* Deal with inheritance */
1415
List *baselist = Getattr(n,"bases");
2009
List *baselist = Getattr(n, "bases");
1416
2010
if (baselist) {
1417
2011
Iterator base = First(baselist);
1418
while(base.item && GetFlag(base.item,"feature:ignore")) {
2012
while (base.item && GetFlag(base.item, "feature:ignore")) {
1419
2013
base = Next(base);
1421
2015
base = Next(base);
1422
2016
if (base.item) {
1423
2017
/* Warn about multiple inheritance for additional base class(es) */
1424
2018
while (base.item) {
1425
if (GetFlag(base.item,"feature:ignore")) {
2019
if (GetFlag(base.item, "feature:ignore")) {
1426
2020
base = Next(base);
1429
String *proxyclassname = SwigType_str(Getattr(n,"classtypeobj"),0);
1430
String *baseclassname = SwigType_str(Getattr(base.item,"name"),0);
1431
Swig_warning(WARN_PHP4_MULTIPLE_INHERITANCE, input_file, line_number,
1432
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Php4.\n", proxyclassname, baseclassname);
2023
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
2024
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
2025
Swig_warning(WARN_PHP4_MULTIPLE_INHERITANCE, input_file, line_number,
2026
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Php4.\n", proxyclassname, baseclassname);
1433
2027
base = Next(base);
1438
2032
/* Write out class init code */
1439
Printf(s_vdecl,"static zend_class_entry ce_swig_%s;\n",shadow_classname);
1440
Printf(s_vdecl,"static zend_class_entry* ptr_ce_swig_%s=NULL;\n",shadow_classname);
2033
Printf(s_vdecl, "static zend_class_entry ce_swig_%s;\n", shadow_classname);
2034
Printf(s_vdecl, "static zend_class_entry* ptr_ce_swig_%s=NULL;\n", shadow_classname);
2035
} else if (shadow && php_version == 5) {
2036
char *rename = GetChar(n, "sym:name");
2038
if (!addSymbol(rename, n))
2040
shadow_classname = NewString(rename);
2042
shadow_get_vars = NewHash();
2043
shadow_set_vars = NewHash();
2045
/* Deal with inheritance */
2046
List *baselist = Getattr(n, "bases");
2048
Iterator base = First(baselist);
2049
while (base.item && GetFlag(base.item, "feature:ignore")) {
2054
/* Warn about multiple inheritance for additional base class(es) */
2056
if (GetFlag(base.item, "feature:ignore")) {
2060
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
2061
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
2062
Swig_warning(WARN_PHP4_MULTIPLE_INHERITANCE, input_file, line_number,
2063
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Php4.\n", proxyclassname, baseclassname);
1444
2071
Language::classHandler(n);
2074
if (shadow && php_version == 4) {
1450
String *s_propget=NewString("");
1451
String *s_propset=NewString("");
2076
String *s_propget = NewStringEmpty();
2077
String *s_propset = NewStringEmpty();
1452
2078
List *baselist = Getattr(n, "bases");
1453
2079
Iterator ki, base;
1456
2081
// If no constructor was generated (abstract class) we had better
1457
2082
// generate a constructor that raises an error about instantiating
1458
2083
// abstract classes
1459
if (Getattr(n,"abstract") && constructors==0 ) {
1460
// have to write out fake constructor which raises an error when called
1461
abstractConstructorHandler(n);
2084
if (Getattr(n, "abstract") && constructors == 0) {
2085
// have to write out fake constructor which raises an error when called
2086
abstractConstructorHandler(n);
1464
Printf(s_oinit,"/* Define class %s */\n",shadow_classname);
1465
Printf(s_oinit,"INIT_OVERLOADED_CLASS_ENTRY(ce_swig_%s,\"%(lower)s\",%s_functions,",
1466
shadow_classname,shadow_classname, shadow_classname);
1467
Printf(s_oinit,"NULL,_wrap_propget_%s,_wrap_propset_%s);\n",shadow_classname,shadow_classname);
2089
Printf(s_oinit, "/* Define class %s */\n", shadow_classname);
2090
Printf(s_oinit, "INIT_OVERLOADED_CLASS_ENTRY(ce_swig_%s,\"%(lower)s\",%s_functions,", shadow_classname, shadow_classname, shadow_classname);
2091
Printf(s_oinit, "NULL,_wrap_propget_%s,_wrap_propset_%s);\n", shadow_classname, shadow_classname);
1469
2093
// ******** Write property SET handlers
1470
Printf(s_header,"static int _wrap_propset_%s(zend_property_reference *property_reference, pval *value);\n",
1472
Printf(s_header,"static int _propset_%s(zend_property_reference *property_reference, pval *value);\n",
2094
Printf(s_header, "static int _wrap_propset_%s(zend_property_reference *property_reference, pval *value);\n", shadow_classname);
2095
Printf(s_header, "static int _propset_%s(zend_property_reference *property_reference, pval *value);\n", shadow_classname);
1475
Printf(s_propset,"static int _wrap_propset_%s(zend_property_reference *property_reference, pval *value) { \n",
1477
Printf(s_propset," zval * _value;\n");
1478
Printf(s_propset," zend_llist_element *element = property_reference->elements_list->head;\n");
1479
Printf(s_propset," zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n");
1480
Printf(s_propset," if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", shadow_classname);
1481
Printf(s_propset," /* set it ourselves as it is %s */\n",shadow_classname);
1482
Printf(s_propset," MAKE_STD_ZVAL(_value);\n");
1483
Printf(s_propset," *_value=*value;\n");
1484
Printf(s_propset," INIT_PZVAL(_value);\n");
1485
Printf(s_propset," zval_copy_ctor(_value);\n");
1486
Printf(s_propset," return add_property_zval_ex(property_reference->object,Z_STRVAL_P(&(property->element)),1+Z_STRLEN_P(&(property->element)),_value);\n");
1487
Printf(s_propset,"}\n");
1488
Printf(s_propset,"static int _propset_%s(zend_property_reference *property_reference, pval *value) {\n",
2097
Printf(s_propset, "static int _wrap_propset_%s(zend_property_reference *property_reference, pval *value) { \n", shadow_classname);
2098
Printf(s_propset, " zval * _value;\n");
2099
Printf(s_propset, " zend_llist_element *element = property_reference->elements_list->head;\n");
2100
Printf(s_propset, " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n");
2101
Printf(s_propset, " if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", shadow_classname);
2102
Printf(s_propset, " /* set it ourselves as it is %s */\n", shadow_classname);
2103
Printf(s_propset, " MAKE_STD_ZVAL(_value);\n");
2104
Printf(s_propset, " *_value=*value;\n");
2105
Printf(s_propset, " INIT_PZVAL(_value);\n");
2106
Printf(s_propset, " zval_copy_ctor(_value);\n");
2108
" return add_property_zval_ex(property_reference->object,Z_STRVAL_P(&(property->element)),1+Z_STRLEN_P(&(property->element)),_value);\n");
2109
Printf(s_propset, "}\n");
2110
Printf(s_propset, "static int _propset_%s(zend_property_reference *property_reference, pval *value) {\n", shadow_classname);
1492
2113
if (baselist) {
1493
base=First(baselist);
2114
base = First(baselist);
1499
while(base.item && GetFlag(base.item,"feature:ignore")) {
2119
while (base.item && GetFlag(base.item, "feature:ignore")) {
1503
2123
ki = First(shadow_set_vars);
1506
2126
// Print function header; we only need to find property name if there
1507
2127
// are properties for this class to look up...
1508
if (key || ! base.item) { // or if we are base class and set it ourselves
1509
Printf(s_propset," /* get the property name */\n");
1510
Printf(s_propset," zend_llist_element *element = property_reference->elements_list->head;\n");
1511
Printf(s_propset," zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n");
1512
Printf(s_propset," char *propname=Z_STRVAL_P(&(property->element));\n");
2128
if (key || !base.item) { // or if we are base class and set it ourselves
2129
Printf(s_propset, " /* get the property name */\n");
2130
Printf(s_propset, " zend_llist_element *element = property_reference->elements_list->head;\n");
2131
Printf(s_propset, " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n");
2132
Printf(s_propset, " char *propname=Z_STRVAL_P(&(property->element));\n");
1515
Printf(s_propset," /* No extra properties for subclass %s */\n",shadow_classname);
1517
Printf(s_propset," /* No properties for base class %s */\n",shadow_classname);
2135
Printf(s_propset, " /* No extra properties for subclass %s */\n", shadow_classname);
2137
Printf(s_propset, " /* No properties for base class %s */\n", shadow_classname);
1522
2141
while (ki.key) {
1525
Printf(s_propset," else");
1527
Printf(s_propset," if (strcmp(propname,\"%s\")==0) {\n",Getattr(shadow_set_vars,key) );
1528
Printf(s_propset," return _wrap_%s(property_reference, value);\n",key);
1529
Printf(s_propset," }");
1535
Printf(s_propset," else");
1538
// If there is a base class then chain it's handler else set directly
1539
// try each base class handler, else set directly...
2143
Printf(s_propset, " if (strcmp(propname,\"%s\")==0) return _wrap_%s(property_reference, value);\n", ki.item, key);
2148
// If the property wasn't in this class, try the handlers of each base
2149
// class (if any) in turn until we succeed in setting the property or
2150
// have tried all base classes.
1540
2151
if (base.item) {
1541
Printf(s_propset, " {\n /* chain to base class */\n");
1543
Printf(s_propset," if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n",
1544
GetChar(base.item, "sym:name"));
1547
while (base.item && GetFlag(base.item,"feature:ignore")) {
1551
Printf(s_propset," }\n");
2152
Printf(s_propset, " /* Try base class(es) */\n");
2154
Printf(s_propset, " if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", GetChar(base.item, "sym:name"));
2157
while (base.item && GetFlag(base.item, "feature:ignore")) {
1553
Printf(s_propset," return FAILURE;\n}\n\n");
2162
Printf(s_propset, " return FAILURE;\n}\n\n");
1555
2164
// ******** Write property GET handlers
1556
Printf(s_header,"static pval _wrap_propget_%s(zend_property_reference *property_reference);\n",
1558
Printf(s_header,"static int _propget_%s(zend_property_reference *property_reference, pval *value);\n",
2165
Printf(s_header, "static pval _wrap_propget_%s(zend_property_reference *property_reference);\n", shadow_classname);
2166
Printf(s_header, "static int _propget_%s(zend_property_reference *property_reference, pval *value);\n", shadow_classname);
1561
Printf(s_propget,"static pval _wrap_propget_%s(zend_property_reference *property_reference) {\n",
1563
Printf(s_propget," pval result;\n");
1564
Printf(s_propget," pval **_result;\n");
1565
Printf(s_propget," zend_llist_element *element = property_reference->elements_list->head;\n");
1566
Printf(s_propget," zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n");
1567
Printf(s_propget," result.type = IS_NULL;\n");
1568
Printf(s_propget," if (_propget_%s(property_reference, &result)==SUCCESS) return result;\n", shadow_classname);
1569
Printf(s_propget," /* return it ourselves */\n");
1570
Printf(s_propget," if (zend_hash_find(Z_OBJPROP_P(property_reference->object),Z_STRVAL_P(&(property->element)),1+Z_STRLEN_P(&(property->element)),(void**)&_result)==SUCCESS) {\n");
1571
Printf(s_propget," zval *_value;\n");
1572
Printf(s_propget," MAKE_STD_ZVAL(_value);");
1573
Printf(s_propget," *_value=**_result;\n");
1574
Printf(s_propget," INIT_PZVAL(_value);\n");
1575
Printf(s_propget," zval_copy_ctor(_value);\n");
1576
Printf(s_propget," return *_value;\n");
1577
Printf(s_propget," }\n");
1578
Printf(s_propget," result.type = IS_NULL;\n");
1579
Printf(s_propget," return result;\n");
1580
Printf(s_propget,"}\n");
1581
Printf(s_propget,"static int _propget_%s(zend_property_reference *property_reference, pval *value) {\n",
2168
Printf(s_propget, "static pval _wrap_propget_%s(zend_property_reference *property_reference) {\n", shadow_classname);
2169
Printf(s_propget, " pval result;\n");
2170
Printf(s_propget, " pval **_result;\n");
2171
Printf(s_propget, " zend_llist_element *element = property_reference->elements_list->head;\n");
2172
Printf(s_propget, " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n");
2173
Printf(s_propget, " result.type = IS_NULL;\n");
2174
Printf(s_propget, " if (_propget_%s(property_reference, &result)==SUCCESS) return result;\n", shadow_classname);
2175
Printf(s_propget, " /* return it ourselves */\n");
2177
" if (zend_hash_find(Z_OBJPROP_P(property_reference->object),Z_STRVAL_P(&(property->element)),1+Z_STRLEN_P(&(property->element)),(void**)&_result)==SUCCESS) {\n");
2178
Printf(s_propget, " zval *_value;\n");
2179
Printf(s_propget, " MAKE_STD_ZVAL(_value);");
2180
Printf(s_propget, " *_value=**_result;\n");
2181
Printf(s_propget, " INIT_PZVAL(_value);\n");
2182
Printf(s_propget, " zval_copy_ctor(_value);\n");
2183
Printf(s_propget, " return *_value;\n");
2184
Printf(s_propget, " }\n");
2185
Printf(s_propget, " result.type = IS_NULL;\n");
2186
Printf(s_propget, " return result;\n");
2187
Printf(s_propget, "}\n");
2188
Printf(s_propget, "static int _propget_%s(zend_property_reference *property_reference, pval *value) {\n", shadow_classname);
1584
2190
if (baselist) {
1585
base=First(baselist);
2191
base = First(baselist);
1589
while(base.item && GetFlag(base.item,"feature:ignore")) {
2195
while (base.item && GetFlag(base.item, "feature:ignore")) {
1592
2198
ki = First(shadow_get_vars);
1596
2202
// Print function header; we only need to find property name if there
1597
2203
// are properties for this class to look up...
1598
if (key || !base.item ) { // or if we are base class...
1599
Printf(s_propget," /* get the property name */\n");
1600
Printf(s_propget," zend_llist_element *element = property_reference->elements_list->head;\n");
1601
Printf(s_propget," zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n");
1602
Printf(s_propget," char *propname=Z_STRVAL_P(&(property->element));\n");
2204
if (key || !base.item) { // or if we are base class...
2205
Printf(s_propget, " /* get the property name */\n");
2206
Printf(s_propget, " zend_llist_element *element = property_reference->elements_list->head;\n");
2207
Printf(s_propget, " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n");
2208
Printf(s_propget, " char *propname=Z_STRVAL_P(&(property->element));\n");
1605
Printf(s_propget," /* No extra properties for subclass %s */\n",shadow_classname);
1607
Printf(s_propget," /* No properties for base class %s */\n",shadow_classname);
2211
Printf(s_propget, " /* No extra properties for subclass %s */\n", shadow_classname);
2213
Printf(s_propget, " /* No properties for base class %s */\n", shadow_classname);
1612
2217
while (ki.key) {
1615
Printf(s_propget," else");
1617
Printf(s_propget," if (strcmp(propname,\"%s\")==0) {\n",Getattr(shadow_get_vars,key));
1618
Printf(s_propget," *value=_wrap_%s(property_reference);\n",key);
1619
Printf(s_propget," return SUCCESS;\n");
1620
Printf(s_propget," }");
1626
Printf(s_propget," else");
1629
// If there is a base class then chain it's handler else return null
2219
Printf(s_propget, " if (strcmp(propname,\"%s\")==0) {\n", ki.item);
2220
Printf(s_propget, " *value=_wrap_%s(property_reference);\n", key);
2221
Printf(s_propget, " return SUCCESS;\n");
2222
Printf(s_propget, " }\n");
2227
// If the property wasn't in this class, try the handlers of each base
2228
// class (if any) in turn until we succeed in setting the property or
2229
// have tried all base classes.
1630
2230
if (base.item) {
1631
Printf(s_propget, " {\n /* chain to base class */\n");
1633
Printf(s_propget," if (_propget_%s(property_reference, value)==SUCCESS) return SUCCESS;\n",
1634
GetChar(base.item, "sym:name"));
2231
Printf(s_propget, " /* Try base class(es). */\n");
2233
Printf(s_propget, " if (_propget_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", GetChar(base.item, "sym:name"));
1637
while (base.item && GetFlag(base.item,"feature:ignore")) {
1641
Printf(s_propget," }\n");
2236
while (base.item && GetFlag(base.item, "feature:ignore")) {
1643
Printf(s_propget," return FAILURE;\n}\n\n");
2241
Printf(s_propget, " return FAILURE;\n}\n\n");
1645
2243
// wrappers generated now...
1647
2245
// add wrappers to output code
1648
Printf(s_wrappers,"/* property handler for class %s */\n",shadow_classname);
1649
Printv(s_wrappers,s_propget,s_propset,NIL);
2246
Printf(s_wrappers, "/* property handler for class %s */\n", shadow_classname);
2247
Printv(s_wrappers, s_propget, s_propset, NIL);
1651
2249
// Save class in class table
1652
2250
if (baselist) {
1653
base=First(baselist);
1658
while(base.item && GetFlag(base.item,"feature:ignore")) {
2251
base = First(baselist);
2255
while (base.item && GetFlag(base.item, "feature:ignore")) {
1662
2259
if (base.item) {
1663
Printf(s_oinit,"if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,&ce_swig_%s,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n",
1664
shadow_classname,shadow_classname,GetChar(base.item, "sym:name"), shadow_classname);
2261
"if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,&ce_swig_%s,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n",
2262
shadow_classname, shadow_classname, GetChar(base.item, "sym:name"), shadow_classname);
1666
Printf(s_oinit,"if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,NULL,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n",
1667
shadow_classname,shadow_classname, shadow_classname);
2265
"if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,NULL,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n",
2266
shadow_classname, shadow_classname, shadow_classname);
1669
Printf(s_oinit,"\n");
2268
Printf(s_oinit, "\n");
1671
2270
// Write the enum initialisation code in a static block
1672
// These are all the enums defined withing the c++ class.
1675
free(shadow_classname);
1676
shadow_classname = NULL;
1678
Delete(shadow_set_vars); shadow_set_vars = NULL;
1679
Delete(shadow_get_vars); shadow_get_vars = NULL;
1681
Printf(all_cs_entry,"%s { NULL, NULL, NULL}\n};\n",cs_entry);
1682
//??delete cs_entry;
2271
// These are all the enums defined within the C++ class.
2273
Delete(shadow_classname);
2274
shadow_classname = NULL;
2276
Delete(shadow_set_vars);
2277
shadow_set_vars = NULL;
2278
Delete(shadow_get_vars);
2279
shadow_get_vars = NULL;
2281
Printv(all_cs_entry, cs_entry, " { NULL, NULL, NULL}\n};\n", NIL);
2284
} else if (shadow && php_version == 5) {
2286
List *baselist = Getattr(n, "bases");
2290
base = First(baselist);
2291
while (base.item && GetFlag(base.item, "feature:ignore")) {
2298
if (Getattr(n, "abstract")) {
2299
Printf(s_phpclasses, "abstract ");
2302
Printf(s_phpclasses, "class %s%s ", prefix, shadow_classname);
2304
String *baseclass = Getattr(base.item, "sym:name");
2306
baseclass = Getattr(base.item, "name");
2307
Printf(s_phpclasses, "extends %s%s ", prefix, baseclass);
2309
Printf(s_phpclasses, "{\n\tpublic $%s=null;\n", SWIG_PTR);
2311
// Write property SET handlers
2312
ki = First(shadow_set_vars);
2315
// This class has setters.
2316
// FIXME: just ignore setting an unknown property name for now.
2317
Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n");
2318
// FIXME: tune this threshold...
2319
if (Len(shadow_set_vars) <= 2) {
2320
// Not many setters, so avoid call_user_func.
2323
Printf(s_phpclasses, "\t\tif ($var == '%s') return %s($this->%s,$value);\n", key, ki.item, SWIG_PTR);
2327
Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_set';\n", shadow_classname);
2328
Printf(s_phpclasses, "\t\tif (function_exists($func) call_user_func($func,$this->%s,$value);\n", SWIG_PTR);
2330
Printf(s_phpclasses, "\t}\n");
2331
/* FIXME: also create __isset for PHP 5.1 and later? */
2333
// Write property GET handlers
2334
ki = First(shadow_get_vars);
2337
// This class has getters.
2338
Printf(s_phpclasses, "\n\tfunction __get($var) {\n");
2339
// FIXME: tune this threshold...
2340
if (Len(shadow_get_vars) <= 2) {
2341
// Not many getters, so avoid call_user_func.
2344
Printf(s_phpclasses, "\t\tif ($var == '%s') return %s($this->%s);\n", key, ki.item, SWIG_PTR);
2348
Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname);
2349
Printf(s_phpclasses, "\t\tif (function_exists($func) return call_user_func($func,$this->%s);\n", SWIG_PTR);
2351
// Reading an unknown property name gives null in PHP.
2352
Printf(s_phpclasses, "\t\treturn null;\n");
2353
Printf(s_phpclasses, "\t}\n");
2356
if (!class_has_ctor) {
2357
Printf(s_phpclasses, "\tfunction __construct($h) {\n");
2358
Printf(s_phpclasses, "\t\t$this->%s=$h;\n", SWIG_PTR);
2359
Printf(s_phpclasses, "\t}\n");
2363
Printf(s_phpclasses, "%s", s_oowrappers);
2364
Delete(s_oowrappers);
2365
s_oowrappers = NULL;
2367
class_has_ctor = false;
2369
Printf(s_phpclasses, "}\n\n");
2371
Delete(shadow_classname);
2372
shadow_classname = NULL;
2374
Delete(shadow_set_vars);
2375
shadow_set_vars = NULL;
2376
Delete(shadow_get_vars);
2377
shadow_get_vars = NULL;
1685
2379
return SWIG_OK;