Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 77a9fc7

Browse files
Merge pull request #16 from ids1024/class
Use `Object<T>::as_mut()` without unsafe, and a couple other small things
2 parents c070941 + fc02415 commit 77a9fc7

39 files changed

+208
-241
lines changed

cairo/sys/build.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#[cfg(not(feature = "dox"))]
22
extern crate system_deps;
33

4-
#[cfg(not(feature = "dox"))]
5-
use std::io;
6-
#[cfg(not(feature = "dox"))]
7-
use std::io::prelude::*;
84
#[cfg(not(feature = "dox"))]
95
use std::process;
106

gio/src/file_info.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
// Licensed under the MIT license, see the LICENSE file or <https://opensource.org/licenses/MIT>
44

55
use gio_sys;
6-
use glib;
7-
use glib::object::IsA;
86
use glib::translate::*;
97
use glib_sys;
10-
use gobject_sys;
118
use std::mem;
12-
use std::pin::Pin;
13-
use std::ptr;
149
use std::time::{Duration, SystemTime};
1510
use FileInfo;
1611

gio/src/subclass/application.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use glib::subclass::prelude::*;
1212
use glib::VariantDict;
1313

1414
use Application;
15-
use ApplicationClass;
1615

1716
use libc::{c_char, c_int, c_void};
1817
use std::convert;
@@ -304,22 +303,21 @@ impl<T: ApplicationImpl> ApplicationImplExt for T {
304303
}
305304

306305
unsafe impl<T: ApplicationImpl> IsSubclassable<T> for Application {
307-
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
306+
fn override_vfuncs(class: &mut ::glib::Class<Self>) {
308307
<glib::Object as IsSubclassable<T>>::override_vfuncs(class);
309-
unsafe {
310-
let klass = &mut *(class.as_mut() as *mut gio_sys::GApplicationClass);
311-
klass.activate = Some(application_activate::<T>);
312-
klass.after_emit = Some(application_after_emit::<T>);
313-
klass.before_emit = Some(application_before_emit::<T>);
314-
klass.command_line = Some(application_command_line::<T>);
315-
klass.local_command_line = Some(application_local_command_line::<T>);
316-
klass.open = Some(application_open::<T>);
317-
klass.quit_mainloop = Some(application_quit_mainloop::<T>);
318-
klass.run_mainloop = Some(application_run_mainloop::<T>);
319-
klass.shutdown = Some(application_shutdown::<T>);
320-
klass.startup = Some(application_startup::<T>);
321-
klass.handle_local_options = Some(application_handle_local_options::<T>);
322-
}
308+
309+
let klass = class.as_mut();
310+
klass.activate = Some(application_activate::<T>);
311+
klass.after_emit = Some(application_after_emit::<T>);
312+
klass.before_emit = Some(application_before_emit::<T>);
313+
klass.command_line = Some(application_command_line::<T>);
314+
klass.local_command_line = Some(application_local_command_line::<T>);
315+
klass.open = Some(application_open::<T>);
316+
klass.quit_mainloop = Some(application_quit_mainloop::<T>);
317+
klass.run_mainloop = Some(application_run_mainloop::<T>);
318+
klass.shutdown = Some(application_shutdown::<T>);
319+
klass.startup = Some(application_startup::<T>);
320+
klass.handle_local_options = Some(application_handle_local_options::<T>);
323321
}
324322
}
325323

gio/src/subclass/input_stream.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use glib::Error;
1212

1313
use Cancellable;
1414
use InputStream;
15-
use InputStreamClass;
1615

1716
use std::mem;
1817
use std::ptr;
@@ -152,14 +151,13 @@ impl<T: InputStreamImpl> InputStreamImplExt for T {
152151
}
153152

154153
unsafe impl<T: InputStreamImpl> IsSubclassable<T> for InputStream {
155-
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
154+
fn override_vfuncs(class: &mut ::glib::Class<Self>) {
156155
<glib::Object as IsSubclassable<T>>::override_vfuncs(class);
157-
unsafe {
158-
let klass = &mut *(class.as_mut() as *mut gio_sys::GInputStreamClass);
159-
klass.read_fn = Some(stream_read::<T>);
160-
klass.close_fn = Some(stream_close::<T>);
161-
klass.skip = Some(stream_skip::<T>);
162-
}
156+
157+
let klass = class.as_mut();
158+
klass.read_fn = Some(stream_read::<T>);
159+
klass.close_fn = Some(stream_close::<T>);
160+
klass.skip = Some(stream_skip::<T>);
163161
}
164162
}
165163

gio/src/subclass/io_stream.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use glib::Error;
1313

1414
use Cancellable;
1515
use IOStream;
16-
use IOStreamClass;
1716

1817
use std::mem;
1918
use std::ptr;
@@ -96,14 +95,13 @@ impl<T: IOStreamImpl> IOStreamImplExt for T {
9695
}
9796

9897
unsafe impl<T: IOStreamImpl> IsSubclassable<T> for IOStream {
99-
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
98+
fn override_vfuncs(class: &mut ::glib::Class<Self>) {
10099
<glib::Object as IsSubclassable<T>>::override_vfuncs(class);
101-
unsafe {
102-
let klass = &mut *(class.as_mut() as *mut gio_sys::GIOStreamClass);
103-
klass.get_input_stream = Some(stream_get_input_stream::<T>);
104-
klass.get_output_stream = Some(stream_get_output_stream::<T>);
105-
klass.close_fn = Some(stream_close::<T>);
106-
}
100+
101+
let klass = class.as_mut();
102+
klass.get_input_stream = Some(stream_get_input_stream::<T>);
103+
klass.get_output_stream = Some(stream_get_output_stream::<T>);
104+
klass.close_fn = Some(stream_close::<T>);
107105
}
108106
}
109107

gio/src/subclass/output_stream.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use glib::Error;
1313
use Cancellable;
1414
use InputStream;
1515
use OutputStream;
16-
use OutputStreamClass;
1716
use OutputStreamSpliceFlags;
1817

1918
use std::mem;
@@ -192,15 +191,14 @@ impl<T: OutputStreamImpl> OutputStreamImplExt for T {
192191
}
193192

194193
unsafe impl<T: OutputStreamImpl> IsSubclassable<T> for OutputStream {
195-
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
194+
fn override_vfuncs(class: &mut ::glib::Class<Self>) {
196195
<glib::Object as IsSubclassable<T>>::override_vfuncs(class);
197-
unsafe {
198-
let klass = &mut *(class.as_mut() as *mut gio_sys::GOutputStreamClass);
199-
klass.write_fn = Some(stream_write::<T>);
200-
klass.close_fn = Some(stream_close::<T>);
201-
klass.flush = Some(stream_flush::<T>);
202-
klass.splice = Some(stream_splice::<T>);
203-
}
196+
197+
let klass = class.as_mut();
198+
klass.write_fn = Some(stream_write::<T>);
199+
klass.close_fn = Some(stream_close::<T>);
200+
klass.flush = Some(stream_flush::<T>);
201+
klass.splice = Some(stream_splice::<T>);
204202
}
205203
}
206204

glib/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ pub use closure::Closure;
104104
pub use error::{BoolError, Error};
105105
pub use file_error::FileError;
106106
pub use object::{
107-
Cast, InitiallyUnowned, InitiallyUnownedClass, IsA, Object, ObjectClass, ObjectExt, ObjectType,
108-
SendWeakRef, WeakRef,
107+
Cast, Class, InitiallyUnowned, InitiallyUnownedClass, IsA, Object, ObjectClass, ObjectExt,
108+
ObjectType, SendWeakRef, WeakRef,
109109
};
110110
pub use signal::{
111111
signal_handler_block, signal_handler_disconnect, signal_handler_unblock,

glib/src/subclass/object.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,11 @@ pub unsafe trait ObjectClassSubclassExt: Sized + 'static {
270270
unsafe impl ObjectClassSubclassExt for ObjectClass {}
271271

272272
unsafe impl<T: ObjectImpl> IsSubclassable<T> for Object {
273-
fn override_vfuncs(class: &mut ::object::Class<Self>) {
274-
unsafe {
275-
let klass = &mut *(class.as_mut() as *mut gobject_sys::GObjectClass);
276-
klass.set_property = Some(set_property::<T>);
277-
klass.get_property = Some(get_property::<T>);
278-
klass.constructed = Some(constructed::<T>);
279-
}
273+
fn override_vfuncs(class: &mut ::Class<Self>) {
274+
let klass = class.as_mut();
275+
klass.set_property = Some(set_property::<T>);
276+
klass.get_property = Some(get_property::<T>);
277+
klass.constructed = Some(constructed::<T>);
280278
}
281279
}
282280

glib/src/subclass/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ unsafe impl<T: ObjectSubclass> super::types::ClassStruct for ClassStruct<T> {
5656
}
5757

5858
impl<T: ObjectSubclass> ops::Deref for ClassStruct<T> {
59-
type Target = ::object::Class<<T as ObjectSubclass>::ParentType>;
59+
type Target = ::Class<<T as ObjectSubclass>::ParentType>;
6060

6161
fn deref(&self) -> &Self::Target {
6262
unsafe { &*(self as *const _ as *const Self::Target) }

glib/src/subclass/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ pub unsafe trait ClassStruct: Sized + 'static {
105105
<Self::Type as ObjectSubclass>::ParentType: IsSubclassable<Self::Type>,
106106
{
107107
unsafe {
108-
let base = &mut *(self as *mut _
109-
as *mut ::object::Class<<Self::Type as ObjectSubclass>::ParentType>);
108+
let base =
109+
&mut *(self as *mut _ as *mut ::Class<<Self::Type as ObjectSubclass>::ParentType>);
110110
<<Self::Type as ObjectSubclass>::ParentType as IsSubclassable<Self::Type>>::override_vfuncs(base);
111111
}
112112
}
@@ -117,7 +117,7 @@ pub unsafe trait IsSubclassable<T: ObjectSubclass>: ObjectType {
117117
/// Override the virtual methods of this class for the given subclass.
118118
///
119119
/// This is automatically called during type initialization.
120-
fn override_vfuncs(class: &mut ::object::Class<Self>);
120+
fn override_vfuncs(class: &mut ::Class<Self>);
121121
}
122122

123123
/// Trait for implementable interfaces.

glib/src/wrapper.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ macro_rules! glib_wrapper {
336336
}
337337
) => {
338338
$crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, @get_type $get_type_expr, @extends [], @implements []);
339-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
339+
$( pub type $rust_class_name = $crate::Class<$name>; )?
340340
};
341341

342342
// Object, class struct, no parents or interfaces
@@ -349,7 +349,7 @@ macro_rules! glib_wrapper {
349349
}
350350
) => {
351351
$crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, @get_type $get_type_expr, @extends [], @implements []);
352-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
352+
$( pub type $rust_class_name = $crate::Class<$name>; )?
353353
};
354354

355355
// Object, no class struct, parents, no interfaces
@@ -363,7 +363,7 @@ macro_rules! glib_wrapper {
363363
) => {
364364
$crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void,
365365
@get_type $get_type_expr, @extends [$($extends),+], @implements []);
366-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
366+
$( pub type $rust_class_name = $crate::Class<$name>; )?
367367
};
368368

369369
// Object, class struct, parents, no interfaces
@@ -377,7 +377,7 @@ macro_rules! glib_wrapper {
377377
) => {
378378
$crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name,
379379
@get_type $get_type_expr, @extends [$($extends),+], @implements []);
380-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
380+
$( pub type $rust_class_name = $crate::Class<$name>; )?
381381
};
382382

383383
// Object, no class struct, no parents, interfaces
@@ -391,7 +391,7 @@ macro_rules! glib_wrapper {
391391
) => {
392392
$crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void,
393393
@get_type $get_type_expr, @extends [], @implements [$($implements),+]);
394-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
394+
$( pub type $rust_class_name = $crate::Class<$name>; )?
395395
};
396396

397397
// Object, class struct, no parents, interfaces
@@ -405,7 +405,7 @@ macro_rules! glib_wrapper {
405405
) => {
406406
$crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name,
407407
@get_type $get_type_expr, @extends [], @implements [$($implements),+]);
408-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
408+
$( pub type $rust_class_name = $crate::Class<$name>; )?
409409
};
410410

411411
// Object, no class struct, parents and interfaces
@@ -419,7 +419,7 @@ macro_rules! glib_wrapper {
419419
) => {
420420
$crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void,
421421
@get_type $get_type_expr, @extends [$($extends),+], @implements [$($implements),+]);
422-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
422+
$( pub type $rust_class_name = $crate::Class<$name>; )?
423423
};
424424

425425
// Object, class struct, parents and interfaces
@@ -433,7 +433,7 @@ macro_rules! glib_wrapper {
433433
) => {
434434
$crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name,
435435
@get_type $get_type_expr, @extends [$($extends),+], @implements [$($implements),+]);
436-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
436+
$( pub type $rust_class_name = $crate::Class<$name>; )?
437437
};
438438

439439
// ObjectSubclass, no parents or interfaces
@@ -445,7 +445,7 @@ macro_rules! glib_wrapper {
445445
$crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class,
446446
@get_type $crate::translate::ToGlib::to_glib(&<$subclass as $crate::subclass::types::ObjectSubclass>::get_type()),
447447
@extends [], @implements []);
448-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
448+
$( pub type $rust_class_name = $crate::Class<$name>; )?
449449
};
450450

451451
// ObjectSubclass, no parents, interfaces
@@ -456,7 +456,7 @@ macro_rules! glib_wrapper {
456456
$crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class,
457457
@get_type $crate::translate::ToGlib::to_glib(&<$subclass as $crate::subclass::types::ObjectSubclass>::get_type()),
458458
@extends [], @implements [$($implements),+]);
459-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
459+
$( pub type $rust_class_name = $crate::Class<$name>; )?
460460
};
461461

462462
// ObjectSubclass, parents, no interfaces
@@ -467,7 +467,7 @@ macro_rules! glib_wrapper {
467467
$crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class,
468468
@get_type $crate::translate::ToGlib::to_glib(&<$subclass as $crate::subclass::types::ObjectSubclass>::get_type()),
469469
@extends [$($extends),+], @implements []);
470-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
470+
$( pub type $rust_class_name = $crate::Class<$name>; )?
471471
};
472472

473473
// ObjectSubclass, parents and interfaces
@@ -478,7 +478,7 @@ macro_rules! glib_wrapper {
478478
$crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class,
479479
@get_type $crate::translate::ToGlib::to_glib(&<$subclass as $crate::subclass::types::ObjectSubclass>::get_type()),
480480
@extends [$($extends),+], @implements [$($implements),+]);
481-
$( pub type $rust_class_name = $crate::object::Class<$name>; )?
481+
$( pub type $rust_class_name = $crate::Class<$name>; )?
482482
};
483483

484484
// Interface, no prerequisites

gtk/src/subclass/application.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<T: GtkApplicationImpl> GtkApplicationImplExt for T {
4949
}
5050

5151
unsafe impl<T: GtkApplicationImpl> IsSubclassable<T> for Application {
52-
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
52+
fn override_vfuncs(class: &mut ::glib::Class<Self>) {
5353
unsafe extern "C" fn application_window_added<T: GtkApplicationImpl>(
5454
ptr: *mut gtk_sys::GtkApplication,
5555
wptr: *mut gtk_sys::GtkWindow,
@@ -82,13 +82,12 @@ unsafe impl<T: GtkApplicationImpl> IsSubclassable<T> for Application {
8282
}
8383

8484
<gio::Application as IsSubclassable<T>>::override_vfuncs(class);
85-
unsafe {
86-
let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkApplicationClass);
87-
klass.window_added = Some(application_window_added::<T>);
88-
klass.window_removed = Some(application_window_removed::<T>);
89-
// Chain our startup handler in here
90-
let klass = &mut class.as_mut().parent_class;
91-
klass.startup = Some(application_startup::<T>);
92-
}
85+
86+
let klass = class.as_mut();
87+
klass.window_added = Some(application_window_added::<T>);
88+
klass.window_removed = Some(application_window_removed::<T>);
89+
// Chain our startup handler in here
90+
let klass = &mut class.as_mut().parent_class;
91+
klass.startup = Some(application_startup::<T>);
9392
}
9493
}

gtk/src/subclass/application_window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use Window;
77
pub trait ApplicationWindowImpl: WindowImpl {}
88

99
unsafe impl<T: ApplicationWindowImpl> IsSubclassable<T> for ApplicationWindow {
10-
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
10+
fn override_vfuncs(class: &mut ::glib::Class<Self>) {
1111
<Window as IsSubclassable<T>>::override_vfuncs(class);
1212
}
1313
}

gtk/src/subclass/bin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use Container;
77
pub trait BinImpl: ContainerImpl {}
88

99
unsafe impl<T: BinImpl> IsSubclassable<T> for Bin {
10-
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
10+
fn override_vfuncs(class: &mut ::glib::Class<Self>) {
1111
<Container as IsSubclassable<T>>::override_vfuncs(class);
1212
}
1313
}

gtk/src/subclass/box_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use Container;
77
pub trait BoxImpl: ContainerImpl {}
88

99
unsafe impl<T: BoxImpl> IsSubclassable<T> for Box {
10-
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
10+
fn override_vfuncs(class: &mut ::glib::Class<Self>) {
1111
<Container as IsSubclassable<T>>::override_vfuncs(class);
1212
}
1313
}

0 commit comments

Comments
 (0)