From b5a18d3dd9ca4315f9d7f75e90363410db405935 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 13 Jul 2012 10:22:43 -0400 Subject: [PATCH] libupkg: Kill upkg_export_class. This function was quite broken, and crapped out on a number of the objects in Engine.u. Kill it off because we now have the machinery to do this more properly. --- src/libupkg.c | 43 ---------------------------------------- src/upkg.c | 55 +++++++++++++++++++++++++++++++++------------------ src/upkg.h | 3 --- 3 files changed, 36 insertions(+), 65 deletions(-) diff --git a/src/libupkg.c b/src/libupkg.c index d4978a3..c87f668 100644 --- a/src/libupkg.c +++ b/src/libupkg.c @@ -542,49 +542,6 @@ const struct upkg_import *upkg_get_import(struct upkg *pub, unsigned long idx) return NULL; } -const char *upkg_export_class(struct upkg *pub, unsigned long idx, - const char **package) -{ - struct upkg_priv *pkg = (struct upkg_priv *)pub; - const struct upkg_import *iclass, *ipackage; - struct upkg_export_priv *export; - unsigned long pkg_idx; - - if (idx >= pkg->pub.export_count) - return NULL; - - export = &pkg->exports[idx]; - - /* Assumption: class references are always imports. */ - format_assert(export->pub.class <= 0, return NULL); - - /* Get the class. */ - if (export->pub.class == 0) { - if (package) *package = "Core"; - return "Class"; - } - - pkg_idx = -(export->pub.class + 1); - if (pkg_idx >= pkg->pub.import_count) - return NULL; - iclass = &pkg->imports[pkg_idx]; - - /* Assumption: class references are always Core.Class. */ - format_assert(!strcmp(iclass->class_package, "Core"), return NULL); - format_assert(!strcmp(iclass->class_name, "Class"), return NULL); - - ipackage = iclass->parent; - if (!ipackage) - return NULL; - - /* Assumption: package references are always Core.Package. */ - format_assert(!strcmp(ipackage->class_package, "Core"), return NULL); - format_assert(!strcmp(ipackage->class_name, "Package"), return NULL); - - if (package) *package = ipackage->name; - return iclass->name; -} - struct upkg_file *upkg_export_open(struct upkg *pub, unsigned long idx) { struct upkg_priv *pkg = (struct upkg_priv *)pub; diff --git a/src/upkg.c b/src/upkg.c index 2b26aa4..55d13f8 100644 --- a/src/upkg.c +++ b/src/upkg.c @@ -206,18 +206,39 @@ static void import_print_fullname(const struct upkg_import *import) } } -void print_upkg_exports(struct upkg *pkg) +static void +export_print_class(GTypeModule *pkg, const struct upkg_export *export) { - for (unsigned i = 0; i < pkg->export_count; i++) { - const struct upkg_export *export = upkg_get_export(pkg, i); - const char *package, *class; + struct upkg *upkg = U_PKG(pkg)->pkg; - class = upkg_export_class(pkg, i, &package); + if (export->class < 0) { + const struct upkg_import *class; - if (!class) - continue; + class = upkg_get_import(upkg, -(export->class+1)); + import_print_fullname(class); + } else if (export->class > 0) { + const struct upkg_export *class; + + class = upkg_get_export(upkg, export->class-1); + export_print_fullname(pkg, class); + } else { + printf("Core.Class"); + } +} + +void print_upkg_exports(GTypeModule *pkg) +{ + struct upkg *upkg = U_PKG(pkg)->pkg; + + for (unsigned i = 0; i < upkg->export_count; i++) { + const struct upkg_export *export = upkg_get_export(upkg, i); + + printf("%u - ", i+1); + export_print_fullname(pkg, export); + printf(" ("); + export_print_class(pkg, export); + printf(")\n"); - printf("%u - %s (%s.%s)\n", i+1, export->name, package, class); printf(" Flags: %lx\n", export->flags); if (verbose >= 2) { print_upkg_object_flags(" ", export->flags); @@ -258,7 +279,7 @@ int package_info(GTypeModule *pkg) } printf("Exports: %lu\n", upkg->export_count); - if (verbose >= 1) print_upkg_exports(upkg); + if (verbose >= 1) print_upkg_exports(pkg); printf("Imports: %lu\n", upkg->import_count); if (verbose >= 1) print_upkg_imports(upkg); @@ -284,10 +305,9 @@ static int package_list(GTypeModule *pkg, long current) export_print_fullname(pkg, export); if (verbose >= 1) { - const char *class, *package; - - class = upkg_export_class(upkg, i, &package); - printf(" (%s.%s)", package, class); + printf(" ("); + export_print_class(pkg, export); + printf(")"); } putchar('\n'); @@ -361,17 +381,14 @@ static int object_info(GTypeModule *pkg, unsigned long idx) { struct upkg *upkg = U_PKG(pkg)->pkg; const struct upkg_export *export; - const char *class, *package; int ret = 0; export = upkg_get_export(upkg, idx); export_print_fullname(pkg, export); - class = upkg_export_class(upkg, idx, &package); - if (class) - printf(" (%s.%s)\n", package, class); - else - printf(" (failed to get class)\n"); + printf(" ("); + export_print_class(pkg, export); + printf(")\n"); if (verbose >= 1 && object_dump_properties(pkg, idx) != 0) ret = -1; diff --git a/src/upkg.h b/src/upkg.h index d236714..da85a26 100644 --- a/src/upkg.h +++ b/src/upkg.h @@ -115,9 +115,6 @@ const struct upkg_import *upkg_get_import(struct upkg *pkg, unsigned long idx); long upkg_export_find(struct upkg *pkg, long parent, const char *name); -const char *upkg_export_class(struct upkg *pkg, unsigned long idx, - const char **package); - struct upkg_file *upkg_export_open(struct upkg *pkg, unsigned long idx); size_t upkg_export_read(struct upkg_file *f, void *buf, size_t n); int upkg_export_seek(struct upkg_file *f, long offset, int whence); -- 2.43.0