summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNishant Gupta <nish.gupta01@gmail.com>2016-08-02 19:26:05 +0530
committerNishant Gupta <nish.gupta01@gmail.com>2016-08-02 19:26:05 +0530
commit6bb67cb6b5d3f15dad72ffbbc753e1a1baca8858 (patch)
treebaf7469d5d510e0215b37d9badaed40e4be8909e
parente66776d20c204a49b9a80cada7247a43d15853c0 (diff)
downloadswig-6bb67cb6b5d3f15dad72ffbbc753e1a1baca8858.tar.gz
int64_t and String for internal pointer type
-rw-r--r--Lib/hhvm/hhvm.swg93
-rw-r--r--Source/Modules/hhvm.cxx32
2 files changed, 71 insertions, 54 deletions
diff --git a/Lib/hhvm/hhvm.swg b/Lib/hhvm/hhvm.swg
index 6fe06aeee..34eae412e 100644
--- a/Lib/hhvm/hhvm.swg
+++ b/Lib/hhvm/hhvm.swg
@@ -60,13 +60,11 @@
char [ANY],
char [],
const char []
- "const HPHP::String&";
+ "const HPHP::String&";
%typemap(hni_parmtype) SWIGTYPE *,
- SWIGTYPE []
- "const HPHP::Object&";
-
-%typemap(hni_parmtype) SWIGTYPE &,
+ SWIGTYPE [],
+ SWIGTYPE &,
SWIGTYPE &&
"HPHP::VRefParam";
@@ -106,10 +104,8 @@
"void";
%typemap(hni_rttype) SWIGTYPE *,
- SWIGTYPE []
- "HPHP::Object";
-
-%typemap(hni_rttype) SWIGTYPE &,
+ SWIGTYPE [],
+ SWIGTYPE &,
SWIGTYPE &&
"HPHP::Variant";
@@ -148,16 +144,21 @@
%{$1 = (char *)$input.c_str();%}
%typemap(in) SWIGTYPE *,
- SWIGTYPE []
-%{$1 = HPHP::Native::data<_wrap_$hhclassname>($input)->_obj_ptr;%}
-
-%typemap(in) SWIGTYPE &,
+ SWIGTYPE [],
+ SWIGTYPE &,
SWIGTYPE &&
-%{$1 = HPHP::Native::data<_wrap_$hhclassname>($input.toObject())->_obj_ptr;%}
+%{$1 = *($&1_ltype)&(HPHP::Native::data<_wrap_$hhclassname>($input.toObject())->_obj_ptr);%}
-%typemap(in) SWIGTYPE
-%{$1 = *(HPHP::Native::data<_wrap_$&hhclassname>($input)->_obj_ptr);%}
+%typemap(in) SWIGTYPE ($&1_type argp)
+%{
+ argp = *($&1_ltype*)&(HPHP::Native::data<_wrap_$&hhclassname>($input)->_obj_ptr);
+ $1 = *argp;
+%}
+%typemap(in) SWIGTYPE (CLASS::*) %{
+ const char *temp = HPHP::Native::data<_wrap_$hhclassname>($input.toObject())->_obj_ptr.c_str();
+ SWIG_UnpackData(temp, (void *)&$1, sizeof($1));
+%}
/* out typemaps */
%typemap(out) int,
@@ -192,29 +193,32 @@
%typemap(out) void ""
%typemap(out) SWIGTYPE *,
- SWIGTYPE []
-%{
- $result = HPHP::Object(_wrap_$hhclassname::getClass());
- auto wrap_$1 = HPHP::Native::data<_wrap_$hhclassname>($result);
- wrap_$1->_obj_ptr = $1;
- wrap_$1->isRef = true;
-%}
-
-%typemap(out) SWIGTYPE &,
+ SWIGTYPE [],
+ SWIGTYPE &,
SWIGTYPE &&
%{
$result = HPHP::Object(_wrap_$hhclassname::getClass());
auto wrap_$1 = HPHP::Native::data<_wrap_$hhclassname>($result.toObject());
- wrap_$1->_obj_ptr = $1;
+ *($&1_ltype)&wrap_$1->_obj_ptr = $1;
wrap_$1->isRef = true;
%}
+%typemap(out) SWIGTYPE (CLASS::*) %{
+ auto cls = HPHP::Unit::lookupClass(HPHP::makeStaticString("$&hhclassname"));
+ $result = HPHP::Object(cls);
+ auto wrap_$1 = HPHP::Native::data<_wrap_$&hhclassname>($result);
+ char buf[128];
+ char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
+ *data = '\0';
+ wrap_$1->_obj_ptr = HPHP::String::FromCStr(buf);
+%}
+
%typemap(out) SWIGTYPE
%{
auto cls = HPHP::Unit::lookupClass(HPHP::makeStaticString("$&hhclassname"));
$result = HPHP::Object(cls);
auto wrap_$1 = HPHP::Native::data<_wrap_$&hhclassname>($result);
- wrap_$1->_obj_ptr = new $1_ltype((const $1_ltype &) $1);
+ *($&1_ltype*)&wrap_$1->_obj_ptr = new $1_ltype((const $1_ltype &) $1);
%}
/* php types */
@@ -250,10 +254,8 @@
"void";
%typemap(php_type) SWIGTYPE *,
- SWIGTYPE []
- "$hhclassname";
-
-%typemap(php_type) SWIGTYPE &,
+ SWIGTYPE [],
+ SWIGTYPE &,
SWIGTYPE &&
"mixed&";
@@ -355,13 +357,36 @@ class _wrap_$hhclassname {
public:
static HPHP::Class* getClass();
void sweep() {
- _obj_ptr = nullptr;
+ _obj_ptr = 0;
+ }
+ ~_wrap_$hhclassname() { sweep(); }
+
+ static HPHP::Class* s_class;
+ static const HPHP::StaticString s_className;
+ int64_t _obj_ptr{0};
+ bool isRef{false};
+};
+
+HPHP::Class* _wrap_$hhclassname::s_class = nullptr;
+const HPHP::StaticString _wrap_$hhclassname::s_className("$hhclassname");
+
+IMPLEMENT_GET_CLASS(_wrap_$hhclassname)
+
+%}
+
+%typemap(hhwrapclass) SWIGTYPE (CLASS::*) %{
+
+class _wrap_$hhclassname {
+public:
+ static HPHP::Class* getClass();
+ void sweep() {
+ _obj_ptr.clear();
}
~_wrap_$hhclassname() { sweep(); }
static HPHP::Class* s_class;
static const HPHP::StaticString s_className;
- $1_ltype _obj_ptr{nullptr};
+ HPHP::String _obj_ptr;
bool isRef{false};
};
@@ -370,4 +395,4 @@ const HPHP::StaticString _wrap_$hhclassname::s_className("$hhclassname");
IMPLEMENT_GET_CLASS(_wrap_$hhclassname)
-%} \ No newline at end of file
+%} \ No newline at end of file
diff --git a/Source/Modules/hhvm.cxx b/Source/Modules/hhvm.cxx
index 4ddd7651e..0dd1e7f38 100644
--- a/Source/Modules/hhvm.cxx
+++ b/Source/Modules/hhvm.cxx
@@ -466,16 +466,14 @@ public:
}
Printf(f_link, "%s(%s);\n", wname, call_parms);
} else if (is_constructor) {
- String *overresolve = is_overloaded ? NewString(".toObject()") : NULL;
- Printf(f_link, " auto new_obj = %s(%s)%s;\n", wname, call_parms, overresolve);
+ Printf(f_link, " auto new_obj = %s(%s);\n", wname, call_parms);
String *wclassname = GetChar(Swig_methodclass(n), "wrap:name");
- Printf(f_link, " Native::data<%s>(this_)->_obj_ptr = Native::data<%s>(new_obj)->_obj_ptr;\n", wclassname, wclassname);
- Printf(f_link, " Native::data<%s>(new_obj)->_obj_ptr = nullptr;\n", wclassname);
+ Printf(f_link, " Native::data<%s>(this_)->_obj_ptr = Native::data<%s>(new_obj.toObject())->_obj_ptr;\n", wclassname, wclassname);
} else if(is_destructor) {
String *wclassname = GetChar(Swig_methodclass(n), "wrap:name");
Printf(f_link, " if (!Native::data<%s>(this_)->isRef)\n", wclassname);
Printf(f_link, " %s(%s);\n", wname, call_parms);
- Printf(f_link, " Native::data<%s>(this_)->_obj_ptr = nullptr;\n", wclassname);
+ Printf(f_link, " Native::data<%s>(this_)->_obj_ptr = 0;\n", wclassname);
} else {
Printf(f_link, " ");
if (!is_void_return) {
@@ -867,8 +865,6 @@ public:
}
Printf(f_phpcode, "class %s ", name);
- Printf(f_classes, "class %s {\n", wname);
- Printf(f_classes, "public:\n");
String *baseclass = NULL;
if (base.item && Getattr(base.item, "module")) {
baseclass = Getattr(base.item, "sym:name");
@@ -880,19 +876,15 @@ public:
}
Printf(f_phpcode, "{\n");
- Printf(f_classes, " static HPHP::Class* getClass();\n");
- Printf(f_classes, " void sweep() {\n");
- Printf(f_classes, " _obj_ptr = nullptr;\n");
- Printf(f_classes, " }\n");
- Printf(f_classes, " ~%s() { sweep(); }\n\n", wname);
- Printf(f_classes, " static HPHP::Class* s_class;\n");
- Printf(f_classes, " static const HPHP::StaticString s_className;\n");
- Printf(f_classes, " %s* _obj_ptr{nullptr};\n", Getattr(n, "classtype"));
- Printf(f_classes, " bool isRef{false};\n");
- Printf(f_classes, "}; // class %s\n\n", wname);
- Printf(f_classes, "HPHP::Class* %s::s_class = nullptr;\n", wname);
- Printf(f_classes, "const HPHP::StaticString %s::s_className(\"%s\");\n\n", wname, name);
- Printf(f_classes, "IMPLEMENT_GET_CLASS(%s)\n\n", wname);
+ {
+ SwigType *t = Copy(Getattr(n, "sym:name"));
+ SwigType_add_pointer(t);
+ Node *node = NewHash();
+ Setattr(node, "type", t);
+ String *tm = Swig_typemap_lookup("hhwrapclass", node, "", 0);
+ Replaceall(tm, "$hhclassname", name);
+ Printv(f_classes, tm, NIL);
+ }
Printf(f_register, " Native::registerNativeDataInfo<%s>(%s::s_className.get());\n\n", wname, wname);