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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port init-image-library to rust #1536

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

benreyn
Copy link

@benreyn benreyn commented Aug 12, 2019

Hello there! 馃憢

Im excited about the opportunity to use remacs to help me get a better lower-level understanding of Rust, C, and Emacs.

My build is still failing due to...

error[E0432]: unresolved import `crate::remacs_sys::lookup_image_type`
 --> src/image.rs:8:31
  |
8 | use crate::{lisp::LispObject, remacs_sys::lookup_image_type};
  |                               ^^^^^^^^^^^^-----------------
  |                               |           |
  |                               |           help: a similar name exists in the module: `Flookup_image_map`
  |                               no `lookup_image_type` in `remacs_sys`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: Could not compile `remacs`.

To learn more, run the command again with --verbose.
make[1]: *** [../rust_src/target/release/libremacs_lib.a] Error 101
make: *** [src] Error 2

Any pointers on how to expose lookup_image_type from C to Rust?

Will close #1252

use crate::{lisp::LispObject, remacs_sys::valid_image_p};
use crate::remacs_sys::valid_image_p;

use crate::{lisp::LispObject, remacs_sys::lookup_image_type};
Copy link
Collaborator

Choose a reason for hiding this comment

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

group the `remacs_sys items together please.
This should be:

use crate::lisp::LispObject;
use crate::remacs_sys::{valid_image_p, lookup_image_type};

Copy link
Author

Choose a reason for hiding this comment

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

Even if that means moving the valid_image_p out from under the #[cfg(feature = "glyph-debug")]?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the glyph-debug remains then import it separately. Maybe that is why the two other imports were grouped together? Was that done by you or by rustformat?

Copy link
Author

Choose a reason for hiding this comment

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

I grouped the imports as they are currently. lisp::LispObject was needed by both init_image_library and imagep but valid_image_p was only used by imagep, which is under #[cfg(feature = "glyph-debug")]. It felt right to only import valid_image_p in the scenarios where it is needed. Happy to expose everything though if thats the preference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

use crate::lisp::LispObject;
use remacs_sys::lookup_image_type;

Then see what rustformat does with it.....

/// the library file(s) specified by `dynamic-library-alist'.
#[lisp_fn]
pub fn init_image_library(r#type: LispObject) -> bool {
unsafe { lookup_image_type(r#type) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

lookup_image_type is declared static in the C code. static marks the function as only accessible to that C file. The name is not exposed. This is why Rust cannot see it. We often need to remove the static modifier and then copy the function definition into a header so it will be visible to Rust.

@benreyn benreyn force-pushed the br-port-init-image-library branch 3 times, most recently from 4eb261c to 7291918 Compare August 13, 2019 01:37
@benreyn
Copy link
Author

benreyn commented Aug 13, 2019

@shaleh, so I got this branch to build on my local environment, and the smoke test I wrote is passing. TravisCI however is still failing. Any ideas?

@shaleh
Copy link
Collaborator

shaleh commented Aug 13, 2019

hmm, it appears to be dying because rustfmt is not installed for the linux without X Window System test case. That should be its own PR. Not sure why it is dying now.... Similarly, the Mac build is dying because it needs --without-makeinfo.

@benreyn
Copy link
Author

benreyn commented Aug 13, 2019

So, neither of this Travis failures are actually related to this PR? Im happy to take a stab at those updates with some guidance.

@benreyn
Copy link
Author

benreyn commented Nov 3, 2019

@shaleh Just following up on this. Are there any todo's for me on this PR or are there unrelated issues causing the test failures.

@shaleh
Copy link
Collaborator

shaleh commented Nov 5, 2019

Thanks for the reminder @benreyn. I need to look into this again.

The code in the PR looks good. I would typically suggest not using the r# style naming. But here, it is important to keep the variable name for export.

@shaleh
Copy link
Collaborator

shaleh commented Nov 5, 2019

Kicking the PR, let's see what happens.

@shaleh shaleh closed this Nov 5, 2019
@shaleh shaleh reopened this Nov 5, 2019
@shaleh
Copy link
Collaborator

shaleh commented Jan 12, 2020

I am fairly certain this will need to be rebased to succeed at the unit tests.

@benreyn
Copy link
Author

benreyn commented Jan 13, 2020

Thanks for circling back on it @shaleh. Ill get it rebased sometime today.

@benreyn
Copy link
Author

benreyn commented Jan 15, 2020

@shaleh Just rebased and pushed. Lets see what Ci does 馃

@benreyn
Copy link
Author

benreyn commented Jan 22, 2020

Looks like CI is still failing here @shaleh. I havent had a chance to check it out locally and see whats going on.

@shaleh
Copy link
Collaborator

shaleh commented Jan 22, 2020

@benreyn you missed the 'static' keyword here:

remacs/src/image.c

Lines 9705 to 9706 in 7aa6840

static struct image_type *
lookup_image_type (Lisp_Object type)

This means the function is not exported and available to Rust.

@shaleh
Copy link
Collaborator

shaleh commented Jan 22, 2020

This function should not have the static keyword. Sorry if I was not clear. It is important that neither this location nor the earlier reference to the function in the same file has static.

@benreyn
Copy link
Author

benreyn commented Jan 22, 2020

Thanks for catching that @shaleh. Im still learning the ins and outs of how Remacs is pieced together.

@shaleh
Copy link
Collaborator

shaleh commented Jan 22, 2020

No worries @benreyn. This is an odd project because of the mix of C and Rust.

'static' means a function is not exported from the C file it is declared in. For variables, they will automatically be set to zero. Not initialized -- zero.

There is also a requirement in C that a function be declared before it is used. Which is why the function you were touching had two instances of it. One was a forward declaration on one line and the later the full definition.

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.

Port init-image-library
2 participants