Making users handle the package member directly leads to some fairly
ridiculous and somewhat tricky code. Resolve them all at package load
time and store pointers directly in the upkg_export structure, which
should help simplify the callers.
At this point, we codify the "exports cannot have packages which are
imports" assumption, which appears to be valid. It's not obvious how
name lookup could possibly succeed if this were not the case.
while (index < pkg->pub.export_count) {
struct upkg_export_priv *export = &pkg->exports[index];
while (index < pkg->pub.export_count) {
struct upkg_export_priv *export = &pkg->exports[index];
+ unsigned long parent_index;
long tmp;
/* Read some data into buffer. */
long tmp;
/* Read some data into buffer. */
len += rc;
if (nbuf-len < 4) goto err;
len += rc;
if (nbuf-len < 4) goto err;
- export->pub.package = unpack_s32_le(buf+len);
+ parent_index = unpack_32_le(buf+len);
+ export->pub.parent = NULL;
+ if (parent_index > 0) {
+ parent_index--;
+ if (parent_index >= pkg->pub.export_count)
+ goto err;
+ export->pub.parent = &pkg->exports[parent_index].pub;
+ }
+
rc = upkg_decode_index(&tmp, buf+len, nbuf-len);
if (rc == 0 || tmp < 0 || tmp >= pkg->pub.name_count) goto err;
export->pub.name = pkg->names[tmp].name;
rc = upkg_decode_index(&tmp, buf+len, nbuf-len);
if (rc == 0 || tmp < 0 || tmp >= pkg->pub.name_count) goto err;
export->pub.name = pkg->names[tmp].name;
return pkg->names[idx].name;
}
return pkg->names[idx].name;
}
-long upkg_export_find(struct upkg *pub, long parent, const char *name)
+long upkg_export_find(struct upkg *pub, long parent_index, const char *name)
{
struct upkg_priv *pkg = (struct upkg_priv *)pub;
{
struct upkg_priv *pkg = (struct upkg_priv *)pub;
+ struct upkg_export *parent = NULL;
- /* This only makes sense if the assertion below is not violated. */
- long package = parent < 0 ? 0 : parent + 1;
+ if (parent_index >= 0) {
+ if (parent_index >= pkg->pub.export_count)
+ return -1;
+ parent = &pkg->exports[parent_index].pub;
+ }
for (unsigned long i = 0; i < pkg->pub.export_count; i++) {
struct upkg_export_priv *e = &pkg->exports[i];
for (unsigned long i = 0; i < pkg->pub.export_count; i++) {
struct upkg_export_priv *e = &pkg->exports[i];
- /* Assertion: an object's package is an export. */
- format_assert(e->pub.package >= 0, continue);
- if (e->pub.package == package
- && strcmp(e->pub.name, name) == 0) {
+ if (e->pub.parent == parent && !strcmp(e->pub.name, name))
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <glib-object.h>
#include <getopt.h>
#include <glib-object.h>
static void export_print_name(struct upkg *upkg, const struct upkg_export *e)
{
if (e) {
static void export_print_name(struct upkg *upkg, const struct upkg_export *e)
{
if (e) {
- export_print_name(upkg, upkg_get_export(upkg, e->package-1));
+ export_print_name(upkg, e->parent);
printf(".%s", e->name);
}
}
printf(".%s", e->name);
}
}
export_print_name(U_PKG(pkg)->pkg, export);
}
export_print_name(U_PKG(pkg)->pkg, export);
}
-static int package_list(GTypeModule *pkg, long parent)
+static int package_list(GTypeModule *pkg, long current)
{
struct upkg *upkg = U_PKG(pkg)->pkg;
{
struct upkg *upkg = U_PKG(pkg)->pkg;
- const struct upkg_export *export;
+ const struct upkg_export *parent = NULL;
+
+ if (current >= 0) {
+ parent = upkg_get_export(upkg, current);
+ assert(parent != NULL);
+ }
for (unsigned i = 0; i < upkg->export_count; i++) {
for (unsigned i = 0; i < upkg->export_count; i++) {
- export = upkg_get_export(upkg, i);
+ const struct upkg_export *export = upkg_get_export(upkg, i);
- if (export->package != parent)
+ if (export->parent != parent)
continue;
export_print_fullname(pkg, export);
continue;
export_print_fullname(pkg, export);
ret = object_info(pkg, current);
break;
case MODE_LIST:
ret = object_info(pkg, current);
break;
case MODE_LIST:
- ret = package_list(pkg, current+1);
+ ret = package_list(pkg, current);
break;
case MODE_EXPORT:
if (current < 0)
break;
case MODE_EXPORT:
if (current < 0)
+ const struct upkg_export *parent;