diff options
Diffstat (limited to 'qpb')
| -rw-r--r-- | qpb/linear_allocator.h | 184 | ||||
| -rw-r--r-- | qpb/qpb.c | 1 | ||||
| -rw-r--r-- | qpb/qpb.h | 404 | ||||
| -rw-r--r-- | qpb/qpb_allocator.c | 28 | ||||
| -rw-r--r-- | qpb/qpb_allocator.h | 55 | 
5 files changed, 320 insertions, 352 deletions
diff --git a/qpb/linear_allocator.h b/qpb/linear_allocator.h index 273bc7369d..40393a9a96 100644 --- a/qpb/linear_allocator.h +++ b/qpb/linear_allocator.h @@ -40,42 +40,41 @@   */  #define LINEAR_ALLOCATOR_ALIGNMENT        8 -#define LINEAR_ALLOCATOR_ALIGN(value)					\ -  (((value) + LINEAR_ALLOCATOR_ALIGNMENT - 1) & ~(LINEAR_ALLOCATOR_ALIGNMENT - 1)); +#define LINEAR_ALLOCATOR_ALIGN(value)                                          \ +	(((value) + LINEAR_ALLOCATOR_ALIGNMENT - 1)                            \ +	 & ~(LINEAR_ALLOCATOR_ALIGNMENT - 1));  /*   * linear_allocator_align_ptr   */ -static inline char * -linear_allocator_align_ptr (char *ptr) +static inline char *linear_allocator_align_ptr(char *ptr)  { -  return (char *) LINEAR_ALLOCATOR_ALIGN ((intptr_t) ptr); +	return (char *)LINEAR_ALLOCATOR_ALIGN((intptr_t)ptr);  } -typedef struct linear_allocator_t_ -{ -  char *buf; - -  /* -   * Current location in the buffer. -   */ -  char *cur; - -  /* -   * End of buffer. -   */ -  char *end; - -  /* -   * Version number of the allocator, this is bumped up when the allocator -   * is reset and helps identifies bad frees. -   */ -  uint32_t version; - -  /* -   * The number of blocks that are currently allocated. -   */ -  int num_allocated; +typedef struct linear_allocator_t_ { +	char *buf; + +	/* +	 * Current location in the buffer. +	 */ +	char *cur; + +	/* +	 * End of buffer. +	 */ +	char *end; + +	/* +	 * Version number of the allocator, this is bumped up when the allocator +	 * is reset and helps identifies bad frees. +	 */ +	uint32_t version; + +	/* +	 * The number of blocks that are currently allocated. +	 */ +	int num_allocated;  } linear_allocator_t;  /* @@ -83,15 +82,14 @@ typedef struct linear_allocator_t_   *   * Header structure at the begining of each block.   */ -typedef struct linear_allocator_block_t_ -{ -  uint32_t flags; - -  /* -   * The version of the allocator when this block was allocated. -   */ -  uint32_t version; -  char data[0]; +typedef struct linear_allocator_block_t_ { +	uint32_t flags; + +	/* +	 * The version of the allocator when this block was allocated. +	 */ +	uint32_t version; +	char data[0];  } linear_allocator_block_t;  #define LINEAR_ALLOCATOR_BLOCK_IN_USE 0x01 @@ -104,36 +102,33 @@ typedef struct linear_allocator_block_t_   * The total amount of space a block will take in the buffer,   * including the size of the header.   */ -static inline size_t -linear_allocator_block_size (size_t user_size) +static inline size_t linear_allocator_block_size(size_t user_size)  { -  return LINEAR_ALLOCATOR_ALIGN (LINEAR_ALLOCATOR_HDR_SIZE + user_size); +	return LINEAR_ALLOCATOR_ALIGN(LINEAR_ALLOCATOR_HDR_SIZE + user_size);  }  /*   * linear_allocator_ptr_to_block   */ -static inline linear_allocator_block_t * -linear_allocator_ptr_to_block (void *ptr) +static inline linear_allocator_block_t *linear_allocator_ptr_to_block(void *ptr)  { -  void *block_ptr; -  block_ptr = ((char *) ptr) - offsetof (linear_allocator_block_t, data); -  return block_ptr; +	void *block_ptr; +	block_ptr = ((char *)ptr) - offsetof(linear_allocator_block_t, data); +	return block_ptr;  }  /*   * linear_allocator_init   */ -static inline void -linear_allocator_init (linear_allocator_t * allocator, char *buf, -		       size_t buf_len) +static inline void linear_allocator_init(linear_allocator_t *allocator, +					 char *buf, size_t buf_len)  { -  memset (allocator, 0, sizeof (*allocator)); +	memset(allocator, 0, sizeof(*allocator)); -  assert (linear_allocator_align_ptr (buf) == buf); -  allocator->buf = buf; -  allocator->cur = buf; -  allocator->end = buf + buf_len; +	assert(linear_allocator_align_ptr(buf) == buf); +	allocator->buf = buf; +	allocator->cur = buf; +	allocator->end = buf + buf_len;  }  /* @@ -143,64 +138,59 @@ linear_allocator_init (linear_allocator_t * allocator, char *buf,   *   * *** NOTE ** This implicitly frees all the blocks in the allocator.   */ -static inline void -linear_allocator_reset (linear_allocator_t *allocator) +static inline void linear_allocator_reset(linear_allocator_t *allocator)  { -  allocator->num_allocated = 0; -  allocator->version++; -  allocator->cur = allocator->buf; +	allocator->num_allocated = 0; +	allocator->version++; +	allocator->cur = allocator->buf;  }  /*   * linear_allocator_alloc   */ -static inline void * -linear_allocator_alloc (linear_allocator_t *allocator, size_t user_size) +static inline void *linear_allocator_alloc(linear_allocator_t *allocator, +					   size_t user_size)  { -  size_t block_size; -  linear_allocator_block_t *block; +	size_t block_size; +	linear_allocator_block_t *block; -  block_size = linear_allocator_block_size (user_size); +	block_size = linear_allocator_block_size(user_size); -  if (allocator->cur + block_size > allocator->end) -    { -      return NULL; -    } +	if (allocator->cur + block_size > allocator->end) { +		return NULL; +	} -  block = (linear_allocator_block_t *) allocator->cur; -  allocator->cur += block_size; +	block = (linear_allocator_block_t *)allocator->cur; +	allocator->cur += block_size; -  block->flags = LINEAR_ALLOCATOR_BLOCK_IN_USE; -  block->version = allocator->version; -  allocator->num_allocated++; -  return block->data; +	block->flags = LINEAR_ALLOCATOR_BLOCK_IN_USE; +	block->version = allocator->version; +	allocator->num_allocated++; +	return block->data;  }  /*   * linear_allocator_free   */ -static inline void -linear_allocator_free (linear_allocator_t *allocator, void *ptr) +static inline void linear_allocator_free(linear_allocator_t *allocator, +					 void *ptr)  { -  linear_allocator_block_t *block; - -  if (((char *) ptr) < allocator->buf || ((char *) ptr) >= allocator->end) -    { -      assert (0); -      return; -    } - -  block = linear_allocator_ptr_to_block (ptr); -  if (block->version != allocator->version) -    { -      assert (0); -      return; -    } - -  block->flags = block->flags & ~LINEAR_ALLOCATOR_BLOCK_IN_USE; - -  if (--allocator->num_allocated < 0) -    { -      assert (0); -    } +	linear_allocator_block_t *block; + +	if (((char *)ptr) < allocator->buf || ((char *)ptr) >= allocator->end) { +		assert(0); +		return; +	} + +	block = linear_allocator_ptr_to_block(ptr); +	if (block->version != allocator->version) { +		assert(0); +		return; +	} + +	block->flags = block->flags & ~LINEAR_ALLOCATOR_BLOCK_IN_USE; + +	if (--allocator->num_allocated < 0) { +		assert(0); +	}  } @@ -25,4 +25,3 @@  /*   * Main file for the qpb library.   */ - @@ -39,105 +39,103 @@   * qpb__address_family__set   */  #define qpb_address_family_set qpb__address_family__set -static inline int -qpb__address_family__set (Qpb__AddressFamily *pb_family, u_char family) +static inline int qpb__address_family__set(Qpb__AddressFamily *pb_family, +					   u_char family)  { -  switch (family) { -  case AF_INET: -    *pb_family = QPB__ADDRESS_FAMILY__IPV4; -    return 1; +	switch (family) { +	case AF_INET: +		*pb_family = QPB__ADDRESS_FAMILY__IPV4; +		return 1; -  case AF_INET6: -    *pb_family = QPB__ADDRESS_FAMILY__IPV6; -    return 1; +	case AF_INET6: +		*pb_family = QPB__ADDRESS_FAMILY__IPV6; +		return 1; -  default: -    *pb_family = QPB__ADDRESS_FAMILY__UNKNOWN_AF; -  } +	default: +		*pb_family = QPB__ADDRESS_FAMILY__UNKNOWN_AF; +	} -  return 0; +	return 0;  }  /*   * qpb__address_family__get   */  #define qpb_address_family_get qpb__address_family__get -static inline int -qpb__address_family__get (Qpb__AddressFamily pb_family, u_char *family) +static inline int qpb__address_family__get(Qpb__AddressFamily pb_family, +					   u_char *family)  { -  switch (pb_family) { -  case QPB__ADDRESS_FAMILY__IPV4: -    *family = AF_INET; -    return 1; +	switch (pb_family) { +	case QPB__ADDRESS_FAMILY__IPV4: +		*family = AF_INET; +		return 1; -  case QPB__ADDRESS_FAMILY__IPV6: -    *family = AF_INET6; -    return 1; +	case QPB__ADDRESS_FAMILY__IPV6: +		*family = AF_INET6; +		return 1; -  case QPB__ADDRESS_FAMILY__UNKNOWN_AF: -    return 0; -  default: /* protobuf "magic value" _QPB__ADDRESS_FAMILY_IS_INT_SIZE */ -    return 0; -  } +	case QPB__ADDRESS_FAMILY__UNKNOWN_AF: +		return 0; +	default: /* protobuf "magic value" _QPB__ADDRESS_FAMILY_IS_INT_SIZE */ +		return 0; +	} -  return 0; +	return 0;  }  /*   * qpb__l3_prefix__create   */  #define qpb_l3_prefix_create qpb__l3_prefix__create -static inline Qpb__L3Prefix * -qpb__l3_prefix__create (qpb_allocator_t *allocator, struct prefix *p) +static inline Qpb__L3Prefix *qpb__l3_prefix__create(qpb_allocator_t *allocator, +						    struct prefix *p)  { -  Qpb__L3Prefix *prefix; - -  prefix = QPB_ALLOC(allocator, typeof(*prefix)); -  if (!prefix) { -    return NULL; -  } -  qpb__l3_prefix__init(prefix); -  prefix->length = p->prefixlen; -  prefix->bytes.len = (p->prefixlen + 7)/8; -  prefix->bytes.data = qpb_alloc(allocator, prefix->bytes.len); -  if (!prefix->bytes.data) { -    return NULL; -  } - -  memcpy(prefix->bytes.data, &p->u.prefix, prefix->bytes.len); - -  return prefix; +	Qpb__L3Prefix *prefix; + +	prefix = QPB_ALLOC(allocator, typeof(*prefix)); +	if (!prefix) { +		return NULL; +	} +	qpb__l3_prefix__init(prefix); +	prefix->length = p->prefixlen; +	prefix->bytes.len = (p->prefixlen + 7) / 8; +	prefix->bytes.data = qpb_alloc(allocator, prefix->bytes.len); +	if (!prefix->bytes.data) { +		return NULL; +	} + +	memcpy(prefix->bytes.data, &p->u.prefix, prefix->bytes.len); + +	return prefix;  }  /*   * qpb__l3_prefix__get   */  #define qpb_l3_prefix_get qpb__l3_prefix__get -static inline int -qpb__l3_prefix__get (const Qpb__L3Prefix *pb_prefix, u_char family, -		     struct prefix *prefix) +static inline int qpb__l3_prefix__get(const Qpb__L3Prefix *pb_prefix, +				      u_char family, struct prefix *prefix)  { -  switch (family) -    { +	switch (family) { -    case AF_INET: -      memset(prefix, 0, sizeof(struct prefix_ipv4)); -      break; +	case AF_INET: +		memset(prefix, 0, sizeof(struct prefix_ipv4)); +		break; -    case AF_INET6: -      memset(prefix, 0, sizeof(struct prefix_ipv6)); -      break; +	case AF_INET6: +		memset(prefix, 0, sizeof(struct prefix_ipv6)); +		break; -    default: -      memset(prefix, 0, sizeof(*prefix)); -    } +	default: +		memset(prefix, 0, sizeof(*prefix)); +	} -  prefix->prefixlen = pb_prefix->length; -  prefix->family = family; -  memcpy(&prefix->u.prefix, pb_prefix->bytes.data, pb_prefix->bytes.len); -  return 1; +	prefix->prefixlen = pb_prefix->length; +	prefix->family = family; +	memcpy(&prefix->u.prefix, pb_prefix->bytes.data, pb_prefix->bytes.len); +	return 1;  }  /* @@ -146,103 +144,101 @@ qpb__l3_prefix__get (const Qpb__L3Prefix *pb_prefix, u_char family,   * Translate a quagga route type to a protobuf protocol.   */  #define qpb_protocol_set qpb__protocol__set -static inline int -qpb__protocol__set (Qpb__Protocol *pb_proto, int route_type) +static inline int qpb__protocol__set(Qpb__Protocol *pb_proto, int route_type)  { -  switch (route_type) { -  case ZEBRA_ROUTE_KERNEL: -    *pb_proto = QPB__PROTOCOL__KERNEL; -    break; - -  case ZEBRA_ROUTE_CONNECT: -    *pb_proto = QPB__PROTOCOL__CONNECTED; -    break; - -  case ZEBRA_ROUTE_STATIC: -    *pb_proto = QPB__PROTOCOL__STATIC; -    break; - -  case ZEBRA_ROUTE_RIP: -    *pb_proto = QPB__PROTOCOL__RIP; -    break; - -  case ZEBRA_ROUTE_RIPNG: -    *pb_proto = QPB__PROTOCOL__RIPNG; -    break; - -  case ZEBRA_ROUTE_OSPF: -  case ZEBRA_ROUTE_OSPF6: -    *pb_proto = QPB__PROTOCOL__OSPF; -    break; - -  case ZEBRA_ROUTE_ISIS: -    *pb_proto = QPB__PROTOCOL__ISIS; -    break; - -  case ZEBRA_ROUTE_BGP: -    *pb_proto = QPB__PROTOCOL__BGP; -    break; - -  case ZEBRA_ROUTE_HSLS: -  case ZEBRA_ROUTE_OLSR: -  case ZEBRA_ROUTE_MAX: -  case ZEBRA_ROUTE_SYSTEM: -  default: -    *pb_proto = QPB__PROTOCOL__OTHER; -  } - -  return 1; +	switch (route_type) { +	case ZEBRA_ROUTE_KERNEL: +		*pb_proto = QPB__PROTOCOL__KERNEL; +		break; + +	case ZEBRA_ROUTE_CONNECT: +		*pb_proto = QPB__PROTOCOL__CONNECTED; +		break; + +	case ZEBRA_ROUTE_STATIC: +		*pb_proto = QPB__PROTOCOL__STATIC; +		break; + +	case ZEBRA_ROUTE_RIP: +		*pb_proto = QPB__PROTOCOL__RIP; +		break; + +	case ZEBRA_ROUTE_RIPNG: +		*pb_proto = QPB__PROTOCOL__RIPNG; +		break; + +	case ZEBRA_ROUTE_OSPF: +	case ZEBRA_ROUTE_OSPF6: +		*pb_proto = QPB__PROTOCOL__OSPF; +		break; + +	case ZEBRA_ROUTE_ISIS: +		*pb_proto = QPB__PROTOCOL__ISIS; +		break; + +	case ZEBRA_ROUTE_BGP: +		*pb_proto = QPB__PROTOCOL__BGP; +		break; + +	case ZEBRA_ROUTE_HSLS: +	case ZEBRA_ROUTE_OLSR: +	case ZEBRA_ROUTE_MAX: +	case ZEBRA_ROUTE_SYSTEM: +	default: +		*pb_proto = QPB__PROTOCOL__OTHER; +	} + +	return 1;  }  /*   * qpb__ipv4_address__create   */  static inline Qpb__Ipv4Address * -qpb__ipv4_address__create (qpb_allocator_t *allocator, -			   struct in_addr *addr) +qpb__ipv4_address__create(qpb_allocator_t *allocator, struct in_addr *addr)  { -  Qpb__Ipv4Address *v4; +	Qpb__Ipv4Address *v4; -  v4 = QPB_ALLOC(allocator, typeof(*v4)); -  if (!v4) { -    return NULL; -  } -  qpb__ipv4_address__init(v4); +	v4 = QPB_ALLOC(allocator, typeof(*v4)); +	if (!v4) { +		return NULL; +	} +	qpb__ipv4_address__init(v4); -  v4->value = ntohl(addr->s_addr); -  return v4; +	v4->value = ntohl(addr->s_addr); +	return v4;  }  /*   * qpb__ipv4_address__get   */ -static inline int -qpb__ipv4_address__get (const Qpb__Ipv4Address *v4, struct in_addr *addr) +static inline int qpb__ipv4_address__get(const Qpb__Ipv4Address *v4, +					 struct in_addr *addr)  { -  addr->s_addr = htonl(v4->value); -  return 1; +	addr->s_addr = htonl(v4->value); +	return 1;  }  /*   * qpb__ipv6_address__create   */  static inline Qpb__Ipv6Address * -qpb__ipv6_address__create (qpb_allocator_t *allocator, struct in6_addr *addr) +qpb__ipv6_address__create(qpb_allocator_t *allocator, struct in6_addr *addr)  { -  Qpb__Ipv6Address *v6; +	Qpb__Ipv6Address *v6; -  v6 = QPB_ALLOC(allocator, typeof(*v6)); -  if (!v6) -    return NULL; +	v6 = QPB_ALLOC(allocator, typeof(*v6)); +	if (!v6) +		return NULL; -  qpb__ipv6_address__init(v6); -  v6->bytes.len = 16; -  v6->bytes.data = qpb_alloc(allocator, 16); -  if (!v6->bytes.data) -    return NULL; +	qpb__ipv6_address__init(v6); +	v6->bytes.len = 16; +	v6->bytes.data = qpb_alloc(allocator, 16); +	if (!v6->bytes.data) +		return NULL; -  memcpy(v6->bytes.data, addr->s6_addr, v6->bytes.len); -  return v6; +	memcpy(v6->bytes.data, addr->s6_addr, v6->bytes.len); +	return v6;  }  /* @@ -250,14 +246,14 @@ qpb__ipv6_address__create (qpb_allocator_t *allocator, struct in6_addr *addr)   *   * Read out information from a protobuf ipv6 address structure.   */ -static inline int -qpb__ipv6_address__get (const Qpb__Ipv6Address *v6, struct in6_addr *addr) +static inline int qpb__ipv6_address__get(const Qpb__Ipv6Address *v6, +					 struct in6_addr *addr)  { -  if (v6->bytes.len != 16) -    return 0; +	if (v6->bytes.len != 16) +		return 0; -  memcpy(addr->s6_addr, v6->bytes.data, v6->bytes.len); -  return 1; +	memcpy(addr->s6_addr, v6->bytes.data, v6->bytes.len); +	return 1;  }  /* @@ -265,34 +261,34 @@ qpb__ipv6_address__get (const Qpb__Ipv6Address *v6, struct in6_addr *addr)   */  #define qpb_l3_address_create qpb__l3_address__create  static inline Qpb__L3Address * -qpb__l3_address__create (qpb_allocator_t *allocator, union g_addr *addr, -			 u_char family) +qpb__l3_address__create(qpb_allocator_t *allocator, union g_addr *addr, +			u_char family)  { -  Qpb__L3Address *l3_addr; +	Qpb__L3Address *l3_addr; -  l3_addr = QPB_ALLOC(allocator, typeof(*l3_addr)); -  if (!l3_addr) -    return NULL; +	l3_addr = QPB_ALLOC(allocator, typeof(*l3_addr)); +	if (!l3_addr) +		return NULL; -  qpb__l3_address__init(l3_addr); +	qpb__l3_address__init(l3_addr); -  switch (family) { +	switch (family) { -  case AF_INET: -    l3_addr->v4 = qpb__ipv4_address__create (allocator, &addr->ipv4); -    if (!l3_addr->v4) -      return NULL; +	case AF_INET: +		l3_addr->v4 = qpb__ipv4_address__create(allocator, &addr->ipv4); +		if (!l3_addr->v4) +			return NULL; -    break; +		break; -  case AF_INET6: -    l3_addr->v6 = qpb__ipv6_address__create (allocator, &addr->ipv6); -    if (!l3_addr->v6) -      return NULL; +	case AF_INET6: +		l3_addr->v6 = qpb__ipv6_address__create(allocator, &addr->ipv6); +		if (!l3_addr->v6) +			return NULL; -    break; -  } -  return l3_addr; +		break; +	} +	return l3_addr;  }  /* @@ -301,25 +297,22 @@ qpb__l3_address__create (qpb_allocator_t *allocator, union g_addr *addr,   * Read out a gateway address from a protobuf l3 address.   */  #define qpb_l3_address_get qpb__l3_address__get -static inline int -qpb__l3_address__get (const Qpb__L3Address *l3_addr, -		      u_char *family, union g_addr *addr) +static inline int qpb__l3_address__get(const Qpb__L3Address *l3_addr, +				       u_char *family, union g_addr *addr)  { -  if (l3_addr->v4) -    { -      qpb__ipv4_address__get (l3_addr->v4, &addr->ipv4); -      *family = AF_INET; -      return 1; -    } - -  if (l3_addr->v6) -    { -      qpb__ipv6_address__get(l3_addr->v6, &addr->ipv6); -      *family = AF_INET6; -      return 1; -    } - -  return 0; +	if (l3_addr->v4) { +		qpb__ipv4_address__get(l3_addr->v4, &addr->ipv4); +		*family = AF_INET; +		return 1; +	} + +	if (l3_addr->v6) { +		qpb__ipv6_address__get(l3_addr->v6, &addr->ipv6); +		*family = AF_INET6; +		return 1; +	} + +	return 0;  }  /* @@ -327,18 +320,18 @@ qpb__l3_address__get (const Qpb__L3Address *l3_addr,   */  #define qpb_if_identifier_create qpb__if_identifier__create  static inline Qpb__IfIdentifier * -qpb__if_identifier__create (qpb_allocator_t *allocator, uint if_index) +qpb__if_identifier__create(qpb_allocator_t *allocator, uint if_index)  { -  Qpb__IfIdentifier *if_id; - -  if_id = QPB_ALLOC(allocator, typeof(*if_id)); -  if (!if_id) { -    return NULL; -  } -  qpb__if_identifier__init(if_id); -  if_id->has_index = 1; -  if_id->index = if_index; -  return if_id; +	Qpb__IfIdentifier *if_id; + +	if_id = QPB_ALLOC(allocator, typeof(*if_id)); +	if (!if_id) { +		return NULL; +	} +	qpb__if_identifier__init(if_id); +	if_id->has_index = 1; +	if_id->index = if_index; +	return if_id;  }  /* @@ -347,26 +340,25 @@ qpb__if_identifier__create (qpb_allocator_t *allocator, uint if_index)   * Get interface name and/or if_index from an if identifier.   */  #define qpb_if_identifier_get qpb__if_identifier__get -static inline int -qpb__if_identifier__get (Qpb__IfIdentifier *if_id, uint *if_index, -			 char **name) +static inline int qpb__if_identifier__get(Qpb__IfIdentifier *if_id, +					  uint *if_index, char **name)  { -  char *str; -  uint ix; +	char *str; +	uint ix; -  if (!if_index) -    if_index = &ix; +	if (!if_index) +		if_index = &ix; -  if (!name) -    name = &str; +	if (!name) +		name = &str; -  if (if_id->has_index) -    *if_index = if_id->index; -  else -    *if_index = 0; +	if (if_id->has_index) +		*if_index = if_id->index; +	else +		*if_index = 0; -  *name = if_id->name; -  return 1; +	*name = if_id->name; +	return 1;  }  #endif diff --git a/qpb/qpb_allocator.c b/qpb/qpb_allocator.c index ae48d55891..8b0ee941a5 100644 --- a/qpb/qpb_allocator.c +++ b/qpb/qpb_allocator.c @@ -29,38 +29,30 @@  /*   * _qpb_alloc   */ -static void * -_qpb_alloc (void *allocator_data, size_t size) +static void *_qpb_alloc(void *allocator_data, size_t size)  { -  return linear_allocator_alloc (allocator_data, size); +	return linear_allocator_alloc(allocator_data, size);  }  /*   * _qpb_free   */ -static void -_qpb_free (void *allocator_data, void *ptr) +static void _qpb_free(void *allocator_data, void *ptr)  { -  linear_allocator_free (allocator_data, ptr); +	linear_allocator_free(allocator_data, ptr);  } -static ProtobufCAllocator allocator_template = { -  _qpb_alloc, -  _qpb_free, -  NULL, -  8192, -  NULL -}; +static ProtobufCAllocator allocator_template = {_qpb_alloc, _qpb_free, NULL, +						8192, NULL};  /*   * qpb_allocator_init_linear   *   * Initialize qpb_allocator_t with the given linear allocator.   */ -void -qpb_allocator_init_linear (qpb_allocator_t *allocator, -			   linear_allocator_t *linear_allocator) +void qpb_allocator_init_linear(qpb_allocator_t *allocator, +			       linear_allocator_t *linear_allocator)  { -  *allocator = allocator_template; -  allocator->allocator_data = linear_allocator; +	*allocator = allocator_template; +	allocator->allocator_data = linear_allocator;  } diff --git a/qpb/qpb_allocator.h b/qpb/qpb_allocator.h index bdf2dc0e7f..c9022af713 100644 --- a/qpb/qpb_allocator.h +++ b/qpb/qpb_allocator.h @@ -41,10 +41,9 @@ typedef ProtobufCAllocator qpb_allocator_t;  /*   * qpb_alloc   */ -static inline void * -qpb_alloc (qpb_allocator_t *allocator, size_t size) +static inline void *qpb_alloc(qpb_allocator_t *allocator, size_t size)  { -  return allocator->alloc (allocator->allocator_data, size); +	return allocator->alloc(allocator->allocator_data, size);  }  /* @@ -52,19 +51,18 @@ qpb_alloc (qpb_allocator_t *allocator, size_t size)   *   * Allocate space for the specified number of pointers.   */ -static inline void * -qpb_alloc_ptr_array (qpb_allocator_t *allocator, size_t num_ptrs) +static inline void *qpb_alloc_ptr_array(qpb_allocator_t *allocator, +					size_t num_ptrs)  { -  return qpb_alloc (allocator, num_ptrs * sizeof (void *)); +	return qpb_alloc(allocator, num_ptrs * sizeof(void *));  }  /*   * qpb_free   */ -static inline void -qpb_free (qpb_allocator_t *allocator, void *ptr) +static inline void qpb_free(qpb_allocator_t *allocator, void *ptr)  { -  allocator->free (allocator->allocator_data, ptr); +	allocator->free(allocator->allocator_data, ptr);  }  /* @@ -74,39 +72,36 @@ qpb_free (qpb_allocator_t *allocator, void *ptr)   * incorrect size. It returns enough memory to store the given type,   * and evaluates to an appropriately typed pointer.   */ -#define QPB_ALLOC(allocator, type)		\ -  (type *) qpb_alloc(allocator, sizeof(type)) +#define QPB_ALLOC(allocator, type) (type *)qpb_alloc(allocator, sizeof(type))  /*   * Externs.   */ -extern void qpb_allocator_init_linear (qpb_allocator_t *, -				       struct linear_allocator_t_ *); +extern void qpb_allocator_init_linear(qpb_allocator_t *, +				      struct linear_allocator_t_ *);  /*   * The following macros are for the common case where a qpb allocator   * is being used alongside a linear allocator that allocates memory   * off of the stack.   */ -#define QPB_DECLARE_STACK_ALLOCATOR(allocator, size)	\ -    qpb_allocator_t allocator;				\ -    linear_allocator_t lin_ ## allocator;		\ -    char lin_ ## allocator ## _buf[size] +#define QPB_DECLARE_STACK_ALLOCATOR(allocator, size)                           \ +	qpb_allocator_t allocator;                                             \ +	linear_allocator_t lin_##allocator;                                    \ +	char lin_##allocator##_buf[size] -#define QPB_INIT_STACK_ALLOCATOR(allocator)				\ -  do									\ -    {									\ -      linear_allocator_init(&(lin_ ## allocator),			\ -			    lin_ ## allocator ## _buf,			\ -			    sizeof(lin_ ## allocator ## _buf));		\ -      qpb_allocator_init_linear(&allocator, &(lin_ ## allocator));	\ -    } while (0) +#define QPB_INIT_STACK_ALLOCATOR(allocator)                                    \ +	do {                                                                   \ +		linear_allocator_init(&(lin_##allocator),                      \ +				      lin_##allocator##_buf,                   \ +				      sizeof(lin_##allocator##_buf));          \ +		qpb_allocator_init_linear(&allocator, &(lin_##allocator));     \ +	} while (0) -#define QPB_RESET_STACK_ALLOCATOR(allocator)		\ -  do							\ -    {							\ -      linear_allocator_reset (&(lin_ ## allocator));	\ -    } while (0) +#define QPB_RESET_STACK_ALLOCATOR(allocator)                                   \ +	do {                                                                   \ +		linear_allocator_reset(&(lin_##allocator));                    \ +	} while (0)  #endif /* _QPB_ALLOCATOR_H_ */  | 
