Skip to content

Commit 9272ec4

Browse files
committed
capi: Shorten blaze_user_meta_kind constants
Commit 3b47031 ("capi: Convert blaze_user_meta_kind to use associated constants") missed to rename the newly introduced associated constants, leading to unwieldy names. Introduce the proper shorter named constants and deprecated to long ones. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent 545d7f7 commit 9272ec4

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

capi/include/blazesym.h

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,26 @@ typedef uint8_t blaze_user_meta_kind;
272272
/**
273273
* [`blaze_user_meta_variant::unknown`] is valid.
274274
*/
275-
#define BLAZE_USER_META_KIND_BLAZE_USER_META_UNKNOWN 0
275+
#define BLAZE_USER_META_KIND_UNKNOWN 0
276276
/**
277277
* [`blaze_user_meta_variant::apk`] is valid.
278278
*/
279-
#define BLAZE_USER_META_KIND_BLAZE_USER_META_APK 1
279+
#define BLAZE_USER_META_KIND_APK 1
280280
/**
281281
* [`blaze_user_meta_variant::elf`] is valid.
282282
*/
283+
#define BLAZE_USER_META_KIND_ELF 2
284+
/**
285+
* Deprecated; use `BLAZE_USER_META_KIND_UNKNOWN`.
286+
*/
287+
#define BLAZE_USER_META_KIND_BLAZE_USER_META_UNKNOWN 0
288+
/**
289+
* Deprecated; use `BLAZE_USER_META_KIND_APK`.
290+
*/
291+
#define BLAZE_USER_META_KIND_BLAZE_USER_META_APK 1
292+
/**
293+
* Deprecated; use `BLAZE_USER_META_KIND_ELF`.
294+
*/
283295
#define BLAZE_USER_META_KIND_BLAZE_USER_META_ELF 2
284296

285297
/**
@@ -347,15 +359,15 @@ typedef struct blaze_user_meta_unknown {
347359
*/
348360
typedef union blaze_user_meta_variant {
349361
/**
350-
* Valid on [`blaze_user_meta_kind::BLAZE_USER_META_APK`].
362+
* Valid on [`blaze_user_meta_kind::APK`].
351363
*/
352364
struct blaze_user_meta_apk apk;
353365
/**
354-
* Valid on [`blaze_user_meta_kind::BLAZE_USER_META_ELF`].
366+
* Valid on [`blaze_user_meta_kind::ELF`].
355367
*/
356368
struct blaze_user_meta_elf elf;
357369
/**
358-
* Valid on [`blaze_user_meta_kind::BLAZE_USER_META_UNKNOWN`].
370+
* Valid on [`blaze_user_meta_kind::UNKNOWN`].
359371
*/
360372
struct blaze_user_meta_unknown unknown;
361373
} blaze_user_meta_variant;
@@ -465,12 +477,10 @@ typedef struct blaze_normalize_opts {
465477
bool map_files;
466478
/**
467479
* Normalize addresses inside APKs to the contained ELF file and
468-
* report a regular
469-
* [`BLAZE_USER_META_ELF`][blaze_user_meta_kind::BLAZE_USER_META_ELF]
470-
* meta data entry instead of an
471-
* [`BLAZE_USER_META_APK`][blaze_user_meta_kind::BLAZE_USER_META_APK]
472-
* one. As a result, the reported file offset will also be relative
473-
* to the contained ELF file and not to the APK itself.
480+
* report a regular [`blaze_user_meta_kind::ELF`] meta data entry
481+
* instead of an [`blaze_user_meta_kind::APK`] one. As a result,
482+
* the reported file offset will also be relative to the contained
483+
* ELF file and not to the APK itself.
474484
*/
475485
bool apk_to_elf;
476486
/**

capi/src/normalize.rs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ pub struct blaze_normalize_opts {
122122
/// better choice.
123123
pub map_files: bool,
124124
/// Normalize addresses inside APKs to the contained ELF file and
125-
/// report a regular
126-
/// [`BLAZE_USER_META_ELF`][blaze_user_meta_kind::BLAZE_USER_META_ELF]
127-
/// meta data entry instead of an
128-
/// [`BLAZE_USER_META_APK`][blaze_user_meta_kind::BLAZE_USER_META_APK]
129-
/// one. As a result, the reported file offset will also be relative
130-
/// to the contained ELF file and not to the APK itself.
125+
/// report a regular [`blaze_user_meta_kind::ELF`] meta data entry
126+
/// instead of an [`blaze_user_meta_kind::APK`] one. As a result,
127+
/// the reported file offset will also be relative to the contained
128+
/// ELF file and not to the APK itself.
131129
pub apk_to_elf: bool,
132130
/// Unused member available for future expansion. Must be initialized
133131
/// to zero.
@@ -281,10 +279,21 @@ pub struct blaze_user_meta_kind(u8);
281279

282280
impl blaze_user_meta_kind {
283281
/// [`blaze_user_meta_variant::unknown`] is valid.
284-
pub const BLAZE_USER_META_UNKNOWN: blaze_user_meta_kind = blaze_user_meta_kind(0);
282+
pub const UNKNOWN: blaze_user_meta_kind = blaze_user_meta_kind(0);
285283
/// [`blaze_user_meta_variant::apk`] is valid.
286-
pub const BLAZE_USER_META_APK: blaze_user_meta_kind = blaze_user_meta_kind(1);
284+
pub const APK: blaze_user_meta_kind = blaze_user_meta_kind(1);
287285
/// [`blaze_user_meta_variant::elf`] is valid.
286+
pub const ELF: blaze_user_meta_kind = blaze_user_meta_kind(2);
287+
288+
// TODO: Remove the following constants with the 0.2 release
289+
/// Deprecated; use `BLAZE_USER_META_KIND_UNKNOWN`.
290+
#[deprecated]
291+
pub const BLAZE_USER_META_UNKNOWN: blaze_user_meta_kind = blaze_user_meta_kind(0);
292+
/// Deprecated; use `BLAZE_USER_META_KIND_APK`.
293+
#[deprecated]
294+
pub const BLAZE_USER_META_APK: blaze_user_meta_kind = blaze_user_meta_kind(1);
295+
/// Deprecated; use `BLAZE_USER_META_KIND_ELF`.
296+
#[deprecated]
288297
pub const BLAZE_USER_META_ELF: blaze_user_meta_kind = blaze_user_meta_kind(2);
289298
}
290299

@@ -491,11 +500,11 @@ impl blaze_user_meta_unknown {
491500
/// The actual variant data in [`blaze_user_meta`].
492501
#[repr(C)]
493502
pub union blaze_user_meta_variant {
494-
/// Valid on [`blaze_user_meta_kind::BLAZE_USER_META_APK`].
503+
/// Valid on [`blaze_user_meta_kind::APK`].
495504
pub apk: ManuallyDrop<blaze_user_meta_apk>,
496-
/// Valid on [`blaze_user_meta_kind::BLAZE_USER_META_ELF`].
505+
/// Valid on [`blaze_user_meta_kind::ELF`].
497506
pub elf: ManuallyDrop<blaze_user_meta_elf>,
498-
/// Valid on [`blaze_user_meta_kind::BLAZE_USER_META_UNKNOWN`].
507+
/// Valid on [`blaze_user_meta_kind::UNKNOWN`].
499508
pub unknown: ManuallyDrop<blaze_user_meta_unknown>,
500509
}
501510

@@ -525,23 +534,23 @@ impl blaze_user_meta {
525534
fn from(other: UserMeta) -> ManuallyDrop<Self> {
526535
let slf = match other {
527536
UserMeta::Apk(apk) => Self {
528-
kind: blaze_user_meta_kind::BLAZE_USER_META_APK,
537+
kind: blaze_user_meta_kind::APK,
529538
unused: [0; 7],
530539
variant: blaze_user_meta_variant {
531540
apk: blaze_user_meta_apk::from(apk),
532541
},
533542
reserved: [0; 16],
534543
},
535544
UserMeta::Elf(elf) => Self {
536-
kind: blaze_user_meta_kind::BLAZE_USER_META_ELF,
545+
kind: blaze_user_meta_kind::ELF,
537546
unused: [0; 7],
538547
variant: blaze_user_meta_variant {
539548
elf: blaze_user_meta_elf::from(elf),
540549
},
541550
reserved: [0; 16],
542551
},
543552
UserMeta::Unknown(unknown) => Self {
544-
kind: blaze_user_meta_kind::BLAZE_USER_META_UNKNOWN,
553+
kind: blaze_user_meta_kind::UNKNOWN,
545554
unused: [0; 7],
546555
variant: blaze_user_meta_variant {
547556
unknown: blaze_user_meta_unknown::from(unknown),
@@ -555,13 +564,13 @@ impl blaze_user_meta {
555564

556565
unsafe fn free(self) {
557566
match self.kind {
558-
blaze_user_meta_kind::BLAZE_USER_META_APK => unsafe {
567+
blaze_user_meta_kind::APK => unsafe {
559568
ManuallyDrop::into_inner(self.variant.apk).free()
560569
},
561-
blaze_user_meta_kind::BLAZE_USER_META_ELF => unsafe {
570+
blaze_user_meta_kind::ELF => unsafe {
562571
ManuallyDrop::into_inner(self.variant.elf).free()
563572
},
564-
blaze_user_meta_kind::BLAZE_USER_META_UNKNOWN => {
573+
blaze_user_meta_kind::UNKNOWN => {
565574
ManuallyDrop::into_inner(unsafe { self.variant.unknown }).free()
566575
}
567576
_ => {
@@ -808,7 +817,7 @@ mod tests {
808817
"blaze_normalized_output { output: 4919, meta_idx: 1, reserved: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }"
809818
);
810819

811-
let meta_kind = blaze_user_meta_kind::BLAZE_USER_META_APK;
820+
let meta_kind = blaze_user_meta_kind::APK;
812821
assert_eq!(format!("{meta_kind:?}"), "blaze_user_meta_kind(1)");
813822

814823
let apk = blaze_user_meta_apk {
@@ -841,7 +850,7 @@ mod tests {
841850
);
842851

843852
let meta = blaze_user_meta {
844-
kind: blaze_user_meta_kind::BLAZE_USER_META_UNKNOWN,
853+
kind: blaze_user_meta_kind::UNKNOWN,
845854
unused: [0; 7],
846855
variant: blaze_user_meta_variant {
847856
unknown: ManuallyDrop::new(blaze_user_meta_unknown {
@@ -976,7 +985,7 @@ mod tests {
976985
assert_eq!(user_addrs.output_cnt, 6);
977986

978987
let meta = unsafe { user_addrs.metas.read() };
979-
assert_eq!(meta.kind, blaze_user_meta_kind::BLAZE_USER_META_UNKNOWN);
988+
assert_eq!(meta.kind, blaze_user_meta_kind::UNKNOWN);
980989
assert_eq!(
981990
unsafe { meta.variant.unknown.reason },
982991
blaze_normalize_reason::UNMAPPED
@@ -1144,7 +1153,7 @@ mod tests {
11441153

11451154
let output = unsafe { &*normalized.outputs.add(0) };
11461155
let meta = unsafe { &*normalized.metas.add(output.meta_idx) };
1147-
assert_eq!(meta.kind, blaze_user_meta_kind::BLAZE_USER_META_ELF);
1156+
assert_eq!(meta.kind, blaze_user_meta_kind::ELF);
11481157

11491158
let elf = unsafe { &meta.variant.elf };
11501159

@@ -1218,7 +1227,7 @@ mod tests {
12181227

12191228
let output = unsafe { &*normalized.outputs.add(0) };
12201229
let meta = unsafe { &*normalized.metas.add(output.meta_idx) };
1221-
assert_eq!(meta.kind, blaze_user_meta_kind::BLAZE_USER_META_ELF);
1230+
assert_eq!(meta.kind, blaze_user_meta_kind::ELF);
12221231

12231232
let elf = unsafe { &meta.variant.elf };
12241233
let path = unsafe { CStr::from_ptr(elf.path) };

0 commit comments

Comments
 (0)