Skip to content

Commit 62eaff4

Browse files
committed
Merge branch 'fix-array-2' of github.com:rbran/binaryninja-api into dev
2 parents bec6531 + f3c1a3c commit 62eaff4

17 files changed

+117
-118
lines changed

rust/src/backgroundtask.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ unsafe impl CoreOwnedArrayProvider for BackgroundTask {
112112
}
113113
}
114114

115-
unsafe impl<'a> CoreArrayWrapper<'a> for BackgroundTask {
116-
type Wrapped = Guard<'a, BackgroundTask>;
115+
unsafe impl CoreArrayWrapper for BackgroundTask {
116+
type Wrapped<'a> = Guard<'a, BackgroundTask>;
117117

118-
unsafe fn wrap_raw(
118+
unsafe fn wrap_raw<'a>(
119119
raw: &'a *mut BNBackgroundTask,
120120
context: &'a (),
121-
) -> Guard<'a, BackgroundTask> {
121+
) -> Self::Wrapped<'a> {
122122
Guard::new(BackgroundTask::from_raw(*raw), context)
123123
}
124124
}

rust/src/basicblock.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ unsafe impl<'a, C: 'a + BlockContext> CoreOwnedArrayProvider for Edge<'a, C> {
7676
}
7777
}
7878

79-
unsafe impl<'a, C: 'a + BlockContext> CoreArrayWrapper<'a> for Edge<'a, C> {
80-
type Wrapped = Edge<'a, C>;
79+
unsafe impl<'a, C: BlockContext> CoreArrayWrapper for Edge<'a, C> {
80+
type Wrapped<'b> = Edge<'b, C> where 'a: 'b;
8181

82-
unsafe fn wrap_raw(raw: &'a Self::Raw, context: &'a Self::Context) -> Edge<'a, C> {
82+
unsafe fn wrap_raw<'b>(raw: &'b Self::Raw, context: &'b Self::Context) -> Self::Wrapped<'b> {
8383
let edge_target = Guard::new(
8484
BasicBlock::from_raw(raw.target, context.orig_block.context.clone()),
8585
raw,
@@ -309,10 +309,10 @@ unsafe impl<C: BlockContext> CoreOwnedArrayProvider for BasicBlock<C> {
309309
}
310310
}
311311

312-
unsafe impl<'a, C: 'a + BlockContext> CoreArrayWrapper<'a> for BasicBlock<C> {
313-
type Wrapped = Guard<'a, BasicBlock<C>>;
312+
unsafe impl<C: BlockContext> CoreArrayWrapper for BasicBlock<C> {
313+
type Wrapped<'a> = Guard<'a, BasicBlock<C>> where C: 'a;
314314

315-
unsafe fn wrap_raw(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped {
315+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
316316
Guard::new(BasicBlock::from_raw(*raw, context.clone()), context)
317317
}
318318
}

rust/src/callingconvention.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,10 @@ unsafe impl<A: Architecture> CoreOwnedArrayProvider for CallingConvention<A> {
694694
}
695695
}
696696

697-
unsafe impl<'a, A: Architecture> CoreArrayWrapper<'a> for CallingConvention<A> {
698-
type Wrapped = Guard<'a, CallingConvention<A>>;
697+
unsafe impl<A: Architecture> CoreArrayWrapper for CallingConvention<A> {
698+
type Wrapped<'a> = Guard<'a, CallingConvention<A>>;
699699

700-
unsafe fn wrap_raw(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped {
700+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
701701
Guard::new(
702702
CallingConvention {
703703
handle: *raw,

rust/src/custombinaryview.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ unsafe impl CoreOwnedArrayProvider for BinaryViewType {
297297
}
298298
}
299299

300-
unsafe impl<'a> CoreArrayWrapper<'a> for BinaryViewType {
301-
type Wrapped = BinaryViewType;
300+
unsafe impl CoreArrayWrapper for BinaryViewType {
301+
type Wrapped<'a> = Guard<'a, BinaryViewType>;
302302

303-
unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped {
304-
BinaryViewType(*raw)
303+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
304+
Guard::new(BinaryViewType(*raw), &())
305305
}
306306
}
307307

rust/src/downloadprovider.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::rc::{
2-
Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref, RefCountable,
2+
Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable,
33
};
44
use crate::settings::Settings;
55
use crate::string::{BnStrCompatible, BnString};
@@ -71,11 +71,11 @@ unsafe impl CoreOwnedArrayProvider for DownloadProvider {
7171
}
7272
}
7373

74-
unsafe impl<'a> CoreArrayWrapper<'a> for DownloadProvider {
75-
type Wrapped = DownloadProvider;
74+
unsafe impl CoreArrayWrapper for DownloadProvider {
75+
type Wrapped<'a> = Guard<'a, DownloadProvider>;
7676

77-
unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped {
78-
DownloadProvider::from_raw(*raw)
77+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
78+
Guard::new(DownloadProvider::from_raw(*raw), &())
7979
}
8080
}
8181

rust/src/function.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ unsafe impl CoreOwnedArrayProvider for Function {
422422
}
423423
}
424424

425-
unsafe impl<'a> CoreArrayWrapper<'a> for Function {
426-
type Wrapped = Guard<'a, Function>;
425+
unsafe impl CoreArrayWrapper for Function {
426+
type Wrapped<'a> = Guard<'a, Function>;
427427

428-
unsafe fn wrap_raw(raw: &'a *mut BNFunction, context: &'a ()) -> Guard<'a, Function> {
428+
unsafe fn wrap_raw<'a>(raw: &'a *mut BNFunction, context: &'a ()) -> Self::Wrapped<'a> {
429429
Guard::new(Function { handle: *raw }, context)
430430
}
431431
}
@@ -476,10 +476,10 @@ unsafe impl CoreOwnedArrayProvider for AddressRange {
476476
}
477477
}
478478

479-
unsafe impl<'a> CoreArrayWrapper<'a> for AddressRange {
480-
type Wrapped = &'a AddressRange;
479+
unsafe impl CoreArrayWrapper for AddressRange {
480+
type Wrapped<'a> = &'a AddressRange;
481481

482-
unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped {
482+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
483483
mem::transmute(raw)
484484
}
485485
}

rust/src/linearview.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,10 @@ unsafe impl CoreOwnedArrayProvider for LinearDisassemblyLine {
423423
}
424424
}
425425

426-
unsafe impl<'a> CoreArrayWrapper<'a> for LinearDisassemblyLine {
427-
type Wrapped = Guard<'a, LinearDisassemblyLine>;
426+
unsafe impl CoreArrayWrapper for LinearDisassemblyLine {
427+
type Wrapped<'a> = Guard<'a, LinearDisassemblyLine>;
428428

429-
unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped {
429+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
430430
Guard::new(LinearDisassemblyLine::from_raw(raw), _context)
431431
}
432432
}

rust/src/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ unsafe impl CoreOwnedArrayProvider for Metadata {
343343
}
344344
}
345345

346-
unsafe impl<'a> CoreArrayWrapper<'a> for Metadata {
347-
type Wrapped = Guard<'a, Metadata>;
346+
unsafe impl CoreArrayWrapper for Metadata {
347+
type Wrapped<'a> = Guard<'a, Metadata>;
348348

349-
unsafe fn wrap_raw(raw: &'a *mut BNMetadata, context: &'a ()) -> Guard<'a, Metadata> {
349+
unsafe fn wrap_raw<'a>(raw: &'a *mut BNMetadata, context: &'a ()) -> Self::Wrapped<'a> {
350350
Guard::new(Metadata::from_raw(*raw), context)
351351
}
352352
}

rust/src/platform.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ unsafe impl CoreOwnedArrayProvider for Platform {
373373
}
374374
}
375375

376-
unsafe impl<'a> CoreArrayWrapper<'a> for Platform {
377-
type Wrapped = Guard<'a, Platform>;
376+
unsafe impl CoreArrayWrapper for Platform {
377+
type Wrapped<'a> = Guard<'a, Platform>;
378378

379-
unsafe fn wrap_raw(raw: &'a *mut BNPlatform, context: &'a ()) -> Guard<'a, Platform> {
379+
unsafe fn wrap_raw<'a>(raw: &'a *mut BNPlatform, context: &'a ()) -> Self::Wrapped<'a> {
380380
debug_assert!(!raw.is_null());
381381
Guard::new(Platform { handle: *raw }, context)
382382
}

rust/src/rc.rs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,12 @@ pub unsafe trait CoreOwnedArrayProvider: CoreArrayProvider {
196196
unsafe fn free(raw: *mut Self::Raw, count: usize, context: &Self::Context);
197197
}
198198

199-
pub unsafe trait CoreArrayWrapper<'a>: CoreArrayProvider
200-
where
201-
Self::Raw: 'a,
202-
Self::Context: 'a,
203-
{
204-
type Wrapped: 'a;
199+
pub unsafe trait CoreArrayWrapper: CoreArrayProvider {
200+
type Wrapped<'a>
201+
where
202+
Self: 'a;
205203

206-
unsafe fn wrap_raw(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped;
204+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a>;
207205
}
208206

209207
pub struct Array<P: CoreOwnedArrayProvider> {
@@ -250,25 +248,25 @@ impl<P: CoreOwnedArrayProvider> Array<P> {
250248
}
251249
}
252250

253-
impl<'a, P: 'a + CoreArrayWrapper<'a> + CoreOwnedArrayProvider> Array<P> {
251+
impl<P: CoreArrayWrapper + CoreOwnedArrayProvider> Array<P> {
254252
#[inline]
255-
pub fn get(&'a self, index: usize) -> P::Wrapped {
253+
pub fn get(&self, index: usize) -> P::Wrapped<'_> {
256254
unsafe {
257255
let backing = slice::from_raw_parts(self.contents, self.count);
258256
P::wrap_raw(&backing[index], &self.context)
259257
}
260258
}
261259

262-
pub fn iter(&'a self) -> ArrayIter<'a, P> {
260+
pub fn iter(&self) -> ArrayIter<P> {
263261
ArrayIter {
264262
it: unsafe { slice::from_raw_parts(self.contents, self.count).iter() },
265263
context: &self.context,
266264
}
267265
}
268266
}
269267

270-
impl<'a, P: 'a + CoreArrayWrapper<'a> + CoreOwnedArrayProvider> IntoIterator for &'a Array<P> {
271-
type Item = P::Wrapped;
268+
impl<'a, P: CoreArrayWrapper + CoreOwnedArrayProvider> IntoIterator for &'a Array<P> {
269+
type Item = P::Wrapped<'a>;
272270
type IntoIter = ArrayIter<'a, P>;
273271

274272
fn into_iter(self) -> Self::IntoIter {
@@ -323,25 +321,25 @@ impl<P: CoreArrayProvider> ArrayGuard<P> {
323321
}
324322
}
325323

326-
impl<'a, P: 'a + CoreArrayWrapper<'a> + CoreArrayProvider> ArrayGuard<P> {
324+
impl<P: CoreArrayWrapper + CoreArrayProvider> ArrayGuard<P> {
327325
#[inline]
328-
pub fn get(&'a self, index: usize) -> P::Wrapped {
326+
pub fn get(&self, index: usize) -> P::Wrapped<'_> {
329327
unsafe {
330328
let backing = slice::from_raw_parts(self.contents, self.count);
331329
P::wrap_raw(&backing[index], &self.context)
332330
}
333331
}
334332

335-
pub fn iter(&'a self) -> ArrayIter<'a, P> {
333+
pub fn iter(&self) -> ArrayIter<P> {
336334
ArrayIter {
337335
it: unsafe { slice::from_raw_parts(self.contents, self.count).iter() },
338336
context: &self.context,
339337
}
340338
}
341339
}
342340

343-
impl<'a, P: 'a + CoreArrayWrapper<'a> + CoreArrayProvider> IntoIterator for &'a ArrayGuard<P> {
344-
type Item = P::Wrapped;
341+
impl<'a, P: CoreArrayWrapper + CoreArrayProvider> IntoIterator for &'a ArrayGuard<P> {
342+
type Item = P::Wrapped<'a>;
345343
type IntoIter = ArrayIter<'a, P>;
346344

347345
fn into_iter(self) -> Self::IntoIter {
@@ -351,27 +349,27 @@ impl<'a, P: 'a + CoreArrayWrapper<'a> + CoreArrayProvider> IntoIterator for &'a
351349

352350
pub struct ArrayIter<'a, P>
353351
where
354-
P: 'a + CoreArrayWrapper<'a>,
352+
P: CoreArrayWrapper,
355353
{
356354
it: slice::Iter<'a, P::Raw>,
357355
context: &'a P::Context,
358356
}
359357

360-
unsafe impl<'a, P> Send for ArrayIter<'a, P>
358+
unsafe impl<P> Send for ArrayIter<'_, P>
361359
where
362-
P: CoreArrayWrapper<'a>,
360+
P: CoreArrayWrapper,
363361
P::Context: Sync,
364362
{
365363
}
366364

367365
impl<'a, P> Iterator for ArrayIter<'a, P>
368366
where
369-
P: 'a + CoreArrayWrapper<'a>,
367+
P: 'a + CoreArrayWrapper,
370368
{
371-
type Item = P::Wrapped;
369+
type Item = P::Wrapped<'a>;
372370

373371
#[inline]
374-
fn next(&mut self) -> Option<P::Wrapped> {
372+
fn next(&mut self) -> Option<Self::Item> {
375373
self.it
376374
.next()
377375
.map(|r| unsafe { P::wrap_raw(r, self.context) })
@@ -385,7 +383,7 @@ where
385383

386384
impl<'a, P> ExactSizeIterator for ArrayIter<'a, P>
387385
where
388-
P: 'a + CoreArrayWrapper<'a>,
386+
P: 'a + CoreArrayWrapper,
389387
{
390388
#[inline]
391389
fn len(&self) -> usize {
@@ -395,10 +393,10 @@ where
395393

396394
impl<'a, P> DoubleEndedIterator for ArrayIter<'a, P>
397395
where
398-
P: 'a + CoreArrayWrapper<'a>,
396+
P: 'a + CoreArrayWrapper,
399397
{
400398
#[inline]
401-
fn next_back(&mut self) -> Option<P::Wrapped> {
399+
fn next_back(&mut self) -> Option<P::Wrapped<'a>> {
402400
self.it
403401
.next_back()
404402
.map(|r| unsafe { P::wrap_raw(r, self.context) })
@@ -412,20 +410,20 @@ use rayon::prelude::*;
412410
use rayon::iter::plumbing::*;
413411

414412
#[cfg(feature = "rayon")]
415-
impl<'a, P> Array<P>
413+
impl<P> Array<P>
416414
where
417-
P: 'a + CoreArrayWrapper<'a> + CoreOwnedArrayProvider,
415+
P: CoreArrayWrapper + CoreOwnedArrayProvider,
418416
P::Context: Sync,
419-
P::Wrapped: Send,
417+
for<'a> P::Wrapped<'a>: Send,
420418
{
421-
pub fn par_iter(&'a self) -> ParArrayIter<'a, P> {
419+
pub fn par_iter(&self) -> ParArrayIter<'_, P> {
422420
ParArrayIter { it: self.iter() }
423421
}
424422
}
425423
#[cfg(feature = "rayon")]
426424
pub struct ParArrayIter<'a, P>
427425
where
428-
P: 'a + CoreArrayWrapper<'a>,
426+
P: 'a + CoreArrayWrapper,
429427
ArrayIter<'a, P>: Send,
430428
{
431429
it: ArrayIter<'a, P>,
@@ -434,11 +432,11 @@ where
434432
#[cfg(feature = "rayon")]
435433
impl<'a, P> ParallelIterator for ParArrayIter<'a, P>
436434
where
437-
P: 'a + CoreArrayWrapper<'a>,
438-
P::Wrapped: Send,
435+
P: 'a + CoreArrayWrapper,
436+
P::Wrapped<'a>: Send,
439437
ArrayIter<'a, P>: Send,
440438
{
441-
type Item = P::Wrapped;
439+
type Item = P::Wrapped<'a>;
442440

443441
fn drive_unindexed<C>(self, consumer: C) -> C::Result
444442
where
@@ -455,8 +453,8 @@ where
455453
#[cfg(feature = "rayon")]
456454
impl<'a, P> IndexedParallelIterator for ParArrayIter<'a, P>
457455
where
458-
P: 'a + CoreArrayWrapper<'a>,
459-
P::Wrapped: Send,
456+
P: 'a + CoreArrayWrapper,
457+
P::Wrapped<'a>: Send,
460458
ArrayIter<'a, P>: Send,
461459
{
462460
fn drive<C>(self, consumer: C) -> C::Result
@@ -481,7 +479,7 @@ where
481479
#[cfg(feature = "rayon")]
482480
struct ArrayIterProducer<'a, P>
483481
where
484-
P: 'a + CoreArrayWrapper<'a>,
482+
P: 'a + CoreArrayWrapper,
485483
ArrayIter<'a, P>: Send,
486484
{
487485
it: ArrayIter<'a, P>,
@@ -490,10 +488,10 @@ where
490488
#[cfg(feature = "rayon")]
491489
impl<'a, P> Producer for ArrayIterProducer<'a, P>
492490
where
493-
P: 'a + CoreArrayWrapper<'a>,
491+
P: 'a + CoreArrayWrapper,
494492
ArrayIter<'a, P>: Send,
495493
{
496-
type Item = P::Wrapped;
494+
type Item = P::Wrapped<'a>;
497495
type IntoIter = ArrayIter<'a, P>;
498496

499497
fn into_iter(self) -> ArrayIter<'a, P> {

0 commit comments

Comments
 (0)