Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into releases
Browse files Browse the repository at this point in the history
  • Loading branch information
be5invis committed Nov 19, 2016
2 parents ad54c1c + 8b741c9 commit 0afb4a8
Show file tree
Hide file tree
Showing 135 changed files with 2,096 additions and 1,187 deletions.
11 changes: 11 additions & 0 deletions dep/extern/json-builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ static size_t measure_string(unsigned int length, const json_char *str) {
json_char c = str[i];

switch (c) {
case 0:
measured_length += 6;
break;
case '"':
case '\\':
case '\b':
Expand Down Expand Up @@ -420,6 +423,14 @@ static size_t serialize_string(json_char *buf, unsigned int length, const json_c
json_char c = str[i];

switch (c) {
case 0:
*buf++ = '\\';
*buf++ = 'u';
*buf++ = '0';
*buf++ = '0';
*buf++ = '0';
*buf++ = '0';
continue;
case '"':
PRINT_ESCAPED('\"');
continue;
Expand Down
65 changes: 5 additions & 60 deletions include/caryll/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,11 @@
#include <string.h>
#include <stdbool.h>

#ifndef __CARYLL_INLINE__
#ifdef _MSC_VER
#define __CARYLL_INLINE__ __forceinline /* use __forceinline (VC++ specific) */
#else
#define __CARYLL_INLINE__ inline /* use standard inline */
#endif
#endif

#define __caryll_malloc malloc
#define __caryll_calloc calloc
#define __caryll_realloc realloc
#define __caryll_free free

// We assume all T have trivial move constructors.
#define caryll_T(T) \
void (*init)(MODIFY T *); \
void (*copy)(MODIFY T *, const T *); \
void (*move)(MODIFY T *, T *); \
void (*dispose)(MOVE T *);
#define caryll_VT(T) \
caryll_T(T); \
Expand All @@ -31,7 +19,7 @@
#define caryll_RT(T) \
caryll_T(T); \
T *(*create)(); \
void (*destroy)(MOVE T *);
void (*free)(MOVE T *);

#define caryll_ElementInterfaceOf(T) const struct __caryll_elementinterface_##T
#define caryll_ElementInterface(T) \
Expand All @@ -42,52 +30,9 @@
caryll_ElementInterfaceOf(T) { \
caryll_RT(T); \
}

#define caryll_TrivialElementImpl(T, name) \
static __CARYLL_INLINE__ void name##_init(MODIFY T *x) { \
memset(x, 0, sizeof(T)); \
} \
static __CARYLL_INLINE__ void name##_copy(MODIFY T *dst, const T *src) { \
memcpy(dst, src, sizeof(T)); \
} \
static __CARYLL_INLINE__ void name##_dispose(MODIFY T *x) {} \
caryll_ElementInterfaceOf(T) name = { \
.init = name##_init, .copy = name##_copy, .dispose = name##_dispose, \
}

#define caryll_DtorElementImpl(T, dtor, name) \
static __CARYLL_INLINE__ void name##_init(MODIFY T *x) { \
memset(x, 0, sizeof(T)); \
} \
static __CARYLL_INLINE__ void name##_copy(MODIFY T *dst, const T *src) { \
memcpy(dst, src, sizeof(T)); \
} \
caryll_ElementInterfaceOf(T) name = { \
.init = name##_init, .copy = name##_copy, .dispose = dtor, \
}

#define caryll_CDRefElementImplFn(T, ctor, dtor, name) \
static __CARYLL_INLINE__ T *name##_create() { \
T *x = (T *)malloc(sizeof(T)); \
ctor(x); \
return x; \
} \
static __CARYLL_INLINE__ void name##_copy(MODIFY T *dst, const T *src) { \
memcpy(dst, src, sizeof(T)); \
} \
static __CARYLL_INLINE__ void name##_destroy(MOVE T *x) { \
if (!x) return; \
dtor(x); \
__caryll_free(x); \
}

#define caryll_CdRefElementImplAsg(T, ctor, dtor, name) \
.init = ctor, .copy = name##_copy, .dispose = dtor, .create = name##_create, .destroy = name##_destroy

#define caryll_CDRefElementImpl(T, ctor, dtor, name) \
caryll_CDRefElementImplFn(T, ctor, dtor, name); \
caryll_ElementInterfaceOf(T) name = { \
caryll_CdRefElementImplAsg(T, ctor, dtor, name), \
#define caryll_ValElementInterface(T) \
caryll_ElementInterfaceOf(T) { \
caryll_VT(T); \
}

#endif
Loading

0 comments on commit 0afb4a8

Please sign in to comment.