Skip to content

Commit b0ca10f

Browse files
rolandshoemakergopherbot
authored andcommitted
internal/language: bump script types to uint16 and update registry
The IANA language-subtag-registry now contains more than 256 scripts, causing the uint8 types to overflow during table generation. The internal script types are bumped to uint16 which should be more than enough. Fixes golang/go#45093 Change-Id: I58184902e6652f488521d084fce6e0b424121825 Reviewed-on: https://go-review.googlesource.com/c/text/+/304029 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Roland Shoemaker <[email protected]>
1 parent ba9b0e1 commit b0ca10f

File tree

10 files changed

+507
-478
lines changed

10 files changed

+507
-478
lines changed

Diff for: encoding/htmlindex/tables.go

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: encoding/ianaindex/tables.go

+30-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: encoding/internal/identifier/mib.go

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: internal/language/compact/tables.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: internal/language/gen.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -1209,12 +1209,12 @@ func (b *builder) writeLikelyData() {
12091209
type ( // generated types
12101210
likelyScriptRegion struct {
12111211
region uint16
1212-
script uint8
1212+
script uint16
12131213
flags uint8
12141214
}
12151215
likelyLangScript struct {
12161216
lang uint16
1217-
script uint8
1217+
script uint16
12181218
flags uint8
12191219
}
12201220
likelyLangRegion struct {
@@ -1226,7 +1226,7 @@ func (b *builder) writeLikelyData() {
12261226
likelyTag struct {
12271227
lang uint16
12281228
region uint16
1229-
script uint8
1229+
script uint16
12301230
}
12311231
)
12321232
var ( // generated variables
@@ -1279,7 +1279,7 @@ func (b *builder) writeLikelyData() {
12791279
log.Fatalf("region changed unexpectedly: %s -> %s", from, to)
12801280
}
12811281
likelyRegionGroup[id].lang = uint16(b.langIndex(to[0]))
1282-
likelyRegionGroup[id].script = uint8(b.script.index(to[1]))
1282+
likelyRegionGroup[id].script = uint16(b.script.index(to[1]))
12831283
likelyRegionGroup[id].region = uint16(b.region.index(to[2]))
12841284
} else {
12851285
regionToOther[r] = append(regionToOther[r], fromTo{from, to})
@@ -1293,11 +1293,11 @@ func (b *builder) writeLikelyData() {
12931293
list := langToOther[id]
12941294
if len(list) == 1 {
12951295
likelyLang[id].region = uint16(b.region.index(list[0].to[2]))
1296-
likelyLang[id].script = uint8(b.script.index(list[0].to[1]))
1296+
likelyLang[id].script = uint16(b.script.index(list[0].to[1]))
12971297
} else if len(list) > 1 {
12981298
likelyLang[id].flags = isList
12991299
likelyLang[id].region = uint16(len(likelyLangList))
1300-
likelyLang[id].script = uint8(len(list))
1300+
likelyLang[id].script = uint16(len(list))
13011301
for _, x := range list {
13021302
flags := uint8(0)
13031303
if len(x.from) > 1 {
@@ -1309,7 +1309,7 @@ func (b *builder) writeLikelyData() {
13091309
}
13101310
likelyLangList = append(likelyLangList, likelyScriptRegion{
13111311
region: uint16(b.region.index(x.to[2])),
1312-
script: uint8(b.script.index(x.to[1])),
1312+
script: uint16(b.script.index(x.to[1])),
13131313
flags: flags,
13141314
})
13151315
}
@@ -1324,21 +1324,21 @@ func (b *builder) writeLikelyData() {
13241324
list := regionToOther[id]
13251325
if len(list) == 1 {
13261326
likelyRegion[id].lang = uint16(b.langIndex(list[0].to[0]))
1327-
likelyRegion[id].script = uint8(b.script.index(list[0].to[1]))
1327+
likelyRegion[id].script = uint16(b.script.index(list[0].to[1]))
13281328
if len(list[0].from) > 2 {
13291329
likelyRegion[id].flags = scriptInFrom
13301330
}
13311331
} else if len(list) > 1 {
13321332
likelyRegion[id].flags = isList
13331333
likelyRegion[id].lang = uint16(len(likelyRegionList))
1334-
likelyRegion[id].script = uint8(len(list))
1334+
likelyRegion[id].script = uint16(len(list))
13351335
for i, x := range list {
13361336
if len(x.from) == 2 && i != 0 || i > 0 && len(x.from) != 3 {
13371337
log.Fatalf("unspecified script must be first in list: %v at %d", x.from, i)
13381338
}
13391339
x := likelyLangScript{
13401340
lang: uint16(b.langIndex(x.to[0])),
1341-
script: uint8(b.script.index(x.to[1])),
1341+
script: uint16(b.script.index(x.to[1])),
13421342
}
13431343
if len(list[0].from) > 2 {
13441344
x.flags = scriptInFrom
@@ -1453,8 +1453,8 @@ func (b *builder) writeRegionInclusionData() {
14531453

14541454
type parentRel struct {
14551455
lang uint16
1456-
script uint8
1457-
maxScript uint8
1456+
script uint16
1457+
maxScript uint16
14581458
toRegion uint16
14591459
fromRegion []uint16
14601460
}
@@ -1477,10 +1477,10 @@ func (b *builder) writeParents() {
14771477
if len(sub) == 2 {
14781478
// TODO: check that all undefined scripts are indeed Latn in these
14791479
// cases.
1480-
parent.maxScript = uint8(b.script.index("Latn"))
1480+
parent.maxScript = uint16(b.script.index("Latn"))
14811481
parent.toRegion = uint16(b.region.index(sub[1]))
14821482
} else {
1483-
parent.script = uint8(b.script.index(sub[1]))
1483+
parent.script = uint16(b.script.index(sub[1]))
14841484
parent.maxScript = parent.script
14851485
parent.toRegion = uint16(b.region.index(sub[2]))
14861486
}

Diff for: internal/language/language_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
func TestTagSize(t *testing.T) {
1515
id := Tag{}
1616
typ := reflect.TypeOf(id)
17-
if typ.Size() > 24 {
18-
t.Errorf("size of Tag was %d; want 24", typ.Size())
17+
if typ.Size() > 32 {
18+
t.Errorf("size of Tag was %d; want <= 32", typ.Size())
1919
}
2020
}
2121

Diff for: internal/language/lookup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func (r Region) IsPrivateUse() bool {
328328
return r.typ()&iso3166UserAssigned != 0
329329
}
330330

331-
type Script uint8
331+
type Script uint16
332332

333333
// getScriptID returns the script id for string s. It assumes that s
334334
// is of the format [A-Z][a-z]{3}.

0 commit comments

Comments
 (0)