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

Port unibyte-char-to-multibyte function #218

Merged
merged 5 commits into from Jul 14, 2017

Conversation

shanavas786
Copy link
Collaborator

No description provided.

let mut c = ch.as_fixnum().unwrap() as u32;
if c >= 0x100 {
unsafe {
error("Not a unibyte character: %d".as_ptr(), c);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this should be error("Not a unibyte character, %d\0".as_ptr(), c), as Rust does not null-terminate it's string literals automatically.

@DavidDeSimone
Copy link
Collaborator

Looks like the build is failing due to the release rustc 1.20.0-nightly not playing well with alloc_unexecmacosx. I'll take a look at that this morning if no one else does.

Other then my one inline comment, this looks like a solid PR 👍

@shanavas786
Copy link
Collaborator Author

@DavidDeSimone Thanks, updated

/// Check if Lisp object is a character or not.
/// Similar to CHECK_CHARACTER
#[inline]
pub fn is_character_or_error(self) -> () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make this as_character_or_error. Then you can make the cast to fixnum and ultimately to Codepoint here already.

/// UNIBYTE_TO_CHAR macro
#[inline]
pub fn unibyte_to_char(cp: Codepoint) -> Codepoint {
if (cp as u8).is_ascii() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This cast is dangerous - it will truncate the codepoint so that thinks that aren't ascii will look like ascii.

#[inline]
#[allow(unused_comparisons)]
pub fn make_char_multibyte(cp: Codepoint) -> Codepoint {
debug_assert!((cp) >= 0 && (cp) < 256);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just omit the >= 0 comparison, and remove the allow.

// Same as CHECK_TYPE macro,
// order of arguments changed
#[inline]
#[allow(dead_code)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is it dead code?

#[lisp_fn]
fn unibyte_char_to_multibyte(ch: LispObject) -> LispObject {
ch.is_character_or_error();
let mut c = ch.as_fixnum().unwrap() as u32;
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need for mut - just do either direct return or let below.

@@ -30,13 +30,11 @@ fn char_or_string_p(object: LispObject) -> LispObject {
/// Convert the byte CH to multibyte character.
#[lisp_fn]
fn unibyte_char_to_multibyte(ch: LispObject) -> LispObject {
ch.is_character_or_error();
let mut c = ch.as_fixnum().unwrap() as u32;
let c = ch.as_character_or_error() as u32;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The "as u32" should be unnecessary (especially since Codepoint is just an alias for it 😄)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes it is, updated :)

@shanavas786 shanavas786 force-pushed the char-funcs branch 2 times, most recently from f8cac5a to 7f5c3d0 Compare July 12, 2017 05:31
@shanavas786
Copy link
Collaborator Author

Conflicts resolved

@DavidDeSimone
Copy link
Collaborator

@shanavas786 OSX build fix is on master. If you merge in master travis should go green.

@shanavas786
Copy link
Collaborator Author

@DavidDeSimone done :)

@birkenfeld birkenfeld merged commit 295e1f6 into remacs:master Jul 14, 2017
@birkenfeld
Copy link
Collaborator

Thanks!

@shanavas786 shanavas786 deleted the char-funcs branch July 14, 2017 16:19
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.

None yet

3 participants