mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Copying ede-bug-report from branches in trunk
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#ifndef ASSERTX_HPP_INCLUDED
|
||||
#define ASSERTX_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
|
||||
/* The compiler often warns you if you give a function formal parameter a
|
||||
name, but don't use it. But because assert() disappears when doing an
|
||||
optimized build, the compiler doesn't recognize your reference to the
|
||||
parameter in the assert() argument. To avoid the bogus warning in
|
||||
this case, we have ASSERT_ONLY_ARG(), which declares a name for a
|
||||
formal parameter for purposes of assert() only. In cases where an
|
||||
assert() would disappear, ASSERT_ONLY_ARG() disappears too.
|
||||
|
||||
E.g.
|
||||
|
||||
void foo(int const ASSERT_ONLY_ARG(arg1)) {
|
||||
|
||||
assert(arg1 > 0);
|
||||
}
|
||||
*/
|
||||
#ifdef NDEBUG
|
||||
#define ASSERT_ONLY_ARG(x)
|
||||
#else
|
||||
#define ASSERT_ONLY_ARG(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
/* This takes the place of C99 stdbool.h, which at least some Windows
|
||||
compilers don't have. (October 2005).
|
||||
|
||||
One must not also include <stdbool.h>, because it might cause a name
|
||||
collision.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
/* At least the GNU compiler defines __bool_true_false_are_defined */
|
||||
#ifndef __bool_true_false_are_defined
|
||||
#define __bool_true_false_are_defined
|
||||
typedef enum {
|
||||
false = 0,
|
||||
true = 1
|
||||
} bool;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef C_UTIL_H_INCLUDED
|
||||
#define C_UTIL_H_INCLUDED
|
||||
|
||||
/* C language stuff. Doesn't involve any libraries that aren't part of
|
||||
the compiler.
|
||||
*/
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
/* GNU_PRINTF_ATTR lets the GNU compiler check printf-type
|
||||
calls to be sure the arguments match the format string, thus preventing
|
||||
runtime segmentation faults and incorrect messages.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define GNU_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
|
||||
#else
|
||||
#define GNU_PRINTF_ATTR(a,b)
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef CASPRINTF_H_INCLUDED
|
||||
#define CASPRINTF_H_INCLUDED
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "c_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const char * const strsol;
|
||||
|
||||
void
|
||||
cvasprintf(const char ** const retvalP,
|
||||
const char * const fmt,
|
||||
va_list varargs);
|
||||
|
||||
void GNU_PRINTF_ATTR(2,3)
|
||||
casprintf(const char ** const retvalP, const char * const fmt, ...);
|
||||
|
||||
void
|
||||
strfree(const char * const string);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,86 @@
|
||||
#ifndef CMDLINE_PARSER_H
|
||||
#define CMDLINE_PARSER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if 0
|
||||
} /* to fake out automatic code indenters */
|
||||
#endif
|
||||
|
||||
#include "int.h"
|
||||
|
||||
/*
|
||||
|
||||
NOTE NOTE NOTE: cmd_getOptionValueString() and
|
||||
cmd_getArgument() return malloc'ed memory (and abort the program if
|
||||
out of memory). You must free it.
|
||||
|
||||
*/
|
||||
|
||||
enum optiontype {
|
||||
OPTTYPE_FLAG,
|
||||
OPTTYPE_INT,
|
||||
OPTTYPE_UINT,
|
||||
OPTTYPE_STRING,
|
||||
OPTTYPE_BINUINT,
|
||||
OPTTYPE_FLOAT
|
||||
};
|
||||
|
||||
struct cmdlineParserCtl;
|
||||
|
||||
typedef struct cmdlineParserCtl * cmdlineParser;
|
||||
|
||||
void
|
||||
cmd_processOptions(cmdlineParser const cpP,
|
||||
int const argc,
|
||||
const char ** const argv,
|
||||
const char ** const errorP);
|
||||
|
||||
cmdlineParser
|
||||
cmd_createOptionParser(void);
|
||||
|
||||
void
|
||||
cmd_destroyOptionParser(cmdlineParser const cpP);
|
||||
|
||||
void
|
||||
cmd_defineOption(cmdlineParser const cpP,
|
||||
const char * const name,
|
||||
enum optiontype const type);
|
||||
|
||||
int
|
||||
cmd_optionIsPresent(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
int
|
||||
cmd_getOptionValueInt(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
unsigned int
|
||||
cmd_getOptionValueUint(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
const char *
|
||||
cmd_getOptionValueString(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
uint64_t
|
||||
cmd_getOptionValueBinUint(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
double
|
||||
cmd_getOptionValueFloat(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
unsigned int
|
||||
cmd_argumentCount(cmdlineParser const cpP);
|
||||
|
||||
const char *
|
||||
cmd_getArgument(cmdlineParser const cpP,
|
||||
unsigned int const argNumber);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,59 @@
|
||||
#ifndef CMDLINE_PARSER_HPP_INCLUDED
|
||||
#define CMDLINE_PARSER_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
struct cmdlineParserCtl;
|
||||
|
||||
class CmdlineParser {
|
||||
public:
|
||||
CmdlineParser();
|
||||
|
||||
~CmdlineParser();
|
||||
|
||||
enum optType {FLAG, INT, UINT, STRING, BINUINT, FLOAT};
|
||||
|
||||
void
|
||||
defineOption(std::string const optionName,
|
||||
optType const optionType);
|
||||
|
||||
void
|
||||
processOptions(int const argc,
|
||||
const char ** const argv);
|
||||
|
||||
bool
|
||||
optionIsPresent(std::string const optionName) const;
|
||||
|
||||
int
|
||||
getOptionValueInt(std::string const optionName) const;
|
||||
|
||||
unsigned int
|
||||
getOptionValueUint(std::string const optionName) const;
|
||||
|
||||
std::string
|
||||
getOptionValueString(std::string const optionName) const;
|
||||
|
||||
unsigned long long
|
||||
getOptionValueBinUint(std::string const optionName) const;
|
||||
|
||||
double
|
||||
getOptionValueFloat(std::string const optionName) const;
|
||||
|
||||
unsigned int
|
||||
argumentCount() const;
|
||||
|
||||
std::string
|
||||
getArgument(unsigned int const argNumber) const;
|
||||
|
||||
private:
|
||||
struct cmdlineParserCtl * cp;
|
||||
|
||||
// Make sure no one can copy this object, because if there are two
|
||||
// copies, there will be two attempts to destroy *cp.
|
||||
CmdlineParser(CmdlineParser const&) {};
|
||||
|
||||
CmdlineParser&
|
||||
operator=(CmdlineParser const&) {return *this;}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef __GIRMATH_H
|
||||
#define __GIRMATH_H
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef GIRSTRING_H_INCLUDED
|
||||
#define GIRSTRING_H_INCLUDED
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "xmlrpc_config.h"
|
||||
#include "bool.h"
|
||||
|
||||
bool
|
||||
stripcaseeq(const char * const comparand,
|
||||
const char * const comparator);
|
||||
|
||||
static __inline__ bool
|
||||
streq(const char * const comparator,
|
||||
const char * const comparand) {
|
||||
|
||||
return (strcmp(comparand, comparator) == 0);
|
||||
}
|
||||
|
||||
static __inline__ bool
|
||||
memeq(const void * const comparator,
|
||||
const void * const comparand,
|
||||
size_t const size) {
|
||||
|
||||
return (memcmp(comparator, comparand, size) == 0);
|
||||
}
|
||||
|
||||
#define MEMEQ(a,b,c) (memcmp(a, b, c) == 0)
|
||||
|
||||
#define MEMSSET(a,b) (memset(a, b, sizeof(*a)))
|
||||
|
||||
#define MEMSCPY(a,b) (memcpy(a, b, sizeof(*a)))
|
||||
|
||||
#define MEMSZERO(a) (MEMSSET(a, 0))
|
||||
|
||||
static __inline__ const char *
|
||||
sdup(const char * const input) {
|
||||
return (const char *) strdup(input);
|
||||
}
|
||||
|
||||
/* Copy string pointed by B to array A with size checking. */
|
||||
#define STRSCPY(A,B) \
|
||||
(strncpy((A), (B), sizeof(A)), *((A)+sizeof(A)-1) = '\0')
|
||||
#define STRSCMP(A,B) \
|
||||
(strncmp((A), (B), sizeof(A)))
|
||||
|
||||
/* Concatenate string B onto string in array A with size checking */
|
||||
#define STRSCAT(A,B) \
|
||||
(strncat((A), (B), sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef XMLRPC_INLINE_H_INCLUDED
|
||||
#define XMLRPC_INLINE_H_INCLUDED
|
||||
|
||||
/* Xmlrpc-c uses __inline__ to declare functions that should be
|
||||
compiled as inline code. Some compilers, e.g. GNU, recognize the
|
||||
__inline__ keyword.
|
||||
*/
|
||||
#ifndef __GNUC__
|
||||
#ifndef __inline__
|
||||
#ifdef __sgi
|
||||
#define __inline__ __inline
|
||||
#else
|
||||
#define __inline__
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
/* This takes the place of C99 inttypes.h, which at least some Windows
|
||||
compilers don't have. (October 2007).
|
||||
*/
|
||||
|
||||
/* PRId64 is the printf-style format specifier for a long long type, as in
|
||||
long long mynumber = 5;
|
||||
printf("My number is %" PRId64 ".\n", mynumber);
|
||||
|
||||
The LL/ULL macro is for 64 bit integer literals, like this:
|
||||
|
||||
long long mask= ULL(1) << 33;
|
||||
*/
|
||||
|
||||
/* 'uint' is quite convenient, but there's no simple way have it everywhere.
|
||||
Some systems have it in the base system (e.g. GNU C library has it in
|
||||
<sys/types.h>, and others (e.g. Solaris - 08.12.02) don't. Since we
|
||||
can't define it unless we know it's not defined already, and we don't
|
||||
want to burden the reader with a special Xmlrpc-c name such as xuint,
|
||||
we just use standard "unsigned int" instead.
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define PRId64 "I64d"
|
||||
# define PRIu64 "I64u"
|
||||
|
||||
#ifndef int16_t
|
||||
typedef short int16_t;
|
||||
#endif
|
||||
#ifndef uint16_t
|
||||
typedef unsigned short uint16_t;
|
||||
#endif
|
||||
#ifndef int32_t
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
#ifndef uint32_t
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
#ifndef int64_t
|
||||
typedef __int64 int64_t;
|
||||
#endif
|
||||
#ifndef uint64_t
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#endif
|
||||
#ifndef uint8_t
|
||||
typedef unsigned char uint8_t;
|
||||
#endif
|
||||
|
||||
/* Older Microsoft compilers don't know the standard ll/ull suffixes */
|
||||
#define LL(x) x ## i64
|
||||
#define ULL(x) x ## u64
|
||||
|
||||
#else
|
||||
/* Not Microsoft compiler */
|
||||
#include <inttypes.h>
|
||||
#define LL(x) x ## ll
|
||||
#define ULL(x) x ## ull
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
#ifndef LINKLIST_H_INCLUDED
|
||||
#define LINKLIST_H_INCLUDED
|
||||
|
||||
#include "inline.h"
|
||||
|
||||
struct list_head {
|
||||
/*----------------------------------------------------------------------------
|
||||
This is a header for an element of a doubly linked list, or an anchor
|
||||
for such a list.
|
||||
|
||||
itemP == NULL means it's an anchor; otherwise it's a header.
|
||||
|
||||
Initialize a list header with list_init_header(). You don't have to
|
||||
do anything to terminate a list header.
|
||||
|
||||
Initialize an anchor with list_make_emtpy(). You don't have to do anything
|
||||
to terminate a list header.
|
||||
-----------------------------------------------------------------------------*/
|
||||
struct list_head * nextP;
|
||||
/* For a header, this is the address of the list header for
|
||||
the next element in the list. If there is no next element,
|
||||
it points to the anchor. If the header is not in a list at
|
||||
all, it is NULL.
|
||||
|
||||
For an anchor, it is the address of the list header of the
|
||||
first element. If the list is empty, it points to the
|
||||
anchor itself.
|
||||
*/
|
||||
struct list_head * prevP;
|
||||
/* For a header, this is the address of the list header for
|
||||
the previous element in the list. If there is no previous element,
|
||||
it points to the anchor. If the header is not in a list at
|
||||
all, it is NULL.
|
||||
|
||||
For an anchor, it is the address of the list header of the
|
||||
last element. If the list is empty, it points to the
|
||||
anchor itself.
|
||||
*/
|
||||
void * itemP;
|
||||
/* For a header, this is the address of the list element to which it
|
||||
belongs. For an anchor, this is NULL.
|
||||
*/
|
||||
};
|
||||
|
||||
static __inline__ void
|
||||
list_init_header(struct list_head * const headerP,
|
||||
void * const itemP) {
|
||||
|
||||
headerP->prevP = NULL;
|
||||
headerP->nextP = NULL;
|
||||
headerP->itemP = itemP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ int
|
||||
list_is_linked(struct list_head * headerP) {
|
||||
return headerP->prevP != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ int
|
||||
list_is_empty(struct list_head * const anchorP) {
|
||||
return anchorP->nextP == anchorP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ unsigned int
|
||||
list_count(struct list_head * const anchorP) {
|
||||
unsigned int count;
|
||||
|
||||
struct list_head * p;
|
||||
|
||||
for (p = anchorP->nextP, count = 0;
|
||||
p != anchorP;
|
||||
p = p->nextP, ++count);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ void
|
||||
list_make_empty(struct list_head * const anchorP) {
|
||||
anchorP->prevP = anchorP;
|
||||
anchorP->nextP = anchorP;
|
||||
anchorP->itemP = NULL;
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
list_insert_after(struct list_head * const beforeHeaderP,
|
||||
struct list_head * const newHeaderP) {
|
||||
newHeaderP->prevP = beforeHeaderP;
|
||||
newHeaderP->nextP = beforeHeaderP->nextP;
|
||||
|
||||
beforeHeaderP->nextP = newHeaderP;
|
||||
newHeaderP->nextP->prevP = newHeaderP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ void
|
||||
list_add_tail(struct list_head * const anchorP,
|
||||
struct list_head * const headerP) {
|
||||
list_insert_after(anchorP->prevP, headerP);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ void
|
||||
list_add_head(struct list_head * const anchorP,
|
||||
struct list_head * const headerP) {
|
||||
list_insert_after(anchorP, headerP);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ void
|
||||
list_remove(struct list_head * const headerP) {
|
||||
headerP->prevP->nextP = headerP->nextP;
|
||||
headerP->nextP->prevP = headerP->prevP;
|
||||
headerP->prevP = NULL;
|
||||
headerP->nextP = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ struct list_head *
|
||||
list_remove_head(struct list_head * const anchorP) {
|
||||
struct list_head * retval;
|
||||
|
||||
if (list_is_empty(anchorP))
|
||||
retval = NULL;
|
||||
else {
|
||||
retval = anchorP->nextP;
|
||||
list_remove(retval);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ struct list_head *
|
||||
list_remove_tail(struct list_head * const anchorP) {
|
||||
struct list_head * retval;
|
||||
|
||||
if (list_is_empty(anchorP))
|
||||
retval = NULL;
|
||||
else {
|
||||
retval = anchorP->prevP;
|
||||
list_remove(retval);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ void *
|
||||
list_foreach(struct list_head * const anchorP,
|
||||
void * functionP(struct list_head *, void *),
|
||||
void * const context) {
|
||||
|
||||
struct list_head * p;
|
||||
struct list_head * nextP;
|
||||
void * result;
|
||||
|
||||
for (p = anchorP->nextP, nextP = p->nextP, result=NULL;
|
||||
p != anchorP && result == NULL;
|
||||
p = nextP, nextP = p->nextP)
|
||||
result = (*functionP)(p, context);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ void
|
||||
list_append(struct list_head * const newAnchorP,
|
||||
struct list_head * const baseAnchorP) {
|
||||
|
||||
if (!list_is_empty(newAnchorP)) {
|
||||
baseAnchorP->prevP->nextP = newAnchorP->nextP;
|
||||
newAnchorP->nextP->prevP = baseAnchorP->prevP;
|
||||
newAnchorP->prevP->nextP = baseAnchorP;
|
||||
baseAnchorP->prevP = newAnchorP->prevP;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/* These are some dynamic memory allocation facilities. They are essentially
|
||||
an extension to C, as they do allocations with a cognizance of C
|
||||
variables. You can use them to make C read more like a high level
|
||||
language.
|
||||
|
||||
Before including this, you must define an __inline__ macro if your
|
||||
compiler doesn't recognize it as a keyword.
|
||||
*/
|
||||
|
||||
#ifndef MALLOCVAR_INCLUDED
|
||||
#define MALLOCVAR_INCLUDED
|
||||
|
||||
#include "xmlrpc_config.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static __inline__ void
|
||||
mallocProduct(void ** const resultP,
|
||||
unsigned int const factor1,
|
||||
unsigned int const factor2) {
|
||||
/*----------------------------------------------------------------------------
|
||||
malloc a space whose size in bytes is the product of 'factor1' and
|
||||
'factor2'. But if that size cannot be represented as an unsigned int,
|
||||
return NULL without allocating anything. Also return NULL if the malloc
|
||||
fails.
|
||||
|
||||
If either factor is zero, malloc a single byte.
|
||||
|
||||
Note that malloc() actually takes a size_t size argument, so the
|
||||
proper test would be whether the size can be represented by size_t,
|
||||
not unsigned int. But there is no reliable indication available to
|
||||
us, like UINT_MAX, of what the limitations of size_t are. We
|
||||
assume size_t is at least as expressive as unsigned int and that
|
||||
nobody really needs to allocate more than 4GB of memory.
|
||||
-----------------------------------------------------------------------------*/
|
||||
if (factor1 == 0 || factor2 == 0)
|
||||
*resultP = malloc(1);
|
||||
else {
|
||||
if (UINT_MAX / factor2 < factor1)
|
||||
*resultP = NULL;
|
||||
else
|
||||
*resultP = malloc(factor1 * factor2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ void
|
||||
reallocProduct(void ** const blockP,
|
||||
unsigned int const factor1,
|
||||
unsigned int const factor2) {
|
||||
|
||||
void * const oldBlockP = *blockP;
|
||||
|
||||
void * newBlockP;
|
||||
|
||||
if (UINT_MAX / factor2 < factor1)
|
||||
newBlockP = NULL;
|
||||
else
|
||||
newBlockP = realloc(oldBlockP, factor1 * factor2);
|
||||
|
||||
if (newBlockP)
|
||||
*blockP = newBlockP;
|
||||
else {
|
||||
free(oldBlockP);
|
||||
*blockP = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* IMPLEMENTATION NOTE: There are huge strict aliasing pitfalls here
|
||||
if you cast pointers, e.g. (void **)
|
||||
*/
|
||||
|
||||
#define MALLOCARRAY(arrayName, nElements) do { \
|
||||
void * array; \
|
||||
mallocProduct(&array, nElements, sizeof(arrayName[0])); \
|
||||
arrayName = array; \
|
||||
} while (0)
|
||||
|
||||
#define REALLOCARRAY(arrayName, nElements) do { \
|
||||
void * array = arrayName; \
|
||||
reallocProduct(&array, nElements, sizeof(arrayName[0])); \
|
||||
arrayName = array; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define MALLOCARRAY_NOFAIL(arrayName, nElements) \
|
||||
do { \
|
||||
MALLOCARRAY(arrayName, nElements); \
|
||||
if ((arrayName) == NULL) \
|
||||
abort(); \
|
||||
} while(0)
|
||||
|
||||
#define REALLOCARRAY_NOFAIL(arrayName, nElements) \
|
||||
do { \
|
||||
REALLOCARRAY(arrayName, nElements); \
|
||||
if ((arrayName) == NULL) \
|
||||
abort(); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define MALLOCVAR(varName) \
|
||||
varName = malloc(sizeof(*varName))
|
||||
|
||||
#define MALLOCVAR_NOFAIL(varName) \
|
||||
do {if ((varName = malloc(sizeof(*varName))) == NULL) abort();} while(0)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
** SUCH DAMAGE. */
|
||||
|
||||
#ifndef PTHREADX_H_INCLUDED
|
||||
#define PTHREADX_H_INCLUDED
|
||||
|
||||
#ifndef WIN32
|
||||
# define _REENTRANT
|
||||
# include <pthread.h>
|
||||
#elif defined (WIN32)
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef HANDLE pthread_t;
|
||||
typedef CRITICAL_SECTION pthread_mutex_t;
|
||||
|
||||
#define PTHREAD_MUTEX_INITIALIZER NULL
|
||||
/* usage: pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; */
|
||||
|
||||
typedef
|
||||
struct {
|
||||
int attrs; /* currently unused. placeholder. */
|
||||
} pthread_attr_t;
|
||||
|
||||
typedef
|
||||
struct {
|
||||
int attrs; /* currently unused. placeholder. */
|
||||
} pthread_mutexattr_t;
|
||||
|
||||
/* We make pthread_func identical to a Windows thread start function
|
||||
so we can use Windows thread functions to implement these pthread
|
||||
functions directly.
|
||||
*/
|
||||
typedef unsigned (WINAPI pthread_func)(void *);
|
||||
|
||||
extern int pthread_create(pthread_t * const new_thread_ID,
|
||||
const pthread_attr_t * const attr,
|
||||
pthread_func * start_func,
|
||||
void * const arg);
|
||||
extern int pthread_cancel(pthread_t target_thread);
|
||||
extern int pthread_join(pthread_t target_thread, void **status);
|
||||
extern int pthread_detach(pthread_t target_thread);
|
||||
|
||||
extern int pthread_mutex_init(pthread_mutex_t * const mp,
|
||||
const pthread_mutexattr_t * const attr);
|
||||
extern int pthread_mutex_lock(pthread_mutex_t * const mp);
|
||||
extern int pthread_mutex_unlock(pthread_mutex_t * const mp);
|
||||
extern int pthread_mutex_destroy(pthread_mutex_t * const mp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
#ifndef STDARGX_H_INCLUDED
|
||||
#define STDARGX_H_INCLUDED
|
||||
|
||||
#include "xmlrpc_config.h"
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
We need a special version of va_list in order to pass around the
|
||||
variable argument heap by reference, thus allowing a subroutine to
|
||||
advance the heap's pointer.
|
||||
|
||||
On some systems (e.g. Gcc for PPC or AMD64), va_list is an array.
|
||||
That invites the scourge of array-to-pointer degeneration if you try
|
||||
to take its address. Burying it inside a struct as we do with out
|
||||
va_listx type makes it immune.
|
||||
|
||||
Example of what would happen if we used va_list instead of va_listx,
|
||||
on a system where va_list is an array:
|
||||
|
||||
void sub2(va_list * argsP) [
|
||||
...
|
||||
}
|
||||
|
||||
void sub1(va_list args) {
|
||||
sub2(&args);
|
||||
}
|
||||
|
||||
This doesn't work. '&args' is the same thing as 'args', so is
|
||||
va_list, not va_list *. The compiler will even warn you about the
|
||||
pointer type mismatch.
|
||||
|
||||
To use va_listx:
|
||||
|
||||
void sub1_va(char * format, va_list args) {
|
||||
va_listx argsx;
|
||||
init_va_listx(&argsx, args);
|
||||
sub2(format, &argsx);
|
||||
}
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
typedef struct {
|
||||
/*----------------------------------------------------------------------------
|
||||
Same thing as va_list, but in a form that works everywhere. See above.
|
||||
-----------------------------------------------------------------------------*/
|
||||
va_list v;
|
||||
} va_listx;
|
||||
|
||||
|
||||
|
||||
static __inline__ void
|
||||
init_va_listx(va_listx * const argsxP,
|
||||
va_list const args) {
|
||||
#if VA_LIST_IS_ARRAY
|
||||
/* 'args' is NOT a va_list. It is a pointer to the first element of a
|
||||
'va_list', which is the same address as a pointer to the va_list
|
||||
itself.
|
||||
*/
|
||||
memcpy(&argsxP->v, args, sizeof(argsxP->v));
|
||||
#else
|
||||
argsxP->v = args;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef STRING_PARSER_H_INCLUDED
|
||||
#define STRING_PARSER_H_INCLUDED
|
||||
|
||||
#include "int.h"
|
||||
|
||||
void
|
||||
interpretUll(const char * const string,
|
||||
uint64_t * const ullP,
|
||||
const char ** const errorP);
|
||||
|
||||
void
|
||||
interpretLl(const char * const string,
|
||||
int64_t * const llP,
|
||||
const char ** const errorP);
|
||||
|
||||
void
|
||||
interpretUint(const char * const string,
|
||||
unsigned int * const uintP,
|
||||
const char ** const errorP);
|
||||
|
||||
void
|
||||
interpretInt(const char * const string,
|
||||
int * const uintP,
|
||||
const char ** const errorP);
|
||||
|
||||
void
|
||||
interpretBinUint(const char * const string,
|
||||
uint64_t * const valueP,
|
||||
const char ** const errorP);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef UNISTDX_H_INCLUDED
|
||||
#define UNISTDX_H_INCLUDED
|
||||
|
||||
/* Xmlrpc-c code #includes "unistdx.h" instead of <unistd.h> because
|
||||
<unistd.h> does not exist on WIN32.
|
||||
*/
|
||||
|
||||
#ifndef WIN32
|
||||
# include <unistd.h>
|
||||
#else
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user