Skip to content

Commit

Permalink
Use std::.. for documented <c...> header functions. Remove UNUSED hac…
Browse files Browse the repository at this point in the history
…kery
  • Loading branch information
vaeth committed Mar 28, 2017
1 parent 4341f66 commit 197d544
Show file tree
Hide file tree
Showing 65 changed files with 283 additions and 411 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*eix-0.32.7
Martin Väth <martin at mvath.de>:
- internal: provide and use eix::array instead of hacks
- internal: use std::.. for documented functions from #include <c...>
- internal: remove UNUSED hackery
- contrib/make.sh: Improve clang filtering

*eix-0.32.6
Expand Down
12 changes: 6 additions & 6 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,9 @@
/* Define if __attribute__ ((signal)) can be used */
#undef HAVE_ATTRIBUTE_SIGNAL

/* Define if __attribute__ ((unused)) can be used */
#undef HAVE_ATTRIBUTE_UNUSED

/* Define if [[noreturn]] can be used */
#undef HAVE_C11ATTRIBUTE_NORETURN

/* Define if [[maybe_unused]] can be used */
#undef HAVE_C11ATTRIBUTE_UNUSED

/* Define to 1 if you have the `canonicalize_file_name' function. */
#undef HAVE_CANONICALIZE_FILE_NAME

Expand Down Expand Up @@ -247,9 +241,15 @@
/* Define to 1 if you have the `strtol' function. */
#undef HAVE_STRTOL

/* Define to 1 if you have the `strtoll' function. */
#undef HAVE_STRTOLL

/* Define to 1 if you have the `strtoul' function. */
#undef HAVE_STRTOUL

/* Define to 1 if you have the `strtoull' function. */
#undef HAVE_STRTOULL

/* Define to 1 if you have the <sys/file.h> header file. */
#undef HAVE_SYS_FILE_H

Expand Down
45 changes: 5 additions & 40 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,12 @@ AC_CHECK_FUNCS([regcomp strchr strerror strrchr fnmatch memset],
[AC_MSG_ERROR([We really need this function ..])])

# We need at least one of the following, the former the better
AC_CHECK_FUNCS([strtoul strtol atoi],
AC_CHECK_FUNCS([strtoull strtoul],
[break],
[AC_MSG_ERROR([At least one of strtoul/strtoll/atoi is needed ..])])
[:])
AC_CHECK_FUNCS([strtoll strtol atoi],
[break],
[AC_MSG_ERROR([At least one of stroll/strtol/atoi is needed ..])])

# Optional header files:
AC_CHECK_HEADERS([sys/param.h \
Expand Down Expand Up @@ -913,44 +916,6 @@ AS_IF([$gcc_diag_pragma],
[1],
[Define if _Pragma GCC diagnostic can be used everywhere])])

# Check if [[maybe_unused]] works
AC_MSG_CHECKING([[whether [[maybe_unused]] can be used]])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
static int dummy(int i);
static int
dummy([[maybe_unused]] int i)
{ return 0; }
]], [[
return dummy(1);
]])],
[MV_MSG_RESULT([yes])
AS_VAR_SET([c11attr_unused], [:])],
[MV_MSG_RESULT([no])
AS_VAR_SET([c11attr_unused], [false])])
AS_IF([$c11attr_unused],
[AC_DEFINE([HAVE_C11ATTRIBUTE_UNUSED],
[1],
[Define if [[maybe_unused]] can be used])])

# Check if __attribute__ ((unused)) works
AC_MSG_CHECKING([whether __attribute__ ((unused)) can be used])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
static int dummy(int i);
static int
dummy(__attribute__ ((unused)) int i)
{ return 0; }
]], [[
return dummy(1);
]])],
[MV_MSG_RESULT([yes])
AS_VAR_SET([attr_unused], [:])],
[MV_MSG_RESULT([no])
AS_VAR_SET([attr_unused], [false])])
AS_IF([$attr_unused],
[AC_DEFINE([HAVE_ATTRIBUTE_UNUSED],
[1],
[Define if __attribute__ ((unused)) can be used])])

# Check if [[noreturn]] works
AC_MSG_CHECKING([[whether [[noreturn]] can be used]])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Expand Down
26 changes: 15 additions & 11 deletions contrib/check_includes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Check '"eixTk/assert\.h"' -e 'eix_assert'
Check '"eixTk/stringtypes\.h"' -e 'WordVec' -e 'WordSet' -e 'WordMap' -e 'WordList' -e 'LineVec' -e 'WordSize'
Check '"eixTk/dialect\.h"' -e 'CONSTEXPR' -e 'ASSIGN_DELETE' -e 'OVERRIDE[^_A-Z]' -e 'NOEXCEPT'
Check '"eixTk/diagnostics\.h"' -e DIAG_OFF -e DIAG_ON
Check '"eixTk/eixarray\.h"' -e 'eix::array'
Check '"eixTk/eixint\.h"' -e OffsetType -e UChar -e UNumber -e Treesize -e Catsize -e Versize -e SignedBool -e TinySigned -e TinyUnsigned
Check '"eixTk/formated\.h"' -e 'eix::format' -e 'eix::print' -e 'eix::say'
Check '"eixTk/i18n\.h"' -e '_('
Expand All @@ -138,13 +139,12 @@ Check '"eixTk/null\.h"' -e 'NULLPTR'
Check '"eixTk/auto_array\.h"' -e 'auto_array'
Check '"eixTk/forward_list\.h"' -e 'forward_list'
Check '"eixTk/ptr_container\.h"' -e 'ptr_container' -e 'ptr_forward_container'
Check '"eixTk/stringutils\.h"' -e 'split[^- ]' -e isdigit -e '[^a-z]isal[np]' -e isspace -e isdigit -e isalpha -e isalnum -e is_numeric -e tolower -e toupper -e to_lower -e trim -e StringHash -e escape_string -e localeC -e match_list -e slot_subslot -e casecontains -e caseequal -e my_atoi
Check '"eixTk/unused\.h"' -e '[^_]UNUSED' -e '^UNUSED'
Check '"eixTk/stringutils\.h"' -e 'split[^- ]' -e isdigit -e '[^a-z]isal[np]' -e isspace -e isdigit -e isalpha -e isalnum -e is_numeric -e tolower -e toupper -e to_lower -e trim -e StringHash -e escape_string -e localeC -e match_list -e slot_subslot -e casecontains -e caseequal -e my_atou -e my_atos
Check '"eixTk/attribute\.h"' -e 'ATTRIBUTE_'
Check '"portage/basicversion\.h"' -e 'BasicVersion' -e 'BasicPart'
CheckWithout '"search/packagetest\.h"' -e 'PackageTest::'

Check '<iostream>' -e '[^a-z]cout[^a-z]' -e '[^a-z]cerr[^a-z]' -e '[^a-z]cin[^a-z]'
Check '<iostream>' -e std::cout -e std::cerr -e std::cin
Check '<list>' -e '[^_]list<' -e '^list<'
Check '<map>' -e '[^_]map<' -e '^map<'
Check '<set>' -e '[^_]set<' -e '^set<'
Expand All @@ -163,19 +163,23 @@ CheckWith : 'string' -e '[^:_]string[^a-zA-Z_0-9]*'
#Check : 'cout' -e '[^:_]cout[^a-z]'
#Check : 'endl' -e '[^:_]endl[^a-z]'
GrepAllWith -e '[^:_]cerr[^a-z]' -e '[^:_]cout[^a-z]' -e '[^:_]endl[^a-z]'
GrepAllWith -e '[^:]fopen' -e '[^:]fclose' -e '[^:]fflush' -e '[^:"]fseek[^o]' -e '[^:]ftell[^o]' -e '[^:]fread' -e '[^:]fwrite' -e '[^:fn]printf(' -e '[^:]fprintf(' -e '[^:]snprintf(' -e '[^:f]puts(' -e '[^:]fputs(' -e '[^:f]putc(' -e '[^:]fputc(' -e '[^:f]getc(' -e '[^:]fgetc('
GrepAllWith -e '[^:_a-z]exit(' -e '[^:.>a-z_]free(' -e '[^:]malloc' -e '[^:]getenv' -e '[^:]strtoull' -e '[^:]strtoul' -e '[^:]strtoll' -e '[^:]strtol' -e '[^:_]atoi'
GrepAllWith -e '[^:]strlen' -e '[^:]strcmp' -e '[^:]strncmp' -e '[^:]strchr' -e '[^:]strrchr' -e '[^:]strerror' -e '[^:]memset'
GrepAllWith -e '[^:]time_t'
GrepAllWith -e '[^:]signal('
GrepAllWith -e '[^:]strerror'

Check '<cassert>' -e 'assert('
Check '<cstddef>' -e '[^_N]NULL\([^P]\|$\)'
Check '<cstdio>' -e fopen -e fclose -e fflush -e '[^A-Z_]FILE[^A-Z_]' -e 'printf(' -e fseek -e 'puts(' -e 'putc('
Check '<cstdlib>' -e '[^_a-z]exit[^_]' -e '[^.>]free[^a-z]' -e malloc -e getenv -e strtol -e EXIT_SUCCESS -e EXIT_FAILURE
Check '<cstring>' -e strlen -e strcmp -e strncmp -e strchr -e strrchr -e strerror -e memset
Check '<csignal>' -e signal -e sigaction
Check '<cerrno>' -e '[^c]errno'
Check '<ctime>' -e time_t
Check '<cstdio>' -e std::fopen -e std::fclose -e std::fflush -e std::fseek -e fseeko -e std::ftell -e ftello -e std::fread -e std::fwrite -e std::printf -e std::fprintf -e std::snprintf -e std::puts -e std::fputs -e std::putc -e std::fputc -e std::getc -e std::fgetc -e flock -e fileno -e '[^A-Z_]FILE[^A-Z_]'
Check '<cstdlib>' -e std::exit -e std::free -e std::malloc -e std::getenv -e std::strtoull -e std::strtoul -e std::strtoll -e std::strtol -e std::atoi -e EXIT_SUCCESS -e EXIT_FAILURE -e mkstemp
Check '<cstring>' -e std::strlen -e std::strcmp -e std::strncmp -e strcasecmp -e strncasecmp -e std::strchr -e std::strrchr -e std::strerror -e std::memset
Check '<csignal>' -e std::signal -e sigaction
Check '<cerrno>' -e '[^c]errno' -e std::strerror
Check '<ctime>' -e std::time_t
Check '<fcntl\.h>' -e '[^a-z_.]open(' -e '[^a-z_.]close(' -e '[^a-z_.]open (' -e '[^a-z_.]close ('
Check '<unistd\.h>' -e '[^a-z]_exit' -e '[^a-z]exec[lv]' -e setuid -e getuid -e chown -e '[^a-z_.]close(' -e isatty
Check '<sys/types\.h>' -e uid_t -e gid_t -e "size_t[^y]" -e off_t
Check '<sys/stat\.h>' -e fchown -e fchmod -e 'stat[^a-z]'
Check '<sys/mman\.h>' -e mmap


2 changes: 1 addition & 1 deletion po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ src/eixTk/compare.cc
src/eixTk/compare.h
src/eixTk/diagnostics.h
src/eixTk/dialect.h
src/eixTk/eixarray.h
src/eixTk/eixint.h
src/eixTk/filenames.cc
src/eixTk/filenames.h
Expand Down Expand Up @@ -91,7 +92,6 @@ src/eixTk/stringutils.cc
src/eixTk/stringutils.h
src/eixTk/sysutils.cc
src/eixTk/sysutils.h
src/eixTk/unused.h
src/eixTk/utils.cc
src/eixTk/utils.h
src/eixTk/varsreader.cc
Expand Down
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ eixTk/ptr_iterator.h \
eixTk/regexp.cc \
eixTk/regexp.h \
$(sysutils_src) \
eixTk/unused.h \
$(varsreader_src)

nodist_eixtk_src =
Expand Down
4 changes: 2 additions & 2 deletions src/cache/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ void BasicCache::env_add_package(WordMap *env, const Package& package, const Ver

// Set default variables

const char *envptr(getenv("PATH"));
const char *envptr(std::getenv("PATH"));
if(likely(envptr != NULLPTR)) {
(*env)["PATH"] = envptr;
}
envptr = getenv("ROOT");
envptr = std::getenv("ROOT");
if(unlikely(envptr != NULLPTR)) {
(*env)["ROOT"] = envptr;
eroot = envptr + m_prefix;
Expand Down
29 changes: 7 additions & 22 deletions src/cache/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "eixTk/null.h"
#include "eixTk/stringtypes.h"
#include "eixTk/sysutils.h"
#include "eixTk/unused.h"
#include "portage/extendedversion.h"

class Category;
Expand Down Expand Up @@ -136,13 +135,10 @@ class BasicCache {
@param category If packagetree is NULLPTR, the packages matching cat_name are added to this category.
@return false if some error caused incomplete read
**/
virtual bool readCategories(ATTRIBUTE_UNUSED PackageTree *packagetree, ATTRIBUTE_UNUSED const char *cat_name, ATTRIBUTE_UNUSED Category *category) {
UNUSED(packagetree);
UNUSED(cat_name);
UNUSED(category);
return 1;
virtual bool readCategories(PackageTree * /* packagetree */, const char * /* cat_name */, Category * /* category */) {
return true;
}
bool readCategories(ATTRIBUTE_UNUSED PackageTree *packagetree) {
bool readCategories(PackageTree *packagetree) {
return readCategories(packagetree, NULLPTR, NULLPTR);
}

Expand Down Expand Up @@ -177,29 +173,18 @@ class BasicCache {
m_catname.clear();
}

ATTRIBUTE_NONNULL_ virtual bool get_time(ATTRIBUTE_UNUSED time_t *t, ATTRIBUTE_UNUSED const std::string &pkg_name, ATTRIBUTE_UNUSED const std::string &ver_name) const {
UNUSED(t);
UNUSED(pkg_name);
UNUSED(ver_name);
ATTRIBUTE_NONNULL_ virtual bool get_time(std::time_t * /* time */, const std::string & /* pkg_name */, const std::string & /* ver_name */) const {
return 0;
}

ATTRIBUTE_NONNULL_ virtual const char *get_md5sum(ATTRIBUTE_UNUSED const std::string &pkg_name, ATTRIBUTE_UNUSED const std::string &ver_name) const {
UNUSED(pkg_name);
UNUSED(ver_name);
ATTRIBUTE_NONNULL_ virtual const char *get_md5sum(const std::string & /* pkg_name */, const std::string & /* ver_name */) const {
return NULLPTR;
}

ATTRIBUTE_NONNULL_ virtual void get_version_info(ATTRIBUTE_UNUSED const std::string &pkg_name, ATTRIBUTE_UNUSED const std::string &ver_name, ATTRIBUTE_UNUSED Version *version) const {
UNUSED(pkg_name);
UNUSED(ver_name);
UNUSED(version);
ATTRIBUTE_NONNULL_ virtual void get_version_info(const std::string & /* pkg_name */, const std::string & /* ver_name */, Version * /* version */) const {
}

ATTRIBUTE_NONNULL_ virtual void get_common_info(ATTRIBUTE_UNUSED const std::string &pkg_name, ATTRIBUTE_UNUSED const std::string &ver_name, ATTRIBUTE_UNUSED Package *pkg) const {
UNUSED(pkg_name);
UNUSED(ver_name);
UNUSED(pkg);
ATTRIBUTE_NONNULL_ virtual void get_common_info(const std::string & /* pkg_name */, const std::string & /* ver_name */, Package * /* pkg */) const {
}

protected:
Expand Down
8 changes: 4 additions & 4 deletions src/cache/common/assign_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ const char *AssignReader::get_md5sum(const string &filename) {
return md5->second.c_str();
}

bool AssignReader::get_mtime(time_t *t, const string &filename) {
bool AssignReader::get_mtime(std::time_t *t, const string &filename) {
if(unlikely(!get_map(filename))) {
return false;
}
WordMap::const_iterator mt(cf->find("_mtime_"));
if(mt == cf->end()) {
return false;
}
return likely(((*t) = my_atois(mt->second.c_str())) != 0);
return likely(((*t) = my_atos(mt->second.c_str())) != 0);
}

/**
Expand All @@ -92,7 +92,7 @@ void AssignReader::get_keywords_slot_iuse_restrict(const string& filename, strin
string *props, Depend *dep) {
if(unlikely(!get_map(filename))) {
m_cache->m_error_callback(eix::format(_("cannot read cache file %s: %s"))
% filename % strerror(errno));
% filename % std::strerror(errno));
return;
}
(*eapi) = (*cf)["EAPI"];
Expand All @@ -115,7 +115,7 @@ Read an "assign type" cache file
void AssignReader::read_file(const string& filename, Package *pkg) {
if(unlikely(!get_map(filename))) {
m_cache->m_error_callback(eix::format(_("cannot read cache file %s: %s"))
% filename % strerror(errno));
% filename % std::strerror(errno));
return;
}
pkg->homepage = (*cf)["HOMEPAGE"];
Expand Down
2 changes: 1 addition & 1 deletion src/cache/common/assign_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AssignReader : public BasicReader {
}

ATTRIBUTE_NONNULL_ const char *get_md5sum(const std::string &filename) OVERRIDE;
ATTRIBUTE_NONNULL_ bool get_mtime(time_t *t, const std::string &filename) OVERRIDE;
ATTRIBUTE_NONNULL_ bool get_mtime(std::time_t *t, const std::string &filename) OVERRIDE;
ATTRIBUTE_NONNULL_ void get_keywords_slot_iuse_restrict(const std::string& filename, std::string *eapi, std::string *keywords, std::string *slotname, std::string *iuse, std::string *required_use, std::string *restr, std::string *props, Depend *dep) OVERRIDE;
ATTRIBUTE_NONNULL_ void read_file(const std::string& filename, Package *pkg) OVERRIDE;

Expand Down
35 changes: 19 additions & 16 deletions src/cache/common/ebuild_exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,19 @@ GCC_DIAG_OFF(old-style-cast)
sigaction(SIGTERM, &m_handler, NULLPTR);
#else
// ifndef HAVE_SIGACTION
handleHUP = signal(SIGHUP, SIG_IGN);
handleINT = signal(SIGINT, SIG_IGN);
handleTERM = signal(SIGTERM, SIG_IGN);
handleHUP = std::signal(SIGHUP, SIG_IGN);
handleINT = std::signal(SIGINT, SIG_IGN);
handleTERM = std::signal(SIGTERM, SIG_IGN);
have_set_signals = true;
if(handleHUP != SIG_IGN)
signal(SIGHUP, ebuild_sig_handler);
if(handleINT != SIG_IGN)
signal(SIGINT, ebuild_sig_handler);
if(handleTERM != SIG_IGN)
signal(SIGTERM, ebuild_sig_handler);
if(handleHUP != SIG_IGN) {
std::signal(SIGHUP, ebuild_sig_handler);
}
if(handleINT != SIG_IGN) {
std::signal(SIGINT, ebuild_sig_handler);
}
if(handleTERM != SIG_IGN) {
std::signal(SIGTERM, ebuild_sig_handler);
}
#endif
GCC_DIAG_ON(old-style-cast)
}
Expand All @@ -128,9 +131,9 @@ void EbuildExec::remove_handler() {
sigaction(SIGINT, &handleHUP, NULLPTR);
sigaction(SIGTERM, &handleTERM, NULLPTR);
#else
signal(SIGHUP, handleHUP);
signal(SIGINT, handleINT);
signal(SIGTERM, handleTERM);
std::signal(SIGHUP, handleHUP);
std::signal(SIGINT, handleINT);
std::signal(SIGTERM, handleTERM);
#endif
have_set_signals = false;
}
Expand All @@ -141,10 +144,10 @@ bool EbuildExec::make_tempfile() {
string::size_type l(tmpdir.size());
char *temp = new char[256 + l];
if(l == 0) {
strcpy(temp, "/tmp/ebuild-cache.XXXXXXXX"); // NOLINT(runtime/printf)
std::strcpy(temp, "/tmp/ebuild-cache.XXXXXXXX"); // NOLINT(runtime/printf)
} else {
strcpy(temp, tmpdir.c_str()); // NOLINT(runtime/printf)
strcpy(temp + l, "/ebuild-cache.XXXXXXXX"); // NOLINT(runtime/printf)
std::strcpy(temp, tmpdir.c_str()); // NOLINT(runtime/printf)
std::strcpy(temp + l, "/ebuild-cache.XXXXXXXX"); // NOLINT(runtime/printf)
}
int fd(mkstemp(temp));
if(fd == -1) {
Expand Down Expand Up @@ -195,7 +198,7 @@ void EbuildExec::calc_environment(const char *name, const string& dir, const Pac
#ifndef HAVE_SETENV
if(!use_ebuild_sh) {
for(char **e(environ); likely(*e != NULLPTR); ++e) {
const char *s(strchr(*e, '='));
const char *s(std::strchr(*e, '='));
if(likely(s != NULLPTR)) {
env[string(*e, s - (*e))] = s + 1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cache/common/flat_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool FlatReader::skip_lines(const eix::TinyUnsigned nr, ifstream *is, const stri
is->ignore(std::numeric_limits<int>::max(), '\n');
if(is->fail()) {
m_cache->m_error_callback(eix::format(_("cannot read cache file %s: %s"))
% filename % strerror(errno));
% filename % std::strerror(errno));
return false;
}
}
Expand All @@ -49,7 +49,7 @@ void FlatReader::get_keywords_slot_iuse_restrict(const string& filename, string
ifstream is(filename.c_str());
if(!is.is_open()) {
m_cache->m_error_callback(eix::format(_("cannot open %s: %s"))
% filename % strerror(errno));
% filename % std::strerror(errno));
}
string depend, rdepend, pdepend;
bool use_dep(Depend::use_depend);
Expand Down Expand Up @@ -97,7 +97,7 @@ void FlatReader::read_file(const string& filename, Package *pkg) {
ifstream is(filename.c_str());
if(!is.is_open()) {
m_cache->m_error_callback(eix::format(_("cannot open %s: %s"))
% filename % strerror(errno));
% filename % std::strerror(errno));
}
skip_lines(5, &is, filename);
string linebuf;
Expand Down
Loading

0 comments on commit 197d544

Please sign in to comment.