Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/generators/cpp/gen/cppGenClassHeader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let gen_member_function ctx class_def is_static func =

Printf.sprintf "\t\t%s %s %s(%s);\n" attributes return_type_str func.tcf_name (print_arg_list func.tcf_args "") |> output;

if (not func.tcf_is_virtual || not func.tcf_is_overriding) && func.tcf_is_reflective then
if (not func.tcf_is_virtual || not func.tcf_is_overriding) && not (is_native_gen_class class_def) then
let prefix = if is_static then "static " else "" in
let signature = func_to_callable_string "::hx::Callable" func in
Printf.sprintf "\t\t%s%s %s_dyn();\n" prefix signature func.tcf_name |> output;
Expand Down
26 changes: 17 additions & 9 deletions src/generators/cpp/gen/cppGenClassImplementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,24 @@ let gen_function ctx tcpp_class is_static func =
output "\n\n";

(* generate dynamic version too ... *)
if (not func.tcf_is_virtual || not func.tcf_is_overriding) && func.tcf_is_reflective then
if (not func.tcf_is_virtual || not func.tcf_is_overriding) && not (is_native_gen_class tcpp_class.tcl_class) then
let callable_name = Printf.sprintf "__%s%s" tcpp_class.tcl_name func.tcf_name in
let signature = func_to_callable_string "::hx::Callable" func in
if is_static then
Printf.sprintf
"%s %s::%s_dyn() { return _hx_alloc%s; }\n\n"
signature
tcpp_class.tcl_name
func.tcf_name
callable_name |> output
if func.tcf_is_reflective then
Printf.sprintf
"%s %s::%s_dyn() { return _hx_alloc%s; }\n\n"
signature
tcpp_class.tcl_name
func.tcf_name
callable_name |> output
else
Printf.sprintf
"%s %s::%s_dyn() { return new %s(); }\n\n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is new overloaded here? If not then it will cause a memory leak because there is no delete.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be any leaks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"%s %s::%s_dyn() { return new %s(this); }\n\n"

It doesn't look that different.

signature
tcpp_class.tcl_name
func.tcf_name
callable_name |> output
else
Printf.sprintf
"%s %s::%s_dyn() { return new %s(this); }\n\n"
Expand All @@ -105,7 +113,7 @@ let gen_function ctx tcpp_class is_static func =
callable_name |> output

let gen_function_closures ctx tcpp_class is_static func =
if (not func.tcf_is_virtual || not func.tcf_is_overriding) && func.tcf_is_reflective then
if (not func.tcf_is_virtual || not func.tcf_is_overriding) && not (is_native_gen_class tcpp_class.tcl_class) then
let output = ctx.ctx_output in
let return_type_str = type_to_string ctx.ctx_common.basic func.tcf_func.tf_type in
let return_type = cpp_type_of ctx.ctx_common.basic func.tcf_func.tf_type in
Expand All @@ -125,7 +133,7 @@ let gen_function_closures ctx tcpp_class is_static func =

write_callable_trailer captures output;

if is_static then
if is_static && func.tcf_is_reflective then
let signature = func_to_callable_string "::hx::Callable" func in
Printf.sprintf "%s _hx_alloc%s;\n\n" signature callable_name |> output

Expand Down
38 changes: 38 additions & 0 deletions tests/unit/src/unit/issues/Issue12437.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package unit.issues;

#if (cpp && !cppia)
@:unreflective
private class Unreflective {
public static var lastInstance:String;
public static var lastStatic:String;

public function new() {}

public function onInstance(value:String):Void {
lastInstance = value;
}

public static function onStatic(value:String):Void {
lastStatic = value;
}
}

private class Dispatcher {
public static function call(listener:String->Void, value:String):Void {
listener(value);
}
}
#end

class Issue12437 extends Test {
#if (cpp && !cppia)
function test() {
Dispatcher.call(Unreflective.onStatic, "static");
eq("static", Unreflective.lastStatic);

var u = new Unreflective();
Dispatcher.call(u.onInstance, "instance");
eq("instance", Unreflective.lastInstance);
}
#end
}
Loading