Skip to content

Commit

Permalink
code cleanup : suppress majority of superfluous static and inline
Browse files Browse the repository at this point in the history
  • Loading branch information
cesar-douady committed Mar 28, 2024
1 parent aad3d51 commit 932dea9
Show file tree
Hide file tree
Showing 45 changed files with 426 additions and 422 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ endif
endif

ifneq ($(USE_CLANG),)
WARNING_FLAGS += -Wno-misleading-indentation -Wno-unknown-warning-option -Wno-c2x-extensions -Wno-unused-function -Wno-c++2b-extensions
WARNING_FLAGS += -Wno-misleading-indentation -Wno-unknown-warning-option -Wno-c2x-extensions -Wno-c++2b-extensions
endif

# this is the recommanded way to insert a , when calling functions
Expand Down
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ it has been tested with the dockers listed in the docker directory
- the relative positions of these 4 dirs must remain the same, i.e. they must stay in the same directory with the same names.
- specialization
- you can specialize the build process to better suit your needs :
- this can be done by setting variables on the command line
- for example, you can run : make CC=/my/gcc
- PYTHON can be set to your preferred python. You will be told if it is not supported.
- this can be done by setting variables on the command line or in the environment
- for example, you can run : make CC=/my/gcc or CC=/my/gcc make
- PYTHON2 can be set to your preferred Python 2 (defaults to python2). You will be told if it is not supported.
- PYTHON can be set to your preferred Python 3 (defaults to python3). You will be told if it is not supported.
- CC can be set to your preferred compiler. You will be told if it is not supported.
- LMAKE_OPT_LVL can be defined between 0 and 5 inclusive :
- -O compiler option is given the provided value, up to 3
- if 0, the -g flag is also provided
- if 4 or above, -DNDEBUG is defined. There are *a lot* of assertions throughout the code, so it makes sens to run with -DNDEBUG.
furthermore, a few essential assertions are left active, even with -DNDEBUG
- if 5, no trace is generated
- LMAKE_OP can be defined as [0123][gG][dD][tT] (default is 3GDT)
- [0123] controls the -O option.
- [gG] controls the -g option : G passes it to enable debug, g does not.
- [dD] controls -DNDEBUG : D passes it to enable asserts, d does not.
- [tT] controls -DNO_TRACE : T does not pass it to enable traces, t passes it.
- the -j flag of make is automatically set to the number of processors, you may want to override this, though
- it is up to you to provide a suitable LD_LIBRARY_PATH value.
it will be transferred as a default value for rules, to the extent it is necessary to provide lmake semantic (mostly this means we keep what is necessary to run python)
- if you modify these variables, you should execute git clean as make will not detect this modification automatically
it will be transferred as a default value for rules, to the extent it is necessary to provide lmake semantic (mostly this means we keep what is necessary to run python).
- if you modify these variables, you should execute git clean as make will not detect such modifications automatically.

# coding rules

Expand Down Expand Up @@ -125,18 +125,17 @@ Names are suffixed with \_ if needed to suppress ambiguities
- words include standard name such as syscall names or libc functions
- special cases :
<table>
<tr> <th> abbrev </th> <th> full-name </tdh </tr>
<tr> <td> ddate </td> <td> disk date </td> </tr>
<tr> <td> dflag </td> <td> dependency flag </td> </tr>
<tr> <td> filename </td> <td> file name </td> </tr>
<tr> <td> lnk </td> <td> symbolic link </td> </tr>
<tr> <td> ongoing </td> <td> on going </td> </tr>
<tr> <td> pdate </td> <td> process date </td> </tr>
<tr> <td> regexpr </td> <td> regular expression </td> </tr>
<tr> <td> serdes </td> <td> serialize, deserialize </td> </tr>
<tr> <td> tflag </td> <td> target flag </td> </tr>
<tr> <td> wakeup </td> <td> wake_up </td> </tr>
<tr> <td> wrt </td> <td> with respect to </td> </tr>
<tr> <th> abbrev </th> <th> full-name </tdh </tr>
<tr> <td> ddate </td> <td> disk date </td> </tr>
<tr> <td> dflag </td> <td> dependency flag </td> </tr>
<tr> <td> filename </td> <td> file name </td> </tr>
<tr> <td> lnk </td> <td> symbolic link </td> </tr>
<tr> <td> ongoing </td> <td> on going </td> </tr>
<tr> <td> pdate </td> <td> process date </td> </tr>
<tr> <td> regexpr </td> <td> regular expression </td> </tr>
<tr> <td> serdes </td> <td> serialize, deserialize </td> </tr>
<tr> <td> tflag </td> <td> target flag </td> </tr>
<tr> <td> wrt </td> <td> with respect to </td> </tr>
</table>

## layout
Expand Down
6 changes: 4 additions & 2 deletions TO_DO
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ items :

* missing some deps when reading elf
- it seems that libc.so is missing at least in some occasions
* ld_audit does not seem to correctly bind symbols with ldopen on Ubuntu20
* reimplement hierarchical repositories
- add a sub_repositories entry to config
- map priorities to RuleIdx
Expand All @@ -28,7 +27,6 @@ items :
* LACK (not implemented but necessary for lmake semantic)
****************************************************************************************************

* rework side_targets versus side_deps
* improve lshow -i
- generate info on nodes
* use Pdate (end of job) rather than Ddate (target date) to detect clash
Expand Down Expand Up @@ -74,6 +72,10 @@ items :
* ROBUSTNESS & MAINTENABILITY (fragile/difficult to read or maintain as long as not implemented)
****************************************************************************************************

* support 64-bits id
- configure with NBits rather than types
- in store/file.hh, reserve address space after NBits instead of type
- first candidate would be deps, by far the most demanding
* add a warning when ids reach 15/16 of their limits
* implement noexcept/except everywhere pertinent
* use the Path struct instead of at/file
Expand Down
4 changes: 4 additions & 0 deletions _lib/lmake/rules.src.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class _PyRule(Rule) :
mask_python_deps = False
def cmd() : # this will be executed before cmd() of concrete subclasses as cmd() are chained in case of inheritance
if gen_module_deps or mask_python_deps : # fast path :if nothing to do, do nothing
try : import lmake
except ModuleNotFoundError :
import sys
sys.path[0:0] = (_lmake_dir+'/lib',)
from lmake.import_machinery import fix_import
fix_import(gen_module_deps=gen_module_deps,mask_python_deps=mask_python_deps)
cmd.shell = '' # support shell cmd's that may launch python as a subprocess XXX : manage to execute fix_import()
Expand Down
4 changes: 2 additions & 2 deletions src/app.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extern ::string* g_lmake_dir ; // pointer to avoid init/fini order hazards,
extern ::string* g_root_dir ; // pointer to avoid init/fini order hazards, absolute , root of repository
extern ::string* g_exe_name ; // pointer to avoid init/fini order hazards, absolute , executable name for user messages

/**/ void app_init( Bool3 chk_version_=Yes , bool cd_root=true ) ; // if chk_version_==Maybe, it is ok to initialize stored version
static inline void app_init( bool cd_root ) { app_init(Yes,cd_root) ; }
/**/ void app_init( Bool3 chk_version_=Yes , bool cd_root=true ) ; // if chk_version_==Maybe, it is ok to initialize stored version
inline void app_init( bool cd_root ) { app_init(Yes,cd_root) ; }

void chk_version( bool may_init=false , ::string const& admin_dir=AdminDir ) ;

Expand Down
10 changes: 5 additions & 5 deletions src/autodep/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ using namespace Disk ;
::ostream& operator<<( ::ostream& os , AutodepEnv const& ade ) {
os << "AutodepEnv(" ;
if (ade.active) {
/**/ os << static_cast<RealPathEnv const&>(ade) ;
/**/ os <<','<< ade.service ;
if ( ade.auto_mkdir ) os <<",auto_mkdir" ;
if ( ade.ignore_stat) os <<",ignore_stat" ;
if (!ade.disabled ) os <<",disabled" ;
/**/ os << static_cast<RealPathEnv const&>(ade) ;
/**/ os <<','<< ade.service ;
if (ade.auto_mkdir ) os <<",auto_mkdir" ;
if (ade.ignore_stat) os <<",ignore_stat" ;
if (ade.disabled ) os <<",disabled" ;
}
return os <<')' ;
}
Expand Down
3 changes: 1 addition & 2 deletions src/autodep/gather.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,5 @@ void Gather::reorder(bool at_end) {
i_dst++ ;
}
accesses.resize(i_dst) ;
if (at_end) access_map.clear() ; // safer not to leave outdated info
else for( NodeIdx i=0 ; i<accesses.size() ; i++ ) access_map.at(accesses[i].first) = i ; // always recompute access_map as accesses has been sorted
for( NodeIdx i=0 ; i<accesses.size() ; i++ ) access_map.at(accesses[i].first) = i ; // always recompute access_map as accesses has been sorted
}
4 changes: 2 additions & 2 deletions src/autodep/ld_audit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void load_exec(::string const& /*file*/) {} // the auditing mechanism tells us a
void elf_deps ( Record& /*r*/ , Record::Solve const& , const char* /*ld_library_path*/ , ::string&& /*comment*/="elf_dep" ) { }
Record::Read search_elf( Record& /*r*/ , const char* /*file*/ , ::string&& /*comment*/="elf_srch" ) { return {} ; }

static inline bool started() { return true ; }
static bool started() { return true ; }

#define LD_AUDIT 1
#include "ld_common.x.cc"
Expand Down Expand Up @@ -166,7 +166,7 @@ Qualify :
/**/ return {true ,is_libc} ;
}

template<class Sym> static inline uintptr_t _la_symbind( Sym* sym , unsigned int /*ndx*/ , uintptr_t* /*ref_cook*/ , uintptr_t* def_cook , unsigned int* /*flags*/ , const char* sym_name ) {
template<class Sym> uintptr_t _la_symbind( Sym* sym , unsigned int /*ndx*/ , uintptr_t* /*ref_cook*/ , uintptr_t* def_cook , unsigned int* /*flags*/ , const char* sym_name ) {
//
auditer() ; // force Audit static init
if (g_force_orig) goto Ignore ; // avoid recursion loop
Expand Down
2 changes: 1 addition & 1 deletion src/autodep/ld_preload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// This program is free software: you can redistribute/modify under the terms of the GPL-v3 (https://www.gnu.org/licenses/gpl-3.0.html).
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

static inline bool started() { return true ; }
static bool started() { return true ; }

#include "ld.x.cc"
2 changes: 1 addition & 1 deletion src/autodep/ld_preload_jemalloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// ensure malloc has been initialized (at least at first call to malloc) in case jemalloc is used with ld_preload to avoid malloc_init->open->malloc->malloc_init loop
static bool _g_started = false ;

static inline bool started() { return _g_started ; }
static bool started() { return _g_started ; }

#define LD_PRELOAD_JEMALLOC
#include "ld.x.cc"
Expand Down
2 changes: 1 addition & 1 deletion src/autodep/ld_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
thread_local bool AutodepLock::t_active = false ;
/**/ ::mutex AutodepLock::_s_mutex ;

static inline bool started() { return AutodepLock::t_active ; } // no auto-start for server
static bool started() { return AutodepLock::t_active ; } // no auto-start for server

#define IN_SERVER
#include "ld.x.cc"
6 changes: 3 additions & 3 deletions src/autodep/record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ Record::Mkdir::Mkdir( Record& r , Path&& path , ::string&& c ) : Solve{r,::move(
if (file_loc==FileLoc::Repo) r._report_guard( ::move(real) , ::move(c) ) ;
}

static inline bool _do_stat (int flags) { return flags&O_PATH ; }
static inline bool _do_read (int flags) { return !_do_stat(flags) && (flags&O_ACCMODE)!=O_WRONLY && !(flags&O_TRUNC) ; }
static inline bool _do_write(int flags) { return !_do_stat(flags) && (flags&O_ACCMODE)!=O_RDONLY ; }
static bool _do_stat (int flags) { return flags&O_PATH ; }
static bool _do_read (int flags) { return !_do_stat(flags) && (flags&O_ACCMODE)!=O_WRONLY && !(flags&O_TRUNC) ; }
static bool _do_write(int flags) { return !_do_stat(flags) && (flags&O_ACCMODE)!=O_RDONLY ; }
Record::Open::Open( Record& r , Path&& path , int flags , ::string&& c ) :
Solve{ r , ::move(path) , bool(flags&O_NOFOLLOW) , _do_read(flags) , true/*allow_tmp_map*/ , to_string(c,::hex,'.',flags) }
, do_write{_do_write(flags)}
Expand Down
Loading

0 comments on commit 932dea9

Please sign in to comment.