From: Nicholas Clark Date: Sat, 22 Oct 2005 12:08:34 +0000 (+0000) Subject: Mark more static Encode data structures as const. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0629a5b339b45d14dcfb89e3642fe75983f27c16;p=p5sagit%2Fp5-mst-13.2.git Mark more static Encode data structures as const. p4raw-id: //depot/perl@25821 --- diff --git a/ext/Encode/Encode.xs b/ext/Encode/Encode.xs index 8e225cd..274fae0 100644 --- a/ext/Encode/Encode.xs +++ b/ext/Encode/Encode.xs @@ -89,7 +89,7 @@ do_fallback_cb(pTHX_ UV ch) } static SV * -encode_method(pTHX_ encode_t * enc, encpage_t * dir, SV * src, +encode_method(pTHX_ const encode_t * enc, const encpage_t * dir, SV * src, int check, STRLEN * offset, SV * term, int * retcode) { STRLEN slen; diff --git a/ext/Encode/Encode/encode.h b/ext/Encode/Encode/encode.h index 94764a6..7a2fa26 100644 --- a/ext/Encode/Encode/encode.h +++ b/ext/Encode/Encode/encode.h @@ -18,7 +18,7 @@ struct encpage_s /* fields ordered to pack nicely on 32-bit machines */ const U8 *seq; /* Packed output sequences we generate if we match */ - encpage_t *next; /* Page to go to if we match */ + const encpage_t *next; /* Page to go to if we match */ U8 min; /* Min value of octet to match this entry */ U8 max; /* Max value of octet to match this entry */ U8 dlen; /* destination length - @@ -60,10 +60,10 @@ struct encpage_s typedef struct encode_s encode_t; struct encode_s { - encpage_t *t_utf8; /* Starting table for translation from - the encoding to UTF-8 form */ - encpage_t *f_utf8; /* Starting table for translation - from UTF-8 to the encoding */ + const encpage_t *t_utf8; /* Starting table for translation from + the encoding to UTF-8 form */ + const encpage_t *f_utf8; /* Starting table for translation + from UTF-8 to the encoding */ const U8 *rep; /* Replacement character in this encoding e.g. "?" */ int replen; /* Number of octets in rep */ @@ -75,7 +75,7 @@ struct encode_s #ifdef U8 /* See comment at top of file for deviousness */ -extern int do_encode(encpage_t *enc, const U8 *src, STRLEN *slen, +extern int do_encode(const encpage_t *enc, const U8 *src, STRLEN *slen, U8 *dst, STRLEN dlen, STRLEN *dout, int approx, const U8 *term, STRLEN tlen); diff --git a/ext/Encode/bin/enc2xs b/ext/Encode/bin/enc2xs index da89552..ae2a166 100644 --- a/ext/Encode/bin/enc2xs +++ b/ext/Encode/bin/enc2xs @@ -279,7 +279,7 @@ if ($doC) my @info = ($e2u->{Cname},$u2e->{Cname},qq((U8 *)"$rep"),$replen,$min_el,$max_el); my $sym = "${enc}_encoding"; $sym =~ s/\W+/_/g; - print C "encode_t $sym = \n"; + print C "const encode_t $sym = \n"; # This is to make null encoding work -- dankogai for (my $i = (scalar @info) - 1; $i >= 0; --$i){ $info[$i] ||= 1; @@ -685,7 +685,7 @@ sub addstrings if ($a->{'Forward'}) { my $var = $^O eq 'MacOS' ? 'extern' : 'static'; - print $fh "$var encpage_t $name\[",scalar(@{$a->{'Entries'}}),"];\n"; + print $fh "$var const encpage_t $name\[",scalar(@{$a->{'Entries'}}),"];\n"; } $a->{'DoneStrings'} = 1; foreach my $b (@{$a->{'Entries'}}) @@ -773,7 +773,8 @@ sub outtable my ($s,$e,$out,$t,$end,$l) = @$b; outtable($fh,$t,$bigname) unless $t->{'Done'}; } - print $fh "\nstatic encpage_t $name\[",scalar(@{$a->{'Entries'}}),"] = {\n"; + print $fh "\nstatic const encpage_t $name\[", + scalar(@{$a->{'Entries'}}), "] = {\n"; foreach my $b (@{$a->{'Entries'}}) { my ($sc,$ec,$out,$t,$end,$l,$fb) = @$b; diff --git a/ext/Encode/encengine.c b/ext/Encode/encengine.c index 4ea0667..6fb65da 100644 --- a/ext/Encode/encengine.c +++ b/ext/Encode/encengine.c @@ -92,7 +92,7 @@ we add a flag to re-add the removed byte to the source we could handle #include "encode.h" int -do_encode(encpage_t * enc, const U8 * src, STRLEN * slen, U8 * dst, +do_encode(const encpage_t * enc, const U8 * src, STRLEN * slen, U8 * dst, STRLEN dlen, STRLEN * dout, int approx, const U8 *term, STRLEN tlen) { const U8 *s = src; @@ -102,7 +102,7 @@ do_encode(encpage_t * enc, const U8 * src, STRLEN * slen, U8 * dst, U8 *dend = d + dlen, *dlast = d; int code = 0; while (s < send) { - encpage_t *e = enc; + const encpage_t *e = enc; U8 byte = *s; while (byte > e->max) e++;