Skip to content

Commit

Permalink
Get rid of unnecessary typedefs
Browse files Browse the repository at this point in the history
This follows from recommendations made by the Linux Kernel C style
guide. It's simpler, and more clear to just write 'struct Foo', rather
than declaring a 'typedef struct _Foo Foo'.
  • Loading branch information
cjdrake committed Feb 28, 2015
1 parent b791e5b commit da3bdd5
Show file tree
Hide file tree
Showing 15 changed files with 606 additions and 633 deletions.
14 changes: 7 additions & 7 deletions extension/boolexpr/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
#include "boolexpr.h"


BoolExprArray *
BoolExprArray_New(size_t length, BoolExpr **items)
struct BoolExprArray *
BoolExprArray_New(size_t length, struct BoolExpr **items)
{
BoolExprArray *array;
struct BoolExprArray *array;

array = (BoolExprArray *) malloc(sizeof(BoolExprArray));
array = (struct BoolExprArray *) malloc(sizeof(struct BoolExprArray));
if (array == NULL)
return NULL; // LCOV_EXCL_LINE

array->items = (BoolExpr **) malloc(length * sizeof(BoolExpr *));
array->items = (struct BoolExpr **) malloc(length * sizeof(struct BoolExpr *));
if (array->items == NULL) {
free(array); // LCOV_EXCL_LINE
return NULL; // LCOV_EXCL_LINE
Expand All @@ -31,7 +31,7 @@ BoolExprArray_New(size_t length, BoolExpr **items)


void
BoolExprArray_Del(BoolExprArray *array)
BoolExprArray_Del(struct BoolExprArray *array)
{
for (size_t i = 0; i < array->length; ++i)
BoolExpr_DecRef(array->items[i]);
Expand All @@ -42,7 +42,7 @@ BoolExprArray_Del(BoolExprArray *array)


bool
BoolExprArray_Equal(BoolExprArray *self, BoolExprArray *other)
BoolExprArray_Equal(struct BoolExprArray *self, struct BoolExprArray *other)
{
if (self->length != other->length)
return false;
Expand Down
40 changes: 20 additions & 20 deletions extension/boolexpr/array2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@


/* boolexpr.c */
BoolExpr * _opn_new(BoolExprType t, size_t n, ...);
struct BoolExpr * _opn_new(BoolExprType t, size_t n, ...);


BoolExprArray2 *
BoolExprArray2_New(size_t length, size_t *lengths, BoolExpr ***items)
struct BoolExprArray2 *
BoolExprArray2_New(size_t length, size_t *lengths, struct BoolExpr ***items)
{
BoolExprArray2 *array2;
struct BoolExprArray2 *array2;

array2 = (BoolExprArray2 *) malloc(sizeof(BoolExprArray2));
array2 = (struct BoolExprArray2 *) malloc(sizeof(struct BoolExprArray2));
if (array2 == NULL)
return NULL; // LCOV_EXCL_LINE

array2->items = (BoolExprArray **) malloc(length * sizeof(BoolExprArray *));
array2->items = (struct BoolExprArray **) malloc(length * sizeof(struct BoolExprArray *));
if (array2->items == NULL) {
free(array2); // LCOV_EXCL_LINE
return NULL; // LCOV_EXCL_LINE
Expand All @@ -35,7 +35,7 @@ BoolExprArray2_New(size_t length, size_t *lengths, BoolExpr ***items)


void
BoolExprArray2_Del(BoolExprArray2 *array2)
BoolExprArray2_Del(struct BoolExprArray2 *array2)
{
for (size_t i = 0; i < array2->length; ++i)
BoolExprArray_Del(array2->items[i]);
Expand All @@ -46,7 +46,7 @@ BoolExprArray2_Del(BoolExprArray2 *array2)


bool
BoolExprArray2_Equal(BoolExprArray2 *self, BoolExprArray2 *other)
BoolExprArray2_Equal(struct BoolExprArray2 *self, struct BoolExprArray2 *other)
{
if (self->length != other->length)
return false;
Expand All @@ -59,14 +59,14 @@ BoolExprArray2_Equal(BoolExprArray2 *self, BoolExprArray2 *other)
}


static BoolExprArray *
_multiply(BoolExprArray *a, BoolExprArray *b, BoolExprType t)
static struct BoolExprArray *
_multiply(struct BoolExprArray *a, struct BoolExprArray *b, BoolExprType t)
{
size_t length = a->length * b->length;
BoolExpr **items;
BoolExprArray *prod;
struct BoolExpr **items;
struct BoolExprArray *prod;

items = (BoolExpr **) malloc(length * sizeof(BoolExpr *));
items = (struct BoolExpr **) malloc(length * sizeof(struct BoolExpr *));
if (items == NULL)
return NULL; // LCOV_EXCL_LINE

Expand Down Expand Up @@ -94,16 +94,16 @@ _multiply(BoolExprArray *a, BoolExprArray *b, BoolExprType t)
}


static BoolExprArray *
_product(BoolExprArray2 *array2, BoolExprType t, size_t n)
static struct BoolExprArray *
_product(struct BoolExprArray2 *array2, BoolExprType t, size_t n)
{
if (n == 0) {
BoolExpr *items[] = {IDENTITY[t]};
struct BoolExpr *items[] = {IDENTITY[t]};
return BoolExprArray_New(1, items);
}
else {
BoolExprArray *prev;
BoolExprArray *prod;
struct BoolExprArray *prev;
struct BoolExprArray *prod;

prev = _product(array2, t, n-1);
if (prev == NULL)
Expand All @@ -118,8 +118,8 @@ _product(BoolExprArray2 *array2, BoolExprType t, size_t n)
}


BoolExprArray *
BoolExprArray2_Product(BoolExprArray2 *self, BoolExprType t)
struct BoolExprArray *
BoolExprArray2_Product(struct BoolExprArray2 *self, BoolExprType t)
{
return _product(self, t, self->length);
}
Expand Down
44 changes: 22 additions & 22 deletions extension/boolexpr/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@


/* boolexpr.c */
BoolExpr * _op_new(BoolExprType t, size_t n, BoolExpr **xs);
struct BoolExpr * _op_new(BoolExprType t, size_t n, struct BoolExpr **xs);

/* util.c */
BoolExpr * _op_transform(BoolExpr *op, BoolExpr * (*fn)(BoolExpr *));
struct BoolExpr * _op_transform(struct BoolExpr *op, struct BoolExpr * (*fn)(struct BoolExpr *));


static BoolExpr *
_commutative_binify(BoolExpr *op)
static struct BoolExpr *
_commutative_binify(struct BoolExpr *op)
{
if (op->data.xs->length == 2) {
return BoolExpr_IncRef(op);
Expand All @@ -25,11 +25,11 @@ _commutative_binify(BoolExpr *op)
size_t mid = op->data.xs->length / 2;
size_t n0 = mid;
size_t n1 = op->data.xs->length - mid;
BoolExpr **items0 = op->data.xs->items;
BoolExpr **items1 = op->data.xs->items + mid;
BoolExpr *xs[2];
BoolExpr *temp;
BoolExpr *y;
struct BoolExpr **items0 = op->data.xs->items;
struct BoolExpr **items1 = op->data.xs->items + mid;
struct BoolExpr *xs[2];
struct BoolExpr *temp;
struct BoolExpr *y;

if (n0 == 1) {
xs[0] = BoolExpr_IncRef(items0[0]);
Expand All @@ -53,20 +53,20 @@ _commutative_binify(BoolExpr *op)
}


static BoolExpr *
_eq_binify(BoolExpr *op)
static struct BoolExpr *
_eq_binify(struct BoolExpr *op)
{
if (op->data.xs->length == 2) {
return BoolExpr_IncRef(op);
}
else {
size_t length;
BoolExpr **xs;
BoolExpr *temp;
BoolExpr *y;
struct BoolExpr **xs;
struct BoolExpr *temp;
struct BoolExpr *y;

length = (op->data.xs->length * (op->data.xs->length - 1)) >> 1;
xs = (BoolExpr **) malloc(length * sizeof(BoolExpr *));
xs = (struct BoolExpr **) malloc(length * sizeof(struct BoolExpr *));

for (size_t i = 0, index = 0; i < (op->data.xs->length - 1); ++i) {
for (size_t j = i+1; j < op->data.xs->length; ++j, ++index) {
Expand Down Expand Up @@ -104,14 +104,14 @@ _eq_binify(BoolExpr *op)
}


static BoolExpr *
_fixed_binify(BoolExpr *op)
static struct BoolExpr *
_fixed_binify(struct BoolExpr *op)
{
return BoolExpr_IncRef(op);
}


static BoolExpr * (*_op_binify[16])(BoolExpr *ex) = {
static struct BoolExpr * (*_op_binify[16])(struct BoolExpr *ex) = {
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,

Expand All @@ -127,15 +127,15 @@ static BoolExpr * (*_op_binify[16])(BoolExpr *ex) = {
};


BoolExpr *
BoolExpr_ToBinary(BoolExpr *ex)
struct BoolExpr *
BoolExpr_ToBinary(struct BoolExpr *ex)
{
if (IS_ATOM(ex)) {
return BoolExpr_IncRef(ex);
}
else {
BoolExpr *temp;
BoolExpr *y;
struct BoolExpr *temp;
struct BoolExpr *y;

CHECK_NULL(temp, _op_transform(ex, BoolExpr_ToBinary));
CHECK_NULL_1(y, _op_binify[temp->type](temp), temp);
Expand Down

0 comments on commit da3bdd5

Please sign in to comment.