From 16bb40f3232181e071545764409e1275e054a9b9 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Tue, 8 Nov 2016 00:39:49 +0100 Subject: [PATCH] Bug 1151899 - rust-url-capi error code changes; r=manishearth MozReview-Commit-ID: AHwbkgGifmr --HG-- extra : rebase_source : 82e96b565d44f9f742454ccf2198603d85f0f79c --- .../base/rust-url-capi/src/error_mapping.rs | 53 ++++++++----------- netwerk/base/rust-url-capi/src/lib.rs | 18 +++++-- .../base/rust-url-capi/src/rust-url-capi.h | 8 ++- .../base/rust-url-capi/src/string_utils.rs | 4 ++ netwerk/base/rust-url-capi/test/test.cpp | 4 ++ 5 files changed, 53 insertions(+), 34 deletions(-) diff --git a/netwerk/base/rust-url-capi/src/error_mapping.rs b/netwerk/base/rust-url-capi/src/error_mapping.rs index f20afb263c5f..587076a1bc64 100644 --- a/netwerk/base/rust-url-capi/src/error_mapping.rs +++ b/netwerk/base/rust-url-capi/src/error_mapping.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + use url::ParseError; pub trait ErrorCode { @@ -13,40 +17,29 @@ impl ErrorCode for Result<(), T> { } } -impl ErrorCode for () { - fn error_code(&self) -> i32 { - return -1; +impl ErrorCode for Result<(), ()> { + fn error_code(&self) -> i32 { + match *self { + Ok(_) => 0, + Err(_) => -255, } + } } + impl ErrorCode for ParseError { fn error_code(&self) -> i32 { - return -1; -// match *self { -// ParseError::EmptyHost => -1, -// ParseError::InvalidScheme => -2, -// ParseError::InvalidPort => -3, -// ParseError::InvalidIpv6Address => -4, -// ParseError::InvalidDomainCharacter => -5, -// ParseError::InvalidCharacter => -6, -// ParseError::InvalidBackslash => -7, -// ParseError::InvalidPercentEncoded => -8, -// ParseError::InvalidAtSymbolInUser => -9, -// ParseError::ExpectedTwoSlashes => -10, -// ParseError::ExpectedInitialSlash => -11, -// ParseError::NonUrlCodePoint => -12, -// ParseError::RelativeUrlWithScheme => -13, -// ParseError::RelativeUrlWithoutBase => -14, -// ParseError::RelativeUrlWithNonRelativeBase => -15, -// ParseError::NonAsciiDomainsNotSupportedYet => -16, -// ParseError::CannotSetJavascriptFragment => -17, -// ParseError::CannotSetPortWithFileLikeScheme => -18, -// ParseError::CannotSetUsernameWithNonRelativeScheme => -19, -// ParseError::CannotSetPasswordWithNonRelativeScheme => -20, -// ParseError::CannotSetHostPortWithNonRelativeScheme => -21, -// ParseError::CannotSetHostWithNonRelativeScheme => -22, -// ParseError::CannotSetPortWithNonRelativeScheme => -23, -// ParseError::CannotSetPathWithNonRelativeScheme => -24, -// } + match *self { + ParseError::EmptyHost => -1, + ParseError::InvalidPort => -2, + ParseError::InvalidIpv6Address => -3, + ParseError::InvalidDomainCharacter => -4, + ParseError::IdnaError => -5, + ParseError::InvalidIpv4Address => -6, + ParseError::RelativeUrlWithoutBase => -7, + ParseError::RelativeUrlWithCannotBeABaseBase => -8, + ParseError::SetHostOnCannotBeABaseUrl => -9, + ParseError::Overflow => -10, + } } } diff --git a/netwerk/base/rust-url-capi/src/lib.rs b/netwerk/base/rust-url-capi/src/lib.rs index e2997ce46997..26ec91d5804c 100644 --- a/netwerk/base/rust-url-capi/src/lib.rs +++ b/netwerk/base/rust-url-capi/src/lib.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + extern crate url; use url::{Url, ParseError, ParseOptions}; use url::quirks; @@ -320,7 +324,9 @@ pub unsafe extern "C" fn rusturl_set_path(urlptr: rusturl_ptr, path: *mut libc:: None => return ParseError::InvalidDomainCharacter.error_code() // utf-8 failed }; - quirks::set_pathname(url, path_).error_code() + quirks::set_pathname(url, path_); + NSError::OK.error_code() + } #[no_mangle] @@ -336,7 +342,8 @@ pub unsafe extern "C" fn rusturl_set_query(urlptr: rusturl_ptr, query: *mut libc None => return ParseError::InvalidDomainCharacter.error_code() // utf-8 failed }; - quirks::set_search(url, query_).error_code() + quirks::set_search(url, query_); + NSError::OK.error_code() } #[no_mangle] @@ -352,7 +359,8 @@ pub unsafe extern "C" fn rusturl_set_fragment(urlptr: rusturl_ptr, fragment: *mu None => return ParseError::InvalidDomainCharacter.error_code() // utf-8 failed }; - quirks::set_hash(url, fragment_).error_code() + quirks::set_hash(url, fragment_); + NSError::OK.error_code() } #[no_mangle] @@ -475,3 +483,7 @@ pub unsafe extern "C" fn rusturl_relative_spec(urlptr1: rusturl_ptr, urlptr2: ru return cont.assign(&buffer); } +#[no_mangle] +pub unsafe extern "C" fn sizeof_rusturl() -> size_t { + mem::size_of::() +} diff --git a/netwerk/base/rust-url-capi/src/rust-url-capi.h b/netwerk/base/rust-url-capi/src/rust-url-capi.h index 8d7a05aedcc7..ed5c75e01c2d 100644 --- a/netwerk/base/rust-url-capi/src/rust-url-capi.h +++ b/netwerk/base/rust-url-capi/src/rust-url-capi.h @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef __RUST_URL_CAPI #define __RUST_URL_CAPI #include @@ -38,8 +42,10 @@ int32_t rusturl_resolve(rusturl_ptr url, const char *relative, size_t len, void* int32_t rusturl_common_base_spec(rusturl_ptr url1, rusturl_ptr url2, void*); int32_t rusturl_relative_spec(rusturl_ptr url1, rusturl_ptr url2, void*); +size_t sizeof_rusturl(); + #ifdef __cplusplus } #endif -#endif // __RUST_URL_CAPI \ No newline at end of file +#endif // __RUST_URL_CAPI diff --git a/netwerk/base/rust-url-capi/src/string_utils.rs b/netwerk/base/rust-url-capi/src/string_utils.rs index ae68a60dc3d2..7ada29d04a8a 100644 --- a/netwerk/base/rust-url-capi/src/string_utils.rs +++ b/netwerk/base/rust-url-capi/src/string_utils.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + extern crate libc; use libc::size_t; diff --git a/netwerk/base/rust-url-capi/test/test.cpp b/netwerk/base/rust-url-capi/test/test.cpp index 6e90ea43b0cd..80a83c91d691 100644 --- a/netwerk/base/rust-url-capi/test/test.cpp +++ b/netwerk/base/rust-url-capi/test/test.cpp @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include #include #include