Skip to content

Commit 6a39c87

Browse files
committed
from_parts should be unsafe
1 parent dd0d41d commit 6a39c87

File tree

11 files changed

+57
-54
lines changed

11 files changed

+57
-54
lines changed

alpm/src/conflict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Alpm {
188188
) -> AlpmListMut<OwnedConflict> {
189189
let list = unsafe { list.into_raw_alpm_list() };
190190
let ret = unsafe { alpm_checkconflicts(self.as_ptr(), list.list()) };
191-
AlpmListMut::from_parts(self, ret)
191+
unsafe { AlpmListMut::from_parts(self, ret) }
192192
}
193193
}
194194

alpm/src/db.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'h> Db<'h> {
109109

110110
pub fn servers(&self) -> AlpmList<'h, &'h str> {
111111
let list = unsafe { alpm_db_get_servers(self.as_ptr()) };
112-
AlpmList::from_parts(self.handle, list)
112+
unsafe { AlpmList::from_parts(self.handle, list) }
113113
}
114114

115115
pub fn pkg<S: Into<Vec<u8>>>(&self, name: S) -> Result<Package<'h>> {
@@ -122,7 +122,7 @@ impl<'h> Db<'h> {
122122
#[doc(alias = "pkgcache")]
123123
pub fn pkgs(&self) -> AlpmList<'h, Package<'h>> {
124124
let pkgs = unsafe { alpm_db_get_pkgcache(self.as_ptr()) };
125-
AlpmList::from_parts(self.handle, pkgs)
125+
unsafe { AlpmList::from_parts(self.handle, pkgs) }
126126
}
127127

128128
pub fn group<S: Into<Vec<u8>>>(&self, name: S) -> Result<Group<'h>> {
@@ -145,14 +145,14 @@ impl<'h> Db<'h> {
145145
let list = unsafe { list.into_raw_alpm_list() };
146146
let ok = unsafe { alpm_db_search(self.as_ptr(), list.list(), &mut ret) };
147147
self.handle.check_ret(ok)?;
148-
Ok(AlpmListMut::from_parts(self.handle, ret))
148+
unsafe { Ok(AlpmListMut::from_parts(self.handle, ret)) }
149149
}
150150

151151
#[doc(alias = "groupcache")]
152152
pub fn groups(&self) -> Result<AlpmListMut<'h, Group<'h>>> {
153153
let groups = unsafe { alpm_db_get_groupcache(self.as_ptr()) };
154154
self.handle.check_null(groups)?;
155-
Ok(AlpmListMut::from_parts(self.handle, groups))
155+
unsafe { Ok(AlpmListMut::from_parts(self.handle, groups)) }
156156
}
157157

158158
pub fn siglevel(&self) -> SigLevel {

alpm/src/deps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl Alpm {
363363
reverse_deps,
364364
)
365365
};
366-
AlpmListMut::from_parts(self, ret)
366+
unsafe { AlpmListMut::from_parts(self, ret) }
367367
}
368368
}
369369

alpm/src/dload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Alpm {
1313
let list = unsafe { urls.into_raw_alpm_list() };
1414
let ret = unsafe { alpm_fetch_pkgurl(self.as_ptr(), list.list(), &mut out) };
1515
self.check_ret(ret)?;
16-
let fetched = AlpmListMut::from_parts(self, out);
16+
let fetched = unsafe { AlpmListMut::from_parts(self, out) };
1717
Ok(fetched)
1818
}
1919
}

alpm/src/handle.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ impl Alpm {
2727

2828
pub fn hookdirs(&self) -> AlpmList<'_, &str> {
2929
let list = unsafe { alpm_option_get_hookdirs(self.as_ptr()) };
30-
AlpmList::from_parts(self, list)
30+
unsafe { AlpmList::from_parts(self, list) }
3131
}
3232

3333
pub fn cachedirs(&self) -> AlpmList<'_, &str> {
3434
let list = unsafe { alpm_option_get_cachedirs(self.as_ptr()) };
35-
AlpmList::from_parts(self, list)
35+
unsafe { AlpmList::from_parts(self, list) }
3636
}
3737

3838
pub fn lockfile(&self) -> &str {
@@ -49,37 +49,37 @@ impl Alpm {
4949

5050
pub fn noupgrades(&self) -> AlpmList<'_, &str> {
5151
let list = unsafe { alpm_option_get_noupgrades(self.as_ptr()) };
52-
AlpmList::from_parts(self, list)
52+
unsafe { AlpmList::from_parts(self, list) }
5353
}
5454

5555
pub fn noextracts(&self) -> AlpmList<'_, &str> {
5656
let list = unsafe { alpm_option_get_noextracts(self.as_ptr()) };
57-
AlpmList::from_parts(self, list)
57+
unsafe { AlpmList::from_parts(self, list) }
5858
}
5959

6060
pub fn ignorepkgs(&self) -> AlpmList<'_, &str> {
6161
let list = unsafe { alpm_option_get_ignorepkgs(self.as_ptr()) };
62-
AlpmList::from_parts(self, list)
62+
unsafe { AlpmList::from_parts(self, list) }
6363
}
6464

6565
pub fn ignoregroups(&self) -> AlpmList<'_, &str> {
6666
let list = unsafe { alpm_option_get_ignoregroups(self.as_ptr()) };
67-
AlpmList::from_parts(self, list)
67+
unsafe { AlpmList::from_parts(self, list) }
6868
}
6969

7070
pub fn overwrite_files(&self) -> AlpmList<'_, &str> {
7171
let list = unsafe { alpm_option_get_overwrite_files(self.as_ptr()) };
72-
AlpmList::from_parts(self, list)
72+
unsafe { AlpmList::from_parts(self, list) }
7373
}
7474

7575
pub fn assume_installed(&self) -> AlpmList<'_, Depend> {
7676
let list = unsafe { alpm_option_get_assumeinstalled(self.as_ptr()) };
77-
AlpmList::from_parts(self, list)
77+
unsafe { AlpmList::from_parts(self, list) }
7878
}
7979

8080
pub fn architectures(&self) -> AlpmList<'_, &str> {
8181
let list = unsafe { alpm_option_get_architectures(self.as_ptr()) };
82-
AlpmList::from_parts(self, list)
82+
unsafe { AlpmList::from_parts(self, list) }
8383
}
8484

8585
pub fn check_space(&self) -> bool {
@@ -348,12 +348,12 @@ impl Alpm {
348348

349349
pub fn syncdbs(&self) -> AlpmList<Db> {
350350
let dbs = unsafe { alpm_get_syncdbs(self.as_ptr()) };
351-
AlpmList::from_parts(self, dbs)
351+
unsafe { AlpmList::from_parts(self, dbs) }
352352
}
353353

354354
pub fn syncdbs_mut(&mut self) -> AlpmList<DbMut> {
355355
let dbs = unsafe { alpm_get_syncdbs(self.as_ptr()) };
356-
AlpmList::from_parts(self, dbs)
356+
unsafe { AlpmList::from_parts(self, dbs) }
357357
}
358358

359359
pub fn set_check_space(&self, b: bool) {

alpm/src/list.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ where
265265

266266
impl<'a> AlpmList<'a, String> {
267267
pub fn as_str<'b>(&'b self) -> AlpmList<'a, &'b str> {
268-
AlpmList::from_parts(self.handle, self.list)
268+
unsafe { AlpmList::from_parts(self.handle, self.list) }
269269
}
270270
}
271271

@@ -277,7 +277,7 @@ where
277277
pub fn to_list_mut(&self) -> AlpmListMut<'a, T> {
278278
let list = unsafe { alpm_list_copy(self.list) };
279279
AlpmListMut {
280-
list: AlpmList::from_parts(self.handle, list),
280+
list: unsafe { AlpmList::from_parts(self.handle, list) },
281281
}
282282
}
283283
}
@@ -365,7 +365,7 @@ where
365365
self.list.list = unsafe { alpm_list_remove_item(self.list.list, item) };
366366
unsafe { (*item).next = ptr::null_mut() };
367367
unsafe { (*item).prev = ptr::null_mut() };
368-
AlpmListMut::from_parts(self.handle, item)
368+
unsafe { AlpmListMut::from_parts(self.handle, item) }
369369
}
370370

371371
pub fn as_list(&self) -> AlpmList<'a, T> {
@@ -504,7 +504,7 @@ where
504504
for<'b> T: IntoAlpmListItem<'a, 'b>,
505505
{
506506
fn drop(&mut self) {
507-
AlpmListMut::<T>::from_parts(self.list.handle, self.current);
507+
unsafe { AlpmListMut::<T>::from_parts(self.list.handle, self.current) };
508508
}
509509
}
510510

@@ -605,7 +605,7 @@ where
605605
}
606606

607607
impl<'a, T> AlpmList<'a, T> {
608-
pub(crate) fn from_parts(handle: &'a Alpm, list: *mut alpm_list_t) -> AlpmList<'a, T> {
608+
pub(crate) unsafe fn from_parts(handle: &'a Alpm, list: *mut alpm_list_t) -> AlpmList<'a, T> {
609609
AlpmList {
610610
handle,
611611
list,
@@ -620,11 +620,14 @@ where
620620
{
621621
pub fn new(handle: &'a Alpm) -> AlpmListMut<'a, T> {
622622
AlpmListMut {
623-
list: AlpmList::from_parts(handle, ptr::null_mut()),
623+
list: unsafe { AlpmList::from_parts(handle, ptr::null_mut()) },
624624
}
625625
}
626626

627-
pub(crate) fn from_parts(handle: &'a Alpm, list: *mut alpm_list_t) -> AlpmListMut<'a, T> {
627+
pub(crate) unsafe fn from_parts(
628+
handle: &'a Alpm,
629+
list: *mut alpm_list_t,
630+
) -> AlpmListMut<'a, T> {
628631
AlpmListMut {
629632
list: AlpmList::from_parts(handle, list),
630633
}

alpm/src/package.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,47 +187,47 @@ impl<'h> Pkg<'h> {
187187

188188
pub fn licenses(&self) -> AlpmList<'h, &'h str> {
189189
let list = unsafe { alpm_pkg_get_licenses(self.as_ptr()) };
190-
AlpmList::from_parts(self.handle, list)
190+
unsafe { AlpmList::from_parts(self.handle, list) }
191191
}
192192

193193
pub fn groups(&self) -> AlpmList<'h, &'h str> {
194194
let list = unsafe { alpm_pkg_get_groups(self.as_ptr()) };
195-
AlpmList::from_parts(self.handle, list)
195+
unsafe { AlpmList::from_parts(self.handle, list) }
196196
}
197197

198198
pub fn depends(&self) -> AlpmList<'h, Dep<'h>> {
199199
let list = unsafe { alpm_pkg_get_depends(self.as_ptr()) };
200-
AlpmList::from_parts(self.handle, list)
200+
unsafe { AlpmList::from_parts(self.handle, list) }
201201
}
202202

203203
pub fn optdepends(&self) -> AlpmList<'h, Dep<'h>> {
204204
let list = unsafe { alpm_pkg_get_optdepends(self.as_ptr()) };
205-
AlpmList::from_parts(self.handle, list)
205+
unsafe { AlpmList::from_parts(self.handle, list) }
206206
}
207207

208208
pub fn checkdepends(&self) -> AlpmList<'h, Dep<'h>> {
209209
let list = unsafe { alpm_pkg_get_checkdepends(self.as_ptr()) };
210-
AlpmList::from_parts(self.handle, list)
210+
unsafe { AlpmList::from_parts(self.handle, list) }
211211
}
212212

213213
pub fn makedepends(&self) -> AlpmList<'h, Dep<'h>> {
214214
let list = unsafe { alpm_pkg_get_makedepends(self.as_ptr()) };
215-
AlpmList::from_parts(self.handle, list)
215+
unsafe { AlpmList::from_parts(self.handle, list) }
216216
}
217217

218218
pub fn conflicts(&self) -> AlpmList<'h, Dep<'h>> {
219219
let list = unsafe { alpm_pkg_get_conflicts(self.as_ptr()) };
220-
AlpmList::from_parts(self.handle, list)
220+
unsafe { AlpmList::from_parts(self.handle, list) }
221221
}
222222

223223
pub fn provides(&self) -> AlpmList<'h, Dep<'h>> {
224224
let list = unsafe { alpm_pkg_get_provides(self.as_ptr()) };
225-
AlpmList::from_parts(self.handle, list)
225+
unsafe { AlpmList::from_parts(self.handle, list) }
226226
}
227227

228228
pub fn replaces(&self) -> AlpmList<'h, Dep<'h>> {
229229
let list = unsafe { alpm_pkg_get_replaces(self.as_ptr()) };
230-
AlpmList::from_parts(self.handle, list)
230+
unsafe { AlpmList::from_parts(self.handle, list) }
231231
}
232232

233233
pub fn files(&self) -> FileList {
@@ -237,7 +237,7 @@ impl<'h> Pkg<'h> {
237237

238238
pub fn backup(&self) -> AlpmList<'h, Backup> {
239239
let list = unsafe { alpm_pkg_get_backup(self.as_ptr()) };
240-
AlpmList::from_parts(self.handle, list)
240+
unsafe { AlpmList::from_parts(self.handle, list) }
241241
}
242242

243243
pub fn db(&self) -> Option<Db<'h>> {
@@ -265,12 +265,12 @@ impl<'h> Pkg<'h> {
265265

266266
pub fn required_by(&self) -> AlpmListMut<'h, String> {
267267
let list = unsafe { alpm_pkg_compute_requiredby(self.as_ptr()) };
268-
AlpmListMut::from_parts(self.handle, list)
268+
unsafe { AlpmListMut::from_parts(self.handle, list) }
269269
}
270270

271271
pub fn optional_for(&self) -> AlpmListMut<'h, String> {
272272
let list = unsafe { alpm_pkg_compute_optionalfor(self.as_ptr()) };
273-
AlpmListMut::from_parts(self.handle, list)
273+
unsafe { AlpmListMut::from_parts(self.handle, list) }
274274
}
275275

276276
pub fn base64_sig(&self) -> Option<&'h str> {

alpm/src/signing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,6 @@ impl Alpm {
238238
};
239239

240240
self.check_ret(ret)?;
241-
Ok(AlpmListMut::from_parts(self, keys))
241+
unsafe { Ok(AlpmListMut::from_parts(self, keys)) }
242242
}
243243
}

alpm/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Alpm {
3030
) -> AlpmListMut<'a, Package<'a>> {
3131
let name = CString::new(s).unwrap();
3232
let ret = unsafe { alpm_find_group_pkgs(dbs.list, name.as_ptr()) };
33-
AlpmListMut::from_parts(self, ret)
33+
unsafe { AlpmListMut::from_parts(self, ret) }
3434
}
3535
}
3636

alpm/src/trans.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ impl Alpm {
4343

4444
if let Err(err) = err {
4545
let ret = match err {
46-
Error::PkgInvalidArch => {
46+
Error::PkgInvalidArch => unsafe {
4747
PrepareResult::PkgInvalidArch(AlpmListMut::from_parts(self, list))
48-
}
49-
Error::UnsatisfiedDeps => {
48+
},
49+
Error::UnsatisfiedDeps => unsafe {
5050
PrepareResult::UnsatisfiedDeps(AlpmListMut::from_parts(self, list))
51-
}
52-
Error::ConflictingDeps => {
51+
},
52+
Error::ConflictingDeps => unsafe {
5353
PrepareResult::ConflictingDeps(AlpmListMut::from_parts(self, list))
54-
}
54+
},
5555
_ => PrepareResult::Ok,
5656
};
5757

@@ -68,12 +68,12 @@ impl Alpm {
6868

6969
if let Err(err) = err {
7070
let ret = match err {
71-
Error::FileConflicts => {
71+
Error::FileConflicts => unsafe {
7272
CommitResult::FileConflict(AlpmListMut::from_parts(self, list))
73-
}
74-
Error::PkgInvalid | Error::PkgInvalidSig | Error::PkgInvalidChecksum => {
73+
},
74+
Error::PkgInvalid | Error::PkgInvalidSig | Error::PkgInvalidChecksum => unsafe {
7575
CommitResult::PkgInvalid(AlpmListMut::from_parts(self, list))
76-
}
76+
},
7777
_ => CommitResult::Ok,
7878
};
7979

@@ -90,12 +90,12 @@ impl Alpm {
9090

9191
pub fn trans_add(&self) -> AlpmList<Package> {
9292
let list = unsafe { alpm_trans_get_add(self.as_ptr()) };
93-
AlpmList::from_parts(self, list)
93+
unsafe { AlpmList::from_parts(self, list) }
9494
}
9595

9696
pub fn trans_remove(&self) -> AlpmList<Package> {
9797
let list = unsafe { alpm_trans_get_remove(self.as_ptr()) };
98-
AlpmList::from_parts(self, list)
98+
unsafe { AlpmList::from_parts(self, list) }
9999
}
100100

101101
pub fn trans_release(&mut self) -> Result<()> {

0 commit comments

Comments
 (0)