Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c25d09a1 authored by Jeff Vander Stoep's avatar Jeff Vander Stoep
Browse files

Use usize instead of c_long in Rust code

Needed to upgrade bindgen from 0.59.0 to 0.63.0. Resolves the
following errors:

error[E0308]: mismatched types
  --> frameworks/native/libs/binder/rust/src/parcel/parcelable.rs:91:22
   |
91 |                 Some(serialize_element::<Self>),
   |                 ---- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u64
`
   |                 |
   |                 arguments to this enum variant are incorrect
   |
   = note: expected fn pointer `unsafe extern "C" fn(_, _, usize) -> _`
                 found fn item `unsafe extern "C" fn(_, _, u64) -> _ {parcel::pa
rcelable::serialize_element::<Self>}`
note: tuple variant defined here

error[E0308]: mismatched types
   --> frameworks/native/libs/binder/rust/src/parcel/parcelable.rs:136:22
    |
136 |                 Some(deserialize_element::<Self>),
    |                 ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `
u64`
    |                 |
    |                 arguments to this enum variant are incorrect
    |
    = note: expected fn pointer `unsafe extern "C" fn(_, _, usize) -> _`
                  found fn item `unsafe extern "C" fn(_, _, u64) -> _ {parcel::p
arcelable::deserialize_element::<Self>}`

Test: Treehugger
Change-Id: I019e17bd8770da0574b2397f72e717419aa537cd
parent 1884da10
Loading
Loading
Loading
Loading
+3 −11
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ use crate::sys;
use std::convert::{TryFrom, TryInto};
use std::ffi::c_void;
use std::mem::{self, ManuallyDrop, MaybeUninit};
use std::os::raw::{c_char, c_ulong};
use std::os::raw::c_char;
use std::ptr;
use std::slice;

@@ -103,12 +103,8 @@ pub trait SerializeArray: Serialize + Sized {
unsafe extern "C" fn serialize_element<T: Serialize>(
    parcel: *mut sys::AParcel,
    array: *const c_void,
    index: c_ulong,
    index: usize,
) -> status_t {
    // c_ulong and usize are the same, but we need the explicitly sized version
    // so the function signature matches what bindgen generates.
    let index = index as usize;

    let slice: &[T] = slice::from_raw_parts(array.cast(), index + 1);

    let mut parcel = match BorrowedParcel::from_raw(parcel) {
@@ -158,12 +154,8 @@ pub trait DeserializeArray: Deserialize {
unsafe extern "C" fn deserialize_element<T: Deserialize>(
    parcel: *const sys::AParcel,
    array: *mut c_void,
    index: c_ulong,
    index: usize,
) -> status_t {
    // c_ulong and usize are the same, but we need the explicitly sized version
    // so the function signature matches what bindgen generates.
    let index = index as usize;

    let vec = &mut *(array as *mut Option<Vec<MaybeUninit<T>>>);
    let vec = match vec {
        Some(v) => v,