Skip to content

Native function link name should be an attribute #906

Closed
@brson

Description

@brson
Contributor

Instead of

    fn close(fd: int) -> int = "_close";

we should write

    #[link_name = "_close"]
    fn close(fd: int) -> int;

Activity

lht

lht commented on Nov 11, 2011

@lht
Contributor

Should native mod be moved to attribute also to keep it consistent with native fn?

So

native "cdecl" mod ssl = "crypto" {...}

becomes

#[link_name = "crypto"]
native "cdecl" mod ssl {...}
lht

lht commented on Nov 11, 2011

@lht
Contributor

Okay, I guess the answer is yes. Issue #547 (Replace some native module syntax with attributes).

brson

brson commented on Nov 11, 2011

@brson
ContributorAuthor

Also native mods that are crate directives.

lht

lht commented on Nov 21, 2011

@lht
Contributor

Now I'm about to start hacking crate directive. The plan is:

  1. change
    mod os_fs = "posix_fs.rs";
    to
    #[path = "posix_fs.rs"] mod os_fs;
    path is chosen over filename, considering it might indicate a directory.
  2. Remove option::t from ast::cdir_src_mod and ast::cdir_dir_mod.
  3. Add native support, so we can parse
#[link_name="real_foo"]
native mod foo;```

I'm not totally sure if moving filename/path to attribute is the plan, please confirm?
brson

brson commented on Nov 21, 2011

@brson
ContributorAuthor

Yes. What you propose sounds good.

lht

lht commented on Nov 22, 2011

@lht
Contributor

Are native item declarations in .rc files allowed? As hinted by the few native rc test cases.

native.rc:
native "cdecl" mod rustrt {
  fn str_buf(str s) -> int;
}

native mod libc = target_libc {
  fn puts(int s) -> ();
}

but the reference states a crate is a sequence of directives.

brson

brson commented on Nov 22, 2011

@brson
ContributorAuthor

Seems to be a feature that was never implemented, and I don't think there's any need.

lht

lht commented on Dec 1, 2011

@lht
Contributor

I guess this can be closed? Or should we remove the tests:

./run-pass/native-mod.rc
./run-pass/native.rc

brson

brson commented on Dec 1, 2011

@brson
ContributorAuthor

Let's leave the tests as a reminder that somebody wanted that feature at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lht@brson

        Issue actions

          Native function link name should be an attribute · Issue #906 · rust-lang/rust