Skip to content

Commit

Permalink
Merge branch 'htop-dev:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex313031 authored Aug 18, 2024
2 parents d7543d7 + 2503239 commit 3e4317c
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CPUMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static void CPUMeter_init(Meter* this) {

// Custom uiName runtime logic to include the param (processor)
static void CPUMeter_getUiName(const Meter* this, char* buffer, size_t length) {
assert(length > 0);

if (this->param > 0)
xSnprintf(buffer, length, "%s %u", Meter_uiName(this), this->param);
else
Expand Down
10 changes: 8 additions & 2 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,14 @@ static void print_backtrace(void) {
#elif defined(HAVE_EXECINFO_H)
void* backtraceArray[256];

size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray));
backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO);
int nptrs = backtrace(backtraceArray, ARRAYSIZE(backtraceArray));
if (nptrs > 0) {
backtrace_symbols_fd(backtraceArray, nptrs, STDERR_FILENO);
} else {
full_write_str(STDERR_FILENO,
"[No backtrace information available from libc]\n"
);
}
#else
#error No implementation for print_backtrace()!
#endif
Expand Down
14 changes: 9 additions & 5 deletions DynamicMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in the source distribution for its full text.

#include "DynamicMeter.h"

#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
Expand Down Expand Up @@ -97,17 +98,20 @@ static const char* DynamicMeter_getCaption(const Meter* this) {
}

static void DynamicMeter_getUiName(const Meter* this, char* name, size_t length) {
assert(length > 0);

const Settings* settings = this->host->settings;
const DynamicMeter* meter = Hashtable_get(settings->dynamicMeters, this->param);
if (meter) {
const char* uiName = meter->caption;
if (uiName) {
int len = strlen(uiName);
if (len > 2 && uiName[len - 2] == ':')
len -= 2;
xSnprintf(name, length, "%.*s", len, uiName);
size_t uiNameLen = strlen(uiName);
if (uiNameLen > 2 && uiName[uiNameLen - 2] == ':')
uiNameLen -= 2;

String_safeStrncpy(name, uiName, MINIMUM(length, uiNameLen + 1));
} else {
xSnprintf(name, length, "%s", meter->name);
String_safeStrncpy(name, meter->name, length);
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ in the source distribution for its full text.

#include "ListItem.h"
#include "Machine.h"
#include "Macros.h"
#include "MeterMode.h"
#include "Object.h"

Expand Down Expand Up @@ -47,13 +48,13 @@ in the source distribution for its full text.
struct Meter_;
typedef struct Meter_ Meter;

typedef void(*Meter_Init)(Meter*);
typedef void(*Meter_Done)(Meter*);
typedef void(*Meter_UpdateMode)(Meter*, MeterModeId);
typedef void(*Meter_UpdateValues)(Meter*);
typedef void(*Meter_Draw)(Meter*, int, int, int);
typedef const char* (*Meter_GetCaption)(const Meter*);
typedef void(*Meter_GetUiName)(const Meter*, char*, size_t);
typedef ATTR_NONNULL void (*Meter_Init)(Meter*);
typedef ATTR_NONNULL void (*Meter_Done)(Meter*);
typedef ATTR_NONNULL void (*Meter_UpdateMode)(Meter*, MeterModeId);
typedef ATTR_NONNULL void (*Meter_UpdateValues)(Meter*);
typedef ATTR_NONNULL void (*Meter_Draw)(Meter*, int, int, int);
typedef ATTR_NONNULL const char* (*Meter_GetCaption)(const Meter*);
typedef ATTR_NONNULL ATTR_ACCESS3_W(2, 3) void (*Meter_GetUiName)(const Meter*, char*, size_t);

typedef struct MeterClass_ {
const ObjectClass super;
Expand Down
6 changes: 0 additions & 6 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,6 @@ static bool Process_setPriority(Process* this, int priority) {
return (err == 0);
}

bool Process_rowSetPriority(Row* super, int priority) {
Process* this = (Process*) super;
assert(Object_isA((const Object*) this, (const ObjectClass*) &Process_class));
return Process_setPriority(this, priority);
}

bool Process_rowChangePriorityBy(Row* super, Arg delta) {
Process* this = (Process*) super;
assert(Object_isA((const Object*) this, (const ObjectClass*) &Process_class));
Expand Down
2 changes: 0 additions & 2 deletions Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ void Process_init(Process* this, const struct Machine_* host);

const char* Process_rowGetSortKey(Row* super);

bool Process_rowSetPriority(Row* super, int priority);

bool Process_rowChangePriorityBy(Row* super, Arg delta);

bool Process_rowSendSignal(Row* super, Arg sgn);
Expand Down
2 changes: 1 addition & 1 deletion Table.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void Table_add(Table* this, Row* row) {
// removing items.
// Note: for processes should only be called from ProcessTable_iterate to avoid
// breaking dying process highlighting.
void Table_removeIndex(Table* this, const Row* row, int idx) {
static void Table_removeIndex(Table* this, const Row* row, int idx) {
int rowid = row->id;

assert(row == (Row*)Vector_get(this->rows, idx));
Expand Down
3 changes: 1 addition & 2 deletions Table.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ void Table_printHeader(const Settings* settings, RichString* header);

void Table_add(Table* this, struct Row_* row);

void Table_removeIndex(Table* this, const struct Row_* row, int idx);

void Table_updateDisplayList(Table* this);

void Table_expandTree(Table* this);
Expand All @@ -90,6 +88,7 @@ void Table_cleanupRow(Table* this, Row* row, int idx);

static inline void Table_compact(Table* this) {
Vector_compact(this->rows);
this->needsSort = true;
}

#endif
2 changes: 2 additions & 0 deletions XUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ int xAsprintf(char** strp, const char* fmt, ...) {
}

int xSnprintf(char* buf, size_t len, const char* fmt, ...) {
assert(len > 0);

va_list vl;
va_start(vl, fmt);
int n = vsnprintf(buf, len, fmt, vl);
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
AC_COMPILE_IFELSE([
AC_LANG_SOURCE(
[
/* Attribute supported in GCC 4.3 or later */
__attribute__((alloc_size(1))) char* my_alloc(int size) { return 0; }
],[]
)],
Expand All @@ -211,6 +212,7 @@ CFLAGS="$CFLAGS -Wno-error -Werror=attributes"
AC_COMPILE_IFELSE([
AC_LANG_SOURCE(
[
/* Attribute supported in GCC 10 or later */
__attribute__((access(read_only, 1, 2))) extern int foo(const char* str, unsigned len);
],[]
)],
Expand Down
2 changes: 1 addition & 1 deletion freebsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) {
this->curItems = 4;
percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ];
} else {
v[CPU_METER_NORMAL] = cpuData->systemAllPercent;
v[CPU_METER_KERNEL] = cpuData->systemAllPercent;
this->curItems = 3;
percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL];
}
Expand Down

0 comments on commit 3e4317c

Please sign in to comment.