Remove remnants of attempts to wrap to PHP global vars

This isn't really workable since PHP doesn't support intercepting
accesses to global variables (nor to static class properties, so
we can't wrap C/C++ global variables that way either).

The _get() and _set() function wrappers actually work and have
been generated for a very long time.
This commit is contained in:
Olly Betts 2021-04-17 05:59:18 +12:00
commit 2629764e3f
3 changed files with 16 additions and 69 deletions

View file

@ -306,8 +306,10 @@ print seki_get();
<p> <p>
SWIG supports global variables of all C datatypes including pointers SWIG supports global variables of all C datatypes including pointers
and complex objects. Additional types can be supported by using the and complex objects. To support additional types, you just need to
<tt>varinit</tt> typemap. supply the standard <tt>in</tt> and <tt>out</tt> typemaps, which get
used because of the wrapping as <tt>_get()</tt> and <tt>_set()</tt>
functions.
</p> </p>
<p> <p>

View file

@ -10,7 +10,6 @@
%include <phpinit.swg> // PHP initialization routine. %include <phpinit.swg> // PHP initialization routine.
%include <globalvar.i> // Global variables.
%include <const.i> %include <const.i>
// use %init %{ "/*code goes here*/ " %} // use %init %{ "/*code goes here*/ " %}

View file

@ -50,7 +50,6 @@ static String *s_init;
static String *r_init; // RINIT user code static String *r_init; // RINIT user code
static String *s_shutdown; // MSHUTDOWN user code static String *s_shutdown; // MSHUTDOWN user code
static String *r_shutdown; // RSHUTDOWN user code static String *r_shutdown; // RSHUTDOWN user code
static String *s_vinit; // varinit initialization code.
static String *s_vdecl; static String *s_vdecl;
static String *s_cinit; // consttab initialization code. static String *s_cinit; // consttab initialization code.
static String *s_oinit; static String *s_oinit;
@ -266,7 +265,6 @@ public:
s_header = NewString("/* header section */\n"); s_header = NewString("/* header section */\n");
s_wrappers = NewString("/* wrapper section */\n"); s_wrappers = NewString("/* wrapper section */\n");
/* subsections of the init section */ /* subsections of the init section */
s_vinit = NewStringEmpty();
s_vdecl = NewString("/* vdecl subsection */\n"); s_vdecl = NewString("/* vdecl subsection */\n");
s_cinit = NewString(" /* cinit subsection */\n"); s_cinit = NewString(" /* cinit subsection */\n");
s_oinit = NewString(" /* oinit subsection */\n"); s_oinit = NewString(" /* oinit subsection */\n");
@ -474,7 +472,7 @@ public:
} else { } else {
Printf(s_init, " NULL, /* No MSHUTDOWN code */\n"); Printf(s_init, " NULL, /* No MSHUTDOWN code */\n");
} }
if (Len(r_init) > 0 || Len(s_vinit) > 0) { if (Len(r_init) > 0) {
Printf(s_init, " PHP_RINIT(%s),\n", module); Printf(s_init, " PHP_RINIT(%s),\n", module);
} else { } else {
Printf(s_init, " NULL, /* No RINIT code */\n"); Printf(s_init, " NULL, /* No RINIT code */\n");
@ -535,27 +533,14 @@ public:
Printf(s_init, "}\n\n"); Printf(s_init, "}\n\n");
// Now do REQUEST init which holds any user specified %rinit, and also vinit // Now do REQUEST init which holds any user specified %rinit, and also vinit
if (Len(r_init) > 0 || Len(s_vinit) > 0) { if (Len(r_init) > 0) {
Printf(f_h, "PHP_RINIT_FUNCTION(%s);\n", module); Printf(f_h, "PHP_RINIT_FUNCTION(%s);\n", module);
Printf(s_init, "PHP_RINIT_FUNCTION(%s)\n{\n", module); Printf(s_init, "PHP_RINIT_FUNCTION(%s)\n{\n", module);
if (Len(r_init) > 0) { Printv(s_init,
Printv(s_init, "/* rinit section */\n",
"/* rinit section */\n", r_init, "\n",
r_init, "\n", NIL);
NIL);
}
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);
Printf(s_init, " return SUCCESS;\n"); Printf(s_init, " return SUCCESS;\n");
Printf(s_init, "}\n\n"); Printf(s_init, "}\n\n");
@ -1517,56 +1502,17 @@ public:
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
virtual int globalvariableHandler(Node *n) { virtual int globalvariableHandler(Node *n) {
char *name = GetChar(n, "name");
char *iname = GetChar(n, "sym:name");
SwigType *t = Getattr(n, "type");
String *tm;
wrapperType = globalvar; wrapperType = globalvar;
/* First do the wrappers such as name_set(), name_get() /* PHP doesn't support intercepting reads and writes to global variables
* as provided by the baseclass's implementation of variableWrapper * (nor static property reads and writes so we can't wrap them as static
* properties on a dummy class) so just let SWIG do its default thing and
* wrap them as name_get() and name_set().
*/ */
if (Language::globalvariableHandler(n) == SWIG_NOWRAP) { int result = Language::globalvariableHandler(n);
return SWIG_NOWRAP;
}
if (!addSymbol(iname, n))
return SWIG_ERROR;
/* First link C variables to PHP */
tm = Swig_typemap_lookup("varinit", n, name, 0);
if (tm) {
Printf(s_vinit, "%s\n", tm);
} else {
Swig_error(input_file, line_number, "Unable to link with type %s\n", SwigType_str(t, 0));
}
/* Now generate PHP -> C sync blocks */
/*
tm = Swig_typemap_lookup("varin", n, name, 0);
if(tm) {
Replaceall(tm, "$symname", iname);
Printf(f_c->code, "%s\n", tm);
} else {
Swig_error(input_file, line_number, "Unable to link with type %s\n", SwigType_str(t, 0));
}
*/
/* Now generate C -> PHP sync blocks */
/*
if(!GetFlag(n,"feature:immutable")) {
tm = Swig_typemap_lookup("varout", n, name, 0);
if(tm) {
Replaceall(tm, "$symname", iname);
Printf(f_php->code, "%s\n", tm);
} else {
Swig_error(input_file, line_number, "Unable to link with type %s\n", SwigType_str(t, 0));
}
}
*/
wrapperType = standard; wrapperType = standard;
return SWIG_OK; return result;
} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------