Skip to content

Commit

Permalink
Unwind the __fixed_rust business
Browse files Browse the repository at this point in the history
This gives the unsuffixed names the correct signatures, and deprecates
the suffixed names in favor of the now fixed unsuffixed ones. The
suffixed names now forward to the unsuffixed ones.
  • Loading branch information
davidben committed Jun 3, 2023
1 parent 4b4a344 commit 2c098b7
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 176 deletions.
24 changes: 0 additions & 24 deletions openssl-sys/build/run_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,28 +208,4 @@ impl ParseCallbacks for OpensslCallbacks {
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior {
MacroParsingBehavior::Ignore
}

fn item_name(&self, original_item_name: &str) -> Option<String> {
match original_item_name {
// Our original definitions of these are wrong, so rename to avoid breakage
"CRYPTO_EX_new"
| "CRYPTO_EX_dup"
| "CRYPTO_EX_free"
| "BIO_meth_set_write"
| "BIO_meth_set_read"
| "BIO_meth_set_puts"
| "BIO_meth_set_ctrl"
| "BIO_meth_set_create"
| "BIO_meth_set_destroy"
| "CRYPTO_set_locking_callback"
| "CRYPTO_set_id_callback"
| "SSL_CTX_set_tmp_dh_callback"
| "SSL_set_tmp_dh_callback"
| "SSL_CTX_set_tmp_ecdh_callback"
| "SSL_set_tmp_ecdh_callback"
| "SSL_CTX_callback_ctrl"
| "SSL_CTX_set_alpn_select_cb" => Some(format!("{}__fixed_rust", original_item_name)),
_ => None,
}
}
}
87 changes: 50 additions & 37 deletions openssl-sys/src/bio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,54 @@ pub unsafe fn BIO_get_mem_data(b: *mut BIO, pp: *mut *mut c_char) -> c_long {
BIO_ctrl(b, BIO_CTRL_INFO, 0, pp as *mut c_void)
}

extern "C" {
#[deprecated(note = "use BIO_meth_set_write__fixed_rust instead")]
#[cfg(any(ossl110, libressl273))]
pub fn BIO_meth_set_write(
biom: *mut BIO_METHOD,
write: unsafe extern "C" fn(*mut BIO, *const c_char, c_int) -> c_int,
) -> c_int;
#[deprecated(note = "use BIO_meth_set_read__fixed_rust instead")]
#[cfg(any(ossl110, libressl273))]
pub fn BIO_meth_set_read(
biom: *mut BIO_METHOD,
read: unsafe extern "C" fn(*mut BIO, *mut c_char, c_int) -> c_int,
) -> c_int;
#[deprecated(note = "use BIO_meth_set_puts__fixed_rust instead")]
#[cfg(any(ossl110, libressl273))]
pub fn BIO_meth_set_puts(
biom: *mut BIO_METHOD,
read: unsafe extern "C" fn(*mut BIO, *const c_char) -> c_int,
) -> c_int;
#[deprecated(note = "use BIO_meth_set_ctrl__fixed_rust instead")]
#[cfg(any(ossl110, libressl273))]
pub fn BIO_meth_set_ctrl(
biom: *mut BIO_METHOD,
read: unsafe extern "C" fn(*mut BIO, c_int, c_long, *mut c_void) -> c_long,
) -> c_int;
#[deprecated(note = "use BIO_meth_set_create__fixed_rust instead")]
#[cfg(any(ossl110, libressl273))]
pub fn BIO_meth_set_create(
biom: *mut BIO_METHOD,
create: unsafe extern "C" fn(*mut BIO) -> c_int,
) -> c_int;
#[deprecated(note = "use BIO_meth_set_destroy__fixed_rust instead")]
#[cfg(any(ossl110, libressl273))]
pub fn BIO_meth_set_destroy(
biom: *mut BIO_METHOD,
destroy: unsafe extern "C" fn(*mut BIO) -> c_int,
) -> c_int;
// These symbols were originally bound with the wrong signatures. They were then
// deprecated in favor of `__fixed_rust`-suffixed versions. The unsuffixed
// symbols are now fixed, so the suffixed ones are deprecated aliases.
#[deprecated(note = "use BIO_meth_set_write instead")]
#[cfg(any(ossl110, libressl273))]
pub unsafe fn BIO_meth_set_write__fixed_rust(
biom: *mut BIO_METHOD,
write: Option<unsafe extern "C" fn(*mut BIO, *const c_char, c_int) -> c_int>,
) -> c_int {
BIO_meth_set_write(biom, write)
}
#[deprecated(note = "use BIO_meth_set_read instead")]
#[cfg(any(ossl110, libressl273))]
pub unsafe fn BIO_meth_set_read__fixed_rust(
biom: *mut BIO_METHOD,
read: Option<unsafe extern "C" fn(*mut BIO, *mut c_char, c_int) -> c_int>,
) -> c_int {
BIO_meth_set_read(biom, read)
}
#[deprecated(note = "use BIO_meth_set_puts instead")]
#[cfg(any(ossl110, libressl273))]
pub unsafe fn BIO_meth_set_puts__fixed_rust(
biom: *mut BIO_METHOD,
puts: Option<unsafe extern "C" fn(*mut BIO, *const c_char) -> c_int>,
) -> c_int {
BIO_meth_set_puts(biom, puts)
}
#[deprecated(note = "use BIO_meth_set_ctrl instead")]
#[cfg(any(ossl110, libressl273))]
pub unsafe fn BIO_meth_set_ctrl__fixed_rust(
biom: *mut BIO_METHOD,
ctrl: Option<unsafe extern "C" fn(*mut BIO, c_int, c_long, *mut c_void) -> c_long>,
) -> c_int {
BIO_meth_set_ctrl(biom, ctrl)
}
#[deprecated(note = "use BIO_meth_set_create instead")]
#[cfg(any(ossl110, libressl273))]
pub unsafe fn BIO_meth_set_create__fixed_rust(
biom: *mut BIO_METHOD,
create: Option<unsafe extern "C" fn(*mut BIO) -> c_int>,
) -> c_int {
BIO_meth_set_create(biom, create)
}
#[deprecated(note = "use BIO_meth_set_destroy instead")]
#[cfg(any(ossl110, libressl273))]
pub unsafe fn BIO_meth_set_destroy__fixed_rust(
biom: *mut BIO_METHOD,
destroy: Option<unsafe extern "C" fn(*mut BIO) -> c_int>,
) -> c_int {
BIO_meth_set_destroy(biom, destroy)
}
24 changes: 14 additions & 10 deletions openssl-sys/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use super::*;
use libc::*;

extern "C" {
#[deprecated(note = "use CRYPTO_set_locking_callback__fixed_rust instead")]
#[cfg(not(ossl110))]
pub fn CRYPTO_set_locking_callback(
func: unsafe extern "C" fn(mode: c_int, n: c_int, file: *const c_char, line: c_int),
);

#[deprecated(note = "use CRYPTO_set_id_callback__fixed_rust instead")]
#[cfg(not(ossl110))]
pub fn CRYPTO_set_id_callback(func: unsafe extern "C" fn() -> c_ulong);
// These symbols were originally bound with the wrong signatures. They were then
// deprecated in favor of `__fixed_rust`-suffixed versions. The unsuffixed
// symbols are now fixed, so the suffixed ones are deprecated aliases.
#[cfg(not(ossl110))]
#[deprecated(note = "use CRYPTO_set_locking_callback instead")]
pub fn CRYPTO_set_locking_callback__fixed_rust(
func: Option<unsafe extern "C" fn(mode: c_int, n: c_int, file: *const c_char, line: c_int)>,
) {
CRYPTO_set_locking_callback(func)
}
#[cfg(not(ossl110))]
#[deprecated(note = "use CRYPTO_set_id_callback instead")]
pub fn CRYPTO_set_id_callback__fixed_rust(func: Option<unsafe extern "C" fn() -> c_ulong>) {
CRYPTO_set_id_callback(func)
}

cfg_if! {
Expand Down
18 changes: 6 additions & 12 deletions openssl-sys/src/handwritten/bio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,32 @@ extern "C" {
#[allow(clashing_extern_declarations)]
extern "C" {
#[cfg(any(ossl110, libressl273))]
#[link_name = "BIO_meth_set_write"]
pub fn BIO_meth_set_write__fixed_rust(
pub fn BIO_meth_set_write(
biom: *mut BIO_METHOD,
write: Option<unsafe extern "C" fn(*mut BIO, *const c_char, c_int) -> c_int>,
) -> c_int;
#[cfg(any(ossl110, libressl273))]
#[link_name = "BIO_meth_set_read"]
pub fn BIO_meth_set_read__fixed_rust(
pub fn BIO_meth_set_read(
biom: *mut BIO_METHOD,
read: Option<unsafe extern "C" fn(*mut BIO, *mut c_char, c_int) -> c_int>,
) -> c_int;
#[cfg(any(ossl110, libressl273))]
#[link_name = "BIO_meth_set_puts"]
pub fn BIO_meth_set_puts__fixed_rust(
pub fn BIO_meth_set_puts(
biom: *mut BIO_METHOD,
read: Option<unsafe extern "C" fn(*mut BIO, *const c_char) -> c_int>,
) -> c_int;
#[cfg(any(ossl110, libressl273))]
#[link_name = "BIO_meth_set_ctrl"]
pub fn BIO_meth_set_ctrl__fixed_rust(
pub fn BIO_meth_set_ctrl(
biom: *mut BIO_METHOD,
read: Option<unsafe extern "C" fn(*mut BIO, c_int, c_long, *mut c_void) -> c_long>,
) -> c_int;
#[cfg(any(ossl110, libressl273))]
#[link_name = "BIO_meth_set_create"]
pub fn BIO_meth_set_create__fixed_rust(
pub fn BIO_meth_set_create(
biom: *mut BIO_METHOD,
create: Option<unsafe extern "C" fn(*mut BIO) -> c_int>,
) -> c_int;
#[cfg(any(ossl110, libressl273))]
#[link_name = "BIO_meth_set_destroy"]
pub fn BIO_meth_set_destroy__fixed_rust(
pub fn BIO_meth_set_destroy(
biom: *mut BIO_METHOD,
destroy: Option<unsafe extern "C" fn(*mut BIO) -> c_int>,
) -> c_int;
Expand Down
6 changes: 2 additions & 4 deletions openssl-sys/src/handwritten/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ extern "C" {
#[allow(clashing_extern_declarations)]
extern "C" {
#[cfg(not(ossl110))]
#[link_name = "CRYPTO_set_locking_callback"]
pub fn CRYPTO_set_locking_callback__fixed_rust(
pub fn CRYPTO_set_locking_callback(
func: Option<unsafe extern "C" fn(mode: c_int, n: c_int, file: *const c_char, line: c_int)>,
);

#[cfg(not(ossl110))]
#[link_name = "CRYPTO_set_id_callback"]
pub fn CRYPTO_set_id_callback__fixed_rust(func: Option<unsafe extern "C" fn() -> c_ulong>);
pub fn CRYPTO_set_id_callback(func: Option<unsafe extern "C" fn() -> c_ulong>);
}

extern "C" {
Expand Down
18 changes: 6 additions & 12 deletions openssl-sys/src/handwritten/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ extern "C" {
#[cfg(any(ossl102, libressl261))]
pub fn SSL_set_alpn_protos(s: *mut SSL, data: *const c_uchar, len: c_uint) -> c_int;
#[cfg(any(ossl102, libressl261))]
#[link_name = "SSL_CTX_set_alpn_select_cb"]
pub fn SSL_CTX_set_alpn_select_cb__fixed_rust(
pub fn SSL_CTX_set_alpn_select_cb(
ssl: *mut SSL_CTX,
cb: Option<
unsafe extern "C" fn(
Expand Down Expand Up @@ -670,8 +669,7 @@ extern "C" {
) -> c_int;
pub fn SSL_ctrl(ssl: *mut SSL, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long;
pub fn SSL_CTX_ctrl(ctx: *mut SSL_CTX, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long;
#[link_name = "SSL_CTX_callback_ctrl"]
pub fn SSL_CTX_callback_ctrl__fixed_rust(
pub fn SSL_CTX_callback_ctrl(
ctx: *mut SSL_CTX,
cmd: c_int,
fp: Option<unsafe extern "C" fn()>,
Expand Down Expand Up @@ -818,31 +816,27 @@ extern "C" {
}

extern "C" {
#[link_name = "SSL_CTX_set_tmp_dh_callback"]
pub fn SSL_CTX_set_tmp_dh_callback__fixed_rust(
pub fn SSL_CTX_set_tmp_dh_callback(
ctx: *mut SSL_CTX,
dh: Option<
unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut DH,
>,
);
#[link_name = "SSL_set_tmp_dh_callback"]
pub fn SSL_set_tmp_dh_callback__fixed_rust(
pub fn SSL_set_tmp_dh_callback(
ctx: *mut SSL,
dh: Option<
unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut DH,
>,
);
#[cfg(not(ossl110))]
#[link_name = "SSL_CTX_set_tmp_ecdh_callback"]
pub fn SSL_CTX_set_tmp_ecdh_callback__fixed_rust(
pub fn SSL_CTX_set_tmp_ecdh_callback(
ctx: *mut SSL_CTX,
ecdh: Option<
unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut EC_KEY,
>,
);
#[cfg(not(ossl110))]
#[link_name = "SSL_set_tmp_ecdh_callback"]
pub fn SSL_set_tmp_ecdh_callback__fixed_rust(
pub fn SSL_set_tmp_ecdh_callback(
ssl: *mut SSL,
ecdh: Option<
unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut EC_KEY,
Expand Down
4 changes: 2 additions & 2 deletions openssl-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod openssl {
}

unsafe {
CRYPTO_set_id_callback__fixed_rust(Some(thread_id));
CRYPTO_set_id_callback(Some(thread_id));
}
}
} else {
Expand All @@ -190,7 +190,7 @@ mod openssl {
Box::new((0..num_locks).map(|_| None).collect());
GUARDS = mem::transmute(guards);

CRYPTO_set_locking_callback__fixed_rust(Some(locking_function));
CRYPTO_set_locking_callback(Some(locking_function));
set_id_callback();
})
}
Expand Down
Loading

0 comments on commit 2c098b7

Please sign in to comment.