Skip to content

Commit

Permalink
Convert cord source files to valid C++ code
Browse files Browse the repository at this point in the history
Issue #206 (bdwgc).

* cord/cordbscs.c (Concatenation, Function, Generic): Define struct
outside union (i.e. the union just uses them).
* cord/cordbscs.c (CORD_cat_char_star, CORD_from_fn_inner,
CORD_substr_checked): Cast GC_MALLOC_ATOMIC() result to char*.
* cord/cordprnt.c (CORD_vsprintf): Likewise.
* cord/cordxtra.c (CORD_cat_char, CORD_to_char_star,
CORD_from_char_star, CORD_ec_flush_buf): Likewise.
* cord/cordbscs.c (CORD_substr_checked): Remove register keyword for
"result" local variable.
  • Loading branch information
ivmai committed Feb 14, 2018
1 parent b2b0d27 commit 246ad41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
24 changes: 15 additions & 9 deletions cord/cordbscs.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ oom_fn CORD_oom_fn = (oom_fn) 0;

typedef unsigned long word;

typedef union {
struct Concatenation {
char null;
char header;
Expand All @@ -54,7 +53,8 @@ typedef union {
word len;
CORD left; /* length(left) > 0 */
CORD right; /* length(right) > 0 */
} concatenation;
};

struct Function {
char null;
char header;
Expand All @@ -63,14 +63,20 @@ typedef union {
word len;
CORD_fn fn;
void * client_data;
} function;
};

struct Generic {
char null;
char header;
char depth;
char left_len;
word len;
} generic;
};

typedef union {
struct Concatenation concatenation;
struct Function function;
struct Generic generic;
char string[1];
} CordRep;

Expand Down Expand Up @@ -161,7 +167,7 @@ CORD CORD_cat_char_star(CORD x, const char * y, size_t leny)
lenx = strlen(x);
result_len = lenx + leny;
if (result_len <= SHORT_LIMIT) {
register char * result = GC_MALLOC_ATOMIC(result_len+1);
char * result = (char *)GC_MALLOC_ATOMIC(result_len + 1);

if (result == 0) OUT_OF_MEMORY;
memcpy(result, x, lenx);
Expand Down Expand Up @@ -193,7 +199,7 @@ CORD CORD_cat_char_star(CORD x, const char * y, size_t leny)
}
result_len = right_len + leny; /* length of new_right */
if (result_len <= SHORT_LIMIT) {
new_right = GC_MALLOC_ATOMIC(result_len + 1);
new_right = (char *)GC_MALLOC_ATOMIC(result_len + 1);
if (new_right == 0) OUT_OF_MEMORY;
memcpy(new_right, right, right_len);
memcpy(new_right + right_len, y, leny);
Expand Down Expand Up @@ -293,7 +299,7 @@ static CordRep *CORD_from_fn_inner(CORD_fn fn, void * client_data, size_t len)
buf[i] = c;
}

result = GC_MALLOC_ATOMIC(len+1);
result = (char *)GC_MALLOC_ATOMIC(len + 1);
if (result == 0) OUT_OF_MEMORY;
memcpy(result, buf, len);
result[len] = '\0';
Expand Down Expand Up @@ -378,7 +384,7 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n)
if (n > SUBSTR_LIMIT) {
return(CORD_substr_closure(x, i, n, CORD_index_access_fn));
} else {
register char * result = GC_MALLOC_ATOMIC(n+1);
char * result = (char *)GC_MALLOC_ATOMIC(n + 1);

if (result == 0) OUT_OF_MEMORY;
strncpy(result, x+i, n);
Expand Down Expand Up @@ -448,7 +454,7 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n)
}
*p++ = c;
}
result = GC_MALLOC_ATOMIC(n+1);
result = (char *)GC_MALLOC_ATOMIC(n + 1);
if (result == 0) OUT_OF_MEMORY;
memcpy(result, buf, n);
result[n] = '\0';
Expand Down
5 changes: 3 additions & 2 deletions cord/cordprnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args)
len = (unsigned)prec;
}
if (width != NONE && len < (size_t)width) {
char * blanks = GC_MALLOC_ATOMIC(width-len+1);
char * blanks =
(char *)GC_MALLOC_ATOMIC(width - len + 1);

if (NULL == blanks) OUT_OF_MEMORY;
memset(blanks, ' ', width-len);
Expand Down Expand Up @@ -306,7 +307,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args)
if (prec != NONE && prec > max_size) max_size = prec;
max_size += CONV_RESULT_LEN;
if (max_size >= CORD_BUFSZ) {
buf = GC_MALLOC_ATOMIC(max_size + 1);
buf = (char *)GC_MALLOC_ATOMIC(max_size + 1);
if (NULL == buf) OUT_OF_MEMORY;
} else {
if (CORD_BUFSZ - (result[0].ec_bufptr-result[0].ec_buf)
Expand Down
8 changes: 4 additions & 4 deletions cord/cordxtra.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ CORD CORD_cat_char(CORD x, char c)
register char * string;

if (c == '\0') return(CORD_cat(x, CORD_nul(1)));
string = GC_MALLOC_ATOMIC(2);
string = (char *)GC_MALLOC_ATOMIC(2);
if (string == 0) OUT_OF_MEMORY;
string[0] = c;
string[1] = '\0';
Expand Down Expand Up @@ -244,7 +244,7 @@ int CORD_ncmp(CORD x, size_t x_start, CORD y, size_t y_start, size_t len)
char * CORD_to_char_star(CORD x)
{
register size_t len = CORD_len(x);
char * result = GC_MALLOC_ATOMIC(len + 1);
char * result = (char *)GC_MALLOC_ATOMIC(len + 1);

if (result == 0) OUT_OF_MEMORY;
if (len > 0 && CORD_fill_buf(x, 0, len, result) != 1)
Expand All @@ -259,7 +259,7 @@ CORD CORD_from_char_star(const char *s)
size_t len = strlen(s);

if (0 == len) return(CORD_EMPTY);
result = GC_MALLOC_ATOMIC(len + 1);
result = (char *)GC_MALLOC_ATOMIC(len + 1);
if (result == 0) OUT_OF_MEMORY;
memcpy(result, s, len+1);
return(result);
Expand Down Expand Up @@ -434,7 +434,7 @@ void CORD_ec_flush_buf(CORD_ec x)
char * s;

if (len == 0) return;
s = GC_MALLOC_ATOMIC(len+1);
s = (char *)GC_MALLOC_ATOMIC(len + 1);
if (NULL == s) OUT_OF_MEMORY;
memcpy(s, x[0].ec_buf, len);
s[len] = '\0';
Expand Down

0 comments on commit 246ad41

Please sign in to comment.