Skip to content

add implementations of memcpy et al #128

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

Merged
merged 1 commit into from
Dec 18, 2016
Merged

add implementations of memcpy et al #128

merged 1 commit into from
Dec 18, 2016

Conversation

japaric
Copy link
Member

@japaric japaric commented Dec 18, 2016

behind the "mem" Cargo feature, which used to be named "weak"

fixes #126

Possible solution to #126
r? @alexcrichton

behind the "mem" Cargo feature, which used to be named "weak"

fixes rust-lang#126
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Dec 18, 2016

📌 Commit a1caa7c has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Dec 18, 2016

⌛ Testing commit a1caa7c with merge 568df8f...

bors added a commit that referenced this pull request Dec 18, 2016
add implementations of memcpy et al

behind the "mem" Cargo feature, which used to be named "weak"

fixes #126

Possible solution to #126
r? @alexcrichton
}

#[no_mangle]
pub unsafe extern "C" fn memset(s: *mut u8, c: i32, n: usize) -> *mut u8 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why c is i32? Will it work on all architectures? maybe it should be isize or usize?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be c_int but it's better not to depend on libc, which is where c_int is defined. Right now, c_int is defined as type c_int = i32 in libc.

Will it work on all architectures?

That's a good question. AVR seems to define int as 16-bit. I don't know about MSP430. You probably know that better. It's likely that all these implementations don't work correctly on architectures where sizeof(usize) is neither 32 or 64.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, on MSP430 int is 16bit. And I would like to have a working memset on MSP430. My point is that if you make it isize instead of i32 it will be compatible with all architectures that rust supports AFAIK.

Copy link
Member Author

Choose a reason for hiding this comment

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

But 64-bit architectures expect c to be i32 (c_int is 32-bit on 64 and 32 bit architectures).

Copy link
Contributor

Choose a reason for hiding this comment

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

Both x86_64 and AArch64 do not care if you pass a 64bit or 32bit value inside their 64bit registers. And the receiving code does cast to i8 anyway.

@bors
Copy link
Contributor

bors commented Dec 18, 2016

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 568df8f to master...

@bors bors merged commit a1caa7c into rust-lang:master Dec 18, 2016
@japaric japaric deleted the mem branch December 18, 2016 21:44
tgross35 pushed a commit to tgross35/compiler-builtins that referenced this pull request Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

linker error when the "weak" feature is enabled
4 participants