Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,12 @@ func=atomic
printf "Checking for GCC atomic builtins ... "
cat <<EOF >_$func.c
int main() {
volatile unsigned long val = 1;
__sync_fetch_and_add(&val, 1);
__sync_fetch_and_sub(&val, 1);
__sync_add_and_fetch(&val, 1);
__sync_sub_and_fetch(&val, 1);
unsigned long val = 1;
__atomic_load_n(&val, __ATOMIC_RELAXED);
__atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);
__atomic_fetch_sub(&val, 1, __ATOMIC_RELEASE);
__atomic_add_fetch(&val, 1, __ATOMIC_RELAXED);
__atomic_sub_fetch(&val, 1, __ATOMIC_ACQ_REL);
return 0;
}
EOF
Expand Down
14 changes: 12 additions & 2 deletions include/xbps/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

#define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x))[0])

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#ifndef MIN
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif

#if __has_builtin(__builtin_imaxabs)
# define ABS(x) __builtin_imaxabs((x))
Expand Down Expand Up @@ -32,4 +36,10 @@
#define strcaseeq(a, b) (strcasecmp((a), (b)) == 0)
#define strcaseneq(a, b, n) (strcasencmp((a), (b), (n)) == 0)

#if __has_attribute(deprecated)
# define DEPRECATED __attribute__ ((deprecated))
#else
# define DEPRECATED /* deprecated */
#endif

#endif /* !_XBPS_MACRO_H */
126 changes: 113 additions & 13 deletions include/xbps/xbps_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
#ifndef _XBPS_ARRAY_H_
#define _XBPS_ARRAY_H_

#include <sys/types.h>

#include <stdint.h>

#include <xbps/xbps_object.h>
#include <xbps/macro.h>

typedef struct _prop_array *xbps_array_t;

Expand Down Expand Up @@ -68,9 +72,7 @@ char * xbps_array_externalize(xbps_array_t);
xbps_array_t xbps_array_internalize(const char *);

bool xbps_array_externalize_to_file(xbps_array_t, const char *);
bool xbps_array_externalize_to_zfile(xbps_array_t, const char *);
xbps_array_t xbps_array_internalize_from_file(const char *);
xbps_array_t xbps_array_internalize_from_zfile(const char *);

/*
* Utility routines to make it more convenient to work with values
Expand All @@ -81,6 +83,60 @@ bool xbps_array_get_bool(xbps_array_t, unsigned int,
bool xbps_array_set_bool(xbps_array_t, unsigned int,
bool);

bool xbps_array_get_schar(xbps_array_t, unsigned int,
signed char *);
bool xbps_array_get_uchar(xbps_array_t, unsigned int,
unsigned char *);
bool xbps_array_set_schar(xbps_array_t, unsigned int,
signed char);
bool xbps_array_set_uchar(xbps_array_t, unsigned int,
unsigned char);

bool xbps_array_get_short(xbps_array_t, unsigned int,
short *);
bool xbps_array_get_ushort(xbps_array_t, unsigned int,
unsigned short *);
bool xbps_array_set_short(xbps_array_t, unsigned int,
short);
bool xbps_array_set_ushort(xbps_array_t, unsigned int,
unsigned short);

bool xbps_array_get_int(xbps_array_t, unsigned int,
int *);
bool xbps_array_get_uint(xbps_array_t, unsigned int,
unsigned int *);
bool xbps_array_set_int(xbps_array_t, unsigned int,
int);
bool xbps_array_set_uint(xbps_array_t, unsigned int,
unsigned int);

bool xbps_array_get_long(xbps_array_t, unsigned int,
long *);
bool xbps_array_get_ulong(xbps_array_t, unsigned int,
unsigned long *);
bool xbps_array_set_long(xbps_array_t, unsigned int,
long);
bool xbps_array_set_ulong(xbps_array_t, unsigned int,
unsigned long);

bool xbps_array_get_longlong(xbps_array_t, unsigned int,
long long *);
bool xbps_array_get_ulonglong(xbps_array_t, unsigned int,
unsigned long long *);
bool xbps_array_set_longlong(xbps_array_t, unsigned int,
long long);
bool xbps_array_set_ulonglong(xbps_array_t, unsigned int,
unsigned long long );

bool xbps_array_get_intptr(xbps_array_t, unsigned int,
intptr_t *);
bool xbps_array_get_uintptr(xbps_array_t, unsigned int,
uintptr_t *);
bool xbps_array_set_intptr(xbps_array_t, unsigned int,
intptr_t);
bool xbps_array_set_uintptr(xbps_array_t, unsigned int,
uintptr_t);

bool xbps_array_get_int8(xbps_array_t, unsigned int,
int8_t *);
bool xbps_array_get_uint8(xbps_array_t, unsigned int,
Expand Down Expand Up @@ -117,6 +173,29 @@ bool xbps_array_set_int64(xbps_array_t, unsigned int,
bool xbps_array_set_uint64(xbps_array_t, unsigned int,
uint64_t);

bool xbps_array_set_and_rel(xbps_array_t, unsigned int,
xbps_object_t);

bool xbps_array_add_bool(xbps_array_t, bool);

bool xbps_array_add_schar(xbps_array_t, signed char);
bool xbps_array_add_uchar(xbps_array_t, unsigned char);

bool xbps_array_add_short(xbps_array_t, short);
bool xbps_array_add_ushort(xbps_array_t, unsigned short);

bool xbps_array_add_int(xbps_array_t, int);
bool xbps_array_add_uint(xbps_array_t, unsigned int);

bool xbps_array_add_long(xbps_array_t, long);
bool xbps_array_add_ulong(xbps_array_t, unsigned long);

bool xbps_array_add_longlong(xbps_array_t, long long);
bool xbps_array_add_ulonglong(xbps_array_t, unsigned long long);

bool xbps_array_add_intptr(xbps_array_t, intptr_t);
bool xbps_array_add_uintptr(xbps_array_t, uintptr_t);

bool xbps_array_add_int8(xbps_array_t, int8_t);
bool xbps_array_add_uint8(xbps_array_t, uint8_t);

Expand All @@ -129,20 +208,41 @@ bool xbps_array_add_uint32(xbps_array_t, uint32_t);
bool xbps_array_add_int64(xbps_array_t, int64_t);
bool xbps_array_add_uint64(xbps_array_t, uint64_t);

bool xbps_array_get_string(xbps_array_t, unsigned int,
const char **);
bool xbps_array_set_string(xbps_array_t, unsigned int,
const char *);
bool xbps_array_add_string(xbps_array_t, const char *);
bool xbps_array_set_string_nocopy(xbps_array_t, unsigned int,
const char *);
bool xbps_array_add_string_nocopy(xbps_array_t, const char *);

bool xbps_array_get_data(xbps_array_t, unsigned int,
const void **, size_t *);
bool xbps_array_set_data(xbps_array_t, unsigned int,
const void *, size_t);
bool xbps_array_add_data(xbps_array_t,
const void *, size_t);
bool xbps_array_set_data_nocopy(xbps_array_t, unsigned int,
const void *, size_t);
bool xbps_array_add_data_nocopy(xbps_array_t,
const void *, size_t);

bool xbps_array_add_and_rel(xbps_array_t, xbps_object_t);

/* Deprecated functions. */
bool xbps_array_add_cstring(xbps_array_t, const char *);
bool xbps_array_get_cstring(xbps_array_t, unsigned int,
char **);
char **) DEPRECATED;
bool xbps_array_set_cstring(xbps_array_t, unsigned int,
const char *);
bool xbps_array_add_cstring(xbps_array_t, const char *);
const char *) DEPRECATED;

bool xbps_array_add_cstring_nocopy(xbps_array_t,
const char *);
bool xbps_array_get_cstring_nocopy(xbps_array_t,
unsigned int,
const char **);
bool xbps_array_set_cstring_nocopy(xbps_array_t,
unsigned int,
const char *);
bool xbps_array_add_and_rel(xbps_array_t, xbps_object_t);
const char *) DEPRECATED;
bool xbps_array_get_cstring_nocopy(xbps_array_t, unsigned int,
const char **) DEPRECATED;
bool xbps_array_set_cstring_nocopy(xbps_array_t, unsigned int,
const char *) DEPRECATED;

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions include/xbps/xbps_bool.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ xbps_bool_t xbps_bool_create(bool);
xbps_bool_t xbps_bool_copy(xbps_bool_t);

bool xbps_bool_true(xbps_bool_t);
bool xbps_bool_value(xbps_bool_t);

bool xbps_bool_equals(xbps_bool_t, xbps_bool_t);

Expand Down
21 changes: 16 additions & 5 deletions include/xbps/xbps_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
#ifndef _XBPS_DATA_H_
#define _XBPS_DATA_H_

#include <stdint.h>
#include <sys/types.h>

#include <stdint.h>

#include <xbps/macro.h>
#include <xbps/xbps_object.h>

typedef struct _prop_data *xbps_data_t;
Expand All @@ -42,19 +45,27 @@ typedef struct _prop_data *xbps_data_t;
extern "C" {
#endif

xbps_data_t xbps_data_create_data(const void *, size_t);
xbps_data_t xbps_data_create_data_nocopy(const void *, size_t);
xbps_data_t xbps_data_create_copy(const void *, size_t);
xbps_data_t xbps_data_create_nocopy(const void *, size_t);

xbps_data_t xbps_data_copy(xbps_data_t);

size_t xbps_data_size(xbps_data_t);

void * xbps_data_data(xbps_data_t);
const void * xbps_data_data_nocopy(xbps_data_t);
const void * xbps_data_value(xbps_data_t);
bool xbps_data_copy_value(xbps_data_t, void *, size_t);

bool xbps_data_equals(xbps_data_t, xbps_data_t);
bool xbps_data_equals_data(xbps_data_t, const void *, size_t);


/* Deprecated functions. */
xbps_data_t xbps_data_create_data(const void *, size_t) DEPRECATED;
xbps_data_t xbps_data_create_data_nocopy(const void *, size_t) DEPRECATED;

void * xbps_data_data(xbps_data_t) DEPRECATED;
const void * xbps_data_data_nocopy(xbps_data_t) DEPRECATED;

#ifdef __cplusplus
}
#endif
Expand Down
95 changes: 83 additions & 12 deletions include/xbps/xbps_dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
#define _XBPS_DICTIONARY_H_

#include <stdint.h>
#include <xbps/xbps_object.h>

#include <xbps/macro.h>
#include <xbps/xbps_array.h>
#include <xbps/xbps_object.h>

typedef struct _prop_dictionary *xbps_dictionary_t;
typedef struct _prop_dictionary_keysym *xbps_dictionary_keysym_t;
Expand Down Expand Up @@ -78,12 +80,9 @@ xbps_dictionary_t xbps_dictionary_internalize(const char *);

bool xbps_dictionary_externalize_to_file(xbps_dictionary_t,
const char *);
bool xbps_dictionary_externalize_to_zfile(xbps_dictionary_t,
const char *);
xbps_dictionary_t xbps_dictionary_internalize_from_file(const char *);
xbps_dictionary_t xbps_dictionary_internalize_from_zfile(const char *);

const char * xbps_dictionary_keysym_cstring_nocopy(xbps_dictionary_keysym_t);
const char * xbps_dictionary_keysym_value(xbps_dictionary_keysym_t k);

bool xbps_dictionary_keysym_equals(xbps_dictionary_keysym_t,
xbps_dictionary_keysym_t);
Expand All @@ -99,6 +98,60 @@ bool xbps_dictionary_get_bool(xbps_dictionary_t, const char *,
bool xbps_dictionary_set_bool(xbps_dictionary_t, const char *,
bool);

bool xbps_dictionary_get_schar(xbps_dictionary_t, const char *,
signed char *);
bool xbps_dictionary_get_uchar(xbps_dictionary_t, const char *,
unsigned char *);
bool xbps_dictionary_set_schar(xbps_dictionary_t, const char *,
signed char);
bool xbps_dictionary_set_uchar(xbps_dictionary_t, const char *,
unsigned char);

bool xbps_dictionary_get_short(xbps_dictionary_t, const char *,
short *);
bool xbps_dictionary_get_ushort(xbps_dictionary_t, const char *,
unsigned short *);
bool xbps_dictionary_set_short(xbps_dictionary_t, const char *,
short);
bool xbps_dictionary_set_ushort(xbps_dictionary_t, const char *,
unsigned short);

bool xbps_dictionary_get_int(xbps_dictionary_t, const char *,
int *);
bool xbps_dictionary_get_uint(xbps_dictionary_t, const char *,
unsigned int *);
bool xbps_dictionary_set_int(xbps_dictionary_t, const char *,
int);
bool xbps_dictionary_set_uint(xbps_dictionary_t, const char *,
unsigned int);

bool xbps_dictionary_get_long(xbps_dictionary_t, const char *,
long *);
bool xbps_dictionary_get_ulong(xbps_dictionary_t, const char *,
unsigned long *);
bool xbps_dictionary_set_long(xbps_dictionary_t, const char *,
long);
bool xbps_dictionary_set_ulong(xbps_dictionary_t, const char *,
unsigned long);

bool xbps_dictionary_get_longlong(xbps_dictionary_t, const char *,
long long *);
bool xbps_dictionary_get_ulonglong(xbps_dictionary_t, const char *,
unsigned long long *);
bool xbps_dictionary_set_longlong(xbps_dictionary_t, const char *,
long long);
bool xbps_dictionary_set_ulonglong(xbps_dictionary_t, const char *,
unsigned long long );

bool xbps_dictionary_get_intptr(xbps_dictionary_t, const char *,
intptr_t *);
bool xbps_dictionary_get_uintptr(xbps_dictionary_t, const char *,
uintptr_t *);
bool xbps_dictionary_set_intptr(xbps_dictionary_t, const char *,
intptr_t);
bool xbps_dictionary_set_uintptr(xbps_dictionary_t, const char *,
uintptr_t);

bool xbps_dictionary_get_int8(xbps_dictionary_t, const char *,
int8_t *);
bool xbps_dictionary_get_uint8(xbps_dictionary_t, const char *,
Expand Down Expand Up @@ -135,20 +188,38 @@ bool xbps_dictionary_set_int64(xbps_dictionary_t, const char *,
bool xbps_dictionary_set_uint64(xbps_dictionary_t, const char *,
uint64_t);

bool xbps_dictionary_get_string(xbps_dictionary_t, const char *,
const char **cpp);
bool xbps_dictionary_set_string(xbps_dictionary_t, const char *,
const char *);
bool xbps_dictionary_set_string_nocopy(xbps_dictionary_t,
const char *, const char *);

bool xbps_dictionary_get_data(xbps_dictionary_t, const char *,
const void **, size_t *);
bool xbps_dictionary_set_data(xbps_dictionary_t, const char *,
const void *, size_t);
bool xbps_dictionary_set_data_nocopy(xbps_dictionary_t, const char *,
const void *, size_t);

bool xbps_dictionary_set_and_rel(xbps_dictionary_t,
const char *,
xbps_object_t);

/* Deprecated functions. */
bool xbps_dictionary_get_cstring(xbps_dictionary_t, const char *,
char **);
char **) DEPRECATED;
bool xbps_dictionary_set_cstring(xbps_dictionary_t, const char *,
const char *);
const char *) DEPRECATED;

bool xbps_dictionary_get_cstring_nocopy(xbps_dictionary_t,
const char *,
const char **);
const char **) DEPRECATED;
bool xbps_dictionary_set_cstring_nocopy(xbps_dictionary_t,
const char *,
const char *);
bool xbps_dictionary_set_and_rel(xbps_dictionary_t,
const char *,
xbps_object_t);
const char *) DEPRECATED;

const char * xbps_dictionary_keysym_cstring_nocopy(xbps_dictionary_keysym_t) DEPRECATED;

#ifdef __cplusplus
}
Expand Down
Loading
Loading