Skip to content

Commit dee86e9

Browse files
committed
cxx-qt-lib: remove null-pointer dereference from QStringList's upcast
1 parent 21f2216 commit dee86e9

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

crates/cxx-qt-lib/src/core/qstringlist.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
5-
use crate::core::qstringlist::ffi::QList_QString;
65
use crate::{QList, QString};
76
use core::mem::MaybeUninit;
87
use cxx::{type_id, ExternType};
@@ -28,21 +27,6 @@ mod ffi {
2827
include!("cxx-qt-lib/qstringlist.h");
2928
type QStringList = super::QStringList;
3029

31-
include!("cxx-qt/casting.h");
32-
33-
#[doc(hidden)]
34-
#[rust_name = "upcast_qstringlist"]
35-
#[cxx_name = "upcastPtr"]
36-
#[namespace = "rust::cxxqt1"]
37-
unsafe fn upcast(thiz: *const QStringList) -> *const QList_QString;
38-
39-
#[doc(hidden)]
40-
#[rust_name = "downcast_qlist_qstring"]
41-
#[cxx_name = "downcastPtr"]
42-
#[namespace = "rust::cxxqt1"]
43-
#[cfg(cxxqt_qt_version_at_least_6)]
44-
unsafe fn downcast(base: *const QList_QString) -> *const QStringList;
45-
4630
/// Returns true if the list contains the string str; otherwise returns false.
4731
fn contains(self: &QStringList, str: &QString, cs: CaseSensitivity) -> bool;
4832

@@ -67,6 +51,19 @@ mod ffi {
6751
) -> &mut QStringList;
6852
}
6953

54+
#[namespace = "rust::cxxqt1"]
55+
unsafe extern "C++" {
56+
include!("cxx-qt/casting.h");
57+
58+
#[doc(hidden)]
59+
#[rust_name = "upcast_qstringlist"]
60+
unsafe fn upcastPtr(thiz: *const QStringList) -> *const QList_QString;
61+
62+
#[doc(hidden)]
63+
#[rust_name = "downcast_qlist_qstring"]
64+
unsafe fn downcastPtrStatic(base: *const QList_QString) -> *const QStringList;
65+
}
66+
7067
#[namespace = "rust::cxxqtlib1"]
7168
unsafe extern "C++" {
7269
include!("cxx-qt-lib/common.h");
@@ -207,20 +204,14 @@ impl DerefMut for QStringList {
207204
}
208205
}
209206

210-
impl Upcast<QList_QString> for QStringList {
211-
unsafe fn upcast_ptr(this: *const Self) -> *const QList_QString {
207+
impl Upcast<QList<QString>> for QStringList {
208+
unsafe fn upcast_ptr(this: *const Self) -> *const QList<QString> {
212209
ffi::upcast_qstringlist(this)
213210
}
214211

215-
#[cfg(cxxqt_qt_version_at_least_6)]
216-
unsafe fn from_base_ptr(base: *const QList_QString) -> *const Self {
212+
unsafe fn from_base_ptr(base: *const QList<QString>) -> *const Self {
217213
ffi::downcast_qlist_qstring(base)
218214
}
219-
220-
#[cfg(cxxqt_qt_version_major = "5")]
221-
unsafe fn from_base_ptr(_base: *const QList_QString) -> *const Self {
222-
std::ptr::null()
223-
}
224215
}
225216

226217
// Safety:

0 commit comments

Comments
 (0)