Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r102:538bc1da9a17 Date: 2014-11-28 17:48 +0100 http://bitbucket.org/cffi/creflect/changeset/538bc1da9a17/
Log: A tool in C to dump the reflection information stored in a library compiled from the output of "creflect". diff --git a/creflect/src/creflect_check.c b/creflect/src/creflect_check.c new file mode 100644 --- /dev/null +++ b/creflect/src/creflect_check.c @@ -0,0 +1,54 @@ +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <unistd.h> + +#include "creflect.h" +#include "creflect_print.h" + + +void creflect_dump_information(const char *filename) +{ + char filename_ex[PATH_MAX]; + + if (strchr(filename, '/') == NULL) + strcpy(filename_ex, "./"); + else + strcpy(filename_ex, ""); + strncat(filename_ex, filename, sizeof(filename_ex) - 3); + + void *lib = dlopen(filename_ex, RTLD_LAZY); + if (lib == NULL) + goto err; + + void (*crxmain)(crx_builder_t *); + crxmain = (void(*)(crx_builder_t *))dlsym(lib, "_creflect_main"); + if (crxmain == NULL) + goto err; + + crxmain(&maincb); + + if (dlclose(lib) != 0) { + lib = NULL; + goto err; + } + return; + + err: + fprintf(stderr, "error: %s\n", dlerror()); + if (lib) + dlclose(lib); +} + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + fprintf(stderr, "One argument needed: the name of the library file" + " out of which the creflect information is dumped.\n"); + return 2; + } + creflect_dump_information(argv[1]); + return 0; +} _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit