1
1
// Take a look at the license at the top of the repository in the LICENSE file.
2
2
3
3
use glib:: translate:: * ;
4
+ use std:: ffi:: c_char;
4
5
5
6
pub use crate :: auto:: functions:: * ;
6
7
#[ cfg( feature = "v1_44" ) ]
@@ -27,13 +28,15 @@ pub fn shape_full(
27
28
Some ( s) => s. len ( ) ,
28
29
None => 0 ,
29
30
} as i32 ;
30
- let paragraph_text = paragraph_text. to_glib_none ( ) ;
31
31
let item_length = item_text. len ( ) as i32 ;
32
32
unsafe {
33
+ // The function does not take null-terminated strings when a length is provided.
34
+ // It also requires item_text to point to a subsequence of paragraph_text.
35
+ // Using to_glib_none() on &str will copy the string and cause problems.
33
36
ffi:: pango_shape_full (
34
- item_text. to_glib_none ( ) . 0 ,
37
+ item_text. as_bytes ( ) . to_glib_none ( ) . 0 as * const c_char ,
35
38
item_length,
36
- paragraph_text. 0 ,
39
+ paragraph_text. map ( |t| t . as_bytes ( ) ) . to_glib_none ( ) . 0 as * const c_char ,
37
40
paragraph_length,
38
41
analysis. to_glib_none ( ) . 0 ,
39
42
glyphs. to_glib_none_mut ( ) . 0 ,
@@ -54,10 +57,11 @@ pub fn shape_with_flags(
54
57
let item_length = item_text. len ( ) as i32 ;
55
58
let paragraph_length = paragraph_text. map ( |t| t. len ( ) as i32 ) . unwrap_or_default ( ) ;
56
59
unsafe {
60
+ // See: shape_full
57
61
ffi:: pango_shape_with_flags (
58
- item_text. to_glib_none ( ) . 0 ,
62
+ item_text. as_bytes ( ) . to_glib_none ( ) . 0 as * const c_char ,
59
63
item_length,
60
- paragraph_text. to_glib_none ( ) . 0 ,
64
+ paragraph_text. map ( |t| t . as_bytes ( ) ) . to_glib_none ( ) . 0 as * const c_char ,
61
65
paragraph_length,
62
66
analysis. to_glib_none ( ) . 0 ,
63
67
glyphs. to_glib_none_mut ( ) . 0 ,
0 commit comments