summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-10-17 08:17:49 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-10-17 08:17:49 -0700
commit9f158a44b7e88c1dcfb8d56f4f85d642fc423b59 (patch)
tree336dc9997f047c3ea954312b3dbc715157de0b67
parent499f04dc4f9f864071d6ff7e75c9cbec60e2fd12 (diff)
downloadtxr-9f158a44b7e88c1dcfb8d56f4f85d642fc423b59.tar.gz
txr-9f158a44b7e88c1dcfb8d56f4f85d642fc423b59.tar.bz2
txr-9f158a44b7e88c1dcfb8d56f4f85d642fc423b59.zip
Purge stray occurrences of "void *" from code base.
* lib.c (cobj_print_op): In the format call, cast the C pointer to val, since the ~p conversion now takes a val rather than void *. (cptr_equal_op, obj_print, obj_pprint): Remove cast to void *, since obj now already has the type that ~p expects. * lib.h (struct any): Use mem_t * instead of void *. * parser.h (yyscan_t): Repeat the definition from inside the Flex-generated lex.yy.c. (yylex_init, yylex_destroy, yyget_extra, yyset_extra): Re-declare using yyscan_t typedef in place of void *. * parser.l (yyget_column, yyerrprepf): Re-declare using yyscan_t. (grammar): Use yyg in place of yyscanner in calls to yyerrprepf. * parser.y (yylex, %lex-param): Use yyscan_t instead of void *. (parse): Use yyscan_t for local variable. * signal.c (stack): Change type from void * to mem_t *. * stream.c (vformat): Conversion specifier p extracts val instead of void *. (run): Use casts that only remove const, not all the way to void *. * txr.1: Documented p conversion specifier of format. * Makefile (OBJS-y): Initialize with := to make sure it is a simple variable, and not a macro. (SRCS): New variable, listing source files. (enforce): New rule for enforcing coding conventions. Currently checks for void * occurrences.
-rw-r--r--ChangeLog37
-rw-r--r--Makefile12
-rw-r--r--lib.c10
-rw-r--r--lib.h2
-rw-r--r--parser.h13
-rw-r--r--parser.l24
-rw-r--r--parser.y8
-rw-r--r--signal.c2
-rw-r--r--stream.c13
-rw-r--r--txr.18
10 files changed, 96 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index facc151b..5d6fc509 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2014-10-17 Kaz Kylheku <kaz@kylheku.com>
+
+ Purge stray occurrences of "void *" from code base.
+
+ * lib.c (cobj_print_op): In the format call, cast
+ the C pointer to val, since the ~p conversion now
+ takes a val rather than void *.
+ (cptr_equal_op, obj_print, obj_pprint): Remove cast to
+ void *, since obj now already has the type that ~p expects.
+
+ * lib.h (struct any): Use mem_t * instead of void *.
+
+ * parser.h (yyscan_t): Repeat the definition from inside
+ the Flex-generated lex.yy.c.
+ (yylex_init, yylex_destroy, yyget_extra, yyset_extra): Re-declare
+ using yyscan_t typedef in place of void *.
+
+ * parser.l (yyget_column, yyerrprepf): Re-declare using yyscan_t.
+ (grammar): Use yyg in place of yyscanner in calls to yyerrprepf.
+
+ * parser.y (yylex, %lex-param): Use yyscan_t instead of void *.
+ (parse): Use yyscan_t for local variable.
+
+ * signal.c (stack): Change type from void * to mem_t *.
+
+ * stream.c (vformat): Conversion specifier p extracts val
+ instead of void *.
+ (run): Use casts that only remove const, not all the way to void *.
+
+ * txr.1: Documented p conversion specifier of format.
+
+ * Makefile (OBJS-y): Initialize with := to make sure it is a
+ simple variable, and not a macro.
+ (SRCS): New variable, listing source files.
+ (enforce): New rule for enforcing coding conventions.
+ Currently checks for void * occurrences.
+
2014-10-16 Kaz Kylheku <kaz@kylheku.com>
* arith.c (gcd): Fix semantics. If either operand is
diff --git a/Makefile b/Makefile
index b2f5b936..a68fd849 100644
--- a/Makefile
+++ b/Makefile
@@ -35,11 +35,14 @@ CFLAGS := $(filter-out -Wmissing-prototypes -Wstrict-prototypes,$(CFLAGS))
endif
# TXR objects
+OBJS-y := # make sure OBJ-y is a value variable, not a macro variable
OBJS := txr.o lex.yy.o y.tab.o match.o lib.o regex.o gc.o unwind.o stream.o
OBJS += arith.o hash.o utf8.o filter.o eval.o rand.o combi.o sysif.o
OBJS-$(debug_support) += debug.o
OBJS-$(have_syslog) += syslog.o
OBJS-$(have_posix_sigs) += signal.o
+SRCS := $(filter-out lex.yy.c y.tab.c y.tab.h,\
+ $(shell git ls-files "*.c" "*.h" "*.l" "*.y"))
# MPI objects
MPI_OBJ_BASE=mpi.o mplogic.o
@@ -147,6 +150,15 @@ tests/011/%: TXR_DBG_OPTS :=
%.expected: %.txr
./$(PROG) $(TXR_OPTS) $^ $(TXR_ARGS) > $@
+.PHONY: enforce
+enforce:
+ @if [ $$(grep -E '\<void[\t ]*\*' $(SRCS) | wc -l) -ne 1 ] ; then \
+ echo "New 'void *' occurrences have been found:" ; \
+ grep -n -E '\<void[\t ]*\*' $(SRCS) \
+ | grep -v -F 'typedef void *yyscan_t' ; \
+ exit 1 ; \
+ fi
+
#
# Installation macro.
#
diff --git a/lib.c b/lib.c
index 4b929c97..33717864 100644
--- a/lib.c
+++ b/lib.c
@@ -5177,7 +5177,7 @@ void cobj_print_op(val obj, val out)
{
put_string(lit("#<"), out);
obj_print(obj->co.cls, out);
- format(out, lit(": ~p>"), obj->co.handle, nao);
+ format(out, lit(": ~p>"), (val) obj->co.handle, nao);
}
static val cptr_equal_op(val left, val right)
@@ -6555,11 +6555,11 @@ finish:
obj->co.ops->print(obj, out);
return obj;
case ENV:
- format(out, lit("#<environment: ~p>"), (void *) obj, nao);
+ format(out, lit("#<environment: ~p>"), obj, nao);
return obj;
}
- format(out, lit("#<garbage: ~p>"), (void *) obj, nao);
+ format(out, lit("#<garbage: ~p>"), obj, nao);
return obj;
}
@@ -6686,11 +6686,11 @@ finish:
obj->co.ops->print(obj, out);
return obj;
case ENV:
- format(out, lit("#<environment: ~p>"), (void *) obj, nao);
+ format(out, lit("#<environment: ~p>"), obj, nao);
return obj;
}
- format(out, lit("#<garbage: ~p>"), (void *) obj, nao);
+ format(out, lit("#<garbage: ~p>"), obj, nao);
return obj;
}
diff --git a/lib.h b/lib.h
index fd4763e0..f9c7e0bf 100644
--- a/lib.h
+++ b/lib.h
@@ -73,7 +73,7 @@ typedef unsigned char mem_t;
struct any {
obj_common;
- void *dummy[2];
+ mem_t *dummy[2];
val next; /* GC free list */
};
diff --git a/parser.h b/parser.h
index 532fbfb1..e9003039 100644
--- a/parser.h
+++ b/parser.h
@@ -36,6 +36,11 @@ typedef struct {
scanner_t *scanner;
} parser_t;
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void *yyscan_t;
+#endif
+
extern const wchar_t *spec_file;
extern val form_to_ln_hash;
void yyerror(scanner_t *scanner, parser_t *, const char *s);
@@ -44,10 +49,10 @@ void yyerrorf(scanner_t *scanner, val s, ...);
void yybadtoken(parser_t *, int tok, val context);
void end_of_regex(scanner_t *scanner);
void end_of_char(scanner_t *scanner);
-int yylex_init(void **pscanner);
-int yylex_destroy(void *scanner);
-parser_t *yyget_extra(void *scanner);
-void yyset_extra(parser_t *, void *scanner);
+int yylex_init(yyscan_t *pscanner);
+int yylex_destroy(yyscan_t scanner);
+parser_t *yyget_extra(yyscan_t scanner);
+void yyset_extra(parser_t *, yyscan_t);
void parse_init(void);
void open_txr_file(val spec_file, val *name, val *stream);
int parse(val stream, val name, parser_t *parser);
diff --git a/parser.l b/parser.l
index d17b0c01..be447af2 100644
--- a/parser.l
+++ b/parser.l
@@ -75,8 +75,8 @@ int yylex_destroy(void)
#endif
/* Missing prototypes not generated by flex. */
-int yyget_column(void *);
-void yyset_column (int column_no , yyscan_t yyscanner);
+int yyget_column(yyscan_t);
+void yyset_column (int column_no, yyscan_t yyscanner);
void yyerror(scanner_t *scanner, parser_t *parser, const char *s)
{
@@ -103,7 +103,7 @@ void yyerrorf(scanner_t *scanner, val fmt, ...)
parser->errors++;
}
-static void yyerrprepf(void *scanner, val fmt, ...)
+static void yyerrprepf(scanner_t *scanner, val fmt, ...)
{
parser_t *parser = yyget_extra(scanner);
@@ -689,13 +689,13 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
}
<SPECIAL,QSPECIAL,NESTED,BRACED>{UANYN} {
- yyerrprepf(yyscanner, lit("bad character in directive: '~a'"),
+ yyerrprepf(yyg, lit("bad character in directive: '~a'"),
string_utf8(yytext), nao);
return ERRTOK;
}
<SPECIAL,QSPECIAL,NESTED,BRACED>. {
- yyerrprepf(yyscanner, lit("non-UTF-8 byte in directive: '\\x~02x'"),
+ yyerrprepf(yyg, lit("non-UTF-8 byte in directive: '\\x~02x'"),
num((unsigned char) yytext[0]), nao);
return ERRTOK;
}
@@ -727,7 +727,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
<REGEX>\n {
yyextra->lineno++;
- yyerrprepf(yyscanner, lit("newline in regex"), nao);
+ yyerrprepf(yyg, lit("newline in regex"), nao);
return ERRTOK;
}
@@ -752,7 +752,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
}
<REGEX>[\\] {
- yyerrprepf(yyscanner, lit("dangling backslash in regex"), nao);
+ yyerrprepf(yyg, lit("dangling backslash in regex"), nao);
return ERRTOK;
}
@@ -764,7 +764,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
}
<REGEX>. {
- yyerrprepf(yyscanner, lit("non-UTF-8 byte in regex: '\\x~02x'"),
+ yyerrprepf(yyg, lit("non-UTF-8 byte in regex: '\\x~02x'"),
num((unsigned char) yytext[0]), nao);
return ERRTOK;
}
@@ -857,21 +857,21 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
}
<STRLIT>\n {
- yyerrprepf(yyscanner, lit("newline in string literal"), nao);
+ yyerrprepf(yyg, lit("newline in string literal"), nao);
yyextra->lineno++;
yylval->chr = yytext[0];
return ERRTOK;
}
<CHRLIT>\n {
- yyerrprepf(yyscanner, lit("newline in character literal"), nao);
+ yyerrprepf(yyg, lit("newline in character literal"), nao);
yyextra->lineno++;
yylval->chr = yytext[0];
return ERRTOK;
}
<QSILIT>\n {
- yyerrprepf(yyscanner, lit("newline in string quasiliteral"), nao);
+ yyerrprepf(yyg, lit("newline in string quasiliteral"), nao);
yyextra->lineno++;
yylval->chr = yytext[0];
return ERRTOK;
@@ -898,7 +898,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
}
<STRLIT,CHRLIT,QSILIT,WLIT,QWLIT>. {
- yyerrprepf(yyscanner, lit("non-UTF-8 byte in literal: '\\x~02x'"),
+ yyerrprepf(yyg, lit("non-UTF-8 byte in literal: '\\x~02x'"),
num((unsigned char) yytext[0]), nao);
return ERRTOK;
}
diff --git a/parser.y b/parser.y
index fb2ff6ea..f0c80f39 100644
--- a/parser.y
+++ b/parser.y
@@ -60,7 +60,7 @@ static val make_expr(parser_t *, val sym, val rest, val lineno);
#if YYBISON
union YYSTYPE;
-int yylex(union YYSTYPE *, void *scanner);
+int yylex(union YYSTYPE *, yyscan_t scanner);
#endif
#define rl(form, line) rlrec(parser, form, line)
@@ -74,7 +74,7 @@ int yylex(union YYSTYPE *, void *scanner);
%pure-parser
%parse-param{scanner_t *scnr}
%parse-param{parser_t *parser}
-%lex-param{void *scnr}
+%lex-param{yyscan_t scnr}
%union {
wchar_t *lexeme;
@@ -979,7 +979,7 @@ not_a_clause : ALL { $$ = mkexp(all_s, nil, num(parser->lineno)); }
%%
-int yylex(YYSTYPE *, void *scanner);
+int yylex(YYSTYPE *, yyscan_t scanner);
/* C99 inline instantiations. */
#if __STDC_VERSION__ >= 199901L
@@ -1354,7 +1354,7 @@ void yybadtoken(parser_t *parser, int tok, val context)
int parse(val stream, val name, parser_t *parser)
{
int res;
- void *scanner;
+ yyscan_t scanner;
parser->lineno = 1;
parser->errors = 0;
diff --git a/signal.c b/signal.c
index e900f536..b81f2196 100644
--- a/signal.c
+++ b/signal.c
@@ -179,7 +179,7 @@ void sig_init(void)
#if HAVE_SIGALTSTACK
-static void *stack;
+static mem_t *stack;
static void setup_alt_stack(void)
{
diff --git a/stream.c b/stream.c
index 48943fb4..7d2b39bb 100644
--- a/stream.c
+++ b/stream.c
@@ -1511,7 +1511,6 @@ val vformat(val stream, val fmtstr, va_list vl)
int width = 0, precision = 0, precision_p = 0, digits = 0;
int left = 0, sign = 0, zeropad = 0;
cnum value;
- void *ptr;
for (;;) {
val obj;
@@ -1810,9 +1809,11 @@ val vformat(val stream, val fmtstr, va_list vl)
obj_print(obj, stream);
continue;
case 'p':
- ptr = va_arg(vl, void *);
- value = (cnum) ptr;
- sprintf(num_buf, num_fmt->hex, value);
+ {
+ val ptr = va_arg(vl, val);
+ value = (cnum) ptr;
+ sprintf(num_buf, num_fmt->hex, value);
+ }
goto output_num;
default:
uw_throwf(error_s, lit("unknown format directive character ~s\n"),
@@ -2350,8 +2351,8 @@ static val run(val command, val args)
status = _wspawnvp(_P_WAIT, c_str(command), wargv);
for (i = 0; i < nargs; i++)
- free((void *) wargv[i]);
- free((void *) wargv);
+ free((wchar_t *) wargv[i]);
+ free((wchar_t **) wargv);
rel1(&args);
diff --git a/txr.1 b/txr.1
index e7097a20..4541c485 100644
--- a/txr.1
+++ b/txr.1
@@ -21007,6 +21007,14 @@ Exactly that many digits are printed, regardless of the precision of the
number. If the precision is omitted, then the number of digits after the
decimal point is three. If the precision is zero, then a decimal portion is
truncated off entirely, including the decimal point.
+
+.coIP p
+The
+.code p
+directive prints a numeric representation in hexadecimal of the bit pattern
+of the object, which is meaningful to someone familiar with the internals
+of \*(TX. If the object is a pointer to heaped data, that value
+has a correspondence to its address.
.RE
.PP