Kaynağa Gözat

use function pointers instead of weak symbols for cmdline parsing

Passing function pointers around while working on this was very icky,
but if weak symbols are too much to ask for…

Reverts "do not use "-Wl,-Bsymbolic-functions" during the build to avoid
breakage" aka a5fc9be36211a290a7abc3ca2a8bf98943bc1f57.
David Kalnischkies 10 yıl önce
ebeveyn
işleme
90986d4dbb

+ 7 - 9
apt-private/private-cmndline.cc

@@ -378,7 +378,8 @@ static void ShowHelpListCommands(std::vector<aptDispatchWithHelp> const &Cmds)/*
    }
    }
 }
 }
 									/*}}}*/
 									/*}}}*/
-static bool ShowCommonHelp(APT_CMD const Binary, CommandLine &CmdL, std::vector<aptDispatchWithHelp> const &Cmds)/*{{{*/
+static bool ShowCommonHelp(APT_CMD const Binary, CommandLine &CmdL, std::vector<aptDispatchWithHelp> const &Cmds,/*{{{*/
+      bool (*ShowHelp)(CommandLine &))
 {
 {
    std::cout << PACKAGE << " " << PACKAGE_VERSION << " (" << COMMON_ARCH << ")" << std::endl;
    std::cout << PACKAGE << " " << PACKAGE_VERSION << " (" << COMMON_ARCH << ")" << std::endl;
    if (_config->FindB("version") == true && Binary != APT_CMD::APT_GET)
    if (_config->FindB("version") == true && Binary != APT_CMD::APT_GET)
@@ -442,7 +443,8 @@ static void BinarySpecificConfiguration(char const * const Binary)	/*{{{*/
 }
 }
 									/*}}}*/
 									/*}}}*/
 std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD const Binary,/*{{{*/
 std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD const Binary,/*{{{*/
-      Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[])
+      Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[],
+      bool (*ShowHelp)(CommandLine &), std::vector<aptDispatchWithHelp> (*GetCommands)(void))
 {
 {
    if (Cnf != NULL && pkgInitConfig(**Cnf) == false)
    if (Cnf != NULL && pkgInitConfig(**Cnf) == false)
    {
    {
@@ -477,7 +479,7 @@ std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD c
        (Sys != NULL && pkgInitSystem(*_config, *Sys) == false))
        (Sys != NULL && pkgInitSystem(*_config, *Sys) == false))
    {
    {
       if (_config->FindB("version") == true)
       if (_config->FindB("version") == true)
-	 ShowCommonHelp(Binary, CmdL, CmdsWithHelp);
+	 ShowCommonHelp(Binary, CmdL, CmdsWithHelp, ShowHelp);
 
 
       _error->DumpErrors();
       _error->DumpErrors();
       exit(100);
       exit(100);
@@ -487,12 +489,12 @@ std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD c
    if (_config->FindB("help") == true || _config->FindB("version") == true ||
    if (_config->FindB("help") == true || _config->FindB("version") == true ||
 	 (CmdL.FileSize() > 0 && strcmp(CmdL.FileList[0], "help") == 0))
 	 (CmdL.FileSize() > 0 && strcmp(CmdL.FileList[0], "help") == 0))
    {
    {
-      ShowCommonHelp(Binary, CmdL, CmdsWithHelp);
+      ShowCommonHelp(Binary, CmdL, CmdsWithHelp, ShowHelp);
       exit(0);
       exit(0);
    }
    }
    if (Cmds.empty() == false && CmdL.FileSize() == 0)
    if (Cmds.empty() == false && CmdL.FileSize() == 0)
    {
    {
-      ShowCommonHelp(Binary, CmdL, CmdsWithHelp);
+      ShowCommonHelp(Binary, CmdL, CmdsWithHelp, ShowHelp);
       exit(1);
       exit(1);
    }
    }
    return Cmds;
    return Cmds;
@@ -514,7 +516,3 @@ unsigned short DispatchCommandLine(CommandLine &CmdL, std::vector<CommandLine::D
    return Errors == true ? 100 : 0;
    return Errors == true ? 100 : 0;
 }
 }
 									/*}}}*/
 									/*}}}*/
-
-// weak symbols
-bool ShowHelp(CommandLine &) { return false; }
-std::vector<aptDispatchWithHelp> GetCommands() { return {}; }

+ 2 - 1
apt-private/private-cmndline.h

@@ -33,7 +33,8 @@ struct aptDispatchWithHelp
 APT_PUBLIC std::vector<aptDispatchWithHelp> GetCommands() APT_WEAK;
 APT_PUBLIC std::vector<aptDispatchWithHelp> GetCommands() APT_WEAK;
 
 
 APT_PUBLIC std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD const Binary,
 APT_PUBLIC std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD const Binary,
-      Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char * argv[]);
+      Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char * argv[],
+      bool (*ShowHelp)(CommandLine &), std::vector<aptDispatchWithHelp> (*GetCommands)(void));
 APT_PUBLIC unsigned short DispatchCommandLine(CommandLine &CmdL, std::vector<CommandLine::Dispatch> const &Cmds);
 APT_PUBLIC unsigned short DispatchCommandLine(CommandLine &CmdL, std::vector<CommandLine::Dispatch> const &Cmds);
 
 
 APT_PUBLIC std::vector<CommandLine::Args> getCommandArgs(APT_CMD const Program, char const * const Cmd);
 APT_PUBLIC std::vector<CommandLine::Args> getCommandArgs(APT_CMD const Program, char const * const Cmd);

+ 1 - 1
cmdline/apt-cache.cc

@@ -1247,7 +1247,7 @@ int main(int argc,const char *argv[])					/*{{{*/
 
 
    // Parse the command line and initialize the package library
    // Parse the command line and initialize the package library
    CommandLine CmdL;
    CommandLine CmdL;
-   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CACHE, &_config, &_system, argc, argv);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CACHE, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
    InitOutput();
    InitOutput();
 
 

+ 1 - 1
cmdline/apt-cdrom.cc

@@ -229,7 +229,7 @@ int main(int argc,const char *argv[])					/*{{{*/
 
 
    // Parse the command line and initialize the package library
    // Parse the command line and initialize the package library
    CommandLine CmdL;
    CommandLine CmdL;
-   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CDROM, &_config, &_system, argc, argv);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CDROM, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
    InitOutput();
    InitOutput();
 
 

+ 1 - 1
cmdline/apt-config.cc

@@ -101,7 +101,7 @@ int main(int argc,const char *argv[])					/*{{{*/
 
 
    // Parse the command line and initialize the package library
    // Parse the command line and initialize the package library
    CommandLine CmdL;
    CommandLine CmdL;
-   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CONFIG, &_config, &_system, argc, argv);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CONFIG, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
    std::vector<std::string> const langs = APT::Configuration::getLanguages(true);
    std::vector<std::string> const langs = APT::Configuration::getLanguages(true);
    _config->Clear("Acquire::Languages");
    _config->Clear("Acquire::Languages");

+ 1 - 1
cmdline/apt-extracttemplates.cc

@@ -342,7 +342,7 @@ int main(int argc, const char **argv)					/*{{{*/
 	InitLocale();
 	InitLocale();
 
 
 	CommandLine CmdL;
 	CommandLine CmdL;
-	auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_EXTRACTTEMPLATES, &_config, &_system, argc, argv);
+	auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_EXTRACTTEMPLATES, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
 	Go(CmdL);
 	Go(CmdL);
 
 

+ 1 - 1
cmdline/apt-get.cc

@@ -434,7 +434,7 @@ int main(int argc,const char *argv[])					/*{{{*/
 
 
    // Parse the command line and initialize the package library
    // Parse the command line and initialize the package library
    CommandLine CmdL;
    CommandLine CmdL;
-   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_GET, &_config, &_system, argc, argv);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_GET, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
    InitSignals();
    InitSignals();
    InitOutput();
    InitOutput();

+ 1 - 1
cmdline/apt-helper.cc

@@ -131,7 +131,7 @@ int main(int argc,const char *argv[])					/*{{{*/
    InitLocale();
    InitLocale();
 
 
    CommandLine CmdL;
    CommandLine CmdL;
-   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_HELPER, &_config, &_system, argc, argv);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_HELPER, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
    InitOutput();
    InitOutput();
 
 

+ 1 - 1
cmdline/apt-internal-solver.cc

@@ -71,7 +71,7 @@ int main(int argc,const char *argv[])					/*{{{*/
 	DropPrivileges();
 	DropPrivileges();
 
 
 	CommandLine CmdL;
 	CommandLine CmdL;
-	ParseCommandLine(CmdL, APT_CMD::APT_INTERNAL_SOLVER, &_config, NULL, argc, argv);
+	ParseCommandLine(CmdL, APT_CMD::APT_INTERNAL_SOLVER, &_config, NULL, argc, argv, &ShowHelp, &GetCommands);
 
 
 	if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0)
 	if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0)
 	{
 	{

+ 1 - 1
cmdline/apt-mark.cc

@@ -322,7 +322,7 @@ int main(int argc,const char *argv[])					/*{{{*/
    InitLocale();
    InitLocale();
 
 
    CommandLine CmdL;
    CommandLine CmdL;
-   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_MARK, &_config, &_system, argc, argv);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_MARK, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
    InitOutput();
    InitOutput();
 
 

+ 1 - 1
cmdline/apt-sortpkgs.cc

@@ -155,7 +155,7 @@ int main(int argc,const char *argv[])					/*{{{*/
    InitLocale();
    InitLocale();
 
 
    CommandLine CmdL;
    CommandLine CmdL;
-   ParseCommandLine(CmdL, APT_CMD::APT_SORTPKG, &_config, &_system, argc, argv);
+   ParseCommandLine(CmdL, APT_CMD::APT_SORTPKG, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
    // Match the operation
    // Match the operation
    for (unsigned int I = 0; I != CmdL.FileSize(); I++)
    for (unsigned int I = 0; I != CmdL.FileSize(); I++)

+ 1 - 1
cmdline/apt.cc

@@ -100,7 +100,7 @@ int main(int argc, const char *argv[])					/*{{{*/
    InitLocale();
    InitLocale();
 
 
    CommandLine CmdL;
    CommandLine CmdL;
-   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT, &_config, &_system, argc, argv);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
 
 
    int const quiet = _config->FindI("quiet", 0);
    int const quiet = _config->FindI("quiet", 0);
    if (quiet == 2)
    if (quiet == 2)

+ 1 - 4
debian/rules

@@ -29,10 +29,7 @@ ifneq (,$(shell which dpkg-buildflags))
   # (http://savannah.gnu.org/bugs/?10593)
   # (http://savannah.gnu.org/bugs/?10593)
   dpkg_buildflags = DEB_BUILD_MAINT_OPTIONS=hardening=+all dpkg-buildflags
   dpkg_buildflags = DEB_BUILD_MAINT_OPTIONS=hardening=+all dpkg-buildflags
   export CXXFLAGS = $(shell $(dpkg_buildflags) --get CXXFLAGS)
   export CXXFLAGS = $(shell $(dpkg_buildflags) --get CXXFLAGS)
-  # we can not use "-Wl,-Bsymbolic-functions" with the new weak symbols
-  # in libapt-private (commit 28f24d3d added those)
-  comma:= ,
-  export LDFLAGS = $(subst -Wl$(comma)-Bsymbolic-functions,,$(shell $(dpkg_buildflags) --get LDFLAGS))
+  export LDFLAGS = $(shell $(dpkg_buildflags) --get LDFLAGS)
   export CPPFLAGS = $(shell $(dpkg_buildflags) --get CPPFLAGS)
   export CPPFLAGS = $(shell $(dpkg_buildflags) --get CPPFLAGS)
 else
 else
   ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
   ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))

+ 1 - 1
ftparchive/apt-ftparchive.cc

@@ -1048,7 +1048,7 @@ int main(int argc, const char *argv[])					/*{{{*/
 
 
    // Parse the command line and initialize the package library
    // Parse the command line and initialize the package library
    CommandLine CmdL;
    CommandLine CmdL;
-   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_FTPARCHIVE, &_config, NULL, argc, argv);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_FTPARCHIVE, &_config, NULL, argc, argv, ShowHelp, &GetCommands);
 
 
    _config->CndSet("quiet",0);
    _config->CndSet("quiet",0);
    Quiet = _config->FindI("quiet",0);
    Quiet = _config->FindI("quiet",0);