X-Git-Url: https://git.draconx.ca/gitweb/upkg.git/blobdiff_plain/7904dbe4fcbe956ee4bf785df97d714a397defc1..07c7ad2a8ae59fd0159c52c27c263f034aa7746a:/src/libupkg.c diff --git a/src/libupkg.c b/src/libupkg.c index 6b1cfb3..b87c5dd 100644 --- a/src/libupkg.c +++ b/src/libupkg.c @@ -494,13 +494,17 @@ const char *upkg_get_name(struct upkg *pkg, unsigned long idx) return pkg->priv->names[idx].name; } -long upkg_export_find(struct upkg *pkg, const char *name) +long upkg_export_find(struct upkg *pkg, long parent, const char *name) { - /* This is wrong. - * Export names are not necessarily unique within a package. */ - for (unsigned i = 0; i < pkg->export_count; i++) { - struct upkg_export *export = &pkg->priv->exports[i]; - if (strcmp(export->name, name) == 0) { + /* This only makes sense if the assertion below is not violated. */ + long package = parent < 0 ? 0 : parent + 1; + + for (unsigned long i = 0; i < pkg->export_count; i++) { + struct upkg_export *e = &pkg->priv->exports[i]; + + /* Assertion: an object's package is an export. */ + format_assert(e->package >= 0, continue); + if (e->package == package && strcmp(e->name, name) == 0) { return i; } }