Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cairo/src/image_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ impl ImageSurface {
(data.as_mut_ptr(), data.len())
};

assert!(len >= (height * stride) as usize);
assert!(width >= 0, "width must be non-negative");
assert!(height >= 0, "height must be non-negative");
assert!(stride >= 0, "stride must be non-negative");

// check if there is integer overflow
assert!(len >= height.checked_mul(stride).unwrap() as usize);
let result = unsafe {
ImageSurface::from_raw_full(ffi::cairo_image_surface_create_for_data(
ptr,
Expand Down
2 changes: 2 additions & 0 deletions cairo/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ impl Region {
#[doc(alias = "get_rectangle")]
#[doc(alias = "cairo_region_get_rectangle")]
pub fn rectangle(&self, nth: i32) -> RectangleInt {
let total_rectangles = self.num_rectangles();
assert!(nth >= 0 && nth < total_rectangles, "nth is out of range");
unsafe {
let rectangle: RectangleInt = ::std::mem::zeroed();
ffi::cairo_region_get_rectangle(self.0.as_ptr(), nth, rectangle.to_raw_none());
Expand Down
2 changes: 1 addition & 1 deletion gir
Submodule gir updated 2 files
+13 −4 Cargo.lock
+2 −2 Cargo.toml
2 changes: 1 addition & 1 deletion glib/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl Date {
#[doc(alias = "g_date_subtract_days")]
pub fn subtract_days(&mut self, n_days: u32) -> Result<(), BoolError> {
let julian = self.julian();
if julian > n_days {
if julian < n_days {
Err(bool_error!("invalid number of days"))
} else {
unsafe {
Expand Down
14 changes: 8 additions & 6 deletions glib/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn spawn_async_with_pipes<
let mut standard_output = mem::MaybeUninit::uninit();
let mut standard_error = mem::MaybeUninit::uninit();
let mut error = ptr::null_mut();
let _ = ffi::g_spawn_async_with_pipes(
let success = ffi::g_spawn_async_with_pipes(
working_directory.as_ref().to_glib_none().0,
argv.to_glib_none().0,
envp.to_glib_none().0,
Expand All @@ -179,11 +179,11 @@ pub fn spawn_async_with_pipes<
standard_error.as_mut_ptr(),
&mut error,
);
let child_pid = from_glib(child_pid.assume_init());
let standard_input = standard_input.assume_init();
let standard_output = standard_output.assume_init();
let standard_error = standard_error.assume_init();
if error.is_null() {
if from_glib(success) {
let child_pid = from_glib(child_pid.assume_init());
let standard_input = standard_input.assume_init();
let standard_output = standard_output.assume_init();
let standard_error = standard_error.assume_init();
#[cfg(not(windows))]
{
Ok((
Expand All @@ -204,6 +204,8 @@ pub fn spawn_async_with_pipes<
// ))
// }
} else {
// Function failed, output parameters are not initialized
// Return the error without calling assume_init()
Err(from_glib_full(error))
}
}
Expand Down
9 changes: 9 additions & 0 deletions graphene/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ boxed_inline = true
name = "init_from_vec3"
rename = "from_vec3"
manual = true # manual proper constructor
[[object.function]]
name = "intersect_box"
manual = true # fix issue 1805
[[object.function]]
name = "intersect_sphere"
manual = true # fix issue 1805
[[object.function]]
name = "intersect_triangle"
manual = true # fix issue 1805
Comment on lines +378 to +386
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[[object.function]]
name = "intersect_box"
manual = true # fix issue 1805
[[object.function]]
name = "intersect_sphere"
manual = true # fix issue 1805
[[object.function]]
name = "intersect_triangle"
manual = true # fix issue 1805
[[object.function]]
pattern = "intersect_(box|sphere|triangle)"
manual = true # Handle no intersection cases


[[object]]
name = "Graphene.Rect"
Expand Down
41 changes: 1 addition & 40 deletions graphene/src/auto/ray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi, Box, Plane, Point3D, RayIntersectionKind, Sphere, Triangle, Vec3};
use crate::{ffi, Box, Plane, Point3D, Sphere, Triangle, Vec3};
use glib::translate::*;

glib::wrapper! {
Expand Down Expand Up @@ -85,45 +85,6 @@ impl Ray {
}
}

#[doc(alias = "graphene_ray_intersect_box")]
pub fn intersect_box(&self, b: &Box) -> (RayIntersectionKind, f32) {
unsafe {
let mut t_out = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::graphene_ray_intersect_box(
self.to_glib_none().0,
b.to_glib_none().0,
t_out.as_mut_ptr(),
));
(ret, t_out.assume_init())
}
}

#[doc(alias = "graphene_ray_intersect_sphere")]
pub fn intersect_sphere(&self, s: &Sphere) -> (RayIntersectionKind, f32) {
unsafe {
let mut t_out = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::graphene_ray_intersect_sphere(
self.to_glib_none().0,
s.to_glib_none().0,
t_out.as_mut_ptr(),
));
(ret, t_out.assume_init())
}
}

#[doc(alias = "graphene_ray_intersect_triangle")]
pub fn intersect_triangle(&self, t: &Triangle) -> (RayIntersectionKind, f32) {
unsafe {
let mut t_out = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::graphene_ray_intersect_triangle(
self.to_glib_none().0,
t.to_glib_none().0,
t_out.as_mut_ptr(),
));
(ret, t_out.assume_init())
}
}

#[doc(alias = "graphene_ray_intersects_box")]
pub fn intersects_box(&self, b: &Box) -> bool {
unsafe { ffi::graphene_ray_intersects_box(self.to_glib_none().0, b.to_glib_none().0) }
Expand Down
50 changes: 49 additions & 1 deletion graphene/src/ray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;

use glib::translate::*;

use crate::{ffi, Point3D, Ray, Vec3};
use crate::{ffi, Box, Point3D, Ray, RayIntersectionKind, Sphere, Triangle, Vec3};

impl Ray {
#[doc(alias = "graphene_ray_init")]
Expand Down Expand Up @@ -35,6 +35,54 @@ impl Ray {
ray
}
}

#[doc(alias = "graphene_ray_intersect_box")]
pub fn intersect_box(&self, b: &Box) -> (RayIntersectionKind, Option<f32>) {
unsafe {
let mut t_out = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::graphene_ray_intersect_box(
self.to_glib_none().0,
b.to_glib_none().0,
t_out.as_mut_ptr(),
));
match ret {
RayIntersectionKind::None => (ret, None),
_ => (ret, Some(t_out.assume_init())),
}
}
}

#[doc(alias = "graphene_ray_intersect_sphere")]
pub fn intersect_sphere(&self, s: &Sphere) -> (RayIntersectionKind, Option<f32>) {
unsafe {
let mut t_out = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::graphene_ray_intersect_sphere(
self.to_glib_none().0,
s.to_glib_none().0,
t_out.as_mut_ptr(),
));
match ret {
RayIntersectionKind::None => (ret, None),
_ => (ret, Some(t_out.assume_init())),
}
}
}

#[doc(alias = "graphene_ray_intersect_triangle")]
pub fn intersect_triangle(&self, t: &Triangle) -> (RayIntersectionKind, Option<f32>) {
unsafe {
let mut t_out = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::graphene_ray_intersect_triangle(
self.to_glib_none().0,
t.to_glib_none().0,
t_out.as_mut_ptr(),
));
match ret {
RayIntersectionKind::None => (ret, None),
_ => (ret, Some(t_out.assume_init())),
}
}
}
}

impl fmt::Debug for Ray {
Expand Down
2 changes: 2 additions & 0 deletions pango/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ status = "generate"
ignore = true
[[object.function]]
name = "itemize"
manual = true
[[object.function.parameter]]
name = "cached_iter"
const = true
Comment on lines 100 to 102
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can drop those

[[object.function]]
name = "itemize_with_base_dir"
manual = true
[[object.function.parameter]]
name = "cached_iter"
const = true
Expand Down
45 changes: 1 addition & 44 deletions pango/src/auto/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// DO NOT EDIT

use crate::{
ffi, AttrIterator, AttrList, Context, Direction, Item, Stretch, Style, Variant, Weight,
ffi, AttrList, Direction, Stretch, Style, Variant, Weight,
};
use glib::translate::*;

Expand Down Expand Up @@ -56,49 +56,6 @@ pub fn is_zero_width(ch: char) -> bool {
unsafe { from_glib(ffi::pango_is_zero_width(ch.into_glib())) }
}

#[doc(alias = "pango_itemize")]
pub fn itemize(
context: &Context,
text: &str,
start_index: i32,
length: i32,
attrs: &AttrList,
cached_iter: Option<&AttrIterator>,
) -> Vec<Item> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::pango_itemize(
context.to_glib_none().0,
text.to_glib_none().0,
start_index,
length,
attrs.to_glib_none().0,
mut_override(cached_iter.to_glib_none().0),
))
}
}

#[doc(alias = "pango_itemize_with_base_dir")]
pub fn itemize_with_base_dir(
context: &Context,
base_dir: Direction,
text: &str,
start_index: i32,
length: i32,
attrs: &AttrList,
cached_iter: Option<&AttrIterator>,
) -> Vec<Item> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::pango_itemize_with_base_dir(
context.to_glib_none().0,
base_dir.into_glib(),
text.to_glib_none().0,
start_index,
length,
attrs.to_glib_none().0,
mut_override(cached_iter.to_glib_none().0),
))
}
}

#[doc(alias = "pango_markup_parser_finish")]
pub fn markup_parser_finish(
Expand Down
64 changes: 63 additions & 1 deletion pango/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{ffi::c_char, ptr};
pub use crate::auto::functions::*;
#[cfg(feature = "v1_44")]
use crate::ShapeFlags;
use crate::{ffi, Analysis, GlyphString, Item};
use crate::{ffi, Analysis, AttrIterator, AttrList, Context, Direction, GlyphString, Item};

#[doc(alias = "pango_reorder_items")]
pub fn reorder_items(logical_items: &glib::List<Item>) -> glib::List<Item> {
Expand Down Expand Up @@ -93,3 +93,65 @@ pub fn extents_to_pixels(
ffi::pango_extents_to_pixels(inclusive.to_glib_none_mut().0, nearest.to_glib_none_mut().0);
}
}

#[doc(alias = "pango_itemize")]
pub fn itemize(
context: &Context,
text: &str,
start_index: i32,
length: i32,
attrs: &AttrList,
cached_iter: Option<&AttrIterator>,
) -> Vec<Item> {
let total_length = text.len() as i32;
assert!(
start_index >= 0 && start_index < total_length,
"start_index is out of range"
);
assert!(
length >= 0 && start_index.checked_add(length).unwrap() < total_length,
"start_index + length is out of range"
);
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::pango_itemize(
context.to_glib_none().0,
text.to_glib_none().0,
start_index,
length,
attrs.to_glib_none().0,
mut_override(cached_iter.to_glib_none().0),
))
}
}

#[doc(alias = "pango_itemize_with_base_dir")]
pub fn itemize_with_base_dir(
context: &Context,
base_dir: Direction,
text: &str,
start_index: i32,
length: i32,
attrs: &AttrList,
cached_iter: Option<&AttrIterator>,
) -> Vec<Item> {
let total_length = text.len() as i32;
assert!(
start_index >= 0 && start_index < total_length,
"start_index is out of range"
);
assert!(
length >= 0 && start_index.checked_add(length).unwrap() < total_length,
"start_index + length is out of range"
);
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::pango_itemize_with_base_dir(
context.to_glib_none().0,
base_dir.into_glib(),
text.to_glib_none().0,
start_index,
length,
attrs.to_glib_none().0,
mut_override(cached_iter.to_glib_none().0),
))
}
}
Loading