Merge branch 'master' into directorargout_and_java_typemaps

This commit is contained in:
Andrey Starodubtsev 2017-01-21 17:41:31 +03:00
commit 4ba9de370e
470 changed files with 15434 additions and 3110 deletions

View file

@ -57,6 +57,7 @@ static Node *currentOuterClass = 0; /* for nested classes */
static const char *last_cpptype = 0;
static int inherit_list = 0;
static Parm *template_parameters = 0;
static int parsing_template_declaration = 0;
static int extendmode = 0;
static int compact_default_args = 0;
static int template_reduce = 0;
@ -262,6 +263,7 @@ static String *add_oldname = 0;
static String *make_name(Node *n, String *name,SwigType *decl) {
String *made_name = 0;
int destructor = name && (*(Char(name)) == '~');
if (yyrename) {
@ -275,7 +277,13 @@ static String *make_name(Node *n, String *name,SwigType *decl) {
}
if (!name) return 0;
return Swig_name_make(n,Namespaceprefix,name,decl,add_oldname);
if (parsing_template_declaration)
SetFlag(n, "parsing_template_declaration");
made_name = Swig_name_make(n, Namespaceprefix, name, decl, add_oldname);
Delattr(n, "parsing_template_declaration");
return made_name;
}
/* Generate an unnamed identifier */
@ -440,7 +448,10 @@ static void add_symbols(Node *n) {
symname = Copy(Getattr(n,"unnamed"));
}
if (symname) {
if (parsing_template_declaration)
SetFlag(n, "parsing_template_declaration");
wrn = Swig_name_warning(n, Namespaceprefix, symname,0);
Delattr(n, "parsing_template_declaration");
}
} else {
String *name = Getattr(n,"name");
@ -453,7 +464,10 @@ static void add_symbols(Node *n) {
Swig_features_get(Swig_cparse_features(),Namespaceprefix,name,fun,n);
symname = make_name(n, name,fun);
if (parsing_template_declaration)
SetFlag(n, "parsing_template_declaration");
wrn = Swig_name_warning(n, Namespaceprefix,symname,fun);
Delattr(n, "parsing_template_declaration");
Delete(fdecl);
Delete(fun);
@ -1462,7 +1476,7 @@ static void mark_nodes_as_extend(Node *n) {
%type <p> parm valparm rawvalparms valparms valptail ;
%type <p> typemap_parm tm_list tm_tail ;
%type <p> templateparameter ;
%type <id> templcpptype cpptype access_specifier;
%type <id> templcpptype cpptype classkey classkeyopt access_specifier;
%type <node> base_specifier;
%type <str> ellipsis variadic;
%type <type> type rawtype type_right anon_bitfield_type decltype ;
@ -1613,14 +1627,14 @@ swig_directive : extend_directive { $$ = $1; }
%extend classname { ... }
------------------------------------------------------------ */
extend_directive : EXTEND options idcolon LBRACE {
extend_directive : EXTEND options classkeyopt idcolon LBRACE {
Node *cls;
String *clsname;
extendmode = 1;
cplus_mode = CPLUS_PUBLIC;
if (!classes) classes = NewHash();
if (!classes_typedefs) classes_typedefs = NewHash();
clsname = make_class_name($3);
clsname = make_class_name($4);
cls = Getattr(classes,clsname);
if (!cls) {
cls = Getattr(classes_typedefs, clsname);
@ -1629,7 +1643,7 @@ extend_directive : EXTEND options idcolon LBRACE {
Node *am = Getattr(Swig_extend_hash(),clsname);
if (!am) {
Swig_symbol_newscope();
Swig_symbol_setscopename($3);
Swig_symbol_setscopename($4);
prev_symtab = 0;
} else {
prev_symtab = Swig_symbol_setscope(Getattr(am,"symtab"));
@ -1642,7 +1656,7 @@ extend_directive : EXTEND options idcolon LBRACE {
prev_symtab = Swig_symbol_setscope(Getattr(cls, "symtab"));
current_class = cls;
SWIG_WARN_NODE_BEGIN(cls);
Swig_warning(WARN_PARSE_EXTEND_NAME, cparse_file, cparse_line, "Deprecated %%extend name used - the %s name '%s' should be used instead of the typedef name '%s'.\n", Getattr(cls, "kind"), SwigType_namestr(Getattr(cls, "name")), $3);
Swig_warning(WARN_PARSE_EXTEND_NAME, cparse_file, cparse_line, "Deprecated %%extend name used - the %s name '%s' should be used instead of the typedef name '%s'.\n", Getattr(cls, "kind"), SwigType_namestr(Getattr(cls, "name")), $4);
SWIG_WARN_NODE_END(cls);
}
} else {
@ -1650,7 +1664,7 @@ extend_directive : EXTEND options idcolon LBRACE {
prev_symtab = Swig_symbol_setscope(Getattr(cls,"symtab"));
current_class = cls;
}
Classprefix = NewString($3);
Classprefix = NewString($4);
Namespaceprefix= Swig_symbol_qualifiedscopename(0);
Delete(clsname);
} cpp_members RBRACE {
@ -1662,22 +1676,22 @@ extend_directive : EXTEND options idcolon LBRACE {
Swig_symbol_setscope(prev_symtab);
}
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
clsname = make_class_name($3);
clsname = make_class_name($4);
Setattr($$,"name",clsname);
mark_nodes_as_extend($6);
mark_nodes_as_extend($7);
if (current_class) {
/* We add the extension to the previously defined class */
appendChild($$,$6);
appendChild($$, $7);
appendChild(current_class,$$);
} else {
/* We store the extensions in the extensions hash */
Node *am = Getattr(Swig_extend_hash(),clsname);
if (am) {
/* Append the members to the previous extend methods */
appendChild(am,$6);
appendChild(am, $7);
} else {
appendChild($$,$6);
appendChild($$, $7);
Setattr(Swig_extend_hash(),clsname,$$);
}
}
@ -2901,25 +2915,24 @@ c_declaration : c_decl {
| USING idcolon EQUAL type plain_declarator SEMI {
/* Convert using statement to a typedef statement */
$$ = new_node("cdecl");
SwigType_push($4,$5.type);
Setattr($$,"type",$4);
Setattr($$,"storage","typedef");
Setattr($$,"name",$2);
Setattr($$,"decl","");
Setattr($$,"decl",$5.type);
SetFlag($$,"typealias");
add_symbols($$);
}
| TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL type plain_declarator SEMI {
$$ = new_node("using");
/* Convert alias template to a "template" typedef statement */
$$ = new_node("template");
Setattr($$,"type",$8);
Setattr($$,"storage","typedef");
Setattr($$,"name",$6);
SwigType_push($8,$9.type);
Setattr($$,"uname",$8);
Setattr($$,"decl",$9.type);
Setattr($$,"templateparms",$3);
Setattr($$,"templatetype","cdecl");
SetFlag($$,"aliastemplate");
add_symbols($$);
SWIG_WARN_NODE_BEGIN($$);
Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line, "The 'using' keyword in template aliasing is not fully supported yet.\n");
SWIG_WARN_NODE_END($$);
$$ = 0; /* TODO - ignored for now */
}
;
@ -3851,9 +3864,10 @@ cpp_forward_class_decl : storage_class cpptype idcolon SEMI {
------------------------------------------------------------ */
cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN {
if (currentOuterClass)
Setattr(currentOuterClass, "template_parameters", template_parameters);
if (currentOuterClass)
Setattr(currentOuterClass, "template_parameters", template_parameters);
template_parameters = $3;
parsing_template_declaration = 1;
} cpp_temp_possible {
String *tname = 0;
int error = 0;
@ -4106,6 +4120,7 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN {
template_parameters = Getattr(currentOuterClass, "template_parameters");
else
template_parameters = 0;
parsing_template_declaration = 0;
}
/* Explicit template instantiation */
@ -6295,7 +6310,6 @@ access_specifier : PUBLIC { $$ = (char*)"public"; }
| PROTECTED { $$ = (char*)"protected"; }
;
templcpptype : CLASS {
$$ = (char*)"class";
if (!inherit_list) last_cpptype = $$;
@ -6327,6 +6341,28 @@ cpptype : templcpptype {
}
;
classkey : CLASS {
$$ = (char*)"class";
if (!inherit_list) last_cpptype = $$;
}
| STRUCT {
$$ = (char*)"struct";
if (!inherit_list) last_cpptype = $$;
}
| UNION {
$$ = (char*)"union";
if (!inherit_list) last_cpptype = $$;
}
;
classkeyopt : classkey {
$$ = $1;
}
| empty {
$$ = 0;
}
;
opt_virtual : VIRTUAL
| empty
;

View file

@ -93,8 +93,8 @@
#define WARN_PARSE_EXTEND_NAME 326
#define WARN_CPP11_LAMBDA 340
#define WARN_CPP11_ALIAS_DECLARATION 341
#define WARN_CPP11_ALIAS_TEMPLATE 342
#define WARN_CPP11_ALIAS_DECLARATION 341 /* redundant now */
#define WARN_CPP11_ALIAS_TEMPLATE 342 /* redundant now */
#define WARN_CPP11_VARIADIC_TEMPLATE 343
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
@ -215,9 +215,9 @@
/* Feel free to claim any number in this space that's not currently being used. Just make sure you
add an entry here */
#define WARN_D_TYPEMAP_CTYPE_UNDEF 700
#define WARN_D_TYPEMAP_CTYPE_UNDEF 700
#define WARN_D_TYPEMAP_IMTYPE_UNDEF 701
#define WARN_D_TYPEMAP_DTYPE_UNDEF 702
#define WARN_D_TYPEMAP_DTYPE_UNDEF 702
#define WARN_D_MULTIPLE_INHERITANCE 703
#define WARN_D_TYPEMAP_CLASSMOD_UNDEF 704
#define WARN_D_TYPEMAP_DBODY_UNDEF 705

View file

@ -62,6 +62,7 @@ eswig_SOURCES = CParse/cscanner.c \
Modules/overload.cxx \
Modules/perl5.cxx \
Modules/php.cxx \
Modules/php5.cxx \
Modules/pike.cxx \
Modules/python.cxx \
Modules/r.cxx \

View file

@ -197,15 +197,17 @@ class Allocate:public Dispatcher {
// Found a polymorphic method.
// Mark the polymorphic method, in case the virtual keyword was not used.
Setattr(n, "storage", "virtual");
if (both_have_public_access || both_have_protected_access) {
if (!is_non_public_base(inclass, b))
Setattr(n, "override", base); // Note C# definition of override, ie access must be the same
} else if (!both_have_private_access) {
// Different access
if (this_wrapping_protected_members || base_wrapping_protected_members)
if (!Getattr(b, "feature:interface")) { // interface implementation neither hides nor overrides
if (both_have_public_access || both_have_protected_access) {
if (!is_non_public_base(inclass, b))
Setattr(n, "hides", base); // Note C# definition of hiding, ie hidden if access is different
Setattr(n, "override", base); // Note C# definition of override, ie access must be the same
}
else if (!both_have_private_access) {
// Different access
if (this_wrapping_protected_members || base_wrapping_protected_members)
if (!is_non_public_base(inclass, b))
Setattr(n, "hides", base); // Note C# definition of hiding, ie hidden if access is different
}
}
// Try and find the most base's covariant return type
SwigType *most_base_covariant_type = Getattr(base, "covariant");

View file

@ -1584,11 +1584,23 @@ public:
* ----------------------------------------------------------------------------- */
virtual int insertDirective(Node *n) {
int ret = SWIG_OK;
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
Replaceall(code, "$module", module_class_name);
Replaceall(code, "$imclassname", imclass_name);
Replaceall(code, "$dllimport", dllimport);
return Language::insertDirective(n);
if (!ImportMode && (Cmp(section, "proxycode") == 0)) {
if (proxy_class_code) {
Swig_typemap_replace_embedded_typemap(code, n);
int offset = Len(code) > 0 && *Char(code) == '\n' ? 1 : 0;
Printv(proxy_class_code, Char(code) + offset, "\n", NIL);
}
} else {
ret = Language::insertDirective(n);
}
return ret;
}
/* -----------------------------------------------------------------------------
@ -2044,34 +2056,6 @@ public:
}
}
/* ----------------------------------------------------------------------
* calculateDirectBase()
* ---------------------------------------------------------------------- */
void calculateDirectBase(Node* n) {
Node* direct_base = 0;
// C++ inheritance
Node *attributes = NewHash();
SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
const String *pure_baseclass = typemapLookup(n, "csbase", typemap_lookup_type, WARN_NONE, attributes);
bool purebase_replace = GetFlag(attributes, "tmap:csbase:replace") ? true : false;
bool purebase_notderived = GetFlag(attributes, "tmap:csbase:notderived") ? true : false;
Delete(attributes);
if (!purebase_replace) {
if (List *baselist = Getattr(n, "bases")) {
Iterator base = First(baselist);
while (base.item && (GetFlag(base.item, "feature:ignore") || Getattr(base.item, "feature:interface")))
base = Next(base);
direct_base = base.item;
}
if (!direct_base && purebase_notderived)
direct_base = symbolLookup(const_cast<String*>(pure_baseclass));
} else {
direct_base = symbolLookup(const_cast<String*>(pure_baseclass));
}
Setattr(n, "direct_base", direct_base);
}
/* ----------------------------------------------------------------------
* classHandler()
* ---------------------------------------------------------------------- */
@ -2157,7 +2141,6 @@ public:
emitInterfaceDeclaration(n, interface_name, interface_class_code);
Delete(output_directory);
}
calculateDirectBase(n);
}
Language::classHandler(n);
@ -2426,21 +2409,8 @@ public:
Printf(function_code, " %s ", methodmods);
if (!is_smart_pointer()) {
// Smart pointer classes do not mirror the inheritance hierarchy of the underlying pointer type, so no virtual/override/new required.
if (Node *base_ovr = Getattr(n, "override")) {
if (GetFlag(n, "isextendmember"))
if (Getattr(n, "override"))
Printf(function_code, "override ");
else {
Node* base = parentNode(base_ovr);
bool ovr = false;
for (Node* direct_base = Getattr(parentNode(n), "direct_base"); direct_base; direct_base = Getattr(direct_base, "direct_base")) {
if (direct_base == base) { // "override" only applies if the base was not discarded (e.g. in case of multiple inheritance or via "ignore")
ovr = true;
break;
}
}
Printf(function_code, ovr ? "override " : "virtual ");
}
}
else if (checkAttribute(n, "storage", "virtual"))
Printf(function_code, "virtual ");
if (Getattr(n, "hides"))
@ -3917,8 +3887,12 @@ public:
}
Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name);
if (!ignored_method)
Printf(director_delegate_definitions, " public delegate %s", tm);
if (!ignored_method) {
const String *csdirectordelegatemodifiers = Getattr(n, "feature:csdirectordelegatemodifiers");
String *modifiers = (csdirectordelegatemodifiers ? NewStringf("%s%s", csdirectordelegatemodifiers, Len(csdirectordelegatemodifiers) > 0 ? " " : "") : NewStringf("public "));
Printf(director_delegate_definitions, " %sdelegate %s", modifiers, tm);
Delete(modifiers);
}
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}

View file

@ -717,9 +717,20 @@ public:
* D::insertDirective()
* --------------------------------------------------------------------------- */
virtual int insertDirective(Node *n) {
int ret = SWIG_OK;
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
replaceModuleVariables(code);
return Language::insertDirective(n);
if (!ImportMode && (Cmp(section, "proxycode") == 0)) {
if (proxy_class_body_code) {
Swig_typemap_replace_embedded_typemap(code, n);
Printv(proxy_class_body_code, code, NIL);
}
} else {
ret = Language::insertDirective(n);
}
return ret;
}
/* ---------------------------------------------------------------------------

View file

@ -1612,10 +1612,22 @@ public:
* ----------------------------------------------------------------------------- */
virtual int insertDirective(Node *n) {
int ret = SWIG_OK;
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
Replaceall(code, "$module", module_class_name);
Replaceall(code, "$imclassname", imclass_name);
return Language::insertDirective(n);
if (!ImportMode && (Cmp(section, "proxycode") == 0)) {
if (proxy_class_code) {
Swig_typemap_replace_embedded_typemap(code, n);
int offset = Len(code) > 0 && *Char(code) == '\n' ? 1 : 0;
Printv(proxy_class_code, Char(code) + offset, "\n", NIL);
}
} else {
ret = Language::insertDirective(n);
}
return ret;
}
/* -----------------------------------------------------------------------------

View file

@ -870,7 +870,7 @@ int Language::cDeclaration(Node *n) {
} else {
// Found an unignored templated method that has an empty template instantiation (%template())
// Ignore it unless it has been %rename'd
if (Strncmp(symname, "__dummy_", 8) == 0) {
if (Strncmp(symname, "__dummy_", 8) == 0 && Cmp(storage, "typedef") != 0) {
SetFlag(n, "feature:ignore");
Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number,
"%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n));

View file

@ -64,7 +64,7 @@ static const char *usage1 = (const char *) "\
-copyctor - Automatically generate copy constructors wherever possible\n\
-cpperraswarn - Treat the preprocessor #error statement as #warning (default)\n\
-cppext <ext> - Change file extension of generated C++ files to <ext>\n\
(default is cxx, except for PHP which uses cpp)\n\
(default is cxx, except for PHP5 which uses cpp)\n\
-copyright - Display copyright notices\n\
-debug-classes - Display information about the classes found in the interface\n\
-debug-module <n>- Display module parse tree at stages 1-4, <n> is a csv list of stages\n\

View file

@ -43,7 +43,7 @@
#include <errno.h>
static const char *usage = "\
PHP Options (available with -php)\n\
PHP Options (available with -php7)\n\
-noproxy - Don't generate proxy classes.\n\
-prefix <prefix> - Prepend <prefix> to all class names in PHP wrappers\n\
\n";
@ -100,6 +100,11 @@ static String *s_oowrappers;
static String *s_fakeoowrappers;
static String *s_phpclasses;
/* To reduce code size (generated and compiled) we only want to emit each
* different arginfo once, so we need to track which have been used.
*/
static Hash *arginfo_used;
/* Variables for using PHP classes */
static Node *current_class = 0;
@ -129,6 +134,7 @@ extern "C" {
static void SwigPHP_emit_resource_registrations() {
Iterator ki;
bool emitted_default_dtor = false;
if (!zend_types)
return;
@ -140,9 +146,7 @@ static void SwigPHP_emit_resource_registrations() {
DOH *key = ki.key;
Node *class_node = ki.item;
String *human_name = key;
// Write out destructor function header
Printf(s_wrappers, "static ZEND_RSRC_DTOR_FUNC(_wrap_destroy%s) {\n", key);
String *rsrc_dtor_name = NULL;
// write out body
if (class_node != NOTCLASS) {
@ -152,51 +156,42 @@ static void SwigPHP_emit_resource_registrations() {
human_name = Getattr(class_node, "name");
// Do we have a known destructor for this type?
if (destructor) {
Printf(s_wrappers, " %s(rsrc, SWIGTYPE%s->name TSRMLS_CC);\n", destructor, key);
} else {
Printf(s_wrappers, " /* No destructor for class %s */\n", human_name);
Printf(s_wrappers, " efree(rsrc->ptr);\n");
rsrc_dtor_name = NewStringf("_wrap_destroy%s", key);
// Write out custom destructor function
Printf(s_wrappers, "static ZEND_RSRC_DTOR_FUNC(%s) {\n", rsrc_dtor_name);
Printf(s_wrappers, " %s(res, SWIGTYPE%s->name);\n", destructor, key);
Printf(s_wrappers, "}\n");
}
} else {
Printf(s_wrappers, " /* No destructor for simple type %s */\n", key);
Printf(s_wrappers, " efree(rsrc->ptr);\n");
}
// close function
Printf(s_wrappers, "}\n");
if (!rsrc_dtor_name) {
rsrc_dtor_name = NewString("_swig_default_rsrc_destroy");
if (!emitted_default_dtor) {
// Write out custom destructor function
Printf(s_wrappers, "static ZEND_RSRC_DTOR_FUNC(%s) {\n", rsrc_dtor_name);
Printf(s_wrappers, " efree(res->ptr);\n");
Printf(s_wrappers, "}\n");
emitted_default_dtor = true;
}
}
// declare le_swig_<mangled> to store php registration
Printf(s_vdecl, "static int le_swig_%s=0; /* handle for %s */\n", key, human_name);
// register with php
Printf(s_oinit, "le_swig_%s=zend_register_list_destructors_ex"
"(_wrap_destroy%s,NULL,(char *)(SWIGTYPE%s->name),module_number);\n", key, key, key);
"(%s, NULL, SWIGTYPE%s->name, module_number);\n", key, rsrc_dtor_name, key);
// store php type in class struct
Printf(s_oinit, "SWIG_TypeClientData(SWIGTYPE%s,&le_swig_%s);\n", key, key);
Delete(rsrc_dtor_name);
ki = Next(ki);
}
}
class PHP : public Language {
String *emit_action(Node *n) {
// Adjust wrap:action to add TSRMLS_CC.
String * action = Getattr(n, "wrap:action");
if (action) {
char * p = Strstr(action, "Swig::DirectorPureVirtualException::raise(\"");
if (p) {
p += strlen("Swig::DirectorPureVirtualException::raise(\"");
p = strchr(p, '"');
if (p) {
++p;
Insert(action, (int)(p - Char(action)), " TSRMLS_CC");
}
}
}
return ::emit_action(n);
}
public:
PHP() {
director_language = 1;
@ -208,7 +203,6 @@ public:
virtual void main(int argc, char *argv[]) {
SWIG_library_directory("php");
SWIG_config_cppext("cpp");
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-prefix") == 0) {
@ -225,25 +219,11 @@ public:
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-help") == 0) {
fputs(usage, stdout);
} else if (strcmp(argv[i], "-make") == 0 ||
strcmp(argv[i], "-withc") == 0 ||
strcmp(argv[i], "-withcxx") == 0) {
Printf(stderr, "*** %s is no longer supported.\n", argv[i]);
SWIG_exit(EXIT_FAILURE);
} else if (strcmp(argv[i], "-phpfull") == 0 ||
strcmp(argv[i], "-withlibs") == 0 ||
strcmp(argv[i], "-withincs") == 0) {
Printf(stderr, "*** %s is no longer supported.\n*** We recommend building as a dynamically loadable module.\n", argv[i]);
SWIG_exit(EXIT_FAILURE);
} else if (strcmp(argv[i], "-dlname") == 0) {
Printf(stderr, "*** -dlname is no longer supported.\n*** If you want to change the module name, use -module instead.\n");
SWIG_exit(EXIT_FAILURE);
}
}
Preprocessor_define("SWIGPHP 1", 0);
// SWIGPHP5 is deprecated, and no longer documented.
Preprocessor_define("SWIGPHP5 1", 0);
Preprocessor_define("SWIGPHP7 1", 0);
SWIG_typemap_lang("php");
SWIG_config_file("php.swg");
allow_overloading();
@ -267,7 +247,7 @@ public:
}
/* Set comparison with null for ConstructorToFunction */
setSubclassInstanceCheck(NewString("$arg->type != IS_NULL"));
setSubclassInstanceCheck(NewString("Z_TYPE_P($arg) != IS_NULL"));
/* Initialize all of the output files */
String *outfile = Getattr(n, "outfile");
@ -282,14 +262,14 @@ public:
f_runtime = NewStringEmpty();
/* sections of the output file */
s_init = NewString("/* init section */\n");
r_init = NewString("/* rinit section */\n");
s_shutdown = NewString("/* shutdown section */\n");
r_shutdown = NewString("/* rshutdown section */\n");
s_init = NewStringEmpty();
r_init = NewStringEmpty();
s_shutdown = NewStringEmpty();
r_shutdown = NewStringEmpty();
s_header = NewString("/* header section */\n");
s_wrappers = NewString("/* wrapper section */\n");
/* subsections of the init section */
s_vinit = NewString("/* vinit subsection */\n");
s_vinit = NewStringEmpty();
s_vdecl = NewString("/* vdecl subsection */\n");
s_cinit = NewString("/* cinit subsection */\n");
s_oinit = NewString("/* oinit subsection */\n");
@ -382,7 +362,7 @@ public:
/* Initialize the rest of the module */
Printf(s_oinit, "ZEND_INIT_MODULE_GLOBALS(%s, %s_init_globals, %s_destroy_globals);\n", module, module, module);
Printf(s_oinit, "ZEND_INIT_MODULE_GLOBALS(%s, %s_init_globals, NULL);\n", module, module);
/* start the header section */
Printf(s_header, "ZEND_BEGIN_MODULE_GLOBALS(%s)\n", module);
@ -390,21 +370,16 @@ public:
Printf(s_header, "int error_code;\n");
Printf(s_header, "ZEND_END_MODULE_GLOBALS(%s)\n", module);
Printf(s_header, "ZEND_DECLARE_MODULE_GLOBALS(%s)\n", module);
Printf(s_header, "#ifdef ZTS\n");
Printf(s_header, "#define SWIG_ErrorMsg() TSRMG(%s_globals_id, zend_%s_globals *, error_msg )\n", module, module);
Printf(s_header, "#define SWIG_ErrorCode() TSRMG(%s_globals_id, zend_%s_globals *, error_code )\n", module, module);
Printf(s_header, "#else\n");
Printf(s_header, "#define SWIG_ErrorMsg() (%s_globals.error_msg)\n", module);
Printf(s_header, "#define SWIG_ErrorCode() (%s_globals.error_code)\n", module);
Printf(s_header, "#endif\n\n");
/* The following can't go in Lib/php/phprun.swg as it uses SWIG_ErrorMsg(), etc
* which has to be dynamically generated as it depends on the module name.
*/
Append(s_header, "#ifdef __GNUC__\n");
Append(s_header, "static void SWIG_FAIL(TSRMLS_D) __attribute__ ((__noreturn__));\n");
Append(s_header, "static void SWIG_FAIL(void) __attribute__ ((__noreturn__));\n");
Append(s_header, "#endif\n\n");
Append(s_header, "static void SWIG_FAIL(TSRMLS_D) {\n");
Append(s_header, "static void SWIG_FAIL(void) {\n");
Append(s_header, " zend_error(SWIG_ErrorCode(), \"%s\", SWIG_ErrorMsg());\n");
// zend_error() should never return with the parameters we pass, but if it
// does, we really don't want to let SWIG_FAIL() return. This also avoids
@ -417,41 +392,36 @@ public:
Printf(s_header, " globals->error_code = default_error_code;\n");
Printf(s_header, "}\n");
Printf(s_header, "static void %s_destroy_globals(zend_%s_globals * globals) { (void)globals; }\n", module, module);
Printf(s_header, "\n");
Printf(s_header, "static void SWIG_ResetError(TSRMLS_D) {\n");
Printf(s_header, "static void SWIG_ResetError(void) {\n");
Printf(s_header, " SWIG_ErrorMsg() = default_error_msg;\n");
Printf(s_header, " SWIG_ErrorCode() = default_error_code;\n");
Printf(s_header, "}\n");
Append(s_header, "\n");
Printf(s_header, "ZEND_NAMED_FUNCTION(_wrap_swig_%s_alter_newobject) {\n", module);
Append(s_header, " zval **args[2];\n");
Append(s_header, " zval args[2];\n");
Append(s_header, " swig_object_wrapper *value;\n");
Append(s_header, " int type;\n");
Append(s_header, "\n");
Append(s_header, " SWIG_ResetError(TSRMLS_C);\n");
Append(s_header, " SWIG_ResetError();\n");
Append(s_header, " if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_array_ex(2, args) != SUCCESS) {\n");
Append(s_header, " WRONG_PARAM_COUNT;\n");
Append(s_header, " }\n");
Append(s_header, "\n");
Append(s_header, " value = (swig_object_wrapper *) zend_list_find((*args[0])->value.lval, &type);\n");
Append(s_header, " value->newobject = zval_is_true(*args[1]);\n");
Append(s_header, " value = (swig_object_wrapper *) Z_RES_VAL(args[0]);\n");
Append(s_header, " value->newobject = zval_is_true(&args[1]);\n");
Append(s_header, "\n");
Append(s_header, " return;\n");
Append(s_header, "}\n");
Printf(s_header, "ZEND_NAMED_FUNCTION(_wrap_swig_%s_get_newobject) {\n", module);
Append(s_header, " zval **args[1];\n");
Append(s_header, " zval args[1];\n");
Append(s_header, " swig_object_wrapper *value;\n");
Append(s_header, " int type;\n");
Append(s_header, "\n");
Append(s_header, " SWIG_ResetError(TSRMLS_C);\n");
Append(s_header, " SWIG_ResetError();\n");
Append(s_header, " if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, args) != SUCCESS) {\n");
Append(s_header, " WRONG_PARAM_COUNT;\n");
Append(s_header, " }\n");
Append(s_header, "\n");
Append(s_header, " value = (swig_object_wrapper *) zend_list_find((*args[0])->value.lval, &type);\n");
Append(s_header, " value = (swig_object_wrapper *) Z_RES_VAL(args[0]);\n");
Append(s_header, " RETVAL_LONG(value->newobject);\n");
Append(s_header, "\n");
Append(s_header, " return;\n");
@ -496,17 +466,10 @@ public:
Printf(f_h, "#else\n");
Printf(f_h, "# define PHP_%s_API\n", cap_module);
Printf(f_h, "#endif\n\n");
Printf(f_h, "#ifdef ZTS\n");
Printf(f_h, "#include \"TSRM.h\"\n");
Printf(f_h, "#endif\n\n");
Printf(f_h, "PHP_MINIT_FUNCTION(%s);\n", module);
Printf(f_h, "PHP_MSHUTDOWN_FUNCTION(%s);\n", module);
Printf(f_h, "PHP_RINIT_FUNCTION(%s);\n", module);
Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module);
Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n\n", module);
/* start the arginfo section */
s_arginfo = NewString("/* arginfo subsection */\n");
arginfo_used = NewHash();
/* start the function entry section */
s_entry = NewString("/* entry subsection */\n");
@ -518,45 +481,66 @@ public:
Printf(s_entry, "/* Every non-class user visible function must have an entry here */\n");
Printf(s_entry, "static zend_function_entry %s_functions[] = {\n", module);
/* start the init section */
Append(s_init, "#if ZEND_MODULE_API_NO <= 20090626\n");
Append(s_init, "#undef ZEND_MODULE_BUILD_ID\n");
Append(s_init, "#define ZEND_MODULE_BUILD_ID (char*)\"API\" ZEND_TOSTR(ZEND_MODULE_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA\n");
Append(s_init, "#endif\n");
Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n", NIL);
Printf(s_init, " STANDARD_MODULE_HEADER,\n");
Printf(s_init, " (char*)\"%s\",\n", module);
Printf(s_init, " %s_functions,\n", module);
Printf(s_init, " PHP_MINIT(%s),\n", module);
Printf(s_init, " PHP_MSHUTDOWN(%s),\n", module);
Printf(s_init, " PHP_RINIT(%s),\n", module);
Printf(s_init, " PHP_RSHUTDOWN(%s),\n", module);
Printf(s_init, " PHP_MINFO(%s),\n", module);
Printf(s_init, " NO_VERSION_YET,\n");
Printf(s_init, " STANDARD_MODULE_PROPERTIES\n");
Printf(s_init, "};\n");
Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module);
/* Emit all of the code */
Language::top(n);
Printf(s_init, "#ifdef __cplusplus\n");
Printf(s_init, "extern \"C\" {\n");
Printf(s_init, "#endif\n");
// We want to write "SWIGEXPORT ZEND_GET_MODULE(%s)" but ZEND_GET_MODULE
// in PHP5 has "extern "C" { ... }" around it so we can't do that.
Printf(s_init, "SWIGEXPORT zend_module_entry *get_module(void) { return &%s_module_entry; }\n", module);
Printf(s_init, "#ifdef __cplusplus\n");
Printf(s_init, "}\n");
Printf(s_init, "#endif\n\n");
SwigPHP_emit_resource_registrations();
/* start the init section */
{
String * s_init_old = s_init;
s_init = NewString("/* init section */\n");
Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n", NIL);
Printf(s_init, " STANDARD_MODULE_HEADER,\n");
Printf(s_init, " \"%s\",\n", module);
Printf(s_init, " %s_functions,\n", module);
Printf(s_init, " PHP_MINIT(%s),\n", module);
if (Len(s_shutdown) > 0) {
Printf(s_init, " PHP_MSHUTDOWN(%s),\n", module);
} else {
Printf(s_init, " NULL, /* No MSHUTDOWN code */\n");
}
if (Len(r_init) > 0 || Len(s_vinit) > 0) {
Printf(s_init, " PHP_RINIT(%s),\n", module);
} else {
Printf(s_init, " NULL, /* No RINIT code */\n");
}
if (Len(r_shutdown) > 0) {
Printf(s_init, " PHP_RSHUTDOWN(%s),\n", module);
} else {
Printf(s_init, " NULL, /* No RSHUTDOWN code */\n");
}
if (Len(pragma_phpinfo) > 0) {
Printf(s_init, " PHP_MINFO(%s),\n", module);
} else {
Printf(s_init, " NULL, /* No MINFO code */\n");
}
Printf(s_init, " NO_VERSION_YET,\n");
Printf(s_init, " STANDARD_MODULE_PROPERTIES\n");
Printf(s_init, "};\n");
Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module);
Printf(s_init, "#ifdef __cplusplus\n");
Printf(s_init, "extern \"C\" {\n");
Printf(s_init, "#endif\n");
// We want to write "SWIGEXPORT ZEND_GET_MODULE(%s)" but ZEND_GET_MODULE
// in PHP5 has "extern "C" { ... }" around it so we can't do that.
Printf(s_init, "SWIGEXPORT zend_module_entry *get_module(void) { return &%s_module_entry; }\n", module);
Printf(s_init, "#ifdef __cplusplus\n");
Printf(s_init, "}\n");
Printf(s_init, "#endif\n\n");
Printf(s_init, "#define SWIG_php_minit PHP_MINIT_FUNCTION(%s)\n\n", module);
Printv(s_init, s_init_old, NIL);
Delete(s_init_old);
}
/* We have to register the constants before they are (possibly) used
* by the pointer typemaps. This all needs re-arranging really as
* things are being called in the wrong order
*/
Printf(s_init, "#define SWIG_php_minit PHP_MINIT_FUNCTION(%s)\n", module);
/* Emit all of the code */
Language::top(n);
SwigPHP_emit_resource_registrations();
// Printv(s_init,s_resourcetypes,NIL);
/* We need this after all classes written out by ::top */
Printf(s_oinit, "CG(active_class_entry) = NULL;\n");
@ -573,38 +557,66 @@ public:
Printf(s_init, "}\n\n");
// Now do REQUEST init which holds any user specified %rinit, and also vinit
Printf(s_init, "PHP_RINIT_FUNCTION(%s)\n{\n", module);
Printf(s_init, "%s\n", r_init);
if (Len(r_init) > 0 || Len(s_vinit) > 0) {
Printf(f_h, "PHP_RINIT_FUNCTION(%s);\n", module);
/* finish our init section which will have been used by class wrappers */
Printf(s_vinit, "/* end vinit subsection */\n");
Printf(s_init, "%s\n", s_vinit);
Clear(s_vinit);
Delete(s_vinit);
Printf(s_init, "PHP_RINIT_FUNCTION(%s)\n{\n", module);
if (Len(r_init) > 0) {
Printv(s_init,
"/* rinit section */\n",
r_init, "\n",
NIL);
}
Printf(s_init, " return SUCCESS;\n");
Printf(s_init, "}\n\n");
if (Len(s_vinit) > 0) {
/* finish our init section which will have been used by class wrappers */
Printv(s_init,
"/* vinit subsection */\n",
s_vinit, "\n"
"/* end vinit subsection */\n",
NIL);
Clear(s_vinit);
}
Delete(s_vinit);
Printv(s_init, "PHP_MSHUTDOWN_FUNCTION(", module, ")\n"
"{\n",
s_shutdown,
"#ifdef ZTS\n"
" ts_free_id(", module, "_globals_id);\n"
"#endif\n"
" return SUCCESS;\n"
"}\n\n", NIL);
Printf(s_init, " return SUCCESS;\n");
Printf(s_init, "}\n\n");
}
Printf(s_init, "PHP_RSHUTDOWN_FUNCTION(%s)\n{\n", module);
Printf(s_init, "%s\n", r_shutdown);
Printf(s_init, " return SUCCESS;\n");
Printf(s_init, "}\n\n");
Printf(f_h, "PHP_MINIT_FUNCTION(%s);\n", module);
if (Len(s_shutdown) > 0) {
Printf(f_h, "PHP_MSHUTDOWN_FUNCTION(%s);\n", module);
Printv(s_init, "PHP_MSHUTDOWN_FUNCTION(", module, ")\n"
"/* shutdown section */\n"
"{\n",
s_shutdown,
" return SUCCESS;\n"
"}\n\n", NIL);
}
if (Len(r_shutdown) > 0) {
Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module);
Printf(s_init, "PHP_RSHUTDOWN_FUNCTION(%s)\n{\n", module);
Printf(s_init, "/* rshutdown section */\n");
Printf(s_init, "%s\n", r_shutdown);
Printf(s_init, " return SUCCESS;\n");
Printf(s_init, "}\n\n");
}
if (Len(pragma_phpinfo) > 0) {
Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n", module);
Printf(s_init, "PHP_MINFO_FUNCTION(%s)\n{\n", module);
Printf(s_init, "%s", pragma_phpinfo);
Printf(s_init, "}\n");
}
Printf(s_init, "PHP_MINFO_FUNCTION(%s)\n{\n", module);
Printf(s_init, "%s", pragma_phpinfo);
Printf(s_init, "}\n");
Printf(s_init, "/* end init section */\n");
Printf(f_h, "#endif /* PHP_%s_H */\n", cap_module);
Printf(f_h, "\n#endif /* PHP_%s_H */\n", cap_module);
Delete(f_h);
@ -648,6 +660,7 @@ public:
Delete(s_arginfo);
Delete(f_runtime);
Delete(f_begin);
Delete(arginfo_used);
Printf(f_phpcode, "%s\n%s\n", pragma_incl, pragma_code);
if (s_fakeoowrappers) {
@ -667,22 +680,36 @@ public:
void create_command(String *cname, String *iname, Node *n) {
// This is for the single main zend_function_entry record
Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", iname);
String * s = cs_entry;
if (!s) s = s_entry;
Printf(s, " SWIG_ZEND_NAMED_FE(%(lower)s,%s,swig_arginfo_%(lower)s)\n", cname, iname, cname);
// This is the above referenced arginfo structure.
// We want to only emit each different arginfo once, as that reduces the
// size of both the generated source code and the compiled extension
// module. To do this, we name the arginfo to encode the number of
// parameters and which (if any) are passed by reference by using a
// sequence of 0s (for non-reference) and 1s (for by references).
ParmList *l = Getattr(n, "parms");
Printf(s_arginfo, "ZEND_BEGIN_ARG_INFO_EX(swig_arginfo_%(lower)s, 0, 0, 0)\n", cname);
String * arginfo_code = NewStringEmpty();
for (Parm *p = l; p; p = Getattr(p, "tmap:in:next")) {
/* Ignored parameters */
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
continue;
}
int byref = GetFlag(p, "tmap:in:byref");
Printf(s_arginfo, " ZEND_ARG_PASS_INFO(%d)\n", byref);
Append(arginfo_code, GetFlag(p, "tmap:in:byref") ? "1" : "0");
}
Printf(s_arginfo, "ZEND_END_ARG_INFO()\n");
if (!GetFlag(arginfo_used, arginfo_code)) {
// Not had this one before, so emit it.
SetFlag(arginfo_used, arginfo_code);
Printf(s_arginfo, "ZEND_BEGIN_ARG_INFO_EX(swig_arginfo_%s, 0, 0, 0)\n", arginfo_code);
for (const char * p = Char(arginfo_code); *p; ++p) {
Printf(s_arginfo, " ZEND_ARG_PASS_INFO(%c)\n", *p);
}
Printf(s_arginfo, "ZEND_END_ARG_INFO()\n");
}
String * s = cs_entry;
if (!s) s = s_entry;
Printf(s, " SWIG_ZEND_NAMED_FE(%(lower)s,%s,swig_arginfo_%s)\n", cname, iname, arginfo_code);
Delete(arginfo_code);
}
/* ------------------------------------------------------------
@ -710,12 +737,12 @@ public:
Wrapper_add_local(f, "argc", "int argc");
Printf(tmp, "zval **argv[%d]", maxargs);
Printf(tmp, "zval argv[%d]", maxargs);
Wrapper_add_local(f, "argv", tmp);
Printf(f->code, "argc = ZEND_NUM_ARGS();\n");
Printf(f->code, "zend_get_parameters_array_ex(argc,argv);\n");
Printf(f->code, "zend_get_parameters_array_ex(argc, argv);\n");
Replaceall(dispatch, "$args", "self,args");
@ -723,7 +750,7 @@ public:
Printf(f->code, "SWIG_ErrorCode() = E_ERROR;\n");
Printf(f->code, "SWIG_ErrorMsg() = \"No matching function for overloaded '%s'\";\n", symname);
Printv(f->code, "SWIG_FAIL(TSRMLS_C);\n", NIL);
Printv(f->code, "SWIG_FAIL();\n", NIL);
Printv(f->code, "}\n", NIL);
Wrapper_print(f, s_wrappers);
@ -819,8 +846,8 @@ public:
if (num_arguments > 0) {
String *args = NewStringEmpty();
if (wrapperType == directorconstructor)
Wrapper_add_local(f, "arg0", "zval *arg0");
Printf(args, "zval **args[%d]", num_arguments);
Wrapper_add_local(f, "arg0", "zval * arg0");
Printf(args, "zval args[%d]", num_arguments);
Wrapper_add_local(f, "args", args);
Delete(args);
args = NULL;
@ -834,7 +861,7 @@ public:
// NOTE: possible we ignore this_ptr as a param for native constructor
Printf(f->code, "SWIG_ResetError(TSRMLS_C);\n");
Printf(f->code, "SWIG_ResetError();\n");
if (numopt > 0) { // membervariable wrappers do not have optional args
Wrapper_add_local(f, "arg_count", "int arg_count");
@ -851,7 +878,7 @@ public:
Printf(f->code, "WRONG_PARAM_COUNT;\n}\n\n");
}
if (wrapperType == directorconstructor)
Printf(f->code, "arg0 = *args[0];\n \n");
Printf(f->code, "arg0 = &args[0];\n \n");
/* Now convert from PHP to C variables */
// At this point, argcount if used is the number of deliberately passed args
@ -891,7 +918,7 @@ public:
}
if ((tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$source", source);
Replaceall(tm, "$source", &source);
Replaceall(tm, "$target", ln);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
@ -915,7 +942,7 @@ public:
if (is_member_director(n)) {
Wrapper_add_local(f, "upcall", "bool upcall = false");
Printf(f->code, "upcall = !Swig::Director::swig_is_overridden_method((char *)\"%s%s\", (char *)\"%s\" TSRMLS_CC);\n",
Printf(f->code, "upcall = !Swig::Director::swig_is_overridden_method(\"%s%s\", \"%s\");\n",
prefix, Swig_class_name(Swig_methodclass(n)), name);
}
@ -1006,7 +1033,7 @@ public:
/* Error handling code */
Printf(f->code, "fail:\n");
Printv(f->code, cleanup, NIL);
Append(f->code, "SWIG_FAIL(TSRMLS_C);\n");
Append(f->code, "SWIG_FAIL();\n");
Printf(f->code, "}\n");
@ -1056,6 +1083,7 @@ public:
bool handle_as_overload = false;
String **arg_names;
String **arg_values;
unsigned char * byref;
// Method or static method or plain function.
const char *methodname = 0;
String *output = s_oowrappers;
@ -1196,7 +1224,8 @@ public:
}
arg_values = (String **) malloc(max_num_of_arguments * sizeof(String *));
if (!arg_values) {
byref = (unsigned char *) malloc(max_num_of_arguments);
if (!arg_values || !byref) {
/* FIXME: How should this be handled? The rest of SWIG just seems
* to not bother checking for malloc failing! */
fprintf(stderr, "Malloc failed!\n");
@ -1204,6 +1233,7 @@ public:
}
for (i = 0; i < max_num_of_arguments; ++i) {
arg_values[i] = NULL;
byref[i] = false;
}
Node *o;
@ -1223,6 +1253,7 @@ public:
continue;
}
assert(0 <= argno && argno < max_num_of_arguments);
byref[argno] = GetFlag(p, "tmap:in:byref");
String *&pname = arg_names[argno];
const char *pname_cstr = GetChar(p, "name");
// Just get rid of the C++ namespace part for now.
@ -1471,6 +1502,7 @@ public:
Printf(args, ",");
if (i || wrapperType == memberfn)
Printf(invoke, ",");
if (byref[i]) Printf(args, "&");
String *value = arg_values[i];
if (value) {
const char *v = Char(value);
@ -1479,6 +1511,9 @@ public:
Replaceall(value, "$", "\\$");
}
Printf(args, "$%s=%s", arg_names[i], value);
} else if (constructor && i >= 1 && i < min_num_of_arguments) {
// We need to be able to call __construct($resource).
Printf(args, "$%s=null", arg_names[i]);
} else {
Printf(args, "$%s", arg_names[i]);
}
@ -1499,6 +1534,15 @@ public:
Printf(invoke_args, ",");
}
Printf(invoke_args, "%s", args);
if (constructor && min_num_of_arguments > 1) {
// We need to be able to call __construct($resource).
Clear(args);
Printf(args, "$%s", arg_names[0]);
for (i = 1; i < min_num_of_arguments; ++i) {
Printf(args, ",");
Printf(args, "$%s=null", arg_names[i]);
}
}
bool had_a_case = false;
int last_handled_i = i - 1;
for (; i < max_num_of_arguments; ++i) {
@ -2290,15 +2334,15 @@ done:
Delete(director_ctor_code);
director_ctor_code = NewStringEmpty();
director_prot_ctor_code = NewStringEmpty();
Printf(director_ctor_code, "if ( arg0->type == IS_NULL ) { /* not subclassed */\n");
Printf(director_prot_ctor_code, "if ( arg0->type == IS_NULL ) { /* not subclassed */\n");
Printf(director_ctor_code, "if (Z_TYPE_P(arg0) == IS_NULL) { /* not subclassed */\n");
Printf(director_prot_ctor_code, "if (Z_TYPE_P(arg0) == IS_NULL) { /* not subclassed */\n");
Printf(director_ctor_code, " %s = (%s *)new %s(%s);\n", Swig_cresult_name(), ctype, ctype, args);
Printf(director_prot_ctor_code, " SWIG_PHP_Error(E_ERROR, \"accessing abstract class or protected constructor\");\n", name, name, args);
if (i) {
Insert(args, 0, ", ");
}
Printf(director_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0 TSRMLS_CC%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_prot_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0 TSRMLS_CC%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_prot_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Delete(args);
wrapperType = directorconstructor;
@ -2328,9 +2372,9 @@ done:
Wrapper *f = NewWrapper();
Printf(f->def, "/* This function is designed to be called by the zend list destructors */\n");
Printf(f->def, "/* to typecast and do the actual destruction */\n");
Printf(f->def, "static void %s(zend_rsrc_list_entry *rsrc, const char *type_name TSRMLS_DC) {\n", destructorname);
Printf(f->def, "static void %s(zend_resource *res, const char *type_name) {\n", destructorname);
Wrapper_add_localv(f, "value", "swig_object_wrapper *value=(swig_object_wrapper *) rsrc->ptr", NIL);
Wrapper_add_localv(f, "value", "swig_object_wrapper *value=(swig_object_wrapper *) res->ptr", NIL);
Wrapper_add_localv(f, "ptr", "void *ptr=value->ptr", NIL);
Wrapper_add_localv(f, "newobject", "int newobject=value->newobject", NIL);
@ -2348,7 +2392,7 @@ done:
Printf(f->code, " efree(value);\n");
Printf(f->code, " if (! newobject) return; /* can't delete it! */\n");
Printf(f->code, " arg1 = (%s)SWIG_ZTS_ConvertResourceData(ptr,type_name,SWIGTYPE%s TSRMLS_CC);\n", SwigType_lstr(pt, 0), SwigType_manglestr(pt));
Printf(f->code, " arg1 = (%s)SWIG_ConvertResourceData(ptr, type_name, SWIGTYPE%s);\n", SwigType_lstr(pt, 0), SwigType_manglestr(pt));
Printf(f->code, " if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name));
Setattr(n, "wrap:name", destructorname);
@ -2360,7 +2404,7 @@ done:
Printf(f->code, "thrown:\n");
Append(f->code, "return;\n");
Append(f->code, "fail:\n");
Append(f->code, "SWIG_FAIL(TSRMLS_C);\n");
Append(f->code, "SWIG_FAIL();\n");
Printf(f->code, "}\n");
Wrapper_print(f, s_wrappers);
@ -2420,16 +2464,9 @@ done:
String *call;
String *basetype = Getattr(parent, "classtype");
// We put TSRMLS_DC after the self parameter in order to cope with
// any default parameters.
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
const char * p = Char(target);
const char * comma = strchr(p, ',');
int ins = comma ? (int)(comma - p) : Len(target) - 1;
Insert(target, ins, " TSRMLS_DC");
call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, Swig::Director(self TSRMLS_CC) {", classname, target, call);
Printf(w->def, "%s::%s: %s, Swig::Director(self) {", classname, target, call);
Append(w->def, "}");
Delete(target);
Wrapper_print(w, f_directors);
@ -2439,14 +2476,7 @@ done:
/* constructor header */
{
// We put TSRMLS_DC after the self parameter in order to cope with
// any default parameters.
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
const char * p = Char(target);
const char * comma = strchr(p, ',');
int ins = comma ? (int)(comma - p) : Len(target) - 1;
Insert(target, ins, " TSRMLS_DC");
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
@ -2531,8 +2561,6 @@ done:
Append(w->def, " {");
Append(declaration, ";\n");
Printf(w->code, "TSRMLS_FETCH_FROM_CTX(swig_zts_ctx);\n");
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
@ -2553,7 +2581,7 @@ done:
Printf(w->code, "%s;\n", super_call);
Delete(super_call);
} else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\" TSRMLS_CC);\n", SwigType_namestr(c_classname),
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
SwigType_namestr(name));
}
} else {
@ -2568,7 +2596,6 @@ done:
Swig_typemap_attach_parms("directorargout", l, w);
Parm *p;
char source[256];
int outputs = 0;
if (!is_void)
@ -2592,16 +2619,11 @@ done:
if ((tm = Getattr(p, "tmap:directorin")) != 0) {
String *parse = Getattr(p, "tmap:directorin:parse");
if (!parse) {
sprintf(source, "obj%d", idx++);
String *input = NewStringf("&%s", source);
String *input = NewStringf("&args[%d]", idx++);
Setattr(p, "emit:directorinput", input);
Replaceall(tm, "$input", input);
Delete(input);
Replaceall(tm, "$owner", "0");
Printv(wrap_args, "zval ", source, ";\n", NIL);
Printf(wrap_args, "args[%d] = &%s;\n", idx - 1, source);
Printv(wrap_args, "INIT_ZVAL(", source, ");\n", NIL);
Printv(wrap_args, tm, "\n", NIL);
Putc('O', parse_args);
} else {
@ -2644,17 +2666,17 @@ done:
}
if (!idx) {
Printf(w->code, "zval **args = NULL;\n");
Printf(w->code, "zval *args = NULL;\n");
} else {
Printf(w->code, "zval *args[%d];\n", idx);
Printf(w->code, "zval args[%d];\n", idx);
}
Printf(w->code, "zval *%s, funcname;\n", Swig_cresult_name());
Append(w->code, "if (!swig_self) {\n");
Append(w->code, " SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");");
Append(w->code, "}\n\n");
Printf(w->code, "MAKE_STD_ZVAL(%s);\n", Swig_cresult_name());
// typemap_directorout testcase requires that 0 can be assigned to the
// variable named after the result of Swig_cresult_name(), so that can't
// be a zval - make it a pointer to one instead.
Printf(w->code, "zval swig_zval_result, swig_funcname;\n", Swig_cresult_name());
Printf(w->code, "zval * SWIGUNUSED %s = &swig_zval_result;\n", Swig_cresult_name());
const char * funcname = GetChar(n, "sym:name");
Printf(w->code, "ZVAL_STRINGL(&funcname, (char *)\"%s\", %d, 0);\n", funcname, strlen(funcname));
Printf(w->code, "ZVAL_STRINGL(&swig_funcname, \"%s\", %d);\n", funcname, strlen(funcname));
/* wrap complex arguments to zvals */
Printv(w->code, wrap_args, NIL);
@ -2662,8 +2684,8 @@ done:
if (error_used_in_typemap) {
Append(w->code, "error = ");
}
Append(w->code, "call_user_function(EG(function_table), (zval**)&swig_self, &funcname,");
Printf(w->code, " %s, %d, args TSRMLS_CC);\n", Swig_cresult_name(), idx);
Append(w->code, "call_user_function(EG(function_table), &swig_self, &swig_funcname,");
Printf(w->code, " &swig_zval_result, %d, args);\n", idx);
if (tm) {
Printv(w->code, Str(tm), "\n", NIL);
@ -2715,8 +2737,6 @@ done:
}
}
Printf(w->code, "FREE_ZVAL(%s);\n", Swig_cresult_name());
Delete(parse_args);
Delete(cleanup);
Delete(outarg);
@ -2738,7 +2758,7 @@ done:
}
Append(w->code, "fail:\n");
Append(w->code, "SWIG_FAIL(TSRMLS_C);\n");
Append(w->code, "SWIG_FAIL();\n");
Append(w->code, "}\n");
// We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
@ -2783,7 +2803,8 @@ static PHP *maininstance = 0;
// We use this function to be able to write out zend_register_list_destructor_ex
// lines for most things in the type table
// NOTE: it's a function NOT A PHP::METHOD
extern "C" void typetrace(const SwigType *ty, String *mangled, String *clientdata) {
extern "C" {
static void typetrace(const SwigType *ty, String *mangled, String *clientdata) {
Node *class_node;
if (!zend_types) {
zend_types = NewHash();
@ -2803,6 +2824,7 @@ extern "C" void typetrace(const SwigType *ty, String *mangled, String *clientdat
if (r_prevtracefunc)
(*r_prevtracefunc) (ty, mangled, (String *) clientdata);
}
}
/* -----------------------------------------------------------------------------
* new_swig_php() - Instantiate module
@ -2819,13 +2841,6 @@ static Language *new_swig_php() {
return maininstance;
}
extern "C" Language *swig_php4(void) {
Printf(stderr, "*** -php4 is no longer supported.\n"
"*** Either upgrade to PHP5 or use SWIG 1.3.36 or earlier.\n");
SWIG_exit(EXIT_FAILURE);
return NULL; // To avoid compiler warnings.
}
extern "C" Language *swig_php(void) {
return new_swig_php();
}

2858
Source/Modules/php5.cxx Normal file

File diff suppressed because it is too large Load diff

View file

@ -261,10 +261,9 @@ public:
rename = strip(name);
Printf(f_classInit, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
break;
case CLASS_CONST:
assert(false); // shouldn't have gotten here for CLASS_CONST nodes
default:
assert(false); // what is this?
case CLASS_CONST: // shouldn't have gotten here for CLASS_CONST nodes
default: // what is this?
assert(false);
}
Delete(rename);
}

View file

@ -44,7 +44,7 @@ static File *f_shadow_py = 0;
static String *f_shadow = 0;
static String *f_shadow_begin = 0;
static Hash *f_shadow_imports = 0;
static String *f_shadow_builtin_imports = 0;
static String *f_shadow_after_begin = 0;
static String *f_shadow_stubs = 0;
static Hash *builtin_getset = 0;
static Hash *builtin_closures = 0;
@ -565,6 +565,7 @@ public:
* interface file to enable director generation.
*/
String *mod_docstring = NULL;
String *moduleimport = NULL;
{
Node *mod = Getattr(n, "module");
if (mod) {
@ -605,6 +606,7 @@ public:
}
mod_docstring = Getattr(options, "docstring");
package = Getattr(options, "package");
moduleimport = Getattr(options, "moduleimport");
}
}
}
@ -779,6 +781,7 @@ public:
}
/* If shadow classing is enabled, we're going to change the module name to "_module" */
String *default_import_code = NewString("");
if (shadow) {
String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module));
// If we don't have an interface then change the module name X to _X
@ -796,7 +799,7 @@ public:
f_shadow = NewString("");
f_shadow_begin = NewString("");
f_shadow_imports = NewHash();
f_shadow_builtin_imports = NewString("");
f_shadow_after_begin = NewString("");
f_shadow_stubs = NewString("");
Swig_register_filebyname("shadow", f_shadow);
@ -808,19 +811,19 @@ public:
// follow PEP257 rules: https://www.python.org/dev/peps/pep-0257/
// reported by pep257: https://github.com/GreenSteam/pep257
bool multi_line_ds = Strchr(mod_docstring, '\n') != 0;
Printv(f_shadow, triple_double, multi_line_ds ? "\n":"", mod_docstring, multi_line_ds ? "\n":"", triple_double, "\n\n", NIL);
Printv(f_shadow_after_begin, "\n", triple_double, multi_line_ds ? "\n":"", mod_docstring, multi_line_ds ? "\n":"", triple_double, "\n", NIL);
}
Delete(mod_docstring);
mod_docstring = NULL;
}
Printv(f_shadow, "\nfrom sys import version_info as _swig_python_version_info\n", NULL);
Printv(default_import_code, "\nfrom sys import version_info as _swig_python_version_info\n", NULL);
if (!builtin && fastproxy) {
Printv(f_shadow, "if _swig_python_version_info >= (3, 0, 0):\n", NULL);
Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
Printv(f_shadow, "else:\n", NULL);
Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
Printv(default_import_code, "if _swig_python_version_info >= (3, 0, 0):\n", NULL);
Printf(default_import_code, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
Printv(default_import_code, "else:\n", NULL);
Printv(default_import_code, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
}
/* Import the C-extension module. This should be a relative import,
@ -840,42 +843,39 @@ public:
* ImportError then fallback and try and load just the module name from
* the global namespace.
*/
Printv(f_shadow, "if _swig_python_version_info >= (2, 7, 0):\n", NULL);
Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
Printv(f_shadow, tab8, "import importlib\n", NULL);
Printv(f_shadow, tab8, "pkg = __name__.rpartition('.')[0]\n", NULL);
Printf(f_shadow, tab8 "mname = '.'.join((pkg, '%s')).lstrip('.')\n",
module);
Printv(f_shadow, tab8, "try:\n", NULL);
Printv(f_shadow, tab8, tab4, "return importlib.import_module(mname)\n",
NULL);
Printv(f_shadow, tab8, "except ImportError:\n", NULL);
Printf(f_shadow, tab8 tab4 "return importlib.import_module('%s')\n",
module);
Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
Printv(f_shadow, "elif _swig_python_version_info >= (2, 6, 0):\n", NULL);
Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
Printv(f_shadow, tab8, "from os.path import dirname\n", NULL);
Printv(f_shadow, tab8, "import imp\n", NULL);
Printv(f_shadow, tab8, "fp = None\n", NULL);
Printv(f_shadow, tab8, "try:\n", NULL);
Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
Printf(f_shadow, tab8 "except ImportError:\n");
Printv(default_import_code, "if _swig_python_version_info >= (2, 7, 0):\n", NULL);
Printv(default_import_code, tab4, "def swig_import_helper():\n", NULL);
Printv(default_import_code, tab8, "import importlib\n", NULL);
Printv(default_import_code, tab8, "pkg = __name__.rpartition('.')[0]\n", NULL);
Printf(default_import_code, tab8 "mname = '.'.join((pkg, '%s')).lstrip('.')\n", module);
Printv(default_import_code, tab8, "try:\n", NULL);
Printv(default_import_code, tab8, tab4, "return importlib.import_module(mname)\n", NULL);
Printv(default_import_code, tab8, "except ImportError:\n", NULL);
Printf(default_import_code, tab8 tab4 "return importlib.import_module('%s')\n", module);
Printf(default_import_code, tab4 "%s = swig_import_helper()\n", module);
Printv(default_import_code, tab4, "del swig_import_helper\n", NULL);
Printv(default_import_code, "elif _swig_python_version_info >= (2, 6, 0):\n", NULL);
Printv(default_import_code, tab4, "def swig_import_helper():\n", NULL);
Printv(default_import_code, tab8, "from os.path import dirname\n", NULL);
Printv(default_import_code, tab8, "import imp\n", NULL);
Printv(default_import_code, tab8, "fp = None\n", NULL);
Printv(default_import_code, tab8, "try:\n", NULL);
Printf(default_import_code, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
Printf(default_import_code, tab8 "except ImportError:\n");
/* At here, the module may already loaded, so simply import it. */
Printf(f_shadow, tab4 tab8 "import %s\n", module);
Printf(f_shadow, tab4 tab8 "return %s\n", module);
Printv(f_shadow, tab8 "try:\n", NULL);
Printf(default_import_code, tab4 tab8 "import %s\n", module);
Printf(default_import_code, tab4 tab8 "return %s\n", module);
Printv(default_import_code, tab8 "try:\n", NULL);
/* imp.load_module() handles fp being None. */
Printf(f_shadow, tab4 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
Printv(f_shadow, tab8, "finally:\n", NULL);
Printv(f_shadow, tab4 tab8 "if fp is not None:\n", NULL);
Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL);
Printv(f_shadow, tab8, "return _mod\n", NULL);
Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
Printv(f_shadow, "else:\n", NULL);
Printf(f_shadow, tab4 "import %s\n", module);
Printf(default_import_code, tab4 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
Printv(default_import_code, tab8, "finally:\n", NULL);
Printv(default_import_code, tab4 tab8 "if fp is not None:\n", NULL);
Printv(default_import_code, tab8 tab8, "fp.close()\n", NULL);
Printv(default_import_code, tab8, "return _mod\n", NULL);
Printf(default_import_code, tab4 "%s = swig_import_helper()\n", module);
Printv(default_import_code, tab4, "del swig_import_helper\n", NULL);
Printv(default_import_code, "else:\n", NULL);
Printf(default_import_code, tab4 "import %s\n", module);
if (builtin) {
/*
@ -890,22 +890,22 @@ public:
* globals()[attr] = getattr(_foo, attr)
*
*/
Printf(f_shadow, "# pull in all the attributes from %s\n", module);
Printv(f_shadow, "if __name__.rpartition('.')[0] != '':\n", NULL);
Printv(f_shadow, tab4, "if _swig_python_version_info >= (2, 7, 0):\n", NULL);
Printv(f_shadow, tab8, "try:\n", NULL);
Printf(f_shadow, tab8 tab4 "from .%s import *\n", module);
Printv(f_shadow, tab8 "except ImportError:\n", NULL);
Printf(f_shadow, tab8 tab4 "from %s import *\n", module);
Printv(f_shadow, tab4, "else:\n", NULL);
Printf(f_shadow, tab8 "from %s import *\n", module);
Printv(f_shadow, "else:\n", NULL);
Printf(f_shadow, tab4 "from %s import *\n", module);
Printf(default_import_code, "# pull in all the attributes from %s\n", module);
Printv(default_import_code, "if __name__.rpartition('.')[0] != '':\n", NULL);
Printv(default_import_code, tab4, "if _swig_python_version_info >= (2, 7, 0):\n", NULL);
Printv(default_import_code, tab8, "try:\n", NULL);
Printf(default_import_code, tab8 tab4 "from .%s import *\n", module);
Printv(default_import_code, tab8 "except ImportError:\n", NULL);
Printf(default_import_code, tab8 tab4 "from %s import *\n", module);
Printv(default_import_code, tab4, "else:\n", NULL);
Printf(default_import_code, tab8 "from %s import *\n", module);
Printv(default_import_code, "else:\n", NULL);
Printf(default_import_code, tab4 "from %s import *\n", module);
}
/* Delete the _swig_python_version_info symbol since we don't use it elsewhere in the
* module. */
Printv(f_shadow, "del _swig_python_version_info\n", NULL);
Printv(default_import_code, "del _swig_python_version_info\n\n", NULL);
if (modern || !classic) {
Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n\n", NULL);
@ -1052,8 +1052,16 @@ public:
if (!modern && !classic) {
Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
}
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL);
if (Len(f_shadow_begin) > 0)
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
if (Len(f_shadow_after_begin) > 0)
Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL);
if (moduleimport) {
Replaceall(moduleimport, "$module", module);
Printv(f_shadow_py, "\n", moduleimport, "\n", NIL);
} else {
Printv(f_shadow_py, default_import_code, NIL);
}
Printv(f_shadow_py, f_shadow, "\n", NIL);
Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
Delete(f_shadow_py);
@ -1077,6 +1085,11 @@ public:
Printf(f_begin, "static PyTypeObject *builtin_bases[%d];\n\n", max_bases + 2);
Wrapper_pretty_print(f_init, f_begin);
Delete(default_import_code);
Delete(f_shadow_after_begin);
Delete(f_shadow_imports);
Delete(f_shadow_begin);
Delete(f_shadow);
Delete(f_header);
Delete(f_wrappers);
Delete(f_builtins);
@ -1385,7 +1398,7 @@ public:
String *_import = import_directive_string(package, pkg, modname, "_");
if (!GetFlagAttr(f_shadow_imports, _import)) {
String *import = import_directive_string(package, pkg, modname);
Printf(builtin ? f_shadow_builtin_imports : f_shadow, "%s", import);
Printf(builtin ? f_shadow_after_begin : f_shadow, "%s", import);
Delete(import);
SetFlag(f_shadow_imports, _import);
}

View file

@ -974,7 +974,9 @@ int R::OutputClassMemberTable(Hash *tb, File *out) {
String *key;
int i, n = Len(keys);
/* Loop over all the <Class>_set and <Class>_get entries in the table. */
/* This function checks for names ending in _set - perhaps it should */
/* use attributes of some other form, as it potentially clashes with */
/* methods ending in _set */
if(n && outputNamespaceInfo) {
Printf(s_namespace, "exportClasses(");
}
@ -984,9 +986,13 @@ int R::OutputClassMemberTable(Hash *tb, File *out) {
String *className = Getitem(el, 0);
char *ptr = Char(key);
ptr = &ptr[Len(key) - 3];
int isSet = strcmp(ptr, "set") == 0;
int klen = Len(key);
int isSet = 0;
if (klen > 4) {
ptr = &ptr[klen - 4];
isSet = strcmp(ptr, "_set") == 0;
}
// OutputArrayMethod(className, el, out);
OutputMemberReferenceMethod(className, isSet, el, out);
@ -1064,7 +1070,7 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
if (!isSet && varaccessor > 0) {
Printf(f->code, "%svaccessors = c(", tab8);
int vcount = 0;
int first = 1;
for(j = 0; j < numMems; j+=3) {
String *item = Getitem(el, j);
String *dup = Getitem(el, j + 1);
@ -1072,8 +1078,8 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
ptr = &ptr[Len(dup) - 3];
if (!strcmp(ptr, "get")) {
vcount++;
Printf(f->code, "'%s'%s", item, vcount < varaccessor ? ", " : "");
Printf(f->code, "%s'%s'", first ? "" : ", ", item);
first = 0;
}
}
Printf(f->code, ");\n");
@ -1273,7 +1279,9 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name,
if(isSet < 0) {
int n = Len(name);
char *ptr = Char(name);
isSet = Strcmp(NewString(&ptr[n-3]), "set") == 0;
if (n>4) {
isSet = Strcmp(NewString(&ptr[n-4]), "_set") == 0;
}
}
List *l = isSet ? class_member_set_functions : class_member_functions;
@ -1753,7 +1761,8 @@ int R::functionWrapper(Node *n) {
int n = Len(iname);
char *ptr = Char(iname);
bool isSet(Strcmp(NewString(&ptr[n-3]), "set") == 0);
bool isSet(0);
if (n > 4) isSet = Strcmp(NewString(&ptr[n-4]), "_set") == 0;
String *tmp = NewString("");

View file

@ -1419,9 +1419,8 @@ public:
case DESTRUCTOR:
case CLASS_CONST:
case STATIC_VAR:
assert(false); // Should not have gotten here for these types
default:
assert(false);
assert(false); // Should not have gotten here for these types
}
defineAliases(n, iname);
@ -3288,7 +3287,7 @@ public:
}
/* declare Ruby return value */
String *value_result = NewStringf("VALUE %s", Swig_cresult_name());
String *value_result = NewStringf("VALUE SWIGUNUSED %s", Swig_cresult_name());
Wrapper_add_local(w, Swig_cresult_name(), value_result);
Delete(value_result);

View file

@ -36,6 +36,7 @@ extern "C" {
Language *swig_java(void);
Language *swig_php(void);
Language *swig_php4(void);
Language *swig_php5(void);
Language *swig_ocaml(void);
Language *swig_octave(void);
Language *swig_pike(void);
@ -83,9 +84,10 @@ static swig_module modules[] = {
{"-octave", swig_octave, "Octave"},
{"-perl", swig_perl5, "Perl"},
{"-perl5", swig_perl5, 0},
{"-php", swig_php, "PHP"},
{"-php", swig_php5, 0},
{"-php4", swig_php4, 0},
{"-php5", swig_php, 0},
{"-php5", swig_php5, "PHP5"},
{"-php7", swig_php, "PHP7"},
{"-pike", swig_pike, "Pike"},
{"-python", swig_python, "Python"},
{"-r", swig_r, "R (aka GNU S)"},

View file

@ -566,6 +566,10 @@ class TypePass:private Dispatcher {
SwigType_typedef_class(rname);
Delete(rname);
/* SwigType_typedef_class(name); */
} else if (Strcmp(ttype, "cdecl") == 0) {
String *rname = SwigType_typedef_resolve_all(name);
SwigType_typedef_class(rname);
Delete(rname);
}
return SWIG_OK;
}

View file

@ -1459,7 +1459,7 @@ String *Preprocessor_parse(String *s) {
break;
}
state = 43;
/* no break intended here */
/* FALL THRU */
case 43:
/* Get preprocessor value */

View file

@ -404,7 +404,17 @@ DOH *Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType
}
Delete(cls);
}
/* A template-based class lookup, check name first */
/* Lookup a name within a templated-based class */
if (!rn) {
String *t_name = SwigType_istemplate_templateprefix(prefix);
if (t_name) {
Clear(tname);
Printf(tname, "%s::%s", t_name, name);
rn = name_object_get(namehash, tname, decl, ncdecl);
Delete(t_name);
}
}
/* Lookup a template-based name within a class */
if (!rn) {
String *t_name = SwigType_istemplate_templateprefix(name);
if (t_name)
@ -789,6 +799,8 @@ static int need_name_warning(Node *n) {
need = 0;
} else if (Getattr(n, "templatetype")) {
need = 0;
} else if (GetFlag(n, "parsing_template_declaration")) {
need = 0;
}
return need;
}

View file

@ -400,6 +400,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_typemap_clear(const_String_or_char_ptr tmap_method, ParmList *pattern);
extern int Swig_typemap_apply(ParmList *srcpat, ParmList *destpat);
extern void Swig_typemap_clear_apply(ParmList *pattern);
extern void Swig_typemap_replace_embedded_typemap(String *s, Node *file_line_node);
extern void Swig_typemap_debug(void);
extern void Swig_typemap_search_debug_set(void);
extern void Swig_typemap_used_debug_set(void);

View file

@ -518,7 +518,6 @@ void Swig_symbol_inherit(Symtab *s) {
void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
Node *append = 0;
Node *cn;
/* There are a few options for weak symbols. A "weak" symbol
is any symbol that can be replaced by another symbol in the C symbol
@ -1907,19 +1906,37 @@ SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) {
int len = Len(elements);
int i;
#ifdef SWIG_TEMPLATE_DEFTYPE_CACHE
static Hash *deftype_cache = 0;
String *scopetype = tscope ? NewStringf("%s::%s", Getattr(tscope, "name"), type)
static Hash *s_cache = 0;
Hash *scope_cache;
/* The lookup depends on the current scope and potential namespace qualification.
Looking up x in namespace y is not the same as looking up x::y in outer scope.
-> we use a 2-level hash: first scope and then symbol. */
String *scope_name = tscope
? Swig_symbol_qualifiedscopename(tscope)
: Swig_symbol_qualifiedscopename(current_symtab);
String *type_name = tscope
? NewStringf("%s::%s", Getattr(tscope, "name"), type)
: NewStringf("%s::%s", Swig_symbol_getscopename(), type);
if (!deftype_cache) {
deftype_cache = NewHash();
if (!scope_name) scope_name = NewString("::");
if (!s_cache) {
s_cache = NewHash();
}
if (scopetype) {
String *cres = Getattr(deftype_cache, scopetype);
scope_cache = Getattr(s_cache, scope_name);
if (scope_cache) {
String *cres = Getattr(scope_cache, type_name);
if (cres) {
Append(result, cres);
Delete(scopetype);
#ifdef SWIG_DEBUG
Printf(stderr, "cached deftype %s(%s) -> %s\n", type, scope_name, result);
#endif
Delete(type_name);
Delete(scope_name);
return result;
}
} else {
scope_cache = NewHash();
Setattr(s_cache, scope_name, scope_cache);
Delete(scope_name);
}
#endif
@ -2019,8 +2036,8 @@ SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) {
}
Delete(elements);
#ifdef SWIG_TEMPLATE_DEFTYPE_CACHE
Setattr(deftype_cache, scopetype, result);
Delete(scopetype);
Setattr(scope_cache, type_name, result);
Delete(type_name);
#endif
return result;

View file

@ -1876,6 +1876,21 @@ static List *split_embedded_typemap(String *s) {
return args;
}
/* -----------------------------------------------------------------------------
* Swig_typemap_replace_embedded_typemap()
*
* For special variable macro $typemap(...) expansion outside of typemaps.
* Only limited usage works as most typemap special variables ($1, $input etc)
* are not expanded correctly outside of typemaps.
* ----------------------------------------------------------------------------- */
void Swig_typemap_replace_embedded_typemap(String *s, Node *file_line_node) {
Setfile(s, Getfile(file_line_node));
Setline(s, Getline(file_line_node));
Replaceall(s, "$typemap", "$TYPEMAP");
replace_embedded_typemap(s, 0, 0, file_line_node);
}
/* -----------------------------------------------------------------------------
* replace_embedded_typemap()
*