From b78c59b29c46210ccbfc0fe4815b4e49fba8817b Mon Sep 17 00:00:00 2001 From: ian Date: Fri, 6 Sep 2002 19:25:57 +0000 Subject: [PATCH 1/1] Better integration with tclreadline. Less recompilation of serpent.[ch]. --- base/chiark-tcl.h | 2 +- base/enum.c | 48 ++++++++++++++++++++++++++++++++-------- base/hook.c | 19 ++++++++++++++++ base/tables-examples.tct | 10 +++++++++ base/tcmdifgen | 28 ++++++++++++++--------- base/troglodyte-Makefile | 3 +++ hbytes/hbytes.c | 2 +- hbytes/hbytes.h | 2 +- hbytes/hook.c | 19 ++++++++++++++++ 9 files changed, 111 insertions(+), 22 deletions(-) diff --git a/base/chiark-tcl.h b/base/chiark-tcl.h index 15abca2..86b2dba 100644 --- a/base/chiark-tcl.h +++ b/base/chiark-tcl.h @@ -78,7 +78,7 @@ void hbytes_empty(HBytes_Value *returns); void hbytes_sentinel(HBytes_Value *returns); void hbytes_array(HBytes_Value *returns, const Byte *array, int l); Byte *hbytes_arrayspace(HBytes_Value *returns, int l); -void hbytes_free(HBytes_Value *frees); +void hbytes_free(const HBytes_Value *frees); /* _empty, _sentinel and _array do not free or read the old value; * _free it first if needed. _free leaves it garbage, so you * have to call _empty to reuse it. _arrayspace doesn't fill diff --git a/base/enum.c b/base/enum.c index a4e9de7..8041cd3 100644 --- a/base/enum.c +++ b/base/enum.c @@ -28,6 +28,35 @@ Tcl_ObjType enum1_nearlytype = { 0, enum_nt_dup, enum_nt_ustr, enum_nt_sfa }; +static void report_bad(Tcl_Interp *ip, const char *what, const char *supplied, + const void *first, size_t each, + int (*isvalid)(const void *entry), + void (*appres)(Tcl_Interp *ip, const void *entry)) { + int count, i; + const Byte *entry; + + for (entry=first; isvalid(entry); entry+=each); + count= (entry - (const Byte*)first) / each; + + Tcl_ResetResult(ip); + Tcl_AppendResult(ip, "bad ",what," \"",supplied,"\": must be",(char*)0); + + for (i=0, entry=first; i hb + zeroes + length int + => hb + random + length int + => hb + +#Table udp UDP_SubCommand +# create +# diff --git a/base/tcmdifgen b/base/tcmdifgen index 514dc01..90f0818 100755 --- a/base/tcmdifgen +++ b/base/tcmdifgen @@ -162,6 +162,10 @@ foreach $c_table (sort keys %tables) { $any_mand= 0; $any_optl= 0; $any_eerr= 0; + $any_eargc= 0; + $pa_hint= ''; + $pa_hint .= "$c_table " if length $c_table; + $pa_hint.= $c_entry; foreach $arg (@{ $r_entry->{A} }) { $n= $arg->{N}; $t= $arg->{T}; @@ -169,18 +173,19 @@ foreach $c_table (sort keys %tables) { push @do_al, make_decl($n, $t, $arg->{A}); $pa_vars .= make_decl_init("a_$n", $t, $a, \$pa_init); if ($arg->{O}) { + $pa_hint .= " ?$n?"; if ($any_mand) { - $pa_argc .= " if (objc < $any_mand) {". - " e=\"too few args\"; goto e_err; }\n"; - $pa_body .= " objc -= $any_mand;\n"; $any_mand= 0; $any_eerr= 1; } $pa_body .= " if (!objc--) goto end_optional;\n"; $any_optl= 1; } else { - die if $any_optl; + $pa_hint .= " $n"; + $pa_body .= " if (!objc--) goto wrong_count_args;\n"; $any_mand++; + $any_eargc= 1; + die if $any_optl; } $paarg= "&a_$n"; $pafin= ''; @@ -202,18 +207,15 @@ foreach $c_table (sort keys %tables) { push @do_aa, "a_$n"; } if (exists $r_entry->{V}) { - if ($any_mand) { - $pa_body .= " objc -= $any_mand;\n"; - } + $pa_hint .= " ..."; $va= $r_entry->{V}; push @do_al, subst_in_decl("${va}c", 'int @'); push @do_al, subst_in_decl("${va}v", 'Tcl_Obj *const *@'); push @do_aa, "objc+1", "objv-1"; } else { if (!$any_optl) { - $pa_argc .= " if (objc != $any_mand) {". - " e=\"wrong number of args\"; goto e_err; }\n"; - $any_eerr= 1; + $pa_body .= " if (objc) goto wrong_count_args;\n"; + $any_eargc= 1; } } if ($any_optl) { @@ -236,6 +238,12 @@ foreach $c_table (sort keys %tables) { $pa_rslt .= "rc_err:\n"; $pa_fini .= " return rc;\n"; + if ($any_eargc) { + $pa_fini .= "\nwrong_count_args:\n"; + $pa_fini .= " e=\"wrong # args: should be \\\"$pa_hint\\\"\";\n"; + $pa_fini .= " goto e_err;"; + $any_eerr= 1; + } if ($any_eerr) { $pa_vars .= " const char *e;\n"; $pa_fini .= "\n"; diff --git a/base/troglodyte-Makefile b/base/troglodyte-Makefile index c557d80..33cace8 100644 --- a/base/troglodyte-Makefile +++ b/base/troglodyte-Makefile @@ -37,5 +37,8 @@ hbytes.so: $(OBJS) %.o: %.c $(HDRS) $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< +serpent.o: serpent.c serpent.h serpentsboxes.h + $(CC) $(CFLAGS) $(CPPFLAGS) -O3 -o $@ -c $< + clean: rm -f $(OBJS) $(TARGETS) *~ ./#*# diff --git a/hbytes/hbytes.c b/hbytes/hbytes.c index 41fc12a..6bb86c3 100644 --- a/hbytes/hbytes.c +++ b/hbytes/hbytes.c @@ -52,7 +52,7 @@ void hbytes_array(HBytes_Value *returns, const Byte *array, int l) { /* destructor */ -void hbytes_free(HBytes_Value *frees) { +void hbytes_free(const HBytes_Value *frees) { if (HBYTES_ISCOMPLEX(frees)) { HBytes_ComplexValue *cx= COMPLEX(frees); TFREE(cx->dstart - cx->prespace); diff --git a/hbytes/hbytes.h b/hbytes/hbytes.h index 15abca2..86b2dba 100644 --- a/hbytes/hbytes.h +++ b/hbytes/hbytes.h @@ -78,7 +78,7 @@ void hbytes_empty(HBytes_Value *returns); void hbytes_sentinel(HBytes_Value *returns); void hbytes_array(HBytes_Value *returns, const Byte *array, int l); Byte *hbytes_arrayspace(HBytes_Value *returns, int l); -void hbytes_free(HBytes_Value *frees); +void hbytes_free(const HBytes_Value *frees); /* _empty, _sentinel and _array do not free or read the old value; * _free it first if needed. _free leaves it garbage, so you * have to call _empty to reuse it. _arrayspace doesn't fill diff --git a/hbytes/hook.c b/hbytes/hook.c index 68df783..b6c0c9e 100644 --- a/hbytes/hook.c +++ b/hbytes/hook.c @@ -147,6 +147,25 @@ int do_hbytes_length(ClientData cd, Tcl_Interp *ip, return TCL_OK; } +int do_hbytes_random(ClientData cd, Tcl_Interp *ip, + int length, HBytes_Value *result) { + Byte *space; + int rc; + + space= hbytes_arrayspace(result, length); + rc= get_urandom(ip, space, length); + if (rc) { hbytes_free(result); return rc; } + return TCL_OK; +} + +int do_hbytes_zeroes(ClientData cd, Tcl_Interp *ip, + int length, HBytes_Value *result) { + Byte *space; + space= hbytes_arrayspace(result, length); + memset(space,0,length); + return TCL_OK; +} + int do__hbytes(ClientData cd, Tcl_Interp *ip, const HBytes_SubCommand *subcmd, int objc, Tcl_Obj *const *objv) { -- 2.30.2