Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.heap: cAlloc, cRealloc redeclares mem #585

Closed
scurest opened this issue Nov 5, 2017 · 3 comments
Closed

std.heap: cAlloc, cRealloc redeclares mem #585

scurest opened this issue Nov 5, 2017 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@scurest
Copy link
Contributor

scurest commented Nov 5, 2017

const heap = @import("std").heap;
pub fn main() -> %void {
    _ = heap.c_allocator.alloc(u8, 100);
}

gives error: redeclaration of variable 'mem' at

https://github.com/zig-lang/zig/blob/4cc9fe90a8a3c0bce803bf9fffd66477da9e37d0/std/heap.zig#L20

mem just needs to be renamed. Same for cRealloc.


I tried to do this but when I add a test that uses c_allocator to heap.zig, I get a mysterious linker error when I run the tests

lld: error: duplicate symbol: _start
>>> defined at init.c
>>>            /usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../lib/Scrt1.o:(_start)
>>> defined at bootstrap.zig:16 (/home/scurest/zig/build/lib/zig/std/special/bootstrap.zig:16)
>>>            ./zig-cache/test.o:(.text+0x6FC00)
@tiehuis
Copy link
Member

tiehuis commented Nov 5, 2017

When using the c allocator you will need to use the --library c command line flag to link the c library.

@scurest
Copy link
Contributor Author

scurest commented Nov 5, 2017

Ah, that does makes sense :)

I see that in addPkgTests in tests/tests.zig, it adds the tests once with and once without linking libc. So is the right thing to do to just guard the test that needs it with if (builtin.link_libc)?

@andrewrk
Copy link
Member

andrewrk commented Nov 5, 2017

So is the right thing to do to just guard the test that needs it with if (builtin.link_libc)?

Yes, this is right. Thanks for working on adding a test for this.

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Nov 5, 2017
@andrewrk andrewrk added this to the 0.2.0 milestone Nov 5, 2017
@scurest scurest mentioned this issue Nov 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants