summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Gilleron <marc.gilleron@gmail.com>2018-01-24 23:16:00 +0100
committerMarc Gilleron <marc.gilleron@gmail.com>2018-01-25 20:55:56 +0100
commitac0679eb1a4e46225422c73f9c4752c5e7b3ad73 (patch)
tree88143ba0656529693180f612f43442f6644ac6a6
parent9ed6edaae19439314558c1cf97e5881a073c7e59 (diff)
downloadredot-cpp-ac0679eb1a4e46225422c73f9c4752c5e7b3ad73.tar.gz
Fix Ref leak when using Godot getters
-rw-r--r--binding_generator.py4
-rw-r--r--include/core/Ref.hpp9
2 files changed, 11 insertions, 2 deletions
diff --git a/binding_generator.py b/binding_generator.py
index 9c6b00a..54c56f2 100644
--- a/binding_generator.py
+++ b/binding_generator.py
@@ -346,7 +346,7 @@ def generate_class_implementation(icalls, used_classes, c):
if is_enum(method["return_type"]):
return_statement += "return (" + remove_enum_prefix(method["return_type"]) + ") "
elif is_reference_type(method["return_type"]):
- return_statement += "return Ref<" + strip_name(method["return_type"]) + ">(";
+ return_statement += "return Ref<" + strip_name(method["return_type"]) + ">::__internal_constructor(";
else:
return_statement += "return " + ("(" + strip_name(method["return_type"]) + " *) " if is_class_type(method["return_type"]) else "")
else:
@@ -414,7 +414,7 @@ def generate_class_implementation(icalls, used_classes, c):
cast = ""
if is_class_type(method["return_type"]):
if is_reference_type(method["return_type"]):
- cast += "Ref<" + stip_name(method["return_type"]) + ">::__internal_constructor(__result);"
+ cast += "Ref<" + strip_name(method["return_type"]) + ">::__internal_constructor(__result);"
else:
cast += "(" + strip_name(method["return_type"]) + " *) (Object *) __result;"
else:
diff --git a/include/core/Ref.hpp b/include/core/Ref.hpp
index 3d06e75..f81dbbe 100644
--- a/include/core/Ref.hpp
+++ b/include/core/Ref.hpp
@@ -199,6 +199,15 @@ public:
unref();
}
+
+ // Used exclusively in the bindings to recreate the Ref Godot encapsulates in return values,
+ // without adding to the refcount.
+ inline static Ref<T> __internal_constructor(Object *obj)
+ {
+ Ref<T> r;
+ r.reference = (T*)obj;
+ return r;
+ }
};
}