-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* There was an edge case where the arena could be destroyed twice on error: once from the arena itself and once from the decl destruction. * The type of the created decl was incorrect (it should have been the pointer child type), but it's not required anyway, so it's now just initialized to anyopaque (which more accurately reflects what's actually at that memory, since e.g. [*]T may correspond to nothing). * A runtime bitcast of the pointer was performed, meaning @extern didn't work at comptime. This is unnecessary: the decl_ref can just be initialized with the correct pointer type.
- Loading branch information
Showing
5 changed files
with
84 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const obj = b.addObject(.{ | ||
.name = "exports", | ||
.root_source_file = .{ .path = "exports.zig" }, | ||
.target = .{}, | ||
.optimize = optimize, | ||
}); | ||
const main = b.addTest(.{ | ||
.root_source_file = .{ .path = "main.zig" }, | ||
.optimize = optimize, | ||
}); | ||
main.addObject(obj); | ||
|
||
const test_step = b.step("test", "Test it"); | ||
test_step.dependOn(&main.step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var hidden: u32 = 0; | ||
export fn updateHidden(val: u32) void { | ||
hidden = val; | ||
} | ||
export fn getHidden() u32 { | ||
return hidden; | ||
} | ||
|
||
const T = extern struct { x: u32 }; | ||
|
||
export var mut_val: f64 = 1.23; | ||
export const const_val: T = .{ .x = 42 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const assert = @import("std").debug.assert; | ||
|
||
const updateHidden = @extern(*const fn (u32) callconv(.C) void, .{ .name = "updateHidden" }); | ||
const getHidden = @extern(*const fn () callconv(.C) u32, .{ .name = "getHidden" }); | ||
|
||
const T = extern struct { x: u32 }; | ||
|
||
test { | ||
var mut_val_ptr = @extern(*f64, .{ .name = "mut_val" }); | ||
var const_val_ptr = @extern(*const T, .{ .name = "const_val" }); | ||
|
||
assert(getHidden() == 0); | ||
updateHidden(123); | ||
assert(getHidden() == 123); | ||
|
||
assert(mut_val_ptr.* == 1.23); | ||
mut_val_ptr.* = 10.0; | ||
assert(mut_val_ptr.* == 10.0); | ||
|
||
assert(const_val_ptr.x == 42); | ||
} |