Skip to content

Commit

Permalink
Remove #[inline] from azul-dll functions (see rust-lang/rust#72944)
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Jun 3, 2020
1 parent 75c1316 commit 39014f3
Show file tree
Hide file tree
Showing 7 changed files with 440 additions and 397 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ members = [
# "azul-widgets",
"azul-css-parser",
"azul-native-style",
]
]

[profile.release]
lto = true
panic = "abort"
codegen-units = 1
12 changes: 6 additions & 6 deletions api/gen-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def generate_rust_dll(apiData):
fn_args = fn_args_c_api(const, class_name, class_ptr_name, False, apiData)

functions_map[str(fn_prefix + to_snake_case(class_name) + "_" + fn_name)] = [fn_args, class_ptr_name];
code += "#[no_mangle] #[inline] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_" + fn_name + "(" + fn_args + ") -> " + class_ptr_name + " { "
code += "#[no_mangle] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_" + fn_name + "(" + fn_args + ") -> " + class_ptr_name + " { "
code += fn_body
code += " }\r\n"

Expand Down Expand Up @@ -560,7 +560,7 @@ def generate_rust_dll(apiData):

functions_map[str(fn_prefix + to_snake_case(class_name) + "_" + fn_name)] = [fn_args, returns];
return_arrow = "" if returns == "" else " -> "
code += "#[no_mangle] #[inline] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_" + fn_name + "(" + fn_args + ")" + return_arrow + returns + " { "
code += "#[no_mangle] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_" + fn_name + "(" + fn_args + ")" + return_arrow + returns + " { "
code += fn_body
code += " }\r\n"

Expand Down Expand Up @@ -588,26 +588,26 @@ def generate_rust_dll(apiData):
# az_item_delete()
code += "/// Destructor: Takes ownership of the `" + class_name + "` pointer and deletes it.\r\n"
functions_map[str(fn_prefix + to_snake_case(class_name) + "_delete")] = ["object: &mut " + class_ptr_name, ""];
code += "#[no_mangle] #[inline] #[allow(unused_variables)] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_delete" + lifetime + "(object: &mut " + class_ptr_name + ") { " + stack_delete_body + "}\r\n"
code += "#[no_mangle] #[allow(unused_variables)] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_delete" + lifetime + "(object: &mut " + class_ptr_name + ") { " + stack_delete_body + "}\r\n"

# az_item_deep_copy()
code += "/// Copies the object\r\n"
functions_map[str(fn_prefix + to_snake_case(class_name) + "_deep_copy")] = ["object: &" + class_ptr_name, class_ptr_name];
code += "#[no_mangle] #[inline] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_deep_copy" + lifetime + "(object: &" + class_ptr_name + ") -> " + class_ptr_name + " { "
code += "#[no_mangle] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_deep_copy" + lifetime + "(object: &" + class_ptr_name + ") -> " + class_ptr_name + " { "
code += "object.clone()"
code += " }\r\n"
else:
# az_item_delete()
code += "/// Destructor: Takes ownership of the `" + class_name + "` pointer and deletes it.\r\n"
functions_map[str(fn_prefix + to_snake_case(class_name) + "_delete")] = ["ptr: &mut " + class_ptr_name, ""];
code += "#[no_mangle] #[inline] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_delete" + lifetime + "(ptr: &mut " + class_ptr_name + ") { "
code += "#[no_mangle] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_delete" + lifetime + "(ptr: &mut " + class_ptr_name + ") { "
code += "let _ = unsafe { Box::<" + rust_class_name + ">::from_raw(ptr.ptr as *mut " + rust_class_name + ") };"
code += " }\r\n"

# az_item_shallow_copy()
code += "/// Copies the pointer: WARNING: After calling this function you'll have two pointers to the same Box<`" + class_name + "`>!.\r\n"
functions_map[str(fn_prefix + to_snake_case(class_name) + "_shallow_copy")] = ["ptr: &" + class_ptr_name, class_ptr_name];
code += "#[no_mangle] #[inline] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_shallow_copy" + lifetime + "(ptr: &" + class_ptr_name + ") -> " + class_ptr_name + " { "
code += "#[no_mangle] pub extern \"C\" fn " + fn_prefix + to_snake_case(class_name) + "_shallow_copy" + lifetime + "(ptr: &" + class_ptr_name + ") -> " + class_ptr_name + " { "
code += class_ptr_name + " { ptr: ptr.ptr }"
code += " }\r\n"

Expand Down
9 changes: 9 additions & 0 deletions azul-dll/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ categories = ["gui"]
repository = "https://github.com/maps4print/azul"
edition = "2018"

[lib]
name = "azul"
crate-type = ["rlib", "cdylib"]

[profile.release]
lto = true
panic = "abort"
codegen-units = 1

[dependencies]
azul-core = { path = "../azul-core", version = "0.0.2", default-features = false, features = ["opengl"] }

Expand Down
Loading

0 comments on commit 39014f3

Please sign in to comment.