#7752: use fcnptr for glob errfunc.#9497
Merged
bors merged 2 commits intorust-lang:masterfrom Sep 26, 2013
Merged
Conversation
src/libstd/libc.rs
Outdated
Contributor
There was a problem hiding this comment.
man glob suggests that this can be NULL, so I think it should be Option<extern ... -> int>.
Contributor
Author
There was a problem hiding this comment.
ah, thanks, I'll give that a whirl.
Contributor
|
I'm not opposed to this, but I'm not really sure why it's necessary when we have |
Contributor
Author
|
@cmr i admit, the main use case I can think of is for people porting existing C code to Rust who want minimum barrier to entry. (But that's a somewhat facetious argument, since such people will already have to jump through hoops to deal with the Other than that, all I can think of is "if we're going to offer access to the POSIX |
bors
added a commit
that referenced
this pull request
Sep 26, 2013
…unc, r=cmr Fix #7752. ~~(The glob API is a little funky; I tried to make a small test for it, which I'll add to the end of this description, and its not clear whether globfree is supposed to free solely the structure allocated by glob itself, or if it is going to try to free more than that.)~~ (The previous note was a user-error: I was misusing the CString API.) Anyway, this seems to work in terms of calling errfunc where expected.) ```rust #[allow(unused_imports)]; use std::libc::types::os::arch::c95::{c_char, c_int, size_t}; use std::libc::funcs::posix01::glob; use std::libc::types::os::common::posix01::glob_t; use std::libc::consts::os::posix01::{GLOB_APPEND, GLOB_DOOFFS, GLOB_ERR, GLOB_MARK, GLOB_NOCHECK, GLOB_NOSORT, GLOB_NOESCAPE, GLOB_NOSPACE, GLOB_ABORTED, GLOB_NOMATCH}; use std::ptr; use std::c_str; #[fixed_stack_segment] fn main() { let mut g = glob_t { gl_pathc: 0, // size_t, __unused1: 0, // c_int, gl_offs: 2, // size_t, __unused2: 0, // c_int, gl_pathv: ptr::null(), // **c_char, __unused3: ptr::null(), // *c_void, __unused4: ptr::null(), // *c_void, __unused5: ptr::null(), // *c_void, __unused6: ptr::null(), // *c_void, __unused7: ptr::null(), // *c_void, __unused8: ptr::null(), // *c_void, }; extern "C" fn errfunc(_epath: *c_char, _errno: int) -> int { println!("errfunc called"); return 0; } struct Reduced { pathc: size_t, offs: size_t, pathv: **c_char, } impl Reduced { fn from(g: &glob_t) -> Reduced { Reduced {pathc: g.gl_pathc, offs: g.gl_offs, pathv: g.gl_pathv} } } do ("*.rs/*").with_c_str |pat| { println!("calling glob"); unsafe { glob::glob(pat, GLOB_DOOFFS, errfunc, &mut g); } println!("After glob call"); println!("g: {:?}", Reduced::from(&g)); for i in range(0, g.gl_pathc as int) { unsafe { let p : **c_char = ptr::offset(g.gl_pathv, g.gl_offs as int + i); let x = c_str::CString::new(*p, false); match x.as_str() { Some(s) => { println!("gl_pathc[{:d}]: {:?}", i, s); } None => { println!("gl_pathc[{:d}]: unvalid", i); } } } } } println!("calling globfree on g: {:?}", g); unsafe { glob::globfree(&mut g); } println!("after globfree call"); } ```
flip1995
pushed a commit
to flip1995/rust
that referenced
this pull request
Oct 6, 2022
[`needless_return`] Recursively remove unneeded semicolons fix rust-lang#8336, fix rust-lang#8156, fix rust-lang/rust-clippy#7358, fix rust-lang#9192, fix rust-lang/rust-clippy#9503 changelog: [`needless_return`] Recursively remove unneeded semicolons For now the suggestion about removing the semicolons are hidden because they would be very noisy and should be obvious if the user wants to apply the lint manually instead of using `--fix`. This could be an issue for beginner, but haven't found better way to display it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #7752.
(The glob API is a little funky; I tried to make a small test for it, which I'll add to the end of this description, and its not clear whether globfree is supposed to free solely the structure allocated by glob itself, or if it is going to try to free more than that.)(The previous note was a user-error: I was misusing the CString API.)Anyway, this seems to work in terms of calling errfunc where expected.)