Fix dynamic borrow check errors.

This reduces the scope of the borrow on `family` to the single FFI call that
needs it.
This commit is contained in:
Jack Moffitt 2013-05-16 09:23:18 -06:00
parent c8520e9249
commit 5fd0fcbc91

View file

@ -66,19 +66,25 @@ pub impl FontListHandle {
let font_set = FcConfigGetFonts(config, FcSetSystem); let font_set = FcConfigGetFonts(config, FcSetSystem);
let font_set_array_ptr = ptr::to_unsafe_ptr(&font_set); let font_set_array_ptr = ptr::to_unsafe_ptr(&font_set);
unsafe { unsafe {
do str::as_c_str("family") |FC_FAMILY| { let pattern = FcPatternCreate();
do str::as_c_str(family.family_name) |family_name| {
let pattern = FcPatternCreate(); let pattern = FcPatternCreate();
assert!(pattern.is_not_null()); assert!(pattern.is_not_null());
let family_name = family_name as *FcChar8; do str::as_c_str("family") |FC_FAMILY| {
let ok = FcPatternAddString(pattern, FC_FAMILY, family_name); do str::as_c_str(family.family_name) |family_name| {
let ok = FcPatternAddString(pattern, FC_FAMILY, family_name as *FcChar8);
assert!(ok != 0); assert!(ok != 0);
}
}
let object_set = FcObjectSetCreate(); let object_set = FcObjectSetCreate();
assert!(object_set.is_not_null()); assert!(object_set.is_not_null());
str::as_c_str("file", |FC_FILE| FcObjectSetAdd(object_set, FC_FILE) ); do str::as_c_str("file") |FC_FILE| {
str::as_c_str("index", |FC_INDEX| FcObjectSetAdd(object_set, FC_INDEX) ); FcObjectSetAdd(object_set, FC_FILE);
}
do str::as_c_str("index") |FC_INDEX| {
FcObjectSetAdd(object_set, FC_INDEX);
}
let matches = FcFontSetList(config, font_set_array_ptr, 1, pattern, object_set); let matches = FcFontSetList(config, font_set_array_ptr, 1, pattern, object_set);
@ -120,8 +126,6 @@ pub impl FontListHandle {
FcObjectSetDestroy(object_set); FcObjectSetDestroy(object_set);
} }
} }
}
}
} }
pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ()> { pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ()> {