Skip to content

Commit

Permalink
chore(dependencies): remove libc crate from dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Jan 28, 2024
1 parent b114244 commit 4caf220
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ http-body-util = { version = "0.1", optional = true }
httparse = { version = "1.8", optional = true }
httpdate = { version = "1.0", optional = true }
itoa = { version = "1", optional = true }
libc = { version = "0.2", optional = true }
pin-project-lite = { version = "0.2.4", optional = true }
smallvec = { version = "1.12", features = ["const_generics", "const_new"], optional = true }
tracing = { version = "0.1", default-features = false, features = ["std"], optional = true }
Expand Down Expand Up @@ -85,7 +84,7 @@ client = ["dep:want", "dep:pin-project-lite", "dep:smallvec"]
server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec"]

# C-API support (currently unstable (no semver))
ffi = ["dep:libc", "dep:http-body-util"]
ffi = ["dep:http-body-util"]

# Utilize tracing (currently unstable)
tracing = ["dep:tracing"]
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/body.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::ffi::c_void;
use std::ffi::{c_int, c_void};
use std::mem::ManuallyDrop;
use std::ptr;
use std::task::{Context, Poll};

use http_body_util::BodyExt as _;
use libc::{c_int, size_t};

use super::task::{hyper_context, hyper_task, hyper_task_return_type, AsTaskType};
use super::{UserDataPointer, HYPER_ITER_CONTINUE};
use crate::body::{Bytes, Frame, Incoming as IncomingBody};
use crate::ffi::size_t;

/// A streaming HTTP body.
///
Expand Down
3 changes: 1 addition & 2 deletions src/ffi/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::ffi::c_int;
use std::ptr;
use std::sync::Arc;

use libc::c_int;

use crate::client::conn;
use crate::rt::Executor as _;

Expand Down
2 changes: 1 addition & 1 deletion src/ffi/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use libc::size_t;
use crate::ffi::size_t;

/// A more detailed error object returned by some hyper functions.
///
Expand Down
5 changes: 3 additions & 2 deletions src/ffi/http_types.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::ffi::{c_int, c_void};

use bytes::Bytes;
use libc::{c_int, size_t};
use std::ffi::c_void;

use super::body::hyper_body;
use super::error::hyper_code;
use super::task::{hyper_task_return_type, AsTaskType};
use super::{UserDataPointer, HYPER_ITER_CONTINUE};
use crate::body::Incoming as IncomingBody;
use crate::ext::{HeaderCaseMap, OriginalHeaderOrder, ReasonPhrase};
use crate::ffi::size_t;
use crate::header::{HeaderName, HeaderValue};
use crate::{HeaderMap, Method, Request, Response, Uri};

Expand Down
5 changes: 2 additions & 3 deletions src/ffi/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::ffi::c_void;
use std::pin::Pin;
use std::task::{Context, Poll};

use crate::rt::{Read, Write};
use libc::size_t;

use super::task::hyper_context;
use crate::ffi::size_t;
use crate::rt::{Read, Write};

/// Sentinel value to return from a read or write callback that the operation
/// is pending.
Expand Down
18 changes: 11 additions & 7 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ pub use self::io::*;
pub use self::task::*;

/// Return in iter functions to continue iterating.
pub const HYPER_ITER_CONTINUE: libc::c_int = 0;
pub const HYPER_ITER_CONTINUE: std::ffi::c_int = 0;
/// Return in iter functions to stop iterating.
#[allow(unused)]
pub const HYPER_ITER_BREAK: libc::c_int = 1;
pub const HYPER_ITER_BREAK: std::ffi::c_int = 1;

/// An HTTP Version that is unspecified.
pub const HYPER_HTTP_VERSION_NONE: libc::c_int = 0;
pub const HYPER_HTTP_VERSION_NONE: std::ffi::c_int = 0;
/// The HTTP/1.0 version.
pub const HYPER_HTTP_VERSION_1_0: libc::c_int = 10;
pub const HYPER_HTTP_VERSION_1_0: std::ffi::c_int = 10;
/// The HTTP/1.1 version.
pub const HYPER_HTTP_VERSION_1_1: libc::c_int = 11;
pub const HYPER_HTTP_VERSION_1_1: std::ffi::c_int = 11;
/// The HTTP/2 version.
pub const HYPER_HTTP_VERSION_2: libc::c_int = 20;
pub const HYPER_HTTP_VERSION_2: std::ffi::c_int = 20;

#[derive(Clone)]
struct UserDataPointer(*mut std::ffi::c_void);
Expand All @@ -87,9 +87,13 @@ unsafe impl Sync for UserDataPointer {}
/// cbindgen:ignore
static VERSION_CSTR: &str = concat!(env!("CARGO_PKG_VERSION"), "\0");

// `core::ffi::c_size_t` is a nightly-only experimental API.
// https://github.com/rust-lang/rust/issues/88345
type size_t = usize;

ffi_fn! {
/// Returns a static ASCII (null terminated) string of the hyper version.
fn hyper_version() -> *const libc::c_char {
fn hyper_version() -> *const std::ffi::c_char {
VERSION_CSTR.as_ptr() as _
} ?= std::ptr::null()
}
3 changes: 1 addition & 2 deletions src/ffi/task.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ffi::c_void;
use std::ffi::{c_int, c_void};
use std::future::Future;
use std::pin::Pin;
use std::ptr;
Expand All @@ -9,7 +9,6 @@ use std::sync::{
use std::task::{Context, Poll};

use futures_util::stream::{FuturesUnordered, Stream};
use libc::c_int;

use super::error::hyper_code;
use super::UserDataPointer;
Expand Down

0 comments on commit 4caf220

Please sign in to comment.