Skip to content

Commit

Permalink
Revert "add pointer-sized opaque format character p"
Browse files Browse the repository at this point in the history
This reverts commit a95c629.
  • Loading branch information
troydhanson committed Dec 4, 2014
1 parent a95c629 commit c304850
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 54 deletions.
29 changes: 9 additions & 20 deletions src/tpl.c
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2014, Troy D. Hanson http://troydhanson.github.io/tpl/
Copyright (c) 2005-2013, Troy D. Hanson http://troydhanson.github.com/tpl/
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand All @@ -21,7 +21,10 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#define TPL_VERSION 1.6.1
#define TPL_VERSION 1.6

static const char id[]="$Id: tpl.c 192 2009-04-24 10:35:30Z thanson $";


#include <stdlib.h> /* malloc */
#include <stdarg.h> /* va_list */
Expand Down Expand Up @@ -107,7 +110,6 @@ typedef unsigned __int64 uint64_t;
#define TPL_TYPE_INT16 10
#define TPL_TYPE_UINT16 11
#define TPL_TYPE_POUND 12
#define TPL_TYPE_PTR 13

/* error codes */
#define ERR_NOT_MINSIZE (-1)
Expand Down Expand Up @@ -228,9 +230,9 @@ tpl_hook_t tpl_hook = {
/* .gather_max = */ 0 /* max tpl size (bytes) for tpl_gather */
};

static const char tpl_fmt_chars[] = "AS($)BiucsfIUjv#p"; /* valid format chars */
static const char tpl_S_fmt_chars[] = "iucsfIUjv#$()p"; /* valid within S(...) */
static const char tpl_datapeek_ok_chars[] = "iucsfIUjvp"; /* valid in datapeek */
static const char tpl_fmt_chars[] = "AS($)BiucsfIUjv#"; /* valid format chars */
static const char tpl_S_fmt_chars[] = "iucsfIUjv#$()"; /* valid within S(...) */
static const char tpl_datapeek_ok_chars[] = "iucsfIUjv"; /* valid in datapeek */
static const struct tpl_type_t tpl_types[] = {
/* [TPL_TYPE_ROOT] = */ {'r', 0},
/* [TPL_TYPE_INT32] = */ {'i', sizeof(int32_t)},
Expand All @@ -245,7 +247,6 @@ static const struct tpl_type_t tpl_types[] = {
/* [TPL_TYPE_INT16] = */ {'j', sizeof(int16_t)},
/* [TPL_TYPE_UINT16] = */ {'v', sizeof(uint16_t)},
/* [TPL_TYPE_POUND] = */ {'#', 0},
/* [TPL_TYPE_PTR] = */ {'p', sizeof(void*)},
};

/* default error-reporting function. Just writes to stderr. */
Expand Down Expand Up @@ -355,7 +356,6 @@ TPL_API tpl_node *tpl_map_va(char *fmt, va_list ap) {
case 'I':
case 'U':
case 'f':
case 'p':
if (*c=='c') t=TPL_TYPE_BYTE;
else if (*c=='i') t=TPL_TYPE_INT32;
else if (*c=='u') t=TPL_TYPE_UINT32;
Expand All @@ -364,7 +364,6 @@ TPL_API tpl_node *tpl_map_va(char *fmt, va_list ap) {
else if (*c=='I') t=TPL_TYPE_INT64;
else if (*c=='U') t=TPL_TYPE_UINT64;
else if (*c=='f') t=TPL_TYPE_DOUBLE;
else if (*c=='p') t=TPL_TYPE_PTR;

if (expect_lparen) goto fail;
n = tpl_node_new(parent);
Expand Down Expand Up @@ -418,7 +417,7 @@ TPL_API tpl_node *tpl_map_va(char *fmt, va_list ap) {
t == TPL_TYPE_UINT32 || t == TPL_TYPE_DOUBLE ||
t == TPL_TYPE_UINT64 || t == TPL_TYPE_INT64 ||
t == TPL_TYPE_UINT16 || t == TPL_TYPE_INT16 ||
t == TPL_TYPE_STR || t == TPL_TYPE_PTR )) goto fail;
t == TPL_TYPE_STR )) goto fail;
}
/* count up how many contiguous # and form their product */
pound_prod=1;
Expand Down Expand Up @@ -630,7 +629,6 @@ static void tpl_free_keep_map(tpl_node *r) {
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_POUND:
case TPL_TYPE_PTR:
find_next_node=1;
break;
case TPL_TYPE_ARY:
Expand Down Expand Up @@ -728,7 +726,6 @@ TPL_API void tpl_free(tpl_node *r) {
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_POUND:
case TPL_TYPE_PTR:
tpl_hook.free(c->data);
find_next_node=1;
break;
Expand Down Expand Up @@ -860,7 +857,6 @@ static void *tpl_dump_atyp(tpl_node *n, tpl_atyp* at, void *dv) {
case TPL_TYPE_UINT64:
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_PTR:
dv = tpl_cpv(dv,datav,tpl_types[c->type].sz * c->num);
datav = (void*)((uintptr_t)datav + tpl_types[c->type].sz * c->num);
break;
Expand Down Expand Up @@ -934,7 +930,6 @@ static size_t tpl_ser_osz(tpl_node *n) {
case TPL_TYPE_UINT64:
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_PTR:
sz += tpl_types[c->type].sz * c->num;
break;
case TPL_TYPE_BIN:
Expand Down Expand Up @@ -1105,7 +1100,6 @@ static int tpl_dump_to_mem(tpl_node *r,void *addr,size_t sz) {
case TPL_TYPE_UINT64:
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_PTR:
dv = tpl_cpv(dv,c->data,tpl_types[c->type].sz * c->num);
break;
case TPL_TYPE_BIN:
Expand Down Expand Up @@ -1587,7 +1581,6 @@ static void tpl_free_atyp(tpl_node *n, tpl_atyp *atyp) {
case TPL_TYPE_UINT64:
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_PTR:
dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz*c->num);
break;
case TPL_TYPE_BIN:
Expand Down Expand Up @@ -1666,7 +1659,6 @@ static int tpl_serlen(tpl_node *r, tpl_node *n, void *dv, size_t *serlen) {
case TPL_TYPE_UINT64:
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_PTR:
for(fidx=0; fidx < c->num; fidx++) { /* octothorpe support */
if ((uintptr_t)dv + tpl_types[c->type].sz > buf_past) return -1;
dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz);
Expand Down Expand Up @@ -1819,7 +1811,6 @@ TPL_API int tpl_pack(tpl_node *r, int i) {
case TPL_TYPE_UINT64:
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_PTR:
/* no need to use fidx iteration here; we can copy multiple values in one memcpy */
memcpy(child->data,child->addr,tpl_types[child->type].sz * child->num);
if (datav) datav = tpl_cpv(datav,child->data,tpl_types[child->type].sz * child->num);
Expand Down Expand Up @@ -1998,7 +1989,6 @@ TPL_API int tpl_unpack(tpl_node *r, int i) {
case TPL_TYPE_UINT64:
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_PTR:
/* unpack elements of cross-endian octothorpic array individually */
if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) {
for(fidx=0; fidx < c->num; fidx++) {
Expand Down Expand Up @@ -2111,7 +2101,6 @@ static int tpl_unpackA0(tpl_node *r) {
case TPL_TYPE_UINT64:
case TPL_TYPE_INT16:
case TPL_TYPE_UINT16:
case TPL_TYPE_PTR:
for(fidx=0;fidx < c->num; fidx++) {
dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tpl.h
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2014, Troy D. Hanson http://troydhanson.github.io/tpl/
Copyright (c) 2005-2013, Troy D. Hanson http://troydhanson.github.com/tpl/
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Expand Up @@ -36,7 +36,7 @@ PROGS = test1 test2 test3 test4 test5 test6 test7 test8 \
test97 test98 test99 test100 test101 test102 test103 test104 \
test105 test106 test107 test108 test109 test110 test111 test112 \
test113 test114 test115 test116 test117 test118 test119 test120 \
test121 test122 test123 test124 test125 test126
test121 test122 test123 test124 test125

TPLSRC = ../src
CFLAGS = -I$(TPLSRC) -g
Expand Down
3 changes: 0 additions & 3 deletions tests/test126.ans

This file was deleted.

29 changes: 0 additions & 29 deletions tests/test126.c

This file was deleted.

0 comments on commit c304850

Please sign in to comment.