mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1622732 - Use error! instead of println! in rsdparsa_capi; r=ng
Differential Revision: https://phabricator.services.mozilla.com/D66958 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
8e00f3c3ce
commit
c57e9e9841
@ -24,6 +24,9 @@ use rsdparsa::error::SdpParserError;
|
||||
use rsdparsa::media_type::{SdpMediaValue, SdpProtocolValue};
|
||||
use rsdparsa::{SdpBandwidth, SdpSession, SdpTiming};
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
pub mod attribute;
|
||||
pub mod media_section;
|
||||
pub mod network;
|
||||
@ -39,13 +42,13 @@ pub unsafe extern "C" fn parse_sdp(
|
||||
sdp: StringView,
|
||||
fail_on_warning: bool,
|
||||
session: *mut *const SdpSession,
|
||||
error: *mut *const SdpParserError,
|
||||
parser_error: *mut *const SdpParserError,
|
||||
) -> nsresult {
|
||||
let sdp_str: String = match sdp.try_into() {
|
||||
Ok(string) => string,
|
||||
Err(boxed_error) => {
|
||||
*session = ptr::null();
|
||||
*error = Box::into_raw(Box::new(SdpParserError::Sequence {
|
||||
*parser_error = Box::into_raw(Box::new(SdpParserError::Sequence {
|
||||
message: format!("{}", boxed_error),
|
||||
line_number: 0,
|
||||
}));
|
||||
@ -56,7 +59,7 @@ pub unsafe extern "C" fn parse_sdp(
|
||||
let parser_result = rsdparsa::parse_sdp(&sdp_str, fail_on_warning);
|
||||
match parser_result {
|
||||
Ok(mut parsed) => {
|
||||
*error = match parsed.warnings.len() {
|
||||
*parser_error = match parsed.warnings.len() {
|
||||
0 => ptr::null(),
|
||||
_ => Box::into_raw(Box::new(parsed.warnings.remove(0))),
|
||||
};
|
||||
@ -65,8 +68,8 @@ pub unsafe extern "C" fn parse_sdp(
|
||||
}
|
||||
Err(e) => {
|
||||
*session = ptr::null();
|
||||
println!("Error parsing SDP in rust: {}", e);
|
||||
*error = Box::into_raw(Box::new(e));
|
||||
error!("Error parsing SDP in rust: {}", e);
|
||||
*parser_error = Box::into_raw(Box::new(e));
|
||||
NS_ERROR_INVALID_ARG
|
||||
}
|
||||
}
|
||||
@ -96,8 +99,8 @@ pub unsafe extern "C" fn sdp_new_reference(session: *mut SdpSession) -> *const S
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sdp_get_error_line_num(error: *mut SdpParserError) -> size_t {
|
||||
match *error {
|
||||
pub unsafe extern "C" fn sdp_get_error_line_num(parser_error: *mut SdpParserError) -> size_t {
|
||||
match *parser_error {
|
||||
SdpParserError::Line { line_number, .. }
|
||||
| SdpParserError::Unsupported { line_number, .. }
|
||||
| SdpParserError::Sequence { line_number, .. } => line_number,
|
||||
@ -106,8 +109,8 @@ pub unsafe extern "C" fn sdp_get_error_line_num(error: *mut SdpParserError) -> s
|
||||
|
||||
#[no_mangle]
|
||||
// Callee must check that a nullptr is not returned
|
||||
pub unsafe extern "C" fn sdp_get_error_message(error: *mut SdpParserError) -> *mut c_char {
|
||||
let message = format!("{}", *error);
|
||||
pub unsafe extern "C" fn sdp_get_error_message(parser_error: *mut SdpParserError) -> *mut c_char {
|
||||
let message = format!("{}", *parser_error);
|
||||
return match CString::new(message.as_str()) {
|
||||
Ok(c_char_ptr) => c_char_ptr.into_raw(),
|
||||
Err(_) => 0 as *mut c_char,
|
||||
@ -122,8 +125,8 @@ pub unsafe extern "C" fn sdp_free_error_message(message: *mut c_char) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sdp_free_error(error: *mut SdpParserError) {
|
||||
let e = Box::from_raw(error);
|
||||
pub unsafe extern "C" fn sdp_free_error(parser_error: *mut SdpParserError) {
|
||||
let e = Box::from_raw(parser_error);
|
||||
drop(e);
|
||||
}
|
||||
|
||||
@ -180,7 +183,7 @@ pub unsafe extern "C" fn sdp_add_media_section(
|
||||
let address_string: String = match address.try_into() {
|
||||
Ok(x) => x,
|
||||
Err(boxed_error) => {
|
||||
println!("Error while parsing string, description: {}", boxed_error);
|
||||
error!("Error while parsing string, description: {}", boxed_error);
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
};
|
||||
|
@ -198,7 +198,7 @@ pub unsafe extern "C" fn sdp_media_add_codec(
|
||||
codec_name: match codec_name.try_into() {
|
||||
Ok(x) => x,
|
||||
Err(boxed_error) => {
|
||||
println!("Error while parsing string, description: {}", boxed_error);
|
||||
error!("Error while parsing string, description: {}", boxed_error);
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user