Bug 1567739 - Stop using deprecated rust libc integer types in storage_variant and kvstore. r=lina

Differential Revision: https://phabricator.services.mozilla.com/D38940

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Hommey 2019-07-23 00:13:43 +00:00
Родитель baf04d4ceb
Коммит 103c1bec20
3 изменённых файлов: 13 добавлений и 15 удалений

Просмотреть файл

@ -9,7 +9,7 @@ extern crate xpcom;
mod bag;
use libc::{c_double, int64_t, uint16_t};
use libc::c_double;
use nserror::{nsresult, NS_OK};
use nsstring::{nsACString, nsAString, nsCString, nsString};
use xpcom::{getter_addrefs, interfaces::nsIVariant, RefPtr};
@ -17,10 +17,10 @@ use xpcom::{getter_addrefs, interfaces::nsIVariant, RefPtr};
pub use crate::bag::HashPropertyBag;
extern "C" {
fn NS_GetDataType(variant: *const nsIVariant) -> uint16_t;
fn NS_GetDataType(variant: *const nsIVariant) -> u16;
fn NS_NewStorageNullVariant(result: *mut *const nsIVariant);
fn NS_NewStorageBooleanVariant(value: bool, result: *mut *const nsIVariant);
fn NS_NewStorageIntegerVariant(value: int64_t, result: *mut *const nsIVariant);
fn NS_NewStorageIntegerVariant(value: i64, result: *mut *const nsIVariant);
fn NS_NewStorageFloatVariant(value: c_double, result: *mut *const nsIVariant);
fn NS_NewStorageTextVariant(value: *const nsAString, result: *mut *const nsIVariant);
fn NS_NewStorageUTF8TextVariant(value: *const nsACString, result: *mut *const nsIVariant);
@ -52,19 +52,19 @@ pub enum DataType {
// and since that enum is unlikely to change frequently, this workaround
// seems sufficient.)
//
pub const DATA_TYPE_INT32: uint16_t = DataType::INT32 as u16;
pub const DATA_TYPE_DOUBLE: uint16_t = DataType::DOUBLE as u16;
pub const DATA_TYPE_BOOL: uint16_t = DataType::BOOL as u16;
pub const DATA_TYPE_VOID: uint16_t = DataType::VOID as u16;
pub const DATA_TYPE_WSTRING: uint16_t = DataType::WSTRING as u16;
pub const DATA_TYPE_EMPTY: uint16_t = DataType::EMPTY as u16;
pub const DATA_TYPE_INT32: u16 = DataType::INT32 as u16;
pub const DATA_TYPE_DOUBLE: u16 = DataType::DOUBLE as u16;
pub const DATA_TYPE_BOOL: u16 = DataType::BOOL as u16;
pub const DATA_TYPE_VOID: u16 = DataType::VOID as u16;
pub const DATA_TYPE_WSTRING: u16 = DataType::WSTRING as u16;
pub const DATA_TYPE_EMPTY: u16 = DataType::EMPTY as u16;
pub trait GetDataType {
fn get_data_type(&self) -> uint16_t;
fn get_data_type(&self) -> u16;
}
impl GetDataType for nsIVariant {
fn get_data_type(&self) -> uint16_t {
fn get_data_type(&self) -> u16 {
unsafe { NS_GetDataType(self) }
}
}

Просмотреть файл

@ -2,7 +2,6 @@
* 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 libc::uint16_t;
use nserror::{
nsresult, NS_ERROR_FAILURE, NS_ERROR_NOT_IMPLEMENTED, NS_ERROR_NO_INTERFACE,
NS_ERROR_NULL_POINTER, NS_ERROR_UNEXPECTED,
@ -53,7 +52,7 @@ pub enum KeyValueError {
UnexpectedValue,
#[fail(display = "unsupported variant type: {}", _0)]
UnsupportedVariant(uint16_t),
UnsupportedVariant(u16),
}
impl From<nsresult> for KeyValueError {

Просмотреть файл

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use error::KeyValueError;
use libc::int32_t;
use nsstring::nsString;
use rkv::OwnedValue;
use storage_variant::{
@ -35,7 +34,7 @@ pub fn variant_to_owned(variant: &nsIVariant) -> Result<Option<OwnedValue>, KeyV
match data_type {
DATA_TYPE_INT32 => {
let mut val: int32_t = 0;
let mut val: i32 = 0;
unsafe { variant.GetAsInt32(&mut val) }.to_result()?;
Ok(Some(OwnedValue::I64(val.into())))
}