__attribute__((nonnull)) will help catching "calling with NULL" mistake on
compile time.
I also convert xStrdup into a macro, that will do assert() inline when the
code is *not* built with -DNDEBUG . For release builds (with -DNDEBUG),
preprocessor trick will ensure that generated code remains the same.
This effectively reverts "Stricter strdup." 4674b4a732
If str is NULL upon the calling of strdup(), it should crash with SIGSEGV.
Just let it crash. Adding the "if (!str) fail();" code serves nothing but
bloat.
3 effects in this commit, with the first being the main one:
1. Fix the "`missing' script is too old or missing" warning. See:
<https://lists.gnu.org/archive/html/automake/2010-08/msg00108.html>
2. By moving AC_CANONICAL_TARGET down in order, we are now able to
set the directory for auxiliary scripts. For now it's still './'.
I added the line "AC_CONFIG_AUX_DIR([.])" to show that the directory
change is possible.
3. AC_USE_SYSTEM_EXTENSIONS includes checks from AC_PROG_CC, by moving
the former macro down, we can save size in 'configure' by not
generating repeated checks.
AC_HELP_STRING -> AS_HELP_STRING
AC_TRY_COMPILE -> AC_COMPILE_IFELSE([AC_LANG_PROGRAM([...])],...)
AC_CONFIG_HEADER -> AC_CONFIG_HEADERS
AC_PROG_LIBTOOL -> LT_INIT
Note: There might be more deprecated macros that I haven't noticed.
I just wish to avoid painful highlighting from my text editor (gedit)
that complains about them. :)
The (this_) token was not expanded properly, but the bug was not caught
because all uses of this macro specifies (this_)=this .
Also parenthesize macro tokens to prevent further problems.
Rationale (copied from htop issue #471):
The function name "setValues" is misleading. For most OOP (object-
oriented programming) contexts, setXXX functions mean they will change
some member variables of an object into something specified in
function arguments. But in the *Meter_setValues() case, the new values
are not from the arguments, but from a hard-coded source. The caller
is not supposed to change the values[] to anything it likes, but
rather to "update" the values from the source. Hence, updateValues is
a better name for this family of functions.
Removed a loop that sets the bar[] buffer with spaces and merged that
task to the snprintf() call just below. No need for the barOffset
variable. Display behavior is unchanged.
Size comparision (when compiled on Ubuntu 14.04 64-bit):
$ size htop.old htop.new
text data bss dec hex filename
137312 15112 3776 156200 26228 htop.old
137216 15112 3776 156104 261c8 htop.new
Just assume Platform_meterTypes[0] is always &CPUMeter_class for every
platform. This removes a conditional in AvailableMetersPanel_new().
Also adds some comments about the logic here. Without assuming
Platform_meterTypes[0], the (int i=1) clause in this for loop will not
make sense. (I.e. Why not (int i=0)? )
Also replaced a sprintf() call with safer snprintf() in code further
below.
Two changes in this commit:
- All meters now explicitly specify "maxItems" property, even for just
1 item. (Exception is "container" CPU meter classes, which use
CUSTOM_METERMODE.)
- "maxItems" being 0 is now allowed. This will let bar meters and graph
meters render an empty meter.
calloc() allows 'nmemb' or 'size' to be zero, in which case NULL may be
returned. Letting htop die because of either argument being zero doesn't
make sense.
As a side note: As size_t is unsigned, compiler should be able to optimize
conditional (nmemb > 0 && size > 0) to (nmemb && size). This theorically
shouldn't increase code size too much.