From 1d69b61bb83522a0e24ce2a3c786149bf8f0088f Mon Sep 17 00:00:00 2001 From: ellson Date: Sat, 30 Jul 2005 17:10:16 +0000 Subject: [PATCH] For static and dynamic programs, builtins are now found by scanning the symbol table of the program itsel. This means that making a plugin library into a builtin just requires adding it to the list of libraries at link time. This doesn't quite work yet when dot is itself a plugin (tcldot and the script language bindings) so they still need a builtins.c --- cmd/dot/Makefile.am | 7 ++++-- cmd/tools/Makefile.am | 4 +++- cmd/tools/plugins.c | 26 ---------------------- lib/gvc/Makefile.am | 2 +- lib/gvc/builtins.c | 30 ------------------------- lib/gvc/gvc.c | 4 ++-- lib/gvc/gvconfig.c | 35 ++++++++++++++++++++++++----- lib/gvc/gvplugin.c | 2 +- lib/gvc/gvplugin.h | 3 ++- tclpkg/gv/Makefile.am | 2 +- tclpkg/gv/builtins.c | 47 +++++++++++++++++++++++++++++++++++++++ tclpkg/tcldot/Makefile.am | 7 +++--- tclpkg/tcldot/builtins.c | 47 +++++++++++++++++++++++++++++++++++++++ 13 files changed, 142 insertions(+), 74 deletions(-) delete mode 100644 cmd/tools/plugins.c delete mode 100644 lib/gvc/builtins.c create mode 100644 tclpkg/gv/builtins.c create mode 100644 tclpkg/tcldot/builtins.c diff --git a/cmd/dot/Makefile.am b/cmd/dot/Makefile.am index b1f5efbdc..1e0c46895 100644 --- a/cmd/dot/Makefile.am +++ b/cmd/dot/Makefile.am @@ -21,7 +21,8 @@ endif man_MANS = dot.1 pdf_DATA = dot.pdf -dot_SOURCES = dot.c $(top_srcdir)/lib/gvc/builtins.c +dot_SOURCES = dot.c +dot_LDFLAGS = -export-dynamic -dlpreopen self -export-symbols-regex '.*_LTX_library' dot_LDADD = \ $(top_builddir)/lib/plugin/libgvplugin_dot_layout.la \ $(top_builddir)/lib/plugin/libgvplugin_neato_layout.la \ @@ -57,6 +58,8 @@ dot_static_DEPENDENCIES = \ $(top_builddir)/lib/graph/.libs/libgraph.a \ $(top_builddir)/lib/cdt/.libs/libcdt.a \ $(top_builddir)/lib/gd/.libs/libgvgd.a +dot_static_LDFLAGS = -export-dynamic -dlpreopen self -export-symbols-regex '.*_LTX_library' + dot_static_LDADD = \ $(top_builddir)/lib/plugin/.libs/libgvplugin_dot_layout.a \ $(top_builddir)/lib/plugin/.libs/libgvplugin_neato_layout.a \ @@ -67,7 +70,7 @@ dot_static_LDADD = \ $(top_builddir)/lib/graph/.libs/libgraph.a \ $(top_builddir)/lib/cdt/.libs/libcdt.a \ $(top_builddir)/lib/gd/.libs/libgvgd.a \ - @GD_LIBS@ @EXPAT_LIBS@ @Z_LIBS@ @LIBGEN_LIBS@ @LIBLTDL@ @SOCKET_LIBS@ + @ICONV_LIBS@ @FC_LIBS@ @FT_LIBS@ @JPEG_LIBS@ @PNG_LIBS@ @MATH_LIBS@ @EXPAT_LIBS@ @Z_LIBS@ @LIBGEN_LIBS@ @LIBLTDL@ @SOCKET_LIBS@ EXTRA_DIST = Makefile.old dot.1 dot.pdf diff --git a/cmd/tools/Makefile.am b/cmd/tools/Makefile.am index e064d12f3..5707e9b78 100644 --- a/cmd/tools/Makefile.am +++ b/cmd/tools/Makefile.am @@ -95,7 +95,9 @@ gc_LDADD = \ $(top_builddir)/lib/ingraphs/libingraphs.la \ $(top_builddir)/lib/graph/libgraph.la -gvpack_SOURCES = gvpack.c plugins.c +gvpack_SOURCES = gvpack.c + +gvpack_LDFLAGS = -export-dynamic -dlpreopen self -export-symbols-regex '.*_LTX_library' gvpack_LDADD = \ $(top_builddir)/lib/common/libcommon.la \ diff --git a/cmd/tools/plugins.c b/cmd/tools/plugins.c deleted file mode 100644 index 582bd424e..000000000 --- a/cmd/tools/plugins.c +++ /dev/null @@ -1,26 +0,0 @@ -/* $Id$ $Revision$ */ -/* vim:set shiftwidth=4 ts=8: */ - -/********************************************************** -* This software is part of the graphviz package * -* http://www.graphviz.org/ * -* * -* Copyright (c) 1994-2004 AT&T Corp. * -* and is licensed under the * -* Common Public License, Version 1.0 * -* by AT&T Corp. * -* * -* Information and Software Systems Research * -* AT&T Research, Florham Park NJ * -**********************************************************/ - -#include - -#include "config.h" -#include "types.h" -#include "macros.h" -#include "gvc.h" -gvplugin_library_t *builtins[] = { - NULL -}; - diff --git a/lib/gvc/Makefile.am b/lib/gvc/Makefile.am index 9411836da..abf17e88f 100644 --- a/lib/gvc/Makefile.am +++ b/lib/gvc/Makefile.am @@ -28,4 +28,4 @@ libgvc_la_LIBADD = \ $(top_builddir)/lib/pathplan/libpathplan.la \ @GD_LIBS@ @EXPAT_LIBS@ @Z_LIBS@ @LIBGEN_LIBS@ -EXTRA_DIST = Makefile.old builtins.c +EXTRA_DIST = Makefile.old diff --git a/lib/gvc/builtins.c b/lib/gvc/builtins.c deleted file mode 100644 index dcc30668c..000000000 --- a/lib/gvc/builtins.c +++ /dev/null @@ -1,30 +0,0 @@ -/* $Id$ $Revision$ */ -/* vim:set shiftwidth=4 ts=8: */ - -/********************************************************** -* This software is part of the graphviz package * -* http://www.graphviz.org/ * -* * -* Copyright (c) 1994-2004 AT&T Corp. * -* and is licensed under the * -* Common Public License, Version 1.0 * -* by AT&T Corp. * -* * -* Information and Software Systems Research * -* AT&T Research, Florham Park NJ * -**********************************************************/ - -#include "gvplugin.h" - -extern gvplugin_library_t - gvplugin_dot_layout_LTX_library, - gvplugin_neato_layout_LTX_library, - gvplugin_usershape_gd_LTX_library; - -gvplugin_library_t *builtins[] = { - &gvplugin_dot_layout_LTX_library, - &gvplugin_neato_layout_LTX_library, - &gvplugin_usershape_gd_LTX_library, - NULL -}; - diff --git a/lib/gvc/gvc.c b/lib/gvc/gvc.c index c06d424f7..94aa0cf3a 100644 --- a/lib/gvc/gvc.c +++ b/lib/gvc/gvc.c @@ -16,7 +16,7 @@ #include "gvc.h" -char *Info[] = { +char *LibInfo[] = { "libgvc", /* Program */ VERSION, /* Version */ BUILDDATE /* Build Date */ @@ -28,7 +28,7 @@ GVC_t *gvContext(void) aginit(); agnodeattr(NULL, "label", NODENAME_ESC); - gvc = gvNEWcontext(Info, username()); + gvc = gvNEWcontext(LibInfo, username()); gvconfig(gvc, FALSE); /* configure for available plugins and codegens */ return gvc; } diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index bfa84f14a..95ca0615b 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -200,6 +200,32 @@ static void gvconfig_plugin_install_from_library(GVC_t * gvc, char *path, gvplug } } +struct lt_symlist +{ + const char *name; + void* address; +}; + +extern const struct lt_symlist lt_preloaded_symbols[]; + +static void gvconfig_plugin_install_builtins(GVC_t * gvc) +{ + const struct lt_symlist *s; + const char *name; + + s = lt_preloaded_symbols; + while ((name = s->name)) { +fprintf(stderr,"%s\n",name); + if (name[0] == 'g' + && name[1] == 'v' + && name[2] == 'p' + && strstr(name, "_LTX_library")) { + gvconfig_plugin_install_from_library(gvc, NULL, (gvplugin_library_t *)(s->address)); + } + s++; + } +} + #ifndef DISABLE_LTDL static void gvconfig_write_library_config(char *path, gvplugin_library_t *library, FILE *f) { @@ -253,8 +279,6 @@ char * gvconfig_libdir(void) } #endif -extern gvplugin_library_t *builtins[]; - #ifndef DISABLE_LTDL static void config_rescan(GVC_t *gvc, char *config_path) { @@ -431,7 +455,9 @@ codegen_info_t *next_codegen(codegen_info_t * p) */ void gvconfig(GVC_t * gvc, boolean rescan) { +#if 0 gvplugin_library_t **libraryp; +#endif #ifndef DISABLE_LTDL int sz, rc; struct stat config_st, libdir_st; @@ -451,10 +477,9 @@ void gvconfig(GVC_t * gvc, boolean rescan) "cg", NULL, (gvplugin_installed_t *) p); #endif - for (libraryp = builtins; *libraryp; libraryp++) { - gvconfig_plugin_install_from_library(gvc, NULL, *libraryp); - } #ifndef DISABLE_LTDL + gvconfig_plugin_install_builtins(gvc); + /* see if there are any new plugins */ libdir = gvconfig_libdir(); rc = stat(libdir, &libdir_st); diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index 93e2b159f..c508d5c7f 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -134,7 +134,7 @@ gvplugin_library_t *gvplugin_library_load(char *path) } hndl = lt_dlopen (p); if (!hndl) { - agerr(AGWARN, "failed to dlopen %s\n", p); + agerr(AGWARN, lt_dlerror()); return NULL; } diff --git a/lib/gvc/gvplugin.h b/lib/gvc/gvplugin.h index a9e0886b4..e75e181a5 100644 --- a/lib/gvc/gvplugin.h +++ b/lib/gvc/gvplugin.h @@ -27,7 +27,6 @@ extern "C" { #define NULL (void *)0 #endif - /* * Terminology: * @@ -75,6 +74,8 @@ extern "C" { gvplugin_api_t *apis; } gvplugin_library_t; + extern gvplugin_library_t *builtins[]; + #ifdef __cplusplus } #endif diff --git a/tclpkg/gv/Makefile.am b/tclpkg/gv/Makefile.am index 51fecaacd..b8aa928b8 100644 --- a/tclpkg/gv/Makefile.am +++ b/tclpkg/gv/Makefile.am @@ -10,7 +10,7 @@ AM_CPPFLAGS = \ LIBS = @LIBS@ -lc -BASESOURCES = gv.cpp $(top_srcdir)/lib/gvc/builtins.c +BASESOURCES = gv.cpp builtins.c BASELIBS = \ $(top_builddir)/lib/plugin/libgvplugin_dot_layout.la \ $(top_builddir)/lib/plugin/libgvplugin_neato_layout.la \ diff --git a/tclpkg/gv/builtins.c b/tclpkg/gv/builtins.c new file mode 100644 index 000000000..a97ee53ca --- /dev/null +++ b/tclpkg/gv/builtins.c @@ -0,0 +1,47 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +#include "gvplugin.h" + +struct lt_symlist +{ + const char *name; + void* address; +}; + +#if 0 +const char *gvplugin_dot_layout_name = "gvplugin_dot_layout_LTX_library"; +const char *gvplugin_neato_layout_name = "gvplugin_neato_layout_LTX_library"; +const char *gvplugin_usershape_gd_name = "gvplugin_usershape_gd_LTX_library"; + +extern gvplugin_library_t *gvplugin_dot_layout_LTX_library; +extern gvplugin_library_t *gvplugin_neato_layout_LTX_library; +extern gvplugin_library_t *gvplugin_usershape_gd_LTX_library; + +const struct lt_symlist lt_preloaded_symbols[] = { + { gvplugin_dot_layout_name, + (void*)gvplugin_dot_layout_LTX_library }, + { gvplugin_neato_layout_name, + (void*)gvplugin_neato_layout_LTX_library }, + { gvplugin_usershape_gd_name, + (void*)gvplugin_usershape_gd_LTX_library }, + { 0, + 0 } +}; +#else +const struct lt_symlist lt_preloaded_symbols[] = {{0,0,},}; +#endif + diff --git a/tclpkg/tcldot/Makefile.am b/tclpkg/tcldot/Makefile.am index 407aeaec2..f1db7fa03 100644 --- a/tclpkg/tcldot/Makefile.am +++ b/tclpkg/tcldot/Makefile.am @@ -30,16 +30,15 @@ pdf_DATA = $(pdf) html_DATA = $(html) endif -libtcldot_la_SOURCES = tcldot.c tkgen.c \ - $(top_srcdir)/tclpkg/gdtclft/gdtclft.c \ - $(top_srcdir)/lib/gvc/builtins.c +libtcldot_la_SOURCES = tcldot.c tkgen.c builtins.c \ + $(top_srcdir)/tclpkg/gdtclft/gdtclft.c libtcldot_la_LIBADD = \ $(top_builddir)/tclpkg/tclhandle/libtclhandle.la \ $(top_builddir)/tclpkg/tclstubs/libtclstubs.la \ $(top_builddir)/lib/plugin/libgvplugin_dot_layout.la \ $(top_builddir)/lib/plugin/libgvplugin_neato_layout.la \ $(top_builddir)/lib/plugin/libgvplugin_usershape_gd.la \ - $(top_builddir)/lib/gvc/libgvc.la + $(top_builddir)/lib/gvc/libgvc.la @LIBGEN_LIBS@ @LIBLTDL@ if WITH_TCL all-local: pkgIndex.tcl diff --git a/tclpkg/tcldot/builtins.c b/tclpkg/tcldot/builtins.c new file mode 100644 index 000000000..a97ee53ca --- /dev/null +++ b/tclpkg/tcldot/builtins.c @@ -0,0 +1,47 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +#include "gvplugin.h" + +struct lt_symlist +{ + const char *name; + void* address; +}; + +#if 0 +const char *gvplugin_dot_layout_name = "gvplugin_dot_layout_LTX_library"; +const char *gvplugin_neato_layout_name = "gvplugin_neato_layout_LTX_library"; +const char *gvplugin_usershape_gd_name = "gvplugin_usershape_gd_LTX_library"; + +extern gvplugin_library_t *gvplugin_dot_layout_LTX_library; +extern gvplugin_library_t *gvplugin_neato_layout_LTX_library; +extern gvplugin_library_t *gvplugin_usershape_gd_LTX_library; + +const struct lt_symlist lt_preloaded_symbols[] = { + { gvplugin_dot_layout_name, + (void*)gvplugin_dot_layout_LTX_library }, + { gvplugin_neato_layout_name, + (void*)gvplugin_neato_layout_LTX_library }, + { gvplugin_usershape_gd_name, + (void*)gvplugin_usershape_gd_LTX_library }, + { 0, + 0 } +}; +#else +const struct lt_symlist lt_preloaded_symbols[] = {{0,0,},}; +#endif + -- 2.40.0