New upstream version 19.0.3+dfsg1

This commit is contained in:
Sebastian Ramacher 2017-06-29 21:01:10 +02:00
parent 3708b8e092
commit 1f1bbb3518
534 changed files with 13862 additions and 2459 deletions

View file

@ -49,13 +49,13 @@ enum {
* Use if a problem occurs that doesn't affect the program and is
* recoverable.
*
* Use in places where where failure isn't entirely unexpected, and can
* Use in places where failure isn't entirely unexpected, and can
* be handled safely.
*/
LOG_WARNING = 200,
/**
* Informative essage to be displayed in the log.
* Informative message to be displayed in the log.
*/
LOG_INFO = 300,

View file

@ -39,7 +39,7 @@
* incredibly inept moron could possibly be managing the visual C compiler
* project. They should be fired, and legally forbidden to have a job in
* ANYTHING even REMOTELY related to programming. FOREVER. This should also
* apply to the next 10 generations all of their descendents. */
* apply to the next 10 generations all of their descendants. */
#ifndef __cplusplus
#define inline __inline
#endif

View file

@ -123,6 +123,7 @@ static bool cf_is_token_break(struct base_token *start_token,
start_token->type = BASETOKEN_DIGIT;
break;
}
/* Falls through. */
case BASETOKEN_NONE:
return true;

View file

@ -162,7 +162,7 @@ static inline void cf_def_free(struct cf_def *cfd)
* + option to exclude features such as #import, variadic macros, and other
* features for certain language implementations
* + macro parameter string operator #
* + macro parameter token concactenation operator ##
* + macro parameter token concatenation operator ##
* + predefined macros
* + restricted macros
*/

View file

@ -445,14 +445,10 @@ int config_save_safe(config_t *config, const char *temp_ext,
if (*backup_ext != '.')
dstr_cat(&backup_file, ".");
dstr_cat(&backup_file, backup_ext);
os_unlink(backup_file.array);
os_rename(file, backup_file.array);
} else {
os_unlink(file);
}
os_rename(temp_file.array, file);
if (os_safe_replace(file, temp_file.array, backup_file.array) != 0)
ret = CONFIG_ERROR;
cleanup:
pthread_mutex_unlock(&config->mutex);

View file

@ -88,7 +88,7 @@ EXPORT bool config_remove_value(config_t *config, const char *section,
* These do *not* actually set any values, they only set what values will be
* returned for config_get_* if the specified variable does not exist.
*
* You can initialize the defaults programmitically using config_set_default_*
* You can initialize the defaults programmatically using config_set_default_*
* functions (recommended for most cases), or you can initialize it via a file
* with config_open_defaults.
*/

View file

@ -33,7 +33,7 @@ extern "C" {
* NOTE: Not type-safe when using directly.
* Specifying size per call with inline maximizes compiler optimizations
*
* See DARRAY macro at the bottom of thhe file for slightly safer usage.
* See DARRAY macro at the bottom of the file for slightly safer usage.
*/
#define DARRAY_INVALID ((size_t)-1)
@ -438,7 +438,7 @@ static inline void darray_swap(const size_t element_size,
* Makes it a little easier to use as well.
*
* I did -not- want to use a gigantic macro to generate a crapload of
* typsafe inline functions per type. It just feels like a mess to me.
* typesafe inline functions per type. It just feels like a mess to me.
*/
#define DARRAY(type) \

View file

@ -197,6 +197,11 @@ wchar_t *wstrstri(const wchar_t *str, const wchar_t *find)
return NULL;
}
static inline bool is_padding(char ch)
{
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r';
}
char *strdepad(char *str)
{
char *temp;
@ -210,7 +215,7 @@ char *strdepad(char *str)
temp = str;
/* remove preceding spaces/tabs */
while (*temp == ' ' || *temp == '\t')
while (is_padding(*temp))
++temp;
len = strlen(str);
@ -219,7 +224,7 @@ char *strdepad(char *str)
if (len) {
temp = str + (len-1);
while (*temp == ' ' || *temp == '\t')
while (is_padding(*temp))
*(temp--) = 0;
}

View file

@ -22,6 +22,8 @@
#include <dlfcn.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <CoreServices/CoreServices.h>
#include <mach/mach.h>
@ -312,3 +314,41 @@ void os_inhibit_sleep_destroy(os_inhibit_t *info)
bfree(info);
}
}
static int physical_cores = 0;
static int logical_cores = 0;
static bool core_count_initialized = false;
static void os_get_cores_internal(void)
{
if (core_count_initialized)
return;
core_count_initialized = true;
size_t size;
int ret;
size = sizeof(physical_cores);
ret = sysctlbyname("machdep.cpu.core_count", &physical_cores,
&size, NULL, 0);
if (ret != 0)
return;
ret = sysctlbyname("machdep.cpu.thread_count", &logical_cores,
&size, NULL, 0);
}
int os_get_physical_cores(void)
{
if (!core_count_initialized)
os_get_cores_internal();
return physical_cores;
}
int os_get_logical_cores(void)
{
if (!core_count_initialized)
os_get_cores_internal();
return logical_cores;
}

View file

@ -432,6 +432,13 @@ int os_rename(const char *old_path, const char *new_path)
return rename(old_path, new_path);
}
int os_safe_replace(const char *target, const char *from, const char *backup)
{
if (backup && os_file_exists(target) && rename(target, backup) != 0)
return -1;
return rename(from, target);
}
#if !defined(__APPLE__)
os_performance_token_t *os_request_high_performance(const char *reason)
{
@ -615,3 +622,69 @@ void os_breakpoint()
{
raise(SIGTRAP);
}
#ifndef __APPLE__
static int physical_cores = 0;
static int logical_cores = 0;
static bool core_count_initialized = false;
/* return sysconf(_SC_NPROCESSORS_ONLN); */
static void os_get_cores_internal(void)
{
if (core_count_initialized)
return;
core_count_initialized = true;
logical_cores = sysconf(_SC_NPROCESSORS_ONLN);
#ifndef __linux__
physical_cores = logical_cores;
#else
char *text = os_quick_read_utf8_file("/proc/cpuinfo");
char *core_id = text;
if (!text || !*text) {
physical_cores = logical_cores;
return;
}
for (;;) {
core_id = strstr(core_id, "\ncore id");
if (!core_id)
break;
physical_cores++;
core_id++;
}
if (physical_cores == 0)
physical_cores = logical_cores;
bfree(text);
#endif
}
int os_get_physical_cores(void)
{
if (!core_count_initialized)
os_get_cores_internal();
return physical_cores;
}
int os_get_logical_cores(void)
{
if (!core_count_initialized)
os_get_cores_internal();
return logical_cores;
}
#endif
uint64_t os_get_free_disk_space(const char *dir)
{
struct statvfs info;
if (statvfs(dir, &info) != 0)
return 0;
return (uint64_t)info.f_frsize * (uint64_t)info.f_bavail;
}

View file

@ -549,7 +549,8 @@ int os_rename(const char *old_path, const char *new_path)
goto error;
}
code = MoveFileW(old_path_utf16, new_path_utf16) ? 0 : -1;
code = MoveFileExW(old_path_utf16, new_path_utf16,
MOVEFILE_REPLACE_EXISTING) ? 0 : -1;
error:
bfree(old_path_utf16);
@ -557,6 +558,36 @@ error:
return code;
}
int os_safe_replace(const char *target, const char *from, const char *backup)
{
wchar_t *wtarget = NULL;
wchar_t *wfrom = NULL;
wchar_t *wbackup = NULL;
int code = -1;
if (!target || !from)
return -1;
if (!os_utf8_to_wcs_ptr(target, 0, &wtarget))
return -1;
if (!os_utf8_to_wcs_ptr(from, 0, &wfrom))
goto fail;
if (backup && !os_utf8_to_wcs_ptr(backup, 0, &wbackup))
goto fail;
if (ReplaceFileW(wtarget, wfrom, wbackup, 0, NULL, NULL)) {
code = 0;
} else if (GetLastError() == ERROR_FILE_NOT_FOUND) {
code = MoveFileExW(wfrom, wtarget, MOVEFILE_REPLACE_EXISTING)
? 0 : -1;
}
fail:
bfree(wtarget);
bfree(wfrom);
bfree(wbackup);
return code;
}
BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
{
switch (reason) {
@ -848,3 +879,83 @@ void os_breakpoint(void)
{
__debugbreak();
}
DWORD num_logical_cores(ULONG_PTR mask)
{
DWORD left_shift = sizeof(ULONG_PTR) * 8 - 1;
DWORD bit_set_count = 0;
ULONG_PTR bit_test = (ULONG_PTR)1 << left_shift;
for (DWORD i = 0; i <= left_shift; ++i) {
bit_set_count += ((mask & bit_test) ? 1 : 0);
bit_test /= 2;
}
return bit_set_count;
}
static int physical_cores = 0;
static int logical_cores = 0;
static bool core_count_initialized = false;
static void os_get_cores_internal(void)
{
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION info = NULL, temp = NULL;
DWORD len = 0;
if (core_count_initialized)
return;
core_count_initialized = true;
GetLogicalProcessorInformation(info, &len);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return;
info = malloc(len);
if (GetLogicalProcessorInformation(info, &len)) {
DWORD num = len / sizeof(*info);
temp = info;
for (DWORD i = 0; i < num; i++) {
if (temp->Relationship == RelationProcessorCore) {
ULONG_PTR mask = temp->ProcessorMask;
physical_cores++;
logical_cores += num_logical_cores(mask);
}
temp++;
}
}
free(info);
}
int os_get_physical_cores(void)
{
if (!core_count_initialized)
os_get_cores_internal();
return physical_cores;
}
int os_get_logical_cores(void)
{
if (!core_count_initialized)
os_get_cores_internal();
return logical_cores;
}
uint64_t os_get_free_disk_space(const char *dir)
{
wchar_t *wdir = NULL;
if (!os_utf8_to_wcs_ptr(dir, 0, &wdir))
return 0;
ULARGE_INTEGER free;
bool success = !!GetDiskFreeSpaceExW(wdir, &free, NULL, NULL);
bfree(wdir);
return success ? free.QuadPart : 0;
}

View file

@ -248,6 +248,7 @@ bool os_quick_write_mbs_file(const char *path, const char *str, size_t len)
if (mbs_len)
fwrite(mbs, 1, mbs_len, f);
bfree(mbs);
fflush(f);
fclose(f);
return true;
@ -264,6 +265,7 @@ bool os_quick_write_utf8_file(const char *path, const char *str, size_t len,
fwrite("\xEF\xBB\xBF", 1, 3, f);
if (len)
fwrite(str, 1, len, f);
fflush(f);
fclose(f);
return true;
@ -297,17 +299,10 @@ bool os_quick_write_utf8_file_safe(const char *path, const char *str,
if (*backup_ext != '.')
dstr_cat(&backup_path, ".");
dstr_cat(&backup_path, backup_ext);
os_unlink(backup_path.array);
os_rename(path, backup_path.array);
dstr_free(&backup_path);
} else {
os_unlink(path);
}
os_rename(temp_path.array, path);
success = true;
if (os_safe_replace(path, temp_path.array, backup_path.array) == 0)
success = true;
cleanup:
dstr_free(&backup_path);

View file

@ -153,6 +153,8 @@ EXPORT int os_rmdir(const char *path);
EXPORT char *os_getcwd(char *path, size_t size);
EXPORT int os_chdir(const char *path);
EXPORT uint64_t os_get_free_disk_space(const char *dir);
#define MKDIR_EXISTS 1
#define MKDIR_SUCCESS 0
#define MKDIR_ERROR -1
@ -161,6 +163,8 @@ EXPORT int os_mkdir(const char *path);
EXPORT int os_mkdirs(const char *path);
EXPORT int os_rename(const char *old_path, const char *new_path);
EXPORT int os_copyfile(const char *file_in, const char *file_out);
EXPORT int os_safe_replace(const char *target_path, const char *from_path,
const char *backup_path);
EXPORT char *os_generate_formatted_filename(const char *extension, bool space,
const char *format);
@ -174,6 +178,9 @@ EXPORT void os_inhibit_sleep_destroy(os_inhibit_t *info);
EXPORT void os_breakpoint(void);
EXPORT int os_get_physical_cores(void);
EXPORT int os_get_logical_cores(void);
#ifdef _MSC_VER
#define strtoll _strtoi64
#if _MSC_VER < 1900

View file

@ -19,7 +19,7 @@
/*
* Text Lookup interface
*
* Used for storing and looking up localized strings. Stores locazation
* Used for storing and looking up localized strings. Stores localization
* strings in a radix/trie tree to efficiently look up associated strings via a
* unique string identifier name.
*/
@ -30,7 +30,7 @@
extern "C" {
#endif
/* opaque typdef */
/* opaque typedef */
struct text_lookup;
typedef struct text_lookup lookup_t;

View file

@ -362,7 +362,7 @@ size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out,
/*
* NOTE: do not check here for forbidden UTF-8 characters.
* They cannot appear here because we do proper convertion.
* They cannot appear here because we do proper conversion.
*/
p += n;

View file

@ -46,6 +46,8 @@ public:
inline bool operator!() {return ptr == NULL;}
inline bool operator==(T p) {return ptr == p;}
inline bool operator!=(T p) {return ptr != p;}
inline T *Get() const {return ptr;}
};
class ConfigFile {

View file

@ -172,7 +172,7 @@ typedef unsigned __int64 uintmax_t;
/* 7.18.4.1 Macros for minimum-width integer constants
Accoding to Douglas Gwyn <gwyn@arl.mil>:
According to Douglas Gwyn <gwyn@arl.mil>:
"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
9899:1999 as initially published, the expansion was required
to be an integer constant of precisely matching type, which