diff --git a/.github/update.log b/.github/update.log index 218cf06919..4fbfaf6284 100644 --- a/.github/update.log +++ b/.github/update.log @@ -607,3 +607,4 @@ Update On Mon Apr 1 20:26:51 CEST 2024 Update On Tue Apr 2 20:27:11 CEST 2024 Update On Wed Apr 3 20:26:29 CEST 2024 Update On Thu Apr 4 20:27:14 CEST 2024 +Update On Fri Apr 5 20:26:37 CEST 2024 diff --git a/clash-meta-android/core/src/foss/golang/clash/.github/workflows/build.yml b/clash-meta-android/core/src/foss/golang/clash/.github/workflows/build.yml index d95226b032..2639c04b7a 100644 --- a/clash-meta-android/core/src/foss/golang/clash/.github/workflows/build.yml +++ b/clash-meta-android/core/src/foss/golang/clash/.github/workflows/build.yml @@ -143,7 +143,7 @@ jobs: run: | go test ./... - - name: Update UA + - name: Update CA run: | sudo apt-get install ca-certificates sudo update-ca-certificates diff --git a/clash-meta-android/core/src/foss/golang/clash/adapter/inbound/addition.go b/clash-meta-android/core/src/foss/golang/clash/adapter/inbound/addition.go index c38c1aa148..ed560818d8 100644 --- a/clash-meta-android/core/src/foss/golang/clash/adapter/inbound/addition.go +++ b/clash-meta-android/core/src/foss/golang/clash/adapter/inbound/addition.go @@ -47,7 +47,7 @@ func WithDstAddr(addr net.Addr) Addition { func WithSrcAddr(addr net.Addr) Addition { return func(metadata *C.Metadata) { m := C.Metadata{} - if err := m.SetRemoteAddr(addr);err ==nil{ + if err := m.SetRemoteAddr(addr); err == nil { metadata.SrcIP = m.DstIP metadata.SrcPort = m.DstPort } @@ -57,7 +57,7 @@ func WithSrcAddr(addr net.Addr) Addition { func WithInAddr(addr net.Addr) Addition { return func(metadata *C.Metadata) { m := C.Metadata{} - if err := m.SetRemoteAddr(addr);err ==nil{ + if err := m.SetRemoteAddr(addr); err == nil { metadata.InIP = m.DstIP metadata.InPort = m.DstPort } diff --git a/clash-meta-android/core/src/foss/golang/clash/adapter/inbound/http.go b/clash-meta-android/core/src/foss/golang/clash/adapter/inbound/http.go index 8f912fbe79..f7d45399fb 100644 --- a/clash-meta-android/core/src/foss/golang/clash/adapter/inbound/http.go +++ b/clash-meta-android/core/src/foss/golang/clash/adapter/inbound/http.go @@ -14,7 +14,7 @@ func NewHTTP(target socks5.Addr, srcConn net.Conn, conn net.Conn, additions ...A metadata.Type = C.HTTP metadata.RawSrcAddr = srcConn.RemoteAddr() metadata.RawDstAddr = srcConn.LocalAddr() - ApplyAdditions(metadata, WithSrcAddr(srcConn.RemoteAddr()), WithInAddr(conn.LocalAddr())) + ApplyAdditions(metadata, WithSrcAddr(srcConn.RemoteAddr()), WithInAddr(srcConn.LocalAddr())) ApplyAdditions(metadata, additions...) return conn, metadata } diff --git a/clash-meta-android/core/src/foss/golang/clash/adapter/outbound/direct.go b/clash-meta-android/core/src/foss/golang/clash/adapter/outbound/direct.go index 7def7b208f..1b01a576c4 100644 --- a/clash-meta-android/core/src/foss/golang/clash/adapter/outbound/direct.go +++ b/clash-meta-android/core/src/foss/golang/clash/adapter/outbound/direct.go @@ -3,18 +3,18 @@ package outbound import ( "context" "errors" - "fmt" "net/netip" N "github.com/metacubex/mihomo/common/net" "github.com/metacubex/mihomo/component/dialer" + "github.com/metacubex/mihomo/component/loopback" "github.com/metacubex/mihomo/component/resolver" C "github.com/metacubex/mihomo/constant" ) type Direct struct { *Base - loopBack *loopBackDetector + loopBack *loopback.Detector } type DirectOption struct { @@ -24,8 +24,8 @@ type DirectOption struct { // DialContext implements C.ProxyAdapter func (d *Direct) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) { - if d.loopBack.CheckConn(metadata.SourceAddrPort()) { - return nil, fmt.Errorf("reject loopback connection to: %s", metadata.RemoteAddress()) + if err := d.loopBack.CheckConn(metadata); err != nil { + return nil, err } opts = append(opts, dialer.WithResolver(resolver.DefaultResolver)) c, err := dialer.DialContext(ctx, "tcp", metadata.RemoteAddress(), d.Base.DialOptions(opts...)...) @@ -38,8 +38,8 @@ func (d *Direct) DialContext(ctx context.Context, metadata *C.Metadata, opts ... // ListenPacketContext implements C.ProxyAdapter func (d *Direct) ListenPacketContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.PacketConn, error) { - if d.loopBack.CheckPacketConn(metadata.SourceAddrPort()) { - return nil, fmt.Errorf("reject loopback connection to: %s", metadata.RemoteAddress()) + if err := d.loopBack.CheckPacketConn(metadata); err != nil { + return nil, err } // net.UDPConn.WriteTo only working with *net.UDPAddr, so we need a net.UDPAddr if !metadata.Resolved() { @@ -68,7 +68,7 @@ func NewDirectWithOption(option DirectOption) *Direct { rmark: option.RoutingMark, prefer: C.NewDNSPrefer(option.IPVersion), }, - loopBack: newLoopBackDetector(), + loopBack: loopback.NewDetector(), } } @@ -80,7 +80,7 @@ func NewDirect() *Direct { udp: true, prefer: C.DualStack, }, - loopBack: newLoopBackDetector(), + loopBack: loopback.NewDetector(), } } @@ -92,6 +92,6 @@ func NewCompatible() *Direct { udp: true, prefer: C.DualStack, }, - loopBack: newLoopBackDetector(), + loopBack: loopback.NewDetector(), } } diff --git a/clash-meta-android/core/src/foss/golang/clash/adapter/outboundgroup/parser.go b/clash-meta-android/core/src/foss/golang/clash/adapter/outboundgroup/parser.go index 74947587f7..132ef2c8cd 100644 --- a/clash-meta-android/core/src/foss/golang/clash/adapter/outboundgroup/parser.go +++ b/clash-meta-android/core/src/foss/golang/clash/adapter/outboundgroup/parser.go @@ -88,6 +88,30 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide } groupOption.ExpectedStatus = status + if len(groupOption.Use) != 0 { + list, err := getProviders(providersMap, groupOption.Use) + if err != nil { + return nil, fmt.Errorf("%s: %w", groupName, err) + } + + if groupOption.URL == "" { + for _, p := range list { + if p.HealthCheckURL() != "" { + groupOption.URL = p.HealthCheckURL() + break + } + } + + if groupOption.URL == "" { + groupOption.URL = C.DefaultTestURL + } + } + + // different proxy groups use different test URL + addTestUrlToProviders(list, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval)) + providers = append(providers, list...) + } + if len(groupOption.Proxies) != 0 { ps, err := getProxies(proxyMap, groupOption.Proxies) if err != nil { @@ -98,14 +122,15 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide return nil, fmt.Errorf("%s: %w", groupName, errDuplicateProvider) } - // select don't need health check + if groupOption.URL == "" { + groupOption.URL = C.DefaultTestURL + } + + // select don't need auto health check if groupOption.Type != "select" && groupOption.Type != "relay" { if groupOption.Interval == 0 { groupOption.Interval = 300 } - if groupOption.URL == "" { - groupOption.URL = C.DefaultTestURL - } } hc := provider.NewHealthCheck(ps, groupOption.URL, uint(groupOption.TestTimeout), uint(groupOption.Interval), groupOption.Lazy, expectedStatus) @@ -119,30 +144,6 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide providersMap[groupName] = pd } - if len(groupOption.Use) != 0 { - list, err := getProviders(providersMap, groupOption.Use) - if err != nil { - return nil, fmt.Errorf("%s: %w", groupName, err) - } - - if groupOption.URL == "" { - for _, p := range list { - if p.HealthCheckURL() != "" { - groupOption.URL = p.HealthCheckURL() - } - break - } - - if groupOption.URL == "" { - groupOption.URL = C.DefaultTestURL - } - } - - // different proxy groups use different test URL - addTestUrlToProviders(list, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval)) - providers = append(providers, list...) - } - var group C.ProxyAdapter switch groupOption.Type { case "url-test": diff --git a/clash-meta-android/core/src/foss/golang/clash/adapter/outbound/direct_loopback_detect.go b/clash-meta-android/core/src/foss/golang/clash/component/loopback/detector.go similarity index 58% rename from clash-meta-android/core/src/foss/golang/clash/adapter/outbound/direct_loopback_detect.go rename to clash-meta-android/core/src/foss/golang/clash/component/loopback/detector.go index 410d5a2fc8..b07270ed0a 100644 --- a/clash-meta-android/core/src/foss/golang/clash/adapter/outbound/direct_loopback_detect.go +++ b/clash-meta-android/core/src/foss/golang/clash/component/loopback/detector.go @@ -1,6 +1,8 @@ -package outbound +package loopback import ( + "errors" + "fmt" "net/netip" "github.com/metacubex/mihomo/common/callback" @@ -9,19 +11,21 @@ import ( "github.com/puzpuzpuz/xsync/v3" ) -type loopBackDetector struct { +var ErrReject = errors.New("reject loopback connection") + +type Detector struct { connMap *xsync.MapOf[netip.AddrPort, struct{}] packetConnMap *xsync.MapOf[netip.AddrPort, struct{}] } -func newLoopBackDetector() *loopBackDetector { - return &loopBackDetector{ +func NewDetector() *Detector { + return &Detector{ connMap: xsync.NewMapOf[netip.AddrPort, struct{}](), packetConnMap: xsync.NewMapOf[netip.AddrPort, struct{}](), } } -func (l *loopBackDetector) NewConn(conn C.Conn) C.Conn { +func (l *Detector) NewConn(conn C.Conn) C.Conn { metadata := C.Metadata{} if metadata.SetRemoteAddr(conn.LocalAddr()) != nil { return conn @@ -36,7 +40,7 @@ func (l *loopBackDetector) NewConn(conn C.Conn) C.Conn { }) } -func (l *loopBackDetector) NewPacketConn(conn C.PacketConn) C.PacketConn { +func (l *Detector) NewPacketConn(conn C.PacketConn) C.PacketConn { metadata := C.Metadata{} if metadata.SetRemoteAddr(conn.LocalAddr()) != nil { return conn @@ -51,18 +55,24 @@ func (l *loopBackDetector) NewPacketConn(conn C.PacketConn) C.PacketConn { }) } -func (l *loopBackDetector) CheckConn(connAddr netip.AddrPort) bool { +func (l *Detector) CheckConn(metadata *C.Metadata) error { + connAddr := metadata.SourceAddrPort() if !connAddr.IsValid() { - return false + return nil } - _, ok := l.connMap.Load(connAddr) - return ok + if _, ok := l.connMap.Load(connAddr); ok { + return fmt.Errorf("%w to: %s", ErrReject, metadata.RemoteAddress()) + } + return nil } -func (l *loopBackDetector) CheckPacketConn(connAddr netip.AddrPort) bool { +func (l *Detector) CheckPacketConn(metadata *C.Metadata) error { + connAddr := metadata.SourceAddrPort() if !connAddr.IsValid() { - return false + return nil } - _, ok := l.packetConnMap.Load(connAddr) - return ok + if _, ok := l.packetConnMap.Load(connAddr); ok { + return fmt.Errorf("%w to: %s", ErrReject, metadata.RemoteAddress()) + } + return nil } diff --git a/clash-meta-android/core/src/foss/golang/clash/constant/rule.go b/clash-meta-android/core/src/foss/golang/clash/constant/rule.go index fcefaba6ca..8fdd75a6c0 100644 --- a/clash-meta-android/core/src/foss/golang/clash/constant/rule.go +++ b/clash-meta-android/core/src/foss/golang/clash/constant/rule.go @@ -8,8 +8,10 @@ const ( DomainRegex GEOSITE GEOIP - IPCIDR + SrcGEOIP IPASN + SrcIPASN + IPCIDR SrcIPCIDR IPSuffix SrcIPSuffix @@ -48,10 +50,14 @@ func (rt RuleType) String() string { return "GeoSite" case GEOIP: return "GeoIP" - case IPCIDR: - return "IPCIDR" + case SrcGEOIP: + return "SrcGeoIP" case IPASN: return "IPASN" + case SrcIPASN: + return "SrcIPASN" + case IPCIDR: + return "IPCIDR" case SrcIPCIDR: return "SrcIPCIDR" case IPSuffix: diff --git a/clash-meta-android/core/src/foss/golang/clash/go.mod b/clash-meta-android/core/src/foss/golang/clash/go.mod index c70aca9784..7270049a65 100644 --- a/clash-meta-android/core/src/foss/golang/clash/go.mod +++ b/clash-meta-android/core/src/foss/golang/clash/go.mod @@ -23,7 +23,7 @@ require ( github.com/metacubex/sing-quic v0.0.0-20240310154810-47bca850fc01 github.com/metacubex/sing-shadowsocks v0.2.6 github.com/metacubex/sing-shadowsocks2 v0.2.0 - github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd + github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 github.com/metacubex/tfo-go v0.0.0-20240228025757-be1269474a66 diff --git a/clash-meta-android/core/src/foss/golang/clash/go.sum b/clash-meta-android/core/src/foss/golang/clash/go.sum index 7422a0627a..4bddc40e91 100644 --- a/clash-meta-android/core/src/foss/golang/clash/go.sum +++ b/clash-meta-android/core/src/foss/golang/clash/go.sum @@ -114,8 +114,8 @@ github.com/metacubex/sing-shadowsocks v0.2.6 h1:6oEB3QcsFYnNiFeoevcXrCwJ3sAablwV github.com/metacubex/sing-shadowsocks v0.2.6/go.mod h1:zIkMeSnb8Mbf4hdqhw0pjzkn1d99YJ3JQm/VBg5WMTg= github.com/metacubex/sing-shadowsocks2 v0.2.0 h1:hqwT/AfI5d5UdPefIzR6onGHJfDXs5zgOM5QSgaM/9A= github.com/metacubex/sing-shadowsocks2 v0.2.0/go.mod h1:LCKF6j1P94zN8ZS+LXRK1gmYTVGB3squivBSXAFnOg8= -github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd h1:NgLb6Lvr8ZxX0inWswVYjal2SUzsJJ54dFQNOluUJuE= -github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 h1:SEkMqQlInU4KoyaISvEPKEzhDw0CnTr2TvIuj/hmEQ0= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f h1:QjXrHKbTMBip/C+R79bvbfr42xH1gZl3uFb0RELdZiQ= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f/go.mod h1:olVkD4FChQ5gKMHG4ZzuD7+fMkJY1G8vwOKpRehjrmY= github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 h1:AGyIB55UfQm/0ZH0HtQO9u3l//yjtHUpjeRjjPGfGRI= diff --git a/clash-meta-android/core/src/foss/golang/clash/listener/sing_tun/server.go b/clash-meta-android/core/src/foss/golang/clash/listener/sing_tun/server.go index 384ff016b5..8fe534df53 100644 --- a/clash-meta-android/core/src/foss/golang/clash/listener/sing_tun/server.go +++ b/clash-meta-android/core/src/foss/golang/clash/listener/sing_tun/server.go @@ -261,15 +261,17 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis } } l.tunIf = tunIf - l.tunStack, err = tun.NewStack(strings.ToLower(options.Stack.String()), stackOptions) + + tunStack, err := tun.NewStack(strings.ToLower(options.Stack.String()), stackOptions) if err != nil { return } - err = l.tunStack.Start() + err = tunStack.Start() if err != nil { return } + l.tunStack = tunStack //l.openAndroidHotspot(tunOptions) diff --git a/clash-meta-android/core/src/foss/golang/clash/listener/tproxy/tproxy.go b/clash-meta-android/core/src/foss/golang/clash/listener/tproxy/tproxy.go index efb144a9a5..fa7e7dbe47 100644 --- a/clash-meta-android/core/src/foss/golang/clash/listener/tproxy/tproxy.go +++ b/clash-meta-android/core/src/foss/golang/clash/listener/tproxy/tproxy.go @@ -34,6 +34,8 @@ func (l *Listener) Close() error { func (l *Listener) handleTProxy(conn net.Conn, tunnel C.Tunnel, additions ...inbound.Addition) { target := socks5.ParseAddrToSocksAddr(conn.LocalAddr()) N.TCPKeepAlive(conn) + // TProxy's conn.LocalAddr() is target address, so we set from l.listener + additions = append([]inbound.Addition{inbound.WithInAddr(l.listener.Addr())}, additions...) tunnel.HandleTCPConn(inbound.NewSocket(target, conn, C.TPROXY, additions...)) } diff --git a/clash-meta-android/core/src/foss/golang/clash/rules/common/domain.go b/clash-meta-android/core/src/foss/golang/clash/rules/common/domain.go index 23f21185a6..306eb65fd8 100644 --- a/clash-meta-android/core/src/foss/golang/clash/rules/common/domain.go +++ b/clash-meta-android/core/src/foss/golang/clash/rules/common/domain.go @@ -4,6 +4,7 @@ import ( "strings" C "github.com/metacubex/mihomo/constant" + "golang.org/x/net/idna" ) type Domain struct { @@ -29,9 +30,10 @@ func (d *Domain) Payload() string { } func NewDomain(domain string, adapter string) *Domain { + punycode, _ := idna.ToASCII(strings.ToLower(domain)) return &Domain{ Base: &Base{}, - domain: strings.ToLower(domain), + domain: punycode, adapter: adapter, } } diff --git a/clash-meta-android/core/src/foss/golang/clash/rules/common/domain_keyword.go b/clash-meta-android/core/src/foss/golang/clash/rules/common/domain_keyword.go index ec01293a12..9d6f1c1559 100644 --- a/clash-meta-android/core/src/foss/golang/clash/rules/common/domain_keyword.go +++ b/clash-meta-android/core/src/foss/golang/clash/rules/common/domain_keyword.go @@ -4,6 +4,7 @@ import ( "strings" C "github.com/metacubex/mihomo/constant" + "golang.org/x/net/idna" ) type DomainKeyword struct { @@ -30,9 +31,10 @@ func (dk *DomainKeyword) Payload() string { } func NewDomainKeyword(keyword string, adapter string) *DomainKeyword { + punycode, _ := idna.ToASCII(strings.ToLower(keyword)) return &DomainKeyword{ Base: &Base{}, - keyword: strings.ToLower(keyword), + keyword: punycode, adapter: adapter, } } diff --git a/clash-meta-android/core/src/foss/golang/clash/rules/common/domain_suffix.go b/clash-meta-android/core/src/foss/golang/clash/rules/common/domain_suffix.go index b7b1794d8c..c5b87208eb 100644 --- a/clash-meta-android/core/src/foss/golang/clash/rules/common/domain_suffix.go +++ b/clash-meta-android/core/src/foss/golang/clash/rules/common/domain_suffix.go @@ -4,6 +4,7 @@ import ( "strings" C "github.com/metacubex/mihomo/constant" + "golang.org/x/net/idna" ) type DomainSuffix struct { @@ -30,9 +31,10 @@ func (ds *DomainSuffix) Payload() string { } func NewDomainSuffix(suffix string, adapter string) *DomainSuffix { + punycode, _ := idna.ToASCII(strings.ToLower(suffix)) return &DomainSuffix{ Base: &Base{}, - suffix: strings.ToLower(suffix), + suffix: punycode, adapter: adapter, } } diff --git a/clash-meta-android/core/src/foss/golang/clash/rules/common/geoip.go b/clash-meta-android/core/src/foss/golang/clash/rules/common/geoip.go index 223a79042d..b50680a47a 100644 --- a/clash-meta-android/core/src/foss/golang/clash/rules/common/geoip.go +++ b/clash-meta-android/core/src/foss/golang/clash/rules/common/geoip.go @@ -17,6 +17,7 @@ type GEOIP struct { country string adapter string noResolveIP bool + isSourceIP bool geoIPMatcher *router.GeoIPMatcher recodeSize int } @@ -24,11 +25,17 @@ type GEOIP struct { var _ C.Rule = (*GEOIP)(nil) func (g *GEOIP) RuleType() C.RuleType { + if g.isSourceIP { + return C.SrcGEOIP + } return C.GEOIP } func (g *GEOIP) Match(metadata *C.Metadata) (bool, string) { ip := metadata.DstIP + if g.isSourceIP { + ip = metadata.SrcIP + } if !ip.IsValid() { return false, "" } @@ -49,6 +56,16 @@ func (g *GEOIP) Match(metadata *C.Metadata) (bool, string) { } if !C.GeodataMode { + if g.isSourceIP { + codes := mmdb.IPInstance().LookupCode(ip.AsSlice()) + for _, code := range codes { + if g.country == code { + return true, g.adapter + } + } + return false, g.adapter + } + if metadata.DstGeoIP != nil { return false, g.adapter } @@ -62,7 +79,7 @@ func (g *GEOIP) Match(metadata *C.Metadata) (bool, string) { } match := g.geoIPMatcher.Match(ip) - if match { + if match && !g.isSourceIP { metadata.DstGeoIP = append(metadata.DstGeoIP, g.country) } return match, g.adapter @@ -92,7 +109,7 @@ func (g *GEOIP) GetRecodeSize() int { return g.recodeSize } -func NewGEOIP(country string, adapter string, noResolveIP bool) (*GEOIP, error) { +func NewGEOIP(country string, adapter string, isSrc, noResolveIP bool) (*GEOIP, error) { if err := geodata.InitGeoIP(); err != nil { log.Errorln("can't initial GeoIP: %s", err) return nil, err @@ -105,6 +122,7 @@ func NewGEOIP(country string, adapter string, noResolveIP bool) (*GEOIP, error) country: country, adapter: adapter, noResolveIP: noResolveIP, + isSourceIP: isSrc, } return geoip, nil } @@ -120,6 +138,7 @@ func NewGEOIP(country string, adapter string, noResolveIP bool) (*GEOIP, error) country: country, adapter: adapter, noResolveIP: noResolveIP, + isSourceIP: isSrc, geoIPMatcher: geoIPMatcher, recodeSize: size, } diff --git a/clash-meta-android/core/src/foss/golang/clash/rules/common/ipasn.go b/clash-meta-android/core/src/foss/golang/clash/rules/common/ipasn.go index 1fce8af482..df4b6531c6 100644 --- a/clash-meta-android/core/src/foss/golang/clash/rules/common/ipasn.go +++ b/clash-meta-android/core/src/foss/golang/clash/rules/common/ipasn.go @@ -14,24 +14,32 @@ type ASN struct { asn string adapter string noResolveIP bool + isSourceIP bool } func (a *ASN) Match(metadata *C.Metadata) (bool, string) { ip := metadata.DstIP + if a.isSourceIP { + ip = metadata.SrcIP + } if !ip.IsValid() { return false, "" } result := mmdb.ASNInstance().LookupASN(ip.AsSlice()) - asnNumber := strconv.FormatUint(uint64(result.AutonomousSystemNumber), 10) - metadata.DstIPASN = asnNumber + " " + result.AutonomousSystemOrganization + if !a.isSourceIP { + metadata.DstIPASN = asnNumber + " " + result.AutonomousSystemOrganization + } match := a.asn == asnNumber return match, a.adapter } func (a *ASN) RuleType() C.RuleType { + if a.isSourceIP { + return C.SrcIPASN + } return C.IPASN } @@ -51,7 +59,7 @@ func (a *ASN) GetASN() string { return a.asn } -func NewIPASN(asn string, adapter string, noResolveIP bool) (*ASN, error) { +func NewIPASN(asn string, adapter string, isSrc, noResolveIP bool) (*ASN, error) { C.ASNEnable = true if err := geodata.InitASN(); err != nil { log.Errorln("can't initial ASN: %s", err) @@ -63,5 +71,6 @@ func NewIPASN(asn string, adapter string, noResolveIP bool) (*ASN, error) { asn: asn, adapter: adapter, noResolveIP: noResolveIP, + isSourceIP: isSrc, }, nil } diff --git a/clash-meta-android/core/src/foss/golang/clash/rules/parser.go b/clash-meta-android/core/src/foss/golang/clash/rules/parser.go index b69cc4fd9c..032a02e4b0 100644 --- a/clash-meta-android/core/src/foss/golang/clash/rules/parser.go +++ b/clash-meta-android/core/src/foss/golang/clash/rules/parser.go @@ -23,13 +23,17 @@ func ParseRule(tp, payload, target string, params []string, subRules map[string] parsed, parseErr = RC.NewGEOSITE(payload, target) case "GEOIP": noResolve := RC.HasNoResolve(params) - parsed, parseErr = RC.NewGEOIP(payload, target, noResolve) + parsed, parseErr = RC.NewGEOIP(payload, target, false, noResolve) + case "SRC-GEOIP": + parsed, parseErr = RC.NewGEOIP(payload, target, true, true) + case "IP-ASN": + noResolve := RC.HasNoResolve(params) + parsed, parseErr = RC.NewIPASN(payload, target, false, noResolve) + case "SRC-IP-ASN": + parsed, parseErr = RC.NewIPASN(payload, target, true, true) case "IP-CIDR", "IP-CIDR6": noResolve := RC.HasNoResolve(params) parsed, parseErr = RC.NewIPCIDR(payload, target, RC.WithIPCIDRNoResolve(noResolve)) - case "IP-ASN": - noResolve := RC.HasNoResolve(params) - parsed, parseErr = RC.NewIPASN(payload, target, noResolve) case "SRC-IP-CIDR": parsed, parseErr = RC.NewIPCIDR(payload, target, RC.WithIPCIDRSourceIP(true), RC.WithIPCIDRNoResolve(true)) case "IP-SUFFIX": diff --git a/clash-meta-android/core/src/foss/golang/clash/tunnel/tunnel.go b/clash-meta-android/core/src/foss/golang/clash/tunnel/tunnel.go index d5a226e961..608ab2c5bd 100644 --- a/clash-meta-android/core/src/foss/golang/clash/tunnel/tunnel.go +++ b/clash-meta-android/core/src/foss/golang/clash/tunnel/tunnel.go @@ -12,6 +12,7 @@ import ( "time" N "github.com/metacubex/mihomo/common/net" + "github.com/metacubex/mihomo/component/loopback" "github.com/metacubex/mihomo/component/nat" P "github.com/metacubex/mihomo/component/process" "github.com/metacubex/mihomo/component/resolver" @@ -694,6 +695,9 @@ func shouldStopRetry(err error) bool { if errors.Is(err, resolver.ErrIPv6Disabled) { return true } + if errors.Is(err, loopback.ErrReject) { + return true + } return false } diff --git a/clash-meta-android/core/src/foss/golang/go.mod b/clash-meta-android/core/src/foss/golang/go.mod index 0921e85d6f..9256db15f2 100644 --- a/clash-meta-android/core/src/foss/golang/go.mod +++ b/clash-meta-android/core/src/foss/golang/go.mod @@ -51,7 +51,7 @@ require ( github.com/metacubex/sing-quic v0.0.0-20240310154810-47bca850fc01 // indirect github.com/metacubex/sing-shadowsocks v0.2.6 // indirect github.com/metacubex/sing-shadowsocks2 v0.2.0 // indirect - github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd // indirect + github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 // indirect github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f // indirect github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 // indirect github.com/metacubex/tfo-go v0.0.0-20240228025757-be1269474a66 // indirect diff --git a/clash-meta-android/core/src/foss/golang/go.sum b/clash-meta-android/core/src/foss/golang/go.sum index aadc8317ce..f7c8878429 100644 --- a/clash-meta-android/core/src/foss/golang/go.sum +++ b/clash-meta-android/core/src/foss/golang/go.sum @@ -108,8 +108,8 @@ github.com/metacubex/sing-shadowsocks v0.2.6 h1:6oEB3QcsFYnNiFeoevcXrCwJ3sAablwV github.com/metacubex/sing-shadowsocks v0.2.6/go.mod h1:zIkMeSnb8Mbf4hdqhw0pjzkn1d99YJ3JQm/VBg5WMTg= github.com/metacubex/sing-shadowsocks2 v0.2.0 h1:hqwT/AfI5d5UdPefIzR6onGHJfDXs5zgOM5QSgaM/9A= github.com/metacubex/sing-shadowsocks2 v0.2.0/go.mod h1:LCKF6j1P94zN8ZS+LXRK1gmYTVGB3squivBSXAFnOg8= -github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd h1:NgLb6Lvr8ZxX0inWswVYjal2SUzsJJ54dFQNOluUJuE= -github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 h1:SEkMqQlInU4KoyaISvEPKEzhDw0CnTr2TvIuj/hmEQ0= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f h1:QjXrHKbTMBip/C+R79bvbfr42xH1gZl3uFb0RELdZiQ= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f/go.mod h1:olVkD4FChQ5gKMHG4ZzuD7+fMkJY1G8vwOKpRehjrmY= github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 h1:AGyIB55UfQm/0ZH0HtQO9u3l//yjtHUpjeRjjPGfGRI= diff --git a/clash-meta-android/core/src/main/golang/go.mod b/clash-meta-android/core/src/main/golang/go.mod index 9f2c768e5b..9f67169a89 100644 --- a/clash-meta-android/core/src/main/golang/go.mod +++ b/clash-meta-android/core/src/main/golang/go.mod @@ -58,7 +58,7 @@ require ( github.com/metacubex/sing-quic v0.0.0-20240310154810-47bca850fc01 // indirect github.com/metacubex/sing-shadowsocks v0.2.6 // indirect github.com/metacubex/sing-shadowsocks2 v0.2.0 // indirect - github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd // indirect + github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 // indirect github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f // indirect github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 // indirect github.com/metacubex/tfo-go v0.0.0-20240228025757-be1269474a66 // indirect diff --git a/clash-meta-android/core/src/main/golang/go.sum b/clash-meta-android/core/src/main/golang/go.sum index aadc8317ce..f7c8878429 100644 --- a/clash-meta-android/core/src/main/golang/go.sum +++ b/clash-meta-android/core/src/main/golang/go.sum @@ -108,8 +108,8 @@ github.com/metacubex/sing-shadowsocks v0.2.6 h1:6oEB3QcsFYnNiFeoevcXrCwJ3sAablwV github.com/metacubex/sing-shadowsocks v0.2.6/go.mod h1:zIkMeSnb8Mbf4hdqhw0pjzkn1d99YJ3JQm/VBg5WMTg= github.com/metacubex/sing-shadowsocks2 v0.2.0 h1:hqwT/AfI5d5UdPefIzR6onGHJfDXs5zgOM5QSgaM/9A= github.com/metacubex/sing-shadowsocks2 v0.2.0/go.mod h1:LCKF6j1P94zN8ZS+LXRK1gmYTVGB3squivBSXAFnOg8= -github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd h1:NgLb6Lvr8ZxX0inWswVYjal2SUzsJJ54dFQNOluUJuE= -github.com/metacubex/sing-tun v0.2.1-0.20240320004934-5d2b35447bfd/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 h1:SEkMqQlInU4KoyaISvEPKEzhDw0CnTr2TvIuj/hmEQ0= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f h1:QjXrHKbTMBip/C+R79bvbfr42xH1gZl3uFb0RELdZiQ= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f/go.mod h1:olVkD4FChQ5gKMHG4ZzuD7+fMkJY1G8vwOKpRehjrmY= github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 h1:AGyIB55UfQm/0ZH0HtQO9u3l//yjtHUpjeRjjPGfGRI= diff --git a/clash-meta/.github/workflows/build.yml b/clash-meta/.github/workflows/build.yml index d95226b032..2639c04b7a 100644 --- a/clash-meta/.github/workflows/build.yml +++ b/clash-meta/.github/workflows/build.yml @@ -143,7 +143,7 @@ jobs: run: | go test ./... - - name: Update UA + - name: Update CA run: | sudo apt-get install ca-certificates sudo update-ca-certificates diff --git a/clash-meta/adapter/outboundgroup/parser.go b/clash-meta/adapter/outboundgroup/parser.go index bec262f231..ac4546d822 100644 --- a/clash-meta/adapter/outboundgroup/parser.go +++ b/clash-meta/adapter/outboundgroup/parser.go @@ -88,6 +88,30 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide } groupOption.ExpectedStatus = status + if len(groupOption.Use) != 0 { + PDs, err := getProviders(providersMap, groupOption.Use) + if err != nil { + return nil, fmt.Errorf("%s: %w", groupName, err) + } + + // if test URL is empty, use the first health check URL of providers + if groupOption.URL == "" { + for _, pd := range PDs { + if pd.HealthCheckURL() != "" { + groupOption.URL = pd.HealthCheckURL() + break + } + } + if groupOption.URL == "" { + groupOption.URL = C.DefaultTestURL + } + } else { + addTestUrlToProviders(PDs, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval)) + } + + providers = append(providers, PDs...) + } + if len(groupOption.Proxies) != 0 { ps, err := getProxies(proxyMap, groupOption.Proxies) if err != nil { @@ -98,14 +122,17 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide return nil, fmt.Errorf("%s: %w", groupName, errDuplicateProvider) } - if groupOption.Interval == 0 { - groupOption.Interval = 300 - } - if groupOption.URL == "" { groupOption.URL = C.DefaultTestURL } + // select don't need auto health check + if groupOption.Type != "select" && groupOption.Type != "relay" { + if groupOption.Interval == 0 { + groupOption.Interval = 300 + } + } + hc := provider.NewHealthCheck(ps, groupOption.URL, uint(groupOption.TestTimeout), uint(groupOption.Interval), groupOption.Lazy, expectedStatus) pd, err := provider.NewCompatibleProvider(groupName, ps, hc) @@ -117,30 +144,6 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide providersMap[groupName] = pd } - if len(groupOption.Use) != 0 { - list, err := getProviders(providersMap, groupOption.Use) - if err != nil { - return nil, fmt.Errorf("%s: %w", groupName, err) - } - - if groupOption.URL == "" { - for _, p := range list { - if p.HealthCheckURL() != "" { - groupOption.URL = p.HealthCheckURL() - } - break - } - - if groupOption.URL == "" { - groupOption.URL = C.DefaultTestURL - } - } - - // different proxy groups use different test URL - addTestUrlToProviders(list, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval)) - providers = append(providers, list...) - } - var group C.ProxyAdapter switch groupOption.Type { case "url-test": diff --git a/clash-meta/go.mod b/clash-meta/go.mod index 78f50d02be..7270049a65 100644 --- a/clash-meta/go.mod +++ b/clash-meta/go.mod @@ -23,7 +23,7 @@ require ( github.com/metacubex/sing-quic v0.0.0-20240310154810-47bca850fc01 github.com/metacubex/sing-shadowsocks v0.2.6 github.com/metacubex/sing-shadowsocks2 v0.2.0 - github.com/metacubex/sing-tun v0.2.1-0.20240402145739-0223b8bb1c85 + github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 github.com/metacubex/tfo-go v0.0.0-20240228025757-be1269474a66 diff --git a/clash-meta/go.sum b/clash-meta/go.sum index 12c207e427..4bddc40e91 100644 --- a/clash-meta/go.sum +++ b/clash-meta/go.sum @@ -114,8 +114,8 @@ github.com/metacubex/sing-shadowsocks v0.2.6 h1:6oEB3QcsFYnNiFeoevcXrCwJ3sAablwV github.com/metacubex/sing-shadowsocks v0.2.6/go.mod h1:zIkMeSnb8Mbf4hdqhw0pjzkn1d99YJ3JQm/VBg5WMTg= github.com/metacubex/sing-shadowsocks2 v0.2.0 h1:hqwT/AfI5d5UdPefIzR6onGHJfDXs5zgOM5QSgaM/9A= github.com/metacubex/sing-shadowsocks2 v0.2.0/go.mod h1:LCKF6j1P94zN8ZS+LXRK1gmYTVGB3squivBSXAFnOg8= -github.com/metacubex/sing-tun v0.2.1-0.20240402145739-0223b8bb1c85 h1:r7XXIvooixabmv2Ry95I1Xv3T0c+9VWtes9LhkXGg34= -github.com/metacubex/sing-tun v0.2.1-0.20240402145739-0223b8bb1c85/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 h1:SEkMqQlInU4KoyaISvEPKEzhDw0CnTr2TvIuj/hmEQ0= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f h1:QjXrHKbTMBip/C+R79bvbfr42xH1gZl3uFb0RELdZiQ= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f/go.mod h1:olVkD4FChQ5gKMHG4ZzuD7+fMkJY1G8vwOKpRehjrmY= github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 h1:AGyIB55UfQm/0ZH0HtQO9u3l//yjtHUpjeRjjPGfGRI= diff --git a/clash-nyanpasu/backend/tauri/src/cmds.rs b/clash-nyanpasu/backend/tauri/src/cmds.rs index 99b7968667..03cd2e9822 100644 --- a/clash-nyanpasu/backend/tauri/src/cmds.rs +++ b/clash-nyanpasu/backend/tauri/src/cmds.rs @@ -397,21 +397,17 @@ pub async fn set_custom_app_dir(app_handle: tauri::AppHandle, path: String) -> C let app_exe = tauri::utils::platform::current_exe()?; let app_exe = dunce::canonicalize(app_exe)?.to_string_lossy().to_string(); std::thread::spawn(move || { - std::thread::spawn(move || { - std::thread::sleep(Duration::from_secs(3)); - utils::help::quit_application(&app_handle); - }); - let args = vec![ - "/C", - app_exe.as_str(), - "migrate-home-dir", - path_str.as_str(), - ]; - runas::Command::new("cmd") - .args(&args) - .show(true) - .status() - .unwrap(); + std::process::Command::new("powershell") + .arg("-Command") + .arg( + format!( + r#"Start-Process '{}' -ArgumentList 'migrate-home-dir','{}' -Verb runAs"#, + app_exe.as_str(), + path_str.as_str() + ) + .as_str(), + ).spawn().unwrap(); + utils::help::quit_application(&app_handle); }); } else { set_app_dir(&path)?; diff --git a/clash-nyanpasu/manifest/version.json b/clash-nyanpasu/manifest/version.json index 900087740e..1fd6f9e96a 100644 --- a/clash-nyanpasu/manifest/version.json +++ b/clash-nyanpasu/manifest/version.json @@ -2,7 +2,7 @@ "manifest_version": 1, "latest": { "mihomo": "v1.18.3", - "mihomo_alpha": "alpha-b56e73a", + "mihomo_alpha": "alpha-90bf158", "clash_rs": "v0.1.15", "clash_premium": "2023-09-05-gdcc8d87" }, @@ -36,5 +36,5 @@ "darwin-x64": "clash-darwin-amd64-n{}.gz" } }, - "updated_at": "2024-04-03T22:19:03.121Z" + "updated_at": "2024-04-04T22:19:02.557Z" } diff --git a/clash-nyanpasu/package.json b/clash-nyanpasu/package.json index 894564a2cd..da4903a70e 100644 --- a/clash-nyanpasu/package.json +++ b/clash-nyanpasu/package.json @@ -73,7 +73,7 @@ "@mui/icons-material": "5.15.15", "@mui/lab": "5.0.0-alpha.170", "@mui/material": "5.15.15", - "@mui/x-data-grid": "7.1.0", + "@mui/x-data-grid": "7.1.1", "@tauri-apps/api": "1.5.3", "ahooks": "3.7.11", "axios": "1.6.8", @@ -151,7 +151,7 @@ "stylelint-scss": "6.2.1", "telegraf": "4.16.3", "tsx": "4.7.2", - "typescript": "5.4.3", + "typescript": "5.4.4", "vite": "5.2.8", "vite-plugin-monaco-editor": "1.1.0", "vite-plugin-sass-dts": "1.3.17", diff --git a/clash-nyanpasu/pnpm-lock.yaml b/clash-nyanpasu/pnpm-lock.yaml index d404c202cd..9bcada81e8 100644 --- a/clash-nyanpasu/pnpm-lock.yaml +++ b/clash-nyanpasu/pnpm-lock.yaml @@ -39,8 +39,8 @@ dependencies: specifier: 5.15.15 version: 5.15.15(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@types/react@18.2.74)(react-dom@18.2.0)(react@18.2.0) '@mui/x-data-grid': - specifier: 7.1.0 - version: 7.1.0(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@mui/material@5.15.15)(@types/react@18.2.74)(react-dom@18.2.0)(react@18.2.0) + specifier: 7.1.1 + version: 7.1.1(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@mui/material@5.15.15)(@types/react@18.2.74)(react-dom@18.2.0)(react@18.2.0) '@tauri-apps/api': specifier: 1.5.3 version: 1.5.3 @@ -108,7 +108,7 @@ devDependencies: version: 6.0.0 '@commitlint/cli': specifier: 19.2.1 - version: 19.2.1(@types/node@20.12.4)(typescript@5.4.3) + version: 19.2.1(@types/node@20.12.4)(typescript@5.4.4) '@commitlint/config-conventional': specifier: 19.1.0 version: 19.1.0 @@ -138,10 +138,10 @@ devDependencies: version: 4.4.10 '@typescript-eslint/eslint-plugin': specifier: 7.5.0 - version: 7.5.0(@typescript-eslint/parser@7.5.0)(eslint@8.57.0)(typescript@5.4.3) + version: 7.5.0(@typescript-eslint/parser@7.5.0)(eslint@8.57.0)(typescript@5.4.4) '@typescript-eslint/parser': specifier: 7.5.0 - version: 7.5.0(eslint@8.57.0)(typescript@5.4.3) + version: 7.5.0(eslint@8.57.0)(typescript@5.4.4) '@vitejs/plugin-react': specifier: 4.2.1 version: 4.2.1(vite@5.2.8) @@ -243,7 +243,7 @@ devDependencies: version: 1.2.4 stylelint: specifier: 16.3.1 - version: 16.3.1(typescript@5.4.3) + version: 16.3.1(typescript@5.4.4) stylelint-config-html: specifier: 1.1.0 version: 1.1.0(postcss-html@1.6.0)(stylelint@16.3.1) @@ -269,8 +269,8 @@ devDependencies: specifier: 4.7.2 version: 4.7.2 typescript: - specifier: 5.4.3 - version: 5.4.3 + specifier: 5.4.4 + version: 5.4.4 vite: specifier: 5.2.8 version: 5.2.8(@types/node@20.12.4)(sass@1.74.1) @@ -282,10 +282,10 @@ devDependencies: version: 1.3.17(postcss@8.4.38)(prettier@3.2.5)(sass@1.74.1)(vite@5.2.8) vite-plugin-svgr: specifier: 4.2.0 - version: 4.2.0(typescript@5.4.3)(vite@5.2.8) + version: 4.2.0(typescript@5.4.4)(vite@5.2.8) vite-tsconfig-paths: specifier: 4.3.2 - version: 4.3.2(typescript@5.4.3)(vite@5.2.8) + version: 4.3.2(typescript@5.4.4)(vite@5.2.8) packages: @@ -549,14 +549,14 @@ packages: '@babel/helper-validator-identifier': 7.22.20 to-fast-properties: 2.0.0 - /@commitlint/cli@19.2.1(@types/node@20.12.4)(typescript@5.4.3): + /@commitlint/cli@19.2.1(@types/node@20.12.4)(typescript@5.4.4): resolution: {integrity: sha512-cbkYUJsLqRomccNxvoJTyv5yn0bSy05BBizVyIcLACkRbVUqYorC351Diw/XFSWC/GtpwiwT2eOvQgFZa374bg==} engines: {node: '>=v18'} hasBin: true dependencies: '@commitlint/format': 19.0.3 '@commitlint/lint': 19.1.0 - '@commitlint/load': 19.2.0(@types/node@20.12.4)(typescript@5.4.3) + '@commitlint/load': 19.2.0(@types/node@20.12.4)(typescript@5.4.4) '@commitlint/read': 19.2.1 '@commitlint/types': 19.0.3 execa: 8.0.1 @@ -625,7 +625,7 @@ packages: '@commitlint/types': 19.0.3 dev: true - /@commitlint/load@19.2.0(@types/node@20.12.4)(typescript@5.4.3): + /@commitlint/load@19.2.0(@types/node@20.12.4)(typescript@5.4.4): resolution: {integrity: sha512-XvxxLJTKqZojCxaBQ7u92qQLFMMZc4+p9qrIq/9kJDy8DOrEa7P1yx7Tjdc2u2JxIalqT4KOGraVgCE7eCYJyQ==} engines: {node: '>=v18'} dependencies: @@ -634,8 +634,8 @@ packages: '@commitlint/resolve-extends': 19.1.0 '@commitlint/types': 19.0.3 chalk: 5.3.0 - cosmiconfig: 9.0.0(typescript@5.4.3) - cosmiconfig-typescript-loader: 5.0.0(@types/node@20.12.4)(cosmiconfig@9.0.0)(typescript@5.4.3) + cosmiconfig: 9.0.0(typescript@5.4.4) + cosmiconfig-typescript-loader: 5.0.0(@types/node@20.12.4)(cosmiconfig@9.0.0)(typescript@5.4.4) lodash.isplainobject: 4.0.6 lodash.merge: 4.6.2 lodash.uniq: 4.5.0 @@ -1617,36 +1617,6 @@ packages: react: 18.2.0 dev: false - /@mui/system@5.15.14(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@types/react@18.2.74)(react@18.2.0): - resolution: {integrity: sha512-auXLXzUaCSSOLqJXmsAaq7P96VPRXg2Rrz6OHNV7lr+kB8lobUF+/N84Vd9C4G/wvCXYPs5TYuuGBRhcGbiBGg==} - engines: {node: '>=12.0.0'} - peerDependencies: - '@emotion/react': ^11.5.0 - '@emotion/styled': ^11.3.0 - '@types/react': ^17.0.0 || ^18.0.0 - react: ^17.0.0 || ^18.0.0 - peerDependenciesMeta: - '@emotion/react': - optional: true - '@emotion/styled': - optional: true - '@types/react': - optional: true - dependencies: - '@babel/runtime': 7.24.1 - '@emotion/react': 11.11.4(@types/react@18.2.74)(react@18.2.0) - '@emotion/styled': 11.11.5(@emotion/react@11.11.4)(@types/react@18.2.74)(react@18.2.0) - '@mui/private-theming': 5.15.14(@types/react@18.2.74)(react@18.2.0) - '@mui/styled-engine': 5.15.14(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(react@18.2.0) - '@mui/types': 7.2.14(@types/react@18.2.74) - '@mui/utils': 5.15.14(@types/react@18.2.74)(react@18.2.0) - '@types/react': 18.2.74 - clsx: 2.1.0 - csstype: 3.1.3 - prop-types: 15.8.1 - react: 18.2.0 - dev: false - /@mui/system@5.15.15(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@types/react@18.2.74)(react@18.2.0): resolution: {integrity: sha512-aulox6N1dnu5PABsfxVGOZffDVmlxPOVgj56HrUnJE8MCSh8lOvvkd47cebIVQQYAjpwieXQXiDPj5pwM40jTQ==} engines: {node: '>=12.0.0'} @@ -1706,8 +1676,8 @@ packages: react-is: 18.2.0 dev: false - /@mui/x-data-grid@7.1.0(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@mui/material@5.15.15)(@types/react@18.2.74)(react-dom@18.2.0)(react@18.2.0): - resolution: {integrity: sha512-VnvX6ZyVUw/cjosh6SvkPtTmukFIa587JHcnWDPnaOijSOg6Zq72xbzEqqwZn9oOZCj88FD7lEDVHUIjoncDvg==} + /@mui/x-data-grid@7.1.1(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@mui/material@5.15.15)(@types/react@18.2.74)(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-hNvz927lkAznFdy45QPE7mIZVyQhlqveHmTK9+SD0N1us4sSTij90uUJ/roTNDod0VA9f5GqWmNz+5h8ihpz6Q==} engines: {node: '>=14.0.0'} peerDependencies: '@mui/material': ^5.15.14 @@ -1716,7 +1686,7 @@ packages: dependencies: '@babel/runtime': 7.24.1 '@mui/material': 5.15.15(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@types/react@18.2.74)(react-dom@18.2.0)(react@18.2.0) - '@mui/system': 5.15.14(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@types/react@18.2.74)(react@18.2.0) + '@mui/system': 5.15.15(@emotion/react@11.11.4)(@emotion/styled@11.11.5)(@types/react@18.2.74)(react@18.2.0) '@mui/utils': 5.15.14(@types/react@18.2.74)(react@18.2.0) clsx: 2.1.0 prop-types: 15.8.1 @@ -2057,14 +2027,14 @@ packages: '@svgr/babel-plugin-transform-svg-component': 8.0.0(@babel/core@7.23.6) dev: true - /@svgr/core@8.1.0(typescript@5.4.3): + /@svgr/core@8.1.0(typescript@5.4.4): resolution: {integrity: sha512-8QqtOQT5ACVlmsvKOJNEaWmRPmcojMOzCz4Hs2BGG/toAp/K38LcsMRyLp349glq5AzJbCEeimEoxaX6v/fLrA==} engines: {node: '>=14'} dependencies: '@babel/core': 7.23.6 '@svgr/babel-preset': 8.1.0(@babel/core@7.23.6) camelcase: 6.3.0 - cosmiconfig: 8.3.6(typescript@5.4.3) + cosmiconfig: 8.3.6(typescript@5.4.4) snake-case: 3.0.4 transitivePeerDependencies: - supports-color @@ -2087,7 +2057,7 @@ packages: dependencies: '@babel/core': 7.23.6 '@svgr/babel-preset': 8.1.0(@babel/core@7.23.6) - '@svgr/core': 8.1.0(typescript@5.4.3) + '@svgr/core': 8.1.0(typescript@5.4.4) '@svgr/hast-util-to-babel-ast': 8.0.0 svg-parser: 2.0.4 transitivePeerDependencies: @@ -2366,7 +2336,7 @@ packages: resolution: {integrity: sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==} dev: false - /@typescript-eslint/eslint-plugin@7.5.0(@typescript-eslint/parser@7.5.0)(eslint@8.57.0)(typescript@5.4.3): + /@typescript-eslint/eslint-plugin@7.5.0(@typescript-eslint/parser@7.5.0)(eslint@8.57.0)(typescript@5.4.4): resolution: {integrity: sha512-HpqNTH8Du34nLxbKgVMGljZMG0rJd2O9ecvr2QLYp+7512ty1j42KnsFwspPXg1Vh8an9YImf6CokUBltisZFQ==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: @@ -2378,10 +2348,10 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.10.0 - '@typescript-eslint/parser': 7.5.0(eslint@8.57.0)(typescript@5.4.3) + '@typescript-eslint/parser': 7.5.0(eslint@8.57.0)(typescript@5.4.4) '@typescript-eslint/scope-manager': 7.5.0 - '@typescript-eslint/type-utils': 7.5.0(eslint@8.57.0)(typescript@5.4.3) - '@typescript-eslint/utils': 7.5.0(eslint@8.57.0)(typescript@5.4.3) + '@typescript-eslint/type-utils': 7.5.0(eslint@8.57.0)(typescript@5.4.4) + '@typescript-eslint/utils': 7.5.0(eslint@8.57.0)(typescript@5.4.4) '@typescript-eslint/visitor-keys': 7.5.0 debug: 4.3.4 eslint: 8.57.0 @@ -2389,13 +2359,13 @@ packages: ignore: 5.3.1 natural-compare: 1.4.0 semver: 7.6.0 - ts-api-utils: 1.0.3(typescript@5.4.3) - typescript: 5.4.3 + ts-api-utils: 1.0.3(typescript@5.4.4) + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/parser@7.5.0(eslint@8.57.0)(typescript@5.4.3): + /@typescript-eslint/parser@7.5.0(eslint@8.57.0)(typescript@5.4.4): resolution: {integrity: sha512-cj+XGhNujfD2/wzR1tabNsidnYRaFfEkcULdcIyVBYcXjBvBKOes+mpMBP7hMpOyk+gBcfXsrg4NBGAStQyxjQ==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: @@ -2407,11 +2377,11 @@ packages: dependencies: '@typescript-eslint/scope-manager': 7.5.0 '@typescript-eslint/types': 7.5.0 - '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.3) + '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.4) '@typescript-eslint/visitor-keys': 7.5.0 debug: 4.3.4 eslint: 8.57.0 - typescript: 5.4.3 + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true @@ -2424,7 +2394,7 @@ packages: '@typescript-eslint/visitor-keys': 7.5.0 dev: true - /@typescript-eslint/type-utils@7.5.0(eslint@8.57.0)(typescript@5.4.3): + /@typescript-eslint/type-utils@7.5.0(eslint@8.57.0)(typescript@5.4.4): resolution: {integrity: sha512-A021Rj33+G8mx2Dqh0nMO9GyjjIBK3MqgVgZ2qlKf6CJy51wY/lkkFqq3TqqnH34XyAHUkq27IjlUkWlQRpLHw==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: @@ -2434,12 +2404,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.3) - '@typescript-eslint/utils': 7.5.0(eslint@8.57.0)(typescript@5.4.3) + '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.4) + '@typescript-eslint/utils': 7.5.0(eslint@8.57.0)(typescript@5.4.4) debug: 4.3.4 eslint: 8.57.0 - ts-api-utils: 1.0.3(typescript@5.4.3) - typescript: 5.4.3 + ts-api-utils: 1.0.3(typescript@5.4.4) + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true @@ -2449,7 +2419,7 @@ packages: engines: {node: ^18.18.0 || >=20.0.0} dev: true - /@typescript-eslint/typescript-estree@7.5.0(typescript@5.4.3): + /@typescript-eslint/typescript-estree@7.5.0(typescript@5.4.4): resolution: {integrity: sha512-YklQQfe0Rv2PZEueLTUffiQGKQneiIEKKnfIqPIOxgM9lKSZFCjT5Ad4VqRKj/U4+kQE3fa8YQpskViL7WjdPQ==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: @@ -2465,13 +2435,13 @@ packages: is-glob: 4.0.3 minimatch: 9.0.3 semver: 7.6.0 - ts-api-utils: 1.0.3(typescript@5.4.3) - typescript: 5.4.3 + ts-api-utils: 1.0.3(typescript@5.4.4) + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils@7.5.0(eslint@8.57.0)(typescript@5.4.3): + /@typescript-eslint/utils@7.5.0(eslint@8.57.0)(typescript@5.4.4): resolution: {integrity: sha512-3vZl9u0R+/FLQcpy2EHyRGNqAS/ofJ3Ji8aebilfJe+fobK8+LbIFmrHciLVDxjDoONmufDcnVSF38KwMEOjzw==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: @@ -2482,7 +2452,7 @@ packages: '@types/semver': 7.5.6 '@typescript-eslint/scope-manager': 7.5.0 '@typescript-eslint/types': 7.5.0 - '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.3) + '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.4) eslint: 8.57.0 semver: 7.6.0 transitivePeerDependencies: @@ -3145,7 +3115,7 @@ packages: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} dev: true - /cosmiconfig-typescript-loader@5.0.0(@types/node@20.12.4)(cosmiconfig@9.0.0)(typescript@5.4.3): + /cosmiconfig-typescript-loader@5.0.0(@types/node@20.12.4)(cosmiconfig@9.0.0)(typescript@5.4.4): resolution: {integrity: sha512-+8cK7jRAReYkMwMiG+bxhcNKiHJDM6bR9FD/nGBXOWdMLuYawjF5cGrtLilJ+LGd3ZjCXnJjR5DkfWPoIVlqJA==} engines: {node: '>=v16'} peerDependencies: @@ -3154,9 +3124,9 @@ packages: typescript: '>=4' dependencies: '@types/node': 20.12.4 - cosmiconfig: 9.0.0(typescript@5.4.3) + cosmiconfig: 9.0.0(typescript@5.4.4) jiti: 1.21.0 - typescript: 5.4.3 + typescript: 5.4.4 dev: true /cosmiconfig@7.0.1: @@ -3170,7 +3140,7 @@ packages: yaml: 1.10.2 dev: false - /cosmiconfig@8.3.6(typescript@5.4.3): + /cosmiconfig@8.3.6(typescript@5.4.4): resolution: {integrity: sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==} engines: {node: '>=14'} peerDependencies: @@ -3183,10 +3153,10 @@ packages: js-yaml: 4.1.0 parse-json: 5.2.0 path-type: 4.0.0 - typescript: 5.4.3 + typescript: 5.4.4 dev: true - /cosmiconfig@9.0.0(typescript@5.4.3): + /cosmiconfig@9.0.0(typescript@5.4.4): resolution: {integrity: sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==} engines: {node: '>=14'} peerDependencies: @@ -3199,7 +3169,7 @@ packages: import-fresh: 3.3.0 js-yaml: 4.1.0 parse-json: 5.2.0 - typescript: 5.4.3 + typescript: 5.4.4 dev: true /cross-env@7.0.3: @@ -3766,7 +3736,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 7.5.0(eslint@8.57.0)(typescript@5.4.3) + '@typescript-eslint/parser': 7.5.0(eslint@8.57.0)(typescript@5.4.4) debug: 3.2.7 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 @@ -3803,7 +3773,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 7.5.0(eslint@8.57.0)(typescript@5.4.3) + '@typescript-eslint/parser': 7.5.0(eslint@8.57.0)(typescript@5.4.4) array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2 @@ -6849,7 +6819,7 @@ packages: stylelint: '>=14.0.0' dependencies: postcss-html: 1.6.0 - stylelint: 16.3.1(typescript@5.4.3) + stylelint: 16.3.1(typescript@5.4.4) dev: true /stylelint-config-recess-order@5.0.0(stylelint@16.3.1): @@ -6857,7 +6827,7 @@ packages: peerDependencies: stylelint: '>=16' dependencies: - stylelint: 16.3.1(typescript@5.4.3) + stylelint: 16.3.1(typescript@5.4.4) stylelint-order: 6.0.4(stylelint@16.3.1) dev: true @@ -6867,7 +6837,7 @@ packages: peerDependencies: stylelint: ^16.0.0 dependencies: - stylelint: 16.3.1(typescript@5.4.3) + stylelint: 16.3.1(typescript@5.4.4) dev: true /stylelint-config-standard@36.0.0(stylelint@16.3.1): @@ -6876,7 +6846,7 @@ packages: peerDependencies: stylelint: ^16.1.0 dependencies: - stylelint: 16.3.1(typescript@5.4.3) + stylelint: 16.3.1(typescript@5.4.4) stylelint-config-recommended: 14.0.0(stylelint@16.3.1) dev: true @@ -6886,7 +6856,7 @@ packages: peerDependencies: stylelint: ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 dependencies: - stylelint: 16.3.1(typescript@5.4.3) + stylelint: 16.3.1(typescript@5.4.4) dev: true /stylelint-order@6.0.4(stylelint@16.3.1): @@ -6896,7 +6866,7 @@ packages: dependencies: postcss: 8.4.38 postcss-sorting: 8.0.2(postcss@8.4.38) - stylelint: 16.3.1(typescript@5.4.3) + stylelint: 16.3.1(typescript@5.4.4) dev: true /stylelint-scss@6.2.1(stylelint@16.3.1): @@ -6910,10 +6880,10 @@ packages: postcss-resolve-nested-selector: 0.1.1 postcss-selector-parser: 6.0.15 postcss-value-parser: 4.2.0 - stylelint: 16.3.1(typescript@5.4.3) + stylelint: 16.3.1(typescript@5.4.4) dev: true - /stylelint@16.3.1(typescript@5.4.3): + /stylelint@16.3.1(typescript@5.4.4): resolution: {integrity: sha512-/JOwQnBvxEKOT2RtNgGpBVXnCSMBgKOL2k7w0K52htwCyJls4+cHvc4YZgXlVoAZS9QJd2DgYAiRnja96pTgxw==} engines: {node: '>=18.12.0'} hasBin: true @@ -6925,7 +6895,7 @@ packages: '@dual-bundle/import-meta-resolve': 4.0.0 balanced-match: 2.0.0 colord: 2.9.3 - cosmiconfig: 9.0.0(typescript@5.4.3) + cosmiconfig: 9.0.0(typescript@5.4.4) css-functions-list: 3.2.1 css-tree: 2.3.1 debug: 4.3.4 @@ -7086,16 +7056,16 @@ packages: resolution: {integrity: sha512-tmMpK00BjZiUyVyvrBK7knerNgmgvcV/KLVyuma/SC+TQN167GrMRciANTz09+k3zW8L8t60jWO1GpfkZdjTaw==} dev: false - /ts-api-utils@1.0.3(typescript@5.4.3): + /ts-api-utils@1.0.3(typescript@5.4.4): resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} engines: {node: '>=16.13.0'} peerDependencies: typescript: '>=4.2.0' dependencies: - typescript: 5.4.3 + typescript: 5.4.4 dev: true - /tsconfck@3.0.3(typescript@5.4.3): + /tsconfck@3.0.3(typescript@5.4.4): resolution: {integrity: sha512-4t0noZX9t6GcPTfBAbIbbIU4pfpCwh0ueq3S4O/5qXI1VwK1outmxhe9dOiEWqMz3MW2LKgDTpqWV+37IWuVbA==} engines: {node: ^18 || >=20} hasBin: true @@ -7105,7 +7075,7 @@ packages: typescript: optional: true dependencies: - typescript: 5.4.3 + typescript: 5.4.4 dev: true /tsconfig-paths@3.15.0: @@ -7235,8 +7205,8 @@ packages: possible-typed-array-names: 1.0.0 dev: true - /typescript@5.4.3: - resolution: {integrity: sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==} + /typescript@5.4.4: + resolution: {integrity: sha512-dGE2Vv8cpVvw28v8HCPqyb08EzbBURxDpuhJvTrusShUfGnhHBafDsLdS1EhhxyL6BJQE+2cT3dDPAv+MQ6oLw==} engines: {node: '>=14.17'} hasBin: true dev: true @@ -7400,13 +7370,13 @@ packages: vite: 5.2.8(@types/node@20.12.4)(sass@1.74.1) dev: true - /vite-plugin-svgr@4.2.0(typescript@5.4.3)(vite@5.2.8): + /vite-plugin-svgr@4.2.0(typescript@5.4.4)(vite@5.2.8): resolution: {integrity: sha512-SC7+FfVtNQk7So0XMjrrtLAbEC8qjFPifyD7+fs/E6aaNdVde6umlVVh0QuwDLdOMu7vp5RiGFsB70nj5yo0XA==} peerDependencies: vite: ^2.6.0 || 3 || 4 || 5 dependencies: '@rollup/pluginutils': 5.0.5 - '@svgr/core': 8.1.0(typescript@5.4.3) + '@svgr/core': 8.1.0(typescript@5.4.4) '@svgr/plugin-jsx': 8.1.0(@svgr/core@8.1.0) vite: 5.2.8(@types/node@20.12.4)(sass@1.74.1) transitivePeerDependencies: @@ -7415,7 +7385,7 @@ packages: - typescript dev: true - /vite-tsconfig-paths@4.3.2(typescript@5.4.3)(vite@5.2.8): + /vite-tsconfig-paths@4.3.2(typescript@5.4.4)(vite@5.2.8): resolution: {integrity: sha512-0Vd/a6po6Q+86rPlntHye7F31zA2URZMbH8M3saAZ/xR9QoGN/L21bxEGfXdWmFdNkqPpRdxFT7nmNe12e9/uA==} peerDependencies: vite: '*' @@ -7425,7 +7395,7 @@ packages: dependencies: debug: 4.3.4 globrex: 0.1.2 - tsconfck: 3.0.3(typescript@5.4.3) + tsconfck: 3.0.3(typescript@5.4.4) vite: 5.2.8(@types/node@20.12.4)(sass@1.74.1) transitivePeerDependencies: - supports-color diff --git a/echo/.github/workflows/cd.yaml b/echo/.github/workflows/cd.yaml index f2ba449e26..9a6cd48e67 100644 --- a/echo/.github/workflows/cd.yaml +++ b/echo/.github/workflows/cd.yaml @@ -1,6 +1,9 @@ name: build-image on: + schedule: + # 每天 UTC 时间 00:00 自动触发构建 + - cron: "0 0 * * *" push: tags: - "*" diff --git a/echo/.goreleaser.yml b/echo/.goreleaser.yml index d670de0c19..adad3873e8 100644 --- a/echo/.goreleaser.yml +++ b/echo/.goreleaser.yml @@ -32,3 +32,6 @@ changelog: upx: - enabled: true compress: 9 + +release: + prerelease: auto diff --git a/echo/pkg/sub/clash.go b/echo/pkg/sub/clash.go index bc652a3aad..088171b186 100644 --- a/echo/pkg/sub/clash.go +++ b/echo/pkg/sub/clash.go @@ -109,32 +109,11 @@ func (c *ClashSub) Refresh() error { return nil } +// ToRelayConfigs convert clash sub to relay configs +// Proxy's port will be used as relay listen port +// Group's proxies will be merged into load balance in relay +// a new free port will be used as relay listen port for each group func (c *ClashSub) ToRelayConfigs(listenHost string) ([]*relay_cfg.Config, error) { - // assign free port to proxies in batch - needAssign := 0 - for _, proxy := range *c.cCfg.Proxies { - if proxy.freePort == "" { - needAssign++ - } - if proxy.groupLeader != nil && proxy.groupLeader.freePort == "" { - needAssign++ - } - } - freePortList, err := getFreePortInBatch(listenHost, needAssign) - if err != nil { - return nil, err - } - for i, p := range *c.cCfg.Proxies { - if p.freePort == "" { - (*c.cCfg.Proxies)[i].freePort = strconv.Itoa(freePortList[0]) - freePortList = freePortList[1:] - } - if p.groupLeader != nil && p.groupLeader.freePort == "" { - (*c.cCfg.Proxies)[i].groupLeader.freePort = strconv.Itoa(freePortList[0]) - freePortList = freePortList[1:] - } - } - relayConfigs := []*relay_cfg.Config{} // generate relay config for each proxy for _, proxy := range *c.cCfg.Proxies { @@ -144,7 +123,7 @@ func (c *ClashSub) ToRelayConfigs(listenHost string) ([]*relay_cfg.Config, error } else { newName = fmt.Sprintf("%s-%s", proxy.Name, c.Name) } - rc, err := proxy.ToRelayConfig(listenHost, proxy.freePort, newName) + rc, err := proxy.ToRelayConfig(listenHost, proxy.Port, newName) if err != nil { return nil, err } @@ -162,12 +141,25 @@ func (c *ClashSub) ToRelayConfigs(listenHost string) ([]*relay_cfg.Config, error } else { newName = fmt.Sprintf("%s-lb", groupName) } - rc, err := groupLeader.ToRelayConfig(listenHost, groupLeader.freePort, newName) + + // group listen port is the max port in group + 1 + port := 0 + for _, proxy := range proxies { + pp, err := strconv.Atoi(proxy.Port) + if err != nil { + return nil, err + } + if pp > port { + port = pp + } + } + port++ + rc, err := groupLeader.ToRelayConfig(listenHost, strconv.Itoa(port), newName) if err != nil { return nil, err } - // add other proxies in group to relay config + // add other proxies address in group to relay config for _, proxy := range proxies[1:] { remote := net.JoinHostPort(proxy.rawServer, proxy.rawPort) // skip duplicate remote, because the relay cfg for this leader will be cached when first init diff --git a/echo/pkg/sub/clash_types.go b/echo/pkg/sub/clash_types.go index 5b8689d888..d36e6822d7 100644 --- a/echo/pkg/sub/clash_types.go +++ b/echo/pkg/sub/clash_types.go @@ -88,7 +88,6 @@ type Proxies struct { rawServer string rawPort string relayCfg *relay_cfg.Config - freePort string groupLeader *Proxies } diff --git a/echo/pkg/sub/utils.go b/echo/pkg/sub/utils.go index 4dafebf08f..d3c72e080c 100644 --- a/echo/pkg/sub/utils.go +++ b/echo/pkg/sub/utils.go @@ -3,7 +3,6 @@ package sub import ( "fmt" "io" - "net" "net/http" "sort" "strings" @@ -12,25 +11,6 @@ import ( var client = http.Client{Timeout: time.Second * 10} -// todo: fix this use sync way to ensure the port is free -func getFreePortInBatch(host string, count int) ([]int, error) { - res := make([]int, 0, count) - listenerList := make([]net.Listener, 0, count) - for i := 0; i < count; i++ { - listener, err := net.Listen("tcp", fmt.Sprintf("%s:0", host)) - if err != nil { - return res, err - } - listenerList = append(listenerList, listener) - address := listener.Addr().(*net.TCPAddr) - res = append(res, address.Port) - } - for _, listener := range listenerList { - _ = listener.Close() - } - return res, nil -} - func getHttpBody(url string) ([]byte, error) { resp, err := client.Get(url) if err != nil { diff --git a/lede/include/kernel-6.6 b/lede/include/kernel-6.6 index d2c082c447..5c67d52577 100644 --- a/lede/include/kernel-6.6 +++ b/lede/include/kernel-6.6 @@ -1,2 +1,2 @@ -LINUX_VERSION-6.6 = .24 -LINUX_KERNEL_HASH-6.6.24 = 3e9ef879dae8319338eb0dc2d2c2025c13257fdeddf6245c000cb5a85a8af6f5 +LINUX_VERSION-6.6 = .25 +LINUX_KERNEL_HASH-6.6.25 = 99d210be87908233a55b0fadc0dccd3b95926c0651b6b82e37350b2029de1f44 diff --git a/lede/package/boot/arm-trusted-firmware-rockchip-vendor/Makefile b/lede/package/boot/arm-trusted-firmware-rockchip-vendor/Makefile index 1374f16a2f..1668a8c3a9 100644 --- a/lede/package/boot/arm-trusted-firmware-rockchip-vendor/Makefile +++ b/lede/package/boot/arm-trusted-firmware-rockchip-vendor/Makefile @@ -1,81 +1,96 @@ # SPDX-License-Identifier: GPL-2.0-only # -# Copyright (C) 2022 ImmortalWrt.org +# Copyright (C) 2021-2023 ImmortalWrt.org include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/trusted-firmware-a.mk -PKG_NAME:=arm-trusted-firmware-rockchip-vendor -PKG_RELEASE:=$(AUTORELEASE) +PKG_NAME:=rkbin +PKG_RELEASE:=1 PKG_SOURCE_PROTO:=git -PKG_SOURCE_URL=https://github.com/rockchip-linux/rkbin.git -PKG_SOURCE_DATE:=2023-07-26 -PKG_SOURCE_VERSION:=b4558da0860ca48bf1a571dd33ccba580b9abe23 -PKG_MIRROR_HASH:=039f0f72d0dd179487b5d4b135d13684b220f3d81fa7308a34431a86701f69c6 +PKG_SOURCE_URL:=https://gitlab.com/rk3588_linux/rk/rkbin.git +PKG_SOURCE_DATE:=2023-08-04 +PKG_SOURCE_VERSION:=1a417bbf7d05c3491ee9613be12a9905fbb8ccb7 +PKG_MIRROR_HASH:=5ca2f3b759759ed7c5be70e7ec5e1f0c8d82b6db8265e83f637a55b2b3d61fe5 PKG_MAINTAINER:=Tianling Shen -MAKE_PATH:=$(PKG_NAME) - include $(INCLUDE_DIR)/package.mk +include ./atf-version.mk -define Package/arm-trusted-firmware-rockchip-vendor - SECTION:=boot - CATEGORY:=Boot Loaders - TITLE:=ARM Trusted Firmware for Rockchip +define Trusted-Firmware-A/Default + NAME:=Rockchip $(1) + BUILD_TARGET:=rockchip endef -define Package/arm-trusted-firmware-rk3328 - $(Package/arm-trusted-firmware-rockchip-vendor) - DEPENDS:=@TARGET_rockchip_armv8 - VARIANT:=rk3328 +define Trusted-Firmware-A/rk3328 + ATF:=rk33/$(RK3328_ATF) + DDR:=rk33/$(RK3328_DDR) + LOADER:=rk33/$(RK3328_LOADER) endef -define Package/arm-trusted-firmware-rk3399 - $(Package/arm-trusted-firmware-rockchip-vendor) - DEPENDS:=@TARGET_rockchip_armv8 - VARIANT:=rk3399 +define Trusted-Firmware-A/rk3399 + ATF:=rk33/$(RK3399_ATF) + DDR:=rk33/$(RK3399_DDR) + LOADER:=rk33/$(RK3399_LOADER) endef -define Package/arm-trusted-firmware-rk3566 - $(Package/arm-trusted-firmware-rockchip-vendor) - DEPENDS:=@TARGET_rockchip_armv8 - VARIANT:=rk3566 +define Trusted-Firmware-A/rk3528 + ATF:=rk35/$(RK3528_ATF) + DDR:=rk35/$(RK3528_DDR) endef -define Package/arm-trusted-firmware-rk3568 - $(Package/arm-trusted-firmware-rockchip-vendor) - DEPENDS:=@TARGET_rockchip_armv8 - VARIANT:=rk3568 +define Trusted-Firmware-A/rk3566 + ATF:=rk35/$(RK3568_ATF) + DDR:=rk35/$(RK3566_DDR) endef -define Build/Configure - $(SED) 's,$$$$(PKG_BUILD_DIR),$(PKG_BUILD_DIR),g' $(PKG_BUILD_DIR)/trust.ini - $(SED) 's,$$$$(VARIANT),$(BUILD_VARIANT),g' $(PKG_BUILD_DIR)/trust.ini - $(call Build/Configure/Default) +define Trusted-Firmware-A/rk3568 + ATF:=rk35/$(RK3568_ATF) + DDR:=rk35/$(RK3568_DDR) endef +define Trusted-Firmware-A/rk3588 + ATF:=rk35/$(RK3588_ATF) + DDR:=rk35/$(RK3588_DDR) +endef + +TFA_TARGETS:= \ + rk3328 \ + rk3399 \ + rk3528 \ + rk3566 \ + rk3568 \ + rk3588 + define Build/Compile - $(CURDIR)/pack-firmware.sh build $(BUILD_VARIANT) '$(PKG_BUILD_DIR)' + # This comment is the workaround for "extraneous 'endif'" error +ifneq ($(LOADER),) + ( \ + pushd $(PKG_BUILD_DIR) ; \ + $(SED) 's,$$$$(PKG_BUILD_DIR),$(PKG_BUILD_DIR),g' trust.ini ; \ + $(SED) 's,$$$$(VARIANT),$(BUILD_VARIANT),g' trust.ini ; \ + ./tools/mkimage -n $(BUILD_VARIANT) -T rksd -d bin/$(DDR) \ + $(BUILD_VARIANT)-idbloader.bin ; \ + cat bin/$(LOADER) >> $(BUILD_VARIANT)-idbloader.bin ; \ + ./tools/trust_merger --replace bl31.elf bin/$(ATF) trust.ini ; \ + popd ; \ + ) +endif endef -define Build/InstallDev - $(CURDIR)/pack-firmware.sh install $(BUILD_VARIANT) '$(PKG_BUILD_DIR)' '$(STAGING_DIR_IMAGE)' +define Package/trusted-firmware-a/install + $(INSTALL_DIR) $(STAGING_DIR_IMAGE) + + $(CP) $(PKG_BUILD_DIR)/bin/$(ATF) $(STAGING_DIR_IMAGE)/ +ifneq ($(LOADER),) + $(CP) $(PKG_BUILD_DIR)/tools/loaderimage $(STAGING_DIR_IMAGE)/ + $(CP) $(PKG_BUILD_DIR)/$(BUILD_VARIANT)-idbloader.bin $(STAGING_DIR_IMAGE)/ + $(CP) $(PKG_BUILD_DIR)/$(BUILD_VARIANT)-trust.bin $(STAGING_DIR_IMAGE)/ +else + $(CP) $(PKG_BUILD_DIR)/bin/$(DDR) $(STAGING_DIR_IMAGE)/ +endif endef -define Package/arm-trusted-firmware-rk3328/install -endef - -define Package/arm-trusted-firmware-rk3399/install -endef - -define Package/arm-trusted-firmware-rk3566/install -endef - -define Package/arm-trusted-firmware-rk3568/install -endef - -$(eval $(call BuildPackage,arm-trusted-firmware-rk3328)) -$(eval $(call BuildPackage,arm-trusted-firmware-rk3399)) -$(eval $(call BuildPackage,arm-trusted-firmware-rk3566)) -$(eval $(call BuildPackage,arm-trusted-firmware-rk3568)) +$(eval $(call BuildPackage/Trusted-Firmware-A)) \ No newline at end of file diff --git a/lede/package/boot/arm-trusted-firmware-rockchip-vendor/atf-version.mk b/lede/package/boot/arm-trusted-firmware-rockchip-vendor/atf-version.mk new file mode 100644 index 0000000000..03fc5acd97 --- /dev/null +++ b/lede/package/boot/arm-trusted-firmware-rockchip-vendor/atf-version.mk @@ -0,0 +1,17 @@ +RK3328_ATF:=rk322xh_bl31_v1.49.elf +RK3328_DDR:=rk3328_ddr_333MHz_v1.19.bin +RK3328_LOADER:=rk322xh_miniloader_v2.50.bin + +RK3399_ATF:=rk3399_bl31_v1.36.elf +RK3399_DDR:=rk3399_ddr_800MHz_v1.30.bin +RK3399_LOADER:=rk3399_miniloader_v1.30.bin + +RK3528_ATF:=rk3528_bl31_v1.16.elf +RK3528_DDR:=rk3528_ddr_1056MHz_v1.07.bin + +RK3568_ATF:=rk3568_bl31_v1.43.elf +RK3568_DDR:=rk3568_ddr_1560MHz_v1.18.bin +RK3566_DDR:=rk3566_ddr_1056MHz_v1.18.bin + +RK3588_ATF:=rk3588_bl31_v1.41.elf +RK3588_DDR:=rk3588_ddr_lp4_2112MHz_lp5_2736MHz_v1.13.bin \ No newline at end of file diff --git a/lede/package/boot/arm-trusted-firmware-rockchip-vendor/pack-firmware.sh b/lede/package/boot/arm-trusted-firmware-rockchip-vendor/pack-firmware.sh deleted file mode 100755 index c5d1287a41..0000000000 --- a/lede/package/boot/arm-trusted-firmware-rockchip-vendor/pack-firmware.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# Copyright (C) 2021 ImmortalWrt.org - -ACTION="$1" -VARIANT="$2" -PKG_BUILD_DIR="$3" -STAGING_DIR_IMAGE="$4" - -case "$VARIANT" in -"rk3328") - ATF="rk33/rk322xh_bl31_v1.49.elf" - DDR="rk33/rk3328_ddr_333MHz_v1.19.bin" - LOADER="rk33/rk322xh_miniloader_v2.50.bin" - ;; -"rk3399") - ATF="rk33/rk3399_bl31_v1.36.elf" - DDR="rk33/rk3399_ddr_800MHz_v1.30.bin" - LOADER="rk33/rk3399_miniloader_v1.30.bin" - ;; -"rk3566") - ATF="rk35/rk3568_bl31_v1.43.elf" - DDR="rk35/rk3566_ddr_1056MHz_v1.18.bin" - ;; -"rk3568") - ATF="rk35/rk3568_bl31_v1.43.elf" - DDR="rk35/rk3568_ddr_1560MHz_v1.18.bin" - ;; -"rk3588") - ATF="rk35/rk3588_bl31_v1.40.elf" - DDR="rk35/rk3588_ddr_lp4_2112MHz_lp5_2736MHz_v1.12.bin" - ;; -*) - echo -e "Not compatible with your platform: $VARIANT." - exit 1 - ;; -esac - -set -x -if [ "$ACTION" == "build" ]; then - case "$VARIANT" in - rk33*) - "$PKG_BUILD_DIR"/tools/mkimage -n "$VARIANT" -T "rksd" -d "$PKG_BUILD_DIR/bin/$DDR" "$PKG_BUILD_DIR/$VARIANT-idbloader.bin" - cat "$PKG_BUILD_DIR/bin/$LOADER" >> "$PKG_BUILD_DIR/$VARIANT-idbloader.bin" - "$PKG_BUILD_DIR/tools/trust_merger" --replace "bl31.elf" "$PKG_BUILD_DIR/bin/$ATF" "$PKG_BUILD_DIR/trust.ini" - ;; - esac -elif [ "$ACTION" == "install" ]; then - mkdir -p "$STAGING_DIR_IMAGE" - cp -fp "$PKG_BUILD_DIR/bin/$ATF" "$STAGING_DIR_IMAGE"/ - case "$VARIANT" in - rk33*) - cp -fp "$PKG_BUILD_DIR/tools/loaderimage" "$STAGING_DIR_IMAGE"/ - cp -fp "$PKG_BUILD_DIR/$VARIANT-idbloader.bin" "$STAGING_DIR_IMAGE"/ - cp -fp "$PKG_BUILD_DIR/$VARIANT-trust.bin" "$STAGING_DIR_IMAGE"/ - ;; - rk35*) - cp -fp "$PKG_BUILD_DIR/bin/$DDR" "$STAGING_DIR_IMAGE"/ - ;; - esac -else - echo -e "Unknown operation: $ACTION." - exit 1 -fi -set +x diff --git a/lede/package/boot/uboot-rockchip/Makefile b/lede/package/boot/uboot-rockchip/Makefile index e892c6620a..03ec322432 100644 --- a/lede/package/boot/uboot-rockchip/Makefile +++ b/lede/package/boot/uboot-rockchip/Makefile @@ -29,7 +29,7 @@ define U-Boot/nanopi-r2c-rk3328 NAME:=NanoPi R2C BUILD_DEVICES:= \ friendlyarm_nanopi-r2c - DEPENDS:=+PACKAGE_u-boot-nanopi-r2c-rk3328:arm-trusted-firmware-rk3328 + DEPENDS:=+PACKAGE_u-boot-nanopi-r2c-rk3328:trusted-firmware-a-rk3328 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk322xh_bl31_v1.49.elf USE_RKBIN:=1 @@ -41,7 +41,7 @@ define U-Boot/nanopi-r2s-rk3328 BUILD_DEVICES:= \ friendlyarm_nanopi-r2s \ friendlyarm_nanopi-neo3 - DEPENDS:=+PACKAGE_u-boot-nanopi-r2s-rk3328:arm-trusted-firmware-rk3328 + DEPENDS:=+PACKAGE_u-boot-nanopi-r2s-rk3328:trusted-firmware-a-rk3328 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk322xh_bl31_v1.49.elf USE_RKBIN:=1 @@ -52,7 +52,7 @@ define U-Boot/orangepi-r1-plus-rk3328 NAME:=Orange Pi R1 Plus BUILD_DEVICES:= \ xunlong_orangepi-r1-plus - DEPENDS:=+PACKAGE_u-boot-orangepi-r1-plus-rk3328:arm-trusted-firmware-rk3328 + DEPENDS:=+PACKAGE_u-boot-orangepi-r1-plus-rk3328:trusted-firmware-a-rk3328 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk322xh_bl31_v1.49.elf USE_RKBIN:=1 @@ -63,7 +63,7 @@ define U-Boot/orangepi-r1-plus-lts-rk3328 NAME:=Orange Pi R1 Plus LTS BUILD_DEVICES:= \ xunlong_orangepi-r1-plus-lts - DEPENDS:=+PACKAGE_u-boot-orangepi-r1-plus-lts-rk3328:arm-trusted-firmware-rk3328 + DEPENDS:=+PACKAGE_u-boot-orangepi-r1-plus-lts-rk3328:trusted-firmware-a-rk3328 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk322xh_bl31_v1.49.elf USE_RKBIN:=1 @@ -87,7 +87,7 @@ define U-Boot/nanopi-r4s-rk3399 NAME:=NanoPi R4S BUILD_DEVICES:= \ friendlyarm_nanopi-r4s - DEPENDS:=+PACKAGE_u-boot-nanopi-r4s-rk3399:arm-trusted-firmware-rk3399 + DEPENDS:=+PACKAGE_u-boot-nanopi-r4s-rk3399:trusted-firmware-a-rk3399 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3399_bl31_v1.36.elf USE_RKBIN:=1 @@ -98,7 +98,7 @@ define U-Boot/nanopi-r4se-rk3399 NAME:=NanoPi R4SE BUILD_DEVICES:= \ friendlyarm_nanopi-r4se - DEPENDS:=+PACKAGE_u-boot-nanopi-r4se-rk3399:arm-trusted-firmware-rk3399 + DEPENDS:=+PACKAGE_u-boot-nanopi-r4se-rk3399:trusted-firmware-a-rk3399 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3399_bl31_v1.36.elf USE_RKBIN:=1 @@ -129,7 +129,7 @@ define U-Boot/rongpin-king3399-rk3399 NAME:=Rongpin King3399 BUILD_DEVICES:= \ rongpin_king3399 - DEPENDS:=+PACKAGE_u-boot-rongpin-king3399-rk3399:arm-trusted-firmware-rk3399 + DEPENDS:=+PACKAGE_u-boot-rongpin-king3399-rk3399:trusted-firmware-a-rk3399 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3399_bl31_v1.36.elf USE_RKBIN:=1 @@ -140,7 +140,7 @@ define U-Boot/rocktech-mpc1903-rk3399 NAME:=Rocktech MPC1903 BUILD_DEVICES:= \ rocktech_mpc1903 - DEPENDS:=+PACKAGE_u-boot-rocktech-mpc1903-rk3399:arm-trusted-firmware-rk3399 + DEPENDS:=+PACKAGE_u-boot-rocktech-mpc1903-rk3399:trusted-firmware-a-rk3399 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3399_bl31_v1.36.elf USE_RKBIN:=1 @@ -151,7 +151,7 @@ define U-Boot/sharevdi-h3399pc-rk3399 NAME:=SHAREVDI H3399PC BUILD_DEVICES:= \ sharevdi_h3399pc - DEPENDS:=+PACKAGE_u-boot-sharevdi-h3399pc-rk3399:arm-trusted-firmware-rk3399 + DEPENDS:=+PACKAGE_u-boot-sharevdi-h3399pc-rk3399:trusted-firmware-a-rk3399 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3399_bl31_v1.36.elf USE_RKBIN:=1 @@ -162,7 +162,7 @@ define U-Boot/dilusense-dlfr100-rk3399 NAME:=Dilusense DLFR100 BUILD_DEVICES:= \ dilusense_dlfr100 - DEPENDS:=+PACKAGE_u-boot-dilusense-dlfr100-rk3399:arm-trusted-firmware-rk3399 + DEPENDS:=+PACKAGE_u-boot-dilusense-dlfr100-rk3399:trusted-firmware-a-rk3399 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3399_bl31_v1.36.elf USE_RKBIN:=1 @@ -173,7 +173,7 @@ define U-Boot/xiaobao-nas-v1-rk3399 NAME:=Codinge Xiaobao NAS-I BUILD_DEVICES:= \ codinge_xiaobao-nas-v1 - DEPENDS:=+PACKAGE_u-boot-xiaobao-nas-v1-rk3399:arm-trusted-firmware-rk3399 + DEPENDS:=+PACKAGE_u-boot-xiaobao-nas-v1-rk3399:trusted-firmware-a-rk3399 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3399_bl31_v1.36.elf USE_RKBIN:=1 @@ -186,7 +186,7 @@ define U-Boot/panther-x2-rk3566 NAME:=Panther X2 BUILD_DEVICES:= \ panther_x2 - DEPENDS:=+PACKAGE_u-boot-panther-x2-rk3566:arm-trusted-firmware-rk3566 + DEPENDS:=+PACKAGE_u-boot-panther-x2-rk3566:trusted-firmware-a-rk3566 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3566_ddr_1056MHz_v1.18.bin @@ -199,7 +199,7 @@ define U-Boot/lyt-t68m-rk3568 NAME:=LYT T68M BUILD_DEVICES:= \ lyt_t68m - DEPENDS:=+PACKAGE_u-boot-lyt-t68m-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-lyt-t68m-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -211,7 +211,7 @@ define U-Boot/mrkaio-m68s-rk3568 BUILD_DEVICES:= \ ezpro_mrkaio-m68s \ ezpro_mrkaio-m68s-plus - DEPENDS:=+PACKAGE_u-boot-mrkaio-m68s-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-mrkaio-m68s-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -223,7 +223,7 @@ define U-Boot/nanopi-r5s-rk3568 BUILD_DEVICES:= \ friendlyarm_nanopi-r5c \ friendlyarm_nanopi-r5s - DEPENDS:=+PACKAGE_u-boot-nanopi-r5s-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-nanopi-r5s-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -236,7 +236,7 @@ define U-Boot/opc-h68k-rk3568 hinlink_opc-h66k \ hinlink_opc-h68k \ hinlink_opc-h69k - DEPENDS:=+PACKAGE_u-boot-opc-h68k-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-opc-h68k-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -247,7 +247,7 @@ define U-Boot/photonicat-rk3568 NAME:=Ariaboard Photonicat BUILD_DEVICES:= \ ariaboard_photonicat - DEPENDS:=+PACKAGE_u-boot-photonicat-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-photonicat-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -258,7 +258,7 @@ define U-Boot/radxa-e25-rk3568 NAME:=Radxa E25 BUILD_DEVICES:= \ radxa_e25 - DEPENDS:=+PACKAGE_u-boot-radxa-e25-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-radxa-e25-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -269,7 +269,7 @@ define U-Boot/rock-3a-rk3568 NAME:=ROCK3 Model A BUILD_DEVICES:= \ radxa_rock-3a - DEPENDS:=+PACKAGE_u-boot-rock-3a-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-rock-3a-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -281,7 +281,7 @@ define U-Boot/r66s-rk3568 BUILD_DEVICES:= \ fastrhino_r66s \ fastrhino_r68s - DEPENDS:=+PACKAGE_u-boot-r66s-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-r66s-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -292,7 +292,7 @@ define U-Boot/seewo-sv21-rk3568 NAME:=Seewo sv21-rk3568 BUILD_DEVICES:= \ seewo_sv21-rk3568 - DEPENDS:=+PACKAGE_u-boot-seewo-sv21-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-seewo-sv21-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin @@ -303,13 +303,25 @@ define U-Boot/station-p2-rk3568 NAME:=StationP2 BUILD_DEVICES:= \ firefly_station-p2 - DEPENDS:=+PACKAGE_u-boot-station-p2-rk3568:arm-trusted-firmware-rk3568 + DEPENDS:=+PACKAGE_u-boot-station-p2-rk3568:trusted-firmware-a-rk3568 + PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor + ATF:=rk3568_bl31_v1.43.elf + DDR:=rk3568_ddr_1560MHz_v1.18.bin +endef + +define U-Boot/advantech-rsb4810-rk3568 + BUILD_SUBTARGET:=armv8 + NAME:=Advantech RSB4810 + BUILD_DEVICES:= \ + advantech_rsb4810 + DEPENDS:=+PACKAGE_u-boot-advantech-rsb4810-rk3568:trusted-firmware-a-rk3568 PKG_BUILD_DEPENDS:=arm-trusted-firmware-rockchip-vendor ATF:=rk3568_bl31_v1.43.elf DDR:=rk3568_ddr_1560MHz_v1.18.bin endef UBOOT_TARGETS := \ + advantech-rsb4810-rk3568 \ lyt-t68m-rk3568 \ mrkaio-m68s-rk3568 \ opc-h68k-rk3568 \ @@ -342,12 +354,12 @@ UBOOT_MAKE_FLAGS += \ PATH=$(STAGING_DIR_HOST)/bin:$(PATH) \ BL31=$(STAGING_DIR_IMAGE)/$(ATF) -ifeq ($(CONFIG_PACKAGE_arm-trusted-firmware-rk3568),y) +ifeq ($(CONFIG_PACKAGE_trusted-firmware-a-rk3568),y) UBOOT_MAKE_FLAGS += \ ROCKCHIP_TPL=$(STAGING_DIR_IMAGE)/$(DDR) endif -ifeq ($(CONFIG_PACKAGE_arm-trusted-firmware-rk3566),y) +ifeq ($(CONFIG_PACKAGE_trusted-firmware-a-rk3566),y) UBOOT_MAKE_FLAGS += \ ROCKCHIP_TPL=$(STAGING_DIR_IMAGE)/$(DDR) endif diff --git a/lede/package/boot/uboot-rockchip/patches/318-rockchip-rk3568-Add-support-for-advantech-rsb4810.patch b/lede/package/boot/uboot-rockchip/patches/318-rockchip-rk3568-Add-support-for-advantech-rsb4810.patch new file mode 100644 index 0000000000..3e1df85747 --- /dev/null +++ b/lede/package/boot/uboot-rockchip/patches/318-rockchip-rk3568-Add-support-for-advantech-rsb4810.patch @@ -0,0 +1,146 @@ +--- a/arch/arm/dts/Makefile ++++ b/arch/arm/dts/Makefile +@@ -184,7 +184,8 @@ dtb-$(CONFIG_ROCKCHIP_RK3568) += \ + rk3568-evb.dtb \ + rk3568-r66s.dtb \ + rk3568-rock-3a.dtb \ +- rk3568-radxa-e25.dtb ++ rk3568-radxa-e25.dtb \ ++ rk3568-rsb4810.dtb + + dtb-$(CONFIG_ROCKCHIP_RK3588) += \ + rk3588-edgeble-neu6a-io.dtb \ +--- /dev/null ++++ b/arch/arm/dts/rk3568-rsb4810.dts +@@ -0,0 +1,19 @@ ++// SPDX-License-Identifier: (GPL-2.0+ OR MIT) ++/* ++ * Copyright (c) 2021 Rockchip Electronics Co., Ltd. ++ * ++ */ ++ ++/dts-v1/; ++#include ++#include ++#include "rk3568.dtsi" ++ ++/ { ++ model = "Advantech RK3568 RSB4810 Board"; ++ compatible = "advantech-rsb4810", "rockchip,rk3568"; ++}; ++ ++&uart2 { ++ status = "okay"; ++}; +--- /dev/null ++++ b/arch/arm/dts/rk3568-rsb4810-u-boot.dtsi +@@ -0,0 +1,23 @@ ++// SPDX-License-Identifier: GPL-2.0+ ++/* ++ * (C) Copyright 2021 Rockchip Electronics Co., Ltd ++ */ ++ ++#include "rk356x-u-boot.dtsi" ++ ++/ { ++ chosen { ++ stdout-path = &uart2; ++ u-boot,spl-boot-order = "same-as-spl", &sdmmc0, &sdhci; ++ }; ++}; ++ ++&sdmmc0 { ++ status = "okay"; ++}; ++ ++&uart2 { ++ clock-frequency = <24000000>; ++ u-boot,dm-spl; ++ status = "okay"; ++}; +--- /dev/null ++++ b/configs/advantech-rsb4810-rk3568_defconfig +@@ -0,0 +1,83 @@ ++CONFIG_ARM=y ++CONFIG_SKIP_LOWLEVEL_INIT=y ++CONFIG_COUNTER_FREQUENCY=24000000 ++CONFIG_ARCH_ROCKCHIP=y ++CONFIG_TEXT_BASE=0x00a00000 ++CONFIG_SPL_LIBCOMMON_SUPPORT=y ++CONFIG_SPL_LIBGENERIC_SUPPORT=y ++CONFIG_NR_DRAM_BANKS=2 ++CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y ++CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xc00000 ++CONFIG_DEFAULT_DEVICE_TREE="rk3568-rsb4810" ++CONFIG_ROCKCHIP_RK3568=y ++CONFIG_SPL_ROCKCHIP_COMMON_BOARD=y ++CONFIG_SPL_SERIAL=y ++CONFIG_SPL_STACK_R_ADDR=0x600000 ++CONFIG_SPL_STACK=0x400000 ++CONFIG_DEBUG_UART_BASE=0xFE660000 ++CONFIG_DEBUG_UART_CLOCK=24000000 ++CONFIG_SYS_LOAD_ADDR=0xc00800 ++CONFIG_DEBUG_UART=y ++CONFIG_FIT=y ++CONFIG_FIT_VERBOSE=y ++CONFIG_SPL_LOAD_FIT=y ++CONFIG_LEGACY_IMAGE_FORMAT=y ++CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-rsb4810.dtb" ++# CONFIG_DISPLAY_CPUINFO is not set ++CONFIG_DISPLAY_BOARDINFO_LATE=y ++CONFIG_SPL_MAX_SIZE=0x40000 ++CONFIG_SPL_PAD_TO=0x7f8000 ++CONFIG_SPL_HAS_BSS_LINKER_SECTION=y ++CONFIG_SPL_BSS_START_ADDR=0x4000000 ++CONFIG_SPL_BSS_MAX_SIZE=0x4000 ++# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set ++# CONFIG_SPL_SHARES_INIT_SP_ADDR is not set ++CONFIG_SPL_STACK_R=y ++CONFIG_SPL_ATF=y ++CONFIG_CMD_GPIO=y ++CONFIG_CMD_GPT=y ++CONFIG_CMD_I2C=y ++CONFIG_CMD_MMC=y ++CONFIG_CMD_USB=y ++# CONFIG_CMD_SETEXPR is not set ++CONFIG_CMD_PMIC=y ++CONFIG_CMD_REGULATOR=y ++# CONFIG_SPL_DOS_PARTITION is not set ++CONFIG_SPL_OF_CONTROL=y ++CONFIG_OF_LIVE=y ++CONFIG_OF_SPL_REMOVE_PROPS="clock-names interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents" ++CONFIG_SPL_REGMAP=y ++CONFIG_SPL_SYSCON=y ++CONFIG_SPL_CLK=y ++CONFIG_ROCKCHIP_GPIO=y ++CONFIG_SYS_I2C_ROCKCHIP=y ++CONFIG_MISC=y ++CONFIG_SUPPORT_EMMC_RPMB=y ++CONFIG_MMC_DW=y ++CONFIG_MMC_DW_ROCKCHIP=y ++CONFIG_MMC_SDHCI=y ++CONFIG_MMC_SDHCI_SDMA=y ++CONFIG_MMC_SDHCI_ROCKCHIP=y ++CONFIG_ETH_DESIGNWARE=y ++CONFIG_GMAC_ROCKCHIP=y ++CONFIG_PHY_ROCKCHIP_INNO_USB2=y ++CONFIG_PHY_ROCKCHIP_NANENG_COMBOPHY=y ++CONFIG_SPL_PINCTRL=y ++CONFIG_DM_PMIC=y ++CONFIG_PMIC_RK8XX=y ++CONFIG_REGULATOR_RK8XX=y ++CONFIG_PWM_ROCKCHIP=y ++CONFIG_SPL_RAM=y ++CONFIG_BAUDRATE=1500000 ++CONFIG_DEBUG_UART_SHIFT=2 ++CONFIG_SYS_NS16550_MEM32=y ++CONFIG_SYSRESET=y ++CONFIG_USB=y ++CONFIG_USB_XHCI_HCD=y ++CONFIG_USB_XHCI_DWC3=y ++CONFIG_USB_EHCI_HCD=y ++CONFIG_USB_EHCI_GENERIC=y ++CONFIG_USB_OHCI_HCD=y ++CONFIG_USB_OHCI_GENERIC=y ++CONFIG_USB_DWC3=y ++CONFIG_ERRNO_STR=y diff --git a/lede/package/boot/uboot-sunxi/patches/501-fix-int-phy-eth-h3-h6-with-ac300.patch b/lede/package/boot/uboot-sunxi/patches/501-fix-int-phy-eth-h3-h6-with-ac300.patch index 43abaec1fa..bf734d2947 100644 --- a/lede/package/boot/uboot-sunxi/patches/501-fix-int-phy-eth-h3-h6-with-ac300.patch +++ b/lede/package/boot/uboot-sunxi/patches/501-fix-int-phy-eth-h3-h6-with-ac300.patch @@ -24,7 +24,7 @@ #ifdef CONFIG_LED_STATUS if (IS_ENABLED(CONFIG_SPL_DRIVERS_MISC)) -@@ -667,25 +670,31 @@ +@@ -667,25 +670,33 @@ */ if (!power_failed) clock_set_pll1(get_board_sys_clk()); @@ -51,6 +51,7 @@ - data[0] = 0x08; - data[1] = 0x14; - i2c_write(0x10, 0, 1, data, 2); ++#if CONFIG_IS_ENABLED(SPL_I2C) && CONFIG_IS_ENABLED(SPL_SYS_I2C_LEGACY) + val=readl(0x300622c); + if((val&sunxi_ac300_key)==0) + { @@ -71,6 +72,7 @@ + data[1] = 0x14; + i2c_write(0x10, 0, 1, data, 2); + } ++#endif } #endif /* CONFIG_SPL_BUILD */ diff --git a/lede/target/linux/rockchip/armv8/base-files/etc/board.d/02_network b/lede/target/linux/rockchip/armv8/base-files/etc/board.d/02_network index 12ce6a7810..7573d939c8 100755 --- a/lede/target/linux/rockchip/armv8/base-files/etc/board.d/02_network +++ b/lede/target/linux/rockchip/armv8/base-files/etc/board.d/02_network @@ -8,6 +8,7 @@ rockchip_setup_interfaces() local board="$1" case "$board" in + advantech,rsb4810|\ ariaboard,photonicat|\ dilusense,dlfr100|\ ezpro,mrkaio-m68s|\ @@ -77,6 +78,7 @@ rockchip_setup_macs() local label_mac="" case "$board" in + advantech,rsb4810|\ ariaboard,photonicat|\ codinge,xiaobao-nas-v1|\ dilusense,dlfr100|\ diff --git a/lede/target/linux/rockchip/files/arch/arm64/boot/dts/rockchip/rk3568-rsb4810.dts b/lede/target/linux/rockchip/files/arch/arm64/boot/dts/rockchip/rk3568-rsb4810.dts new file mode 100644 index 0000000000..139d2cd8cf --- /dev/null +++ b/lede/target/linux/rockchip/files/arch/arm64/boot/dts/rockchip/rk3568-rsb4810.dts @@ -0,0 +1,890 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) + +/dts-v1/; +#include +#include +#include +#include "rk3568.dtsi" + +/ { + model = "Advantech RK3568 RSB4810 Board"; + compatible = "advantech,rsb4810", "rockchip,rk3568"; + + aliases { + ethernet0 = &gmac0; + ethernet1 = &gmac1; + mmc0 = &sdhci; + mmc1 = &sdmmc0; + }; + + chosen: chosen { + stdout-path = "serial2:1500000n8"; + }; + +#ifdef DTS_NO_LEGACY + hdmi-con { + compatible = "hdmi-connector"; + type = "a"; + + port { + hdmi_con_in: endpoint { + remote-endpoint = <&hdmi_out_con>; + }; + }; + }; +#endif + + dc_12v: dc-12v { + compatible = "regulator-fixed"; + regulator-name = "dc_12v"; + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <12000000>; + regulator-max-microvolt = <12000000>; + }; + + vcc3v3_sys: vcc3v3-sys { + compatible = "regulator-fixed"; + regulator-name = "vcc3v3_sys"; + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + vin-supply = <&dc_12v>; + }; + + vcc5v0_sys: vcc5v0-sys { + compatible = "regulator-fixed"; + regulator-name = "vcc5v0_sys"; + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + vin-supply = <&dc_12v>; + }; + + vcc5v0_host: vcc5v0-host-regulator { + compatible = "regulator-fixed"; + enable-active-high; + gpio = <&gpio0 RK_PA6 GPIO_ACTIVE_HIGH>; + pinctrl-names = "default"; + pinctrl-0 = <&vcc5v0_host_en>; + regulator-name = "vcc5v0_host"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + }; + + vcc5v0_otg: vcc5v0-otg-regulator { + compatible = "regulator-fixed"; + enable-active-high; + gpio = <&gpio0 RK_PA5 GPIO_ACTIVE_HIGH>; + pinctrl-names = "default"; + pinctrl-0 = <&vcc5v0_otg_en>; + regulator-name = "vcc5v0_otg"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + }; + + pcie30_avdd0v9: pcie30-avdd0v9 { + compatible = "regulator-fixed"; + regulator-name = "pcie30_avdd0v9"; + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <900000>; + regulator-max-microvolt = <900000>; + vin-supply = <&vcc3v3_sys>; + }; + + pcie30_avdd1v8: pcie30-avdd1v8 { + compatible = "regulator-fixed"; + regulator-name = "pcie30_avdd1v8"; + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + vin-supply = <&vcc3v3_sys>; + }; + + vcc3v3_pcie: vcc3v3-pcie { + compatible = "regulator-fixed"; + enable-active-high; + gpios = <&gpio0 RK_PC6 GPIO_ACTIVE_HIGH>; + pinctrl-0 = <&m2_pwr_h>; + pinctrl-names = "default"; + regulator-name = "vcc3v3_pcie"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + }; + + vcc3v3_minipcie: vcc3v3-minipcie { + compatible = "regulator-fixed"; + enable-active-high; + gpios = <&gpio0 RK_PD4 GPIO_ACTIVE_HIGH>; + pinctrl-0 = <&minipcie_pwr_h>; + pinctrl-names = "default"; + regulator-name = "vcc3v3_minipcie"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + }; + + usb_hub_en: usb-hub-en { + compatible = "regulator-fixed"; + enable-active-high; + gpio = <&gpio0 RK_PB7 GPIO_ACTIVE_HIGH>; + pinctrl-0 = <&usb_hub_reset>; + pinctrl-names = "default"; + regulator-name = "usb_hub_en"; + regulator-always-on; + regulator-boot-on; + }; + + usb_m2_en: usb-m2-en { + compatible = "regulator-fixed"; + enable-active-high; + gpio = <&gpio3 RK_PB5 GPIO_ACTIVE_HIGH>; + pinctrl-0 = <&usb_m2_reset>; + pinctrl-names = "default"; + regulator-name = "usb_m2_en"; + regulator-always-on; + regulator-boot-on; + }; + + cust_gpios_en: cust-gpios-en { + compatible = "regulator-fixed"; + enable-active-high; + pinctrl-0 = <&cust_gpios_h>; + pinctrl-names = "default"; + gpio = <&gpio2 RK_PD0 GPIO_ACTIVE_HIGH>; + regulator-name = "cust_gpio_en"; + regulator-always-on; + regulator-boot-on; + }; + + uart4_en: uart4-en { + compatible = "regulator-fixed"; + enable-active-high; + pinctrl-0 = <&uart4_en_h>; + pinctrl-names = "default"; + gpio = <&gpio4 RK_PB2 GPIO_ACTIVE_HIGH>; + regulator-name = "uart4_en"; + regulator-always-on; + regulator-boot-on; + }; + + uart7_en: uart7-en { + compatible = "regulator-fixed"; + enable-active-high; + pinctrl-0 = <&uart7_en_h>; + pinctrl-names = "default"; + gpio = <&gpio4 RK_PC0 GPIO_ACTIVE_HIGH>; + regulator-name = "uart7_en"; + regulator-always-on; + regulator-boot-on; + }; + + sdio_pwrseq: sdio-pwrseq { + compatible = "mmc-pwrseq-simple"; + clocks = <&rk809 1>; + clock-names = "ext_clock"; + pinctrl-0 = <&wifi_enable_h>; + pinctrl-names = "default"; + + /* + * On the module itself this is one of these (depending + * on the actual card populated): + * - SDIO_RESET_L_WL_REG_ON + * - PDN (power down when low) + */ + post-power-on-delay-ms = <200>; + reset-gpios = <&gpio2 RK_PC6 GPIO_ACTIVE_LOW>; + }; + + rk809_sound: rk809-sound { + compatible = "simple-audio-card"; + simple-audio-card,format = "i2s"; + simple-audio-card,name = "Analog RK809"; + simple-audio-card,mclk-fs = <256>; + + simple-audio-card,cpu { + sound-dai = <&i2s1_8ch>; + }; + simple-audio-card,codec { + sound-dai = <&rk809>; + }; + }; +}; + +&combphy0 { + status = "okay"; +}; + +&combphy1 { + status = "okay"; +}; + +&combphy2 { + status = "okay"; +}; + +&cpu0 { + cpu-supply = <&vdd_cpu>; +}; + +&cpu1 { + cpu-supply = <&vdd_cpu>; +}; + +&cpu2 { + cpu-supply = <&vdd_cpu>; +}; + +&cpu3 { + cpu-supply = <&vdd_cpu>; +}; + +&gmac0 { + assigned-clocks = <&cru SCLK_GMAC0_RX_TX>, <&cru SCLK_GMAC0>; + assigned-clock-parents = <&cru SCLK_GMAC0_RGMII_SPEED>, <&cru CLK_MAC0_2TOP>; + assigned-clock-rates = <0>, <125000000>; + clock_in_out = "input"; + phy-mode = "rgmii"; + pinctrl-names = "default"; + pinctrl-0 = <&gmac0_reset + &gmac0_miim + &gmac0_tx_bus2 + &gmac0_rx_bus2 + &gmac0_rgmii_clk + &gmac0_rgmii_bus>; + snps,reset-gpio = <&gpio3 RK_PB7 GPIO_ACTIVE_LOW>; + snps,reset-active-low; + /* Reset time is 20ms, 100ms for rtl8211f */ + snps,reset-delays-us = <0 20000 100000>; + enable_phy_delay = <0>; + tx_delay = <0x37>; + rx_delay = <0x0d>; + phy-handle = <&rgmii_phy0>; + status = "okay"; +}; + +&gmac1 { + assigned-clocks = <&cru SCLK_GMAC1_RX_TX>, <&cru SCLK_GMAC1>; + assigned-clock-parents = <&cru SCLK_GMAC1_RGMII_SPEED>, <&cru CLK_MAC1_2TOP>; + assigned-clock-rates = <0>, <125000000>; + clock_in_out = "input"; + phy-mode = "rgmii"; + pinctrl-names = "default"; + pinctrl-0 = <&gmac1_reset + &gmac1m1_miim + &gmac1m1_tx_bus2 + &gmac1m1_rx_bus2 + &gmac1m1_rgmii_clk + &gmac1m1_rgmii_bus + &gmac1m1_clkinout>; + snps,reset-gpio = <&gpio3 RK_PB0 GPIO_ACTIVE_LOW>; + snps,reset-active-low; + /* Reset time is 20ms, 100ms for rtl8211f */ + snps,reset-delays-us = <0 20000 100000>; + enable_phy_delay = <0>; + tx_delay = <0x3c>; + rx_delay = <0x2f>; + phy-handle = <&rgmii_phy1>; + status = "okay"; +}; + +#ifdef DTS_NO_LEGACY +&gpu { + mali-supply = <&vdd_gpu>; + status = "okay"; +}; + +&hdmi { + status = "okay"; +}; + +&hdmi_in { + hdmi_in_vp0: endpoint { + remote-endpoint = <&vp0_out_hdmi>; + }; +}; + +&hdmi_out { + hdmi_out_con: endpoint { + remote-endpoint = <&hdmi_con_in>; + }; +}; + +&hdmi_sound { + status = "okay"; +}; +#endif + +&i2c0 { + status = "okay"; + + vdd_cpu: syr828@41 { + compatible = "silergy,syr828"; + reg = <0x41>; + vin-supply = <&vcc5v0_sys>; + regulator-compatible = "fan53555-reg"; + regulator-name = "vdd_cpu"; + regulator-min-microvolt = <800000>; + regulator-max-microvolt = <1250000>; + regulator-ramp-delay = <1000>; + fcs,suspend-voltage-selector = <1>; + regulator-always-on; + regulator-boot-on; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + rk809: pmic@20 { + compatible = "rockchip,rk809"; + reg = <0x20>; + interrupt-parent = <&gpio0>; + interrupts = ; + assigned-clocks = <&cru I2S1_MCLKOUT_TX>; + assigned-clock-parents = <&cru CLK_I2S1_8CH_TX>; + #clock-cells = <1>; + clock-names = "mclk"; + clocks = <&cru I2S1_MCLKOUT_TX>; + pinctrl-names = "default"; + pinctrl-0 = <&pmic_int>, <&i2s1m0_mclk>; + rockchip,system-power-controller; + #sound-dai-cells = <0>; + wakeup-source; + + vcc1-supply = <&vcc3v3_sys>; + vcc2-supply = <&vcc3v3_sys>; + vcc3-supply = <&vcc3v3_sys>; + vcc4-supply = <&vcc3v3_sys>; + vcc5-supply = <&vcc3v3_sys>; + vcc6-supply = <&vcc3v3_sys>; + vcc7-supply = <&vcc3v3_sys>; + vcc8-supply = <&vcc3v3_sys>; + vcc9-supply = <&vcc3v3_sys>; + + regulators { + vdd_logic: DCDC_REG1 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <1350000>; + regulator-init-microvolt = <900000>; + regulator-ramp-delay = <6001>; + regulator-initial-mode = <0x2>; + regulator-name = "vdd_logic"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vdd_gpu: DCDC_REG2 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <1350000>; + regulator-init-microvolt = <900000>; + regulator-ramp-delay = <6001>; + regulator-initial-mode = <0x2>; + regulator-name = "vdd_gpu"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vcc_ddr: DCDC_REG3 { + regulator-always-on; + regulator-boot-on; + regulator-initial-mode = <0x2>; + regulator-name = "vcc_ddr"; + + regulator-state-mem { + regulator-on-in-suspend; + }; + }; + + vdd_npu: DCDC_REG4 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <1350000>; + regulator-init-microvolt = <900000>; + regulator-ramp-delay = <6001>; + regulator-initial-mode = <0x2>; + regulator-name = "vdd_npu"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vdda0v9_image: LDO_REG1 { + regulator-boot-on; + regulator-always-on; + regulator-min-microvolt = <900000>; + regulator-max-microvolt = <900000>; + regulator-name = "vdda0v9_image"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vdda_0v9: LDO_REG2 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <900000>; + regulator-max-microvolt = <900000>; + regulator-name = "vdda_0v9"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vdda0v9_pmu: LDO_REG3 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <900000>; + regulator-max-microvolt = <900000>; + regulator-name = "vdda0v9_pmu"; + + regulator-state-mem { + regulator-on-in-suspend; + regulator-suspend-microvolt = <900000>; + }; + }; + + vccio_acodec: LDO_REG4 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + regulator-name = "vccio_acodec"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vccio_sd: LDO_REG5 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <3300000>; + regulator-name = "vccio_sd"; + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vcc3v3_pmu: LDO_REG6 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + regulator-name = "vcc3v3_pmu"; + + regulator-state-mem { + regulator-on-in-suspend; + regulator-suspend-microvolt = <3300000>; + }; + }; + + vcca_1v8: LDO_REG7 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-name = "vcca_1v8"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vcca1v8_pmu: LDO_REG8 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-name = "vcca1v8_pmu"; + + regulator-state-mem { + regulator-on-in-suspend; + regulator-suspend-microvolt = <1800000>; + }; + }; + + vcca1v8_image: LDO_REG9 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-name = "vcca1v8_image"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vcc_1v8: DCDC_REG5 { + regulator-always-on; + regulator-boot-on; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-name = "vcc_1v8"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vcc_3v3: SWITCH_REG1 { + regulator-always-on; + regulator-boot-on; + regulator-name = "vcc_3v3"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + + vcc3v3_sd: SWITCH_REG2 { + regulator-always-on; + regulator-boot-on; + regulator-name = "vcc3v3_sd"; + + regulator-state-mem { + regulator-off-in-suspend; + }; + }; + }; + + codec { + mic-in-differential; + }; + }; +}; + +&i2c2 { + status = "okay"; + pinctrl-names = "default"; + pinctrl-0 = <&i2c2m1_xfer>; +}; + +&i2c3 { + status = "okay"; +}; + +&i2c4 { + status = "okay"; + pinctrl-names = "default"; + pinctrl-0 = <&i2c4m1_xfer>; +}; + +&i2s1_8ch { + status = "okay"; + rockchip,trcm-sync-tx-only; + pinctrl-names = "default"; + pinctrl-0 = <&i2s1m0_sclktx + &i2s1m0_lrcktx + &i2s1m0_sdi0 + &i2s1m0_sdo0>; +}; + +&mdio0 { + rgmii_phy0: phy@0 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <0x0>; + }; +}; + +&mdio1 { + rgmii_phy1: phy@0 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <0x0>; + }; +}; + +&pcie30phy { + data-lanes = <1 2>; + status = "okay"; +}; + +&pcie3x1 { + num-lanes = <1>; + pinctrl-names = "default"; + pinctrl-0 = <&minipcie_reset_l>; + reset-gpios = <&gpio2 RK_PD6 GPIO_ACTIVE_HIGH>; + vpcie3v3-supply = <&vcc3v3_minipcie>; + status = "okay"; +}; + +&pcie3x2 { + num-lanes = <1>; + pinctrl-names = "default"; + pinctrl-0 = <&m2_pcie_reset_l>; + reset-gpios = <&gpio3 RK_PA1 GPIO_ACTIVE_HIGH>; + vpcie3v3-supply = <&vcc3v3_pcie>; + status = "okay"; +}; + +&pinctrl { + pmic { + pmic_int: pmic_int { + rockchip,pins = <0 RK_PA3 RK_FUNC_GPIO &pcfg_pull_up>; + }; + }; + + pcie { + minipcie_pwr_h: minipcie-pwr-h { + rockchip,pins = <0 RK_PD4 RK_FUNC_GPIO &pcfg_pull_up>; + }; + + m2_pwr_h: m2-pwr-h { + rockchip,pins = <0 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>; + }; + + minipcie_reset_l: minipcie-reset-l { + rockchip,pins = <2 RK_PD6 RK_FUNC_GPIO &pcfg_pull_none>; + }; + + m2_pcie_reset_l: m2-pcie-reset-l { + rockchip,pins = <3 RK_PA1 RK_FUNC_GPIO &pcfg_pull_down>; + }; + }; + + usb { + vcc5v0_host_en: vcc5v0-host-en { + rockchip,pins = <0 RK_PA6 RK_FUNC_GPIO &pcfg_pull_none>; + }; + + vcc5v0_otg_en: vcc5v0-otg-en { + rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>; + }; + + usb_hub_reset: usb-hub-reset { + rockchip,pins = <0 RK_PB7 RK_FUNC_GPIO &pcfg_pull_up>; + }; + + usb_m2_reset: usb-m2-reset { + rockchip,pins = <3 RK_PB5 RK_FUNC_GPIO &pcfg_pull_up>; + }; + }; + + gmac0 { + gmac0_reset: gmac0_reset { + rockchip,pins = <3 RK_PB7 RK_FUNC_GPIO &pcfg_pull_down>; + }; + }; + + gmac1 { + gmac1_reset: gmac1_reset { + rockchip,pins = <3 RK_PB0 RK_FUNC_GPIO &pcfg_pull_down>; + }; + }; + + misc { + system_rst_h: system-rst-h { + rockchip,pins = <0 RK_PA1 RK_FUNC_GPIO &pcfg_pull_down>; + }; + + cust_gpios_h: cust-gpios-h { + rockchip,pins = <3 RK_PA0 RK_FUNC_GPIO &pcfg_pull_none>, + <3 RK_PA2 RK_FUNC_GPIO &pcfg_pull_none>, + <3 RK_PA3 RK_FUNC_GPIO &pcfg_pull_none>, + <3 RK_PA4 RK_FUNC_GPIO &pcfg_pull_none>, + <3 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>, + <3 RK_PA6 RK_FUNC_GPIO &pcfg_pull_none>; + }; + + uart4_en_h: uart4-en-h { + rockchip,pins = <4 RK_PB2 RK_FUNC_GPIO &pcfg_pull_up>; + }; + + uart7_en_h: uart7-en-h { + rockchip,pins = <4 RK_PC0 RK_FUNC_GPIO &pcfg_pull_up>; + }; + + uart4m1_xfer_adv: uart4m1-xfer { + rockchip,pins = <3 RK_PB1 4 &pcfg_pull_down>, + <3 RK_PB2 4 &pcfg_pull_down>; + }; + + uart7m1_xfer_adv: uart7m1-xfer { + rockchip,pins = <3 RK_PC5 4 &pcfg_pull_down>, + <3 RK_PC4 4 &pcfg_pull_down>; + }; + }; + + sdio-pwrseq { + wifi_enable_h: wifi-enable-h { + rockchip,pins = <2 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>; + }; + }; +}; + +&pmu_io_domains { + status = "okay"; + pmuio1-supply = <&vcc3v3_pmu>; + pmuio2-supply = <&vcc3v3_pmu>; + vccio1-supply = <&vccio_acodec>; + vccio3-supply = <&vccio_sd>; + vccio4-supply = <&vcc_1v8>; + vccio5-supply = <&vcc_3v3>; + vccio6-supply = <&vcc_1v8>; + vccio7-supply = <&vcc_3v3>; +}; + +&pwm2 { + status = "okay"; + pinctrl-names = "active"; + pinctrl-0 = <&pwm2m1_pins>; +}; + +&pwm4 { + status = "okay"; +}; + +&rng { + status = "okay"; +}; + +&saradc { + vref-supply = <&vcca_1v8>; + status = "okay"; +}; + +&sdhci { + bus-width = <8>; + non-removable; + max-frequency = <200000000>; + status = "okay"; +}; + +&sdmmc0 { + broken-cd; + bus-width = <4>; + cap-sd-highspeed; + disable-wp; + sd-uhs-sdr104; + vmmc-supply = <&vcc3v3_sd>; + vqmmc-supply = <&vccio_sd>; + pinctrl-names = "default"; + pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd &sdmmc0_det>; + status = "okay"; +}; + +&sdmmc2 { + bus-width = <4>; + cap-sd-highspeed; + cap-sdio-irq; + disable-wp; + keep-power-in-suspend; + mmc-pwrseq = <&sdio_pwrseq>; + non-removable; + pinctrl-names = "default"; + pinctrl-0 = <&sdmmc2m0_bus4 &sdmmc2m0_cmd &sdmmc2m0_clk>; + status = "okay"; +}; + +&sata2 { + status = "okay"; +}; + +&tsadc { + status = "okay"; +}; + +&uart2 { + status = "okay"; +}; + +&uart4 { + pinctrl-0 = <&uart4m1_xfer_adv>; + pinctrl-names = "default"; + status = "okay"; +}; + +&uart7 { + pinctrl-0 = <&uart7m1_xfer_adv>; + pinctrl-names = "default"; + status = "okay"; +}; + +&usb_host0_ehci { + status = "okay"; +}; + +&usb_host0_ohci { + status = "okay"; +}; + +&usb_host0_xhci { + extcon = <&usb2phy0>; + status = "okay"; +}; + +&usb_host1_ehci { + status = "okay"; +}; + +&usb_host1_ohci { + status = "okay"; +}; + +&usb_host1_xhci { + status = "okay"; +}; + +&usb2phy0 { + status = "okay"; +}; + +&usb2phy0_host { + phy-supply = <&vcc5v0_host>; + status = "okay"; +}; + +&usb2phy0_otg { + phy-supply = <&vcc5v0_otg>; + status = "okay"; +}; + +&usb2phy1 { + status = "okay"; +}; + +&usb2phy1_host { + phy-supply = <&vcc5v0_host>; + status = "okay"; +}; + +&usb2phy1_otg { + phy-supply = <&vcc5v0_host>; + status = "okay"; +}; + +#ifdef DTS_NO_LEGACY +&vop { + assigned-clocks = <&cru DCLK_VOP0>, <&cru DCLK_VOP1>; + assigned-clock-parents = <&pmucru PLL_HPLL>, <&cru PLL_VPLL>; + status = "okay"; +}; + +&vop_mmu { + status = "okay"; +}; + +&vp0 { + vp0_out_hdmi: endpoint@ROCKCHIP_VOP2_EP_HDMI0 { + reg = ; + remote-endpoint = <&hdmi_in_vp0>; + }; +}; +#endif diff --git a/lede/target/linux/rockchip/image/armv8.mk b/lede/target/linux/rockchip/image/armv8.mk index 820d155e2e..2faee85653 100644 --- a/lede/target/linux/rockchip/image/armv8.mk +++ b/lede/target/linux/rockchip/image/armv8.mk @@ -2,6 +2,16 @@ # # Copyright (C) 2020 Tobias Maedel +define Device/advantech_rsb4810 + DEVICE_VENDOR := Advantech + DEVICE_MODEL := RSB4810 + SOC := rk3568 + UBOOT_DEVICE_NAME := advantech-rsb4810-rk3568 + IMAGE/sysupgrade.img.gz := boot-common | boot-script nanopi-r5s | pine64-img | gzip | append-metadata + DEVICE_PACKAGES := kmod-ata-ahci kmod-ata-ahci-platform -urngd +endef +TARGET_DEVICES += advantech_rsb4810 + define Device/ariaboard_photonicat DEVICE_VENDOR := Ariaboard DEVICE_MODEL := Photonicat diff --git a/lede/target/linux/rockchip/patches-5.15/210-rockchip-rk356x-add-support-for-new-boards.patch b/lede/target/linux/rockchip/patches-5.15/210-rockchip-rk356x-add-support-for-new-boards.patch index 40230634d6..ed01e540d3 100644 --- a/lede/target/linux/rockchip/patches-5.15/210-rockchip-rk356x-add-support-for-new-boards.patch +++ b/lede/target/linux/rockchip/patches-5.15/210-rockchip-rk356x-add-support-for-new-boards.patch @@ -1,6 +1,6 @@ --- a/arch/arm64/boot/dts/rockchip/Makefile +++ b/arch/arm64/boot/dts/rockchip/Makefile -@@ -59,3 +59,19 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-sa +@@ -59,3 +59,20 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-sa dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-sapphire-excavator.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399pro-rock-pi-n10.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-evb1-v10.dtb @@ -17,6 +17,7 @@ +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-roc-pc.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-r66s.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-r68s.dtb ++dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-rsb4810.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-seewo-sv21.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-t68m.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3566-panther-x2.dtb diff --git a/lede/target/linux/rockchip/patches-6.1/210-rockchip-rk356x-add-support-for-new-boards.patch b/lede/target/linux/rockchip/patches-6.1/210-rockchip-rk356x-add-support-for-new-boards.patch index 371e3c9dd4..6caa7a34a9 100644 --- a/lede/target/linux/rockchip/patches-6.1/210-rockchip-rk356x-add-support-for-new-boards.patch +++ b/lede/target/linux/rockchip/patches-6.1/210-rockchip-rk356x-add-support-for-new-boards.patch @@ -1,6 +1,6 @@ --- a/arch/arm64/boot/dts/rockchip/Makefile +++ b/arch/arm64/boot/dts/rockchip/Makefile -@@ -79,3 +79,18 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3566-so +@@ -79,3 +79,19 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3566-so dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-bpi-r2-pro.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-evb1-v10.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-rock-3a.dtb @@ -16,6 +16,7 @@ +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-r66s.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-r68s.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-roc-pc.dtb ++dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-rsb4810.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-seewo-sv21.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-t68m.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3566-panther-x2.dtb diff --git a/lede/target/linux/rockchip/patches-6.6/210-rockchip-rk356x-add-support-for-new-boards.patch b/lede/target/linux/rockchip/patches-6.6/210-rockchip-rk356x-add-support-for-new-boards.patch index 699e7f5b9b..139589e314 100644 --- a/lede/target/linux/rockchip/patches-6.6/210-rockchip-rk356x-add-support-for-new-boards.patch +++ b/lede/target/linux/rockchip/patches-6.6/210-rockchip-rk356x-add-support-for-new-boards.patch @@ -8,7 +8,7 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3566-quartz64-a.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3566-quartz64-b.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3566-radxa-cm3-io.dtb -@@ -98,9 +99,19 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-lu +@@ -98,9 +99,20 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-lu dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-nanopi-r5c.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-nanopi-r5s.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-odroid-m1.dtb @@ -21,6 +21,7 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-radxa-e25.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-roc-pc.dtb dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-rock-3a.dtb ++dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-rsb4810.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-photonicat.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-seewo-sv21.dtb +dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3568-mrkaio-m68s.dtb diff --git a/mihomo/.github/workflows/build.yml b/mihomo/.github/workflows/build.yml index d95226b032..2639c04b7a 100644 --- a/mihomo/.github/workflows/build.yml +++ b/mihomo/.github/workflows/build.yml @@ -143,7 +143,7 @@ jobs: run: | go test ./... - - name: Update UA + - name: Update CA run: | sudo apt-get install ca-certificates sudo update-ca-certificates diff --git a/mihomo/adapter/outboundgroup/parser.go b/mihomo/adapter/outboundgroup/parser.go index bec262f231..ac4546d822 100644 --- a/mihomo/adapter/outboundgroup/parser.go +++ b/mihomo/adapter/outboundgroup/parser.go @@ -88,6 +88,30 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide } groupOption.ExpectedStatus = status + if len(groupOption.Use) != 0 { + PDs, err := getProviders(providersMap, groupOption.Use) + if err != nil { + return nil, fmt.Errorf("%s: %w", groupName, err) + } + + // if test URL is empty, use the first health check URL of providers + if groupOption.URL == "" { + for _, pd := range PDs { + if pd.HealthCheckURL() != "" { + groupOption.URL = pd.HealthCheckURL() + break + } + } + if groupOption.URL == "" { + groupOption.URL = C.DefaultTestURL + } + } else { + addTestUrlToProviders(PDs, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval)) + } + + providers = append(providers, PDs...) + } + if len(groupOption.Proxies) != 0 { ps, err := getProxies(proxyMap, groupOption.Proxies) if err != nil { @@ -98,14 +122,17 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide return nil, fmt.Errorf("%s: %w", groupName, errDuplicateProvider) } - if groupOption.Interval == 0 { - groupOption.Interval = 300 - } - if groupOption.URL == "" { groupOption.URL = C.DefaultTestURL } + // select don't need auto health check + if groupOption.Type != "select" && groupOption.Type != "relay" { + if groupOption.Interval == 0 { + groupOption.Interval = 300 + } + } + hc := provider.NewHealthCheck(ps, groupOption.URL, uint(groupOption.TestTimeout), uint(groupOption.Interval), groupOption.Lazy, expectedStatus) pd, err := provider.NewCompatibleProvider(groupName, ps, hc) @@ -117,30 +144,6 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide providersMap[groupName] = pd } - if len(groupOption.Use) != 0 { - list, err := getProviders(providersMap, groupOption.Use) - if err != nil { - return nil, fmt.Errorf("%s: %w", groupName, err) - } - - if groupOption.URL == "" { - for _, p := range list { - if p.HealthCheckURL() != "" { - groupOption.URL = p.HealthCheckURL() - } - break - } - - if groupOption.URL == "" { - groupOption.URL = C.DefaultTestURL - } - } - - // different proxy groups use different test URL - addTestUrlToProviders(list, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval)) - providers = append(providers, list...) - } - var group C.ProxyAdapter switch groupOption.Type { case "url-test": diff --git a/mihomo/go.mod b/mihomo/go.mod index 78f50d02be..7270049a65 100644 --- a/mihomo/go.mod +++ b/mihomo/go.mod @@ -23,7 +23,7 @@ require ( github.com/metacubex/sing-quic v0.0.0-20240310154810-47bca850fc01 github.com/metacubex/sing-shadowsocks v0.2.6 github.com/metacubex/sing-shadowsocks2 v0.2.0 - github.com/metacubex/sing-tun v0.2.1-0.20240402145739-0223b8bb1c85 + github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 github.com/metacubex/tfo-go v0.0.0-20240228025757-be1269474a66 diff --git a/mihomo/go.sum b/mihomo/go.sum index 12c207e427..4bddc40e91 100644 --- a/mihomo/go.sum +++ b/mihomo/go.sum @@ -114,8 +114,8 @@ github.com/metacubex/sing-shadowsocks v0.2.6 h1:6oEB3QcsFYnNiFeoevcXrCwJ3sAablwV github.com/metacubex/sing-shadowsocks v0.2.6/go.mod h1:zIkMeSnb8Mbf4hdqhw0pjzkn1d99YJ3JQm/VBg5WMTg= github.com/metacubex/sing-shadowsocks2 v0.2.0 h1:hqwT/AfI5d5UdPefIzR6onGHJfDXs5zgOM5QSgaM/9A= github.com/metacubex/sing-shadowsocks2 v0.2.0/go.mod h1:LCKF6j1P94zN8ZS+LXRK1gmYTVGB3squivBSXAFnOg8= -github.com/metacubex/sing-tun v0.2.1-0.20240402145739-0223b8bb1c85 h1:r7XXIvooixabmv2Ry95I1Xv3T0c+9VWtes9LhkXGg34= -github.com/metacubex/sing-tun v0.2.1-0.20240402145739-0223b8bb1c85/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060 h1:SEkMqQlInU4KoyaISvEPKEzhDw0CnTr2TvIuj/hmEQ0= +github.com/metacubex/sing-tun v0.2.1-0.20240405021556-f37a4aa3d060/go.mod h1:GfLZG/QgGpW9+BPjltzONrL5vVms86TWqmZ23J68ISc= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f h1:QjXrHKbTMBip/C+R79bvbfr42xH1gZl3uFb0RELdZiQ= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f/go.mod h1:olVkD4FChQ5gKMHG4ZzuD7+fMkJY1G8vwOKpRehjrmY= github.com/metacubex/sing-wireguard v0.0.0-20240321042214-224f96122a63 h1:AGyIB55UfQm/0ZH0HtQO9u3l//yjtHUpjeRjjPGfGRI= diff --git a/openwrt-packages/adguardhome/Makefile b/openwrt-packages/adguardhome/Makefile index 3325598895..8abe1cb964 100644 --- a/openwrt-packages/adguardhome/Makefile +++ b/openwrt-packages/adguardhome/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=adguardhome -PKG_VERSION:=0.107.47 +PKG_VERSION:=0.107.48 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://codeload.github.com/AdguardTeam/AdGuardHome/tar.gz/v$(PKG_VERSION)? -PKG_HASH:=d803348688ff0d44f20bd201801720f2f0bd48528c20abc48da9a01a59de65a9 +PKG_HASH:=189afe8ccc4efd229c3554d812f590cc8727e966c05a6129d444c88a905b83a1 PKG_LICENSE:=GPL-3.0-only PKG_LICENSE_FILES:=LICENSE.txt @@ -57,7 +57,7 @@ define Download/adguardhome-frontend URL:=https://github.com/AdguardTeam/AdGuardHome/releases/download/v$(PKG_VERSION)/ URL_FILE:=AdGuardHome_frontend.tar.gz FILE:=$(FRONTEND_FILE) - HASH:=59b2236a65fa2d3d65435c9445402a2e7d511db2996790fe78c8afd90d863c6f + HASH:=48670d085bbdd7a70f4a4cbcba047dd94052190c5471ada5be92c334ed793aa2 endef define Build/Prepare diff --git a/ryujinx/src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs b/ryujinx/src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs index df3f8dc93e..05fb29ac71 100644 --- a/ryujinx/src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs +++ b/ryujinx/src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs @@ -4,7 +4,7 @@ using System.Threading; namespace Ryujinx.Common.Memory { - public sealed partial class ByteMemoryPool + public partial class ByteMemoryPool { /// /// Represents a that wraps an array rented from diff --git a/ryujinx/src/Ryujinx.Common/Memory/ByteMemoryPool.cs b/ryujinx/src/Ryujinx.Common/Memory/ByteMemoryPool.cs index 071f56b136..6fd6a98aa7 100644 --- a/ryujinx/src/Ryujinx.Common/Memory/ByteMemoryPool.cs +++ b/ryujinx/src/Ryujinx.Common/Memory/ByteMemoryPool.cs @@ -6,24 +6,8 @@ namespace Ryujinx.Common.Memory /// /// Provides a pool of re-usable byte array instances. /// - public sealed partial class ByteMemoryPool + public static partial class ByteMemoryPool { - private static readonly ByteMemoryPool _shared = new(); - - /// - /// Constructs a instance. Private to force access through - /// the instance. - /// - private ByteMemoryPool() - { - // No implementation - } - - /// - /// Retrieves a shared instance. - /// - public static ByteMemoryPool Shared => _shared; - /// /// Returns the maximum buffer size supported by this pool. /// @@ -95,6 +79,20 @@ namespace Ryujinx.Common.Memory return buffer; } + /// + /// Copies into a newly rented byte memory buffer. + /// + /// The byte buffer to copy + /// A wrapping the rented memory with copied to it + public static IMemoryOwner RentCopy(ReadOnlySpan buffer) + { + var copy = RentImpl(buffer.Length); + + buffer.CopyTo(copy.Memory.Span); + + return copy; + } + private static ByteMemoryPoolBuffer RentImpl(int length) { if ((uint)length > Array.MaxLength) diff --git a/ryujinx/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs b/ryujinx/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs index 80f7c8a1f8..0c2e5f33a0 100644 --- a/ryujinx/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs +++ b/ryujinx/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs @@ -3,10 +3,10 @@ using Ryujinx.Memory; using Ryujinx.Memory.Range; using Ryujinx.Memory.Tracking; using System; +using System.Buffers; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Runtime.Versioning; namespace Ryujinx.Cpu.AppleHv @@ -15,7 +15,7 @@ namespace Ryujinx.Cpu.AppleHv /// Represents a CPU memory manager which maps guest virtual memory directly onto the Hypervisor page table. /// [SupportedOSPlatform("macos")] - public class HvMemoryManager : VirtualMemoryManagerRefCountedBase, IMemoryManager, IVirtualMemoryManagerTracked, IWritableBlock + public sealed class HvMemoryManager : VirtualMemoryManagerRefCountedBase, IMemoryManager, IVirtualMemoryManagerTracked { private readonly InvalidAccessHandler _invalidAccessHandler; @@ -96,12 +96,6 @@ namespace Ryujinx.Cpu.AppleHv } } - /// - public void MapForeign(ulong va, nuint hostPointer, ulong size) - { - throw new NotSupportedException(); - } - /// public void Unmap(ulong va, ulong size) { @@ -126,20 +120,11 @@ namespace Ryujinx.Cpu.AppleHv } } - /// - public T Read(ulong va) where T : unmanaged - { - return MemoryMarshal.Cast(GetSpan(va, Unsafe.SizeOf()))[0]; - } - - /// - public T ReadTracked(ulong va) where T : unmanaged + public override T ReadTracked(ulong va) { try { - SignalMemoryTracking(va, (ulong)Unsafe.SizeOf(), false); - - return Read(va); + return base.ReadTracked(va); } catch (InvalidMemoryRegionException) { @@ -152,7 +137,6 @@ namespace Ryujinx.Cpu.AppleHv } } - /// public override void Read(ulong va, Span data) { try @@ -168,101 +152,11 @@ namespace Ryujinx.Cpu.AppleHv } } - /// - public void Write(ulong va, T value) where T : unmanaged - { - Write(va, MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1))); - } - - /// - public void Write(ulong va, ReadOnlySpan data) - { - if (data.Length == 0) - { - return; - } - - SignalMemoryTracking(va, (ulong)data.Length, true); - - WriteImpl(va, data); - } - - /// - public void WriteUntracked(ulong va, ReadOnlySpan data) - { - if (data.Length == 0) - { - return; - } - - WriteImpl(va, data); - } - - /// - public bool WriteWithRedundancyCheck(ulong va, ReadOnlySpan data) - { - if (data.Length == 0) - { - return false; - } - - SignalMemoryTracking(va, (ulong)data.Length, false); - - if (IsContiguousAndMapped(va, data.Length)) - { - var target = _backingMemory.GetSpan(GetPhysicalAddressInternal(va), data.Length); - - bool changed = !data.SequenceEqual(target); - - if (changed) - { - data.CopyTo(target); - } - - return changed; - } - else - { - WriteImpl(va, data); - - return true; - } - } - - private void WriteImpl(ulong va, ReadOnlySpan data) + public override void Write(ulong va, ReadOnlySpan data) { try { - AssertValidAddressAndSize(va, (ulong)data.Length); - - if (IsContiguousAndMapped(va, data.Length)) - { - data.CopyTo(_backingMemory.GetSpan(GetPhysicalAddressInternal(va), data.Length)); - } - else - { - int offset = 0, size; - - if ((va & PageMask) != 0) - { - ulong pa = GetPhysicalAddressChecked(va); - - size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); - - data[..size].CopyTo(_backingMemory.GetSpan(pa, size)); - - offset += size; - } - - for (; offset < data.Length; offset += size) - { - ulong pa = GetPhysicalAddressChecked(va + (ulong)offset); - - size = Math.Min(data.Length - offset, PageSize); - - data.Slice(offset, size).CopyTo(_backingMemory.GetSpan(pa, size)); - } - } + base.Write(va, data); } catch (InvalidMemoryRegionException) { @@ -273,61 +167,38 @@ namespace Ryujinx.Cpu.AppleHv } } - /// - public ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) + public override void WriteUntracked(ulong va, ReadOnlySpan data) { - if (size == 0) + try { - return ReadOnlySpan.Empty; + base.WriteUntracked(va, data); } - - if (tracked) + catch (InvalidMemoryRegionException) { - SignalMemoryTracking(va, (ulong)size, false); - } - - if (IsContiguousAndMapped(va, size)) - { - return _backingMemory.GetSpan(GetPhysicalAddressInternal(va), size); - } - else - { - Span data = new byte[size]; - - base.Read(va, data); - - return data; + if (_invalidAccessHandler == null || !_invalidAccessHandler(va)) + { + throw; + } } } - /// - public WritableRegion GetWritableRegion(ulong va, int size, bool tracked = false) + public override ReadOnlySequence GetReadOnlySequence(ulong va, int size, bool tracked = false) { - if (size == 0) + try { - return new WritableRegion(null, va, Memory.Empty); + return base.GetReadOnlySequence(va, size, tracked); } - - if (tracked) + catch (InvalidMemoryRegionException) { - SignalMemoryTracking(va, (ulong)size, true); - } + if (_invalidAccessHandler == null || !_invalidAccessHandler(va)) + { + throw; + } - if (IsContiguousAndMapped(va, size)) - { - return new WritableRegion(null, va, _backingMemory.GetMemory(GetPhysicalAddressInternal(va), size)); - } - else - { - Memory memory = new byte[size]; - - base.Read(va, memory.Span); - - return new WritableRegion(this, va, memory); + return ReadOnlySequence.Empty; } } - /// public ref T GetRef(ulong va) where T : unmanaged { if (!IsContiguous(va, Unsafe.SizeOf())) @@ -340,9 +211,8 @@ namespace Ryujinx.Cpu.AppleHv return ref _backingMemory.GetRef(GetPhysicalAddressChecked(va)); } - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool IsMapped(ulong va) + public override bool IsMapped(ulong va) { return ValidateAddress(va) && _pages.IsMapped(va); } @@ -355,39 +225,6 @@ namespace Ryujinx.Cpu.AppleHv return _pages.IsRangeMapped(va, size); } - private static void ThrowMemoryNotContiguous() => throw new MemoryNotContiguousException(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool IsContiguousAndMapped(ulong va, int size) => IsContiguous(va, size) && IsMapped(va); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool IsContiguous(ulong va, int size) - { - if (!ValidateAddress(va) || !ValidateAddressAndSize(va, (ulong)size)) - { - return false; - } - - int pages = GetPagesCount(va, (uint)size, out va); - - for (int page = 0; page < pages - 1; page++) - { - if (!ValidateAddress(va + PageSize)) - { - return false; - } - - if (GetPhysicalAddressInternal(va) + PageSize != GetPhysicalAddressInternal(va + PageSize)) - { - return false; - } - - va += PageSize; - } - - return true; - } - /// public IEnumerable GetHostRegions(ulong va, ulong size) { @@ -464,11 +301,10 @@ namespace Ryujinx.Cpu.AppleHv return regions; } - /// /// /// This function also validates that the given range is both valid and mapped, and will throw if it is not. /// - public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) + public override void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) { AssertValidAddressAndSize(va, size); @@ -481,24 +317,6 @@ namespace Ryujinx.Cpu.AppleHv _pages.SignalMemoryTracking(Tracking, va, size, write, exemptId); } - /// - /// Computes the number of pages in a virtual address range. - /// - /// Virtual address of the range - /// Size of the range - /// The virtual address of the beginning of the first page - /// This function does not differentiate between allocated and unallocated pages. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int GetPagesCount(ulong va, ulong size, out ulong startVa) - { - // WARNING: Always check if ulong does not overflow during the operations. - startVa = va & ~(ulong)PageMask; - ulong vaSpan = (va - startVa + size + PageMask) & ~(ulong)PageMask; - - return (int)(vaSpan / PageSize); - } - - /// public void Reprotect(ulong va, ulong size, MemoryPermission protection) { // TODO @@ -535,7 +353,7 @@ namespace Ryujinx.Cpu.AppleHv return Tracking.BeginSmartGranularTracking(address, size, granularity, id); } - private ulong GetPhysicalAddressChecked(ulong va) + private nuint GetPhysicalAddressChecked(ulong va) { if (!IsMapped(va)) { @@ -545,9 +363,9 @@ namespace Ryujinx.Cpu.AppleHv return GetPhysicalAddressInternal(va); } - private ulong GetPhysicalAddressInternal(ulong va) + private nuint GetPhysicalAddressInternal(ulong va) { - return _pageTable.Read(va) + (va & PageMask); + return (nuint)(_pageTable.Read(va) + (va & PageMask)); } /// @@ -558,10 +376,17 @@ namespace Ryujinx.Cpu.AppleHv _addressSpace.Dispose(); } - protected override Span GetPhysicalAddressSpan(ulong pa, int size) + protected override Memory GetPhysicalAddressMemory(nuint pa, int size) + => _backingMemory.GetMemory(pa, size); + + protected override Span GetPhysicalAddressSpan(nuint pa, int size) => _backingMemory.GetSpan(pa, size); - protected override ulong TranslateVirtualAddressForRead(ulong va) + protected override nuint TranslateVirtualAddressChecked(ulong va) => GetPhysicalAddressChecked(va); + + protected override nuint TranslateVirtualAddressUnchecked(ulong va) + => GetPhysicalAddressInternal(va); + } } diff --git a/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManager.cs b/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManager.cs index c87c8b8cc5..dfa5b93539 100644 --- a/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManager.cs +++ b/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManager.cs @@ -3,6 +3,7 @@ using Ryujinx.Memory; using Ryujinx.Memory.Range; using Ryujinx.Memory.Tracking; using System; +using System.Buffers; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; @@ -14,7 +15,7 @@ namespace Ryujinx.Cpu.Jit /// /// Represents a CPU memory manager. /// - public sealed class MemoryManager : VirtualMemoryManagerRefCountedBase, IMemoryManager, IVirtualMemoryManagerTracked, IWritableBlock + public sealed class MemoryManager : VirtualMemoryManagerRefCountedBase, IMemoryManager, IVirtualMemoryManagerTracked { private const int PteSize = 8; @@ -97,12 +98,6 @@ namespace Ryujinx.Cpu.Jit Tracking.Map(oVa, size); } - /// - public void MapForeign(ulong va, nuint hostPointer, ulong size) - { - throw new NotSupportedException(); - } - /// public void Unmap(ulong va, ulong size) { @@ -128,20 +123,11 @@ namespace Ryujinx.Cpu.Jit } } - /// - public T Read(ulong va) where T : unmanaged - { - return MemoryMarshal.Cast(GetSpan(va, Unsafe.SizeOf()))[0]; - } - - /// - public T ReadTracked(ulong va) where T : unmanaged + public override T ReadTracked(ulong va) { try { - SignalMemoryTracking(va, (ulong)Unsafe.SizeOf(), false); - - return Read(va); + return base.ReadTracked(va); } catch (InvalidMemoryRegionException) { @@ -190,117 +176,11 @@ namespace Ryujinx.Cpu.Jit } } - /// - public void Write(ulong va, T value) where T : unmanaged - { - Write(va, MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1))); - } - - /// - public void Write(ulong va, ReadOnlySpan data) - { - if (data.Length == 0) - { - return; - } - - SignalMemoryTracking(va, (ulong)data.Length, true); - - WriteImpl(va, data); - } - - /// - public void WriteGuest(ulong va, T value) where T : unmanaged - { - Span data = MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1)); - - SignalMemoryTrackingImpl(va, (ulong)data.Length, true, true); - - WriteImpl(va, data); - } - - /// - public void WriteUntracked(ulong va, ReadOnlySpan data) - { - if (data.Length == 0) - { - return; - } - - WriteImpl(va, data); - } - - /// - public bool WriteWithRedundancyCheck(ulong va, ReadOnlySpan data) - { - if (data.Length == 0) - { - return false; - } - - SignalMemoryTracking(va, (ulong)data.Length, false); - - if (IsContiguousAndMapped(va, data.Length)) - { - var target = _backingMemory.GetSpan(GetPhysicalAddressInternal(va), data.Length); - - bool changed = !data.SequenceEqual(target); - - if (changed) - { - data.CopyTo(target); - } - - return changed; - } - else - { - WriteImpl(va, data); - - return true; - } - } - - /// - /// Writes data to CPU mapped memory. - /// - /// Virtual address to write the data into - /// Data to be written - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void WriteImpl(ulong va, ReadOnlySpan data) + public override void Write(ulong va, ReadOnlySpan data) { try { - AssertValidAddressAndSize(va, (ulong)data.Length); - - if (IsContiguousAndMapped(va, data.Length)) - { - data.CopyTo(_backingMemory.GetSpan(GetPhysicalAddressInternal(va), data.Length)); - } - else - { - int offset = 0, size; - - if ((va & PageMask) != 0) - { - ulong pa = GetPhysicalAddressInternal(va); - - size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); - - data[..size].CopyTo(_backingMemory.GetSpan(pa, size)); - - offset += size; - } - - for (; offset < data.Length; offset += size) - { - ulong pa = GetPhysicalAddressInternal(va + (ulong)offset); - - size = Math.Min(data.Length - offset, PageSize); - - data.Slice(offset, size).CopyTo(_backingMemory.GetSpan(pa, size)); - } - } + base.Write(va, data); } catch (InvalidMemoryRegionException) { @@ -312,60 +192,47 @@ namespace Ryujinx.Cpu.Jit } /// - public ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) + public void WriteGuest(ulong va, T value) where T : unmanaged { - if (size == 0) + Span data = MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1)); + + SignalMemoryTrackingImpl(va, (ulong)data.Length, true, true); + + Write(va, data); + } + + public override void WriteUntracked(ulong va, ReadOnlySpan data) + { + try { - return ReadOnlySpan.Empty; + base.WriteUntracked(va, data); } - - if (tracked) + catch (InvalidMemoryRegionException) { - SignalMemoryTracking(va, (ulong)size, false); - } - - if (IsContiguousAndMapped(va, size)) - { - return _backingMemory.GetSpan(GetPhysicalAddressInternal(va), size); - } - else - { - Span data = new byte[size]; - - base.Read(va, data); - - return data; + if (_invalidAccessHandler == null || !_invalidAccessHandler(va)) + { + throw; + } } } - /// - public WritableRegion GetWritableRegion(ulong va, int size, bool tracked = false) + public override ReadOnlySequence GetReadOnlySequence(ulong va, int size, bool tracked = false) { - if (size == 0) + try { - return new WritableRegion(null, va, Memory.Empty); + return base.GetReadOnlySequence(va, size, tracked); } - - if (IsContiguousAndMapped(va, size)) + catch (InvalidMemoryRegionException) { - if (tracked) + if (_invalidAccessHandler == null || !_invalidAccessHandler(va)) { - SignalMemoryTracking(va, (ulong)size, true); + throw; } - return new WritableRegion(null, va, _backingMemory.GetMemory(GetPhysicalAddressInternal(va), size)); - } - else - { - Memory memory = new byte[size]; - - GetSpan(va, size).CopyTo(memory.Span); - - return new WritableRegion(this, va, memory, tracked); + return ReadOnlySequence.Empty; } } - /// public ref T GetRef(ulong va) where T : unmanaged { if (!IsContiguous(va, Unsafe.SizeOf())) @@ -378,56 +245,6 @@ namespace Ryujinx.Cpu.Jit return ref _backingMemory.GetRef(GetPhysicalAddressInternal(va)); } - /// - /// Computes the number of pages in a virtual address range. - /// - /// Virtual address of the range - /// Size of the range - /// The virtual address of the beginning of the first page - /// This function does not differentiate between allocated and unallocated pages. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int GetPagesCount(ulong va, uint size, out ulong startVa) - { - // WARNING: Always check if ulong does not overflow during the operations. - startVa = va & ~(ulong)PageMask; - ulong vaSpan = (va - startVa + size + PageMask) & ~(ulong)PageMask; - - return (int)(vaSpan / PageSize); - } - - private static void ThrowMemoryNotContiguous() => throw new MemoryNotContiguousException(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool IsContiguousAndMapped(ulong va, int size) => IsContiguous(va, size) && IsMapped(va); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool IsContiguous(ulong va, int size) - { - if (!ValidateAddress(va) || !ValidateAddressAndSize(va, (ulong)size)) - { - return false; - } - - int pages = GetPagesCount(va, (uint)size, out va); - - for (int page = 0; page < pages - 1; page++) - { - if (!ValidateAddress(va + PageSize)) - { - return false; - } - - if (GetPhysicalAddressInternal(va) + PageSize != GetPhysicalAddressInternal(va + PageSize)) - { - return false; - } - - va += PageSize; - } - - return true; - } - /// public IEnumerable GetHostRegions(ulong va, ulong size) { @@ -532,9 +349,8 @@ namespace Ryujinx.Cpu.Jit return true; } - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool IsMapped(ulong va) + public override bool IsMapped(ulong va) { if (!ValidateAddress(va)) { @@ -544,9 +360,9 @@ namespace Ryujinx.Cpu.Jit return _pageTable.Read((va / PageSize) * PteSize) != 0; } - private ulong GetPhysicalAddressInternal(ulong va) + private nuint GetPhysicalAddressInternal(ulong va) { - return PteToPa(_pageTable.Read((va / PageSize) * PteSize) & ~(0xffffUL << 48)) + (va & PageMask); + return (nuint)(PteToPa(_pageTable.Read((va / PageSize) * PteSize) & ~(0xffffUL << 48)) + (va & PageMask)); } /// @@ -643,9 +459,7 @@ namespace Ryujinx.Cpu.Jit { ref long pageRef = ref _pageTable.GetRef(pageStart * PteSize); - long pte; - - pte = Volatile.Read(ref pageRef); + long pte = Volatile.Read(ref pageRef); if ((pte & tag) != 0) { @@ -663,7 +477,7 @@ namespace Ryujinx.Cpu.Jit } /// - public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) + public override void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) { SignalMemoryTrackingImpl(va, size, write, false, precise, exemptId); } @@ -683,10 +497,16 @@ namespace Ryujinx.Cpu.Jit /// protected override void Destroy() => _pageTable.Dispose(); - protected override Span GetPhysicalAddressSpan(ulong pa, int size) + protected override Memory GetPhysicalAddressMemory(nuint pa, int size) + => _backingMemory.GetMemory(pa, size); + + protected override Span GetPhysicalAddressSpan(nuint pa, int size) => _backingMemory.GetSpan(pa, size); - protected override ulong TranslateVirtualAddressForRead(ulong va) + protected override nuint TranslateVirtualAddressChecked(ulong va) + => GetPhysicalAddressInternal(va); + + protected override nuint TranslateVirtualAddressUnchecked(ulong va) => GetPhysicalAddressInternal(va); } } diff --git a/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs b/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs index f410d02e96..c60ab6b246 100644 --- a/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs +++ b/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs @@ -3,6 +3,7 @@ using Ryujinx.Memory; using Ryujinx.Memory.Range; using Ryujinx.Memory.Tracking; using System; +using System.Buffers; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; @@ -12,7 +13,7 @@ namespace Ryujinx.Cpu.Jit /// /// Represents a CPU memory manager which maps guest virtual memory directly onto a host virtual region. /// - public sealed class MemoryManagerHostMapped : VirtualMemoryManagerRefCountedBase, IMemoryManager, IVirtualMemoryManagerTracked, IWritableBlock + public sealed class MemoryManagerHostMapped : VirtualMemoryManagerRefCountedBase, IMemoryManager, IVirtualMemoryManagerTracked { private readonly InvalidAccessHandler _invalidAccessHandler; private readonly bool _unsafeMode; @@ -96,12 +97,6 @@ namespace Ryujinx.Cpu.Jit Tracking.Map(va, size); } - /// - public void MapForeign(ulong va, nuint hostPointer, ulong size) - { - throw new NotSupportedException(); - } - /// public void Unmap(ulong va, ulong size) { @@ -138,8 +133,7 @@ namespace Ryujinx.Cpu.Jit } } - /// - public T Read(ulong va) where T : unmanaged + public override T Read(ulong va) { try { @@ -158,14 +152,11 @@ namespace Ryujinx.Cpu.Jit } } - /// - public T ReadTracked(ulong va) where T : unmanaged + public override T ReadTracked(ulong va) { try { - SignalMemoryTracking(va, (ulong)Unsafe.SizeOf(), false); - - return Read(va); + return base.ReadTracked(va); } catch (InvalidMemoryRegionException) { @@ -178,7 +169,6 @@ namespace Ryujinx.Cpu.Jit } } - /// public override void Read(ulong va, Span data) { try @@ -196,9 +186,7 @@ namespace Ryujinx.Cpu.Jit } } - - /// - public void Write(ulong va, T value) where T : unmanaged + public override void Write(ulong va, T value) { try { @@ -215,8 +203,7 @@ namespace Ryujinx.Cpu.Jit } } - /// - public void Write(ulong va, ReadOnlySpan data) + public override void Write(ulong va, ReadOnlySpan data) { try { @@ -233,8 +220,7 @@ namespace Ryujinx.Cpu.Jit } } - /// - public void WriteUntracked(ulong va, ReadOnlySpan data) + public override void WriteUntracked(ulong va, ReadOnlySpan data) { try { @@ -251,8 +237,7 @@ namespace Ryujinx.Cpu.Jit } } - /// - public bool WriteWithRedundancyCheck(ulong va, ReadOnlySpan data) + public override bool WriteWithRedundancyCheck(ulong va, ReadOnlySpan data) { try { @@ -279,8 +264,21 @@ namespace Ryujinx.Cpu.Jit } } - /// - public ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) + public override ReadOnlySequence GetReadOnlySequence(ulong va, int size, bool tracked = false) + { + if (tracked) + { + SignalMemoryTracking(va, (ulong)size, write: false); + } + else + { + AssertMapped(va, (ulong)size); + } + + return new ReadOnlySequence(_addressSpace.Mirror.GetMemory(va, size)); + } + + public override ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) { if (tracked) { @@ -294,8 +292,7 @@ namespace Ryujinx.Cpu.Jit return _addressSpace.Mirror.GetSpan(va, size); } - /// - public WritableRegion GetWritableRegion(ulong va, int size, bool tracked = false) + public override WritableRegion GetWritableRegion(ulong va, int size, bool tracked = false) { if (tracked) { @@ -309,7 +306,6 @@ namespace Ryujinx.Cpu.Jit return _addressSpace.Mirror.GetWritableRegion(va, size); } - /// public ref T GetRef(ulong va) where T : unmanaged { SignalMemoryTracking(va, (ulong)Unsafe.SizeOf(), true); @@ -317,9 +313,8 @@ namespace Ryujinx.Cpu.Jit return ref _addressSpace.Mirror.GetRef(va); } - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool IsMapped(ulong va) + public override bool IsMapped(ulong va) { return ValidateAddress(va) && _pages.IsMapped(va); } @@ -390,11 +385,10 @@ namespace Ryujinx.Cpu.Jit return _pageTable.Read(va) + (va & PageMask); } - /// /// /// This function also validates that the given range is both valid and mapped, and will throw if it is not. /// - public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) + public override void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) { AssertValidAddressAndSize(va, size); @@ -407,23 +401,6 @@ namespace Ryujinx.Cpu.Jit _pages.SignalMemoryTracking(Tracking, va, size, write, exemptId); } - /// - /// Computes the number of pages in a virtual address range. - /// - /// Virtual address of the range - /// Size of the range - /// The virtual address of the beginning of the first page - /// This function does not differentiate between allocated and unallocated pages. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int GetPagesCount(ulong va, ulong size, out ulong startVa) - { - // WARNING: Always check if ulong does not overflow during the operations. - startVa = va & ~(ulong)PageMask; - ulong vaSpan = (va - startVa + size + PageMask) & ~(ulong)PageMask; - - return (int)(vaSpan / PageSize); - } - /// public void Reprotect(ulong va, ulong size, MemoryPermission protection) { @@ -470,10 +447,16 @@ namespace Ryujinx.Cpu.Jit _memoryEh.Dispose(); } - protected override Span GetPhysicalAddressSpan(ulong pa, int size) + protected override Memory GetPhysicalAddressMemory(nuint pa, int size) + => _addressSpace.Mirror.GetMemory(pa, size); + + protected override Span GetPhysicalAddressSpan(nuint pa, int size) => _addressSpace.Mirror.GetSpan(pa, size); - protected override ulong TranslateVirtualAddressForRead(ulong va) - => va; + protected override nuint TranslateVirtualAddressChecked(ulong va) + => (nuint)GetPhysicalAddressChecked(va); + + protected override nuint TranslateVirtualAddressUnchecked(ulong va) + => (nuint)GetPhysicalAddressInternal(va); } } diff --git a/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManagerHostTracked.cs b/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManagerHostTracked.cs index 18404bcc74..b2964cd29c 100644 --- a/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManagerHostTracked.cs +++ b/ryujinx/src/Ryujinx.Cpu/Jit/MemoryManagerHostTracked.cs @@ -8,14 +8,13 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace Ryujinx.Cpu.Jit { /// /// Represents a CPU memory manager which maps guest virtual memory directly onto a host virtual region. /// - public sealed class MemoryManagerHostTracked : VirtualMemoryManagerRefCountedBase, IWritableBlock, IMemoryManager, IVirtualMemoryManagerTracked + public sealed class MemoryManagerHostTracked : VirtualMemoryManagerRefCountedBase, IMemoryManager, IVirtualMemoryManagerTracked { private readonly InvalidAccessHandler _invalidAccessHandler; private readonly bool _unsafeMode; @@ -100,12 +99,6 @@ namespace Ryujinx.Cpu.Jit Tracking.Map(va, size); } - /// - public void MapForeign(ulong va, nuint hostPointer, ulong size) - { - throw new NotSupportedException(); - } - /// public void Unmap(ulong va, ulong size) { @@ -120,18 +113,11 @@ namespace Ryujinx.Cpu.Jit _nativePageTable.Unmap(va, size); } - public T Read(ulong va) where T : unmanaged - { - return MemoryMarshal.Cast(GetSpan(va, Unsafe.SizeOf()))[0]; - } - - public T ReadTracked(ulong va) where T : unmanaged + public override T ReadTracked(ulong va) { try { - SignalMemoryTracking(va, (ulong)Unsafe.SizeOf(), false); - - return Read(va); + return base.ReadTracked(va); } catch (InvalidMemoryRegionException) { @@ -145,38 +131,39 @@ namespace Ryujinx.Cpu.Jit } public override void Read(ulong va, Span data) - { - ReadImpl(va, data); - } - - public void Write(ulong va, T value) where T : unmanaged - { - Write(va, MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1))); - } - - public void Write(ulong va, ReadOnlySpan data) { if (data.Length == 0) { return; } - SignalMemoryTracking(va, (ulong)data.Length, true); - - WriteImpl(va, data); - } - - public void WriteUntracked(ulong va, ReadOnlySpan data) - { - if (data.Length == 0) + try { - return; - } + AssertValidAddressAndSize(va, (ulong)data.Length); - WriteImpl(va, data); + ulong endVa = va + (ulong)data.Length; + int offset = 0; + + while (va < endVa) + { + (MemoryBlock memory, ulong rangeOffset, ulong copySize) = GetMemoryOffsetAndSize(va, (ulong)(data.Length - offset)); + + memory.GetSpan(rangeOffset, (int)copySize).CopyTo(data.Slice(offset, (int)copySize)); + + va += copySize; + offset += (int)copySize; + } + } + catch (InvalidMemoryRegionException) + { + if (_invalidAccessHandler == null || !_invalidAccessHandler(va)) + { + throw; + } + } } - public bool WriteWithRedundancyCheck(ulong va, ReadOnlySpan data) + public override bool WriteWithRedundancyCheck(ulong va, ReadOnlySpan data) { if (data.Length == 0) { @@ -206,35 +193,7 @@ namespace Ryujinx.Cpu.Jit } } - private void WriteImpl(ulong va, ReadOnlySpan data) - { - try - { - AssertValidAddressAndSize(va, (ulong)data.Length); - - ulong endVa = va + (ulong)data.Length; - int offset = 0; - - while (va < endVa) - { - (MemoryBlock memory, ulong rangeOffset, ulong copySize) = GetMemoryOffsetAndSize(va, (ulong)(data.Length - offset)); - - data.Slice(offset, (int)copySize).CopyTo(memory.GetSpan(rangeOffset, (int)copySize)); - - va += copySize; - offset += (int)copySize; - } - } - catch (InvalidMemoryRegionException) - { - if (_invalidAccessHandler == null || !_invalidAccessHandler(va)) - { - throw; - } - } - } - - public ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) + public override ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) { if (size == 0) { @@ -254,13 +213,13 @@ namespace Ryujinx.Cpu.Jit { Span data = new byte[size]; - ReadImpl(va, data); + Read(va, data); return data; } } - public WritableRegion GetWritableRegion(ulong va, int size, bool tracked = false) + public override WritableRegion GetWritableRegion(ulong va, int size, bool tracked = false) { if (size == 0) { @@ -280,7 +239,7 @@ namespace Ryujinx.Cpu.Jit { Memory memory = new byte[size]; - ReadImpl(va, memory.Span); + Read(va, memory.Span); return new WritableRegion(this, va, memory); } @@ -299,7 +258,7 @@ namespace Ryujinx.Cpu.Jit } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool IsMapped(ulong va) + public override bool IsMapped(ulong va) { return ValidateAddress(va) && _pages.IsMapped(va); } @@ -311,8 +270,6 @@ namespace Ryujinx.Cpu.Jit return _pages.IsRangeMapped(va, size); } - private static void ThrowMemoryNotContiguous() => throw new MemoryNotContiguousException(); - private bool TryGetVirtualContiguous(ulong va, int size, out MemoryBlock memory, out ulong offset) { if (_addressSpace.HasAnyPrivateAllocation(va, (ulong)size, out PrivateRange range)) @@ -491,44 +448,11 @@ namespace Ryujinx.Cpu.Jit return regions; } - private void ReadImpl(ulong va, Span data) - { - if (data.Length == 0) - { - return; - } - - try - { - AssertValidAddressAndSize(va, (ulong)data.Length); - - ulong endVa = va + (ulong)data.Length; - int offset = 0; - - while (va < endVa) - { - (MemoryBlock memory, ulong rangeOffset, ulong copySize) = GetMemoryOffsetAndSize(va, (ulong)(data.Length - offset)); - - memory.GetSpan(rangeOffset, (int)copySize).CopyTo(data.Slice(offset, (int)copySize)); - - va += copySize; - offset += (int)copySize; - } - } - catch (InvalidMemoryRegionException) - { - if (_invalidAccessHandler == null || !_invalidAccessHandler(va)) - { - throw; - } - } - } - /// /// /// This function also validates that the given range is both valid and mapped, and will throw if it is not. /// - public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) + public override void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) { AssertValidAddressAndSize(va, size); @@ -543,23 +467,6 @@ namespace Ryujinx.Cpu.Jit _pages.SignalMemoryTracking(Tracking, va, size, write, exemptId); } - /// - /// Computes the number of pages in a virtual address range. - /// - /// Virtual address of the range - /// Size of the range - /// The virtual address of the beginning of the first page - /// This function does not differentiate between allocated and unallocated pages. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private int GetPagesCount(ulong va, ulong size, out ulong startVa) - { - // WARNING: Always check if ulong does not overflow during the operations. - startVa = va & ~(ulong)PageMask; - ulong vaSpan = (va - startVa + size + PageMask) & ~(ulong)PageMask; - - return (int)(vaSpan / PageSize); - } - public RegionHandle BeginTracking(ulong address, ulong size, int id, RegionFlags flags = RegionFlags.None) { return Tracking.BeginTracking(address, size, id, flags); @@ -618,10 +525,44 @@ namespace Ryujinx.Cpu.Jit _nativePageTable.Dispose(); } - protected override Span GetPhysicalAddressSpan(ulong pa, int size) + protected override Memory GetPhysicalAddressMemory(nuint pa, int size) + => _backingMemory.GetMemory(pa, size); + + protected override Span GetPhysicalAddressSpan(nuint pa, int size) => _backingMemory.GetSpan(pa, size); - protected override ulong TranslateVirtualAddressForRead(ulong va) - => GetPhysicalAddressInternal(va); + protected override void WriteImpl(ulong va, ReadOnlySpan data) + { + try + { + AssertValidAddressAndSize(va, (ulong)data.Length); + + ulong endVa = va + (ulong)data.Length; + int offset = 0; + + while (va < endVa) + { + (MemoryBlock memory, ulong rangeOffset, ulong copySize) = GetMemoryOffsetAndSize(va, (ulong)(data.Length - offset)); + + data.Slice(offset, (int)copySize).CopyTo(memory.GetSpan(rangeOffset, (int)copySize)); + + va += copySize; + offset += (int)copySize; + } + } + catch (InvalidMemoryRegionException) + { + if (_invalidAccessHandler == null || !_invalidAccessHandler(va)) + { + throw; + } + } + } + + protected override nuint TranslateVirtualAddressChecked(ulong va) + => (nuint)GetPhysicalAddressChecked(va); + + protected override nuint TranslateVirtualAddressUnchecked(ulong va) + => (nuint)GetPhysicalAddressInternal(va); } } diff --git a/ryujinx/src/Ryujinx.Cpu/VirtualMemoryManagerRefCountedBase.cs b/ryujinx/src/Ryujinx.Cpu/VirtualMemoryManagerRefCountedBase.cs index c2d8cfb1a0..3c7b338055 100644 --- a/ryujinx/src/Ryujinx.Cpu/VirtualMemoryManagerRefCountedBase.cs +++ b/ryujinx/src/Ryujinx.Cpu/VirtualMemoryManagerRefCountedBase.cs @@ -1,13 +1,10 @@ using Ryujinx.Memory; using System.Diagnostics; -using System.Numerics; using System.Threading; namespace Ryujinx.Cpu { - public abstract class VirtualMemoryManagerRefCountedBase : VirtualMemoryManagerBase, IRefCounted - where TVirtual : IBinaryInteger - where TPhysical : IBinaryInteger + public abstract class VirtualMemoryManagerRefCountedBase : VirtualMemoryManagerBase, IRefCounted { private int _referenceCount; diff --git a/ryujinx/src/Ryujinx.Memory/AddressSpaceManager.cs b/ryujinx/src/Ryujinx.Memory/AddressSpaceManager.cs index f19b45b659..f089c85736 100644 --- a/ryujinx/src/Ryujinx.Memory/AddressSpaceManager.cs +++ b/ryujinx/src/Ryujinx.Memory/AddressSpaceManager.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace Ryujinx.Memory { @@ -11,7 +10,7 @@ namespace Ryujinx.Memory /// Represents a address space manager. /// Supports virtual memory region mapping, address translation and read/write access to mapped regions. /// - public sealed class AddressSpaceManager : VirtualMemoryManagerBase, IVirtualMemoryManager, IWritableBlock + public sealed class AddressSpaceManager : VirtualMemoryManagerBase, IVirtualMemoryManager { /// public bool Supports4KBPages => true; @@ -63,8 +62,7 @@ namespace Ryujinx.Memory } } - /// - public void MapForeign(ulong va, nuint hostPointer, ulong size) + public override void MapForeign(ulong va, nuint hostPointer, ulong size) { AssertValidAddressAndSize(va, size); @@ -92,106 +90,6 @@ namespace Ryujinx.Memory } } - /// - public T Read(ulong va) where T : unmanaged - { - return MemoryMarshal.Cast(GetSpan(va, Unsafe.SizeOf()))[0]; - } - - /// - public void Write(ulong va, T value) where T : unmanaged - { - Write(va, MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1))); - } - - /// - public void Write(ulong va, ReadOnlySpan data) - { - if (data.Length == 0) - { - return; - } - - AssertValidAddressAndSize(va, (ulong)data.Length); - - if (IsContiguousAndMapped(va, data.Length)) - { - data.CopyTo(GetHostSpanContiguous(va, data.Length)); - } - else - { - int offset = 0, size; - - if ((va & PageMask) != 0) - { - size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); - - data[..size].CopyTo(GetHostSpanContiguous(va, size)); - - offset += size; - } - - for (; offset < data.Length; offset += size) - { - size = Math.Min(data.Length - offset, PageSize); - - data.Slice(offset, size).CopyTo(GetHostSpanContiguous(va + (ulong)offset, size)); - } - } - } - - /// - public bool WriteWithRedundancyCheck(ulong va, ReadOnlySpan data) - { - Write(va, data); - - return true; - } - - /// - public ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) - { - if (size == 0) - { - return ReadOnlySpan.Empty; - } - - if (IsContiguousAndMapped(va, size)) - { - return GetHostSpanContiguous(va, size); - } - else - { - Span data = new byte[size]; - - Read(va, data); - - return data; - } - } - - /// - public unsafe WritableRegion GetWritableRegion(ulong va, int size, bool tracked = false) - { - if (size == 0) - { - return new WritableRegion(null, va, Memory.Empty); - } - - if (IsContiguousAndMapped(va, size)) - { - return new WritableRegion(null, va, new NativeMemoryManager((byte*)GetHostAddress(va), size).Memory); - } - else - { - Memory memory = new byte[size]; - - GetSpan(va, size).CopyTo(memory.Span); - - return new WritableRegion(this, va, memory); - } - } - /// public unsafe ref T GetRef(ulong va) where T : unmanaged { @@ -203,50 +101,6 @@ namespace Ryujinx.Memory return ref *(T*)GetHostAddress(va); } - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int GetPagesCount(ulong va, uint size, out ulong startVa) - { - // WARNING: Always check if ulong does not overflow during the operations. - startVa = va & ~(ulong)PageMask; - ulong vaSpan = (va - startVa + size + PageMask) & ~(ulong)PageMask; - - return (int)(vaSpan / PageSize); - } - - private static void ThrowMemoryNotContiguous() => throw new MemoryNotContiguousException(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool IsContiguousAndMapped(ulong va, int size) => IsContiguous(va, size) && IsMapped(va); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool IsContiguous(ulong va, int size) - { - if (!ValidateAddress(va) || !ValidateAddressAndSize(va, (ulong)size)) - { - return false; - } - - int pages = GetPagesCount(va, (uint)size, out va); - - for (int page = 0; page < pages - 1; page++) - { - if (!ValidateAddress(va + PageSize)) - { - return false; - } - - if (GetHostAddress(va) + PageSize != GetHostAddress(va + PageSize)) - { - return false; - } - - va += PageSize; - } - - return true; - } - /// public IEnumerable GetHostRegions(ulong va, ulong size) { @@ -304,7 +158,7 @@ namespace Ryujinx.Memory return null; } - int pages = GetPagesCount(va, (uint)size, out va); + int pages = GetPagesCount(va, size, out va); var regions = new List(); @@ -336,9 +190,8 @@ namespace Ryujinx.Memory return regions; } - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool IsMapped(ulong va) + public override bool IsMapped(ulong va) { if (!ValidateAddress(va)) { @@ -351,7 +204,7 @@ namespace Ryujinx.Memory /// public bool IsRangeMapped(ulong va, ulong size) { - if (size == 0UL) + if (size == 0) { return true; } @@ -376,11 +229,6 @@ namespace Ryujinx.Memory return true; } - private unsafe Span GetHostSpanContiguous(ulong va, int size) - { - return new Span((void*)GetHostAddress(va), size); - } - private nuint GetHostAddress(ulong va) { return _pageTable.Read(va) + (nuint)(va & PageMask); @@ -397,16 +245,16 @@ namespace Ryujinx.Memory throw new NotImplementedException(); } - /// - public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) - { - // Only the ARM Memory Manager has tracking for now. - } + protected unsafe override Memory GetPhysicalAddressMemory(nuint pa, int size) + => new NativeMemoryManager((byte*)pa, size).Memory; protected override unsafe Span GetPhysicalAddressSpan(nuint pa, int size) - => new((void*)pa, size); + => new Span((void*)pa, size); - protected override nuint TranslateVirtualAddressForRead(ulong va) + protected override nuint TranslateVirtualAddressChecked(ulong va) + => GetHostAddress(va); + + protected override nuint TranslateVirtualAddressUnchecked(ulong va) => GetHostAddress(va); } } diff --git a/ryujinx/src/Ryujinx.Memory/BytesReadOnlySequenceSegment.cs b/ryujinx/src/Ryujinx.Memory/BytesReadOnlySequenceSegment.cs new file mode 100644 index 0000000000..5fe8d936c3 --- /dev/null +++ b/ryujinx/src/Ryujinx.Memory/BytesReadOnlySequenceSegment.cs @@ -0,0 +1,60 @@ +using System; +using System.Buffers; +using System.Runtime.InteropServices; + +namespace Ryujinx.Memory +{ + /// + /// A concrete implementation of , + /// with methods to help build a full sequence. + /// + public sealed class BytesReadOnlySequenceSegment : ReadOnlySequenceSegment + { + public BytesReadOnlySequenceSegment(Memory memory) => Memory = memory; + + public BytesReadOnlySequenceSegment Append(Memory memory) + { + var nextSegment = new BytesReadOnlySequenceSegment(memory) + { + RunningIndex = RunningIndex + Memory.Length + }; + + Next = nextSegment; + + return nextSegment; + } + + /// + /// Attempts to determine if the current and are contiguous. + /// Only works if both were created by a . + /// + /// The segment to check if continuous with the current one + /// The starting address of the contiguous segment + /// The size of the contiguous segment + /// True if the segments are contiguous, otherwise false + public unsafe bool IsContiguousWith(Memory other, out nuint contiguousStart, out int contiguousSize) + { + if (MemoryMarshal.TryGetMemoryManager>(Memory, out var thisMemoryManager) && + MemoryMarshal.TryGetMemoryManager>(other, out var otherMemoryManager) && + thisMemoryManager.Pointer + thisMemoryManager.Length == otherMemoryManager.Pointer) + { + contiguousStart = (nuint)thisMemoryManager.Pointer; + contiguousSize = thisMemoryManager.Length + otherMemoryManager.Length; + return true; + } + else + { + contiguousStart = 0; + contiguousSize = 0; + return false; + } + } + + /// + /// Replaces the current value with the one provided. + /// + /// The new segment to hold in this + public void Replace(Memory memory) + => Memory = memory; + } +} diff --git a/ryujinx/src/Ryujinx.Memory/IVirtualMemoryManager.cs b/ryujinx/src/Ryujinx.Memory/IVirtualMemoryManager.cs index 557da2f261..96d3e85797 100644 --- a/ryujinx/src/Ryujinx.Memory/IVirtualMemoryManager.cs +++ b/ryujinx/src/Ryujinx.Memory/IVirtualMemoryManager.cs @@ -124,6 +124,16 @@ namespace Ryujinx.Memory } } + /// + /// Gets a read-only sequence of read-only memory blocks from CPU mapped memory. + /// + /// Virtual address of the data + /// Size of the data + /// True if read tracking is triggered on the memory + /// A read-only sequence of read-only memory of the data + /// Throw for unhandled invalid or unmapped memory accesses + ReadOnlySequence GetReadOnlySequence(ulong va, int size, bool tracked = false); + /// /// Gets a read-only span of data from CPU mapped memory. /// diff --git a/ryujinx/src/Ryujinx.Memory/NativeMemoryManager.cs b/ryujinx/src/Ryujinx.Memory/NativeMemoryManager.cs index fe718bda81..9ca6329382 100644 --- a/ryujinx/src/Ryujinx.Memory/NativeMemoryManager.cs +++ b/ryujinx/src/Ryujinx.Memory/NativeMemoryManager.cs @@ -14,6 +14,10 @@ namespace Ryujinx.Memory _length = length; } + public unsafe T* Pointer => _pointer; + + public int Length => _length; + public override Span GetSpan() { return new Span((void*)_pointer, _length); diff --git a/ryujinx/src/Ryujinx.Memory/VirtualMemoryManagerBase.cs b/ryujinx/src/Ryujinx.Memory/VirtualMemoryManagerBase.cs index cbec88cc56..506e25f668 100644 --- a/ryujinx/src/Ryujinx.Memory/VirtualMemoryManagerBase.cs +++ b/ryujinx/src/Ryujinx.Memory/VirtualMemoryManagerBase.cs @@ -1,34 +1,171 @@ +using Ryujinx.Common.Memory; using System; -using System.Numerics; +using System.Buffers; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Ryujinx.Memory { - public abstract class VirtualMemoryManagerBase - where TVirtual : IBinaryInteger - where TPhysical : IBinaryInteger + public abstract class VirtualMemoryManagerBase : IWritableBlock { public const int PageBits = 12; public const int PageSize = 1 << PageBits; public const int PageMask = PageSize - 1; - protected abstract TVirtual AddressSpaceSize { get; } + protected abstract ulong AddressSpaceSize { get; } - public virtual void Read(TVirtual va, Span data) + public virtual ReadOnlySequence GetReadOnlySequence(ulong va, int size, bool tracked = false) + { + if (size == 0) + { + return ReadOnlySequence.Empty; + } + + if (tracked) + { + SignalMemoryTracking(va, (ulong)size, false); + } + + if (IsContiguousAndMapped(va, size)) + { + nuint pa = TranslateVirtualAddressUnchecked(va); + + return new ReadOnlySequence(GetPhysicalAddressMemory(pa, size)); + } + else + { + AssertValidAddressAndSize(va, size); + + int offset = 0, segmentSize; + + BytesReadOnlySequenceSegment first = null, last = null; + + if ((va & PageMask) != 0) + { + nuint pa = TranslateVirtualAddressChecked(va); + + segmentSize = Math.Min(size, PageSize - (int)(va & PageMask)); + + Memory memory = GetPhysicalAddressMemory(pa, segmentSize); + + first = last = new BytesReadOnlySequenceSegment(memory); + + offset += segmentSize; + } + + for (; offset < size; offset += segmentSize) + { + nuint pa = TranslateVirtualAddressChecked(va + (ulong)offset); + + segmentSize = Math.Min(size - offset, PageSize); + + Memory memory = GetPhysicalAddressMemory(pa, segmentSize); + + if (first is null) + { + first = last = new BytesReadOnlySequenceSegment(memory); + } + else + { + if (last.IsContiguousWith(memory, out nuint contiguousStart, out int contiguousSize)) + { + last.Replace(GetPhysicalAddressMemory(contiguousStart, contiguousSize)); + } + else + { + last = last.Append(memory); + } + } + } + + return new ReadOnlySequence(first, 0, last, (int)(size - last.RunningIndex)); + } + } + + public virtual ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) + { + if (size == 0) + { + return ReadOnlySpan.Empty; + } + + if (tracked) + { + SignalMemoryTracking(va, (ulong)size, false); + } + + if (IsContiguousAndMapped(va, size)) + { + nuint pa = TranslateVirtualAddressUnchecked(va); + + return GetPhysicalAddressSpan(pa, size); + } + else + { + Span data = new byte[size]; + + Read(va, data); + + return data; + } + } + + public virtual WritableRegion GetWritableRegion(ulong va, int size, bool tracked = false) + { + if (size == 0) + { + return new WritableRegion(null, va, Memory.Empty); + } + + if (tracked) + { + SignalMemoryTracking(va, (ulong)size, true); + } + + if (IsContiguousAndMapped(va, size)) + { + nuint pa = TranslateVirtualAddressUnchecked(va); + + return new WritableRegion(null, va, GetPhysicalAddressMemory(pa, size)); + } + else + { + IMemoryOwner memoryOwner = ByteMemoryPool.Rent(size); + + Read(va, memoryOwner.Memory.Span); + + return new WritableRegion(this, va, memoryOwner); + } + } + + public abstract bool IsMapped(ulong va); + + public virtual void MapForeign(ulong va, nuint hostPointer, ulong size) + { + throw new NotSupportedException(); + } + + public virtual T Read(ulong va) where T : unmanaged + { + return MemoryMarshal.Cast(GetSpan(va, Unsafe.SizeOf()))[0]; + } + + public virtual void Read(ulong va, Span data) { if (data.Length == 0) { return; } - AssertValidAddressAndSize(va, TVirtual.CreateChecked(data.Length)); + AssertValidAddressAndSize(va, data.Length); int offset = 0, size; - if ((int.CreateTruncating(va) & PageMask) != 0) + if ((va & PageMask) != 0) { - TPhysical pa = TranslateVirtualAddressForRead(va); + nuint pa = TranslateVirtualAddressChecked(va); - size = Math.Min(data.Length, PageSize - ((int.CreateTruncating(va) & PageMask))); + size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); GetPhysicalAddressSpan(pa, size).CopyTo(data[..size]); @@ -37,7 +174,7 @@ namespace Ryujinx.Memory for (; offset < data.Length; offset += size) { - TPhysical pa = TranslateVirtualAddressForRead(va + TVirtual.CreateChecked(offset)); + nuint pa = TranslateVirtualAddressChecked(va + (ulong)offset); size = Math.Min(data.Length - offset, PageSize); @@ -45,13 +182,84 @@ namespace Ryujinx.Memory } } + public virtual T ReadTracked(ulong va) where T : unmanaged + { + SignalMemoryTracking(va, (ulong)Unsafe.SizeOf(), false); + + return Read(va); + } + + public virtual void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) + { + // No default implementation + } + + public virtual void Write(ulong va, ReadOnlySpan data) + { + if (data.Length == 0) + { + return; + } + + SignalMemoryTracking(va, (ulong)data.Length, true); + + WriteImpl(va, data); + } + + public virtual void Write(ulong va, T value) where T : unmanaged + { + Write(va, MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1))); + } + + public virtual void WriteUntracked(ulong va, ReadOnlySpan data) + { + if (data.Length == 0) + { + return; + } + + WriteImpl(va, data); + } + + public virtual bool WriteWithRedundancyCheck(ulong va, ReadOnlySpan data) + { + if (data.Length == 0) + { + return false; + } + + if (IsContiguousAndMapped(va, data.Length)) + { + SignalMemoryTracking(va, (ulong)data.Length, false); + + nuint pa = TranslateVirtualAddressChecked(va); + + var target = GetPhysicalAddressSpan(pa, data.Length); + + bool changed = !data.SequenceEqual(target); + + if (changed) + { + data.CopyTo(target); + } + + return changed; + } + else + { + Write(va, data); + + return true; + } + } + /// /// Ensures the combination of virtual address and size is part of the addressable space. /// /// Virtual address of the range /// Size of the range in bytes /// Throw when the memory region specified outside the addressable space - protected void AssertValidAddressAndSize(TVirtual va, TVirtual size) + protected void AssertValidAddressAndSize(ulong va, ulong size) { if (!ValidateAddressAndSize(va, size)) { @@ -59,16 +267,82 @@ namespace Ryujinx.Memory } } - protected abstract Span GetPhysicalAddressSpan(TPhysical pa, int size); + /// + /// Ensures the combination of virtual address and size is part of the addressable space. + /// + /// Virtual address of the range + /// Size of the range in bytes + /// Throw when the memory region specified outside the addressable space + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected void AssertValidAddressAndSize(ulong va, int size) + => AssertValidAddressAndSize(va, (ulong)size); - protected abstract TPhysical TranslateVirtualAddressForRead(TVirtual va); + /// + /// Computes the number of pages in a virtual address range. + /// + /// Virtual address of the range + /// Size of the range + /// The virtual address of the beginning of the first page + /// This function does not differentiate between allocated and unallocated pages. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected static int GetPagesCount(ulong va, ulong size, out ulong startVa) + { + // WARNING: Always check if ulong does not overflow during the operations. + startVa = va & ~(ulong)PageMask; + ulong vaSpan = (va - startVa + size + PageMask) & ~(ulong)PageMask; + + return (int)(vaSpan / PageSize); + } + + protected abstract Memory GetPhysicalAddressMemory(nuint pa, int size); + + protected abstract Span GetPhysicalAddressSpan(nuint pa, int size); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected bool IsContiguous(ulong va, int size) => IsContiguous(va, (ulong)size); + + protected virtual bool IsContiguous(ulong va, ulong size) + { + if (!ValidateAddress(va) || !ValidateAddressAndSize(va, size)) + { + return false; + } + + int pages = GetPagesCount(va, size, out va); + + for (int page = 0; page < pages - 1; page++) + { + if (!ValidateAddress(va + PageSize)) + { + return false; + } + + if (TranslateVirtualAddressUnchecked(va) + PageSize != TranslateVirtualAddressUnchecked(va + PageSize)) + { + return false; + } + + va += PageSize; + } + + return true; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected bool IsContiguousAndMapped(ulong va, int size) + => IsContiguous(va, size) && IsMapped(va); + + protected abstract nuint TranslateVirtualAddressChecked(ulong va); + + protected abstract nuint TranslateVirtualAddressUnchecked(ulong va); /// /// Checks if the virtual address is part of the addressable space. /// /// Virtual address /// True if the virtual address is part of the addressable space - protected bool ValidateAddress(TVirtual va) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected bool ValidateAddress(ulong va) { return va < AddressSpaceSize; } @@ -79,13 +353,53 @@ namespace Ryujinx.Memory /// Virtual address of the range /// Size of the range in bytes /// True if the combination of virtual address and size is part of the addressable space - protected bool ValidateAddressAndSize(TVirtual va, TVirtual size) + protected bool ValidateAddressAndSize(ulong va, ulong size) { - TVirtual endVa = va + size; + ulong endVa = va + size; return endVa >= va && endVa >= size && endVa <= AddressSpaceSize; } protected static void ThrowInvalidMemoryRegionException(string message) => throw new InvalidMemoryRegionException(message); + + protected static void ThrowMemoryNotContiguous() + => throw new MemoryNotContiguousException(); + + protected virtual void WriteImpl(ulong va, ReadOnlySpan data) + { + AssertValidAddressAndSize(va, data.Length); + + if (IsContiguousAndMapped(va, data.Length)) + { + nuint pa = TranslateVirtualAddressUnchecked(va); + + data.CopyTo(GetPhysicalAddressSpan(pa, data.Length)); + } + else + { + int offset = 0, size; + + if ((va & PageMask) != 0) + { + nuint pa = TranslateVirtualAddressChecked(va); + + size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); + + data[..size].CopyTo(GetPhysicalAddressSpan(pa, size)); + + offset += size; + } + + for (; offset < data.Length; offset += size) + { + nuint pa = TranslateVirtualAddressChecked(va + (ulong)offset); + + size = Math.Min(data.Length - offset, PageSize); + + data.Slice(offset, size).CopyTo(GetPhysicalAddressSpan(pa, size)); + } + } + } + } } diff --git a/ryujinx/src/Ryujinx.Memory/WritableRegion.cs b/ryujinx/src/Ryujinx.Memory/WritableRegion.cs index 666c8a99b2..2c21ef4e80 100644 --- a/ryujinx/src/Ryujinx.Memory/WritableRegion.cs +++ b/ryujinx/src/Ryujinx.Memory/WritableRegion.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; namespace Ryujinx.Memory { @@ -6,6 +7,7 @@ namespace Ryujinx.Memory { private readonly IWritableBlock _block; private readonly ulong _va; + private readonly IMemoryOwner _memoryOwner; private readonly bool _tracked; private bool NeedsWriteback => _block != null; @@ -20,6 +22,12 @@ namespace Ryujinx.Memory Memory = memory; } + public WritableRegion(IWritableBlock block, ulong va, IMemoryOwner memoryOwner, bool tracked = false) + : this(block, va, memoryOwner.Memory, tracked) + { + _memoryOwner = memoryOwner; + } + public void Dispose() { if (NeedsWriteback) @@ -33,6 +41,8 @@ namespace Ryujinx.Memory _block.WriteUntracked(_va, Memory.Span); } } + + _memoryOwner?.Dispose(); } } } diff --git a/ryujinx/src/Ryujinx.Tests.Memory/MockVirtualMemoryManager.cs b/ryujinx/src/Ryujinx.Tests.Memory/MockVirtualMemoryManager.cs index 85a1ac02bc..15e7d9b89a 100644 --- a/ryujinx/src/Ryujinx.Tests.Memory/MockVirtualMemoryManager.cs +++ b/ryujinx/src/Ryujinx.Tests.Memory/MockVirtualMemoryManager.cs @@ -1,6 +1,7 @@ using Ryujinx.Memory; using Ryujinx.Memory.Range; using System; +using System.Buffers; using System.Collections.Generic; namespace Ryujinx.Tests.Memory @@ -57,6 +58,11 @@ namespace Ryujinx.Tests.Memory throw new NotImplementedException(); } + public ReadOnlySequence GetReadOnlySequence(ulong va, int size, bool tracked = false) + { + throw new NotImplementedException(); + } + public ReadOnlySpan GetSpan(ulong va, int size, bool tracked = false) { throw new NotImplementedException(); diff --git a/ryujinx/src/Ryujinx/AppHost.cs b/ryujinx/src/Ryujinx/AppHost.cs index 868d194fb3..d69bfc147f 100644 --- a/ryujinx/src/Ryujinx/AppHost.cs +++ b/ryujinx/src/Ryujinx/AppHost.cs @@ -777,31 +777,31 @@ namespace Ryujinx.Ava var memoryConfiguration = ConfigurationState.Instance.System.ExpandRam.Value ? MemoryConfiguration.MemoryConfiguration6GiB : MemoryConfiguration.MemoryConfiguration4GiB; HLEConfiguration configuration = new(VirtualFileSystem, - _viewModel.LibHacHorizonManager, - ContentManager, - _accountManager, - _userChannelPersistence, - renderer, - InitializeAudio(), - memoryConfiguration, - _viewModel.UiHandler, - (SystemLanguage)ConfigurationState.Instance.System.Language.Value, - (RegionCode)ConfigurationState.Instance.System.Region.Value, - ConfigurationState.Instance.Graphics.EnableVsync, - ConfigurationState.Instance.System.EnableDockedMode, - ConfigurationState.Instance.System.EnablePtc, - ConfigurationState.Instance.System.EnableInternetAccess, - ConfigurationState.Instance.System.EnableFsIntegrityChecks ? IntegrityCheckLevel.ErrorOnInvalid : IntegrityCheckLevel.None, - ConfigurationState.Instance.System.FsGlobalAccessLogMode, - ConfigurationState.Instance.System.SystemTimeOffset, - ConfigurationState.Instance.System.TimeZone, - ConfigurationState.Instance.System.MemoryManagerMode, - ConfigurationState.Instance.System.IgnoreMissingServices, - ConfigurationState.Instance.Graphics.AspectRatio, - ConfigurationState.Instance.System.AudioVolume, - ConfigurationState.Instance.System.UseHypervisor, - ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value, - ConfigurationState.Instance.Multiplayer.Mode); + _viewModel.LibHacHorizonManager, + ContentManager, + _accountManager, + _userChannelPersistence, + renderer, + InitializeAudio(), + memoryConfiguration, + _viewModel.UiHandler, + (SystemLanguage)ConfigurationState.Instance.System.Language.Value, + (RegionCode)ConfigurationState.Instance.System.Region.Value, + ConfigurationState.Instance.Graphics.EnableVsync, + ConfigurationState.Instance.System.EnableDockedMode, + ConfigurationState.Instance.System.EnablePtc, + ConfigurationState.Instance.System.EnableInternetAccess, + ConfigurationState.Instance.System.EnableFsIntegrityChecks ? IntegrityCheckLevel.ErrorOnInvalid : IntegrityCheckLevel.None, + ConfigurationState.Instance.System.FsGlobalAccessLogMode, + ConfigurationState.Instance.System.SystemTimeOffset, + ConfigurationState.Instance.System.TimeZone, + ConfigurationState.Instance.System.MemoryManagerMode, + ConfigurationState.Instance.System.IgnoreMissingServices, + ConfigurationState.Instance.Graphics.AspectRatio, + ConfigurationState.Instance.System.AudioVolume, + ConfigurationState.Instance.System.UseHypervisor, + ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value, + ConfigurationState.Instance.Multiplayer.Mode); Device = new Switch(configuration); } diff --git a/ryujinx/src/Ryujinx/Assets/Locales/en_US.json b/ryujinx/src/Ryujinx/Assets/Locales/en_US.json index 3a3cb3017d..ef40fd5b2e 100644 --- a/ryujinx/src/Ryujinx/Assets/Locales/en_US.json +++ b/ryujinx/src/Ryujinx/Assets/Locales/en_US.json @@ -597,6 +597,7 @@ "UserProfileWindowTitle": "User Profiles Manager", "CheatWindowTitle": "Cheats Manager", "DlcWindowTitle": "Manage Downloadable Content for {0} ({1})", + "ModWindowTitle": "Manage Mods for {0} ({1})", "UpdateWindowTitle": "Title Update Manager", "CheatWindowHeading": "Cheats Available for {0} [{1}]", "BuildId": "BuildId:", diff --git a/ryujinx/src/Ryujinx/UI/Windows/ModManagerWindow.axaml.cs b/ryujinx/src/Ryujinx/UI/Windows/ModManagerWindow.axaml.cs index d9ae0d4f32..98f694db81 100644 --- a/ryujinx/src/Ryujinx/UI/Windows/ModManagerWindow.axaml.cs +++ b/ryujinx/src/Ryujinx/UI/Windows/ModManagerWindow.axaml.cs @@ -38,7 +38,7 @@ namespace Ryujinx.Ava.UI.Windows SecondaryButtonText = "", CloseButtonText = "", Content = new ModManagerWindow(titleId), - Title = string.Format(LocaleManager.Instance[LocaleKeys.ModWindowHeading], titleName, titleId.ToString("X16")), + Title = string.Format(LocaleManager.Instance[LocaleKeys.ModWindowTitle], titleName, titleId.ToString("X16")), }; Style bottomBorder = new(x => x.OfType().Name("DialogSpace").Child().OfType()); diff --git a/small/luci-app-passwall/luasrc/passwall/util_xray.lua b/small/luci-app-passwall/luasrc/passwall/util_xray.lua index 7121f2fb4b..56f6008b8d 100644 --- a/small/luci-app-passwall/luasrc/passwall/util_xray.lua +++ b/small/luci-app-passwall/luasrc/passwall/util_xray.lua @@ -646,6 +646,17 @@ function gen_config(var) return "balancer-" .. _node_id end + local function gen_loopback(outboundTag, dst_node_id) + if not outboundTag then return nil end + local inboundTag = dst_node_id and "loop-in-" .. dst_node_id or outboundTag .. "-lo" + table.insert(outbounds, { + protocol = "loopback", + tag = outboundTag, + settings = { inboundTag = inboundTag } + }) + return inboundTag + end + local function gen_balancer(_node, loopbackTag) local blc_nodes = _node.balancing_node local fallback_node_id = _node.fallback_node @@ -720,12 +731,7 @@ function gen_config(var) end end if loopbackTag == nil or loopbackTag =="" then loopbackTag = _node[".name"] end - local inboundTag = loopbackTag .. "-in" - table.insert(outbounds, { - protocol = "loopback", - tag = loopbackTag, - settings = { inboundTag = inboundTag } - }) + local inboundTag = gen_loopback(loopbackTag, _node[".name"]) table.insert(rules, { type = "field", inboundTag = { inboundTag }, balancerTag = balancerTag }) valid = true end @@ -761,46 +767,10 @@ function gen_config(var) end if node.protocol == "_shunt" then - local preproxy_enabled = node.preproxy_enabled == "1" - local preproxy_tag = "main" - local preproxy_node_id = node["main_node"] - local preproxy_node = preproxy_enabled and preproxy_node_id and uci:get_all(appname, preproxy_node_id) or nil - local preproxy_is_balancer - - if preproxy_node_id and preproxy_node_id:find("Socks_") then - local socks_id = preproxy_node_id:sub(1 + #"Socks_") - local socks_node = uci:get_all(appname, socks_id) or nil - if socks_node then - local _node = { - type = "Xray", - protocol = "socks", - address = "127.0.0.1", - port = socks_node.port, - transport = "tcp", - stream_security = "none" - } - local preproxy_outbound = gen_outbound(flag, _node, preproxy_tag) - if preproxy_outbound then - table.insert(outbounds, preproxy_outbound) - else - preproxy_enabled = false - end - end - elseif preproxy_node and api.is_normal_node(preproxy_node) then - local preproxy_outbound = gen_outbound(flag, preproxy_node, preproxy_tag, { fragment = xray_settings.fragment == "1" or nil }) - if preproxy_outbound then - set_outbound_detour(preproxy_node, preproxy_outbound, outbounds, preproxy_tag) - table.insert(outbounds, preproxy_outbound) - else - preproxy_enabled = false - end - elseif preproxy_node and preproxy_node.protocol == "_balancing" then - preproxy_is_balancer = true - local valid = gen_balancer(preproxy_node, preproxy_tag) - if not valid then - preproxy_enabled = false - end - end + local proxy_tag = "main" + local proxy_node_id = node["main_node"] + local proxy_node = node.preproxy_enabled == "1" and proxy_node_id and uci:get_all(appname, proxy_node_id) or nil + local proxy_outboundTag, proxy_balancerTag local function gen_shunt_node(rule_name, _node_id) if not rule_name then return nil, nil end @@ -811,7 +781,7 @@ function gen_config(var) rule_outboundTag = "direct" elseif _node_id == "_blackhole" then rule_outboundTag = "blackhole" - elseif _node_id == "_default" and rule_name ~= "default" then + elseif _node_id == "_default" then rule_outboundTag = "default" elseif _node_id:find("Socks_") then local socks_id = _node_id:sub(1 + #"Socks_") @@ -825,9 +795,9 @@ function gen_config(var) transport = "tcp", stream_security = "none" } - local _outbound = gen_outbound(flag, _node, rule_name) - if _outbound then - table.insert(outbounds, _outbound) + local outbound = gen_outbound(flag, _node, rule_name) + if outbound then + table.insert(outbounds, outbound) rule_outboundTag = rule_name end end @@ -836,19 +806,18 @@ function gen_config(var) if not _node then return nil, nil end if api.is_normal_node(_node) then - local proxy = preproxy_enabled and node[rule_name .. "_proxy_tag"] == preproxy_tag and _node_id ~= preproxy_node_id - if proxy and preproxy_is_balancer then - local blc_nodes = proxy_node.balancing_node - for _, blc_node_id in ipairs(blc_nodes) do + local use_proxy = proxy_node and node[rule_name .. "_proxy_tag"] == proxy_tag and _node_id ~= proxy_node_id + if use_proxy and proxy_balancerTag then + for _, blc_node_id in ipairs(proxy_node.balancing_node) do if _node_id == blc_node_id then - proxy = false + use_proxy = false break end end end local copied_outbound for index, value in ipairs(outbounds) do - if value["_flag_tag"] == _node_id and value["_flag_proxy_tag"] == preproxy_tag then + if value["_flag_tag"] == _node_id and value["_flag_proxy_tag"] == proxy_tag then copied_outbound = api.clone(value) break end @@ -858,69 +827,60 @@ function gen_config(var) table.insert(outbounds, copied_outbound) rule_outboundTag = rule_name else - if proxy then - local pre_proxy = nil - if _node.type ~= "Xray" then - pre_proxy = true - end - if _node.type == "Xray" and _node.flow == "xtls-rprx-vision" then - pre_proxy = true - end - if pre_proxy then - new_port = get_new_port() - table.insert(inbounds, { - tag = "proxy_" .. rule_name, - listen = "127.0.0.1", - port = new_port, - protocol = "dokodemo-door", - settings = {network = "tcp,udp", address = _node.address, port = tonumber(_node.port)} - }) - if _node.tls_serverName == nil then - _node.tls_serverName = _node.address - end - _node.address = "127.0.0.1" - _node.port = new_port - table.insert(rules, 1, { - type = "field", - inboundTag = {"proxy_" .. rule_name}, - outboundTag = is_balancing_proxy and nil or preproxy_tag, - balancerTag = is_balancing_proxy and get_balancer_tag(proxy_node_id) or nil - }) + if use_proxy and (_node.type ~= "Xray" or _node.flow == "xtls-rprx-vision") then + new_port = get_new_port() + table.insert(inbounds, { + tag = "proxy_" .. rule_name, + listen = "127.0.0.1", + port = new_port, + protocol = "dokodemo-door", + settings = {network = "tcp,udp", address = _node.address, port = tonumber(_node.port)} + }) + if _node.tls_serverName == nil then + _node.tls_serverName = _node.address end + _node.address = "127.0.0.1" + _node.port = new_port + table.insert(rules, 1, { + type = "field", + inboundTag = {"proxy_" .. rule_name}, + outboundTag = proxy_outboundTag, + balancerTag = proxy_balancerTag + }) end local proxy_table = { - proxy = proxy and 1 or 0, - tag = proxy and preproxy_tag or nil + proxy = use_proxy and 1 or 0, + tag = use_proxy and proxy_tag or nil } if xray_settings.fragment == "1" and not proxy_table.tag then proxy_table.fragment = true end - local _outbound = gen_outbound(flag, _node, rule_name, proxy_table) - if _outbound then - set_outbound_detour(_node, _outbound, outbounds, rule_name) - table.insert(outbounds, _outbound) - if proxy then preproxy_used = true end + local outbound = gen_outbound(flag, _node, rule_name, proxy_table) + if outbound then + set_outbound_detour(_node, outbound, outbounds, rule_name) + table.insert(outbounds, outbound) rule_outboundTag = rule_name end end elseif _node.protocol == "_balancing" then local is_new_balancer = true + rule_balancerTag = get_balancer_tag(_node_id) for _, v in ipairs(balancers) do - if v["_flag_tag"] == _node_id then + if v.tag == rule_balancerTag then is_new_balancer = false - rule_balancerTag = v.tag + gen_loopback(rule_name, _node_id) break end end if is_new_balancer then - local valid = gen_balancer(_node) - if valid then - rule_balancerTag = get_balancer_tag(_node_id) + local valid = gen_balancer(_node, rule_name) + if not valid then + rule_balancerTag = nil end end elseif _node.protocol == "_iface" then if _node.iface then - local _outbound = { + local outbound = { protocol = "freedom", tag = rule_name, streamSettings = { @@ -930,7 +890,7 @@ function gen_config(var) } } } - table.insert(outbounds, _outbound) + table.insert(outbounds, outbound) rule_outboundTag = rule_name sys.call("touch /tmp/etc/passwall/iface/" .. _node.iface) end @@ -938,6 +898,14 @@ function gen_config(var) end return rule_outboundTag, rule_balancerTag end + + --proxy_node + if proxy_node then + proxy_outboundTag, proxy_balancerTag = gen_shunt_node(proxy_tag, proxy_node_id) + if not proxy_outboundTag and not proxy_balancerTag then + proxy_node = nil + end + end --default_node local default_node_id = node.default_node or "_direct" local default_outboundTag, default_balancerTag = gen_shunt_node("default", default_node_id) diff --git a/v2rayn/v2rayN/v2rayN/Sample/dns_singbox_normal b/v2rayn/v2rayN/v2rayN/Sample/dns_singbox_normal index dedab8b56f..0aa14b1f53 100644 --- a/v2rayn/v2rayN/v2rayN/Sample/dns_singbox_normal +++ b/v2rayn/v2rayN/v2rayN/Sample/dns_singbox_normal @@ -3,11 +3,13 @@ { "tag": "remote", "address": "tcp://8.8.8.8", + "strategy": "ipv4_only", "detour": "proxy" }, { "tag": "local", "address": "223.5.5.5", + "strategy": "ipv4_only", "detour": "direct" }, { @@ -18,9 +20,9 @@ "rules": [ { "geosite": [ - "cn" + "geolocation-!cn" ], - "server": "local" + "server": "remote" }, { "geosite": [ diff --git a/v2rayn/v2rayN/v2rayN/Sample/tun_singbox_dns b/v2rayn/v2rayN/v2rayN/Sample/tun_singbox_dns index 5d03bf90ff..0aa14b1f53 100644 --- a/v2rayn/v2rayN/v2rayN/Sample/tun_singbox_dns +++ b/v2rayn/v2rayN/v2rayN/Sample/tun_singbox_dns @@ -3,11 +3,13 @@ { "tag": "remote", "address": "tcp://8.8.8.8", + "strategy": "ipv4_only", "detour": "proxy" }, { "tag": "local", "address": "223.5.5.5", + "strategy": "ipv4_only", "detour": "direct" }, { @@ -18,18 +20,15 @@ "rules": [ { "geosite": [ - "cn" + "geolocation-!cn" ], - "server": "local", - "disable_cache": true + "server": "remote" }, { "geosite": [ "category-ads-all" ], - "server": "block", - "disable_cache": true + "server": "block" } - ], - "strategy": "ipv4_only" + ] } \ No newline at end of file diff --git a/v2rayn/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayn/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs index 23366026bc..67b9af5fa7 100644 --- a/v2rayn/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayn/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs @@ -196,13 +196,14 @@ namespace v2rayN.ViewModels return; } - var lst = new List(); + var lst = new List(); foreach (var it in SelectedSources) { var item = _rules.FirstOrDefault(t => t.id == it?.id); if (item != null) { - lst.Add(item); + var item2 = JsonUtils.Deserialize(JsonUtils.Serialize(item)); + lst.Add(item2 ?? new()); } } if (lst.Count > 0) diff --git a/yass/CMakeLists.txt b/yass/CMakeLists.txt index dff2b3d976..51f8d286d6 100644 --- a/yass/CMakeLists.txt +++ b/yass/CMakeLists.txt @@ -3046,8 +3046,8 @@ elseif (USE_NGHTTP2) set(ENABLE_HPACK_TOOLS OFF CACHE BOOL "") set(ENABLE_EXAMPLES OFF CACHE BOOL "") set(ENABLE_LIB_ONLY ON CACHE BOOL "") - set(ENABLE_SHARED_LIB OFF CACHE BOOL "") - set(ENABLE_STATIC_LIB ON CACHE BOOL "") + set(BUILD_SHARED_LIBS OFF CACHE BOOL "") + set(BUILD_STATIC_LIBS ON CACHE BOOL "") set(ENABLE_DOC OFF CACHE BOOL "") set(DISABLE_INSTALL ON CACHE BOOL "") add_subdirectory(third_party/nghttp2) diff --git a/yass/README.md b/yass/README.md index d14a60378a..e600f57961 100644 --- a/yass/README.md +++ b/yass/README.md @@ -22,13 +22,13 @@ More Information refers to [wiki](https://github.com/Chilledheart/yass/wiki) and ## Usages ### Prebuilt binaries -- Android [download apk](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-android-release-arm64-1.8.1.apk) or [download 32-bit apk](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-android-release-arm-1.8.1.apk) -- iOS [join via TestFlight](https://testflight.apple.com/join/6AkiEq09) or [download ipa](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-ios-release-arm64-1.8.1.ipa) -- Windows [download installer](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-mingw-winxp-release-x86_64-1.8.1-system-installer.exe) or [download 32-bit installer (require runtime)](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-mingw-winxp-release-i686-1.8.1-system-installer.exe) or [download woa arm64 installer](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-mingw-release-aarch64-1.8.1-system-installer.exe) -- macOS [download intel dmg](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-macos-release-x64-1.8.1.dmg) or [download apple silicon dmg](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-macos-release-arm64-1.8.1.dmg) -- Linux [download rpm](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass.el7.x86_64.1.8.1-0.rpm) or [download deb](https://github.com/Chilledheart/yass/releases/download/1.8.1/yass-client-ubuntu-16.04-xenial_amd64.1.8.1.deb) +- Android [download apk](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-android-release-arm64-1.8.2.apk) or [download 32-bit apk](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-android-release-arm-1.8.2.apk) +- iOS [join via TestFlight](https://testflight.apple.com/join/6AkiEq09) or [download ipa](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-ios-release-arm64-1.8.2.ipa) +- Windows [download installer](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-mingw-winxp-release-x86_64-1.8.2-system-installer.exe) or [download 32-bit installer (require runtime)](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-mingw-winxp-release-i686-1.8.2-system-installer.exe) or [download woa arm64 installer](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-mingw-release-aarch64-1.8.2-system-installer.exe) +- macOS [download intel dmg](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-macos-release-x64-1.8.2.dmg) or [download apple silicon dmg](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-macos-release-arm64-1.8.2.dmg) +- Linux [download rpm](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass.el7.x86_64.1.8.2-0.rpm) or [download deb](https://github.com/Chilledheart/yass/releases/download/1.8.2/yass-client-ubuntu-16.04-xenial_amd64.1.8.2.deb) -View more at [release page](https://github.com/Chilledheart/yass/releases/tag/1.8.1) +View more at [release page](https://github.com/Chilledheart/yass/releases/tag/1.8.2) ### Status of Package Store Visit wiki's [Status of Package Store](https://github.com/Chilledheart/yass/wiki/Status-of-Package-Store) diff --git a/yass/debian/changelog b/yass/debian/changelog index e88e442ae4..95e59d52e9 100644 --- a/yass/debian/changelog +++ b/yass/debian/changelog @@ -1,3 +1,8 @@ +yass (1.8.2-1) UNRELEASED; urgency=medium + + * fix (nghttp2) CVE-2024-30255 + + -- Chilledheart Fri, 5 Apr 2024 16:13:05 +0800 yass (1.8.1-1) UNRELEASED; urgency=medium * bump to chromium 124 dependents. diff --git a/yass/third_party/nghttp2/.clang-format b/yass/third_party/nghttp2/.clang-format index b4380bcfaa..4aa455a506 100644 --- a/yass/third_party/nghttp2/.clang-format +++ b/yass/third_party/nghttp2/.clang-format @@ -3,10 +3,30 @@ Language: Cpp AccessModifierOffset: -2 AlignAfterOpenBracket: Align AlignArrayOfStructures: None -AlignConsecutiveMacros: None -AlignConsecutiveAssignments: None -AlignConsecutiveBitFields: None -AlignConsecutiveDeclarations: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true AlignEscapedNewlines: Right AlignOperands: Align AlignTrailingComments: true @@ -47,7 +67,7 @@ BraceWrapping: SplitEmptyRecord: true SplitEmptyNamespace: true BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: true +BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeColon @@ -102,9 +122,10 @@ IndentCaseBlocks: false IndentGotoLabels: true IndentPPDirectives: AfterHash IndentExternBlock: AfterExternBlock -IndentRequires: false +IndentRequiresClause: false IndentWidth: 2 IndentWrappedFunctionNames: false +InsertBraces: false InsertTrailingCommas: None JavaScriptQuotes: Leave JavaScriptWrapImports: true @@ -134,6 +155,7 @@ PPIndentWidth: -1 ReferenceAlignment: Pointer ReflowComments: true RemoveBracesLLVM: false +RequiresClausePosition: OwnLine SeparateDefinitionBlocks: Leave ShortNamespaceLines: 1 SortIncludes: Never @@ -155,6 +177,8 @@ SpaceBeforeParensOptions: AfterFunctionDeclarationName: false AfterIfMacros: true AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false BeforeNonEmptyParentheses: false SpaceAroundPointerQualifiers: Default SpaceBeforeRangeBasedForLoopColon: true diff --git a/yass/third_party/nghttp2/.github/dependabot.yml b/yass/third_party/nghttp2/.github/dependabot.yml index 8c139c7bec..9cb65bae74 100644 --- a/yass/third_party/nghttp2/.github/dependabot.yml +++ b/yass/third_party/nghttp2/.github/dependabot.yml @@ -4,3 +4,7 @@ updates: directory: "/" schedule: interval: "weekly" +- package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" diff --git a/yass/third_party/nghttp2/.github/workflows/build.yml b/yass/third_party/nghttp2/.github/workflows/build.yml index 9d87efac82..7728f0b722 100644 --- a/yass/third_party/nghttp2/.github/workflows/build.yml +++ b/yass/third_party/nghttp2/.github/workflows/build.yml @@ -5,12 +5,13 @@ on: [push, pull_request] permissions: read-all env: - LIBBPF_VERSION: v1.2.2 + LIBBPF_VERSION: v1.3.0 OPENSSL1_VERSION: 1_1_1w+quic - OPENSSL3_VERSION: 3.1.2+quic - BORINGSSL_VERSION: 6ca49385b168f47a50e7172d82a590b218f55e4d - NGHTTP3_VERSION: v1.0.0 - NGTCP2_VERSION: v1.0.1 + OPENSSL3_VERSION: 3.1.5+quic + BORINGSSL_VERSION: fae0964b3d44e94ca2a2d21f86e61dabe683d130 + AWSLC_VERSION: v1.23.0 + NGHTTP3_VERSION: v1.2.0 + NGTCP2_VERSION: v1.4.0 jobs: build-cache: @@ -21,50 +22,60 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - name: Restore libbpf cache id: cache-libbpf - uses: actions/cache@v3 + uses: actions/cache@v4 if: runner.os == 'Linux' with: path: libbpf/build key: ${{ runner.os }}-libbpf-${{ env.LIBBPF_VERSION }} - name: Restore OpenSSL v1.1.1 cache id: cache-openssl1 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: openssl1/build key: ${{ runner.os }}-openssl-${{ env.OPENSSL1_VERSION }} - name: Restore OpenSSL v3.x cache id: cache-openssl3 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: openssl3/build key: ${{ runner.os }}-openssl-${{ env.OPENSSL3_VERSION }} - name: Restore BoringSSL cache id: cache-boringssl - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | boringssl/build/crypto/libcrypto.a boringssl/build/ssl/libssl.a boringssl/include key: ${{ runner.os }}-boringssl-${{ env.BORINGSSL_VERSION }} + - name: Restore aws-lc cache + id: cache-awslc + uses: actions/cache@v4 + with: + path: | + aws-lc/build/crypto/libcrypto.a + aws-lc/build/ssl/libssl.a + aws-lc/include + key: ${{ runner.os }}-awslc-${{ env.AWSLC_VERSION }} - name: Restore nghttp3 cache id: cache-nghttp3 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: nghttp3/build key: ${{ runner.os }}-nghttp3-${{ env.NGHTTP3_VERSION }} - name: Restore ngtcp2 + quictls/openssl v1.1.1 cache id: cache-ngtcp2-openssl1 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ngtcp2-openssl1/build key: ${{ runner.os }}-ngtcp2-${{ env.NGTCP2_VERSION }}-openssl-${{ env.OPENSSL1_VERSION }} - name: Restore ngtcp2 + quictls/openssl v3.x cache id: cache-ngtcp2-openssl3 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ngtcp2-openssl3/build key: ${{ runner.os }}-ngtcp2-${{ env.NGTCP2_VERSION }}-openssl-${{ env.OPENSSL3_VERSION }} @@ -74,6 +85,7 @@ jobs: steps.cache-openssl1.outputs.cache-hit != 'true' || steps.cache-openssl3.outputs.cache-hit != 'true' || steps.cache-boringssl.outputs.cache-hit != 'true' || + steps.cache-awslc.outputs.cache-hit != 'true' || steps.cache-nghttp3.outputs.cache-hit != 'true' || steps.cache-ngtcp2-openssl1.outputs.cache-hit != 'true' || steps.cache-ngtcp2-openssl3.outputs.cache-hit != 'true' @@ -82,9 +94,10 @@ jobs: - name: Linux setup if: runner.os == 'Linux' && steps.settings.outputs.needs-build == 'true' run: | + sudo apt-get update sudo apt-get install \ g++-12 \ - clang-14 \ + clang-15 \ autoconf \ automake \ autotools-dev \ @@ -104,13 +117,13 @@ jobs: - name: Build libbpf if: steps.cache-libbpf.outputs.cache-hit != 'true' && runner.os == 'Linux' run: | - git clone -b ${{ env.LIBBPF_VERSION }} https://github.com/libbpf/libbpf + git clone --recursive -b ${{ env.LIBBPF_VERSION }} https://github.com/libbpf/libbpf cd libbpf make -C src install PREFIX=$PWD/build - name: Build quictls/openssl v1.1.1 if: steps.cache-openssl1.outputs.cache-hit != 'true' run: | - git clone --depth 1 -b OpenSSL_${{ env.OPENSSL1_VERSION }} https://github.com/quictls/openssl openssl1 + git clone --recursive --depth 1 -b OpenSSL_${{ env.OPENSSL1_VERSION }} https://github.com/quictls/openssl openssl1 cd openssl1 ./config --prefix=$PWD/build make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" @@ -118,7 +131,7 @@ jobs: - name: Build quictls/openssl v3.x if: steps.cache-openssl3.outputs.cache-hit != 'true' run: | - git clone --depth 1 -b openssl-${{ env.OPENSSL3_VERSION }} https://github.com/quictls/openssl openssl3 + git clone --recursive --depth 1 -b openssl-${{ env.OPENSSL3_VERSION }} https://github.com/quictls/openssl openssl3 cd openssl3 ./config enable-ktls --prefix=$PWD/build --libdir=$PWD/build/lib make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" @@ -126,26 +139,36 @@ jobs: - name: Build BoringSSL if: steps.cache-boringssl.outputs.cache-hit != 'true' run: | - git clone https://boringssl.googlesource.com/boringssl + mkdir boringssl cd boringssl + git init + git remote add origin https://boringssl.googlesource.com/boringssl + git fetch origin --depth 1 ${{ env.BORINGSSL_VERSION }} git checkout ${{ env.BORINGSSL_VERSION }} mkdir build cd build cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON .. make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" + - name: Build aws-lc + if: steps.cache-awslc.outputs.cache-hit != 'true' + run: | + git clone --recursive --depth 1 -b "${AWSLC_VERSION}" https://github.com/aws/aws-lc + cd aws-lc + cmake -B build -DDISABLE_GO=ON + make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" -C build - name: Build nghttp3 if: steps.cache-nghttp3.outputs.cache-hit != 'true' run: | - git clone --depth 1 -b ${{ env.NGHTTP3_VERSION}} https://github.com/ngtcp2/nghttp3 + git clone --recursive --depth 1 -b ${{ env.NGHTTP3_VERSION}} https://github.com/ngtcp2/nghttp3 cd nghttp3 autoreconf -i ./configure --prefix=$PWD/build --enable-lib-only make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" check make install - - name: Build ngtcp2 + quictls/openssl v1.1.1 + - name: Build ngtcp2 + quictls/openssl v1.1.1 + BoringSSL if: steps.cache-ngtcp2-openssl1.outputs.cache-hit != 'true' run: | - git clone --depth 1 -b ${{ env.NGTCP2_VERSION }} https://github.com/ngtcp2/ngtcp2 ngtcp2-openssl1 + git clone --recursive --depth 1 -b ${{ env.NGTCP2_VERSION }} https://github.com/ngtcp2/ngtcp2 ngtcp2-openssl1 cd ngtcp2-openssl1 autoreconf -i ./configure --prefix=$PWD/build --enable-lib-only \ @@ -155,16 +178,16 @@ jobs: --with-boringssl make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" check make install - - name: Build ngtcp2 + quictls/openssl v3.x + - name: Build ngtcp2 + quictls/openssl v3.x + aws-lc if: steps.cache-ngtcp2-openssl3.outputs.cache-hit != 'true' run: | - git clone --depth 1 -b ${{ env.NGTCP2_VERSION }} https://github.com/ngtcp2/ngtcp2 ngtcp2-openssl3 + git clone --recursive --depth 1 -b ${{ env.NGTCP2_VERSION }} https://github.com/ngtcp2/ngtcp2 ngtcp2-openssl3 cd ngtcp2-openssl3 autoreconf -i ./configure --prefix=$PWD/build --enable-lib-only \ PKG_CONFIG_PATH="../openssl3/build/lib/pkgconfig" \ - BORINGSSL_CFLAGS="-I$PWD/../boringssl/include/" \ - BORINGSSL_LIBS="-L$PWD/../boringssl/build/ssl -lssl -L$PWD/../boringssl/build/crypto -lcrypto" \ + BORINGSSL_CFLAGS="-I$PWD/../aws-lc/include/" \ + BORINGSSL_LIBS="-L$PWD/../aws-lc/build/ssl -lssl -L$PWD/../aws-lc/build/crypto -lcrypto" \ --with-boringssl make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" check make install @@ -179,7 +202,7 @@ jobs: compiler: [gcc, clang] buildtool: [autotools, cmake] http3: [http3, no-http3] - openssl: [openssl1, openssl3, boringssl] + openssl: [openssl1, openssl3, boringssl, awslc] exclude: - os: macos-12 openssl: openssl3 @@ -196,24 +219,33 @@ jobs: buildtool: cmake - openssl: boringssl compiler: gcc + - os: macos-12 + openssl: awslc + - openssl: awslc + buildtool: cmake + - openssl: awslc + compiler: gcc runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive - name: Linux setup if: runner.os == 'Linux' run: | + sudo apt-get update sudo apt-get install \ g++-12 \ - clang-14 \ + clang-15 \ autoconf \ automake \ autotools-dev \ libtool \ pkg-config \ zlib1g-dev \ - libcunit1-dev \ libssl-dev \ libxml2-dev \ libev-dev \ @@ -222,10 +254,17 @@ jobs: libjemalloc-dev \ libc-ares-dev \ libelf-dev \ + libbrotli-dev \ cmake \ cmake-data echo 'CPPFLAGS=-fsanitize=address,undefined -fno-sanitize-recover=undefined -g' >> $GITHUB_ENV echo 'LDFLAGS=-fsanitize=address,undefined -fno-sanitize-recover=undefined' >> $GITHUB_ENV + + # https://github.com/actions/runner-images/issues/9491#issuecomment-1989718917 + # Asan in llvm 14 provided in ubuntu 22.04 is incompatible with + # high-entropy ASLR in much newer kernels that GitHub runners are + # using leading to random crashes: https://reviews.llvm.org/D148280 + sudo sysctl vm.mmap_rnd_bits=28 - name: MacOS setup if: runner.os == 'macOS' run: | @@ -233,8 +272,8 @@ jobs: libev \ libevent \ c-ares \ - cunit \ libressl \ + brotli \ autoconf \ automake \ pkg-config \ @@ -243,8 +282,8 @@ jobs: - name: Setup clang (Linux) if: runner.os == 'Linux' && matrix.compiler == 'clang' run: | - echo 'CC=clang-14' >> $GITHUB_ENV - echo 'CXX=clang++-14' >> $GITHUB_ENV + echo 'CC=clang-15' >> $GITHUB_ENV + echo 'CXX=clang++-15' >> $GITHUB_ENV - name: Setup clang (MacOS) if: runner.os == 'macOS' && matrix.compiler == 'clang' run: | @@ -261,7 +300,7 @@ jobs: echo 'CC=gcc' >> $GITHUB_ENV echo 'CXX=g++' >> $GITHUB_ENV - name: Restore libbpf cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && matrix.compiler == 'clang' && runner.os == 'Linux' with: path: libbpf/build @@ -278,21 +317,21 @@ jobs: echo 'EXTRA_AUTOTOOLS_OPTS='"$EXTRA_AUTOTOOLS_OPTS" >> $GITHUB_ENV echo 'EXTRA_CMAKE_OPTS='"$EXTRA_CMAKE_OPTS" >> $GITHUB_ENV - name: Restore quictls/openssl v1.1.1 cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && matrix.openssl == 'openssl1' with: path: openssl1/build key: ${{ runner.os }}-openssl-${{ env.OPENSSL1_VERSION }} fail-on-cache-miss: true - name: Restore quictls/openssl v3.x cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && matrix.openssl == 'openssl3' with: path: openssl3/build key: ${{ runner.os }}-openssl-${{ env.OPENSSL3_VERSION }} fail-on-cache-miss: true - name: Restore BoringSSL cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.openssl == 'boringssl' with: path: | @@ -301,11 +340,35 @@ jobs: boringssl/include key: ${{ runner.os }}-boringssl-${{ env.BORINGSSL_VERSION }} fail-on-cache-miss: true + - name: Restore aws-lc cache + uses: actions/cache/restore@v4 + if: matrix.openssl == 'awslc' + with: + path: | + aws-lc/build/crypto/libcrypto.a + aws-lc/build/ssl/libssl.a + aws-lc/include + key: ${{ runner.os }}-awslc-${{ env.AWSLC_VERSION }} + fail-on-cache-miss: true - name: Set BoringSSL variables if: matrix.openssl == 'boringssl' run: | cd boringssl + OPENSSL_CFLAGS="-I$PWD/include/" + OPENSSL_LIBS="-L$PWD/build/ssl -lssl -L$PWD/build/crypto -lcrypto -pthread" + EXTRA_AUTOTOOLS_OPTS="$EXTRA_AUTOTOOLS_OPTS --without-neverbleed --without-jemalloc --disable-examples" + + echo 'OPENSSL_CFLAGS='"$OPENSSL_CFLAGS" >> $GITHUB_ENV + echo 'OPENSSL_LIBS='"$OPENSSL_LIBS" >> $GITHUB_ENV + echo 'BORINGSSL_CFLAGS='"$OPENSSL_CFLAGS" >> $GITHUB_ENV + echo 'BORINGSSL_LIBS='"$OPENSSL_LIBS" >> $GITHUB_ENV + echo 'EXTRA_AUTOTOOLS_OPTS='"$EXTRA_AUTOTOOLS_OPTS" >> $GITHUB_ENV + - name: Set aws-lc variables + if: matrix.openssl == 'awslc' + run: | + cd aws-lc + OPENSSL_CFLAGS="-I$PWD/include/" OPENSSL_LIBS="-L$PWD/build/ssl -lssl -L$PWD/build/crypto -lcrypto -pthread" EXTRA_AUTOTOOLS_OPTS="$EXTRA_AUTOTOOLS_OPTS --without-neverbleed --without-jemalloc" @@ -316,22 +379,22 @@ jobs: echo 'BORINGSSL_LIBS='"$OPENSSL_LIBS" >> $GITHUB_ENV echo 'EXTRA_AUTOTOOLS_OPTS='"$EXTRA_AUTOTOOLS_OPTS" >> $GITHUB_ENV - name: Restore nghttp3 cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' with: path: nghttp3/build key: ${{ runner.os }}-nghttp3-${{ env.NGHTTP3_VERSION }} fail-on-cache-miss: true - - name: Restore ngtcp2 + quictls/openssl v1.1.1 cache - uses: actions/cache/restore@v3 + - name: Restore ngtcp2 + quictls/openssl v1.1.1 cache + BoringSSL + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && (matrix.openssl == 'openssl1' || matrix.openssl == 'boringssl') with: path: ngtcp2-openssl1/build key: ${{ runner.os }}-ngtcp2-${{ env.NGTCP2_VERSION }}-openssl-${{ env.OPENSSL1_VERSION }} fail-on-cache-miss: true - - name: Restore ngtcp2 + quictls/openssl v3.x cache - uses: actions/cache/restore@v3 - if: matrix.http3 == 'http3' && matrix.openssl == 'openssl3' + - name: Restore ngtcp2 + quictls/openssl v3.x cache + aws-lc + uses: actions/cache/restore@v4 + if: matrix.http3 == 'http3' && (matrix.openssl == 'openssl3' || matrix.openssl == 'awslc') with: path: ngtcp2-openssl3/build key: ${{ runner.os }}-ngtcp2-${{ env.NGTCP2_VERSION }}-openssl-${{ env.OPENSSL3_VERSION }} @@ -348,9 +411,6 @@ jobs: echo 'LDFLAGS='"$LDFLAGS" >> $GITHUB_ENV echo 'EXTRA_AUTOTOOLS_OPTS='"$EXTRA_AUTOTOOLS_OPTS" >> $GITHUB_ENV echo 'EXTRA_CMAKE_OPTS='"$EXTRA_CMAKE_OPTS" >> $GITHUB_ENV - - name: Setup git submodules - run: | - git submodule update --init - name: Configure autotools run: | autoreconf -i @@ -364,7 +424,7 @@ jobs: cd nghttp2-$VERSION echo 'NGHTTP2_CMAKE_DIR='"$PWD" >> $GITHUB_ENV - cmake -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DWITH_NEVERBLEED=1 -DENABLE_APP=1 $EXTRA_CMAKE_OPTS -DCPPFLAGS="$CPPFLAGS" -DLDFLAGS="$LDFLAGS" . + cmake -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DWITH_NEVERBLEED=1 -DENABLE_APP=1 $EXTRA_CMAKE_OPTS -DCPPFLAGS="$CPPFLAGS" -DLDFLAGS="$LDFLAGS" -DBUILD_STATIC_LIBS=ON -DBUILD_TESTING=ON . - name: Configure cmake (MacOS) if: matrix.buildtool == 'cmake' && runner.os == 'macOS' run: | @@ -377,24 +437,24 @@ jobs: # This fixes infamous 'stdio.h not found' error. echo 'SDKROOT='"$(xcrun --sdk macosx --show-sdk-path)" >> $GITHUB_ENV - cmake -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DENABLE_APP=1 $EXTRA_CMAKE_OPTS -DCPPFLAGS="$CPPFLAGS" -DLDFLAGS="$LDFLAGS" . + cmake -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DENABLE_APP=1 $EXTRA_CMAKE_OPTS -DCPPFLAGS="$CPPFLAGS" -DLDFLAGS="$LDFLAGS" -DBUILD_STATIC_LIBS=ON -DBUILD_TESTING=ON . - name: Build nghttp2 with autotools (Linux) if: matrix.buildtool == 'autotools' && runner.os == 'Linux' run: | make -j"$(nproc)" distcheck \ - DISTCHECK_CONFIGURE_FLAGS="--with-mruby --with-neverbleed --with-libev --enable-werror $EXTRA_AUTOTOOLS_OPTS CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" + DISTCHECK_CONFIGURE_FLAGS="--with-mruby --with-neverbleed --with-libev --with-libbrotlienc --with-libbrotlidec --enable-werror $EXTRA_AUTOTOOLS_OPTS CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" - name: Build nghttp2 with autotools (MacOS) if: matrix.buildtool == 'autotools' && runner.os == 'macOS' run: | make -j"$(sysctl -n hw.ncpu)" distcheck \ - DISTCHECK_CONFIGURE_FLAGS="--with-mruby --with-libev --enable-werror $EXTRA_AUTOTOOLS_OPTS CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" + DISTCHECK_CONFIGURE_FLAGS="--with-mruby --with-libev --with-libbrotlienc --with-libbrotlidec --enable-werror $EXTRA_AUTOTOOLS_OPTS CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" - name: Build nghttp2 with cmake if: matrix.buildtool == 'cmake' run: | cd $NGHTTP2_CMAKE_DIR make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" check - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 if: matrix.buildtool == 'cmake' with: go-version-file: go.mod @@ -404,7 +464,7 @@ jobs: if: matrix.buildtool == 'cmake' run: | cd $NGHTTP2_CMAKE_DIR/integration-tests - make itprep it + make it build-cross: strategy: @@ -417,7 +477,10 @@ jobs: HOST: ${{ matrix.host }} steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive - name: Linux setup run: | sudo dpkg --add-architecture i386 @@ -430,20 +493,11 @@ jobs: libtool \ pkg-config \ wine - - name: Build CUnit - run: | - curl -LO https://jaist.dl.sourceforge.net/project/cunit/CUnit/2.1-3/CUnit-2.1-3.tar.bz2 - tar xf CUnit-2.1-3.tar.bz2 - cd CUnit-2.1-3 - ./bootstrap - ./configure --disable-shared --host="$HOST" --prefix="$PWD/build" - make -j$(nproc) install - name: Configure autotools run: | autoreconf -i && \ - ./configure --enable-werror --enable-lib-only --with-cunit \ - --host="$HOST" PKG_CONFIG_PATH="$PWD/CUnit-2.1-3/build/lib/pkgconfig" \ - CFLAGS="-g -O2 -D_WIN32_WINNT=0x0600" + ./configure --enable-werror --enable-lib-only --host="$HOST" \ + CFLAGS="-g -O2 -D_WIN32_WINNT=0x0600" LIBS="-pthread" - name: Build nghttp2 run: | make -j$(nproc) @@ -451,6 +505,7 @@ jobs: - name: Run tests if: matrix.host == 'x86_64-w64-mingw32' run: | + export WINEPATH=/usr/x86_64-w64-mingw32/lib cd tests wine main.exe @@ -467,16 +522,84 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v4 - - uses: microsoft/setup-msbuild@v1 - - run: | - vcpkg --triplet=${{ matrix.arch }}-windows install cunit + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + - uses: microsoft/setup-msbuild@v2 - name: Configure cmake - run: | - mkdir build - cd build - cmake -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_GENERATOR_PLATFORM=${{ matrix.platform }} -DVCPKG_TARGET_TRIPLET=${{ matrix.arch}}-windows .. + run: cmake -B build -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_GENERATOR_PLATFORM=${{ matrix.platform }} -DVCPKG_TARGET_TRIPLET=${{ matrix.arch}}-windows -DBUILD_STATIC_LIBS=ON -DBUILD_TESTING=ON - name: Build nghttp2 run: | cmake --build build cmake --build build --target check + + release: + if: github.ref_type == 'tag' + + needs: + - build + - build-cross + - build-windows + + permissions: + contents: write + + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + - name: Make artifacts + run: | + ver='${{ github.ref_name }}' + + prev_ver=$(git tag --sort v:refname | grep -v -F "${ver}" | \ + grep 'v[0-9]\+\.[0-9]\+\.0' | tail -n1) + + echo -n "$GPG_KEY" | gpg --batch --pinentry-mode loopback --import + ./makerelease.sh "${ver}" "${prev_ver}" + env: + GPG_KEY: ${{ secrets.GPG_KEY }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + - name: Make release + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs') + + let ver = '${{ github.ref_name }}' + + let {data: release} = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: ver, + name: `nghttp2 ${ver}`, + draft: true, + generate_release_notes: true, + discussion_category_name: 'Announcements', + }) + + let v = ver.substring(1) + + let files = [ + 'checksums.txt', + `nghttp2-${v}.tar.bz2`, + `nghttp2-${v}.tar.bz2.asc`, + `nghttp2-${v}.tar.gz`, + `nghttp2-${v}.tar.gz.asc`, + `nghttp2-${v}.tar.xz`, + `nghttp2-${v}.tar.xz.asc`, + ] + + await Promise.all(files.map(elem => + github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.id, + name: elem, + data: fs.readFileSync(elem), + }) + )) diff --git a/yass/third_party/nghttp2/.github/workflows/docker.yaml b/yass/third_party/nghttp2/.github/workflows/docker.yaml new file mode 100644 index 0000000000..7945573237 --- /dev/null +++ b/yass/third_party/nghttp2/.github/workflows/docker.yaml @@ -0,0 +1,24 @@ +name: docker-build + +on: + push: + paths: + - docker/Dockerfile + branches: + - '**' + +permissions: read-all + +jobs: + build: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build + uses: docker/build-push-action@v5 + with: + context: docker + build-args: NGHTTP2_BRANCH=${{ github.ref_name }} diff --git a/yass/third_party/nghttp2/.github/workflows/fuzz.yml b/yass/third_party/nghttp2/.github/workflows/fuzz.yml index 326cf4627a..b4ced5b6fa 100644 --- a/yass/third_party/nghttp2/.github/workflows/fuzz.yml +++ b/yass/third_party/nghttp2/.github/workflows/fuzz.yml @@ -5,6 +5,13 @@ jobs: Fuzzing: runs-on: ubuntu-latest steps: + - name: LLVM workaround + run: | + # https://github.com/actions/runner-images/issues/9491#issuecomment-1989718917 + # Asan in llvm 14 provided in ubuntu 22.04 is incompatible with + # high-entropy ASLR in much newer kernels that GitHub runners are + # using leading to random crashes: https://reviews.llvm.org/D148280 + sudo sysctl vm.mmap_rnd_bits=28 - name: Build Fuzzers uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master with: @@ -17,7 +24,7 @@ jobs: fuzz-seconds: 600 dry-run: false - name: Upload Crash - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() with: name: artifacts diff --git a/yass/third_party/nghttp2/.github/workflows/stale.yaml b/yass/third_party/nghttp2/.github/workflows/stale.yaml new file mode 100644 index 0000000000..2c7841b20d --- /dev/null +++ b/yass/third_party/nghttp2/.github/workflows/stale.yaml @@ -0,0 +1,20 @@ +name: 'Close stale issues' + +on: + schedule: + - cron: '30 1 * * *' + +permissions: + issues: write + +jobs: + stale: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/stale@v9 + with: + stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.' + days-before-stale: 30 + days-before-close: 7 + exempt-all-milestones: true diff --git a/yass/third_party/nghttp2/.gitignore b/yass/third_party/nghttp2/.gitignore index 8c089da403..da25ded208 100644 --- a/yass/third_party/nghttp2/.gitignore +++ b/yass/third_party/nghttp2/.gitignore @@ -42,6 +42,7 @@ rules.ninja lib*.so lib*.so.* lib*.a + # generated by "make test" with cmake Testing/ @@ -54,3 +55,10 @@ _VC_ROOT/ .depend.MSVC *.pyd *.egg-info/ + +# Build Directories +build/ + +# IDEs +cmake-* +.idea/ diff --git a/yass/third_party/nghttp2/.gitmodules b/yass/third_party/nghttp2/.gitmodules index 393c80881d..fe2dd42120 100644 --- a/yass/third_party/nghttp2/.gitmodules +++ b/yass/third_party/nghttp2/.gitmodules @@ -5,3 +5,6 @@ path = third-party/neverbleed url = https://github.com/tatsuhiro-t/neverbleed.git branch = nghttp2 +[submodule "tests/munit"] + path = tests/munit + url = https://github.com/ngtcp2/munit diff --git a/yass/third_party/nghttp2/AUTHORS b/yass/third_party/nghttp2/AUTHORS index bb1ae74f12..de4be6d76f 100644 --- a/yass/third_party/nghttp2/AUTHORS +++ b/yass/third_party/nghttp2/AUTHORS @@ -29,10 +29,12 @@ Andy Davies Angus Gratton Anna Henningsen Ant Bryan +Anthony Alayo Asra Ali Benedikt Christoph Wolters Benjamin Peterson Bernard Spil +Bernhard Walle Brendan Heinonen Brian Card Brian Suh @@ -70,6 +72,8 @@ Jay Satiro Jeff 'Raid' Baitis Jianqing Wang Jim Morrison +Jiwoo Park +Jonas Kvinge Josh Braegger José F. Calcerrada Kamil Dudka @@ -110,6 +114,7 @@ Rudi Heitbaum Ryo Ota Scott Mitchell Sebastiaan Deckers +Sergey Fedorov Shelley Vohr Simon Frankenberger Simone Basso @@ -143,6 +148,7 @@ dalf dawg es fangdingjun +hrxi jwchoi kumagi lhuang04 diff --git a/yass/third_party/nghttp2/CMakeLists.txt b/yass/third_party/nghttp2/CMakeLists.txt index 7243d8086b..9b3c01b0e9 100644 --- a/yass/third_party/nghttp2/CMakeLists.txt +++ b/yass/third_party/nghttp2/CMakeLists.txt @@ -22,15 +22,15 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.14) # XXX using 1.8.90 instead of 1.9.0-DEV -project(nghttp2 VERSION 1.58.0) +project(nghttp2 VERSION 1.61.0) # See versioning rule: # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -set(LT_CURRENT 39) -set(LT_REVISION 1) -set(LT_AGE 25) +set(LT_CURRENT 42) +set(LT_REVISION 0) +set(LT_AGE 28) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) include(Version) @@ -52,6 +52,32 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) endif() include(GNUInstallDirs) +include(CMakeDependentOption) + +# Auto-detection of features that can be toggled +if(NOT ENABLE_LIB_ONLY) + find_package(Libev 4.11) + find_package(Libcares 1.7.5) + find_package(ZLIB 1.2.3) + find_package(Libbrotlienc 1.0.9) + find_package(Libbrotlidec 1.0.9) +endif() + +if (ENABLE_HPACK_TOOLS) + find_package(Systemd 209) + find_package(Jansson 2.5) +endif() +if (ENABLE_EXAMPLES) + # 2.0.8 is required because we use evconnlistener_set_error_cb() + find_package(Libevent 2.0.8 COMPONENTS core extra openssl) +endif() + +if (WITH_LIBXML2) + find_package(LibXml2 2.6.26) +endif() +if (WITH_JEMALLOC) + find_package(Jemalloc) +endif() include(CMakeOptions.txt) @@ -67,45 +93,26 @@ if(ENABLE_LIB_ONLY) set(ENABLE_EXAMPLES OFF) endif() -# For documentation -if (ENABLE_DOC) +if(ENABLE_DOC) + # For documentation find_package(Python3 COMPONENTS Interpreter) endif() -# Auto-detection of features that can be toggled if (ENABLE_APP) - find_package(OpenSSL 1.0.1 REQUIRED) - find_package(Libev 4.11 REQUIRED) - find_package(Libcares 1.7.5) - find_package(ZLIB 1.2.3 REQUIRED) - find_package(Libngtcp2 0.0.0) - find_package(Libngtcp2_crypto_quictls 0.0.0) + find_package(OpenSSL 1.1.1) + find_package(Libngtcp2 1.0.0) + find_package(Libngtcp2_crypto_quictls 1.0.0) if(LIBNGTCP2_CRYPTO_QUICTLS_FOUND) set(HAVE_LIBNGTCP2_CRYPTO_QUICTLS 1) endif() - find_package(Libnghttp3 0.0.0) -endif() -if(WITH_LIBBPF) - find_package(Libbpf 0.4.0) - if(NOT LIBBPF_FOUND) - message(FATAL_ERROR "libbpf was requested (WITH_LIBBPF=1) but not found.") + find_package(Libnghttp3 1.1.0) + if(WITH_LIBBPF) + find_package(Libbpf 0.7.0) + if(NOT LIBBPF_FOUND) + message(FATAL_ERROR "libbpf was requested (WITH_LIBBPF=1) but not found.") + endif() endif() endif() -if (ENABLE_HPACK_TOOLS) - find_package(Systemd 209) - find_package(Jansson 2.5 REQUIRED) -endif() -if (ENABLE_EXAMPLES) - # 2.0.8 is required because we use evconnlistener_set_error_cb() - find_package(Libevent 2.0.8 COMPONENTS core extra openssl REQUIRED) -endif() - -if (WITH_LIBXML2) - find_package(LibXml2 2.6.26 REQUIRED) -endif() -if (WITH_JEMALLOC) - find_package(Jemalloc REQUIRED) -endif() # Do not disable assertions based on CMAKE_BUILD_TYPE. foreach(_build_type "Release" "MinSizeRel" "RelWithDebInfo") @@ -166,13 +173,6 @@ endif() # XXX shouldn't ${CMAKE_DL_LIBS} be appended to OPENSSL_LIBRARIES instead of # APP_LIBRARIES if it is really specific to OpenSSL? -find_package(CUnit 2.1) -enable_testing() -set(HAVE_CUNIT ${CUNIT_FOUND}) -if(HAVE_CUNIT) - add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) -endif() - # openssl (for src) include(CheckSymbolExists) set(HAVE_OPENSSL ${OPENSSL_FOUND}) @@ -184,9 +184,11 @@ if(OPENSSL_FOUND) if(WIN32) set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}" "ws2_32" "bcrypt") endif() - check_symbol_exists(SSL_is_quic "openssl/ssl.h" HAVE_SSL_IS_QUIC) - if(NOT HAVE_SSL_IS_QUIC) - message(WARNING "OpenSSL in ${OPENSSL_LIBRARIES} does not have SSL_is_quic. HTTP/3 support cannot be enabled") + if(ENABLE_HTTP3) + check_symbol_exists(SSL_provide_quic_data "openssl/ssl.h" HAVE_SSL_PROVIDE_QUIC_DATA) + if(NOT HAVE_SSL_PROVIDE_QUIC_DATA) + message(WARNING "OpenSSL in ${OPENSSL_LIBRARIES} does not have SSL_provide_quic_data. HTTP/3 support cannot be enabled") + endif() endif() cmake_pop_check_state() else() @@ -223,6 +225,13 @@ endif() # jemalloc set(HAVE_JEMALLOC ${JEMALLOC_FOUND}) +# libbrotli (for src) +set(HAVE_LIBBROTLIENC ${LIBBROTLIENC_FOUND}) +set(HAVE_LIBBROTLIDEC ${LIBBROTLIDEC_FOUND}) +if(LIBBROTLIENC_FOUND AND LIBBROTLIDEC_FOUND) + set(HAVE_LIBBROTLI 1) +endif() + # libbpf (for bpf) set(HAVE_LIBBPF ${LIBBPF_FOUND}) if(LIBBPF_FOUND) @@ -244,7 +253,7 @@ endif() # HTTP/3 requires quictls/openssl, libngtcp2, libngtcp2_crypto_quictls # and libnghttp3. -if(ENABLE_HTTP3 AND NOT (HAVE_SSL_IS_QUIC AND LIBNGTCP2_FOUND AND LIBNGTCP2_CRYPTO_QUICTLS_FOUND AND LIBNGHTTP3_FOUND)) +if(ENABLE_HTTP3 AND NOT (HAVE_SSL_PROVIDE_QUIC_DATA AND LIBNGTCP2_FOUND AND LIBNGTCP2_CRYPTO_QUICTLS_FOUND AND LIBNGHTTP3_FOUND)) message(FATAL_ERROR "HTTP/3 was requested (ENABLE_HTTP3=1) but dependencies are not met.") endif() @@ -281,10 +290,9 @@ check_include_file("netinet/ip.h" HAVE_NETINET_IP_H) check_include_file("pwd.h" HAVE_PWD_H) check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) check_include_file("sys/time.h" HAVE_SYS_TIME_H) -check_include_file("sysinfoapi.h" HAVE_SYSINFOAPI_H) check_include_file("syslog.h" HAVE_SYSLOG_H) -check_include_file("time.h" HAVE_TIME_H) check_include_file("unistd.h" HAVE_UNISTD_H) +check_include_file("windows.h" HAVE_WINDOWS_H) include(CheckTypeSize) # Checks for typedefs, structures, and compiler characteristics. @@ -318,10 +326,6 @@ endif() include(CheckStructHasMember) check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF) -# Check size of pointer to decide we need 8 bytes alignment adjustment. -check_type_size("int *" SIZEOF_INT_P) -check_type_size("time_t" SIZEOF_TIME_T) - # Checks for library functions. include(CheckFunctionExists) check_function_exists(_Exit HAVE__EXIT) @@ -342,6 +346,8 @@ if(NOT HAVE_DECL_INITGROUPS AND HAVE_UNISTD_H) endif() endif() +check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_DECL_CLOCK_MONOTONIC) + set(WARNCFLAGS) set(WARNCXXFLAGS) if(CMAKE_C_COMPILER_ID MATCHES "MSVC") @@ -359,6 +365,15 @@ else() include(PickyWarningsCXX) endif() +if(ENABLE_STATIC_CRT) + foreach(lang C CXX) + foreach(suffix "" _DEBUG _MINSIZEREL _RELEASE _RELWITHDEBINFO) + set(var "CMAKE_${lang}_FLAGS${suffix}") + string(REPLACE "/MD" "/MT" ${var} "${${var}}") + endforeach() + endforeach() +endif() + if(ENABLE_DEBUG) set(DEBUGBUILD 1) endif() @@ -387,30 +402,26 @@ set(VERSION "${PACKAGE_VERSION}") # For init scripts and systemd service file (in contrib/) set(bindir "${CMAKE_INSTALL_FULL_BINDIR}") set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}") - -set(name lib/includes/nghttp2/nghttp2ver.h) -configure_file("${name}.in" "${name}" @ONLY) -if (NOT DISABLE_INSTALL) - foreach(name - lib/libnghttp2.pc - integration-tests/config.go - integration-tests/setenv - doc/conf.py - doc/index.rst - doc/package_README.rst - doc/tutorial-client.rst - doc/tutorial-server.rst - doc/tutorial-hpack.rst - doc/nghttpx-howto.rst - doc/h2load-howto.rst - doc/building-android-binary.rst - doc/nghttp2.h.rst - doc/nghttp2ver.h.rst - doc/contribute.rst - ) - configure_file("${name}.in" "${name}" @ONLY) - endforeach() -endif() +foreach(name + lib/libnghttp2.pc + lib/includes/nghttp2/nghttp2ver.h + integration-tests/config.go + integration-tests/setenv + doc/conf.py + doc/index.rst + doc/package_README.rst + doc/tutorial-client.rst + doc/tutorial-server.rst + doc/tutorial-hpack.rst + doc/nghttpx-howto.rst + doc/h2load-howto.rst + doc/building-android-binary.rst + doc/nghttp2.h.rst + doc/nghttp2ver.h.rst + doc/contribute.rst +) + configure_file("${name}.in" "${name}" @ONLY) +endforeach() if(APPLE) add_definitions(-D__APPLE_USE_RFC_3542) @@ -438,10 +449,14 @@ endif() if (ENABLE_EXAMPLES) add_subdirectory(examples) endif() -add_subdirectory(tests) -#add_subdirectory(tests/testdata) -add_subdirectory(integration-tests) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + add_subdirectory(tests) + #add_subdirectory(tests/testdata) + add_subdirectory(integration-tests) +endif() if(ENABLE_DOC) + # For documentation + find_package(Python3 COMPONENTS Interpreter) add_subdirectory(doc) endif() add_subdirectory(contrib) diff --git a/yass/third_party/nghttp2/CMakeOptions.txt b/yass/third_party/nghttp2/CMakeOptions.txt index 0b4bd90cf7..797bd29d51 100644 --- a/yass/third_party/nghttp2/CMakeOptions.txt +++ b/yass/third_party/nghttp2/CMakeOptions.txt @@ -8,11 +8,12 @@ option(ENABLE_HPACK_TOOLS "Build HPACK tools" OFF) option(ENABLE_EXAMPLES "Build examples" OFF) option(ENABLE_FAILMALLOC "Build failmalloc test program" ON) option(ENABLE_LIB_ONLY "Build libnghttp2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0 -DENABLE_HPACK_TOOLS=0") -option(ENABLE_STATIC_LIB "Build libnghttp2 in static mode also") -option(ENABLE_SHARED_LIB "Build libnghttp2 as a shared library" ON) +option(BUILD_SHARED_LIBS "Build libnghttp2 as a shared library" ON) +option(BUILD_STATIC_LIBS "Build libnghttp2 in static mode also" OFF) option(ENABLE_STATIC_CRT "Build libnghttp2 against the MS LIBCMT[d]") option(ENABLE_HTTP3 "Enable HTTP/3 support" OFF) option(ENABLE_DOC "Build documentation" ON) +cmake_dependent_option(BUILD_TESTING "Enable tests" ON "BUILD_STATIC_LIBS" OFF) option(WITH_LIBXML2 "Use libxml2" OFF) option(WITH_JEMALLOC "Use jemalloc" OFF) diff --git a/yass/third_party/nghttp2/Makefile.am b/yass/third_party/nghttp2/Makefile.am index 683b9896b0..684ac17fdc 100644 --- a/yass/third_party/nghttp2/Makefile.am +++ b/yass/third_party/nghttp2/Makefile.am @@ -35,7 +35,6 @@ EXTRA_DIST = nghttpx.conf.sample proxy.pac.sample android-config android-env \ cmake/ExtractValidFlags.cmake \ cmake/FindJemalloc.cmake \ cmake/FindLibev.cmake \ - cmake/FindCUnit.cmake \ cmake/Version.cmake \ cmake/FindLibevent.cmake \ cmake/FindJansson.cmake \ @@ -45,6 +44,8 @@ EXTRA_DIST = nghttpx.conf.sample proxy.pac.sample android-config android-env \ cmake/FindLibnghttp3.cmake \ cmake/FindLibngtcp2.cmake \ cmake/FindLibngtcp2_crypto_quictls.cmake \ + cmake/FindLibbrotlienc.cmake \ + cmake/FindLibbrotlidec.cmake \ cmake/PickyWarningsC.cmake \ cmake/PickyWarningsCXX.cmake diff --git a/yass/third_party/nghttp2/README.rst b/yass/third_party/nghttp2/README.rst index 1934341bff..fc81c03979 100644 --- a/yass/third_party/nghttp2/README.rst +++ b/yass/third_party/nghttp2/README.rst @@ -29,10 +29,10 @@ Public Test Server The following endpoints are available to try out our nghttp2 implementation. -* https://nghttp2.org/ (TLS + ALPN/NPN and HTTP/3) +* https://nghttp2.org/ (TLS + ALPN and HTTP/3) This endpoint supports ``h2``, ``h2-16``, ``h2-14``, and - ``http/1.1`` via ALPN/NPN and requires TLSv1.2 for HTTP/2 + ``http/1.1`` via ALPN and requires TLSv1.2 for HTTP/2 connection. It also supports HTTP/3. @@ -48,11 +48,6 @@ The following package is required to build the libnghttp2 library: * pkg-config >= 0.20 -To build and run the unit test programs, the following package is -required: - -* cunit >= 2.1 - To build the documentation, you need to install: * sphinx (http://sphinx-doc.org/) @@ -66,15 +61,12 @@ To build and run the application programs (``nghttp``, ``nghttpd``, ``nghttpx`` and ``h2load``) in the ``src`` directory, the following packages are required: -* OpenSSL >= 1.0.1 +* OpenSSL >= 1.1.1; or LibreSSL >= 3.8.1; or aws-lc >= 1.19.0; or + BoringSSL * libev >= 4.11 * zlib >= 1.2.3 * libc-ares >= 1.7.5 -ALPN support requires OpenSSL >= 1.0.2 (released 22 January 2015). -LibreSSL >= 2.2.0 can be used instead of OpenSSL, but OpenSSL has more -features than LibreSSL at the time of this writing. - To enable ``-a`` option (getting linked assets from the downloaded resource) in ``nghttp``, the following package is required: @@ -103,10 +95,15 @@ To mitigate heap fragmentation in long running server programs Alpine Linux currently does not support malloc replacement due to musl limitations. See details in issue `#762 `_. +For BoringSSL or aws-lc build, to enable :rfc:`8879` TLS Certificate +Compression in applications, the following library is required: + +* libbrotli-dev >= 1.0.9 + To enable mruby support for nghttpx, `mruby `_ is required. We need to build mruby with C++ ABI explicitly turned on, and probably need other -mrgems, mruby is manged by git submodule under third-party/mruby +mrgems, mruby is managed by git submodule under third-party/mruby directory. Currently, mruby support for nghttpx is disabled by default. To enable mruby support, use ``--with-mruby`` configure option. Note that at the time of this writing, libmruby-dev and mruby @@ -118,20 +115,21 @@ required: * bison nghttpx supports `neverbleed `_, -privilege separation engine for OpenSSL / LibreSSL. In short, it -minimizes the risk of private key leakage when serious bug like -Heartbleed is exploited. The neverbleed is disabled by default. To -enable it, use ``--with-neverbleed`` configure option. +privilege separation engine for OpenSSL. In short, it minimizes the +risk of private key leakage when serious bug like Heartbleed is +exploited. The neverbleed is disabled by default. To enable it, use +``--with-neverbleed`` configure option. To enable the experimental HTTP/3 support for h2load and nghttpx, the following libraries are required: * `OpenSSL with QUIC support `_; or + LibreSSL (does not support 0RTT); or aws-lc; or `BoringSSL `_ (commit - 6ca49385b168f47a50e7172d82a590b218f55e4d) -* `ngtcp2 `_ >= 1.0.0 -* `nghttp3 `_ >= 1.0.0 + fae0964b3d44e94ca2a2d21f86e61dabe683d130) +* `ngtcp2 `_ >= 1.4.0 +* `nghttp3 `_ >= 1.1.0 Use ``--enable-http3`` configure option to enable HTTP/3 feature for h2load and nghttpx. @@ -146,7 +144,7 @@ Use ``--with-libbpf`` configure option to build eBPF program. libelf-dev is needed to build libbpf. For Ubuntu 20.04, you can build libbpf from `the source code -`_. nghttpx +`_. nghttpx requires eBPF program for reloading its configuration and hot swapping its executable. @@ -207,7 +205,7 @@ required packages: sudo apt-get install g++ clang make binutils autoconf automake \ autotools-dev libtool pkg-config \ - zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev \ + zlib1g-dev libssl-dev libxml2-dev libev-dev \ libevent-dev libjansson-dev \ libc-ares-dev libjemalloc-dev libsystemd-dev \ ruby-dev bison libelf-dev @@ -339,23 +337,24 @@ connections alive during reload. The detailed steps to build HTTP/3 enabled h2load and nghttpx follow. -Build custom OpenSSL: +Build aws-lc: .. code-block:: text - $ git clone --depth 1 -b OpenSSL_1_1_1w+quic https://github.com/quictls/openssl - $ cd openssl - $ ./config --prefix=$PWD/build --openssldir=/etc/ssl - $ make -j$(nproc) - $ make install_sw + $ git clone --depth 1 -b v1.23.0 https://github.com/aws/aws-lc + $ cd aws-lc + $ cmake -B build -DDISABLE_GO=ON --install-prefix=$PWD/opt + $ make -j$(nproc) -C build + $ cmake --install build $ cd .. Build nghttp3: .. code-block:: text - $ git clone --depth 1 -b v1.0.0 https://github.com/ngtcp2/nghttp3 + $ git clone --depth 1 -b v1.2.0 https://github.com/ngtcp2/nghttp3 $ cd nghttp3 + $ git submodule update --init --depth 1 $ autoreconf -i $ ./configure --prefix=$PWD/build --enable-lib-only $ make -j$(nproc) @@ -366,11 +365,13 @@ Build ngtcp2: .. code-block:: text - $ git clone --depth 1 -b v1.0.1 https://github.com/ngtcp2/ngtcp2 + $ git clone --depth 1 -b v1.4.0 https://github.com/ngtcp2/ngtcp2 $ cd ngtcp2 + $ git submodule update --init --depth 1 $ autoreconf -i - $ ./configure --prefix=$PWD/build --enable-lib-only \ - PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig" + $ ./configure --prefix=$PWD/build --enable-lib-only --with-boringssl \ + BORINGSSL_CFLAGS="-I$PWD/../aws-lc/opt/include" \ + BORINGSSL_LIBS="-L$PWD/../aws-lc/opt/lib -lssl -lcrypto" $ make -j$(nproc) $ make install $ cd .. @@ -380,7 +381,7 @@ from source: .. code-block:: text - $ git clone --depth 1 -b v1.2.2 https://github.com/libbpf/libbpf + $ git clone --depth 1 -b v1.3.0 https://github.com/libbpf/libbpf $ cd libbpf $ PREFIX=$PWD/build make -C src install $ cd .. @@ -393,10 +394,10 @@ Build nghttp2: $ cd nghttp2 $ git submodule update --init $ autoreconf -i - $ ./configure --with-mruby --with-neverbleed --enable-http3 --with-libbpf \ - CC=clang-14 CXX=clang++-14 \ - PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \ - LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../openssl/build/lib -Wl,-rpath,$PWD/../libbpf/build/lib64" + $ ./configure --with-mruby --enable-http3 --with-libbpf \ + CC=clang-15 CXX=clang++-15 \ + PKG_CONFIG_PATH="$PWD/../aws-lc/opt/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \ + LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../aws-lc/opt/lib -Wl,-rpath,$PWD/../libbpf/build/lib64" $ make -j$(nproc) The eBPF program ``reuseport_kern.o`` should be found under bpf @@ -481,7 +482,7 @@ Previously nghttp2 library did not send client magic, which is first 24 bytes byte string of client connection preface, and client applications have to send it by themselves. Since v1.0.0, client magic is sent by library via first call of ``nghttp2_session_send()`` -or ``nghttp2_session_mem_send()``. +or ``nghttp2_session_mem_send2()``. The client applications which send client magic must remove the relevant code. @@ -539,7 +540,7 @@ nghttp - client +++++++++++++++ ``nghttp`` is a HTTP/2 client. It can connect to the HTTP/2 server -with prior knowledge, HTTP Upgrade and NPN/ALPN TLS extension. +with prior knowledge, HTTP Upgrade and ALPN TLS extension. It has verbose output mode for framing information. Here is sample output from ``nghttp`` client: @@ -765,8 +766,8 @@ nghttpd - server By default, it uses SSL/TLS connection. Use ``--no-tls`` option to disable it. -``nghttpd`` only accepts HTTP/2 connections via NPN/ALPN or direct -HTTP/2 connections. No HTTP Upgrade is supported. +``nghttpd`` only accepts HTTP/2 connections via ALPN or direct HTTP/2 +connections. No HTTP Upgrade is supported. The ``-p`` option allows users to configure server push. @@ -847,7 +848,7 @@ to know how to migrate from earlier releases. ``nghttpx`` implements `important performance-oriented features `_ in TLS, such as session IDs, session tickets (with automatic key rotation), OCSP -stapling, dynamic record sizing, ALPN/NPN, forward secrecy and HTTP/2. +stapling, dynamic record sizing, ALPN, forward secrecy and HTTP/2. ``nghttpx`` also offers the functionality to share session cache and ticket keys among multiple ``nghttpx`` instances via memcached. @@ -974,12 +975,15 @@ threads to avoid saturating a single core on client side. servers. If the experimental HTTP/3 is enabled, h2load can send requests to -HTTP/3 server. To do this, specify ``h3`` to ``--npn-list`` option +HTTP/3 server. To do this, specify ``h3`` to ``--alpn-list`` option like so: .. code-block:: text - $ h2load --npn-list h3 https://127.0.0.1:4433 + $ h2load --alpn-list h3 https://127.0.0.1:4433 + +For nghttp2 v1.58 or earlier, use ``--npn-list`` instead of +``--alpn-list``. HPACK tools ----------- @@ -1445,17 +1449,6 @@ See `Contribution Guidelines `_ for more details. -Reporting vulnerability ------------------------ - -If you find a vulnerability in our software, please send the email to -"tatsuhiro.t at gmail dot com" about its details instead of submitting -issues on github issue page. It is a standard practice not to -disclose vulnerability information publicly until a fixed version is -released, or mitigation is worked out. - -In the future, we may setup a dedicated mail address for this purpose. - Versioning ---------- diff --git a/yass/third_party/nghttp2/doc/sources/security.rst b/yass/third_party/nghttp2/SECURITY.md similarity index 50% rename from yass/third_party/nghttp2/doc/sources/security.rst rename to yass/third_party/nghttp2/SECURITY.md index 5a8fcd0796..b8328a5ec9 100644 --- a/yass/third_party/nghttp2/doc/sources/security.rst +++ b/yass/third_party/nghttp2/SECURITY.md @@ -1,16 +1,15 @@ -Security Process -================ +# Security Process -If you find a vulnerability in our software, please send the email to -"tatsuhiro.t at gmail dot com" about its details instead of submitting +If you find a vulnerability in our software, please report it via +GitHub "Private vulnerability reporting" feature at +https://github.com/nghttp2/nghttp2/security instead of submitting issues on github issue page. It is a standard practice not to disclose vulnerability information publicly until a fixed version is -released, or mitigation is worked out. In the future, we may setup a -dedicated mail address for this purpose. +released, or mitigation is worked out. If we identify that the reported issue is really a vulnerability, we -open a new security advisory draft using `GitHub security feature -`_ and discuss the +open a new security advisory draft using [GitHub security +feature](https://github.com/nghttp2/nghttp2/security) and discuss the mitigation and bug fixes there. The fixes are committed to the private repository. @@ -21,12 +20,11 @@ We make a new release with the fix at the same time when the vulnerability is disclosed to public. At least 7 days before the public disclosure date, we open a new issue -on `nghttp2 issue tracker -`_ which notifies that the -upcoming release will have a security fix. The ``SECURITY`` label is -attached to this kind of issue. The issue is not opened if a -vulnerability is already disclosed, and it is publicly known that -nghttp2 is affected by that. +on [nghttp2 issue tracker](https://github.com/nghttp2/nghttp2/issues) +which notifies that the upcoming release will have a security fix. +The `SECURITY` label is attached to this kind of issue. The issue is +not opened if a vulnerability is already disclosed, and it is publicly +known that nghttp2 is affected by that. Before few hours of new release, we merge the fixes to the master branch (and/or a release branch if necessary) and make a new release. diff --git a/yass/third_party/nghttp2/bpf/reuseport_kern.c b/yass/third_party/nghttp2/bpf/reuseport_kern.c index 74c08c5aae..e2c2184eca 100644 --- a/yass/third_party/nghttp2/bpf/reuseport_kern.c +++ b/yass/third_party/nghttp2/bpf/reuseport_kern.c @@ -42,11 +42,6 @@ License is Public Domain. Commit hash: 12e7744b4919e9d55de75b7ab566326a1c8e7a67 */ -#define AES_BLOCKLEN \ - 16 /* Block length in bytes - AES is 128b block \ - only */ - -#define AES_KEYLEN 16 /* Key length in bytes */ #define AES_keyExpSize 176 struct AES_ctx { @@ -57,7 +52,6 @@ struct AES_ctx { in AES. Value=4 */ #define Nb 4 -#define Nk 4 /* The number of 32 bit words in a key. */ #define Nr 10 /* The number of rounds in AES Cipher. */ /* state - array holding the intermediate results during @@ -68,31 +62,6 @@ typedef __u8 state_t[4][4]; read-only storage instead of RAM The numbers below can be computed dynamically trading ROM for RAM - This can be useful in (embedded) bootloader applications, where ROM is often limited. */ -static const __u8 sbox[256] = { - /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ - 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, - 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, - 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, - 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, - 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, - 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, - 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, - 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, - 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, - 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, - 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, - 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, - 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, - 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, - 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, - 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, - 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, - 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, - 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, - 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, - 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, - 0xb0, 0x54, 0xbb, 0x16}; - static const __u8 rsbox[256] = { 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, @@ -117,78 +86,6 @@ static const __u8 rsbox[256] = { 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d}; -/* The round constant word array, Rcon[i], contains the values given - by x to the power (i-1) being powers of x (x is denoted as {02}) in - the field GF(2^8) */ -static const __u8 Rcon[11] = {0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, - 0x20, 0x40, 0x80, 0x1b, 0x36}; - -#define getSBoxValue(num) (sbox[(num)]) - -/* This function produces Nb(Nr+1) round keys. The round keys are used - in each round to decrypt the states. */ -static void KeyExpansion(__u8 *RoundKey, const __u8 *Key) { - unsigned i, j, k; - __u8 tempa[4]; /* Used for the column/row operations */ - - /* The first round key is the key itself. */ - for (i = 0; i < Nk; ++i) { - RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; - RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; - RoundKey[(i * 4) + 2] = Key[(i * 4) + 2]; - RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; - } - - /* All other round keys are found from the previous round keys. */ - for (i = Nk; i < Nb * (Nr + 1); ++i) { - { - k = (i - 1) * 4; - tempa[0] = RoundKey[k + 0]; - tempa[1] = RoundKey[k + 1]; - tempa[2] = RoundKey[k + 2]; - tempa[3] = RoundKey[k + 3]; - } - - if (i % Nk == 0) { - /* This function shifts the 4 bytes in a word to the left once. - [a0,a1,a2,a3] becomes [a1,a2,a3,a0] */ - - /* Function RotWord() */ - { - const __u8 u8tmp = tempa[0]; - tempa[0] = tempa[1]; - tempa[1] = tempa[2]; - tempa[2] = tempa[3]; - tempa[3] = u8tmp; - } - - /* SubWord() is a function that takes a four-byte input word and - applies the S-box to each of the four bytes to produce an - output word. */ - - /* Function Subword() */ - { - tempa[0] = getSBoxValue(tempa[0]); - tempa[1] = getSBoxValue(tempa[1]); - tempa[2] = getSBoxValue(tempa[2]); - tempa[3] = getSBoxValue(tempa[3]); - } - - tempa[0] = tempa[0] ^ Rcon[i / Nk]; - } - j = i * 4; - k = (i - Nk) * 4; - RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; - RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; - RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; - RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3]; - } -} - -static void AES_init_ctx(struct AES_ctx *ctx, const __u8 *key) { - KeyExpansion(ctx->RoundKey, key); -} - /* This function adds the round key to state. The round key is added to the state by an XOR function. */ static void AddRoundKey(__u8 round, state_t *state, const __u8 *RoundKey) { @@ -428,7 +325,7 @@ struct { __uint(max_entries, 255); __type(key, __u64); __type(value, __u32); -} cid_prefix_map SEC(".maps"); +} worker_id_map SEC(".maps"); struct { __uint(type, BPF_MAP_TYPE_REUSEPORT_SOCKARRAY); @@ -439,11 +336,18 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); - __uint(max_entries, 3); + __uint(max_entries, 1); __type(key, __u32); __type(value, __u64); } sk_info SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, struct AES_ctx); +} aes_key SEC(".maps"); + typedef struct quic_hd { __u8 *dcid; __u32 dcidlen; @@ -451,11 +355,11 @@ typedef struct quic_hd { __u8 type; } quic_hd; -#define SV_DCIDLEN 20 +#define SV_DCIDLEN 17 #define MAX_DCIDLEN 20 #define MIN_DCIDLEN 8 -#define CID_PREFIXLEN 8 -#define CID_PREFIX_OFFSET 1 +#define WORKER_IDLEN 8 +#define WORKER_ID_OFFSET 1 enum { NGTCP2_PKT_INITIAL = 0x0, @@ -573,14 +477,39 @@ static __u32 sk_index_from_dcid(const quic_hd *qhd, SEC("sk_reuseport") int select_reuseport(struct sk_reuseport_md *reuse_md) { __u32 sk_index, *psk_index; - __u64 *pnum_socks, *pkey; - __u32 zero = 0, key_high_idx = 1, key_low_idx = 2; + __u64 *pnum_socks; + __u32 zero = 0; int rv; quic_hd qhd; __u8 qpktbuf[6 + MAX_DCIDLEN]; - struct AES_ctx aes_ctx; - __u8 key[AES_KEYLEN]; - __u8 *cid_prefix; + struct AES_ctx *aes_ctx; + __u8 *worker_id; + __u16 remote_port; + __u8 *data = reuse_md->data; + + /* Packets less than 22 bytes never be a valid QUIC packet. */ + if (reuse_md->len < sizeof(struct udphdr) + 22) { + return SK_DROP; + } + + if (reuse_md->data + sizeof(struct udphdr) > reuse_md->data_end) { + return SK_DROP; + } + + remote_port = (data[0] << 8) + data[1]; + + switch (remote_port) { + case 1900: + case 5353: + case 11211: + case 20800: + case 27015: + return SK_DROP; + default: + if (remote_port < 1024) { + return SK_DROP; + } + } if (bpf_skb_load_bytes(reuse_md, sizeof(struct udphdr), qpktbuf, sizeof(qpktbuf)) != 0) { @@ -592,35 +521,24 @@ int select_reuseport(struct sk_reuseport_md *reuse_md) { return SK_DROP; } - pkey = bpf_map_lookup_elem(&sk_info, &key_high_idx); - if (pkey == NULL) { + aes_ctx = bpf_map_lookup_elem(&aes_key, &zero); + if (aes_ctx == NULL) { return SK_DROP; } - __builtin_memcpy(key, pkey, sizeof(*pkey)); - - pkey = bpf_map_lookup_elem(&sk_info, &key_low_idx); - if (pkey == NULL) { - return SK_DROP; - } - - __builtin_memcpy(key + sizeof(*pkey), pkey, sizeof(*pkey)); - rv = parse_quic(&qhd, qpktbuf, qpktbuf + sizeof(qpktbuf)); if (rv != 0) { return SK_DROP; } - AES_init_ctx(&aes_ctx, key); - switch (qhd.type) { case NGTCP2_PKT_INITIAL: case NGTCP2_PKT_0RTT: if (qhd.dcidlen == SV_DCIDLEN) { - cid_prefix = qhd.dcid + CID_PREFIX_OFFSET; - AES_ECB_decrypt(&aes_ctx, cid_prefix); + worker_id = qhd.dcid + WORKER_ID_OFFSET; + AES_ECB_decrypt(aes_ctx, worker_id); - psk_index = bpf_map_lookup_elem(&cid_prefix_map, cid_prefix); + psk_index = bpf_map_lookup_elem(&worker_id_map, worker_id); if (psk_index != NULL) { sk_index = *psk_index; @@ -637,10 +555,10 @@ int select_reuseport(struct sk_reuseport_md *reuse_md) { return SK_DROP; } - cid_prefix = qhd.dcid + CID_PREFIX_OFFSET; - AES_ECB_decrypt(&aes_ctx, cid_prefix); + worker_id = qhd.dcid + WORKER_ID_OFFSET; + AES_ECB_decrypt(aes_ctx, worker_id); - psk_index = bpf_map_lookup_elem(&cid_prefix_map, cid_prefix); + psk_index = bpf_map_lookup_elem(&worker_id_map, worker_id); if (psk_index == NULL) { sk_index = sk_index_from_dcid(&qhd, reuse_md, *pnum_socks); diff --git a/yass/third_party/nghttp2/cmake/FindCUnit.cmake b/yass/third_party/nghttp2/cmake/FindCUnit.cmake deleted file mode 100644 index ada87c1653..0000000000 --- a/yass/third_party/nghttp2/cmake/FindCUnit.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# - Try to find cunit -# Once done this will define -# CUNIT_FOUND - System has cunit -# CUNIT_INCLUDE_DIRS - The cunit include directories -# CUNIT_LIBRARIES - The libraries needed to use cunit - -find_package(PkgConfig QUIET) -pkg_check_modules(PC_CUNIT QUIET cunit) - -find_path(CUNIT_INCLUDE_DIR - NAMES CUnit/CUnit.h - HINTS ${PC_CUNIT_INCLUDE_DIRS} -) -find_library(CUNIT_LIBRARY - NAMES cunit - HINTS ${PC_CUNIT_LIBRARY_DIRS} -) - -if(CUNIT_INCLUDE_DIR) - set(_version_regex "^#define[ \t]+CU_VERSION[ \t]+\"([^\"]+)\".*") - file(STRINGS "${CUNIT_INCLUDE_DIR}/CUnit/CUnit.h" - CUNIT_VERSION REGEX "${_version_regex}") - string(REGEX REPLACE "${_version_regex}" "\\1" - CUNIT_VERSION "${CUNIT_VERSION}") - unset(_version_regex) -endif() - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set CUNIT_FOUND to TRUE -# if all listed variables are TRUE and the requested version matches. -find_package_handle_standard_args(CUnit REQUIRED_VARS - CUNIT_LIBRARY CUNIT_INCLUDE_DIR - VERSION_VAR CUNIT_VERSION) - -if(CUNIT_FOUND) - set(CUNIT_LIBRARIES ${CUNIT_LIBRARY}) - set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR}) -endif() - -mark_as_advanced(CUNIT_INCLUDE_DIR CUNIT_LIBRARY) diff --git a/yass/third_party/nghttp2/cmake/FindLibbrotlidec.cmake b/yass/third_party/nghttp2/cmake/FindLibbrotlidec.cmake new file mode 100644 index 0000000000..59066c6401 --- /dev/null +++ b/yass/third_party/nghttp2/cmake/FindLibbrotlidec.cmake @@ -0,0 +1,36 @@ +# - Try to find libbrotlidec +# Once done this will define +# LIBBROTLIDEC_FOUND - System has libbrotlidec +# LIBBROTLIDEC_INCLUDE_DIRS - The libbrotlidec include directories +# LIBBROTLIDEC_LIBRARIES - The libraries needed to use libbrotlidec + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_LIBBROTLIDEC QUIET libbrotlidec) + +find_path(LIBBROTLIDEC_INCLUDE_DIR + NAMES brotli/decode.h + HINTS ${PC_LIBBROTLIDEC_INCLUDE_DIRS} +) +find_library(LIBBROTLIDEC_LIBRARY + NAMES brotlidec + HINTS ${PC_LIBBROTLIDEC_LIBRARY_DIRS} +) + +if(PC_LIBBROTLIDEC_FOUND) + set(LIBBROTLIDEC_VERSION ${PC_LIBBROTLIDEC_VERSION}) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBBROTLIDEC_FOUND +# to TRUE if all listed variables are TRUE and the requested version +# matches. +find_package_handle_standard_args(Libbrotlidec REQUIRED_VARS + LIBBROTLIDEC_LIBRARY LIBBROTLIDEC_INCLUDE_DIR + VERSION_VAR LIBBROTLIDEC_VERSION) + +if(LIBBROTLIDEC_FOUND) + set(LIBBROTLIDEC_LIBRARIES ${LIBBROTLIDEC_LIBRARY}) + set(LIBBROTLIDEC_INCLUDE_DIRS ${LIBBROTLIDEC_INCLUDE_DIR}) +endif() + +mark_as_advanced(LIBBROTLIDEC_INCLUDE_DIR LIBBROTLIDEC_LIBRARY) diff --git a/yass/third_party/nghttp2/cmake/FindLibbrotlienc.cmake b/yass/third_party/nghttp2/cmake/FindLibbrotlienc.cmake new file mode 100644 index 0000000000..acf63343cb --- /dev/null +++ b/yass/third_party/nghttp2/cmake/FindLibbrotlienc.cmake @@ -0,0 +1,36 @@ +# - Try to find libbrotlienc +# Once done this will define +# LIBBROTLIENC_FOUND - System has libbrotlienc +# LIBBROTLIENC_INCLUDE_DIRS - The libbrotlienc include directories +# LIBBROTLIENC_LIBRARIES - The libraries needed to use libbrotlienc + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_LIBBROTLIENC QUIET libbrotlienc) + +find_path(LIBBROTLIENC_INCLUDE_DIR + NAMES brotli/encode.h + HINTS ${PC_LIBBROTLIENC_INCLUDE_DIRS} +) +find_library(LIBBROTLIENC_LIBRARY + NAMES brotlienc + HINTS ${PC_LIBBROTLIENC_LIBRARY_DIRS} +) + +if(PC_LIBBROTLIENC_FOUND) + set(LIBBROTLIENC_VERSION ${PC_LIBBROTLIENC_VERSION}) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBBROTLIENC_FOUND +# to TRUE if all listed variables are TRUE and the requested version +# matches. +find_package_handle_standard_args(Libbrotlienc REQUIRED_VARS + LIBBROTLIENC_LIBRARY LIBBROTLIENC_INCLUDE_DIR + VERSION_VAR LIBBROTLIENC_VERSION) + +if(LIBBROTLIENC_FOUND) + set(LIBBROTLIENC_LIBRARIES ${LIBBROTLIENC_LIBRARY}) + set(LIBBROTLIENC_INCLUDE_DIRS ${LIBBROTLIENC_INCLUDE_DIR}) +endif() + +mark_as_advanced(LIBBROTLIENC_INCLUDE_DIR LIBBROTLIENC_LIBRARY) diff --git a/yass/third_party/nghttp2/cmake/PickyWarningsC.cmake b/yass/third_party/nghttp2/cmake/PickyWarningsC.cmake index 50eb789180..6a5ee27d04 100644 --- a/yass/third_party/nghttp2/cmake/PickyWarningsC.cmake +++ b/yass/third_party/nghttp2/cmake/PickyWarningsC.cmake @@ -85,7 +85,6 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MA -Wstrict-prototypes # clang 1.0 gcc 3.3 # -Wswitch-enum # clang 3.0 gcc 4.1 # Not used because this basically disallows default case -Wunreachable-code # clang 3.0 gcc 4.1 - -Wunused-macros # clang 3.0 gcc 4.1 -Wunused-parameter # clang 3.0 gcc 4.1 -Wvla # clang 2.8 gcc 4.3 ) diff --git a/yass/third_party/nghttp2/cmakeconfig.h.in b/yass/third_party/nghttp2/cmakeconfig.h.in index d93fed6a92..20916cae69 100644 --- a/yass/third_party/nghttp2/cmakeconfig.h.in +++ b/yass/third_party/nghttp2/cmakeconfig.h.in @@ -19,12 +19,6 @@ /* Define to 1 if you have `neverbleed` library. */ #cmakedefine HAVE_NEVERBLEED 1 -/* sizeof(int *) */ -#cmakedefine SIZEOF_INT_P @SIZEOF_INT_P@ - -/* sizeof(time_t) */ -#cmakedefine SIZEOF_TIME_T @SIZEOF_TIME_T@ - /* Define to 1 if you have the `_Exit` function. */ #cmakedefine HAVE__EXIT 1 @@ -43,6 +37,9 @@ /* Define to 1 if you have the `initgroups` function. */ #cmakedefine01 HAVE_DECL_INITGROUPS +/* Define to 1 if you have the `CLOCK_MONOTONIC` defined. */ +#cmakedefine01 HAVE_DECL_CLOCK_MONOTONIC + /* Define to 1 to enable debug output. */ #cmakedefine DEBUGBUILD 1 @@ -79,18 +76,15 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_TIME_H 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYSINFOAPI_H 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYSLOG_H 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_TIME_H 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_UNISTD_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WINDOWS_H 1 + /* Define to 1 if HTTP/3 is enabled. */ #cmakedefine ENABLE_HTTP3 1 @@ -105,3 +99,6 @@ /* Define to 1 if you have `libev` library. */ #cmakedefine HAVE_LIBEV 1 + +/* Define to 1 if you have `libbrotlienc` and `libbrotlidec` libraries. */ +#cmakedefine HAVE_LIBBROTLI 1 diff --git a/yass/third_party/nghttp2/configure.ac b/yass/third_party/nghttp2/configure.ac index ad9b316b5d..5f9fe43a8b 100644 --- a/yass/third_party/nghttp2/configure.ac +++ b/yass/third_party/nghttp2/configure.ac @@ -25,7 +25,7 @@ dnl Do not change user variables! dnl https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html AC_PREREQ(2.61) -AC_INIT([nghttp2], [1.58.0], [t-tujikawa@users.sourceforge.net]) +AC_INIT([nghttp2], [1.61.0], [t-tujikawa@users.sourceforge.net]) AC_CONFIG_AUX_DIR([.]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) @@ -38,15 +38,15 @@ AC_CANONICAL_BUILD AC_CANONICAL_HOST AC_CANONICAL_TARGET -AM_INIT_AUTOMAKE([subdir-objects]) +AM_INIT_AUTOMAKE([subdir-objects tar-pax]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) dnl See versioning rule: dnl https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -AC_SUBST(LT_CURRENT, 39) -AC_SUBST(LT_REVISION, 1) -AC_SUBST(LT_AGE, 25) +AC_SUBST(LT_CURRENT, 42) +AC_SUBST(LT_REVISION, 0) +AC_SUBST(LT_AGE, 28) major=`echo $PACKAGE_VERSION |cut -d. -f1 | sed -e "s/[^0-9]//g"` minor=`echo $PACKAGE_VERSION |cut -d. -f2 | sed -e "s/[^0-9]//g"` @@ -137,11 +137,6 @@ AC_ARG_WITH([libev], [Use libev [default=check]])], [request_libev=$withval], [request_libev=check]) -AC_ARG_WITH([cunit], - [AS_HELP_STRING([--with-cunit], - [Use cunit [default=check]])], - [request_cunit=$withval], [request_cunit=check]) - AC_ARG_WITH([jemalloc], [AS_HELP_STRING([--with-jemalloc], [Use jemalloc [default=check]])], @@ -177,6 +172,16 @@ AC_ARG_WITH([libbpf], [Use libbpf [default=no]])], [request_libbpf=$withval], [request_libbpf=no]) +AC_ARG_WITH([libbrotlienc], + [AS_HELP_STRING([--with-libbrotlienc], + [Use libbrotlienc [default=no]])], + [request_libbrotlienc=$withval], [request_libbrotlienc=no]) + +AC_ARG_WITH([libbrotlidec], + [AS_HELP_STRING([--with-libbrotlidec], + [Use libbrotlidec [default=no]])], + [request_libbrotlidec=$withval], [request_libbrotlidec=no]) + dnl Define variables AC_ARG_VAR([LIBEV_CFLAGS], [C compiler flags for libev, skipping any checks]) AC_ARG_VAR([LIBEV_LIBS], [linker flags for libev, skipping any checks]) @@ -377,43 +382,6 @@ case "${host_os}" in ;; esac -# cunit -have_cunit=no -if test "x${request_cunit}" != "xno"; then - PKG_CHECK_MODULES([CUNIT], [cunit >= 2.1], [have_cunit=yes], [have_cunit=no]) - # If pkg-config does not find cunit, check it using AC_CHECK_LIB. We - # do this because Debian (Ubuntu) lacks pkg-config file for cunit. - if test "x${have_cunit}" = "xno"; then - AC_MSG_WARN([${CUNIT_PKG_ERRORS}]) - AC_CHECK_LIB([cunit], [CU_initialize_registry], - [have_cunit=yes], [have_cunit=no]) - if test "x${have_cunit}" = "xyes"; then - CUNIT_LIBS="-lcunit" - CUNIT_CFLAGS="" - AC_SUBST([CUNIT_LIBS]) - AC_SUBST([CUNIT_CFLAGS]) - fi - fi - if test "x${have_cunit}" = "xyes"; then - # cunit in Mac OS X requires ncurses. Note that in Mac OS X, test - # program can be built without -lncurses, but it emits runtime - # error. - case "${build}" in - *-apple-darwin*) - CUNIT_LIBS="$CUNIT_LIBS -lncurses" - AC_SUBST([CUNIT_LIBS]) - ;; - esac - fi -fi - -if test "x${request_cunit}" = "xyes" && - test "x${have_cunit}" != "xyes"; then - AC_MSG_ERROR([cunit was requested (--with-cunit) but not found]) -fi - -AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ]) - # libev (for src) have_libev=no if test "x${request_libev}" != "xno"; then @@ -447,27 +415,30 @@ fi # openssl (for src) have_openssl=no if test "x${request_openssl}" != "xno"; then - PKG_CHECK_MODULES([OPENSSL], [openssl >= 1.0.1], + PKG_CHECK_MODULES([OPENSSL], [openssl >= 1.1.1], [have_openssl=yes], [have_openssl=no]) if test "x${have_openssl}" = "xno"; then AC_MSG_NOTICE($OPENSSL_PKG_ERRORS) else - save_CFLAGS="$CFLAGS" + # Use C++ compiler because boringssl needs C++ runtime. + AC_LANG_PUSH(C++) + + save_CXXFLAGS="$CXXFLAGS" save_LIBS="$LIBS" - CFLAGS="$OPENSSL_CFLAGS $CFLAGS" + CXXFLAGS="$OPENSSL_CFLAGS $CXXFLAGS" LIBS="$OPENSSL_LIBS $LIBS" - # quictls/openssl has SSL_is_quic. - have_ssl_is_quic=no - AC_MSG_CHECKING([for SSL_is_quic]) + # quictls/openssl has SSL_provide_quic_data. boringssl also has + # it. We will deal with it later. + have_ssl_provide_quic_data=no + AC_MSG_CHECKING([for SSL_provide_quic_data]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], [[ - SSL *ssl = NULL; - SSL_is_quic(ssl); + SSL_provide_quic_data(NULL, (ssl_encryption_level_t)0, NULL, 0); ]])], - [AC_MSG_RESULT([yes]); have_ssl_is_quic=yes], - [AC_MSG_RESULT([no]); have_ssl_is_quic=no]) + [AC_MSG_RESULT([yes]); have_ssl_provide_quic_data=yes], + [AC_MSG_RESULT([no]); have_ssl_provide_quic_data=no]) # boringssl has SSL_set_quic_early_data_context. AC_MSG_CHECKING([for SSL_set_quic_early_data_context]) @@ -480,8 +451,10 @@ if test "x${request_openssl}" != "xno"; then [AC_MSG_RESULT([yes]); have_boringssl_quic=yes], [AC_MSG_RESULT([no]); have_boringssl_quic=no]) - CFLAGS="$save_CFLAGS" + CXXFLAGS="$save_CXXFLAGS" LIBS="$save_LIBS" + + AC_LANG_POP() fi fi @@ -508,7 +481,7 @@ fi # ngtcp2 (for src) have_libngtcp2=no if test "x${request_libngtcp2}" != "xno"; then - PKG_CHECK_MODULES([LIBNGTCP2], [libngtcp2 >= 1.0.0], [have_libngtcp2=yes], + PKG_CHECK_MODULES([LIBNGTCP2], [libngtcp2 >= 1.4.0], [have_libngtcp2=yes], [have_libngtcp2=no]) if test "x${have_libngtcp2}" = "xno"; then AC_MSG_NOTICE($LIBNGTCP2_PKG_ERRORS) @@ -522,7 +495,8 @@ fi # ngtcp2_crypto_quictls (for src) have_libngtcp2_crypto_quictls=no -if test "x${have_ssl_is_quic}" = "xyes" && +if test "x${have_ssl_provide_quic_data}" = "xyes" && + test "x${have_boringssl_quic}" != "xyes" && test "x${request_libngtcp2}" != "xno"; then PKG_CHECK_MODULES([LIBNGTCP2_CRYPTO_QUICTLS], [libngtcp2_crypto_quictls >= 1.0.0], @@ -536,7 +510,8 @@ if test "x${have_ssl_is_quic}" = "xyes" && fi fi -if test "x${have_ssl_is_quic}" = "xyes" && +if test "x${have_ssl_provide_quic_data}" = "xyes" && + test "x${have_boringssl_quic}" != "xyes" && test "x${request_libngtcp2}" = "xyes" && test "x${have_libngtcp2_crypto_quictls}" != "xyes"; then AC_MSG_ERROR([libngtcp2_crypto_quictls was requested (--with-libngtcp2) but not found]) @@ -567,7 +542,7 @@ fi # nghttp3 (for src) have_libnghttp3=no if test "x${request_libnghttp3}" != "xno"; then - PKG_CHECK_MODULES([LIBNGHTTP3], [libnghttp3 >= 1.0.0], [have_libnghttp3=yes], + PKG_CHECK_MODULES([LIBNGHTTP3], [libnghttp3 >= 1.1.0], [have_libnghttp3=yes], [have_libnghttp3=no]) if test "x${have_libnghttp3}" = "xno"; then AC_MSG_NOTICE($LIBNGHTTP3_PKG_ERRORS) @@ -624,6 +599,47 @@ fi AM_CONDITIONAL([HAVE_LIBBPF], [ test "x${have_libbpf}" = "xyes" ]) +# libbrotlienc (for src) +have_libbrotlienc=no +if test "x${request_libbrotlienc}" != "xno"; then + PKG_CHECK_MODULES([LIBBROTLIENC], [libbrotlienc >= 1.0.9], + [have_libbrotlienc=yes], + [have_libbrotlienc=no]) + if test "x${have_libbrotlienc}" = "xno"; then + AC_MSG_NOTICE($LIBBROTLIENC_PKG_ERRORS) + fi +fi + +if test "x${request_libbrotlienc}" = "xyes" && + test "x${have_libbrotlienc}" != "xyes"; then + AC_MSG_ERROR([libbrotlienc was requested (--with-libbrotlienc) but not found]) +fi + +# libbrotlidec (for src) +have_libbrotlidec=no +if test "x${request_libbrotlidec}" != "xno"; then + PKG_CHECK_MODULES([LIBBROTLIDEC], [libbrotlidec >= 1.0.9], + [have_libbrotlidec=yes], + [have_libbrotlidec=no]) + if test "x${have_libbrotlidec}" = "xno"; then + AC_MSG_NOTICE($LIBBROTLIDEC_PKG_ERRORS) + fi +fi + +if test "x${request_libbrotlidec}" = "xyes" && + test "x${have_libbrotlidec}" != "xyes"; then + AC_MSG_ERROR([libbrotlidec was requested (--with-libbrotlidec) but not found]) +fi + +have_libbrotli=no +if test "x${have_libbrotlienc}" = "xyes" && + test "x${have_libbrotlidec}" = "xyes"; then + have_libbrotli=yes + + AC_DEFINE([HAVE_LIBBROTLI], [1], + [Define to 1 if you have `libbrotlienc` and `libbrotlidec` libraries.]) +fi + # libevent_openssl (for examples) # 2.0.8 is required because we use evconnlistener_set_error_cb() have_libevent_openssl=no @@ -752,8 +768,6 @@ AM_CONDITIONAL([ENABLE_APP], [ test "x${enable_app}" = "xyes" ]) # Check HTTP/3 support enable_http3=no if test "x${request_http3}" != "xno" && - (test "x${have_ssl_is_quic}" = "xyes" || - test "x${have_boringssl_quic}" = "xyes") && test "x${have_libngtcp2}" = "xyes" && (test "x${have_libngtcp2_crypto_quictls}" = "xyes" || test "x${have_libngtcp2_crypto_boringssl}" = "xyes") && @@ -855,10 +869,9 @@ AC_CHECK_HEADERS([ \ string.h \ sys/socket.h \ sys/time.h \ - sysinfoapi.h \ syslog.h \ - time.h \ unistd.h \ + windows.h \ ]) # Checks for typedefs, structures, and compiler characteristics. @@ -908,12 +921,6 @@ if test "x$have_struct_tm_tm_gmtoff" = "xyes"; then [Define to 1 if you have `struct tm.tm_gmtoff` member.]) fi -# Check size of pointer to decide we need 8 bytes alignment -# adjustment. -AC_CHECK_SIZEOF([int *]) - -AC_CHECK_SIZEOF([time_t]) - # Checks for library functions. # Don't check malloc, since it does not play nicely with C++ stdlib @@ -959,7 +966,7 @@ AC_CHECK_FUNC([timerfd_create], AC_MSG_CHECKING([checking for GetTickCount64]) AC_LINK_IFELSE([AC_LANG_PROGRAM( [[ -#include +#include ]], [[ GetTickCount64(); @@ -985,6 +992,10 @@ AC_CHECK_DECLS([initgroups], [], [], [[ #include ]]) +AC_CHECK_DECLS([CLOCK_MONOTONIC], [], [], [[ +#include +]]) + save_CFLAGS=$CFLAGS save_CXXFLAGS=$CXXFLAGS @@ -1158,7 +1169,6 @@ AC_MSG_NOTICE([summary of build options: Python: ${PYTHON} PYTHON_VERSION: ${PYTHON_VERSION} Test: - CUnit: ${have_cunit} (CFLAGS='${CUNIT_CFLAGS}' LIBS='${CUNIT_LIBS}') Failmalloc: ${enable_failmalloc} Libs: OpenSSL: ${have_openssl} (CFLAGS='${OPENSSL_CFLAGS}' LIBS='${OPENSSL_LIBS}') @@ -1175,6 +1185,8 @@ AC_MSG_NOTICE([summary of build options: Jemalloc: ${have_jemalloc} (CFLAGS='${JEMALLOC_CFLAGS}' LIBS='${JEMALLOC_LIBS}') Zlib: ${have_zlib} (CFLAGS='${ZLIB_CFLAGS}' LIBS='${ZLIB_LIBS}') Systemd: ${have_libsystemd} (CFLAGS='${SYSTEMD_CFLAGS}' LIBS='${SYSTEMD_LIBS}') + Libbrotlienc: ${have_libbrotlienc} (CFLAGS="${LIBBROTLIENC_CFLAGS}' LIBS='${LIBBROTLIENC_LIBS}') + Libbrotlidec: ${have_libbrotlidec} (CFLAGS="${LIBBROTLIDEC_CFLAGS}' LIBS='${LIBBROTLIDEC_LIBS}') Third-party: http-parser: ${enable_third_party} MRuby: ${have_mruby} (CFLAGS='${LIBMRUBY_CFLAGS}' LIBS='${LIBMRUBY_LIBS}') diff --git a/yass/third_party/nghttp2/doc/Makefile.am b/yass/third_party/nghttp2/doc/Makefile.am index 96f449ffe7..50d57b2217 100644 --- a/yass/third_party/nghttp2/doc/Makefile.am +++ b/yass/third_party/nghttp2/doc/Makefile.am @@ -33,6 +33,7 @@ APIDOCS= \ nghttp2_check_header_value_rfc9113.rst \ nghttp2_check_method.rst \ nghttp2_check_path.rst \ + nghttp2_extpri_parse_priority.rst \ nghttp2_hd_deflate_bound.rst \ nghttp2_hd_deflate_change_table_size.rst \ nghttp2_hd_deflate_del.rst \ @@ -41,7 +42,9 @@ APIDOCS= \ nghttp2_hd_deflate_get_num_table_entries.rst \ nghttp2_hd_deflate_get_table_entry.rst \ nghttp2_hd_deflate_hd.rst \ + nghttp2_hd_deflate_hd2.rst \ nghttp2_hd_deflate_hd_vec.rst \ + nghttp2_hd_deflate_hd_vec2.rst \ nghttp2_hd_deflate_new.rst \ nghttp2_hd_deflate_new2.rst \ nghttp2_hd_inflate_change_table_size.rst \ @@ -53,6 +56,7 @@ APIDOCS= \ nghttp2_hd_inflate_get_table_entry.rst \ nghttp2_hd_inflate_hd.rst \ nghttp2_hd_inflate_hd2.rst \ + nghttp2_hd_inflate_hd3.rst \ nghttp2_hd_inflate_new.rst \ nghttp2_hd_inflate_new2.rst \ nghttp2_http2_strerror.rst \ @@ -73,10 +77,12 @@ APIDOCS= \ nghttp2_option_set_peer_max_concurrent_streams.rst \ nghttp2_option_set_server_fallback_rfc7540_priorities.rst \ nghttp2_option_set_user_recv_extension_type.rst \ + nghttp2_option_set_max_continuations.rst \ nghttp2_option_set_max_outbound_ack.rst \ nghttp2_option_set_max_settings.rst \ nghttp2_option_set_stream_reset_rate_limit.rst \ nghttp2_pack_settings_payload.rst \ + nghttp2_pack_settings_payload2.rst \ nghttp2_priority_spec_check_default.rst \ nghttp2_priority_spec_default_init.rst \ nghttp2_priority_spec_init.rst \ @@ -85,10 +91,12 @@ APIDOCS= \ nghttp2_rcbuf_incref.rst \ nghttp2_rcbuf_is_static.rst \ nghttp2_select_next_protocol.rst \ + nghttp2_select_alpn.rst \ nghttp2_session_callbacks_del.rst \ nghttp2_session_callbacks_new.rst \ nghttp2_session_callbacks_set_before_frame_send_callback.rst \ nghttp2_session_callbacks_set_data_source_read_length_callback.rst \ + nghttp2_session_callbacks_set_data_source_read_length_callback2.rst \ nghttp2_session_callbacks_set_error_callback.rst \ nghttp2_session_callbacks_set_error_callback2.rst \ nghttp2_session_callbacks_set_on_begin_frame_callback.rst \ @@ -105,9 +113,13 @@ APIDOCS= \ nghttp2_session_callbacks_set_on_invalid_header_callback2.rst \ nghttp2_session_callbacks_set_on_stream_close_callback.rst \ nghttp2_session_callbacks_set_pack_extension_callback.rst \ + nghttp2_session_callbacks_set_pack_extension_callback2.rst \ nghttp2_session_callbacks_set_recv_callback.rst \ + nghttp2_session_callbacks_set_recv_callback2.rst \ nghttp2_session_callbacks_set_select_padding_callback.rst \ + nghttp2_session_callbacks_set_select_padding_callback2.rst \ nghttp2_session_callbacks_set_send_callback.rst \ + nghttp2_session_callbacks_set_send_callback2.rst \ nghttp2_session_callbacks_set_send_data_callback.rst \ nghttp2_session_callbacks_set_unpack_extension_callback.rst \ nghttp2_session_change_extpri_stream_priority.rst \ @@ -125,6 +137,7 @@ APIDOCS= \ nghttp2_session_find_stream.rst \ nghttp2_session_get_effective_local_window_size.rst \ nghttp2_session_get_effective_recv_data_length.rst \ + nghttp2_session_get_extpri_stream_priority.rst \ nghttp2_session_get_hd_deflate_dynamic_table_size.rst \ nghttp2_session_get_hd_inflate_dynamic_table_size.rst \ nghttp2_session_get_last_proc_stream_id.rst \ @@ -143,7 +156,9 @@ APIDOCS= \ nghttp2_session_get_stream_remote_window_size.rst \ nghttp2_session_get_stream_user_data.rst \ nghttp2_session_mem_recv.rst \ + nghttp2_session_mem_recv2.rst \ nghttp2_session_mem_send.rst \ + nghttp2_session_mem_send2.rst \ nghttp2_session_recv.rst \ nghttp2_session_resume_data.rst \ nghttp2_session_send.rst \ @@ -171,6 +186,7 @@ APIDOCS= \ nghttp2_strerror.rst \ nghttp2_submit_altsvc.rst \ nghttp2_submit_data.rst \ + nghttp2_submit_data2.rst \ nghttp2_submit_extension.rst \ nghttp2_submit_goaway.rst \ nghttp2_submit_headers.rst \ @@ -180,7 +196,9 @@ APIDOCS= \ nghttp2_submit_priority_update.rst \ nghttp2_submit_push_promise.rst \ nghttp2_submit_request.rst \ + nghttp2_submit_request2.rst \ nghttp2_submit_response.rst \ + nghttp2_submit_response2.rst \ nghttp2_submit_rst_stream.rst \ nghttp2_submit_settings.rst \ nghttp2_submit_shutdown_notice.rst \ @@ -209,7 +227,6 @@ EXTRA_DIST = \ sources/h2load-howto.rst \ sources/building-android-binary.rst \ sources/contribute.rst \ - sources/security.rst \ _exts/rubydomain/LICENSE.rubydomain \ _exts/rubydomain/__init__.py \ _exts/rubydomain/rubydomain.py \ diff --git a/yass/third_party/nghttp2/doc/README.rst b/yass/third_party/nghttp2/doc/README.rst index 549e5506ac..7d4809cdf5 100644 --- a/yass/third_party/nghttp2/doc/README.rst +++ b/yass/third_party/nghttp2/doc/README.rst @@ -68,7 +68,7 @@ The example follows:: * Callback function invoked when |session| wants to send data to * remote peer. */ - typedef ssize_t (*nghttp2_send_callback) + typedef nghttp2_ssize (*nghttp2_send_callback2) (nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data); diff --git a/yass/third_party/nghttp2/doc/bash_completion/h2load b/yass/third_party/nghttp2/doc/bash_completion/h2load index 80afe39188..e07d75327e 100644 --- a/yass/third_party/nghttp2/doc/bash_completion/h2load +++ b/yass/third_party/nghttp2/doc/bash_completion/h2load @@ -8,7 +8,7 @@ _h2load() _get_comp_words_by_ref cur prev case $cur in -*) - COMPREPLY=( $( compgen -W '--requests --clients --threads --input-file --max-concurrent-streams --max-frame-size --window-bits --connection-window-bits --header --ciphers --tls13-ciphers --no-tls-proto --data --rate --rate-period --duration --warm-up-time --connection-active-timeout --connection-inactivity-timeout --timing-script-file --base-uri --npn-list --h1 --header-table-size --encoder-header-table-size --log-file --qlog-file-base --connect-to --rps --groups --no-udp-gso --max-udp-payload-size --ktls --verbose --version --help ' -- "$cur" ) ) + COMPREPLY=( $( compgen -W '--requests --clients --threads --input-file --max-concurrent-streams --max-frame-size --window-bits --connection-window-bits --header --ciphers --tls13-ciphers --no-tls-proto --data --rate --rate-period --duration --warm-up-time --connection-active-timeout --connection-inactivity-timeout --timing-script-file --base-uri --alpn-list --h1 --header-table-size --encoder-header-table-size --log-file --qlog-file-base --connect-to --rps --groups --no-udp-gso --max-udp-payload-size --ktls --sni --verbose --version --help ' -- "$cur" ) ) ;; *) _filedir diff --git a/yass/third_party/nghttp2/doc/bash_completion/nghttpx b/yass/third_party/nghttp2/doc/bash_completion/nghttpx index 72dd590b31..782309cec8 100644 --- a/yass/third_party/nghttp2/doc/bash_completion/nghttpx +++ b/yass/third_party/nghttp2/doc/bash_completion/nghttpx @@ -8,7 +8,7 @@ _nghttpx() _get_comp_words_by_ref cur prev case $cur in -*) - COMPREPLY=( $( compgen -W '--backend --frontend --backlog --backend-address-family --backend-http-proxy-uri --workers --single-thread --read-rate --read-burst --write-rate --write-burst --worker-read-rate --worker-read-burst --worker-write-rate --worker-write-burst --worker-frontend-connections --backend-connections-per-host --backend-connections-per-frontend --rlimit-nofile --rlimit-memlock --backend-request-buffer --backend-response-buffer --fastopen --no-kqueue --frontend-http2-read-timeout --frontend-http3-read-timeout --frontend-read-timeout --frontend-write-timeout --frontend-keep-alive-timeout --stream-read-timeout --stream-write-timeout --backend-read-timeout --backend-write-timeout --backend-connect-timeout --backend-keep-alive-timeout --listener-disable-timeout --frontend-http2-setting-timeout --backend-http2-settings-timeout --backend-max-backoff --ciphers --tls13-ciphers --client-ciphers --tls13-client-ciphers --ecdh-curves --insecure --cacert --private-key-passwd-file --subcert --dh-param-file --npn-list --verify-client --verify-client-cacert --verify-client-tolerate-expired --client-private-key-file --client-cert-file --tls-min-proto-version --tls-max-proto-version --tls-ticket-key-file --tls-ticket-key-memcached --tls-ticket-key-memcached-address-family --tls-ticket-key-memcached-interval --tls-ticket-key-memcached-max-retry --tls-ticket-key-memcached-max-fail --tls-ticket-key-cipher --tls-ticket-key-memcached-cert-file --tls-ticket-key-memcached-private-key-file --fetch-ocsp-response-file --ocsp-update-interval --ocsp-startup --no-verify-ocsp --no-ocsp --tls-session-cache-memcached --tls-session-cache-memcached-address-family --tls-session-cache-memcached-cert-file --tls-session-cache-memcached-private-key-file --tls-dyn-rec-warmup-threshold --tls-dyn-rec-idle-timeout --no-http2-cipher-block-list --client-no-http2-cipher-block-list --tls-sct-dir --psk-secrets --client-psk-secrets --tls-no-postpone-early-data --tls-max-early-data --tls-ktls --frontend-http2-max-concurrent-streams --backend-http2-max-concurrent-streams --frontend-http2-window-size --frontend-http2-connection-window-size --backend-http2-window-size --backend-http2-connection-window-size --http2-no-cookie-crumbling --padding --no-server-push --frontend-http2-optimize-write-buffer-size --frontend-http2-optimize-window-size --frontend-http2-encoder-dynamic-table-size --frontend-http2-decoder-dynamic-table-size --backend-http2-encoder-dynamic-table-size --backend-http2-decoder-dynamic-table-size --http2-proxy --log-level --accesslog-file --accesslog-syslog --accesslog-format --accesslog-write-early --errorlog-file --errorlog-syslog --syslog-facility --add-x-forwarded-for --strip-incoming-x-forwarded-for --no-add-x-forwarded-proto --no-strip-incoming-x-forwarded-proto --add-forwarded --strip-incoming-forwarded --forwarded-by --forwarded-for --no-via --no-strip-incoming-early-data --no-location-rewrite --host-rewrite --altsvc --http2-altsvc --add-request-header --add-response-header --request-header-field-buffer --max-request-header-fields --response-header-field-buffer --max-response-header-fields --error-page --server-name --no-server-rewrite --redirect-https-port --require-http-scheme --api-max-request-body --dns-cache-timeout --dns-lookup-timeout --dns-max-try --frontend-max-requests --frontend-http2-dump-request-header --frontend-http2-dump-response-header --frontend-frame-debug --daemon --pid-file --user --single-process --max-worker-processes --worker-process-grace-shutdown-period --mruby-file --ignore-per-pattern-mruby-error --frontend-quic-idle-timeout --frontend-quic-debug-log --quic-bpf-program-file --frontend-quic-early-data --frontend-quic-qlog-dir --frontend-quic-require-token --frontend-quic-congestion-controller --frontend-quic-secret-file --quic-server-id --frontend-quic-initial-rtt --no-quic-bpf --frontend-http3-window-size --frontend-http3-connection-window-size --frontend-http3-max-window-size --frontend-http3-max-connection-window-size --frontend-http3-max-concurrent-streams --conf --include --version --help ' -- "$cur" ) ) + COMPREPLY=( $( compgen -W '--backend --frontend --backlog --backend-address-family --backend-http-proxy-uri --workers --single-thread --read-rate --read-burst --write-rate --write-burst --worker-read-rate --worker-read-burst --worker-write-rate --worker-write-burst --worker-frontend-connections --backend-connections-per-host --backend-connections-per-frontend --rlimit-nofile --rlimit-memlock --backend-request-buffer --backend-response-buffer --fastopen --no-kqueue --frontend-http2-idle-timeout --frontend-http3-idle-timeout --frontend-write-timeout --frontend-keep-alive-timeout --frontend-header-timeout --stream-read-timeout --stream-write-timeout --backend-read-timeout --backend-write-timeout --backend-connect-timeout --backend-keep-alive-timeout --listener-disable-timeout --frontend-http2-setting-timeout --backend-http2-settings-timeout --backend-max-backoff --ciphers --tls13-ciphers --client-ciphers --tls13-client-ciphers --ecdh-curves --insecure --cacert --private-key-passwd-file --subcert --dh-param-file --alpn-list --verify-client --verify-client-cacert --verify-client-tolerate-expired --client-private-key-file --client-cert-file --tls-min-proto-version --tls-max-proto-version --tls-ticket-key-file --tls-ticket-key-memcached --tls-ticket-key-memcached-address-family --tls-ticket-key-memcached-interval --tls-ticket-key-memcached-max-retry --tls-ticket-key-memcached-max-fail --tls-ticket-key-cipher --tls-ticket-key-memcached-cert-file --tls-ticket-key-memcached-private-key-file --fetch-ocsp-response-file --ocsp-update-interval --ocsp-startup --no-verify-ocsp --no-ocsp --tls-session-cache-memcached --tls-session-cache-memcached-address-family --tls-session-cache-memcached-cert-file --tls-session-cache-memcached-private-key-file --tls-dyn-rec-warmup-threshold --tls-dyn-rec-idle-timeout --no-http2-cipher-block-list --client-no-http2-cipher-block-list --tls-sct-dir --psk-secrets --client-psk-secrets --tls-no-postpone-early-data --tls-max-early-data --tls-ktls --frontend-http2-max-concurrent-streams --backend-http2-max-concurrent-streams --frontend-http2-window-size --frontend-http2-connection-window-size --backend-http2-window-size --backend-http2-connection-window-size --http2-no-cookie-crumbling --padding --no-server-push --frontend-http2-optimize-write-buffer-size --frontend-http2-optimize-window-size --frontend-http2-encoder-dynamic-table-size --frontend-http2-decoder-dynamic-table-size --backend-http2-encoder-dynamic-table-size --backend-http2-decoder-dynamic-table-size --http2-proxy --log-level --accesslog-file --accesslog-syslog --accesslog-format --accesslog-write-early --errorlog-file --errorlog-syslog --syslog-facility --add-x-forwarded-for --strip-incoming-x-forwarded-for --no-add-x-forwarded-proto --no-strip-incoming-x-forwarded-proto --add-forwarded --strip-incoming-forwarded --forwarded-by --forwarded-for --no-via --no-strip-incoming-early-data --no-location-rewrite --host-rewrite --altsvc --http2-altsvc --add-request-header --add-response-header --request-header-field-buffer --max-request-header-fields --response-header-field-buffer --max-response-header-fields --error-page --server-name --no-server-rewrite --redirect-https-port --require-http-scheme --api-max-request-body --dns-cache-timeout --dns-lookup-timeout --dns-max-try --frontend-max-requests --frontend-http2-dump-request-header --frontend-http2-dump-response-header --frontend-frame-debug --daemon --pid-file --user --single-process --max-worker-processes --worker-process-grace-shutdown-period --mruby-file --ignore-per-pattern-mruby-error --frontend-quic-idle-timeout --frontend-quic-debug-log --quic-bpf-program-file --frontend-quic-early-data --frontend-quic-qlog-dir --frontend-quic-require-token --frontend-quic-congestion-controller --frontend-quic-secret-file --quic-server-id --frontend-quic-initial-rtt --no-quic-bpf --frontend-http3-window-size --frontend-http3-connection-window-size --frontend-http3-max-window-size --frontend-http3-max-connection-window-size --frontend-http3-max-concurrent-streams --conf --include --version --help ' -- "$cur" ) ) ;; *) _filedir diff --git a/yass/third_party/nghttp2/doc/h2load.1 b/yass/third_party/nghttp2/doc/h2load.1 index 9f4cec51e2..79f6e8a3eb 100644 --- a/yass/third_party/nghttp2/doc/h2load.1 +++ b/yass/third_party/nghttp2/doc/h2load.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "H2LOAD" "1" "Oct 27, 2023" "1.58.0" "nghttp2" +.TH "H2LOAD" "1" "Apr 04, 2024" "1.61.0" "nghttp2" .SH NAME h2load \- HTTP/2 benchmarking tool .SH SYNOPSIS @@ -255,20 +255,19 @@ input files as usual. .UNINDENT .INDENT 0.0 .TP -.B \-\-npn\-list= +.B \-\-alpn\-list= Comma delimited list of ALPN protocol identifier sorted in the order of preference. That means most desirable -protocol comes first. This is used in both ALPN and -NPN. The parameter must be delimited by a single comma -only and any white spaces are treated as a part of -protocol string. +protocol comes first. The parameter must be delimited +by a single comma only and any white spaces are treated +as a part of protocol string. .sp Default: \fBh2,h2\-16,h2\-14,http/1.1\fP .UNINDENT .INDENT 0.0 .TP .B \-\-h1 -Short hand for \fI\%\-\-npn\-list\fP=http/1.1 +Short hand for \fI\%\-\-alpn\-list\fP=http/1.1 \fI\%\-\-no\-tls\-proto\fP=http/1.1, which effectively force http/1.1 for both http and https URI. .UNINDENT @@ -345,6 +344,12 @@ Enable ktls. .UNINDENT .INDENT 0.0 .TP +.B \-\-sni= +Send in TLS SNI, overriding the host name +specified in URI. +.UNINDENT +.INDENT 0.0 +.TP .B \-v, \-\-verbose Output debug information. .UNINDENT diff --git a/yass/third_party/nghttp2/doc/h2load.1.rst b/yass/third_party/nghttp2/doc/h2load.1.rst index 0f65849d68..d63a839244 100644 --- a/yass/third_party/nghttp2/doc/h2load.1.rst +++ b/yass/third_party/nghttp2/doc/h2load.1.rst @@ -213,20 +213,19 @@ OPTIONS the first URI appeared in the command line or inside input files as usual. -.. option:: --npn-list= +.. option:: --alpn-list= Comma delimited list of ALPN protocol identifier sorted in the order of preference. That means most desirable - protocol comes first. This is used in both ALPN and - NPN. The parameter must be delimited by a single comma - only and any white spaces are treated as a part of - protocol string. + protocol comes first. The parameter must be delimited + by a single comma only and any white spaces are treated + as a part of protocol string. Default: ``h2,h2-16,h2-14,http/1.1`` .. option:: --h1 - Short hand for :option:`--npn-list`\=http/1.1 + Short hand for :option:`--alpn-list`\=http/1.1 :option:`--no-tls-proto`\=http/1.1, which effectively force http/1.1 for both http and https URI. @@ -291,6 +290,11 @@ OPTIONS Enable ktls. +.. option:: --sni= + + Send in TLS SNI, overriding the host name + specified in URI. + .. option:: -v, --verbose Output debug information. diff --git a/yass/third_party/nghttp2/doc/nghttp.1 b/yass/third_party/nghttp2/doc/nghttp.1 index 4bf274fb87..0709cc9b8b 100644 --- a/yass/third_party/nghttp2/doc/nghttp.1 +++ b/yass/third_party/nghttp2/doc/nghttp.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "NGHTTP" "1" "Oct 27, 2023" "1.58.0" "nghttp2" +.TH "NGHTTP" "1" "Apr 04, 2024" "1.61.0" "nghttp2" .SH NAME nghttp \- HTTP/2 client .SH SYNOPSIS diff --git a/yass/third_party/nghttp2/doc/nghttpd.1 b/yass/third_party/nghttp2/doc/nghttpd.1 index 232757da1b..57a46f2f18 100644 --- a/yass/third_party/nghttp2/doc/nghttpd.1 +++ b/yass/third_party/nghttp2/doc/nghttpd.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "NGHTTPD" "1" "Oct 27, 2023" "1.58.0" "nghttp2" +.TH "NGHTTPD" "1" "Apr 04, 2024" "1.61.0" "nghttp2" .SH NAME nghttpd \- HTTP/2 server .SH SYNOPSIS diff --git a/yass/third_party/nghttp2/doc/nghttpx.1 b/yass/third_party/nghttp2/doc/nghttpx.1 index 1aaa47e60d..6b9f54ba62 100644 --- a/yass/third_party/nghttp2/doc/nghttpx.1 +++ b/yass/third_party/nghttp2/doc/nghttpx.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "NGHTTPX" "1" "Oct 27, 2023" "1.58.0" "nghttp2" +.TH "NGHTTPX" "1" "Apr 04, 2024" "1.61.0" "nghttp2" .SH NAME nghttpx \- HTTP/2 proxy .SH SYNOPSIS @@ -555,27 +555,24 @@ this option will be simply ignored. .SS Timeout .INDENT 0.0 .TP -.B \-\-frontend\-http2\-read\-timeout= -Specify read timeout for HTTP/2 frontend connection. +.B \-\-frontend\-http2\-idle\-timeout= +Specify idle timeout for HTTP/2 frontend connection. If +no active streams exist for this duration, connection is +closed. .sp Default: \fB3m\fP .UNINDENT .INDENT 0.0 .TP -.B \-\-frontend\-http3\-read\-timeout= -Specify read timeout for HTTP/3 frontend connection. +.B \-\-frontend\-http3\-idle\-timeout= +Specify idle timeout for HTTP/3 frontend connection. If +no active streams exist for this duration, connection is +closed. .sp Default: \fB3m\fP .UNINDENT .INDENT 0.0 .TP -.B \-\-frontend\-read\-timeout= -Specify read timeout for HTTP/1.1 frontend connection. -.sp -Default: \fB1m\fP -.UNINDENT -.INDENT 0.0 -.TP .B \-\-frontend\-write\-timeout= Specify write timeout for all frontend connections. .sp @@ -591,6 +588,17 @@ Default: \fB1m\fP .UNINDENT .INDENT 0.0 .TP +.B \-\-frontend\-header\-timeout= +Specify duration that the server waits for an HTTP +request header fields to be received completely. On +timeout, HTTP/1 and HTTP/2 connections are closed. For +HTTP/3, the stream is shutdown, and the connection +itself is left intact. +.sp +Default: \fB1m\fP +.UNINDENT +.INDENT 0.0 +.TP .B \-\-stream\-read\-timeout= Specify read timeout for HTTP/2 streams. 0 means no timeout. @@ -783,13 +791,12 @@ available. .UNINDENT .INDENT 0.0 .TP -.B \-\-npn\-list= +.B \-\-alpn\-list= Comma delimited list of ALPN protocol identifier sorted in the order of preference. That means most desirable -protocol comes first. This is used in both ALPN and -NPN. The parameter must be delimited by a single comma -only and any white spaces are treated as a part of -protocol string. +protocol comes first. The parameter must be delimited +by a single comma only and any white spaces are treated +as a part of protocol string. .sp Default: \fBh2,h2\-16,h2\-14,http/1.1\fP .UNINDENT @@ -1847,12 +1854,12 @@ as QUIC keying materials. It is used to derive keys for encrypting tokens and Connection IDs. It is not used to encrypt QUIC packets. Each line of this file must contain exactly 136 bytes hex\-encoded string (when -decoded the byte string is 68 bytes long). The first 2 +decoded the byte string is 68 bytes long). The first 3 bits of decoded byte string are used to identify the keying material. An empty line or a line which starts \(aq#\(aq is ignored. The file can contain more than one -keying materials. Because the identifier is 2 bits, at -most 4 keying materials are read and the remaining data +keying materials. Because the identifier is 3 bits, at +most 8 keying materials are read and the remaining data is discarded. The first keying material in the file is primarily used for encryption and decryption for new connection. The other ones are used to decrypt data for diff --git a/yass/third_party/nghttp2/doc/nghttpx.1.rst b/yass/third_party/nghttp2/doc/nghttpx.1.rst index b70b163233..cee23f2a11 100644 --- a/yass/third_party/nghttp2/doc/nghttpx.1.rst +++ b/yass/third_party/nghttp2/doc/nghttpx.1.rst @@ -522,24 +522,22 @@ Performance Timeout ~~~~~~~ -.. option:: --frontend-http2-read-timeout= +.. option:: --frontend-http2-idle-timeout= - Specify read timeout for HTTP/2 frontend connection. + Specify idle timeout for HTTP/2 frontend connection. If + no active streams exist for this duration, connection is + closed. Default: ``3m`` -.. option:: --frontend-http3-read-timeout= +.. option:: --frontend-http3-idle-timeout= - Specify read timeout for HTTP/3 frontend connection. + Specify idle timeout for HTTP/3 frontend connection. If + no active streams exist for this duration, connection is + closed. Default: ``3m`` -.. option:: --frontend-read-timeout= - - Specify read timeout for HTTP/1.1 frontend connection. - - Default: ``1m`` - .. option:: --frontend-write-timeout= Specify write timeout for all frontend connections. @@ -553,6 +551,16 @@ Timeout Default: ``1m`` +.. option:: --frontend-header-timeout= + + Specify duration that the server waits for an HTTP + request header fields to be received completely. On + timeout, HTTP/1 and HTTP/2 connections are closed. For + HTTP/3, the stream is shutdown, and the connection + itself is left intact. + + Default: ``1m`` + .. option:: --stream-read-timeout= Specify read timeout for HTTP/2 streams. 0 means no @@ -728,14 +736,13 @@ SSL/TLS Without this option, DHE cipher suites are not available. -.. option:: --npn-list= +.. option:: --alpn-list= Comma delimited list of ALPN protocol identifier sorted in the order of preference. That means most desirable - protocol comes first. This is used in both ALPN and - NPN. The parameter must be delimited by a single comma - only and any white spaces are treated as a part of - protocol string. + protocol comes first. The parameter must be delimited + by a single comma only and any white spaces are treated + as a part of protocol string. Default: ``h2,h2-16,h2-14,http/1.1`` @@ -1687,12 +1694,12 @@ HTTP/3 and QUIC encrypting tokens and Connection IDs. It is not used to encrypt QUIC packets. Each line of this file must contain exactly 136 bytes hex-encoded string (when - decoded the byte string is 68 bytes long). The first 2 + decoded the byte string is 68 bytes long). The first 3 bits of decoded byte string are used to identify the keying material. An empty line or a line which starts '#' is ignored. The file can contain more than one - keying materials. Because the identifier is 2 bits, at - most 4 keying materials are read and the remaining data + keying materials. Because the identifier is 3 bits, at + most 8 keying materials are read and the remaining data is discarded. The first keying material in the file is primarily used for encryption and decryption for new connection. The other ones are used to decrypt data for diff --git a/yass/third_party/nghttp2/doc/programmers-guide.rst b/yass/third_party/nghttp2/doc/programmers-guide.rst index 820cd20495..4bf5e288b5 100644 --- a/yass/third_party/nghttp2/doc/programmers-guide.rst +++ b/yass/third_party/nghttp2/doc/programmers-guide.rst @@ -40,28 +40,28 @@ most event-based architecture applications use is single thread per core, and handling one connection I/O is done by single thread. To feed input to :type:`nghttp2_session` object, one can use -`nghttp2_session_recv()` or `nghttp2_session_mem_recv()` functions. +`nghttp2_session_recv()` or `nghttp2_session_mem_recv2()` functions. They behave similarly, and the difference is that `nghttp2_session_recv()` will use :type:`nghttp2_read_callback` to get -input. On the other hand, `nghttp2_session_mem_recv()` will take -input as its parameter. If in doubt, use `nghttp2_session_mem_recv()` -since it is simpler, and could be faster since it avoids calling -callback function. +input. On the other hand, `nghttp2_session_mem_recv2()` will take +input as its parameter. If in doubt, use +`nghttp2_session_mem_recv2()` since it is simpler, and could be faster +since it avoids calling callback function. To get output from :type:`nghttp2_session` object, one can use -`nghttp2_session_send()` or `nghttp2_session_mem_send()`. The +`nghttp2_session_send()` or `nghttp2_session_mem_send2()`. The difference between them is that the former uses :type:`nghttp2_send_callback` to pass output to an application. On the other hand, the latter returns the output to the caller. If in -doubt, use `nghttp2_session_mem_send()` since it is simpler. But +doubt, use `nghttp2_session_mem_send2()` since it is simpler. But `nghttp2_session_send()` might be easier to use if the output buffer an application has is fixed sized. -In general, an application should call `nghttp2_session_mem_send()` +In general, an application should call `nghttp2_session_mem_send2()` when it gets input from underlying connection. Since there is great chance to get something pushed into transmission queue while the call -of `nghttp2_session_mem_send()`, it is recommended to call -`nghttp2_session_mem_recv()` after `nghttp2_session_mem_send()`. +of `nghttp2_session_mem_send2()`, it is recommended to call +`nghttp2_session_mem_recv2()` after `nghttp2_session_mem_send2()`. There is a question when we are safe to close HTTP/2 session without waiting for the closure of underlying connection. We offer 2 API @@ -70,7 +70,7 @@ calls for this: `nghttp2_session_want_read()` and can destroy :type:`nghttp2_session`, and then close the underlying connection. But make sure that the buffered output has been transmitted to the peer before closing the connection when -`nghttp2_session_mem_send()` is used, since +`nghttp2_session_mem_send2()` is used, since `nghttp2_session_want_write()` does not take into account the transmission of the buffered data outside of :type:`nghttp2_session`. @@ -87,18 +87,18 @@ The header files are also available online: :doc:`nghttp2.h` and Remarks ------- -Do not call `nghttp2_session_send()`, `nghttp2_session_mem_send()`, -`nghttp2_session_recv()` or `nghttp2_session_mem_recv()` from the +Do not call `nghttp2_session_send()`, `nghttp2_session_mem_send2()`, +`nghttp2_session_recv()` or `nghttp2_session_mem_recv2()` from the nghttp2 callback functions directly or indirectly. It will lead to the crash. You can submit requests or frames in the callbacks then call these functions outside the callbacks. -`nghttp2_session_send()` and `nghttp2_session_mem_send()` send first +`nghttp2_session_send()` and `nghttp2_session_mem_send2()` send first 24 bytes of client magic string (MAGIC) (:macro:`NGHTTP2_CLIENT_MAGIC`) on client configuration. The applications are responsible to send SETTINGS frame as part of connection preface using `nghttp2_submit_settings()`. Similarly, -`nghttp2_session_recv()` and `nghttp2_session_mem_recv()` consume +`nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` consume MAGIC on server configuration unless `nghttp2_option_set_no_recv_client_magic()` is used with nonzero option value. @@ -222,7 +222,7 @@ above, the following code does not work: .. code-block:: c - nghttp2_submit_response(...) + nghttp2_submit_response2(...) nghttp2_submit_rst_stream(...) RST_STREAM cancels HEADERS (and DATA), and just RST_STREAM is sent. @@ -258,9 +258,9 @@ For example, we will illustrate how to send `ALTSVC const char *field; } alt_svc; - ssize_t pack_extension_callback(nghttp2_session *session, uint8_t *buf, - size_t len, const nghttp2_frame *frame, - void *user_data) { + nghttp2_ssize pack_extension_callback(nghttp2_session *session, uint8_t *buf, + size_t len, const nghttp2_frame *frame, + void *user_data) { const alt_svc *altsvc = (const alt_svc *)frame->ext.payload; size_t originlen = strlen(altsvc->origin); size_t fieldlen = strlen(altsvc->field); @@ -497,8 +497,8 @@ order to receive and process PRIORITY_UPDATE frame, server has to call NGHTTP2_PRIORITY_UPDATE)`` (see the above section), and pass the option to `nghttp2_session_server_new2()` or `nghttp2_session_server_new3()` to create a server session. Client -can send Priority header field via `nghttp2_submit_request()`. It can -also send PRIORITY_UPDATE frame via +can send Priority header field via `nghttp2_submit_request2()`. It +can also send PRIORITY_UPDATE frame via `nghttp2_submit_priority_update()`. Server processes Priority header field in a request header field and updates the stream priority unless HTTP messaging rule enforcement is disabled (see diff --git a/yass/third_party/nghttp2/doc/security.rst b/yass/third_party/nghttp2/doc/security.rst deleted file mode 100644 index 00b0c9cb05..0000000000 --- a/yass/third_party/nghttp2/doc/security.rst +++ /dev/null @@ -1 +0,0 @@ -.. include:: ../doc/sources/security.rst diff --git a/yass/third_party/nghttp2/docker/Dockerfile b/yass/third_party/nghttp2/docker/Dockerfile index e7b549675f..cdec4eecf6 100644 --- a/yass/third_party/nghttp2/docker/Dockerfile +++ b/yass/third_party/nghttp2/docker/Dockerfile @@ -1,21 +1,23 @@ FROM debian:12 as build +ARG NGHTTP2_BRANCH=master + RUN apt-get update && \ - apt-get install -y --no-install-recommends \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ git clang make binutils autoconf automake autotools-dev libtool \ - pkg-config \ + pkg-config cmake cmake-data \ zlib1g-dev libev-dev libjemalloc-dev ruby-dev libc-ares-dev bison \ - libelf-dev + libelf-dev libbrotli-dev -RUN git clone --depth 1 -b OpenSSL_1_1_1w+quic https://github.com/quictls/openssl && \ - cd openssl && \ - ./config --openssldir=/etc/ssl && \ - make -j$(nproc) && \ - make install_sw && \ +RUN git clone --recursive --depth 1 -b v1.23.0 https://github.com/aws/aws-lc && \ + cd aws-lc && \ + cmake -B build -DDISABLE_GO=ON && \ + make -j$(nproc) -C build && \ + cmake --install build && \ cd .. && \ - rm -rf openssl + rm -rf aws-lc -RUN git clone --depth 1 -b v1.0.0 https://github.com/ngtcp2/nghttp3 && \ +RUN git clone --recursive --depth 1 -b v1.2.0 https://github.com/ngtcp2/nghttp3 && \ cd nghttp3 && \ autoreconf -i && \ ./configure --enable-lib-only && \ @@ -24,55 +26,57 @@ RUN git clone --depth 1 -b v1.0.0 https://github.com/ngtcp2/nghttp3 && \ cd .. && \ rm -rf nghttp3 -RUN git clone --depth 1 -b v1.0.1 https://github.com/ngtcp2/ngtcp2 && \ +RUN git clone --recursive --depth 1 -b v1.4.0 https://github.com/ngtcp2/ngtcp2 && \ cd ngtcp2 && \ autoreconf -i && \ - ./configure --enable-lib-only \ + ./configure --enable-lib-only --with-boringssl \ LIBTOOL_LDFLAGS="-static-libtool-libs" \ - OPENSSL_LIBS="-l:libssl.a -l:libcrypto.a -ldl -lpthread" \ + BORINGSSL_LIBS="-l:libssl.a -l:libcrypto.a" \ PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig" && \ make -j$(nproc) && \ make install-strip && \ cd .. && \ rm -rf ngtcp2 -RUN git clone --depth 1 -b v1.2.2 https://github.com/libbpf/libbpf && \ +RUN git clone --depth 1 -b v1.3.0 https://github.com/libbpf/libbpf && \ cd libbpf && \ PREFIX=/usr/local make -C src install && \ cd .. && \ rm -rf libbpf -RUN git clone --depth 1 https://github.com/nghttp2/nghttp2.git && \ +RUN git clone --recursive --depth 1 -b $NGHTTP2_BRANCH https://github.com/nghttp2/nghttp2 && \ cd nghttp2 && \ - git submodule update --init && \ autoreconf -i && \ ./configure --disable-examples --disable-hpack-tools \ - --with-mruby --with-neverbleed \ + --with-mruby \ --enable-http3 --with-libbpf \ + --with-libbrotlienc --with-libbrotlidec \ CC=clang CXX=clang++ \ LIBTOOL_LDFLAGS="-static-libtool-libs" \ - OPENSSL_LIBS="-l:libssl.a -l:libcrypto.a -ldl -pthread" \ + OPENSSL_LIBS="-l:libssl.a -l:libcrypto.a" \ LIBEV_LIBS="-l:libev.a" \ JEMALLOC_LIBS="-l:libjemalloc.a" \ LIBCARES_LIBS="-l:libcares.a" \ ZLIB_LIBS="-l:libz.a" \ LIBBPF_LIBS="-L/usr/local/lib64 -l:libbpf.a -l:libelf.a" \ + LIBBROTLIENC_LIBS="-l:libbrotlienc.a -l:libbrotlicommon.a" \ + LIBBROTLIDEC_LIBS="-l:libbrotlidec.a -l:libbrotlicommon.a" \ LDFLAGS="-static-libgcc -static-libstdc++" \ PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig" && \ make -j$(nproc) install-strip && \ cd .. && \ rm -rf nghttp2 -FROM gcr.io/distroless/base-debian12 +FROM gcr.io/distroless/base-nossl-debian12 -COPY --from=build \ +COPY --from=build --link \ /usr/local/share/nghttp2/ \ /usr/local/share/nghttp2/ -COPY --from=build \ +COPY --from=build --link \ /usr/local/bin/h2load \ /usr/local/bin/nghttpx \ /usr/local/bin/nghttp \ /usr/local/bin/nghttpd \ /usr/local/bin/ -COPY --from=build /usr/local/lib/nghttp2/reuseport_kern.o \ +COPY --from=build --link /usr/local/lib/nghttp2/reuseport_kern.o \ /usr/local/lib/nghttp2/ diff --git a/yass/third_party/nghttp2/examples/client.c b/yass/third_party/nghttp2/examples/client.c index 6cc3fddf76..7d25610578 100644 --- a/yass/third_party/nghttp2/examples/client.c +++ b/yass/third_party/nghttp2/examples/client.c @@ -56,6 +56,7 @@ #include #include +#define NGHTTP2_NO_SSIZE_T #include #include @@ -154,13 +155,14 @@ static void diec(const char *func, int error_code) { } /* - * The implementation of nghttp2_send_callback type. Here we write + * The implementation of nghttp2_send_callback2 type. Here we write * |data| with size |length| to the network and return the number of * bytes actually written. See the documentation of * nghttp2_send_callback for the details. */ -static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) { +static nghttp2_ssize send_callback(nghttp2_session *session, + const uint8_t *data, size_t length, + int flags, void *user_data) { struct Connection *connection; int rv; (void)session; @@ -184,13 +186,14 @@ static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, } /* - * The implementation of nghttp2_recv_callback type. Here we read data - * from the network and write them in |buf|. The capacity of |buf| is - * |length| bytes. Returns the number of bytes stored in |buf|. See - * the documentation of nghttp2_recv_callback for the details. + * The implementation of nghttp2_recv_callback2 type. Here we read + * data from the network and write them in |buf|. The capacity of + * |buf| is |length| bytes. Returns the number of bytes stored in + * |buf|. See the documentation of nghttp2_recv_callback for the + * details. */ -static ssize_t recv_callback(nghttp2_session *session, uint8_t *buf, - size_t length, int flags, void *user_data) { +static nghttp2_ssize recv_callback(nghttp2_session *session, uint8_t *buf, + size_t length, int flags, void *user_data) { struct Connection *connection; int rv; (void)session; @@ -328,9 +331,9 @@ static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, * recv_callback is also required. */ static void setup_nghttp2_callbacks(nghttp2_session_callbacks *callbacks) { - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); - nghttp2_session_callbacks_set_recv_callback(callbacks, recv_callback); + nghttp2_session_callbacks_set_recv_callback2(callbacks, recv_callback); nghttp2_session_callbacks_set_on_frame_send_callback(callbacks, on_frame_send_callback); @@ -345,29 +348,6 @@ static void setup_nghttp2_callbacks(nghttp2_session_callbacks *callbacks) { callbacks, on_data_chunk_recv_callback); } -#ifndef OPENSSL_NO_NEXTPROTONEG -/* - * Callback function for TLS NPN. Since this program only supports - * HTTP/2 protocol, if server does not offer HTTP/2 the nghttp2 - * library supports, we terminate program. - */ -static int select_next_proto_cb(SSL *ssl, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg) { - int rv; - (void)ssl; - (void)arg; - - /* nghttp2_select_next_protocol() selects HTTP/2 protocol the - nghttp2 library supports. */ - rv = nghttp2_select_next_protocol(out, outlen, in, inlen); - if (rv <= 0) { - die("Server did not advertise HTTP/2 protocol"); - } - return SSL_TLSEXT_ERR_OK; -} -#endif /* !OPENSSL_NO_NEXTPROTONEG */ - /* * Setup SSL/TLS context. */ @@ -376,14 +356,8 @@ static void init_ssl_ctx(SSL_CTX *ssl_ctx) { SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2); SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY); SSL_CTX_set_mode(ssl_ctx, SSL_MODE_RELEASE_BUFFERS); - /* Set NPN callback */ -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, NULL); -#endif /* !OPENSSL_NO_NEXTPROTONEG */ -#if OPENSSL_VERSION_NUMBER >= 0x10002000L SSL_CTX_set_alpn_protos(ssl_ctx, (const unsigned char *)"\x02h2", 3); -#endif /* OPENSSL_VERSION_NUMBER >= 0x10002000L */ } static void ssl_handshake(SSL *ssl, int fd) { @@ -487,8 +461,8 @@ static void submit_request(struct Connection *connection, struct Request *req) { MAKE_NV("accept", "*/*"), MAKE_NV("user-agent", "nghttp2/" NGHTTP2_VERSION)}; - stream_id = nghttp2_submit_request(connection->session, NULL, nva, - sizeof(nva) / sizeof(nva[0]), NULL, req); + stream_id = nghttp2_submit_request2(connection->session, NULL, nva, + sizeof(nva) / sizeof(nva[0]), NULL, req); if (stream_id < 0) { diec("nghttp2_submit_request", stream_id); @@ -719,19 +693,6 @@ int main(int argc, char **argv) { act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, 0); -#if OPENSSL_VERSION_NUMBER >= 0x1010000fL - /* No explicit initialization is required. */ -#elif defined(OPENSSL_IS_BORINGSSL) - CRYPTO_library_init(); -#else /* !(OPENSSL_VERSION_NUMBER >= 0x1010000fL) && \ - !defined(OPENSSL_IS_BORINGSSL) */ - OPENSSL_config(NULL); - SSL_load_error_strings(); - SSL_library_init(); - OpenSSL_add_all_algorithms(); -#endif /* !(OPENSSL_VERSION_NUMBER >= 0x1010000fL) && \ - !defined(OPENSSL_IS_BORINGSSL) */ - rv = parse_uri(&uri, argv[1]); if (rv != 0) { die("parse_uri failed"); diff --git a/yass/third_party/nghttp2/examples/deflate.c b/yass/third_party/nghttp2/examples/deflate.c index df1cb92025..8343b165ad 100644 --- a/yass/third_party/nghttp2/examples/deflate.c +++ b/yass/third_party/nghttp2/examples/deflate.c @@ -29,6 +29,7 @@ #include #include +#define NGHTTP2_NO_SSIZE_T #include #define MAKE_NV(K, V) \ @@ -93,7 +94,7 @@ int main(void) { static void deflate(nghttp2_hd_deflater *deflater, nghttp2_hd_inflater *inflater, const nghttp2_nv *const nva, size_t nvlen) { - ssize_t rv; + nghttp2_ssize rv; uint8_t *buf; size_t buflen; size_t outlen; @@ -118,10 +119,10 @@ static void deflate(nghttp2_hd_deflater *deflater, buflen = nghttp2_hd_deflate_bound(deflater, nva, nvlen); buf = malloc(buflen); - rv = nghttp2_hd_deflate_hd(deflater, buf, buflen, nva, nvlen); + rv = nghttp2_hd_deflate_hd2(deflater, buf, buflen, nva, nvlen); if (rv < 0) { - fprintf(stderr, "nghttp2_hd_deflate_hd() failed with error: %s\n", + fprintf(stderr, "nghttp2_hd_deflate_hd2() failed with error: %s\n", nghttp2_strerror((int)rv)); free(buf); @@ -166,17 +167,18 @@ static void deflate(nghttp2_hd_deflater *deflater, int inflate_header_block(nghttp2_hd_inflater *inflater, uint8_t *in, size_t inlen, int final) { - ssize_t rv; + nghttp2_ssize rv; for (;;) { nghttp2_nv nv; int inflate_flags = 0; size_t proclen; - rv = nghttp2_hd_inflate_hd(inflater, &nv, &inflate_flags, in, inlen, final); + rv = + nghttp2_hd_inflate_hd3(inflater, &nv, &inflate_flags, in, inlen, final); if (rv < 0) { - fprintf(stderr, "inflate failed with error code %zd", rv); + fprintf(stderr, "inflate failed with error code %td", rv); return -1; } diff --git a/yass/third_party/nghttp2/examples/libevent-client.c b/yass/third_party/nghttp2/examples/libevent-client.c index 2debd7b844..7f98368127 100644 --- a/yass/third_party/nghttp2/examples/libevent-client.c +++ b/yass/third_party/nghttp2/examples/libevent-client.c @@ -63,6 +63,7 @@ char *strndup(const char *s, size_t size); #include #include +#define NGHTTP2_NO_SSIZE_T #include #include "url-parser/url_parser.h" @@ -196,18 +197,19 @@ static void print_headers(FILE *f, nghttp2_nv *nva, size_t nvlen) { fprintf(f, "\n"); } -/* nghttp2_send_callback. Here we transmit the |data|, |length| bytes, - to the network. Because we are using libevent bufferevent, we just - write those bytes into bufferevent buffer. */ -static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) { +/* nghttp2_send_callback2. Here we transmit the |data|, |length| + bytes, to the network. Because we are using libevent bufferevent, + we just write those bytes into bufferevent buffer. */ +static nghttp2_ssize send_callback(nghttp2_session *session, + const uint8_t *data, size_t length, + int flags, void *user_data) { http2_session_data *session_data = (http2_session_data *)user_data; struct bufferevent *bev = session_data->bev; (void)session; (void)flags; bufferevent_write(bev, data, length); - return (ssize_t)length; + return (nghttp2_ssize)length; } /* nghttp2_on_header_callback: Called when nghttp2 library emits @@ -308,23 +310,6 @@ static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id, return 0; } -#ifndef OPENSSL_NO_NEXTPROTONEG -/* NPN TLS extension client callback. We check that server advertised - the HTTP/2 protocol the nghttp2 library supports. If not, exit - the program. */ -static int select_next_proto_cb(SSL *ssl, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg) { - (void)ssl; - (void)arg; - - if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) { - errx(1, "Server did not advertise " NGHTTP2_PROTO_VERSION_ID); - } - return SSL_TLSEXT_ERR_OK; -} -#endif /* !OPENSSL_NO_NEXTPROTONEG */ - /* Create SSL_CTX. */ static SSL_CTX *create_ssl_ctx(void) { SSL_CTX *ssl_ctx; @@ -337,13 +322,8 @@ static SSL_CTX *create_ssl_ctx(void) { SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION); -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, NULL); -#endif /* !OPENSSL_NO_NEXTPROTONEG */ -#if OPENSSL_VERSION_NUMBER >= 0x10002000L SSL_CTX_set_alpn_protos(ssl_ctx, (const unsigned char *)"\x02h2", 3); -#endif /* OPENSSL_VERSION_NUMBER >= 0x10002000L */ return ssl_ctx; } @@ -364,7 +344,7 @@ static void initialize_nghttp2_session(http2_session_data *session_data) { nghttp2_session_callbacks_new(&callbacks); - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, on_frame_recv_callback); @@ -425,8 +405,8 @@ static void submit_request(http2_session_data *session_data) { MAKE_NV(":path", stream_data->path, stream_data->pathlen)}; fprintf(stderr, "Request headers:\n"); print_headers(stderr, hdrs, ARRLEN(hdrs)); - stream_id = nghttp2_submit_request(session_data->session, NULL, hdrs, - ARRLEN(hdrs), NULL, stream_data); + stream_id = nghttp2_submit_request2(session_data->session, NULL, hdrs, + ARRLEN(hdrs), NULL, stream_data); if (stream_id < 0) { errx(1, "Could not submit HTTP request: %s", nghttp2_strerror(stream_id)); } @@ -453,12 +433,12 @@ static int session_send(http2_session_data *session_data) { context. To send them, we call session_send() in the end. */ static void readcb(struct bufferevent *bev, void *ptr) { http2_session_data *session_data = (http2_session_data *)ptr; - ssize_t readlen; + nghttp2_ssize readlen; struct evbuffer *input = bufferevent_get_input(bev); size_t datalen = evbuffer_get_length(input); unsigned char *data = evbuffer_pullup(input, -1); - readlen = nghttp2_session_mem_recv(session_data->session, data, datalen); + readlen = nghttp2_session_mem_recv2(session_data->session, data, datalen); if (readlen < 0) { warnx("Fatal error: %s", nghttp2_strerror((int)readlen)); delete_http2_session_data(session_data); @@ -508,14 +488,9 @@ static void eventcb(struct bufferevent *bev, short events, void *ptr) { ssl = bufferevent_openssl_get_ssl(session_data->bev); -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(ssl, &alpn, &alpnlen); -#endif /* !OPENSSL_NO_NEXTPROTONEG */ -#if OPENSSL_VERSION_NUMBER >= 0x10002000L if (alpn == NULL) { SSL_get0_alpn_selected(ssl, &alpn, &alpnlen); } -#endif /* OPENSSL_VERSION_NUMBER >= 0x10002000L */ if (alpn == NULL || alpnlen != 2 || memcmp("h2", alpn, 2) != 0) { fprintf(stderr, "h2 is not negotiated\n"); @@ -617,19 +592,6 @@ int main(int argc, char **argv) { act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); -#if OPENSSL_VERSION_NUMBER >= 0x1010000fL - /* No explicit initialization is required. */ -#elif defined(OPENSSL_IS_BORINGSSL) - CRYPTO_library_init(); -#else /* !(OPENSSL_VERSION_NUMBER >= 0x1010000fL) && \ - !defined(OPENSSL_IS_BORINGSSL) */ - OPENSSL_config(NULL); - SSL_load_error_strings(); - SSL_library_init(); - OpenSSL_add_all_algorithms(); -#endif /* !(OPENSSL_VERSION_NUMBER >= 0x1010000fL) && \ - !defined(OPENSSL_IS_BORINGSSL) */ - run(argv[1]); return 0; } diff --git a/yass/third_party/nghttp2/examples/libevent-server.c b/yass/third_party/nghttp2/examples/libevent-server.c index 9f4e1281bc..cc6c510a44 100644 --- a/yass/third_party/nghttp2/examples/libevent-server.c +++ b/yass/third_party/nghttp2/examples/libevent-server.c @@ -71,6 +71,7 @@ #include #include +#define NGHTTP2_NO_SSIZE_T #include #define OUTPUT_WOULDBLOCK_THRESHOLD (1 << 16) @@ -106,22 +107,6 @@ struct app_context { struct event_base *evbase; }; -static unsigned char next_proto_list[256]; -static size_t next_proto_list_len; - -#ifndef OPENSSL_NO_NEXTPROTONEG -static int next_proto_cb(SSL *ssl, const unsigned char **data, - unsigned int *len, void *arg) { - (void)ssl; - (void)arg; - - *data = next_proto_list; - *len = (unsigned int)next_proto_list_len; - return SSL_TLSEXT_ERR_OK; -} -#endif /* !OPENSSL_NO_NEXTPROTONEG */ - -#if OPENSSL_VERSION_NUMBER >= 0x10002000L static int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg) { @@ -129,7 +114,7 @@ static int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, (void)ssl; (void)arg; - rv = nghttp2_select_next_protocol((unsigned char **)out, outlen, in, inlen); + rv = nghttp2_select_alpn(out, outlen, in, inlen); if (rv != 1) { return SSL_TLSEXT_ERR_NOACK; @@ -137,7 +122,6 @@ static int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, return SSL_TLSEXT_ERR_OK; } -#endif /* OPENSSL_VERSION_NUMBER >= 0x10002000L */ /* Create SSL_CTX. */ static SSL_CTX *create_ssl_ctx(const char *key_file, const char *cert_file) { @@ -177,18 +161,7 @@ static SSL_CTX *create_ssl_ctx(const char *key_file, const char *cert_file) { errx(1, "Could not read certificate file %s", cert_file); } - next_proto_list[0] = NGHTTP2_PROTO_VERSION_ID_LEN; - memcpy(&next_proto_list[1], NGHTTP2_PROTO_VERSION_ID, - NGHTTP2_PROTO_VERSION_ID_LEN); - next_proto_list_len = 1 + NGHTTP2_PROTO_VERSION_ID_LEN; - -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_CTX_set_next_protos_advertised_cb(ssl_ctx, next_proto_cb, NULL); -#endif /* !OPENSSL_NO_NEXTPROTONEG */ - -#if OPENSSL_VERSION_NUMBER >= 0x10002000L SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, NULL); -#endif /* OPENSSL_VERSION_NUMBER >= 0x10002000L */ return ssl_ctx; } @@ -305,16 +278,16 @@ static int session_send(http2_session_data *session_data) { } /* Read the data in the bufferevent and feed them into nghttp2 library - function. Invocation of nghttp2_session_mem_recv() may make + function. Invocation of nghttp2_session_mem_recv2() may make additional pending frames, so call session_send() at the end of the function. */ static int session_recv(http2_session_data *session_data) { - ssize_t readlen; + nghttp2_ssize readlen; struct evbuffer *input = bufferevent_get_input(session_data->bev); size_t datalen = evbuffer_get_length(input); unsigned char *data = evbuffer_pullup(input, -1); - readlen = nghttp2_session_mem_recv(session_data->session, data, datalen); + readlen = nghttp2_session_mem_recv2(session_data->session, data, datalen); if (readlen < 0) { warnx("Fatal error: %s", nghttp2_strerror((int)readlen)); return -1; @@ -329,8 +302,9 @@ static int session_recv(http2_session_data *session_data) { return 0; } -static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) { +static nghttp2_ssize send_callback(nghttp2_session *session, + const uint8_t *data, size_t length, + int flags, void *user_data) { http2_session_data *session_data = (http2_session_data *)user_data; struct bufferevent *bev = session_data->bev; (void)session; @@ -342,7 +316,7 @@ static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, return NGHTTP2_ERR_WOULDBLOCK; } bufferevent_write(bev, data, length); - return (ssize_t)length; + return (nghttp2_ssize)length; } /* Returns nonzero if the string |s| ends with the substring |sub| */ @@ -398,11 +372,11 @@ static char *percent_decode(const uint8_t *value, size_t valuelen) { return res; } -static ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, - uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) { +static nghttp2_ssize file_read_callback(nghttp2_session *session, + int32_t stream_id, uint8_t *buf, + size_t length, uint32_t *data_flags, + nghttp2_data_source *source, + void *user_data) { int fd = source->fd; ssize_t r; (void)session; @@ -417,17 +391,17 @@ static ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, if (r == 0) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; } - return r; + return (nghttp2_ssize)r; } static int send_response(nghttp2_session *session, int32_t stream_id, nghttp2_nv *nva, size_t nvlen, int fd) { int rv; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = fd; data_prd.read_callback = file_read_callback; - rv = nghttp2_submit_response(session, stream_id, nva, nvlen, &data_prd); + rv = nghttp2_submit_response2(session, stream_id, nva, nvlen, &data_prd); if (rv != 0) { warnx("Fatal error: %s", nghttp2_strerror(rv)); return -1; @@ -618,7 +592,7 @@ static void initialize_nghttp2_session(http2_session_data *session_data) { nghttp2_session_callbacks_new(&callbacks); - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, on_frame_recv_callback); @@ -702,14 +676,7 @@ static void eventcb(struct bufferevent *bev, short events, void *ptr) { ssl = bufferevent_openssl_get_ssl(session_data->bev); -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(ssl, &alpn, &alpnlen); -#endif /* !OPENSSL_NO_NEXTPROTONEG */ -#if OPENSSL_VERSION_NUMBER >= 0x10002000L - if (alpn == NULL) { - SSL_get0_alpn_selected(ssl, &alpn, &alpnlen); - } -#endif /* OPENSSL_VERSION_NUMBER >= 0x10002000L */ + SSL_get0_alpn_selected(ssl, &alpn, &alpnlen); if (alpn == NULL || alpnlen != 2 || memcmp("h2", alpn, 2) != 0) { fprintf(stderr, "%s h2 is not negotiated\n", session_data->client_addr); @@ -817,19 +784,6 @@ int main(int argc, char **argv) { act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); -#if OPENSSL_VERSION_NUMBER >= 0x1010000fL - /* No explicit initialization is required. */ -#elif defined(OPENSSL_IS_BORINGSSL) - CRYPTO_library_init(); -#else /* !(OPENSSL_VERSION_NUMBER >= 0x1010000fL) && \ - !defined(OPENSSL_IS_BORINGSSL) */ - OPENSSL_config(NULL); - SSL_load_error_strings(); - SSL_library_init(); - OpenSSL_add_all_algorithms(); -#endif /* !(OPENSSL_VERSION_NUMBER >= 0x1010000fL) && \ - !defined(OPENSSL_IS_BORINGSSL) */ - run(argv[1], argv[2], argv[3]); return 0; } diff --git a/yass/third_party/nghttp2/fuzz/fuzz_target.cc b/yass/third_party/nghttp2/fuzz/fuzz_target.cc index 4adc5ed658..1932802780 100644 --- a/yass/third_party/nghttp2/fuzz/fuzz_target.cc +++ b/yass/third_party/nghttp2/fuzz/fuzz_target.cc @@ -40,7 +40,7 @@ namespace { void send_pending(nghttp2_session *session) { for (;;) { const uint8_t *data; - auto n = nghttp2_session_mem_send(session, &data); + auto n = nghttp2_session_mem_send2(session, &data); if (n == 0) { return; } @@ -70,7 +70,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { nghttp2_settings_entry iv{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}; nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); send_pending(session); - nghttp2_session_mem_recv(session, data, size); + nghttp2_session_mem_recv2(session, data, size); send_pending(session); nghttp2_session_del(session); diff --git a/yass/third_party/nghttp2/fuzz/fuzz_target_fdp.cc b/yass/third_party/nghttp2/fuzz/fuzz_target_fdp.cc index f94b96433d..668c83fd14 100644 --- a/yass/third_party/nghttp2/fuzz/fuzz_target_fdp.cc +++ b/yass/third_party/nghttp2/fuzz/fuzz_target_fdp.cc @@ -44,7 +44,7 @@ namespace { void send_pending(nghttp2_session *session) { for (;;) { const uint8_t *data; - auto n = nghttp2_session_mem_send(session, &data); + auto n = nghttp2_session_mem_send2(session, &data); if (n == 0) { return; } @@ -87,7 +87,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { send_pending(session); std::vector d = data_provider.ConsumeRemainingBytes(); - nghttp2_session_mem_recv(session, d.data(), d.size()); + nghttp2_session_mem_recv2(session, d.data(), d.size()); send_pending(session); diff --git a/yass/third_party/nghttp2/genheaderfunc.py b/yass/third_party/nghttp2/genheaderfunc.py index 71927609d6..2ac3c37341 100755 --- a/yass/third_party/nghttp2/genheaderfunc.py +++ b/yass/third_party/nghttp2/genheaderfunc.py @@ -35,6 +35,7 @@ HEADERS = [ "early-data", "sec-websocket-accept", "sec-websocket-key", + "priority", # disallowed h1 headers 'connection', 'keep-alive', diff --git a/yass/third_party/nghttp2/gennghttpxfun.py b/yass/third_party/nghttp2/gennghttpxfun.py index ffd253f019..80058e0ac4 100755 --- a/yass/third_party/nghttp2/gennghttpxfun.py +++ b/yass/third_party/nghttp2/gennghttpxfun.py @@ -200,6 +200,10 @@ OPTIONS = [ "frontend-quic-initial-rtt", "require-http-scheme", "tls-ktls", + "alpn-list", + "frontend-header-timeout", + "frontend-http2-idle-timeout", + "frontend-http3-idle-timeout", ] LOGVARS = [ diff --git a/yass/third_party/nghttp2/go.mod b/yass/third_party/nghttp2/go.mod index a2b31c1416..fb00b322cf 100644 --- a/yass/third_party/nghttp2/go.mod +++ b/yass/third_party/nghttp2/go.mod @@ -1,26 +1,24 @@ module github.com/nghttp2/nghttp2 -go 1.20 +go 1.21.1 require ( - github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746 - github.com/quic-go/quic-go v0.35.1 - github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20150408091349-4742878d9c90 - golang.org/x/net v0.17.0 + github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 + github.com/quic-go/quic-go v0.42.0 + github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20240121064059-46ccb0a462a8 + golang.org/x/net v0.22.0 ) require ( - github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect - github.com/golang/mock v1.6.0 // indirect + github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect - github.com/onsi/ginkgo/v2 v2.2.0 // indirect + github.com/onsi/ginkgo/v2 v2.9.5 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect - golang.org/x/crypto v0.14.0 // indirect + go.uber.org/mock v0.4.0 // indirect + golang.org/x/crypto v0.21.0 // indirect golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect - golang.org/x/mod v0.8.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect - golang.org/x/tools v0.6.0 // indirect + golang.org/x/mod v0.11.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.9.1 // indirect ) diff --git a/yass/third_party/nghttp2/go.sum b/yass/third_party/nghttp2/go.sum index 49f9e873f0..43011ec840 100644 --- a/yass/third_party/nghttp2/go.sum +++ b/yass/third_party/nghttp2/go.sum @@ -1,78 +1,59 @@ -github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746 h1:wAIE/kN63Oig1DdOzN7O+k4AbFh2cCJoKMFXrwRJtzk= -github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= +github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 h1:N7oVaKyGp8bttX0bfZGmcGkjz7DLQXhAn3DNd3T0ous= +github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874/go.mod h1:r5xuitiExdLAJ09PR7vBVENGvp4ZuTBeWTGtxuX3K+c= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/onsi/ginkgo/v2 v2.2.0 h1:3ZNA3L1c5FYDFTTxbFeVGGD8jYvjYauHD30YgLxVsNI= -github.com/onsi/ginkgo/v2 v2.2.0/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= -github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= +github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q= +github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k= +github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= +github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= -github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= -github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.35.1 h1:b0kzj6b/cQAf05cT0CkQubHM31wiA+xH3IBkxP62poo= -github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g= +github.com/quic-go/quic-go v0.42.0 h1:uSfdap0eveIl8KXnipv9K7nlwZ5IqLlYOpJ58u5utpM= +github.com/quic-go/quic-go v0.42.0/go.mod h1:132kz4kL3F9vxhW3CtQJLDVwcFe5wdWeJXXijhsO57M= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20150408091349-4742878d9c90 h1:ccVm9C6f5YMcVv6t9MXahIDkqVvzD6vklkJTIE4D2nY= -github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20150408091349-4742878d9c90/go.mod h1:YZhsh86DfZgAShPKeg1eBLVrmuQxWcR9H4TdpgNvSnw= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20240121064059-46ccb0a462a8 h1:zKJxuRe+a0O34V81GAZWOrotuU6mveT30QLjJ7OPMMg= +github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20240121064059-46ccb0a462a8/go.mod h1:gTqc3Q4boc+cKRlSFywTYdX9t6VGRcsThlNIWwaL3Dc= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o= golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= +golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/yass/third_party/nghttp2/integration-tests/CMakeLists.txt b/yass/third_party/nghttp2/integration-tests/CMakeLists.txt index 0815cb341a..cc92e9fdc7 100644 --- a/yass/third_party/nghttp2/integration-tests/CMakeLists.txt +++ b/yass/third_party/nghttp2/integration-tests/CMakeLists.txt @@ -19,12 +19,6 @@ set(EXTRA_DIST resp-return.rb ) -add_custom_target(itprep - COMMAND go get -d -v golang.org/x/net/http2 - COMMAND go get -d -v github.com/tatsuhiro-t/go-nghttp2 - COMMAND go get -d -v golang.org/x/net/websocket -) - # 'go test' requires both config.go and the test files in the same directory. # For out-of-tree builds, config.go is normally not placed next to the source # files, so copy the tests to the build directory as a workaround. diff --git a/yass/third_party/nghttp2/integration-tests/nghttpx_http1_test.go b/yass/third_party/nghttp2/integration-tests/nghttpx_http1_test.go index 740396d8f8..805525e205 100644 --- a/yass/third_party/nghttp2/integration-tests/nghttpx_http1_test.go +++ b/yass/third_party/nghttp2/integration-tests/nghttpx_http1_test.go @@ -58,7 +58,7 @@ func TestH1H1PlainGETClose(t *testing.T) { // 501 status code func TestH1H1InvalidMethod(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -82,7 +82,7 @@ func TestH1H1InvalidMethod(t *testing.T) { // contains multiple Content-Length header fields. func TestH1H1MultipleRequestCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -255,7 +255,7 @@ func TestH1H1HostRewrite(t *testing.T) { // characters in host header field. func TestH1H1BadHost(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -281,7 +281,7 @@ func TestH1H1BadHost(t *testing.T) { // bad characters in authority component of requset URI. func TestH1H1BadAuthority(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -307,7 +307,7 @@ func TestH1H1BadAuthority(t *testing.T) { // bad characters in scheme component of requset URI. func TestH1H1BadScheme(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -394,7 +394,7 @@ func TestH1H1HTTP10NoHostRewrite(t *testing.T) { // backend. func TestH1H1RequestTrailer(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { buf := make([]byte, 4096) for { _, err := r.Body.Read(buf) @@ -436,7 +436,7 @@ func TestH1H1HeaderFieldBufferPath(t *testing.T) { // limit. opts := options{ args: []string{"--request-header-field-buffer=100"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -460,7 +460,7 @@ func TestH1H1HeaderFieldBufferPath(t *testing.T) { func TestH1H1HeaderFieldBuffer(t *testing.T) { opts := options{ args: []string{"--request-header-field-buffer=10"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -483,7 +483,7 @@ func TestH1H1HeaderFieldBuffer(t *testing.T) { func TestH1H1HeaderFields(t *testing.T) { opts := options{ args: []string{"--max-request-header-fields=1"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -533,7 +533,7 @@ func TestH1H1Websocket(t *testing.T) { func TestH1H1ReqPhaseSetHeader(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-set-header.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("User-Agent"), "mruby"; got != want { t.Errorf("User-Agent = %v; want %v", got, want) } @@ -559,7 +559,7 @@ func TestH1H1ReqPhaseSetHeader(t *testing.T) { func TestH1H1ReqPhaseReturn(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -599,7 +599,7 @@ func TestH1H1ReqPhaseReturn(t *testing.T) { func TestH1H1ReqPhaseReturnCONNECTMethod(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -884,7 +884,7 @@ func TestH1H1CONNECTMethodFailure(t *testing.T) { func TestH1H2NoHost(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -978,7 +978,7 @@ func TestH1H2HTTP10NoHostRewrite(t *testing.T) { func TestH1H2CrumbleCookie(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Cookie"), "alpha; bravo; charlie"; got != want { t.Errorf("Cookie: %v; want %v", got, want) } @@ -1006,7 +1006,7 @@ func TestH1H2CrumbleCookie(t *testing.T) { func TestH1H2GenerateVia(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Via"), "1.1 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } @@ -1092,7 +1092,7 @@ func TestH1H2ReqPhaseReturn(t *testing.T) { "--http2-bridge", "--mruby-file=" + testDir + "/req-return.rb", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -1172,7 +1172,7 @@ func TestH1H2RespPhaseReturn(t *testing.T) { func TestH1H2TE(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("te"), "trailers"; got != want { t.Errorf("te: %v; want %v", got, want) } @@ -1200,7 +1200,7 @@ func TestH1H2TE(t *testing.T) { func TestH1APIBackendconfig(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1242,7 +1242,7 @@ backend=127.0.0.1,3011 func TestH1APIBackendconfigQuery(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1284,7 +1284,7 @@ backend=127.0.0.1,3011 func TestH1APIBackendconfigBadMethod(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1325,7 +1325,7 @@ backend=127.0.0.1,3011 func TestH1APIConfigrevision(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1368,7 +1368,7 @@ func TestH1APIConfigrevision(t *testing.T) { func TestH1APINotFound(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1409,7 +1409,7 @@ backend=127.0.0.1,3011 func TestH1Healthmon(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3011;healthmon;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3011, @@ -1434,7 +1434,7 @@ func TestH1Healthmon(t *testing.T) { func TestH1ResponseBeforeRequestEnd(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("request should not be forwarded") }, } @@ -1462,7 +1462,7 @@ func TestH1ResponseBeforeRequestEnd(t *testing.T) { // if the backend chunked encoded response ends prematurely. func TestH1H1ChunkedEndsPrematurely(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -1495,7 +1495,7 @@ func TestH1H1ChunkedEndsPrematurely(t *testing.T) { // request which contains malformed transfer-encoding. func TestH1H1RequestMalformedTransferEncoding(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -1523,7 +1523,7 @@ func TestH1H1RequestMalformedTransferEncoding(t *testing.T) { // its response contains malformed transfer-encoding. func TestH1H1ResponseMalformedTransferEncoding(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -1559,7 +1559,7 @@ func TestH1H1ResponseMalformedTransferEncoding(t *testing.T) { // its response contains unknown transfer-encoding. func TestH1H1ResponseUnknownTransferEncoding(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -1607,7 +1607,7 @@ func TestH1H1ResponseUnknownTransferEncoding(t *testing.T) { // HTTP/1.0 request which contains transfer-encoding. func TestH1H1RequestHTTP10TransferEncoding(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } diff --git a/yass/third_party/nghttp2/integration-tests/nghttpx_http2_test.go b/yass/third_party/nghttp2/integration-tests/nghttpx_http2_test.go index 5324a18c52..8cda1bc9a5 100644 --- a/yass/third_party/nghttp2/integration-tests/nghttpx_http2_test.go +++ b/yass/third_party/nghttp2/integration-tests/nghttpx_http2_test.go @@ -40,7 +40,7 @@ func TestH2H1PlainGET(t *testing.T) { func TestH2H1AddXfp(t *testing.T) { opts := options{ args: []string{"--no-strip-incoming-x-forwarded-proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "foo, http"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -72,7 +72,7 @@ func TestH2H1NoAddXfp(t *testing.T) { "--no-add-x-forwarded-proto", "--no-strip-incoming-x-forwarded-proto", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "foo"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -100,7 +100,7 @@ func TestH2H1NoAddXfp(t *testing.T) { // x-forwarded-proto header field. func TestH2H1StripXfp(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "http"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -129,7 +129,7 @@ func TestH2H1StripXfp(t *testing.T) { func TestH2H1StripNoAddXfp(t *testing.T) { opts := options{ args: []string{"--no-add-x-forwarded-proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, found := r.Header["X-Forwarded-Proto"]; found { t.Errorf("X-Forwarded-Proto = %q; want nothing", got) } @@ -157,7 +157,7 @@ func TestH2H1StripNoAddXfp(t *testing.T) { func TestH2H1AddXff(t *testing.T) { opts := options{ args: []string{"--add-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "127.0.0.1" if xff != want { @@ -184,7 +184,7 @@ func TestH2H1AddXff(t *testing.T) { func TestH2H1AddXff2(t *testing.T) { opts := options{ args: []string{"--add-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "host, 127.0.0.1" if xff != want { @@ -214,7 +214,7 @@ func TestH2H1AddXff2(t *testing.T) { func TestH2H1StripXff(t *testing.T) { opts := options{ args: []string{"--strip-incoming-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if xff, found := r.Header["X-Forwarded-For"]; found { t.Errorf("X-Forwarded-For = %v; want nothing", xff) } @@ -245,7 +245,7 @@ func TestH2H1StripAddXff(t *testing.T) { "--strip-incoming-x-forwarded-for", "--add-x-forwarded-for", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "127.0.0.1" if xff != want { @@ -275,7 +275,7 @@ func TestH2H1StripAddXff(t *testing.T) { func TestH2H1AddForwardedObfuscated(t *testing.T) { opts := options{ args: []string{"--add-forwarded=by,for,host,proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { pattern := fmt.Sprintf(`by=_[^;]+;for=_[^;]+;host="127\.0\.0\.1:%v";proto=http`, serverPort) validFwd := regexp.MustCompile(pattern) got := r.Header.Get("Forwarded") @@ -304,7 +304,7 @@ func TestH2H1AddForwardedObfuscated(t *testing.T) { func TestH2H1AddForwardedByIP(t *testing.T) { opts := options{ args: []string{"--add-forwarded=by,for", "--forwarded-by=ip"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { pattern := fmt.Sprintf(`by="127\.0\.0\.1:%v";for=_[^;]+`, serverPort) validFwd := regexp.MustCompile(pattern) if got := r.Header.Get("Forwarded"); !validFwd.MatchString(got) { @@ -335,7 +335,7 @@ func TestH2H1AddForwardedForIP(t *testing.T) { "--forwarded-by=_alpha", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { want := fmt.Sprintf(`by=_alpha;for=127.0.0.1;host="127.0.0.1:%v";proto=http`, serverPort) if got := r.Header.Get("Forwarded"); got != want { t.Errorf("Forwarded = %v; want %v", got, want) @@ -362,7 +362,7 @@ func TestH2H1AddForwardedForIP(t *testing.T) { func TestH2H1AddForwardedMerge(t *testing.T) { opts := options{ args: []string{"--add-forwarded=proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Forwarded"), `host=foo, proto=http`; got != want { t.Errorf("Forwarded = %v; want %v", got, want) } @@ -394,7 +394,7 @@ func TestH2H1AddForwardedStrip(t *testing.T) { "--strip-incoming-forwarded", "--add-forwarded=proto", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Forwarded"), `proto=http`; got != want { t.Errorf("Forwarded = %v; want %v", got, want) } @@ -422,7 +422,7 @@ func TestH2H1AddForwardedStrip(t *testing.T) { func TestH2H1StripForwarded(t *testing.T) { opts := options{ args: []string{"--strip-incoming-forwarded"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, found := r.Header["Forwarded"]; found { t.Errorf("Forwarded = %v; want nothing", got) } @@ -454,7 +454,7 @@ func TestH2H1AddForwardedStatic(t *testing.T) { "--add-forwarded=by,for", "--forwarded-by=_alpha", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { pattern := `by=_alpha;for=_[^;]+` validFwd := regexp.MustCompile(pattern) if got := r.Header.Get("Forwarded"); !validFwd.MatchString(got) { @@ -480,7 +480,7 @@ func TestH2H1AddForwardedStatic(t *testing.T) { // from backend server. func TestH2H1GenerateVia(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Via"), "2 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } @@ -639,7 +639,7 @@ func TestH2H1BadRequestCL(t *testing.T) { // response body size. func TestH2H1BadResponseCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { // we set content-length: 1024, but only send 3 bytes. w.Header().Add("Content-Length", "1024") if _, err := w.Write([]byte("foo")); err != nil { @@ -667,7 +667,7 @@ func TestH2H1BadResponseCL(t *testing.T) { // works. func TestH2H1LocationRewrite(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { // TODO we cannot get st.ts's port number // here.. 8443 is just a place holder. We // ignore it on rewrite. @@ -693,7 +693,7 @@ func TestH2H1LocationRewrite(t *testing.T) { // TestH2H1ChunkedRequestBody tests that chunked request body works. func TestH2H1ChunkedRequestBody(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { want := "[chunked]" if got := fmt.Sprint(r.TransferEncoding); got != want { t.Errorf("Transfer-Encoding: %v; want %v", got, want) @@ -728,7 +728,7 @@ func TestH2H1ChunkedRequestBody(t *testing.T) { // multiple Content-Length request header fields. func TestH2H1MultipleRequestCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -754,7 +754,7 @@ func TestH2H1MultipleRequestCL(t *testing.T) { // Content-Length which cannot be parsed as a number. func TestH2H1InvalidRequestCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -800,7 +800,7 @@ func TestH2H1InvalidRequestCL(t *testing.T) { // 501. func TestH2H1InvalidMethod(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -823,7 +823,7 @@ func TestH2H1InvalidMethod(t *testing.T) { // bad characters in :authority header field. func TestH2H1BadAuthority(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -846,7 +846,7 @@ func TestH2H1BadAuthority(t *testing.T) { // bad characters in :scheme header field. func TestH2H1BadScheme(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -869,7 +869,7 @@ func TestH2H1BadScheme(t *testing.T) { // request is assembled into 1 when forwarding to HTTP/1 backend link. func TestH2H1AssembleCookies(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Cookie"), "alpha; bravo; charlie"; got != want { t.Errorf("Cookie: %v; want %v", got, want) } @@ -918,7 +918,7 @@ func TestH2H1TETrailers(t *testing.T) { // field contains gzip. func TestH2H1TEGzip(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Error("server should not forward bad request") }, } @@ -967,7 +967,7 @@ func TestH2H1SNI(t *testing.T) { // connection is encrypted. func TestH2H1TLSXfp(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("x-forwarded-proto"), "http"; got != want { t.Errorf("x-forwarded-proto: want %v; got %v", want, got) } @@ -1028,7 +1028,7 @@ func TestH2H1ServerPush(t *testing.T) { // backend. func TestH2H1RequestTrailer(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { buf := make([]byte, 4096) for { _, err := r.Body.Read(buf) @@ -1067,7 +1067,7 @@ func TestH2H1RequestTrailer(t *testing.T) { func TestH2H1HeaderFieldBuffer(t *testing.T) { opts := options{ args: []string{"--request-header-field-buffer=10"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -1090,7 +1090,7 @@ func TestH2H1HeaderFieldBuffer(t *testing.T) { func TestH2H1HeaderFields(t *testing.T) { opts := options{ args: []string{"--max-request-header-fields=1"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -1115,7 +1115,7 @@ func TestH2H1HeaderFields(t *testing.T) { func TestH2H1ReqPhaseSetHeader(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-set-header.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("User-Agent"), "mruby"; got != want { t.Errorf("User-Agent = %v; want %v", got, want) } @@ -1141,7 +1141,7 @@ func TestH2H1ReqPhaseSetHeader(t *testing.T) { func TestH2H1ReqPhaseReturn(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -1284,7 +1284,7 @@ func TestH2H1ProxyProtocolV1ForwardedForObfuscated(t *testing.T) { "--add-forwarded=for", "--forwarded-for=obfuscated", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got := r.Header.Get("Forwarded"); !validFwd.MatchString(got) { t.Errorf("Forwarded: %v; want pattern %v", got, pattern) } @@ -1321,7 +1321,7 @@ func TestH2H1ProxyProtocolV1TCP4(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1361,7 +1361,7 @@ func TestH2H1ProxyProtocolV1TCP6(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1401,7 +1401,7 @@ func TestH2H1ProxyProtocolV1TCP4TLS(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1439,7 +1439,7 @@ func TestH2H1ProxyProtocolV1TCP6TLS(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1476,7 +1476,7 @@ func TestH2H1ProxyProtocolV1Unknown(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, notWant := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got == notWant { t.Errorf("X-Forwarded-For: %v; want something else", got) } @@ -1881,7 +1881,7 @@ func TestH2H1ProxyProtocolV2TCP4(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1937,7 +1937,7 @@ func TestH2H1ProxyProtocolV2TCP6(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "2001:db8:85a3::8a2e:370:7334"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2009,7 +2009,7 @@ func TestH2H1ProxyProtocolV2TCP4TLS(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2063,7 +2063,7 @@ func TestH2H1ProxyProtocolV2TCP6TLS(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "2001:db8:85a3::8a2e:370:7334"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2100,7 +2100,7 @@ func TestH2H1ProxyProtocolV2Local(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "127.0.0.1"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2193,7 +2193,7 @@ func TestH2H1ProxyProtocolV2Unix(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "127.0.0.1"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2248,7 +2248,7 @@ func TestH2H1ProxyProtocolV2Unspec(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "127.0.0.1"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2383,7 +2383,7 @@ func TestH2H1HTTPSRedirectPort(t *testing.T) { // transfer-encoding is valid. func TestH2H1Code204(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) }, } @@ -2406,7 +2406,7 @@ func TestH2H1Code204(t *testing.T) { // is allowed. func TestH2H1Code204CL0(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -2447,7 +2447,7 @@ func TestH2H1Code204CL0(t *testing.T) { // content-length is not allowed. func TestH2H1Code204CLNonzero(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -2484,7 +2484,7 @@ func TestH2H1Code204CLNonzero(t *testing.T) { // not allowed. func TestH2H1Code204TE(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -2659,7 +2659,7 @@ func TestH2H1GracefulShutdown(t *testing.T) { func TestH2H2MultipleResponseCL(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { w.Header().Add("content-length", "1") w.Header().Add("content-length", "1") }, @@ -2684,7 +2684,7 @@ func TestH2H2MultipleResponseCL(t *testing.T) { func TestH2H2InvalidResponseCL(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { w.Header().Add("content-length", "") }, } @@ -2783,7 +2783,7 @@ func TestH2H2NoHostRewrite(t *testing.T) { func TestH2H2TLSXfp(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("x-forwarded-proto"), "http"; got != want { t.Errorf("x-forwarded-proto: want %v; got %v", want, got) } @@ -2812,7 +2812,7 @@ func TestH2H2AddXfp(t *testing.T) { "--http2-bridge", "--no-strip-incoming-x-forwarded-proto", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "foo, http"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -2846,7 +2846,7 @@ func TestH2H2NoAddXfp(t *testing.T) { "--no-add-x-forwarded-proto", "--no-strip-incoming-x-forwarded-proto", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "foo"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -2876,7 +2876,7 @@ func TestH2H2NoAddXfp(t *testing.T) { func TestH2H2StripXfp(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "http"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -2906,7 +2906,7 @@ func TestH2H2StripXfp(t *testing.T) { func TestH2H2StripNoAddXfp(t *testing.T) { opts := options{ args: []string{"--http2-bridge", "--no-add-x-forwarded-proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, found := r.Header["X-Forwarded-Proto"]; found { t.Errorf("X-Forwarded-Proto = %q; want nothing", got) } @@ -2935,7 +2935,7 @@ func TestH2H2StripNoAddXfp(t *testing.T) { func TestH2H2AddXff(t *testing.T) { opts := options{ args: []string{"--http2-bridge", "--add-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "127.0.0.1" if xff != want { @@ -2963,7 +2963,7 @@ func TestH2H2AddXff(t *testing.T) { func TestH2H2AddXff2(t *testing.T) { opts := options{ args: []string{"--http2-bridge", "--add-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "host, 127.0.0.1" if xff != want { @@ -2997,7 +2997,7 @@ func TestH2H2StripXff(t *testing.T) { "--http2-bridge", "--strip-incoming-x-forwarded-for", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if xff, found := r.Header["X-Forwarded-For"]; found { t.Errorf("X-Forwarded-For = %v; want nothing", xff) } @@ -3030,7 +3030,7 @@ func TestH2H2StripAddXff(t *testing.T) { "--strip-incoming-x-forwarded-for", "--add-x-forwarded-for", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "127.0.0.1" if xff != want { @@ -3065,7 +3065,7 @@ func TestH2H2AddForwarded(t *testing.T) { "--add-forwarded=by,for,host,proto", "--forwarded-by=_alpha", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { pattern := fmt.Sprintf(`by=_alpha;for=_[^;]+;host="127\.0\.0\.1:%v";proto=https`, serverPort) validFwd := regexp.MustCompile(pattern) if got := r.Header.Get("Forwarded"); !validFwd.MatchString(got) { @@ -3099,7 +3099,7 @@ func TestH2H2AddForwardedMerge(t *testing.T) { "--add-forwarded=by,host,proto", "--forwarded-by=_alpha", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { want := fmt.Sprintf(`host=foo, by=_alpha;host="127.0.0.1:%v";proto=https`, serverPort) if got := r.Header.Get("Forwarded"); got != want { t.Errorf("Forwarded = %v; want %v", got, want) @@ -3136,7 +3136,7 @@ func TestH2H2AddForwardedStrip(t *testing.T) { "--add-forwarded=by,host,proto", "--forwarded-by=_alpha", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { want := fmt.Sprintf(`by=_alpha;host="127.0.0.1:%v";proto=https`, serverPort) if got := r.Header.Get("Forwarded"); got != want { t.Errorf("Forwarded = %v; want %v", got, want) @@ -3167,7 +3167,7 @@ func TestH2H2AddForwardedStrip(t *testing.T) { func TestH2H2StripForwarded(t *testing.T) { opts := options{ args: []string{"--http2-bridge", "--strip-incoming-forwarded"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, found := r.Header["Forwarded"]; found { t.Errorf("Forwarded = %v; want nothing", got) } @@ -3200,7 +3200,7 @@ func TestH2H2ReqPhaseReturn(t *testing.T) { "--http2-bridge", "--mruby-file=" + testDir + "/req-return.rb", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -3322,7 +3322,7 @@ func TestH2H2DNS(t *testing.T) { func TestH2H2Code204(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) }, } @@ -3346,7 +3346,7 @@ func TestH2H2Code204(t *testing.T) { func TestH2APIBackendconfig(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3388,7 +3388,7 @@ backend=127.0.0.1,3011 func TestH2APIBackendconfigQuery(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3430,7 +3430,7 @@ backend=127.0.0.1,3011 func TestH2APIBackendconfigBadMethod(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3471,7 +3471,7 @@ backend=127.0.0.1,3011 func TestH2APIConfigrevision(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3514,7 +3514,7 @@ func TestH2APIConfigrevision(t *testing.T) { func TestH2APINotFound(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3555,7 +3555,7 @@ backend=127.0.0.1,3011 func TestH2Healthmon(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3011;healthmon;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3011, @@ -3580,7 +3580,7 @@ func TestH2Healthmon(t *testing.T) { func TestH2ResponseBeforeRequestEnd(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("request should not be forwarded") }, } @@ -3603,7 +3603,7 @@ func TestH2ResponseBeforeRequestEnd(t *testing.T) { // backend chunked encoded response ends prematurely. func TestH2H1ChunkedEndsPrematurely(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -3641,7 +3641,7 @@ func TestH2H1ChunkedEndsPrematurely(t *testing.T) { func TestH2H1RequireHTTPSchemeHTTPSWithoutEncryption(t *testing.T) { opts := options{ args: []string{"--require-http-scheme"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -3666,7 +3666,7 @@ func TestH2H1RequireHTTPSchemeHTTPSWithoutEncryption(t *testing.T) { func TestH2H1RequireHTTPSchemeHTTPWithEncryption(t *testing.T) { opts := options{ args: []string{"--require-http-scheme"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, tls: true, @@ -3693,7 +3693,7 @@ func TestH2H1RequireHTTPSchemeHTTPWithEncryption(t *testing.T) { func TestH2H1RequireHTTPSchemeUnknownSchemeWithoutEncryption(t *testing.T) { opts := options{ args: []string{"--require-http-scheme"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -3718,7 +3718,7 @@ func TestH2H1RequireHTTPSchemeUnknownSchemeWithoutEncryption(t *testing.T) { func TestH2H1RequireHTTPSchemeUnknownSchemeWithEncryption(t *testing.T) { opts := options{ args: []string{"--require-http-scheme"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, tls: true, diff --git a/yass/third_party/nghttp2/integration-tests/nghttpx_http3_test.go b/yass/third_party/nghttp2/integration-tests/nghttpx_http3_test.go index 9ea85d7447..757c96f1ba 100644 --- a/yass/third_party/nghttp2/integration-tests/nghttpx_http3_test.go +++ b/yass/third_party/nghttp2/integration-tests/nghttpx_http3_test.go @@ -41,7 +41,7 @@ func TestH3H1RequestBody(t *testing.T) { } opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { buf := make([]byte, 4096) buflen := 0 p := buf @@ -92,7 +92,7 @@ func TestH3H1RequestBody(t *testing.T) { // and from backend server. func TestH3H1GenerateVia(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Via"), "3 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } @@ -177,7 +177,7 @@ func TestH3H1NoVia(t *testing.T) { // response body size. func TestH3H1BadResponseCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { // we set content-length: 1024, but only send 3 bytes. w.Header().Add("Content-Length", "1024") if _, err := w.Write([]byte("foo")); err != nil { @@ -256,7 +256,7 @@ func TestH3H2ReqPhaseReturn(t *testing.T) { "--http2-bridge", "--mruby-file=" + testDir + "/req-return.rb", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, quic: true, @@ -338,7 +338,7 @@ func TestH3H2RespPhaseReturn(t *testing.T) { func TestH3ResponseBeforeRequestEnd(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("request should not be forwarded") }, quic: true, @@ -362,7 +362,7 @@ func TestH3ResponseBeforeRequestEnd(t *testing.T) { // backend chunked encoded response ends prematurely. func TestH3H1ChunkedEndsPrematurely(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) diff --git a/yass/third_party/nghttp2/integration-tests/server_tester.go b/yass/third_party/nghttp2/integration-tests/server_tester.go index 6a4ce650d7..a1bccad6d6 100644 --- a/yass/third_party/nghttp2/integration-tests/server_tester.go +++ b/yass/third_party/nghttp2/integration-tests/server_tester.go @@ -652,7 +652,7 @@ type serverResponse struct { errCode http2.ErrCode // error code received in HTTP/2 RST_STREAM or GOAWAY connErr bool // true if HTTP/2 connection error connClose bool // Connection: close is included in response header in HTTP/1 test - reqHeader http.Header // http request header, currently only sotres pushed request header + reqHeader http.Header // http request header, currently only stores pushed request header pushResponse []*serverResponse // pushed response } diff --git a/yass/third_party/nghttp2/lib/CMakeLists.txt b/yass/third_party/nghttp2/lib/CMakeLists.txt index e39d42787d..8142317d63 100644 --- a/yass/third_party/nghttp2/lib/CMakeLists.txt +++ b/yass/third_party/nghttp2/lib/CMakeLists.txt @@ -14,7 +14,7 @@ set(NGHTTP2_SOURCES nghttp2_stream.c nghttp2_outbound_item.c nghttp2_session.c nghttp2_submit.c nghttp2_helper.c - nghttp2_npn.c + nghttp2_alpn.c nghttp2_hd.c nghttp2_hd_huffman.c nghttp2_hd_huffman_data.c nghttp2_version.c nghttp2_priority_spec.c @@ -31,6 +31,12 @@ set(NGHTTP2_SOURCES ) set(NGHTTP2_RES "") +set(STATIC_LIB "nghttp2_static") +set(SHARED_LIB "nghttp2") + +if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS AND MSVC AND NOT STATIC_LIB_SUFFIX) + set(STATIC_LIB_SUFFIX "_static") +endif() if(WIN32) configure_file( @@ -41,46 +47,67 @@ if(WIN32) set(NGHTTP2_RES ${CMAKE_CURRENT_BINARY_DIR}/version.rc) endif() +set(EXPORT_SET "${PROJECT_NAME}-targets") + # Public shared library -if(ENABLE_SHARED_LIB) - add_library(nghttp2 SHARED ${NGHTTP2_SOURCES} ${NGHTTP2_RES}) - set_target_properties(nghttp2 PROPERTIES +if(BUILD_SHARED_LIBS) + add_library(${SHARED_LIB} SHARED ${NGHTTP2_SOURCES} ${NGHTTP2_RES}) + + set_target_properties(${SHARED_LIB} PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} C_VISIBILITY_PRESET hidden ) - target_include_directories(nghttp2 INTERFACE - "${CMAKE_CURRENT_BINARY_DIR}/includes" - "${CMAKE_CURRENT_SOURCE_DIR}/includes" + + target_include_directories(${SHARED_LIB} INTERFACE + $ + $ + $ ) if(NOT DISABLE_INSTALL) - install(TARGETS nghttp2 - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + install(TARGETS ${SHARED_LIB} EXPORT ${EXPORT_SET}) endif() + list(APPEND nghttp2_exports ${SHARED_LIB}) endif() -if(HAVE_CUNIT OR ENABLE_STATIC_LIB) - # Static library (for unittests because of symbol visibility) - add_library(nghttp2_static STATIC ${NGHTTP2_SOURCES}) - set_target_properties(nghttp2_static PROPERTIES +# Static library (for unittests because of symbol visibility) +if(BUILD_STATIC_LIBS) + add_library(${STATIC_LIB} STATIC ${NGHTTP2_SOURCES}) + + set_target_properties(${STATIC_LIB} PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} ARCHIVE_OUTPUT_NAME nghttp2${STATIC_LIB_SUFFIX} ) - target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB") - if(ENABLE_STATIC_LIB) - if(NOT DISABLE_INSTALL) - install(TARGETS nghttp2_static - DESTINATION "${CMAKE_INSTALL_LIBDIR}") - endif() + + target_include_directories(${STATIC_LIB} INTERFACE + $ + $ + $ + ) + + target_compile_definitions(${STATIC_LIB} PUBLIC "-DNGHTTP2_STATICLIB") + + if(NOT DISABLE_INSTALL) + install(TARGETS ${STATIC_LIB} EXPORT ${EXPORT_SET}) endif() + list(APPEND nghttp2_exports ${STATIC_LIB}) endif() +if(BUILD_SHARED_LIBS) + set(LIB_SELECTED ${SHARED_LIB}) +else() + set(LIB_SELECTED ${STATIC_LIB}) +endif() + +add_library(${PROJECT_NAME}::nghttp2 ALIAS ${LIB_SELECTED}) if(NOT DISABLE_INSTALL) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + + install(EXPORT ${EXPORT_SET} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + NAMESPACE ${PROJECT_NAME}::) endif() diff --git a/yass/third_party/nghttp2/lib/Makefile.am b/yass/third_party/nghttp2/lib/Makefile.am index c3ace4029a..1168c1e613 100644 --- a/yass/third_party/nghttp2/lib/Makefile.am +++ b/yass/third_party/nghttp2/lib/Makefile.am @@ -41,7 +41,7 @@ OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \ nghttp2_stream.c nghttp2_outbound_item.c \ nghttp2_session.c nghttp2_submit.c \ nghttp2_helper.c \ - nghttp2_npn.c \ + nghttp2_alpn.c \ nghttp2_hd.c nghttp2_hd_huffman.c nghttp2_hd_huffman_data.c \ nghttp2_version.c \ nghttp2_priority_spec.c \ @@ -60,7 +60,7 @@ HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \ nghttp2_frame.h \ nghttp2_buf.h \ nghttp2_session.h nghttp2_helper.h nghttp2_stream.h nghttp2_int.h \ - nghttp2_npn.h \ + nghttp2_alpn.h \ nghttp2_submit.h nghttp2_outbound_item.h \ nghttp2_net.h \ nghttp2_hd.h nghttp2_hd_huffman.h \ diff --git a/yass/third_party/nghttp2/lib/Makefile.msvc b/yass/third_party/nghttp2/lib/Makefile.msvc index 611b39d0b1..752389e0fc 100644 --- a/yass/third_party/nghttp2/lib/Makefile.msvc +++ b/yass/third_party/nghttp2/lib/Makefile.msvc @@ -74,7 +74,7 @@ NGHTTP2_SRC := nghttp2_pq.c \ nghttp2_session.c \ nghttp2_submit.c \ nghttp2_helper.c \ - nghttp2_npn.c \ + nghttp2_alpn.c \ nghttp2_hd.c \ nghttp2_hd_huffman.c \ nghttp2_hd_huffman_data.c \ diff --git a/yass/third_party/nghttp2/lib/includes/nghttp2/nghttp2.h b/yass/third_party/nghttp2/lib/includes/nghttp2/nghttp2.h index fa22081c51..92c3ccc6e4 100644 --- a/yass/third_party/nghttp2/lib/includes/nghttp2/nghttp2.h +++ b/yass/third_party/nghttp2/lib/includes/nghttp2/nghttp2.h @@ -51,6 +51,7 @@ extern "C" { #endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ #include #include +#include #include @@ -71,6 +72,13 @@ extern "C" { # endif /* !BUILDING_NGHTTP2 */ #endif /* !defined(WIN32) */ +/** + * @typedef + * + * :type:`nghttp2_ssize` is a signed counterpart of size_t. + */ +typedef ptrdiff_t nghttp2_ssize; + /** * @macro * @@ -168,6 +176,12 @@ typedef struct { /** * @macro * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The default weight of stream dependency. */ #define NGHTTP2_DEFAULT_WEIGHT 16 @@ -175,6 +189,12 @@ typedef struct { /** * @macro * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The maximum weight of stream dependency. */ #define NGHTTP2_MAX_WEIGHT 256 @@ -182,6 +202,12 @@ typedef struct { /** * @macro * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The minimum weight of stream dependency. */ #define NGHTTP2_MIN_WEIGHT 1 @@ -255,7 +281,7 @@ typedef enum { */ NGHTTP2_ERR_UNSUPPORTED_VERSION = -503, /** - * Used as a return value from :type:`nghttp2_send_callback`, + * Used as a return value from :type:`nghttp2_send_callback2`, * :type:`nghttp2_recv_callback` and * :type:`nghttp2_send_data_callback` to indicate that the operation * would block. @@ -275,9 +301,9 @@ typedef enum { NGHTTP2_ERR_EOF = -507, /** * Used as a return value from - * :func:`nghttp2_data_source_read_callback` to indicate that data + * :func:`nghttp2_data_source_read_callback2` to indicate that data * transfer is postponed. See - * :func:`nghttp2_data_source_read_callback` for details. + * :func:`nghttp2_data_source_read_callback2` for details. */ NGHTTP2_ERR_DEFERRED = -508, /** @@ -440,7 +466,12 @@ typedef enum { * exhaustion on server side to send these frames forever and does * not read network. */ - NGHTTP2_ERR_FLOODED = -904 + NGHTTP2_ERR_FLOODED = -904, + /** + * When a local endpoint receives too many CONTINUATION frames + * following a HEADER frame. + */ + NGHTTP2_ERR_TOO_MANY_CONTINUATIONS = -905, } nghttp2_error; /** @@ -830,7 +861,7 @@ typedef struct { * @union * * This union represents the some kind of data source passed to - * :type:`nghttp2_data_source_read_callback`. + * :type:`nghttp2_data_source_read_callback2`. */ typedef union { /** @@ -847,7 +878,7 @@ typedef union { * @enum * * The flags used to set in |data_flags| output parameter in - * :type:`nghttp2_data_source_read_callback`. + * :type:`nghttp2_data_source_read_callback2`. */ typedef enum { /** @@ -861,8 +892,8 @@ typedef enum { /** * Indicates that END_STREAM flag must not be set even if * NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send - * trailer fields with `nghttp2_submit_request()` or - * `nghttp2_submit_response()`. + * trailer fields with `nghttp2_submit_request2()` or + * `nghttp2_submit_response2()`. */ NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02, /** @@ -872,9 +903,15 @@ typedef enum { NGHTTP2_DATA_FLAG_NO_COPY = 0x04 } nghttp2_data_flag; +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_data_source_read_callback2` + * instead. + * * Callback function invoked when the library wants to read data from * the |source|. The read data is sent in the stream |stream_id|. * The implementation of this function must read at most |length| @@ -939,9 +976,83 @@ typedef ssize_t (*nghttp2_data_source_read_callback)( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, uint32_t *data_flags, nghttp2_data_source *source, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when the library wants to read data from + * the |source|. The read data is sent in the stream |stream_id|. + * The implementation of this function must read at most |length| + * bytes of data from |source| (or possibly other places) and store + * them in |buf| and return number of data stored in |buf|. If EOF is + * reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag + * in |*data_flags|. + * + * Sometime it is desirable to avoid copying data into |buf| and let + * application to send data directly. To achieve this, set + * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to + * |*data_flags| (and possibly other flags, just like when we do + * copy), and return the number of bytes to send without copying data + * into |buf|. The library, seeing + * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke + * :type:`nghttp2_send_data_callback`. The application must send + * complete DATA frame in that callback. + * + * If this callback is set by `nghttp2_submit_request2()`, + * `nghttp2_submit_response2()` or `nghttp2_submit_headers()` and + * `nghttp2_submit_data2()` with flag parameter + * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and + * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to + * |*data_flags|, DATA frame will have END_STREAM flag set. Usually, + * this is expected behaviour and all are fine. One exception is send + * trailer fields. You cannot send trailer fields after sending frame + * with END_STREAM set. To avoid this problem, one can set + * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along + * with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the + * library not to set END_STREAM in DATA frame. Then application can + * use `nghttp2_submit_trailer()` to send trailer fields. + * `nghttp2_submit_trailer()` can be called inside this callback. + * + * If the application wants to postpone DATA frames (e.g., + * asynchronous I/O, or reading data blocks for long time), it is + * achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED` + * without reading any data in this invocation. The library removes + * DATA frame from the outgoing queue temporarily. To move back + * deferred DATA frame to outgoing queue, call + * `nghttp2_session_resume_data()`. + * + * By default, |length| is limited to 16KiB at maximum. If peer + * allows larger frames, application can enlarge transmission buffer + * size. See :type:`nghttp2_data_source_read_length_callback` for + * more details. + * + * If the application just wants to return from + * `nghttp2_session_send()` or `nghttp2_session_mem_send2()` without + * sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. + * + * In case of error, there are 2 choices. Returning + * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will + * close the stream by issuing RST_STREAM with + * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. If a different + * error code is desirable, use `nghttp2_submit_rst_stream()` with a + * desired error code and then return + * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. + * Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will + * signal the entire session failure. + */ +typedef nghttp2_ssize (*nghttp2_data_source_read_callback2)( + nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, + uint32_t *data_flags, nghttp2_data_source *source, void *user_data); + +#ifndef NGHTTP2_NO_SSIZE_T /** * @struct * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_data_provider2` instead. + * * This struct represents the data source and the way to read a chunk * of data from it. */ @@ -956,6 +1067,25 @@ typedef struct { nghttp2_data_source_read_callback read_callback; } nghttp2_data_provider; +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @struct + * + * This struct represents the data source and the way to read a chunk + * of data from it. + */ +typedef struct { + /** + * The data source. + */ + nghttp2_data_source source; + /** + * The callback function to read a chunk of data from the |source|. + */ + nghttp2_data_source_read_callback2 read_callback; +} nghttp2_data_provider2; + /** * @struct * @@ -1008,6 +1138,12 @@ typedef enum { /** * @struct * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The structure to specify stream dependency. */ typedef struct { @@ -1042,6 +1178,12 @@ typedef struct { */ size_t padlen; /** + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The priority specification */ nghttp2_priority_spec pri_spec; @@ -1062,6 +1204,12 @@ typedef struct { /** * @struct * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The PRIORITY frame. It has the following members: */ typedef struct { @@ -1305,9 +1453,14 @@ typedef union { nghttp2_extension ext; } nghttp2_frame; +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_send_callback2` instead. + * * Callback function invoked when |session| wants to send data to the * remote peer. The implementation of this function must send at most * |length| bytes of data stored in |data|. The |flags| is currently @@ -1340,6 +1493,44 @@ typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when |session| wants to send data to the + * remote peer. The implementation of this function must send at most + * |length| bytes of data stored in |data|. The |flags| is currently + * not used and always 0. It must return the number of bytes sent if + * it succeeds. If it cannot send any single byte without blocking, + * it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. For + * other errors, it must return + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The + * |user_data| pointer is the third argument passed in to the call to + * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. + * + * This callback is required if the application uses + * `nghttp2_session_send()` to send data to the remote endpoint. If + * the application uses solely `nghttp2_session_mem_send2()` instead, + * this callback function is unnecessary. + * + * To set this callback to :type:`nghttp2_session_callbacks`, use + * `nghttp2_session_callbacks_set_send_callback2()`. + * + * .. note:: + * + * The |length| may be very small. If that is the case, and + * application disables Nagle algorithm (``TCP_NODELAY``), then just + * writing |data| to the network stack leads to very small packet, + * and it is very inefficient. An application should be responsible + * to buffer up small chunks of data as necessary to avoid this + * situation. + */ +typedef nghttp2_ssize (*nghttp2_send_callback2)(nghttp2_session *session, + const uint8_t *data, + size_t length, int flags, + void *user_data); + /** * @functypedef * @@ -1370,7 +1561,7 @@ typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session, * error; if partial frame data has already sent, it is impossible to * send another data in that state, and all we can do is tear down * connection). When data is fully processed, but application wants - * to make `nghttp2_session_mem_send()` or `nghttp2_session_send()` + * to make `nghttp2_session_mem_send2()` or `nghttp2_session_send()` * return immediately without processing next frames, return * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. If application decided to * reset this stream, return @@ -1387,9 +1578,14 @@ typedef int (*nghttp2_send_data_callback)(nghttp2_session *session, nghttp2_data_source *source, void *user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_recv_callback2` instead. + * * Callback function invoked when |session| wants to receive data from * the remote peer. The implementation of this function must read at * most |length| bytes of data and store it in |buf|. The |flags| is @@ -1417,11 +1613,43 @@ typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf, size_t length, int flags, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when |session| wants to receive data from + * the remote peer. The implementation of this function must read at + * most |length| bytes of data and store it in |buf|. The |flags| is + * currently not used and always 0. It must return the number of + * bytes written in |buf| if it succeeds. If it cannot read any + * single byte without blocking, it must return + * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF + * before it reads any single byte, it must return + * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`. For other errors, it must + * return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. + * Returning 0 is treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. The |user_data| + * pointer is the third argument passed in to the call to + * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. + * + * This callback is required if the application uses + * `nghttp2_session_recv()` to receive data from the remote endpoint. + * If the application uses solely `nghttp2_session_mem_recv2()` + * instead, this callback function is unnecessary. + * + * To set this callback to :type:`nghttp2_session_callbacks`, use + * `nghttp2_session_callbacks_set_recv_callback2()`. + */ +typedef nghttp2_ssize (*nghttp2_recv_callback2)(nghttp2_session *session, + uint8_t *buf, size_t length, + int flags, void *user_data); + /** * @functypedef * * Callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when a frame is received. The + * `nghttp2_session_mem_recv2()` when a frame is received. The * |user_data| pointer is the third argument passed in to the call to * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. * @@ -1439,8 +1667,8 @@ typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf, * * The implementation of this function must return 0 if it succeeds. * If nonzero value is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1454,7 +1682,7 @@ typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session, * @functypedef * * Callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is + * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is * received. The error is indicated by the |lib_error_code|, which is * one of the values defined in :type:`nghttp2_error`. When this * callback function is invoked, the library automatically submits @@ -1468,8 +1696,8 @@ typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session, * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1492,19 +1720,19 @@ typedef int (*nghttp2_on_invalid_frame_recv_callback)( * argument passed in to the call to `nghttp2_session_client_new()` or * `nghttp2_session_server_new()`. * - * If the application uses `nghttp2_session_mem_recv()`, it can return - * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make - * `nghttp2_session_mem_recv()` return without processing further + * If the application uses `nghttp2_session_mem_recv2()`, it can + * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make + * `nghttp2_session_mem_recv2()` return without processing further * input bytes. The memory by pointed by the |data| is retained until - * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called. - * The application must retain the input bytes which was used to - * produce the |data| parameter, because it may refer to the memory + * `nghttp2_session_mem_recv2()` or `nghttp2_session_recv()` is + * called. The application must retain the input bytes which was used + * to produce the |data| parameter, because it may refer to the memory * region included in the input bytes. * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error, and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1531,8 +1759,8 @@ typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session, * If there is a fatal error while executing this callback, the * implementation should return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which makes - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * If the other value is returned, it is treated as if @@ -1556,8 +1784,8 @@ typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session, * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1579,8 +1807,8 @@ typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session, * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * `nghttp2_session_get_stream_user_data()` can be used to get @@ -1601,7 +1829,7 @@ typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session, * The reason of closure is indicated by the |error_code|. The * |error_code| is usually one of :enum:`nghttp2_error_code`, but that * is not guaranteed. The stream_user_data, which was specified in - * `nghttp2_submit_request()` or `nghttp2_submit_headers()`, is still + * `nghttp2_submit_request2()` or `nghttp2_submit_headers()`, is still * available in this function. The |user_data| pointer is the third * argument passed in to the call to `nghttp2_session_client_new()` or * `nghttp2_session_server_new()`. @@ -1610,8 +1838,8 @@ typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session, * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_recv()`, `nghttp2_session_mem_recv()`, - * `nghttp2_session_send()`, and `nghttp2_session_mem_send()` + * `nghttp2_session_recv()`, `nghttp2_session_mem_recv2()`, + * `nghttp2_session_send()`, and `nghttp2_session_mem_send2()` * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * @@ -1681,7 +1909,7 @@ typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session, * value is returned, it is treated as if * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. If * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned, - * `nghttp2_session_mem_recv()` function will immediately return + * `nghttp2_session_mem_recv2()` function will immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1726,11 +1954,11 @@ typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session, * performs validation based on HTTP Messaging rule, which is briefly * explained in :ref:`http-messaging` section. * - * If the application uses `nghttp2_session_mem_recv()`, it can return - * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make - * `nghttp2_session_mem_recv()` return without processing further + * If the application uses `nghttp2_session_mem_recv2()`, it can + * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make + * `nghttp2_session_mem_recv2()` return without processing further * input bytes. The memory pointed by |frame|, |name| and |value| - * parameters are retained until `nghttp2_session_mem_recv()` or + * parameters are retained until `nghttp2_session_mem_recv2()` or * `nghttp2_session_recv()` is called. The application must retain * the input bytes which was used to produce these parameters, because * it may refer to the memory region included in the input bytes. @@ -1757,8 +1985,8 @@ typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session, * nonzero value is returned, it is treated as * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1873,9 +2101,15 @@ typedef int (*nghttp2_on_invalid_header_callback2)( nghttp2_session *session, const nghttp2_frame *frame, nghttp2_rcbuf *name, nghttp2_rcbuf *value, uint8_t flags, void *user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_select_padding_callback2` + * instead. + * * Callback function invoked when the library asks application how * many padding bytes are required for the transmission of the * |frame|. The application must choose the total length of payload @@ -1896,9 +2130,39 @@ typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session, size_t max_payloadlen, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @functypedef * + * Callback function invoked when the library asks application how + * many padding bytes are required for the transmission of the + * |frame|. The application must choose the total length of payload + * including padded bytes in range [frame->hd.length, max_payloadlen], + * inclusive. Choosing number not in this range will be treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Returning + * ``frame->hd.length`` means no padding is added. Returning + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. + * + * To set this callback to :type:`nghttp2_session_callbacks`, use + * `nghttp2_session_callbacks_set_select_padding_callback2()`. + */ +typedef nghttp2_ssize (*nghttp2_select_padding_callback2)( + nghttp2_session *session, const nghttp2_frame *frame, size_t max_payloadlen, + void *user_data); + +#ifndef NGHTTP2_NO_SSIZE_T +/** + * @functypedef + * + * .. warning:: + * + * Deprecated. Use + * :type:`nghttp2_data_source_read_length_callback2` instead. + * * Callback function invoked when library wants to get max length of * data to send data to the remote peer. The implementation of this * function should return a value in the following range. [1, @@ -1926,6 +2190,38 @@ typedef ssize_t (*nghttp2_data_source_read_length_callback)( int32_t session_remote_window_size, int32_t stream_remote_window_size, uint32_t remote_max_frame_size, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when library wants to get max length of + * data to send data to the remote peer. The implementation of this + * function should return a value in the following range. [1, + * min(|session_remote_window_size|, |stream_remote_window_size|, + * |remote_max_frame_size|)]. If a value greater than this range is + * returned than the max allow value will be used. Returning a value + * smaller than this range is treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The + * |frame_type| is provided for future extensibility and identifies + * the type of frame (see :type:`nghttp2_frame_type`) for which to get + * the length for. Currently supported frame types are: + * :enum:`nghttp2_frame_type.NGHTTP2_DATA`. + * + * This callback can be used to control the length in bytes for which + * :type:`nghttp2_data_source_read_callback` is allowed to send to the + * remote endpoint. This callback is optional. Returning + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the + * entire session failure. + * + * To set this callback to :type:`nghttp2_session_callbacks`, use + * `nghttp2_session_callbacks_set_data_source_read_length_callback2()`. + */ +typedef nghttp2_ssize (*nghttp2_data_source_read_length_callback2)( + nghttp2_session *session, uint8_t frame_type, int32_t stream_id, + int32_t session_remote_window_size, int32_t stream_remote_window_size, + uint32_t remote_max_frame_size, void *user_data); + /** * @functypedef * @@ -1942,8 +2238,8 @@ typedef ssize_t (*nghttp2_data_source_read_length_callback)( * * The implementation of this function must return 0 if it succeeds. * If nonzero value is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1967,8 +2263,8 @@ typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session, * * If fatal error occurred, application should return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other * values are returned, currently they are treated as * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. @@ -1997,7 +2293,7 @@ typedef int (*nghttp2_on_extension_chunk_recv_callback)( * ``NULL``. The |*payload| is available as ``frame->ext.payload`` in * :type:`nghttp2_on_frame_recv_callback`. Therefore if application * can free that memory inside :type:`nghttp2_on_frame_recv_callback` - * callback. Of course, application has a liberty not ot use + * callback. Of course, application has a liberty not to use * |*payload|, and do its own mechanism to process extension frames. * * To abort processing this extension frame, return @@ -2005,8 +2301,8 @@ typedef int (*nghttp2_on_extension_chunk_recv_callback)( * * If fatal error occurred, application should return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other * values are returned, currently they are treated as * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. @@ -2016,9 +2312,15 @@ typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session, const nghttp2_frame_hd *hd, void *user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_pack_extension_callback2` + * instead. + * * Callback function invoked when library asks the application to pack * extension payload in its wire format. The frame header will be * packed by library. Application must pack payload only. @@ -2049,18 +2351,53 @@ typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session, const nghttp2_frame *frame, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @functypedef * + * Callback function invoked when library asks the application to pack + * extension payload in its wire format. The frame header will be + * packed by library. Application must pack payload only. + * ``frame->ext.payload`` is the object passed to + * `nghttp2_submit_extension()` as payload parameter. Application + * must pack extension payload to the |buf| of its capacity |len| + * bytes. The |len| is at least 16KiB. + * + * The implementation of this function should return the number of + * bytes written into |buf| when it succeeds. + * + * To abort processing this extension frame, return + * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and + * :type:`nghttp2_on_frame_not_send_callback` will be invoked. + * + * If fatal error occurred, application should return + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other + * values are returned, currently they are treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the return + * value is strictly larger than |len|, it is treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. + */ +typedef nghttp2_ssize (*nghttp2_pack_extension_callback2)( + nghttp2_session *session, uint8_t *buf, size_t len, + const nghttp2_frame *frame, void *user_data); + +/** + * @functypedef + * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_error_callback2` instead. + * * Callback function invoked when library provides the error message * intended for human consumption. This callback is solely for * debugging purpose. The |msg| is typically NULL-terminated string * of length |len|. |len| does not include the sentinel NULL * character. * - * This function is deprecated. The new application should use - * :type:`nghttp2_error_callback2`. - * * The format of error message may change between nghttp2 library * versions. The application should not depend on the particular * format. @@ -2143,9 +2480,15 @@ nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr); NGHTTP2_EXTERN void nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_session_callbacks_set_send_callback2()` + * with :type:`nghttp2_send_callback2` instead. + * * Sets callback function invoked when a session wants to send data to * the remote peer. This callback is not necessary if the application * uses solely `nghttp2_session_mem_send()` to serialize data to @@ -2154,9 +2497,28 @@ nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks); NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback( nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * + * Sets callback function invoked when a session wants to send data to + * the remote peer. This callback is not necessary if the application + * uses solely `nghttp2_session_mem_send2()` to serialize data to + * transmit. + */ +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback2( + nghttp2_session_callbacks *cbs, nghttp2_send_callback2 send_callback); + +#ifndef NGHTTP2_NO_SSIZE_T +/** + * @function + * + * .. warning:: + * + * Deprecated. Use `nghttp2_session_callbacks_set_recv_callback2()` + * with :type:`nghttp2_recv_callback2` instead. + * * Sets callback function invoked when the a session wants to receive * data from the remote peer. This callback is not necessary if the * application uses solely `nghttp2_session_mem_recv()` to process @@ -2165,11 +2527,24 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback( NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback( nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Sets callback function invoked when the a session wants to receive + * data from the remote peer. This callback is not necessary if the + * application uses solely `nghttp2_session_mem_recv2()` to process + * received data. + */ +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback2( + nghttp2_session_callbacks *cbs, nghttp2_recv_callback2 recv_callback); + /** * @function * * Sets callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when a frame is received. + * `nghttp2_session_mem_recv2()` when a frame is received. */ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback( nghttp2_session_callbacks *cbs, @@ -2179,7 +2554,7 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback( * @function * * Sets callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is + * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is * received. */ NGHTTP2_EXTERN void @@ -2290,9 +2665,16 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2( nghttp2_session_callbacks *cbs, nghttp2_on_invalid_header_callback2 on_invalid_header_callback2); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use + * `nghttp2_session_callbacks_set_select_padding_callback2()` with + * :type:`nghttp2_select_padding_callback2` instead. + * * Sets callback function invoked when the library asks application * how many padding bytes are required for the transmission of the * given frame. @@ -2301,9 +2683,29 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback( nghttp2_session_callbacks *cbs, nghttp2_select_padding_callback select_padding_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * + * Sets callback function invoked when the library asks application + * how many padding bytes are required for the transmission of the + * given frame. + */ +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_select_padding_callback2 select_padding_callback); + +#ifndef NGHTTP2_NO_SSIZE_T +/** + * @function + * + * .. warning:: + * + * Deprecated. Use + * `nghttp2_session_callbacks_set_data_source_read_length_callback2()` + * with :type:`nghttp2_data_source_read_length_callback2` instead. + * * Sets callback function determine the length allowed in * :type:`nghttp2_data_source_read_callback`. */ @@ -2312,6 +2714,19 @@ nghttp2_session_callbacks_set_data_source_read_length_callback( nghttp2_session_callbacks *cbs, nghttp2_data_source_read_length_callback data_source_read_length_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Sets callback function determine the length allowed in + * :type:`nghttp2_data_source_read_callback2`. + */ +NGHTTP2_EXTERN void +nghttp2_session_callbacks_set_data_source_read_length_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_data_source_read_length_callback2 data_source_read_length_callback); + /** * @function * @@ -2326,15 +2741,22 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback( * * Sets callback function invoked when * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in - * :type:`nghttp2_data_source_read_callback` to avoid data copy. + * :type:`nghttp2_data_source_read_callback2` to avoid data copy. */ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback( nghttp2_session_callbacks *cbs, nghttp2_send_data_callback send_data_callback); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use + * `nghttp2_session_callbacks_set_pack_extension_callback2()` with + * :type:`nghttp2_pack_extension_callback2` instead. + * * Sets callback function invoked when the library asks the * application to pack extension frame payload in wire format. */ @@ -2342,6 +2764,18 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback( nghttp2_session_callbacks *cbs, nghttp2_pack_extension_callback pack_extension_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Sets callback function invoked when the library asks the + * application to pack extension frame payload in wire format. + */ +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_pack_extension_callback2 pack_extension_callback); + /** * @function * @@ -2366,12 +2800,15 @@ nghttp2_session_callbacks_set_on_extension_chunk_recv_callback( /** * @function * + * .. warning:: + * + * Deprecated. Use + * `nghttp2_session_callbacks_set_error_callback2()` with + * :type:`nghttp2_error_callback2` instead. + * * Sets callback function invoked when library tells error message to * the application. * - * This function is deprecated. The new application should use - * `nghttp2_session_callbacks_set_error_callback2()`. - * * If both :type:`nghttp2_error_callback` and * :type:`nghttp2_error_callback2` are set, the latter takes * precedence. @@ -2568,7 +3005,7 @@ nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option, * * If this option is not used or used with zero value, if MAGIC does * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()` - * and `nghttp2_session_mem_recv()` will return error + * and `nghttp2_session_mem_recv2()` will return error * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal * error. */ @@ -2773,6 +3210,17 @@ NGHTTP2_EXTERN void nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, uint64_t burst, uint64_t rate); +/** + * @function + * + * This function sets the maximum number of CONTINUATION frames + * following an incoming HEADER frame. If more than those frames are + * received, the remote endpoint is considered to be misbehaving and + * session will be closed. The default value is 8. + */ +NGHTTP2_EXTERN void nghttp2_option_set_max_continuations(nghttp2_option *option, + size_t val); + /** * @function * @@ -2781,7 +3229,7 @@ nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, * does not store |callbacks|. The |user_data| is an arbitrary user * supplied data, which will be passed to the callback functions. * - * The :type:`nghttp2_send_callback` must be specified. If the + * The :type:`nghttp2_send_callback2` must be specified. If the * application code uses `nghttp2_session_recv()`, the * :type:`nghttp2_recv_callback` must be specified. The other members * of |callbacks| can be ``NULL``. @@ -2807,7 +3255,7 @@ nghttp2_session_client_new(nghttp2_session **session_ptr, * does not store |callbacks|. The |user_data| is an arbitrary user * supplied data, which will be passed to the callback functions. * - * The :type:`nghttp2_send_callback` must be specified. If the + * The :type:`nghttp2_send_callback2` must be specified. If the * application code uses `nghttp2_session_recv()`, the * :type:`nghttp2_recv_callback` must be specified. The other members * of |callbacks| can be ``NULL``. @@ -2943,7 +3391,7 @@ NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); * This function retrieves the highest prioritized frame from the * outbound queue and sends it to the remote peer. It does this as * many times as possible until the user callback - * :type:`nghttp2_send_callback` returns + * :type:`nghttp2_send_callback2` returns * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`, the outbound queue * becomes empty or flow control is triggered (remote window size * becomes depleted or maximum number of concurrent streams is @@ -2973,7 +3421,7 @@ NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort * the following steps. * - * 8. :type:`nghttp2_send_callback` is invoked one or more times to + * 8. :type:`nghttp2_send_callback2` is invoked one or more times to * send the frame. * * 9. :type:`nghttp2_on_frame_send_callback` is invoked. @@ -2992,9 +3440,14 @@ NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); */ NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_session_mem_send2()` instead. + * * Returns the serialized data to send. * * This function behaves like `nghttp2_session_send()` except that it @@ -3034,6 +3487,50 @@ NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session); NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session, const uint8_t **data_ptr); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Returns the serialized data to send. + * + * This function behaves like `nghttp2_session_send()` except that it + * does not use :type:`nghttp2_send_callback2` to transmit data. + * Instead, it assigns the pointer to the serialized data to the + * |*data_ptr| and returns its length. The other callbacks are called + * in the same way as they are in `nghttp2_session_send()`. + * + * If no data is available to send, this function returns 0. + * + * This function may not return all serialized data in one invocation. + * To get all data, call this function repeatedly until it returns 0 + * or one of negative error codes. + * + * The assigned |*data_ptr| is valid until the next call of + * `nghttp2_session_mem_send2()` or `nghttp2_session_send()`. + * + * The caller must send all data before sending the next chunk of + * data. + * + * This function returns the length of the data pointed by the + * |*data_ptr| if it succeeds, or one of the following negative error + * codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * + * .. note:: + * + * This function may produce very small byte string. If that is the + * case, and application disables Nagle algorithm (``TCP_NODELAY``), + * then writing this small chunk leads to very small packet, and it + * is very inefficient. An application should be responsible to + * buffer up small chunks of data as necessary to avoid this + * situation. + */ +NGHTTP2_EXTERN nghttp2_ssize +nghttp2_session_mem_send2(nghttp2_session *session, const uint8_t **data_ptr); + /** * @function * @@ -3104,9 +3601,14 @@ NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session, */ NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_session_mem_recv2()` instead. + * * Processes data |in| as an input from the remote endpoint. The * |inlen| indicates the number of bytes to receive in the |in|. * @@ -3145,6 +3647,49 @@ NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, size_t inlen); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Processes data |in| as an input from the remote endpoint. The + * |inlen| indicates the number of bytes to receive in the |in|. + * + * This function behaves like `nghttp2_session_recv()` except that it + * does not use :type:`nghttp2_recv_callback` to receive data; the + * |in| is the only data for the invocation of this function. If all + * bytes are processed, this function returns. The other callbacks + * are called in the same way as they are in `nghttp2_session_recv()`. + * + * In the current implementation, this function always tries to + * processes |inlen| bytes of input data unless either an error occurs or + * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from + * :type:`nghttp2_on_header_callback` or + * :type:`nghttp2_on_data_chunk_recv_callback`. If + * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value + * includes the number of bytes which was used to produce the data or + * frame for the callback. + * + * This function returns the number of processed bytes, or one of the + * following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` + * The callback function failed. + * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC` + * Invalid client magic was detected. This error only returns + * when |session| was configured as server and + * `nghttp2_option_set_no_recv_client_magic()` is not used with + * nonzero value. + * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED` + * Flooding was detected in this HTTP/2 session, and it must be + * closed. This is most likely caused by misbehaviour of peer. + */ +NGHTTP2_EXTERN nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, + const uint8_t *in, + size_t inlen); + /** * @function * @@ -3190,7 +3735,7 @@ NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session); * @function * * Returns stream_user_data for the stream |stream_id|. The - * stream_user_data is provided by `nghttp2_submit_request()`, + * stream_user_data is provided by `nghttp2_submit_request2()`, * `nghttp2_submit_headers()` or * `nghttp2_session_set_stream_user_data()`. Unless it is set using * `nghttp2_session_set_stream_user_data()`, if the stream is @@ -3626,6 +4171,13 @@ NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session, /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return 0 without doing anything. + * * Changes priority of existing stream denoted by |stream_id|. The * new priority specification is |pri_spec|. * @@ -3665,6 +4217,13 @@ nghttp2_session_change_stream_priority(nghttp2_session *session, /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return 0 without doing anything. + * * Creates idle stream with the given |stream_id|, and priority * |pri_spec|. * @@ -3715,10 +4274,6 @@ nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, /** * @function * - * Performs post-process of HTTP Upgrade request. This function can - * be called from both client and server, but the behavior is very - * different in each other. - * * .. warning:: * * This function is deprecated in favor of @@ -3730,6 +4285,10 @@ nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, * HEAD is used in request, the length of response body must be 0 * regardless of value included in content-length header field. * + * Performs post-process of HTTP Upgrade request. This function can + * be called from both client and server, but the behavior is very + * different in each other. + * * If called from client side, the |settings_payload| must be the * value sent in ``HTTP2-Settings`` header field and must be decoded * by base64url decoder. The |settings_payloadlen| is the length of @@ -3809,6 +4368,37 @@ NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session, int head_request, void *stream_user_data); +#ifndef NGHTTP2_NO_SSIZE_T +/** + * @function + * + * .. warning:: + * + * Deprecated. Use `nghttp2_pack_settings_payload2()` instead. + * + * Serializes the SETTINGS values |iv| in the |buf|. The size of the + * |buf| is specified by |buflen|. The number of entries in the |iv| + * array is given by |niv|. The required space in |buf| for the |niv| + * entries is ``6*niv`` bytes and if the given buffer is too small, an + * error is returned. This function is used mainly for creating a + * SETTINGS payload to be sent with the ``HTTP2-Settings`` header + * field in an HTTP Upgrade request. The data written in |buf| is NOT + * base64url encoded and the application is responsible for encoding. + * + * This function returns the number of bytes written in |buf|, or one + * of the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * The |iv| contains duplicate settings ID or invalid value. + * + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` + * The provided |buflen| size is too small to hold the output. + */ +NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload( + uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv); + +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * @@ -3830,7 +4420,7 @@ NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session, * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` * The provided |buflen| size is too small to hold the output. */ -NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload( +NGHTTP2_EXTERN nghttp2_ssize nghttp2_pack_settings_payload2( uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv); /** @@ -3854,6 +4444,12 @@ NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * Initializes |pri_spec| with the |stream_id| of the stream to depend * on with |weight| and its exclusive flag. If |exclusive| is * nonzero, exclusive flag is set. @@ -3868,6 +4464,12 @@ NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec, /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * Initializes |pri_spec| with the default values. The default values * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and * exclusive = 0. @@ -3878,18 +4480,29 @@ nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * Returns nonzero if the |pri_spec| is filled with default values. */ NGHTTP2_EXTERN int nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_submit_request2()` instead. + * * Submits HEADERS frame and optionally one or more DATA frames. * - * The |pri_spec| is priority specification of this request. ``NULL`` - * means the default priority (see + * The |pri_spec| is a deprecated priority specification of this + * request. ``NULL`` means the default priority (see * `nghttp2_priority_spec_default_init()`). To specify the priority, * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, * this function will copy its data members. @@ -3970,9 +4583,105 @@ NGHTTP2_EXTERN int32_t nghttp2_submit_request( const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd, void *stream_user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * + * Submits HEADERS frame and optionally one or more DATA frames. + * + * The |pri_spec| is a deprecated priority specification of this + * request. ``NULL`` means the default priority (see + * `nghttp2_priority_spec_default_init()`). To specify the priority, + * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, + * this function will copy its data members. In the future release + * after the end of 2024, this function will ignore |pri_spec| and + * behave as if ``NULL`` is given. + * + * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, + * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` + * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes + * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than + * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes + * :macro:`NGHTTP2_MAX_WEIGHT`. + * + * If + * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` + * of value of 1 is received by a remote endpoint, |pri_spec| is + * ignored, and treated as if ``NULL`` is specified. + * + * The |nva| is an array of name/value pair :type:`nghttp2_nv` with + * |nvlen| elements. The application is responsible to include + * required pseudo-header fields (header field whose name starts with + * ":") in |nva| and must place pseudo-headers before regular header + * fields. + * + * This function creates copies of all name/value pairs in |nva|. It + * also lower-cases all names in |nva|. The order of elements in + * |nva| is preserved. For header fields with + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, + * header field name and value are not copied respectively. With + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application + * is responsible to pass header field name in lowercase. The + * application should maintain the references to them until + * :type:`nghttp2_on_frame_send_callback` or + * :type:`nghttp2_on_frame_not_send_callback` is called. + * + * HTTP/2 specification has requirement about header fields in the + * request HEADERS. See the specification for more details. + * + * If |data_prd| is not ``NULL``, it provides data which will be sent + * in subsequent DATA frames. In this case, a method that allows + * request message bodies + * (https://tools.ietf.org/html/rfc7231#section-4) must be specified + * with ``:method`` key in |nva| (e.g. ``POST``). This function does + * not take ownership of the |data_prd|. The function copies the + * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have + * END_STREAM set. The |stream_user_data| is data associated to the + * stream opened by this request and can be an arbitrary pointer, + * which can be retrieved later by + * `nghttp2_session_get_stream_user_data()`. + * + * This function returns assigned stream ID if it succeeds, or one of + * the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` + * No stream ID is available because maximum stream ID was + * reached. + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * Trying to depend on itself (new stream ID equals + * ``pri_spec->stream_id``). + * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` + * The |session| is server session. + * + * .. warning:: + * + * This function returns assigned stream ID if it succeeds. But + * that stream is not created yet. The application must not submit + * frame to that stream ID before + * :type:`nghttp2_before_frame_send_callback` is called for this + * frame. This means `nghttp2_session_get_stream_user_data()` does + * not work before the callback. But + * `nghttp2_session_set_stream_user_data()` handles this situation + * specially, and it can set data to a stream during this period. + * + */ +NGHTTP2_EXTERN int32_t nghttp2_submit_request2( + nghttp2_session *session, const nghttp2_priority_spec *pri_spec, + const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider2 *data_prd, + void *stream_user_data); + +#ifndef NGHTTP2_NO_SSIZE_T +/** + * @function + * + * .. warning:: + * + * Deprecated. Use `nghttp2_submit_response2()` instead. + * * Submits response HEADERS frame and optionally one or more DATA * frames against the stream |stream_id|. * @@ -4039,6 +4748,77 @@ nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Submits response HEADERS frame and optionally one or more DATA + * frames against the stream |stream_id|. + * + * The |nva| is an array of name/value pair :type:`nghttp2_nv` with + * |nvlen| elements. The application is responsible to include + * required pseudo-header fields (header field whose name starts with + * ":") in |nva| and must place pseudo-headers before regular header + * fields. + * + * This function creates copies of all name/value pairs in |nva|. It + * also lower-cases all names in |nva|. The order of elements in + * |nva| is preserved. For header fields with + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, + * header field name and value are not copied respectively. With + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application + * is responsible to pass header field name in lowercase. The + * application should maintain the references to them until + * :type:`nghttp2_on_frame_send_callback` or + * :type:`nghttp2_on_frame_not_send_callback` is called. + * + * HTTP/2 specification has requirement about header fields in the + * response HEADERS. See the specification for more details. + * + * If |data_prd| is not ``NULL``, it provides data which will be sent + * in subsequent DATA frames. This function does not take ownership + * of the |data_prd|. The function copies the members of the + * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have + * END_STREAM flag set. + * + * This method can be used as normal HTTP response and push response. + * When pushing a resource using this function, the |session| must be + * configured using `nghttp2_session_server_new()` or its variants and + * the target stream denoted by the |stream_id| must be reserved using + * `nghttp2_submit_push_promise()`. + * + * To send non-final response headers (e.g., HTTP status 101), don't + * use this function because this function half-closes the outbound + * stream. Instead, use `nghttp2_submit_headers()` for this purpose. + * + * This function returns 0 if it succeeds, or one of the following + * negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * The |stream_id| is 0. + * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` + * DATA or HEADERS has been already submitted and not fully + * processed yet. Normally, this does not happen, but when + * application wrongly calls `nghttp2_submit_response2()` twice, + * this may happen. + * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` + * The |session| is client session. + * + * .. warning:: + * + * Calling this function twice for the same stream ID may lead to + * program crash. It is generally considered to a programming error + * to commit response twice. + */ +NGHTTP2_EXTERN int +nghttp2_submit_response2(nghttp2_session *session, int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider2 *data_prd); + /** * @function * @@ -4064,22 +4844,23 @@ nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, * DATA without END_STREAM flat set. The library does not enforce * this requirement, and applications should do this for themselves. * If `nghttp2_submit_trailer()` is called before any response HEADERS - * submission (usually by `nghttp2_submit_response()`), the content of - * |nva| will be sent as response headers, which will result in error. + * submission (usually by `nghttp2_submit_response2()`), the content + * of |nva| will be sent as response headers, which will result in + * error. * * This function has the same effect with `nghttp2_submit_headers()`, * with flags = :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` and both * pri_spec and stream_user_data to NULL. * - * To submit trailer fields after `nghttp2_submit_response()` is + * To submit trailer fields after `nghttp2_submit_response2()` is * called, the application has to specify - * :type:`nghttp2_data_provider` to `nghttp2_submit_response()`. - * Inside of :type:`nghttp2_data_source_read_callback`, when setting + * :type:`nghttp2_data_provider2` to `nghttp2_submit_response2()`. + * Inside of :type:`nghttp2_data_source_read_callback2`, when setting * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF`, also set * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM`. After * that, the application can send trailer fields using * `nghttp2_submit_trailer()`. `nghttp2_submit_trailer()` can be used - * inside :type:`nghttp2_data_source_read_callback`. + * inside :type:`nghttp2_data_source_read_callback2`. * * This function returns 0 if it succeeds and |stream_id| is -1. * Otherwise, this function returns 0 if it succeeds, or one of the @@ -4114,11 +4895,13 @@ NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, * assigned stream ID will be returned. Otherwise, specify stream ID * in |stream_id|. * - * The |pri_spec| is priority specification of this request. ``NULL`` - * means the default priority (see + * The |pri_spec| is a deprecated priority specification of this + * request. ``NULL`` means the default priority (see * `nghttp2_priority_spec_default_init()`). To specify the priority, * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, - * this function will copy its data members. + * this function will copy its data members. In the future release + * after the end of 2024, this function will ignore |pri_spec| and + * behave as if ``NULL`` is given. * * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` @@ -4156,8 +4939,8 @@ NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, * * This function is low-level in a sense that the application code can * specify flags directly. For usual HTTP request, - * `nghttp2_submit_request()` is useful. Likewise, for HTTP response, - * prefer `nghttp2_submit_response()`. + * `nghttp2_submit_request2()` is useful. Likewise, for HTTP + * response, prefer `nghttp2_submit_response2()`. * * This function returns newly assigned stream ID if it succeeds and * |stream_id| is -1. Otherwise, this function returns 0 if it @@ -4192,9 +4975,14 @@ NGHTTP2_EXTERN int32_t nghttp2_submit_headers( const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, void *stream_user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_submit_data2()` instead. + * * Submits one or more DATA frames to the stream |stream_id|. The * data to be sent are provided by |data_prd|. If |flags| contains * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame @@ -4237,19 +5025,73 @@ NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, int32_t stream_id, const nghttp2_data_provider *data_prd); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * + * Submits one or more DATA frames to the stream |stream_id|. The + * data to be sent are provided by |data_prd|. If |flags| contains + * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame + * has END_STREAM flag set. + * + * This function does not take ownership of the |data_prd|. The + * function copies the members of the |data_prd|. + * + * This function returns 0 if it succeeds, or one of the following + * negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` + * DATA or HEADERS has been already submitted and not fully + * processed yet. + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * The |stream_id| is 0. + * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED` + * The stream was already closed; or the |stream_id| is invalid. + * + * .. note:: + * + * Currently, only one DATA or HEADERS is allowed for a stream at a + * time. Submitting these frames more than once before first DATA + * or HEADERS is finished results in + * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code. The + * earliest callback which tells that previous frame is done is + * :type:`nghttp2_on_frame_send_callback`. In side that callback, + * new data can be submitted using `nghttp2_submit_data2()`. Of + * course, all data except for last one must not have + * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|. + * This sounds a bit complicated, and we recommend to use + * `nghttp2_submit_request2()` and `nghttp2_submit_response2()` to + * avoid this cascading issue. The experience shows that for HTTP + * use, these two functions are enough to implement both client and + * server. + */ +NGHTTP2_EXTERN int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider2 *data_prd); + +/** + * @function + * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return 0 without doing anything. + * * Submits PRIORITY frame to change the priority of stream |stream_id| * to the priority specification |pri_spec|. * * The |flags| is currently ignored and should be * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. * - * The |pri_spec| is priority specification of this request. ``NULL`` - * is not allowed for this function. To specify the priority, use - * `nghttp2_priority_spec_init()`. This function will copy its data - * members. + * The |pri_spec| is a deprecated priority specification of this + * request. ``NULL`` is not allowed for this function. To specify the + * priority, use `nghttp2_priority_spec_init()`. This function will + * copy its data members. * * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` @@ -4429,7 +5271,7 @@ NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session, * The client side is not allowed to use this function. * * To submit response headers and data, use - * `nghttp2_submit_response()`. + * `nghttp2_submit_response2()`. * * This function returns assigned promised stream ID if it succeeds, * or one of the following negative error codes: @@ -4568,10 +5410,11 @@ nghttp2_session_get_last_proc_stream_id(nghttp2_session *session); * reasons are: session is server; stream ID has been spent; GOAWAY * has been sent or received. * - * The application can call `nghttp2_submit_request()` without - * consulting this function. In that case, `nghttp2_submit_request()` - * may return error. Or, request is failed to sent, and - * :type:`nghttp2_on_stream_close_callback` is called. + * The application can call `nghttp2_submit_request2()` without + * consulting this function. In that case, + * `nghttp2_submit_request2()` may return error. Or, request is + * failed to sent, and :type:`nghttp2_on_stream_close_callback` is + * called. */ NGHTTP2_EXTERN int nghttp2_session_check_request_allowed(nghttp2_session *session); @@ -4673,11 +5516,11 @@ nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, * Application can pass arbitrary frame flags and stream ID in |flags| * and |stream_id| respectively. The |payload| is opaque pointer, and * it can be accessible though ``frame->ext.payload`` in - * :type:`nghttp2_pack_extension_callback`. The library will not own + * :type:`nghttp2_pack_extension_callback2`. The library will not own * passed |payload| pointer. * - * The application must set :type:`nghttp2_pack_extension_callback` - * using `nghttp2_session_callbacks_set_pack_extension_callback()`. + * The application must set :type:`nghttp2_pack_extension_callback2` + * using `nghttp2_session_callbacks_set_pack_extension_callback2()`. * * The application should retain the memory pointed by |payload| until * the transmission of extension frame is done (which is indicated by @@ -4685,7 +5528,7 @@ nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`). * If application does not touch this memory region after packing it * into a wire format, application can free it inside - * :type:`nghttp2_pack_extension_callback`. + * :type:`nghttp2_pack_extension_callback2`. * * The standard HTTP/2 frame cannot be sent with this function, so * |type| must be strictly grater than 0x9. Otherwise, this function @@ -4696,7 +5539,7 @@ nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, * negative error codes: * * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` - * If :type:`nghttp2_pack_extension_callback` is not set. + * If :type:`nghttp2_pack_extension_callback2` is not set. * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` * If |type| specifies standard HTTP/2 frame type. The frame * types in the rage [0x0, 0x9], both inclusive, are standard @@ -4958,6 +5801,55 @@ NGHTTP2_EXTERN int nghttp2_session_change_extpri_stream_priority( nghttp2_session *session, int32_t stream_id, const nghttp2_extpri *extpri, int ignore_client_signal); +/** + * @function + * + * Stores the stream priority of the existing stream denoted by + * |stream_id| in the object pointed by |extpri|. This function is + * meant to be used by server for :rfc:`9218` extensible + * prioritization scheme. + * + * If |session| is initialized as client, this function returns + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. + * + * If + * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` + * of value of 1 is not submitted via `nghttp2_submit_settings()`, + * this function does nothing and returns 0. + * + * This function returns 0 if it succeeds, or one of the following + * negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` + * The |session| is initialized as client. + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * |stream_id| is zero; or a stream denoted by |stream_id| is not + * found. + */ +NGHTTP2_EXTERN int nghttp2_session_get_extpri_stream_priority( + nghttp2_session *session, nghttp2_extpri *extpri, int32_t stream_id); + +/** + * @function + * + * Parses Priority header field value pointed by |value| of length + * |len|, and stores the result in the object pointed by |extpri|. + * Priority header field is defined in :rfc:`9218`. + * + * This function does not initialize the object pointed by |extpri| + * before storing the result. It only assigns the values that the + * parser correctly extracted to fields. + * + * This function returns 0 if it succeeds, or one of the following + * negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * Failed to parse the header field value. + */ +NGHTTP2_EXTERN int nghttp2_extpri_parse_priority(nghttp2_extpri *extpri, + const uint8_t *value, + size_t len); + /** * @function * @@ -4973,11 +5865,14 @@ NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs, /** * @function * - * A helper function for dealing with NPN in client side or ALPN in - * server side. The |in| contains peer's protocol list in preferable - * order. The format of |in| is length-prefixed and not - * null-terminated. For example, ``h2`` and - * ``http/1.1`` stored in |in| like this:: + * .. warning:: + * + * Deprecated. Use `nghttp2_select_alpn` instead. + * + * A helper function for dealing with ALPN in server side. The |in| + * contains peer's protocol list in preferable order. The format of + * |in| is length-prefixed and not null-terminated. For example, + * ``h2`` and ``http/1.1`` stored in |in| like this:: * * in[0] = 2 * in[1..2] = "h2" @@ -5002,20 +5897,18 @@ NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs, * * For ALPN, refer to https://tools.ietf.org/html/rfc7301 * - * See http://technotes.googlecode.com/git/nextprotoneg.html for more - * details about NPN. + * To use this method you should do something like:: * - * For NPN, to use this method you should do something like:: - * - * static int select_next_proto_cb(SSL* ssl, - * unsigned char **out, + * static int alpn_select_proto_cb(SSL* ssl, + * const unsigned char **out, * unsigned char *outlen, * const unsigned char *in, * unsigned int inlen, * void *arg) * { * int rv; - * rv = nghttp2_select_next_protocol(out, outlen, in, inlen); + * rv = nghttp2_select_next_protocol((unsigned char**)out, outlen, + * in, inlen); * if (rv == -1) { * return SSL_TLSEXT_ERR_NOACK; * } @@ -5025,7 +5918,7 @@ NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs, * return SSL_TLSEXT_ERR_OK; * } * ... - * SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj); + * SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj); * */ NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out, @@ -5033,6 +5926,65 @@ NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out, const unsigned char *in, unsigned int inlen); +/** + * @function + * + * A helper function for dealing with ALPN in server side. The |in| + * contains peer's protocol list in preferable order. The format of + * |in| is length-prefixed and not null-terminated. For example, + * ``h2`` and ``http/1.1`` stored in |in| like this:: + * + * in[0] = 2 + * in[1..2] = "h2" + * in[3] = 8 + * in[4..11] = "http/1.1" + * inlen = 12 + * + * The selection algorithm is as follows: + * + * 1. If peer's list contains HTTP/2 protocol the library supports, + * it is selected and returns 1. The following step is not taken. + * + * 2. If peer's list contains ``http/1.1``, this function selects + * ``http/1.1`` and returns 0. The following step is not taken. + * + * 3. This function selects nothing and returns -1 (So called + * non-overlap case). In this case, |out| and |outlen| are left + * untouched. + * + * Selecting ``h2`` means that ``h2`` is written into |*out| and its + * length (which is 2) is assigned to |*outlen|. + * + * For ALPN, refer to https://tools.ietf.org/html/rfc7301 + * + * To use this method you should do something like:: + * + * static int alpn_select_proto_cb(SSL* ssl, + * const unsigned char **out, + * unsigned char *outlen, + * const unsigned char *in, + * unsigned int inlen, + * void *arg) + * { + * int rv; + * rv = nghttp2_select_alpn(out, outlen, in, inlen); + * if (rv == -1) { + * return SSL_TLSEXT_ERR_NOACK; + * } + * if (rv == 1) { + * ((MyType*)arg)->http2_selected = 1; + * } + * return SSL_TLSEXT_ERR_OK; + * } + * ... + * SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj); + * + */ +NGHTTP2_EXTERN int nghttp2_select_alpn(const unsigned char **out, + unsigned char *outlen, + const unsigned char *in, + unsigned int inlen); + /** * @function * @@ -5208,9 +6160,14 @@ NGHTTP2_EXTERN int nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater, size_t settings_max_dynamic_table_size); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_hd_deflate_hd2()` instead. + * * Deflates the |nva|, which has the |nvlen| name/value pairs, into * the |buf| of length |buflen|. * @@ -5240,10 +6197,48 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, const nghttp2_nv *nva, size_t nvlen); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * * Deflates the |nva|, which has the |nvlen| name/value pairs, into + * the |buf| of length |buflen|. + * + * If |buf| is not large enough to store the deflated header block, + * this function fails with + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller + * should use `nghttp2_hd_deflate_bound()` to know the upper bound of + * buffer size required to deflate given header name/value pairs. + * + * Once this function fails, subsequent call of this function always + * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. + * + * After this function returns, it is safe to delete the |nva|. + * + * This function returns the number of bytes written to |buf| if it + * succeeds, or one of the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` + * Deflation process has failed. + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` + * The provided |buflen| size is too small to hold the output. + */ +NGHTTP2_EXTERN nghttp2_ssize +nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, uint8_t *buf, + size_t buflen, const nghttp2_nv *nva, size_t nvlen); + +#ifndef NGHTTP2_NO_SSIZE_T +/** + * @function + * + * .. warning:: + * + * Deprecated. Use `nghttp2_hd_deflate_hd_vec2()` instead. + * + * Deflates the |nva|, which has the |nvlen| name/value pairs, into * the |veclen| size of buf vector |vec|. The each size of buffer * must be set in len field of :type:`nghttp2_vec`. If and only if * one chunk is filled up completely, next chunk will be used. If @@ -5274,6 +6269,40 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater, const nghttp2_nv *nva, size_t nvlen); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Deflates the |nva|, which has the |nvlen| name/value pairs, into + * the |veclen| size of buf vector |vec|. The each size of buffer + * must be set in len field of :type:`nghttp2_vec`. If and only if + * one chunk is filled up completely, next chunk will be used. If + * |vec| is not large enough to store the deflated header block, this + * function fails with + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller + * should use `nghttp2_hd_deflate_bound()` to know the upper bound of + * buffer size required to deflate given header name/value pairs. + * + * Once this function fails, subsequent call of this function always + * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. + * + * After this function returns, it is safe to delete the |nva|. + * + * This function returns the number of bytes written to |vec| if it + * succeeds, or one of the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` + * Deflation process has failed. + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` + * The provided |buflen| size is too small to hold the output. + */ +NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_deflate_hd_vec2( + nghttp2_hd_deflater *deflater, const nghttp2_vec *vec, size_t veclen, + const nghttp2_nv *nva, size_t nvlen); + /** * @function * @@ -5387,7 +6416,7 @@ NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater); * This function must not be called while header block is being * inflated. In other words, this function must be called after * initialization of |inflater|, but before calling - * `nghttp2_hd_inflate_hd2()`, or after + * `nghttp2_hd_inflate_hd3()`, or after * `nghttp2_hd_inflate_end_headers()`. Otherwise, * `NGHTTP2_ERR_INVALID_STATE` was returned. * @@ -5425,6 +6454,7 @@ typedef enum { NGHTTP2_HD_INFLATE_EMIT = 0x02 } nghttp2_hd_inflate_flag; +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * @@ -5512,9 +6542,16 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, int *inflate_flags, uint8_t *in, size_t inlen, int in_final); +#endif /* NGHTTP2_NO_SSIZE_T */ + +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_hd_inflate_hd3()` instead. + * * Inflates name/value block stored in |in| with length |inlen|. This * function performs decompression. For each successful emission of * header name/value pair, @@ -5601,6 +6638,95 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, const uint8_t *in, size_t inlen, int in_final); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Inflates name/value block stored in |in| with length |inlen|. This + * function performs decompression. For each successful emission of + * header name/value pair, + * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in + * |*inflate_flags| and name/value pair is assigned to the |nv_out| + * and the function returns. The caller must not free the members of + * |nv_out|. + * + * The |nv_out| may include pointers to the memory region in the |in|. + * The caller must retain the |in| while the |nv_out| is used. + * + * The application should call this function repeatedly until the + * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and + * return value is non-negative. If that happens, all given input + * data (|inlen| bytes) are processed successfully. Then the + * application must call `nghttp2_hd_inflate_end_headers()` to prepare + * for the next header block input. + * + * In other words, if |in_final| is nonzero, and this function returns + * |inlen|, you can assert that + * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in + * |*inflate_flags|. + * + * The caller can feed complete compressed header block. It also can + * feed it in several chunks. The caller must set |in_final| to + * nonzero if the given input is the last block of the compressed + * header. + * + * This function returns the number of bytes processed if it succeeds, + * or one of the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` + * Inflation process has failed. + * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR` + * The header field name or value is too large. + * + * Example follows:: + * + * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, + * uint8_t *in, size_t inlen, int final) + * { + * nghttp2_ssize rv; + * + * for(;;) { + * nghttp2_nv nv; + * int inflate_flags = 0; + * + * rv = nghttp2_hd_inflate_hd3(hd_inflater, &nv, &inflate_flags, + * in, inlen, final); + * + * if(rv < 0) { + * fprintf(stderr, "inflate failed with error code %td", rv); + * return -1; + * } + * + * in += rv; + * inlen -= rv; + * + * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { + * fwrite(nv.name, nv.namelen, 1, stderr); + * fprintf(stderr, ": "); + * fwrite(nv.value, nv.valuelen, 1, stderr); + * fprintf(stderr, "\n"); + * } + * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { + * nghttp2_hd_inflate_end_headers(hd_inflater); + * break; + * } + * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && + * inlen == 0) { + * break; + * } + * } + * + * return 0; + * } + * + */ +NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_inflate_hd3( + nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, + const uint8_t *in, size_t inlen, int in_final); + /** * @function * @@ -5674,8 +6800,8 @@ typedef struct nghttp2_stream nghttp2_stream; * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|. * * Unless |stream_id| == 0, the returned pointer is valid until next - * call of `nghttp2_session_send()`, `nghttp2_session_mem_send()`, - * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv()`. + * call of `nghttp2_session_send()`, `nghttp2_session_mem_send2()`, + * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv2()`. */ NGHTTP2_EXTERN nghttp2_stream * nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id); @@ -5729,6 +6855,12 @@ nghttp2_stream_get_state(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * Returns root of dependency tree, which is imaginary stream with * stream ID 0. The returned pointer is valid until |session| is * freed by `nghttp2_session_del()`. @@ -5739,6 +6871,13 @@ nghttp2_session_get_root_stream(nghttp2_session *session); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return NULL. + * * Returns the parent stream of |stream| in dependency tree. Returns * NULL if there is no such stream. */ @@ -5750,6 +6889,13 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return NULL. + * * Returns the next sibling stream of |stream| in dependency tree. * Returns NULL if there is no such stream. */ @@ -5759,6 +6905,13 @@ nghttp2_stream_get_next_sibling(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return NULL. + * * Returns the previous sibling stream of |stream| in dependency tree. * Returns NULL if there is no such stream. */ @@ -5768,6 +6921,13 @@ nghttp2_stream_get_previous_sibling(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return NULL. + * * Returns the first child stream of |stream| in dependency tree. * Returns NULL if there is no such stream. */ @@ -5777,6 +6937,14 @@ nghttp2_stream_get_first_child(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return + * :macro:`NGHTTP2_DEFAULT_WEIGHT`. + * * Returns dependency weight to the parent stream of |stream|. */ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); @@ -5784,6 +6952,13 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return 0. + * * Returns the sum of the weight for |stream|'s children. */ NGHTTP2_EXTERN int32_t diff --git a/yass/third_party/nghttp2/lib/nghttp2_npn.c b/yass/third_party/nghttp2/lib/nghttp2_alpn.c similarity index 65% rename from yass/third_party/nghttp2/lib/nghttp2_npn.c rename to yass/third_party/nghttp2/lib/nghttp2_alpn.c index d1384c8075..33c5885f8d 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_npn.c +++ b/yass/third_party/nghttp2/lib/nghttp2_alpn.c @@ -22,13 +22,13 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "nghttp2_npn.h" +#include "nghttp2_alpn.h" #include -static int select_next_protocol(unsigned char **out, unsigned char *outlen, - const unsigned char *in, unsigned int inlen, - const char *key, unsigned int keylen) { +static int select_alpn(const unsigned char **out, unsigned char *outlen, + const unsigned char *in, unsigned int inlen, + const char *key, unsigned int keylen) { unsigned int i; for (i = 0; i + keylen <= inlen; i += (unsigned int)(in[i] + 1)) { if (memcmp(&in[i], key, keylen) == 0) { @@ -45,12 +45,25 @@ static int select_next_protocol(unsigned char **out, unsigned char *outlen, int nghttp2_select_next_protocol(unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen) { - if (select_next_protocol(out, outlen, in, inlen, NGHTTP2_PROTO_ALPN, - NGHTTP2_PROTO_ALPN_LEN) == 0) { + if (select_alpn((const unsigned char **)out, outlen, in, inlen, + NGHTTP2_PROTO_ALPN, NGHTTP2_PROTO_ALPN_LEN) == 0) { return 1; } - if (select_next_protocol(out, outlen, in, inlen, NGHTTP2_HTTP_1_1_ALPN, - NGHTTP2_HTTP_1_1_ALPN_LEN) == 0) { + if (select_alpn((const unsigned char **)out, outlen, in, inlen, + NGHTTP2_HTTP_1_1_ALPN, NGHTTP2_HTTP_1_1_ALPN_LEN) == 0) { + return 0; + } + return -1; +} + +int nghttp2_select_alpn(const unsigned char **out, unsigned char *outlen, + const unsigned char *in, unsigned int inlen) { + if (select_alpn(out, outlen, in, inlen, NGHTTP2_PROTO_ALPN, + NGHTTP2_PROTO_ALPN_LEN) == 0) { + return 1; + } + if (select_alpn(out, outlen, in, inlen, NGHTTP2_HTTP_1_1_ALPN, + NGHTTP2_HTTP_1_1_ALPN_LEN) == 0) { return 0; } return -1; diff --git a/yass/third_party/nghttp2/lib/nghttp2_npn.h b/yass/third_party/nghttp2/lib/nghttp2_alpn.h similarity index 94% rename from yass/third_party/nghttp2/lib/nghttp2_npn.h rename to yass/third_party/nghttp2/lib/nghttp2_alpn.h index c6f1c04b68..09810fd821 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_npn.h +++ b/yass/third_party/nghttp2/lib/nghttp2_alpn.h @@ -22,8 +22,8 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef NGHTTP2_NPN_H -#define NGHTTP2_NPN_H +#ifndef NGHTTP2_ALPN_H +#define NGHTTP2_ALPN_H #ifdef HAVE_CONFIG_H # include @@ -31,4 +31,4 @@ #include -#endif /* NGHTTP2_NPN_H */ +#endif /* NGHTTP2_ALPN_H */ diff --git a/yass/third_party/nghttp2/lib/nghttp2_buf.c b/yass/third_party/nghttp2/lib/nghttp2_buf.c index a32844712e..101035f923 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_buf.c +++ b/yass/third_party/nghttp2/lib/nghttp2_buf.c @@ -430,7 +430,7 @@ int nghttp2_bufs_orb_hold(nghttp2_bufs *bufs, uint8_t b) { return 0; } -ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out) { +nghttp2_ssize nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out) { size_t len; nghttp2_buf_chain *chain; nghttp2_buf *buf; @@ -462,7 +462,7 @@ ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out) { *out = res; - return (ssize_t)len; + return (nghttp2_ssize)len; } size_t nghttp2_bufs_remove_copy(nghttp2_bufs *bufs, uint8_t *out) { diff --git a/yass/third_party/nghttp2/lib/nghttp2_buf.h b/yass/third_party/nghttp2/lib/nghttp2_buf.h index 45f62f16e2..95ff3706a2 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_buf.h +++ b/yass/third_party/nghttp2/lib/nghttp2_buf.h @@ -349,7 +349,7 @@ int nghttp2_bufs_orb_hold(nghttp2_bufs *bufs, uint8_t b); * NGHTTP2_ERR_NOMEM * Out of memory */ -ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out); +nghttp2_ssize nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out); /* * Copies all data stored in |bufs| to |out|. This function assumes diff --git a/yass/third_party/nghttp2/lib/nghttp2_callbacks.c b/yass/third_party/nghttp2/lib/nghttp2_callbacks.c index 3c38214859..1776f7d276 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_callbacks.c +++ b/yass/third_party/nghttp2/lib/nghttp2_callbacks.c @@ -45,11 +45,21 @@ void nghttp2_session_callbacks_set_send_callback( cbs->send_callback = send_callback; } +void nghttp2_session_callbacks_set_send_callback2( + nghttp2_session_callbacks *cbs, nghttp2_send_callback2 send_callback) { + cbs->send_callback2 = send_callback; +} + void nghttp2_session_callbacks_set_recv_callback( nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback) { cbs->recv_callback = recv_callback; } +void nghttp2_session_callbacks_set_recv_callback2( + nghttp2_session_callbacks *cbs, nghttp2_recv_callback2 recv_callback) { + cbs->recv_callback2 = recv_callback; +} + void nghttp2_session_callbacks_set_on_frame_recv_callback( nghttp2_session_callbacks *cbs, nghttp2_on_frame_recv_callback on_frame_recv_callback) { @@ -128,12 +138,24 @@ void nghttp2_session_callbacks_set_select_padding_callback( cbs->select_padding_callback = select_padding_callback; } +void nghttp2_session_callbacks_set_select_padding_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_select_padding_callback2 select_padding_callback) { + cbs->select_padding_callback2 = select_padding_callback; +} + void nghttp2_session_callbacks_set_data_source_read_length_callback( nghttp2_session_callbacks *cbs, nghttp2_data_source_read_length_callback data_source_read_length_callback) { cbs->read_length_callback = data_source_read_length_callback; } +void nghttp2_session_callbacks_set_data_source_read_length_callback2( + nghttp2_session_callbacks *cbs, nghttp2_data_source_read_length_callback2 + data_source_read_length_callback) { + cbs->read_length_callback2 = data_source_read_length_callback; +} + void nghttp2_session_callbacks_set_on_begin_frame_callback( nghttp2_session_callbacks *cbs, nghttp2_on_begin_frame_callback on_begin_frame_callback) { @@ -152,6 +174,12 @@ void nghttp2_session_callbacks_set_pack_extension_callback( cbs->pack_extension_callback = pack_extension_callback; } +void nghttp2_session_callbacks_set_pack_extension_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_pack_extension_callback2 pack_extension_callback) { + cbs->pack_extension_callback2 = pack_extension_callback; +} + void nghttp2_session_callbacks_set_unpack_extension_callback( nghttp2_session_callbacks *cbs, nghttp2_unpack_extension_callback unpack_extension_callback) { diff --git a/yass/third_party/nghttp2/lib/nghttp2_callbacks.h b/yass/third_party/nghttp2/lib/nghttp2_callbacks.h index 61e51fa536..a611f48548 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_callbacks.h +++ b/yass/third_party/nghttp2/lib/nghttp2_callbacks.h @@ -36,19 +36,33 @@ */ struct nghttp2_session_callbacks { /** - * Callback function invoked when the session wants to send data to - * the remote peer. This callback is not necessary if the - * application uses solely `nghttp2_session_mem_send()` to serialize - * data to transmit. + * Deprecated. Use send_callback2 instead. Callback function + * invoked when the session wants to send data to the remote peer. + * This callback is not necessary if the application uses solely + * `nghttp2_session_mem_send()` to serialize data to transmit. */ nghttp2_send_callback send_callback; /** - * Callback function invoked when the session wants to receive data - * from the remote peer. This callback is not necessary if the - * application uses solely `nghttp2_session_mem_recv()` to process - * received data. + * Callback function invoked when the session wants to send data to + * the remote peer. This callback is not necessary if the + * application uses solely `nghttp2_session_mem_send2()` to + * serialize data to transmit. + */ + nghttp2_send_callback2 send_callback2; + /** + * Deprecated. Use recv_callback2 instead. Callback function + * invoked when the session wants to receive data from the remote + * peer. This callback is not necessary if the application uses + * solely `nghttp2_session_mem_recv()` to process received data. */ nghttp2_recv_callback recv_callback; + /** + * Callback function invoked when the session wants to receive data + * from the remote peer. This callback is not necessary if the + * application uses solely `nghttp2_session_mem_recv2()` to process + * received data. + */ + nghttp2_recv_callback2 recv_callback2; /** * Callback function invoked by `nghttp2_session_recv()` when a * frame is received. @@ -100,22 +114,39 @@ struct nghttp2_session_callbacks { nghttp2_on_invalid_header_callback on_invalid_header_callback; nghttp2_on_invalid_header_callback2 on_invalid_header_callback2; /** - * Callback function invoked when the library asks application how - * many padding bytes are required for the transmission of the given + * Deprecated. Use select_padding_callback2 instead. Callback + * function invoked when the library asks application how many + * padding bytes are required for the transmission of the given * frame. */ nghttp2_select_padding_callback select_padding_callback; /** - * The callback function used to determine the length allowed in + * Callback function invoked when the library asks application how + * many padding bytes are required for the transmission of the given + * frame. + */ + nghttp2_select_padding_callback2 select_padding_callback2; + /** + * Deprecated. Use read_length_callback2 instead. The callback + * function used to determine the length allowed in * `nghttp2_data_source_read_callback()` */ nghttp2_data_source_read_length_callback read_length_callback; + /** + * The callback function used to determine the length allowed in + * `nghttp2_data_source_read_callback2()` + */ + nghttp2_data_source_read_length_callback2 read_length_callback2; /** * Sets callback function invoked when a frame header is received. */ nghttp2_on_begin_frame_callback on_begin_frame_callback; nghttp2_send_data_callback send_data_callback; + /** + * Deprecated. Use pack_extension_callback2 instead. + */ nghttp2_pack_extension_callback pack_extension_callback; + nghttp2_pack_extension_callback2 pack_extension_callback2; nghttp2_unpack_extension_callback unpack_extension_callback; nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback; nghttp2_error_callback error_callback; diff --git a/yass/third_party/nghttp2/lib/nghttp2_extpri.c b/yass/third_party/nghttp2/lib/nghttp2_extpri.c index 3fd9b78163..ba0263e7c8 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_extpri.c +++ b/yass/third_party/nghttp2/lib/nghttp2_extpri.c @@ -24,6 +24,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "nghttp2_extpri.h" +#include "nghttp2_http.h" uint8_t nghttp2_extpri_to_uint8(const nghttp2_extpri *extpri) { return (uint8_t)((uint32_t)extpri->inc << 7 | extpri->urgency); @@ -33,3 +34,8 @@ void nghttp2_extpri_from_uint8(nghttp2_extpri *extpri, uint8_t u8extpri) { extpri->urgency = nghttp2_extpri_uint8_urgency(u8extpri); extpri->inc = nghttp2_extpri_uint8_inc(u8extpri); } + +int nghttp2_extpri_parse_priority(nghttp2_extpri *extpri, const uint8_t *value, + size_t len) { + return nghttp2_http_parse_priority(extpri, value, len); +} diff --git a/yass/third_party/nghttp2/lib/nghttp2_hd.c b/yass/third_party/nghttp2/lib/nghttp2_hd.c index 8a2bda64c1..1b0c71331a 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_hd.c +++ b/yass/third_party/nghttp2/lib/nghttp2_hd.c @@ -850,9 +850,10 @@ static size_t encode_length(uint8_t *buf, size_t n, size_t prefix) { * in the next call will be stored in |*shift_ptr|) and returns number * of bytes processed, or returns -1, indicating decoding error. */ -static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *fin, - uint32_t initial, size_t shift, const uint8_t *in, - const uint8_t *last, size_t prefix) { +static nghttp2_ssize decode_length(uint32_t *res, size_t *shift_ptr, int *fin, + uint32_t initial, size_t shift, + const uint8_t *in, const uint8_t *last, + size_t prefix) { uint32_t k = (uint8_t)((1 << prefix) - 1); uint32_t n = initial; const uint8_t *start = in; @@ -871,7 +872,7 @@ static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *fin, if (++in == last) { *res = n; - return (ssize_t)(in - start); + return (nghttp2_ssize)(in - start); } } @@ -906,12 +907,12 @@ static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *fin, if (in == last) { *res = n; - return (ssize_t)(in - start); + return (nghttp2_ssize)(in - start); } *res = n; *fin = 1; - return (ssize_t)(in + 1 - start); + return (nghttp2_ssize)(in + 1 - start); } static int emit_table_size(nghttp2_bufs *bufs, size_t table_size) { @@ -1164,7 +1165,7 @@ static int add_hd_table_incremental(nghttp2_hd_context *context, } typedef struct { - ssize_t index; + nghttp2_ssize index; /* Nonzero if both name and value are matched. */ int name_value_match; } search_result; @@ -1213,8 +1214,8 @@ static search_result search_hd_table(nghttp2_hd_context *context, return res; } - res.index = - (ssize_t)(context->next_seq - 1 - ent->seq + NGHTTP2_STATIC_TABLE_LENGTH); + res.index = (nghttp2_ssize)(context->next_seq - 1 - ent->seq + + NGHTTP2_STATIC_TABLE_LENGTH); res.name_value_match = exact_match; return res; @@ -1343,7 +1344,7 @@ static int deflate_nv(nghttp2_hd_deflater *deflater, nghttp2_bufs *bufs, const nghttp2_nv *nv) { int rv; search_result res; - ssize_t idx; + nghttp2_ssize idx; int indexing_mode; int32_t token; nghttp2_mem *mem; @@ -1379,7 +1380,7 @@ static int deflate_nv(nghttp2_hd_deflater *deflater, nghttp2_bufs *bufs, if (res.name_value_match) { - DEBUGF("deflatehd: name/value match index=%zd\n", idx); + DEBUGF("deflatehd: name/value match index=%td\n", idx); rv = emit_indexed_block(bufs, (size_t)idx); if (rv != 0) { @@ -1390,7 +1391,7 @@ static int deflate_nv(nghttp2_hd_deflater *deflater, nghttp2_bufs *bufs, } if (res.index != -1) { - DEBUGF("deflatehd: name match index=%zd\n", res.index); + DEBUGF("deflatehd: name match index=%td\n", res.index); } if (indexing_mode == NGHTTP2_HD_WITH_INDEXING) { @@ -1491,6 +1492,12 @@ fail: ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, uint8_t *buf, size_t buflen, const nghttp2_nv *nv, size_t nvlen) { + return (ssize_t)nghttp2_hd_deflate_hd2(deflater, buf, buflen, nv, nvlen); +} + +nghttp2_ssize nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, + uint8_t *buf, size_t buflen, + const nghttp2_nv *nv, size_t nvlen) { nghttp2_bufs bufs; int rv; nghttp2_mem *mem; @@ -1517,12 +1524,18 @@ ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, uint8_t *buf, return rv; } - return (ssize_t)buflen; + return (nghttp2_ssize)buflen; } ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater, const nghttp2_vec *vec, size_t veclen, const nghttp2_nv *nv, size_t nvlen) { + return (ssize_t)nghttp2_hd_deflate_hd_vec2(deflater, vec, veclen, nv, nvlen); +} + +nghttp2_ssize nghttp2_hd_deflate_hd_vec2(nghttp2_hd_deflater *deflater, + const nghttp2_vec *vec, size_t veclen, + const nghttp2_nv *nv, size_t nvlen) { nghttp2_bufs bufs; int rv; nghttp2_mem *mem; @@ -1550,7 +1563,7 @@ ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater, return rv; } - return (ssize_t)buflen; + return (nghttp2_ssize)buflen; } size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater, @@ -1643,10 +1656,11 @@ static void hd_inflate_set_huffman_encoded(nghttp2_hd_inflater *inflater, * NGHTTP2_ERR_HEADER_COMP * Integer decoding failed */ -static ssize_t hd_inflate_read_len(nghttp2_hd_inflater *inflater, int *rfin, - const uint8_t *in, const uint8_t *last, - size_t prefix, size_t maxlen) { - ssize_t rv; +static nghttp2_ssize hd_inflate_read_len(nghttp2_hd_inflater *inflater, + int *rfin, const uint8_t *in, + const uint8_t *last, size_t prefix, + size_t maxlen) { + nghttp2_ssize rv; uint32_t out; *rfin = 0; @@ -1684,10 +1698,10 @@ static ssize_t hd_inflate_read_len(nghttp2_hd_inflater *inflater, int *rfin, * NGHTTP2_ERR_HEADER_COMP * Huffman decoding failed */ -static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater, - nghttp2_buf *buf, const uint8_t *in, - const uint8_t *last) { - ssize_t readlen; +static nghttp2_ssize hd_inflate_read_huff(nghttp2_hd_inflater *inflater, + nghttp2_buf *buf, const uint8_t *in, + const uint8_t *last) { + nghttp2_ssize readlen; int fin = 0; if ((size_t)(last - in) >= inflater->left) { last = in + inflater->left; @@ -1721,14 +1735,15 @@ static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater, * NGHTTP2_ERR_HEADER_COMP * Header decompression failed */ -static ssize_t hd_inflate_read(nghttp2_hd_inflater *inflater, nghttp2_buf *buf, - const uint8_t *in, const uint8_t *last) { +static nghttp2_ssize hd_inflate_read(nghttp2_hd_inflater *inflater, + nghttp2_buf *buf, const uint8_t *in, + const uint8_t *last) { size_t len = nghttp2_min((size_t)(last - in), inflater->left); buf->last = nghttp2_cpymem(buf->last, in, len); inflater->left -= len; - return (ssize_t)len; + return (nghttp2_ssize)len; } /* @@ -1843,7 +1858,15 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, const uint8_t *in, size_t inlen, int in_final) { - ssize_t rv; + return (nghttp2_ssize)nghttp2_hd_inflate_hd3(inflater, nv_out, inflate_flags, + in, inlen, in_final); +} + +nghttp2_ssize nghttp2_hd_inflate_hd3(nghttp2_hd_inflater *inflater, + nghttp2_nv *nv_out, int *inflate_flags, + const uint8_t *in, size_t inlen, + int in_final) { + nghttp2_ssize rv; nghttp2_hd_nv hd_nv; rv = nghttp2_hd_inflate_hd_nv(inflater, &hd_nv, inflate_flags, in, inlen, @@ -1866,11 +1889,11 @@ ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, return rv; } -ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, - nghttp2_hd_nv *nv_out, int *inflate_flags, - const uint8_t *in, size_t inlen, - int in_final) { - ssize_t rv = 0; +nghttp2_ssize nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, + nghttp2_hd_nv *nv_out, + int *inflate_flags, const uint8_t *in, + size_t inlen, int in_final) { + nghttp2_ssize rv = 0; const uint8_t *first = in; const uint8_t *last = in + inlen; int rfin = 0; @@ -1992,7 +2015,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } else { inflater->index = inflater->left; --inflater->index; @@ -2050,7 +2073,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, in += rv; - DEBUGF("inflatehd: %zd bytes read\n", rv); + DEBUGF("inflatehd: %td bytes read\n", rv); if (inflater->left) { DEBUGF("inflatehd: still %zu bytes to go\n", inflater->left); @@ -2072,7 +2095,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, in += rv; - DEBUGF("inflatehd: %zd bytes read\n", rv); + DEBUGF("inflatehd: %td bytes read\n", rv); if (inflater->left) { DEBUGF("inflatehd: still %zu bytes to go\n", inflater->left); @@ -2138,7 +2161,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, in += rv; - DEBUGF("inflatehd: %zd bytes read\n", rv); + DEBUGF("inflatehd: %td bytes read\n", rv); if (inflater->left) { DEBUGF("inflatehd: still %zu bytes to go\n", inflater->left); @@ -2162,18 +2185,18 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); case NGHTTP2_HD_STATE_READ_VALUE: rv = hd_inflate_read(inflater, &inflater->valuebuf, in, last); if (rv < 0) { - DEBUGF("inflatehd: value read failure %zd: %s\n", rv, + DEBUGF("inflatehd: value read failure %td: %s\n", rv, nghttp2_strerror((int)rv)); goto fail; } in += rv; - DEBUGF("inflatehd: %zd bytes read\n", rv); + DEBUGF("inflatehd: %td bytes read\n", rv); if (inflater->left) { DEBUGF("inflatehd: still %zu bytes to go\n", inflater->left); @@ -2196,7 +2219,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } } @@ -2216,7 +2239,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, } *inflate_flags |= NGHTTP2_HD_INFLATE_FINAL; } - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); almost_ok: if (in_final) { @@ -2226,10 +2249,10 @@ almost_ok: goto fail; } - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); fail: - DEBUGF("inflatehd: error return %zd\n", rv); + DEBUGF("inflatehd: error return %td\n", rv); inflater->ctx.bad = 1; return rv; @@ -2297,9 +2320,10 @@ int nghttp2_hd_emit_table_size(nghttp2_bufs *bufs, size_t table_size) { return emit_table_size(bufs, table_size); } -ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *fin, - uint32_t initial, size_t shift, uint8_t *in, - uint8_t *last, size_t prefix) { +nghttp2_ssize nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, + int *fin, uint32_t initial, size_t shift, + uint8_t *in, uint8_t *last, + size_t prefix) { return decode_length(res, shift_ptr, fin, initial, shift, in, last, prefix); } diff --git a/yass/third_party/nghttp2/lib/nghttp2_hd.h b/yass/third_party/nghttp2/lib/nghttp2_hd.h index 6de0052aae..38a31a83c3 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_hd.h +++ b/yass/third_party/nghttp2/lib/nghttp2_hd.h @@ -357,9 +357,10 @@ void nghttp2_hd_inflate_free(nghttp2_hd_inflater *inflater); * that return values and semantics are the same as * nghttp2_hd_inflate_hd(). */ -ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, - nghttp2_hd_nv *nv_out, int *inflate_flags, - const uint8_t *in, size_t inlen, int in_final); +nghttp2_ssize nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, + nghttp2_hd_nv *nv_out, + int *inflate_flags, const uint8_t *in, + size_t inlen, int in_final); /* For unittesting purpose */ int nghttp2_hd_emit_indname_block(nghttp2_bufs *bufs, size_t index, @@ -376,9 +377,10 @@ int nghttp2_hd_emit_table_size(nghttp2_bufs *bufs, size_t table_size); nghttp2_hd_nv nghttp2_hd_table_get(nghttp2_hd_context *context, size_t index); /* For unittesting purpose */ -ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *fin, - uint32_t initial, size_t shift, uint8_t *in, - uint8_t *last, size_t prefix); +nghttp2_ssize nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, + int *fin, uint32_t initial, size_t shift, + uint8_t *in, uint8_t *last, + size_t prefix); /* Huffman encoding/decoding functions */ @@ -427,9 +429,9 @@ void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx); * NGHTTP2_ERR_HEADER_COMP * Decoding process has failed. */ -ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, - nghttp2_buf *buf, const uint8_t *src, - size_t srclen, int fin); +nghttp2_ssize nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, + nghttp2_buf *buf, const uint8_t *src, + size_t srclen, int fin); /* * nghttp2_hd_huff_decode_failure_state returns nonzero if |ctx| diff --git a/yass/third_party/nghttp2/lib/nghttp2_hd_huffman.c b/yass/third_party/nghttp2/lib/nghttp2_hd_huffman.c index ac90f49c44..959053f774 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_hd_huffman.c +++ b/yass/third_party/nghttp2/lib/nghttp2_hd_huffman.c @@ -107,9 +107,9 @@ void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx) { ctx->fstate = NGHTTP2_HUFF_ACCEPTED; } -ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, - nghttp2_buf *buf, const uint8_t *src, - size_t srclen, int final) { +nghttp2_ssize nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, + nghttp2_buf *buf, const uint8_t *src, + size_t srclen, int final) { const uint8_t *end = src + srclen; nghttp2_huff_decode node = {ctx->fstate, 0}; const nghttp2_huff_decode *t = &node; @@ -136,7 +136,7 @@ ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, return NGHTTP2_ERR_HEADER_COMP; } - return (ssize_t)srclen; + return (nghttp2_ssize)srclen; } int nghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context *ctx) { diff --git a/yass/third_party/nghttp2/lib/nghttp2_helper.c b/yass/third_party/nghttp2/lib/nghttp2_helper.c index 93dd4754b7..b3563d98e0 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_helper.c +++ b/yass/third_party/nghttp2/lib/nghttp2_helper.c @@ -336,6 +336,8 @@ const char *nghttp2_strerror(int error_code) { "closed"; case NGHTTP2_ERR_TOO_MANY_SETTINGS: return "SETTINGS frame contained more than the maximum allowed entries"; + case NGHTTP2_ERR_TOO_MANY_CONTINUATIONS: + return "Too many CONTINUATION frames following a HEADER frame"; default: return "Unknown error code"; } diff --git a/yass/third_party/nghttp2/lib/nghttp2_option.c b/yass/third_party/nghttp2/lib/nghttp2_option.c index 43d4e95229..53144b9b75 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_option.c +++ b/yass/third_party/nghttp2/lib/nghttp2_option.c @@ -150,3 +150,8 @@ void nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, option->stream_reset_burst = burst; option->stream_reset_rate = rate; } + +void nghttp2_option_set_max_continuations(nghttp2_option *option, size_t val) { + option->opt_set_mask |= NGHTTP2_OPT_MAX_CONTINUATIONS; + option->max_continuations = val; +} diff --git a/yass/third_party/nghttp2/lib/nghttp2_option.h b/yass/third_party/nghttp2/lib/nghttp2_option.h index 2259e1849d..c89cb97f8b 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_option.h +++ b/yass/third_party/nghttp2/lib/nghttp2_option.h @@ -71,6 +71,7 @@ typedef enum { NGHTTP2_OPT_SERVER_FALLBACK_RFC7540_PRIORITIES = 1 << 13, NGHTTP2_OPT_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION = 1 << 14, NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT = 1 << 15, + NGHTTP2_OPT_MAX_CONTINUATIONS = 1 << 16, } nghttp2_option_flag; /** @@ -98,6 +99,10 @@ struct nghttp2_option { * NGHTTP2_OPT_MAX_SETTINGS */ size_t max_settings; + /** + * NGHTTP2_OPT_MAX_CONTINUATIONS + */ + size_t max_continuations; /** * Bitwise OR of nghttp2_option_flag to determine that which fields * are specified. diff --git a/yass/third_party/nghttp2/lib/nghttp2_outbound_item.c b/yass/third_party/nghttp2/lib/nghttp2_outbound_item.c index 2a3041db19..a9e9f7693e 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_outbound_item.c +++ b/yass/third_party/nghttp2/lib/nghttp2_outbound_item.c @@ -27,6 +27,32 @@ #include #include +nghttp2_data_provider_wrap * +nghttp2_data_provider_wrap_v1(nghttp2_data_provider_wrap *dpw, + const nghttp2_data_provider *data_prd) { + if (!data_prd) { + return NULL; + } + + dpw->version = NGHTTP2_DATA_PROVIDER_V1; + dpw->data_prd.v1 = *data_prd; + + return dpw; +} + +nghttp2_data_provider_wrap * +nghttp2_data_provider_wrap_v2(nghttp2_data_provider_wrap *dpw, + const nghttp2_data_provider2 *data_prd) { + if (!data_prd) { + return NULL; + } + + dpw->version = NGHTTP2_DATA_PROVIDER_V2; + dpw->data_prd.v2 = *data_prd; + + return dpw; +} + void nghttp2_outbound_item_init(nghttp2_outbound_item *item) { item->cycle = 0; item->qnext = NULL; diff --git a/yass/third_party/nghttp2/lib/nghttp2_outbound_item.h b/yass/third_party/nghttp2/lib/nghttp2_outbound_item.h index bd4611b551..4e91750088 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_outbound_item.h +++ b/yass/third_party/nghttp2/lib/nghttp2_outbound_item.h @@ -33,9 +33,32 @@ #include "nghttp2_frame.h" #include "nghttp2_mem.h" +#define NGHTTP2_DATA_PROVIDER_V1 1 +#define NGHTTP2_DATA_PROVIDER_V2 2 + +typedef struct nghttp2_data_provider_wrap { + int version; + union { + struct { + nghttp2_data_source source; + void *read_callback; + }; + nghttp2_data_provider v1; + nghttp2_data_provider2 v2; + } data_prd; +} nghttp2_data_provider_wrap; + +nghttp2_data_provider_wrap * +nghttp2_data_provider_wrap_v1(nghttp2_data_provider_wrap *dpw, + const nghttp2_data_provider *data_prd); + +nghttp2_data_provider_wrap * +nghttp2_data_provider_wrap_v2(nghttp2_data_provider_wrap *dpw, + const nghttp2_data_provider2 *data_prd); + /* struct used for HEADERS and PUSH_PROMISE frame */ typedef struct { - nghttp2_data_provider data_prd; + nghttp2_data_provider_wrap dpw; void *stream_user_data; /* error code when request HEADERS is canceled by RST_STREAM while it is in queue. */ @@ -50,7 +73,7 @@ typedef struct { /** * The data to be sent for this DATA frame. */ - nghttp2_data_provider data_prd; + nghttp2_data_provider_wrap dpw; /** * The flags of DATA frame. We use separate flags here and * nghttp2_data frame. The latter contains flags actually sent to diff --git a/yass/third_party/nghttp2/lib/nghttp2_session.c b/yass/third_party/nghttp2/lib/nghttp2_session.c index ec5024d0f2..004a4dffaa 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_session.c +++ b/yass/third_party/nghttp2/lib/nghttp2_session.c @@ -39,6 +39,7 @@ #include "nghttp2_extpri.h" #include "nghttp2_time.h" #include "nghttp2_debug.h" +#include "nghttp2_submit.h" /* * Returns non-zero if the number of outgoing opened streams is larger @@ -496,6 +497,7 @@ static int session_new(nghttp2_session **session_ptr, (*session_ptr)->max_send_header_block_length = NGHTTP2_MAX_HEADERSLEN; (*session_ptr)->max_outbound_ack = NGHTTP2_DEFAULT_MAX_OBQ_FLOOD_ITEM; (*session_ptr)->max_settings = NGHTTP2_DEFAULT_MAX_SETTINGS; + (*session_ptr)->max_continuations = NGHTTP2_DEFAULT_MAX_CONTINUATIONS; if (option) { if ((option->opt_set_mask & NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE) && @@ -584,6 +586,10 @@ static int session_new(nghttp2_session **session_ptr, option->stream_reset_burst, option->stream_reset_rate); } + + if (option->opt_set_mask & NGHTTP2_OPT_MAX_CONTINUATIONS) { + (*session_ptr)->max_continuations = option->max_continuations; + } } rv = nghttp2_hd_deflate_init2(&(*session_ptr)->hd_deflater, @@ -978,7 +984,14 @@ static int session_attach_stream_item(nghttp2_session *session, return 0; } - return session_ob_data_push(session, stream); + rv = session_ob_data_push(session, stream); + if (rv != 0) { + nghttp2_stream_detach_item(stream); + + return rv; + } + + return 0; } static void session_detach_stream_item(nghttp2_session *session, @@ -1308,9 +1321,11 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, assert((stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) || nghttp2_stream_in_dep_tree(stream)); + nghttp2_session_detach_idle_stream(session, stream); + if (nghttp2_stream_in_dep_tree(stream)) { assert(!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)); - nghttp2_session_detach_idle_stream(session, stream); + rv = nghttp2_stream_dep_remove(stream); if (rv != 0) { return NULL; @@ -1470,6 +1485,21 @@ int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id, DEBUGF("stream: stream(%p)=%d close\n", stream, stream->stream_id); + /* We call on_stream_close_callback even if stream->state is + NGHTTP2_STREAM_INITIAL. This will happen while sending request + HEADERS, a local endpoint receives RST_STREAM for that stream. It + may be PROTOCOL_ERROR, but without notifying stream closure will + hang the stream in a local endpoint. + */ + + if (session->callbacks.on_stream_close_callback) { + if (session->callbacks.on_stream_close_callback( + session, stream_id, error_code, session->user_data) != 0) { + + return NGHTTP2_ERR_CALLBACK_FAILURE; + } + } + if (stream->item) { nghttp2_outbound_item *item; @@ -1487,21 +1517,6 @@ int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id, } } - /* We call on_stream_close_callback even if stream->state is - NGHTTP2_STREAM_INITIAL. This will happen while sending request - HEADERS, a local endpoint receives RST_STREAM for that stream. It - may be PROTOCOL_ERROR, but without notifying stream closure will - hang the stream in a local endpoint. - */ - - if (session->callbacks.on_stream_close_callback) { - if (session->callbacks.on_stream_close_callback( - session, stream_id, error_code, session->user_data) != 0) { - - return NGHTTP2_ERR_CALLBACK_FAILURE; - } - } - is_my_stream_id = nghttp2_session_is_my_stream_id(session, stream_id); /* pushed streams which is not opened yet is not counted toward max @@ -1558,6 +1573,11 @@ int nghttp2_session_destroy_stream(nghttp2_session *session, } } + if (stream->queued && + (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)) { + session_ob_data_remove(session, stream); + } + nghttp2_map_remove(&session->streams, stream->stream_id); nghttp2_stream_free(stream); nghttp2_mem_free(mem, stream); @@ -2103,10 +2123,9 @@ static int session_predicate_priority_update_send(nghttp2_session *session, /* Take into account settings max frame size and both connection-level flow control here */ -static ssize_t -nghttp2_session_enforce_flow_control_limits(nghttp2_session *session, - nghttp2_stream *stream, - ssize_t requested_window_size) { +static nghttp2_ssize nghttp2_session_enforce_flow_control_limits( + nghttp2_session *session, nghttp2_stream *stream, + nghttp2_ssize requested_window_size) { DEBUGF("send: remote windowsize connection=%d, remote maxframsize=%u, " "stream(id %d)=%d\n", session->remote_window_size, session->remote_settings.max_frame_size, @@ -2126,12 +2145,12 @@ nghttp2_session_enforce_flow_control_limits(nghttp2_session *session, */ static size_t nghttp2_session_next_data_read(nghttp2_session *session, nghttp2_stream *stream) { - ssize_t window_size; + nghttp2_ssize window_size; window_size = nghttp2_session_enforce_flow_control_limits( session, stream, NGHTTP2_DATA_PAYLOADLEN); - DEBUGF("send: available window=%zd\n", window_size); + DEBUGF("send: available window=%td\n", window_size); return window_size > 0 ? (size_t)window_size : 0; } @@ -2186,29 +2205,33 @@ static int nghttp2_session_predicate_data_send(nghttp2_session *session, return NGHTTP2_ERR_INVALID_STREAM_STATE; } -static ssize_t session_call_select_padding(nghttp2_session *session, - const nghttp2_frame *frame, - size_t max_payloadlen) { - ssize_t rv; +static nghttp2_ssize session_call_select_padding(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payloadlen) { + nghttp2_ssize rv; + size_t max_paddedlen; - if (frame->hd.length >= max_payloadlen) { - return (ssize_t)frame->hd.length; + if (frame->hd.length >= max_payloadlen || + (!session->callbacks.select_padding_callback2 && + !session->callbacks.select_padding_callback)) { + return (nghttp2_ssize)frame->hd.length; } - if (session->callbacks.select_padding_callback) { - size_t max_paddedlen; + max_paddedlen = + nghttp2_min(frame->hd.length + NGHTTP2_MAX_PADLEN, max_payloadlen); - max_paddedlen = - nghttp2_min(frame->hd.length + NGHTTP2_MAX_PADLEN, max_payloadlen); - - rv = session->callbacks.select_padding_callback( + if (session->callbacks.select_padding_callback2) { + rv = session->callbacks.select_padding_callback2( + session, frame, max_paddedlen, session->user_data); + } else { + rv = (nghttp2_ssize)session->callbacks.select_padding_callback( session, frame, max_paddedlen, session->user_data); - if (rv < (ssize_t)frame->hd.length || rv > (ssize_t)max_paddedlen) { - return NGHTTP2_ERR_CALLBACK_FAILURE; - } - return rv; } - return (ssize_t)frame->hd.length; + if (rv < (nghttp2_ssize)frame->hd.length || + rv > (nghttp2_ssize)max_paddedlen) { + return NGHTTP2_ERR_CALLBACK_FAILURE; + } + return rv; } /* Add padding to HEADERS or PUSH_PROMISE. We use @@ -2216,7 +2239,7 @@ static ssize_t session_call_select_padding(nghttp2_session *session, frame->push_promise has also padlen in the same position. */ static int session_headers_add_pad(nghttp2_session *session, nghttp2_frame *frame) { - ssize_t padded_payloadlen; + nghttp2_ssize padded_payloadlen; nghttp2_active_outbound_item *aob; nghttp2_bufs *framebufs; size_t padlen; @@ -2237,7 +2260,7 @@ static int session_headers_add_pad(nghttp2_session *session, padlen = (size_t)padded_payloadlen - frame->hd.length; - DEBUGF("send: padding selected: payloadlen=%zd, padlen=%zu\n", + DEBUGF("send: padding selected: payloadlen=%td, padlen=%zu\n", padded_payloadlen, padlen); nghttp2_frame_add_pad(framebufs, &frame->hd, padlen, 0); @@ -2257,18 +2280,24 @@ static size_t session_estimate_headers_payload(nghttp2_session *session, static int session_pack_extension(nghttp2_session *session, nghttp2_bufs *bufs, nghttp2_frame *frame) { - ssize_t rv; + nghttp2_ssize rv; nghttp2_buf *buf; size_t buflen; size_t framelen; - assert(session->callbacks.pack_extension_callback); + assert(session->callbacks.pack_extension_callback2 || + session->callbacks.pack_extension_callback); buf = &bufs->head->buf; buflen = nghttp2_min(nghttp2_buf_avail(buf), NGHTTP2_MAX_PAYLOADLEN); - rv = session->callbacks.pack_extension_callback(session, buf->last, buflen, - frame, session->user_data); + if (session->callbacks.pack_extension_callback2) { + rv = session->callbacks.pack_extension_callback2(session, buf->last, buflen, + frame, session->user_data); + } else { + rv = (nghttp2_ssize)session->callbacks.pack_extension_callback( + session, buf->last, buflen, frame, session->user_data); + } if (rv == NGHTTP2_ERR_CANCEL) { return (int)rv; } @@ -2451,7 +2480,7 @@ static int session_prep_frame(nghttp2_session *session, return rv; } - DEBUGF("send: before padding, HEADERS serialized in %zd bytes\n", + DEBUGF("send: before padding, HEADERS serialized in %zu bytes\n", nghttp2_bufs_len(&session->aob.framebufs)); rv = session_headers_add_pad(session, frame); @@ -2460,7 +2489,7 @@ static int session_prep_frame(nghttp2_session *session, return rv; } - DEBUGF("send: HEADERS finally serialized in %zd bytes\n", + DEBUGF("send: HEADERS finally serialized in %zu bytes\n", nghttp2_bufs_len(&session->aob.framebufs)); if (frame->headers.cat == NGHTTP2_HCAT_REQUEST) { @@ -2877,7 +2906,7 @@ static int session_after_frame_sent1(nghttp2_session *session) { /* Call on_frame_send_callback after nghttp2_stream_detach_item(), so that application can issue - nghttp2_submit_data() in the callback. */ + nghttp2_submit_data2() in the callback. */ if (session->callbacks.on_frame_send_callback) { rv = session_call_on_frame_send(session, frame); if (nghttp2_is_fatal(rv)) { @@ -2949,15 +2978,17 @@ static int session_after_frame_sent1(nghttp2_session *session) { } /* We assume aux_data is a pointer to nghttp2_headers_aux_data */ aux_data = &item->aux_data.headers; - if (aux_data->data_prd.read_callback) { - /* nghttp2_submit_data() makes a copy of aux_data->data_prd */ - rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, - frame->hd.stream_id, &aux_data->data_prd); + if (aux_data->dpw.data_prd.read_callback) { + /* nghttp2_submit_data_shared() makes a copy of + aux_data->dpw */ + rv = nghttp2_submit_data_shared(session, NGHTTP2_FLAG_END_STREAM, + frame->hd.stream_id, &aux_data->dpw); if (nghttp2_is_fatal(rv)) { return rv; } - /* TODO nghttp2_submit_data() may fail if stream has already - DATA frame item. We might have to handle it here. */ + /* TODO nghttp2_submit_data_shared() may fail if stream has + already DATA frame item. We might have to handle it + here. */ } return 0; } @@ -2978,14 +3009,15 @@ static int session_after_frame_sent1(nghttp2_session *session) { } /* We assume aux_data is a pointer to nghttp2_headers_aux_data */ aux_data = &item->aux_data.headers; - if (aux_data->data_prd.read_callback) { - rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, - frame->hd.stream_id, &aux_data->data_prd); + if (aux_data->dpw.data_prd.read_callback) { + rv = nghttp2_submit_data_shared(session, NGHTTP2_FLAG_END_STREAM, + frame->hd.stream_id, &aux_data->dpw); if (nghttp2_is_fatal(rv)) { return rv; } - /* TODO nghttp2_submit_data() may fail if stream has already - DATA frame item. We might have to handle it here. */ + /* TODO nghttp2_submit_data_shared() may fail if stream has + already DATA frame item. We might have to handle it + here. */ } return 0; default: @@ -3144,7 +3176,7 @@ static void session_after_frame_sent2(nghttp2_session *session) { aux_data = &item->aux_data.data; /* On EOF, we have already detached data. Please note that - application may issue nghttp2_submit_data() in + application may issue nghttp2_submit_data2() in on_frame_send_callback (call from session_after_frame_sent1), which attach data to stream. We don't want to detach it. */ if (aux_data->eof) { @@ -3191,7 +3223,7 @@ static int session_call_send_data(nghttp2_session *session, aux_data = &item->aux_data.data; rv = session->callbacks.send_data_callback(session, frame, buf->pos, length, - &aux_data->data_prd.source, + &aux_data->dpw.data_prd.source, session->user_data); switch (rv) { @@ -3205,9 +3237,9 @@ static int session_call_send_data(nghttp2_session *session, } } -static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, - const uint8_t **data_ptr, - int fast_cb) { +static nghttp2_ssize nghttp2_session_mem_send_internal(nghttp2_session *session, + const uint8_t **data_ptr, + int fast_cb) { int rv; nghttp2_active_outbound_item *aob; nghttp2_bufs *framebufs; @@ -3302,7 +3334,7 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, } if (rv == NGHTTP2_ERR_HEADER_COMP) { - /* If header compression error occurred, should terminiate + /* If header compression error occurred, should terminate connection. */ rv = nghttp2_session_terminate_session(session, NGHTTP2_INTERNAL_ERROR); @@ -3385,7 +3417,7 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, } } - DEBUGF("send: start transmitting frame type=%u, length=%zd\n", + DEBUGF("send: start transmitting frame type=%u, length=%td\n", framebufs->cur->buf.pos[3], framebufs->cur->buf.last - framebufs->cur->buf.pos); @@ -3425,7 +3457,7 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, everything, we will adjust it. */ buf->pos += datalen; - return (ssize_t)datalen; + return (nghttp2_ssize)datalen; } case NGHTTP2_OB_SEND_NO_COPY: { nghttp2_stream *stream; @@ -3502,7 +3534,7 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, buf->pos += datalen; - return (ssize_t)datalen; + return (nghttp2_ssize)datalen; } } } @@ -3510,8 +3542,13 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, ssize_t nghttp2_session_mem_send(nghttp2_session *session, const uint8_t **data_ptr) { + return (ssize_t)nghttp2_session_mem_send2(session, data_ptr); +} + +nghttp2_ssize nghttp2_session_mem_send2(nghttp2_session *session, + const uint8_t **data_ptr) { int rv; - ssize_t len; + nghttp2_ssize len; *data_ptr = NULL; @@ -3528,7 +3565,7 @@ ssize_t nghttp2_session_mem_send(nghttp2_session *session, rv = session_after_frame_sent1(session); if (rv < 0) { assert(nghttp2_is_fatal(rv)); - return (ssize_t)rv; + return (nghttp2_ssize)rv; } } @@ -3537,8 +3574,8 @@ ssize_t nghttp2_session_mem_send(nghttp2_session *session, int nghttp2_session_send(nghttp2_session *session) { const uint8_t *data = NULL; - ssize_t datalen; - ssize_t sentlen; + nghttp2_ssize datalen; + nghttp2_ssize sentlen; nghttp2_bufs *framebufs; framebufs = &session->aob.framebufs; @@ -3548,8 +3585,13 @@ int nghttp2_session_send(nghttp2_session *session) { if (datalen <= 0) { return (int)datalen; } - sentlen = session->callbacks.send_callback(session, data, (size_t)datalen, - 0, session->user_data); + if (session->callbacks.send_callback2) { + sentlen = session->callbacks.send_callback2( + session, data, (size_t)datalen, 0, session->user_data); + } else { + sentlen = (nghttp2_ssize)session->callbacks.send_callback( + session, data, (size_t)datalen, 0, session->user_data); + } if (sentlen < 0) { if (sentlen == NGHTTP2_ERR_WOULDBLOCK) { /* Transmission canceled. Rewind the offset */ @@ -3564,11 +3606,17 @@ int nghttp2_session_send(nghttp2_session *session) { } } -static ssize_t session_recv(nghttp2_session *session, uint8_t *buf, - size_t len) { - ssize_t rv; - rv = session->callbacks.recv_callback(session, buf, len, 0, - session->user_data); +static nghttp2_ssize session_recv(nghttp2_session *session, uint8_t *buf, + size_t len) { + nghttp2_ssize rv; + + if (session->callbacks.recv_callback2) { + rv = session->callbacks.recv_callback2(session, buf, len, 0, + session->user_data); + } else { + rv = (nghttp2_ssize)session->callbacks.recv_callback(session, buf, len, 0, + session->user_data); + } if (rv > 0) { if ((size_t)rv > len) { return NGHTTP2_ERR_CALLBACK_FAILURE; @@ -3870,7 +3918,7 @@ static int session_inflate_handle_invalid_connection(nghttp2_session *session, static int inflate_header_block(nghttp2_session *session, nghttp2_frame *frame, size_t *readlen_ptr, uint8_t *in, size_t inlen, int final, int call_header_cb) { - ssize_t proclen; + nghttp2_ssize proclen; int rv; int inflate_flags; nghttp2_hd_nv nv; @@ -3923,7 +3971,7 @@ static int inflate_header_block(nghttp2_session *session, nghttp2_frame *frame, inlen -= (size_t)proclen; *readlen_ptr += (size_t)proclen; - DEBUGF("recv: proclen=%zd\n", proclen); + DEBUGF("recv: proclen=%td\n", proclen); if (call_header_cb && (inflate_flags & NGHTTP2_HD_INFLATE_EMIT)) { rv = 0; @@ -5763,7 +5811,7 @@ static int inbound_frame_handle_pad(nghttp2_inbound_frame *iframe, * Computes number of padding based on flags. This function returns * the calculated length if it succeeds, or -1. */ -static ssize_t inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) { +static nghttp2_ssize inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) { size_t padlen; /* 1 for Pad Length field */ @@ -5778,7 +5826,7 @@ static ssize_t inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) { iframe->padlen = padlen; - return (ssize_t)padlen; + return (nghttp2_ssize)padlen; } /* @@ -5787,9 +5835,9 @@ static ssize_t inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) { * |payloadleft| does not include |readlen|. If padding was started * strictly before this data chunk, this function returns -1. */ -static ssize_t inbound_frame_effective_readlen(nghttp2_inbound_frame *iframe, - size_t payloadleft, - size_t readlen) { +static nghttp2_ssize +inbound_frame_effective_readlen(nghttp2_inbound_frame *iframe, + size_t payloadleft, size_t readlen) { size_t trail_padlen = nghttp2_frame_trail_padlen(&iframe->frame, iframe->padlen); @@ -5799,19 +5847,24 @@ static ssize_t inbound_frame_effective_readlen(nghttp2_inbound_frame *iframe, if (readlen < padlen) { return -1; } - return (ssize_t)(readlen - padlen); + return (nghttp2_ssize)(readlen - padlen); } - return (ssize_t)(readlen); + return (nghttp2_ssize)(readlen); } static const uint8_t static_in[] = {0}; ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, size_t inlen) { + return (ssize_t)nghttp2_session_mem_recv2(session, in, inlen); +} + +nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, + const uint8_t *in, size_t inlen) { const uint8_t *first, *last; nghttp2_inbound_frame *iframe = &session->iframe; size_t readlen; - ssize_t padlen; + nghttp2_ssize padlen; int rv; int busy = 0; nghttp2_frame_hd cont_hd; @@ -5841,7 +5894,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (!nghttp2_session_want_read(session)) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } for (;;) { @@ -5871,7 +5924,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, in += readlen; if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } if (iframe->sbuf.pos[3] != NGHTTP2_SETTINGS || @@ -5893,7 +5946,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->state = NGHTTP2_IB_READ_HEAD; @@ -5908,7 +5961,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, in += readlen; if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } nghttp2_frame_unpack_frame_hd(&iframe->frame.hd, iframe->sbuf.pos); @@ -5929,7 +5982,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } switch (iframe->frame.hd.type) { @@ -5944,7 +5997,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, rv = session_on_data_received_fail_fast(session); if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_IGN_PAYLOAD) { DEBUGF("recv: DATA not allowed stream_id=%d\n", @@ -5966,7 +6019,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == 1) { @@ -5993,7 +6046,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == 1) { @@ -6036,7 +6089,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, busy = 1; if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { @@ -6137,7 +6190,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->iv = nghttp2_mem_malloc(mem, sizeof(nghttp2_settings_entry) * @@ -6175,7 +6228,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == 1) { @@ -6235,7 +6288,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; default: DEBUGF("recv: extension frame\n"); @@ -6346,7 +6399,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (iframe->payloadleft < 4) { @@ -6404,11 +6457,11 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, in += readlen; iframe->payloadleft -= readlen; - DEBUGF("recv: readlen=%zu, payloadleft=%zu, left=%zd\n", readlen, + DEBUGF("recv: readlen=%zu, payloadleft=%zu, left=%zu\n", readlen, iframe->payloadleft, nghttp2_buf_mark_avail(&iframe->sbuf)); if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } switch (iframe->frame.hd.type) { @@ -6424,7 +6477,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->frame.headers.padlen = (size_t)padlen; @@ -6451,7 +6504,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, busy = 1; if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { @@ -6481,7 +6534,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } } @@ -6495,7 +6548,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6513,7 +6566,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->frame.push_promise.padlen = (size_t)padlen; @@ -6539,7 +6592,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, busy = 1; if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { @@ -6568,7 +6621,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6603,7 +6656,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6661,7 +6714,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, break; case NGHTTP2_IB_READ_HEADER_BLOCK: case NGHTTP2_IB_IGN_HEADER_BLOCK: { - ssize_t data_readlen; + nghttp2_ssize data_readlen; size_t trail_padlen; int final; #ifdef DEBUGBUILD @@ -6705,14 +6758,14 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_PAUSE) { in += hd_proclen; iframe->payloadleft -= hd_proclen; - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { @@ -6778,6 +6831,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } } session_inbound_frame_reset(session); + + session->num_continuations = 0; } break; } @@ -6819,7 +6874,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, assert(iframe->state == NGHTTP2_IB_IGN_ALL); - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; case NGHTTP2_IB_READ_SETTINGS: DEBUGF("recv: [IB_READ_SETTINGS]\n"); @@ -6849,7 +6904,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6883,7 +6938,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6899,11 +6954,15 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } #endif /* DEBUGBUILD */ + if (++session->num_continuations > session->max_continuations) { + return NGHTTP2_ERR_TOO_MANY_CONTINUATIONS; + } + readlen = inbound_frame_buf_read(iframe, in, last); in += readlen; if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } nghttp2_frame_unpack_frame_hd(&cont_hd, iframe->sbuf.pos); @@ -6925,7 +6984,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } /* CONTINUATION won't bear NGHTTP2_PADDED flag */ @@ -6961,7 +7020,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, iframe->payloadleft, nghttp2_buf_mark_avail(&iframe->sbuf)); if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } /* Pad Length field is subject to flow control */ @@ -6971,7 +7030,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } /* Pad Length field is consumed immediately */ @@ -6983,7 +7042,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } stream = nghttp2_session_get_stream(session, iframe->frame.hd.stream_id); @@ -7006,7 +7065,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->frame.data.padlen = (size_t)padlen; @@ -7033,7 +7092,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, iframe->payloadleft); if (readlen > 0) { - ssize_t data_readlen; + nghttp2_ssize data_readlen; rv = nghttp2_session_update_recv_connection_window_size(session, readlen); @@ -7042,7 +7101,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } rv = nghttp2_session_update_recv_stream_window_size( @@ -7061,7 +7120,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, data_readlen = 0; } - padlen = (ssize_t)readlen - data_readlen; + padlen = (nghttp2_ssize)readlen - data_readlen; if (padlen > 0) { /* Padding is considered as "consumed" immediately */ @@ -7073,11 +7132,11 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } } - DEBUGF("recv: data_readlen=%zd\n", data_readlen); + DEBUGF("recv: data_readlen=%td\n", data_readlen); if (data_readlen > 0) { if (session_enforce_http_messaging(session)) { @@ -7092,7 +7151,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_DATA) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } } @@ -7111,7 +7170,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, session, iframe->frame.hd.flags, iframe->frame.hd.stream_id, in - readlen, (size_t)data_readlen, session->user_data); if (rv == NGHTTP2_ERR_PAUSE) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } if (nghttp2_is_fatal(rv)) { @@ -7153,7 +7212,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE) { @@ -7166,7 +7225,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } } } @@ -7179,7 +7238,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, break; case NGHTTP2_IB_IGN_ALL: - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; case NGHTTP2_IB_READ_EXTENSION_PAYLOAD: DEBUGF("recv: [IB_READ_EXTENSION_PAYLOAD]\n"); @@ -7274,7 +7333,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -7291,16 +7350,17 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, assert(in == last); - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } int nghttp2_session_recv(nghttp2_session *session) { uint8_t buf[NGHTTP2_INBOUND_BUFFER_LENGTH]; while (1) { - ssize_t readlen; + nghttp2_ssize readlen; readlen = session_recv(session, buf, sizeof(buf)); if (readlen > 0) { - ssize_t proclen = nghttp2_session_mem_recv(session, buf, (size_t)readlen); + nghttp2_ssize proclen = + nghttp2_session_mem_recv2(session, buf, (size_t)readlen); if (proclen < 0) { return (int)proclen; } @@ -7642,8 +7702,8 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, nghttp2_stream *stream) { int rv; uint32_t data_flags; - ssize_t payloadlen; - ssize_t padded_payloadlen; + nghttp2_ssize payloadlen; + nghttp2_ssize padded_payloadlen; nghttp2_buf *buf; size_t max_payloadlen; @@ -7651,19 +7711,26 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, buf = &bufs->cur->buf; - if (session->callbacks.read_length_callback) { + if (session->callbacks.read_length_callback2 || + session->callbacks.read_length_callback) { + if (session->callbacks.read_length_callback2) { + payloadlen = session->callbacks.read_length_callback2( + session, frame->hd.type, stream->stream_id, + session->remote_window_size, stream->remote_window_size, + session->remote_settings.max_frame_size, session->user_data); + } else { + payloadlen = (nghttp2_ssize)session->callbacks.read_length_callback( + session, frame->hd.type, stream->stream_id, + session->remote_window_size, stream->remote_window_size, + session->remote_settings.max_frame_size, session->user_data); + } - payloadlen = session->callbacks.read_length_callback( - session, frame->hd.type, stream->stream_id, session->remote_window_size, - stream->remote_window_size, session->remote_settings.max_frame_size, - session->user_data); - - DEBUGF("send: read_length_callback=%zd\n", payloadlen); + DEBUGF("send: read_length_callback=%td\n", payloadlen); payloadlen = nghttp2_session_enforce_flow_control_limits(session, stream, payloadlen); - DEBUGF("send: read_length_callback after flow control=%zd\n", payloadlen); + DEBUGF("send: read_length_callback after flow control=%td\n", payloadlen); if (payloadlen <= 0) { return NGHTTP2_ERR_CALLBACK_FAILURE; @@ -7679,9 +7746,9 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, DEBUGF("send: realloc buffer failed rv=%d", rv); /* If reallocation failed, old buffers are still in tact. So use safe limit. */ - payloadlen = (ssize_t)datamax; + payloadlen = (nghttp2_ssize)datamax; - DEBUGF("send: use safe limit payloadlen=%zd", payloadlen); + DEBUGF("send: use safe limit payloadlen=%td", payloadlen); } else { assert(&session->aob.framebufs == bufs); @@ -7695,9 +7762,23 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, assert(nghttp2_buf_avail(buf) >= datamax); data_flags = NGHTTP2_DATA_FLAG_NONE; - payloadlen = aux_data->data_prd.read_callback( - session, frame->hd.stream_id, buf->pos, datamax, &data_flags, - &aux_data->data_prd.source, session->user_data); + switch (aux_data->dpw.version) { + case NGHTTP2_DATA_PROVIDER_V1: + payloadlen = (nghttp2_ssize)aux_data->dpw.data_prd.v1.read_callback( + session, frame->hd.stream_id, buf->pos, datamax, &data_flags, + &aux_data->dpw.data_prd.source, session->user_data); + + break; + case NGHTTP2_DATA_PROVIDER_V2: + payloadlen = aux_data->dpw.data_prd.v2.read_callback( + session, frame->hd.stream_id, buf->pos, datamax, &data_flags, + &aux_data->dpw.data_prd.source, session->user_data); + + break; + default: + assert(0); + abort(); + } if (payloadlen == NGHTTP2_ERR_DEFERRED || payloadlen == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE || @@ -8275,7 +8356,7 @@ int nghttp2_session_change_stream_priority( /* We don't intentionally call nghttp2_session_adjust_idle_stream() so that idle stream created by this function, and existing ones are kept for application. We will adjust number of idle stream - in nghttp2_session_mem_send or nghttp2_session_mem_recv is + in nghttp2_session_mem_send2 or nghttp2_session_mem_recv2 is called. */ return 0; } @@ -8313,7 +8394,7 @@ int nghttp2_session_create_idle_stream(nghttp2_session *session, /* We don't intentionally call nghttp2_session_adjust_idle_stream() so that idle stream created by this function, and existing ones are kept for application. We will adjust number of idle stream - in nghttp2_session_mem_send or nghttp2_session_mem_recv is + in nghttp2_session_mem_send2 or nghttp2_session_mem_recv2 is called. */ return 0; } @@ -8366,3 +8447,30 @@ int nghttp2_session_change_extpri_stream_priority( return session_update_stream_priority(session, stream, nghttp2_extpri_to_uint8(&extpri)); } + +int nghttp2_session_get_extpri_stream_priority(nghttp2_session *session, + nghttp2_extpri *extpri, + int32_t stream_id) { + nghttp2_stream *stream; + + if (!session->server) { + return NGHTTP2_ERR_INVALID_STATE; + } + + if (session->pending_no_rfc7540_priorities != 1) { + return 0; + } + + if (stream_id == 0) { + return NGHTTP2_ERR_INVALID_ARGUMENT; + } + + stream = nghttp2_session_get_stream_raw(session, stream_id); + if (!stream) { + return NGHTTP2_ERR_INVALID_ARGUMENT; + } + + nghttp2_extpri_from_uint8(extpri, stream->extpri); + + return 0; +} diff --git a/yass/third_party/nghttp2/lib/nghttp2_session.h b/yass/third_party/nghttp2/lib/nghttp2_session.h index b119329a04..ef8f7b27d6 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_session.h +++ b/yass/third_party/nghttp2/lib/nghttp2_session.h @@ -110,6 +110,10 @@ typedef struct { #define NGHTTP2_DEFAULT_STREAM_RESET_BURST 1000 #define NGHTTP2_DEFAULT_STREAM_RESET_RATE 33 +/* The default max number of CONTINUATION frames following an incoming + HEADER frame. */ +#define NGHTTP2_DEFAULT_MAX_CONTINUATIONS 8 + /* Internal state when receiving incoming frame */ typedef enum { /* Receiving frame header */ @@ -290,6 +294,12 @@ struct nghttp2_session { size_t max_send_header_block_length; /* The maximum number of settings accepted per SETTINGS frame. */ size_t max_settings; + /* The maximum number of CONTINUATION frames following an incoming + HEADER frame. */ + size_t max_continuations; + /* The number of CONTINUATION frames following an incoming HEADER + frame. This variable is reset when END_HEADERS flag is seen. */ + size_t num_continuations; /* Next Stream ID. Made unsigned int to detect >= (1 << 31). */ uint32_t next_stream_id; /* The last stream ID this session initiated. For client session, diff --git a/yass/third_party/nghttp2/lib/nghttp2_submit.c b/yass/third_party/nghttp2/lib/nghttp2_submit.c index f5554eb564..f947969cd9 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_submit.c +++ b/yass/third_party/nghttp2/lib/nghttp2_submit.c @@ -68,7 +68,7 @@ static int32_t submit_headers_shared(nghttp2_session *session, uint8_t flags, int32_t stream_id, const nghttp2_priority_spec *pri_spec, nghttp2_nv *nva_copy, size_t nvlen, - const nghttp2_data_provider *data_prd, + const nghttp2_data_provider_wrap *dpw, void *stream_user_data) { int rv; uint8_t flags_copy; @@ -87,8 +87,8 @@ static int32_t submit_headers_shared(nghttp2_session *session, uint8_t flags, nghttp2_outbound_item_init(item); - if (data_prd != NULL && data_prd->read_callback != NULL) { - item->aux_data.headers.data_prd = *data_prd; + if (dpw != NULL && dpw->data_prd.read_callback != NULL) { + item->aux_data.headers.dpw = *dpw; } item->aux_data.headers.stream_user_data = stream_user_data; @@ -143,7 +143,7 @@ static int32_t submit_headers_shared_nva(nghttp2_session *session, uint8_t flags, int32_t stream_id, const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd, + const nghttp2_data_provider_wrap *dpw, void *stream_user_data) { int rv; nghttp2_nv *nva_copy; @@ -165,7 +165,7 @@ static int32_t submit_headers_shared_nva(nghttp2_session *session, } return submit_headers_shared(session, flags, stream_id, ©_pri_spec, - nva_copy, nvlen, data_prd, stream_user_data); + nva_copy, nvlen, dpw, stream_user_data); } int nghttp2_submit_trailer(nghttp2_session *session, int32_t stream_id, @@ -740,9 +740,9 @@ fail_item_malloc: } static uint8_t set_request_flags(const nghttp2_priority_spec *pri_spec, - const nghttp2_data_provider *data_prd) { + const nghttp2_data_provider_wrap *dpw) { uint8_t flags = NGHTTP2_FLAG_NONE; - if (data_prd == NULL || data_prd->read_callback == NULL) { + if (dpw == NULL || dpw->data_prd.read_callback == NULL) { flags |= NGHTTP2_FLAG_END_STREAM; } @@ -753,11 +753,11 @@ static uint8_t set_request_flags(const nghttp2_priority_spec *pri_spec, return flags; } -int32_t nghttp2_submit_request(nghttp2_session *session, - const nghttp2_priority_spec *pri_spec, - const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd, - void *stream_user_data) { +static int32_t submit_request_shared(nghttp2_session *session, + const nghttp2_priority_spec *pri_spec, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider_wrap *dpw, + void *stream_user_data) { uint8_t flags; int rv; @@ -775,23 +775,47 @@ int32_t nghttp2_submit_request(nghttp2_session *session, pri_spec = NULL; } - flags = set_request_flags(pri_spec, data_prd); + flags = set_request_flags(pri_spec, dpw); return submit_headers_shared_nva(session, flags, -1, pri_spec, nva, nvlen, - data_prd, stream_user_data); + dpw, stream_user_data); } -static uint8_t set_response_flags(const nghttp2_data_provider *data_prd) { +int32_t nghttp2_submit_request(nghttp2_session *session, + const nghttp2_priority_spec *pri_spec, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider *data_prd, + void *stream_user_data) { + nghttp2_data_provider_wrap dpw; + + return submit_request_shared(session, pri_spec, nva, nvlen, + nghttp2_data_provider_wrap_v1(&dpw, data_prd), + stream_user_data); +} + +int32_t nghttp2_submit_request2(nghttp2_session *session, + const nghttp2_priority_spec *pri_spec, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider2 *data_prd, + void *stream_user_data) { + nghttp2_data_provider_wrap dpw; + + return submit_request_shared(session, pri_spec, nva, nvlen, + nghttp2_data_provider_wrap_v2(&dpw, data_prd), + stream_user_data); +} + +static uint8_t set_response_flags(const nghttp2_data_provider_wrap *dpw) { uint8_t flags = NGHTTP2_FLAG_NONE; - if (data_prd == NULL || data_prd->read_callback == NULL) { + if (dpw == NULL || dpw->data_prd.read_callback == NULL) { flags |= NGHTTP2_FLAG_END_STREAM; } return flags; } -int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, - const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd) { +static int submit_response_shared(nghttp2_session *session, int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider_wrap *dpw) { uint8_t flags; if (stream_id <= 0) { @@ -802,14 +826,32 @@ int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, return NGHTTP2_ERR_PROTO; } - flags = set_response_flags(data_prd); + flags = set_response_flags(dpw); return submit_headers_shared_nva(session, flags, stream_id, NULL, nva, nvlen, - data_prd, NULL); + dpw, NULL); } -int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, - int32_t stream_id, - const nghttp2_data_provider *data_prd) { +int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider *data_prd) { + nghttp2_data_provider_wrap dpw; + + return submit_response_shared(session, stream_id, nva, nvlen, + nghttp2_data_provider_wrap_v1(&dpw, data_prd)); +} + +int nghttp2_submit_response2(nghttp2_session *session, int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider2 *data_prd) { + nghttp2_data_provider_wrap dpw; + + return submit_response_shared(session, stream_id, nva, nvlen, + nghttp2_data_provider_wrap_v2(&dpw, data_prd)); +} + +int nghttp2_submit_data_shared(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider_wrap *dpw) { int rv; nghttp2_outbound_item *item; nghttp2_frame *frame; @@ -832,7 +874,7 @@ int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, frame = &item->frame; aux_data = &item->aux_data.data; - aux_data->data_prd = *data_prd; + aux_data->dpw = *dpw; aux_data->eof = 0; aux_data->flags = nflags; @@ -848,9 +890,37 @@ int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, return 0; } +int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider *data_prd) { + nghttp2_data_provider_wrap dpw; + + assert(data_prd); + + return nghttp2_submit_data_shared( + session, flags, stream_id, nghttp2_data_provider_wrap_v1(&dpw, data_prd)); +} + +int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider2 *data_prd) { + nghttp2_data_provider_wrap dpw; + + assert(data_prd); + + return nghttp2_submit_data_shared( + session, flags, stream_id, nghttp2_data_provider_wrap_v2(&dpw, data_prd)); +} + ssize_t nghttp2_pack_settings_payload(uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv) { + return (ssize_t)nghttp2_pack_settings_payload2(buf, buflen, iv, niv); +} + +nghttp2_ssize nghttp2_pack_settings_payload2(uint8_t *buf, size_t buflen, + const nghttp2_settings_entry *iv, + size_t niv) { if (!nghttp2_iv_check(iv, niv)) { return NGHTTP2_ERR_INVALID_ARGUMENT; } @@ -859,7 +929,7 @@ ssize_t nghttp2_pack_settings_payload(uint8_t *buf, size_t buflen, return NGHTTP2_ERR_INSUFF_BUFSIZE; } - return (ssize_t)nghttp2_frame_pack_settings_payload(buf, iv, niv); + return (nghttp2_ssize)nghttp2_frame_pack_settings_payload(buf, iv, niv); } int nghttp2_submit_extension(nghttp2_session *session, uint8_t type, @@ -875,7 +945,8 @@ int nghttp2_submit_extension(nghttp2_session *session, uint8_t type, return NGHTTP2_ERR_INVALID_ARGUMENT; } - if (!session->callbacks.pack_extension_callback) { + if (!session->callbacks.pack_extension_callback2 && + !session->callbacks.pack_extension_callback) { return NGHTTP2_ERR_INVALID_STATE; } diff --git a/yass/third_party/nghttp2/lib/nghttp2_submit.h b/yass/third_party/nghttp2/lib/nghttp2_submit.h index 74d702fbcf..96781d2a27 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_submit.h +++ b/yass/third_party/nghttp2/lib/nghttp2_submit.h @@ -31,4 +31,10 @@ #include +typedef struct nghttp2_data_provider_wrap nghttp2_data_provider_wrap; + +int nghttp2_submit_data_shared(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider_wrap *dpw); + #endif /* NGHTTP2_SUBMIT_H */ diff --git a/yass/third_party/nghttp2/lib/nghttp2_time.c b/yass/third_party/nghttp2/lib/nghttp2_time.c index 897556fe2c..947b5449e5 100644 --- a/yass/third_party/nghttp2/lib/nghttp2_time.c +++ b/yass/third_party/nghttp2/lib/nghttp2_time.c @@ -24,13 +24,11 @@ */ #include "nghttp2_time.h" -#ifdef HAVE_TIME_H -# include -#endif /* HAVE_TIME_H */ +#ifdef HAVE_WINDOWS_H +# include +#endif /* HAVE_WINDOWS_H */ -#ifdef HAVE_SYSINFOAPI_H -# include -#endif /* HAVE_SYSINFOAPI_H */ +#include #if !defined(HAVE_GETTICKCOUNT64) || defined(__CYGWIN__) static uint64_t time_now_sec(void) { @@ -46,7 +44,8 @@ static uint64_t time_now_sec(void) { #if defined(HAVE_GETTICKCOUNT64) && !defined(__CYGWIN__) uint64_t nghttp2_time_now_sec(void) { return GetTickCount64() / 1000; } -#elif defined(HAVE_CLOCK_GETTIME) +#elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_DECL_CLOCK_MONOTONIC) && \ + HAVE_DECL_CLOCK_MONOTONIC uint64_t nghttp2_time_now_sec(void) { struct timespec tp; int rv = clock_gettime(CLOCK_MONOTONIC, &tp); @@ -57,6 +56,8 @@ uint64_t nghttp2_time_now_sec(void) { return (uint64_t)tp.tv_sec; } -#else /* (!HAVE_CLOCK_GETTIME || __CYGWIN__) && !HAVE_GETTICKCOUNT64 */ +#else /* (!HAVE_CLOCK_GETTIME || !HAVE_DECL_CLOCK_MONOTONIC) && \ + (!HAVE_GETTICKCOUNT64 || __CYGWIN__)) */ uint64_t nghttp2_time_now_sec(void) { return time_now_sec(); } -#endif /* (!HAVE_CLOCK_GETTIME || __CYGWIN__) && !HAVE_GETTICKCOUNT64 */ +#endif /* (!HAVE_CLOCK_GETTIME || !HAVE_DECL_CLOCK_MONOTONIC) && \ + (!HAVE_GETTICKCOUNT64 || __CYGWIN__)) */ diff --git a/yass/third_party/nghttp2/makerelease.sh b/yass/third_party/nghttp2/makerelease.sh index b65e08f57f..9e84988ac4 100755 --- a/yass/third_party/nghttp2/makerelease.sh +++ b/yass/third_party/nghttp2/makerelease.sh @@ -6,18 +6,17 @@ PREV_TAG=$2 git checkout refs/tags/$TAG git log --pretty=fuller --date=short refs/tags/$PREV_TAG..HEAD > ChangeLog -git submodule update --init - autoreconf -i -./configure --with-mruby && \ - make dist-bzip2 && make dist-gzip && make dist-xz || echo "error" +./configure +make dist-bzip2 +make dist-gzip +make dist-xz +make distclean rm -f checksums.txt -VERSION=`echo -n $TAG | sed -E 's|^v([0-9]+\.[0-9]+\.[0-9]+)(-DEV)?$|\1|'` +VERSION=`echo -n $TAG | sed -E 's|^v([0-9]+\.[0-9]+\.[0-9]+(-[^.]+(\.[0-9]+)?)?)$|\1|'` for f in nghttp2-$VERSION.tar.bz2 nghttp2-$VERSION.tar.gz nghttp2-$VERSION.tar.xz; do sha256sum $f >> checksums.txt - gpg --armor --detach-sign $f + echo -n "$GPG_PASSPHRASE" | gpg --batch --passphrase-fd 0 --pinentry-mode loopback --armor --detach-sign $f done - -make distclean diff --git a/yass/third_party/nghttp2/script/fetch-ocsp-response b/yass/third_party/nghttp2/script/fetch-ocsp-response index 0ff7461ee2..f9c2100292 100755 --- a/yass/third_party/nghttp2/script/fetch-ocsp-response +++ b/yass/third_party/nghttp2/script/fetch-ocsp-response @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # nghttp2 - HTTP/2 C Library @@ -96,7 +96,7 @@ def run_openssl(args, allow_tempfail=False): raise Exception('nonzero return code {}'.format(p.returncode)) return buf.getvalue() except Exception as e: - msg = 'OpenSSL exitted abnormally: {}:{}'.format(args, e) + msg = 'OpenSSL exited abnormally: {}:{}'.format(args, e) tempfail(msg) if allow_tempfail else die(msg) diff --git a/yass/third_party/nghttp2/src/CMakeLists.txt b/yass/third_party/nghttp2/src/CMakeLists.txt index 201c5a2d51..6583324ed0 100644 --- a/yass/third_party/nghttp2/src/CMakeLists.txt +++ b/yass/third_party/nghttp2/src/CMakeLists.txt @@ -21,6 +21,8 @@ include_directories( ${JANSSON_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${LIBBPF_INCLUDE_DIRS} + ${LIBBROTLIENC_INCLUDE_DIRS} + ${LIBBROTLIDEC_INCLUDE_DIRS} ) # XXX per-target? @@ -38,6 +40,8 @@ link_libraries( ${ZLIB_LIBRARIES} ${APP_LIBRARIES} ${LIBBPF_LIBRARIES} + ${LIBBROTLIENC_LIBRARIES} + ${LIBBROTLIDEC_LIBRARIES} ) if(ENABLE_APP) @@ -163,45 +167,45 @@ if(ENABLE_APP) target_link_libraries(nghttpx_static neverbleed) endif() - - if(HAVE_CUNIT) - set(NGHTTPX_UNITTEST_SOURCES - shrpx-unittest.cc - shrpx_tls_test.cc - shrpx_downstream_test.cc - shrpx_config_test.cc - shrpx_worker_test.cc - shrpx_http_test.cc - shrpx_router_test.cc - http2_test.cc - util_test.cc - nghttp2_gzip_test.c - nghttp2_gzip.c - buffer_test.cc - memchunk_test.cc - template_test.cc - base64_test.cc + set(NGHTTPX_UNITTEST_SOURCES + shrpx-unittest.cc + shrpx_tls_test.cc + shrpx_downstream_test.cc + shrpx_config_test.cc + shrpx_worker_test.cc + shrpx_http_test.cc + shrpx_router_test.cc + http2_test.cc + util_test.cc + nghttp2_gzip_test.c + nghttp2_gzip.c + buffer_test.cc + memchunk_test.cc + template_test.cc + base64_test.cc + ${CMAKE_SOURCE_DIR}/tests/munit/munit.c + ) + add_executable(nghttpx-unittest EXCLUDE_FROM_ALL + ${NGHTTPX_UNITTEST_SOURCES} + $ + $ ) - add_executable(nghttpx-unittest EXCLUDE_FROM_ALL - ${NGHTTPX_UNITTEST_SOURCES} - $ - $ - ) - target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS}) - target_compile_definitions(nghttpx-unittest - PRIVATE "-DNGHTTP2_SRC_DIR=\"${CMAKE_SOURCE_DIR}/src\"" - ) - target_link_libraries(nghttpx-unittest nghttpx_static ${CUNIT_LIBRARIES}) - if(HAVE_MRUBY) - target_link_libraries(nghttpx-unittest mruby-lib) - endif() - if(HAVE_NEVERBLEED) - target_link_libraries(nghttpx-unittest neverbleed) - endif() - - add_test(nghttpx-unittest nghttpx-unittest) - add_dependencies(check nghttpx-unittest) + target_include_directories(nghttpx-unittest PRIVATE + ${CMAKE_SOURCE_DIR}/tests/munit + ) + target_compile_definitions(nghttpx-unittest + PRIVATE "-DNGHTTP2_SRC_DIR=\"${CMAKE_SOURCE_DIR}/src\"" + ) + target_link_libraries(nghttpx-unittest nghttpx_static) + if(HAVE_MRUBY) + target_link_libraries(nghttpx-unittest mruby-lib) endif() + if(HAVE_NEVERBLEED) + target_link_libraries(nghttpx-unittest neverbleed) + endif() + + add_test(nghttpx-unittest nghttpx-unittest) + add_dependencies(check nghttpx-unittest) add_executable(nghttp ${NGHTTP_SOURCES} $ $ @@ -221,8 +225,7 @@ if(ENABLE_APP) $ ) - install(TARGETS nghttp nghttpd nghttpx h2load - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + install(TARGETS nghttp nghttpd nghttpx h2load) endif() if(ENABLE_HPACK_TOOLS) @@ -238,6 +241,5 @@ if(ENABLE_HPACK_TOOLS) ) add_executable(inflatehd ${inflatehd_SOURCES}) add_executable(deflatehd ${deflatehd_SOURCES}) - install(TARGETS inflatehd deflatehd - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + install(TARGETS inflatehd deflatehd) endif() diff --git a/yass/third_party/nghttp2/src/HttpServer.cc b/yass/third_party/nghttp2/src/HttpServer.cc index 34b7444e45..6b28d1be89 100644 --- a/yass/third_party/nghttp2/src/HttpServer.cc +++ b/yass/third_party/nghttp2/src/HttpServer.cc @@ -291,9 +291,7 @@ public: return ssl; } const Config *get_config() const { return config_; } - struct ev_loop *get_loop() const { - return loop_; - } + struct ev_loop *get_loop() const { return loop_; } int64_t get_next_session_id() { auto session_id = next_session_id_; if (next_session_id_ == std::numeric_limits::max()) { @@ -585,9 +583,7 @@ Http2Handler::~Http2Handler() { void Http2Handler::remove_self() { sessions_->remove_handler(this); } -struct ev_loop *Http2Handler::get_loop() const { - return sessions_->get_loop(); -} +struct ev_loop *Http2Handler::get_loop() const { return sessions_->get_loop(); } Http2Handler::WriteBuf *Http2Handler::get_wb() { return &wb_; } @@ -611,10 +607,10 @@ int Http2Handler::fill_wb() { for (;;) { const uint8_t *data; - auto datalen = nghttp2_session_mem_send(session_, &data); + auto datalen = nghttp2_session_mem_send2(session_, &data); if (datalen < 0) { - std::cerr << "nghttp2_session_mem_send() returned error: " + std::cerr << "nghttp2_session_mem_send2() returned error: " << nghttp2_strerror(datalen) << std::endl; return -1; } @@ -652,10 +648,10 @@ int Http2Handler::read_clear() { util::hexdump(stdout, buf.data(), nread); } - rv = nghttp2_session_mem_recv(session_, buf.data(), nread); + rv = nghttp2_session_mem_recv2(session_, buf.data(), nread); if (rv < 0) { if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { - std::cerr << "nghttp2_session_mem_recv() returned error: " + std::cerr << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv) << std::endl; } return -1; @@ -729,7 +725,7 @@ int Http2Handler::tls_handshake() { std::cerr << "SSL/TLS handshake completed" << std::endl; } - if (verify_npn_result() != 0) { + if (verify_alpn_result() != 0) { return -1; } @@ -754,34 +750,40 @@ int Http2Handler::read_tls() { ERR_clear_error(); - auto rv = SSL_read(ssl_, buf.data(), buf.size()); + for (;;) { + auto rv = SSL_read(ssl_, buf.data(), buf.size()); - if (rv <= 0) { - auto err = SSL_get_error(ssl_, rv); - switch (err) { - case SSL_ERROR_WANT_READ: - return write_(*this); - case SSL_ERROR_WANT_WRITE: - // renegotiation started - return -1; - default: + if (rv <= 0) { + auto err = SSL_get_error(ssl_, rv); + switch (err) { + case SSL_ERROR_WANT_READ: + return write_(*this); + case SSL_ERROR_WANT_WRITE: + // renegotiation started + return -1; + default: + return -1; + } + } + + auto nread = rv; + + if (get_config()->hexdump) { + util::hexdump(stdout, buf.data(), nread); + } + + rv = nghttp2_session_mem_recv2(session_, buf.data(), nread); + if (rv < 0) { + if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { + std::cerr << "nghttp2_session_mem_recv2() returned error: " + << nghttp2_strerror(rv) << std::endl; + } return -1; } - } - auto nread = rv; - - if (get_config()->hexdump) { - util::hexdump(stdout, buf.data(), nread); - } - - rv = nghttp2_session_mem_recv(session_, buf.data(), nread); - if (rv < 0) { - if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { - std::cerr << "nghttp2_session_mem_recv() returned error: " - << nghttp2_strerror(rv) << std::endl; + if (SSL_pending(ssl_) == 0) { + break; } - return -1; } return write_(*this); @@ -896,29 +898,18 @@ int Http2Handler::connection_made() { return on_write(); } -int Http2Handler::verify_npn_result() { +int Http2Handler::verify_alpn_result() { const unsigned char *next_proto = nullptr; unsigned int next_proto_len; - // Check the negotiated protocol in NPN or ALPN -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(ssl_, &next_proto, &next_proto_len); -#endif // !OPENSSL_NO_NEXTPROTONEG - for (int i = 0; i < 2; ++i) { - if (next_proto) { - auto proto = StringRef{next_proto, next_proto_len}; - if (sessions_->get_config()->verbose) { - std::cout << "The negotiated protocol: " << proto << std::endl; - } - if (util::check_h2_is_selected(proto)) { - return 0; - } - break; - } else { -#if OPENSSL_VERSION_NUMBER >= 0x10002000L - SSL_get0_alpn_selected(ssl_, &next_proto, &next_proto_len); -#else // OPENSSL_VERSION_NUMBER < 0x10002000L - break; -#endif // OPENSSL_VERSION_NUMBER < 0x10002000L + // Check the negotiated protocol in ALPN + SSL_get0_alpn_selected(ssl_, &next_proto, &next_proto_len); + if (next_proto) { + auto proto = StringRef{next_proto, next_proto_len}; + if (sessions_->get_config()->verbose) { + std::cout << "The negotiated protocol: " << proto << std::endl; + } + if (util::check_h2_is_selected(proto)) { + return 0; } } if (sessions_->get_config()->verbose) { @@ -932,7 +923,7 @@ int Http2Handler::verify_npn_result() { int Http2Handler::submit_file_response(const StringRef &status, Stream *stream, time_t last_modified, off_t file_length, const std::string *content_type, - nghttp2_data_provider *data_prd) { + nghttp2_data_provider2 *data_prd) { std::string last_modified_str; auto nva = make_array(http2::make_nv_ls_nocopy(":status", status), http2::make_nv_ls_nocopy("server", NGHTTPD_SERVER), @@ -957,13 +948,13 @@ int Http2Handler::submit_file_response(const StringRef &status, Stream *stream, if (!trailer_names.empty()) { nva[nvlen++] = http2::make_nv_ls_nocopy("trailer", trailer_names); } - return nghttp2_submit_response(session_, stream->stream_id, nva.data(), nvlen, - data_prd); + return nghttp2_submit_response2(session_, stream->stream_id, nva.data(), + nvlen, data_prd); } int Http2Handler::submit_response(const StringRef &status, int32_t stream_id, const HeaderRefs &headers, - nghttp2_data_provider *data_prd) { + nghttp2_data_provider2 *data_prd) { auto nva = std::vector(); nva.reserve(4 + headers.size()); nva.push_back(http2::make_nv_ls_nocopy(":status", status)); @@ -980,13 +971,13 @@ int Http2Handler::submit_response(const StringRef &status, int32_t stream_id, for (auto &nv : headers) { nva.push_back(http2::make_nv_nocopy(nv.name, nv.value, nv.no_index)); } - int r = nghttp2_submit_response(session_, stream_id, nva.data(), nva.size(), - data_prd); + int r = nghttp2_submit_response2(session_, stream_id, nva.data(), nva.size(), + data_prd); return r; } int Http2Handler::submit_response(const StringRef &status, int32_t stream_id, - nghttp2_data_provider *data_prd) { + nghttp2_data_provider2 *data_prd) { auto nva = make_array(http2::make_nv_ls_nocopy(":status", status), http2::make_nv_ls_nocopy("server", NGHTTPD_SERVER), http2::make_nv_ls("date", sessions_->get_cached_date()), @@ -1000,8 +991,8 @@ int Http2Handler::submit_response(const StringRef &status, int32_t stream_id, } } - return nghttp2_submit_response(session_, stream_id, nva.data(), nvlen, - data_prd); + return nghttp2_submit_response2(session_, stream_id, nva.data(), nvlen, + data_prd); } int Http2Handler::submit_non_final_response(const std::string &status, @@ -1091,9 +1082,10 @@ void Http2Handler::terminate_session(uint32_t error_code) { nghttp2_session_terminate_session(session_, error_code); } -ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, uint32_t *data_flags, - nghttp2_data_source *source, void *user_data) { +nghttp2_ssize file_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t length, + uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { int rv; auto hd = static_cast(user_data); auto stream = hd->get_stream(stream_id); @@ -1142,7 +1134,7 @@ void prepare_status_response(Stream *stream, Http2Handler *hd, int status) { // we don't set stream->file_ent since we don't want to expire it. stream->body_length = file_ent->length; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = file_ent->fd; data_prd.read_callback = file_read_callback; @@ -1170,7 +1162,7 @@ void prepare_echo_response(Stream *stream, Http2Handler *hd) { hd->submit_rst_stream(stream, NGHTTP2_INTERNAL_ERROR); return; } - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = stream->file_ent->fd; data_prd.read_callback = file_read_callback; @@ -1393,7 +1385,7 @@ void prepare_response(Stream *stream, Http2Handler *hd, stream->body_length = file_ent->length; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = file_ent->fd; data_prd.read_callback = file_read_callback; @@ -1691,9 +1683,9 @@ int send_data_callback(nghttp2_session *session, nghttp2_frame *frame, } // namespace namespace { -ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, size_t max_payload, - void *user_data) { +nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payload, void *user_data) { auto hd = static_cast(user_data); return std::min(max_payload, frame->hd.length + hd->get_config()->padding); } @@ -1780,7 +1772,7 @@ void fill_callback(nghttp2_session_callbacks *callbacks, const Config *config) { send_data_callback); if (config->padding) { - nghttp2_session_callbacks_set_select_padding_callback( + nghttp2_session_callbacks_set_select_padding_callback2( callbacks, select_padding_callback); } } @@ -1996,18 +1988,6 @@ HttpServer::HttpServer(const Config *config) : config_(config) { }; } -#ifndef OPENSSL_NO_NEXTPROTONEG -namespace { -int next_proto_cb(SSL *s, const unsigned char **data, unsigned int *len, - void *arg) { - auto next_proto = static_cast *>(arg); - *data = next_proto->data(); - *len = next_proto->size(); - return SSL_TLSEXT_ERR_OK; -} -} // namespace -#endif // !OPENSSL_NO_NEXTPROTONEG - namespace { int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) { // We don't verify the client certificate. Just request it for the @@ -2093,7 +2073,6 @@ int start_listen(HttpServer *sv, struct ev_loop *loop, Sessions *sessions, } } // namespace -#if OPENSSL_VERSION_NUMBER >= 0x10002000L namespace { int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in, @@ -2115,7 +2094,6 @@ int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, return SSL_TLSEXT_ERR_OK; } } // namespace -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L int HttpServer::run() { SSL_CTX *ssl_ctx = nullptr; @@ -2161,23 +2139,12 @@ int HttpServer::run() { SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_SERVER); #ifndef OPENSSL_NO_EC -# if !LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L if (SSL_CTX_set1_curves_list(ssl_ctx, "P-256") != 1) { std::cerr << "SSL_CTX_set1_curves_list failed: " << ERR_error_string(ERR_get_error(), nullptr); return -1; } -# else // !(!LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L) - auto ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); - if (ecdh == nullptr) { - std::cerr << "EC_KEY_new_by_curv_name failed: " - << ERR_error_string(ERR_get_error(), nullptr); - return -1; - } - SSL_CTX_set_tmp_ecdh(ssl_ctx, ecdh); - EC_KEY_free(ecdh); -# endif // !(!LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L) -#endif // OPENSSL_NO_EC +#endif // OPENSSL_NO_EC if (!config_->dh_param_file.empty()) { // Read DH parameters from file @@ -2243,13 +2210,17 @@ int HttpServer::run() { next_proto = util::get_default_alpn(); -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_CTX_set_next_protos_advertised_cb(ssl_ctx, next_proto_cb, &next_proto); -#endif // !OPENSSL_NO_NEXTPROTONEG -#if OPENSSL_VERSION_NUMBER >= 0x10002000L // ALPN selection callback SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, this); -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + nghttp2::tls::cert_compress, nghttp2::tls::cert_decompress)) { + std::cerr << "SSL_CTX_add_cert_compression_alg failed." << std::endl; + return -1; + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI } auto loop = EV_DEFAULT; @@ -2264,6 +2235,9 @@ int HttpServer::run() { } ev_run(loop, 0); + + SSL_CTX_free(ssl_ctx); + return 0; } diff --git a/yass/third_party/nghttp2/src/HttpServer.h b/yass/third_party/nghttp2/src/HttpServer.h index f825b83e33..00fd6bf2b7 100644 --- a/yass/third_party/nghttp2/src/HttpServer.h +++ b/yass/third_party/nghttp2/src/HttpServer.h @@ -41,6 +41,7 @@ #include +#define NGHTTP2_NO_SSIZE_T #include #include "http2.h" @@ -167,19 +168,19 @@ public: int on_read(); int on_write(); int connection_made(); - int verify_npn_result(); + int verify_alpn_result(); int submit_file_response(const StringRef &status, Stream *stream, time_t last_modified, off_t file_length, const std::string *content_type, - nghttp2_data_provider *data_prd); + nghttp2_data_provider2 *data_prd); int submit_response(const StringRef &status, int32_t stream_id, - nghttp2_data_provider *data_prd); + nghttp2_data_provider2 *data_prd); int submit_response(const StringRef &status, int32_t stream_id, const HeaderRefs &headers, - nghttp2_data_provider *data_prd); + nghttp2_data_provider2 *data_prd); int submit_non_final_response(const std::string &status, int32_t stream_id); diff --git a/yass/third_party/nghttp2/src/Makefile.am b/yass/third_party/nghttp2/src/Makefile.am index f112ac2cbc..5e900181da 100644 --- a/yass/third_party/nghttp2/src/Makefile.am +++ b/yass/third_party/nghttp2/src/Makefile.am @@ -53,6 +53,8 @@ AM_CPPFLAGS = \ @JANSSON_CFLAGS@ \ @LIBBPF_CFLAGS@ \ @ZLIB_CFLAGS@ \ + @LIBBROTLIENC_CFLAGS@ \ + @LIBBROTLIDEC_CFLAGS@ \ @EXTRA_DEFS@ \ @DEFS@ AM_LDFLAGS = @LIBTOOL_LDFLAGS@ @@ -73,6 +75,8 @@ LDADD = $(top_builddir)/lib/libnghttp2.la \ @JANSSON_LIBS@ \ @LIBBPF_LIBS@ \ @ZLIB_LIBS@ \ + @LIBBROTLIENC_LIBS@ \ + @LIBBROTLIDEC_LIBS@ \ @APPLDFLAGS@ if ENABLE_APP @@ -203,7 +207,6 @@ libnghttpx_a_CPPFLAGS += -I${top_srcdir}/third-party/neverbleed nghttpx_LDADD += ${top_builddir}/third-party/libneverbleed.la endif # HAVE_NEVERBLEED -if HAVE_CUNIT check_PROGRAMS += nghttpx-unittest nghttpx_unittest_SOURCES = shrpx-unittest.cc \ shrpx_tls_test.cc shrpx_tls_test.h \ @@ -219,10 +222,13 @@ nghttpx_unittest_SOURCES = shrpx-unittest.cc \ buffer_test.cc buffer_test.h \ memchunk_test.cc memchunk_test.h \ template_test.cc template_test.h \ - base64_test.cc base64_test.h + base64_test.cc base64_test.h \ + $(top_srcdir)/tests/munit/munit.c $(top_srcdir)/tests/munit/munit.h \ + $(top_srcdir)/tests/munit/munitxx.h nghttpx_unittest_CPPFLAGS = ${AM_CPPFLAGS} \ + -I$(top_srcdir)/tests/munit \ -DNGHTTP2_SRC_DIR=\"$(top_srcdir)/src\" -nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} @CUNIT_LIBS@ @TESTLDADD@ +nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} @TESTLDADD@ if HAVE_MRUBY nghttpx_unittest_CPPFLAGS += \ @@ -237,7 +243,6 @@ nghttpx_unittest_LDADD += ${top_builddir}/third-party/libneverbleed.la endif # HAVE_NEVERBLEED TESTS += nghttpx-unittest -endif # HAVE_CUNIT endif # ENABLE_APP diff --git a/yass/third_party/nghttp2/src/allocator.h b/yass/third_party/nghttp2/src/allocator.h index 97b9a41818..363ee916ac 100644 --- a/yass/third_party/nghttp2/src/allocator.h +++ b/yass/third_party/nghttp2/src/allocator.h @@ -119,7 +119,7 @@ struct BlockAllocator { } if (!head || - head->end - head->last < static_cast(size + sizeof(size_t))) { + static_cast(head->end - head->last) < size + sizeof(size_t)) { head = alloc_mem_block(block_size); } diff --git a/yass/third_party/nghttp2/src/app_helper.cc b/yass/third_party/nghttp2/src/app_helper.cc index ef9276285a..666d16cd7d 100644 --- a/yass/third_party/nghttp2/src/app_helper.cc +++ b/yass/third_party/nghttp2/src/app_helper.cc @@ -53,8 +53,6 @@ #include #include -#include - #include "app_helper.h" #include "util.h" #include "http2.h" @@ -477,42 +475,4 @@ std::chrono::steady_clock::time_point get_time() { return std::chrono::steady_clock::now(); } -ssize_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in, - size_t inlen) { - int rv; - z_stream zst{}; - uint8_t temp_out[8_k]; - auto temp_outlen = sizeof(temp_out); - - rv = deflateInit2(&zst, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 31, 9, - Z_DEFAULT_STRATEGY); - - if (rv != Z_OK) { - return -1; - } - - zst.avail_in = inlen; - zst.next_in = (uint8_t *)in; - zst.avail_out = temp_outlen; - zst.next_out = temp_out; - - rv = deflate(&zst, Z_FINISH); - - deflateEnd(&zst); - - if (rv != Z_STREAM_END) { - return -1; - } - - temp_outlen -= zst.avail_out; - - if (temp_outlen > outlen) { - return -1; - } - - memcpy(out, temp_out, temp_outlen); - - return temp_outlen; -} - } // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/app_helper.h b/yass/third_party/nghttp2/src/app_helper.h index 5424054ffa..a7ef7ccfcb 100644 --- a/yass/third_party/nghttp2/src/app_helper.h +++ b/yass/third_party/nghttp2/src/app_helper.h @@ -90,9 +90,6 @@ void set_color_output(bool f); // used. void set_output(FILE *file); -ssize_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in, - size_t inlen); - } // namespace nghttp2 #endif // APP_HELPER_H diff --git a/yass/third_party/nghttp2/src/base64_test.cc b/yass/third_party/nghttp2/src/base64_test.cc index 4324bd744c..9ab770fb85 100644 --- a/yass/third_party/nghttp2/src/base64_test.cc +++ b/yass/third_party/nghttp2/src/base64_test.cc @@ -27,7 +27,7 @@ #include #include -#include +#include "munitxx.h" #include @@ -35,26 +35,38 @@ namespace nghttp2 { +namespace { +const MunitTest tests[]{ + munit_void_test(test_base64_encode), + munit_void_test(test_base64_decode), + munit_test_end(), +}; +} // namespace + +const MunitSuite base64_suite{ + "/base64", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_base64_encode(void) { { std::string in = "\xff"; auto out = base64::encode(std::begin(in), std::end(in)); - CU_ASSERT("/w==" == out); + assert_stdstring_equal("/w==", out); } { std::string in = "\xff\xfe"; auto out = base64::encode(std::begin(in), std::end(in)); - CU_ASSERT("//4=" == out); + assert_stdstring_equal("//4=", out); } { std::string in = "\xff\xfe\xfd"; auto out = base64::encode(std::begin(in), std::end(in)); - CU_ASSERT("//79" == out); + assert_stdstring_equal("//79", out); } { std::string in = "\xff\xfe\xfd\xfc"; auto out = base64::encode(std::begin(in), std::end(in)); - CU_ASSERT("//79/A==" == out); + assert_stdstring_equal("//79/A==", out); } } @@ -63,58 +75,65 @@ void test_base64_decode(void) { { std::string in = "/w=="; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("\xff" == out); - CU_ASSERT("\xff" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("\xff", out); + assert_stdstring_equal( + "\xff", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { std::string in = "//4="; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("\xff\xfe" == out); - CU_ASSERT("\xff\xfe" == - base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("\xff\xfe", out); + assert_stdstring_equal( + "\xff\xfe", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { std::string in = "//79"; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("\xff\xfe\xfd" == out); - CU_ASSERT("\xff\xfe\xfd" == - base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("\xff\xfe\xfd", out); + assert_stdstring_equal( + "\xff\xfe\xfd", + base64::decode(balloc, std::begin(in), std::end(in)).str()); } { std::string in = "//79/A=="; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("\xff\xfe\xfd\xfc" == out); - CU_ASSERT("\xff\xfe\xfd\xfc" == - base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("\xff\xfe\xfd\xfc", out); + assert_stdstring_equal( + "\xff\xfe\xfd\xfc", + base64::decode(balloc, std::begin(in), std::end(in)).str()); } { // we check the number of valid input must be multiples of 4 std::string in = "//79="; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("" == out); - CU_ASSERT("" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("", out); + assert_stdstring_equal( + "", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { // ending invalid character at the boundary of multiples of 4 is // bad std::string in = "bmdodHRw\n"; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("" == out); - CU_ASSERT("" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("", out); + assert_stdstring_equal( + "", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { // after seeing '=', subsequent input must be also '='. std::string in = "//79/A=A"; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("" == out); - CU_ASSERT("" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("", out); + assert_stdstring_equal( + "", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { // additional '=' at the end is bad std::string in = "//79/A======"; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("" == out); - CU_ASSERT("" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("", out); + assert_stdstring_equal( + "", base64::decode(balloc, std::begin(in), std::end(in)).str()); } } diff --git a/yass/third_party/nghttp2/src/base64_test.h b/yass/third_party/nghttp2/src/base64_test.h index 8bdb84f8ec..fd74f274c4 100644 --- a/yass/third_party/nghttp2/src/base64_test.h +++ b/yass/third_party/nghttp2/src/base64_test.h @@ -29,10 +29,16 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace nghttp2 { -void test_base64_encode(void); -void test_base64_decode(void); +extern const MunitSuite base64_suite; + +munit_void_test_decl(test_base64_encode); +munit_void_test_decl(test_base64_decode); } // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/buffer_test.cc b/yass/third_party/nghttp2/src/buffer_test.cc index 38688edc7a..20790861ac 100644 --- a/yass/third_party/nghttp2/src/buffer_test.cc +++ b/yass/third_party/nghttp2/src/buffer_test.cc @@ -28,7 +28,7 @@ #include #include -#include +#include "munitxx.h" #include @@ -36,43 +36,54 @@ namespace nghttp2 { +namespace { +const MunitTest tests[]{ + munit_void_test(test_buffer_write), + munit_test_end(), +}; +} // namespace + +const MunitSuite buffer_suite{ + "/buffer", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_buffer_write(void) { Buffer<16> b; - CU_ASSERT(0 == b.rleft()); - CU_ASSERT(16 == b.wleft()); + assert_size(0, ==, b.rleft()); + assert_size(16, ==, b.wleft()); b.write("012", 3); - CU_ASSERT(3 == b.rleft()); - CU_ASSERT(13 == b.wleft()); - CU_ASSERT(b.pos == std::begin(b.buf)); + assert_size(3, ==, b.rleft()); + assert_size(13, ==, b.wleft()); + assert_ptr_equal(b.pos, std::begin(b.buf)); b.drain(3); - CU_ASSERT(0 == b.rleft()); - CU_ASSERT(13 == b.wleft()); - CU_ASSERT(3 == b.pos - std::begin(b.buf)); + assert_size(0, ==, b.rleft()); + assert_size(13, ==, b.wleft()); + assert_ptrdiff(3, ==, b.pos - std::begin(b.buf)); auto n = b.write("0123456789ABCDEF", 16); - CU_ASSERT(n == 13); + assert_ssize(13, ==, n); - CU_ASSERT(13 == b.rleft()); - CU_ASSERT(0 == b.wleft()); - CU_ASSERT(3 == b.pos - std::begin(b.buf)); - CU_ASSERT(0 == memcmp(b.pos, "0123456789ABC", 13)); + assert_size(13, ==, b.rleft()); + assert_size(0, ==, b.wleft()); + assert_ptrdiff(3, ==, b.pos - std::begin(b.buf)); + assert_memory_equal(13, b.pos, "0123456789ABC"); b.reset(); - CU_ASSERT(0 == b.rleft()); - CU_ASSERT(16 == b.wleft()); - CU_ASSERT(b.pos == std::begin(b.buf)); + assert_size(0, ==, b.rleft()); + assert_size(16, ==, b.wleft()); + assert_ptr_equal(b.pos, std::begin(b.buf)); b.write(5); - CU_ASSERT(5 == b.rleft()); - CU_ASSERT(11 == b.wleft()); - CU_ASSERT(b.pos == std::begin(b.buf)); + assert_size(5, ==, b.rleft()); + assert_size(11, ==, b.wleft()); + assert_ptr_equal(b.pos, std::begin(b.buf)); } } // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/buffer_test.h b/yass/third_party/nghttp2/src/buffer_test.h index 6789aa39bc..4fb004f2a6 100644 --- a/yass/third_party/nghttp2/src/buffer_test.h +++ b/yass/third_party/nghttp2/src/buffer_test.h @@ -29,9 +29,15 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace nghttp2 { -void test_buffer_write(void); +extern const MunitSuite buffer_suite; + +munit_void_test_decl(test_buffer_write); } // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/deflatehd.cc b/yass/third_party/nghttp2/src/deflatehd.cc index 7dcfccffcf..ad472de2f8 100644 --- a/yass/third_party/nghttp2/src/deflatehd.cc +++ b/yass/third_party/nghttp2/src/deflatehd.cc @@ -41,6 +41,7 @@ #include +#define NGHTTP2_NO_SSIZE_T #include #include "template.h" @@ -113,11 +114,10 @@ static void output_to_json(nghttp2_hd_deflater *deflater, const uint8_t *buf, static void deflate_hd(nghttp2_hd_deflater *deflater, const std::vector &nva, size_t inputlen, int seq) { - ssize_t rv; std::array buf; - rv = nghttp2_hd_deflate_hd(deflater, buf.data(), buf.size(), - (nghttp2_nv *)nva.data(), nva.size()); + auto rv = nghttp2_hd_deflate_hd2(deflater, buf.data(), buf.size(), + (nghttp2_nv *)nva.data(), nva.size()); if (rv < 0) { fprintf(stderr, "deflate failed with error code %zd at %d\n", rv, seq); exit(EXIT_FAILURE); diff --git a/yass/third_party/nghttp2/src/h2load.cc b/yass/third_party/nghttp2/src/h2load.cc index c885f5fb7f..4f9f00e0ac 100644 --- a/yass/third_party/nghttp2/src/h2load.cc +++ b/yass/third_party/nghttp2/src/h2load.cc @@ -71,6 +71,7 @@ #include "http2.h" #include "util.h" #include "template.h" +#include "ssl_compat.h" #ifndef O_BINARY # define O_BINARY (0) @@ -86,17 +87,6 @@ bool recorded(const std::chrono::steady_clock::time_point &t) { } } // namespace -#if OPENSSL_1_1_1_API -namespace { -std::ofstream keylog_file; -void keylog_callback(const SSL *ssl, const char *line) { - keylog_file.write(line, strlen(line)); - keylog_file.put('\n'); - keylog_file.flush(); -} -} // namespace -#endif // OPENSSL_1_1_1_API - Config::Config() : ciphers(tls::DEFAULT_CIPHER_LIST), tls13_ciphers("TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_" @@ -156,8 +146,8 @@ bool Config::has_base_uri() const { return (!this->base_uri.empty()); } bool Config::rps_enabled() const { return this->rps > 0.0; } bool Config::is_quic() const { #ifdef ENABLE_HTTP3 - return !npn_list.empty() && - (npn_list[0] == NGHTTP3_ALPN_H3 || npn_list[0] == "\x5h3-29"); + return !alpn_list.empty() && + (alpn_list[0] == NGHTTP3_ALPN_H3 || alpn_list[0] == "\x5h3-29"); #else // !ENABLE_HTTP3 return false; #endif // !ENABLE_HTTP3 @@ -411,7 +401,7 @@ namespace { void client_request_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) { auto client = static_cast(w->data); - if (client->streams.size() >= (size_t)config.max_concurrent_streams) { + if (client->streams.size() >= config.max_concurrent_streams) { ev_timer_stop(client->worker->loop, w); return; } @@ -583,8 +573,12 @@ int Client::make_socket(addrinfo *addr) { } } - if (ssl && !util::numeric_host(config.host.c_str())) { - SSL_set_tlsext_host_name(ssl, config.host.c_str()); + if (ssl) { + if (!config.sni.empty()) { + SSL_set_tlsext_host_name(ssl, config.sni.c_str()); + } else if (!util::numeric_host(config.host.c_str())) { + SSL_set_tlsext_host_name(ssl, config.host.c_str()); + } } if (config.is_quic()) { @@ -834,8 +828,6 @@ void Client::process_request_failure() { namespace { void print_server_tmp_key(SSL *ssl) { -// libressl does not have SSL_get_server_tmp_key -#if OPENSSL_VERSION_NUMBER >= 0x10002000L && defined(SSL_get_server_tmp_key) EVP_PKEY *key; if (!SSL_get_server_tmp_key(ssl, &key)) { @@ -855,7 +847,7 @@ void print_server_tmp_key(SSL *ssl) { std::cout << "DH " << EVP_PKEY_bits(key) << " bits" << std::endl; break; case EVP_PKEY_EC: { -# if OPENSSL_3_0_0_API +#if OPENSSL_3_0_0_API std::array curve_name; const char *cname; if (!EVP_PKEY_get_utf8_string_param(key, "group", curve_name.data(), @@ -864,7 +856,7 @@ void print_server_tmp_key(SSL *ssl) { } else { cname = curve_name.data(); } -# else // !OPENSSL_3_0_0_API +#else // !OPENSSL_3_0_0_API auto ec = EVP_PKEY_get1_EC_KEY(key); auto ec_del = defer(EC_KEY_free, ec); auto nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec)); @@ -872,7 +864,7 @@ void print_server_tmp_key(SSL *ssl) { if (!cname) { cname = OBJ_nid2sn(nid); } -# endif // !OPENSSL_3_0_0_API +#endif // !OPENSSL_3_0_0_API std::cout << "ECDH " << cname << " " << EVP_PKEY_bits(key) << " bits" << std::endl; @@ -883,7 +875,6 @@ void print_server_tmp_key(SSL *ssl) { << std::endl; break; } -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L } } // namespace @@ -951,6 +942,10 @@ void Client::on_header(int32_t stream_id, const uint8_t *name, size_t namelen, } } + if (status < 200) { + return; + } + stream.req_stat.status = status; if (status >= 200 && status < 300) { ++worker->stats.status[2]; @@ -1099,14 +1094,7 @@ int Client::connection_made() { const unsigned char *next_proto = nullptr; unsigned int next_proto_len; -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(ssl, &next_proto, &next_proto_len); -#endif // !OPENSSL_NO_NEXTPROTONEG -#if OPENSSL_VERSION_NUMBER >= 0x10002000L - if (next_proto == nullptr) { - SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len); - } -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len); if (next_proto) { auto proto = StringRef{next_proto, next_proto_len}; @@ -1134,11 +1122,10 @@ int Client::connection_made() { std::cout << "No protocol negotiated. Fallback behaviour may be activated" << std::endl; - for (const auto &proto : config.npn_list) { + for (const auto &proto : config.alpn_list) { if (util::streq(NGHTTP2_H1_1_ALPN, StringRef{proto})) { - std::cout - << "Server does not support NPN/ALPN. Falling back to HTTP/1.1." - << std::endl; + std::cout << "Server does not support ALPN. Falling back to HTTP/1.1." + << std::endl; session = std::make_unique(this); selected_proto = NGHTTP2_H1_1.str(); break; @@ -1154,7 +1141,7 @@ int Client::connection_made() { std::cout << "No supported protocol was negotiated. Supported protocols were:" << std::endl; - for (const auto &proto : config.npn_list) { + for (const auto &proto : config.alpn_list) { std::cout << proto.substr(1) << std::endl; } disconnect(); @@ -1888,23 +1875,6 @@ std::string get_reqline(const char *uri, const http_parser_url &u) { } } // namespace -#ifndef OPENSSL_NO_NEXTPROTONEG -namespace { -int client_select_next_proto_cb(SSL *ssl, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg) { - if (util::select_protocol(const_cast(out), outlen, in, - inlen, config.npn_list)) { - return SSL_TLSEXT_ERR_OK; - } - - // OpenSSL will terminate handshake with fatal alert if we return - // NOACK. So there is no way to fallback. - return SSL_TLSEXT_ERR_NOACK; -} -} // namespace -#endif // !OPENSSL_NO_NEXTPROTONEG - namespace { constexpr char UNIX_PATH_PREFIX[] = "unix:"; } // namespace @@ -2080,6 +2050,27 @@ int parse_header_table_size(uint32_t &dst, const char *opt, } } // namespace +namespace { +std::string make_http_authority(const Config &config) { + std::string host; + + if (util::numeric_host(config.host.c_str(), AF_INET6)) { + host += '['; + host += config.host; + host += ']'; + } else { + host = config.host; + } + + if (config.port != config.default_port) { + host += ':'; + host += util::utos(config.port); + } + + return host; +} +} // namespace + namespace { void print_version(std::ostream &out) { out << "h2load nghttp2/" NGHTTP2_VERSION << std::endl; @@ -2095,7 +2086,7 @@ benchmarking tool for HTTP/2 server)" } // namespace namespace { -constexpr char DEFAULT_NPN_LIST[] = "h2,h2-16,h2-14,http/1.1"; +constexpr char DEFAULT_ALPN_LIST[] = "h2,h2-16,h2-14,http/1.1"; } // namespace namespace { @@ -2255,16 +2246,15 @@ Options: instead of TCP. In this case, scheme is inferred from the first URI appeared in the command line or inside input files as usual. - --npn-list= + --alpn-list= Comma delimited list of ALPN protocol identifier sorted in the order of preference. That means most desirable - protocol comes first. This is used in both ALPN and - NPN. The parameter must be delimited by a single comma - only and any white spaces are treated as a part of - protocol string. + protocol comes first. The parameter must be delimited + by a single comma only and any white spaces are treated + as a part of protocol string. Default: )" - << DEFAULT_NPN_LIST << R"( - --h1 Short hand for --npn-list=http/1.1 + << DEFAULT_ALPN_LIST << R"( + --h1 Short hand for --alpn-list=http/1.1 --no-tls-proto=http/1.1, which effectively force http/1.1 for both http and https URI. --header-table-size= @@ -2306,6 +2296,9 @@ Options: --max-udp-payload-size= Specify the maximum outgoing UDP datagram payload size. --ktls Enable ktls. + --sni= + Send in TLS SNI, overriding the host name + specified in URI. -v, --verbose Output debug information. --version Display version information and exit. @@ -2325,15 +2318,8 @@ Options: } // namespace int main(int argc, char **argv) { - tls::libssl_init(); - -#ifndef NOTHREADS - tls::LibsslGlobalLock lock; -#endif // NOTHREADS - std::string datafile; std::string logfile; - std::string qlog_base; bool nreqs_set_manually = false; while (1) { static int flag = 0; @@ -2374,6 +2360,8 @@ int main(int argc, char **argv) { {"qlog-file-base", required_argument, &flag, 16}, {"max-udp-payload-size", required_argument, &flag, 17}, {"ktls", no_argument, &flag, 18}, + {"alpn-list", required_argument, &flag, 19}, + {"sni", required_argument, &flag, 20}, {nullptr, 0, nullptr, 0}}; int option_index = 0; auto c = getopt_long(argc, argv, @@ -2601,10 +2589,6 @@ int main(int argc, char **argv) { config.ifile = optarg; config.timing_script = true; break; - case 4: - // npn-list option - config.npn_list = util::parse_config_str_list(StringRef{optarg}); - break; case 5: // rate-period config.rate_period = util::parse_duration_with_unit(optarg); @@ -2615,7 +2599,7 @@ int main(int argc, char **argv) { break; case 6: // --h1 - config.npn_list = + config.alpn_list = util::parse_config_str_list(StringRef::from_lit("http/1.1")); config.no_tls_proto = Config::PROTO_HTTP1_1; break; @@ -2683,7 +2667,7 @@ int main(int argc, char **argv) { break; case 16: // --qlog-file-base - qlog_base = optarg; + config.qlog_file_base = optarg; break; case 17: { // --max-udp-payload-size @@ -2705,6 +2689,19 @@ int main(int argc, char **argv) { // --ktls config.ktls = true; break; + case 4: + // npn-list option + std::cerr << "--npn-list: deprecated. Use --alpn-list instead." + << std::endl; + // fall through + case 19: + // alpn-list option + config.alpn_list = util::parse_config_str_list(StringRef{optarg}); + break; + case 20: + // --sni + config.sni = optarg; + break; } break; default: @@ -2725,13 +2722,13 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - if (config.npn_list.empty()) { - config.npn_list = - util::parse_config_str_list(StringRef::from_lit(DEFAULT_NPN_LIST)); + if (config.alpn_list.empty()) { + config.alpn_list = + util::parse_config_str_list(StringRef::from_lit(DEFAULT_ALPN_LIST)); } // serialize the APLN tokens - for (auto &proto : config.npn_list) { + for (auto &proto : config.alpn_list) { proto.insert(proto.begin(), static_cast(proto.size())); } @@ -2889,16 +2886,9 @@ int main(int argc, char **argv) { } } - if (!qlog_base.empty()) { - if (!config.is_quic()) { - std::cerr - << "Warning: --qlog-file-base: only effective in quic, ignoring." - << std::endl; - } else { -#ifdef ENABLE_HTTP3 - config.qlog_file_base = qlog_base; -#endif // ENABLE_HTTP3 - } + if (!config.qlog_file_base.empty() && !config.is_quic()) { + std::cerr << "Warning: --qlog-file-base: only effective in quic, ignoring." + << std::endl; } struct sigaction act {}; @@ -2957,65 +2947,51 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_LIBRESSL) if (SSL_CTX_set_ciphersuites(ssl_ctx, config.tls13_ciphers.c_str()) == 0) { std::cerr << "SSL_CTX_set_ciphersuites with " << config.tls13_ciphers << " failed: " << ERR_error_string(ERR_get_error(), nullptr) << std::endl; exit(EXIT_FAILURE); } -#endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_GENUINE_OPENSSL || NGHTTP2_OPENSSL_IS_LIBRESSL -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) if (SSL_CTX_set1_groups_list(ssl_ctx, config.groups.c_str()) != 1) { std::cerr << "SSL_CTX_set1_groups_list failed" << std::endl; exit(EXIT_FAILURE); } -#else // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) - if (SSL_CTX_set1_curves_list(ssl_ctx, config.groups.c_str()) != 1) { - std::cerr << "SSL_CTX_set1_curves_list failed" << std::endl; - exit(EXIT_FAILURE); - } -#endif // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_CTX_set_next_proto_select_cb(ssl_ctx, client_select_next_proto_cb, - nullptr); -#endif // !OPENSSL_NO_NEXTPROTONEG - -#if OPENSSL_VERSION_NUMBER >= 0x10002000L std::vector proto_list; - for (const auto &proto : config.npn_list) { + for (const auto &proto : config.alpn_list) { std::copy_n(proto.c_str(), proto.size(), std::back_inserter(proto_list)); } SSL_CTX_set_alpn_protos(ssl_ctx, proto_list.data(), proto_list.size()); -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L -#if OPENSSL_1_1_1_API - auto keylog_filename = getenv("SSLKEYLOGFILE"); - if (keylog_filename) { - keylog_file.open(keylog_filename, std::ios_base::app); - if (keylog_file) { - SSL_CTX_set_keylog_callback(ssl_ctx, keylog_callback); - } + if (tls::setup_keylog_callback(ssl_ctx) != 0) { + std::cerr << "Failed to setup keylog" << std::endl; + + exit(EXIT_FAILURE); } -#endif // OPENSSL_1_1_1_API + +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + nghttp2::tls::cert_compress, nghttp2::tls::cert_decompress)) { + std::cerr << "SSL_CTX_add_cert_compression_alg failed" << std::endl; + exit(EXIT_FAILURE); + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI std::string user_agent = "h2load nghttp2/" NGHTTP2_VERSION; Headers shared_nva; shared_nva.emplace_back(":scheme", config.scheme); - if (config.port != config.default_port) { - shared_nva.emplace_back(":authority", - config.host + ":" + util::utos(config.port)); - } else { - shared_nva.emplace_back(":authority", config.host); - } + shared_nva.emplace_back(":authority", make_http_authority(config)); shared_nva.emplace_back(":method", config.data_fd == -1 ? "GET" : "POST"); shared_nva.emplace_back("user-agent", user_agent); // list header fields that can be overridden. - auto override_hdrs = make_array(":authority", ":host", ":method", + auto override_hdrs = make_array(":authority", "host", ":method", ":scheme", "user-agent"); for (auto &kv : config.custom_headers) { @@ -3023,7 +2999,7 @@ int main(int argc, char **argv) { kv.name) != std::end(override_hdrs)) { // override header for (auto &nv : shared_nva) { - if ((nv.name == ":authority" && kv.name == ":host") || + if ((nv.name == ":authority" && kv.name == "host") || (nv.name == kv.name)) { nv.value = kv.value; } @@ -3113,18 +3089,18 @@ int main(int argc, char **argv) { #ifndef NOTHREADS size_t nreqs_per_thread = 0; - ssize_t nreqs_rem = 0; + size_t nreqs_rem = 0; if (!config.timing_script) { nreqs_per_thread = config.nreqs / config.nthreads; nreqs_rem = config.nreqs % config.nthreads; } - size_t nclients_per_thread = config.nclients / config.nthreads; - ssize_t nclients_rem = config.nclients % config.nthreads; + auto nclients_per_thread = config.nclients / config.nthreads; + auto nclients_rem = config.nclients % config.nthreads; - size_t rate_per_thread = config.rate / config.nthreads; - ssize_t rate_per_thread_rem = config.rate % config.nthreads; + auto rate_per_thread = config.rate / config.nthreads; + auto rate_per_thread_rem = config.rate % config.nthreads; size_t max_samples_per_thread = std::max(static_cast(256), MAX_SAMPLES / config.nthreads); diff --git a/yass/third_party/nghttp2/src/h2load.h b/yass/third_party/nghttp2/src/h2load.h index d848fdf2ee..860bf77d3c 100644 --- a/yass/third_party/nghttp2/src/h2load.h +++ b/yass/third_party/nghttp2/src/h2load.h @@ -43,6 +43,7 @@ #include #include +#define NGHTTP2_NO_SSIZE_T #include #ifdef ENABLE_HTTP3 @@ -92,7 +93,7 @@ struct Config { size_t nclients; size_t nthreads; // The maximum number of concurrent streams per session. - ssize_t max_concurrent_streams; + size_t max_concurrent_streams; size_t window_bits; size_t connection_window_bits; size_t max_frame_size; @@ -127,9 +128,9 @@ struct Config { bool base_uri_unix; // used when UNIX domain socket is used (base_uri_unix is true). sockaddr_un unix_addr; - // list of supported NPN/ALPN protocol strings in the order of + // list of supported ALPN protocol strings in the order of // preference. - std::vector npn_list; + std::vector alpn_list; // The number of request per second for each client. double rps; // Disables GSO for UDP connections. @@ -138,6 +139,9 @@ struct Config { size_t max_udp_payload_size; // Enable ktls. bool ktls; + // sni is the value sent in TLS SNI, overriding DNS name of the + // remote host. + std::string sni; Config(); ~Config(); diff --git a/yass/third_party/nghttp2/src/h2load_http2_session.cc b/yass/third_party/nghttp2/src/h2load_http2_session.cc index 9cafa0e384..6e810abeb0 100644 --- a/yass/third_party/nghttp2/src/h2load_http2_session.cc +++ b/yass/third_party/nghttp2/src/h2load_http2_session.cc @@ -47,8 +47,7 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *value, size_t valuelen, uint8_t flags, void *user_data) { auto client = static_cast(user_data); - if (frame->hd.type != NGHTTP2_HEADERS || - frame->headers.cat != NGHTTP2_HCAT_RESPONSE) { + if (frame->hd.type != NGHTTP2_HEADERS) { return 0; } client->on_header(frame->hd.stream_id, name, namelen, value, valuelen); @@ -70,15 +69,17 @@ namespace { int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame, void *user_data) { auto client = static_cast(user_data); - if (frame->hd.type != NGHTTP2_HEADERS || - frame->headers.cat != NGHTTP2_HCAT_RESPONSE) { - return 0; - } - client->worker->stats.bytes_head += - frame->hd.length - frame->headers.padlen - - ((frame->hd.flags & NGHTTP2_FLAG_PRIORITY) ? 5 : 0); - if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { - client->record_ttfb(); + switch (frame->hd.type) { + case NGHTTP2_HEADERS: + client->worker->stats.bytes_head += + frame->hd.length - frame->headers.padlen - + ((frame->hd.flags & NGHTTP2_FLAG_PRIORITY) ? 5 : 0); + // fall through + case NGHTTP2_DATA: + if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { + client->record_ttfb(); + } + break; } return 0; } @@ -123,9 +124,10 @@ int before_frame_send_callback(nghttp2_session *session, } // namespace namespace { -ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, uint32_t *data_flags, - nghttp2_data_source *source, void *user_data) { +nghttp2_ssize file_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t length, + uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { auto client = static_cast(user_data); auto config = client->worker->config; auto req_stat = client->get_req_stat(stream_id); @@ -157,8 +159,8 @@ ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, } // namespace namespace { -ssize_t send_callback(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) { +nghttp2_ssize send_callback(nghttp2_session *session, const uint8_t *data, + size_t length, int flags, void *user_data) { auto client = static_cast(user_data); auto &wb = client->wb; @@ -197,7 +199,7 @@ void Http2Session::on_connect() { nghttp2_session_callbacks_set_before_frame_send_callback( callbacks, before_frame_send_callback); - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); nghttp2_option *opt; @@ -256,11 +258,11 @@ int Http2Session::submit_request() { client_->reqidx = 0; } - nghttp2_data_provider prd{{0}, file_read_callback}; + nghttp2_data_provider2 prd{{0}, file_read_callback}; auto stream_id = - nghttp2_submit_request(session_, nullptr, nva.data(), nva.size(), - config->data_fd == -1 ? nullptr : &prd, nullptr); + nghttp2_submit_request2(session_, nullptr, nva.data(), nva.size(), + config->data_fd == -1 ? nullptr : &prd, nullptr); if (stream_id < 0) { return -1; } @@ -271,7 +273,7 @@ int Http2Session::submit_request() { } int Http2Session::on_read(const uint8_t *data, size_t len) { - auto rv = nghttp2_session_mem_recv(session_, data, len); + auto rv = nghttp2_session_mem_recv2(session_, data, len); if (rv < 0) { return -1; } @@ -307,7 +309,7 @@ void Http2Session::terminate() { } size_t Http2Session::max_concurrent_streams() { - return (size_t)client_->worker->config->max_concurrent_streams; + return client_->worker->config->max_concurrent_streams; } } // namespace h2load diff --git a/yass/third_party/nghttp2/src/h2load_http3_session.cc b/yass/third_party/nghttp2/src/h2load_http3_session.cc index f4779beb5f..03a223364f 100644 --- a/yass/third_party/nghttp2/src/h2load_http3_session.cc +++ b/yass/third_party/nghttp2/src/h2load_http3_session.cc @@ -124,7 +124,7 @@ int Http3Session::on_write() { return -1; } void Http3Session::terminate() {} size_t Http3Session::max_concurrent_streams() { - return (size_t)client_->worker->config->max_concurrent_streams; + return client_->worker->config->max_concurrent_streams; } namespace { @@ -147,6 +147,23 @@ int Http3Session::stream_close(int64_t stream_id, uint64_t app_error_code) { return 0; } +namespace { +int end_stream(nghttp3_conn *conn, int64_t stream_id, void *user_data, + void *stream_user_data) { + auto s = static_cast(user_data); + if (s->end_stream(stream_id) != 0) { + return NGHTTP3_ERR_CALLBACK_FAILURE; + } + return 0; +} +} // namespace + +int Http3Session::end_stream(int64_t stream_id) { + client_->record_ttfb(); + + return 0; +} + namespace { int recv_data(nghttp3_conn *conn, int64_t stream_id, const uint8_t *data, size_t datalen, void *user_data, void *stream_user_data) { @@ -321,7 +338,7 @@ int Http3Session::init_conn() { h2load::recv_header, nullptr, // end_trailers h2load::stop_sending, - nullptr, // end_stream + h2load::end_stream, h2load::reset_stream, nullptr, // shutdown }; diff --git a/yass/third_party/nghttp2/src/h2load_http3_session.h b/yass/third_party/nghttp2/src/h2load_http3_session.h index 89c7ca00f5..861041796a 100644 --- a/yass/third_party/nghttp2/src/h2load_http3_session.h +++ b/yass/third_party/nghttp2/src/h2load_http3_session.h @@ -46,6 +46,7 @@ public: int init_conn(); int stream_close(int64_t stream_id, uint64_t app_error_code); + int end_stream(int64_t stream_id); void recv_data(int64_t stream_id, const uint8_t *data, size_t datalen); void consume(int64_t stream_id, size_t nconsumed); void begin_headers(int64_t stream_id); diff --git a/yass/third_party/nghttp2/src/h2load_quic.cc b/yass/third_party/nghttp2/src/h2load_quic.cc index 65fbc109cb..8b3c552fb8 100644 --- a/yass/third_party/nghttp2/src/h2load_quic.cc +++ b/yass/third_party/nghttp2/src/h2load_quic.cc @@ -438,11 +438,11 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen, }, }; - assert(config->npn_list.size()); + assert(config->alpn_list.size()); uint32_t quic_version; - if (config->npn_list[0] == NGHTTP3_ALPN_H3) { + if (config->alpn_list[0] == NGHTTP3_ALPN_H3) { quic_version = NGTCP2_PROTO_VER_V1; } else { quic_version = NGTCP2_PROTO_VER_MIN; @@ -654,7 +654,8 @@ int Client::write_quic() { ngtcp2_conn_get_path_max_tx_udp_payload_size(quic.conn); #endif // UDP_SEGMENT auto max_pktcnt = - ngtcp2_conn_get_send_quantum(quic.conn) / max_udp_payload_size; + std::max(ngtcp2_conn_get_send_quantum(quic.conn) / max_udp_payload_size, + static_cast(1)); uint8_t *bufpos = quic.tx.data.get(); ngtcp2_path_storage ps; size_t gso_size = 0; diff --git a/yass/third_party/nghttp2/src/http2.cc b/yass/third_party/nghttp2/src/http2.cc index 07d0144888..661c4c91dc 100644 --- a/yass/third_party/nghttp2/src/http2.cc +++ b/yass/third_party/nghttp2/src/http2.cc @@ -831,6 +831,11 @@ int lookup_token(const uint8_t *name, size_t namelen) { return HD_LOCATION; } break; + case 'y': + if (util::streq_l("priorit", name, 7)) { + return HD_PRIORITY; + } + break; } break; case 9: @@ -1092,7 +1097,7 @@ bool check_link_param_empty(const char *first, const char *last, const char *pat, size_t patlen) { if (first + patlen <= last) { if (std::equal(pat, pat + patlen, first, util::CaseCmp())) { - // we only accept URI if pat is followd by "" (e.g., + // we only accept URI if pat is followed by "" (e.g., // loadpolicy="") here. if (first + patlen + 2 <= last) { if (*(first + patlen) != '"' || *(first + patlen + 1) != '"') { diff --git a/yass/third_party/nghttp2/src/http2.h b/yass/third_party/nghttp2/src/http2.h index e5b4f1b1c5..7cfe46193f 100644 --- a/yass/third_party/nghttp2/src/http2.h +++ b/yass/third_party/nghttp2/src/http2.h @@ -322,6 +322,7 @@ enum { HD_KEEP_ALIVE, HD_LINK, HD_LOCATION, + HD_PRIORITY, HD_PROXY_CONNECTION, HD_SEC_WEBSOCKET_ACCEPT, HD_SEC_WEBSOCKET_KEY, diff --git a/yass/third_party/nghttp2/src/http2_test.cc b/yass/third_party/nghttp2/src/http2_test.cc index f8be9f4544..3cb0b71484 100644 --- a/yass/third_party/nghttp2/src/http2_test.cc +++ b/yass/third_party/nghttp2/src/http2_test.cc @@ -28,7 +28,7 @@ #include #include -#include +#include "munitxx.h" #include "url-parser/url_parser.h" @@ -45,12 +45,39 @@ using namespace nghttp2; namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_http2_add_header), + munit_void_test(test_http2_get_header), + munit_void_test(test_http2_copy_headers_to_nva), + munit_void_test(test_http2_build_http1_headers_from_headers), + munit_void_test(test_http2_lws), + munit_void_test(test_http2_rewrite_location_uri), + munit_void_test(test_http2_parse_http_status_code), + munit_void_test(test_http2_index_header), + munit_void_test(test_http2_lookup_token), + munit_void_test(test_http2_parse_link_header), + munit_void_test(test_http2_path_join), + munit_void_test(test_http2_normalize_path), + munit_void_test(test_http2_rewrite_clean_path), + munit_void_test(test_http2_get_pure_path_component), + munit_void_test(test_http2_construct_push_component), + munit_void_test(test_http2_contains_trailers), + munit_void_test(test_http2_check_transfer_encoding), + munit_test_end(), +}; +} // namespace + +const MunitSuite http2_suite{ + "/http2", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + namespace { void check_nv(const HeaderRef &a, const nghttp2_nv *b) { - CU_ASSERT(a.name.size() == b->namelen); - CU_ASSERT(a.value.size() == b->valuelen); - CU_ASSERT(memcmp(a.name.c_str(), b->name, b->namelen) == 0); - CU_ASSERT(memcmp(a.value.c_str(), b->value, b->valuelen) == 0); + assert_size(a.name.size(), ==, b->namelen); + assert_size(a.value.size(), ==, b->valuelen); + assert_memory_equal(b->namelen, a.name.c_str(), b->name); + assert_memory_equal(b->valuelen, a.value.c_str(), b->value); } } // namespace @@ -59,51 +86,51 @@ void test_http2_add_header(void) { http2::add_header(nva, (const uint8_t *)"alpha", 5, (const uint8_t *)"123", 3, false, -1); - CU_ASSERT(Headers::value_type("alpha", "123") == nva[0]); - CU_ASSERT(!nva[0].no_index); + assert_true(Headers::value_type("alpha", "123") == nva[0]); + assert_false(nva[0].no_index); nva.clear(); http2::add_header(nva, (const uint8_t *)"alpha", 5, (const uint8_t *)"", 0, true, -1); - CU_ASSERT(Headers::value_type("alpha", "") == nva[0]); - CU_ASSERT(nva[0].no_index); + assert_true(Headers::value_type("alpha", "") == nva[0]); + assert_true(nva[0].no_index); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" b", 2, false, -1); - CU_ASSERT(Headers::value_type("a", "b") == nva[0]); + assert_true(Headers::value_type("a", "b") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)"b ", 2, false, -1); - CU_ASSERT(Headers::value_type("a", "b") == nva[0]); + assert_true(Headers::value_type("a", "b") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" b ", 5, false, -1); - CU_ASSERT(Headers::value_type("a", "b") == nva[0]); + assert_true(Headers::value_type("a", "b") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" bravo ", 9, false, -1); - CU_ASSERT(Headers::value_type("a", "bravo") == nva[0]); + assert_true(Headers::value_type("a", "bravo") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" ", 4, false, -1); - CU_ASSERT(Headers::value_type("a", "") == nva[0]); + assert_true(Headers::value_type("a", "") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"te", 2, (const uint8_t *)"trailers", 8, false, http2::HD_TE); - CU_ASSERT(http2::HD_TE == nva[0].token); + assert_int32(http2::HD_TE, ==, nva[0].token); } void test_http2_get_header(void) { @@ -112,21 +139,21 @@ void test_http2_get_header(void) { {"content-length", "7"}}; const Headers::value_type *rv; rv = http2::get_header(nva, "delta"); - CU_ASSERT(rv != nullptr); - CU_ASSERT("delta" == rv->name); + assert_not_null(rv); + assert_stdstring_equal("delta", rv->name); rv = http2::get_header(nva, "bravo"); - CU_ASSERT(rv != nullptr); - CU_ASSERT("bravo" == rv->name); + assert_not_null(rv); + assert_stdstring_equal("bravo", rv->name); rv = http2::get_header(nva, "foxtrot"); - CU_ASSERT(rv == nullptr); + assert_null(rv); http2::HeaderIndex hdidx; http2::init_hdidx(hdidx); hdidx[http2::HD_CONTENT_LENGTH] = 6; rv = http2::get_header(hdidx, http2::HD_CONTENT_LENGTH, nva); - CU_ASSERT("content-length" == rv->name); + assert_stdstring_equal("content-length", rv->name); } namespace { @@ -177,29 +204,31 @@ void test_http2_copy_headers_to_nva(void) { http2::copy_headers_to_nva_nocopy(nva, headers, http2::HDOP_STRIP_X_FORWARDED_FOR); - CU_ASSERT(7 == nva.size()); + assert_size(7, ==, nva.size()); for (size_t i = 0; i < ans.size(); ++i) { check_nv(headers[ans[i]], &nva[i]); if (ans[i] == 0) { - CU_ASSERT((NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE | - NGHTTP2_NV_FLAG_NO_INDEX) == nva[i].flags); + assert_uint8((NGHTTP2_NV_FLAG_NO_COPY_NAME | + NGHTTP2_NV_FLAG_NO_COPY_VALUE | NGHTTP2_NV_FLAG_NO_INDEX), + ==, nva[i].flags); } else { - CU_ASSERT((NGHTTP2_NV_FLAG_NO_COPY_NAME | - NGHTTP2_NV_FLAG_NO_COPY_VALUE) == nva[i].flags); + assert_uint8( + (NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE), ==, + nva[i].flags); } } nva.clear(); http2::copy_headers_to_nva(nva, headers, http2::HDOP_STRIP_X_FORWARDED_FOR); - CU_ASSERT(7 == nva.size()); + assert_size(7, ==, nva.size()); for (size_t i = 0; i < ans.size(); ++i) { check_nv(headers[ans[i]], &nva[i]); if (ans[i] == 0) { - CU_ASSERT(nva[i].flags & NGHTTP2_NV_FLAG_NO_INDEX); + assert_true(nva[i].flags & NGHTTP2_NV_FLAG_NO_INDEX); } else { - CU_ASSERT(NGHTTP2_NV_FLAG_NONE == nva[i].flags); + assert_false(nva[i].flags); } } @@ -207,7 +236,7 @@ void test_http2_copy_headers_to_nva(void) { auto ans2 = std::vector{0, 2, 4, 6}; http2::copy_headers_to_nva(nva, headers2, http2::HDOP_NONE); - CU_ASSERT(ans2.size() == nva.size()); + assert_size(ans2.size(), ==, nva.size()); for (size_t i = 0; i < ans2.size(); ++i) { check_nv(headers2[ans2[i]], &nva[i]); } @@ -215,7 +244,7 @@ void test_http2_copy_headers_to_nva(void) { nva.clear(); http2::copy_headers_to_nva(nva, headers2, http2::HDOP_STRIP_ALL); - CU_ASSERT(nva.empty()); + assert_true(nva.empty()); } void test_http2_build_http1_headers_from_headers(void) { @@ -224,36 +253,38 @@ void test_http2_build_http1_headers_from_headers(void) { http2::build_http1_headers_from_headers(&buf, headers, http2::HDOP_STRIP_X_FORWARDED_FOR); auto hdrs = std::string(buf.head->pos, buf.head->last); - CU_ASSERT("Alpha: 0\r\n" - "Bravo: 1\r\n" - "Delta: 4\r\n" - "Expect: 5\r\n" - "Foxtrot: 6\r\n" - "Tango: 7\r\n" - "Te: 8\r\n" - "Te: 9\r\n" - "Zulu: 12\r\n" == hdrs); + assert_stdstring_equal("Alpha: 0\r\n" + "Bravo: 1\r\n" + "Delta: 4\r\n" + "Expect: 5\r\n" + "Foxtrot: 6\r\n" + "Tango: 7\r\n" + "Te: 8\r\n" + "Te: 9\r\n" + "Zulu: 12\r\n", + hdrs); buf.reset(); http2::build_http1_headers_from_headers(&buf, headers2, http2::HDOP_NONE); hdrs = std::string(buf.head->pos, buf.head->last); - CU_ASSERT("X-Forwarded-For: xff1\r\n" - "X-Forwarded-Proto: xfp1\r\n" - "Forwarded: fwd1\r\n" - "Via: via1\r\n" == hdrs); + assert_stdstring_equal("X-Forwarded-For: xff1\r\n" + "X-Forwarded-Proto: xfp1\r\n" + "Forwarded: fwd1\r\n" + "Via: via1\r\n", + hdrs); buf.reset(); http2::build_http1_headers_from_headers(&buf, headers2, http2::HDOP_STRIP_ALL); - CU_ASSERT(0 == buf.rleft()); + assert_size(0, ==, buf.rleft()); } void test_http2_lws(void) { - CU_ASSERT(!http2::lws("alpha")); - CU_ASSERT(http2::lws(" ")); - CU_ASSERT(http2::lws("")); + assert_false(http2::lws("alpha")); + assert_true(http2::lws(" ")); + assert_true(http2::lws("")); } namespace { @@ -263,11 +294,11 @@ void check_rewrite_location_uri(const std::string &want, const std::string &uri, const std::string &upstream_scheme) { BlockAllocator balloc(4096, 4096); http_parser_url u{}; - CU_ASSERT(0 == http_parser_parse_url(uri.c_str(), uri.size(), 0, &u)); + assert_int(0, ==, http_parser_parse_url(uri.c_str(), uri.size(), 0, &u)); auto got = http2::rewrite_location_uri( balloc, StringRef{uri}, u, StringRef{match_host}, StringRef{req_authority}, StringRef{upstream_scheme}); - CU_ASSERT(want == got); + assert_stdstring_equal(want, got.str()); } } // namespace @@ -299,13 +330,15 @@ void test_http2_rewrite_location_uri(void) { } void test_http2_parse_http_status_code(void) { - CU_ASSERT(200 == http2::parse_http_status_code(StringRef::from_lit("200"))); - CU_ASSERT(102 == http2::parse_http_status_code(StringRef::from_lit("102"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef::from_lit("099"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef::from_lit("99"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef::from_lit("-1"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef::from_lit("20a"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef{})); + assert_int(200, ==, + http2::parse_http_status_code(StringRef::from_lit("200"))); + assert_int(102, ==, + http2::parse_http_status_code(StringRef::from_lit("102"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef::from_lit("099"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef::from_lit("99"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef::from_lit("-1"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef::from_lit("20a"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef{})); } void test_http2_index_header(void) { @@ -315,402 +348,402 @@ void test_http2_index_header(void) { http2::index_header(hdidx, http2::HD__AUTHORITY, 0); http2::index_header(hdidx, -1, 1); - CU_ASSERT(0 == hdidx[http2::HD__AUTHORITY]); + assert_uint16(0, ==, hdidx[http2::HD__AUTHORITY]); } void test_http2_lookup_token(void) { - CU_ASSERT(http2::HD__AUTHORITY == - http2::lookup_token(StringRef::from_lit(":authority"))); - CU_ASSERT(-1 == http2::lookup_token(StringRef::from_lit(":authorit"))); - CU_ASSERT(-1 == http2::lookup_token(StringRef::from_lit(":Authority"))); - CU_ASSERT(http2::HD_EXPECT == - http2::lookup_token(StringRef::from_lit("expect"))); + assert_int(http2::HD__AUTHORITY, ==, + http2::lookup_token(StringRef::from_lit(":authority"))); + assert_int(-1, ==, http2::lookup_token(StringRef::from_lit(":authorit"))); + assert_int(-1, ==, http2::lookup_token(StringRef::from_lit(":Authority"))); + assert_int(http2::HD_EXPECT, ==, + http2::lookup_token(StringRef::from_lit("expect"))); } void test_http2_parse_link_header(void) { { // only URI appears; we don't extract URI unless it bears rel=preload auto res = http2::parse_link_header(StringRef::from_lit("")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // URI url should be extracted auto res = http2::parse_link_header(StringRef::from_lit("; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With extra link-param. URI url should be extracted auto res = http2::parse_link_header( StringRef::from_lit("; rel=preload; as=file")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With extra link-param. URI url should be extracted auto res = http2::parse_link_header( StringRef::from_lit("; as=file; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With extra link-param and quote-string. URI url should be // extracted auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel=preload; title="foo,bar")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With extra link-param and quote-string. URI url should be // extracted auto res = http2::parse_link_header( StringRef::from_lit(R"(; title="foo,bar"; rel=preload)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // ',' after quote-string auto res = http2::parse_link_header( StringRef::from_lit(R"(; title="foo,bar", ; rel=preload)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // Only first URI should be extracted. auto res = http2::parse_link_header( StringRef::from_lit("; rel=preload, ")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // Both have rel=preload, so both urls should be extracted auto res = http2::parse_link_header( StringRef::from_lit("; rel=preload, ; rel=preload")); - CU_ASSERT(2 == res.size()); - CU_ASSERT("url" == res[0].uri); - CU_ASSERT("url2" == res[1].uri); + assert_size(2, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); + assert_stdstring_equal("url2", res[1].uri.str()); } { // Second URI uri should be extracted. auto res = http2::parse_link_header( StringRef::from_lit(", ;rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // Error if input ends with ';' auto res = http2::parse_link_header(StringRef::from_lit(";rel=preload;")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Error if link header ends with ';' auto res = http2::parse_link_header( StringRef::from_lit(";rel=preload;, ")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // OK if input ends with ',' auto res = http2::parse_link_header(StringRef::from_lit(";rel=preload,")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // Multiple repeated ','s between fields is OK auto res = http2::parse_link_header( StringRef::from_lit(",,,;rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // Error if url is not enclosed by <> auto res = http2::parse_link_header(StringRef::from_lit("url>;rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Error if url is not enclosed by <> auto res = http2::parse_link_header(StringRef::from_lit(";rel=preload; as=")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Empty parameter value is not allowed auto res = http2::parse_link_header(StringRef::from_lit(";as=;rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Empty parameter value is not allowed auto res = http2::parse_link_header( StringRef::from_lit(";as=, ;rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Empty parameter name is not allowed auto res = http2::parse_link_header( StringRef::from_lit("; =file; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Without whitespaces auto res = http2::parse_link_header( StringRef::from_lit(";as=file;rel=preload,;rel=preload")); - CU_ASSERT(2 == res.size()); - CU_ASSERT("url" == res[0].uri); - CU_ASSERT("url2" == res[1].uri); + assert_size(2, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); + assert_stdstring_equal("url2", res[1].uri.str()); } { // link-extension may have no value auto res = http2::parse_link_header(StringRef::from_lit("; as; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // ext-name-star auto res = http2::parse_link_header( StringRef::from_lit("; foo*=bar; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // '*' is not allowed expect for trailing one auto res = http2::parse_link_header( StringRef::from_lit("; *=bar; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // '*' is not allowed expect for trailing one auto res = http2::parse_link_header( StringRef::from_lit("; foo*bar=buzz; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // ext-name-star must be followed by '=' auto res = http2::parse_link_header( StringRef::from_lit("; foo*; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // '>' is not followed by ';' auto res = http2::parse_link_header(StringRef::from_lit(" rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Starting with whitespace is no problem. auto res = http2::parse_link_header(StringRef::from_lit(" ; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload is a prefix of bogus rel parameter value auto res = http2::parse_link_header(StringRef::from_lit("; rel=preloadx")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="preload")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list followed by another parameter auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="preload foo")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list following another parameter auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="foo preload")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list between other parameters auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="foo preload bar")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list between other parameters auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="foo preload bar")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // no preload in relation-types list auto res = http2::parse_link_header(StringRef::from_lit(R"(; rel="foo")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // no preload in relation-types list, multiple unrelated elements. auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="foo bar")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list, followed by another link-value. auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="preload", )")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list, following another link-value. auto res = http2::parse_link_header( StringRef::from_lit(R"(, ; rel="preload")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // preload in relation-types list, followed by another link-param. auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="preload"; as="font")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list, followed by character other // than ';' or ',' auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="preload".)")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list, followed by ';' but it // terminates input auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="preload";)")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list, followed by ',' but it // terminates input auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="preload",)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list but there is preceding white // space. auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel=" preload")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list but there is trailing white // space. auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel="preload ")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // backslash escaped characters in quoted-string auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel=preload; title="foo\"baz\"bar")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // anchor="" is acceptable auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel=preload; anchor="")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With anchor="#foo", url should be ignored auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel=preload; anchor="#foo")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // With anchor=f, url should be ignored auto res = http2::parse_link_header( StringRef::from_lit("; rel=preload; anchor=f")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // First url is ignored With anchor="#foo", but url should be // accepted. auto res = http2::parse_link_header(StringRef::from_lit( R"(; rel=preload; anchor="#foo", ; rel=preload)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // With loadpolicy="next", url should be ignored auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel=preload; loadpolicy="next")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // url should be picked up if empty loadpolicy is specified auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel=preload; loadpolicy="")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // case-insensitive match auto res = http2::parse_link_header( StringRef::from_lit(R"(; rel=preload; ANCHOR="#foo", ; )" R"(REL=PRELOAD, ; REL="foo PRELOAD bar")")); - CU_ASSERT(2 == res.size()); - CU_ASSERT("url2" == res[0].uri); - CU_ASSERT("url3" == res[1].uri); + assert_size(2, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); + assert_stdstring_equal("url3", res[1].uri.str()); } { // nopush at the end of input auto res = http2::parse_link_header( StringRef::from_lit("; rel=preload; nopush")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // nopush followed by ';' auto res = http2::parse_link_header( StringRef::from_lit("; rel=preload; nopush; foo")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // nopush followed by ',' auto res = http2::parse_link_header( StringRef::from_lit("; nopush; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // string whose prefix is nopush auto res = http2::parse_link_header( StringRef::from_lit("; nopushyes; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // rel=preload twice auto res = http2::parse_link_header( StringRef::from_lit("; rel=preload; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } } @@ -718,124 +751,132 @@ void test_http2_path_join(void) { { auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/"); - CU_ASSERT("/" == http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/alpha"); - CU_ASSERT("/alpha" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel ends with trailing '/' auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/alpha/"); - CU_ASSERT("/alpha/" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel contains multiple components auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/alpha/bravo"); - CU_ASSERT("/alpha/bravo" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/bravo", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel is relative auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("alpha/bravo"); - CU_ASSERT("/alpha/bravo" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/bravo", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel is relative and base ends without /, which means it refers // to file. auto base = StringRef::from_lit("/alpha"); auto rel = StringRef::from_lit("bravo/charlie"); - CU_ASSERT("/bravo/charlie" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/bravo/charlie", + http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel contains repeated '/'s auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/alpha/////bravo/////"); - CU_ASSERT("/alpha/bravo/" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/bravo/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // base ends with '/', so '..' eats 'bravo' auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("../charlie/delta"); - CU_ASSERT("/alpha/charlie/delta" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/charlie/delta", + http2::path_join(base, StringRef{}, rel, StringRef{})); } { // base does not end with '/', so '..' eats 'alpha/bravo' auto base = StringRef::from_lit("/alpha/bravo"); auto rel = StringRef::from_lit("../charlie"); - CU_ASSERT("/charlie" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/charlie", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // 'charlie' is eaten by following '..' auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("../charlie/../delta"); - CU_ASSERT("/alpha/delta" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/delta", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // excessive '..' results in '/' auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("../../../"); - CU_ASSERT("/" == http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // excessive '..' and path component auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("../../../charlie"); - CU_ASSERT("/charlie" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/charlie", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel ends with '..' auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("charlie/.."); - CU_ASSERT("/alpha/bravo/" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/bravo/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // base empty and rel contains '..' auto base = StringRef{}; auto rel = StringRef::from_lit("charlie/.."); - CU_ASSERT("/" == http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // '.' is ignored auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("charlie/././././delta"); - CU_ASSERT("/charlie/delta" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/charlie/delta", + http2::path_join(base, StringRef{}, rel, StringRef{})); } { // trailing '.' is ignored auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("charlie/."); - CU_ASSERT("/charlie/" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/charlie/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // query auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/"); auto relq = StringRef::from_lit("q"); - CU_ASSERT("/?q" == http2::path_join(base, StringRef{}, rel, relq)); + assert_stdstring_equal("/?q", + http2::path_join(base, StringRef{}, rel, relq)); } { // empty rel and query auto base = StringRef::from_lit("/alpha"); auto rel = StringRef{}; auto relq = StringRef::from_lit("q"); - CU_ASSERT("/alpha?q" == http2::path_join(base, StringRef{}, rel, relq)); + assert_stdstring_equal("/alpha?q", + http2::path_join(base, StringRef{}, rel, relq)); } { // both rel and query are empty @@ -843,26 +884,28 @@ void test_http2_path_join(void) { auto baseq = StringRef::from_lit("r"); auto rel = StringRef{}; auto relq = StringRef{}; - CU_ASSERT("/alpha?r" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/alpha?r", + http2::path_join(base, baseq, rel, relq)); } { // empty base auto base = StringRef{}; auto rel = StringRef::from_lit("/alpha"); - CU_ASSERT("/alpha" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // everything is empty - CU_ASSERT("/" == http2::path_join(StringRef{}, StringRef{}, StringRef{}, - StringRef{})); + assert_stdstring_equal("/", http2::path_join(StringRef{}, StringRef{}, + StringRef{}, StringRef{})); } { // only baseq is not empty auto base = StringRef{}; auto baseq = StringRef::from_lit("r"); auto rel = StringRef{}; - CU_ASSERT("/?r" == http2::path_join(base, baseq, rel, StringRef{})); + assert_stdstring_equal("/?r", + http2::path_join(base, baseq, rel, StringRef{})); } { // path starts with multiple '/'s. @@ -870,8 +913,8 @@ void test_http2_path_join(void) { auto baseq = StringRef{}; auto rel = StringRef::from_lit("//alpha//bravo"); auto relq = StringRef::from_lit("charlie"); - CU_ASSERT("/alpha/bravo?charlie" == - http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/alpha/bravo?charlie", + http2::path_join(base, baseq, rel, relq)); } // Test cases from RFC 3986, section 5.4. constexpr auto base = StringRef::from_lit("/b/c/d;p"); @@ -879,239 +922,266 @@ void test_http2_path_join(void) { { auto rel = StringRef::from_lit("g"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("./g"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g/"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("/g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef{}; auto relq = StringRef::from_lit("y"); - CU_ASSERT("/b/c/d;p?y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/d;p?y", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g"); auto relq = StringRef::from_lit("y"); - CU_ASSERT("/b/c/g?y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g?y", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit(";x"); auto relq = StringRef{}; - CU_ASSERT("/b/c/;x" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/;x", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g;x"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g;x" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g;x", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g;x"); auto relq = StringRef::from_lit("y"); - CU_ASSERT("/b/c/g;x?y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g;x?y", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef{}; auto relq = StringRef{}; - CU_ASSERT("/b/c/d;p?q" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/d;p?q", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("."); auto relq = StringRef{}; - CU_ASSERT("/b/c/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("./"); auto relq = StringRef{}; - CU_ASSERT("/b/c/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit(".."); auto relq = StringRef{}; - CU_ASSERT("/b/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../"); auto relq = StringRef{}; - CU_ASSERT("/b/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../g"); auto relq = StringRef{}; - CU_ASSERT("/b/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../.."); auto relq = StringRef{}; - CU_ASSERT("/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../../"); auto relq = StringRef{}; - CU_ASSERT("/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../../g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../../../g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../../../../g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("/./g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("/../g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g."); auto relq = StringRef{}; - CU_ASSERT("/b/c/g." == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g.", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit(".g"); auto relq = StringRef{}; - CU_ASSERT("/b/c/.g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/.g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g.."); auto relq = StringRef{}; - CU_ASSERT("/b/c/g.." == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g..", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("..g"); auto relq = StringRef{}; - CU_ASSERT("/b/c/..g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/..g", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("./../g"); auto relq = StringRef{}; - CU_ASSERT("/b/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("./g/."); auto relq = StringRef{}; - CU_ASSERT("/b/c/g/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g/./h"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g/h" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g/h", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g/../h"); auto relq = StringRef{}; - CU_ASSERT("/b/c/h" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/h", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g;x=1/./y"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g;x=1/y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g;x=1/y", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g;x=1/../y"); auto relq = StringRef{}; - CU_ASSERT("/b/c/y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/y", http2::path_join(base, baseq, rel, relq)); } } void test_http2_normalize_path(void) { - CU_ASSERT("/alpha/charlie" == - http2::normalize_path( - StringRef::from_lit("/alpha/bravo/../charlie"), StringRef{})); + assert_stdstring_equal( + "/alpha/charlie", + http2::normalize_path(StringRef::from_lit("/alpha/bravo/../charlie"), + StringRef{})); - CU_ASSERT("/alpha" == - http2::normalize_path(StringRef::from_lit("/a%6c%70%68%61"), - StringRef{})); + assert_stdstring_equal( + "/alpha", http2::normalize_path(StringRef::from_lit("/a%6c%70%68%61"), + StringRef{})); - CU_ASSERT( - "/alpha%2F%3A" == + assert_stdstring_equal( + "/alpha%2F%3A", http2::normalize_path(StringRef::from_lit("/alpha%2f%3a"), StringRef{})); - CU_ASSERT("/%2F" == - http2::normalize_path(StringRef::from_lit("%2f"), StringRef{})); + assert_stdstring_equal( + "/%2F", http2::normalize_path(StringRef::from_lit("%2f"), StringRef{})); - CU_ASSERT("/%f" == - http2::normalize_path(StringRef::from_lit("%f"), StringRef{})); + assert_stdstring_equal( + "/%f", http2::normalize_path(StringRef::from_lit("%f"), StringRef{})); - CU_ASSERT("/%" == - http2::normalize_path(StringRef::from_lit("%"), StringRef{})); + assert_stdstring_equal( + "/%", http2::normalize_path(StringRef::from_lit("%"), StringRef{})); - CU_ASSERT("/" == http2::normalize_path(StringRef{}, StringRef{})); + assert_stdstring_equal("/", http2::normalize_path(StringRef{}, StringRef{})); - CU_ASSERT("/alpha?bravo" == - http2::normalize_path(StringRef::from_lit("/alpha"), - StringRef::from_lit("bravo"))); + assert_stdstring_equal("/alpha?bravo", + http2::normalize_path(StringRef::from_lit("/alpha"), + StringRef::from_lit("bravo"))); } void test_http2_rewrite_clean_path(void) { BlockAllocator balloc(4096, 4096); // unreserved characters - CU_ASSERT("/alpha/bravo/" == - http2::rewrite_clean_path(balloc, - StringRef::from_lit("/alpha/%62ravo/"))); + assert_stdstring_equal( + "/alpha/bravo/", + http2::rewrite_clean_path(balloc, StringRef::from_lit("/alpha/%62ravo/")) + .str()); // percent-encoding is converted to upper case. - CU_ASSERT("/delta%3A" == http2::rewrite_clean_path( - balloc, StringRef::from_lit("/delta%3a"))); + assert_stdstring_equal( + "/delta%3A", + http2::rewrite_clean_path(balloc, StringRef::from_lit("/delta%3a")) + .str()); // path component is normalized before matching - CU_ASSERT( - "/alpha/bravo/" == + assert_stdstring_equal( + "/alpha/bravo/", http2::rewrite_clean_path( - balloc, StringRef::from_lit("/alpha/charlie/%2e././bravo/delta/.."))); + balloc, StringRef::from_lit("/alpha/charlie/%2e././bravo/delta/..")) + .str()); - CU_ASSERT("alpha%3a" == - http2::rewrite_clean_path(balloc, StringRef::from_lit("alpha%3a"))); + assert_stdstring_equal( + "alpha%3a", + http2::rewrite_clean_path(balloc, StringRef::from_lit("alpha%3a")).str()); - CU_ASSERT("" == http2::rewrite_clean_path(balloc, StringRef{})); + assert_stdstring_equal("", + http2::rewrite_clean_path(balloc, StringRef{}).str()); - CU_ASSERT( - "/alpha?bravo" == - http2::rewrite_clean_path(balloc, StringRef::from_lit("//alpha?bravo"))); + assert_stdstring_equal( + "/alpha?bravo", + http2::rewrite_clean_path(balloc, StringRef::from_lit("//alpha?bravo")) + .str()); } void test_http2_get_pure_path_component(void) { - CU_ASSERT("/" == http2::get_pure_path_component(StringRef::from_lit("/"))); + assert_stdstring_equal( + "/", http2::get_pure_path_component(StringRef::from_lit("/")).str()); - CU_ASSERT("/foo" == - http2::get_pure_path_component(StringRef::from_lit("/foo"))); + assert_stdstring_equal( + "/foo", + http2::get_pure_path_component(StringRef::from_lit("/foo")).str()); - CU_ASSERT("/bar" == http2::get_pure_path_component( - StringRef::from_lit("https://example.org/bar"))); + assert_stdstring_equal("/bar", + http2::get_pure_path_component( + StringRef::from_lit("https://example.org/bar")) + .str()); - CU_ASSERT("/alpha" == http2::get_pure_path_component(StringRef::from_lit( - "https://example.org/alpha?q=a"))); + assert_stdstring_equal( + "/alpha", http2::get_pure_path_component( + StringRef::from_lit("https://example.org/alpha?q=a")) + .str()); - CU_ASSERT("/bravo" == http2::get_pure_path_component(StringRef::from_lit( - "https://example.org/bravo?q=a#fragment"))); + assert_stdstring_equal( + "/bravo", + http2::get_pure_path_component( + StringRef::from_lit("https://example.org/bravo?q=a#fragment")) + .str()); - CU_ASSERT("" == - http2::get_pure_path_component(StringRef::from_lit("\x01\x02"))); + assert_stdstring_equal( + "", + http2::get_pure_path_component(StringRef::from_lit("\x01\x02")).str()); } void test_http2_construct_push_component(void) { @@ -1122,11 +1192,12 @@ void test_http2_construct_push_component(void) { base = StringRef::from_lit("/b/"); uri = StringRef::from_lit("https://example.org/foo"); - CU_ASSERT(0 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); - CU_ASSERT("https" == scheme); - CU_ASSERT("example.org" == authority); - CU_ASSERT("/foo" == path); + assert_int(0, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); + assert_stdstring_equal("https", scheme.str()); + assert_stdstring_equal("example.org", authority.str()); + assert_stdstring_equal("/foo", path.str()); scheme = StringRef{}; authority = StringRef{}; @@ -1134,11 +1205,12 @@ void test_http2_construct_push_component(void) { uri = StringRef::from_lit("/foo/bar?q=a"); - CU_ASSERT(0 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); - CU_ASSERT("" == scheme); - CU_ASSERT("" == authority); - CU_ASSERT("/foo/bar?q=a" == path); + assert_int(0, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); + assert_stdstring_equal("", scheme.str()); + assert_stdstring_equal("", authority.str()); + assert_stdstring_equal("/foo/bar?q=a", path.str()); scheme = StringRef{}; authority = StringRef{}; @@ -1146,11 +1218,12 @@ void test_http2_construct_push_component(void) { uri = StringRef::from_lit("foo/../bar?q=a"); - CU_ASSERT(0 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); - CU_ASSERT("" == scheme); - CU_ASSERT("" == authority); - CU_ASSERT("/b/bar?q=a" == path); + assert_int(0, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); + assert_stdstring_equal("", scheme.str()); + assert_stdstring_equal("", authority.str()); + assert_stdstring_equal("/b/bar?q=a", path.str()); scheme = StringRef{}; authority = StringRef{}; @@ -1158,91 +1231,97 @@ void test_http2_construct_push_component(void) { uri = StringRef{}; - CU_ASSERT(-1 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); + assert_int(-1, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); scheme = StringRef{}; authority = StringRef{}; path = StringRef{}; uri = StringRef::from_lit("?q=a"); - CU_ASSERT(0 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); - CU_ASSERT("" == scheme); - CU_ASSERT("" == authority); - CU_ASSERT("/b/?q=a" == path); + assert_int(0, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); + assert_stdstring_equal("", scheme.str()); + assert_stdstring_equal("", authority.str()); + assert_stdstring_equal("/b/?q=a", path.str()); } void test_http2_contains_trailers(void) { - CU_ASSERT(!http2::contains_trailers(StringRef::from_lit(""))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("trailers"))); + assert_false(http2::contains_trailers(StringRef::from_lit(""))); + assert_true(http2::contains_trailers(StringRef::from_lit("trailers"))); // Match must be case-insensitive. - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("TRAILERS"))); - CU_ASSERT(!http2::contains_trailers(StringRef::from_lit("trailer"))); - CU_ASSERT(!http2::contains_trailers(StringRef::from_lit("trailers 3"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("trailers,"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("trailers,foo"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("foo,trailers"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("foo,trailers,bar"))); - CU_ASSERT( + assert_true(http2::contains_trailers(StringRef::from_lit("TRAILERS"))); + assert_false(http2::contains_trailers(StringRef::from_lit("trailer"))); + assert_false(http2::contains_trailers(StringRef::from_lit("trailers 3"))); + assert_true(http2::contains_trailers(StringRef::from_lit("trailers,"))); + assert_true(http2::contains_trailers(StringRef::from_lit("trailers,foo"))); + assert_true(http2::contains_trailers(StringRef::from_lit("foo,trailers"))); + assert_true( + http2::contains_trailers(StringRef::from_lit("foo,trailers,bar"))); + assert_true( http2::contains_trailers(StringRef::from_lit("foo, trailers ,bar"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit(",trailers"))); + assert_true(http2::contains_trailers(StringRef::from_lit(",trailers"))); } void test_http2_check_transfer_encoding(void) { - CU_ASSERT(http2::check_transfer_encoding(StringRef::from_lit("chunked"))); - CU_ASSERT(http2::check_transfer_encoding(StringRef::from_lit("foo,chunked"))); - CU_ASSERT( + assert_true(http2::check_transfer_encoding(StringRef::from_lit("chunked"))); + assert_true( + http2::check_transfer_encoding(StringRef::from_lit("foo,chunked"))); + assert_true( http2::check_transfer_encoding(StringRef::from_lit("foo, chunked"))); - CU_ASSERT( + assert_true( http2::check_transfer_encoding(StringRef::from_lit("foo , chunked"))); - CU_ASSERT( + assert_true( http2::check_transfer_encoding(StringRef::from_lit("chunked;foo=bar"))); - CU_ASSERT( + assert_true( http2::check_transfer_encoding(StringRef::from_lit("chunked ; foo=bar"))); - CU_ASSERT(http2::check_transfer_encoding( + assert_true(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar")"))); - CU_ASSERT(http2::check_transfer_encoding( + assert_true(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="\bar\"";FOO=BAR)"))); - CU_ASSERT( + assert_true( http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo="")"))); - CU_ASSERT(http2::check_transfer_encoding( + assert_true(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar" , gzip)"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef{})); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit(",chunked"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked,"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked, "))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("foo,,chunked"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("chunked;foo"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked;"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("chunked;foo=bar;"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("chunked;?=bar"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("chunked;=bar"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked;;"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked?"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit(","))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit(" "))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit(";"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("\""))); - CU_ASSERT(!http2::check_transfer_encoding( + assert_false(http2::check_transfer_encoding(StringRef{})); + assert_false(http2::check_transfer_encoding(StringRef::from_lit(",chunked"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit("chunked,"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked, "))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("foo,,chunked"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;foo"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit("chunked;"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;foo=bar;"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;?=bar"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;=bar"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;;"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit("chunked?"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit(","))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit(" "))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit(";"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit("\""))); + assert_false(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar)"))); - CU_ASSERT(!http2::check_transfer_encoding( + assert_false(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar\)"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo="bar\)" - "\x0a" - R"(")"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo=")" - "\x0a" - R"(")"))); - CU_ASSERT(!http2::check_transfer_encoding( + assert_false( + http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo="bar\)" + "\x0a" + R"(")"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo=")" + "\x0a" + R"(")"))); + assert_false(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar",,gzip)"))); } diff --git a/yass/third_party/nghttp2/src/http2_test.h b/yass/third_party/nghttp2/src/http2_test.h index 382470d471..75fd707312 100644 --- a/yass/third_party/nghttp2/src/http2_test.h +++ b/yass/third_party/nghttp2/src/http2_test.h @@ -29,25 +29,31 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_http2_add_header(void); -void test_http2_get_header(void); -void test_http2_copy_headers_to_nva(void); -void test_http2_build_http1_headers_from_headers(void); -void test_http2_lws(void); -void test_http2_rewrite_location_uri(void); -void test_http2_parse_http_status_code(void); -void test_http2_index_header(void); -void test_http2_lookup_token(void); -void test_http2_parse_link_header(void); -void test_http2_path_join(void); -void test_http2_normalize_path(void); -void test_http2_rewrite_clean_path(void); -void test_http2_get_pure_path_component(void); -void test_http2_construct_push_component(void); -void test_http2_contains_trailers(void); -void test_http2_check_transfer_encoding(void); +extern const MunitSuite http2_suite; + +munit_void_test_decl(test_http2_add_header); +munit_void_test_decl(test_http2_get_header); +munit_void_test_decl(test_http2_copy_headers_to_nva); +munit_void_test_decl(test_http2_build_http1_headers_from_headers); +munit_void_test_decl(test_http2_lws); +munit_void_test_decl(test_http2_rewrite_location_uri); +munit_void_test_decl(test_http2_parse_http_status_code); +munit_void_test_decl(test_http2_index_header); +munit_void_test_decl(test_http2_lookup_token); +munit_void_test_decl(test_http2_parse_link_header); +munit_void_test_decl(test_http2_path_join); +munit_void_test_decl(test_http2_normalize_path); +munit_void_test_decl(test_http2_rewrite_clean_path); +munit_void_test_decl(test_http2_get_pure_path_component); +munit_void_test_decl(test_http2_construct_push_component); +munit_void_test_decl(test_http2_contains_trailers); +munit_void_test_decl(test_http2_check_transfer_encoding); } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/inflatehd.cc b/yass/third_party/nghttp2/src/inflatehd.cc index f484042a3a..537b4fadca 100644 --- a/yass/third_party/nghttp2/src/inflatehd.cc +++ b/yass/third_party/nghttp2/src/inflatehd.cc @@ -41,6 +41,7 @@ #include +#define NGHTTP2_NO_SSIZE_T #include #include "template.h" @@ -93,7 +94,6 @@ static void to_json(nghttp2_hd_inflater *inflater, json_t *headers, } static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) { - ssize_t rv; nghttp2_nv nv; int inflate_flags; size_t old_settings_table_size = @@ -120,8 +120,8 @@ static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) { seq); return -1; } - rv = nghttp2_hd_inflate_change_table_size(inflater, - json_integer_value(table_size)); + auto rv = nghttp2_hd_inflate_change_table_size( + inflater, json_integer_value(table_size)); if (rv != 0) { fprintf(stderr, "nghttp2_hd_change_table_size() failed with error %s at %d\n", @@ -147,7 +147,8 @@ static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) { auto p = buf.data(); for (;;) { inflate_flags = 0; - rv = nghttp2_hd_inflate_hd(inflater, &nv, &inflate_flags, p, buflen, 1); + auto rv = + nghttp2_hd_inflate_hd3(inflater, &nv, &inflate_flags, p, buflen, 1); if (rv < 0) { fprintf(stderr, "inflate failed with error code %zd at %d\n", rv, seq); exit(EXIT_FAILURE); diff --git a/yass/third_party/nghttp2/src/libevent_util.cc b/yass/third_party/nghttp2/src/libevent_util.cc deleted file mode 100644 index 3b60b6d9df..0000000000 --- a/yass/third_party/nghttp2/src/libevent_util.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* - * nghttp2 - HTTP/2 C Library - * - * Copyright (c) 2014 Tatsuhiro Tsujikawa - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "libevent_util.h" - -#include -#include - -namespace nghttp2 { - -namespace util { - -EvbufferBuffer::EvbufferBuffer() - : evbuffer_(nullptr), - bucket_(nullptr), - buf_(nullptr), - bufmax_(0), - buflen_(0), - limit_(0), - writelen_(0) {} - -EvbufferBuffer::EvbufferBuffer(evbuffer *evbuffer, uint8_t *buf, size_t bufmax, - ssize_t limit) - : evbuffer_(evbuffer), - bucket_(limit == -1 ? nullptr : evbuffer_new()), - buf_(buf), - bufmax_(bufmax), - buflen_(0), - limit_(limit), - writelen_(0) {} - -void EvbufferBuffer::reset(evbuffer *evbuffer, uint8_t *buf, size_t bufmax, - ssize_t limit) { - evbuffer_ = evbuffer; - buf_ = buf; - if (limit != -1 && !bucket_) { - bucket_ = evbuffer_new(); - } - bufmax_ = bufmax; - buflen_ = 0; - limit_ = limit; - writelen_ = 0; -} - -EvbufferBuffer::~EvbufferBuffer() { - if (bucket_) { - evbuffer_free(bucket_); - } -} - -int EvbufferBuffer::write_buffer() { - for (auto pos = buf_, end = buf_ + buflen_; pos < end;) { - // To avoid merging chunks in evbuffer, we first add to temporal - // buffer bucket_ and then move its chain to evbuffer_. - auto nwrite = std::min(end - pos, limit_); - auto rv = evbuffer_add(bucket_, pos, nwrite); - if (rv == -1) { - return -1; - } - rv = evbuffer_add_buffer(evbuffer_, bucket_); - if (rv == -1) { - return -1; - } - pos += nwrite; - } - return 0; -} - -int EvbufferBuffer::flush() { - int rv; - if (buflen_ > 0) { - if (limit_ == -1) { - rv = evbuffer_add(evbuffer_, buf_, buflen_); - } else { - rv = write_buffer(); - } - if (rv == -1) { - return -1; - } - writelen_ += buflen_; - buflen_ = 0; - } - return 0; -} - -int EvbufferBuffer::add(const uint8_t *data, size_t datalen) { - int rv; - if (buflen_ + datalen > bufmax_) { - if (buflen_ > 0) { - if (limit_ == -1) { - rv = evbuffer_add(evbuffer_, buf_, buflen_); - } else { - rv = write_buffer(); - } - if (rv == -1) { - return -1; - } - writelen_ += buflen_; - buflen_ = 0; - } - if (datalen > bufmax_) { - if (limit_ == -1) { - rv = evbuffer_add(evbuffer_, data, datalen); - } else { - rv = write_buffer(); - } - if (rv == -1) { - return -1; - } - writelen_ += buflen_; - return 0; - } - } - memcpy(buf_ + buflen_, data, datalen); - buflen_ += datalen; - return 0; -} - -size_t EvbufferBuffer::get_buflen() const { return buflen_; } - -size_t EvbufferBuffer::get_writelen() const { return writelen_; } - -void bev_enable_unless(bufferevent *bev, int events) { - if ((bufferevent_get_enabled(bev) & events) == events) { - return; - } - - bufferevent_enable(bev, events); -} - -void bev_disable_unless(bufferevent *bev, int events) { - if ((bufferevent_get_enabled(bev) & events) == 0) { - return; - } - - bufferevent_disable(bev, events); -} - -} // namespace util - -} // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/libevent_util.h b/yass/third_party/nghttp2/src/libevent_util.h deleted file mode 100644 index 1d1ee91c42..0000000000 --- a/yass/third_party/nghttp2/src/libevent_util.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * nghttp2 - HTTP/2 C Library - * - * Copyright (c) 2014 Tatsuhiro Tsujikawa - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef LIBEVENT_UTIL_H -#define LIBEVENT_UTIL_H - -#include "nghttp2_config.h" - -#include -#include - -namespace nghttp2 { - -namespace util { - -class EvbufferBuffer { -public: - EvbufferBuffer(); - // If |limit| is not -1, at most min(limit, bufmax) size bytes are - // added to evbuffer_. - EvbufferBuffer(evbuffer *evbuffer, uint8_t *buf, size_t bufmax, - ssize_t limit = -1); - ~EvbufferBuffer(); - void reset(evbuffer *evbuffer, uint8_t *buf, size_t bufmax, - ssize_t limit = -1); - int flush(); - int add(const uint8_t *data, size_t datalen); - size_t get_buflen() const; - int write_buffer(); - // Returns the number of written bytes to evbuffer_ so far. reset() - // resets this value to 0. - size_t get_writelen() const; - -private: - evbuffer *evbuffer_; - evbuffer *bucket_; - uint8_t *buf_; - size_t bufmax_; - size_t buflen_; - ssize_t limit_; - size_t writelen_; -}; - -// These functions are provided to reduce epoll_ctl syscall. Avoid -// calling bufferevent_enable/disable() unless it is required by -// sniffing current enabled events. -void bev_enable_unless(bufferevent *bev, int events); -void bev_disable_unless(bufferevent *bev, int events); - -} // namespace util - -} // namespace nghttp2 - -#endif // LIBEVENT_UTIL_H diff --git a/yass/third_party/nghttp2/src/memchunk_test.cc b/yass/third_party/nghttp2/src/memchunk_test.cc index 236d9ea413..1c57c02d08 100644 --- a/yass/third_party/nghttp2/src/memchunk_test.cc +++ b/yass/third_party/nghttp2/src/memchunk_test.cc @@ -24,7 +24,7 @@ */ #include "memchunk_test.h" -#include +#include "munitxx.h" #include @@ -33,52 +33,72 @@ namespace nghttp2 { +namespace { +const MunitTest tests[]{ + munit_void_test(test_pool_recycle), + munit_void_test(test_memchunks_append), + munit_void_test(test_memchunks_drain), + munit_void_test(test_memchunks_riovec), + munit_void_test(test_memchunks_recycle), + munit_void_test(test_memchunks_reset), + munit_void_test(test_peek_memchunks_append), + munit_void_test(test_peek_memchunks_disable_peek_drain), + munit_void_test(test_peek_memchunks_disable_peek_no_drain), + munit_void_test(test_peek_memchunks_reset), + munit_test_end(), +}; +} // namespace + +const MunitSuite memchunk_suite{ + "/memchunk", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_pool_recycle(void) { MemchunkPool pool; - CU_ASSERT(!pool.pool); - CU_ASSERT(0 == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); + assert_null(pool.pool); + assert_size(0, ==, pool.poolsize); + assert_null(pool.freelist); auto m1 = pool.get(); - CU_ASSERT(m1 == pool.pool); - CU_ASSERT(MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); + assert_ptr_equal(m1, pool.pool); + assert_size(MemchunkPool::value_type::size, ==, pool.poolsize); + assert_null(pool.freelist); auto m2 = pool.get(); - CU_ASSERT(m2 == pool.pool); - CU_ASSERT(2 * MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); - CU_ASSERT(m1 == m2->knext); - CU_ASSERT(nullptr == m1->knext); + assert_ptr_equal(m2, pool.pool); + assert_size(2 * MemchunkPool::value_type::size, ==, pool.poolsize); + assert_null(pool.freelist); + assert_ptr_equal(m1, m2->knext); + assert_null(m1->knext); auto m3 = pool.get(); - CU_ASSERT(m3 == pool.pool); - CU_ASSERT(3 * MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); + assert_ptr_equal(m3, pool.pool); + assert_size(3 * MemchunkPool::value_type::size, ==, pool.poolsize); + assert_null(pool.freelist); pool.recycle(m3); - CU_ASSERT(m3 == pool.pool); - CU_ASSERT(3 * MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(m3 == pool.freelist); + assert_ptr_equal(m3, pool.pool); + assert_size(3 * MemchunkPool::value_type::size, ==, pool.poolsize); + assert_ptr_equal(m3, pool.freelist); auto m4 = pool.get(); - CU_ASSERT(m3 == m4); - CU_ASSERT(m4 == pool.pool); - CU_ASSERT(3 * MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); + assert_ptr_equal(m3, m4); + assert_ptr_equal(m4, pool.pool); + assert_size(3 * MemchunkPool::value_type::size, ==, pool.poolsize); + assert_null(pool.freelist); pool.recycle(m2); pool.recycle(m1); - CU_ASSERT(m1 == pool.freelist); - CU_ASSERT(m2 == m1->next); - CU_ASSERT(nullptr == m2->next); + assert_ptr_equal(m1, pool.freelist); + assert_ptr_equal(m2, m1->next); + assert_null(m2->next); } using Memchunk16 = Memchunk<16>; @@ -94,37 +114,37 @@ void test_memchunks_append(void) { auto m = chunks.tail; - CU_ASSERT(3 == m->len()); - CU_ASSERT(13 == m->left()); + assert_size(3, ==, m->len()); + assert_size(13, ==, m->left()); chunks.append("3456789abcdef@"); - CU_ASSERT(16 == m->len()); - CU_ASSERT(0 == m->left()); + assert_size(16, ==, m->len()); + assert_size(0, ==, m->left()); m = chunks.tail; - CU_ASSERT(1 == m->len()); - CU_ASSERT(15 == m->left()); - CU_ASSERT(17 == chunks.rleft()); + assert_size(1, ==, m->len()); + assert_size(15, ==, m->left()); + assert_size(17, ==, chunks.rleft()); char buf[16]; size_t nread; nread = chunks.remove(buf, 8); - CU_ASSERT(8 == nread); - CU_ASSERT(0 == memcmp("01234567", buf, nread)); - CU_ASSERT(9 == chunks.rleft()); + assert_size(8, ==, nread); + assert_memory_equal(nread, "01234567", buf); + assert_size(9, ==, chunks.rleft()); nread = chunks.remove(buf, sizeof(buf)); - CU_ASSERT(9 == nread); - CU_ASSERT(0 == memcmp("89abcdef@", buf, nread)); - CU_ASSERT(0 == chunks.rleft()); - CU_ASSERT(nullptr == chunks.head); - CU_ASSERT(nullptr == chunks.tail); - CU_ASSERT(32 == pool.poolsize); + assert_size(9, ==, nread); + assert_memory_equal(nread, "89abcdef@", buf); + assert_size(0, ==, chunks.rleft()); + assert_null(chunks.head); + assert_null(chunks.tail); + assert_size(32, ==, pool.poolsize); } void test_memchunks_drain(void) { @@ -137,14 +157,14 @@ void test_memchunks_drain(void) { nread = chunks.drain(3); - CU_ASSERT(3 == nread); + assert_size(3, ==, nread); char buf[16]; nread = chunks.remove(buf, sizeof(buf)); - CU_ASSERT(7 == nread); - CU_ASSERT(0 == memcmp("3456789", buf, nread)); + assert_size(7, ==, nread); + assert_memory_equal(nread, "3456789", buf); } void test_memchunks_riovec(void) { @@ -160,24 +180,24 @@ void test_memchunks_riovec(void) { auto m = chunks.head; - CU_ASSERT(2 == iovcnt); - CU_ASSERT(m->buf.data() == iov[0].iov_base); - CU_ASSERT(m->len() == iov[0].iov_len); + assert_int(2, ==, iovcnt); + assert_ptr_equal(m->buf.data(), iov[0].iov_base); + assert_size(m->len(), ==, iov[0].iov_len); m = m->next; - CU_ASSERT(m->buf.data() == iov[1].iov_base); - CU_ASSERT(m->len() == iov[1].iov_len); + assert_ptr_equal(m->buf.data(), iov[1].iov_base); + assert_size(m->len(), ==, iov[1].iov_len); chunks.drain(2 * 16); iovcnt = chunks.riovec(iov.data(), iov.size()); - CU_ASSERT(1 == iovcnt); + assert_int(1, ==, iovcnt); m = chunks.head; - CU_ASSERT(m->buf.data() == iov[0].iov_base); - CU_ASSERT(m->len() == iov[0].iov_len); + assert_ptr_equal(m->buf.data(), iov[0].iov_base); + assert_size(m->len(), ==, iov[0].iov_len); } void test_memchunks_recycle(void) { @@ -187,14 +207,14 @@ void test_memchunks_recycle(void) { std::array buf{}; chunks.append(buf.data(), buf.size()); } - CU_ASSERT(32 == pool.poolsize); - CU_ASSERT(nullptr != pool.freelist); + assert_size(32, ==, pool.poolsize); + assert_not_null(pool.freelist); auto m = pool.freelist; m = m->next; - CU_ASSERT(nullptr != m); - CU_ASSERT(nullptr == m->next); + assert_not_null(m); + assert_null(m->next); } void test_memchunks_reset(void) { @@ -205,19 +225,19 @@ void test_memchunks_reset(void) { chunks.append(b.data(), b.size()); - CU_ASSERT(32 == chunks.rleft()); + assert_size(32, ==, chunks.rleft()); chunks.reset(); - CU_ASSERT(0 == chunks.rleft()); - CU_ASSERT(nullptr == chunks.head); - CU_ASSERT(nullptr == chunks.tail); + assert_size(0, ==, chunks.rleft()); + assert_null(chunks.head); + assert_null(chunks.tail); auto m = pool.freelist; - CU_ASSERT(nullptr != m); - CU_ASSERT(nullptr != m->next); - CU_ASSERT(nullptr == m->next->next); + assert_not_null(m); + assert_not_null(m->next); + assert_null(m->next->next); } void test_peek_memchunks_append(void) { @@ -232,27 +252,27 @@ void test_peek_memchunks_append(void) { pchunks.append(b.data(), b.size()); - CU_ASSERT(32 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_size(32, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); - CU_ASSERT(0 == pchunks.remove(nullptr, 0)); + assert_size(0, ==, pchunks.remove(nullptr, 0)); - CU_ASSERT(32 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_size(32, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); - CU_ASSERT(12 == pchunks.remove(d.data(), 12)); + assert_size(12, ==, pchunks.remove(d.data(), 12)); - CU_ASSERT(std::equal(std::begin(b), std::begin(b) + 12, std::begin(d))); + assert_true(std::equal(std::begin(b), std::begin(b) + 12, std::begin(d))); - CU_ASSERT(20 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_size(20, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); - CU_ASSERT(20 == pchunks.remove(d.data(), d.size())); + assert_size(20, ==, pchunks.remove(d.data(), d.size())); - CU_ASSERT(std::equal(std::begin(b) + 12, std::end(b), std::begin(d))); + assert_true(std::equal(std::begin(b) + 12, std::end(b), std::begin(d))); - CU_ASSERT(0 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_size(0, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); } void test_peek_memchunks_disable_peek_drain(void) { @@ -267,20 +287,20 @@ void test_peek_memchunks_disable_peek_drain(void) { pchunks.append(b.data(), b.size()); - CU_ASSERT(12 == pchunks.remove(d.data(), 12)); + assert_size(12, ==, pchunks.remove(d.data(), 12)); pchunks.disable_peek(true); - CU_ASSERT(!pchunks.peeking); - CU_ASSERT(20 == pchunks.rleft()); - CU_ASSERT(20 == pchunks.rleft_buffered()); + assert_false(pchunks.peeking); + assert_size(20, ==, pchunks.rleft()); + assert_size(20, ==, pchunks.rleft_buffered()); - CU_ASSERT(20 == pchunks.remove(d.data(), d.size())); + assert_size(20, ==, pchunks.remove(d.data(), d.size())); - CU_ASSERT(std::equal(std::begin(b) + 12, std::end(b), std::begin(d))); + assert_true(std::equal(std::begin(b) + 12, std::end(b), std::begin(d))); - CU_ASSERT(0 == pchunks.rleft()); - CU_ASSERT(0 == pchunks.rleft_buffered()); + assert_size(0, ==, pchunks.rleft()); + assert_size(0, ==, pchunks.rleft_buffered()); } void test_peek_memchunks_disable_peek_no_drain(void) { @@ -295,20 +315,20 @@ void test_peek_memchunks_disable_peek_no_drain(void) { pchunks.append(b.data(), b.size()); - CU_ASSERT(12 == pchunks.remove(d.data(), 12)); + assert_size(12, ==, pchunks.remove(d.data(), 12)); pchunks.disable_peek(false); - CU_ASSERT(!pchunks.peeking); - CU_ASSERT(32 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_false(pchunks.peeking); + assert_size(32, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); - CU_ASSERT(32 == pchunks.remove(d.data(), d.size())); + assert_size(32, ==, pchunks.remove(d.data(), d.size())); - CU_ASSERT(std::equal(std::begin(b), std::end(b), std::begin(d))); + assert_true(std::equal(std::begin(b), std::end(b), std::begin(d))); - CU_ASSERT(0 == pchunks.rleft()); - CU_ASSERT(0 == pchunks.rleft_buffered()); + assert_size(0, ==, pchunks.rleft()); + assert_size(0, ==, pchunks.rleft_buffered()); } void test_peek_memchunks_reset(void) { @@ -323,18 +343,18 @@ void test_peek_memchunks_reset(void) { pchunks.append(b.data(), b.size()); - CU_ASSERT(12 == pchunks.remove(d.data(), 12)); + assert_size(12, ==, pchunks.remove(d.data(), 12)); pchunks.disable_peek(true); pchunks.reset(); - CU_ASSERT(0 == pchunks.rleft()); - CU_ASSERT(0 == pchunks.rleft_buffered()); + assert_size(0, ==, pchunks.rleft()); + assert_size(0, ==, pchunks.rleft_buffered()); - CU_ASSERT(nullptr == pchunks.cur); - CU_ASSERT(nullptr == pchunks.cur_pos); - CU_ASSERT(nullptr == pchunks.cur_last); - CU_ASSERT(pchunks.peeking); + assert_null(pchunks.cur); + assert_null(pchunks.cur_pos); + assert_null(pchunks.cur_last); + assert_true(pchunks.peeking); } } // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/memchunk_test.h b/yass/third_party/nghttp2/src/memchunk_test.h index 7d677e787e..a3fe0285d1 100644 --- a/yass/third_party/nghttp2/src/memchunk_test.h +++ b/yass/third_party/nghttp2/src/memchunk_test.h @@ -29,18 +29,24 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace nghttp2 { -void test_pool_recycle(void); -void test_memchunks_append(void); -void test_memchunks_drain(void); -void test_memchunks_riovec(void); -void test_memchunks_recycle(void); -void test_memchunks_reset(void); -void test_peek_memchunks_append(void); -void test_peek_memchunks_disable_peek_drain(void); -void test_peek_memchunks_disable_peek_no_drain(void); -void test_peek_memchunks_reset(void); +extern const MunitSuite memchunk_suite; + +munit_void_test_decl(test_pool_recycle); +munit_void_test_decl(test_memchunks_append); +munit_void_test_decl(test_memchunks_drain); +munit_void_test_decl(test_memchunks_riovec); +munit_void_test_decl(test_memchunks_recycle); +munit_void_test_decl(test_memchunks_reset); +munit_void_test_decl(test_peek_memchunks_append); +munit_void_test_decl(test_peek_memchunks_disable_peek_drain); +munit_void_test_decl(test_peek_memchunks_disable_peek_no_drain); +munit_void_test_decl(test_peek_memchunks_reset); } // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/nghttp.cc b/yass/third_party/nghttp2/src/nghttp.cc index d4576f3114..66843743d2 100644 --- a/yass/third_party/nghttp2/src/nghttp.cc +++ b/yass/third_party/nghttp2/src/nghttp.cc @@ -157,7 +157,7 @@ std::string strip_fragment(const char *raw_uri) { } // namespace Request::Request(const std::string &uri, const http_parser_url &u, - const nghttp2_data_provider *data_prd, int64_t data_length, + const nghttp2_data_provider2 *data_prd, int64_t data_length, const nghttp2_priority_spec &pri_spec, int level) : uri(uri), u(u), @@ -370,11 +370,11 @@ void continue_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) { auto req = static_cast(w->data); int error; - error = nghttp2_submit_data(client->session, NGHTTP2_FLAG_END_STREAM, - req->stream_id, req->data_prd); + error = nghttp2_submit_data2(client->session, NGHTTP2_FLAG_END_STREAM, + req->stream_id, req->data_prd); if (error) { - std::cerr << "[ERROR] nghttp2_submit_data() returned error: " + std::cerr << "[ERROR] nghttp2_submit_data2() returned error: " << nghttp2_strerror(error) << std::endl; nghttp2_submit_rst_stream(client->session, NGHTTP2_FLAG_NONE, req->stream_id, NGHTTP2_INTERNAL_ERROR); @@ -525,13 +525,13 @@ int submit_request(HttpClient *client, const Headers &headers, Request *req) { nva.data(), nva.size(), req); } else { stream_id = - nghttp2_submit_request(client->session, &req->pri_spec, nva.data(), - nva.size(), req->data_prd, req); + nghttp2_submit_request2(client->session, &req->pri_spec, nva.data(), + nva.size(), req->data_prd, req); } if (stream_id < 0) { std::cerr << "[ERROR] nghttp2_submit_" - << (expect_continue ? "headers" : "request") + << (expect_continue ? "headers" : "request2") << "() returned error: " << nghttp2_strerror(stream_id) << std::endl; return -1; @@ -697,16 +697,10 @@ int HttpClient::initiate_connection() { const auto &host_string = config.host_override.empty() ? host : config.host_override; -#if LIBRESSL_2_7_API || \ - (!LIBRESSL_IN_USE && OPENSSL_VERSION_NUMBER >= 0x10002000L) || \ - defined(OPENSSL_IS_BORINGSSL) auto param = SSL_get0_param(ssl); X509_VERIFY_PARAM_set_hostflags(param, 0); X509_VERIFY_PARAM_set1_host(param, host_string.c_str(), host_string.size()); -#endif // LIBRESSL_2_7_API || (!LIBRESSL_IN_USE && - // OPENSSL_VERSION_NUMBER >= 0x10002000L) || - // defined(OPENSSL_IS_BORINGSSL) SSL_set_verify(ssl, SSL_VERIFY_PEER, verify_cb); if (!util::numeric_host(host_string.c_str())) { @@ -959,14 +953,14 @@ size_t populate_settings(nghttp2_settings_entry *iv) { } // namespace int HttpClient::on_upgrade_connect() { - ssize_t rv; + nghttp2_ssize rv; record_connect_end_time(); assert(!reqvec.empty()); std::array iv; size_t niv = populate_settings(iv.data()); assert(settings_payload.size() >= 8 * niv); - rv = nghttp2_pack_settings_payload(settings_payload.data(), - settings_payload.size(), iv.data(), niv); + rv = nghttp2_pack_settings_payload2(settings_payload.data(), + settings_payload.size(), iv.data(), niv); if (rv < 0) { return -1; } @@ -999,7 +993,7 @@ int HttpClient::on_upgrade_connect() { auto headers = Headers{{"host", hostport}, {"connection", "Upgrade, HTTP2-Settings"}, {"upgrade", NGHTTP2_CLEARTEXT_PROTO_VERSION_ID}, - {"http2-settings", token68}, + {"http2-settings", std::move(token68)}, {"accept", "*/*"}, {"user-agent", "nghttp2/" NGHTTP2_VERSION}}; auto initial_headerslen = headers.size(); @@ -1121,28 +1115,19 @@ int HttpClient::connection_made() { } if (ssl) { - // Check NPN or ALPN result + // Check ALPN result const unsigned char *next_proto = nullptr; unsigned int next_proto_len; -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(ssl, &next_proto, &next_proto_len); -#endif // !OPENSSL_NO_NEXTPROTONEG - for (int i = 0; i < 2; ++i) { - if (next_proto) { - auto proto = StringRef{next_proto, next_proto_len}; - if (config.verbose) { - std::cout << "The negotiated protocol: " << proto << std::endl; - } - if (!util::check_h2_is_selected(proto)) { - next_proto = nullptr; - } - break; + + SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len); + if (next_proto) { + auto proto = StringRef{next_proto, next_proto_len}; + if (config.verbose) { + std::cout << "The negotiated protocol: " << proto << std::endl; + } + if (!util::check_h2_is_selected(proto)) { + next_proto = nullptr; } -#if OPENSSL_VERSION_NUMBER >= 0x10002000L - SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len); -#else // OPENSSL_VERSION_NUMBER < 0x10002000L - break; -#endif // OPENSSL_VERSION_NUMBER < 0x10002000L } if (!next_proto) { print_protocol_nego_error(); @@ -1265,9 +1250,9 @@ int HttpClient::on_read(const uint8_t *data, size_t len) { util::hexdump(stdout, data, len); } - auto rv = nghttp2_session_mem_recv(session, data, len); + auto rv = nghttp2_session_mem_recv2(session, data, len); if (rv < 0) { - std::cerr << "[ERROR] nghttp2_session_mem_recv() returned error: " + std::cerr << "[ERROR] nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv) << std::endl; return -1; } @@ -1291,9 +1276,9 @@ int HttpClient::on_write() { } const uint8_t *data; - auto len = nghttp2_session_mem_send(session, &data); + auto len = nghttp2_session_mem_send2(session, &data); if (len < 0) { - std::cerr << "[ERROR] nghttp2_session_send() returned error: " + std::cerr << "[ERROR] nghttp2_session_send2() returned error: " << nghttp2_strerror(len) << std::endl; return -1; } @@ -1464,7 +1449,7 @@ void HttpClient::update_hostport() { } bool HttpClient::add_request(const std::string &uri, - const nghttp2_data_provider *data_prd, + const nghttp2_data_provider2 *data_prd, int64_t data_length, const nghttp2_priority_spec &pri_spec, int level) { http_parser_url u{}; @@ -1783,9 +1768,9 @@ int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, } // namespace namespace { -ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, size_t max_payload, - void *user_data) { +nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payload, void *user_data) { return std::min(max_payload, frame->hd.length + config.padding); } } // namespace @@ -2252,37 +2237,11 @@ id responseEnd requestStart process code size request path)" } } // namespace -#ifndef OPENSSL_NO_NEXTPROTONEG -namespace { -int client_select_next_proto_cb(SSL *ssl, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg) { - if (config.verbose) { - print_timer(); - std::cout << "[NPN] server offers:" << std::endl; - } - for (unsigned int i = 0; i < inlen; i += in[i] + 1) { - if (config.verbose) { - std::cout << " * "; - std::cout.write(reinterpret_cast(&in[i + 1]), in[i]); - std::cout << std::endl; - } - } - if (!util::select_h2(const_cast(out), outlen, in, - inlen)) { - print_protocol_nego_error(); - return SSL_TLSEXT_ERR_NOACK; - } - return SSL_TLSEXT_ERR_OK; -} -} // namespace -#endif // !OPENSSL_NO_NEXTPROTONEG - namespace { int communicate( const std::string &scheme, const std::string &host, uint16_t port, std::vector< - std::tuple> + std::tuple> requests, const nghttp2_session_callbacks *callbacks) { int result = 0; @@ -2348,16 +2307,29 @@ int communicate( goto fin; } } -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_CTX_set_next_proto_select_cb(ssl_ctx, client_select_next_proto_cb, - nullptr); -#endif // !OPENSSL_NO_NEXTPROTONEG -#if OPENSSL_VERSION_NUMBER >= 0x10002000L auto proto_list = util::get_default_alpn(); SSL_CTX_set_alpn_protos(ssl_ctx, proto_list.data(), proto_list.size()); -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + nghttp2::tls::cert_compress, nghttp2::tls::cert_decompress)) { + std::cerr << "[ERROR] SSL_CTX_add_cert_compression_alg failed." + << std::endl; + result = -1; + goto fin; + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + + if (tls::setup_keylog_callback(ssl_ctx) != 0) { + std::cerr << "[ERROR] Failed to setup keylog" << std::endl; + + result = -1; + + goto fin; + } } { HttpClient client{callbacks, loop, ssl_ctx}; @@ -2438,9 +2410,10 @@ fin: } // namespace namespace { -ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, uint32_t *data_flags, - nghttp2_data_source *source, void *user_data) { +nghttp2_ssize file_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t length, + uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { int rv; auto req = static_cast( nghttp2_session_get_stream_user_data(session, stream_id)); @@ -2476,14 +2449,14 @@ ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, } } - return nread; + return static_cast(nread); } if (req->data_offset > req->data_length || nread == 0) { return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } - return nread; + return static_cast(nread); } } // namespace @@ -2527,7 +2500,7 @@ int run(char **uris, int n) { callbacks, on_frame_not_send_callback); if (config.padding) { - nghttp2_session_callbacks_set_select_padding_callback( + nghttp2_session_callbacks_set_select_padding_callback2( callbacks, select_padding_callback); } @@ -2536,7 +2509,7 @@ int run(char **uris, int n) { uint16_t prev_port = 0; int failures = 0; int data_fd = -1; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; struct stat data_stat; if (!config.datafile.empty()) { @@ -2604,7 +2577,7 @@ int run(char **uris, int n) { data_prd.read_callback = file_read_callback; } std::vector< - std::tuple> + std::tuple> requests; size_t next_weight_idx = 0; @@ -2795,8 +2768,6 @@ Options: } // namespace int main(int argc, char **argv) { - tls::libssl_init(); - bool color = false; while (1) { static int flag = 0; diff --git a/yass/third_party/nghttp2/src/nghttp.h b/yass/third_party/nghttp2/src/nghttp.h index a880414227..5b339e8f86 100644 --- a/yass/third_party/nghttp2/src/nghttp.h +++ b/yass/third_party/nghttp2/src/nghttp.h @@ -45,6 +45,7 @@ #include +#define NGHTTP2_NO_SSIZE_T #include #include "llhttp.h" @@ -77,7 +78,7 @@ struct Config { int64_t encoder_header_table_size; size_t padding; size_t max_concurrent_streams; - ssize_t peer_max_concurrent_streams; + size_t peer_max_concurrent_streams; int multiply; // milliseconds ev_tstamp timeout; @@ -137,7 +138,7 @@ struct ContinueTimer { struct Request { // For pushed request, |uri| is empty and |u| is zero-cleared. Request(const std::string &uri, const http_parser_url &u, - const nghttp2_data_provider *data_prd, int64_t data_length, + const nghttp2_data_provider2 *data_prd, int64_t data_length, const nghttp2_priority_spec &pri_spec, int level = 0); ~Request(); @@ -180,7 +181,7 @@ struct Request { int64_t response_len; nghttp2_gzip *inflater; std::unique_ptr html_parser; - const nghttp2_data_provider *data_prd; + const nghttp2_data_provider2 *data_prd; size_t header_buffer_size; int32_t stream_id; int status; @@ -246,7 +247,7 @@ struct HttpClient { bool all_requests_processed() const; void update_hostport(); bool add_request(const std::string &uri, - const nghttp2_data_provider *data_prd, int64_t data_length, + const nghttp2_data_provider2 *data_prd, int64_t data_length, const nghttp2_priority_spec &pri_spec, int level = 0); void record_start_time(); diff --git a/yass/third_party/nghttp2/src/nghttp2_gzip_test.c b/yass/third_party/nghttp2/src/nghttp2_gzip_test.c index de19d5da33..9a36db0aa8 100644 --- a/yass/third_party/nghttp2/src/nghttp2_gzip_test.c +++ b/yass/third_party/nghttp2/src/nghttp2_gzip_test.c @@ -27,26 +27,35 @@ #include #include -#include +#include "munit.h" #include #include "nghttp2_gzip.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_gzip_inflate), + munit_test_end(), +}; + +const MunitSuite gzip_suite = { + "/gzip", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + static size_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { int rv; z_stream zst = {0}; rv = deflateInit(&zst, Z_DEFAULT_COMPRESSION); - CU_ASSERT(rv == Z_OK); + assert_int(Z_OK, ==, rv); zst.avail_in = (unsigned int)inlen; zst.next_in = (uint8_t *)in; zst.avail_out = (unsigned int)outlen; zst.next_out = out; rv = deflate(&zst, Z_SYNC_FLUSH); - CU_ASSERT(rv == Z_OK); + assert_int(Z_OK, ==, rv); deflateEnd(&zst); @@ -71,41 +80,44 @@ void test_nghttp2_gzip_inflate(void) { inlen = deflate_data(in, inlen, (const uint8_t *)input, sizeof(input) - 1); - CU_ASSERT(0 == nghttp2_gzip_inflate_new(&inflater)); + assert_int(0, ==, nghttp2_gzip_inflate_new(&inflater)); /* First 16 bytes */ inptr = in; inproclen = inlen; outproclen = 16; - CU_ASSERT( - 0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); - CU_ASSERT(16 == outproclen); - CU_ASSERT(inproclen > 0); - CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); + assert_int( + 0, ==, + nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); + assert_size(16, ==, outproclen); + assert_size(0, <, inproclen); + assert_memory_equal(outproclen, inputptr, out); /* Next 32 bytes */ inptr += inproclen; inlen -= inproclen; inproclen = inlen; inputptr += outproclen; outproclen = 32; - CU_ASSERT( - 0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); - CU_ASSERT(32 == outproclen); - CU_ASSERT(inproclen > 0); - CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); + assert_int( + 0, ==, + nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); + assert_size(32, ==, outproclen); + assert_size(0, <, inproclen); + assert_memory_equal(outproclen, inputptr, out); /* Rest */ inptr += inproclen; inlen -= inproclen; inproclen = inlen; inputptr += outproclen; outproclen = sizeof(out); - CU_ASSERT( - 0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); - CU_ASSERT(sizeof(input) - 49 == outproclen); - CU_ASSERT(inproclen > 0); - CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); + assert_int( + 0, ==, + nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); + assert_size(sizeof(input) - 49, ==, outproclen); + assert_size(0, <, inproclen); + assert_memory_equal(outproclen, inputptr, out); inlen -= inproclen; - CU_ASSERT(0 == inlen); + assert_size(0, ==, inlen); nghttp2_gzip_inflate_del(inflater); } diff --git a/yass/third_party/nghttp2/src/nghttp2_gzip_test.h b/yass/third_party/nghttp2/src/nghttp2_gzip_test.h index 8d554f7209..fa6938b581 100644 --- a/yass/third_party/nghttp2/src/nghttp2_gzip_test.h +++ b/yass/third_party/nghttp2/src/nghttp2_gzip_test.h @@ -33,7 +33,13 @@ extern "C" { #endif -void test_nghttp2_gzip_inflate(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite gzip_suite; + +munit_void_test_decl(test_nghttp2_gzip_inflate); #ifdef __cplusplus } diff --git a/yass/third_party/nghttp2/src/nghttpd.cc b/yass/third_party/nghttp2/src/nghttpd.cc index 3c5f5b4bec..9cad874ff4 100644 --- a/yass/third_party/nghttp2/src/nghttpd.cc +++ b/yass/third_party/nghttp2/src/nghttpd.cc @@ -193,12 +193,6 @@ Options: } // namespace int main(int argc, char **argv) { - tls::libssl_init(); - -#ifndef NOTHREADS - tls::LibsslGlobalLock lock; -#endif // NOTHREADS - Config config; bool color = false; auto mime_types_file_set_manually = false; diff --git a/yass/third_party/nghttp2/src/shrpx-unittest.cc b/yass/third_party/nghttp2/src/shrpx-unittest.cc index 07373d5708..ec707e578f 100644 --- a/yass/third_party/nghttp2/src/shrpx-unittest.cc +++ b/yass/third_party/nghttp2/src/shrpx-unittest.cc @@ -26,9 +26,8 @@ # include #endif // HAVE_CONFIG_H -#include -#include -#include +#include "munit.h" + // include test cases' include files here #include "shrpx_tls_test.h" #include "shrpx_downstream_test.h" @@ -47,202 +46,21 @@ #include "shrpx_router_test.h" #include "shrpx_log.h" -static int init_suite1(void) { return 0; } - -static int clean_suite1(void) { return 0; } - int main(int argc, char *argv[]) { - CU_pSuite pSuite = nullptr; - unsigned int num_tests_failed; - - nghttp2::tls::libssl_init(); - shrpx::create_config(); - // initialize the CUnit test registry - if (CUE_SUCCESS != CU_initialize_registry()) - return CU_get_error(); + const MunitSuite suites[] = { + shrpx::tls_suite, shrpx::downstream_suite, + shrpx::config_suite, shrpx::worker_suite, + shrpx::http_suite, shrpx::router_suite, + shrpx::http2_suite, shrpx::util_suite, + gzip_suite, buffer_suite, + memchunk_suite, template_suite, + base64_suite, {NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}, + }; + const MunitSuite suite = { + "", NULL, suites, 1, MUNIT_SUITE_OPTION_NONE, + }; - // add a suite to the registry - pSuite = CU_add_suite("shrpx_TestSuite", init_suite1, clean_suite1); - if (nullptr == pSuite) { - CU_cleanup_registry(); - return CU_get_error(); - } - - // add the tests to the suite - if (!CU_add_test(pSuite, "tls_create_lookup_tree", - shrpx::test_shrpx_tls_create_lookup_tree) || - !CU_add_test(pSuite, "tls_cert_lookup_tree_add_ssl_ctx", - shrpx::test_shrpx_tls_cert_lookup_tree_add_ssl_ctx) || - !CU_add_test(pSuite, "tls_tls_hostname_match", - shrpx::test_shrpx_tls_tls_hostname_match) || - !CU_add_test(pSuite, "tls_tls_verify_numeric_hostname", - shrpx::test_shrpx_tls_verify_numeric_hostname) || - !CU_add_test(pSuite, "tls_tls_verify_dns_hostname", - shrpx::test_shrpx_tls_verify_dns_hostname) || - !CU_add_test(pSuite, "http2_add_header", shrpx::test_http2_add_header) || - !CU_add_test(pSuite, "http2_get_header", shrpx::test_http2_get_header) || - !CU_add_test(pSuite, "http2_copy_headers_to_nva", - shrpx::test_http2_copy_headers_to_nva) || - !CU_add_test(pSuite, "http2_build_http1_headers_from_headers", - shrpx::test_http2_build_http1_headers_from_headers) || - !CU_add_test(pSuite, "http2_lws", shrpx::test_http2_lws) || - !CU_add_test(pSuite, "http2_rewrite_location_uri", - shrpx::test_http2_rewrite_location_uri) || - !CU_add_test(pSuite, "http2_parse_http_status_code", - shrpx::test_http2_parse_http_status_code) || - !CU_add_test(pSuite, "http2_index_header", - shrpx::test_http2_index_header) || - !CU_add_test(pSuite, "http2_lookup_token", - shrpx::test_http2_lookup_token) || - !CU_add_test(pSuite, "http2_parse_link_header", - shrpx::test_http2_parse_link_header) || - !CU_add_test(pSuite, "http2_path_join", shrpx::test_http2_path_join) || - !CU_add_test(pSuite, "http2_normalize_path", - shrpx::test_http2_normalize_path) || - !CU_add_test(pSuite, "http2_rewrite_clean_path", - shrpx::test_http2_rewrite_clean_path) || - !CU_add_test(pSuite, "http2_get_pure_path_component", - shrpx::test_http2_get_pure_path_component) || - !CU_add_test(pSuite, "http2_construct_push_component", - shrpx::test_http2_construct_push_component) || - !CU_add_test(pSuite, "http2_contains_trailers", - shrpx::test_http2_contains_trailers) || - !CU_add_test(pSuite, "http2_check_transfer_encoding", - shrpx::test_http2_check_transfer_encoding) || - !CU_add_test(pSuite, "downstream_field_store_append_last_header", - shrpx::test_downstream_field_store_append_last_header) || - !CU_add_test(pSuite, "downstream_field_store_header", - shrpx::test_downstream_field_store_header) || - !CU_add_test(pSuite, "downstream_crumble_request_cookie", - shrpx::test_downstream_crumble_request_cookie) || - !CU_add_test(pSuite, "downstream_assemble_request_cookie", - shrpx::test_downstream_assemble_request_cookie) || - !CU_add_test(pSuite, "downstream_rewrite_location_response_header", - shrpx::test_downstream_rewrite_location_response_header) || - !CU_add_test(pSuite, "downstream_supports_non_final_response", - shrpx::test_downstream_supports_non_final_response) || - !CU_add_test(pSuite, "downstream_find_affinity_cookie", - shrpx::test_downstream_find_affinity_cookie) || - !CU_add_test(pSuite, "config_parse_header", - shrpx::test_shrpx_config_parse_header) || - !CU_add_test(pSuite, "config_parse_log_format", - shrpx::test_shrpx_config_parse_log_format) || - !CU_add_test(pSuite, "config_read_tls_ticket_key_file", - shrpx::test_shrpx_config_read_tls_ticket_key_file) || - !CU_add_test(pSuite, "config_read_tls_ticket_key_file_aes_256", - shrpx::test_shrpx_config_read_tls_ticket_key_file_aes_256) || - !CU_add_test(pSuite, "worker_match_downstream_addr_group", - shrpx::test_shrpx_worker_match_downstream_addr_group) || - !CU_add_test(pSuite, "http_create_forwarded", - shrpx::test_shrpx_http_create_forwarded) || - !CU_add_test(pSuite, "http_create_via_header_value", - shrpx::test_shrpx_http_create_via_header_value) || - !CU_add_test(pSuite, "http_create_affinity_cookie", - shrpx::test_shrpx_http_create_affinity_cookie) || - !CU_add_test(pSuite, "http_create_atlsvc_header_field_value", - shrpx::test_shrpx_http_create_altsvc_header_value) || - !CU_add_test(pSuite, "http_check_http_scheme", - shrpx::test_shrpx_http_check_http_scheme) || - !CU_add_test(pSuite, "router_match", shrpx::test_shrpx_router_match) || - !CU_add_test(pSuite, "router_match_wildcard", - shrpx::test_shrpx_router_match_wildcard) || - !CU_add_test(pSuite, "router_match_prefix", - shrpx::test_shrpx_router_match_prefix) || - !CU_add_test(pSuite, "util_streq", shrpx::test_util_streq) || - !CU_add_test(pSuite, "util_strieq", shrpx::test_util_strieq) || - !CU_add_test(pSuite, "util_inp_strlower", - shrpx::test_util_inp_strlower) || - !CU_add_test(pSuite, "util_to_base64", shrpx::test_util_to_base64) || - !CU_add_test(pSuite, "util_to_token68", shrpx::test_util_to_token68) || - !CU_add_test(pSuite, "util_percent_encode_token", - shrpx::test_util_percent_encode_token) || - !CU_add_test(pSuite, "util_percent_decode", - shrpx::test_util_percent_decode) || - !CU_add_test(pSuite, "util_quote_string", - shrpx::test_util_quote_string) || - !CU_add_test(pSuite, "util_utox", shrpx::test_util_utox) || - !CU_add_test(pSuite, "util_http_date", shrpx::test_util_http_date) || - !CU_add_test(pSuite, "util_select_h2", shrpx::test_util_select_h2) || - !CU_add_test(pSuite, "util_ipv6_numeric_addr", - shrpx::test_util_ipv6_numeric_addr) || - !CU_add_test(pSuite, "util_utos", shrpx::test_util_utos) || - !CU_add_test(pSuite, "util_make_string_ref_uint", - shrpx::test_util_make_string_ref_uint) || - !CU_add_test(pSuite, "util_utos_unit", shrpx::test_util_utos_unit) || - !CU_add_test(pSuite, "util_utos_funit", shrpx::test_util_utos_funit) || - !CU_add_test(pSuite, "util_parse_uint_with_unit", - shrpx::test_util_parse_uint_with_unit) || - !CU_add_test(pSuite, "util_parse_uint", shrpx::test_util_parse_uint) || - !CU_add_test(pSuite, "util_parse_duration_with_unit", - shrpx::test_util_parse_duration_with_unit) || - !CU_add_test(pSuite, "util_duration_str", - shrpx::test_util_duration_str) || - !CU_add_test(pSuite, "util_format_duration", - shrpx::test_util_format_duration) || - !CU_add_test(pSuite, "util_starts_with", shrpx::test_util_starts_with) || - !CU_add_test(pSuite, "util_ends_with", shrpx::test_util_ends_with) || - !CU_add_test(pSuite, "util_parse_http_date", - shrpx::test_util_parse_http_date) || - !CU_add_test(pSuite, "util_localtime_date", - shrpx::test_util_localtime_date) || - !CU_add_test(pSuite, "util_get_uint64", shrpx::test_util_get_uint64) || - !CU_add_test(pSuite, "util_parse_config_str_list", - shrpx::test_util_parse_config_str_list) || - !CU_add_test(pSuite, "util_make_http_hostport", - shrpx::test_util_make_http_hostport) || - !CU_add_test(pSuite, "util_make_hostport", - shrpx::test_util_make_hostport) || - !CU_add_test(pSuite, "util_strifind", shrpx::test_util_strifind) || - !CU_add_test(pSuite, "util_random_alpha_digit", - shrpx::test_util_random_alpha_digit) || - !CU_add_test(pSuite, "util_format_hex", shrpx::test_util_format_hex) || - !CU_add_test(pSuite, "util_is_hex_string", - shrpx::test_util_is_hex_string) || - !CU_add_test(pSuite, "util_decode_hex", shrpx::test_util_decode_hex) || - !CU_add_test(pSuite, "util_extract_host", - shrpx::test_util_extract_host) || - !CU_add_test(pSuite, "util_split_hostport", - shrpx::test_util_split_hostport) || - !CU_add_test(pSuite, "util_split_str", shrpx::test_util_split_str) || - !CU_add_test(pSuite, "util_rstrip", shrpx::test_util_rstrip) || - !CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) || - !CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) || - !CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) || - !CU_add_test(pSuite, "memchunk_append", nghttp2::test_memchunks_append) || - !CU_add_test(pSuite, "memchunk_drain", nghttp2::test_memchunks_drain) || - !CU_add_test(pSuite, "memchunk_riovec", nghttp2::test_memchunks_riovec) || - !CU_add_test(pSuite, "memchunk_recycle", - nghttp2::test_memchunks_recycle) || - !CU_add_test(pSuite, "memchunk_reset", nghttp2::test_memchunks_reset) || - !CU_add_test(pSuite, "peek_memchunk_append", - nghttp2::test_peek_memchunks_append) || - !CU_add_test(pSuite, "peek_memchunk_disable_peek_drain", - nghttp2::test_peek_memchunks_disable_peek_drain) || - !CU_add_test(pSuite, "peek_memchunk_disable_peek_no_drain", - nghttp2::test_peek_memchunks_disable_peek_no_drain) || - !CU_add_test(pSuite, "peek_memchunk_reset", - nghttp2::test_peek_memchunks_reset) || - !CU_add_test(pSuite, "template_immutable_string", - nghttp2::test_template_immutable_string) || - !CU_add_test(pSuite, "template_string_ref", - nghttp2::test_template_string_ref) || - !CU_add_test(pSuite, "base64_encode", nghttp2::test_base64_encode) || - !CU_add_test(pSuite, "base64_decode", nghttp2::test_base64_decode)) { - CU_cleanup_registry(); - return CU_get_error(); - } - - // Run all tests using the CUnit Basic interface - CU_basic_set_mode(CU_BRM_VERBOSE); - CU_basic_run_tests(); - num_tests_failed = CU_get_number_of_tests_failed(); - CU_cleanup_registry(); - if (CU_get_error() == CUE_SUCCESS) { - return num_tests_failed; - } else { - printf("CUnit Error: %s\n", CU_get_error_msg()); - return CU_get_error(); - } + return munit_suite_main(&suite, NULL, argc, argv); } diff --git a/yass/third_party/nghttp2/src/shrpx.cc b/yass/third_party/nghttp2/src/shrpx.cc index a6ed8f84a8..89a77877e3 100644 --- a/yass/third_party/nghttp2/src/shrpx.cc +++ b/yass/third_party/nghttp2/src/shrpx.cc @@ -141,11 +141,13 @@ constexpr auto ENV_ACCEPT_PREFIX = StringRef::from_lit("NGHTTPX_ACCEPT_"); constexpr auto ENV_ORIG_PID = StringRef::from_lit("NGHTTPX_ORIG_PID"); // Prefix of environment variables to tell new binary the QUIC IPC -// file descriptor and CID prefix of the lingering worker process. -// The value must be comma separated parameters: -// ,,,... is the file -// descriptor. is the I-th CID prefix in hex encoded -// string. +// file descriptor and Worker ID of the lingering worker process. The +// value must be comma separated parameters: +// +// ,,,..., +// +// is the file descriptor. is the I-th Worker ID +// in hex encoded string. constexpr auto ENV_QUIC_WORKER_PROCESS_PREFIX = StringRef::from_lit("NGHTTPX_QUIC_WORKER_PROCESS_"); @@ -203,9 +205,7 @@ struct WorkerProcess { WorkerProcess(struct ev_loop *loop, pid_t worker_pid, int ipc_fd #ifdef ENABLE_HTTP3 , - int quic_ipc_fd, - const std::vector> - &cid_prefixes + int quic_ipc_fd, std::vector worker_ids, uint16_t seq #endif // ENABLE_HTTP3 ) : loop(loop), @@ -214,7 +214,8 @@ struct WorkerProcess { #ifdef ENABLE_HTTP3 , quic_ipc_fd(quic_ipc_fd), - cid_prefixes(cid_prefixes) + worker_ids(std::move(worker_ids)), + seq(seq) #endif // ENABLE_HTTP3 { ev_child_init(&worker_process_childev, worker_process_child_cb, worker_pid, @@ -245,7 +246,8 @@ struct WorkerProcess { std::chrono::steady_clock::time_point termination_deadline; #ifdef ENABLE_HTTP3 int quic_ipc_fd; - std::vector> cid_prefixes; + std::vector worker_ids; + uint16_t seq; #endif // ENABLE_HTTP3 }; @@ -255,6 +257,10 @@ void reload_config(); namespace { std::deque> worker_processes; + +#ifdef ENABLE_HTTP3 +uint16_t worker_process_seq; +#endif // ENABLE_HTTP3 } // namespace namespace { @@ -582,9 +588,10 @@ void exec_binary() { s += util::utos(i + 1); s += '='; s += util::utos(wp->quic_ipc_fd); - for (auto &cid_prefix : wp->cid_prefixes) { + for (auto &wid : wp->worker_ids) { s += ','; - s += util::format_hex(cid_prefix); + s += util::format_hex(reinterpret_cast(&wid), + sizeof(wid)); } quic_lwps.emplace_back(s); @@ -1223,7 +1230,7 @@ std::vector namespace { std::vector get_inherited_quic_lingering_worker_process_from_env() { - std::vector iwps; + std::vector lwps; for (size_t i = 1;; ++i) { auto name = ENV_QUIC_WORKER_PROCESS_PREFIX.str(); @@ -1258,26 +1265,27 @@ get_inherited_quic_lingering_worker_process_from_env() { util::make_socket_closeonexec(fd); - std::vector> cid_prefixes; + std::vector worker_ids; auto p = end_fd + 1; for (;;) { auto end = std::find(p, envend, ','); - auto hex_cid_prefix = StringRef{p, end}; - if (hex_cid_prefix.size() != SHRPX_QUIC_CID_PREFIXLEN * 2 || - !util::is_hex_string(hex_cid_prefix)) { - LOG(WARN) << "Found invalid CID prefix=" << hex_cid_prefix; + auto hex_wid = StringRef{p, end}; + if (hex_wid.size() != SHRPX_QUIC_WORKER_IDLEN * 2 || + !util::is_hex_string(hex_wid)) { + LOG(WARN) << "Found invalid WorkerID=" << hex_wid; break; } if (LOG_ENABLED(INFO)) { - LOG(INFO) << "Inherit worker process CID prefix=" << hex_cid_prefix; + LOG(INFO) << "Inherit worker process WorkerID=" << hex_wid; } - cid_prefixes.emplace_back(); + worker_ids.emplace_back(); - util::decode_hex(std::begin(cid_prefixes.back()), hex_cid_prefix); + util::decode_hex(reinterpret_cast(&worker_ids.back()), + hex_wid); if (end == envend) { break; @@ -1286,10 +1294,20 @@ get_inherited_quic_lingering_worker_process_from_env() { p = end + 1; } - iwps.emplace_back(std::move(cid_prefixes), fd); + lwps.emplace_back(std::move(worker_ids), fd); } - return iwps; + if (!lwps.empty()) { + const auto &lwp = lwps.back(); + + if (!lwp.worker_ids.empty() && + worker_process_seq <= lwp.worker_ids[0].worker_process) { + worker_process_seq = lwp.worker_ids[0].worker_process; + ++worker_process_seq; + } + } + + return lwps; } } // namespace #endif // ENABLE_HTTP3 @@ -1418,32 +1436,33 @@ int create_quic_ipc_socket(std::array &quic_ipc_fd) { } // namespace namespace { -int generate_cid_prefix( - std::vector> &cid_prefixes, - const Config *config) { +int generate_worker_id(std::vector &worker_ids, uint16_t wp_seq, + const Config *config) { auto &apiconf = config->api; auto &quicconf = config->quic; - size_t num_cid_prefix; + size_t num_wid; if (config->single_thread) { - num_cid_prefix = 1; + num_wid = 1; } else { - num_cid_prefix = config->num_worker; + num_wid = config->num_worker; // API endpoint occupies the one dedicated worker thread. - // Although such worker never gets QUIC traffic, we create CID - // prefix for it to make code a bit simpler. + // Although such worker never gets QUIC traffic, we create Worker + // ID for it to make code a bit simpler. if (apiconf.enabled) { - ++num_cid_prefix; + ++num_wid; } } - cid_prefixes.resize(num_cid_prefix); + worker_ids.resize(num_wid); - for (auto &cid_prefix : cid_prefixes) { - if (create_cid_prefix(cid_prefix.data(), quicconf.server_id.data()) != 0) { - return -1; - } + uint16_t idx = 0; + + for (auto &wid : worker_ids) { + wid.server = quicconf.server_id; + wid.worker_process = wp_seq; + wid.thread = idx++; } return 0; @@ -1458,7 +1477,7 @@ collect_quic_lingering_worker_processes() { std::end(inherited_quic_lingering_worker_processes)}; for (auto &wp : worker_processes) { - quic_lwps.emplace_back(wp->cid_prefixes, wp->quic_ipc_fd); + quic_lwps.emplace_back(wp->worker_ids, wp->quic_ipc_fd); } return quic_lwps; @@ -1596,19 +1615,17 @@ namespace { // |main_ipc_fd|. In child process, we will close file descriptors // which are inherited from previous configuration/process, but not // used in the current configuration. -pid_t fork_worker_process( - int &main_ipc_fd +pid_t fork_worker_process(int &main_ipc_fd #ifdef ENABLE_HTTP3 - , - int &wp_quic_ipc_fd + , + int &wp_quic_ipc_fd #endif // ENABLE_HTTP3 - , - const std::vector &iaddrs + , + const std::vector &iaddrs #ifdef ENABLE_HTTP3 - , - const std::vector> - &cid_prefixes, - const std::vector &quic_lwps + , + std::vector worker_ids, + std::vector quic_lwps #endif // ENABLE_HTTP3 ) { std::array errbuf; @@ -1714,9 +1731,9 @@ pid_t fork_worker_process( .ipc_fd = ipc_fd[0], .ready_ipc_fd = worker_process_ready_ipc_fd[1], #ifdef ENABLE_HTTP3 - .cid_prefixes = cid_prefixes, + .worker_ids = std::move(worker_ids), .quic_ipc_fd = quic_ipc_fd[0], - .quic_lingering_worker_processes = quic_lwps, + .quic_lingering_worker_processes = std::move(quic_lwps), #endif // ENABLE_HTTP3 }; rv = worker_process_event_loop(&wpconf); @@ -1835,9 +1852,9 @@ int event_loop() { auto quic_lwps = collect_quic_lingering_worker_processes(); - std::vector> cid_prefixes; + std::vector worker_ids; - if (generate_cid_prefix(cid_prefixes, config) != 0) { + if (generate_worker_id(worker_ids, worker_process_seq, config) != 0) { return -1; } #endif // ENABLE_HTTP3 @@ -1858,7 +1875,7 @@ int event_loop() { {} #ifdef ENABLE_HTTP3 , - cid_prefixes, quic_lwps + worker_ids, std::move(quic_lwps) #endif // ENABLE_HTTP3 ); @@ -1869,12 +1886,13 @@ int event_loop() { ev_timer_init(&worker_process_grace_period_timer, worker_process_grace_period_timercb, 0., 0.); - worker_process_add(std::make_unique(loop, pid, ipc_fd + worker_process_add(std::make_unique( + loop, pid, ipc_fd #ifdef ENABLE_HTTP3 - , - quic_ipc_fd, cid_prefixes + , + quic_ipc_fd, std::move(worker_ids), worker_process_seq++ #endif // ENABLE_HTTP3 - )); + )); // Write PID file when we are ready to accept connection from peer. // This makes easier to write restart script for nghttpx. Because @@ -1911,7 +1929,7 @@ bool conf_exists(const char *path) { } // namespace namespace { -constexpr auto DEFAULT_NPN_LIST = +constexpr auto DEFAULT_ALPN_LIST = StringRef::from_lit("h2,h2-16,h2-14,http/1.1"); } // namespace @@ -1992,11 +2010,7 @@ void fill_default_config(Config *config) { tlsconf.max_proto_version = tls::proto_version_from_string(DEFAULT_TLS_MAX_PROTO_VERSION); tlsconf.max_early_data = 16_k; -#if OPENSSL_1_1_API || defined(OPENSSL_IS_BORINGSSL) tlsconf.ecdh_curves = StringRef::from_lit("X25519:P-256:P-384:P-521"); -#else // !OPENSSL_1_1_API && !defined(OPENSSL_IS_BORINGSSL) - tlsconf.ecdh_curves = StringRef::from_lit("P-256:P-384:P-521"); -#endif // !OPENSSL_1_1_API && !defined(OPENSSL_IS_BORINGSSL) auto &httpconf = config->http; httpconf.server_name = StringRef::from_lit("nghttpx"); @@ -2010,6 +2024,7 @@ void fill_default_config(Config *config) { httpconf.xfp.add = true; httpconf.xfp.strip_incoming = true; httpconf.early_data.strip_incoming = true; + httpconf.timeout.header = 1_min; auto &http2conf = config->http2; { @@ -2092,7 +2107,8 @@ void fill_default_config(Config *config) { static_cast(NGTCP2_DEFAULT_INITIAL_RTT) / NGTCP2_SECONDS; } - if (RAND_bytes(quicconf.server_id.data(), quicconf.server_id.size()) != 1) { + if (RAND_bytes(reinterpret_cast(&quicconf.server_id), + sizeof(quicconf.server_id)) != 1) { assert(0); abort(); } @@ -2136,20 +2152,17 @@ void fill_default_config(Config *config) { auto &upstreamconf = connconf.upstream; { auto &timeoutconf = upstreamconf.timeout; - // Read timeout for HTTP2 upstream connection - timeoutconf.http2_read = 3_min; + // Idle timeout for HTTP2 upstream connection + timeoutconf.http2_idle = 3_min; - // Read timeout for HTTP3 upstream connection - timeoutconf.http3_read = 3_min; - - // Read timeout for non-HTTP2 upstream connection - timeoutconf.read = 1_min; + // Idle timeout for HTTP3 upstream connection + timeoutconf.http3_idle = 3_min; // Write timeout for HTTP2/non-HTTP2 upstream connection timeoutconf.write = 30_s; - // Keep alive timeout for HTTP/1 upstream connection - timeoutconf.idle_read = 1_min; + // Keep alive (idle) timeout for HTTP/1 upstream connection + timeoutconf.idle = 1_min; } } @@ -2648,18 +2661,18 @@ Performance: this option will be simply ignored. Timeout: - --frontend-http2-read-timeout= - Specify read timeout for HTTP/2 frontend connection. + --frontend-http2-idle-timeout= + Specify idle timeout for HTTP/2 frontend connection. If + no active streams exist for this duration, connection is + closed. Default: )" - << util::duration_str(config->conn.upstream.timeout.http2_read) << R"( - --frontend-http3-read-timeout= - Specify read timeout for HTTP/3 frontend connection. + << util::duration_str(config->conn.upstream.timeout.http2_idle) << R"( + --frontend-http3-idle-timeout= + Specify idle timeout for HTTP/3 frontend connection. If + no active streams exist for this duration, connection is + closed. Default: )" - << util::duration_str(config->conn.upstream.timeout.http3_read) << R"( - --frontend-read-timeout= - Specify read timeout for HTTP/1.1 frontend connection. - Default: )" - << util::duration_str(config->conn.upstream.timeout.read) << R"( + << util::duration_str(config->conn.upstream.timeout.http3_idle) << R"( --frontend-write-timeout= Specify write timeout for all frontend connections. Default: )" @@ -2668,7 +2681,15 @@ Timeout: Specify keep-alive timeout for frontend HTTP/1 connection. Default: )" - << util::duration_str(config->conn.upstream.timeout.idle_read) << R"( + << util::duration_str(config->conn.upstream.timeout.idle) << R"( + --frontend-header-timeout= + Specify duration that the server waits for an HTTP + request header fields to be received completely. On + timeout, HTTP/1 and HTTP/2 connections are closed. For + HTTP/3, the stream is shutdown, and the connection + itself is left intact. + Default: )" + << util::duration_str(config->http.timeout.header) << R"( --stream-read-timeout= Specify read timeout for HTTP/2 streams. 0 means no timeout. @@ -2802,15 +2823,14 @@ SSL/TLS: Path to file that contains DH parameters in PEM format. Without this option, DHE cipher suites are not available. - --npn-list= + --alpn-list= Comma delimited list of ALPN protocol identifier sorted in the order of preference. That means most desirable - protocol comes first. This is used in both ALPN and - NPN. The parameter must be delimited by a single comma - only and any white spaces are treated as a part of - protocol string. + protocol comes first. The parameter must be delimited + by a single comma only and any white spaces are treated + as a part of protocol string. Default: )" - << DEFAULT_NPN_LIST + << DEFAULT_ALPN_LIST << R"( --verify-client Require and verify client certificate. @@ -3535,12 +3555,12 @@ HTTP/3 and QUIC: encrypting tokens and Connection IDs. It is not used to encrypt QUIC packets. Each line of this file must contain exactly 136 bytes hex-encoded string (when - decoded the byte string is 68 bytes long). The first 2 + decoded the byte string is 68 bytes long). The first 3 bits of decoded byte string are used to identify the keying material. An empty line or a line which starts '#' is ignored. The file can contain more than one - keying materials. Because the identifier is 2 bits, at - most 4 keying materials are read and the remaining data + keying materials. Because the identifier is 3 bits, at + most 8 keying materials are read and the remaining data is discarded. The first keying material in the file is primarily used for encryption and decryption for new connection. The other ones are used to decrypt data for @@ -3754,8 +3774,8 @@ int process_options(Config *config, auto &tlsconf = config->tls; - if (tlsconf.npn_list.empty()) { - tlsconf.npn_list = util::split_str(DEFAULT_NPN_LIST, ','); + if (tlsconf.alpn_list.empty()) { + tlsconf.alpn_list = util::split_str(DEFAULT_ALPN_LIST, ','); } if (!tlsconf.tls_proto_list.empty()) { @@ -3770,7 +3790,7 @@ int process_options(Config *config, return -1; } - if (tls::set_alpn_prefs(tlsconf.alpn_prefs, tlsconf.npn_list) != 0) { + if (tls::set_alpn_prefs(tlsconf.alpn_prefs, tlsconf.alpn_list) != 0) { return -1; } @@ -4002,9 +4022,10 @@ void reload_config() { auto quic_lwps = collect_quic_lingering_worker_processes(); - std::vector> cid_prefixes; + std::vector worker_ids; - if (generate_cid_prefix(cid_prefixes, new_config.get()) != 0) { + if (generate_worker_id(worker_ids, worker_process_seq, new_config.get()) != + 0) { close_not_inherited_fd(new_config.get(), iaddrs); return; } @@ -4025,7 +4046,7 @@ void reload_config() { iaddrs #ifdef ENABLE_HTTP3 , - cid_prefixes, quic_lwps + worker_ids, std::move(quic_lwps) #endif // ENABLE_HTTP3 ); @@ -4040,12 +4061,13 @@ void reload_config() { close_unused_inherited_addr(iaddrs); - worker_process_add(std::make_unique(loop, pid, ipc_fd + worker_process_add(std::make_unique( + loop, pid, ipc_fd #ifdef ENABLE_HTTP3 - , - quic_ipc_fd, cid_prefixes + , + quic_ipc_fd, std::move(worker_ids), worker_process_seq++ #endif // ENABLE_HTTP3 - )); + )); worker_process_adjust_limit(); @@ -4059,16 +4081,10 @@ int main(int argc, char **argv) { int rv; std::array errbuf; - nghttp2::tls::libssl_init(); - #ifdef HAVE_LIBBPF libbpf_set_strict_mode(LIBBPF_STRICT_ALL); #endif // HAVE_LIBBPF -#ifndef NOTHREADS - nghttp2::tls::LibsslGlobalLock lock; -#endif // NOTHREADS - Log::set_severity_level(NOTICE); create_config(); fill_default_config(mod_config()); @@ -4387,6 +4403,13 @@ int main(int argc, char **argv) { 190}, {SHRPX_OPT_REQUIRE_HTTP_SCHEME.c_str(), no_argument, &flag, 191}, {SHRPX_OPT_TLS_KTLS.c_str(), no_argument, &flag, 192}, + {SHRPX_OPT_ALPN_LIST.c_str(), required_argument, &flag, 193}, + {SHRPX_OPT_FRONTEND_HEADER_TIMEOUT.c_str(), required_argument, &flag, + 194}, + {SHRPX_OPT_FRONTEND_HTTP2_IDLE_TIMEOUT.c_str(), required_argument, + &flag, 195}, + {SHRPX_OPT_FRONTEND_HTTP3_IDLE_TIMEOUT.c_str(), required_argument, + &flag, 196}, {nullptr, 0, nullptr, 0}}; int option_index = 0; @@ -5300,6 +5323,25 @@ int main(int argc, char **argv) { // --tls-ktls cmdcfgs.emplace_back(SHRPX_OPT_TLS_KTLS, StringRef::from_lit("yes")); break; + case 193: + // --alpn-list + cmdcfgs.emplace_back(SHRPX_OPT_ALPN_LIST, StringRef{optarg}); + break; + case 194: + // --frontend-header-timeout + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HEADER_TIMEOUT, + StringRef{optarg}); + break; + case 195: + // --frontend-http2-idle-timeout + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_IDLE_TIMEOUT, + StringRef{optarg}); + break; + case 196: + // --frontend-http3-idle-timeout + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP3_IDLE_TIMEOUT, + StringRef{optarg}); + break; default: break; } diff --git a/yass/third_party/nghttp2/src/shrpx.h b/yass/third_party/nghttp2/src/shrpx.h index d881ef5d9d..e6379bd8b2 100644 --- a/yass/third_party/nghttp2/src/shrpx.h +++ b/yass/third_party/nghttp2/src/shrpx.h @@ -36,6 +36,8 @@ #include +#define NGHTTP2_NO_SSIZE_T + #ifndef HAVE__EXIT # define nghttp2_Exit(status) _exit(status) #else // HAVE__EXIT diff --git a/yass/third_party/nghttp2/src/shrpx_client_handler.cc b/yass/third_party/nghttp2/src/shrpx_client_handler.cc index e94361b7f0..a78b00a184 100644 --- a/yass/third_party/nghttp2/src/shrpx_client_handler.cc +++ b/yass/third_party/nghttp2/src/shrpx_client_handler.cc @@ -444,7 +444,7 @@ ClientHandler::ClientHandler(Worker *worker, int fd, SSL *ssl, rb_(worker->get_mcpool()), conn_(worker->get_loop(), fd, ssl, worker->get_mcpool(), get_config()->conn.upstream.timeout.write, - get_config()->conn.upstream.timeout.read, + get_config()->conn.upstream.timeout.idle, get_config()->conn.upstream.ratelimit.write, get_config()->conn.upstream.ratelimit.read, writecb, readcb, timeoutcb, this, get_config()->tls.dyn_rec.warmup_threshold, @@ -551,7 +551,7 @@ void ClientHandler::setup_http3_upstream( auto config = get_config(); - reset_upstream_read_timeout(config->conn.upstream.timeout.http3_read); + reset_upstream_read_timeout(config->conn.upstream.timeout.http3_idle); } #endif // ENABLE_HTTP3 @@ -587,22 +587,18 @@ ClientHandler::~ClientHandler() { Upstream *ClientHandler::get_upstream() { return upstream_.get(); } -struct ev_loop *ClientHandler::get_loop() const { - return conn_.loop; -} +struct ev_loop *ClientHandler::get_loop() const { return conn_.loop; } void ClientHandler::reset_upstream_read_timeout(ev_tstamp t) { conn_.rt.repeat = t; - if (ev_is_active(&conn_.rt)) { - ev_timer_again(conn_.loop, &conn_.rt); - } + + ev_timer_again(conn_.loop, &conn_.rt); } void ClientHandler::reset_upstream_write_timeout(ev_tstamp t) { conn_.wt.repeat = t; - if (ev_is_active(&conn_.wt)) { - ev_timer_again(conn_.loop, &conn_.wt); - } + + ev_timer_again(conn_.loop, &conn_.wt); } void ClientHandler::repeat_read_timer() { @@ -618,14 +614,7 @@ int ClientHandler::validate_next_proto() { // First set callback for catch all cases on_read_ = &ClientHandler::upstream_read; -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(conn_.tls.ssl, &next_proto, &next_proto_len); -#endif // !OPENSSL_NO_NEXTPROTONEG -#if OPENSSL_VERSION_NUMBER >= 0x10002000L - if (next_proto == nullptr) { - SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len); - } -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len); StringRef proto; @@ -643,7 +632,7 @@ int ClientHandler::validate_next_proto() { proto = StringRef::from_lit("http/1.1"); } - if (!tls::in_proto_list(get_config()->tls.npn_list, proto)) { + if (!tls::in_proto_list(get_config()->tls.alpn_list, proto)) { if (LOG_ENABLED(INFO)) { CLOG(INFO, this) << "The negotiated protocol is not supported: " << proto; } diff --git a/yass/third_party/nghttp2/src/shrpx_config.cc b/yass/third_party/nghttp2/src/shrpx_config.cc index bcb48ebcce..d856c95477 100644 --- a/yass/third_party/nghttp2/src/shrpx_config.cc +++ b/yass/third_party/nghttp2/src/shrpx_config.cc @@ -49,6 +49,8 @@ #include #include +#include + #include #include "url-parser/url_parser.h" @@ -64,6 +66,10 @@ #include "ssl_compat.h" #include "xsi_strerror.h" +#ifndef AI_NUMERICSERV +# define AI_NUMERICSERV 0 +#endif + namespace shrpx { namespace { @@ -276,9 +282,9 @@ read_quic_secret_file(const StringRef &path) { assert(static_cast(p - std::begin(s)) == expectedlen * 2); - qkm.id = qkm.reserved[0] & 0xc0; + qkm.id = qkm.reserved[0] & SHRPX_QUIC_DCID_KM_ID_MASK; - if (kms.size() == 4) { + if (kms.size() == 8) { break; } } @@ -1510,7 +1516,7 @@ int parse_subcert_params(SubcertParams &out, const StringRef &src_params) { auto param = StringRef{first, end}; if (util::istarts_with_l(param, "sct-dir=")) { -#if !LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_BORINGSSL) auto sct_dir = StringRef{std::begin(param) + str_size("sct-dir="), std::end(param)}; if (sct_dir.empty()) { @@ -1518,9 +1524,10 @@ int parse_subcert_params(SubcertParams &out, const StringRef &src_params) { return -1; } out.sct_dir = sct_dir; -#else // !(!LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L) - LOG(WARN) << "subcert: sct-dir requires OpenSSL >= 1.0.2"; -#endif // !(!LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L) +#else // !NGHTTP2_GENUINE_OPENSSL && !NGHTTP2_OPENSSL_IS_BORINGSSL + LOG(WARN) << "subcert: sct-dir is ignored because underlying TLS library " + "does not support SCT"; +#endif // !NGHTTP2_GENUINE_OPENSSL && !NGHTTP2_OPENSSL_IS_BORINGSSL } else if (!param.empty()) { LOG(ERROR) << "subcert: " << param << ": unknown keyword"; return -1; @@ -1652,7 +1659,7 @@ int read_tls_sct_from_dir(std::vector &dst, const StringRef &opt, } } // namespace -#if !LIBRESSL_LEGACY_API +#ifndef OPENSSL_NO_PSK namespace { // Reads PSK secrets from path, and parses each line. The result is // directly stored into config->tls.psk_secrets. This function @@ -1716,9 +1723,9 @@ int parse_psk_secrets(Config *config, const StringRef &path) { return 0; } } // namespace -#endif // !LIBRESSL_LEGACY_API +#endif // !OPENSSL_NO_PSK -#if !LIBRESSL_LEGACY_API +#ifndef OPENSSL_NO_PSK namespace { // Reads PSK secrets from path, and parses each line. The result is // directly stored into config->tls.client.psk. This function returns @@ -1778,7 +1785,7 @@ int parse_client_psk_secrets(Config *config, const StringRef &path) { return 0; } } // namespace -#endif // !LIBRESSL_LEGACY_API +#endif // !OPENSSL_NO_PSK // generated by gennghttpxfun.py int option_lookup_token(const char *name, size_t namelen) { @@ -1911,6 +1918,11 @@ int option_lookup_token(const char *name, size_t namelen) { return SHRPX_OPTID_LOG_LEVEL; } break; + case 't': + if (util::strieq_l("alpn-lis", name, 8)) { + return SHRPX_OPTID_ALPN_LIST; + } + break; } break; case 10: @@ -2384,6 +2396,9 @@ int option_lookup_token(const char *name, size_t namelen) { if (util::strieq_l("backend-connect-timeou", name, 22)) { return SHRPX_OPTID_BACKEND_CONNECT_TIMEOUT; } + if (util::strieq_l("frontend-header-timeou", name, 22)) { + return SHRPX_OPTID_FRONTEND_HEADER_TIMEOUT; + } break; } break; @@ -2514,9 +2529,15 @@ int option_lookup_token(const char *name, size_t namelen) { } break; case 't': + if (util::strieq_l("frontend-http2-idle-timeou", name, 26)) { + return SHRPX_OPTID_FRONTEND_HTTP2_IDLE_TIMEOUT; + } if (util::strieq_l("frontend-http2-read-timeou", name, 26)) { return SHRPX_OPTID_FRONTEND_HTTP2_READ_TIMEOUT; } + if (util::strieq_l("frontend-http3-idle-timeou", name, 26)) { + return SHRPX_OPTID_FRONTEND_HTTP3_IDLE_TIMEOUT; + } if (util::strieq_l("frontend-http3-read-timeou", name, 26)) { return SHRPX_OPTID_FRONTEND_HTTP3_READ_TIMEOUT; } @@ -2954,13 +2975,28 @@ int parse_config(Config *config, int optid, const StringRef &opt, return 0; } - case SHRPX_OPTID_WORKERS: + case SHRPX_OPTID_WORKERS: { #ifdef NOTHREADS LOG(WARN) << "Threading disabled at build time, no threads created."; return 0; #else // !NOTHREADS - return parse_uint(&config->num_worker, opt, optarg); + size_t n; + + if (parse_uint(&n, opt, optarg) != 0) { + return -1; + } + + if (n > 65530) { + LOG(ERROR) << opt << ": the number of workers must not exceed 65530"; + + return -1; + } + + config->num_worker = n; + + return 0; #endif // !NOTHREADS + } case SHRPX_OPTID_HTTP2_MAX_CONCURRENT_STREAMS: { LOG(WARN) << opt << ": deprecated. Use " << SHRPX_OPT_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS << " and " @@ -3016,10 +3052,17 @@ int parse_config(Config *config, int optid, const StringRef &opt, return 0; case SHRPX_OPTID_FRONTEND_HTTP2_READ_TIMEOUT: - return parse_duration(&config->conn.upstream.timeout.http2_read, opt, + LOG(WARN) << opt << ": deprecated. Use frontend-http2-idle-timeout"; + // fall through + case SHRPX_OPTID_FRONTEND_HTTP2_IDLE_TIMEOUT: + return parse_duration(&config->conn.upstream.timeout.http2_idle, opt, optarg); case SHRPX_OPTID_FRONTEND_READ_TIMEOUT: - return parse_duration(&config->conn.upstream.timeout.read, opt, optarg); + LOG(WARN) << opt << ": deprecated. Use frontend-header-timeout"; + + return 0; + case SHRPX_OPTID_FRONTEND_HEADER_TIMEOUT: + return parse_duration(&config->http.timeout.header, opt, optarg); case SHRPX_OPTID_FRONTEND_WRITE_TIMEOUT: return parse_duration(&config->conn.upstream.timeout.write, opt, optarg); case SHRPX_OPTID_BACKEND_READ_TIMEOUT: @@ -3340,15 +3383,6 @@ int parse_config(Config *config, int optid, const StringRef &opt, case SHRPX_OPTID_WORKER_WRITE_BURST: LOG(WARN) << opt << ": not implemented yet"; return 0; - case SHRPX_OPTID_NPN_LIST: { - auto list = util::split_str(optarg, ','); - config->tls.npn_list.resize(list.size()); - for (size_t i = 0; i < list.size(); ++i) { - config->tls.npn_list[i] = make_string_ref(config->balloc, list[i]); - } - - return 0; - } case SHRPX_OPTID_TLS_PROTO_LIST: { LOG(WARN) << opt << ": deprecated. Use tls-min-proto-version and " @@ -3874,19 +3908,17 @@ int parse_config(Config *config, int optid, const StringRef &opt, return parse_uint_with_unit( &config->http2.downstream.decoder_dynamic_table_size, opt, optarg); case SHRPX_OPTID_ECDH_CURVES: -#if !LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L config->tls.ecdh_curves = make_string_ref(config->balloc, optarg); -#else // !(!LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L) - LOG(WARN) << opt << ": This option requires OpenSSL >= 1.0.2"; -#endif // !(!LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L) return 0; case SHRPX_OPTID_TLS_SCT_DIR: -#if !LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_BORINGSSL) return read_tls_sct_from_dir(config->tls.sct_data, opt, optarg); -#else // !(!LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L) - LOG(WARN) << opt << ": This option requires OpenSSL >= 1.0.2"; +#else // !NGHTTP2_GENUINE_OPENSSL && !NGHTTP2_OPENSSL_IS_BORINGSSL + LOG(WARN) + << opt + << ": ignored because underlying TLS library does not support SCT"; return 0; -#endif // !(!LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L) +#endif // !NGHTTP2_GENUINE_OPENSSL && !NGHTTP2_OPENSSL_IS_BORINGSSL case SHRPX_OPTID_DNS_CACHE_TIMEOUT: return parse_duration(&config->dns.timeout.cache, opt, optarg); case SHRPX_OPTID_DNS_LOOKUP_TIMEOUT: @@ -3906,26 +3938,25 @@ int parse_config(Config *config, int optid, const StringRef &opt, return 0; } case SHRPX_OPTID_FRONTEND_KEEP_ALIVE_TIMEOUT: - return parse_duration(&config->conn.upstream.timeout.idle_read, opt, - optarg); + return parse_duration(&config->conn.upstream.timeout.idle, opt, optarg); case SHRPX_OPTID_PSK_SECRETS: -#if !LIBRESSL_LEGACY_API +#ifndef OPENSSL_NO_PSK return parse_psk_secrets(config, optarg); -#else // LIBRESSL_LEGACY_API +#else // OPENSSL_NO_PSK LOG(WARN) << opt << ": ignored because underlying TLS library does not support PSK"; return 0; -#endif // LIBRESSL_LEGACY_API +#endif // OPENSSL_NO_PSK case SHRPX_OPTID_CLIENT_PSK_SECRETS: -#if !LIBRESSL_LEGACY_API +#ifndef OPENSSL_NO_PSK return parse_client_psk_secrets(config, optarg); -#else // LIBRESSL_LEGACY_API +#else // OPENSSL_NO_PSK LOG(WARN) << opt << ": ignored because underlying TLS library does not support PSK"; return 0; -#endif // LIBRESSL_LEGACY_API +#endif // OPENSSL_NO_PSK case SHRPX_OPTID_CLIENT_NO_HTTP2_CIPHER_BLACK_LIST: LOG(WARN) << opt << ": deprecated. Use " << SHRPX_OPT_CLIENT_NO_HTTP2_CIPHER_BLOCK_LIST << " instead."; @@ -4031,8 +4062,11 @@ int parse_config(Config *config, int optid, const StringRef &opt, return 0; } case SHRPX_OPTID_FRONTEND_HTTP3_READ_TIMEOUT: + LOG(WARN) << opt << ": deprecated. Use frontend-http3-idle-timeout"; + // fall through + case SHRPX_OPTID_FRONTEND_HTTP3_IDLE_TIMEOUT: #ifdef ENABLE_HTTP3 - return parse_duration(&config->conn.upstream.timeout.http3_read, opt, + return parse_duration(&config->conn.upstream.timeout.http3_idle, opt, optarg); #else // !ENABLE_HTTP3 return 0; @@ -4125,12 +4159,13 @@ int parse_config(Config *config, int optid, const StringRef &opt, return 0; case SHRPX_OPTID_QUIC_SERVER_ID: #ifdef ENABLE_HTTP3 - if (optarg.size() != config->quic.server_id.size() * 2 || + if (optarg.size() != sizeof(config->quic.server_id) * 2 || !util::is_hex_string(optarg)) { LOG(ERROR) << opt << ": must be a hex-string"; return -1; } - util::decode_hex(std::begin(config->quic.server_id), optarg); + util::decode_hex(reinterpret_cast(&config->quic.server_id), + optarg); #endif // ENABLE_HTTP3 return 0; @@ -4175,6 +4210,18 @@ int parse_config(Config *config, int optid, const StringRef &opt, case SHRPX_OPTID_TLS_KTLS: config->tls.ktls = util::strieq_l("yes", optarg); return 0; + case SHRPX_OPTID_NPN_LIST: + LOG(WARN) << opt << ": deprecated. Use alpn-list instead."; + // fall through + case SHRPX_OPTID_ALPN_LIST: { + auto list = util::split_str(optarg, ','); + config->tls.alpn_list.resize(list.size()); + for (size_t i = 0; i < list.size(); ++i) { + config->tls.alpn_list[i] = make_string_ref(config->balloc, list[i]); + } + + return 0; + } case SHRPX_OPTID_CONF: LOG(WARN) << "conf: ignored"; @@ -4684,4 +4731,38 @@ int resolve_hostname(Address *addr, const char *hostname, uint16_t port, return 0; } +#ifdef ENABLE_HTTP3 +QUICKeyingMaterial::QUICKeyingMaterial(QUICKeyingMaterial &&other) noexcept + : cid_encryption_ctx{std::exchange(other.cid_encryption_ctx, nullptr)}, + cid_decryption_ctx{std::exchange(other.cid_decryption_ctx, nullptr)}, + reserved{other.reserved}, + secret{other.secret}, + salt{other.salt}, + cid_encryption_key{other.cid_encryption_key}, + id{other.id} {} + +QUICKeyingMaterial::~QUICKeyingMaterial() noexcept { + if (cid_encryption_ctx) { + EVP_CIPHER_CTX_free(cid_encryption_ctx); + } + + if (cid_decryption_ctx) { + EVP_CIPHER_CTX_free(cid_decryption_ctx); + } +} + +QUICKeyingMaterial & +QUICKeyingMaterial::operator=(QUICKeyingMaterial &&other) noexcept { + cid_encryption_ctx = std::exchange(other.cid_encryption_ctx, nullptr); + cid_decryption_ctx = std::exchange(other.cid_decryption_ctx, nullptr); + reserved = other.reserved; + secret = other.secret; + salt = other.salt; + cid_encryption_key = other.cid_encryption_key; + id = other.id; + + return *this; +} +#endif // ENABLE_HTTP3 + } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_config.h b/yass/third_party/nghttp2/src/shrpx_config.h index 0c43a3c267..f264b6a6c7 100644 --- a/yass/third_party/nghttp2/src/shrpx_config.h +++ b/yass/third_party/nghttp2/src/shrpx_config.h @@ -405,6 +405,13 @@ constexpr auto SHRPX_OPT_FRONTEND_QUIC_INITIAL_RTT = constexpr auto SHRPX_OPT_REQUIRE_HTTP_SCHEME = StringRef::from_lit("require-http-scheme"); constexpr auto SHRPX_OPT_TLS_KTLS = StringRef::from_lit("tls-ktls"); +constexpr auto SHRPX_OPT_ALPN_LIST = StringRef::from_lit("alpn-list"); +constexpr auto SHRPX_OPT_FRONTEND_HEADER_TIMEOUT = + StringRef::from_lit("frontend-header-timeout"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP2_IDLE_TIMEOUT = + StringRef::from_lit("frontend-http2-idle-timeout"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP3_IDLE_TIMEOUT = + StringRef::from_lit("frontend-http3-idle-timeout"); constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8; @@ -635,6 +642,12 @@ struct TLSCertificate { #ifdef ENABLE_HTTP3 struct QUICKeyingMaterial { + QUICKeyingMaterial() noexcept = default; + QUICKeyingMaterial(QUICKeyingMaterial &&other) noexcept; + ~QUICKeyingMaterial() noexcept; + QUICKeyingMaterial &operator=(QUICKeyingMaterial &&other) noexcept; + EVP_CIPHER_CTX *cid_encryption_ctx; + EVP_CIPHER_CTX *cid_decryption_ctx; std::array reserved; std::array secret; std::array salt; @@ -753,9 +766,9 @@ struct TLSConfig { // The list of additional TLS certificate pair std::vector subcerts; std::vector alpn_prefs; - // list of supported NPN/ALPN protocol strings in the order of + // list of supported ALPN protocol strings in the order of // preference. - std::vector npn_list; + std::vector alpn_list; // list of supported SSL/TLS protocol strings. std::vector tls_proto_list; std::vector sct_data; @@ -809,7 +822,7 @@ struct QUICConfig { StringRef prog_file; bool disabled; } bpf; - std::array server_id; + uint32_t server_id; }; struct Http3Config { @@ -858,6 +871,9 @@ struct HttpConfig { struct { bool strip_incoming; } early_data; + struct { + ev_tstamp header; + } timeout; std::vector altsvcs; // altsvcs serialized in a wire format. StringRef altsvc_header_value; @@ -1042,11 +1058,10 @@ struct ConnectionConfig { struct { struct { - ev_tstamp http2_read; - ev_tstamp http3_read; - ev_tstamp read; + ev_tstamp http2_idle; + ev_tstamp http3_idle; ev_tstamp write; - ev_tstamp idle_read; + ev_tstamp idle; } timeout; struct { RateLimitConfig read; @@ -1183,6 +1198,7 @@ enum { SHRPX_OPTID_ADD_REQUEST_HEADER, SHRPX_OPTID_ADD_RESPONSE_HEADER, SHRPX_OPTID_ADD_X_FORWARDED_FOR, + SHRPX_OPTID_ALPN_LIST, SHRPX_OPTID_ALTSVC, SHRPX_OPTID_API_MAX_REQUEST_BODY, SHRPX_OPTID_BACKEND, @@ -1242,12 +1258,14 @@ enum { SHRPX_OPTID_FORWARDED_FOR, SHRPX_OPTID_FRONTEND, SHRPX_OPTID_FRONTEND_FRAME_DEBUG, + SHRPX_OPTID_FRONTEND_HEADER_TIMEOUT, SHRPX_OPTID_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS, SHRPX_OPTID_FRONTEND_HTTP2_CONNECTION_WINDOW_SIZE, SHRPX_OPTID_FRONTEND_HTTP2_DECODER_DYNAMIC_TABLE_SIZE, SHRPX_OPTID_FRONTEND_HTTP2_DUMP_REQUEST_HEADER, SHRPX_OPTID_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER, SHRPX_OPTID_FRONTEND_HTTP2_ENCODER_DYNAMIC_TABLE_SIZE, + SHRPX_OPTID_FRONTEND_HTTP2_IDLE_TIMEOUT, SHRPX_OPTID_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS, SHRPX_OPTID_FRONTEND_HTTP2_OPTIMIZE_WINDOW_SIZE, SHRPX_OPTID_FRONTEND_HTTP2_OPTIMIZE_WRITE_BUFFER_SIZE, @@ -1256,6 +1274,7 @@ enum { SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_BITS, SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_SIZE, SHRPX_OPTID_FRONTEND_HTTP3_CONNECTION_WINDOW_SIZE, + SHRPX_OPTID_FRONTEND_HTTP3_IDLE_TIMEOUT, SHRPX_OPTID_FRONTEND_HTTP3_MAX_CONCURRENT_STREAMS, SHRPX_OPTID_FRONTEND_HTTP3_MAX_CONNECTION_WINDOW_SIZE, SHRPX_OPTID_FRONTEND_HTTP3_MAX_WINDOW_SIZE, diff --git a/yass/third_party/nghttp2/src/shrpx_config_test.cc b/yass/third_party/nghttp2/src/shrpx_config_test.cc index a8f09628d7..068f185df8 100644 --- a/yass/third_party/nghttp2/src/shrpx_config_test.cc +++ b/yass/third_party/nghttp2/src/shrpx_config_test.cc @@ -30,43 +30,57 @@ #include -#include +#include "munitxx.h" #include "shrpx_config.h" #include "shrpx_log.h" namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_config_parse_header), + munit_void_test(test_shrpx_config_parse_log_format), + munit_void_test(test_shrpx_config_read_tls_ticket_key_file), + munit_void_test(test_shrpx_config_read_tls_ticket_key_file_aes_256), + munit_test_end(), +}; +} // namespace + +const MunitSuite config_suite{ + "/config_suite", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_config_parse_header(void) { BlockAllocator balloc(4096, 4096); auto p = parse_header(balloc, StringRef::from_lit("a: b")); - CU_ASSERT("a" == p.name); - CU_ASSERT("b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal("b", p.value.str()); p = parse_header(balloc, StringRef::from_lit("a: b")); - CU_ASSERT("a" == p.name); - CU_ASSERT("b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal("b", p.value.str()); p = parse_header(balloc, StringRef::from_lit(":a: b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("a: :b")); - CU_ASSERT("a" == p.name); - CU_ASSERT(":b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal(":b", p.value.str()); p = parse_header(balloc, StringRef::from_lit(": b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("alpha: bravo charlie")); - CU_ASSERT("alpha" == p.name); - CU_ASSERT("bravo charlie" == p.value); + assert_stdstring_equal("alpha", p.name.str()); + assert_stdstring_equal("bravo charlie", p.value.str()); p = parse_header(balloc, StringRef::from_lit("a,: b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("a: b\x0a")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); } void test_shrpx_config_parse_log_format(void) { @@ -77,100 +91,102 @@ void test_shrpx_config_parse_log_format(void) { R"($remote_addr - $remote_user [$time_local] )" R"("$request" $status $body_bytes_sent )" R"("${http_referer}" $http_host "$http_user_agent")")); - CU_ASSERT(16 == res.size()); + assert_size(16, ==, res.size()); - CU_ASSERT(LogFragmentType::REMOTE_ADDR == res[0].type); + assert_enum_class(LogFragmentType::REMOTE_ADDR, ==, res[0].type); - CU_ASSERT(LogFragmentType::LITERAL == res[1].type); - CU_ASSERT(" - $remote_user [" == res[1].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[1].type); + assert_stdstring_equal(" - $remote_user [", res[1].value.str()); - CU_ASSERT(LogFragmentType::TIME_LOCAL == res[2].type); + assert_enum_class(LogFragmentType::TIME_LOCAL, ==, res[2].type); - CU_ASSERT(LogFragmentType::LITERAL == res[3].type); - CU_ASSERT("] \"" == res[3].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[3].type); + assert_stdstring_equal("] \"", res[3].value.str()); - CU_ASSERT(LogFragmentType::REQUEST == res[4].type); + assert_enum_class(LogFragmentType::REQUEST, ==, res[4].type); - CU_ASSERT(LogFragmentType::LITERAL == res[5].type); - CU_ASSERT("\" " == res[5].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[5].type); + assert_stdstring_equal("\" ", res[5].value.str()); - CU_ASSERT(LogFragmentType::STATUS == res[6].type); + assert_enum_class(LogFragmentType::STATUS, ==, res[6].type); - CU_ASSERT(LogFragmentType::LITERAL == res[7].type); - CU_ASSERT(" " == res[7].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[7].type); + assert_stdstring_equal(" ", res[7].value.str()); - CU_ASSERT(LogFragmentType::BODY_BYTES_SENT == res[8].type); + assert_enum_class(LogFragmentType::BODY_BYTES_SENT, ==, res[8].type); - CU_ASSERT(LogFragmentType::LITERAL == res[9].type); - CU_ASSERT(" \"" == res[9].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[9].type); + assert_stdstring_equal(" \"", res[9].value.str()); - CU_ASSERT(LogFragmentType::HTTP == res[10].type); - CU_ASSERT("referer" == res[10].value); + assert_enum_class(LogFragmentType::HTTP, ==, res[10].type); + assert_stdstring_equal("referer", res[10].value.str()); - CU_ASSERT(LogFragmentType::LITERAL == res[11].type); - CU_ASSERT("\" " == res[11].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[11].type); + assert_stdstring_equal("\" ", res[11].value.str()); - CU_ASSERT(LogFragmentType::AUTHORITY == res[12].type); + assert_enum_class(LogFragmentType::AUTHORITY, ==, res[12].type); - CU_ASSERT(LogFragmentType::LITERAL == res[13].type); - CU_ASSERT(" \"" == res[13].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[13].type); + assert_stdstring_equal(" \"", res[13].value.str()); - CU_ASSERT(LogFragmentType::HTTP == res[14].type); - CU_ASSERT("user-agent" == res[14].value); + assert_enum_class(LogFragmentType::HTTP, ==, res[14].type); + assert_stdstring_equal("user-agent", res[14].value.str()); - CU_ASSERT(LogFragmentType::LITERAL == res[15].type); - CU_ASSERT("\"" == res[15].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[15].type); + assert_stdstring_equal("\"", res[15].value.str()); res = parse_log_format(balloc, StringRef::from_lit("$")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("$" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("$", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${a")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${a" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${a", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${a ")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${a " == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${a ", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("$$remote_addr")); - CU_ASSERT(2 == res.size()); + assert_size(2, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("$" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("$", res[0].value.str()); - CU_ASSERT(LogFragmentType::REMOTE_ADDR == res[1].type); - CU_ASSERT("" == res[1].value); + assert_enum_class(LogFragmentType::REMOTE_ADDR, ==, res[1].type); + assert_stdstring_equal("", res[1].value.str()); } void test_shrpx_config_read_tls_ticket_key_file(void) { char file1[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd1 = mkstemp(file1); - CU_ASSERT(fd1 != -1); - CU_ASSERT(48 == - write(fd1, "0..............12..............34..............5", 48)); + assert_int(-1, !=, fd1); + assert_ssize( + 48, ==, + write(fd1, "0..............12..............34..............5", 48)); char file2[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd2 = mkstemp(file2); - CU_ASSERT(fd2 != -1); - CU_ASSERT(48 == - write(fd2, "6..............78..............9a..............b", 48)); + assert_int(-1, !=, fd2); + assert_ssize( + 48, ==, + write(fd2, "6..............78..............9a..............b", 48)); close(fd1); close(fd2); @@ -178,44 +194,48 @@ void test_shrpx_config_read_tls_ticket_key_file(void) { {StringRef{file1}, StringRef{file2}}, EVP_aes_128_cbc(), EVP_sha256()); unlink(file1); unlink(file2); - CU_ASSERT(ticket_keys.get() != nullptr); - CU_ASSERT(2 == ticket_keys->keys.size()); + assert_not_null(ticket_keys.get()); + assert_size(2, ==, ticket_keys->keys.size()); auto key = &ticket_keys->keys[0]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "0..............1")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::begin(key->data.enc_key) + 16, "2..............3")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::begin(key->data.hmac_key) + 16, - "4..............5")); - CU_ASSERT(16 == key->hmac_keylen); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "0..............1")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::begin(key->data.enc_key) + 16, + "2..............3")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::begin(key->data.hmac_key) + 16, + "4..............5")); + assert_size(16, ==, key->hmac_keylen); key = &ticket_keys->keys[1]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "6..............7")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::begin(key->data.enc_key) + 16, "8..............9")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::begin(key->data.hmac_key) + 16, - "a..............b")); - CU_ASSERT(16 == key->hmac_keylen); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "6..............7")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::begin(key->data.enc_key) + 16, + "8..............9")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::begin(key->data.hmac_key) + 16, + "a..............b")); + assert_size(16, ==, key->hmac_keylen); } void test_shrpx_config_read_tls_ticket_key_file_aes_256(void) { char file1[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd1 = mkstemp(file1); - CU_ASSERT(fd1 != -1); - CU_ASSERT(80 == write(fd1, - "0..............12..............................34..." - "...........................5", - 80)); + assert_int(-1, !=, fd1); + assert_ssize(80, ==, + write(fd1, + "0..............12..............................34..." + "...........................5", + 80)); char file2[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd2 = mkstemp(file2); - CU_ASSERT(fd2 != -1); - CU_ASSERT(80 == write(fd2, - "6..............78..............................9a..." - "...........................b", - 80)); + assert_int(-1, !=, fd2); + assert_ssize(80, ==, + write(fd2, + "6..............78..............................9a..." + "...........................b", + 80)); close(fd1); close(fd2); @@ -223,27 +243,27 @@ void test_shrpx_config_read_tls_ticket_key_file_aes_256(void) { {StringRef{file1}, StringRef{file2}}, EVP_aes_256_cbc(), EVP_sha256()); unlink(file1); unlink(file2); - CU_ASSERT(ticket_keys.get() != nullptr); - CU_ASSERT(2 == ticket_keys->keys.size()); + assert_not_null(ticket_keys.get()); + assert_size(2, ==, ticket_keys->keys.size()); auto key = &ticket_keys->keys[0]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "0..............1")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::end(key->data.enc_key), - "2..............................3")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::end(key->data.hmac_key), - "4..............................5")); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "0..............1")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::end(key->data.enc_key), + "2..............................3")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::end(key->data.hmac_key), + "4..............................5")); key = &ticket_keys->keys[1]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "6..............7")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::end(key->data.enc_key), - "8..............................9")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::end(key->data.hmac_key), - "a..............................b")); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "6..............7")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::end(key->data.enc_key), + "8..............................9")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::end(key->data.hmac_key), + "a..............................b")); } } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_config_test.h b/yass/third_party/nghttp2/src/shrpx_config_test.h index a30de41aa5..9863101e70 100644 --- a/yass/third_party/nghttp2/src/shrpx_config_test.h +++ b/yass/third_party/nghttp2/src/shrpx_config_test.h @@ -29,13 +29,18 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_config_parse_header(void); -void test_shrpx_config_parse_log_format(void); -void test_shrpx_config_read_tls_ticket_key_file(void); -void test_shrpx_config_read_tls_ticket_key_file_aes_256(void); -void test_shrpx_config_match_downstream_addr_group(void); +extern const MunitSuite config_suite; + +munit_void_test_decl(test_shrpx_config_parse_header); +munit_void_test_decl(test_shrpx_config_parse_log_format); +munit_void_test_decl(test_shrpx_config_read_tls_ticket_key_file); +munit_void_test_decl(test_shrpx_config_read_tls_ticket_key_file_aes_256); } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_connection.cc b/yass/third_party/nghttp2/src/shrpx_connection.cc index 273fba3b84..d863284fb2 100644 --- a/yass/third_party/nghttp2/src/shrpx_connection.cc +++ b/yass/third_party/nghttp2/src/shrpx_connection.cc @@ -45,14 +45,6 @@ using namespace std::chrono_literals; namespace shrpx { -#if !LIBRESSL_3_5_API && !LIBRESSL_2_7_API && !OPENSSL_1_1_API - -void *BIO_get_data(BIO *bio) { return bio->ptr; } -void BIO_set_data(BIO *bio, void *ptr) { bio->ptr = ptr; } -void BIO_set_init(BIO *bio, int init) { bio->init = init; } - -#endif // !LIBRESSL_3_5_API && !LIBRESSL_2_7_API && !OPENSSL_1_1_API - Connection::Connection(struct ev_loop *loop, int fd, SSL *ssl, MemchunkPool *mcpool, ev_tstamp write_timeout, ev_tstamp read_timeout, @@ -263,14 +255,8 @@ long shrpx_bio_ctrl(BIO *b, int cmd, long num, void *ptr) { namespace { int shrpx_bio_create(BIO *b) { -#if OPENSSL_1_1_API || LIBRESSL_3_5_API BIO_set_init(b, 1); -#else // !OPENSSL_1_1_API && !LIBRESSL_3_5_API - b->init = 1; - b->num = 0; - b->ptr = nullptr; - b->flags = 0; -#endif // !OPENSSL_1_1_API && !LIBRESSL_3_5_API + return 1; } } // namespace @@ -281,18 +267,10 @@ int shrpx_bio_destroy(BIO *b) { return 0; } -#if !OPENSSL_1_1_API && !LIBRESSL_3_5_API - b->ptr = nullptr; - b->init = 0; - b->flags = 0; -#endif // !OPENSSL_1_1_API && !LIBRESSL_3_5_API - return 1; } } // namespace -#if OPENSSL_1_1_API || LIBRESSL_3_5_API - BIO_METHOD *create_bio_method() { auto meth = BIO_meth_new(BIO_TYPE_FD, "nghttpx-bio"); BIO_meth_set_write(meth, shrpx_bio_write); @@ -306,20 +284,6 @@ BIO_METHOD *create_bio_method() { return meth; } -#else // !OPENSSL_1_1_API && !LIBRESSL_3_5_API - -BIO_METHOD *create_bio_method() { - static auto meth = new BIO_METHOD{ - BIO_TYPE_FD, "nghttpx-bio", shrpx_bio_write, - shrpx_bio_read, shrpx_bio_puts, shrpx_bio_gets, - shrpx_bio_ctrl, shrpx_bio_create, shrpx_bio_destroy, - }; - - return meth; -} - -#endif // !OPENSSL_1_1_API && !LIBRESSL_3_5_API - void Connection::set_ssl(SSL *ssl) { tls.ssl = ssl; @@ -407,7 +371,7 @@ int Connection::tls_handshake() { ERR_clear_error(); -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL if (!tls.server_handshake || tls.early_data_finish) { rv = SSL_do_handshake(tls.ssl); } else { @@ -458,9 +422,9 @@ int Connection::tls_handshake() { } } } -#else // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#else // !NGHTTP2_GENUINE_OPENSSL rv = SSL_do_handshake(tls.ssl); -#endif // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#endif // !NGHTTP2_GENUINE_OPENSSL if (rv <= 0) { auto err = SSL_get_error(tls.ssl, rv); @@ -509,9 +473,9 @@ int Connection::tls_handshake() { // routine. We have to check HTTP/2 requirement if HTTP/2 was // negotiated before sending finished message to the peer. if ((rv != 1 -#ifdef OPENSSL_IS_BORINGSSL +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL || SSL_in_init(tls.ssl) -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL ) && tls.wbuf.rleft()) { // First write indicates that resumption stuff has done. @@ -549,7 +513,7 @@ int Connection::tls_handshake() { return SHRPX_ERR_INPROGRESS; } -#ifdef OPENSSL_IS_BORINGSSL +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL if (!tlsconf.no_postpone_early_data && SSL_in_early_data(tls.ssl) && SSL_in_init(tls.ssl)) { auto nread = SSL_read(tls.ssl, buf.data(), buf.size()); @@ -581,7 +545,7 @@ int Connection::tls_handshake() { return SHRPX_ERR_INPROGRESS; } } -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL // Handshake was done @@ -611,14 +575,14 @@ int Connection::tls_handshake_simple() { } int rv; -#if OPENSSL_1_1_1_API || defined(OPENSSL_IS_BORINGSSL) +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_BORINGSSL) auto &tlsconf = get_config()->tls; std::array buf; -#endif // OPENSSL_1_1_1_API || defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_GENUINE_OPENSSL || NGHTTP2_OPENSSL_IS_BORINGSSL ERR_clear_error(); -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL if (!tls.server_handshake || tls.early_data_finish) { rv = SSL_do_handshake(tls.ssl); } else { @@ -663,9 +627,9 @@ int Connection::tls_handshake_simple() { } } } -#else // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#else // !NGHTTP2_GENUINE_OPENSSL rv = SSL_do_handshake(tls.ssl); -#endif // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#endif // !NGHTTP2_GENUINE_OPENSSL if (rv <= 0) { auto err = SSL_get_error(tls.ssl, rv); @@ -704,7 +668,7 @@ int Connection::tls_handshake_simple() { return SHRPX_ERR_INPROGRESS; } -#ifdef OPENSSL_IS_BORINGSSL +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL if (!tlsconf.no_postpone_early_data && SSL_in_early_data(tls.ssl) && SSL_in_init(tls.ssl)) { auto nread = SSL_read(tls.ssl, buf.data(), buf.size()); @@ -736,7 +700,7 @@ int Connection::tls_handshake_simple() { return SHRPX_ERR_INPROGRESS; } } -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL // Handshake was done @@ -771,7 +735,7 @@ int Connection::write_tls_pending_handshake() { tls.wbuf.drain(nwrite); } -#ifdef OPENSSL_IS_BORINGSSL +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL if (!SSL_in_init(tls.ssl)) { // This will send a session ticket. auto nwrite = SSL_write(tls.ssl, "", 0); @@ -799,7 +763,7 @@ int Connection::write_tls_pending_handshake() { } } } -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL // We have to start read watcher, since later stage of code expects // this. @@ -830,14 +794,7 @@ int Connection::check_http2_requirement() { const unsigned char *next_proto = nullptr; unsigned int next_proto_len; -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(tls.ssl, &next_proto, &next_proto_len); -#endif // !OPENSSL_NO_NEXTPROTONEG -#if OPENSSL_VERSION_NUMBER >= 0x10002000L - if (next_proto == nullptr) { - SSL_get0_alpn_selected(tls.ssl, &next_proto, &next_proto_len); - } -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + SSL_get0_alpn_selected(tls.ssl, &next_proto, &next_proto_len); if (next_proto == nullptr || !util::check_h2_is_selected(StringRef{next_proto, next_proto_len})) { return 0; @@ -906,7 +863,7 @@ void Connection::start_tls_write_idle() { } } -ssize_t Connection::write_tls(const void *data, size_t len) { +nghttp2_ssize Connection::write_tls(const void *data, size_t len) { // SSL_write requires the same arguments (buf pointer and its // length) on SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. // get_write_limit() may return smaller length than previously @@ -932,7 +889,7 @@ ssize_t Connection::write_tls(const void *data, size_t len) { ERR_clear_error(); -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL int rv; if (SSL_is_init_finished(tls.ssl)) { rv = SSL_write(tls.ssl, data, len); @@ -944,9 +901,9 @@ ssize_t Connection::write_tls(const void *data, size_t len) { rv = nwrite; } } -#else // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#else // !NGHTTP2_GENUINE_OPENSSL auto rv = SSL_write(tls.ssl, data, len); -#endif // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#endif // !NGHTTP2_GENUINE_OPENSSL if (rv <= 0) { auto err = SSL_get_error(tls.ssl, rv); @@ -993,14 +950,14 @@ ssize_t Connection::write_tls(const void *data, size_t len) { return rv; } -ssize_t Connection::read_tls(void *data, size_t len) { +nghttp2_ssize Connection::read_tls(void *data, size_t len) { ERR_clear_error(); -#if OPENSSL_1_1_1_API +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_BORINGSSL) if (tls.earlybuf.rleft()) { return tls.earlybuf.remove(data, len); } -#endif // OPENSSL_1_1_1_API +#endif // NGHTTP2_GENUINE_OPENSSL || NGHTTP2_OPENSSL_IS_BORINGSSL // SSL_read requires the same arguments (buf pointer and its // length) on SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. @@ -1023,7 +980,7 @@ ssize_t Connection::read_tls(void *data, size_t len) { auto via_bio = tls.server_handshake && !tlsconf.session_cache.memcached.host.empty(); -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL if (!tls.early_data_finish) { // TLSv1.3 handshake is still going on. size_t nread; @@ -1067,7 +1024,7 @@ ssize_t Connection::read_tls(void *data, size_t len) { return nread; } -#endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_GENUINE_OPENSSL auto rv = SSL_read(tls.ssl, data, len); @@ -1104,7 +1061,7 @@ ssize_t Connection::read_tls(void *data, size_t len) { return rv; } -ssize_t Connection::write_clear(const void *data, size_t len) { +nghttp2_ssize Connection::write_clear(const void *data, size_t len) { len = std::min(len, wlimit.avail()); if (len == 0) { return 0; @@ -1131,7 +1088,7 @@ ssize_t Connection::write_clear(const void *data, size_t len) { return nwrite; } -ssize_t Connection::writev_clear(struct iovec *iov, int iovcnt) { +nghttp2_ssize Connection::writev_clear(struct iovec *iov, int iovcnt) { iovcnt = limit_iovec(iov, iovcnt, wlimit.avail()); if (iovcnt == 0) { return 0; @@ -1158,7 +1115,7 @@ ssize_t Connection::writev_clear(struct iovec *iov, int iovcnt) { return nwrite; } -ssize_t Connection::read_clear(void *data, size_t len) { +nghttp2_ssize Connection::read_clear(void *data, size_t len) { len = std::min(len, rlimit.avail()); if (len == 0) { return 0; @@ -1183,7 +1140,7 @@ ssize_t Connection::read_clear(void *data, size_t len) { return nread; } -ssize_t Connection::read_nolim_clear(void *data, size_t len) { +nghttp2_ssize Connection::read_nolim_clear(void *data, size_t len) { ssize_t nread; while ((nread = read(fd, data, len)) == -1 && errno == EINTR) ; @@ -1201,7 +1158,7 @@ ssize_t Connection::read_nolim_clear(void *data, size_t len) { return nread; } -ssize_t Connection::peek_clear(void *data, size_t len) { +nghttp2_ssize Connection::peek_clear(void *data, size_t len) { ssize_t nread; while ((nread = recv(fd, data, len, MSG_PEEK)) == -1 && errno == EINTR) ; diff --git a/yass/third_party/nghttp2/src/shrpx_connection.h b/yass/third_party/nghttp2/src/shrpx_connection.h index 3a458488bb..2db2588c9c 100644 --- a/yass/third_party/nghttp2/src/shrpx_connection.h +++ b/yass/third_party/nghttp2/src/shrpx_connection.h @@ -33,6 +33,8 @@ #include +#include + #ifdef ENABLE_HTTP3 # include #endif // ENABLE_HTTP3 @@ -128,8 +130,8 @@ struct Connection { // underlying connection blocks), return 0. SHRPX_ERR_EOF is // returned in case of EOF and no data was read. Otherwise // SHRPX_ERR_NETWORK is return in case of error. - ssize_t write_tls(const void *data, size_t len); - ssize_t read_tls(void *data, size_t len); + nghttp2_ssize write_tls(const void *data, size_t len); + nghttp2_ssize read_tls(void *data, size_t len); size_t get_tls_write_limit(); // Updates the number of bytes written in warm up period. @@ -138,13 +140,13 @@ struct Connection { // determine fallback to short record size mode. void start_tls_write_idle(); - ssize_t write_clear(const void *data, size_t len); - ssize_t writev_clear(struct iovec *iov, int iovcnt); - ssize_t read_clear(void *data, size_t len); + nghttp2_ssize write_clear(const void *data, size_t len); + nghttp2_ssize writev_clear(struct iovec *iov, int iovcnt); + nghttp2_ssize read_clear(void *data, size_t len); // Read at most |len| bytes of data from socket without rate limit. - ssize_t read_nolim_clear(void *data, size_t len); + nghttp2_ssize read_nolim_clear(void *data, size_t len); // Peek at most |len| bytes of data from socket without rate limit. - ssize_t peek_clear(void *data, size_t len); + nghttp2_ssize peek_clear(void *data, size_t len); void handle_tls_pending_read(); @@ -158,7 +160,7 @@ struct Connection { // Restarts read timer with timeout value |t|. void again_rt(ev_tstamp t); - // Restarts read timer without chainging timeout. + // Restarts read timer without changing timeout. void again_rt(); // Returns true if read timer expired. bool expired_rt(); @@ -192,7 +194,7 @@ struct Connection { #ifdef ENABLE_HTTP3 static_assert(std::is_standard_layout::value, - "Conneciton is not standard layout"); + "Connection is not standard layout"); #endif // ENABLE_HTTP3 // Creates BIO_method shared by all SSL objects. diff --git a/yass/third_party/nghttp2/src/shrpx_connection_handler.cc b/yass/third_party/nghttp2/src/shrpx_connection_handler.cc index be6645df46..b29ce9a56c 100644 --- a/yass/third_party/nghttp2/src/shrpx_connection_handler.cc +++ b/yass/third_party/nghttp2/src/shrpx_connection_handler.cc @@ -48,6 +48,7 @@ #include "xsi_strerror.h" #include "util.h" #include "template.h" +#include "ssl_compat.h" using namespace nghttp2; @@ -264,7 +265,7 @@ int ConnectionHandler::create_single_worker() { nb_, #endif // HAVE_NEVERBLEED tlsconf.cacert, memcachedconf.cert_file, - memcachedconf.private_key_file, nullptr); + memcachedconf.private_key_file); all_ssl_ctx_.push_back(session_cache_ssl_ctx); #ifdef ENABLE_HTTP3 quic_all_ssl_ctx_.push_back(nullptr); @@ -277,15 +278,14 @@ int ConnectionHandler::create_single_worker() { #endif // ENABLE_HTTP3 && HAVE_LIBBPF #ifdef ENABLE_HTTP3 - assert(cid_prefixes_.size() == 1); - const auto &cid_prefix = cid_prefixes_[0]; + assert(worker_ids_.size() == 1); + const auto &wid = worker_ids_[0]; #endif // ENABLE_HTTP3 single_worker_ = std::make_unique( loop_, sv_ssl_ctx, cl_ssl_ctx, session_cache_ssl_ctx, cert_tree_.get(), #ifdef ENABLE_HTTP3 - quic_sv_ssl_ctx, quic_cert_tree_.get(), cid_prefix.data(), - cid_prefix.size(), + quic_sv_ssl_ctx, quic_cert_tree_.get(), wid, # ifdef HAVE_LIBBPF /* index = */ 0, # endif // HAVE_LIBBPF @@ -366,7 +366,7 @@ int ConnectionHandler::create_worker_thread(size_t num) { nb_, # endif // HAVE_NEVERBLEED tlsconf.cacert, memcachedconf.cert_file, - memcachedconf.private_key_file, nullptr); + memcachedconf.private_key_file); all_ssl_ctx_.push_back(session_cache_ssl_ctx); # ifdef ENABLE_HTTP3 quic_all_ssl_ctx_.push_back(nullptr); @@ -375,21 +375,20 @@ int ConnectionHandler::create_worker_thread(size_t num) { } # ifdef ENABLE_HTTP3 - assert(cid_prefixes_.size() == num); + assert(worker_ids_.size() == num); # endif // ENABLE_HTTP3 for (size_t i = 0; i < num; ++i) { auto loop = ev_loop_new(config->ev_loop_flags); # ifdef ENABLE_HTTP3 - const auto &cid_prefix = cid_prefixes_[i]; + const auto &wid = worker_ids_[i]; # endif // ENABLE_HTTP3 auto worker = std::make_unique( loop, sv_ssl_ctx, cl_ssl_ctx, session_cache_ssl_ctx, cert_tree_.get(), # ifdef ENABLE_HTTP3 - quic_sv_ssl_ctx, quic_cert_tree_.get(), cid_prefix.data(), - cid_prefix.size(), + quic_sv_ssl_ctx, quic_cert_tree_.get(), wid, # ifdef HAVE_LIBBPF i, # endif // HAVE_LIBBPF @@ -543,9 +542,7 @@ int ConnectionHandler::handle_connection(int fd, sockaddr *addr, int addrlen, return 0; } -struct ev_loop *ConnectionHandler::get_loop() const { - return loop_; -} +struct ev_loop *ConnectionHandler::get_loop() const { return loop_; } Worker *ConnectionHandler::get_single_worker() const { return single_worker_.get(); @@ -740,40 +737,31 @@ void ConnectionHandler::handle_ocsp_complete() { // that case we get nullptr. auto quic_ssl_ctx = quic_all_ssl_ctx_[ocsp_.next]; if (quic_ssl_ctx) { -# ifndef OPENSSL_IS_BORINGSSL auto quic_tls_ctx_data = static_cast( SSL_CTX_get_app_data(quic_ssl_ctx)); -# ifdef HAVE_ATOMIC_STD_SHARED_PTR +# ifdef HAVE_ATOMIC_STD_SHARED_PTR std::atomic_store_explicit( &quic_tls_ctx_data->ocsp_data, std::make_shared>(ocsp_.resp), std::memory_order_release); -# else // !HAVE_ATOMIC_STD_SHARED_PTR +# else // !HAVE_ATOMIC_STD_SHARED_PTR std::lock_guard g(quic_tls_ctx_data->mu); quic_tls_ctx_data->ocsp_data = std::make_shared>(ocsp_.resp); -# endif // !HAVE_ATOMIC_STD_SHARED_PTR -# else // OPENSSL_IS_BORINGSSL - SSL_CTX_set_ocsp_response(quic_ssl_ctx, ocsp_.resp.data(), - ocsp_.resp.size()); -# endif // OPENSSL_IS_BORINGSSL +# endif // !HAVE_ATOMIC_STD_SHARED_PTR } #endif // ENABLE_HTTP3 -#ifndef OPENSSL_IS_BORINGSSL -# ifdef HAVE_ATOMIC_STD_SHARED_PTR +#ifdef HAVE_ATOMIC_STD_SHARED_PTR std::atomic_store_explicit( &tls_ctx_data->ocsp_data, std::make_shared>(std::move(ocsp_.resp)), std::memory_order_release); -# else // !HAVE_ATOMIC_STD_SHARED_PTR +#else // !HAVE_ATOMIC_STD_SHARED_PTR std::lock_guard g(tls_ctx_data->mu); tls_ctx_data->ocsp_data = std::make_shared>(std::move(ocsp_.resp)); -# endif // !HAVE_ATOMIC_STD_SHARED_PTR -#else // OPENSSL_IS_BORINGSSL - SSL_CTX_set_ocsp_response(ssl_ctx, ocsp_.resp.data(), ocsp_.resp.size()); -#endif // OPENSSL_IS_BORINGSSL +#endif // !HAVE_ATOMIC_STD_SHARED_PTR } ++ocsp_.next; @@ -936,8 +924,7 @@ SSL_CTX *ConnectionHandler::create_tls_ticket_key_memcached_ssl_ctx() { #ifdef HAVE_NEVERBLEED nb_, #endif // HAVE_NEVERBLEED - tlsconf.cacert, memcachedconf.cert_file, memcachedconf.private_key_file, - nullptr); + tlsconf.cacert, memcachedconf.cert_file, memcachedconf.private_key_file); all_ssl_ctx_.push_back(ssl_ctx); #ifdef ENABLE_HTTP3 @@ -1019,27 +1006,23 @@ void ConnectionHandler::set_enable_acceptor_on_ocsp_completion(bool f) { #ifdef ENABLE_HTTP3 int ConnectionHandler::forward_quic_packet( const UpstreamAddr *faddr, const Address &remote_addr, - const Address &local_addr, const ngtcp2_pkt_info &pi, - const uint8_t *cid_prefix, const uint8_t *data, size_t datalen) { + const Address &local_addr, const ngtcp2_pkt_info &pi, const WorkerID &wid, + const uint8_t *data, size_t datalen) { assert(!get_config()->single_thread); - for (auto &worker : workers_) { - if (!std::equal(cid_prefix, cid_prefix + SHRPX_QUIC_CID_PREFIXLEN, - worker->get_cid_prefix())) { - continue; - } - - WorkerEvent wev{}; - wev.type = WorkerEventType::QUIC_PKT_FORWARD; - wev.quic_pkt = std::make_unique(faddr->index, remote_addr, - local_addr, pi, data, datalen); - - worker->send(std::move(wev)); - - return 0; + auto worker = find_worker(wid); + if (worker == nullptr) { + return -1; } - return -1; + WorkerEvent wev{}; + wev.type = WorkerEventType::QUIC_PKT_FORWARD; + wev.quic_pkt = std::make_unique(faddr->index, remote_addr, + local_addr, pi, data, datalen); + + worker->send(std::move(wev)); + + return 0; } void ConnectionHandler::set_quic_keying_materials( @@ -1052,22 +1035,40 @@ ConnectionHandler::get_quic_keying_materials() const { return quic_keying_materials_; } -void ConnectionHandler::set_cid_prefixes( - const std::vector> - &cid_prefixes) { - cid_prefixes_ = cid_prefixes; +void ConnectionHandler::set_worker_ids(std::vector worker_ids) { + worker_ids_ = std::move(worker_ids); +} + +namespace { +ssize_t find_worker_index(const std::vector &worker_ids, + const WorkerID &wid) { + assert(!worker_ids.empty()); + + if (wid.server != worker_ids[0].server || + wid.worker_process != worker_ids[0].worker_process || + wid.thread >= worker_ids.size()) { + return -1; + } + + return wid.thread; +} +} // namespace + +Worker *ConnectionHandler::find_worker(const WorkerID &wid) const { + auto idx = find_worker_index(worker_ids_, wid); + if (idx == -1) { + return nullptr; + } + + return workers_[idx].get(); } QUICLingeringWorkerProcess * -ConnectionHandler::match_quic_lingering_worker_process_cid_prefix( - const uint8_t *dcid, size_t dcidlen) { - assert(dcidlen >= SHRPX_QUIC_CID_PREFIXLEN); - +ConnectionHandler::match_quic_lingering_worker_process_worker_id( + const WorkerID &wid) { for (auto &lwps : quic_lingering_worker_processes_) { - for (auto &cid_prefix : lwps.cid_prefixes) { - if (std::equal(std::begin(cid_prefix), std::end(cid_prefix), dcid)) { - return &lwps; - } + if (find_worker_index(lwps.worker_ids, wid) != -1) { + return &lwps; } } @@ -1286,33 +1287,29 @@ int ConnectionHandler::quic_ipc_read() { auto &qkm = quic_keying_materials_->keying_materials.front(); - std::array decrypted_dcid; + ConnectionID decrypted_dcid; - if (decrypt_quic_connection_id(decrypted_dcid.data(), - vc.dcid + SHRPX_QUIC_CID_PREFIX_OFFSET, - qkm.cid_encryption_key.data()) != 0) { + if (decrypt_quic_connection_id(decrypted_dcid, + vc.dcid + SHRPX_QUIC_CID_WORKER_ID_OFFSET, + qkm.cid_decryption_ctx) != 0) { return -1; } - for (auto &worker : workers_) { - if (!std::equal(std::begin(decrypted_dcid), - std::begin(decrypted_dcid) + SHRPX_QUIC_CID_PREFIXLEN, - worker->get_cid_prefix())) { - continue; + auto worker = find_worker(decrypted_dcid.worker); + if (worker == nullptr) { + if (LOG_ENABLED(INFO)) { + LOG(INFO) << "No worker to match Worker ID"; } - WorkerEvent wev{ - .type = WorkerEventType::QUIC_PKT_FORWARD, - .quic_pkt = std::move(pkt), - }; - worker->send(std::move(wev)); - return 0; } - if (LOG_ENABLED(INFO)) { - LOG(INFO) << "No worker to match CID prefix"; - } + WorkerEvent wev{ + .type = WorkerEventType::QUIC_PKT_FORWARD, + .quic_pkt = std::move(pkt), + }; + + worker->send(std::move(wev)); return 0; } diff --git a/yass/third_party/nghttp2/src/shrpx_connection_handler.h b/yass/third_party/nghttp2/src/shrpx_connection_handler.h index f3748ab678..47ec209aec 100644 --- a/yass/third_party/nghttp2/src/shrpx_connection_handler.h +++ b/yass/third_party/nghttp2/src/shrpx_connection_handler.h @@ -108,7 +108,7 @@ struct SerialEvent { struct BPFRef { bpf_object *obj; bpf_map *reuseport_array; - bpf_map *cid_prefix_map; + bpf_map *worker_id_map; }; # endif // HAVE_LIBBPF @@ -121,12 +121,10 @@ enum class QUICIPCType { // WorkerProcesses which are in graceful shutdown period. struct QUICLingeringWorkerProcess { - QUICLingeringWorkerProcess( - std::vector> cid_prefixes, - int quic_ipc_fd) - : cid_prefixes{std::move(cid_prefixes)}, quic_ipc_fd{quic_ipc_fd} {} + QUICLingeringWorkerProcess(std::vector worker_ids, int quic_ipc_fd) + : worker_ids{std::move(worker_ids)}, quic_ipc_fd{quic_ipc_fd} {} - std::vector> cid_prefixes; + std::vector worker_ids; // Socket to send QUIC IPC message to this worker process. int quic_ipc_fd; }; @@ -197,25 +195,23 @@ public: int forward_quic_packet(const UpstreamAddr *faddr, const Address &remote_addr, const Address &local_addr, const ngtcp2_pkt_info &pi, - const uint8_t *cid_prefix, const uint8_t *data, + const WorkerID &wid, const uint8_t *data, size_t datalen); void set_quic_keying_materials(std::shared_ptr qkms); const std::shared_ptr &get_quic_keying_materials() const; - void set_cid_prefixes( - const std::vector> - &cid_prefixes); + void set_worker_ids(std::vector worker_ids); + Worker *find_worker(const WorkerID &wid) const; void set_quic_lingering_worker_processes( const std::vector &quic_lwps); - // Return matching QUICLingeringWorkerProcess which has a CID prefix + // Return matching QUICLingeringWorkerProcess which has a Worker ID // such that |dcid| starts with it. If no such // QUICLingeringWorkerProcess, it returns nullptr. QUICLingeringWorkerProcess * - match_quic_lingering_worker_process_cid_prefix(const uint8_t *dcid, - size_t dcidlen); + match_quic_lingering_worker_process_worker_id(const WorkerID &wid); int forward_quic_packet_to_lingering_worker_process( QUICLingeringWorkerProcess *quic_lwp, const Address &remote_addr, @@ -260,9 +256,8 @@ private: // and signature algorithm presented by client. std::vector> indexed_ssl_ctx_; #ifdef ENABLE_HTTP3 - std::vector> cid_prefixes_; - std::vector> - lingering_cid_prefixes_; + std::vector worker_ids_; + std::vector lingering_worker_ids_; int quic_ipc_fd_; std::vector quic_lingering_worker_processes_; # ifdef HAVE_LIBBPF diff --git a/yass/third_party/nghttp2/src/shrpx_dns_resolver.cc b/yass/third_party/nghttp2/src/shrpx_dns_resolver.cc index f83ecb786a..8253942691 100644 --- a/yass/third_party/nghttp2/src/shrpx_dns_resolver.cc +++ b/yass/third_party/nghttp2/src/shrpx_dns_resolver.cc @@ -55,9 +55,11 @@ void sock_state_cb(void *data, int s, int read, int write) { } // namespace namespace { -void host_cb(void *arg, int status, int timeouts, hostent *hostent) { +void addrinfo_cb(void *arg, int status, int timeouts, ares_addrinfo *result) { auto resolv = static_cast(arg); - resolv->on_result(status, hostent); + resolv->on_result(status, result); + + ares_freeaddrinfo(result); } } // namespace @@ -173,7 +175,10 @@ int DNSResolver::resolve(const StringRef &name, int family) { channel_ = chan; status_ = DNSResolverStatus::RUNNING; - ares_gethostbyname(channel_, name_.c_str(), family_, host_cb, this); + ares_addrinfo_hints hints{}; + hints.ai_family = family_; + + ares_getaddrinfo(channel_, name_.c_str(), nullptr, &hints, addrinfo_cb, this); reset_timeout(); return 0; @@ -285,7 +290,7 @@ void DNSResolver::start_wev(int fd) { void DNSResolver::stop_wev(int fd) { stop_ev(wevs_, loop_, fd, EV_WRITE); } -void DNSResolver::on_result(int status, hostent *hostent) { +void DNSResolver::on_result(int status, ares_addrinfo *ai) { stop_ev(loop_, revs_); stop_ev(loop_, wevs_); ev_timer_stop(loop_, &timer_); @@ -299,40 +304,44 @@ void DNSResolver::on_result(int status, hostent *hostent) { return; } - auto ap = *hostent->h_addr_list; + auto ap = ai->nodes; + + for (; ap; ap = ap->ai_next) { + switch (ap->ai_family) { + case AF_INET: + status_ = DNSResolverStatus::OK; + result_.len = sizeof(result_.su.in); + + assert(sizeof(result_.su.in) == ap->ai_addrlen); + + memcpy(&result_.su.in, ap->ai_addr, sizeof(result_.su.in)); + + break; + case AF_INET6: + status_ = DNSResolverStatus::OK; + result_.len = sizeof(result_.su.in6); + + assert(sizeof(result_.su.in6) == ap->ai_addrlen); + + memcpy(&result_.su.in6, ap->ai_addr, sizeof(result_.su.in6)); + + break; + default: + continue; + } + + break; + } + if (!ap) { if (LOG_ENABLED(INFO)) { - LOG(INFO) << "Name lookup for " << name_ << "failed: no address returned"; + LOG(INFO) << "Name lookup for " << name_ + << " failed: no address returned"; } status_ = DNSResolverStatus::ERROR; return; } - switch (hostent->h_addrtype) { - case AF_INET: - status_ = DNSResolverStatus::OK; - result_.len = sizeof(result_.su.in); - result_.su.in = {}; - result_.su.in.sin_family = AF_INET; -#ifdef HAVE_SOCKADDR_IN_SIN_LEN - result_.su.in.sin_len = sizeof(result_.su.in); -#endif // HAVE_SOCKADDR_IN_SIN_LEN - memcpy(&result_.su.in.sin_addr, ap, sizeof(result_.su.in.sin_addr)); - break; - case AF_INET6: - status_ = DNSResolverStatus::OK; - result_.len = sizeof(result_.su.in6); - result_.su.in6 = {}; - result_.su.in6.sin6_family = AF_INET6; -#ifdef HAVE_SOCKADDR_IN6_SIN6_LEN - result_.su.in6.sin6_len = sizeof(result_.su.in6); -#endif // HAVE_SOCKADDR_IN6_SIN6_LEN - memcpy(&result_.su.in6.sin6_addr, ap, sizeof(result_.su.in6.sin6_addr)); - break; - default: - assert(0); - } - if (status_ == DNSResolverStatus::OK) { if (LOG_ENABLED(INFO)) { LOG(INFO) << "Name lookup succeeded: " << name_ << " -> " diff --git a/yass/third_party/nghttp2/src/shrpx_dns_resolver.h b/yass/third_party/nghttp2/src/shrpx_dns_resolver.h index e622f99625..4d68273da6 100644 --- a/yass/third_party/nghttp2/src/shrpx_dns_resolver.h +++ b/yass/third_party/nghttp2/src/shrpx_dns_resolver.h @@ -88,7 +88,7 @@ public: int on_write(int fd); int on_timeout(); // Calls this function when DNS query finished. - void on_result(int status, hostent *hostent); + void on_result(int status, ares_addrinfo *result); void reset_timeout(); void start_rev(int fd); diff --git a/yass/third_party/nghttp2/src/shrpx_downstream.cc b/yass/third_party/nghttp2/src/shrpx_downstream.cc index 9ea52b4ac0..5fd717e9e2 100644 --- a/yass/third_party/nghttp2/src/shrpx_downstream.cc +++ b/yass/third_party/nghttp2/src/shrpx_downstream.cc @@ -45,6 +45,23 @@ namespace shrpx { +namespace { +void header_timeoutcb(struct ev_loop *loop, ev_timer *w, int revents) { + auto downstream = static_cast(w->data); + auto upstream = downstream->get_upstream(); + + if (LOG_ENABLED(INFO)) { + DLOG(INFO, downstream) << "request header timeout stream_id=" + << downstream->get_stream_id(); + } + + downstream->disable_upstream_rtimer(); + downstream->disable_upstream_wtimer(); + + upstream->on_timeout(downstream); +} +} // namespace + namespace { void upstream_timeoutcb(struct ev_loop *loop, ev_timer *w, int revents) { auto downstream = static_cast(w->data); @@ -148,7 +165,12 @@ Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool, expect_100_continue_(false), stop_reading_(false) { - auto &timeoutconf = get_config()->http2.timeout; + auto config = get_config(); + auto &httpconf = config->http; + + ev_timer_init(&header_timer_, header_timeoutcb, 0., httpconf.timeout.header); + + auto &timeoutconf = config->http2.timeout; ev_timer_init(&upstream_rtimer_, &upstream_rtimeoutcb, 0., timeoutconf.stream_read); @@ -159,6 +181,7 @@ Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool, ev_timer_init(&downstream_wtimer_, &downstream_wtimeoutcb, 0., timeoutconf.stream_write); + header_timer_.data = this; upstream_rtimer_.data = this; upstream_wtimer_.data = this; downstream_rtimer_.data = this; @@ -183,6 +206,7 @@ Downstream::~Downstream() { ev_timer_stop(loop, &upstream_wtimer_); ev_timer_stop(loop, &downstream_rtimer_); ev_timer_stop(loop, &downstream_wtimer_); + ev_timer_stop(loop, &header_timer_); #ifdef HAVE_MRUBY auto handler = upstream_->get_client_handler(); @@ -946,6 +970,18 @@ bool Downstream::expect_response_trailer() const { (resp_.http_major == 3 || resp_.http_major == 2); } +void Downstream::repeat_header_timer() { + auto loop = upstream_->get_client_handler()->get_loop(); + + ev_timer_again(loop, &header_timer_); +} + +void Downstream::stop_header_timer() { + auto loop = upstream_->get_client_handler()->get_loop(); + + ev_timer_stop(loop, &header_timer_); +} + namespace { void reset_timer(struct ev_loop *loop, ev_timer *w) { ev_timer_again(loop, w); } } // namespace diff --git a/yass/third_party/nghttp2/src/shrpx_downstream.h b/yass/third_party/nghttp2/src/shrpx_downstream.h index 146cae583b..15f3a472dc 100644 --- a/yass/third_party/nghttp2/src/shrpx_downstream.h +++ b/yass/third_party/nghttp2/src/shrpx_downstream.h @@ -448,6 +448,9 @@ public: // connection. int on_read(); + void repeat_header_timer(); + void stop_header_timer(); + // Resets upstream read timer. If it is active, timeout value is // reset. If it is not active, timer will be started. void reset_upstream_rtimer(); @@ -562,6 +565,8 @@ private: // if frontend uses RFC 8441 WebSocket bootstrapping via HTTP/2. StringRef ws_key_; + ev_timer header_timer_; + ev_timer upstream_rtimer_; ev_timer upstream_wtimer_; diff --git a/yass/third_party/nghttp2/src/shrpx_downstream_test.cc b/yass/third_party/nghttp2/src/shrpx_downstream_test.cc index 6100b18050..46db9b7e27 100644 --- a/yass/third_party/nghttp2/src/shrpx_downstream_test.cc +++ b/yass/third_party/nghttp2/src/shrpx_downstream_test.cc @@ -26,12 +26,29 @@ #include -#include +#include "munitxx.h" #include "shrpx_downstream.h" namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_downstream_field_store_append_last_header), + munit_void_test(test_downstream_field_store_header), + munit_void_test(test_downstream_crumble_request_cookie), + munit_void_test(test_downstream_assemble_request_cookie), + munit_void_test(test_downstream_rewrite_location_response_header), + munit_void_test(test_downstream_supports_non_final_response), + munit_void_test(test_downstream_find_affinity_cookie), + munit_test_end(), +}; +} // namespace + +const MunitSuite downstream_suite{ + "/downstream", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_downstream_field_store_append_last_header(void) { BlockAllocator balloc(16, 16); FieldStore fs(balloc, 0); @@ -57,7 +74,7 @@ void test_downstream_field_store_append_last_header(void) { HeaderRefs{{StringRef::from_lit("alphabravogolf0123456789"), StringRef::from_lit("CharliedeltAecho0123456789")}, {StringRef::from_lit("echo"), StringRef::from_lit("foxtrot")}}; - CU_ASSERT(ans == fs.headers()); + assert_true(ans == fs.headers()); } void test_downstream_field_store_header(void) { @@ -72,14 +89,14 @@ void test_downstream_field_store_header(void) { http2::HD_CONTENT_LENGTH); // By token - CU_ASSERT(HeaderRef(StringRef{":authority"}, StringRef{"1"}) == - *fs.header(http2::HD__AUTHORITY)); - CU_ASSERT(nullptr == fs.header(http2::HD__METHOD)); + assert_true(HeaderRef(StringRef{":authority"}, StringRef{"1"}) == + *fs.header(http2::HD__AUTHORITY)); + assert_null(fs.header(http2::HD__METHOD)); // By name - CU_ASSERT(HeaderRef(StringRef{"alpha"}, StringRef{"0"}) == - *fs.header(StringRef::from_lit("alpha"))); - CU_ASSERT(nullptr == fs.header(StringRef::from_lit("bravo"))); + assert_true(HeaderRef(StringRef{"alpha"}, StringRef{"0"}) == + *fs.header(StringRef::from_lit("alpha"))); + assert_null(fs.header(StringRef::from_lit("bravo"))); } void test_downstream_crumble_request_cookie(void) { @@ -103,8 +120,8 @@ void test_downstream_crumble_request_cookie(void) { auto num_cookies = d.count_crumble_request_cookie(); - CU_ASSERT(5 == nva.size()); - CU_ASSERT(5 == num_cookies); + assert_size(5, ==, nva.size()); + assert_size(5, ==, num_cookies); HeaderRefs cookies; std::transform(std::begin(nva), std::end(nva), std::back_inserter(cookies), @@ -121,10 +138,10 @@ void test_downstream_crumble_request_cookie(void) { {StringRef::from_lit("cookie"), StringRef::from_lit("delta")}, {StringRef::from_lit("cookie"), StringRef::from_lit("echo")}}; - CU_ASSERT(ans == cookies); - CU_ASSERT(cookies[0].no_index); - CU_ASSERT(cookies[1].no_index); - CU_ASSERT(cookies[2].no_index); + assert_true(ans == cookies); + assert_true(cookies[0].no_index); + assert_true(cookies[1].no_index); + assert_true(cookies[2].no_index); } void test_downstream_assemble_request_cookie(void) { @@ -147,7 +164,8 @@ void test_downstream_assemble_request_cookie(void) { req.fs.add_header_token(StringRef::from_lit("cookie"), StringRef::from_lit("delta;;"), false, http2::HD_COOKIE); - CU_ASSERT("alpha; bravo; charlie; delta" == d.assemble_request_cookie()); + assert_stdstring_equal("alpha; bravo; charlie; delta", + d.assemble_request_cookie().str()); } void test_downstream_rewrite_location_response_header(void) { @@ -161,7 +179,7 @@ void test_downstream_rewrite_location_response_header(void) { false, http2::HD_LOCATION); d.rewrite_location_response_header(StringRef::from_lit("https")); auto location = resp.fs.header(http2::HD_LOCATION); - CU_ASSERT("https://localhost:8443/" == (*location).value); + assert_stdstring_equal("https://localhost:8443/", (*location).value.str()); } void test_downstream_supports_non_final_response(void) { @@ -171,27 +189,27 @@ void test_downstream_supports_non_final_response(void) { req.http_major = 3; req.http_minor = 0; - CU_ASSERT(d.supports_non_final_response()); + assert_true(d.supports_non_final_response()); req.http_major = 2; req.http_minor = 0; - CU_ASSERT(d.supports_non_final_response()); + assert_true(d.supports_non_final_response()); req.http_major = 1; req.http_minor = 1; - CU_ASSERT(d.supports_non_final_response()); + assert_true(d.supports_non_final_response()); req.http_major = 1; req.http_minor = 0; - CU_ASSERT(!d.supports_non_final_response()); + assert_false(d.supports_non_final_response()); req.http_major = 0; req.http_minor = 9; - CU_ASSERT(!d.supports_non_final_response()); + assert_false(d.supports_non_final_response()); } void test_downstream_find_affinity_cookie(void) { @@ -217,15 +235,15 @@ void test_downstream_find_affinity_cookie(void) { aff = d.find_affinity_cookie(StringRef::from_lit("lb")); - CU_ASSERT(0xdeadbeef == aff); + assert_uint32(0xdeadbeef, ==, aff); aff = d.find_affinity_cookie(StringRef::from_lit("LB")); - CU_ASSERT(0xf1f2f3f4 == aff); + assert_uint32(0xf1f2f3f4, ==, aff); aff = d.find_affinity_cookie(StringRef::from_lit("short")); - CU_ASSERT(0 == aff); + assert_uint32(0, ==, aff); } } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_downstream_test.h b/yass/third_party/nghttp2/src/shrpx_downstream_test.h index ef06ea301a..07adbca879 100644 --- a/yass/third_party/nghttp2/src/shrpx_downstream_test.h +++ b/yass/third_party/nghttp2/src/shrpx_downstream_test.h @@ -29,15 +29,21 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_downstream_field_store_append_last_header(void); -void test_downstream_field_store_header(void); -void test_downstream_crumble_request_cookie(void); -void test_downstream_assemble_request_cookie(void); -void test_downstream_rewrite_location_response_header(void); -void test_downstream_supports_non_final_response(void); -void test_downstream_find_affinity_cookie(void); +extern const MunitSuite downstream_suite; + +munit_void_test_decl(test_downstream_field_store_append_last_header); +munit_void_test_decl(test_downstream_field_store_header); +munit_void_test_decl(test_downstream_crumble_request_cookie); +munit_void_test_decl(test_downstream_assemble_request_cookie); +munit_void_test_decl(test_downstream_rewrite_location_response_header); +munit_void_test_decl(test_downstream_supports_non_final_response); +munit_void_test_decl(test_downstream_find_affinity_cookie); } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_http.cc b/yass/third_party/nghttp2/src/shrpx_http.cc index ad32dc9e19..475050093f 100644 --- a/yass/third_party/nghttp2/src/shrpx_http.cc +++ b/yass/third_party/nghttp2/src/shrpx_http.cc @@ -167,9 +167,9 @@ std::string colorizeHeaders(const char *hdrs) { return nhdrs; } -ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, size_t max_payload, - void *user_data) { +nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payload, void *user_data) { return std::min(max_payload, frame->hd.length + get_config()->padding); } diff --git a/yass/third_party/nghttp2/src/shrpx_http.h b/yass/third_party/nghttp2/src/shrpx_http.h index 18935d8279..774686c61d 100644 --- a/yass/third_party/nghttp2/src/shrpx_http.h +++ b/yass/third_party/nghttp2/src/shrpx_http.h @@ -63,9 +63,9 @@ StringRef create_forwarded(BlockAllocator &balloc, int params, // Adds ANSI color codes to HTTP headers |hdrs|. std::string colorizeHeaders(const char *hdrs); -ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, size_t max_payload, - void *user_data); +nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payload, void *user_data); // Creates set-cookie-string for cookie based affinity. If |path| is // not empty, "; " is added. If |secure| is true, "; Secure" is diff --git a/yass/third_party/nghttp2/src/shrpx_http2_downstream_connection.cc b/yass/third_party/nghttp2/src/shrpx_http2_downstream_connection.cc index d27dcc114d..a6c9d53aee 100644 --- a/yass/third_party/nghttp2/src/shrpx_http2_downstream_connection.cc +++ b/yass/third_party/nghttp2/src/shrpx_http2_downstream_connection.cc @@ -162,10 +162,11 @@ int Http2DownstreamConnection::submit_rst_stream(Downstream *downstream, } namespace { -ssize_t http2_data_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, - uint32_t *data_flags, - nghttp2_data_source *source, void *user_data) { +nghttp2_ssize http2_data_read_callback(nghttp2_session *session, + int32_t stream_id, uint8_t *buf, + size_t length, uint32_t *data_flags, + nghttp2_data_source *source, + void *user_data) { int rv; auto sd = static_cast( nghttp2_session_get_stream_user_data(session, stream_id)); @@ -349,13 +350,13 @@ int Http2DownstreamConnection::push_request_headers() { auto upstream = downstream_->get_upstream(); auto handler = upstream->get_client_handler(); -#if OPENSSL_1_1_1_API +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_BORINGSSL) auto conn = handler->get_connection(); if (conn->tls.ssl && !SSL_is_init_finished(conn->tls.ssl)) { nva.push_back(http2::make_nv_ll("early-data", "1")); } -#endif // OPENSSL_1_1_1_API +#endif // NGHTTP2_GENUINE_OPENSSL || NGHTTP2_OPENSSL_IS_BORINGSSL auto fwd = fwdconf.strip_incoming ? nullptr : req.fs.header(http2::HD_FORWARDED); @@ -476,8 +477,8 @@ int Http2DownstreamConnection::push_request_headers() { auto transfer_encoding = req.fs.header(http2::HD_TRANSFER_ENCODING); - nghttp2_data_provider *data_prdptr = nullptr; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 *data_prdptr = nullptr; + nghttp2_data_provider2 data_prd; // Add body as long as transfer-encoding is given even if // req.fs.content_length == 0 to forward trailer fields. diff --git a/yass/third_party/nghttp2/src/shrpx_http2_session.cc b/yass/third_party/nghttp2/src/shrpx_http2_session.cc index 1700994f1d..dccdae4b50 100644 --- a/yass/third_party/nghttp2/src/shrpx_http2_session.cc +++ b/yass/third_party/nghttp2/src/shrpx_http2_session.cc @@ -755,15 +755,15 @@ void Http2Session::remove_stream_data(StreamData *sd) { int Http2Session::submit_request(Http2DownstreamConnection *dconn, const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd) { + const nghttp2_data_provider2 *data_prd) { assert(state_ == Http2SessionState::CONNECTED); auto sd = std::make_unique(); sd->dlnext = sd->dlprev = nullptr; // TODO Specify nullptr to pri_spec for now - auto stream_id = - nghttp2_submit_request(session_, nullptr, nva, nvlen, data_prd, sd.get()); + auto stream_id = nghttp2_submit_request2(session_, nullptr, nva, nvlen, + data_prd, sd.get()); if (stream_id < 0) { - SSLOG(FATAL, this) << "nghttp2_submit_request() failed: " + SSLOG(FATAL, this) << "nghttp2_submit_request2() failed: " << nghttp2_strerror(stream_id); return -1; } @@ -1653,7 +1653,7 @@ nghttp2_session_callbacks *create_http2_downstream_callbacks() { send_data_callback); if (get_config()->padding) { - nghttp2_session_callbacks_set_select_padding_callback( + nghttp2_session_callbacks_set_select_padding_callback2( callbacks, http::select_padding_callback); } @@ -1672,14 +1672,7 @@ int Http2Session::connection_made() { const unsigned char *next_proto = nullptr; unsigned int next_proto_len = 0; -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(conn_.tls.ssl, &next_proto, &next_proto_len); -#endif // !OPENSSL_NO_NEXTPROTONEG -#if OPENSSL_VERSION_NUMBER >= 0x10002000L - if (!next_proto) { - SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len); - } -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len); if (!next_proto) { downstream_failure(addr_, raddr_); @@ -1761,11 +1754,9 @@ int Http2Session::on_read(const uint8_t *data, size_t datalen) { int Http2Session::on_write() { return on_write_(*this); } int Http2Session::downstream_read(const uint8_t *data, size_t datalen) { - ssize_t rv; - - rv = nghttp2_session_mem_recv(session_, data, datalen); + auto rv = nghttp2_session_mem_recv2(session_, data, datalen); if (rv < 0) { - SSLOG(ERROR, this) << "nghttp2_session_mem_recv() returned error: " + SSLOG(ERROR, this) << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv); return -1; } @@ -1785,9 +1776,9 @@ int Http2Session::downstream_read(const uint8_t *data, size_t datalen) { int Http2Session::downstream_write() { for (;;) { const uint8_t *data; - auto datalen = nghttp2_session_mem_send(session_, &data); + auto datalen = nghttp2_session_mem_send2(session_, &data); if (datalen < 0) { - SSLOG(ERROR, this) << "nghttp2_session_mem_send() returned error: " + SSLOG(ERROR, this) << "nghttp2_session_mem_send2() returned error: " << nghttp2_strerror(datalen); return -1; } @@ -1834,9 +1825,7 @@ void Http2Session::signal_write() { } } -struct ev_loop *Http2Session::get_loop() const { - return conn_.loop; -} +struct ev_loop *Http2Session::get_loop() const { return conn_.loop; } ev_io *Http2Session::get_wev() { return &conn_.wev; } diff --git a/yass/third_party/nghttp2/src/shrpx_http2_session.h b/yass/third_party/nghttp2/src/shrpx_http2_session.h index 31b25458bf..1a67a5f709 100644 --- a/yass/third_party/nghttp2/src/shrpx_http2_session.h +++ b/yass/third_party/nghttp2/src/shrpx_http2_session.h @@ -116,7 +116,7 @@ public: void remove_stream_data(StreamData *sd); int submit_request(Http2DownstreamConnection *dconn, const nghttp2_nv *nva, - size_t nvlen, const nghttp2_data_provider *data_prd); + size_t nvlen, const nghttp2_data_provider2 *data_prd); int submit_rst_stream(int32_t stream_id, uint32_t error_code); diff --git a/yass/third_party/nghttp2/src/shrpx_http2_upstream.cc b/yass/third_party/nghttp2/src/shrpx_http2_upstream.cc index 9892bad848..7816f5f0cc 100644 --- a/yass/third_party/nghttp2/src/shrpx_http2_upstream.cc +++ b/yass/third_party/nghttp2/src/shrpx_http2_upstream.cc @@ -285,7 +285,10 @@ void Http2Upstream::on_start_request(const nghttp2_frame *frame) { downstream->reset_upstream_rtimer(); - handler_->repeat_read_timer(); + auto config = get_config(); + auto &httpconf = config->http; + + handler_->reset_upstream_read_timeout(httpconf.timeout.header); auto &req = downstream->request(); @@ -298,8 +301,6 @@ void Http2Upstream::on_start_request(const nghttp2_frame *frame) { ++num_requests_; - auto config = get_config(); - auto &httpconf = config->http; if (httpconf.max_requests <= num_requests_) { start_graceful_shutdown(); } @@ -717,7 +718,7 @@ int on_frame_send_callback(nghttp2_session *session, const nghttp2_frame *frame, upstream, handler->get_mcpool(), promised_stream_id); auto &req = promised_downstream->request(); - // As long as we use nghttp2_session_mem_send(), setting stream + // As long as we use nghttp2_session_mem_send2(), setting stream // user data here should not fail. This is because this callback // is called just after frame was serialized. So no worries about // hanging Downstream. @@ -995,7 +996,7 @@ nghttp2_session_callbacks *create_http2_upstream_callbacks() { auto config = get_config(); if (config->padding) { - nghttp2_session_callbacks_set_select_padding_callback( + nghttp2_session_callbacks_set_select_padding_callback2( callbacks, http::select_padding_callback); } @@ -1132,7 +1133,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler) #endif // defined(TCP_INFO) && defined(TCP_NOTSENT_LOWAT) handler_->reset_upstream_read_timeout( - config->conn.upstream.timeout.http2_read); + config->conn.upstream.timeout.http2_idle); handler_->signal_write(); } @@ -1145,21 +1146,20 @@ Http2Upstream::~Http2Upstream() { } int Http2Upstream::on_read() { - ssize_t rv = 0; auto rb = handler_->get_rb(); auto rlimit = handler_->get_rlimit(); if (rb->rleft()) { - rv = nghttp2_session_mem_recv(session_, rb->pos(), rb->rleft()); + auto rv = nghttp2_session_mem_recv2(session_, rb->pos(), rb->rleft()); if (rv < 0) { if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { - ULOG(ERROR, this) << "nghttp2_session_mem_recv() returned error: " + ULOG(ERROR, this) << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv); } return -1; } - // nghttp2_session_mem_recv should consume all input bytes on + // nghttp2_session_mem_recv2 should consume all input bytes on // success. assert(static_cast(rv) == rb->rleft()); rb->reset(); @@ -1221,10 +1221,10 @@ int Http2Upstream::on_write() { } const uint8_t *data; - auto datalen = nghttp2_session_mem_send(session_, &data); + auto datalen = nghttp2_session_mem_send2(session_, &data); if (datalen < 0) { - ULOG(ERROR, this) << "nghttp2_session_mem_send() returned error: " + ULOG(ERROR, this) << "nghttp2_session_mem_send2() returned error: " << nghttp2_strerror(datalen); return -1; } @@ -1436,11 +1436,11 @@ int Http2Upstream::terminate_session(uint32_t error_code) { } namespace { -ssize_t downstream_data_read_callback(nghttp2_session *session, - int32_t stream_id, uint8_t *buf, - size_t length, uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) { +nghttp2_ssize downstream_data_read_callback(nghttp2_session *session, + int32_t stream_id, uint8_t *buf, + size_t length, uint32_t *data_flags, + nghttp2_data_source *source, + void *user_data) { int rv; auto downstream = static_cast(source->ptr); auto body = downstream->get_response_buf(); @@ -1508,7 +1508,7 @@ int Http2Upstream::send_reply(Downstream *downstream, const uint8_t *body, size_t bodylen) { int rv; - nghttp2_data_provider data_prd, *data_prd_ptr = nullptr; + nghttp2_data_provider2 data_prd, *data_prd_ptr = nullptr; if (bodylen) { data_prd.source.ptr = downstream; @@ -1555,10 +1555,10 @@ int Http2Upstream::send_reply(Downstream *downstream, const uint8_t *body, nva.push_back(http2::make_nv_nocopy(p.name, p.value)); } - rv = nghttp2_submit_response(session_, downstream->get_stream_id(), - nva.data(), nva.size(), data_prd_ptr); + rv = nghttp2_submit_response2(session_, downstream->get_stream_id(), + nva.data(), nva.size(), data_prd_ptr); if (nghttp2_is_fatal(rv)) { - ULOG(FATAL, this) << "nghttp2_submit_response() failed: " + ULOG(FATAL, this) << "nghttp2_submit_response2() failed: " << nghttp2_strerror(rv); return -1; } @@ -1589,7 +1589,7 @@ int Http2Upstream::error_reply(Downstream *downstream, body->append(html); downstream->set_response_state(DownstreamState::MSG_COMPLETE); - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.ptr = downstream; data_prd.read_callback = downstream_data_read_callback; @@ -1607,10 +1607,10 @@ int Http2Upstream::error_reply(Downstream *downstream, http2::make_nv_ls_nocopy("content-length", content_length), http2::make_nv_ls_nocopy("date", date)}}; - rv = nghttp2_submit_response(session_, downstream->get_stream_id(), - nva.data(), nva.size(), &data_prd); + rv = nghttp2_submit_response2(session_, downstream->get_stream_id(), + nva.data(), nva.size(), &data_prd); if (rv < NGHTTP2_ERR_FATAL) { - ULOG(FATAL, this) << "nghttp2_submit_response() failed: " + ULOG(FATAL, this) << "nghttp2_submit_response2() failed: " << nghttp2_strerror(rv); return -1; } @@ -1641,7 +1641,10 @@ void Http2Upstream::remove_downstream(Downstream *downstream) { if (downstream_queue_.get_downstreams() == nullptr) { // There is no downstream at the moment. Start idle timer now. - handler_->repeat_read_timer(); + auto config = get_config(); + auto &upstreamconf = config->conn.upstream; + + handler_->reset_upstream_read_timeout(upstreamconf.timeout.http2_idle); } } @@ -1858,11 +1861,29 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) { nva.size()); } - nghttp2_data_provider data_prd; + auto priority = resp.fs.header(http2::HD_PRIORITY); + if (priority) { + nghttp2_extpri extpri; + + if (nghttp2_session_get_extpri_stream_priority( + session_, &extpri, downstream->get_stream_id()) == 0 && + nghttp2_extpri_parse_priority(&extpri, priority->value.byte(), + priority->value.size()) == 0) { + rv = nghttp2_session_change_extpri_stream_priority( + session_, downstream->get_stream_id(), &extpri, + /* ignore_client_signal = */ 1); + if (rv != 0) { + ULOG(ERROR, this) << "nghttp2_session_change_extpri_stream_priority: " + << nghttp2_strerror(rv); + } + } + } + + nghttp2_data_provider2 data_prd; data_prd.source.ptr = downstream; data_prd.read_callback = downstream_data_read_callback; - nghttp2_data_provider *data_prdptr; + nghttp2_data_provider2 *data_prdptr; if (downstream->expect_response_body() || downstream->expect_response_trailer()) { @@ -1871,10 +1892,10 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) { data_prdptr = nullptr; } - rv = nghttp2_submit_response(session_, downstream->get_stream_id(), - nva.data(), nva.size(), data_prdptr); + rv = nghttp2_submit_response2(session_, downstream->get_stream_id(), + nva.data(), nva.size(), data_prdptr); if (rv != 0) { - ULOG(FATAL, this) << "nghttp2_submit_response() failed"; + ULOG(FATAL, this) << "nghttp2_submit_response2() failed"; return -1; } diff --git a/yass/third_party/nghttp2/src/shrpx_http3_upstream.cc b/yass/third_party/nghttp2/src/shrpx_http3_upstream.cc index bc5c400a91..d12d2da1c8 100644 --- a/yass/third_party/nghttp2/src/shrpx_http3_upstream.cc +++ b/yass/third_party/nghttp2/src/shrpx_http3_upstream.cc @@ -46,6 +46,7 @@ #endif // HAVE_MRUBY #include "http3.h" #include "util.h" +#include "ssl_compat.h" namespace shrpx { @@ -117,7 +118,6 @@ Http3Upstream::Http3Upstream(ClientHandler *handler) httpconn_{nullptr}, downstream_queue_{downstream_queue_size(handler->get_worker()), !get_config()->http2_proxy}, - retry_close_{false}, tx_{ .data = std::unique_ptr(new uint8_t[64_k]), } { @@ -211,8 +211,10 @@ int get_new_connection_id(ngtcp2_conn *conn, ngtcp2_cid *cid, uint8_t *token, auto &qkms = conn_handler->get_quic_keying_materials(); auto &qkm = qkms->keying_materials.front(); - if (generate_quic_connection_id(*cid, cidlen, worker->get_cid_prefix(), - qkm.id, qkm.cid_encryption_key.data()) != 0) { + assert(SHRPX_QUIC_SCIDLEN == cidlen); + + if (generate_quic_connection_id(*cid, worker->get_worker_id(), qkm.id, + qkm.cid_encryption_ctx) != 0) { return NGTCP2_ERR_CALLBACK_FAILURE; } @@ -249,8 +251,9 @@ void Http3Upstream::http_begin_request_headers(int64_t stream_id) { nghttp3_conn_set_stream_user_data(httpconn_, stream_id, downstream.get()); downstream->reset_upstream_rtimer(); + downstream->repeat_header_timer(); - handler_->repeat_read_timer(); + handler_->stop_read_timer(); auto &req = downstream->request(); req.http_major = 3; @@ -421,7 +424,7 @@ int stream_reset(ngtcp2_conn *conn, int64_t stream_id, uint64_t final_size, void *stream_user_data) { auto upstream = static_cast(user_data); - if (upstream->stream_reset(stream_id) != 0) { + if (upstream->http_shutdown_stream_read(stream_id) != 0) { return NGTCP2_ERR_CALLBACK_FAILURE; } @@ -429,24 +432,6 @@ int stream_reset(ngtcp2_conn *conn, int64_t stream_id, uint64_t final_size, } } // namespace -int Http3Upstream::stream_reset(int64_t stream_id) { - if (http_shutdown_stream_read(stream_id) != 0) { - return -1; - } - - if (ngtcp2_is_bidi_stream(stream_id)) { - auto rv = ngtcp2_conn_shutdown_stream_write(conn_, 0, stream_id, - NGHTTP3_H3_NO_ERROR); - if (rv != 0) { - ULOG(ERROR, this) << "ngtcp2_conn_shutdown_stream_write: " - << ngtcp2_strerror(rv); - return -1; - } - } - - return 0; -} - int Http3Upstream::http_shutdown_stream_read(int64_t stream_id) { if (!httpconn_) { return 0; @@ -626,9 +611,8 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr, ngtcp2_cid scid; - if (generate_quic_connection_id(scid, SHRPX_QUIC_SCIDLEN, - worker->get_cid_prefix(), qkm.id, - qkm.cid_encryption_key.data()) != 0) { + if (generate_quic_connection_id(scid, worker->get_worker_id(), qkm.id, + qkm.cid_encryption_ctx) != 0) { return -1; } @@ -652,7 +636,6 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr, settings.cc_algo = quicconf.upstream.congestion_controller; settings.max_window = http3conf.upstream.max_connection_window_size; settings.max_stream_window = http3conf.upstream.max_window_size; - settings.max_tx_udp_payload_size = SHRPX_QUIC_MAX_UDP_PAYLOAD_SIZE; settings.rand_ctx.native_handle = &worker->get_randgen(); settings.token = token; settings.tokenlen = tokenlen; @@ -671,7 +654,7 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr, params.max_idle_timeout = static_cast( quicconf.upstream.timeout.idle * NGTCP2_SECONDS); -#ifdef OPENSSL_IS_BORINGSSL +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL if (quicconf.upstream.early_data) { ngtcp2_transport_params early_data_params; @@ -707,7 +690,7 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr, return -1; } } -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL if (odcid) { params.original_dcid = *odcid; @@ -800,7 +783,9 @@ int Http3Upstream::write_streams() { auto path_max_udp_payload_size = ngtcp2_conn_get_path_max_tx_udp_payload_size(conn_); #endif // UDP_SEGMENT - auto max_pktcnt = ngtcp2_conn_get_send_quantum(conn_) / max_udp_payload_size; + auto max_pktcnt = + std::max(ngtcp2_conn_get_send_quantum(conn_) / max_udp_payload_size, + static_cast(1)); ngtcp2_pkt_info pi, prev_pi; uint8_t *bufpos = tx_.data.get(); ngtcp2_path_storage ps, prev_ps; @@ -1013,7 +998,18 @@ int Http3Upstream::write_streams() { return 0; } -int Http3Upstream::on_timeout(Downstream *downstream) { return 0; } +int Http3Upstream::on_timeout(Downstream *downstream) { + if (LOG_ENABLED(INFO)) { + ULOG(INFO, this) << "Stream timeout stream_id=" + << downstream->get_stream_id(); + } + + shutdown_stream(downstream, NGHTTP3_H3_INTERNAL_ERROR); + + handler_->signal_write(); + + return 0; +} int Http3Upstream::on_downstream_abort_request(Downstream *downstream, unsigned int status_code) { @@ -1427,6 +1423,23 @@ int Http3Upstream::on_downstream_header_complete(Downstream *downstream) { log_response_headers(downstream, nva); } + auto priority = resp.fs.header(http2::HD_PRIORITY); + if (priority) { + nghttp3_pri pri; + + if (nghttp3_conn_get_stream_priority(httpconn_, &pri, + downstream->get_stream_id()) == 0 && + nghttp3_pri_parse_priority(&pri, priority->value.byte(), + priority->value.size()) == 0) { + rv = nghttp3_conn_set_server_stream_priority( + httpconn_, downstream->get_stream_id(), &pri); + if (rv != 0) { + ULOG(ERROR, this) << "nghttp3_conn_set_server_stream_priority: " + << nghttp3_strerror(rv); + } + } + } + nghttp3_data_reader data_read; data_read.read_data = downstream_read_data_callback; @@ -1527,8 +1540,13 @@ void Http3Upstream::on_handler_delete() { quic_conn_handler->remove_connection_id(cid); } - if (retry_close_ || last_error_.type == NGTCP2_CCERR_TYPE_IDLE_CLOSE) { + switch (last_error_.type) { + case NGTCP2_CCERR_TYPE_IDLE_CLOSE: + case NGTCP2_CCERR_TYPE_DROP_CONN: + case NGTCP2_CCERR_TYPE_RETRY: return; + default: + break; } // If this is not idle close, send CONNECTION_CLOSE. @@ -1822,7 +1840,8 @@ int Http3Upstream::on_read(const UpstreamAddr *faddr, return -1; } - retry_close_ = true; + // Overwrite error if any is set + ngtcp2_ccerr_set_liberr(&last_error_, rv, nullptr, 0); quic_conn_handler->send_retry(handler_->get_upstream_addr(), vc.version, vc.dcid, vc.dcidlen, vc.scid, vc.scidlen, @@ -1837,6 +1856,9 @@ int Http3Upstream::on_read(const UpstreamAddr *faddr, } break; case NGTCP2_ERR_DROP_CONN: + // Overwrite error if any is set + ngtcp2_ccerr_set_liberr(&last_error_, rv, nullptr, 0); + return -1; default: if (!last_error_.error_code) { @@ -2148,6 +2170,11 @@ int Http3Upstream::http_recv_request_header(Downstream *downstream, // just ignore if this is a trailer part. if (trailer) { + if (shutdown_stream_read(downstream->get_stream_id(), + NGHTTP3_H3_NO_ERROR) != 0) { + return -1; + } + return 0; } @@ -2181,7 +2208,6 @@ namespace { int http_end_request_headers(nghttp3_conn *conn, int64_t stream_id, int fin, void *user_data, void *stream_user_data) { auto upstream = static_cast(user_data); - auto handler = upstream->get_client_handler(); auto downstream = static_cast(stream_user_data); if (!downstream || downstream->get_stop_reading()) { @@ -2193,7 +2219,7 @@ int http_end_request_headers(nghttp3_conn *conn, int64_t stream_id, int fin, } downstream->reset_upstream_rtimer(); - handler->stop_read_timer(); + downstream->stop_header_timer(); return 0; } diff --git a/yass/third_party/nghttp2/src/shrpx_http3_upstream.h b/yass/third_party/nghttp2/src/shrpx_http3_upstream.h index 18076522ad..53c73ae723 100644 --- a/yass/third_party/nghttp2/src/shrpx_http3_upstream.h +++ b/yass/third_party/nghttp2/src/shrpx_http3_upstream.h @@ -125,7 +125,6 @@ public: void consume(int64_t stream_id, size_t nconsumed); void remove_downstream(Downstream *downstream); int stream_close(int64_t stream_id, uint64_t app_error_code); - int stream_reset(int64_t stream_id); void log_response_headers(Downstream *downstream, const std::vector &nva) const; int http_acked_stream_data(Downstream *downstream, uint64_t datalen); @@ -168,7 +167,6 @@ private: ngtcp2_ccerr last_error_; nghttp3_conn *httpconn_; DownstreamQueue downstream_queue_; - bool retry_close_; std::vector conn_close_; struct { diff --git a/yass/third_party/nghttp2/src/shrpx_http_downstream_connection.cc b/yass/third_party/nghttp2/src/shrpx_http_downstream_connection.cc index bdb42943e5..4164b8b4d9 100644 --- a/yass/third_party/nghttp2/src/shrpx_http_downstream_connection.cc +++ b/yass/third_party/nghttp2/src/shrpx_http_downstream_connection.cc @@ -596,13 +596,13 @@ int HttpDownstreamConnection::push_request_headers() { auto upstream = downstream_->get_upstream(); auto handler = upstream->get_client_handler(); -#if OPENSSL_1_1_1_API +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_BORINGSSL) auto conn = handler->get_connection(); if (conn->tls.ssl && !SSL_is_init_finished(conn->tls.ssl)) { buf->append("Early-Data: 1\r\n"); } -#endif // OPENSSL_1_1_1_API +#endif // NGHTTP2_GENUINE_OPENSSL || NGHTTP2_OPENSSL_IS_BORINGSSL auto fwd = fwdconf.strip_incoming ? nullptr : req.fs.header(http2::HD_FORWARDED); diff --git a/yass/third_party/nghttp2/src/shrpx_http_test.cc b/yass/third_party/nghttp2/src/shrpx_http_test.cc index 3ace8702b7..f753ec8d5a 100644 --- a/yass/third_party/nghttp2/src/shrpx_http_test.cc +++ b/yass/third_party/nghttp2/src/shrpx_http_test.cc @@ -30,7 +30,7 @@ #include -#include +#include "munitxx.h" #include "shrpx_http.h" #include "shrpx_config.h" @@ -38,43 +38,65 @@ namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_http_create_forwarded), + munit_void_test(test_shrpx_http_create_via_header_value), + munit_void_test(test_shrpx_http_create_affinity_cookie), + munit_void_test(test_shrpx_http_create_altsvc_header_value), + munit_void_test(test_shrpx_http_check_http_scheme), + munit_test_end(), +}; +} // namespace + +const MunitSuite http_suite{ + "/http", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_http_create_forwarded(void) { BlockAllocator balloc(1024, 1024); - CU_ASSERT("by=\"example.com:3000\";for=\"[::1]\";host=\"www.example.com\";" - "proto=https" == - http::create_forwarded(balloc, - FORWARDED_BY | FORWARDED_FOR | - FORWARDED_HOST | FORWARDED_PROTO, - StringRef::from_lit("example.com:3000"), - StringRef::from_lit("[::1]"), - StringRef::from_lit("www.example.com"), - StringRef::from_lit("https"))); + assert_stdstring_equal( + "by=\"example.com:3000\";for=\"[::1]\";host=\"www.example.com\";" + "proto=https", + http::create_forwarded( + balloc, + FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | FORWARDED_PROTO, + StringRef::from_lit("example.com:3000"), StringRef::from_lit("[::1]"), + StringRef::from_lit("www.example.com"), StringRef::from_lit("https")) + .str()); - CU_ASSERT("for=192.168.0.1" == - http::create_forwarded( - balloc, FORWARDED_FOR, StringRef::from_lit("alpha"), - StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("bravo"), StringRef::from_lit("charlie"))); + assert_stdstring_equal( + "for=192.168.0.1", + http::create_forwarded( + balloc, FORWARDED_FOR, StringRef::from_lit("alpha"), + StringRef::from_lit("192.168.0.1"), StringRef::from_lit("bravo"), + StringRef::from_lit("charlie")) + .str()); - CU_ASSERT("by=_hidden;for=\"[::1]\"" == - http::create_forwarded( - balloc, FORWARDED_BY | FORWARDED_FOR, - StringRef::from_lit("_hidden"), StringRef::from_lit("[::1]"), - StringRef::from_lit(""), StringRef::from_lit(""))); + assert_stdstring_equal( + "by=_hidden;for=\"[::1]\"", + http::create_forwarded(balloc, FORWARDED_BY | FORWARDED_FOR, + StringRef::from_lit("_hidden"), + StringRef::from_lit("[::1]"), + StringRef::from_lit(""), StringRef::from_lit("")) + .str()); - CU_ASSERT("by=\"[::1]\";for=_hidden" == - http::create_forwarded( - balloc, FORWARDED_BY | FORWARDED_FOR, - StringRef::from_lit("[::1]"), StringRef::from_lit("_hidden"), - StringRef::from_lit(""), StringRef::from_lit(""))); + assert_stdstring_equal( + "by=\"[::1]\";for=_hidden", + http::create_forwarded(balloc, FORWARDED_BY | FORWARDED_FOR, + StringRef::from_lit("[::1]"), + StringRef::from_lit("_hidden"), + StringRef::from_lit(""), StringRef::from_lit("")) + .str()); - CU_ASSERT("" == - http::create_forwarded( - balloc, - FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | FORWARDED_PROTO, - StringRef::from_lit(""), StringRef::from_lit(""), - StringRef::from_lit(""), StringRef::from_lit(""))); + assert_stdstring_equal( + "", http::create_forwarded( + balloc, + FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | FORWARDED_PROTO, + StringRef::from_lit(""), StringRef::from_lit(""), + StringRef::from_lit(""), StringRef::from_lit("")) + .str()); } void test_shrpx_http_create_via_header_value(void) { @@ -82,13 +104,13 @@ void test_shrpx_http_create_via_header_value(void) { auto end = http::create_via_header_value(std::begin(buf), 1, 1); - CU_ASSERT(("1.1 nghttpx" == StringRef{std::begin(buf), end})); + assert_stdstring_equal("1.1 nghttpx", (std::string{std::begin(buf), end})); std::fill(std::begin(buf), std::end(buf), '\0'); end = http::create_via_header_value(std::begin(buf), 2, 0); - CU_ASSERT(("2 nghttpx" == StringRef{std::begin(buf), end})); + assert_stdstring_equal("2 nghttpx", (std::string{std::begin(buf), end})); } void test_shrpx_http_create_affinity_cookie(void) { @@ -98,24 +120,24 @@ void test_shrpx_http_create_affinity_cookie(void) { c = http::create_affinity_cookie(balloc, StringRef::from_lit("cookie-val"), 0xf1e2d3c4u, StringRef{}, false); - CU_ASSERT("cookie-val=f1e2d3c4" == c); + assert_stdstring_equal("cookie-val=f1e2d3c4", c.str()); c = http::create_affinity_cookie(balloc, StringRef::from_lit("alpha"), 0x00000000u, StringRef{}, true); - CU_ASSERT("alpha=00000000; Secure" == c); + assert_stdstring_equal("alpha=00000000; Secure", c.str()); c = http::create_affinity_cookie(balloc, StringRef::from_lit("bravo"), 0x01111111u, StringRef::from_lit("bar"), false); - CU_ASSERT("bravo=01111111; Path=bar" == c); + assert_stdstring_equal("bravo=01111111; Path=bar", c.str()); c = http::create_affinity_cookie(balloc, StringRef::from_lit("charlie"), 0x01111111u, StringRef::from_lit("bar"), true); - CU_ASSERT("charlie=01111111; Path=bar; Secure" == c); + assert_stdstring_equal("charlie=01111111; Path=bar; Secure", c.str()); } void test_shrpx_http_create_altsvc_header_value(void) { @@ -130,8 +152,9 @@ void test_shrpx_http_create_altsvc_header_value(void) { }, }; - CU_ASSERT(R"(h3="127.0.0.1:443"; ma=3600)" == - http::create_altsvc_header_value(balloc, altsvcs)); + assert_stdstring_equal( + R"(h3="127.0.0.1:443"; ma=3600)", + http::create_altsvc_header_value(balloc, altsvcs).str()); } { @@ -149,20 +172,21 @@ void test_shrpx_http_create_altsvc_header_value(void) { }, }; - CU_ASSERT(R"(h3=":443"; ma=3600, h3%25="\"foo\":4433")" == - http::create_altsvc_header_value(balloc, altsvcs)); + assert_stdstring_equal( + R"(h3=":443"; ma=3600, h3%25="\"foo\":4433")", + http::create_altsvc_header_value(balloc, altsvcs).str()); } } void test_shrpx_http_check_http_scheme(void) { - CU_ASSERT(http::check_http_scheme(StringRef::from_lit("https"), true)); - CU_ASSERT(!http::check_http_scheme(StringRef::from_lit("https"), false)); - CU_ASSERT(!http::check_http_scheme(StringRef::from_lit("http"), true)); - CU_ASSERT(http::check_http_scheme(StringRef::from_lit("http"), false)); - CU_ASSERT(!http::check_http_scheme(StringRef::from_lit("foo"), true)); - CU_ASSERT(!http::check_http_scheme(StringRef::from_lit("foo"), false)); - CU_ASSERT(!http::check_http_scheme(StringRef{}, true)); - CU_ASSERT(!http::check_http_scheme(StringRef{}, false)); + assert_true(http::check_http_scheme(StringRef::from_lit("https"), true)); + assert_false(http::check_http_scheme(StringRef::from_lit("https"), false)); + assert_false(http::check_http_scheme(StringRef::from_lit("http"), true)); + assert_true(http::check_http_scheme(StringRef::from_lit("http"), false)); + assert_false(http::check_http_scheme(StringRef::from_lit("foo"), true)); + assert_false(http::check_http_scheme(StringRef::from_lit("foo"), false)); + assert_false(http::check_http_scheme(StringRef{}, true)); + assert_false(http::check_http_scheme(StringRef{}, false)); } } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_http_test.h b/yass/third_party/nghttp2/src/shrpx_http_test.h index d50ab53397..2abdc201ec 100644 --- a/yass/third_party/nghttp2/src/shrpx_http_test.h +++ b/yass/third_party/nghttp2/src/shrpx_http_test.h @@ -29,13 +29,19 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_http_create_forwarded(void); -void test_shrpx_http_create_via_header_value(void); -void test_shrpx_http_create_affinity_cookie(void); -void test_shrpx_http_create_altsvc_header_value(void); -void test_shrpx_http_check_http_scheme(void); +extern const MunitSuite http_suite; + +munit_void_test_decl(test_shrpx_http_create_forwarded); +munit_void_test_decl(test_shrpx_http_create_via_header_value); +munit_void_test_decl(test_shrpx_http_create_affinity_cookie); +munit_void_test_decl(test_shrpx_http_create_altsvc_header_value); +munit_void_test_decl(test_shrpx_http_check_http_scheme); } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_https_upstream.cc b/yass/third_party/nghttp2/src/shrpx_https_upstream.cc index 49d2088343..04123847f3 100644 --- a/yass/third_party/nghttp2/src/shrpx_https_upstream.cc +++ b/yass/third_party/nghttp2/src/shrpx_https_upstream.cc @@ -115,12 +115,9 @@ void HttpsUpstream::on_start_request() { attach_downstream(std::move(downstream)); - auto conn = handler_->get_connection(); - auto &upstreamconf = get_config()->conn.upstream; + auto &httpconf = get_config()->http; - conn->rt.repeat = upstreamconf.timeout.read; - - handler_->repeat_read_timer(); + handler_->reset_upstream_read_timeout(httpconf.timeout.header); ++num_requests_; } @@ -795,12 +792,9 @@ int HttpsUpstream::on_write() { return 0; } - auto conn = handler_->get_connection(); auto &upstreamconf = get_config()->conn.upstream; - conn->rt.repeat = upstreamconf.timeout.idle_read; - - handler_->repeat_read_timer(); + handler_->reset_upstream_read_timeout(upstreamconf.timeout.idle); return resume_read(SHRPX_NO_BUFFER, nullptr, 0); } else { diff --git a/yass/third_party/nghttp2/src/shrpx_live_check.cc b/yass/third_party/nghttp2/src/shrpx_live_check.cc index 5d1057c6e8..8e8d316a0a 100644 --- a/yass/third_party/nghttp2/src/shrpx_live_check.cc +++ b/yass/third_party/nghttp2/src/shrpx_live_check.cc @@ -405,14 +405,7 @@ int LiveCheck::tls_handshake() { const unsigned char *next_proto = nullptr; unsigned int next_proto_len = 0; -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_get0_next_proto_negotiated(conn_.tls.ssl, &next_proto, &next_proto_len); -#endif // !OPENSSL_NO_NEXTPROTONEG -#if OPENSSL_VERSION_NUMBER >= 0x10002000L - if (next_proto == nullptr) { - SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len); - } -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len); auto proto = StringRef{next_proto, next_proto_len}; @@ -587,18 +580,16 @@ int LiveCheck::write_clear() { } int LiveCheck::on_read(const uint8_t *data, size_t len) { - ssize_t rv; - - rv = nghttp2_session_mem_recv(session_, data, len); + auto rv = nghttp2_session_mem_recv2(session_, data, len); if (rv < 0) { - LOG(ERROR) << "nghttp2_session_mem_recv() returned error: " + LOG(ERROR) << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv); return -1; } if (settings_ack_received_ && !session_closing_) { session_closing_ = true; - rv = nghttp2_session_terminate_session(session_, NGHTTP2_NO_ERROR); + auto rv = nghttp2_session_terminate_session(session_, NGHTTP2_NO_ERROR); if (rv != 0) { return -1; } @@ -626,10 +617,10 @@ int LiveCheck::on_read(const uint8_t *data, size_t len) { int LiveCheck::on_write() { for (;;) { const uint8_t *data; - auto datalen = nghttp2_session_mem_send(session_, &data); + auto datalen = nghttp2_session_mem_send2(session_, &data); if (datalen < 0) { - LOG(ERROR) << "nghttp2_session_mem_send() returned error: " + LOG(ERROR) << "nghttp2_session_mem_send2() returned error: " << nghttp2_strerror(datalen); return -1; } diff --git a/yass/third_party/nghttp2/src/shrpx_log.h b/yass/third_party/nghttp2/src/shrpx_log.h index 81035b2e44..bc30097c67 100644 --- a/yass/third_party/nghttp2/src/shrpx_log.h +++ b/yass/third_party/nghttp2/src/shrpx_log.h @@ -45,43 +45,53 @@ using namespace nghttp2; #define LOG_ENABLED(SEVERITY) (ENABLE_LOG && shrpx::Log::log_enabled(SEVERITY)) -#define LOG(SEVERITY) shrpx::Log(SEVERITY, __FILE__, __LINE__) +#ifdef __FILE_NAME__ +# define NGHTTP2_FILE_NAME __FILE_NAME__ +#else // !__FILE_NAME__ +# define NGHTTP2_FILE_NAME __FILE__ +#endif // !__FILE_NAME__ + +#define LOG(SEVERITY) shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) // Listener log #define LLOG(SEVERITY, LISTEN) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[LISTEN:" << LISTEN << "] ") + (shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) \ + << "[LISTEN:" << LISTEN << "] ") // Worker log #define WLOG(SEVERITY, WORKER) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[WORKER:" << WORKER << "] ") + (shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) \ + << "[WORKER:" << WORKER << "] ") // ClientHandler log #define CLOG(SEVERITY, CLIENT_HANDLER) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) \ + (shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) \ << "[CLIENT_HANDLER:" << CLIENT_HANDLER << "] ") // Upstream log #define ULOG(SEVERITY, UPSTREAM) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[UPSTREAM:" << UPSTREAM \ - << "]" \ - " ") + (shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) \ + << "[UPSTREAM:" << UPSTREAM << "] ") // Downstream log #define DLOG(SEVERITY, DOWNSTREAM) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) \ + (shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) \ << "[DOWNSTREAM:" << DOWNSTREAM << "] ") // Downstream connection log #define DCLOG(SEVERITY, DCONN) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[DCONN:" << DCONN << "] ") + (shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) \ + << "[DCONN:" << DCONN << "] ") // Downstream HTTP2 session log #define SSLOG(SEVERITY, HTTP2) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[DHTTP2:" << HTTP2 << "] ") + (shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) \ + << "[DHTTP2:" << HTTP2 << "] ") // Memcached connection log #define MCLOG(SEVERITY, MCONN) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[MCONN:" << MCONN << "] ") + (shrpx::Log(SEVERITY, NGHTTP2_FILE_NAME, __LINE__) \ + << "[MCONN:" << MCONN << "] ") namespace shrpx { diff --git a/yass/third_party/nghttp2/src/shrpx_mruby.cc b/yass/third_party/nghttp2/src/shrpx_mruby.cc index b5c6ed3c85..4d412ef378 100644 --- a/yass/third_party/nghttp2/src/shrpx_mruby.cc +++ b/yass/third_party/nghttp2/src/shrpx_mruby.cc @@ -151,12 +151,12 @@ RProc *compile(mrb_state *mrb, const StringRef &filename) { } auto infile_d = defer(fclose, infile); - auto mrbc = mrbc_context_new(mrb); + auto mrbc = mrb_ccontext_new(mrb); if (mrbc == nullptr) { LOG(ERROR) << "mrb_context_new failed"; return nullptr; } - auto mrbc_d = defer(mrbc_context_free, mrb, mrbc); + auto mrbc_d = defer(mrb_ccontext_free, mrb, mrbc); auto parser = mrb_parse_file(mrb, infile, nullptr); if (parser == nullptr) { diff --git a/yass/third_party/nghttp2/src/shrpx_quic.cc b/yass/third_party/nghttp2/src/shrpx_quic.cc index 2d4de59336..c52eee46a5 100644 --- a/yass/third_party/nghttp2/src/shrpx_quic.cc +++ b/yass/third_party/nghttp2/src/shrpx_quic.cc @@ -173,57 +173,40 @@ int quic_send_packet(const UpstreamAddr *faddr, const sockaddr *remote_sa, return 0; } -int generate_quic_retry_connection_id(ngtcp2_cid &cid, size_t cidlen, - const uint8_t *server_id, uint8_t km_id, - const uint8_t *key) { - assert(cidlen == SHRPX_QUIC_SCIDLEN); - - if (RAND_bytes(cid.data, cidlen) != 1) { +int generate_quic_retry_connection_id(ngtcp2_cid &cid, uint32_t server_id, + uint8_t km_id, EVP_CIPHER_CTX *ctx) { + if (RAND_bytes(cid.data, SHRPX_QUIC_SCIDLEN) != 1) { return -1; } - cid.datalen = cidlen; + cid.datalen = SHRPX_QUIC_SCIDLEN; + cid.data[0] = (cid.data[0] & (~SHRPX_QUIC_DCID_KM_ID_MASK)) | km_id; - cid.data[0] = (cid.data[0] & 0x3f) | km_id; + auto p = cid.data + SHRPX_QUIC_CID_WORKER_ID_OFFSET; - auto p = cid.data + SHRPX_QUIC_CID_PREFIX_OFFSET; + std::copy_n(reinterpret_cast(&server_id), sizeof(server_id), p); - std::copy_n(server_id, SHRPX_QUIC_SERVER_IDLEN, p); - - return encrypt_quic_connection_id(p, p, key); + return encrypt_quic_connection_id(p, p, ctx); } -int generate_quic_connection_id(ngtcp2_cid &cid, size_t cidlen, - const uint8_t *cid_prefix, uint8_t km_id, - const uint8_t *key) { - assert(cidlen == SHRPX_QUIC_SCIDLEN); - - if (RAND_bytes(cid.data, cidlen) != 1) { +int generate_quic_connection_id(ngtcp2_cid &cid, const WorkerID &wid, + uint8_t km_id, EVP_CIPHER_CTX *ctx) { + if (RAND_bytes(cid.data, SHRPX_QUIC_SCIDLEN) != 1) { return -1; } - cid.datalen = cidlen; + cid.datalen = SHRPX_QUIC_SCIDLEN; + cid.data[0] = (cid.data[0] & (~SHRPX_QUIC_DCID_KM_ID_MASK)) | km_id; - cid.data[0] = (cid.data[0] & 0x3f) | km_id; + auto p = cid.data + SHRPX_QUIC_CID_WORKER_ID_OFFSET; - auto p = cid.data + SHRPX_QUIC_CID_PREFIX_OFFSET; + std::copy_n(reinterpret_cast(&wid), sizeof(wid), p); - std::copy_n(cid_prefix, SHRPX_QUIC_CID_PREFIXLEN, p); - - return encrypt_quic_connection_id(p, p, key); + return encrypt_quic_connection_id(p, p, ctx); } int encrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, - const uint8_t *key) { - auto ctx = EVP_CIPHER_CTX_new(); - auto d = defer(EVP_CIPHER_CTX_free, ctx); - - if (!EVP_EncryptInit_ex(ctx, EVP_aes_128_ecb(), nullptr, key, nullptr)) { - return -1; - } - - EVP_CIPHER_CTX_set_padding(ctx, 0); - + EVP_CIPHER_CTX *ctx) { int len; if (!EVP_EncryptUpdate(ctx, dest, &len, src, SHRPX_QUIC_DECRYPTED_DCIDLEN) || @@ -234,21 +217,13 @@ int encrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, return 0; } -int decrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, - const uint8_t *key) { - auto ctx = EVP_CIPHER_CTX_new(); - auto d = defer(EVP_CIPHER_CTX_free, ctx); - - if (!EVP_DecryptInit_ex(ctx, EVP_aes_128_ecb(), nullptr, key, nullptr)) { - return -1; - } - - EVP_CIPHER_CTX_set_padding(ctx, 0); - +int decrypt_quic_connection_id(ConnectionID &dest, const uint8_t *src, + EVP_CIPHER_CTX *ctx) { int len; + auto p = reinterpret_cast(&dest); - if (!EVP_DecryptUpdate(ctx, dest, &len, src, SHRPX_QUIC_DECRYPTED_DCIDLEN) || - !EVP_DecryptFinal_ex(ctx, dest + len, &len)) { + if (!EVP_DecryptUpdate(ctx, p, &len, src, SHRPX_QUIC_DECRYPTED_DCIDLEN) || + !EVP_DecryptFinal_ex(ctx, p + len, &len)) { return -1; } diff --git a/yass/third_party/nghttp2/src/shrpx_quic.h b/yass/third_party/nghttp2/src/shrpx_quic.h index b2f60879bc..dae6e31132 100644 --- a/yass/third_party/nghttp2/src/shrpx_quic.h +++ b/yass/third_party/nghttp2/src/shrpx_quic.h @@ -31,6 +31,8 @@ #include +#include + #include #include "network.h" @@ -63,20 +65,50 @@ struct UpstreamAddr; struct QUICKeyingMaterials; struct QUICKeyingMaterial; -constexpr size_t SHRPX_QUIC_SCIDLEN = 20; +constexpr size_t SHRPX_QUIC_CID_WORKER_ID_OFFSET = 1; constexpr size_t SHRPX_QUIC_SERVER_IDLEN = 4; -// SHRPX_QUIC_CID_PREFIXLEN includes SHRPX_QUIC_SERVER_IDLEN. -constexpr size_t SHRPX_QUIC_CID_PREFIXLEN = 8; -constexpr size_t SHRPX_QUIC_CID_PREFIX_OFFSET = 1; -constexpr size_t SHRPX_QUIC_DECRYPTED_DCIDLEN = 16; +constexpr size_t SHRPX_QUIC_SOCK_IDLEN = 4; +constexpr size_t SHRPX_QUIC_WORKER_IDLEN = + SHRPX_QUIC_SERVER_IDLEN + SHRPX_QUIC_SOCK_IDLEN; +constexpr size_t SHRPX_QUIC_CLIENT_IDLEN = 8; +constexpr size_t SHRPX_QUIC_DECRYPTED_DCIDLEN = + SHRPX_QUIC_WORKER_IDLEN + SHRPX_QUIC_CLIENT_IDLEN; +constexpr size_t SHRPX_QUIC_SCIDLEN = + SHRPX_QUIC_CID_WORKER_ID_OFFSET + SHRPX_QUIC_DECRYPTED_DCIDLEN; constexpr size_t SHRPX_QUIC_CID_ENCRYPTION_KEYLEN = 16; -constexpr size_t SHRPX_QUIC_MAX_UDP_PAYLOAD_SIZE = 1472; constexpr size_t SHRPX_QUIC_CONN_CLOSE_PKTLEN = 256; constexpr size_t SHRPX_QUIC_STATELESS_RESET_BURST = 100; constexpr size_t SHRPX_QUIC_SECRET_RESERVEDLEN = 4; constexpr size_t SHRPX_QUIC_SECRETLEN = 32; constexpr size_t SHRPX_QUIC_SALTLEN = 32; -constexpr uint8_t SHRPX_QUIC_DCID_KM_ID_MASK = 0xc0; +constexpr uint8_t SHRPX_QUIC_DCID_KM_ID_MASK = 0xe0; + +struct WorkerID { + union { + struct { + uint32_t server; + uint16_t worker_process; + uint16_t thread; + }; + uint64_t worker; + }; +}; + +static_assert(sizeof(WorkerID) == SHRPX_QUIC_WORKER_IDLEN, + "WorkerID length assertion failure"); + +inline bool operator==(const WorkerID &lhd, const WorkerID &rhd) { + return lhd.worker == rhd.worker; +} + +inline bool operator!=(const WorkerID &lhd, const WorkerID &rhd) { + return lhd.worker != rhd.worker; +} + +struct ConnectionID { + WorkerID worker; + uint64_t client; +}; ngtcp2_tstamp quic_timestamp(); @@ -85,19 +117,17 @@ int quic_send_packet(const UpstreamAddr *faddr, const sockaddr *remote_sa, size_t local_salen, const ngtcp2_pkt_info &pi, const uint8_t *data, size_t datalen, size_t gso_size); -int generate_quic_retry_connection_id(ngtcp2_cid &cid, size_t cidlen, - const uint8_t *server_id, uint8_t km_id, - const uint8_t *key); +int generate_quic_retry_connection_id(ngtcp2_cid &cid, uint32_t server_id, + uint8_t km_id, EVP_CIPHER_CTX *ctx); -int generate_quic_connection_id(ngtcp2_cid &cid, size_t cidlen, - const uint8_t *cid_prefix, uint8_t km_id, - const uint8_t *key); +int generate_quic_connection_id(ngtcp2_cid &cid, const WorkerID &wid, + uint8_t km_id, EVP_CIPHER_CTX *ctx); int encrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, - const uint8_t *key); + EVP_CIPHER_CTX *ctx); -int decrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, - const uint8_t *key); +int decrypt_quic_connection_id(ConnectionID &dest, const uint8_t *src, + EVP_CIPHER_CTX *ctx); int generate_quic_hashed_connection_id(ngtcp2_cid &dest, const Address &remote_addr, diff --git a/yass/third_party/nghttp2/src/shrpx_quic_connection_handler.cc b/yass/third_party/nghttp2/src/shrpx_quic_connection_handler.cc index 2cd81632d1..b810aa68ae 100644 --- a/yass/third_party/nghttp2/src/shrpx_quic_connection_handler.cc +++ b/yass/third_party/nghttp2/src/shrpx_quic_connection_handler.cc @@ -34,6 +34,7 @@ #include "shrpx_log.h" #include "shrpx_http3_upstream.h" #include "shrpx_connection_handler.h" +#include "ssl_compat.h" namespace shrpx { @@ -122,7 +123,7 @@ int QUICConnectionHandler::handle_packet(const UpstreamAddr *faddr, } if (it == std::end(connections_)) { - std::array decrypted_dcid; + ConnectionID decrypted_dcid; auto &qkms = conn_handler->get_quic_keying_materials(); const QUICKeyingMaterial *qkm = nullptr; @@ -131,19 +132,17 @@ int QUICConnectionHandler::handle_packet(const UpstreamAddr *faddr, qkm = select_quic_keying_material( *qkms.get(), vc.dcid[0] & SHRPX_QUIC_DCID_KM_ID_MASK); - if (decrypt_quic_connection_id(decrypted_dcid.data(), - vc.dcid + SHRPX_QUIC_CID_PREFIX_OFFSET, - qkm->cid_encryption_key.data()) != 0) { + if (decrypt_quic_connection_id(decrypted_dcid, + vc.dcid + SHRPX_QUIC_CID_WORKER_ID_OFFSET, + qkm->cid_decryption_ctx) != 0) { return 0; } if (qkm != &qkms->keying_materials.front() || - !std::equal(std::begin(decrypted_dcid), - std::begin(decrypted_dcid) + SHRPX_QUIC_CID_PREFIXLEN, - worker_->get_cid_prefix())) { + decrypted_dcid.worker != worker_->get_worker_id()) { auto quic_lwp = - conn_handler->match_quic_lingering_worker_process_cid_prefix( - decrypted_dcid.data(), decrypted_dcid.size()); + conn_handler->match_quic_lingering_worker_process_worker_id( + decrypted_dcid.worker); if (quic_lwp) { if (conn_handler->forward_quic_packet_to_lingering_worker_process( quic_lwp, remote_addr, local_addr, pi, data, datalen) == 0) { @@ -176,23 +175,21 @@ int QUICConnectionHandler::handle_packet(const UpstreamAddr *faddr, switch (ngtcp2_accept(&hd, data, datalen)) { case 0: { - // If we get Initial and it has the CID prefix of this worker, - // it is likely that client is intentionally use the prefix. - // Just drop it. + // If we get Initial and it has the Worker ID of this worker, it + // is likely that client is intentionally use the prefix. Just + // drop it. if (vc.dcidlen == SHRPX_QUIC_SCIDLEN) { if (qkm != &qkms->keying_materials.front()) { qkm = &qkms->keying_materials.front(); - if (decrypt_quic_connection_id(decrypted_dcid.data(), - vc.dcid + SHRPX_QUIC_CID_PREFIX_OFFSET, - qkm->cid_encryption_key.data()) != 0) { + if (decrypt_quic_connection_id( + decrypted_dcid, vc.dcid + SHRPX_QUIC_CID_WORKER_ID_OFFSET, + qkm->cid_decryption_ctx) != 0) { return 0; } } - if (std::equal(std::begin(decrypted_dcid), - std::begin(decrypted_dcid) + SHRPX_QUIC_CID_PREFIXLEN, - worker_->get_cid_prefix())) { + if (decrypted_dcid.worker == worker_->get_worker_id()) { return 0; } } @@ -323,22 +320,19 @@ int QUICConnectionHandler::handle_packet(const UpstreamAddr *faddr, break; } default: - if (!config->single_thread && !(data[0] & 0x80) && - vc.dcidlen == SHRPX_QUIC_SCIDLEN && - !std::equal(std::begin(decrypted_dcid), - std::begin(decrypted_dcid) + SHRPX_QUIC_CID_PREFIXLEN, - worker_->get_cid_prefix())) { - if (conn_handler->forward_quic_packet(faddr, remote_addr, local_addr, - pi, decrypted_dcid.data(), data, + if (!(data[0] & 0x80) && vc.dcidlen == SHRPX_QUIC_SCIDLEN && + decrypted_dcid.worker != worker_->get_worker_id()) { + if (!config->single_thread && + conn_handler->forward_quic_packet(faddr, remote_addr, local_addr, + pi, decrypted_dcid.worker, data, datalen) == 0) { return 0; } - } - if (!(data[0] & 0x80)) { - // TODO Must be rate limited - send_stateless_reset(faddr, vc.dcid, vc.dcidlen, remote_addr, - local_addr); + if (datalen >= SHRPX_QUIC_SCIDLEN + 22) { + send_stateless_reset(faddr, datalen, vc.dcid, vc.dcidlen, remote_addr, + local_addr); + } } return 0; @@ -390,9 +384,9 @@ ClientHandler *QUICConnectionHandler::handle_new_connection( return nullptr; } -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL assert(SSL_is_quic(ssl)); -#endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_GENUINE_OPENSSL SSL_set_accept_state(ssl); @@ -400,11 +394,11 @@ ClientHandler *QUICConnectionHandler::handle_new_connection( auto &quicconf = config->quic; if (quicconf.upstream.early_data) { -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL SSL_set_quic_early_data_enabled(ssl, 1); -#else // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#elif defined(NGHTTP2_OPENSSL_IS_BORINGSSL) SSL_set_early_data_enabled(ssl, 1); -#endif // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL } // Disable TLS session ticket if we don't have working ticket @@ -477,9 +471,8 @@ int QUICConnectionHandler::send_retry( ngtcp2_cid retry_scid; - if (generate_quic_retry_connection_id(retry_scid, SHRPX_QUIC_SCIDLEN, - quicconf.server_id.data(), qkm.id, - qkm.cid_encryption_key.data()) != 0) { + if (generate_quic_retry_connection_id(retry_scid, quicconf.server_id, qkm.id, + qkm.cid_encryption_ctx) != 0) { return -1; } @@ -562,11 +555,9 @@ int QUICConnectionHandler::send_version_negotiation( buf.data(), nwrite, 0); } -int QUICConnectionHandler::send_stateless_reset(const UpstreamAddr *faddr, - const uint8_t *dcid, - size_t dcidlen, - const Address &remote_addr, - const Address &local_addr) { +int QUICConnectionHandler::send_stateless_reset( + const UpstreamAddr *faddr, size_t pktlen, const uint8_t *dcid, + size_t dcidlen, const Address &remote_addr, const Address &local_addr) { if (stateless_reset_bucket_ == 0) { if (LOG_ENABLED(INFO)) { LOG(INFO) << "Stateless Reset bucket has been depleted"; @@ -597,17 +588,30 @@ int QUICConnectionHandler::send_stateless_reset(const UpstreamAddr *faddr, return -1; } - std::array rand_bytes; + // SCID + minimum expansion - NGTCP2_STATELESS_RESET_TOKENLEN + constexpr size_t max_rand_byteslen = + SHRPX_QUIC_SCIDLEN + 22 - NGTCP2_STATELESS_RESET_TOKENLEN; - if (RAND_bytes(rand_bytes.data(), rand_bytes.size()) != 1) { + size_t rand_byteslen; + + if (pktlen <= 43) { + // As per + // https://datatracker.ietf.org/doc/html/rfc9000#section-10.3 + rand_byteslen = pktlen - NGTCP2_STATELESS_RESET_TOKENLEN - 1; + } else { + rand_byteslen = max_rand_byteslen; + } + + std::array rand_bytes; + + if (RAND_bytes(rand_bytes.data(), rand_byteslen) != 1) { return -1; } std::array buf; - auto nwrite = - ngtcp2_pkt_write_stateless_reset(buf.data(), buf.size(), token.data(), - rand_bytes.data(), rand_bytes.size()); + auto nwrite = ngtcp2_pkt_write_stateless_reset( + buf.data(), buf.size(), token.data(), rand_bytes.data(), rand_byteslen); if (nwrite < 0) { LOG(ERROR) << "ngtcp2_pkt_write_stateless_reset: " << ngtcp2_strerror(nwrite); diff --git a/yass/third_party/nghttp2/src/shrpx_quic_connection_handler.h b/yass/third_party/nghttp2/src/shrpx_quic_connection_handler.h index 29e73a41c1..7f65370de0 100644 --- a/yass/third_party/nghttp2/src/shrpx_quic_connection_handler.h +++ b/yass/third_party/nghttp2/src/shrpx_quic_connection_handler.h @@ -103,8 +103,9 @@ public: const uint8_t *ini_scid, size_t ini_scidlen, const Address &remote_addr, const Address &local_addr); - int send_stateless_reset(const UpstreamAddr *faddr, const uint8_t *dcid, - size_t dcidlen, const Address &remote_addr, + int send_stateless_reset(const UpstreamAddr *faddr, size_t pktlen, + const uint8_t *dcid, size_t dcidlen, + const Address &remote_addr, const Address &local_addr); // Send Initial CONNECTION_CLOSE. |ini_dcid| is the destination // Connection ID which appeared in Client Initial packet. diff --git a/yass/third_party/nghttp2/src/shrpx_quic_listener.cc b/yass/third_party/nghttp2/src/shrpx_quic_listener.cc index 9b9f1203aa..681f6058c1 100644 --- a/yass/third_party/nghttp2/src/shrpx_quic_listener.cc +++ b/yass/third_party/nghttp2/src/shrpx_quic_listener.cc @@ -74,6 +74,19 @@ void QUICListener::on_read() { return; } + // Packets less than 22 bytes never be a valid QUIC packet. + if (nread < 22) { + ++pktcnt; + + continue; + } + + if (util::quic_prohibited_port(util::get_port(&su))) { + ++pktcnt; + + continue; + } + Address local_addr{}; if (util::msghdr_get_local_addr(local_addr, &msg, su.storage.ss_family) != 0) { @@ -108,7 +121,8 @@ void QUICListener::on_read() { << " bytes"; } - if (datalen == 0) { + // Packets less than 22 bytes never be a valid QUIC packet. + if (datalen < 22) { break; } diff --git a/yass/third_party/nghttp2/src/shrpx_router_test.cc b/yass/third_party/nghttp2/src/shrpx_router_test.cc index 21c2f51964..a9625a0ae8 100644 --- a/yass/third_party/nghttp2/src/shrpx_router_test.cc +++ b/yass/third_party/nghttp2/src/shrpx_router_test.cc @@ -24,12 +24,25 @@ */ #include "shrpx_router_test.h" -#include +#include "munitxx.h" #include "shrpx_router.h" namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_router_match), + munit_void_test(test_shrpx_router_match_wildcard), + munit_void_test(test_shrpx_router_match_prefix), + munit_test_end(), +}; +} // namespace + +const MunitSuite router_suite{ + "/router", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + struct Pattern { StringRef pattern; size_t idx; @@ -61,42 +74,42 @@ void test_shrpx_router_match(void) { idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/")); - CU_ASSERT(0 == idx); + assert_ssize(0, ==, idx); idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha")); - CU_ASSERT(1 == idx); + assert_ssize(1, ==, idx); idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha/")); - CU_ASSERT(2 == idx); + assert_ssize(2, ==, idx); idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha/charlie")); - CU_ASSERT(2 == idx); + assert_ssize(2, ==, idx); idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha/bravo/")); - CU_ASSERT(3 == idx); + assert_ssize(3, ==, idx); // matches pattern when last '/' is missing in path idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha/bravo")); - CU_ASSERT(3 == idx); + assert_ssize(3, ==, idx); idx = router.match(StringRef::from_lit("www2.nghttp2.org"), StringRef::from_lit("/alpha")); - CU_ASSERT(8 == idx); + assert_ssize(8, ==, idx); idx = router.match(StringRef{}, StringRef::from_lit("/alpha")); - CU_ASSERT(5 == idx); + assert_ssize(5, ==, idx); } void test_shrpx_router_match_wildcard(void) { @@ -115,32 +128,41 @@ void test_shrpx_router_match_wildcard(void) { router.add_route(p.pattern, p.idx, p.wildcard); } - CU_ASSERT(0 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/"))); + assert_ssize(0, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/"))); - CU_ASSERT(1 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/a"))); + assert_ssize(1, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/a"))); - CU_ASSERT(1 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/charlie"))); + assert_ssize(1, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/charlie"))); - CU_ASSERT(2 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha"))); + assert_ssize(2, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha"))); - CU_ASSERT(2 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/"))); + assert_ssize(2, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/"))); - CU_ASSERT(3 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/b"))); + assert_ssize(3, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/b"))); - CU_ASSERT(4 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/bravo"))); + assert_ssize(4, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/bravo"))); - CU_ASSERT(5 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/bravocharlie"))); + assert_ssize(5, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/bravocharlie"))); - CU_ASSERT(5 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/bravo/"))); + assert_ssize(5, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/bravo/"))); } void test_shrpx_router_match_prefix(void) { @@ -166,19 +188,19 @@ void test_shrpx_router_match_prefix(void) { idx = router.match_prefix(&nread, &node, StringRef::from_lit("gro.2ptthgn.gmi.ahpla.ovarb")); - CU_ASSERT(0 == idx); - CU_ASSERT(12 == nread); + assert_ssize(0, ==, idx); + assert_size(12, ==, nread); idx = router.match_prefix(&nread, &node, StringRef::from_lit("gmi.ahpla.ovarb")); - CU_ASSERT(2 == idx); - CU_ASSERT(4 == nread); + assert_ssize(2, ==, idx); + assert_size(4, ==, nread); idx = router.match_prefix(&nread, &node, StringRef::from_lit("ahpla.ovarb")); - CU_ASSERT(3 == idx); - CU_ASSERT(6 == nread); + assert_ssize(3, ==, idx); + assert_ssize(6, ==, nread); } } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_router_test.h b/yass/third_party/nghttp2/src/shrpx_router_test.h index d39cb87b4a..04d4c454bd 100644 --- a/yass/third_party/nghttp2/src/shrpx_router_test.h +++ b/yass/third_party/nghttp2/src/shrpx_router_test.h @@ -29,11 +29,17 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_router_match(void); -void test_shrpx_router_match_wildcard(void); -void test_shrpx_router_match_prefix(void); +extern const MunitSuite router_suite; + +munit_void_test_decl(test_shrpx_router_match); +munit_void_test_decl(test_shrpx_router_match_wildcard); +munit_void_test_decl(test_shrpx_router_match_prefix); } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_tls.cc b/yass/third_party/nghttp2/src/shrpx_tls.cc index 2d6e00437e..10bbbf293c 100644 --- a/yass/third_party/nghttp2/src/shrpx_tls.cc +++ b/yass/third_party/nghttp2/src/shrpx_tls.cc @@ -55,9 +55,9 @@ # include # include #endif // OPENSSL_3_0_0_API -#ifdef OPENSSL_IS_BORINGSSL +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL # include -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL #include @@ -72,6 +72,11 @@ # endif // HAVE_LIBNGTCP2_CRYPTO_BORINGSSL #endif // ENABLE_HTTP3 +#ifdef HAVE_LIBBROTLI +# include +# include +#endif // HAVE_LIBBROTLI + #include "shrpx_log.h" #include "shrpx_client_handler.h" #include "shrpx_config.h" @@ -96,26 +101,6 @@ namespace shrpx { namespace tls { -#if !OPENSSL_1_1_API -namespace { -const unsigned char *ASN1_STRING_get0_data(ASN1_STRING *x) { - return ASN1_STRING_data(x); -} -} // namespace -#endif // !OPENSSL_1_1_API - -#ifndef OPENSSL_NO_NEXTPROTONEG -namespace { -int next_proto_cb(SSL *s, const unsigned char **data, unsigned int *len, - void *arg) { - auto &prefs = get_config()->tls.alpn_prefs; - *data = prefs.data(); - *len = prefs.size(); - return SSL_TLSEXT_ERR_OK; -} -} // namespace -#endif // !OPENSSL_NO_NEXTPROTONEG - namespace { int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) { if (!preverify_ok) { @@ -177,6 +162,35 @@ int ssl_pem_passwd_cb(char *buf, int size, int rwflag, void *user_data) { } } // namespace +namespace { +std::shared_ptr> +get_ocsp_data(TLSContextData *tls_ctx_data) { +#ifdef HAVE_ATOMIC_STD_SHARED_PTR + return std::atomic_load_explicit(&tls_ctx_data->ocsp_data, + std::memory_order_acquire); +#else // !HAVE_ATOMIC_STD_SHARED_PTR + std::lock_guard g(tls_ctx_data->mu); + return tls_ctx_data->ocsp_data; +#endif // !HAVE_ATOMIC_STD_SHARED_PTR +} +} // namespace + +namespace { +void set_ocsp_response(SSL *ssl) { +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL + auto tls_ctx_data = + static_cast(SSL_CTX_get_app_data(SSL_get_SSL_CTX(ssl))); + auto data = get_ocsp_data(tls_ctx_data); + + if (!data) { + return; + } + + SSL_set_ocsp_response(ssl, data->data(), data->size()); +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL +} +} // namespace + namespace { // *al is set to SSL_AD_UNRECOGNIZED_NAME by openssl, so we don't have // to set it explicitly. @@ -187,12 +201,16 @@ int servername_callback(SSL *ssl, int *al, void *arg) { auto rawhost = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); if (rawhost == nullptr) { + set_ocsp_response(ssl); + return SSL_TLSEXT_ERR_NOACK; } auto len = strlen(rawhost); // NI_MAXHOST includes terminal NULL. if (len == 0 || len + 1 > NI_MAXHOST) { + set_ocsp_response(ssl); + return SSL_TLSEXT_ERR_NOACK; } @@ -214,6 +232,8 @@ int servername_callback(SSL *ssl, int *al, void *arg) { auto idx = cert_tree->lookup(hostname); if (idx == -1) { + set_ocsp_response(ssl); + return SSL_TLSEXT_ERR_NOACK; } @@ -231,8 +251,7 @@ int servername_callback(SSL *ssl, int *al, void *arg) { assert(!ssl_ctx_list.empty()); -#if !defined(OPENSSL_IS_BORINGSSL) && !LIBRESSL_IN_USE && \ - OPENSSL_VERSION_NUMBER >= 0x10002000L +#ifdef NGHTTP2_GENUINE_OPENSSL auto num_sigalgs = SSL_get_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr); @@ -274,12 +293,7 @@ int servername_callback(SSL *ssl, int *al, void *arg) { for (auto ssl_ctx : ssl_ctx_list) { auto cert = SSL_CTX_get0_certificate(ssl_ctx); - -# if OPENSSL_1_1_API auto pubkey = X509_get0_pubkey(cert); -# else // !OPENSSL_1_1_API - auto pubkey = X509_get_pubkey(cert); -# endif // !OPENSSL_1_1_API if (EVP_PKEY_base_id(pubkey) != EVP_PKEY_EC) { continue; @@ -296,13 +310,8 @@ int servername_callback(SSL *ssl, int *al, void *arg) { SSL_set_SSL_CTX(ssl, ssl_ctx); return SSL_TLSEXT_ERR_OK; } -# else // !OPENSSL_3_0_0_API -# if OPENSSL_1_1_API +# else // !OPENSSL_3_0_0_API auto eckey = EVP_PKEY_get0_EC_KEY(pubkey); -# else // !OPENSSL_1_1_API - auto eckey = EVP_PKEY_get1_EC_KEY(pubkey); -# endif // !OPENSSL_1_1_API - if (eckey == nullptr) { continue; } @@ -310,41 +319,24 @@ int servername_callback(SSL *ssl, int *al, void *arg) { auto ecgroup = EC_KEY_get0_group(eckey); auto cert_curve = EC_GROUP_get_curve_name(ecgroup); -# if !OPENSSL_1_1_API - EC_KEY_free(eckey); - EVP_PKEY_free(pubkey); -# endif // !OPENSSL_1_1_API - if (shared_curve == cert_curve) { SSL_set_SSL_CTX(ssl, ssl_ctx); return SSL_TLSEXT_ERR_OK; } -# endif // !OPENSSL_3_0_0_API +# endif // !OPENSSL_3_0_0_API } } -#endif // !defined(OPENSSL_IS_BORINGSSL) && !LIBRESSL_IN_USE && - // OPENSSL_VERSION_NUMBER >= 0x10002000L +#endif // NGHTTP2_GENUINE_OPENSSL SSL_set_SSL_CTX(ssl, ssl_ctx_list[0]); + set_ocsp_response(ssl); + return SSL_TLSEXT_ERR_OK; } } // namespace -#ifndef OPENSSL_IS_BORINGSSL -namespace { -std::shared_ptr> -get_ocsp_data(TLSContextData *tls_ctx_data) { -# ifdef HAVE_ATOMIC_STD_SHARED_PTR - return std::atomic_load_explicit(&tls_ctx_data->ocsp_data, - std::memory_order_acquire); -# else // !HAVE_ATOMIC_STD_SHARED_PTR - std::lock_guard g(tls_ctx_data->mu); - return tls_ctx_data->ocsp_data; -# endif // !HAVE_ATOMIC_STD_SHARED_PTR -} -} // namespace - +#ifndef NGHTTP2_OPENSSL_IS_BORINGSSL namespace { int ocsp_resp_cb(SSL *ssl, void *arg) { auto ssl_ctx = SSL_get_SSL_CTX(ssl); @@ -357,8 +349,8 @@ int ocsp_resp_cb(SSL *ssl, void *arg) { return SSL_TLSEXT_ERR_OK; } - auto buf = - static_cast(CRYPTO_malloc(data->size(), __FILE__, __LINE__)); + auto buf = static_cast( + CRYPTO_malloc(data->size(), NGHTTP2_FILE_NAME, __LINE__)); if (!buf) { return SSL_TLSEXT_ERR_OK; @@ -371,7 +363,7 @@ int ocsp_resp_cb(SSL *ssl, void *arg) { return SSL_TLSEXT_ERR_OK; } } // namespace -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL constexpr auto MEMCACHED_SESSION_CACHE_KEY_PREFIX = StringRef::from_lit("nghttpx:tls-session-cache:"); @@ -447,13 +439,8 @@ int tls_session_new_cb(SSL *ssl, SSL_SESSION *session) { } // namespace namespace { -SSL_SESSION *tls_session_get_cb(SSL *ssl, -#if OPENSSL_1_1_API || LIBRESSL_2_7_API - const unsigned char *id, -#else // !(OPENSSL_1_1_API || LIBRESSL_2_7_API) - unsigned char *id, -#endif // !(OPENSSL_1_1_API || LIBRESSL_2_7_API) - int idlen, int *copy) { +SSL_SESSION *tls_session_get_cb(SSL *ssl, const unsigned char *id, int idlen, + int *copy) { auto conn = static_cast(SSL_get_app_data(ssl)); auto handler = static_cast(conn->data); auto worker = handler->get_worker(); @@ -676,15 +663,14 @@ void info_callback(const SSL *ssl, int where, int ret) { } } // namespace -#if OPENSSL_VERSION_NUMBER >= 0x10002000L namespace { int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg) { - // We assume that get_config()->npn_list contains ALPN protocol + // We assume that get_config()->alpn_list contains ALPN protocol // identifier sorted by preference order. So we just break when we // found the first overlap. - for (const auto &target_proto_id : get_config()->tls.npn_list) { + for (const auto &target_proto_id : get_config()->tls.alpn_list) { for (auto p = in, end = in + inlen; p < end;) { auto proto_id = p + 1; auto proto_len = *p; @@ -705,10 +691,8 @@ int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, return SSL_TLSEXT_ERR_NOACK; } } // namespace -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L #ifdef ENABLE_HTTP3 -# if OPENSSL_VERSION_NUMBER >= 0x10002000L namespace { int quic_alpn_select_proto_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in, @@ -738,16 +722,9 @@ int quic_alpn_select_proto_cb(SSL *ssl, const unsigned char **out, return SSL_TLSEXT_ERR_ALERT_FATAL; } } // namespace -# endif // OPENSSL_VERSION_NUMBER >= 0x10002000L -#endif // ENABLE_HTTP3 - -#if !LIBRESSL_IN_USE && OPENSSL_VERSION_NUMBER >= 0x10002000L && \ - !defined(OPENSSL_IS_BORINGSSL) - -# ifndef TLSEXT_TYPE_signed_certificate_timestamp -# define TLSEXT_TYPE_signed_certificate_timestamp 18 -# endif // !TLSEXT_TYPE_signed_certificate_timestamp +#endif // ENABLE_HTTP3 +#ifdef NGHTTP2_GENUINE_OPENSSL namespace { int sct_add_cb(SSL *ssl, unsigned int ext_type, unsigned int context, const unsigned char **out, size_t *outlen, X509 *x, @@ -806,34 +783,7 @@ int sct_parse_cb(SSL *ssl, unsigned int ext_type, unsigned int context, } } // namespace -# if !OPENSSL_1_1_1_API - -namespace { -int legacy_sct_add_cb(SSL *ssl, unsigned int ext_type, - const unsigned char **out, size_t *outlen, int *al, - void *add_arg) { - return sct_add_cb(ssl, ext_type, 0, out, outlen, nullptr, 0, al, add_arg); -} -} // namespace - -namespace { -void legacy_sct_free_cb(SSL *ssl, unsigned int ext_type, - const unsigned char *out, void *add_arg) { - sct_free_cb(ssl, ext_type, 0, out, add_arg); -} -} // namespace - -namespace { -int legacy_sct_parse_cb(SSL *ssl, unsigned int ext_type, - const unsigned char *in, size_t inlen, int *al, - void *parse_arg) { - return sct_parse_cb(ssl, ext_type, 0, in, inlen, nullptr, 0, al, parse_arg); -} -} // namespace - -# endif // !OPENSSL_1_1_1_API -#endif // !LIBRESSL_IN_USE && OPENSSL_VERSION_NUMBER >= 0x10002000L && - // !defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_GENUINE_OPENSSL #ifndef OPENSSL_NO_PSK namespace { @@ -896,6 +846,83 @@ unsigned int psk_client_cb(SSL *ssl, const char *hint, char *identity_out, } // namespace #endif // !OPENSSL_NO_PSK +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) +namespace { +int cert_compress(SSL *ssl, CBB *out, const uint8_t *in, size_t in_len) { + uint8_t *dest; + + size_t compressed_size = BrotliEncoderMaxCompressedSize(in_len); + if (compressed_size == 0) { + LOG(ERROR) << "BrotliEncoderMaxCompressedSize failed"; + + return 0; + } + + if (LOG_ENABLED(INFO)) { + LOG(INFO) << "Maximum compressed size is " << compressed_size + << " bytes against input " << in_len << " bytes"; + } + + if (!CBB_reserve(out, &dest, compressed_size)) { + LOG(ERROR) << "CBB_reserve failed"; + + return 0; + } + + if (BrotliEncoderCompress(BROTLI_MAX_QUALITY, BROTLI_DEFAULT_WINDOW, + BROTLI_MODE_GENERIC, in_len, in, &compressed_size, + dest) != BROTLI_TRUE) { + LOG(ERROR) << "BrotliEncoderCompress failed"; + + return 0; + } + + if (LOG_ENABLED(INFO)) { + LOG(INFO) << "BrotliEncoderCompress succeeded, produced " << compressed_size + << " bytes, " << (in_len - compressed_size) * 100 / in_len + << "% reduction"; + } + + if (!CBB_did_write(out, compressed_size)) { + LOG(ERROR) << "CBB_did_write failed"; + + return 0; + } + + return 1; +} + +int cert_decompress(SSL *ssl, CRYPTO_BUFFER **out, size_t uncompressed_len, + const uint8_t *in, size_t in_len) { + uint8_t *dest; + auto buf = CRYPTO_BUFFER_alloc(&dest, uncompressed_len); + auto len = uncompressed_len; + + if (BrotliDecoderDecompress(in_len, in, &len, dest) != + BROTLI_DECODER_RESULT_SUCCESS) { + LOG(ERROR) << "BrotliDecoderDecompress failed"; + + CRYPTO_BUFFER_free(buf); + + return 0; + } + + if (uncompressed_len != len) { + LOG(ERROR) << "Unexpected uncompressed length: expected " + << uncompressed_len << " bytes, actual " << len << " bytes"; + + CRYPTO_BUFFER_free(buf); + + return 0; + } + + *out = buf; + + return 1; +} +} // namespace +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + struct TLSProtocol { StringRef name; long int mask; @@ -942,7 +969,7 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_SINGLE_ECDH_USE | SSL_OP_SINGLE_DH_USE | SSL_OP_CIPHER_SERVER_PREFERENCE -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL // The reason for disabling built-in anti-replay in // OpenSSL is that it only works if client gets back // to the same server. The freshness check @@ -950,7 +977,7 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, // https://tools.ietf.org/html/rfc8446#section-8.3 // is still performed. | SSL_OP_NO_ANTI_REPLAY -#endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_GENUINE_OPENSSL ; auto config = mod_config(); @@ -987,39 +1014,21 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, DIE(); } -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_LIBRESSL) if (SSL_CTX_set_ciphersuites(ssl_ctx, tlsconf.tls13_ciphers.c_str()) == 0) { LOG(FATAL) << "SSL_CTX_set_ciphersuites " << tlsconf.tls13_ciphers << " failed: " << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -#endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_GENUINE_OPENSSL || NGHTTP2_OPENSSL_IS_LIBRESSL #ifndef OPENSSL_NO_EC -# if !LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L if (SSL_CTX_set1_curves_list(ssl_ctx, tlsconf.ecdh_curves.c_str()) != 1) { LOG(FATAL) << "SSL_CTX_set1_curves_list " << tlsconf.ecdh_curves << " failed"; DIE(); } -# if !defined(OPENSSL_IS_BORINGSSL) && !OPENSSL_1_1_API - // It looks like we need this function call for OpenSSL 1.0.2. This - // function was deprecated in OpenSSL 1.1.0 and BoringSSL. - SSL_CTX_set_ecdh_auto(ssl_ctx, 1); -# endif // !defined(OPENSSL_IS_BORINGSSL) && !OPENSSL_1_1_API -# else // LIBRESSL_LEGACY_API || OPENSSL_VERSION_NUBMER < 0x10002000L - // Use P-256, which is sufficiently secure at the time of this - // writing. - auto ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); - if (ecdh == nullptr) { - LOG(FATAL) << "EC_KEY_new_by_curv_name failed: " - << ERR_error_string(ERR_get_error(), nullptr); - DIE(); - } - SSL_CTX_set_tmp_ecdh(ssl_ctx, ecdh); - EC_KEY_free(ecdh); -# endif // LIBRESSL_LEGACY_API || OPENSSL_VERSION_NUBMER < 0x10002000L -#endif // OPENSSL_NO_EC +#endif // OPENSSL_NO_EC if (!tlsconf.dh_param_file.empty()) { // Read DH parameters from file @@ -1141,23 +1150,17 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, #else // !OPENSSL_3_0_0_API SSL_CTX_set_tlsext_ticket_key_cb(ssl_ctx, ticket_key_cb); #endif // !OPENSSL_3_0_0_API -#ifndef OPENSSL_IS_BORINGSSL +#ifndef NGHTTP2_OPENSSL_IS_BORINGSSL SSL_CTX_set_tlsext_status_cb(ssl_ctx, ocsp_resp_cb); -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL SSL_CTX_set_info_callback(ssl_ctx, info_callback); -#ifdef OPENSSL_IS_BORINGSSL +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL SSL_CTX_set_early_data_enabled(ssl_ctx, 1); -#endif // OPENSSL_IS_BORINGSSL +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL - // NPN advertisement -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_CTX_set_next_protos_advertised_cb(ssl_ctx, next_proto_cb, nullptr); -#endif // !OPENSSL_NO_NEXTPROTONEG -#if OPENSSL_VERSION_NUMBER >= 0x10002000L // ALPN selection callback SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, nullptr); -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L auto tls_ctx_data = new TLSContextData(); tls_ctx_data->cert_file = cert_file; @@ -1165,14 +1168,12 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, SSL_CTX_set_app_data(ssl_ctx, tls_ctx_data); -#if !LIBRESSL_IN_USE && OPENSSL_VERSION_NUMBER >= 0x10002000L && \ - !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL // SSL_extension_supported(TLSEXT_TYPE_signed_certificate_timestamp) // returns 1, which means OpenSSL internally handles it. But // OpenSSL handles signed_certificate_timestamp extension specially, // and it lets custom handler to process the extension. if (!sct_data.empty()) { -# if OPENSSL_1_1_1_API // It is not entirely clear to me that SSL_EXT_CLIENT_HELLO is // required here. sct_parse_cb is called without // SSL_EXT_CLIENT_HELLO being set. But the passed context value @@ -1186,18 +1187,8 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -# else // !OPENSSL_1_1_1_API - if (SSL_CTX_add_server_custom_ext( - ssl_ctx, TLSEXT_TYPE_signed_certificate_timestamp, - legacy_sct_add_cb, legacy_sct_free_cb, nullptr, legacy_sct_parse_cb, - nullptr) != 1) { - LOG(FATAL) << "SSL_CTX_add_server_custom_ext failed: " - << ERR_error_string(ERR_get_error(), nullptr); - DIE(); - } -# endif // !OPENSSL_1_1_1_API } -#elif defined(OPENSSL_IS_BORINGSSL) +#elif defined(NGHTTP2_OPENSSL_IS_BORINGSSL) if (!tls_ctx_data->sct_data.empty() && SSL_CTX_set_signed_cert_timestamp_list( ssl_ctx, tls_ctx_data->sct_data.data(), @@ -1206,20 +1197,34 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -#endif // defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#ifdef NGHTTP2_GENUINE_OPENSSL if (SSL_CTX_set_max_early_data(ssl_ctx, tlsconf.max_early_data) != 1) { LOG(FATAL) << "SSL_CTX_set_max_early_data failed: " << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -#endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) + if (SSL_CTX_set_recv_max_early_data(ssl_ctx, tlsconf.max_early_data) != 1) { + LOG(FATAL) << "SSL_CTX_set_recv_max_early_data failed: " + << ERR_error_string(ERR_get_error(), nullptr); + DIE(); + } +#endif // NGHTTP2_GENUINE_OPENSSL #ifndef OPENSSL_NO_PSK SSL_CTX_set_psk_server_callback(ssl_ctx, psk_server_cb); #endif // !LIBRESSL_NO_PSK +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + cert_compress, cert_decompress)) { + LOG(FATAL) << "SSL_CTX_add_cert_compression_alg failed"; + DIE(); + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + return ssl_ctx; } @@ -1243,14 +1248,14 @@ SSL_CTX *create_quic_ssl_context(const char *private_key_file, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_SINGLE_ECDH_USE | SSL_OP_SINGLE_DH_USE | SSL_OP_CIPHER_SERVER_PREFERENCE -# if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +# ifdef NGHTTP2_GENUINE_OPENSSL // The reason for disabling built-in anti-replay in OpenSSL is // that it only works if client gets back to the same server. // The freshness check described in // https://tools.ietf.org/html/rfc8446#section-8.3 is still // performed. | SSL_OP_NO_ANTI_REPLAY -# endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +# endif // NGHTTP2_GENUINE_OPENSSL ; auto config = mod_config(); @@ -1283,39 +1288,21 @@ SSL_CTX *create_quic_ssl_context(const char *private_key_file, DIE(); } -# if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +# if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_LIBRESSL) if (SSL_CTX_set_ciphersuites(ssl_ctx, tlsconf.tls13_ciphers.c_str()) == 0) { LOG(FATAL) << "SSL_CTX_set_ciphersuites " << tlsconf.tls13_ciphers << " failed: " << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -# endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +# endif // NGHTTP2_GENUINE_OPENSSL || NGHTTP2_OPENSSL_IS_LIBRESSL # ifndef OPENSSL_NO_EC -# if !LIBRESSL_LEGACY_API && OPENSSL_VERSION_NUMBER >= 0x10002000L if (SSL_CTX_set1_curves_list(ssl_ctx, tlsconf.ecdh_curves.c_str()) != 1) { LOG(FATAL) << "SSL_CTX_set1_curves_list " << tlsconf.ecdh_curves << " failed"; DIE(); } -# if !defined(OPENSSL_IS_BORINGSSL) && !OPENSSL_1_1_API - // It looks like we need this function call for OpenSSL 1.0.2. This - // function was deprecated in OpenSSL 1.1.0 and BoringSSL. - SSL_CTX_set_ecdh_auto(ssl_ctx, 1); -# endif // !defined(OPENSSL_IS_BORINGSSL) && !OPENSSL_1_1_API -# else // LIBRESSL_LEGACY_API || OPENSSL_VERSION_NUBMER < 0x10002000L - // Use P-256, which is sufficiently secure at the time of this - // writing. - auto ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); - if (ecdh == nullptr) { - LOG(FATAL) << "EC_KEY_new_by_curv_name failed: " - << ERR_error_string(ERR_get_error(), nullptr); - DIE(); - } - SSL_CTX_set_tmp_ecdh(ssl_ctx, ecdh); - EC_KEY_free(ecdh); -# endif // LIBRESSL_LEGACY_API || OPENSSL_VERSION_NUBMER < 0x10002000L -# endif // OPENSSL_NO_EC +# endif // OPENSSL_NO_EC if (!tlsconf.dh_param_file.empty()) { // Read DH parameters from file @@ -1437,14 +1424,12 @@ SSL_CTX *create_quic_ssl_context(const char *private_key_file, # else // !OPENSSL_3_0_0_API SSL_CTX_set_tlsext_ticket_key_cb(ssl_ctx, ticket_key_cb); # endif // !OPENSSL_3_0_0_API -# ifndef OPENSSL_IS_BORINGSSL +# ifndef NGHTTP2_OPENSSL_IS_BORINGSSL SSL_CTX_set_tlsext_status_cb(ssl_ctx, ocsp_resp_cb); -# endif // OPENSSL_IS_BORINGSSL +# endif // NGHTTP2_OPENSSL_IS_BORINGSSL -# if OPENSSL_VERSION_NUMBER >= 0x10002000L // ALPN selection callback SSL_CTX_set_alpn_select_cb(ssl_ctx, quic_alpn_select_proto_cb, nullptr); -# endif // OPENSSL_VERSION_NUMBER >= 0x10002000L auto tls_ctx_data = new TLSContextData(); tls_ctx_data->cert_file = cert_file; @@ -1452,14 +1437,12 @@ SSL_CTX *create_quic_ssl_context(const char *private_key_file, SSL_CTX_set_app_data(ssl_ctx, tls_ctx_data); -# if !LIBRESSL_IN_USE && OPENSSL_VERSION_NUMBER >= 0x10002000L && \ - !defined(OPENSSL_IS_BORINGSSL) +# ifdef NGHTTP2_GENUINE_OPENSSL // SSL_extension_supported(TLSEXT_TYPE_signed_certificate_timestamp) // returns 1, which means OpenSSL internally handles it. But // OpenSSL handles signed_certificate_timestamp extension specially, // and it lets custom handler to process the extension. if (!sct_data.empty()) { -# if OPENSSL_1_1_1_API // It is not entirely clear to me that SSL_EXT_CLIENT_HELLO is // required here. sct_parse_cb is called without // SSL_EXT_CLIENT_HELLO being set. But the passed context value @@ -1473,18 +1456,8 @@ SSL_CTX *create_quic_ssl_context(const char *private_key_file, << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -# else // !OPENSSL_1_1_1_API - if (SSL_CTX_add_server_custom_ext( - ssl_ctx, TLSEXT_TYPE_signed_certificate_timestamp, - legacy_sct_add_cb, legacy_sct_free_cb, nullptr, legacy_sct_parse_cb, - nullptr) != 1) { - LOG(FATAL) << "SSL_CTX_add_server_custom_ext failed: " - << ERR_error_string(ERR_get_error(), nullptr); - DIE(); - } -# endif // !OPENSSL_1_1_1_API } -# elif defined(OPENSSL_IS_BORINGSSL) +# elif defined(NGHTTP2_OPENSSL_IS_BORINGSSL) if (!tls_ctx_data->sct_data.empty() && SSL_CTX_set_signed_cert_timestamp_list( ssl_ctx, tls_ctx_data->sct_data.data(), @@ -1493,9 +1466,9 @@ SSL_CTX *create_quic_ssl_context(const char *private_key_file, << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -# endif // defined(OPENSSL_IS_BORINGSSL) +# endif // NGHTTP2_OPENSSL_IS_BORINGSSL -# if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +# ifdef NGHTTP2_GENUINE_OPENSSL auto &quicconf = config->quic; if (quicconf.upstream.early_data && @@ -1505,72 +1478,31 @@ SSL_CTX *create_quic_ssl_context(const char *private_key_file, << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -# endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +# endif // NGHTTP2_GENUINE_OPENSSL # ifndef OPENSSL_NO_PSK SSL_CTX_set_psk_server_callback(ssl_ctx, psk_server_cb); # endif // !LIBRESSL_NO_PSK +# if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + cert_compress, cert_decompress)) { + LOG(FATAL) << "SSL_CTX_add_cert_compression_alg failed"; + DIE(); + } +# endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + return ssl_ctx; } #endif // ENABLE_HTTP3 -namespace { -int select_h2_next_proto_cb(SSL *ssl, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg) { - if (!util::select_h2(const_cast(out), outlen, in, - inlen)) { - return SSL_TLSEXT_ERR_NOACK; - } - - return SSL_TLSEXT_ERR_OK; -} -} // namespace - -namespace { -int select_h1_next_proto_cb(SSL *ssl, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg) { - auto end = in + inlen; - for (; in < end;) { - if (util::streq(NGHTTP2_H1_1_ALPN, StringRef{in, in + (in[0] + 1)})) { - *out = const_cast(in) + 1; - *outlen = in[0]; - return SSL_TLSEXT_ERR_OK; - } - in += in[0] + 1; - } - - return SSL_TLSEXT_ERR_NOACK; -} -} // namespace - -namespace { -int select_next_proto_cb(SSL *ssl, unsigned char **out, unsigned char *outlen, - const unsigned char *in, unsigned int inlen, - void *arg) { - auto conn = static_cast(SSL_get_app_data(ssl)); - switch (conn->proto) { - case Proto::HTTP1: - return select_h1_next_proto_cb(ssl, out, outlen, in, inlen, arg); - case Proto::HTTP2: - return select_h2_next_proto_cb(ssl, out, outlen, in, inlen, arg); - default: - return SSL_TLSEXT_ERR_NOACK; - } -} -} // namespace - SSL_CTX *create_ssl_client_context( #ifdef HAVE_NEVERBLEED neverbleed_t *nb, #endif // HAVE_NEVERBLEED const StringRef &cacert, const StringRef &cert_file, - const StringRef &private_key_file, - int (*next_proto_select_cb)(SSL *s, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg)) { + const StringRef &private_key_file) { auto ssl_ctx = SSL_CTX_new(TLS_client_method()); if (!ssl_ctx) { LOG(FATAL) << ERR_error_string(ERR_get_error(), nullptr); @@ -1607,14 +1539,14 @@ SSL_CTX *create_ssl_client_context( DIE(); } -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_LIBRESSL) if (SSL_CTX_set_ciphersuites(ssl_ctx, tlsconf.client.tls13_ciphers.c_str()) == 0) { LOG(FATAL) << "SSL_CTX_set_ciphersuites " << tlsconf.client.tls13_ciphers << " failed: " << ERR_error_string(ERR_get_error(), nullptr); DIE(); } -#endif // OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#endif // NGHTTP2_GENUINE_OPENSSL || NGHTTP2_OPENSSL_IS_LIBRESSL SSL_CTX_set_mode(ssl_ctx, SSL_MODE_RELEASE_BUFFERS); @@ -1670,11 +1602,14 @@ SSL_CTX *create_ssl_client_context( SSL_CTX_set_psk_client_callback(ssl_ctx, psk_client_cb); #endif // !OPENSSL_NO_PSK - // NPN selection callback. This is required to set SSL_CTX because - // OpenSSL does not offer SSL_set_next_proto_select_cb. -#ifndef OPENSSL_NO_NEXTPROTONEG - SSL_CTX_set_next_proto_select_cb(ssl_ctx, next_proto_select_cb, nullptr); -#endif // !OPENSSL_NO_NEXTPROTONEG +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + cert_compress, cert_decompress)) { + LOG(FATAL) << "SSL_CTX_add_cert_compression_alg failed"; + DIE(); + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI return ssl_ctx; } @@ -2116,16 +2051,7 @@ int cert_lookup_tree_add_ssl_ctx( SSL_CTX *ssl_ctx) { std::array buf; -#if LIBRESSL_2_7_API || \ - (!LIBRESSL_IN_USE && OPENSSL_VERSION_NUMBER >= 0x10002000L) auto cert = SSL_CTX_get0_certificate(ssl_ctx); -#else // !LIBRESSL_2_7_API && OPENSSL_VERSION_NUMBER < 0x10002000L - auto tls_ctx_data = - static_cast(SSL_CTX_get_app_data(ssl_ctx)); - auto cert = load_certificate(tls_ctx_data->cert_file); - auto cert_deleter = defer(X509_free, cert); -#endif // !LIBRESSL_2_7_API && OPENSSL_VERSION_NUMBER < 0x10002000L - auto altnames = static_cast( X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr)); if (altnames) { @@ -2389,23 +2315,19 @@ SSL_CTX *setup_downstream_client_ssl_context( #ifdef HAVE_NEVERBLEED nb, #endif // HAVE_NEVERBLEED - tlsconf.cacert, tlsconf.client.cert_file, tlsconf.client.private_key_file, - select_next_proto_cb); + tlsconf.cacert, tlsconf.client.cert_file, + tlsconf.client.private_key_file); } void setup_downstream_http2_alpn(SSL *ssl) { -#if OPENSSL_VERSION_NUMBER >= 0x10002000L // ALPN advertisement auto alpn = util::get_default_alpn(); SSL_set_alpn_protos(ssl, alpn.data(), alpn.size()); -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L } void setup_downstream_http1_alpn(SSL *ssl) { -#if OPENSSL_VERSION_NUMBER >= 0x10002000L // ALPN advertisement SSL_set_alpn_protos(ssl, NGHTTP2_H1_1_ALPN.byte(), NGHTTP2_H1_1_ALPN.size()); -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L } std::unique_ptr create_cert_lookup_tree() { @@ -2474,9 +2396,7 @@ int proto_version_from_string(const StringRef &v) { int verify_ocsp_response(SSL_CTX *ssl_ctx, const uint8_t *ocsp_resp, size_t ocsp_resplen) { - -#if !defined(OPENSSL_NO_OCSP) && !LIBRESSL_IN_USE && \ - OPENSSL_VERSION_NUMBER >= 0x10002000L +#ifndef OPENSSL_NO_OCSP int rv; STACK_OF(X509) * chain_certs; @@ -2522,11 +2442,7 @@ int verify_ocsp_response(SSL_CTX *ssl_ctx, const uint8_t *ocsp_resp, return -1; } -# if OPENSSL_1_1_API auto certid = OCSP_SINGLERESP_get0_id(sresp); -# else // !OPENSSL_1_1_API - auto certid = sresp->certId; -# endif // !OPENSSL_1_1_API assert(certid != nullptr); ASN1_INTEGER *serial; @@ -2553,8 +2469,7 @@ int verify_ocsp_response(SSL_CTX *ssl_ctx, const uint8_t *ocsp_resp, if (LOG_ENABLED(INFO)) { LOG(INFO) << "OCSP verification succeeded"; } -#endif // !defined(OPENSSL_NO_OCSP) && !LIBRESSL_IN_USE - // && OPENSSL_VERSION_NUMBER >= 0x10002000L +#endif // !OPENSSL_NO_OCSP return 0; } @@ -2620,7 +2535,7 @@ namespace { int time_t_from_asn1_time(time_t &t, const ASN1_TIME *at) { int rv; -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_LIBRESSL) struct tm tm; rv = ASN1_TIME_to_tm(at, &tm); if (rv != 1) { @@ -2628,7 +2543,7 @@ int time_t_from_asn1_time(time_t &t, const ASN1_TIME *at) { } t = nghttp2_timegm(&tm); -#else // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#else // !NGHTTP2_GENUINE_OPENSSL && !NGHTTP2_OPENSSL_IS_LIBRESSL auto b = BIO_new(BIO_s_mem()); if (!b) { return -1; @@ -2641,7 +2556,7 @@ int time_t_from_asn1_time(time_t &t, const ASN1_TIME *at) { return -1; } -# ifdef OPENSSL_IS_BORINGSSL +# ifdef NGHTTP2_OPENSSL_IS_BORINGSSL char *s; # else unsigned char *s; @@ -2654,18 +2569,14 @@ int time_t_from_asn1_time(time_t &t, const ASN1_TIME *at) { } t = tt; -#endif // !(OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL)) +#endif // !NGHTTP2_GENUINE_OPENSSL && !NGHTTP2_OPENSSL_IS_LIBRESSL return 0; } } // namespace int get_x509_not_before(time_t &t, X509 *x) { -#if OPENSSL_1_1_API auto at = X509_get0_notBefore(x); -#else // !OPENSSL_1_1_API - auto at = X509_get_notBefore(x); -#endif // !OPENSSL_1_1_API if (!at) { return -1; } @@ -2674,11 +2585,7 @@ int get_x509_not_before(time_t &t, X509 *x) { } int get_x509_not_after(time_t &t, X509 *x) { -#if OPENSSL_1_1_API auto at = X509_get0_notAfter(x); -#else // !OPENSSL_1_1_API - auto at = X509_get_notAfter(x); -#endif // !OPENSSL_1_1_API if (!at) { return -1; } diff --git a/yass/third_party/nghttp2/src/shrpx_tls.h b/yass/third_party/nghttp2/src/shrpx_tls.h index 00265d55d7..f740507b72 100644 --- a/yass/third_party/nghttp2/src/shrpx_tls.h +++ b/yass/third_party/nghttp2/src/shrpx_tls.h @@ -89,28 +89,12 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, ); // Create client side SSL_CTX. This does not configure ALPN settings. -// |next_proto_select_cb| is for NPN. SSL_CTX *create_ssl_client_context( #ifdef HAVE_NEVERBLEED neverbleed_t *nb, #endif // HAVE_NEVERBLEED const StringRef &cacert, const StringRef &cert_file, - const StringRef &private_key_file, - int (*next_proto_select_cb)(SSL *s, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg)); - -#ifdef ENABLE_HTTP3 -SSL_CTX *create_quic_ssl_client_context( -# ifdef HAVE_NEVERBLEED - neverbleed_t *nb, -# endif // HAVE_NEVERBLEED - const StringRef &cacert, const StringRef &cert_file, - const StringRef &private_key_file, - int (*next_proto_select_cb)(SSL *s, unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg)); -#endif // ENABLE_HTTP3 + const StringRef &private_key_file); ClientHandler *accept_connection(Worker *worker, int fd, sockaddr *addr, int addrlen, const UpstreamAddr *faddr); diff --git a/yass/third_party/nghttp2/src/shrpx_tls_test.cc b/yass/third_party/nghttp2/src/shrpx_tls_test.cc index 02fb1681fa..04d16daa3b 100644 --- a/yass/third_party/nghttp2/src/shrpx_tls_test.cc +++ b/yass/third_party/nghttp2/src/shrpx_tls_test.cc @@ -24,7 +24,7 @@ */ #include "shrpx_tls_test.h" -#include +#include "munitxx.h" #include "shrpx_tls.h" #include "shrpx_log.h" @@ -35,6 +35,21 @@ using namespace nghttp2; namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_tls_create_lookup_tree), + munit_void_test(test_shrpx_tls_cert_lookup_tree_add_ssl_ctx), + munit_void_test(test_shrpx_tls_tls_hostname_match), + munit_void_test(test_shrpx_tls_verify_numeric_hostname), + munit_void_test(test_shrpx_tls_verify_dns_hostname), + munit_test_end(), +}; +} // namespace + +const MunitSuite tls_suite{ + "/tls", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_tls_create_lookup_tree(void) { auto tree = std::make_unique(); @@ -58,24 +73,24 @@ void test_shrpx_tls_create_lookup_tree(void) { tree->dump(); - CU_ASSERT(0 == tree->lookup(hostnames[0])); - CU_ASSERT(1 == tree->lookup(hostnames[1])); - CU_ASSERT(2 == tree->lookup(StringRef::from_lit("2www.example.org"))); - CU_ASSERT(-1 == tree->lookup(StringRef::from_lit("www2.example.org"))); - CU_ASSERT(3 == tree->lookup(StringRef::from_lit("xy1.host.domain"))); + assert_ssize(0, ==, tree->lookup(hostnames[0])); + assert_ssize(1, ==, tree->lookup(hostnames[1])); + assert_ssize(2, ==, tree->lookup(StringRef::from_lit("2www.example.org"))); + assert_ssize(-1, ==, tree->lookup(StringRef::from_lit("www2.example.org"))); + assert_ssize(3, ==, tree->lookup(StringRef::from_lit("xy1.host.domain"))); // Does not match *yy.host.domain, because * must match at least 1 // character. - CU_ASSERT(-1 == tree->lookup(StringRef::from_lit("yy.host.domain"))); - CU_ASSERT(4 == tree->lookup(StringRef::from_lit("xyy.host.domain"))); - CU_ASSERT(-1 == tree->lookup(StringRef{})); - CU_ASSERT(5 == tree->lookup(hostnames[5])); - CU_ASSERT(6 == tree->lookup(hostnames[6])); + assert_ssize(-1, ==, tree->lookup(StringRef::from_lit("yy.host.domain"))); + assert_ssize(4, ==, tree->lookup(StringRef::from_lit("xyy.host.domain"))); + assert_ssize(-1, ==, tree->lookup(StringRef{})); + assert_ssize(5, ==, tree->lookup(hostnames[5])); + assert_ssize(6, ==, tree->lookup(hostnames[6])); static constexpr char h6[] = "pdylay.sourceforge.net"; for (int i = 0; i < 7; ++i) { - CU_ASSERT(-1 == tree->lookup(StringRef{h6 + i, str_size(h6) - i})); + assert_ssize(-1, ==, tree->lookup(StringRef{h6 + i, str_size(h6) - i})); } - CU_ASSERT(8 == tree->lookup(StringRef::from_lit("x.foo.bar"))); - CU_ASSERT(9 == tree->lookup(hostnames[9])); + assert_ssize(8, ==, tree->lookup(StringRef::from_lit("x.foo.bar"))); + assert_ssize(9, ==, tree->lookup(hostnames[9])); constexpr StringRef names[] = { StringRef::from_lit("rab"), // 1 @@ -90,7 +105,7 @@ void test_shrpx_tls_create_lookup_tree(void) { tree->add_cert(names[idx], idx); } for (size_t i = 0; i < num; ++i) { - CU_ASSERT((ssize_t)i == tree->lookup(names[i])); + assert_ssize((ssize_t)i, ==, tree->lookup(names[i])); } } @@ -128,7 +143,7 @@ void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void) { SSL_CTX_set_app_data(nghttp2_ssl_ctx, nghttp2_tls_ctx_data.get()); rv = SSL_CTX_use_certificate_chain_file(nghttp2_ssl_ctx, nghttp2_certfile); - CU_ASSERT(1 == rv); + assert_int(1, ==, rv); static constexpr char examples_certfile[] = NGHTTP2_SRC_DIR "/test.example.com.pem"; @@ -139,7 +154,7 @@ void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void) { SSL_CTX_set_app_data(examples_ssl_ctx, examples_tls_ctx_data.get()); rv = SSL_CTX_use_certificate_chain_file(examples_ssl_ctx, examples_certfile); - CU_ASSERT(1 == rv); + assert_int(1, ==, rv); tls::CertLookupTree tree; std::vector> indexed_ssl_ctx; @@ -147,18 +162,19 @@ void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void) { rv = tls::cert_lookup_tree_add_ssl_ctx(&tree, indexed_ssl_ctx, nghttp2_ssl_ctx); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = tls::cert_lookup_tree_add_ssl_ctx(&tree, indexed_ssl_ctx, examples_ssl_ctx); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(-1 == tree.lookup(StringRef::from_lit("not-used.nghttp2.org"))); - CU_ASSERT(0 == tree.lookup(StringRef::from_lit("test.nghttp2.org"))); - CU_ASSERT(1 == tree.lookup(StringRef::from_lit("w.test.nghttp2.org"))); - CU_ASSERT(2 == tree.lookup(StringRef::from_lit("www.test.nghttp2.org"))); - CU_ASSERT(3 == tree.lookup(StringRef::from_lit("test.example.com"))); + assert_ssize(-1, ==, + tree.lookup(StringRef::from_lit("not-used.nghttp2.org"))); + assert_ssize(0, ==, tree.lookup(StringRef::from_lit("test.nghttp2.org"))); + assert_ssize(1, ==, tree.lookup(StringRef::from_lit("w.test.nghttp2.org"))); + assert_ssize(2, ==, tree.lookup(StringRef::from_lit("www.test.nghttp2.org"))); + assert_ssize(3, ==, tree.lookup(StringRef::from_lit("test.example.com"))); } template @@ -168,30 +184,32 @@ bool tls_hostname_match_wrapper(const char (&pattern)[N], } void test_shrpx_tls_tls_hostname_match(void) { - CU_ASSERT(tls_hostname_match_wrapper("example.com", "example.com")); - CU_ASSERT(tls_hostname_match_wrapper("example.com", "EXAMPLE.com")); + assert_true(tls_hostname_match_wrapper("example.com", "example.com")); + assert_true(tls_hostname_match_wrapper("example.com", "EXAMPLE.com")); // check wildcard - CU_ASSERT(tls_hostname_match_wrapper("*.example.com", "www.example.com")); - CU_ASSERT(tls_hostname_match_wrapper("*w.example.com", "www.example.com")); - CU_ASSERT(tls_hostname_match_wrapper("www*.example.com", "www1.example.com")); - CU_ASSERT( + assert_true(tls_hostname_match_wrapper("*.example.com", "www.example.com")); + assert_true(tls_hostname_match_wrapper("*w.example.com", "www.example.com")); + assert_true( + tls_hostname_match_wrapper("www*.example.com", "www1.example.com")); + assert_true( tls_hostname_match_wrapper("www*.example.com", "WWW12.EXAMPLE.com")); // at least 2 dots are required after '*' - CU_ASSERT(!tls_hostname_match_wrapper("*.com", "example.com")); - CU_ASSERT(!tls_hostname_match_wrapper("*", "example.com")); + assert_false(tls_hostname_match_wrapper("*.com", "example.com")); + assert_false(tls_hostname_match_wrapper("*", "example.com")); // '*' must be in left most label - CU_ASSERT( - !tls_hostname_match_wrapper("blog.*.example.com", "blog.my.example.com")); + assert_false( + tls_hostname_match_wrapper("blog.*.example.com", "blog.my.example.com")); // prefix is wrong - CU_ASSERT( - !tls_hostname_match_wrapper("client*.example.com", "server.example.com")); + assert_false( + tls_hostname_match_wrapper("client*.example.com", "server.example.com")); // '*' must match at least one character - CU_ASSERT(!tls_hostname_match_wrapper("www*.example.com", "www.example.com")); + assert_false( + tls_hostname_match_wrapper("www*.example.com", "www.example.com")); - CU_ASSERT(!tls_hostname_match_wrapper("example.com", "nghttp2.org")); - CU_ASSERT(!tls_hostname_match_wrapper("www.example.com", "example.com")); - CU_ASSERT(!tls_hostname_match_wrapper("example.com", "www.example.com")); + assert_false(tls_hostname_match_wrapper("example.com", "nghttp2.org")); + assert_false(tls_hostname_match_wrapper("www.example.com", "example.com")); + assert_false(tls_hostname_match_wrapper("example.com", "www.example.com")); } static X509 *load_cert(const char *path) { @@ -207,14 +225,17 @@ static Address parse_addr(const char *ipaddr) { addrinfo hints{}; hints.ai_family = AF_UNSPEC; - hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; + hints.ai_flags = AI_NUMERICHOST; +#ifdef AI_NUMERICSERV + hints.ai_flags |= AI_NUMERICSERV; +#endif addrinfo *res = nullptr; auto rv = getaddrinfo(ipaddr, "443", &hints, &res); - CU_ASSERT(0 == rv); - CU_ASSERT(nullptr != res); + assert_int(0, ==, rv); + assert_not_null(res); Address addr; addr.len = res->ai_addrlen; @@ -234,7 +255,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -247,7 +268,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -260,7 +281,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(-1 == rv); + assert_int(-1, ==, rv); X509_free(cert); } @@ -273,7 +294,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(-1 == rv); + assert_int(-1, ==, rv); X509_free(cert); } @@ -286,7 +307,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -299,7 +320,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { auto rv = tls::verify_dns_hostname( cert, StringRef::from_lit("nghttp2.example.com")); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -310,7 +331,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { auto rv = tls::verify_dns_hostname( cert, StringRef::from_lit("www.nghttp2.example.com")); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -320,7 +341,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/verify_hostname.crt"); auto rv = tls::verify_dns_hostname(cert, StringRef::from_lit("localhost")); - CU_ASSERT(-1 == rv); + assert_int(-1, ==, rv); X509_free(cert); } @@ -330,7 +351,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/nosan.crt"); auto rv = tls::verify_dns_hostname(cert, StringRef::from_lit("localhost")); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } diff --git a/yass/third_party/nghttp2/src/shrpx_tls_test.h b/yass/third_party/nghttp2/src/shrpx_tls_test.h index 7edc742b7f..3334b237d1 100644 --- a/yass/third_party/nghttp2/src/shrpx_tls_test.h +++ b/yass/third_party/nghttp2/src/shrpx_tls_test.h @@ -29,13 +29,19 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_tls_create_lookup_tree(void); -void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void); -void test_shrpx_tls_tls_hostname_match(void); -void test_shrpx_tls_verify_numeric_hostname(void); -void test_shrpx_tls_verify_dns_hostname(void); +extern const MunitSuite tls_suite; + +munit_void_test_decl(test_shrpx_tls_create_lookup_tree); +munit_void_test_decl(test_shrpx_tls_cert_lookup_tree_add_ssl_ctx); +munit_void_test_decl(test_shrpx_tls_tls_hostname_match); +munit_void_test_decl(test_shrpx_tls_verify_numeric_hostname); +munit_void_test_decl(test_shrpx_tls_verify_dns_hostname); } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_worker.cc b/yass/third_party/nghttp2/src/shrpx_worker.cc index 567fc20df3..9f5911fdae 100644 --- a/yass/third_party/nghttp2/src/shrpx_worker.cc +++ b/yass/third_party/nghttp2/src/shrpx_worker.cc @@ -148,7 +148,7 @@ Worker::Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx, tls::CertLookupTree *cert_tree, #ifdef ENABLE_HTTP3 SSL_CTX *quic_sv_ssl_ctx, tls::CertLookupTree *quic_cert_tree, - const uint8_t *cid_prefix, size_t cid_prefixlen, + WorkerID wid, # ifdef HAVE_LIBBPF size_t index, # endif // HAVE_LIBBPF @@ -164,6 +164,7 @@ Worker::Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx, worker_stat_{}, dns_tracker_(loop, get_config()->conn.downstream->family), #ifdef ENABLE_HTTP3 + worker_id_{std::move(wid)}, quic_upstream_addrs_{get_config()->conn.quic_listener.addrs}, #endif // ENABLE_HTTP3 loop_(loop), @@ -180,10 +181,6 @@ Worker::Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx, connect_blocker_( std::make_unique(randgen_, loop_, nullptr, nullptr)), graceful_shutdown_(false) { -#ifdef ENABLE_HTTP3 - std::copy_n(cid_prefix, cid_prefixlen, std::begin(cid_prefix_)); -#endif // ENABLE_HTTP3 - ev_async_init(&w_, eventcb); w_.data = this; ev_async_start(loop_, &w_); @@ -399,7 +396,7 @@ void Worker::replace_downstream_config( } } - dst->shared_addr = shared_addr; + dst->shared_addr = std::move(shared_addr); addr_groups_indexer.emplace(std::move(dkey), i); } else { @@ -507,7 +504,7 @@ void Worker::process_events() { } if (LOG_ENABLED(INFO)) { - WLOG(INFO, this) << "CLIENT_HANDLER:" << client_handler << " created "; + WLOG(INFO, this) << "CLIENT_HANDLER:" << client_handler << " created"; } break; @@ -602,9 +599,7 @@ void Worker::set_ticket_keys(std::shared_ptr ticket_keys) { WorkerStat *Worker::get_worker_stat() { return &worker_stat_; } -struct ev_loop *Worker::get_loop() const { - return loop_; -} +struct ev_loop *Worker::get_loop() const { return loop_; } SSL_CTX *Worker::get_sv_ssl_ctx() const { return sv_ssl_ctx_; } @@ -733,6 +728,119 @@ int Worker::setup_quic_server_socket() { return 0; } +# ifdef HAVE_LIBBPF +namespace { +// https://github.com/kokke/tiny-AES-c +// +// License is Public Domain. +// Commit hash: 12e7744b4919e9d55de75b7ab566326a1c8e7a67 + +// The number of columns comprising a state in AES. This is a constant +// in AES. Value=4 +# define Nb 4 + +# define Nk 4 // The number of 32 bit words in a key. +# define Nr 10 // The number of rounds in AES Cipher. + +// The lookup-tables are marked const so they can be placed in +// read-only storage instead of RAM The numbers below can be computed +// dynamically trading ROM for RAM - This can be useful in (embedded) +// bootloader applications, where ROM is often limited. +const uint8_t sbox[256] = { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, + 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, + 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, + 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, + 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, + 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, + 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, + 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, + 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, + 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, + 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, + 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, + 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, + 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, + 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, + 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, + 0xb0, 0x54, 0xbb, 0x16}; + +# define getSBoxValue(num) (sbox[(num)]) + +// The round constant word array, Rcon[i], contains the values given +// by x to the power (i-1) being powers of x (x is denoted as {02}) in +// the field GF(2^8) +const uint8_t Rcon[11] = {0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, + 0x20, 0x40, 0x80, 0x1b, 0x36}; + +// This function produces Nb(Nr+1) round keys. The round keys are used +// in each round to decrypt the states. +void KeyExpansion(uint8_t *RoundKey, const uint8_t *Key) { + unsigned i, j, k; + uint8_t tempa[4]; // Used for the column/row operations + + // The first round key is the key itself. + for (i = 0; i < Nk; ++i) { + RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; + RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; + RoundKey[(i * 4) + 2] = Key[(i * 4) + 2]; + RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; + } + + // All other round keys are found from the previous round keys. + for (i = Nk; i < Nb * (Nr + 1); ++i) { + { + k = (i - 1) * 4; + tempa[0] = RoundKey[k + 0]; + tempa[1] = RoundKey[k + 1]; + tempa[2] = RoundKey[k + 2]; + tempa[3] = RoundKey[k + 3]; + } + + if (i % Nk == 0) { + // This function shifts the 4 bytes in a word to the left once. + // [a0,a1,a2,a3] becomes [a1,a2,a3,a0] + + // Function RotWord() + { + const uint8_t u8tmp = tempa[0]; + tempa[0] = tempa[1]; + tempa[1] = tempa[2]; + tempa[2] = tempa[3]; + tempa[3] = u8tmp; + } + + // SubWord() is a function that takes a four-byte input word and + // applies the S-box to each of the four bytes to produce an + // output word. + + // Function Subword() + { + tempa[0] = getSBoxValue(tempa[0]); + tempa[1] = getSBoxValue(tempa[1]); + tempa[2] = getSBoxValue(tempa[2]); + tempa[3] = getSBoxValue(tempa[3]); + } + + tempa[0] = tempa[0] ^ Rcon[i / Nk]; + } + j = i * 4; + k = (i - Nk) * 4; + RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; + RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; + RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; + RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3]; + } +} +} // namespace +# endif // HAVE_LIBBPF + int Worker::create_quic_server_socket(UpstreamAddr &faddr) { std::array errbuf; int fd = -1; @@ -960,10 +1068,10 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) { return -1; } - ref.cid_prefix_map = bpf_object__find_map_by_name(obj, "cid_prefix_map"); - if (!ref.cid_prefix_map) { + ref.worker_id_map = bpf_object__find_map_by_name(obj, "worker_id_map"); + if (!ref.worker_id_map) { auto error = errno; - LOG(FATAL) << "Failed to get cid_prefix_map: " + LOG(FATAL) << "Failed to get worker_id_map: " << xsi_strerror(error, errbuf.data(), errbuf.size()); close(fd); return -1; @@ -991,30 +1099,29 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) { return -1; } - constexpr uint32_t key_high_idx = 1; - constexpr uint32_t key_low_idx = 2; - auto &qkms = conn_handler_->get_quic_keying_materials(); auto &qkm = qkms->keying_materials.front(); - rv = bpf_map__update_elem(sk_info, &key_high_idx, sizeof(key_high_idx), - qkm.cid_encryption_key.data(), - qkm.cid_encryption_key.size() / 2, BPF_ANY); - if (rv != 0) { + auto aes_key = bpf_object__find_map_by_name(obj, "aes_key"); + if (!aes_key) { auto error = errno; - LOG(FATAL) << "Failed to update key_high_idx sk_info: " + LOG(FATAL) << "Failed to get aes_key: " << xsi_strerror(error, errbuf.data(), errbuf.size()); close(fd); return -1; } - rv = bpf_map__update_elem(sk_info, &key_low_idx, sizeof(key_low_idx), - qkm.cid_encryption_key.data() + - qkm.cid_encryption_key.size() / 2, - qkm.cid_encryption_key.size() / 2, BPF_ANY); + constexpr size_t expanded_aes_keylen = 176; + std::array aes_exp_key; + + KeyExpansion(aes_exp_key.data(), qkm.cid_encryption_key.data()); + + rv = + bpf_map__update_elem(aes_key, &zero, sizeof(zero), aes_exp_key.data(), + aes_exp_key.size(), BPF_ANY); if (rv != 0) { auto error = errno; - LOG(FATAL) << "Failed to update key_low_idx sk_info: " + LOG(FATAL) << "Failed to update aes_key: " << xsi_strerror(error, errbuf.data(), errbuf.size()); close(fd); return -1; @@ -1045,12 +1152,12 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) { return -1; } - rv = bpf_map__update_elem(ref.cid_prefix_map, cid_prefix_.data(), - cid_prefix_.size(), &sk_index, sizeof(sk_index), + rv = bpf_map__update_elem(ref.worker_id_map, &worker_id_, + sizeof(worker_id_), &sk_index, sizeof(sk_index), BPF_NOEXIST); if (rv != 0) { auto error = errno; - LOG(FATAL) << "Failed to update cid_prefix_map: " + LOG(FATAL) << "Failed to update worker_id_map: " << xsi_strerror(error, errbuf.data(), errbuf.size()); close(fd); return -1; @@ -1077,7 +1184,7 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) { return 0; } -const uint8_t *Worker::get_cid_prefix() const { return cid_prefix_.data(); } +const WorkerID &Worker::get_worker_id() const { return worker_id_; } const UpstreamAddr *Worker::find_quic_upstream_addr(const Address &local_addr) { std::array host; @@ -1334,16 +1441,4 @@ void downstream_failure(DownstreamAddr *addr, const Address *raddr) { } } -#ifdef ENABLE_HTTP3 -int create_cid_prefix(uint8_t *cid_prefix, const uint8_t *server_id) { - auto p = std::copy_n(server_id, SHRPX_QUIC_SERVER_IDLEN, cid_prefix); - - if (RAND_bytes(p, SHRPX_QUIC_CID_PREFIXLEN - SHRPX_QUIC_SERVER_IDLEN) != 1) { - return -1; - } - - return 0; -} -#endif // ENABLE_HTTP3 - } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_worker.h b/yass/third_party/nghttp2/src/shrpx_worker.h index 3cc7b57623..f8a2d84d76 100644 --- a/yass/third_party/nghttp2/src/shrpx_worker.h +++ b/yass/third_party/nghttp2/src/shrpx_worker.h @@ -312,7 +312,7 @@ public: tls::CertLookupTree *cert_tree, #ifdef ENABLE_HTTP3 SSL_CTX *quic_sv_ssl_ctx, tls::CertLookupTree *quic_cert_tree, - const uint8_t *cid_prefix, size_t cid_prefixlen, + WorkerID wid, # ifdef HAVE_LIBBPF size_t index, # endif // HAVE_LIBBPF @@ -377,7 +377,7 @@ public: int setup_quic_server_socket(); - const uint8_t *get_cid_prefix() const; + const WorkerID &get_worker_id() const; # ifdef HAVE_LIBBPF bool should_attach_bpf() const; @@ -414,7 +414,7 @@ private: DNSTracker dns_tracker_; #ifdef ENABLE_HTTP3 - std::array cid_prefix_; + WorkerID worker_id_; std::vector quic_upstream_addrs_; std::vector> quic_listeners_; #endif // ENABLE_HTTP3 @@ -468,13 +468,6 @@ size_t match_downstream_addr_group( // nullptr. This function may schedule live check. void downstream_failure(DownstreamAddr *addr, const Address *raddr); -#ifdef ENABLE_HTTP3 -// Creates unpredictable SHRPX_QUIC_CID_PREFIXLEN bytes sequence which -// is used as a prefix of QUIC Connection ID. This function returns -// -1 on failure. |server_id| must be 2 bytes long. -int create_cid_prefix(uint8_t *cid_prefix, const uint8_t *server_id); -#endif // ENABLE_HTTP3 - } // namespace shrpx #endif // SHRPX_WORKER_H diff --git a/yass/third_party/nghttp2/src/shrpx_worker_process.cc b/yass/third_party/nghttp2/src/shrpx_worker_process.cc index 33ef29c47c..6591e9bd7d 100644 --- a/yass/third_party/nghttp2/src/shrpx_worker_process.cc +++ b/yass/third_party/nghttp2/src/shrpx_worker_process.cc @@ -398,7 +398,7 @@ void nb_child_cb(struct ev_loop *loop, ev_child *w, int revents) { ev_child_stop(loop, w); - LOG(FATAL) << "neverbleed process exitted; aborting now"; + LOG(FATAL) << "neverbleed process exited; aborting now"; nghttp2_Exit(EXIT_FAILURE); } @@ -583,11 +583,31 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) { LOG(ERROR) << "Failed to generate QUIC Connection ID encryption key"; return -1; } + + qkm.cid_encryption_ctx = EVP_CIPHER_CTX_new(); + if (!EVP_EncryptInit_ex(qkm.cid_encryption_ctx, EVP_aes_128_ecb(), nullptr, + qkm.cid_encryption_key.data(), nullptr)) { + LOG(ERROR) + << "Failed to initialize QUIC Connection ID encryption context"; + return -1; + } + + EVP_CIPHER_CTX_set_padding(qkm.cid_encryption_ctx, 0); + + qkm.cid_decryption_ctx = EVP_CIPHER_CTX_new(); + if (!EVP_DecryptInit_ex(qkm.cid_decryption_ctx, EVP_aes_128_ecb(), nullptr, + qkm.cid_encryption_key.data(), nullptr)) { + LOG(ERROR) + << "Failed to initialize QUIC Connection ID decryption context"; + return -1; + } + + EVP_CIPHER_CTX_set_padding(qkm.cid_decryption_ctx, 0); } conn_handler->set_quic_keying_materials(std::move(qkms)); - conn_handler->set_cid_prefixes(wpconf->cid_prefixes); + conn_handler->set_worker_ids(wpconf->worker_ids); conn_handler->set_quic_lingering_worker_processes( wpconf->quic_lingering_worker_processes); #endif // ENABLE_HTTP3 diff --git a/yass/third_party/nghttp2/src/shrpx_worker_process.h b/yass/third_party/nghttp2/src/shrpx_worker_process.h index f4325031b4..155b565e73 100644 --- a/yass/third_party/nghttp2/src/shrpx_worker_process.h +++ b/yass/third_party/nghttp2/src/shrpx_worker_process.h @@ -49,8 +49,8 @@ struct WorkerProcessConfig { // IPv6 socket, or -1 if not used int server_fd6; #ifdef ENABLE_HTTP3 - // CID prefixes for the new worker process. - std::vector> cid_prefixes; + // Worker IDs for the new worker process. + std::vector worker_ids; // IPC socket to read forwarded QUIC UDP datagram from the current // worker process. int quic_ipc_fd; diff --git a/yass/third_party/nghttp2/src/shrpx_worker_test.cc b/yass/third_party/nghttp2/src/shrpx_worker_test.cc index 7c5c3299ec..4b4b7a6461 100644 --- a/yass/third_party/nghttp2/src/shrpx_worker_test.cc +++ b/yass/third_party/nghttp2/src/shrpx_worker_test.cc @@ -30,7 +30,7 @@ #include -#include +#include "munitxx.h" #include "shrpx_worker.h" #include "shrpx_connect_blocker.h" @@ -38,6 +38,17 @@ namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_worker_match_downstream_addr_group), + munit_test_end(), +}; +} // namespace + +const MunitSuite worker_suite{ + "/worker", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_worker_match_downstream_addr_group(void) { auto groups = std::vector>(); for (auto &s : {"nghttp2.org/", "nghttp2.org/alpha/bravo/", @@ -62,131 +73,155 @@ void test_shrpx_worker_match_downstream_addr_group(void) { router.add_route(StringRef{g->pattern}, i); } - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/"), groups, 255, balloc)); // port is removed - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org:8080"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org:8080"), + StringRef::from_lit("/"), groups, 255, balloc)); // host is case-insensitive - CU_ASSERT(4 == match_downstream_addr_group( - routerconf, StringRef::from_lit("WWW.nghttp2.org"), - StringRef::from_lit("/alpha"), groups, 255, balloc)); + assert_size(4, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("WWW.nghttp2.org"), + StringRef::from_lit("/alpha"), groups, 255, balloc)); - CU_ASSERT(1 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo/"), groups, 255, - balloc)); + assert_size(1, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo/"), groups, 255, balloc)); // /alpha/bravo also matches /alpha/bravo/ - CU_ASSERT(1 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); + assert_size(1, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); // path part is case-sensitive - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/Alpha/bravo"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/Alpha/bravo"), groups, 255, balloc)); - CU_ASSERT(1 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo/charlie"), groups, 255, - balloc)); + assert_size(1, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo/charlie"), groups, 255, + balloc)); - CU_ASSERT(2 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/charlie"), groups, 255, - balloc)); + assert_size(2, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/charlie"), groups, 255, balloc)); // pattern which does not end with '/' must match its entirely. So // this matches to group 0, not group 2. - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/charlie/"), groups, 255, - balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/charlie/"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("example.org"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("example.org"), + StringRef::from_lit("/"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit(""), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group(routerconf, StringRef::from_lit(""), + StringRef::from_lit("/"), groups, 255, + balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit(""), - StringRef::from_lit("alpha"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group(routerconf, StringRef::from_lit(""), + StringRef::from_lit("alpha"), groups, + 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("foo/bar"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("foo/bar"), + StringRef::from_lit("/"), groups, 255, balloc)); // If path is StringRef::from_lit("*", only match with host + "/"). - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("*"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("*"), groups, 255, balloc)); - CU_ASSERT(5 == match_downstream_addr_group( - routerconf, StringRef::from_lit("[::1]"), - StringRef::from_lit("/"), groups, 255, balloc)); - CU_ASSERT(5 == match_downstream_addr_group( - routerconf, StringRef::from_lit("[::1]:8080"), - StringRef::from_lit("/"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("[::1"), - StringRef::from_lit("/"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("[::1]8000"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(5, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("[::1]"), + StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(5, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("[::1]:8080"), + StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("[::1"), + StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("[::1]8000"), + StringRef::from_lit("/"), groups, 255, balloc)); // Check the case where adding route extends tree - CU_ASSERT(6 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo/delta"), groups, 255, - balloc)); + assert_size(6, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo/delta"), groups, 255, + balloc)); - CU_ASSERT(1 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo/delta/"), groups, 255, - balloc)); + assert_size(1, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo/delta/"), groups, 255, + balloc)); // Check the case where query is done in a single node - CU_ASSERT(7 == match_downstream_addr_group( - routerconf, StringRef::from_lit("example.com"), - StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); + assert_size(7, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("example.com"), + StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("example.com"), - StringRef::from_lit("/alpha/bravo/"), groups, 255, - balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("example.com"), + StringRef::from_lit("/alpha/bravo/"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("example.com"), - StringRef::from_lit("/alpha"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("example.com"), + StringRef::from_lit("/alpha"), groups, 255, balloc)); // Check the case where quey is done in a single node - CU_ASSERT(8 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/alpha"), groups, 255, balloc)); + assert_size(8, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/alpha"), groups, 255, balloc)); - CU_ASSERT(8 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/alpha/"), groups, 255, balloc)); + assert_size(8, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/alpha/"), groups, 255, balloc)); - CU_ASSERT(8 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); + assert_size(8, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/alph"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/alph"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/"), groups, 255, balloc)); // Test for wildcard hosts auto g1 = std::make_shared(); @@ -214,34 +249,40 @@ void test_shrpx_worker_match_downstream_addr_group(void) { wcrouter.add_route(StringRef::from_lit("lacol."), 2); wp.back().router.add_route(StringRef::from_lit("/"), 13); - CU_ASSERT(11 == match_downstream_addr_group( - routerconf, StringRef::from_lit("git.nghttp2.org"), - StringRef::from_lit("/echo"), groups, 255, balloc)); + assert_size(11, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("git.nghttp2.org"), + StringRef::from_lit("/echo"), groups, 255, balloc)); - CU_ASSERT(10 == match_downstream_addr_group( - routerconf, StringRef::from_lit("0git.nghttp2.org"), - StringRef::from_lit("/echo"), groups, 255, balloc)); + assert_size(10, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("0git.nghttp2.org"), + StringRef::from_lit("/echo"), groups, 255, balloc)); - CU_ASSERT(11 == match_downstream_addr_group( - routerconf, StringRef::from_lit("it.nghttp2.org"), - StringRef::from_lit("/echo"), groups, 255, balloc)); + assert_size(11, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("it.nghttp2.org"), + StringRef::from_lit("/echo"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit(".nghttp2.org"), - StringRef::from_lit("/echo/foxtrot"), groups, 255, - balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit(".nghttp2.org"), + StringRef::from_lit("/echo/foxtrot"), groups, 255, balloc)); - CU_ASSERT(9 == match_downstream_addr_group( - routerconf, StringRef::from_lit("alpha.nghttp2.org"), - StringRef::from_lit("/golf"), groups, 255, balloc)); + assert_size(9, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("alpha.nghttp2.org"), + StringRef::from_lit("/golf"), groups, 255, balloc)); - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/echo"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/echo"), groups, 255, balloc)); - CU_ASSERT(13 == match_downstream_addr_group( - routerconf, StringRef::from_lit("test.local"), - StringRef{}, groups, 255, balloc)); + assert_size(13, ==, + match_downstream_addr_group(routerconf, + StringRef::from_lit("test.local"), + StringRef{}, groups, 255, balloc)); } } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/shrpx_worker_test.h b/yass/third_party/nghttp2/src/shrpx_worker_test.h index 8ffa2f12d0..4dfaa2b07e 100644 --- a/yass/third_party/nghttp2/src/shrpx_worker_test.h +++ b/yass/third_party/nghttp2/src/shrpx_worker_test.h @@ -29,9 +29,15 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_worker_match_downstream_addr_group(void); +extern const MunitSuite worker_suite; + +munit_void_test_decl(test_shrpx_worker_match_downstream_addr_group); } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/ssl_compat.h b/yass/third_party/nghttp2/src/ssl_compat.h index 79f9edbffb..f691104466 100644 --- a/yass/third_party/nghttp2/src/ssl_compat.h +++ b/yass/third_party/nghttp2/src/ssl_compat.h @@ -27,21 +27,22 @@ # include # ifdef LIBRESSL_VERSION_NUMBER -# define OPENSSL_1_1_API 0 -# define OPENSSL_1_1_1_API 0 -# define OPENSSL_3_0_0_API 0 -# define LIBRESSL_IN_USE 1 -# define LIBRESSL_LEGACY_API (LIBRESSL_VERSION_NUMBER < 0x20700000L) -# define LIBRESSL_2_7_API (LIBRESSL_VERSION_NUMBER >= 0x20700000L) -# define LIBRESSL_3_5_API (LIBRESSL_VERSION_NUMBER >= 0x30500000L) -# else // !LIBRESSL_VERSION_NUMBER -# define OPENSSL_1_1_API (OPENSSL_VERSION_NUMBER >= 0x1010000fL) -# define OPENSSL_1_1_1_API (OPENSSL_VERSION_NUMBER >= 0x10101000L) -# define OPENSSL_3_0_0_API (OPENSSL_VERSION_NUMBER >= 0x30000000L) -# define LIBRESSL_IN_USE 0 -# define LIBRESSL_LEGACY_API 0 -# define LIBRESSL_2_7_API 0 -# define LIBRESSL_3_5_API 0 +# define NGHTTP2_OPENSSL_IS_LIBRESSL # endif // !LIBRESSL_VERSION_NUMBER +# if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) +# define NGHTTP2_OPENSSL_IS_BORINGSSL +# endif // OPENSSL_IS_BORINGSSL || OPENSSL_IS_AWSLC + +# if !defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && \ + !defined(NGHTTP2_OPENSSL_IS_LIBRESSL) +# define NGHTTP2_GENUINE_OPENSSL +# endif // !NGHTTP2_OPENSSL_IS_BORINGSSL && !NGHTTP2_OPENSSL_IS_LIBRESSL + +# ifdef NGHTTP2_GENUINE_OPENSSL +# define OPENSSL_3_0_0_API (OPENSSL_VERSION_NUMBER >= 0x30000000L) +# else // !NGHTTP2_GENUINE_OPENSSL +# define OPENSSL_3_0_0_API 0 +# endif // !NGHTTP2_GENUINE_OPENSSL + #endif // OPENSSL_COMPAT_H diff --git a/yass/third_party/nghttp2/src/template_test.cc b/yass/third_party/nghttp2/src/template_test.cc index 4a773158b5..db212d1412 100644 --- a/yass/third_party/nghttp2/src/template_test.cc +++ b/yass/third_party/nghttp2/src/template_test.cc @@ -28,80 +28,92 @@ #include #include -#include +#include "munitxx.h" #include "template.h" namespace nghttp2 { +namespace { +const MunitTest tests[]{ + munit_void_test(test_template_immutable_string), + munit_void_test(test_template_string_ref), + munit_test_end(), +}; +} // namespace + +const MunitSuite template_suite{ + "/template", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_template_immutable_string(void) { ImmutableString null; - CU_ASSERT("" == null); - CU_ASSERT(0 == null.size()); - CU_ASSERT(null.empty()); + assert_string_equal("", null.c_str()); + assert_size(0, ==, null.size()); + assert_true(null.empty()); ImmutableString from_cstr("alpha"); - CU_ASSERT(0 == strcmp("alpha", from_cstr.c_str())); - CU_ASSERT(5 == from_cstr.size()); - CU_ASSERT(!from_cstr.empty()); - CU_ASSERT("alpha" == from_cstr); - CU_ASSERT(from_cstr == "alpha"); - CU_ASSERT(std::string("alpha") == from_cstr); - CU_ASSERT(from_cstr == std::string("alpha")); + assert_string_equal("alpha", from_cstr.c_str()); + assert_size(5, ==, from_cstr.size()); + assert_false(from_cstr.empty()); + assert_true("alpha" == from_cstr); + assert_true(from_cstr == "alpha"); + assert_true(std::string("alpha") == from_cstr); + assert_true(from_cstr == std::string("alpha")); // copy constructor ImmutableString src("charlie"); ImmutableString copy = src; - CU_ASSERT("charlie" == copy); - CU_ASSERT(7 == copy.size()); + assert_string_equal("charlie", copy.c_str()); + assert_size(7, ==, copy.size()); // copy assignment ImmutableString copy2; copy2 = src; - CU_ASSERT("charlie" == copy2); - CU_ASSERT(7 == copy2.size()); + assert_string_equal("charlie", copy2.c_str()); + assert_size(7, ==, copy2.size()); // move constructor ImmutableString move = std::move(copy); - CU_ASSERT("charlie" == move); - CU_ASSERT(7 == move.size()); - CU_ASSERT("" == copy); - CU_ASSERT(0 == copy.size()); + assert_string_equal("charlie", move.c_str()); + assert_size(7, ==, move.size()); + assert_string_equal("", copy.c_str()); + assert_size(0, ==, copy.size()); // move assignment move = std::move(from_cstr); - CU_ASSERT("alpha" == move); - CU_ASSERT(5 == move.size()); - CU_ASSERT("" == from_cstr); - CU_ASSERT(0 == from_cstr.size()); + assert_string_equal("alpha", move.c_str()); + assert_size(5, ==, move.size()); + assert_string_equal("", from_cstr.c_str()); + assert_size(0, ==, from_cstr.size()); // from string literal - auto from_lit = StringRef::from_lit("bravo"); + auto from_lit = ImmutableString::from_lit("bravo"); - CU_ASSERT("bravo" == from_lit); - CU_ASSERT(5 == from_lit.size()); + assert_string_equal("bravo", from_lit.c_str()); + assert_size(5, ==, from_lit.size()); // equality ImmutableString eq("delta"); - CU_ASSERT("delta1" != eq); - CU_ASSERT("delt" != eq); - CU_ASSERT(eq != "delta1"); - CU_ASSERT(eq != "delt"); + assert_true("delta1" != eq); + assert_true("delt" != eq); + assert_true(eq != "delta1"); + assert_true(eq != "delt"); // operator[] ImmutableString br_op("foxtrot"); - CU_ASSERT('f' == br_op[0]); - CU_ASSERT('o' == br_op[1]); - CU_ASSERT('t' == br_op[6]); - CU_ASSERT('\0' == br_op[7]); + assert_char('f', ==, br_op[0]); + assert_char('o', ==, br_op[1]); + assert_char('t', ==, br_op[6]); + assert_char('\0', ==, br_op[7]); // operator==(const ImmutableString &, const ImmutableString &) { @@ -109,9 +121,9 @@ void test_template_immutable_string(void) { ImmutableString b("foo"); ImmutableString c("fo"); - CU_ASSERT(a == b); - CU_ASSERT(a != c); - CU_ASSERT(c != b); + assert_true(a == b); + assert_true(a != c); + assert_true(c != b); } // operator<< @@ -120,7 +132,7 @@ void test_template_immutable_string(void) { std::stringstream ss; ss << a; - CU_ASSERT("foo" == ss.str()); + assert_stdstring_equal("foo", ss.str()); } // operator +=(std::string &, const ImmutableString &) @@ -128,60 +140,60 @@ void test_template_immutable_string(void) { std::string a = "alpha"; a += ImmutableString("bravo"); - CU_ASSERT("alphabravo" == a); + assert_stdstring_equal("alphabravo", a); } } void test_template_string_ref(void) { StringRef empty; - CU_ASSERT("" == empty); - CU_ASSERT(0 == empty.size()); + assert_stdstring_equal("", empty.str()); + assert_size(0, ==, empty.size()); // from std::string std::string alpha = "alpha"; StringRef ref(alpha); - CU_ASSERT("alpha" == ref); - CU_ASSERT(ref == "alpha"); - CU_ASSERT(alpha == ref); - CU_ASSERT(ref == alpha); - CU_ASSERT(5 == ref.size()); + assert_true("alpha" == ref); + assert_true(ref == "alpha"); + assert_true(alpha == ref); + assert_true(ref == alpha); + assert_size(5, ==, ref.size()); // from string literal auto from_lit = StringRef::from_lit("alpha"); - CU_ASSERT("alpha" == from_lit); - CU_ASSERT(5 == from_lit.size()); + assert_stdstring_equal("alpha", from_lit.str()); + assert_size(5, ==, from_lit.size()); // from ImmutableString auto im = ImmutableString::from_lit("bravo"); StringRef imref(im); - CU_ASSERT("bravo" == imref); - CU_ASSERT(5 == imref.size()); + assert_stdstring_equal("bravo", imref.str()); + assert_size(5, ==, imref.size()); // from C-string StringRef cstrref("charlie"); - CU_ASSERT("charlie" == cstrref); - CU_ASSERT(7 == cstrref.size()); + assert_stdstring_equal("charlie", cstrref.str()); + assert_size(7, ==, cstrref.size()); // from C-string and its length StringRef cstrnref("delta", 5); - CU_ASSERT("delta" == cstrnref); - CU_ASSERT(5 == cstrnref.size()); + assert_stdstring_equal("delta", cstrnref.str()); + assert_size(5, ==, cstrnref.size()); // operator[] StringRef br_op("foxtrot"); - CU_ASSERT('f' == br_op[0]); - CU_ASSERT('o' == br_op[1]); - CU_ASSERT('t' == br_op[6]); - CU_ASSERT('\0' == br_op[7]); + assert_char('f', ==, br_op[0]); + assert_char('o', ==, br_op[1]); + assert_char('t', ==, br_op[6]); + assert_char('\0', ==, br_op[7]); // operator<< { @@ -189,7 +201,7 @@ void test_template_string_ref(void) { std::stringstream ss; ss << a; - CU_ASSERT("foo" == ss.str()); + assert_stdstring_equal("foo", ss.str()); } // operator +=(std::string &, const StringRef &) @@ -197,7 +209,7 @@ void test_template_string_ref(void) { std::string a = "alpha"; a += StringRef("bravo"); - CU_ASSERT("alphabravo" == a); + assert_stdstring_equal("alphabravo", a); } } diff --git a/yass/third_party/nghttp2/src/template_test.h b/yass/third_party/nghttp2/src/template_test.h index 2c1448f34d..df39de9976 100644 --- a/yass/third_party/nghttp2/src/template_test.h +++ b/yass/third_party/nghttp2/src/template_test.h @@ -29,10 +29,16 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace nghttp2 { -void test_template_immutable_string(void); -void test_template_string_ref(void); +extern const MunitSuite template_suite; + +munit_void_test_decl(test_template_immutable_string); +munit_void_test_decl(test_template_string_ref); } // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/timegm.c b/yass/third_party/nghttp2/src/timegm.c index fc6df82494..3a671b184a 100644 --- a/yass/third_party/nghttp2/src/timegm.c +++ b/yass/third_party/nghttp2/src/timegm.c @@ -45,11 +45,11 @@ time_t nghttp2_timegm(struct tm *tm) { days = (tm->tm_year - 70) * 365 + num_leap_year + tm->tm_yday; t = ((int64_t)days * 24 + tm->tm_hour) * 3600 + tm->tm_min * 60 + tm->tm_sec; -#if SIZEOF_TIME_T == 4 - if (t < INT32_MIN || t > INT32_MAX) { - return -1; + if (sizeof(time_t) == 4) { + if (t < INT32_MIN || t > INT32_MAX) { + return -1; + } } -#endif /* SIZEOF_TIME_T == 4 */ return (time_t)t; } @@ -78,11 +78,11 @@ time_t nghttp2_timegm_without_yday(struct tm *tm) { } t = ((int64_t)days * 24 + tm->tm_hour) * 3600 + tm->tm_min * 60 + tm->tm_sec; -#if SIZEOF_TIME_T == 4 - if (t < INT32_MIN || t > INT32_MAX) { - return -1; + if (sizeof(time_t) == 4) { + if (t < INT32_MIN || t > INT32_MAX) { + return -1; + } } -#endif /* SIZEOF_TIME_T == 4 */ return (time_t)t; } diff --git a/yass/third_party/nghttp2/src/timegm.h b/yass/third_party/nghttp2/src/timegm.h index 56f9cc6c96..152917cfa9 100644 --- a/yass/third_party/nghttp2/src/timegm.h +++ b/yass/third_party/nghttp2/src/timegm.h @@ -29,14 +29,12 @@ # include #endif /* HAVE_CONFIG_H */ +#include + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -#ifdef HAVE_TIME_H -# include -#endif // HAVE_TIME_H - time_t nghttp2_timegm(struct tm *tm); /* Just like nghttp2_timegm, but without using tm->tm_yday. This is diff --git a/yass/third_party/nghttp2/src/tls.cc b/yass/third_party/nghttp2/src/tls.cc index a5b0975c00..ad62c605da 100644 --- a/yass/third_party/nghttp2/src/tls.cc +++ b/yass/third_party/nghttp2/src/tls.cc @@ -25,55 +25,26 @@ #include "tls.h" #include +#include #include #include #include +#include #include #include +#ifdef HAVE_LIBBROTLI +# include +# include +#endif // HAVE_LIBBROTLI + #include "ssl_compat.h" namespace nghttp2 { namespace tls { -#if OPENSSL_1_1_API - -// CRYPTO_LOCK is deprecated as of OpenSSL 1.1.0 -LibsslGlobalLock::LibsslGlobalLock() {} - -#else // !OPENSSL_1_1_API - -namespace { -std::mutex *ssl_global_locks; -} // namespace - -namespace { -void ssl_locking_cb(int mode, int type, const char *file, int line) { - if (mode & CRYPTO_LOCK) { - ssl_global_locks[type].lock(); - } else { - ssl_global_locks[type].unlock(); - } -} -} // namespace - -LibsslGlobalLock::LibsslGlobalLock() { - if (ssl_global_locks) { - std::cerr << "OpenSSL global lock has been already set" << std::endl; - assert(0); - } - ssl_global_locks = new std::mutex[CRYPTO_num_locks()]; - // CRYPTO_set_id_callback(ssl_thread_id); OpenSSL manual says that - // if threadid_func is not specified using - // CRYPTO_THREADID_set_callback(), then default implementation is - // used. We use this default one. - CRYPTO_set_locking_callback(ssl_locking_cb); -} - -#endif // !OPENSSL_1_1_API - const char *get_tls_protocol(SSL *ssl) { switch (SSL_version(ssl)) { case SSL2_VERSION: @@ -148,52 +119,89 @@ bool check_http2_requirement(SSL *ssl) { return check_http2_tls_version(ssl) && !check_http2_cipher_block_list(ssl); } -void libssl_init() { -#if OPENSSL_1_1_API -// No explicit initialization is required. -#elif defined(OPENSSL_IS_BORINGSSL) - CRYPTO_library_init(); -#else // !OPENSSL_1_1_API && !defined(OPENSSL_IS_BORINGSSL) - OPENSSL_config(nullptr); - SSL_load_error_strings(); - SSL_library_init(); - OpenSSL_add_all_algorithms(); -#endif // !OPENSSL_1_1_API && !defined(OPENSSL_IS_BORINGSSL) -} - int ssl_ctx_set_proto_versions(SSL_CTX *ssl_ctx, int min, int max) { -#if OPENSSL_1_1_API || defined(OPENSSL_IS_BORINGSSL) if (SSL_CTX_set_min_proto_version(ssl_ctx, min) != 1 || SSL_CTX_set_max_proto_version(ssl_ctx, max) != 1) { return -1; } return 0; -#else // !OPENSSL_1_1_API && !defined(OPENSSL_IS_BORINGSSL) - long int opts = 0; +} - // TODO We depends on the ordering of protocol version macro in - // OpenSSL. - if (min > TLS1_VERSION) { - opts |= SSL_OP_NO_TLSv1; - } - if (min > TLS1_1_VERSION) { - opts |= SSL_OP_NO_TLSv1_1; - } - if (min > TLS1_2_VERSION) { - opts |= SSL_OP_NO_TLSv1_2; +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) +int cert_compress(SSL *ssl, CBB *out, const uint8_t *in, size_t in_len) { + uint8_t *dest; + + auto compressed_size = BrotliEncoderMaxCompressedSize(in_len); + if (compressed_size == 0) { + return 0; } - if (max < TLS1_2_VERSION) { - opts |= SSL_OP_NO_TLSv1_2; - } - if (max < TLS1_1_VERSION) { - opts |= SSL_OP_NO_TLSv1_1; + if (!CBB_reserve(out, &dest, compressed_size)) { + return 0; } - SSL_CTX_set_options(ssl_ctx, opts); + if (BrotliEncoderCompress(BROTLI_MAX_QUALITY, BROTLI_DEFAULT_WINDOW, + BROTLI_MODE_GENERIC, in_len, in, &compressed_size, + dest) != BROTLI_TRUE) { + return 0; + } + + if (!CBB_did_write(out, compressed_size)) { + return 0; + } + + return 1; +} + +int cert_decompress(SSL *ssl, CRYPTO_BUFFER **out, size_t uncompressed_len, + const uint8_t *in, size_t in_len) { + uint8_t *dest; + auto buf = CRYPTO_BUFFER_alloc(&dest, uncompressed_len); + auto len = uncompressed_len; + + if (BrotliDecoderDecompress(in_len, in, &len, dest) != + BROTLI_DECODER_RESULT_SUCCESS) { + CRYPTO_BUFFER_free(buf); + + return 0; + } + + if (uncompressed_len != len) { + CRYPTO_BUFFER_free(buf); + + return 0; + } + + *out = buf; + + return 1; +} +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + +namespace { +std::ofstream keylog_file; + +void keylog_callback(const SSL *ssl, const char *line) { + keylog_file.write(line, strlen(line)); + keylog_file.put('\n'); + keylog_file.flush(); +} +} // namespace + +int setup_keylog_callback(SSL_CTX *ssl_ctx) { + auto keylog_filename = getenv("SSLKEYLOGFILE"); + if (!keylog_filename) { + return 0; + } + + keylog_file.open(keylog_filename, std::ios_base::app); + if (!keylog_file) { + return -1; + } + + SSL_CTX_set_keylog_callback(ssl_ctx, keylog_callback); return 0; -#endif // !OPENSSL_1_1_API && !defined(OPENSSL_IS_BORINGSSL) } } // namespace tls diff --git a/yass/third_party/nghttp2/src/tls.h b/yass/third_party/nghttp2/src/tls.h index 8b1cf61676..c5fda32093 100644 --- a/yass/third_party/nghttp2/src/tls.h +++ b/yass/third_party/nghttp2/src/tls.h @@ -37,15 +37,6 @@ namespace nghttp2 { namespace tls { -// Acquire OpenSSL global lock to share SSL_CTX across multiple -// threads. The constructor acquires lock and destructor unlocks. -class LibsslGlobalLock { -public: - LibsslGlobalLock(); - LibsslGlobalLock(const LibsslGlobalLock &) = delete; - LibsslGlobalLock &operator=(const LibsslGlobalLock &) = delete; -}; - // Recommended general purpose "Intermediate compatibility" cipher // suites for TLSv1.2 by mozilla. // @@ -61,11 +52,11 @@ constexpr char DEFAULT_CIPHER_LIST[] = // // https://wiki.mozilla.org/Security/Server_Side_TLS constexpr char DEFAULT_TLS13_CIPHER_LIST[] = -#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) +#if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_LIBRESSL) "TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256" -#else +#else // !NGHTTP2_GENUINE_OPENSSL && !NGHTTP2_OPENSSL_IS_LIBRESSL "" -#endif +#endif // !NGHTTP2_GENUINE_OPENSSL && !NGHTTP2_OPENSSL_IS_LIBRESSL ; constexpr auto NGHTTP2_TLS_MIN_VERSION = TLS1_VERSION; @@ -102,13 +93,22 @@ bool check_http2_cipher_block_list(SSL *ssl); // described in RFC 7540. bool check_http2_requirement(SSL *ssl); -// Initializes OpenSSL library -void libssl_init(); - // Sets TLS min and max versions to |ssl_ctx|. This function returns // 0 if it succeeds, or -1. int ssl_ctx_set_proto_versions(SSL_CTX *ssl_ctx, int min, int max); +constexpr uint16_t CERTIFICATE_COMPRESSION_ALGO_BROTLI = 2; + +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) +int cert_compress(SSL *ssl, CBB *out, const uint8_t *in, size_t in_len); + +int cert_decompress(SSL *ssl, CRYPTO_BUFFER **out, size_t uncompressed_len, + const uint8_t *in, size_t in_len); +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + +// Setup keylog callback. It returns 0 if it succeeds, or -1. +int setup_keylog_callback(SSL_CTX *ssl_ctx); + } // namespace tls } // namespace nghttp2 diff --git a/yass/third_party/nghttp2/src/util.cc b/yass/third_party/nghttp2/src/util.cc index 9d0c1bd7bd..47151b2a63 100644 --- a/yass/third_party/nghttp2/src/util.cc +++ b/yass/third_party/nghttp2/src/util.cc @@ -24,9 +24,6 @@ */ #include "util.h" -#ifdef HAVE_TIME_H -# include -#endif // HAVE_TIME_H #include #ifdef HAVE_SYS_SOCKET_H # include @@ -59,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -619,7 +617,7 @@ void show_candidates(const char *unkopt, const option *options) { if (istarts_with(options[i].name, options[i].name + optnamelen, unkopt, unkopt + unkoptlen)) { if (optnamelen == static_cast(unkoptlen)) { - // Exact match, then we don't show any condidates. + // Exact match, then we don't show any candidates. return; } ++prefix_match; @@ -804,6 +802,30 @@ void set_port(Address &addr, uint16_t port) { } } +uint16_t get_port(const sockaddr_union *su) { + switch (su->storage.ss_family) { + case AF_INET: + return ntohs(su->in.sin_port); + case AF_INET6: + return ntohs(su->in6.sin6_port); + default: + return 0; + } +} + +bool quic_prohibited_port(uint16_t port) { + switch (port) { + case 1900: + case 5353: + case 11211: + case 20800: + case 27015: + return true; + default: + return port < 1024; + } +} + std::string ascii_dump(const uint8_t *data, size_t len) { std::string res; @@ -1350,66 +1372,166 @@ StringRef make_hostport(BlockAllocator &balloc, const StringRef &host, } namespace { -void hexdump8(FILE *out, const uint8_t *first, const uint8_t *last) { - auto stop = std::min(first + 8, last); - for (auto k = first; k != stop; ++k) { - fprintf(out, "%02x ", *k); +uint8_t *hexdump_addr(uint8_t *dest, size_t addr) { + // Lower 32 bits are displayed. + for (size_t i = 0; i < 4; ++i) { + auto a = (addr >> (3 - i) * 8) & 0xff; + + *dest++ = LOWER_XDIGITS[a >> 4]; + *dest++ = LOWER_XDIGITS[a & 0xf]; } - // each byte needs 3 spaces (2 hex value and space) - for (; stop != first + 8; ++stop) { - fputs(" ", out); - } - // we have extra space after 8 bytes - fputc(' ', out); + + return dest; } } // namespace -void hexdump(FILE *out, const uint8_t *src, size_t len) { - if (len == 0) { - return; +namespace { +uint8_t *hexdump_ascii(uint8_t *dest, const uint8_t *data, size_t datalen) { + *dest++ = '|'; + + for (size_t i = 0; i < datalen; ++i) { + if (0x20 <= data[i] && data[i] <= 0x7e) { + *dest++ = data[i]; + } else { + *dest++ = '.'; + } } - size_t buflen = 0; + + *dest++ = '|'; + + return dest; +} +} // namespace + +namespace { +uint8_t *hexdump8(uint8_t *dest, const uint8_t *data, size_t datalen) { + size_t i; + + for (i = 0; i < datalen; ++i) { + *dest++ = LOWER_XDIGITS[data[i] >> 4]; + *dest++ = LOWER_XDIGITS[data[i] & 0xf]; + *dest++ = ' '; + } + + for (; i < 8; ++i) { + *dest++ = ' '; + *dest++ = ' '; + *dest++ = ' '; + } + + return dest; +} +} // namespace + +namespace { +uint8_t *hexdump16(uint8_t *dest, const uint8_t *data, size_t datalen) { + if (datalen > 8) { + dest = hexdump8(dest, data, 8); + *dest++ = ' '; + dest = hexdump8(dest, data + 8, datalen - 8); + *dest++ = ' '; + } else { + dest = hexdump8(dest, data, datalen); + *dest++ = ' '; + dest = hexdump8(dest, nullptr, 0); + *dest++ = ' '; + } + + return dest; +} +} // namespace + +namespace { +uint8_t *hexdump_line(uint8_t *dest, const uint8_t *data, size_t datalen, + size_t addr) { + dest = hexdump_addr(dest, addr); + *dest++ = ' '; + *dest++ = ' '; + + dest = hexdump16(dest, data, datalen); + + return hexdump_ascii(dest, data, datalen); +} +} // namespace + +namespace { +int hexdump_write(int fd, const uint8_t *data, size_t datalen) { + ssize_t nwrite; + + for (; (nwrite = write(fd, data, datalen)) == -1 && errno == EINTR;) + ; + if (nwrite == -1) { + return -1; + } + + return 0; +} +} // namespace + +int hexdump(FILE *out, const void *data, size_t datalen) { + if (datalen == 0) { + return 0; + } + + // min_space is the additional minimum space that the buffer must + // accept, which is the size of a single full line output + one + // repeat line marker ("*\n"). If the remaining buffer size is less + // than that, flush the buffer and reset. + constexpr size_t min_space = 79 + 2; + + auto fd = fileno(out); + std::array buf; + auto last = buf.data(); + auto in = reinterpret_cast(data); auto repeated = false; - std::array buf{}; - auto end = src + len; - auto i = src; - for (;;) { - auto nextlen = - std::min(static_cast(16), static_cast(end - i)); - if (nextlen == buflen && - std::equal(std::begin(buf), std::begin(buf) + buflen, i)) { - // as long as adjacent 16 bytes block are the same, we just - // print single '*'. - if (!repeated) { - repeated = true; - fputs("*\n", out); - } - i += nextlen; - continue; - } - repeated = false; - fprintf(out, "%08lx", static_cast(i - src)); - if (i == end) { - fputc('\n', out); - break; - } - fputs(" ", out); - hexdump8(out, i, end); - hexdump8(out, i + 8, std::max(i + 8, end)); - fputc('|', out); - auto stop = std::min(i + 16, end); - buflen = stop - i; - auto p = buf.data(); - for (; i != stop; ++i) { - *p++ = *i; - if (0x20 <= *i && *i <= 0x7e) { - fputc(*i, out); - } else { - fputc('.', out); + + for (size_t offset = 0; offset < datalen; offset += 16) { + auto n = datalen - offset; + auto s = in + offset; + + if (n >= 16) { + n = 16; + + if (offset > 0) { + if (std::equal(s - 16, s, s)) { + if (repeated) { + continue; + } + + repeated = true; + + *last++ = '*'; + *last++ = '\n'; + + continue; + } + + repeated = false; } } - fputs("|\n", out); + + last = hexdump_line(last, s, n, offset); + *last++ = '\n'; + + auto len = static_cast(last - buf.data()); + if (len + min_space > buf.size()) { + if (hexdump_write(fd, buf.data(), len) != 0) { + return -1; + } + + last = buf.data(); + } } + + last = hexdump_addr(last, datalen); + *last++ = '\n'; + + auto len = static_cast(last - buf.data()); + if (len) { + return hexdump_write(fd, buf.data(), len); + } + + return 0; } void put_uint16be(uint8_t *buf, uint16_t n) { @@ -1531,16 +1653,6 @@ uint32_t hash32(const StringRef &s) { return h; } -#if !OPENSSL_1_1_API -namespace { -EVP_MD_CTX *EVP_MD_CTX_new(void) { return EVP_MD_CTX_create(); } -} // namespace - -namespace { -void EVP_MD_CTX_free(EVP_MD_CTX *ctx) { EVP_MD_CTX_destroy(ctx); } -} // namespace -#endif // !OPENSSL_1_1_API - namespace { int message_digest(uint8_t *res, const EVP_MD *meth, const StringRef &s) { int rv; diff --git a/yass/third_party/nghttp2/src/util.h b/yass/third_party/nghttp2/src/util.h index d818bf2fd3..e1c0d81790 100644 --- a/yass/third_party/nghttp2/src/util.h +++ b/yass/third_party/nghttp2/src/util.h @@ -567,6 +567,12 @@ std::string to_numeric_addr(const struct sockaddr *sa, socklen_t salen); // Sets |port| to |addr|. void set_port(Address &addr, uint16_t port); +// Get port from |su|. +uint16_t get_port(const sockaddr_union *su); + +// Returns true if |port| is prohibited as a QUIC client port. +bool quic_prohibited_port(uint16_t port); + // Returns ASCII dump of |data| of length |len|. Only ASCII printable // characters are preserved. Other characters are replaced with ".". std::string ascii_dump(const uint8_t *data, size_t len); @@ -840,8 +846,10 @@ StringRef make_http_hostport(OutputIt first, const StringRef &host, return StringRef{first, p}; } -// Dumps |src| of length |len| in the format similar to `hexdump -C`. -void hexdump(FILE *out, const uint8_t *src, size_t len); +// hexdump dumps |data| of length |datalen| in the format similar to +// hexdump(1) with -C option. This function returns 0 if it succeeds, +// or -1. +int hexdump(FILE *out, const void *data, size_t datalen); // Copies 2 byte unsigned integer |n| in host byte order to |buf| in // network byte order. diff --git a/yass/third_party/nghttp2/src/util_test.cc b/yass/third_party/nghttp2/src/util_test.cc index 0ac0f1de61..2e01e9d517 100644 --- a/yass/third_party/nghttp2/src/util_test.cc +++ b/yass/third_party/nghttp2/src/util_test.cc @@ -28,7 +28,7 @@ #include #include -#include +#include "munitxx.h" #include @@ -39,166 +39,233 @@ using namespace nghttp2; namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_util_streq), + munit_void_test(test_util_strieq), + munit_void_test(test_util_inp_strlower), + munit_void_test(test_util_to_base64), + munit_void_test(test_util_to_token68), + munit_void_test(test_util_percent_encode_token), + munit_void_test(test_util_percent_decode), + munit_void_test(test_util_quote_string), + munit_void_test(test_util_utox), + munit_void_test(test_util_http_date), + munit_void_test(test_util_select_h2), + munit_void_test(test_util_ipv6_numeric_addr), + munit_void_test(test_util_utos), + munit_void_test(test_util_make_string_ref_uint), + munit_void_test(test_util_utos_unit), + munit_void_test(test_util_utos_funit), + munit_void_test(test_util_parse_uint_with_unit), + munit_void_test(test_util_parse_uint), + munit_void_test(test_util_parse_duration_with_unit), + munit_void_test(test_util_duration_str), + munit_void_test(test_util_format_duration), + munit_void_test(test_util_starts_with), + munit_void_test(test_util_ends_with), + munit_void_test(test_util_parse_http_date), + munit_void_test(test_util_localtime_date), + munit_void_test(test_util_get_uint64), + munit_void_test(test_util_parse_config_str_list), + munit_void_test(test_util_make_http_hostport), + munit_void_test(test_util_make_hostport), + munit_void_test(test_util_strifind), + munit_void_test(test_util_random_alpha_digit), + munit_void_test(test_util_format_hex), + munit_void_test(test_util_is_hex_string), + munit_void_test(test_util_decode_hex), + munit_void_test(test_util_extract_host), + munit_void_test(test_util_split_hostport), + munit_void_test(test_util_split_str), + munit_void_test(test_util_rstrip), + munit_test_end(), +}; +} // namespace + +const MunitSuite util_suite{ + "/util", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_util_streq(void) { - CU_ASSERT( + assert_true( util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alpha"))); - CU_ASSERT(!util::streq(StringRef::from_lit("alpha"), - StringRef::from_lit("alphabravo"))); - CU_ASSERT(!util::streq(StringRef::from_lit("alphabravo"), - StringRef::from_lit("alpha"))); - CU_ASSERT( - !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA"))); - CU_ASSERT(!util::streq(StringRef{}, StringRef::from_lit("a"))); - CU_ASSERT(util::streq(StringRef{}, StringRef{})); - CU_ASSERT(!util::streq(StringRef::from_lit("alpha"), StringRef{})); + assert_false(util::streq(StringRef::from_lit("alpha"), + StringRef::from_lit("alphabravo"))); + assert_false(util::streq(StringRef::from_lit("alphabravo"), + StringRef::from_lit("alpha"))); + assert_false( + util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA"))); + assert_false(util::streq(StringRef{}, StringRef::from_lit("a"))); + assert_true(util::streq(StringRef{}, StringRef{})); + assert_false(util::streq(StringRef::from_lit("alpha"), StringRef{})); - CU_ASSERT( - !util::streq(StringRef::from_lit("alph"), StringRef::from_lit("alpha"))); - CU_ASSERT( - !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alph"))); - CU_ASSERT( - !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA"))); + assert_false( + util::streq(StringRef::from_lit("alph"), StringRef::from_lit("alpha"))); + assert_false( + util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alph"))); + assert_false( + util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA"))); - CU_ASSERT(util::streq_l("alpha", "alpha", 5)); - CU_ASSERT(util::streq_l("alpha", "alphabravo", 5)); - CU_ASSERT(!util::streq_l("alpha", "alphabravo", 6)); - CU_ASSERT(!util::streq_l("alphabravo", "alpha", 5)); - CU_ASSERT(!util::streq_l("alpha", "alphA", 5)); - CU_ASSERT(!util::streq_l("", "a", 1)); - CU_ASSERT(util::streq_l("", "", 0)); - CU_ASSERT(!util::streq_l("alpha", "", 0)); + assert_true(util::streq_l("alpha", "alpha", 5)); + assert_true(util::streq_l("alpha", "alphabravo", 5)); + assert_false(util::streq_l("alpha", "alphabravo", 6)); + assert_false(util::streq_l("alphabravo", "alpha", 5)); + assert_false(util::streq_l("alpha", "alphA", 5)); + assert_false(util::streq_l("", "a", 1)); + assert_true(util::streq_l("", "", 0)); + assert_false(util::streq_l("alpha", "", 0)); } void test_util_strieq(void) { - CU_ASSERT(util::strieq(std::string("alpha"), std::string("alpha"))); - CU_ASSERT(util::strieq(std::string("alpha"), std::string("AlPhA"))); - CU_ASSERT(util::strieq(std::string(), std::string())); - CU_ASSERT(!util::strieq(std::string("alpha"), std::string("AlPhA "))); - CU_ASSERT(!util::strieq(std::string(), std::string("AlPhA "))); + assert_true(util::strieq(std::string("alpha"), std::string("alpha"))); + assert_true(util::strieq(std::string("alpha"), std::string("AlPhA"))); + assert_true(util::strieq(std::string(), std::string())); + assert_false(util::strieq(std::string("alpha"), std::string("AlPhA "))); + assert_false(util::strieq(std::string(), std::string("AlPhA "))); - CU_ASSERT( + assert_true( util::strieq(StringRef::from_lit("alpha"), StringRef::from_lit("alpha"))); - CU_ASSERT( + assert_true( util::strieq(StringRef::from_lit("alpha"), StringRef::from_lit("AlPhA"))); - CU_ASSERT(util::strieq(StringRef{}, StringRef{})); - CU_ASSERT(!util::strieq(StringRef::from_lit("alpha"), - StringRef::from_lit("AlPhA "))); - CU_ASSERT( - !util::strieq(StringRef::from_lit(""), StringRef::from_lit("AlPhA "))); + assert_true(util::strieq(StringRef{}, StringRef{})); + assert_false(util::strieq(StringRef::from_lit("alpha"), + StringRef::from_lit("AlPhA "))); + assert_false( + util::strieq(StringRef::from_lit(""), StringRef::from_lit("AlPhA "))); - CU_ASSERT(util::strieq_l("alpha", "alpha", 5)); - CU_ASSERT(util::strieq_l("alpha", "AlPhA", 5)); - CU_ASSERT(util::strieq_l("", static_cast(nullptr), 0)); - CU_ASSERT(!util::strieq_l("alpha", "AlPhA ", 6)); - CU_ASSERT(!util::strieq_l("", "AlPhA ", 6)); + assert_true(util::strieq_l("alpha", "alpha", 5)); + assert_true(util::strieq_l("alpha", "AlPhA", 5)); + assert_true(util::strieq_l("", static_cast(nullptr), 0)); + assert_false(util::strieq_l("alpha", "AlPhA ", 6)); + assert_false(util::strieq_l("", "AlPhA ", 6)); - CU_ASSERT(util::strieq_l("alpha", StringRef::from_lit("alpha"))); - CU_ASSERT(util::strieq_l("alpha", StringRef::from_lit("AlPhA"))); - CU_ASSERT(util::strieq_l("", StringRef{})); - CU_ASSERT(!util::strieq_l("alpha", StringRef::from_lit("AlPhA "))); - CU_ASSERT(!util::strieq_l("", StringRef::from_lit("AlPhA "))); + assert_true(util::strieq_l("alpha", StringRef::from_lit("alpha"))); + assert_true(util::strieq_l("alpha", StringRef::from_lit("AlPhA"))); + assert_true(util::strieq_l("", StringRef{})); + assert_false(util::strieq_l("alpha", StringRef::from_lit("AlPhA "))); + assert_false(util::strieq_l("", StringRef::from_lit("AlPhA "))); } void test_util_inp_strlower(void) { std::string a("alPha"); util::inp_strlower(a); - CU_ASSERT("alpha" == a); + assert_stdstring_equal("alpha", a); a = "ALPHA123BRAVO"; util::inp_strlower(a); - CU_ASSERT("alpha123bravo" == a); + assert_stdstring_equal("alpha123bravo", a); a = ""; util::inp_strlower(a); - CU_ASSERT("" == a); + assert_stdstring_equal("", a); } void test_util_to_base64(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("AAA++B/=" == - util::to_base64(balloc, StringRef::from_lit("AAA--B_"))); - CU_ASSERT("AAA++B/B" == - util::to_base64(balloc, StringRef::from_lit("AAA--B_B"))); + assert_stdstring_equal( + "AAA++B/=", + util::to_base64(balloc, StringRef::from_lit("AAA--B_")).str()); + assert_stdstring_equal( + "AAA++B/B", + util::to_base64(balloc, StringRef::from_lit("AAA--B_B")).str()); } void test_util_to_token68(void) { std::string x = "AAA++B/="; util::to_token68(x); - CU_ASSERT("AAA--B_" == x); + assert_stdstring_equal("AAA--B_", x); x = "AAA++B/B"; util::to_token68(x); - CU_ASSERT("AAA--B_B" == x); + assert_stdstring_equal("AAA--B_B", x); } void test_util_percent_encode_token(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("h2" == - util::percent_encode_token(balloc, StringRef::from_lit("h2"))); - CU_ASSERT("h3~" == - util::percent_encode_token(balloc, StringRef::from_lit("h3~"))); - CU_ASSERT("100%25" == - util::percent_encode_token(balloc, StringRef::from_lit("100%"))); - CU_ASSERT("http%202" == - util::percent_encode_token(balloc, StringRef::from_lit("http 2"))); + assert_stdstring_equal( + "h2", + util::percent_encode_token(balloc, StringRef::from_lit("h2")).str()); + assert_stdstring_equal( + "h3~", + util::percent_encode_token(balloc, StringRef::from_lit("h3~")).str()); + assert_stdstring_equal( + "100%25", + util::percent_encode_token(balloc, StringRef::from_lit("100%")).str()); + assert_stdstring_equal( + "http%202", + util::percent_encode_token(balloc, StringRef::from_lit("http 2")).str()); } void test_util_percent_decode(void) { { std::string s = "%66%6F%6f%62%61%72"; - CU_ASSERT("foobar" == util::percent_decode(std::begin(s), std::end(s))); + assert_stdstring_equal("foobar", + util::percent_decode(std::begin(s), std::end(s))); } { std::string s = "%66%6"; - CU_ASSERT("f%6" == util::percent_decode(std::begin(s), std::end(s))); + assert_stdstring_equal("f%6", + util::percent_decode(std::begin(s), std::end(s))); } { std::string s = "%66%"; - CU_ASSERT("f%" == util::percent_decode(std::begin(s), std::end(s))); + assert_stdstring_equal("f%", + util::percent_decode(std::begin(s), std::end(s))); } BlockAllocator balloc(1024, 1024); - CU_ASSERT("foobar" == util::percent_decode( - balloc, StringRef::from_lit("%66%6F%6f%62%61%72"))); + assert_stdstring_equal( + "foobar", + util::percent_decode(balloc, StringRef::from_lit("%66%6F%6f%62%61%72")) + .str()); - CU_ASSERT("f%6" == - util::percent_decode(balloc, StringRef::from_lit("%66%6"))); + assert_stdstring_equal( + "f%6", util::percent_decode(balloc, StringRef::from_lit("%66%6")).str()); - CU_ASSERT("f%" == util::percent_decode(balloc, StringRef::from_lit("%66%"))); + assert_stdstring_equal( + "f%", util::percent_decode(balloc, StringRef::from_lit("%66%")).str()); } void test_util_quote_string(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("alpha" == - util::quote_string(balloc, StringRef::from_lit("alpha"))); - CU_ASSERT("" == util::quote_string(balloc, StringRef::from_lit(""))); - CU_ASSERT("\\\"alpha\\\"" == - util::quote_string(balloc, StringRef::from_lit("\"alpha\""))); + assert_stdstring_equal( + "alpha", util::quote_string(balloc, StringRef::from_lit("alpha")).str()); + assert_stdstring_equal( + "", util::quote_string(balloc, StringRef::from_lit("")).str()); + assert_stdstring_equal( + "\\\"alpha\\\"", + util::quote_string(balloc, StringRef::from_lit("\"alpha\"")).str()); } void test_util_utox(void) { - CU_ASSERT("0" == util::utox(0)); - CU_ASSERT("1" == util::utox(1)); - CU_ASSERT("F" == util::utox(15)); - CU_ASSERT("10" == util::utox(16)); - CU_ASSERT("3B9ACA07" == util::utox(1000000007)); - CU_ASSERT("100000000" == util::utox(1LL << 32)); + assert_stdstring_equal("0", util::utox(0)); + assert_stdstring_equal("1", util::utox(1)); + assert_stdstring_equal("F", util::utox(15)); + assert_stdstring_equal("10", util::utox(16)); + assert_stdstring_equal("3B9ACA07", util::utox(1000000007)); + assert_stdstring_equal("100000000", util::utox(1LL << 32)); } void test_util_http_date(void) { - CU_ASSERT("Thu, 01 Jan 1970 00:00:00 GMT" == util::http_date(0)); - CU_ASSERT("Wed, 29 Feb 2012 09:15:16 GMT" == util::http_date(1330506916)); + assert_stdstring_equal("Thu, 01 Jan 1970 00:00:00 GMT", util::http_date(0)); + assert_stdstring_equal("Wed, 29 Feb 2012 09:15:16 GMT", + util::http_date(1330506916)); std::array http_buf; - CU_ASSERT("Thu, 01 Jan 1970 00:00:00 GMT" == - util::format_http_date(http_buf.data(), - std::chrono::system_clock::time_point())); - CU_ASSERT("Wed, 29 Feb 2012 09:15:16 GMT" == - util::format_http_date(http_buf.data(), - std::chrono::system_clock::time_point( - std::chrono::seconds(1330506916)))); + assert_stdstring_equal( + "Thu, 01 Jan 1970 00:00:00 GMT", + util::format_http_date(http_buf.data(), + std::chrono::system_clock::time_point()) + .str()); + assert_stdstring_equal( + "Wed, 29 Feb 2012 09:15:16 GMT", + util::format_http_date(http_buf.data(), + std::chrono::system_clock::time_point( + std::chrono::seconds(1330506916))) + .str()); } void test_util_select_h2(void) { @@ -207,10 +274,10 @@ void test_util_select_h2(void) { // Check single entry and select it. const unsigned char t1[] = "\x2h2"; - CU_ASSERT(util::select_h2(&out, &outlen, t1, sizeof(t1) - 1)); - CU_ASSERT( - memcmp(NGHTTP2_PROTO_VERSION_ID, out, NGHTTP2_PROTO_VERSION_ID_LEN) == 0); - CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen); + assert_true(util::select_h2(&out, &outlen, t1, sizeof(t1) - 1)); + assert_memory_equal(NGHTTP2_PROTO_VERSION_ID_LEN, NGHTTP2_PROTO_VERSION_ID, + out); + assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen); out = nullptr; outlen = 0; @@ -218,224 +285,235 @@ void test_util_select_h2(void) { // Check the case where id is correct but length is invalid and too // long. const unsigned char t2[] = "\x6h2-14"; - CU_ASSERT(!util::select_h2(&out, &outlen, t2, sizeof(t2) - 1)); + assert_false(util::select_h2(&out, &outlen, t2, sizeof(t2) - 1)); // Check the case where h2 is located after bogus ID. const unsigned char t3[] = "\x2h3\x2h2"; - CU_ASSERT(util::select_h2(&out, &outlen, t3, sizeof(t3) - 1)); + assert_true(util::select_h2(&out, &outlen, t3, sizeof(t3) - 1)); - CU_ASSERT( - memcmp(NGHTTP2_PROTO_VERSION_ID, out, NGHTTP2_PROTO_VERSION_ID_LEN) == 0); - CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen); + assert_memory_equal(NGHTTP2_PROTO_VERSION_ID_LEN, NGHTTP2_PROTO_VERSION_ID, + out); + assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen); out = nullptr; outlen = 0; // Check the case that last entry's length is invalid and too long. const unsigned char t4[] = "\x2h3\x6h2-14"; - CU_ASSERT(!util::select_h2(&out, &outlen, t4, sizeof(t4) - 1)); + assert_false(util::select_h2(&out, &outlen, t4, sizeof(t4) - 1)); // Check the case that all entries are not supported. const unsigned char t5[] = "\x2h3\x2h4"; - CU_ASSERT(!util::select_h2(&out, &outlen, t5, sizeof(t5) - 1)); + assert_false(util::select_h2(&out, &outlen, t5, sizeof(t5) - 1)); // Check the case where 2 values are eligible, but last one is // picked up because it has precedence over the other. const unsigned char t6[] = "\x5h2-14\x5h2-16"; - CU_ASSERT(util::select_h2(&out, &outlen, t6, sizeof(t6) - 1)); - CU_ASSERT(util::streq(NGHTTP2_H2_16, StringRef{out, outlen})); + assert_true(util::select_h2(&out, &outlen, t6, sizeof(t6) - 1)); + assert_true(util::streq(NGHTTP2_H2_16, StringRef{out, outlen})); } void test_util_ipv6_numeric_addr(void) { - CU_ASSERT(util::ipv6_numeric_addr("::1")); - CU_ASSERT(util::ipv6_numeric_addr("2001:0db8:85a3:0042:1000:8a2e:0370:7334")); + assert_true(util::ipv6_numeric_addr("::1")); + assert_true( + util::ipv6_numeric_addr("2001:0db8:85a3:0042:1000:8a2e:0370:7334")); // IPv4 - CU_ASSERT(!util::ipv6_numeric_addr("127.0.0.1")); + assert_false(util::ipv6_numeric_addr("127.0.0.1")); // not numeric address - CU_ASSERT(!util::ipv6_numeric_addr("localhost")); + assert_false(util::ipv6_numeric_addr("localhost")); } void test_util_utos(void) { uint8_t buf[32]; - CU_ASSERT(("0" == StringRef{buf, util::utos(buf, 0)})); - CU_ASSERT(("123" == StringRef{buf, util::utos(buf, 123)})); - CU_ASSERT(("18446744073709551615" == - StringRef{buf, util::utos(buf, 18446744073709551615ULL)})); + assert_stdstring_equal("0", (std::string{buf, util::utos(buf, 0)})); + assert_stdstring_equal("123", (std::string{buf, util::utos(buf, 123)})); + assert_stdstring_equal( + "18446744073709551615", + (std::string{buf, util::utos(buf, 18446744073709551615ULL)})); } void test_util_make_string_ref_uint(void) { BlockAllocator balloc(1024, 1024); - CU_ASSERT("0" == util::make_string_ref_uint(balloc, 0)); - CU_ASSERT("123" == util::make_string_ref_uint(balloc, 123)); - CU_ASSERT("18446744073709551615" == - util::make_string_ref_uint(balloc, 18446744073709551615ULL)); + assert_stdstring_equal("0", util::make_string_ref_uint(balloc, 0).str()); + assert_stdstring_equal("123", util::make_string_ref_uint(balloc, 123).str()); + assert_stdstring_equal( + "18446744073709551615", + util::make_string_ref_uint(balloc, 18446744073709551615ULL).str()); } void test_util_utos_unit(void) { - CU_ASSERT("0" == util::utos_unit(0)); - CU_ASSERT("1023" == util::utos_unit(1023)); - CU_ASSERT("1K" == util::utos_unit(1024)); - CU_ASSERT("1K" == util::utos_unit(1025)); - CU_ASSERT("1M" == util::utos_unit(1 << 20)); - CU_ASSERT("1G" == util::utos_unit(1 << 30)); - CU_ASSERT("1024G" == util::utos_unit(1LL << 40)); + assert_stdstring_equal("0", util::utos_unit(0)); + assert_stdstring_equal("1023", util::utos_unit(1023)); + assert_stdstring_equal("1K", util::utos_unit(1024)); + assert_stdstring_equal("1K", util::utos_unit(1025)); + assert_stdstring_equal("1M", util::utos_unit(1 << 20)); + assert_stdstring_equal("1G", util::utos_unit(1 << 30)); + assert_stdstring_equal("1024G", util::utos_unit(1LL << 40)); } void test_util_utos_funit(void) { - CU_ASSERT("0" == util::utos_funit(0)); - CU_ASSERT("1023" == util::utos_funit(1023)); - CU_ASSERT("1.00K" == util::utos_funit(1024)); - CU_ASSERT("1.00K" == util::utos_funit(1025)); - CU_ASSERT("1.09K" == util::utos_funit(1119)); - CU_ASSERT("1.27K" == util::utos_funit(1300)); - CU_ASSERT("1.00M" == util::utos_funit(1 << 20)); - CU_ASSERT("1.18M" == util::utos_funit(1234567)); - CU_ASSERT("1.00G" == util::utos_funit(1 << 30)); - CU_ASSERT("4492450797.23G" == util::utos_funit(4823732313248234343LL)); - CU_ASSERT("1024.00G" == util::utos_funit(1LL << 40)); + assert_stdstring_equal("0", util::utos_funit(0)); + assert_stdstring_equal("1023", util::utos_funit(1023)); + assert_stdstring_equal("1.00K", util::utos_funit(1024)); + assert_stdstring_equal("1.00K", util::utos_funit(1025)); + assert_stdstring_equal("1.09K", util::utos_funit(1119)); + assert_stdstring_equal("1.27K", util::utos_funit(1300)); + assert_stdstring_equal("1.00M", util::utos_funit(1 << 20)); + assert_stdstring_equal("1.18M", util::utos_funit(1234567)); + assert_stdstring_equal("1.00G", util::utos_funit(1 << 30)); + assert_stdstring_equal("4492450797.23G", + util::utos_funit(4823732313248234343LL)); + assert_stdstring_equal("1024.00G", util::utos_funit(1LL << 40)); } void test_util_parse_uint_with_unit(void) { - CU_ASSERT(0 == util::parse_uint_with_unit("0")); - CU_ASSERT(1023 == util::parse_uint_with_unit("1023")); - CU_ASSERT(1024 == util::parse_uint_with_unit("1k")); - CU_ASSERT(2048 == util::parse_uint_with_unit("2K")); - CU_ASSERT(1 << 20 == util::parse_uint_with_unit("1m")); - CU_ASSERT(1 << 21 == util::parse_uint_with_unit("2M")); - CU_ASSERT(1 << 30 == util::parse_uint_with_unit("1g")); - CU_ASSERT(1LL << 31 == util::parse_uint_with_unit("2G")); - CU_ASSERT(9223372036854775807LL == - util::parse_uint_with_unit("9223372036854775807")); + assert_int64(0, ==, util::parse_uint_with_unit("0")); + assert_int64(1023, ==, util::parse_uint_with_unit("1023")); + assert_int64(1024, ==, util::parse_uint_with_unit("1k")); + assert_int64(2048, ==, util::parse_uint_with_unit("2K")); + assert_int64(1 << 20, ==, util::parse_uint_with_unit("1m")); + assert_int64(1 << 21, ==, util::parse_uint_with_unit("2M")); + assert_int64(1 << 30, ==, util::parse_uint_with_unit("1g")); + assert_int64(1LL << 31, ==, util::parse_uint_with_unit("2G")); + assert_int64(9223372036854775807LL, ==, + util::parse_uint_with_unit("9223372036854775807")); // check overflow case - CU_ASSERT(-1 == util::parse_uint_with_unit("9223372036854775808")); - CU_ASSERT(-1 == util::parse_uint_with_unit("10000000000000000000")); - CU_ASSERT(-1 == util::parse_uint_with_unit("9223372036854775807G")); + assert_int64(-1, ==, util::parse_uint_with_unit("9223372036854775808")); + assert_int64(-1, ==, util::parse_uint_with_unit("10000000000000000000")); + assert_int64(-1, ==, util::parse_uint_with_unit("9223372036854775807G")); // bad characters - CU_ASSERT(-1 == util::parse_uint_with_unit("1.1")); - CU_ASSERT(-1 == util::parse_uint_with_unit("1a")); - CU_ASSERT(-1 == util::parse_uint_with_unit("a1")); - CU_ASSERT(-1 == util::parse_uint_with_unit("1T")); - CU_ASSERT(-1 == util::parse_uint_with_unit("")); + assert_int64(-1, ==, util::parse_uint_with_unit("1.1")); + assert_int64(-1, ==, util::parse_uint_with_unit("1a")); + assert_int64(-1, ==, util::parse_uint_with_unit("a1")); + assert_int64(-1, ==, util::parse_uint_with_unit("1T")); + assert_int64(-1, ==, util::parse_uint_with_unit("")); } void test_util_parse_uint(void) { - CU_ASSERT(0 == util::parse_uint("0")); - CU_ASSERT(1023 == util::parse_uint("1023")); - CU_ASSERT(-1 == util::parse_uint("1k")); - CU_ASSERT(9223372036854775807LL == util::parse_uint("9223372036854775807")); + assert_int64(0, ==, util::parse_uint("0")); + assert_int64(1023, ==, util::parse_uint("1023")); + assert_int64(-1, ==, util::parse_uint("1k")); + assert_int64(9223372036854775807LL, ==, + util::parse_uint("9223372036854775807")); // check overflow case - CU_ASSERT(-1 == util::parse_uint("9223372036854775808")); - CU_ASSERT(-1 == util::parse_uint("10000000000000000000")); + assert_int64(-1, ==, util::parse_uint("9223372036854775808")); + assert_int64(-1, ==, util::parse_uint("10000000000000000000")); // bad characters - CU_ASSERT(-1 == util::parse_uint("1.1")); - CU_ASSERT(-1 == util::parse_uint("1a")); - CU_ASSERT(-1 == util::parse_uint("a1")); - CU_ASSERT(-1 == util::parse_uint("1T")); - CU_ASSERT(-1 == util::parse_uint("")); + assert_int64(-1, ==, util::parse_uint("1.1")); + assert_int64(-1, ==, util::parse_uint("1a")); + assert_int64(-1, ==, util::parse_uint("a1")); + assert_int64(-1, ==, util::parse_uint("1T")); + assert_int64(-1, ==, util::parse_uint("")); } void test_util_parse_duration_with_unit(void) { - CU_ASSERT(0. == util::parse_duration_with_unit("0")); - CU_ASSERT(123. == util::parse_duration_with_unit("123")); - CU_ASSERT(123. == util::parse_duration_with_unit("123s")); - CU_ASSERT(0.500 == util::parse_duration_with_unit("500ms")); - CU_ASSERT(123. == util::parse_duration_with_unit("123S")); - CU_ASSERT(0.500 == util::parse_duration_with_unit("500MS")); - CU_ASSERT(180 == util::parse_duration_with_unit("3m")); - CU_ASSERT(3600 * 5 == util::parse_duration_with_unit("5h")); + assert_double(0., ==, util::parse_duration_with_unit("0")); + assert_double(123., ==, util::parse_duration_with_unit("123")); + assert_double(123., ==, util::parse_duration_with_unit("123s")); + assert_double(0.500, ==, util::parse_duration_with_unit("500ms")); + assert_double(123., ==, util::parse_duration_with_unit("123S")); + assert_double(0.500, ==, util::parse_duration_with_unit("500MS")); + assert_double(180, ==, util::parse_duration_with_unit("3m")); + assert_double(3600 * 5, ==, util::parse_duration_with_unit("5h")); auto err = std::numeric_limits::infinity(); // check overflow case - CU_ASSERT(err == util::parse_duration_with_unit("9223372036854775808")); + assert_double(err, ==, util::parse_duration_with_unit("9223372036854775808")); // bad characters - CU_ASSERT(err == util::parse_duration_with_unit("0u")); - CU_ASSERT(err == util::parse_duration_with_unit("0xs")); - CU_ASSERT(err == util::parse_duration_with_unit("0mt")); - CU_ASSERT(err == util::parse_duration_with_unit("0mss")); - CU_ASSERT(err == util::parse_duration_with_unit("s")); - CU_ASSERT(err == util::parse_duration_with_unit("ms")); + assert_double(err, ==, util::parse_duration_with_unit("0u")); + assert_double(err, ==, util::parse_duration_with_unit("0xs")); + assert_double(err, ==, util::parse_duration_with_unit("0mt")); + assert_double(err, ==, util::parse_duration_with_unit("0mss")); + assert_double(err, ==, util::parse_duration_with_unit("s")); + assert_double(err, ==, util::parse_duration_with_unit("ms")); } void test_util_duration_str(void) { - CU_ASSERT("0" == util::duration_str(0.)); - CU_ASSERT("1s" == util::duration_str(1.)); - CU_ASSERT("500ms" == util::duration_str(0.5)); - CU_ASSERT("1500ms" == util::duration_str(1.5)); - CU_ASSERT("2m" == util::duration_str(120.)); - CU_ASSERT("121s" == util::duration_str(121.)); - CU_ASSERT("1h" == util::duration_str(3600.)); + assert_stdstring_equal("0", util::duration_str(0.)); + assert_stdstring_equal("1s", util::duration_str(1.)); + assert_stdstring_equal("500ms", util::duration_str(0.5)); + assert_stdstring_equal("1500ms", util::duration_str(1.5)); + assert_stdstring_equal("2m", util::duration_str(120.)); + assert_stdstring_equal("121s", util::duration_str(121.)); + assert_stdstring_equal("1h", util::duration_str(3600.)); } void test_util_format_duration(void) { - CU_ASSERT("0us" == util::format_duration(std::chrono::microseconds(0))); - CU_ASSERT("999us" == util::format_duration(std::chrono::microseconds(999))); - CU_ASSERT("1.00ms" == util::format_duration(std::chrono::microseconds(1000))); - CU_ASSERT("1.09ms" == util::format_duration(std::chrono::microseconds(1090))); - CU_ASSERT("1.01ms" == util::format_duration(std::chrono::microseconds(1009))); - CU_ASSERT("999.99ms" == - util::format_duration(std::chrono::microseconds(999990))); - CU_ASSERT("1.00s" == - util::format_duration(std::chrono::microseconds(1000000))); - CU_ASSERT("1.05s" == - util::format_duration(std::chrono::microseconds(1050000))); + assert_stdstring_equal("0us", + util::format_duration(std::chrono::microseconds(0))); + assert_stdstring_equal("999us", + util::format_duration(std::chrono::microseconds(999))); + assert_stdstring_equal( + "1.00ms", util::format_duration(std::chrono::microseconds(1000))); + assert_stdstring_equal( + "1.09ms", util::format_duration(std::chrono::microseconds(1090))); + assert_stdstring_equal( + "1.01ms", util::format_duration(std::chrono::microseconds(1009))); + assert_stdstring_equal( + "999.99ms", util::format_duration(std::chrono::microseconds(999990))); + assert_stdstring_equal( + "1.00s", util::format_duration(std::chrono::microseconds(1000000))); + assert_stdstring_equal( + "1.05s", util::format_duration(std::chrono::microseconds(1050000))); - CU_ASSERT("0us" == util::format_duration(0.)); - CU_ASSERT("999us" == util::format_duration(0.000999)); - CU_ASSERT("1.00ms" == util::format_duration(0.001)); - CU_ASSERT("1.09ms" == util::format_duration(0.00109)); - CU_ASSERT("1.01ms" == util::format_duration(0.001009)); - CU_ASSERT("999.99ms" == util::format_duration(0.99999)); - CU_ASSERT("1.00s" == util::format_duration(1.)); - CU_ASSERT("1.05s" == util::format_duration(1.05)); + assert_stdstring_equal("0us", util::format_duration(0.)); + assert_stdstring_equal("999us", util::format_duration(0.000999)); + assert_stdstring_equal("1.00ms", util::format_duration(0.001)); + assert_stdstring_equal("1.09ms", util::format_duration(0.00109)); + assert_stdstring_equal("1.01ms", util::format_duration(0.001009)); + assert_stdstring_equal("999.99ms", util::format_duration(0.99999)); + assert_stdstring_equal("1.00s", util::format_duration(1.)); + assert_stdstring_equal("1.05s", util::format_duration(1.05)); } void test_util_starts_with(void) { - CU_ASSERT(util::starts_with(StringRef::from_lit("foo"), - StringRef::from_lit("foo"))); - CU_ASSERT(util::starts_with(StringRef::from_lit("fooo"), - StringRef::from_lit("foo"))); - CU_ASSERT(util::starts_with(StringRef::from_lit("ofoo"), StringRef{})); - CU_ASSERT(!util::starts_with(StringRef::from_lit("ofoo"), - StringRef::from_lit("foo"))); - - CU_ASSERT(util::istarts_with(StringRef::from_lit("FOO"), - StringRef::from_lit("fOO"))); - CU_ASSERT(util::istarts_with(StringRef::from_lit("ofoo"), StringRef{})); - CU_ASSERT(util::istarts_with(StringRef::from_lit("fOOo"), - StringRef::from_lit("Foo"))); - CU_ASSERT(!util::istarts_with(StringRef::from_lit("ofoo"), + assert_true(util::starts_with(StringRef::from_lit("foo"), StringRef::from_lit("foo"))); + assert_true(util::starts_with(StringRef::from_lit("fooo"), + StringRef::from_lit("foo"))); + assert_true(util::starts_with(StringRef::from_lit("ofoo"), StringRef{})); + assert_false(util::starts_with(StringRef::from_lit("ofoo"), + StringRef::from_lit("foo"))); - CU_ASSERT(util::istarts_with_l(StringRef::from_lit("fOOo"), "Foo")); - CU_ASSERT(!util::istarts_with_l(StringRef::from_lit("ofoo"), "foo")); + assert_true(util::istarts_with(StringRef::from_lit("FOO"), + StringRef::from_lit("fOO"))); + assert_true(util::istarts_with(StringRef::from_lit("ofoo"), StringRef{})); + assert_true(util::istarts_with(StringRef::from_lit("fOOo"), + StringRef::from_lit("Foo"))); + assert_false(util::istarts_with(StringRef::from_lit("ofoo"), + StringRef::from_lit("foo"))); + + assert_true(util::istarts_with_l(StringRef::from_lit("fOOo"), "Foo")); + assert_false(util::istarts_with_l(StringRef::from_lit("ofoo"), "foo")); } void test_util_ends_with(void) { - CU_ASSERT( + assert_true( util::ends_with(StringRef::from_lit("foo"), StringRef::from_lit("foo"))); - CU_ASSERT(util::ends_with(StringRef::from_lit("foo"), StringRef{})); - CU_ASSERT( + assert_true(util::ends_with(StringRef::from_lit("foo"), StringRef{})); + assert_true( util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("foo"))); - CU_ASSERT( - !util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo"))); + assert_false( + util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo"))); - CU_ASSERT( + assert_true( util::iends_with(StringRef::from_lit("fOo"), StringRef::from_lit("Foo"))); - CU_ASSERT(util::iends_with(StringRef::from_lit("foo"), StringRef{})); - CU_ASSERT(util::iends_with(StringRef::from_lit("oFoo"), - StringRef::from_lit("fOO"))); - CU_ASSERT(!util::iends_with(StringRef::from_lit("ofoo"), - StringRef::from_lit("fo"))); + assert_true(util::iends_with(StringRef::from_lit("foo"), StringRef{})); + assert_true(util::iends_with(StringRef::from_lit("oFoo"), + StringRef::from_lit("fOO"))); + assert_false( + util::iends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo"))); - CU_ASSERT(util::iends_with_l(StringRef::from_lit("oFoo"), "fOO")); - CU_ASSERT(!util::iends_with_l(StringRef::from_lit("ofoo"), "fo")); + assert_true(util::iends_with_l(StringRef::from_lit("oFoo"), "fOO")); + assert_false(util::iends_with_l(StringRef::from_lit("ofoo"), "fo")); } void test_util_parse_http_date(void) { - CU_ASSERT(1001939696 == util::parse_http_date(StringRef::from_lit( - "Mon, 1 Oct 2001 12:34:56 GMT"))); + assert_int64(1001939696, ==, + util::parse_http_date( + StringRef::from_lit("Mon, 1 Oct 2001 12:34:56 GMT"))); } void test_util_localtime_date(void) { @@ -450,25 +528,28 @@ void test_util_localtime_date(void) { #endif // !__linux__ tzset(); - CU_ASSERT_STRING_EQUAL("02/Oct/2001:00:34:56 +1200", - util::common_log_date(1001939696).c_str()); - CU_ASSERT_STRING_EQUAL("2001-10-02T00:34:56.123+12:00", - util::iso8601_date(1001939696000LL + 123).c_str()); + assert_stdstring_equal("02/Oct/2001:00:34:56 +1200", + util::common_log_date(1001939696)); + assert_stdstring_equal("2001-10-02T00:34:56.123+12:00", + util::iso8601_date(1001939696000LL + 123)); std::array common_buf; - CU_ASSERT("02/Oct/2001:00:34:56 +1200" == - util::format_common_log(common_buf.data(), - std::chrono::system_clock::time_point( - std::chrono::seconds(1001939696)))); + assert_stdstring_equal( + "02/Oct/2001:00:34:56 +1200", + util::format_common_log(common_buf.data(), + std::chrono::system_clock::time_point( + std::chrono::seconds(1001939696))) + .str()); std::array iso8601_buf; - CU_ASSERT( - "2001-10-02T00:34:56.123+12:00" == + assert_stdstring_equal( + "2001-10-02T00:34:56.123+12:00", util::format_iso8601(iso8601_buf.data(), std::chrono::system_clock::time_point( - std::chrono::milliseconds(1001939696123LL)))); + std::chrono::milliseconds(1001939696123LL))) + .str()); if (tz) { setenv("TZ", tz, 1); @@ -486,7 +567,7 @@ void test_util_get_uint64(void) { auto n = util::get_uint64(v.data()); - CU_ASSERT(0x01123456ff9aabbcULL == n); + assert_uint64(0x01123456ff9aabbcULL, ==, n); } { auto v = std::array{ @@ -494,83 +575,91 @@ void test_util_get_uint64(void) { auto n = util::get_uint64(v.data()); - CU_ASSERT(0xffffffffffffffffULL == n); + assert_uint64(0xffffffffffffffffULL, ==, n); } } void test_util_parse_config_str_list(void) { auto res = util::parse_config_str_list(StringRef::from_lit("a")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("a" == res[0]); + assert_size(1, ==, res.size()); + assert_stdstring_equal("a", res[0]); res = util::parse_config_str_list(StringRef::from_lit("a,")); - CU_ASSERT(2 == res.size()); - CU_ASSERT("a" == res[0]); - CU_ASSERT("" == res[1]); + assert_size(2, ==, res.size()); + assert_stdstring_equal("a", res[0]); + assert_stdstring_equal("", res[1]); res = util::parse_config_str_list(StringRef::from_lit(":a::"), ':'); - CU_ASSERT(4 == res.size()); - CU_ASSERT("" == res[0]); - CU_ASSERT("a" == res[1]); - CU_ASSERT("" == res[2]); - CU_ASSERT("" == res[3]); + assert_size(4, ==, res.size()); + assert_stdstring_equal("", res[0]); + assert_stdstring_equal("a", res[1]); + assert_stdstring_equal("", res[2]); + assert_stdstring_equal("", res[3]); res = util::parse_config_str_list(StringRef{}); - CU_ASSERT(1 == res.size()); - CU_ASSERT("" == res[0]); + assert_size(1, ==, res.size()); + assert_stdstring_equal("", res[0]); res = util::parse_config_str_list(StringRef::from_lit("alpha,bravo,charlie")); - CU_ASSERT(3 == res.size()); - CU_ASSERT("alpha" == res[0]); - CU_ASSERT("bravo" == res[1]); - CU_ASSERT("charlie" == res[2]); + assert_size(3, ==, res.size()); + assert_stdstring_equal("alpha", res[0]); + assert_stdstring_equal("bravo", res[1]); + assert_stdstring_equal("charlie", res[2]); } void test_util_make_http_hostport(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("localhost" == util::make_http_hostport( - balloc, StringRef::from_lit("localhost"), 80)); - CU_ASSERT("[::1]" == - util::make_http_hostport(balloc, StringRef::from_lit("::1"), 443)); - CU_ASSERT( - "localhost:3000" == - util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 3000)); + assert_stdstring_equal( + "localhost", + util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 80) + .str()); + assert_stdstring_equal( + "[::1]", + util::make_http_hostport(balloc, StringRef::from_lit("::1"), 443).str()); + assert_stdstring_equal( + "localhost:3000", + util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 3000) + .str()); } void test_util_make_hostport(void) { std::array hostport_buf; - CU_ASSERT("localhost:80" == - util::make_hostport(std::begin(hostport_buf), - StringRef::from_lit("localhost"), 80)); - CU_ASSERT("[::1]:443" == util::make_hostport(std::begin(hostport_buf), - StringRef::from_lit("::1"), - 443)); + assert_stdstring_equal( + "localhost:80", util::make_hostport(std::begin(hostport_buf), + StringRef::from_lit("localhost"), 80) + .str()); + assert_stdstring_equal("[::1]:443", + util::make_hostport(std::begin(hostport_buf), + StringRef::from_lit("::1"), 443) + .str()); BlockAllocator balloc(4096, 4096); - CU_ASSERT("localhost:80" == - util::make_hostport(balloc, StringRef::from_lit("localhost"), 80)); - CU_ASSERT("[::1]:443" == - util::make_hostport(balloc, StringRef::from_lit("::1"), 443)); + assert_stdstring_equal( + "localhost:80", + util::make_hostport(balloc, StringRef::from_lit("localhost"), 80).str()); + assert_stdstring_equal( + "[::1]:443", + util::make_hostport(balloc, StringRef::from_lit("::1"), 443).str()); } void test_util_strifind(void) { - CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), - StringRef::from_lit("gzip"))); + assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), + StringRef::from_lit("gzip"))); - CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), - StringRef::from_lit("dEflate"))); + assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), + StringRef::from_lit("dEflate"))); - CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), - StringRef::from_lit("BZIP2"))); + assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), + StringRef::from_lit("BZIP2"))); - CU_ASSERT(util::strifind(StringRef::from_lit("nghttp2"), StringRef{})); + assert_true(util::strifind(StringRef::from_lit("nghttp2"), StringRef{})); // Be aware this fact - CU_ASSERT(!util::strifind(StringRef{}, StringRef{})); + assert_false(util::strifind(StringRef{}, StringRef{})); - CU_ASSERT(!util::strifind(StringRef::from_lit("nghttp2"), - StringRef::from_lit("http1"))); + assert_false(util::strifind(StringRef::from_lit("nghttp2"), + StringRef::from_lit("http1"))); } void test_util_random_alpha_digit(void) { @@ -580,116 +669,117 @@ void test_util_random_alpha_digit(void) { auto p = util::random_alpha_digit(std::begin(data), std::end(data), gen); - CU_ASSERT(std::end(data) == p); + assert_true(std::end(data) == p); for (auto b : data) { - CU_ASSERT(('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z') || - ('0' <= b && b <= '9')); + assert_true(('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z') || + ('0' <= b && b <= '9')); } } void test_util_format_hex(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("0ff0" == - util::format_hex(balloc, StringRef::from_lit("\x0f\xf0"))); - CU_ASSERT("" == util::format_hex(balloc, StringRef::from_lit(""))); + assert_stdstring_equal( + "0ff0", util::format_hex(balloc, StringRef::from_lit("\x0f\xf0")).str()); + assert_stdstring_equal( + "", util::format_hex(balloc, StringRef::from_lit("")).str()); } void test_util_is_hex_string(void) { - CU_ASSERT(util::is_hex_string(StringRef{})); - CU_ASSERT(util::is_hex_string(StringRef::from_lit("0123456789abcdef"))); - CU_ASSERT(util::is_hex_string(StringRef::from_lit("0123456789ABCDEF"))); - CU_ASSERT(!util::is_hex_string(StringRef::from_lit("000"))); - CU_ASSERT(!util::is_hex_string(StringRef::from_lit("XX"))); + assert_true(util::is_hex_string(StringRef{})); + assert_true(util::is_hex_string(StringRef::from_lit("0123456789abcdef"))); + assert_true(util::is_hex_string(StringRef::from_lit("0123456789ABCDEF"))); + assert_false(util::is_hex_string(StringRef::from_lit("000"))); + assert_false(util::is_hex_string(StringRef::from_lit("XX"))); } void test_util_decode_hex(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("\x0f\xf0" == - util::decode_hex(balloc, StringRef::from_lit("0ff0"))); - CU_ASSERT("" == util::decode_hex(balloc, StringRef{})); + assert_stdstring_equal( + "\x0f\xf0", util::decode_hex(balloc, StringRef::from_lit("0ff0")).str()); + assert_stdstring_equal("", util::decode_hex(balloc, StringRef{}).str()); } void test_util_extract_host(void) { - CU_ASSERT(StringRef::from_lit("foo") == - util::extract_host(StringRef::from_lit("foo"))); - CU_ASSERT(StringRef::from_lit("foo") == - util::extract_host(StringRef::from_lit("foo:"))); - CU_ASSERT(StringRef::from_lit("foo") == - util::extract_host(StringRef::from_lit("foo:0"))); - CU_ASSERT(StringRef::from_lit("[::1]") == - util::extract_host(StringRef::from_lit("[::1]"))); - CU_ASSERT(StringRef::from_lit("[::1]") == - util::extract_host(StringRef::from_lit("[::1]:"))); + assert_stdstring_equal("foo", + util::extract_host(StringRef::from_lit("foo")).str()); + assert_stdstring_equal("foo", + util::extract_host(StringRef::from_lit("foo:")).str()); + assert_stdstring_equal( + "foo", util::extract_host(StringRef::from_lit("foo:0")).str()); + assert_stdstring_equal( + "[::1]", util::extract_host(StringRef::from_lit("[::1]")).str()); + assert_stdstring_equal( + "[::1]", util::extract_host(StringRef::from_lit("[::1]:")).str()); - CU_ASSERT(util::extract_host(StringRef::from_lit(":foo")).empty()); - CU_ASSERT(util::extract_host(StringRef::from_lit("[::1")).empty()); - CU_ASSERT(util::extract_host(StringRef::from_lit("[::1]0")).empty()); - CU_ASSERT(util::extract_host(StringRef{}).empty()); + assert_true(util::extract_host(StringRef::from_lit(":foo")).empty()); + assert_true(util::extract_host(StringRef::from_lit("[::1")).empty()); + assert_true(util::extract_host(StringRef::from_lit("[::1]0")).empty()); + assert_true(util::extract_host(StringRef{}).empty()); } void test_util_split_hostport(void) { - CU_ASSERT(std::make_pair(StringRef::from_lit("foo"), StringRef{}) == - util::split_hostport(StringRef::from_lit("foo"))); - CU_ASSERT( + assert_true(std::make_pair(StringRef::from_lit("foo"), StringRef{}) == + util::split_hostport(StringRef::from_lit("foo"))); + assert_true( std::make_pair(StringRef::from_lit("foo"), StringRef::from_lit("80")) == util::split_hostport(StringRef::from_lit("foo:80"))); - CU_ASSERT( + assert_true( std::make_pair(StringRef::from_lit("::1"), StringRef::from_lit("80")) == util::split_hostport(StringRef::from_lit("[::1]:80"))); - CU_ASSERT(std::make_pair(StringRef::from_lit("::1"), StringRef{}) == - util::split_hostport(StringRef::from_lit("[::1]"))); + assert_true(std::make_pair(StringRef::from_lit("::1"), StringRef{}) == + util::split_hostport(StringRef::from_lit("[::1]"))); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef{})); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef::from_lit("[::1]:"))); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef::from_lit("foo:"))); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef::from_lit("[::1:"))); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef::from_lit("[::1]80"))); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef{})); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef::from_lit("[::1]:"))); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef::from_lit("foo:"))); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef::from_lit("[::1:"))); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef::from_lit("[::1]80"))); } void test_util_split_str(void) { - CU_ASSERT(std::vector{StringRef::from_lit("")} == - util::split_str(StringRef::from_lit(""), ',')); - CU_ASSERT(std::vector{StringRef::from_lit("alpha")} == - util::split_str(StringRef::from_lit("alpha"), ',')); - CU_ASSERT((std::vector{StringRef::from_lit("alpha"), - StringRef::from_lit("")}) == - util::split_str(StringRef::from_lit("alpha,"), ',')); - CU_ASSERT((std::vector{StringRef::from_lit("alpha"), - StringRef::from_lit("bravo")}) == - util::split_str(StringRef::from_lit("alpha,bravo"), ',')); - CU_ASSERT((std::vector{StringRef::from_lit("alpha"), - StringRef::from_lit("bravo"), - StringRef::from_lit("charlie")}) == - util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',')); - CU_ASSERT( + assert_true(std::vector{StringRef::from_lit("")} == + util::split_str(StringRef::from_lit(""), ',')); + assert_true(std::vector{StringRef::from_lit("alpha")} == + util::split_str(StringRef::from_lit("alpha"), ',')); + assert_true((std::vector{StringRef::from_lit("alpha"), + StringRef::from_lit("")}) == + util::split_str(StringRef::from_lit("alpha,"), ',')); + assert_true((std::vector{StringRef::from_lit("alpha"), + StringRef::from_lit("bravo")}) == + util::split_str(StringRef::from_lit("alpha,bravo"), ',')); + assert_true((std::vector{StringRef::from_lit("alpha"), + StringRef::from_lit("bravo"), + StringRef::from_lit("charlie")}) == + util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',')); + assert_true( (std::vector{StringRef::from_lit("alpha"), StringRef::from_lit("bravo"), StringRef::from_lit("charlie")}) == util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 0)); - CU_ASSERT(std::vector{StringRef::from_lit("")} == - util::split_str(StringRef::from_lit(""), ',', 1)); - CU_ASSERT(std::vector{StringRef::from_lit("")} == - util::split_str(StringRef::from_lit(""), ',', 2)); - CU_ASSERT( + assert_true(std::vector{StringRef::from_lit("")} == + util::split_str(StringRef::from_lit(""), ',', 1)); + assert_true(std::vector{StringRef::from_lit("")} == + util::split_str(StringRef::from_lit(""), ',', 2)); + assert_true( (std::vector{StringRef::from_lit("alpha"), StringRef::from_lit("bravo,charlie")}) == util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 2)); - CU_ASSERT(std::vector{StringRef::from_lit("alpha")} == - util::split_str(StringRef::from_lit("alpha"), ',', 2)); - CU_ASSERT((std::vector{StringRef::from_lit("alpha"), - StringRef::from_lit("")}) == - util::split_str(StringRef::from_lit("alpha,"), ',', 2)); - CU_ASSERT(std::vector{StringRef::from_lit("alpha")} == - util::split_str(StringRef::from_lit("alpha"), ',', 0)); - CU_ASSERT( + assert_true(std::vector{StringRef::from_lit("alpha")} == + util::split_str(StringRef::from_lit("alpha"), ',', 2)); + assert_true((std::vector{StringRef::from_lit("alpha"), + StringRef::from_lit("")}) == + util::split_str(StringRef::from_lit("alpha,"), ',', 2)); + assert_true(std::vector{StringRef::from_lit("alpha")} == + util::split_str(StringRef::from_lit("alpha"), ',', 0)); + assert_true( std::vector{StringRef::from_lit("alpha,bravo,charlie")} == util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 1)); } @@ -697,11 +787,16 @@ void test_util_split_str(void) { void test_util_rstrip(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha"))); - CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha "))); - CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha \t"))); - CU_ASSERT("" == util::rstrip(balloc, StringRef::from_lit(""))); - CU_ASSERT("" == util::rstrip(balloc, StringRef::from_lit("\t\t\t "))); + assert_stdstring_equal( + "alpha", util::rstrip(balloc, StringRef::from_lit("alpha")).str()); + assert_stdstring_equal( + "alpha", util::rstrip(balloc, StringRef::from_lit("alpha ")).str()); + assert_stdstring_equal( + "alpha", util::rstrip(balloc, StringRef::from_lit("alpha \t")).str()); + assert_stdstring_equal("", + util::rstrip(balloc, StringRef::from_lit("")).str()); + assert_stdstring_equal( + "", util::rstrip(balloc, StringRef::from_lit("\t\t\t ")).str()); } } // namespace shrpx diff --git a/yass/third_party/nghttp2/src/util_test.h b/yass/third_party/nghttp2/src/util_test.h index 48925ab2b1..8b9608b5c5 100644 --- a/yass/third_party/nghttp2/src/util_test.h +++ b/yass/third_party/nghttp2/src/util_test.h @@ -29,46 +29,52 @@ # include #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_util_streq(void); -void test_util_strieq(void); -void test_util_inp_strlower(void); -void test_util_to_base64(void); -void test_util_to_token68(void); -void test_util_percent_encode_token(void); -void test_util_percent_decode(void); -void test_util_quote_string(void); -void test_util_utox(void); -void test_util_http_date(void); -void test_util_select_h2(void); -void test_util_ipv6_numeric_addr(void); -void test_util_utos(void); -void test_util_make_string_ref_uint(void); -void test_util_utos_unit(void); -void test_util_utos_funit(void); -void test_util_parse_uint_with_unit(void); -void test_util_parse_uint(void); -void test_util_parse_duration_with_unit(void); -void test_util_duration_str(void); -void test_util_format_duration(void); -void test_util_starts_with(void); -void test_util_ends_with(void); -void test_util_parse_http_date(void); -void test_util_localtime_date(void); -void test_util_get_uint64(void); -void test_util_parse_config_str_list(void); -void test_util_make_http_hostport(void); -void test_util_make_hostport(void); -void test_util_strifind(void); -void test_util_random_alpha_digit(void); -void test_util_format_hex(void); -void test_util_is_hex_string(void); -void test_util_decode_hex(void); -void test_util_extract_host(void); -void test_util_split_hostport(void); -void test_util_split_str(void); -void test_util_rstrip(void); +extern const MunitSuite util_suite; + +munit_void_test_decl(test_util_streq); +munit_void_test_decl(test_util_strieq); +munit_void_test_decl(test_util_inp_strlower); +munit_void_test_decl(test_util_to_base64); +munit_void_test_decl(test_util_to_token68); +munit_void_test_decl(test_util_percent_encode_token); +munit_void_test_decl(test_util_percent_decode); +munit_void_test_decl(test_util_quote_string); +munit_void_test_decl(test_util_utox); +munit_void_test_decl(test_util_http_date); +munit_void_test_decl(test_util_select_h2); +munit_void_test_decl(test_util_ipv6_numeric_addr); +munit_void_test_decl(test_util_utos); +munit_void_test_decl(test_util_make_string_ref_uint); +munit_void_test_decl(test_util_utos_unit); +munit_void_test_decl(test_util_utos_funit); +munit_void_test_decl(test_util_parse_uint_with_unit); +munit_void_test_decl(test_util_parse_uint); +munit_void_test_decl(test_util_parse_duration_with_unit); +munit_void_test_decl(test_util_duration_str); +munit_void_test_decl(test_util_format_duration); +munit_void_test_decl(test_util_starts_with); +munit_void_test_decl(test_util_ends_with); +munit_void_test_decl(test_util_parse_http_date); +munit_void_test_decl(test_util_localtime_date); +munit_void_test_decl(test_util_get_uint64); +munit_void_test_decl(test_util_parse_config_str_list); +munit_void_test_decl(test_util_make_http_hostport); +munit_void_test_decl(test_util_make_hostport); +munit_void_test_decl(test_util_strifind); +munit_void_test_decl(test_util_random_alpha_digit); +munit_void_test_decl(test_util_format_hex); +munit_void_test_decl(test_util_is_hex_string); +munit_void_test_decl(test_util_decode_hex); +munit_void_test_decl(test_util_extract_host); +munit_void_test_decl(test_util_split_hostport); +munit_void_test_decl(test_util_split_str); +munit_void_test_decl(test_util_rstrip); } // namespace shrpx diff --git a/yass/third_party/nghttp2/tests/CMakeLists.txt b/yass/third_party/nghttp2/tests/CMakeLists.txt index 0e05235e18..852cb106e3 100644 --- a/yass/third_party/nghttp2/tests/CMakeLists.txt +++ b/yass/third_party/nghttp2/tests/CMakeLists.txt @@ -1,60 +1,52 @@ # XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem -if(HAVE_CUNIT) - string(REPLACE " " ";" c_flags "${WARNCFLAGS}") - add_compile_options(${c_flags}) +string(REPLACE " " ";" c_flags "${WARNCFLAGS}") +add_compile_options(${c_flags}) - include_directories( - "${CMAKE_SOURCE_DIR}/lib/includes" - "${CMAKE_SOURCE_DIR}/lib" - "${CMAKE_BINARY_DIR}/lib/includes" - ${CUNIT_INCLUDE_DIRS} - ) +include_directories( + "${CMAKE_SOURCE_DIR}/lib/includes" + "${CMAKE_SOURCE_DIR}/lib" + "${CMAKE_SOURCE_DIR}/tests/munit" + "${CMAKE_BINARY_DIR}/lib/includes" +) - set(MAIN_SOURCES - main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c +set(MAIN_SOURCES + main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c + nghttp2_test_helper.c + nghttp2_frame_test.c + nghttp2_stream_test.c + nghttp2_session_test.c + nghttp2_hd_test.c + nghttp2_alpn_test.c + nghttp2_helper_test.c + nghttp2_buf_test.c + nghttp2_http_test.c + nghttp2_extpri_test.c + nghttp2_ratelim_test.c + munit/munit.c +) + +add_executable(main EXCLUDE_FROM_ALL + ${MAIN_SOURCES} +) +target_link_libraries(main + nghttp2_static +) +add_test(main main) +add_dependencies(check main) + +if(ENABLE_FAILMALLOC) + set(FAILMALLOC_SOURCES + failmalloc.c failmalloc_test.c + malloc_wrapper.c nghttp2_test_helper.c - nghttp2_frame_test.c - nghttp2_stream_test.c - nghttp2_session_test.c - nghttp2_hd_test.c - nghttp2_npn_test.c - nghttp2_helper_test.c - nghttp2_buf_test.c - nghttp2_http_test.c - nghttp2_extpri_test.c - nghttp2_ratelim_test.c + munit/munit.c ) - - add_executable(main EXCLUDE_FROM_ALL - ${MAIN_SOURCES} + add_executable(failmalloc EXCLUDE_FROM_ALL + ${FAILMALLOC_SOURCES} ) - target_include_directories(main PRIVATE ${CUNIT_INCLUDE_DIRS}) - target_link_libraries(main + target_link_libraries(failmalloc nghttp2_static - ${CUNIT_LIBRARIES} ) - add_test(main main) - add_dependencies(check main) - - if(ENABLE_FAILMALLOC) - set(FAILMALLOC_SOURCES - failmalloc.c failmalloc_test.c - malloc_wrapper.c - nghttp2_test_helper.c - ) - add_executable(failmalloc EXCLUDE_FROM_ALL - ${FAILMALLOC_SOURCES} - ) - target_link_libraries(failmalloc - nghttp2_static - ${CUNIT_LIBRARIES} - ) - add_test(failmalloc failmalloc) - add_dependencies(check failmalloc) - endif() - - if(ENABLE_APP) - # EXTRA_DIST = end_to_end.py - # TESTS += end_to_end.py - endif() + add_test(failmalloc failmalloc) + add_dependencies(check failmalloc) endif() diff --git a/yass/third_party/nghttp2/tests/Makefile.am b/yass/third_party/nghttp2/tests/Makefile.am index e6cdde111c..456f65f69a 100644 --- a/yass/third_party/nghttp2/tests/Makefile.am +++ b/yass/third_party/nghttp2/tests/Makefile.am @@ -22,9 +22,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SUBDIRS = testdata -EXTRA_DIST = CMakeLists.txt - -if HAVE_CUNIT +EXTRA_DIST = CMakeLists.txt munit/COPYING check_PROGRAMS = main @@ -38,22 +36,25 @@ OBJECTS = main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c \ nghttp2_stream_test.c \ nghttp2_session_test.c \ nghttp2_hd_test.c \ - nghttp2_npn_test.c \ + nghttp2_alpn_test.c \ nghttp2_helper_test.c \ nghttp2_buf_test.c \ nghttp2_http_test.c \ nghttp2_extpri_test.c \ - nghttp2_ratelim_test.c + nghttp2_ratelim_test.c \ + munit/munit.c HFILES = nghttp2_pq_test.h nghttp2_map_test.h nghttp2_queue_test.h \ nghttp2_session_test.h \ nghttp2_frame_test.h nghttp2_stream_test.h nghttp2_hd_test.h \ - nghttp2_npn_test.h nghttp2_helper_test.h \ + nghttp2_alpn_test.h nghttp2_helper_test.h \ + nghttp2_assertion.h \ nghttp2_test_helper.h \ nghttp2_buf_test.h \ nghttp2_http_test.h \ nghttp2_extpri_test.h \ - nghttp2_ratelim_test.h + nghttp2_ratelim_test.h \ + munit/munit.h main_SOURCES = $(HFILES) $(OBJECTS) @@ -65,13 +66,14 @@ else main_LDADD = ${top_builddir}/lib/.libs/*.o endif -main_LDADD += @CUNIT_LIBS@ @TESTLDADD@ +main_LDADD += @TESTLDADD@ main_LDFLAGS = -static if ENABLE_FAILMALLOC failmalloc_SOURCES = failmalloc.c failmalloc_test.c failmalloc_test.h \ malloc_wrapper.c malloc_wrapper.h \ - nghttp2_test_helper.c nghttp2_test_helper.h + nghttp2_test_helper.c nghttp2_test_helper.h \ + munit/munit.c munit/munit.h failmalloc_LDADD = $(main_LDADD) failmalloc_LDFLAGS = $(main_LDFLAGS) endif # ENABLE_FAILMALLOC @@ -79,22 +81,14 @@ endif # ENABLE_FAILMALLOC AM_CFLAGS = $(WARNCFLAGS) \ -I${top_srcdir}/lib \ -I${top_srcdir}/lib/includes \ + -I${top_srcdir}/tests/munit \ -I${top_builddir}/lib/includes \ -DBUILDING_NGHTTP2 \ -DNGHTTP2_STATICLIB \ - @CUNIT_CFLAGS@ @DEFS@ + @DEFS@ TESTS = main if ENABLE_FAILMALLOC TESTS += failmalloc endif # ENABLE_FAILMALLOC - -if ENABLE_APP - -# EXTRA_DIST = end_to_end.py -# TESTS += end_to_end.py - -endif # ENABLE_APP - -endif # HAVE_CUNIT diff --git a/yass/third_party/nghttp2/tests/end_to_end.py b/yass/third_party/nghttp2/tests/end_to_end.py deleted file mode 100755 index cfb3cdd7dc..0000000000 --- a/yass/third_party/nghttp2/tests/end_to_end.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python -"""End to end tests for the utility programs. - -This test assumes the utilities inside src directory have already been -built. - -At the moment top_buiddir is not in the environment, but top_builddir would be -more reliable than '..', so it's worth trying to pull it from the environment. -""" - -__author__ = 'Jim Morrison ' - - -import os -import subprocess -import time -import unittest - - -_PORT = 9893 - - -def _run_server(port, args): - srcdir = os.environ.get('srcdir', '.') - testdata = '%s/testdata' % srcdir - top_builddir = os.environ.get('top_builddir', '..') - base_args = ['%s/src/spdyd' % top_builddir, '-d', testdata] - if args: - base_args.extend(args) - base_args.extend([str(port), '%s/privkey.pem' % testdata, - '%s/cacert.pem' % testdata]) - return subprocess.Popen(base_args) - -def _check_server_up(port): - # Check this check for now. - time.sleep(1) - -def _kill_server(server): - while server.returncode is None: - server.terminate() - time.sleep(1) - server.poll() - - -class EndToEndSpdyTests(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.setUpServer([]) - - @classmethod - def setUpServer(cls, args): - cls.server = _run_server(_PORT, args) - _check_server_up(_PORT) - - @classmethod - def tearDownClass(cls): - _kill_server(cls.server) - - def setUp(self): - build_dir = os.environ.get('top_builddir', '..') - self.client = '%s/src/spdycat' % build_dir - self.stdout = 'No output' - - def call(self, path, args): - full_args = [self.client,'http://localhost:%d%s' % (_PORT, path)] + args - p = subprocess.Popen(full_args, stdout=subprocess.PIPE, - stdin=subprocess.PIPE) - self.stdout, self.stderr = p.communicate() - return p.returncode - - -class EndToEndSpdy2Tests(EndToEndSpdyTests): - def testSimpleRequest(self): - self.assertEquals(0, self.call('/', [])) - - def testSimpleRequestSpdy3(self): - self.assertEquals(0, self.call('/', ['-v', '-3'])) - self.assertIn('NPN selected the protocol: spdy/3', self.stdout) - - def testFailedRequests(self): - self.assertEquals( - 2, self.call('/', ['https://localhost:25/', 'http://localhost:79'])) - - def testOneFailedRequest(self): - self.assertEquals(1, subprocess.call([self.client, 'http://localhost:2/'])) - - def testOneTimedOutRequest(self): - self.assertEquals(1, self.call('/?spdyd_do_not_respond_to_req=yes', - ['--timeout=2'])) - self.assertEquals(0, self.call('/', ['--timeout=20'])) - - -class EndToEndSpdy3Tests(EndToEndSpdyTests): - @classmethod - def setUpClass(cls): - cls.setUpServer(['-3']) - - def testSimpleRequest(self): - self.assertEquals(0, self.call('/', ['-v'])) - self.assertIn('NPN selected the protocol: spdy/3', self.stdout) - - -if __name__ == '__main__': - unittest.main() diff --git a/yass/third_party/nghttp2/tests/failmalloc.c b/yass/third_party/nghttp2/tests/failmalloc.c index 6294cffff8..b491deb827 100644 --- a/yass/third_party/nghttp2/tests/failmalloc.c +++ b/yass/third_party/nghttp2/tests/failmalloc.c @@ -26,54 +26,20 @@ # include #endif /* HAVE_CONFIG_H */ -#include -#include -#include +#include "munit.h" + /* include test cases' include files here */ #include "failmalloc_test.h" -static int init_suite1(void) { return 0; } +int main(int argc, char *argv[]) { + const MunitSuite suites[] = { + failmalloc_suite, + {NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}, + }; + const MunitSuite suite = { + "", NULL, suites, 1, MUNIT_SUITE_OPTION_NONE, + }; -static int clean_suite1(void) { return 0; } - -int main(void) { - CU_pSuite pSuite = NULL; - unsigned int num_tests_failed; - - /* initialize the CUnit test registry */ - if (CUE_SUCCESS != CU_initialize_registry()) - return (int)CU_get_error(); - - /* add a suite to the registry */ - pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1); - if (NULL == pSuite) { - CU_cleanup_registry(); - return (int)CU_get_error(); - } - - /* add the tests to the suite */ - if (!CU_add_test(pSuite, "failmalloc_session_send", - test_nghttp2_session_send) || - !CU_add_test(pSuite, "failmalloc_session_send_server", - test_nghttp2_session_send_server) || - !CU_add_test(pSuite, "failmalloc_session_recv", - test_nghttp2_session_recv) || - !CU_add_test(pSuite, "failmalloc_frame", test_nghttp2_frame) || - !CU_add_test(pSuite, "failmalloc_hd", test_nghttp2_hd)) { - CU_cleanup_registry(); - return (int)CU_get_error(); - } - - /* Run all tests using the CUnit Basic interface */ - CU_basic_set_mode(CU_BRM_VERBOSE); - CU_basic_run_tests(); - num_tests_failed = CU_get_number_of_tests_failed(); - CU_cleanup_registry(); - if (CU_get_error() == CUE_SUCCESS) { - return (int)num_tests_failed; - } else { - printf("CUnit Error: %s\n", CU_get_error_msg()); - return (int)CU_get_error(); - } + return munit_suite_main(&suite, NULL, argc, argv); } diff --git a/yass/third_party/nghttp2/tests/failmalloc_test.c b/yass/third_party/nghttp2/tests/failmalloc_test.c index 594bc727e3..5b204fe44d 100644 --- a/yass/third_party/nghttp2/tests/failmalloc_test.c +++ b/yass/third_party/nghttp2/tests/failmalloc_test.c @@ -27,7 +27,7 @@ #include #include -#include +#include "munit.h" #include "nghttp2_session.h" #include "nghttp2_stream.h" @@ -36,6 +36,19 @@ #include "malloc_wrapper.h" #include "nghttp2_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_session_send), + munit_void_test(test_nghttp2_session_send_server), + munit_void_test(test_nghttp2_session_recv), + munit_void_test(test_nghttp2_frame), + munit_void_test(test_nghttp2_hd), + munit_test_end(), +}; + +const MunitSuite failmalloc_suite = { + "/failmalloc", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct { uint8_t data[8192]; uint8_t *datamark, *datalimit; @@ -59,18 +72,20 @@ static void data_feed_init(data_feed *df, nghttp2_bufs *bufs) { df->datalimit = df->data + data_length; } -static ssize_t null_send_callback(nghttp2_session *session, const uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize null_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { (void)session; (void)data; (void)flags; (void)user_data; - return (ssize_t)len; + return (nghttp2_ssize)len; } -static ssize_t data_feed_recv_callback(nghttp2_session *session, uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize data_feed_recv_callback(nghttp2_session *session, + uint8_t *data, size_t len, + int flags, void *user_data) { data_feed *df = ((my_user_data *)user_data)->df; size_t avail = (size_t)(df->datalimit - df->datamark); size_t wlen = nghttp2_min(avail, len); @@ -79,10 +94,10 @@ static ssize_t data_feed_recv_callback(nghttp2_session *session, uint8_t *data, memcpy(data, df->datamark, wlen); df->datamark += wlen; - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } -static ssize_t fixed_length_data_source_read_callback( +static nghttp2_ssize fixed_length_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { my_user_data *ud = (my_user_data *)user_data; @@ -101,7 +116,7 @@ static ssize_t fixed_length_data_source_read_callback( if (ud->data_source_length == 0) { *data_flags = NGHTTP2_DATA_FLAG_EOF; } - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } #define TEST_FAILMALLOC_RUN(FUN) \ @@ -129,12 +144,12 @@ static void run_nghttp2_session_send(void) { nghttp2_session_callbacks callbacks; nghttp2_nv nv[] = {MAKE_NV(":host", "example.org"), MAKE_NV(":scheme", "https")}; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_settings_entry iv[2]; my_user_data ud; int rv; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64 * 1024; @@ -149,7 +164,7 @@ static void run_nghttp2_session_send(void) { if (rv != 0) { goto client_new_fail; } - rv = nghttp2_submit_request(session, NULL, nv, ARRLEN(nv), &data_prd, NULL); + rv = nghttp2_submit_request2(session, NULL, nv, ARRLEN(nv), &data_prd, NULL); if (rv < 0) { goto fail; } @@ -169,7 +184,7 @@ static void run_nghttp2_session_send(void) { if (rv != 0) { goto fail; } - rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd); + rv = nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd); if (rv != 0) { goto fail; } @@ -221,7 +236,7 @@ static void run_nghttp2_session_send_server(void) { nghttp2_session_callbacks *callbacks; int rv; const uint8_t *txdata; - ssize_t txdatalen; + nghttp2_ssize txdatalen; const uint8_t origin[] = "nghttp2.org"; const uint8_t altsvc_field_value[] = "h2=\":443\""; static const uint8_t nghttp2[] = "https://nghttp2.org"; @@ -256,7 +271,7 @@ static void run_nghttp2_session_send_server(void) { goto fail; } - txdatalen = nghttp2_session_mem_send(session, &txdata); + txdatalen = nghttp2_session_mem_send2(session, &txdata); if (txdatalen < 0) { goto fail; @@ -296,7 +311,7 @@ static void run_nghttp2_session_recv(void) { } memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.recv_callback = data_feed_recv_callback; + callbacks.recv_callback2 = data_feed_recv_callback; ud.df = &df; nghttp2_failmalloc_pause(); diff --git a/yass/third_party/nghttp2/tests/failmalloc_test.h b/yass/third_party/nghttp2/tests/failmalloc_test.h index 576932a7a9..9664480807 100644 --- a/yass/third_party/nghttp2/tests/failmalloc_test.h +++ b/yass/third_party/nghttp2/tests/failmalloc_test.h @@ -29,10 +29,16 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_session_send(void); -void test_nghttp2_session_send_server(void); -void test_nghttp2_session_recv(void); -void test_nghttp2_frame(void); -void test_nghttp2_hd(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite failmalloc_suite; + +munit_void_test_decl(test_nghttp2_session_send); +munit_void_test_decl(test_nghttp2_session_send_server); +munit_void_test_decl(test_nghttp2_session_recv); +munit_void_test_decl(test_nghttp2_frame); +munit_void_test_decl(test_nghttp2_hd); #endif /* FAILMALLOC_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/main.c b/yass/third_party/nghttp2/tests/main.c index fc3c28d17a..ebee3def63 100644 --- a/yass/third_party/nghttp2/tests/main.c +++ b/yass/third_party/nghttp2/tests/main.c @@ -26,9 +26,8 @@ # include #endif /* HAVE_CONFIG_H */ -#include -#include -#include +#include "munit.h" + /* include test cases' include files here */ #include "nghttp2_pq_test.h" #include "nghttp2_map_test.h" @@ -37,7 +36,7 @@ #include "nghttp2_frame_test.h" #include "nghttp2_stream_test.h" #include "nghttp2_hd_test.h" -#include "nghttp2_npn_test.h" +#include "nghttp2_alpn_test.h" #include "nghttp2_helper_test.h" #include "nghttp2_buf_test.h" #include "nghttp2_http_test.h" @@ -46,428 +45,27 @@ extern int nghttp2_enable_strict_preface; -static int init_suite1(void) { return 0; } - -static int clean_suite1(void) { return 0; } - -int main(void) { - CU_pSuite pSuite = NULL; - unsigned int num_tests_failed; +int main(int argc, char *argv[]) { + const MunitSuite suites[] = { + pq_suite, + map_suite, + queue_suite, + frame_suite, + session_suite, + hd_suite, + alpn_suite, + helper_suite, + buf_suite, + http_suite, + extpri_suite, + ratelim_suite, + {NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}, + }; + const MunitSuite suite = { + "", NULL, suites, 1, MUNIT_SUITE_OPTION_NONE, + }; nghttp2_enable_strict_preface = 0; - /* initialize the CUnit test registry */ - if (CUE_SUCCESS != CU_initialize_registry()) - return (int)CU_get_error(); - - /* add a suite to the registry */ - pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1); - if (NULL == pSuite) { - CU_cleanup_registry(); - return (int)CU_get_error(); - } - - /* add the tests to the suite */ - if (!CU_add_test(pSuite, "pq", test_nghttp2_pq) || - !CU_add_test(pSuite, "pq_update", test_nghttp2_pq_update) || - !CU_add_test(pSuite, "pq_remove", test_nghttp2_pq_remove) || - !CU_add_test(pSuite, "map", test_nghttp2_map) || - !CU_add_test(pSuite, "map_functional", test_nghttp2_map_functional) || - !CU_add_test(pSuite, "map_each_free", test_nghttp2_map_each_free) || - !CU_add_test(pSuite, "queue", test_nghttp2_queue) || - !CU_add_test(pSuite, "npn", test_nghttp2_npn) || - !CU_add_test(pSuite, "session_recv", test_nghttp2_session_recv) || - !CU_add_test(pSuite, "session_recv_invalid_stream_id", - test_nghttp2_session_recv_invalid_stream_id) || - !CU_add_test(pSuite, "session_recv_invalid_frame", - test_nghttp2_session_recv_invalid_frame) || - !CU_add_test(pSuite, "session_recv_eof", test_nghttp2_session_recv_eof) || - !CU_add_test(pSuite, "session_recv_data", - test_nghttp2_session_recv_data) || - !CU_add_test(pSuite, "session_recv_data_no_auto_flow_control", - test_nghttp2_session_recv_data_no_auto_flow_control) || - !CU_add_test(pSuite, "session_recv_continuation", - test_nghttp2_session_recv_continuation) || - !CU_add_test(pSuite, "session_recv_headers_with_priority", - test_nghttp2_session_recv_headers_with_priority) || - !CU_add_test(pSuite, "session_recv_headers_with_padding", - test_nghttp2_session_recv_headers_with_padding) || - !CU_add_test(pSuite, "session_recv_headers_early_response", - test_nghttp2_session_recv_headers_early_response) || - !CU_add_test(pSuite, "session_recv_headers_for_closed_stream", - test_nghttp2_session_recv_headers_for_closed_stream) || - !CU_add_test(pSuite, "session_recv_headers_with_extpri", - test_nghttp2_session_recv_headers_with_extpri) || - !CU_add_test(pSuite, "session_server_recv_push_response", - test_nghttp2_session_server_recv_push_response) || - !CU_add_test(pSuite, "session_recv_premature_headers", - test_nghttp2_session_recv_premature_headers) || - !CU_add_test(pSuite, "session_recv_unknown_frame", - test_nghttp2_session_recv_unknown_frame) || - !CU_add_test(pSuite, "session_recv_unexpected_continuation", - test_nghttp2_session_recv_unexpected_continuation) || - !CU_add_test(pSuite, "session_recv_settings_header_table_size", - test_nghttp2_session_recv_settings_header_table_size) || - !CU_add_test(pSuite, "session_recv_too_large_frame_length", - test_nghttp2_session_recv_too_large_frame_length) || - !CU_add_test(pSuite, "session_recv_extension", - test_nghttp2_session_recv_extension) || - !CU_add_test(pSuite, "session_recv_altsvc", - test_nghttp2_session_recv_altsvc) || - !CU_add_test(pSuite, "session_recv_origin", - test_nghttp2_session_recv_origin) || - !CU_add_test(pSuite, "session_recv_priority_update", - test_nghttp2_session_recv_priority_update) || - !CU_add_test(pSuite, "session_continue", test_nghttp2_session_continue) || - !CU_add_test(pSuite, "session_add_frame", - test_nghttp2_session_add_frame) || - !CU_add_test(pSuite, "session_on_request_headers_received", - test_nghttp2_session_on_request_headers_received) || - !CU_add_test(pSuite, "session_on_response_headers_received", - test_nghttp2_session_on_response_headers_received) || - !CU_add_test(pSuite, "session_on_headers_received", - test_nghttp2_session_on_headers_received) || - !CU_add_test(pSuite, "session_on_push_response_headers_received", - test_nghttp2_session_on_push_response_headers_received) || - !CU_add_test(pSuite, "session_on_priority_received", - test_nghttp2_session_on_priority_received) || - !CU_add_test(pSuite, "session_on_rst_stream_received", - test_nghttp2_session_on_rst_stream_received) || - !CU_add_test(pSuite, "session_on_settings_received", - test_nghttp2_session_on_settings_received) || - !CU_add_test(pSuite, "session_on_push_promise_received", - test_nghttp2_session_on_push_promise_received) || - !CU_add_test(pSuite, "session_on_ping_received", - test_nghttp2_session_on_ping_received) || - !CU_add_test(pSuite, "session_on_goaway_received", - test_nghttp2_session_on_goaway_received) || - !CU_add_test(pSuite, "session_on_window_update_received", - test_nghttp2_session_on_window_update_received) || - !CU_add_test(pSuite, "session_on_data_received", - test_nghttp2_session_on_data_received) || - !CU_add_test(pSuite, "session_on_data_received_fail_fast", - test_nghttp2_session_on_data_received_fail_fast) || - !CU_add_test(pSuite, "session_on_altsvc_received", - test_nghttp2_session_on_altsvc_received) || - !CU_add_test(pSuite, "session_send_headers_start_stream", - test_nghttp2_session_send_headers_start_stream) || - !CU_add_test(pSuite, "session_send_headers_reply", - test_nghttp2_session_send_headers_reply) || - !CU_add_test(pSuite, "session_send_headers_frame_size_error", - test_nghttp2_session_send_headers_frame_size_error) || - !CU_add_test(pSuite, "session_send_headers_push_reply", - test_nghttp2_session_send_headers_push_reply) || - !CU_add_test(pSuite, "session_send_rst_stream", - test_nghttp2_session_send_rst_stream) || - !CU_add_test(pSuite, "session_send_push_promise", - test_nghttp2_session_send_push_promise) || - !CU_add_test(pSuite, "session_is_my_stream_id", - test_nghttp2_session_is_my_stream_id) || - !CU_add_test(pSuite, "session_upgrade2", test_nghttp2_session_upgrade2) || - !CU_add_test(pSuite, "session_reprioritize_stream", - test_nghttp2_session_reprioritize_stream) || - !CU_add_test( - pSuite, "session_reprioritize_stream_with_idle_stream_dep", - test_nghttp2_session_reprioritize_stream_with_idle_stream_dep) || - !CU_add_test(pSuite, "submit_data", test_nghttp2_submit_data) || - !CU_add_test(pSuite, "submit_data_read_length_too_large", - test_nghttp2_submit_data_read_length_too_large) || - !CU_add_test(pSuite, "submit_data_read_length_smallest", - test_nghttp2_submit_data_read_length_smallest) || - !CU_add_test(pSuite, "submit_data_twice", - test_nghttp2_submit_data_twice) || - !CU_add_test(pSuite, "submit_request_with_data", - test_nghttp2_submit_request_with_data) || - !CU_add_test(pSuite, "submit_request_without_data", - test_nghttp2_submit_request_without_data) || - !CU_add_test(pSuite, "submit_response_with_data", - test_nghttp2_submit_response_with_data) || - !CU_add_test(pSuite, "submit_response_without_data", - test_nghttp2_submit_response_without_data) || - !CU_add_test(pSuite, "Submit_response_push_response", - test_nghttp2_submit_response_push_response) || - !CU_add_test(pSuite, "submit_trailer", test_nghttp2_submit_trailer) || - !CU_add_test(pSuite, "submit_headers_start_stream", - test_nghttp2_submit_headers_start_stream) || - !CU_add_test(pSuite, "submit_headers_reply", - test_nghttp2_submit_headers_reply) || - !CU_add_test(pSuite, "submit_headers_push_reply", - test_nghttp2_submit_headers_push_reply) || - !CU_add_test(pSuite, "submit_headers", test_nghttp2_submit_headers) || - !CU_add_test(pSuite, "submit_headers_continuation", - test_nghttp2_submit_headers_continuation) || - !CU_add_test(pSuite, "submit_headers_continuation_extra_large", - test_nghttp2_submit_headers_continuation_extra_large) || - !CU_add_test(pSuite, "submit_priority", test_nghttp2_submit_priority) || - !CU_add_test(pSuite, "session_submit_settings", - test_nghttp2_submit_settings) || - !CU_add_test(pSuite, "session_submit_settings_update_local_window_size", - test_nghttp2_submit_settings_update_local_window_size) || - !CU_add_test(pSuite, "session_submit_settings_multiple_times", - test_nghttp2_submit_settings_multiple_times) || - !CU_add_test(pSuite, "session_submit_push_promise", - test_nghttp2_submit_push_promise) || - !CU_add_test(pSuite, "submit_window_update", - test_nghttp2_submit_window_update) || - !CU_add_test(pSuite, "submit_window_update_local_window_size", - test_nghttp2_submit_window_update_local_window_size) || - !CU_add_test(pSuite, "submit_shutdown_notice", - test_nghttp2_submit_shutdown_notice) || - !CU_add_test(pSuite, "submit_invalid_nv", - test_nghttp2_submit_invalid_nv) || - !CU_add_test(pSuite, "submit_extension", test_nghttp2_submit_extension) || - !CU_add_test(pSuite, "submit_altsvc", test_nghttp2_submit_altsvc) || - !CU_add_test(pSuite, "submit_origin", test_nghttp2_submit_origin) || - !CU_add_test(pSuite, "submit_priority_update", - test_nghttp2_submit_priority_update) || - !CU_add_test(pSuite, "submit_rst_stream", - test_nghttp2_submit_rst_stream) || - !CU_add_test(pSuite, "session_open_stream", - test_nghttp2_session_open_stream) || - !CU_add_test(pSuite, "session_open_stream_with_idle_stream_dep", - test_nghttp2_session_open_stream_with_idle_stream_dep) || - !CU_add_test(pSuite, "session_get_next_ob_item", - test_nghttp2_session_get_next_ob_item) || - !CU_add_test(pSuite, "session_pop_next_ob_item", - test_nghttp2_session_pop_next_ob_item) || - !CU_add_test(pSuite, "session_reply_fail", - test_nghttp2_session_reply_fail) || - !CU_add_test(pSuite, "session_max_concurrent_streams", - test_nghttp2_session_max_concurrent_streams) || - !CU_add_test(pSuite, "session_stop_data_with_rst_stream", - test_nghttp2_session_stop_data_with_rst_stream) || - !CU_add_test(pSuite, "session_defer_data", - test_nghttp2_session_defer_data) || - !CU_add_test(pSuite, "session_flow_control", - test_nghttp2_session_flow_control) || - !CU_add_test(pSuite, "session_flow_control_data_recv", - test_nghttp2_session_flow_control_data_recv) || - !CU_add_test(pSuite, "session_flow_control_data_with_padding_recv", - test_nghttp2_session_flow_control_data_with_padding_recv) || - !CU_add_test(pSuite, "session_data_read_temporal_failure", - test_nghttp2_session_data_read_temporal_failure) || - !CU_add_test(pSuite, "session_on_stream_close", - test_nghttp2_session_on_stream_close) || - !CU_add_test(pSuite, "session_on_ctrl_not_send", - test_nghttp2_session_on_ctrl_not_send) || - !CU_add_test(pSuite, "session_get_outbound_queue_size", - test_nghttp2_session_get_outbound_queue_size) || - !CU_add_test(pSuite, "session_get_effective_local_window_size", - test_nghttp2_session_get_effective_local_window_size) || - !CU_add_test(pSuite, "session_set_option", - test_nghttp2_session_set_option) || - !CU_add_test(pSuite, "session_data_backoff_by_high_pri_frame", - test_nghttp2_session_data_backoff_by_high_pri_frame) || - !CU_add_test(pSuite, "session_pack_data_with_padding", - test_nghttp2_session_pack_data_with_padding) || - !CU_add_test(pSuite, "session_pack_headers_with_padding", - test_nghttp2_session_pack_headers_with_padding) || - !CU_add_test(pSuite, "pack_settings_payload", - test_nghttp2_pack_settings_payload) || - !CU_add_test(pSuite, "session_stream_dep_add", - test_nghttp2_session_stream_dep_add) || - !CU_add_test(pSuite, "session_stream_dep_remove", - test_nghttp2_session_stream_dep_remove) || - !CU_add_test(pSuite, "session_stream_dep_add_subtree", - test_nghttp2_session_stream_dep_add_subtree) || - !CU_add_test(pSuite, "session_stream_dep_remove_subtree", - test_nghttp2_session_stream_dep_remove_subtree) || - !CU_add_test( - pSuite, "session_stream_dep_all_your_stream_are_belong_to_us", - test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us) || - !CU_add_test(pSuite, "session_stream_attach_item", - test_nghttp2_session_stream_attach_item) || - !CU_add_test(pSuite, "session_stream_attach_item_subtree", - test_nghttp2_session_stream_attach_item_subtree) || - !CU_add_test(pSuite, "session_stream_get_state", - test_nghttp2_session_stream_get_state) || - !CU_add_test(pSuite, "session_stream_get_something", - test_nghttp2_session_stream_get_something) || - !CU_add_test(pSuite, "session_find_stream", - test_nghttp2_session_find_stream) || - !CU_add_test(pSuite, "session_keep_closed_stream", - test_nghttp2_session_keep_closed_stream) || - !CU_add_test(pSuite, "session_keep_idle_stream", - test_nghttp2_session_keep_idle_stream) || - !CU_add_test(pSuite, "session_detach_idle_stream", - test_nghttp2_session_detach_idle_stream) || - !CU_add_test(pSuite, "session_large_dep_tree", - test_nghttp2_session_large_dep_tree) || - !CU_add_test(pSuite, "session_graceful_shutdown", - test_nghttp2_session_graceful_shutdown) || - !CU_add_test(pSuite, "session_on_header_temporal_failure", - test_nghttp2_session_on_header_temporal_failure) || - !CU_add_test(pSuite, "session_recv_client_magic", - test_nghttp2_session_recv_client_magic) || - !CU_add_test(pSuite, "session_delete_data_item", - test_nghttp2_session_delete_data_item) || - !CU_add_test(pSuite, "session_open_idle_stream", - test_nghttp2_session_open_idle_stream) || - !CU_add_test(pSuite, "session_cancel_reserved_remote", - test_nghttp2_session_cancel_reserved_remote) || - !CU_add_test(pSuite, "session_reset_pending_headers", - test_nghttp2_session_reset_pending_headers) || - !CU_add_test(pSuite, "session_send_data_callback", - test_nghttp2_session_send_data_callback) || - !CU_add_test(pSuite, "session_on_begin_headers_temporal_failure", - test_nghttp2_session_on_begin_headers_temporal_failure) || - !CU_add_test(pSuite, "session_defer_then_close", - test_nghttp2_session_defer_then_close) || - !CU_add_test(pSuite, "session_detach_item_from_closed_stream", - test_nghttp2_session_detach_item_from_closed_stream) || - !CU_add_test(pSuite, "session_flooding", test_nghttp2_session_flooding) || - !CU_add_test(pSuite, "session_change_stream_priority", - test_nghttp2_session_change_stream_priority) || - !CU_add_test(pSuite, "session_change_extpri_stream_priority", - test_nghttp2_session_change_extpri_stream_priority) || - !CU_add_test(pSuite, "session_create_idle_stream", - test_nghttp2_session_create_idle_stream) || - !CU_add_test(pSuite, "session_repeated_priority_change", - test_nghttp2_session_repeated_priority_change) || - !CU_add_test(pSuite, "session_repeated_priority_submission", - test_nghttp2_session_repeated_priority_submission) || - !CU_add_test(pSuite, "session_set_local_window_size", - test_nghttp2_session_set_local_window_size) || - !CU_add_test(pSuite, "session_cancel_from_before_frame_send", - test_nghttp2_session_cancel_from_before_frame_send) || - !CU_add_test(pSuite, "session_too_many_settings", - test_nghttp2_session_too_many_settings) || - !CU_add_test(pSuite, "session_removed_closed_stream", - test_nghttp2_session_removed_closed_stream) || - !CU_add_test(pSuite, "session_pause_data", - test_nghttp2_session_pause_data) || - !CU_add_test(pSuite, "session_no_closed_streams", - test_nghttp2_session_no_closed_streams) || - !CU_add_test(pSuite, "session_set_stream_user_data", - test_nghttp2_session_set_stream_user_data) || - !CU_add_test(pSuite, "session_no_rfc7540_priorities", - test_nghttp2_session_no_rfc7540_priorities) || - !CU_add_test(pSuite, "session_server_fallback_rfc7540_priorities", - test_nghttp2_session_server_fallback_rfc7540_priorities) || - !CU_add_test(pSuite, "session_stream_reset_ratelim", - test_nghttp2_session_stream_reset_ratelim) || - !CU_add_test(pSuite, "http_mandatory_headers", - test_nghttp2_http_mandatory_headers) || - !CU_add_test(pSuite, "http_content_length", - test_nghttp2_http_content_length) || - !CU_add_test(pSuite, "http_content_length_mismatch", - test_nghttp2_http_content_length_mismatch) || - !CU_add_test(pSuite, "http_non_final_response", - test_nghttp2_http_non_final_response) || - !CU_add_test(pSuite, "http_trailer_headers", - test_nghttp2_http_trailer_headers) || - !CU_add_test(pSuite, "http_ignore_regular_header", - test_nghttp2_http_ignore_regular_header) || - !CU_add_test(pSuite, "http_ignore_content_length", - test_nghttp2_http_ignore_content_length) || - !CU_add_test(pSuite, "http_record_request_method", - test_nghttp2_http_record_request_method) || - !CU_add_test(pSuite, "http_push_promise", - test_nghttp2_http_push_promise) || - !CU_add_test(pSuite, "http_head_method_upgrade_workaround", - test_nghttp2_http_head_method_upgrade_workaround) || - !CU_add_test( - pSuite, "http_no_rfc9113_leading_and_trailing_ws_validation", - test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation) || - !CU_add_test(pSuite, "frame_pack_headers", - test_nghttp2_frame_pack_headers) || - !CU_add_test(pSuite, "frame_pack_headers_frame_too_large", - test_nghttp2_frame_pack_headers_frame_too_large) || - !CU_add_test(pSuite, "frame_pack_priority", - test_nghttp2_frame_pack_priority) || - !CU_add_test(pSuite, "frame_pack_rst_stream", - test_nghttp2_frame_pack_rst_stream) || - !CU_add_test(pSuite, "frame_pack_settings", - test_nghttp2_frame_pack_settings) || - !CU_add_test(pSuite, "frame_pack_push_promise", - test_nghttp2_frame_pack_push_promise) || - !CU_add_test(pSuite, "frame_pack_ping", test_nghttp2_frame_pack_ping) || - !CU_add_test(pSuite, "frame_pack_goaway", - test_nghttp2_frame_pack_goaway) || - !CU_add_test(pSuite, "frame_pack_window_update", - test_nghttp2_frame_pack_window_update) || - !CU_add_test(pSuite, "frame_pack_altsvc", - test_nghttp2_frame_pack_altsvc) || - !CU_add_test(pSuite, "frame_pack_origin", - test_nghttp2_frame_pack_origin) || - !CU_add_test(pSuite, "frame_pack_priority_update", - test_nghttp2_frame_pack_priority_update) || - !CU_add_test(pSuite, "nv_array_copy", test_nghttp2_nv_array_copy) || - !CU_add_test(pSuite, "iv_check", test_nghttp2_iv_check) || - !CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) || - !CU_add_test(pSuite, "hd_deflate_same_indexed_repr", - test_nghttp2_hd_deflate_same_indexed_repr) || - !CU_add_test(pSuite, "hd_inflate_indexed", - test_nghttp2_hd_inflate_indexed) || - !CU_add_test(pSuite, "hd_inflate_indname_noinc", - test_nghttp2_hd_inflate_indname_noinc) || - !CU_add_test(pSuite, "hd_inflate_indname_inc", - test_nghttp2_hd_inflate_indname_inc) || - !CU_add_test(pSuite, "hd_inflate_indname_inc_eviction", - test_nghttp2_hd_inflate_indname_inc_eviction) || - !CU_add_test(pSuite, "hd_inflate_newname_noinc", - test_nghttp2_hd_inflate_newname_noinc) || - !CU_add_test(pSuite, "hd_inflate_newname_inc", - test_nghttp2_hd_inflate_newname_inc) || - !CU_add_test(pSuite, "hd_inflate_clearall_inc", - test_nghttp2_hd_inflate_clearall_inc) || - !CU_add_test(pSuite, "hd_inflate_zero_length_huffman", - test_nghttp2_hd_inflate_zero_length_huffman) || - !CU_add_test(pSuite, "hd_inflate_expect_table_size_update", - test_nghttp2_hd_inflate_expect_table_size_update) || - !CU_add_test(pSuite, "hd_inflate_unexpected_table_size_update", - test_nghttp2_hd_inflate_unexpected_table_size_update) || - !CU_add_test(pSuite, "hd_ringbuf_reserve", - test_nghttp2_hd_ringbuf_reserve) || - !CU_add_test(pSuite, "hd_change_table_size", - test_nghttp2_hd_change_table_size) || - !CU_add_test(pSuite, "hd_deflate_inflate", - test_nghttp2_hd_deflate_inflate) || - !CU_add_test(pSuite, "hd_no_index", test_nghttp2_hd_no_index) || - !CU_add_test(pSuite, "hd_deflate_bound", test_nghttp2_hd_deflate_bound) || - !CU_add_test(pSuite, "hd_public_api", test_nghttp2_hd_public_api) || - !CU_add_test(pSuite, "hd_deflate_hd_vec", - test_nghttp2_hd_deflate_hd_vec) || - !CU_add_test(pSuite, "hd_decode_length", test_nghttp2_hd_decode_length) || - !CU_add_test(pSuite, "hd_huff_encode", test_nghttp2_hd_huff_encode) || - !CU_add_test(pSuite, "hd_huff_decode", test_nghttp2_hd_huff_decode) || - !CU_add_test(pSuite, "adjust_local_window_size", - test_nghttp2_adjust_local_window_size) || - !CU_add_test(pSuite, "check_header_name", - test_nghttp2_check_header_name) || - !CU_add_test(pSuite, "check_header_value", - test_nghttp2_check_header_value) || - !CU_add_test(pSuite, "check_header_value_rfc9113", - test_nghttp2_check_header_value_rfc9113) || - !CU_add_test(pSuite, "bufs_add", test_nghttp2_bufs_add) || - !CU_add_test(pSuite, "bufs_add_stack_buffer_overflow_bug", - test_nghttp2_bufs_add_stack_buffer_overflow_bug) || - !CU_add_test(pSuite, "bufs_addb", test_nghttp2_bufs_addb) || - !CU_add_test(pSuite, "bufs_orb", test_nghttp2_bufs_orb) || - !CU_add_test(pSuite, "bufs_remove", test_nghttp2_bufs_remove) || - !CU_add_test(pSuite, "bufs_reset", test_nghttp2_bufs_reset) || - !CU_add_test(pSuite, "bufs_advance", test_nghttp2_bufs_advance) || - !CU_add_test(pSuite, "bufs_next_present", - test_nghttp2_bufs_next_present) || - !CU_add_test(pSuite, "bufs_realloc", test_nghttp2_bufs_realloc) || - !CU_add_test(pSuite, "http_parse_priority", - test_nghttp2_http_parse_priority) || - !CU_add_test(pSuite, "extpri_to_uint8", test_nghttp2_extpri_to_uint8) || - !CU_add_test(pSuite, "ratelim_update", test_nghttp2_ratelim_update) || - !CU_add_test(pSuite, "ratelim_drain", test_nghttp2_ratelim_drain)) { - CU_cleanup_registry(); - return (int)CU_get_error(); - } - - /* Run all tests using the CUnit Basic interface */ - CU_basic_set_mode(CU_BRM_VERBOSE); - CU_basic_run_tests(); - num_tests_failed = CU_get_number_of_tests_failed(); - CU_cleanup_registry(); - if (CU_get_error() == CUE_SUCCESS) { - return (int)num_tests_failed; - } else { - printf("CUnit Error: %s\n", CU_get_error_msg()); - return (int)CU_get_error(); - } + return munit_suite_main(&suite, NULL, argc, argv); } diff --git a/yass/third_party/nghttp2/tests/munit/.appveyor.yml b/yass/third_party/nghttp2/tests/munit/.appveyor.yml new file mode 100644 index 0000000000..55720926e4 --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/.appveyor.yml @@ -0,0 +1,34 @@ +version: "{build}" + +environment: + matrix: + - ARCHITECTURE: x64 + MSVC_VER: 14 + - ARCHITECTURE: x86 + MSVC_VER: 14 + - ARCHITECTURE: x64 + MSVC_VER: 12 + - ARCHITECTURE: x86 + MSVC_VER: 12 + - ARCHITECTURE: x86 + MSVC_VER: 11 + - ARCHITECTURE: x86 + MSVC_VER: 10 + - ARCHITECTURE: x86 + MSVC_VER: 9 + +branches: + except: + - master + - /^(wip\/)?(travis|osx|mingw|ipp)(\-.+)?$/ + +configuration: Debug + +install: + +before_build: + - call "C:\Program Files (x86)\Microsoft Visual Studio %MSVC_VER%.0\VC\vcvarsall.bat" %ARCHITECTURE% + +build_script: cl.exe /W4 /WX /Feexample munit.c example.c + +test_script: example.exe --color always diff --git a/yass/third_party/nghttp2/tests/munit/.clang-format b/yass/third_party/nghttp2/tests/munit/.clang-format new file mode 100644 index 0000000000..4aa455a506 --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/.clang-format @@ -0,0 +1,215 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: NextLine +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: AfterHash +IndentExternBlock: AfterExternBlock +IndentRequiresClause: false +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Right +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RequiresClausePosition: OwnLine +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: Never +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/yass/third_party/nghttp2/tests/munit/.dir-locals.el b/yass/third_party/nghttp2/tests/munit/.dir-locals.el new file mode 100644 index 0000000000..4cc5d84969 --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/.dir-locals.el @@ -0,0 +1,2 @@ +((nil . ((indent-tabs-mode . nil) + (c-basic-offset . 2)))) diff --git a/yass/third_party/nghttp2/tests/munit/.gitignore b/yass/third_party/nghttp2/tests/munit/.gitignore new file mode 100644 index 0000000000..6ad0b44a9b --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/.gitignore @@ -0,0 +1,8 @@ +*~ +.#* +/*.o +/example +/*.exe +/*.dll +.dirstamp +.deps diff --git a/yass/third_party/nghttp2/tests/munit/.travis.yml b/yass/third_party/nghttp2/tests/munit/.travis.yml new file mode 100644 index 0000000000..6f221a8ba0 --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/.travis.yml @@ -0,0 +1,149 @@ +language: c +sudo: false +dist: trusty +branches: + except: + - /^(wip\/)?(appveyor|msvc|mingw|windows)(\-.+)?$/ + # https://github.com/travis-ci/travis-ci/issues/6632 + # - /^master$/ +matrix: + include: + ### + ## Linux builds using various versions of GCC. + ### + - env: C_COMPILER=gcc-6 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-6 + - g++-6 + - env: C_COMPILER=gcc-5 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-5 + - g++-5 + # - env: C_COMPILER=gcc-4.9 + # addons: + # apt: + # sources: + # - ubuntu-toolchain-r-test + # packages: + # - gcc-4.9 + # - g++-4.9 + - env: C_COMPILER=gcc-4.8 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.8 + - g++-4.8 + # - env: C_COMPILER=gcc-4.7 + # addons: + # apt: + # sources: + # - ubuntu-toolchain-r-test + # packages: + # - gcc-4.7 + # - g++-4.7 + - env: C_COMPILER=gcc-4.6 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.6 + - g++-4.6 + # - os: linux + # env: C_COMPILER=gcc-4.5 + # addons: + # apt: + # sources: + # - ubuntu-toolchain-r-test + # packages: + # - gcc-4.5 + # - g++-4.5 + - env: C_COMPILER=gcc-4.4 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.4 + - g++-4.4 + + ### + ## clang on Linux + ### + - env: C_COMPILER=clang-3.9 + addons: + apt: + sources: + - llvm-toolchain-precise-3.9 + - ubuntu-toolchain-r-test + packages: + - clang-3.9 + # - env: C_COMPILER=clang-3.8 + # addons: + # apt: + # sources: + # - llvm-toolchain-precise-3.8 + # - ubuntu-toolchain-r-test + # packages: + # - clang-3.8 + - env: C_COMPILER=clang-3.7 + addons: + apt: + sources: + - llvm-toolchain-precise-3.7 + - ubuntu-toolchain-r-test + packages: + - clang-3.7 + # - env: C_COMPILER=clang-3.6 + # addons: + # apt: + # sources: + # - llvm-toolchain-precise-3.6 + # - ubuntu-toolchain-r-test + # packages: + # - clang-3.6 + - env: C_COMPILER=clang-3.5 + addons: + apt: + sources: + - llvm-toolchain-precise-3.5 + - ubuntu-toolchain-r-test + packages: + - clang-3.5 + + ### + ## PGI + ### + - env: C_COMPILER=pgcc OPENMP=y + + ### + ## OS X + ### + - os: osx + + ### + ## Meson + ### + - env: BUILD_SYSTEM=meson + +before_install: +- if [ -n "${C_COMPILER}" ]; then export CC="${C_COMPILER}"; fi +- if [ "${C_COMPILER}" = "pgcc" ]; then wget -q -O /dev/stdout 'https://raw.githubusercontent.com/nemequ/pgi-travis/master/install-pgi.sh' | /bin/sh; fi +- if [ "${BUILD_SYSTEM}" = "meson" ]; then wget -O /tmp/ninja-linux.zip $(curl -s https://api.github.com/repos/ninja-build/ninja/releases/latest | grep -oP 'https://github.com/ninja-build/ninja/releases/download/v[0-9\.]+/ninja-linux.zip') && unzip -q /tmp/ninja-linux.zip -d ~/bin && pyenv local 3.6 && pip3 install meson; fi + +script: + - if [ "${BUILD_SYSTEM}" = "meson" ]; then meson build && ninja -Cbuild; else make CC="${CC}" AGGRESSIVE_WARNINGS=y EXTENSION="${EXTENSION}" OPENMP="${OPENMP}" ASAN="${ASAN}" UBSAN="${UBSAN}"; fi + - if [ "${BUILD_SYSTEM}" = "meson" ]; then ninja -Cbuild test; else make test; fi + +notifications: + email: false diff --git a/yass/third_party/nghttp2/tests/munit/COPYING b/yass/third_party/nghttp2/tests/munit/COPYING new file mode 100644 index 0000000000..2991ac706d --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/COPYING @@ -0,0 +1,21 @@ +µnit Testing Framework +Copyright (c) 2013-2016 Evan Nemerson + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/yass/third_party/nghttp2/tests/munit/README.md b/yass/third_party/nghttp2/tests/munit/README.md new file mode 100644 index 0000000000..9f861f2a1d --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/README.md @@ -0,0 +1,54 @@ +# µnit + +µnit is a small but full-featured unit testing framework for C. It has +no dependencies (beyond libc), is permissively licensed (MIT), and is +easy to include into any project. + +For more information, see +[the µnit web site](https://nemequ.github.io/munit). + +[![Build status](https://travis-ci.org/nemequ/munit.svg?branch=master)](https://travis-ci.org/nemequ/munit) +[![Windows build status](https://ci.appveyor.com/api/projects/status/db515g5ifcwjohq7/branch/master?svg=true)](https://ci.appveyor.com/project/quixdb/munit/branch/master) + +## Features + +Features µnit currently includes include: + + * Handy assertion macros which make for nice error messages. + * Reproducible cross-platform random number generation, including + support for supplying a seed via CLI. + * Timing of both wall-clock and CPU time. + * Parameterized tests. + * Nested test suites. + * Flexible CLI. + * Forking + ([except on Windows](https://github.com/nemequ/munit/issues/2)). + * Hiding output of successful tests. + +Features µnit does not currently include, but some day may include +(a.k.a., if you file a PR…), include: + + * [TAP](http://testanything.org/) support; feel free to discuss in + [issue #1](https://github.com/nemequ/munit/issues/1) + +### Include into your project with meson + +In your `subprojects` folder put a `munit.wrap` file containing: + +``` +[wrap-git] +directory=munit +url=https://github.com/nemequ/munit/ +revision=head +``` + +Then you can use a subproject fallback when you include munit as a +dependency to your project: `dependency('munit', fallback: ['munit', 'munit_dep'])` + +## Documentation + +See [the µnit web site](https://nemequ.github.io/munit). + +Additionally, there is a heavily-commented +[example.c](https://github.com/nemequ/munit/blob/master/example.c) in +the repository. diff --git a/yass/third_party/nghttp2/tests/munit/example.c b/yass/third_party/nghttp2/tests/munit/example.c new file mode 100644 index 0000000000..d238d09344 --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/example.c @@ -0,0 +1,351 @@ +/* Example file for using µnit. + * + * µnit is MIT-licensed, but for this file and this file alone: + * + * To the extent possible under law, the author(s) of this file have + * waived all copyright and related or neighboring rights to this + * work. See for + * details. + *********************************************************************/ + +#include "munit.h" + +/* This is just to disable an MSVC warning about conditional + * expressions being constant, which you shouldn't have to do for your + * code. It's only here because we want to be able to do silly things + * like assert that 0 != 1 for our demo. */ +#if defined(_MSC_VER) +#pragma warning(disable: 4127) +#endif + +/* Tests are functions that return void, and take a single void* + * parameter. We'll get to what that parameter is later. */ +static MunitResult +test_compare(const MunitParameter params[], void* data) { + /* We'll use these later */ + const unsigned char val_uchar = 'b'; + const short val_short = 1729; + double pi = 3.141592654; + char* stewardesses = "stewardesses"; + char* most_fun_word_to_type; + + /* These are just to silence compiler warnings about the parameters + * being unused. */ + (void) params; + (void) data; + + /* Let's start with the basics. */ + munit_assert(0 != 1); + + /* There is also the more verbose, though slightly more descriptive + munit_assert_true/false: */ + munit_assert_false(0); + + /* You can also call munit_error and munit_errorf yourself. We + * won't do it is used to indicate a failure, but here is what it + * would look like: */ + /* munit_error("FAIL"); */ + /* munit_errorf("Goodbye, cruel %s", "world"); */ + + /* There are macros for comparing lots of types. */ + munit_assert_char('a', ==, 'a'); + + /* Sure, you could just assert('a' == 'a'), but if you did that, a + * failed assertion would just say something like "assertion failed: + * val_uchar == 'b'". µnit will tell you the actual values, so a + * failure here would result in something like "assertion failed: + * val_uchar == 'b' ('X' == 'b')." */ + munit_assert_uchar(val_uchar, ==, 'b'); + + /* Obviously we can handle values larger than 'char' and 'uchar'. + * There are versions for char, short, int, long, long long, + * int8/16/32/64_t, as well as the unsigned versions of them all. */ + munit_assert_short(42, <, val_short); + + /* There is also support for size_t. + * + * The longest word in English without repeating any letters is + * "uncopyrightables", which has uncopyrightable (and + * dermatoglyphics, which is the study of fingerprints) beat by a + * character */ + munit_assert_size(strlen("uncopyrightables"), >, strlen("dermatoglyphics")); + + /* Of course there is also support for doubles and floats. */ + munit_assert_double(pi, ==, 3.141592654); + + /* If you want to compare two doubles for equality, you might want + * to consider using munit_assert_double_equal. It compares two + * doubles for equality within a precison of 1.0 x 10^-(precision). + * Note that precision (the third argument to the macro) needs to be + * fully evaluated to an integer by the preprocessor so µnit doesn't + * have to depend pow, which is often in libm not libc. */ + munit_assert_double_equal(3.141592654, 3.141592653589793, 9); + + /* And if you want to check strings for equality (or inequality), + * there is munit_assert_string_equal/not_equal. + * + * "stewardesses" is the longest word you can type on a QWERTY + * keyboard with only one hand, which makes it loads of fun to type. + * If I'm going to have to type a string repeatedly, let's make it a + * good one! */ + munit_assert_string_equal(stewardesses, "stewardesses"); + + /* A personal favorite macro which is fantastic if you're working + * with binary data, is the one which naïvely checks two blobs of + * memory for equality. If this fails it will tell you the offset + * of the first differing byte. */ + munit_assert_memory_equal(7, stewardesses, "steward"); + + /* You can also make sure that two blobs differ *somewhere*: */ + munit_assert_memory_not_equal(8, stewardesses, "steward"); + + /* There are equal/not_equal macros for pointers, too: */ + most_fun_word_to_type = stewardesses; + munit_assert_ptr_equal(most_fun_word_to_type, stewardesses); + + /* And null/not_null */ + munit_assert_null(NULL); + munit_assert_not_null(most_fun_word_to_type); + + /* Lets verify that the data parameter is what we expected. We'll + * see where this comes from in a bit. + * + * Note that the casting isn't usually required; if you give this + * function a real pointer (instead of a number like 0xdeadbeef) it + * would work as expected. */ + munit_assert_ptr_equal(data, (void*)(uintptr_t)0xdeadbeef); + + return MUNIT_OK; +} + +static MunitResult +test_rand(const MunitParameter params[], void* user_data) { + int random_int; + double random_dbl; + munit_uint8_t data[5]; + + (void) params; + (void) user_data; + + /* One thing missing from a lot of unit testing frameworks is a + * random number generator. You can't just use srand/rand because + * the implementation varies across different platforms, and it's + * important to be able to look at the seed used in a failing test + * to see if you can reproduce it. Some randomness is a fantastic + * thing to have in your tests, I don't know why more people don't + * do it... + * + * µnit's PRNG is re-seeded with the same value for each iteration + * of each test. The seed is retrieved from the MUNIT_SEED + * envirnment variable or, if none is provided, one will be + * (pseudo-)randomly generated. */ + + /* If you need an integer in a given range */ + random_int = munit_rand_int_range(128, 4096); + munit_assert_int(random_int, >=, 128); + munit_assert_int(random_int, <=, 4096); + + /* Or maybe you want a double, between 0 and 1: */ + random_dbl = munit_rand_double(); + munit_assert_double(random_dbl, >=, 0.0); + munit_assert_double(random_dbl, <=, 1.0); + + /* Of course, you want to be able to reproduce bugs discovered + * during testing, so every time the tests are run they print the + * random seed used. When you want to reproduce a result, just put + * that random seed in the MUNIT_SEED environment variable; it even + * works on different platforms. + * + * If you want this to pass, use 0xdeadbeef as the random seed and + * uncomment the next line of code. Note that the PRNG is not + * re-seeded between iterations of the same test, so this will only + * work on the first iteration. */ + /* munit_assert_uint32(munit_rand_uint32(), ==, 1306447409); */ + + /* You can also get blobs of random memory: */ + munit_rand_memory(sizeof(data), data); + + return MUNIT_OK; +} + +/* This test case shows how to accept parameters. We'll see how to + * specify them soon. + * + * By default, every possible variation of a parameterized test is + * run, but you can specify parameters manually if you want to only + * run specific test(s), or you can pass the --single argument to the + * CLI to have the harness simply choose one variation at random + * instead of running them all. */ +static MunitResult +test_parameters(const MunitParameter params[], void* user_data) { + const char* foo; + const char* bar; + + (void) user_data; + + /* The "foo" parameter is specified as one of the following values: + * "one", "two", or "three". */ + foo = munit_parameters_get(params, "foo"); + /* Similarly, "bar" is one of "four", "five", or "six". */ + bar = munit_parameters_get(params, "bar"); + /* "baz" is a bit more complicated. We don't actually specify a + * list of valid values, so by default NULL is passed. However, the + * CLI will accept any value. This is a good way to have a value + * that is usually selected randomly by the test, but can be + * overridden on the command line if desired. */ + /* const char* baz = munit_parameters_get(params, "baz"); */ + + /* Notice that we're returning MUNIT_FAIL instead of writing an + * error message. Error messages are generally preferable, since + * they make it easier to diagnose the issue, but this is an + * option. + * + * Possible values are: + * - MUNIT_OK: Sucess + * - MUNIT_FAIL: Failure + * - MUNIT_SKIP: The test was skipped; usually this happens when a + * particular feature isn't in use. For example, if you're + * writing a test which uses a Wayland-only feature, but your + * application is running on X11. + * - MUNIT_ERROR: The test failed, but not because of anything you + * wanted to test. For example, maybe your test downloads a + * remote resource and tries to parse it, but the network was + * down. + */ + + if (strcmp(foo, "one") != 0 && + strcmp(foo, "two") != 0 && + strcmp(foo, "three") != 0) + return MUNIT_FAIL; + + if (strcmp(bar, "red") != 0 && + strcmp(bar, "green") != 0 && + strcmp(bar, "blue") != 0) + return MUNIT_FAIL; + + return MUNIT_OK; +} + +/* The setup function, if you provide one, for a test will be run + * before the test, and the return value will be passed as the sole + * parameter to the test function. */ +static void* +test_compare_setup(const MunitParameter params[], void* user_data) { + (void) params; + + munit_assert_string_equal(user_data, "µnit"); + return (void*) (uintptr_t) 0xdeadbeef; +} + +/* To clean up after a test, you can use a tear down function. The + * fixture argument is the value returned by the setup function + * above. */ +static void +test_compare_tear_down(void* fixture) { + munit_assert_ptr_equal(fixture, (void*)(uintptr_t)0xdeadbeef); +} + +static char* foo_params[] = { + (char*) "one", (char*) "two", (char*) "three", NULL +}; + +static char* bar_params[] = { + (char*) "red", (char*) "green", (char*) "blue", NULL +}; + +static MunitParameterEnum test_params[] = { + { (char*) "foo", foo_params }, + { (char*) "bar", bar_params }, + { (char*) "baz", NULL }, + { NULL, NULL }, +}; + +/* Creating a test suite is pretty simple. First, you'll need an + * array of tests: */ +static MunitTest test_suite_tests[] = { + { + /* The name is just a unique human-readable way to identify the + * test. You can use it to run a specific test if you want, but + * usually it's mostly decorative. */ + (char*) "/example/compare", + /* You probably won't be surprised to learn that the tests are + * functions. */ + test_compare, + /* If you want, you can supply a function to set up a fixture. If + * you supply NULL, the user_data parameter from munit_suite_main + * will be used directly. If, however, you provide a callback + * here the user_data parameter will be passed to this callback, + * and the return value from this callback will be passed to the + * test function. + * + * For our example we don't really need a fixture, but lets + * provide one anyways. */ + test_compare_setup, + /* If you passed a callback for the fixture setup function, you + * may want to pass a corresponding callback here to reverse the + * operation. */ + test_compare_tear_down, + /* Finally, there is a bitmask for options you can pass here. You + * can provide either MUNIT_TEST_OPTION_NONE or 0 here to use the + * defaults. */ + MUNIT_TEST_OPTION_NONE, + NULL + }, + /* Usually this is written in a much more compact format; all these + * comments kind of ruin that, though. Here is how you'll usually + * see entries written: */ + { (char*) "/example/rand", test_rand, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + /* To tell the test runner when the array is over, just add a NULL + * entry at the end. */ + { (char*) "/example/parameters", test_parameters, NULL, NULL, MUNIT_TEST_OPTION_NONE, test_params }, + { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } +}; + +/* If you wanted to have your test suite run other test suites you + * could declare an array of them. Of course each sub-suite can + * contain more suites, etc. */ +/* static const MunitSuite other_suites[] = { */ +/* { "/second", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }, */ +/* { NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE } */ +/* }; */ + +/* Now we'll actually declare the test suite. You could do this in + * the main function, or on the heap, or whatever you want. */ +static const MunitSuite test_suite = { + /* This string will be prepended to all test names in this suite; + * for example, "/example/rand" will become "/µnit/example/rand". + * Note that, while it doesn't really matter for the top-level + * suite, NULL signal the end of an array of tests; you should use + * an empty string ("") instead. */ + (char*) "", + /* The first parameter is the array of test suites. */ + test_suite_tests, + /* In addition to containing test cases, suites can contain other + * test suites. This isn't necessary in this example, but it can be + * a great help to projects with lots of tests by making it easier + * to spread the tests across many files. This is where you would + * put "other_suites" (which is commented out above). */ + NULL, + /* An interesting feature of µnit is that it supports automatically + * running multiple iterations of the tests. This is usually only + * interesting if you make use of the PRNG to randomize your tests + * cases a bit, or if you are doing performance testing and want to + * average multiple runs. 0 is an alias for 1. */ + 1, + /* Just like MUNIT_TEST_OPTION_NONE, you can provide + * MUNIT_SUITE_OPTION_NONE or 0 to use the default settings. */ + MUNIT_SUITE_OPTION_NONE +}; + +/* This is only necessary for EXIT_SUCCESS and EXIT_FAILURE, which you + * *should* be using but probably aren't (no, zero and non-zero don't + * always mean success and failure). I guess my point is that nothing + * about µnit requires it. */ +#include + +int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) { + /* Finally, we'll actually run our test suite! That second argument + * is the user_data parameter which will be passed either to the + * test or (if provided) the fixture setup function. */ + return munit_suite_main(&test_suite, (void*) "µnit", argc, argv); +} diff --git a/yass/third_party/nghttp2/tests/munit/munit.c b/yass/third_party/nghttp2/tests/munit/munit.c new file mode 100644 index 0000000000..cce17b8dbe --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/munit.c @@ -0,0 +1,2459 @@ +/* Copyright (c) 2013-2018 Evan Nemerson + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/*** Configuration ***/ + +/* This is just where the output from the test goes. It's really just + * meant to let you choose stdout or stderr, but if anyone really want + * to direct it to a file let me know, it would be fairly easy to + * support. */ +#if !defined(MUNIT_OUTPUT_FILE) +# define MUNIT_OUTPUT_FILE stdout +#endif + +/* This is a bit more useful; it tells µnit how to format the seconds in + * timed tests. If your tests run for longer you might want to reduce + * it, and if your computer is really fast and your tests are tiny you + * can increase it. */ +#if !defined(MUNIT_TEST_TIME_FORMAT) +# define MUNIT_TEST_TIME_FORMAT "0.8f" +#endif + +/* If you have long test names you might want to consider bumping + * this. The result information takes 43 characters. */ +#if !defined(MUNIT_TEST_NAME_LEN) +# define MUNIT_TEST_NAME_LEN 37 +#endif + +/* If you don't like the timing information, you can disable it by + * defining MUNIT_DISABLE_TIMING. */ +#if !defined(MUNIT_DISABLE_TIMING) +# define MUNIT_ENABLE_TIMING +#endif + +/*** End configuration ***/ + +#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE < 200809L) +# undef _POSIX_C_SOURCE +#endif +#if !defined(_POSIX_C_SOURCE) +# define _POSIX_C_SOURCE 200809L +#endif + +/* Solaris freaks out if you try to use a POSIX or SUS standard without + * the "right" C standard. */ +#if defined(_XOPEN_SOURCE) +# undef _XOPEN_SOURCE +#endif + +#if defined(__STDC_VERSION__) +# if __STDC_VERSION__ >= 201112L +# define _XOPEN_SOURCE 700 +# elif __STDC_VERSION__ >= 199901L +# define _XOPEN_SOURCE 600 +# endif +#endif + +/* Because, according to Microsoft, POSIX is deprecated. You've got + * to appreciate the chutzpah. */ +#if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_DEPRECATE) +# define _CRT_NONSTDC_NO_DEPRECATE +#endif + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# include +#elif defined(_WIN32) +/* https://msdn.microsoft.com/en-us/library/tf4dy80a.aspx */ +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(MUNIT_NO_NL_LANGINFO) && !defined(_WIN32) +# define MUNIT_NL_LANGINFO +# include +# include +# include +#endif + +#if !defined(_WIN32) +# include +# include +# include +#else +# include +# include +# include +# if !defined(STDERR_FILENO) +# define STDERR_FILENO _fileno(stderr) +# endif +#endif + +#include "munit.h" + +#define MUNIT_STRINGIFY(x) #x +#define MUNIT_XSTRINGIFY(x) MUNIT_STRINGIFY(x) + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_CC) || \ + defined(__IBMCPP__) +# define MUNIT_THREAD_LOCAL __thread +#elif (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201102L)) || \ + defined(_Thread_local) +# define MUNIT_THREAD_LOCAL _Thread_local +#elif defined(_WIN32) +# define MUNIT_THREAD_LOCAL __declspec(thread) +#endif + +/* MSVC 12.0 will emit a warning at /W4 for code like 'do { ... } + * while (0)', or 'do { ... } while (1)'. I'm pretty sure nobody + * at Microsoft compiles with /W4. */ +#if defined(_MSC_VER) && (_MSC_VER <= 1800) +# pragma warning(disable : 4127) +#endif + +#if defined(_WIN32) || defined(__EMSCRIPTEN__) +# define MUNIT_NO_FORK +#endif + +#if defined(__EMSCRIPTEN__) +# define MUNIT_NO_BUFFER +#endif + +/*** Logging ***/ + +static MunitLogLevel munit_log_level_visible = MUNIT_LOG_INFO; +static MunitLogLevel munit_log_level_fatal = MUNIT_LOG_ERROR; + +#if defined(MUNIT_THREAD_LOCAL) +static MUNIT_THREAD_LOCAL munit_bool munit_error_jmp_buf_valid = 0; +static MUNIT_THREAD_LOCAL jmp_buf munit_error_jmp_buf; +#endif + +/* At certain warning levels, mingw will trigger warnings about + * suggesting the format attribute, which we've explicity *not* set + * because it will then choke on our attempts to use the MS-specific + * I64 modifier for size_t (which we have to use since MSVC doesn't + * support the C99 z modifier). */ + +#if defined(__MINGW32__) || defined(__MINGW64__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wsuggest-attribute=format" +#endif + +MUNIT_PRINTF(5, 0) +static void munit_logf_exv(MunitLogLevel level, FILE *fp, const char *filename, + int line, const char *format, va_list ap) { + if (level < munit_log_level_visible) + return; + + switch (level) { + case MUNIT_LOG_DEBUG: + fputs("Debug", fp); + break; + case MUNIT_LOG_INFO: + fputs("Info", fp); + break; + case MUNIT_LOG_WARNING: + fputs("Warning", fp); + break; + case MUNIT_LOG_ERROR: + fputs("Error", fp); + break; + default: + munit_logf_ex(MUNIT_LOG_ERROR, filename, line, "Invalid log level (%d)", + level); + return; + } + + fputs(": ", fp); + if (filename != NULL) + fprintf(fp, "%s:%d: ", filename, line); + vfprintf(fp, format, ap); + fputc('\n', fp); +} + +MUNIT_PRINTF(3, 4) +static void munit_logf_internal(MunitLogLevel level, FILE *fp, + const char *format, ...) { + va_list ap; + + va_start(ap, format); + munit_logf_exv(level, fp, NULL, 0, format, ap); + va_end(ap); +} + +static void munit_log_internal(MunitLogLevel level, FILE *fp, + const char *message) { + munit_logf_internal(level, fp, "%s", message); +} + +void munit_logf_ex(MunitLogLevel level, const char *filename, int line, + const char *format, ...) { + va_list ap; + + va_start(ap, format); + munit_logf_exv(level, stderr, filename, line, format, ap); + va_end(ap); + + if (level >= munit_log_level_fatal) { +#if defined(MUNIT_THREAD_LOCAL) + if (munit_error_jmp_buf_valid) + longjmp(munit_error_jmp_buf, 1); +#endif + abort(); + } +} + +void munit_errorf_ex(const char *filename, int line, const char *format, ...) { + va_list ap; + + va_start(ap, format); + munit_logf_exv(MUNIT_LOG_ERROR, stderr, filename, line, format, ap); + va_end(ap); + +#if defined(MUNIT_THREAD_LOCAL) + if (munit_error_jmp_buf_valid) + longjmp(munit_error_jmp_buf, 1); +#endif + abort(); +} + +#if defined(__MINGW32__) || defined(__MINGW64__) +# pragma GCC diagnostic pop +#endif + +#if !defined(MUNIT_STRERROR_LEN) +# define MUNIT_STRERROR_LEN 80 +#endif + +static void munit_log_errno(MunitLogLevel level, FILE *fp, const char *msg) { +#if defined(MUNIT_NO_STRERROR_R) || \ + (defined(__MINGW32__) && !defined(MINGW_HAS_SECURE_API)) + munit_logf_internal(level, fp, "%s: %s (%d)", msg, strerror(errno), errno); +#else + char munit_error_str[MUNIT_STRERROR_LEN]; + munit_error_str[0] = '\0'; + +# if !defined(_WIN32) + strerror_r(errno, munit_error_str, MUNIT_STRERROR_LEN); +# else + strerror_s(munit_error_str, MUNIT_STRERROR_LEN, errno); +# endif + + munit_logf_internal(level, fp, "%s: %s (%d)", msg, munit_error_str, errno); +#endif +} + +/*** Memory allocation ***/ + +void *munit_malloc_ex(const char *filename, int line, size_t size) { + void *ptr; + + if (size == 0) + return NULL; + + ptr = calloc(1, size); + if (MUNIT_UNLIKELY(ptr == NULL)) { + munit_logf_ex(MUNIT_LOG_ERROR, filename, line, + "Failed to allocate %" MUNIT_SIZE_MODIFIER "u bytes.", size); + } + + return ptr; +} + +/*** Timer code ***/ + +#if defined(MUNIT_ENABLE_TIMING) + +# define psnip_uint64_t munit_uint64_t +# define psnip_uint32_t munit_uint32_t + +/* Code copied from portable-snippets + * . If you need to + * change something, please do it there so we can keep the code in + * sync. */ + +/* Clocks (v1) + * Portable Snippets - https://gitub.com/nemequ/portable-snippets + * Created by Evan Nemerson + * + * To the extent possible under law, the authors have waived all + * copyright and related or neighboring rights to this code. For + * details, see the Creative Commons Zero 1.0 Universal license at + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +# if !defined(PSNIP_CLOCK_H) +# define PSNIP_CLOCK_H + +# if !defined(psnip_uint64_t) +# include "../exact-int/exact-int.h" +# endif + +# if !defined(PSNIP_CLOCK_STATIC_INLINE) +# if defined(__GNUC__) +# define PSNIP_CLOCK__COMPILER_ATTRIBUTES __attribute__((__unused__)) +# else +# define PSNIP_CLOCK__COMPILER_ATTRIBUTES +# endif + +# define PSNIP_CLOCK__FUNCTION PSNIP_CLOCK__COMPILER_ATTRIBUTES static +# endif + +enum PsnipClockType { + /* This clock provides the current time, in units since 1970-01-01 + * 00:00:00 UTC not including leap seconds. In other words, UNIX + * time. Keep in mind that this clock doesn't account for leap + * seconds, and can go backwards (think NTP adjustments). */ + PSNIP_CLOCK_TYPE_WALL = 1, + /* The CPU time is a clock which increases only when the current + * process is active (i.e., it doesn't increment while blocking on + * I/O). */ + PSNIP_CLOCK_TYPE_CPU = 2, + /* Monotonic time is always running (unlike CPU time), but it only + ever moves forward unless you reboot the system. Things like NTP + adjustments have no effect on this clock. */ + PSNIP_CLOCK_TYPE_MONOTONIC = 3 +}; + +struct PsnipClockTimespec { + psnip_uint64_t seconds; + psnip_uint64_t nanoseconds; +}; + +/* Methods we support: */ + +# define PSNIP_CLOCK_METHOD_CLOCK_GETTIME 1 +# define PSNIP_CLOCK_METHOD_TIME 2 +# define PSNIP_CLOCK_METHOD_GETTIMEOFDAY 3 +# define PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER 4 +# define PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME 5 +# define PSNIP_CLOCK_METHOD_CLOCK 6 +# define PSNIP_CLOCK_METHOD_GETPROCESSTIMES 7 +# define PSNIP_CLOCK_METHOD_GETRUSAGE 8 +# define PSNIP_CLOCK_METHOD_GETSYSTEMTIMEPRECISEASFILETIME 9 +# define PSNIP_CLOCK_METHOD_GETTICKCOUNT64 10 + +# include + +# if defined(HEDLEY_UNREACHABLE) +# define PSNIP_CLOCK_UNREACHABLE() HEDLEY_UNREACHABLE() +# else +# define PSNIP_CLOCK_UNREACHABLE() assert(0) +# endif + +/* Choose an implementation */ + +/* #undef PSNIP_CLOCK_WALL_METHOD */ +/* #undef PSNIP_CLOCK_CPU_METHOD */ +/* #undef PSNIP_CLOCK_MONOTONIC_METHOD */ + +/* We want to be able to detect the libc implementation, so we include + ( isn't available everywhere). */ + +# if defined(__unix__) || defined(__unix) || defined(__linux__) +# include +# include +# endif + +# if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) +/* These are known to work without librt. If you know of others + * please let us know so we can add them. */ +# if (defined(__GLIBC__) && \ + (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17))) || \ + (defined(__FreeBSD__)) +# define PSNIP_CLOCK_HAVE_CLOCK_GETTIME +# elif !defined(PSNIP_CLOCK_NO_LIBRT) +# define PSNIP_CLOCK_HAVE_CLOCK_GETTIME +# endif +# endif + +# if defined(_WIN32) +# if !defined(PSNIP_CLOCK_CPU_METHOD) +# define PSNIP_CLOCK_CPU_METHOD PSNIP_CLOCK_METHOD_GETPROCESSTIMES +# endif +# if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) +# define PSNIP_CLOCK_MONOTONIC_METHOD \ + PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER +# endif +# endif + +# if defined(__MACH__) && !defined(__gnu_hurd__) +# if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) +# define PSNIP_CLOCK_MONOTONIC_METHOD \ + PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME +# endif +# endif + +# if defined(PSNIP_CLOCK_HAVE_CLOCK_GETTIME) +# include +# if !defined(PSNIP_CLOCK_WALL_METHOD) +# if defined(CLOCK_REALTIME_PRECISE) +# define PSNIP_CLOCK_WALL_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME +# define PSNIP_CLOCK_CLOCK_GETTIME_WALL CLOCK_REALTIME_PRECISE +# elif !defined(__sun) +# define PSNIP_CLOCK_WALL_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME +# define PSNIP_CLOCK_CLOCK_GETTIME_WALL CLOCK_REALTIME +# endif +# endif +# if !defined(PSNIP_CLOCK_CPU_METHOD) +# if defined(_POSIX_CPUTIME) || defined(CLOCK_PROCESS_CPUTIME_ID) +# define PSNIP_CLOCK_CPU_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME +# define PSNIP_CLOCK_CLOCK_GETTIME_CPU CLOCK_PROCESS_CPUTIME_ID +# elif defined(CLOCK_VIRTUAL) +# define PSNIP_CLOCK_CPU_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME +# define PSNIP_CLOCK_CLOCK_GETTIME_CPU CLOCK_VIRTUAL +# endif +# endif +# if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) +# if defined(CLOCK_MONOTONIC_RAW) +# define PSNIP_CLOCK_MONOTONIC_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME +# define PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC CLOCK_MONOTONIC +# elif defined(CLOCK_MONOTONIC_PRECISE) +# define PSNIP_CLOCK_MONOTONIC_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME +# define PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC CLOCK_MONOTONIC_PRECISE +# elif defined(_POSIX_MONOTONIC_CLOCK) || defined(CLOCK_MONOTONIC) +# define PSNIP_CLOCK_MONOTONIC_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME +# define PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC CLOCK_MONOTONIC +# endif +# endif +# endif + +# if defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L) +# if !defined(PSNIP_CLOCK_WALL_METHOD) +# define PSNIP_CLOCK_WALL_METHOD PSNIP_CLOCK_METHOD_GETTIMEOFDAY +# endif +# endif + +# if !defined(PSNIP_CLOCK_WALL_METHOD) +# define PSNIP_CLOCK_WALL_METHOD PSNIP_CLOCK_METHOD_TIME +# endif + +# if !defined(PSNIP_CLOCK_CPU_METHOD) +# define PSNIP_CLOCK_CPU_METHOD PSNIP_CLOCK_METHOD_CLOCK +# endif + +/* Primarily here for testing. */ +# if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + defined(PSNIP_CLOCK_REQUIRE_MONOTONIC) +# error No monotonic clock found. +# endif + +/* Implementations */ + +# if (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == \ + PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ + (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK)) || \ + (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_TIME)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_TIME)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_TIME)) +# include +# endif + +# if (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY)) +# include +# endif + +# if (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == \ + PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \ + (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64)) +# include +# endif + +# if (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE)) +# include +# include +# endif + +# if (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == \ + PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == \ + PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME)) +# include +# include +# include +# endif + +/*** Implementations ***/ + +# define PSNIP_CLOCK_NSEC_PER_SEC ((psnip_uint32_t)(1000000000ULL)) + +# if (defined(PSNIP_CLOCK_CPU_METHOD) && \ + (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ + (defined(PSNIP_CLOCK_WALL_METHOD) && \ + (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ + (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) +PSNIP_CLOCK__FUNCTION psnip_uint32_t +psnip_clock__clock_getres(clockid_t clk_id) { + struct timespec res; + int r; + + r = clock_getres(clk_id, &res); + if (r != 0) + return 0; + + return (psnip_uint32_t)(PSNIP_CLOCK_NSEC_PER_SEC / + (psnip_uint64_t)res.tv_nsec); +} + +PSNIP_CLOCK__FUNCTION int +psnip_clock__clock_gettime(clockid_t clk_id, struct PsnipClockTimespec *res) { + struct timespec ts; + + if (clock_gettime(clk_id, &ts) != 0) + return -10; + + res->seconds = (psnip_uint64_t)(ts.tv_sec); + res->nanoseconds = (psnip_uint64_t)(ts.tv_nsec); + + return 0; +} +# endif + +PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_wall_get_precision(void) { +# if !defined(PSNIP_CLOCK_WALL_METHOD) + return 0; +# elif defined(PSNIP_CLOCK_WALL_METHOD) && \ + PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME + return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_WALL); +# elif defined(PSNIP_CLOCK_WALL_METHOD) && \ + PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY + return 1000000; +# elif defined(PSNIP_CLOCK_WALL_METHOD) && \ + PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_TIME + return 1; +# else + return 0; +# endif +} + +PSNIP_CLOCK__FUNCTION int +psnip_clock_wall_get_time(struct PsnipClockTimespec *res) { +# if !defined(PSNIP_CLOCK_WALL_METHOD) + (void)res; + + return -2; +# elif defined(PSNIP_CLOCK_WALL_METHOD) && \ + PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME + return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_WALL, res); +# elif defined(PSNIP_CLOCK_WALL_METHOD) && \ + PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_TIME + res->seconds = time(NULL); + res->nanoseconds = 0; +# elif defined(PSNIP_CLOCK_WALL_METHOD) && \ + PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY + struct timeval tv; + + if (gettimeofday(&tv, NULL) != 0) + return -6; + + res->seconds = (psnip_uint64_t)tv.tv_sec; + res->nanoseconds = (psnip_uint64_t)tv.tv_usec * 1000; +# else + (void)res; + + return -2; +# endif + + return 0; +} + +PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_cpu_get_precision(void) { +# if !defined(PSNIP_CLOCK_CPU_METHOD) + return 0; +# elif defined(PSNIP_CLOCK_CPU_METHOD) && \ + PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME + return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_CPU); +# elif defined(PSNIP_CLOCK_CPU_METHOD) && \ + PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK + return CLOCKS_PER_SEC; +# elif defined(PSNIP_CLOCK_CPU_METHOD) && \ + PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES + return PSNIP_CLOCK_NSEC_PER_SEC / 100; +# else + return 0; +# endif +} + +PSNIP_CLOCK__FUNCTION int +psnip_clock_cpu_get_time(struct PsnipClockTimespec *res) { +# if !defined(PSNIP_CLOCK_CPU_METHOD) + (void)res; + return -2; +# elif defined(PSNIP_CLOCK_CPU_METHOD) && \ + PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME + return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_CPU, res); +# elif defined(PSNIP_CLOCK_CPU_METHOD) && \ + PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK + clock_t t = clock(); + if (t == ((clock_t)-1)) + return -5; + res->seconds = t / CLOCKS_PER_SEC; + res->nanoseconds = + (t % CLOCKS_PER_SEC) * (PSNIP_CLOCK_NSEC_PER_SEC / CLOCKS_PER_SEC); +# elif defined(PSNIP_CLOCK_CPU_METHOD) && \ + PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES + FILETIME CreationTime, ExitTime, KernelTime, UserTime; + LARGE_INTEGER date, adjust; + + if (!GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, + &KernelTime, &UserTime)) + return -7; + + /* http://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/ */ + date.HighPart = (LONG)UserTime.dwHighDateTime; + date.LowPart = UserTime.dwLowDateTime; + adjust.QuadPart = 11644473600000 * 10000; + date.QuadPart -= adjust.QuadPart; + + res->seconds = (psnip_uint64_t)(date.QuadPart / 10000000); + res->nanoseconds = (psnip_uint64_t)(date.QuadPart % 10000000) * + (PSNIP_CLOCK_NSEC_PER_SEC / 100); +# elif PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE + struct rusage usage; + if (getrusage(RUSAGE_SELF, &usage) != 0) + return -8; + + res->seconds = usage.ru_utime.tv_sec; + res->nanoseconds = tv.tv_usec * 1000; +# else + (void)res; + return -2; +# endif + + return 0; +} + +PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_monotonic_get_precision(void) { +# if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) + return 0; +# elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME + return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC); +# elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME + static mach_timebase_info_data_t tbi = { + 0, + }; + if (tbi.denom == 0) + mach_timebase_info(&tbi); + return (psnip_uint32_t)(tbi.numer / tbi.denom); +# elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64 + return 1000; +# elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + PSNIP_CLOCK_MONOTONIC_METHOD == \ + PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER + LARGE_INTEGER Frequency; + QueryPerformanceFrequency(&Frequency); + return (psnip_uint32_t)((Frequency.QuadPart > PSNIP_CLOCK_NSEC_PER_SEC) + ? PSNIP_CLOCK_NSEC_PER_SEC + : Frequency.QuadPart); +# else + return 0; +# endif +} + +PSNIP_CLOCK__FUNCTION int +psnip_clock_monotonic_get_time(struct PsnipClockTimespec *res) { +# if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) + (void)res; + return -2; +# elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME + return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC, res); +# elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME + psnip_uint64_t nsec = mach_absolute_time(); + static mach_timebase_info_data_t tbi = { + 0, + }; + if (tbi.denom == 0) + mach_timebase_info(&tbi); + nsec *= ((psnip_uint64_t)tbi.numer) / ((psnip_uint64_t)tbi.denom); + res->seconds = nsec / PSNIP_CLOCK_NSEC_PER_SEC; + res->nanoseconds = nsec % PSNIP_CLOCK_NSEC_PER_SEC; +# elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + PSNIP_CLOCK_MONOTONIC_METHOD == \ + PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER + LARGE_INTEGER t, f; + if (QueryPerformanceCounter(&t) == 0) + return -12; + + QueryPerformanceFrequency(&f); + res->seconds = (psnip_uint64_t)(t.QuadPart / f.QuadPart); + res->nanoseconds = (psnip_uint64_t)(t.QuadPart % f.QuadPart); + if (f.QuadPart > PSNIP_CLOCK_NSEC_PER_SEC) + res->nanoseconds /= (psnip_uint64_t)f.QuadPart / PSNIP_CLOCK_NSEC_PER_SEC; + else + res->nanoseconds *= PSNIP_CLOCK_NSEC_PER_SEC / (psnip_uint64_t)f.QuadPart; +# elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ + PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64 + const ULONGLONG msec = GetTickCount64(); + res->seconds = msec / 1000; + res->nanoseconds = sec % 1000; +# else + return -2; +# endif + + return 0; +} + +/* Returns the number of ticks per second for the specified clock. + * For example, a clock with millisecond precision would return 1000, + * and a clock with 1 second (such as the time() function) would + * return 1. + * + * If the requested clock isn't available, it will return 0. + * Hopefully this will be rare, but if it happens to you please let us + * know so we can work on finding a way to support your system. + * + * Note that different clocks on the same system often have a + * different precisions. + */ +PSNIP_CLOCK__FUNCTION psnip_uint32_t +psnip_clock_get_precision(enum PsnipClockType clock_type) { + switch (clock_type) { + case PSNIP_CLOCK_TYPE_MONOTONIC: + return psnip_clock_monotonic_get_precision(); + case PSNIP_CLOCK_TYPE_CPU: + return psnip_clock_cpu_get_precision(); + case PSNIP_CLOCK_TYPE_WALL: + return psnip_clock_wall_get_precision(); + } + + PSNIP_CLOCK_UNREACHABLE(); + return 0; +} + +/* Set the provided timespec to the requested time. Returns 0 on + * success, or a negative value on failure. */ +PSNIP_CLOCK__FUNCTION int psnip_clock_get_time(enum PsnipClockType clock_type, + struct PsnipClockTimespec *res) { + assert(res != NULL); + + switch (clock_type) { + case PSNIP_CLOCK_TYPE_MONOTONIC: + return psnip_clock_monotonic_get_time(res); + case PSNIP_CLOCK_TYPE_CPU: + return psnip_clock_cpu_get_time(res); + case PSNIP_CLOCK_TYPE_WALL: + return psnip_clock_wall_get_time(res); + } + + return -1; +} + +# endif /* !defined(PSNIP_CLOCK_H) */ + +static psnip_uint64_t munit_clock_get_elapsed(struct PsnipClockTimespec *start, + struct PsnipClockTimespec *end) { + psnip_uint64_t r = (end->seconds - start->seconds) * PSNIP_CLOCK_NSEC_PER_SEC; + if (end->nanoseconds < start->nanoseconds) { + return r - (start->nanoseconds - end->nanoseconds); + } + + return r + (end->nanoseconds - start->nanoseconds); +} + +#else +# include +#endif /* defined(MUNIT_ENABLE_TIMING) */ + +/*** PRNG stuff ***/ + +/* This is (unless I screwed up, which is entirely possible) the + * version of PCG with 32-bit state. It was chosen because it has a + * small enough state that we should reliably be able to use CAS + * instead of requiring a lock for thread-safety. + * + * If I did screw up, I probably will not bother changing it unless + * there is a significant bias. It's really not important this be + * particularly strong, as long as it is fairly random it's much more + * important that it be reproducible, so bug reports have a better + * chance of being reproducible. */ + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(__STDC_NO_ATOMICS__) && !defined(__EMSCRIPTEN__) && \ + (!defined(__GNUC_MINOR__) || (__GNUC__ > 4) || \ + (__GNUC__ == 4 && __GNUC_MINOR__ > 8)) +# define HAVE_STDATOMIC +#elif defined(__clang__) +# if __has_extension(c_atomic) +# define HAVE_CLANG_ATOMICS +# endif +#endif + +/* Workaround for http://llvm.org/bugs/show_bug.cgi?id=26911 */ +#if defined(__clang__) && defined(_WIN32) +# undef HAVE_STDATOMIC +# if defined(__c2__) +# undef HAVE_CLANG_ATOMICS +# endif +#endif + +#if defined(_OPENMP) +# define ATOMIC_UINT32_T uint32_t +# define ATOMIC_UINT32_INIT(x) (x) +#elif defined(HAVE_STDATOMIC) +# include +# define ATOMIC_UINT32_T _Atomic uint32_t +# define ATOMIC_UINT32_INIT(x) ATOMIC_VAR_INIT(x) +#elif defined(HAVE_CLANG_ATOMICS) +# define ATOMIC_UINT32_T _Atomic uint32_t +# define ATOMIC_UINT32_INIT(x) (x) +#elif defined(_WIN32) +# define ATOMIC_UINT32_T volatile LONG +# define ATOMIC_UINT32_INIT(x) (x) +#else +# define ATOMIC_UINT32_T volatile uint32_t +# define ATOMIC_UINT32_INIT(x) (x) +#endif + +static ATOMIC_UINT32_T munit_rand_state = ATOMIC_UINT32_INIT(42); + +#if defined(_OPENMP) +static inline void munit_atomic_store(ATOMIC_UINT32_T *dest, + ATOMIC_UINT32_T value) { +# pragma omp critical(munit_atomics) + *dest = value; +} + +static inline uint32_t munit_atomic_load(ATOMIC_UINT32_T *src) { + int ret; +# pragma omp critical(munit_atomics) + ret = *src; + return ret; +} + +static inline uint32_t munit_atomic_cas(ATOMIC_UINT32_T *dest, + ATOMIC_UINT32_T *expected, + ATOMIC_UINT32_T desired) { + munit_bool ret; + +# pragma omp critical(munit_atomics) + { + if (*dest == *expected) { + *dest = desired; + ret = 1; + } else { + ret = 0; + } + } + + return ret; +} +#elif defined(HAVE_STDATOMIC) +# define munit_atomic_store(dest, value) atomic_store(dest, value) +# define munit_atomic_load(src) atomic_load(src) +# define munit_atomic_cas(dest, expected, value) \ + atomic_compare_exchange_weak(dest, expected, value) +#elif defined(HAVE_CLANG_ATOMICS) +# define munit_atomic_store(dest, value) \ + __c11_atomic_store(dest, value, __ATOMIC_SEQ_CST) +# define munit_atomic_load(src) __c11_atomic_load(src, __ATOMIC_SEQ_CST) +# define munit_atomic_cas(dest, expected, value) \ + __c11_atomic_compare_exchange_weak(dest, expected, value, \ + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) +#elif defined(__GNUC__) && (__GNUC__ > 4) || \ + (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) +# define munit_atomic_store(dest, value) \ + __atomic_store_n(dest, value, __ATOMIC_SEQ_CST) +# define munit_atomic_load(src) __atomic_load_n(src, __ATOMIC_SEQ_CST) +# define munit_atomic_cas(dest, expected, value) \ + __atomic_compare_exchange_n(dest, expected, value, 1, __ATOMIC_SEQ_CST, \ + __ATOMIC_SEQ_CST) +#elif defined(__GNUC__) && (__GNUC__ >= 4) +# define munit_atomic_store(dest, value) \ + do { \ + *(dest) = (value); \ + } while (0) +# define munit_atomic_load(src) (*(src)) +# define munit_atomic_cas(dest, expected, value) \ + __sync_bool_compare_and_swap(dest, *expected, value) +#elif defined(_WIN32) /* Untested */ +# define munit_atomic_store(dest, value) \ + do { \ + *(dest) = (value); \ + } while (0) +# define munit_atomic_load(src) (*(src)) +# define munit_atomic_cas(dest, expected, value) \ + InterlockedCompareExchange((dest), (value), *(expected)) +#else +# warning No atomic implementation, PRNG will not be thread-safe +# define munit_atomic_store(dest, value) \ + do { \ + *(dest) = (value); \ + } while (0) +# define munit_atomic_load(src) (*(src)) +static inline munit_bool munit_atomic_cas(ATOMIC_UINT32_T *dest, + ATOMIC_UINT32_T *expected, + ATOMIC_UINT32_T desired) { + if (*dest == *expected) { + *dest = desired; + return 1; + } else { + return 0; + } +} +#endif + +#define MUNIT_PRNG_MULTIPLIER (747796405U) +#define MUNIT_PRNG_INCREMENT (1729U) + +static munit_uint32_t munit_rand_next_state(munit_uint32_t state) { + return state * MUNIT_PRNG_MULTIPLIER + MUNIT_PRNG_INCREMENT; +} + +static munit_uint32_t munit_rand_from_state(munit_uint32_t state) { + munit_uint32_t res = ((state >> ((state >> 28) + 4)) ^ state) * (277803737U); + res ^= res >> 22; + return res; +} + +void munit_rand_seed(munit_uint32_t seed) { + munit_uint32_t state = munit_rand_next_state(seed + MUNIT_PRNG_INCREMENT); + munit_atomic_store(&munit_rand_state, state); +} + +static munit_uint32_t munit_rand_generate_seed(void) { + munit_uint32_t seed, state; +#if defined(MUNIT_ENABLE_TIMING) + struct PsnipClockTimespec wc = { + 0, + }; + + psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &wc); + seed = (munit_uint32_t)wc.nanoseconds; +#else + seed = (munit_uint32_t)time(NULL); +#endif + + state = munit_rand_next_state(seed + MUNIT_PRNG_INCREMENT); + return munit_rand_from_state(state); +} + +static munit_uint32_t munit_rand_state_uint32(munit_uint32_t *state) { + const munit_uint32_t old = *state; + *state = munit_rand_next_state(old); + return munit_rand_from_state(old); +} + +munit_uint32_t munit_rand_uint32(void) { + munit_uint32_t old, state; + + do { + old = munit_atomic_load(&munit_rand_state); + state = munit_rand_next_state(old); + } while (!munit_atomic_cas(&munit_rand_state, &old, state)); + + return munit_rand_from_state(old); +} + +static void munit_rand_state_memory(munit_uint32_t *state, size_t size, + munit_uint8_t *data) { + size_t members_remaining = size / sizeof(munit_uint32_t); + size_t bytes_remaining = size % sizeof(munit_uint32_t); + munit_uint8_t *b = data; + munit_uint32_t rv; + while (members_remaining-- > 0) { + rv = munit_rand_state_uint32(state); + memcpy(b, &rv, sizeof(munit_uint32_t)); + b += sizeof(munit_uint32_t); + } + if (bytes_remaining != 0) { + rv = munit_rand_state_uint32(state); + memcpy(b, &rv, bytes_remaining); + } +} + +void munit_rand_memory(size_t size, munit_uint8_t *data) { + munit_uint32_t old, state; + + do { + state = old = munit_atomic_load(&munit_rand_state); + munit_rand_state_memory(&state, size, data); + } while (!munit_atomic_cas(&munit_rand_state, &old, state)); +} + +static munit_uint32_t munit_rand_state_at_most(munit_uint32_t *state, + munit_uint32_t salt, + munit_uint32_t max) { + /* We want (UINT32_MAX + 1) % max, which in unsigned arithmetic is the same + * as (UINT32_MAX + 1 - max) % max = -max % max. We compute -max using not + * to avoid compiler warnings. + */ + const munit_uint32_t min = (~max + 1U) % max; + munit_uint32_t x; + + if (max == (~((munit_uint32_t)0U))) + return munit_rand_state_uint32(state) ^ salt; + + max++; + + do { + x = munit_rand_state_uint32(state) ^ salt; + } while (x < min); + + return x % max; +} + +static munit_uint32_t munit_rand_at_most(munit_uint32_t salt, + munit_uint32_t max) { + munit_uint32_t old, state; + munit_uint32_t retval; + + do { + state = old = munit_atomic_load(&munit_rand_state); + retval = munit_rand_state_at_most(&state, salt, max); + } while (!munit_atomic_cas(&munit_rand_state, &old, state)); + + return retval; +} + +int munit_rand_int_range(int min, int max) { + munit_uint64_t range = (munit_uint64_t)max - (munit_uint64_t)min; + + if (min > max) + return munit_rand_int_range(max, min); + + if (range > (~((munit_uint32_t)0U))) + range = (~((munit_uint32_t)0U)); + + return min + (int)munit_rand_at_most(0, (munit_uint32_t)range); +} + +double munit_rand_double(void) { + munit_uint32_t old, state; + double retval = 0.0; + + do { + state = old = munit_atomic_load(&munit_rand_state); + + /* See http://mumble.net/~campbell/tmp/random_real.c for how to do + * this right. Patches welcome if you feel that this is too + * biased. */ + retval = munit_rand_state_uint32(&state) / ((~((munit_uint32_t)0U)) + 1.0); + } while (!munit_atomic_cas(&munit_rand_state, &old, state)); + + return retval; +} + +/*** Test suite handling ***/ + +typedef struct { + unsigned int successful; + unsigned int skipped; + unsigned int failed; + unsigned int errored; +#if defined(MUNIT_ENABLE_TIMING) + munit_uint64_t cpu_clock; + munit_uint64_t wall_clock; +#endif +} MunitReport; + +typedef struct { + const char *prefix; + const MunitSuite *suite; + const char **tests; + munit_uint32_t seed; + unsigned int iterations; + MunitParameter *parameters; + munit_bool single_parameter_mode; + void *user_data; + MunitReport report; + munit_bool colorize; + munit_bool fork; + munit_bool show_stderr; + munit_bool fatal_failures; +} MunitTestRunner; + +const char *munit_parameters_get(const MunitParameter params[], + const char *key) { + const MunitParameter *param; + + for (param = params; param != NULL && param->name != NULL; param++) + if (strcmp(param->name, key) == 0) + return param->value; + return NULL; +} + +#if defined(MUNIT_ENABLE_TIMING) +static void munit_print_time(FILE *fp, munit_uint64_t nanoseconds) { + fprintf(fp, "%" MUNIT_TEST_TIME_FORMAT, + ((double)nanoseconds) / ((double)PSNIP_CLOCK_NSEC_PER_SEC)); +} +#endif + +/* Add a paramter to an array of parameters. */ +static MunitResult munit_parameters_add(size_t *params_size, + MunitParameter **params, char *name, + char *value) { + *params = realloc(*params, sizeof(MunitParameter) * (*params_size + 2)); + if (*params == NULL) + return MUNIT_ERROR; + + (*params)[*params_size].name = name; + (*params)[*params_size].value = value; + (*params_size)++; + (*params)[*params_size].name = NULL; + (*params)[*params_size].value = NULL; + + return MUNIT_OK; +} + +/* Concatenate two strings, but just return one of the components + * unaltered if the other is NULL or "". */ +static char *munit_maybe_concat(size_t *len, char *prefix, char *suffix) { + char *res; + size_t res_l; + const size_t prefix_l = prefix != NULL ? strlen(prefix) : 0; + const size_t suffix_l = suffix != NULL ? strlen(suffix) : 0; + if (prefix_l == 0 && suffix_l == 0) { + res = NULL; + res_l = 0; + } else if (prefix_l == 0 && suffix_l != 0) { + res = suffix; + res_l = suffix_l; + } else if (prefix_l != 0 && suffix_l == 0) { + res = prefix; + res_l = prefix_l; + } else { + res_l = prefix_l + suffix_l; + res = malloc(res_l + 1); + memcpy(res, prefix, prefix_l); + memcpy(res + prefix_l, suffix, suffix_l); + res[res_l] = 0; + } + + if (len != NULL) + *len = res_l; + + return res; +} + +/* Possbily free a string returned by munit_maybe_concat. */ +static void munit_maybe_free_concat(char *s, const char *prefix, + const char *suffix) { + if (prefix != s && suffix != s) + free(s); +} + +/* Cheap string hash function, just used to salt the PRNG. */ +static munit_uint32_t munit_str_hash(const char *name) { + const char *p; + munit_uint32_t h = 5381U; + + for (p = name; *p != '\0'; p++) + h = (munit_uint32_t)(h << 5) + h + (munit_uint32_t)*p; + + return h; +} + +static void munit_splice(int from, int to) { + munit_uint8_t buf[1024]; +#if !defined(_WIN32) + ssize_t len; + ssize_t bytes_written; + ssize_t write_res; +#else + int len; + int bytes_written; + int write_res; +#endif + do { + len = read(from, buf, sizeof(buf)); + if (len > 0) { + bytes_written = 0; + do { + write_res = write(to, buf + bytes_written, +#if !defined(_WIN32) + (size_t) +#else + (unsigned int) +#endif + (len - bytes_written)); + if (write_res < 0) + break; + bytes_written += write_res; + } while (bytes_written < len); + } else + break; + } while (1); +} + +/* This is the part that should be handled in the child process */ +static MunitResult munit_test_runner_exec(MunitTestRunner *runner, + const MunitTest *test, + const MunitParameter params[], + MunitReport *report) { + unsigned int iterations = runner->iterations; + MunitResult result = MUNIT_FAIL; +#if defined(MUNIT_ENABLE_TIMING) + struct PsnipClockTimespec wall_clock_begin = + { + 0, + }, + wall_clock_end = { + 0, + }; + struct PsnipClockTimespec cpu_clock_begin = + { + 0, + }, + cpu_clock_end = { + 0, + }; +#endif + unsigned int i = 0; + + if ((test->options & MUNIT_TEST_OPTION_SINGLE_ITERATION) == + MUNIT_TEST_OPTION_SINGLE_ITERATION) + iterations = 1; + else if (iterations == 0) + iterations = runner->suite->iterations; + + munit_rand_seed(runner->seed); + + do { + void *data = (test->setup == NULL) ? runner->user_data + : test->setup(params, runner->user_data); + +#if defined(MUNIT_ENABLE_TIMING) + psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &wall_clock_begin); + psnip_clock_get_time(PSNIP_CLOCK_TYPE_CPU, &cpu_clock_begin); +#endif + + result = test->test(params, data); + +#if defined(MUNIT_ENABLE_TIMING) + psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &wall_clock_end); + psnip_clock_get_time(PSNIP_CLOCK_TYPE_CPU, &cpu_clock_end); +#endif + + if (test->tear_down != NULL) + test->tear_down(data); + + if (MUNIT_LIKELY(result == MUNIT_OK)) { + report->successful++; +#if defined(MUNIT_ENABLE_TIMING) + report->wall_clock += + munit_clock_get_elapsed(&wall_clock_begin, &wall_clock_end); + report->cpu_clock += + munit_clock_get_elapsed(&cpu_clock_begin, &cpu_clock_end); +#endif + } else { + switch ((int)result) { + case MUNIT_SKIP: + report->skipped++; + break; + case MUNIT_FAIL: + report->failed++; + break; + case MUNIT_ERROR: + report->errored++; + break; + default: + break; + } + break; + } + } while (++i < iterations); + + return result; +} + +#if defined(MUNIT_EMOTICON) +# define MUNIT_RESULT_STRING_OK ":)" +# define MUNIT_RESULT_STRING_SKIP ":|" +# define MUNIT_RESULT_STRING_FAIL ":(" +# define MUNIT_RESULT_STRING_ERROR ":o" +# define MUNIT_RESULT_STRING_TODO ":/" +#else +# define MUNIT_RESULT_STRING_OK "OK " +# define MUNIT_RESULT_STRING_SKIP "SKIP " +# define MUNIT_RESULT_STRING_FAIL "FAIL " +# define MUNIT_RESULT_STRING_ERROR "ERROR" +# define MUNIT_RESULT_STRING_TODO "TODO " +#endif + +static void munit_test_runner_print_color(const MunitTestRunner *runner, + const char *string, char color) { + if (runner->colorize) + fprintf(MUNIT_OUTPUT_FILE, "\x1b[3%cm%s\x1b[39m", color, string); + else + fputs(string, MUNIT_OUTPUT_FILE); +} + +#if !defined(MUNIT_NO_BUFFER) +static int munit_replace_stderr(FILE *stderr_buf) { + if (stderr_buf != NULL) { + const int orig_stderr = dup(STDERR_FILENO); + + int errfd = fileno(stderr_buf); + if (MUNIT_UNLIKELY(errfd == -1)) { + exit(EXIT_FAILURE); + } + + dup2(errfd, STDERR_FILENO); + + return orig_stderr; + } + + return -1; +} + +static void munit_restore_stderr(int orig_stderr) { + if (orig_stderr != -1) { + dup2(orig_stderr, STDERR_FILENO); + close(orig_stderr); + } +} +#endif /* !defined(MUNIT_NO_BUFFER) */ + +/* Run a test with the specified parameters. */ +static void +munit_test_runner_run_test_with_params(MunitTestRunner *runner, + const MunitTest *test, + const MunitParameter params[]) { + MunitResult result = MUNIT_OK; + MunitReport report = { + 0, + 0, + 0, + 0, +#if defined(MUNIT_ENABLE_TIMING) + 0, + 0 +#endif + }; + unsigned int output_l; + munit_bool first; + const MunitParameter *param; + FILE *stderr_buf; +#if !defined(MUNIT_NO_FORK) + int pipefd[2]; + pid_t fork_pid; + ssize_t bytes_written = 0; + ssize_t write_res; + ssize_t bytes_read = 0; + ssize_t read_res; + int status = 0; + pid_t changed_pid; +#endif + + if (params != NULL) { + output_l = 2; + fputs(" ", MUNIT_OUTPUT_FILE); + first = 1; + for (param = params; param != NULL && param->name != NULL; param++) { + if (!first) { + fputs(", ", MUNIT_OUTPUT_FILE); + output_l += 2; + } else { + first = 0; + } + + output_l += (unsigned int)fprintf(MUNIT_OUTPUT_FILE, "%s=%s", param->name, + param->value); + } + while (output_l++ < MUNIT_TEST_NAME_LEN) { + fputc(' ', MUNIT_OUTPUT_FILE); + } + } + + fflush(MUNIT_OUTPUT_FILE); + + stderr_buf = NULL; +#if !defined(_WIN32) || defined(__MINGW32__) + stderr_buf = tmpfile(); +#else + tmpfile_s(&stderr_buf); +#endif + if (stderr_buf == NULL) { + munit_log_errno(MUNIT_LOG_ERROR, stderr, + "unable to create buffer for stderr"); + result = MUNIT_ERROR; + goto print_result; + } + +#if !defined(MUNIT_NO_FORK) + if (runner->fork) { + pipefd[0] = -1; + pipefd[1] = -1; + if (pipe(pipefd) != 0) { + munit_log_errno(MUNIT_LOG_ERROR, stderr, "unable to create pipe"); + result = MUNIT_ERROR; + goto print_result; + } + + fork_pid = fork(); + if (fork_pid == 0) { + int orig_stderr; + + close(pipefd[0]); + + orig_stderr = munit_replace_stderr(stderr_buf); + munit_test_runner_exec(runner, test, params, &report); + + /* Note that we don't restore stderr. This is so we can buffer + * things written to stderr later on (such as by + * asan/tsan/ubsan, valgrind, etc.) */ + close(orig_stderr); + + do { + write_res = + write(pipefd[1], ((munit_uint8_t *)(&report)) + bytes_written, + sizeof(report) - (size_t)bytes_written); + if (write_res < 0) { + if (stderr_buf != NULL) { + munit_log_errno(MUNIT_LOG_ERROR, stderr, "unable to write to pipe"); + } + exit(EXIT_FAILURE); + } + bytes_written += write_res; + } while ((size_t)bytes_written < sizeof(report)); + + if (stderr_buf != NULL) + fclose(stderr_buf); + close(pipefd[1]); + + exit(EXIT_SUCCESS); + } else if (fork_pid == -1) { + close(pipefd[0]); + close(pipefd[1]); + if (stderr_buf != NULL) { + munit_log_errno(MUNIT_LOG_ERROR, stderr, "unable to fork"); + } + report.errored++; + result = MUNIT_ERROR; + } else { + close(pipefd[1]); + do { + read_res = read(pipefd[0], ((munit_uint8_t *)(&report)) + bytes_read, + sizeof(report) - (size_t)bytes_read); + if (read_res < 1) + break; + bytes_read += read_res; + } while (bytes_read < (ssize_t)sizeof(report)); + + changed_pid = waitpid(fork_pid, &status, 0); + + if (MUNIT_LIKELY(changed_pid == fork_pid) && + MUNIT_LIKELY(WIFEXITED(status))) { + if (bytes_read != sizeof(report)) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, + "child exited unexpectedly with status %d", + WEXITSTATUS(status)); + report.errored++; + } else if (WEXITSTATUS(status) != EXIT_SUCCESS) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, + "child exited with status %d", + WEXITSTATUS(status)); + report.errored++; + } + } else { + if (WIFSIGNALED(status)) { +# if defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 700) + munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, + "child killed by signal %d (%s)", + WTERMSIG(status), strsignal(WTERMSIG(status))); +# else + munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, + "child killed by signal %d", WTERMSIG(status)); +# endif + } else if (WIFSTOPPED(status)) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, + "child stopped by signal %d", WSTOPSIG(status)); + } + report.errored++; + } + + close(pipefd[0]); + waitpid(fork_pid, NULL, 0); + } + } else +#endif + { +#if !defined(MUNIT_NO_BUFFER) + const volatile int orig_stderr = munit_replace_stderr(stderr_buf); +#endif + +#if defined(MUNIT_THREAD_LOCAL) + if (MUNIT_UNLIKELY(setjmp(munit_error_jmp_buf) != 0)) { + result = MUNIT_FAIL; + report.failed++; + } else { + munit_error_jmp_buf_valid = 1; + result = munit_test_runner_exec(runner, test, params, &report); + } +#else + result = munit_test_runner_exec(runner, test, params, &report); +#endif + +#if !defined(MUNIT_NO_BUFFER) + munit_restore_stderr(orig_stderr); +#endif + + /* Here just so that the label is used on Windows and we don't get + * a warning */ + goto print_result; + } + +print_result: + + fputs("[ ", MUNIT_OUTPUT_FILE); + if ((test->options & MUNIT_TEST_OPTION_TODO) == MUNIT_TEST_OPTION_TODO) { + if (report.failed != 0 || report.errored != 0 || report.skipped != 0) { + munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_TODO, '3'); + result = MUNIT_OK; + } else { + munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_ERROR, '1'); + if (MUNIT_LIKELY(stderr_buf != NULL)) + munit_log_internal(MUNIT_LOG_ERROR, stderr_buf, + "Test marked TODO, but was successful."); + runner->report.failed++; + result = MUNIT_ERROR; + } + } else if (report.failed > 0) { + munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_FAIL, '1'); + runner->report.failed++; + result = MUNIT_FAIL; + } else if (report.errored > 0) { + munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_ERROR, '1'); + runner->report.errored++; + result = MUNIT_ERROR; + } else if (report.skipped > 0) { + munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_SKIP, '3'); + runner->report.skipped++; + result = MUNIT_SKIP; + } else if (report.successful > 1) { + munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_OK, '2'); +#if defined(MUNIT_ENABLE_TIMING) + fputs(" ] [ ", MUNIT_OUTPUT_FILE); + munit_print_time(MUNIT_OUTPUT_FILE, report.wall_clock / report.successful); + fputs(" / ", MUNIT_OUTPUT_FILE); + munit_print_time(MUNIT_OUTPUT_FILE, report.cpu_clock / report.successful); + fprintf(MUNIT_OUTPUT_FILE, + " CPU ]\n %-" MUNIT_XSTRINGIFY(MUNIT_TEST_NAME_LEN) "s Total: [ ", + ""); + munit_print_time(MUNIT_OUTPUT_FILE, report.wall_clock); + fputs(" / ", MUNIT_OUTPUT_FILE); + munit_print_time(MUNIT_OUTPUT_FILE, report.cpu_clock); + fputs(" CPU", MUNIT_OUTPUT_FILE); +#endif + runner->report.successful++; + result = MUNIT_OK; + } else if (report.successful > 0) { + munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_OK, '2'); +#if defined(MUNIT_ENABLE_TIMING) + fputs(" ] [ ", MUNIT_OUTPUT_FILE); + munit_print_time(MUNIT_OUTPUT_FILE, report.wall_clock); + fputs(" / ", MUNIT_OUTPUT_FILE); + munit_print_time(MUNIT_OUTPUT_FILE, report.cpu_clock); + fputs(" CPU", MUNIT_OUTPUT_FILE); +#endif + runner->report.successful++; + result = MUNIT_OK; + } + fputs(" ]\n", MUNIT_OUTPUT_FILE); + + if (stderr_buf != NULL) { + if (result == MUNIT_FAIL || result == MUNIT_ERROR || runner->show_stderr) { + fflush(MUNIT_OUTPUT_FILE); + + rewind(stderr_buf); + munit_splice(fileno(stderr_buf), STDERR_FILENO); + + fflush(stderr); + } + + fclose(stderr_buf); + } +} + +static void munit_test_runner_run_test_wild(MunitTestRunner *runner, + const MunitTest *test, + const char *test_name, + MunitParameter *params, + MunitParameter *p) { + const MunitParameterEnum *pe; + char **values; + MunitParameter *next; + + for (pe = test->parameters; pe != NULL && pe->name != NULL; pe++) { + if (p->name == pe->name) + break; + } + + if (pe == NULL) + return; + + for (values = pe->values; *values != NULL; values++) { + next = p + 1; + p->value = *values; + if (next->name == NULL) { + munit_test_runner_run_test_with_params(runner, test, params); + } else { + munit_test_runner_run_test_wild(runner, test, test_name, params, next); + } + if (runner->fatal_failures && + (runner->report.failed != 0 || runner->report.errored != 0)) + break; + } +} + +/* Run a single test, with every combination of parameters + * requested. */ +static void munit_test_runner_run_test(MunitTestRunner *runner, + const MunitTest *test, + const char *prefix) { + char *test_name = + munit_maybe_concat(NULL, (char *)prefix, (char *)test->name); + /* The array of parameters to pass to + * munit_test_runner_run_test_with_params */ + MunitParameter *params = NULL; + size_t params_l = 0; + /* Wildcard parameters are parameters which have possible values + * specified in the test, but no specific value was passed to the + * CLI. That means we want to run the test once for every + * possible combination of parameter values or, if --single was + * passed to the CLI, a single time with a random set of + * parameters. */ + MunitParameter *wild_params = NULL; + size_t wild_params_l = 0; + const MunitParameterEnum *pe; + const MunitParameter *cli_p; + munit_bool filled; + unsigned int possible; + char **vals; + size_t first_wild; + const MunitParameter *wp; + int pidx; + + munit_rand_seed(runner->seed); + + fprintf(MUNIT_OUTPUT_FILE, "%-" MUNIT_XSTRINGIFY(MUNIT_TEST_NAME_LEN) "s", + test_name); + + if (test->parameters == NULL) { + /* No parameters. Simple, nice. */ + munit_test_runner_run_test_with_params(runner, test, NULL); + } else { + fputc('\n', MUNIT_OUTPUT_FILE); + + for (pe = test->parameters; pe != NULL && pe->name != NULL; pe++) { + /* Did we received a value for this parameter from the CLI? */ + filled = 0; + for (cli_p = runner->parameters; cli_p != NULL && cli_p->name != NULL; + cli_p++) { + if (strcmp(cli_p->name, pe->name) == 0) { + if (MUNIT_UNLIKELY(munit_parameters_add(¶ms_l, ¶ms, pe->name, + cli_p->value) != MUNIT_OK)) + goto cleanup; + filled = 1; + break; + } + } + if (filled) + continue; + + /* Nothing from CLI, is the enum NULL/empty? We're not a + * fuzzer… */ + if (pe->values == NULL || pe->values[0] == NULL) + continue; + + /* If --single was passed to the CLI, choose a value from the + * list of possibilities randomly. */ + if (runner->single_parameter_mode) { + possible = 0; + for (vals = pe->values; *vals != NULL; vals++) + possible++; + /* We want the tests to be reproducible, even if you're only + * running a single test, but we don't want every test with + * the same number of parameters to choose the same parameter + * number, so use the test name as a primitive salt. */ + pidx = (int)munit_rand_at_most(munit_str_hash(test_name), possible - 1); + if (MUNIT_UNLIKELY(munit_parameters_add(¶ms_l, ¶ms, pe->name, + pe->values[pidx]) != MUNIT_OK)) + goto cleanup; + } else { + /* We want to try every permutation. Put in a placeholder + * entry, we'll iterate through them later. */ + if (MUNIT_UNLIKELY(munit_parameters_add(&wild_params_l, &wild_params, + pe->name, NULL) != MUNIT_OK)) + goto cleanup; + } + } + + if (wild_params_l != 0) { + first_wild = params_l; + for (wp = wild_params; wp != NULL && wp->name != NULL; wp++) { + for (pe = test->parameters; + pe != NULL && pe->name != NULL && pe->values != NULL; pe++) { + if (strcmp(wp->name, pe->name) == 0) { + if (MUNIT_UNLIKELY(munit_parameters_add(¶ms_l, ¶ms, + pe->name, + pe->values[0]) != MUNIT_OK)) + goto cleanup; + } + } + } + + munit_test_runner_run_test_wild(runner, test, test_name, params, + params + first_wild); + } else { + munit_test_runner_run_test_with_params(runner, test, params); + } + + cleanup: + free(params); + free(wild_params); + } + + munit_maybe_free_concat(test_name, prefix, test->name); +} + +/* Recurse through the suite and run all the tests. If a list of + * tests to run was provied on the command line, run only those + * tests. */ +static void munit_test_runner_run_suite(MunitTestRunner *runner, + const MunitSuite *suite, + const char *prefix) { + size_t pre_l; + char *pre = munit_maybe_concat(&pre_l, (char *)prefix, (char *)suite->prefix); + const MunitTest *test; + const char **test_name; + const MunitSuite *child_suite; + + /* Run the tests. */ + for (test = suite->tests; test != NULL && test->test != NULL; test++) { + if (runner->tests != NULL) { /* Specific tests were requested on the CLI */ + for (test_name = runner->tests; test_name != NULL && *test_name != NULL; + test_name++) { + if ((pre_l == 0 || strncmp(pre, *test_name, pre_l) == 0) && + strncmp(test->name, *test_name + pre_l, + strlen(*test_name + pre_l)) == 0) { + munit_test_runner_run_test(runner, test, pre); + if (runner->fatal_failures && + (runner->report.failed != 0 || runner->report.errored != 0)) + goto cleanup; + } + } + } else { /* Run all tests */ + munit_test_runner_run_test(runner, test, pre); + } + } + + if (runner->fatal_failures && + (runner->report.failed != 0 || runner->report.errored != 0)) + goto cleanup; + + /* Run any child suites. */ + for (child_suite = suite->suites; + child_suite != NULL && child_suite->prefix != NULL; child_suite++) { + munit_test_runner_run_suite(runner, child_suite, pre); + } + +cleanup: + + munit_maybe_free_concat(pre, prefix, suite->prefix); +} + +static void munit_test_runner_run(MunitTestRunner *runner) { + munit_test_runner_run_suite(runner, runner->suite, NULL); +} + +static void munit_print_help(int argc, char *const *argv, void *user_data, + const MunitArgument arguments[]) { + const MunitArgument *arg; + (void)argc; + + printf("USAGE: %s [OPTIONS...] [TEST...]\n\n", argv[0]); + puts( + " --seed SEED\n" + " Value used to seed the PRNG. Must be a 32-bit integer in " + "decimal\n" + " notation with no separators (commas, decimals, spaces, " + "etc.), or\n" + " hexidecimal prefixed by \"0x\".\n" + " --iterations N\n" + " Run each test N times. 0 means the default number.\n" + " --param name value\n" + " A parameter key/value pair which will be passed to any test " + "with\n" + " takes a parameter of that name. If not provided, the test " + "will be\n" + " run once for each possible parameter value.\n" + " --list Write a list of all available tests.\n" + " --list-params\n" + " Write a list of all available tests and their possible " + "parameters.\n" + " --single Run each parameterized test in a single configuration " + "instead of\n" + " every possible combination\n" + " --log-visible debug|info|warning|error\n" + " --log-fatal debug|info|warning|error\n" + " Set the level at which messages of different severities are " + "visible,\n" + " or cause the test to terminate.\n" +#if !defined(MUNIT_NO_FORK) + " --no-fork Do not execute tests in a child process. If this option is " + "supplied\n" + " and a test crashes (including by failing an assertion), no " + "further\n" + " tests will be performed.\n" +#endif + " --fatal-failures\n" + " Stop executing tests as soon as a failure is found.\n" + " --show-stderr\n" + " Show data written to stderr by the tests, even if the test " + "succeeds.\n" + " --color auto|always|never\n" + " Colorize (or don't) the output.\n" + /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 + */ + " --help Print this help message and exit.\n"); +#if defined(MUNIT_NL_LANGINFO) + setlocale(LC_ALL, ""); + fputs((strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) ? "µnit" : "munit", + stdout); +#else + puts("munit"); +#endif + printf(" %d.%d.%d\n" + "Full documentation at: https://nemequ.github.io/munit/\n", + (MUNIT_CURRENT_VERSION >> 16) & 0xff, + (MUNIT_CURRENT_VERSION >> 8) & 0xff, + (MUNIT_CURRENT_VERSION >> 0) & 0xff); + for (arg = arguments; arg != NULL && arg->name != NULL; arg++) + arg->write_help(arg, user_data); +} + +static const MunitArgument * +munit_arguments_find(const MunitArgument arguments[], const char *name) { + const MunitArgument *arg; + + for (arg = arguments; arg != NULL && arg->name != NULL; arg++) + if (strcmp(arg->name, name) == 0) + return arg; + + return NULL; +} + +static void munit_suite_list_tests(const MunitSuite *suite, + munit_bool show_params, const char *prefix) { + size_t pre_l; + char *pre = munit_maybe_concat(&pre_l, (char *)prefix, (char *)suite->prefix); + const MunitTest *test; + const MunitParameterEnum *params; + munit_bool first; + char **val; + const MunitSuite *child_suite; + + for (test = suite->tests; test != NULL && test->name != NULL; test++) { + if (pre != NULL) + fputs(pre, stdout); + puts(test->name); + + if (show_params) { + for (params = test->parameters; params != NULL && params->name != NULL; + params++) { + fprintf(stdout, " - %s: ", params->name); + if (params->values == NULL) { + puts("Any"); + } else { + first = 1; + for (val = params->values; *val != NULL; val++) { + if (!first) { + fputs(", ", stdout); + } else { + first = 0; + } + fputs(*val, stdout); + } + putc('\n', stdout); + } + } + } + } + + for (child_suite = suite->suites; + child_suite != NULL && child_suite->prefix != NULL; child_suite++) { + munit_suite_list_tests(child_suite, show_params, pre); + } + + munit_maybe_free_concat(pre, prefix, suite->prefix); +} + +static munit_bool munit_stream_supports_ansi(FILE *stream) { +#if !defined(_WIN32) + return isatty(fileno(stream)); +#else + +# if !defined(__MINGW32__) + size_t ansicon_size = 0; +# endif + + if (isatty(fileno(stream))) { +# if !defined(__MINGW32__) + getenv_s(&ansicon_size, NULL, 0, "ANSICON"); + return ansicon_size != 0; +# else + return getenv("ANSICON") != NULL; +# endif + } + return 0; +#endif +} + +int munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc, + char *const *argv, + const MunitArgument arguments[]) { + int result = EXIT_FAILURE; + MunitTestRunner runner; + size_t parameters_size = 0; + size_t tests_size = 0; + int arg; + + char *envptr; + unsigned long ts; + char *endptr; + unsigned long long iterations; + MunitLogLevel level; + const MunitArgument *argument; + const char **runner_tests; + unsigned int tests_run; + unsigned int tests_total; + + runner.prefix = NULL; + runner.suite = NULL; + runner.tests = NULL; + runner.seed = 0; + runner.iterations = 0; + runner.parameters = NULL; + runner.single_parameter_mode = 0; + runner.user_data = NULL; + + runner.report.successful = 0; + runner.report.skipped = 0; + runner.report.failed = 0; + runner.report.errored = 0; +#if defined(MUNIT_ENABLE_TIMING) + runner.report.cpu_clock = 0; + runner.report.wall_clock = 0; +#endif + + runner.colorize = 0; +#if !defined(_WIN32) + runner.fork = 1; +#else + runner.fork = 0; +#endif + runner.show_stderr = 0; + runner.fatal_failures = 0; + runner.suite = suite; + runner.user_data = user_data; + runner.seed = munit_rand_generate_seed(); + runner.colorize = munit_stream_supports_ansi(MUNIT_OUTPUT_FILE); + + for (arg = 1; arg < argc; arg++) { + if (strncmp("--", argv[arg], 2) == 0) { + if (strcmp("seed", argv[arg] + 2) == 0) { + if (arg + 1 >= argc) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "%s requires an argument", argv[arg]); + goto cleanup; + } + + envptr = argv[arg + 1]; + ts = strtoul(argv[arg + 1], &envptr, 0); + if (*envptr != '\0' || ts > (~((munit_uint32_t)0U))) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "invalid value ('%s') passed to %s", + argv[arg + 1], argv[arg]); + goto cleanup; + } + runner.seed = (munit_uint32_t)ts; + + arg++; + } else if (strcmp("iterations", argv[arg] + 2) == 0) { + if (arg + 1 >= argc) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "%s requires an argument", argv[arg]); + goto cleanup; + } + + endptr = argv[arg + 1]; + iterations = strtoul(argv[arg + 1], &endptr, 0); + if (*endptr != '\0' || iterations > UINT_MAX) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "invalid value ('%s') passed to %s", + argv[arg + 1], argv[arg]); + goto cleanup; + } + + runner.iterations = (unsigned int)iterations; + + arg++; + } else if (strcmp("param", argv[arg] + 2) == 0) { + if (arg + 2 >= argc) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "%s requires two arguments", argv[arg]); + goto cleanup; + } + + runner.parameters = realloc( + runner.parameters, sizeof(MunitParameter) * (parameters_size + 2)); + if (runner.parameters == NULL) { + munit_log_internal(MUNIT_LOG_ERROR, stderr, + "failed to allocate memory"); + goto cleanup; + } + runner.parameters[parameters_size].name = (char *)argv[arg + 1]; + runner.parameters[parameters_size].value = (char *)argv[arg + 2]; + parameters_size++; + runner.parameters[parameters_size].name = NULL; + runner.parameters[parameters_size].value = NULL; + arg += 2; + } else if (strcmp("color", argv[arg] + 2) == 0) { + if (arg + 1 >= argc) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "%s requires an argument", argv[arg]); + goto cleanup; + } + + if (strcmp(argv[arg + 1], "always") == 0) + runner.colorize = 1; + else if (strcmp(argv[arg + 1], "never") == 0) + runner.colorize = 0; + else if (strcmp(argv[arg + 1], "auto") == 0) + runner.colorize = munit_stream_supports_ansi(MUNIT_OUTPUT_FILE); + else { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "invalid value ('%s') passed to %s", + argv[arg + 1], argv[arg]); + goto cleanup; + } + + arg++; + } else if (strcmp("help", argv[arg] + 2) == 0) { + munit_print_help(argc, argv, user_data, arguments); + result = EXIT_SUCCESS; + goto cleanup; + } else if (strcmp("single", argv[arg] + 2) == 0) { + runner.single_parameter_mode = 1; + } else if (strcmp("show-stderr", argv[arg] + 2) == 0) { + runner.show_stderr = 1; +#if !defined(_WIN32) + } else if (strcmp("no-fork", argv[arg] + 2) == 0) { + runner.fork = 0; +#endif + } else if (strcmp("fatal-failures", argv[arg] + 2) == 0) { + runner.fatal_failures = 1; + } else if (strcmp("log-visible", argv[arg] + 2) == 0 || + strcmp("log-fatal", argv[arg] + 2) == 0) { + if (arg + 1 >= argc) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "%s requires an argument", argv[arg]); + goto cleanup; + } + + if (strcmp(argv[arg + 1], "debug") == 0) + level = MUNIT_LOG_DEBUG; + else if (strcmp(argv[arg + 1], "info") == 0) + level = MUNIT_LOG_INFO; + else if (strcmp(argv[arg + 1], "warning") == 0) + level = MUNIT_LOG_WARNING; + else if (strcmp(argv[arg + 1], "error") == 0) + level = MUNIT_LOG_ERROR; + else { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "invalid value ('%s') passed to %s", + argv[arg + 1], argv[arg]); + goto cleanup; + } + + if (strcmp("log-visible", argv[arg] + 2) == 0) + munit_log_level_visible = level; + else + munit_log_level_fatal = level; + + arg++; + } else if (strcmp("list", argv[arg] + 2) == 0) { + munit_suite_list_tests(suite, 0, NULL); + result = EXIT_SUCCESS; + goto cleanup; + } else if (strcmp("list-params", argv[arg] + 2) == 0) { + munit_suite_list_tests(suite, 1, NULL); + result = EXIT_SUCCESS; + goto cleanup; + } else { + argument = munit_arguments_find(arguments, argv[arg] + 2); + if (argument == NULL) { + munit_logf_internal(MUNIT_LOG_ERROR, stderr, + "unknown argument ('%s')", argv[arg]); + goto cleanup; + } + + if (!argument->parse_argument(suite, user_data, &arg, argc, argv)) + goto cleanup; + } + } else { + runner_tests = + realloc((void *)runner.tests, sizeof(char *) * (tests_size + 2)); + if (runner_tests == NULL) { + munit_log_internal(MUNIT_LOG_ERROR, stderr, + "failed to allocate memory"); + goto cleanup; + } + runner.tests = runner_tests; + runner.tests[tests_size++] = argv[arg]; + runner.tests[tests_size] = NULL; + } + } + + fflush(stderr); + fprintf(MUNIT_OUTPUT_FILE, + "Running test suite with seed 0x%08" PRIx32 "...\n", runner.seed); + + munit_test_runner_run(&runner); + + tests_run = + runner.report.successful + runner.report.failed + runner.report.errored; + tests_total = tests_run + runner.report.skipped; + if (tests_run == 0) { + fprintf(stderr, "No tests run, %d (100%%) skipped.\n", + runner.report.skipped); + } else { + fprintf(MUNIT_OUTPUT_FILE, + "%d of %d (%0.0f%%) tests successful, %d (%0.0f%%) test skipped.\n", + runner.report.successful, tests_run, + (((double)runner.report.successful) / ((double)tests_run)) * 100.0, + runner.report.skipped, + (((double)runner.report.skipped) / ((double)tests_total)) * 100.0); + } + + if (runner.report.failed == 0 && runner.report.errored == 0) { + result = EXIT_SUCCESS; + } + +cleanup: + free(runner.parameters); + free((void *)runner.tests); + + return result; +} + +int munit_suite_main(const MunitSuite *suite, void *user_data, int argc, + char *const *argv) { + return munit_suite_main_custom(suite, user_data, argc, argv, NULL); +} + +static uint8_t hexchars[] = "0123456789abcdef"; + +static uint8_t *hexdump_addr(uint8_t *dest, size_t addr) { + size_t i; + uint8_t a; + + for (i = 0; i < 4; ++i) { + a = (addr >> (3 - i) * 8) & 0xff; + + *dest++ = hexchars[a >> 4]; + *dest++ = hexchars[a & 0xf]; + } + + return dest; +} + +static uint8_t *asciidump(uint8_t *dest, const uint8_t *data, size_t datalen) { + size_t i; + + *dest++ = '|'; + + for (i = 0; i < datalen; ++i) { + if (0x20 <= data[i] && data[i] <= 0x7e) { + *dest++ = data[i]; + } else { + *dest++ = '.'; + } + } + + *dest++ = '|'; + + return dest; +} + +static uint8_t *hexdump8(uint8_t *dest, const uint8_t *data, size_t datalen) { + size_t i; + + for (i = 0; i < datalen; ++i) { + *dest++ = hexchars[data[i] >> 4]; + *dest++ = hexchars[data[i] & 0xf]; + *dest++ = ' '; + } + + for (; i < 8; ++i) { + *dest++ = ' '; + *dest++ = ' '; + *dest++ = ' '; + } + + return dest; +} + +static uint8_t *hexdump16(uint8_t *dest, const uint8_t *data, size_t datalen) { + dest = hexdump8(dest, data, datalen < 8 ? datalen : 8); + *dest++ = ' '; + + if (datalen < 8) { + data = NULL; + datalen = 0; + } else { + data += 8; + datalen -= 8; + } + + dest = hexdump8(dest, data, datalen); + *dest++ = ' '; + + return dest; +} + +static uint8_t *hexdump_line(uint8_t *dest, const uint8_t *data, size_t datalen, + size_t addr) { + dest = hexdump_addr(dest, addr); + *dest++ = ' '; + *dest++ = ' '; + + dest = hexdump16(dest, data, datalen); + + dest = asciidump(dest, data, datalen); + + return dest; +} + +int munit_hexdump(FILE *fp, const void *data, size_t datalen) { + size_t offset = 0, n, len; + uint8_t buf[128], *p; + const uint8_t *s; + int repeated = 0; + + if (datalen == 0) { + return 0; + } + + for (; offset < datalen; offset += 16) { + n = datalen - offset; + s = (const uint8_t *)data + offset; + + if (n >= 16) { + n = 16; + + if (offset > 0) { + if (memcmp(s - 16, s, 16) == 0) { + if (repeated) { + continue; + } + + repeated = 1; + + if (fwrite("*\n", 1, 2, fp) < 2) { + return -1; + } + + continue; + } + + repeated = 0; + } + } + + p = hexdump_line(buf, s, n, offset); + *p++ = '\n'; + + len = (size_t)(p - buf); + + if (fwrite(buf, 1, len, fp) < len) { + return -1; + } + } + + p = hexdump_addr(buf, datalen); + *p++ = '\n'; + + len = (size_t)(p - buf); + + if (fwrite(buf, 1, len, fp) < len) { + return -1; + } + + return 0; +} + +int munit_hexdump_diff(FILE *fp, const void *a, size_t alen, const void *b, + size_t blen) { + size_t offset = 0, k, i, len, ncomp, maxlen, adoff = 0; + uint8_t buf[128], *p; + const uint8_t mk[2] = {'-', '+'}; + struct datasource { + const uint8_t *data; + size_t datalen; + const uint8_t *s; + size_t n; + } ds[] = {{a, alen, NULL, 0}, {b, blen, NULL, 0}}, *dp; + + maxlen = alen < blen ? blen : alen; + + for (; offset < maxlen; offset += 16) { + for (k = 0; k < 2; ++k) { + dp = &ds[k]; + + if (offset < dp->datalen) { + dp->s = (const uint8_t *)dp->data + offset; + dp->n = dp->datalen - offset; + + if (dp->n > 16) { + dp->n = 16; + } + } else { + dp->s = NULL; + dp->n = 0; + } + } + + if (ds[0].n == ds[1].n && memcmp(ds[0].s, ds[1].s, ds[0].n) == 0) { + continue; + } + + for (k = 0; k < 2; ++k) { + dp = &ds[k]; + + if (!dp->n) { + continue; + } + + p = buf; + *p++ = mk[k]; + *p++ = mk[k]; + *p++ = mk[k]; + *p++ = mk[k]; + + p = hexdump_line(p, dp->s, dp->n, offset); + *p++ = '\n'; + + len = (size_t)(p - buf); + + if (fwrite(buf, 1, len, fp) < len) { + return -1; + } + } + + if (!ds[0].n || !ds[1].n) { + continue; + } + + ncomp = ds[0].n < ds[1].n ? ds[0].n : ds[1].n; + + p = buf + 4 + 10; + + memset(buf, ' ', 4 + 78); + + for (i = 0; i < ncomp; ++i) { + if (ds[0].s[i] == ds[1].s[i]) { + *p++ = ' '; + *p++ = ' '; + } else { + adoff = 4 + 10 + 51 + i; + *(buf + adoff) = '^'; + + *p++ = '^'; + *p++ = '^'; + } + + *p++ = ' '; + + if (i == 7) { + *p++ = ' '; + } + } + + if (adoff) { + len = adoff + 1; + } else { + len = (size_t)(p - buf); + } + + buf[len++] = '\n'; + + if (fwrite(buf, 1, len, fp) < len) { + return -1; + } + } + + return 0; +} diff --git a/yass/third_party/nghttp2/tests/munit/munit.h b/yass/third_party/nghttp2/tests/munit/munit.h new file mode 100644 index 0000000000..3bdcca0ee8 --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/munit.h @@ -0,0 +1,575 @@ +/* µnit Testing Framework + * Copyright (c) 2013-2017 Evan Nemerson + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef MUNIT_H +#define MUNIT_H + +#include +#include +#include +#include + +#define MUNIT_VERSION(major, minor, revision) \ + (((major) << 16) | ((minor) << 8) | (revision)) + +#define MUNIT_CURRENT_VERSION MUNIT_VERSION(0, 4, 1) + +#if defined(_MSC_VER) && (_MSC_VER < 1600) +# define munit_int8_t __int8 +# define munit_uint8_t unsigned __int8 +# define munit_int16_t __int16 +# define munit_uint16_t unsigned __int16 +# define munit_int32_t __int32 +# define munit_uint32_t unsigned __int32 +# define munit_int64_t __int64 +# define munit_uint64_t unsigned __int64 +#else +# include +# define munit_int8_t int8_t +# define munit_uint8_t uint8_t +# define munit_int16_t int16_t +# define munit_uint16_t uint16_t +# define munit_int32_t int32_t +# define munit_uint32_t uint32_t +# define munit_int64_t int64_t +# define munit_uint64_t uint64_t +#endif + +#if defined(_MSC_VER) && (_MSC_VER < 1800) +# if !defined(PRIi8) +# define PRIi8 "i" +# endif +# if !defined(PRIi16) +# define PRIi16 "i" +# endif +# if !defined(PRIi32) +# define PRIi32 "i" +# endif +# if !defined(PRIi64) +# define PRIi64 "I64i" +# endif +# if !defined(PRId8) +# define PRId8 "d" +# endif +# if !defined(PRId16) +# define PRId16 "d" +# endif +# if !defined(PRId32) +# define PRId32 "d" +# endif +# if !defined(PRId64) +# define PRId64 "I64d" +# endif +# if !defined(PRIx8) +# define PRIx8 "x" +# endif +# if !defined(PRIx16) +# define PRIx16 "x" +# endif +# if !defined(PRIx32) +# define PRIx32 "x" +# endif +# if !defined(PRIx64) +# define PRIx64 "I64x" +# endif +# if !defined(PRIu8) +# define PRIu8 "u" +# endif +# if !defined(PRIu16) +# define PRIu16 "u" +# endif +# if !defined(PRIu32) +# define PRIu32 "u" +# endif +# if !defined(PRIu64) +# define PRIu64 "I64u" +# endif +#else +# include +#endif + +#if !defined(munit_bool) +# if defined(bool) +# define munit_bool bool +# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define munit_bool _Bool +# else +# define munit_bool int +# endif +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +#if defined(__GNUC__) +# define MUNIT_LIKELY(expr) (__builtin_expect((expr), 1)) +# define MUNIT_UNLIKELY(expr) (__builtin_expect((expr), 0)) +# define MUNIT_UNUSED __attribute__((__unused__)) +#else +# define MUNIT_LIKELY(expr) (expr) +# define MUNIT_UNLIKELY(expr) (expr) +# define MUNIT_UNUSED +#endif + +#if !defined(_WIN32) +# define MUNIT_SIZE_MODIFIER "z" +# define MUNIT_CHAR_MODIFIER "hh" +# define MUNIT_SHORT_MODIFIER "h" +#else +# if defined(_M_X64) || defined(__amd64__) +# define MUNIT_SIZE_MODIFIER "I64" +# else +# define MUNIT_SIZE_MODIFIER "" +# endif +# define MUNIT_CHAR_MODIFIER "" +# define MUNIT_SHORT_MODIFIER "" +#endif + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# define MUNIT_NO_RETURN _Noreturn +#elif defined(__GNUC__) +# define MUNIT_NO_RETURN __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +# define MUNIT_NO_RETURN __declspec(noreturn) +#else +# define MUNIT_NO_RETURN +#endif + +#if defined(_MSC_VER) && (_MSC_VER >= 1500) +# define MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + __pragma(warning(push)) __pragma(warning(disable : 4127)) +# define MUNIT_POP_DISABLE_MSVC_C4127_ __pragma(warning(pop)) +#else +# define MUNIT_PUSH_DISABLE_MSVC_C4127_ +# define MUNIT_POP_DISABLE_MSVC_C4127_ +#endif + +typedef enum { + MUNIT_LOG_DEBUG, + MUNIT_LOG_INFO, + MUNIT_LOG_WARNING, + MUNIT_LOG_ERROR +} MunitLogLevel; + +#if defined(__GNUC__) && !defined(__MINGW32__) +# define MUNIT_PRINTF(string_index, first_to_check) \ + __attribute__((format(printf, string_index, first_to_check))) +#else +# define MUNIT_PRINTF(string_index, first_to_check) +#endif + +MUNIT_PRINTF(4, 5) +void munit_logf_ex(MunitLogLevel level, const char *filename, int line, + const char *format, ...); + +#define munit_logf(level, format, ...) \ + munit_logf_ex(level, __FILE__, __LINE__, format, __VA_ARGS__) + +#define munit_log(level, msg) munit_logf(level, "%s", msg) + +MUNIT_NO_RETURN +MUNIT_PRINTF(3, 4) +void munit_errorf_ex(const char *filename, int line, const char *format, ...); + +#define munit_errorf(format, ...) \ + munit_errorf_ex(__FILE__, __LINE__, format, __VA_ARGS__) + +#define munit_error(msg) munit_errorf("%s", msg) + +#define munit_assert(expr) \ + do { \ + if (!MUNIT_LIKELY(expr)) { \ + munit_error("assertion failed: " #expr); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_true(expr) \ + do { \ + if (!MUNIT_LIKELY(expr)) { \ + munit_error("assertion failed: " #expr " is not true"); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_false(expr) \ + do { \ + if (!MUNIT_LIKELY(!(expr))) { \ + munit_error("assertion failed: " #expr " is not false"); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_type_full(prefix, suffix, T, fmt, a, op, b) \ + do { \ + T munit_tmp_a_ = (a); \ + T munit_tmp_b_ = (b); \ + if (!(munit_tmp_a_ op munit_tmp_b_)) { \ + munit_errorf("assertion failed: %s %s %s (" prefix "%" fmt suffix \ + " %s " prefix "%" fmt suffix ")", \ + #a, #op, #b, munit_tmp_a_, #op, munit_tmp_b_); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_type(T, fmt, a, op, b) \ + munit_assert_type_full("", "", T, fmt, a, op, b) + +#define munit_assert_char(a, op, b) \ + munit_assert_type_full("'\\x", "'", char, "02" MUNIT_CHAR_MODIFIER "x", a, \ + op, b) +#define munit_assert_uchar(a, op, b) \ + munit_assert_type_full("'\\x", "'", unsigned char, \ + "02" MUNIT_CHAR_MODIFIER "x", a, op, b) +#define munit_assert_short(a, op, b) \ + munit_assert_type(short, MUNIT_SHORT_MODIFIER "d", a, op, b) +#define munit_assert_ushort(a, op, b) \ + munit_assert_type(unsigned short, MUNIT_SHORT_MODIFIER "u", a, op, b) +#define munit_assert_int(a, op, b) munit_assert_type(int, "d", a, op, b) +#define munit_assert_uint(a, op, b) \ + munit_assert_type(unsigned int, "u", a, op, b) +#define munit_assert_long(a, op, b) munit_assert_type(long int, "ld", a, op, b) +#define munit_assert_ulong(a, op, b) \ + munit_assert_type(unsigned long int, "lu", a, op, b) +#define munit_assert_llong(a, op, b) \ + munit_assert_type(long long int, "lld", a, op, b) +#define munit_assert_ullong(a, op, b) \ + munit_assert_type(unsigned long long int, "llu", a, op, b) + +#define munit_assert_size(a, op, b) \ + munit_assert_type(size_t, MUNIT_SIZE_MODIFIER "u", a, op, b) +#define munit_assert_ssize(a, op, b) \ + munit_assert_type(ssize_t, MUNIT_SIZE_MODIFIER "d", a, op, b) + +#define munit_assert_float(a, op, b) munit_assert_type(float, "f", a, op, b) +#define munit_assert_double(a, op, b) munit_assert_type(double, "g", a, op, b) +#define munit_assert_ptr(a, op, b) \ + munit_assert_type(const void *, "p", a, op, b) + +#define munit_assert_int8(a, op, b) \ + munit_assert_type(munit_int8_t, PRIi8, a, op, b) +#define munit_assert_uint8(a, op, b) \ + munit_assert_type(munit_uint8_t, PRIu8, a, op, b) +#define munit_assert_int16(a, op, b) \ + munit_assert_type(munit_int16_t, PRIi16, a, op, b) +#define munit_assert_uint16(a, op, b) \ + munit_assert_type(munit_uint16_t, PRIu16, a, op, b) +#define munit_assert_int32(a, op, b) \ + munit_assert_type(munit_int32_t, PRIi32, a, op, b) +#define munit_assert_uint32(a, op, b) \ + munit_assert_type(munit_uint32_t, PRIu32, a, op, b) +#define munit_assert_int64(a, op, b) \ + munit_assert_type(munit_int64_t, PRIi64, a, op, b) +#define munit_assert_uint64(a, op, b) \ + munit_assert_type(munit_uint64_t, PRIu64, a, op, b) + +#define munit_assert_ptrdiff(a, op, b) \ + munit_assert_type(ptrdiff_t, "td", a, op, b) + +#define munit_assert_enum(T, a, op, b) munit_assert_type(T, "d", a, op, b) + +#define munit_assert_double_equal(a, b, precision) \ + do { \ + const double munit_tmp_a_ = (a); \ + const double munit_tmp_b_ = (b); \ + const double munit_tmp_diff_ = ((munit_tmp_a_ - munit_tmp_b_) < 0) \ + ? -(munit_tmp_a_ - munit_tmp_b_) \ + : (munit_tmp_a_ - munit_tmp_b_); \ + if (MUNIT_UNLIKELY(munit_tmp_diff_ > 1e-##precision)) { \ + munit_errorf("assertion failed: %s == %s (%0." #precision \ + "g == %0." #precision "g)", \ + #a, #b, munit_tmp_a_, munit_tmp_b_); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#include +#define munit_assert_string_equal(a, b) \ + do { \ + const char *munit_tmp_a_ = a; \ + const char *munit_tmp_b_ = b; \ + if (MUNIT_UNLIKELY(strcmp(munit_tmp_a_, munit_tmp_b_) != 0)) { \ + munit_hexdump_diff(stderr, munit_tmp_a_, strlen(munit_tmp_a_), \ + munit_tmp_b_, strlen(munit_tmp_b_)); \ + munit_errorf("assertion failed: string %s == %s (\"%s\" == \"%s\")", #a, \ + #b, munit_tmp_a_, munit_tmp_b_); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_string_not_equal(a, b) \ + do { \ + const char *munit_tmp_a_ = a; \ + const char *munit_tmp_b_ = b; \ + if (MUNIT_UNLIKELY(strcmp(munit_tmp_a_, munit_tmp_b_) == 0)) { \ + munit_errorf("assertion failed: string %s != %s (\"%s\" == \"%s\")", #a, \ + #b, munit_tmp_a_, munit_tmp_b_); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_memory_equal(size, a, b) \ + do { \ + const unsigned char *munit_tmp_a_ = (const unsigned char *)(a); \ + const unsigned char *munit_tmp_b_ = (const unsigned char *)(b); \ + const size_t munit_tmp_size_ = (size); \ + if (MUNIT_UNLIKELY(memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) != \ + 0) { \ + size_t munit_tmp_pos_; \ + for (munit_tmp_pos_ = 0; munit_tmp_pos_ < munit_tmp_size_; \ + munit_tmp_pos_++) { \ + if (munit_tmp_a_[munit_tmp_pos_] != munit_tmp_b_[munit_tmp_pos_]) { \ + munit_hexdump_diff(stderr, munit_tmp_a_, size, munit_tmp_b_, size); \ + munit_errorf("assertion failed: memory %s == %s, at offset " \ + "%" MUNIT_SIZE_MODIFIER "u", \ + #a, #b, munit_tmp_pos_); \ + break; \ + } \ + } \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_memn_equal(a, a_size, b, b_size) \ + do { \ + const unsigned char *munit_tmp_a_ = (const unsigned char *)(a); \ + const unsigned char *munit_tmp_b_ = (const unsigned char *)(b); \ + const size_t munit_tmp_a_size_ = (a_size); \ + const size_t munit_tmp_b_size_ = (b_size); \ + if (MUNIT_UNLIKELY(munit_tmp_a_size_ != munit_tmp_b_size_) || \ + MUNIT_UNLIKELY(munit_tmp_a_size_ && memcmp(munit_tmp_a_, munit_tmp_b_, \ + munit_tmp_a_size_)) != 0) { \ + munit_hexdump_diff(stderr, munit_tmp_a_, munit_tmp_a_size_, \ + munit_tmp_b_, munit_tmp_b_size_); \ + munit_errorf("assertion failed: memory %s == %s", #a, #b); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_memory_not_equal(size, a, b) \ + do { \ + const unsigned char *munit_tmp_a_ = (const unsigned char *)(a); \ + const unsigned char *munit_tmp_b_ = (const unsigned char *)(b); \ + const size_t munit_tmp_size_ = (size); \ + if (MUNIT_UNLIKELY(memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) == \ + 0) { \ + munit_errorf("assertion failed: memory %s != %s (%zu bytes)", #a, #b, \ + munit_tmp_size_); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#define munit_assert_ptr_equal(a, b) munit_assert_ptr(a, ==, b) +#define munit_assert_ptr_not_equal(a, b) munit_assert_ptr(a, !=, b) +#define munit_assert_null(ptr) munit_assert_ptr(ptr, ==, NULL) +#define munit_assert_not_null(ptr) munit_assert_ptr(ptr, !=, NULL) +#define munit_assert_ptr_null(ptr) munit_assert_ptr(ptr, ==, NULL) +#define munit_assert_ptr_not_null(ptr) munit_assert_ptr(ptr, !=, NULL) + +/*** Memory allocation ***/ + +void *munit_malloc_ex(const char *filename, int line, size_t size); + +#define munit_malloc(size) munit_malloc_ex(__FILE__, __LINE__, (size)) + +#define munit_new(type) ((type *)munit_malloc(sizeof(type))) + +#define munit_calloc(nmemb, size) munit_malloc((nmemb) * (size)) + +#define munit_newa(type, nmemb) ((type *)munit_calloc((nmemb), sizeof(type))) + +/*** Random number generation ***/ + +void munit_rand_seed(munit_uint32_t seed); +munit_uint32_t munit_rand_uint32(void); +int munit_rand_int_range(int min, int max); +double munit_rand_double(void); +void munit_rand_memory(size_t size, munit_uint8_t *buffer); + +/*** Tests and Suites ***/ + +typedef enum { + /* Test successful */ + MUNIT_OK, + /* Test failed */ + MUNIT_FAIL, + /* Test was skipped */ + MUNIT_SKIP, + /* Test failed due to circumstances not intended to be tested + * (things like network errors, invalid parameter value, failure to + * allocate memory in the test harness, etc.). */ + MUNIT_ERROR +} MunitResult; + +typedef struct { + char *name; + char **values; +} MunitParameterEnum; + +typedef struct { + char *name; + char *value; +} MunitParameter; + +const char *munit_parameters_get(const MunitParameter params[], + const char *key); + +typedef enum { + MUNIT_TEST_OPTION_NONE = 0, + MUNIT_TEST_OPTION_SINGLE_ITERATION = 1 << 0, + MUNIT_TEST_OPTION_TODO = 1 << 1 +} MunitTestOptions; + +typedef MunitResult (*MunitTestFunc)(const MunitParameter params[], + void *user_data_or_fixture); +typedef void *(*MunitTestSetup)(const MunitParameter params[], void *user_data); +typedef void (*MunitTestTearDown)(void *fixture); + +typedef struct { + const char *name; + MunitTestFunc test; + MunitTestSetup setup; + MunitTestTearDown tear_down; + MunitTestOptions options; + MunitParameterEnum *parameters; +} MunitTest; + +typedef enum { MUNIT_SUITE_OPTION_NONE = 0 } MunitSuiteOptions; + +typedef struct MunitSuite_ MunitSuite; + +struct MunitSuite_ { + const char *prefix; + const MunitTest *tests; + const MunitSuite *suites; + unsigned int iterations; + MunitSuiteOptions options; +}; + +int munit_suite_main(const MunitSuite *suite, void *user_data, int argc, + char *const *argv); + +/* Note: I'm not very happy with this API; it's likely to change if I + * figure out something better. Suggestions welcome. */ + +typedef struct MunitArgument_ MunitArgument; + +struct MunitArgument_ { + char *name; + munit_bool (*parse_argument)(const MunitSuite *suite, void *user_data, + int *arg, int argc, char *const *argv); + void (*write_help)(const MunitArgument *argument, void *user_data); +}; + +int munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc, + char *const *argv, const MunitArgument arguments[]); + +#if defined(MUNIT_ENABLE_ASSERT_ALIASES) + +# define assert_true(expr) munit_assert_true(expr) +# define assert_false(expr) munit_assert_false(expr) +# define assert_char(a, op, b) munit_assert_char(a, op, b) +# define assert_uchar(a, op, b) munit_assert_uchar(a, op, b) +# define assert_short(a, op, b) munit_assert_short(a, op, b) +# define assert_ushort(a, op, b) munit_assert_ushort(a, op, b) +# define assert_int(a, op, b) munit_assert_int(a, op, b) +# define assert_uint(a, op, b) munit_assert_uint(a, op, b) +# define assert_long(a, op, b) munit_assert_long(a, op, b) +# define assert_ulong(a, op, b) munit_assert_ulong(a, op, b) +# define assert_llong(a, op, b) munit_assert_llong(a, op, b) +# define assert_ullong(a, op, b) munit_assert_ullong(a, op, b) +# define assert_size(a, op, b) munit_assert_size(a, op, b) +# define assert_ssize(a, op, b) munit_assert_ssize(a, op, b) +# define assert_float(a, op, b) munit_assert_float(a, op, b) +# define assert_double(a, op, b) munit_assert_double(a, op, b) +# define assert_ptr(a, op, b) munit_assert_ptr(a, op, b) + +# define assert_int8(a, op, b) munit_assert_int8(a, op, b) +# define assert_uint8(a, op, b) munit_assert_uint8(a, op, b) +# define assert_int16(a, op, b) munit_assert_int16(a, op, b) +# define assert_uint16(a, op, b) munit_assert_uint16(a, op, b) +# define assert_int32(a, op, b) munit_assert_int32(a, op, b) +# define assert_uint32(a, op, b) munit_assert_uint32(a, op, b) +# define assert_int64(a, op, b) munit_assert_int64(a, op, b) +# define assert_uint64(a, op, b) munit_assert_uint64(a, op, b) + +# define assert_ptrdiff(a, op, b) munit_assert_ptrdiff(a, op, b) + +# define assert_enum(T, a, op, b) munit_assert_enum(T, a, op, b) + +# define assert_double_equal(a, b, precision) \ + munit_assert_double_equal(a, b, precision) +# define assert_string_equal(a, b) munit_assert_string_equal(a, b) +# define assert_string_not_equal(a, b) munit_assert_string_not_equal(a, b) +# define assert_memory_equal(size, a, b) munit_assert_memory_equal(size, a, b) +# define assert_memn_equal(a, a_size, b, b_size) \ + munit_assert_memn_equal(a, a_size, b, b_size) +# define assert_memory_not_equal(size, a, b) \ + munit_assert_memory_not_equal(size, a, b) +# define assert_ptr_equal(a, b) munit_assert_ptr_equal(a, b) +# define assert_ptr_not_equal(a, b) munit_assert_ptr_not_equal(a, b) +# define assert_ptr_null(ptr) munit_assert_null_equal(ptr) +# define assert_ptr_not_null(ptr) munit_assert_not_null(ptr) + +# define assert_null(ptr) munit_assert_null(ptr) +# define assert_not_null(ptr) munit_assert_not_null(ptr) + +#endif /* defined(MUNIT_ENABLE_ASSERT_ALIASES) */ + +#define munit_void_test_decl(func) \ + void func(void); \ + \ + static inline MunitResult wrap_##func(const MunitParameter params[], \ + void *fixture) { \ + (void)params; \ + (void)fixture; \ + \ + func(); \ + return MUNIT_OK; \ + } + +#define munit_void_test(func) \ + { "/" #func, wrap_##func, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } + +#define munit_test_end() \ + { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } + +int munit_hexdump(FILE *fp, const void *data, size_t datalen); + +int munit_hexdump_diff(FILE *fp, const void *a, size_t alen, const void *b, + size_t blen); + +#if defined(__cplusplus) +} +#endif + +#endif /* !defined(MUNIT_H) */ + +#if defined(MUNIT_ENABLE_ASSERT_ALIASES) +#if defined(assert) +# undef assert +#endif +#define assert(expr) munit_assert(expr) +#endif diff --git a/yass/third_party/nghttp2/tests/munit/munitxx.h b/yass/third_party/nghttp2/tests/munit/munitxx.h new file mode 100644 index 0000000000..5e509214f2 --- /dev/null +++ b/yass/third_party/nghttp2/tests/munit/munitxx.h @@ -0,0 +1,94 @@ +/* µnit Testing Framework + * Copyright (c) 2013-2017 Evan Nemerson + * Copyright (c) 2023 munit contributors + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef MUNITXX_H +#define MUNITXX_H + +#include + +#include +#include +#if __cplusplus >= 201703L +# include +#endif // __cplusplus >= 201703L + +#define munit_assert_stdstring_equal(a, b) \ + do { \ + const std::string munit_tmp_a_ = a; \ + const std::string munit_tmp_b_ = b; \ + if (MUNIT_UNLIKELY(a != b)) { \ + munit_hexdump_diff(stderr, munit_tmp_a_.c_str(), munit_tmp_a_.size(), \ + munit_tmp_b_.c_str(), munit_tmp_b_.size()); \ + munit_errorf("assertion failed: string %s == %s (\"%s\" == \"%s\")", #a, \ + #b, munit_tmp_a_.c_str(), munit_tmp_b_.c_str()); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#if __cplusplus >= 201703L +# define munit_assert_stdsv_equal(a, b) \ + do { \ + const std::string_view munit_tmp_a_ = a; \ + const std::string_view munit_tmp_b_ = b; \ + if (MUNIT_UNLIKELY(a != b)) { \ + munit_hexdump_diff(stderr, munit_tmp_a_.data(), munit_tmp_a_.size(), \ + munit_tmp_b_.data(), munit_tmp_b_.size()); \ + munit_errorf( \ + "assertion failed: string %s == %s (\"%.*s\" == \"%.*s\")", #a, \ + #b, (int)munit_tmp_a_.size(), munit_tmp_a_.data(), \ + (int)munit_tmp_b_.size(), munit_tmp_b_.data()); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ +#endif // __cplusplus >= 201703L + +#define munit_assert_enum_class(a, op, b) \ + do { \ + auto munit_tmp_a_ = (a); \ + auto munit_tmp_b_ = (b); \ + if (!(munit_tmp_a_ op munit_tmp_b_)) { \ + auto munit_tmp_a_str_ = std::to_string( \ + static_cast>( \ + munit_tmp_a_)); \ + auto munit_tmp_b_str_ = std::to_string( \ + static_cast>( \ + munit_tmp_b_)); \ + munit_errorf("assertion failed: %s %s %s (%s %s %s)", #a, #op, #b, \ + munit_tmp_a_str_.c_str(), #op, munit_tmp_b_str_.c_str()); \ + } \ + MUNIT_PUSH_DISABLE_MSVC_C4127_ \ + } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ + +#if defined(MUNIT_ENABLE_ASSERT_ALIASES) + +# define assert_stdstring_equal(a, b) munit_assert_stdstring_equal(a, b) +# if __cplusplus >= 201703L +# define assert_stdsv_equal(a, b) munit_assert_stdsv_equal(a, b) +# endif // __cplusplus >= 201703L +# define assert_enum_class(a, op, b) munit_assert_enum_class(a, op, b) + +#endif /* defined(MUNIT_ENABLE_ASSERT_ALIASES) */ + +#endif // MUNITXX_H diff --git a/yass/third_party/nghttp2/tests/nghttp2_npn_test.c b/yass/third_party/nghttp2/tests/nghttp2_alpn_test.c similarity index 54% rename from yass/third_party/nghttp2/tests/nghttp2_npn_test.c rename to yass/third_party/nghttp2/tests/nghttp2_alpn_test.c index 99cb751a48..805a23e440 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_npn_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_alpn_test.c @@ -22,22 +22,41 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "nghttp2_npn_test.h" +#include "nghttp2_alpn_test.h" #include #include -#include +#include "munit.h" + #include +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_alpn), + munit_test_end(), +}; + +const MunitSuite alpn_suite = { + "/alpn", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + static void http2(void) { const unsigned char p[] = {8, 'h', 't', 't', 'p', '/', '1', '.', '1', 2, 'h', '2', 6, 's', 'p', 'd', 'y', '/', '3'}; unsigned char outlen; - unsigned char *out; - CU_ASSERT(1 == nghttp2_select_next_protocol(&out, &outlen, p, sizeof(p))); - CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen); - CU_ASSERT(memcmp(NGHTTP2_PROTO_VERSION_ID, out, outlen) == 0); + const unsigned char *out; + assert_int(1, ==, + nghttp2_select_next_protocol((unsigned char **)&out, &outlen, p, + sizeof(p))); + assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen); + assert_memory_equal(outlen, NGHTTP2_PROTO_VERSION_ID, out); + + outlen = 0; + out = NULL; + + assert_int(1, ==, nghttp2_select_alpn(&out, &outlen, p, sizeof(p))); + assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen); + assert_memory_equal(outlen, NGHTTP2_PROTO_VERSION_ID, out); } static void http11(void) { @@ -46,11 +65,19 @@ static void http11(void) { '2', '.', '1', 8, 'h', 't', 't', 'p', '/', '1', '.', '1', }; unsigned char outlen; - unsigned char *out; - CU_ASSERT(0 == - nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy))); - CU_ASSERT(8 == outlen); - CU_ASSERT(memcmp("http/1.1", out, outlen) == 0); + const unsigned char *out; + assert_int(0, ==, + nghttp2_select_next_protocol((unsigned char **)&out, &outlen, spdy, + sizeof(spdy))); + assert_uchar(8, ==, outlen); + assert_memory_equal(outlen, "http/1.1", out); + + outlen = 0; + out = NULL; + + assert_int(0, ==, nghttp2_select_alpn(&out, &outlen, spdy, sizeof(spdy))); + assert_uchar(8, ==, outlen); + assert_memory_equal(outlen, "http/1.1", out); } static void no_overlap(void) { @@ -59,14 +86,22 @@ static void no_overlap(void) { '2', '.', '1', 8, 'h', 't', 't', 'p', '/', '1', '.', '0', }; unsigned char outlen = 0; - unsigned char *out = NULL; - CU_ASSERT(-1 == - nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy))); - CU_ASSERT(0 == outlen); - CU_ASSERT(NULL == out); + const unsigned char *out = NULL; + assert_int(-1, ==, + nghttp2_select_next_protocol((unsigned char **)&out, &outlen, spdy, + sizeof(spdy))); + assert_uchar(0, ==, outlen); + assert_null(out); + + outlen = 0; + out = NULL; + + assert_int(-1, ==, nghttp2_select_alpn(&out, &outlen, spdy, sizeof(spdy))); + assert_uchar(0, ==, outlen); + assert_null(out); } -void test_nghttp2_npn(void) { +void test_nghttp2_alpn(void) { http2(); http11(); no_overlap(); diff --git a/yass/third_party/nghttp2/tests/nghttp2_npn_test.h b/yass/third_party/nghttp2/tests/nghttp2_alpn_test.h similarity index 84% rename from yass/third_party/nghttp2/tests/nghttp2_npn_test.h rename to yass/third_party/nghttp2/tests/nghttp2_alpn_test.h index f1c97631f1..a3757010de 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_npn_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_alpn_test.h @@ -22,13 +22,19 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef NGHTTP2_NPN_TEST_H -#define NGHTTP2_NPN_TEST_H +#ifndef NGHTTP2_ALPN_TEST_H +#define NGHTTP2_ALPN_TEST_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_npn(void); +#define MUNIT_ENABLE_ASSERT_ALIASES -#endif /* NGHTTP2_NPN_TEST_H */ +#include "munit.h" + +extern const MunitSuite alpn_suite; + +munit_void_test_decl(test_nghttp2_alpn); + +#endif /* NGHTTP2_ALPN_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_assertion.h b/yass/third_party/nghttp2/tests/nghttp2_assertion.h new file mode 100644 index 0000000000..28d6929140 --- /dev/null +++ b/yass/third_party/nghttp2/tests/nghttp2_assertion.h @@ -0,0 +1,56 @@ +/* + * nghttp2 - HTTP/2 C Library + * + * Copyright (c) 2024 nghttp2 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef NGHTTP2_ASSERTION_H +#define NGHTTP2_ASSERTION_H + +#ifdef HAVE_CONFIG_H +# include +#endif /* HAVE_CONFIG_H */ + +#include "munit.h" + +#include "nghttp2_frame.h" + +#define assert_nv_equal(A, B, len, mem) \ + do { \ + size_t alloclen = sizeof(nghttp2_nv) * (len); \ + const nghttp2_nv *sa = (A), *sb = (B); \ + nghttp2_nv *a = (mem)->malloc(alloclen, NULL); \ + nghttp2_nv *b = (mem)->malloc(alloclen, NULL); \ + size_t i_; \ + memcpy(a, sa, alloclen); \ + memcpy(b, sb, alloclen); \ + nghttp2_nv_array_sort(a, (len)); \ + nghttp2_nv_array_sort(b, (len)); \ + for (i_ = 0; i_ < (size_t)(len); ++i_) { \ + assert_memn_equal(a[i_].name, a[i_].namelen, b[i_].name, b[i_].namelen); \ + assert_memn_equal(a[i_].value, a[i_].valuelen, b[i_].value, \ + b[i_].valuelen); \ + } \ + (mem)->free(b, NULL); \ + (mem)->free(a, NULL); \ + } while (0); + +#endif /* NGHTTP2_ASSERTION_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_buf_test.c b/yass/third_party/nghttp2/tests/nghttp2_buf_test.c index e3e8a14a5b..43d53f649b 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_buf_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_buf_test.c @@ -26,11 +26,28 @@ #include -#include +#include "munit.h" #include "nghttp2_buf.h" #include "nghttp2_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_bufs_add), + munit_void_test(test_nghttp2_bufs_add_stack_buffer_overflow_bug), + munit_void_test(test_nghttp2_bufs_addb), + munit_void_test(test_nghttp2_bufs_orb), + munit_void_test(test_nghttp2_bufs_remove), + munit_void_test(test_nghttp2_bufs_reset), + munit_void_test(test_nghttp2_bufs_advance), + munit_void_test(test_nghttp2_bufs_next_present), + munit_void_test(test_nghttp2_bufs_realloc), + munit_test_end(), +}; + +const MunitSuite buf_suite = { + "/buf", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_bufs_add(void) { int rv; nghttp2_bufs bufs; @@ -40,27 +57,27 @@ void test_nghttp2_bufs_add(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 1000, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(bufs.cur->buf.pos == bufs.cur->buf.last); + assert_ptr_equal(bufs.cur->buf.pos, bufs.cur->buf.last); rv = nghttp2_bufs_add(&bufs, data, 493); - CU_ASSERT(0 == rv); - CU_ASSERT(493 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(493 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(507 == nghttp2_bufs_cur_avail(&bufs)); + assert_int(0, ==, rv); + assert_size(493, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(493, ==, nghttp2_bufs_len(&bufs)); + assert_size(507, ==, nghttp2_bufs_cur_avail(&bufs)); rv = nghttp2_bufs_add(&bufs, data, 507); - CU_ASSERT(0 == rv); - CU_ASSERT(1000 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1000 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(bufs.cur == bufs.head); + assert_int(0, ==, rv); + assert_size(1000, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1000, ==, nghttp2_bufs_len(&bufs)); + assert_ptr_equal(bufs.cur, bufs.head); rv = nghttp2_bufs_add(&bufs, data, 1); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(bufs.cur == bufs.head->next); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1001, ==, nghttp2_bufs_len(&bufs)); + assert_ptr_equal(bufs.cur, bufs.head->next); nghttp2_bufs_free(&bufs); } @@ -75,12 +92,12 @@ void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 100, 200, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_add(&bufs, data, sizeof(data)); - CU_ASSERT(0 == rv); - CU_ASSERT(sizeof(data) == nghttp2_bufs_len(&bufs)); + assert_int(0, ==, rv); + assert_size(sizeof(data), ==, nghttp2_bufs_len(&bufs)); nghttp2_bufs_free(&bufs); } @@ -88,65 +105,65 @@ void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void) { void test_nghttp2_bufs_addb(void) { int rv; nghttp2_bufs bufs; - ssize_t i; + size_t i; nghttp2_mem *mem; mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 1000, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_addb(&bufs, 14); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(14 == *bufs.cur->buf.pos); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(14, ==, *bufs.cur->buf.pos); for (i = 0; i < 999; ++i) { rv = nghttp2_bufs_addb(&bufs, 254); - CU_ASSERT(0 == rv); - CU_ASSERT((size_t)(i + 2) == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT((size_t)(i + 2) == nghttp2_bufs_len(&bufs)); - CU_ASSERT(254 == *(bufs.cur->buf.last - 1)); - CU_ASSERT(bufs.cur == bufs.head); + assert_int(0, ==, rv); + assert_size(i + 2, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(i + 2, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(254, ==, *(bufs.cur->buf.last - 1)); + assert_ptr_equal(bufs.cur, bufs.head); } rv = nghttp2_bufs_addb(&bufs, 253); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(253 == *(bufs.cur->buf.last - 1)); - CU_ASSERT(bufs.cur == bufs.head->next); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1001, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(253, ==, *(bufs.cur->buf.last - 1)); + assert_ptr_equal(bufs.cur, bufs.head->next); rv = nghttp2_bufs_addb_hold(&bufs, 15); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(15 == *(bufs.cur->buf.last)); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1001, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(15, ==, *(bufs.cur->buf.last)); /* test fast version */ nghttp2_bufs_fast_addb(&bufs, 240); - CU_ASSERT(2 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1002 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(240 == *(bufs.cur->buf.last - 1)); + assert_size(2, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1002, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(240, ==, *(bufs.cur->buf.last - 1)); nghttp2_bufs_fast_addb_hold(&bufs, 113); - CU_ASSERT(2 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1002 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(113 == *(bufs.cur->buf.last)); + assert_size(2, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1002, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(113, ==, *(bufs.cur->buf.last)); /* addb_hold when last == end */ bufs.cur->buf.last = bufs.cur->buf.end; rv = nghttp2_bufs_addb_hold(&bufs, 19); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(2000 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(19 == *(bufs.cur->buf.last)); + assert_int(0, ==, rv); + assert_size(0, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(2000, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(19, ==, *(bufs.cur->buf.last)); nghttp2_bufs_free(&bufs); } @@ -159,28 +176,28 @@ void test_nghttp2_bufs_orb(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 1000, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); *(bufs.cur->buf.last) = 0; rv = nghttp2_bufs_orb_hold(&bufs, 15); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(0 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(15 == *(bufs.cur->buf.last)); + assert_int(0, ==, rv); + assert_size(0, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(0, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(15, ==, *(bufs.cur->buf.last)); rv = nghttp2_bufs_orb(&bufs, 240); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(255 == *(bufs.cur->buf.last - 1)); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(255, ==, *(bufs.cur->buf.last - 1)); *(bufs.cur->buf.last) = 0; nghttp2_bufs_fast_orb_hold(&bufs, 240); - CU_ASSERT(240 == *(bufs.cur->buf.last)); + assert_uint8(240, ==, *(bufs.cur->buf.last)); nghttp2_bufs_fast_orb(&bufs, 15); - CU_ASSERT(255 == *(bufs.cur->buf.last - 1)); + assert_uint8(255, ==, *(bufs.cur->buf.last - 1)); nghttp2_bufs_free(&bufs); } @@ -191,36 +208,36 @@ void test_nghttp2_bufs_remove(void) { nghttp2_buf_chain *chain; int i; uint8_t *out; - ssize_t outlen; + nghttp2_ssize outlen; nghttp2_mem *mem; mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 1000, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_buf_shift_right(&bufs.cur->buf, 10); rv = nghttp2_bufs_add(&bufs, "hello ", 6); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); for (i = 0; i < 2; ++i) { chain = bufs.cur; rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(chain->next == bufs.cur); + assert_ptr_equal(chain->next, bufs.cur); } rv = nghttp2_bufs_add(&bufs, "world", 5); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); outlen = nghttp2_bufs_remove(&bufs, &out); - CU_ASSERT(11 == outlen); + assert_ptrdiff(11, ==, outlen); - CU_ASSERT(0 == memcmp("hello world", out, (size_t)outlen)); - CU_ASSERT(11 == nghttp2_bufs_len(&bufs)); + assert_memory_equal((size_t)outlen, "hello world", out); + assert_size(11, ==, nghttp2_bufs_len(&bufs)); mem->free(out, NULL); nghttp2_bufs_free(&bufs); @@ -236,30 +253,30 @@ void test_nghttp2_bufs_reset(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init3(&bufs, 250, 3, 1, offset, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_add(&bufs, "foo", 3); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_add(&bufs, "bar", 3); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(6 == nghttp2_bufs_len(&bufs)); + assert_size(6, ==, nghttp2_bufs_len(&bufs)); nghttp2_bufs_reset(&bufs); - CU_ASSERT(0 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(bufs.cur == bufs.head); + assert_size(0, ==, nghttp2_bufs_len(&bufs)); + assert_ptr_equal(bufs.cur, bufs.head); for (ci = bufs.head; ci; ci = ci->next) { - CU_ASSERT((ssize_t)offset == ci->buf.pos - ci->buf.begin); - CU_ASSERT(ci->buf.pos == ci->buf.last); + assert_ptrdiff((ptrdiff_t)offset, ==, ci->buf.pos - ci->buf.begin); + assert_ptr_equal(ci->buf.pos, ci->buf.last); } - CU_ASSERT(bufs.head->next == NULL); + assert_null(bufs.head->next); nghttp2_bufs_free(&bufs); } @@ -273,15 +290,15 @@ void test_nghttp2_bufs_advance(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 250, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); for (i = 0; i < 2; ++i) { rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); } rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(NGHTTP2_ERR_BUFFER_ERROR == rv); + assert_int(NGHTTP2_ERR_BUFFER_ERROR, ==, rv); nghttp2_bufs_free(&bufs); } @@ -294,25 +311,25 @@ void test_nghttp2_bufs_next_present(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 250, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(0 == nghttp2_bufs_next_present(&bufs)); + assert_false(nghttp2_bufs_next_present(&bufs)); rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_bufs_rewind(&bufs); - CU_ASSERT(0 == nghttp2_bufs_next_present(&bufs)); + assert_false(nghttp2_bufs_next_present(&bufs)); bufs.cur = bufs.head->next; rv = nghttp2_bufs_addb(&bufs, 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_bufs_rewind(&bufs); - CU_ASSERT(0 != nghttp2_bufs_next_present(&bufs)); + assert_true(nghttp2_bufs_next_present(&bufs)); nghttp2_bufs_free(&bufs); } @@ -325,20 +342,20 @@ void test_nghttp2_bufs_realloc(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init3(&bufs, 266, 3, 1, 10, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); /* Create new buffer to see that these buffers are deallocated on realloc */ rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_realloc(&bufs, 522); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(512 == nghttp2_bufs_cur_avail(&bufs)); + assert_size(512, ==, nghttp2_bufs_cur_avail(&bufs)); rv = nghttp2_bufs_realloc(&bufs, 9); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); nghttp2_bufs_free(&bufs); } diff --git a/yass/third_party/nghttp2/tests/nghttp2_buf_test.h b/yass/third_party/nghttp2/tests/nghttp2_buf_test.h index 714b89fde6..0bbab89a58 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_buf_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_buf_test.h @@ -29,14 +29,20 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_bufs_add(void); -void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void); -void test_nghttp2_bufs_addb(void); -void test_nghttp2_bufs_orb(void); -void test_nghttp2_bufs_remove(void); -void test_nghttp2_bufs_reset(void); -void test_nghttp2_bufs_advance(void); -void test_nghttp2_bufs_next_present(void); -void test_nghttp2_bufs_realloc(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite buf_suite; + +munit_void_test_decl(test_nghttp2_bufs_add); +munit_void_test_decl(test_nghttp2_bufs_add_stack_buffer_overflow_bug); +munit_void_test_decl(test_nghttp2_bufs_addb); +munit_void_test_decl(test_nghttp2_bufs_orb); +munit_void_test_decl(test_nghttp2_bufs_remove); +munit_void_test_decl(test_nghttp2_bufs_reset); +munit_void_test_decl(test_nghttp2_bufs_advance); +munit_void_test_decl(test_nghttp2_bufs_next_present); +munit_void_test_decl(test_nghttp2_bufs_realloc); #endif /* NGHTTP2_BUF_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_extpri_test.c b/yass/third_party/nghttp2/tests/nghttp2_extpri_test.c index 0ef59b7428..a589b9377a 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_extpri_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_extpri_test.c @@ -27,26 +27,35 @@ #include -#include +#include "munit.h" #include "nghttp2_extpri.h" #include "nghttp2_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_extpri_to_uint8), + munit_test_end(), +}; + +const MunitSuite extpri_suite = { + "/extpri", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_extpri_to_uint8(void) { { nghttp2_extpri pri = {1, 0}; - CU_ASSERT(1 == nghttp2_extpri_to_uint8(&pri)); + assert_uint8(1, ==, nghttp2_extpri_to_uint8(&pri)); } { nghttp2_extpri pri = {1, 1}; - CU_ASSERT((0x80 | 1) == nghttp2_extpri_to_uint8(&pri)); + assert_uint8((0x80 | 1), ==, nghttp2_extpri_to_uint8(&pri)); } { nghttp2_extpri pri = {7, 1}; - CU_ASSERT((0x80 | 7) == nghttp2_extpri_to_uint8(&pri)); + assert_uint8((0x80 | 7), ==, nghttp2_extpri_to_uint8(&pri)); } { nghttp2_extpri pri = {7, 0}; - CU_ASSERT(7 == nghttp2_extpri_to_uint8(&pri)); + assert_uint8(7, ==, nghttp2_extpri_to_uint8(&pri)); } } diff --git a/yass/third_party/nghttp2/tests/nghttp2_extpri_test.h b/yass/third_party/nghttp2/tests/nghttp2_extpri_test.h index a8a93b92d9..87358820d0 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_extpri_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_extpri_test.h @@ -30,6 +30,12 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_extpri_to_uint8(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite extpri_suite; + +munit_void_test_decl(test_nghttp2_extpri_to_uint8); #endif /* NGHTTP2_EXTPRI_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_frame_test.c b/yass/third_party/nghttp2/tests/nghttp2_frame_test.c index 7ce98dd045..474f15412c 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_frame_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_frame_test.c @@ -27,13 +27,35 @@ #include #include -#include +#include "munit.h" #include "nghttp2_frame.h" #include "nghttp2_helper.h" #include "nghttp2_test_helper.h" #include "nghttp2_priority_spec.h" +static MunitTest tests[] = { + munit_void_test(test_nghttp2_frame_pack_headers), + munit_void_test(test_nghttp2_frame_pack_headers_frame_too_large), + munit_void_test(test_nghttp2_frame_pack_priority), + munit_void_test(test_nghttp2_frame_pack_rst_stream), + munit_void_test(test_nghttp2_frame_pack_settings), + munit_void_test(test_nghttp2_frame_pack_push_promise), + munit_void_test(test_nghttp2_frame_pack_ping), + munit_void_test(test_nghttp2_frame_pack_goaway), + munit_void_test(test_nghttp2_frame_pack_window_update), + munit_void_test(test_nghttp2_frame_pack_altsvc), + munit_void_test(test_nghttp2_frame_pack_origin), + munit_void_test(test_nghttp2_frame_pack_priority_update), + munit_void_test(test_nghttp2_nv_array_copy), + munit_void_test(test_nghttp2_iv_check), + munit_test_end(), +}; + +const MunitSuite frame_suite = { + "/frame", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + static nghttp2_nv make_nv(const char *name, const char *value) { nghttp2_nv nv; nv.name = (uint8_t *)name; @@ -61,11 +83,11 @@ static nghttp2_nv *headers(nghttp2_mem *mem) { static void check_frame_header(size_t length, uint8_t type, uint8_t flags, int32_t stream_id, nghttp2_frame_hd *hd) { - CU_ASSERT(length == hd->length); - CU_ASSERT(type == hd->type); - CU_ASSERT(flags == hd->flags); - CU_ASSERT(stream_id == hd->stream_id); - CU_ASSERT(0 == hd->reserved); + assert_size(length, ==, hd->length); + assert_uint8(type, ==, hd->type); + assert_uint8(flags, ==, hd->flags); + assert_int32(stream_id, ==, hd->stream_id); + assert_uint8(0, ==, hd->reserved); } void test_nghttp2_frame_pack_headers(void) { @@ -100,24 +122,24 @@ void test_nghttp2_frame_pack_headers(void) { nghttp2_bufs_rewind(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN, NGHTTP2_HEADERS, NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS, 1000000007, &oframe.hd); /* We did not include PRIORITY flag */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == oframe.pri_spec.weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, oframe.pri_spec.weight); hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN; - CU_ASSERT((ssize_t)hdblocklen == - inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem)); + assert_ptrdiff((nghttp2_ssize)hdblocklen, ==, + inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem)); - CU_ASSERT(7 == out.nvlen); - CU_ASSERT(nvnameeq("method", &out.nva[0])); - CU_ASSERT(nvvalueeq("GET", &out.nva[0])); + assert_size(7, ==, out.nvlen); + assert_true(nvnameeq("method", &out.nva[0])); + assert_true(nvvalueeq("GET", &out.nva[0])); nghttp2_frame_headers_free(&oframe, mem); nva_out_reset(&out, mem); @@ -130,9 +152,9 @@ void test_nghttp2_frame_pack_headers(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN, NGHTTP2_HEADERS, @@ -140,20 +162,20 @@ void test_nghttp2_frame_pack_headers(void) { NGHTTP2_FLAG_PRIORITY, 1000000007, &oframe.hd); - CU_ASSERT(1000000009 == oframe.pri_spec.stream_id); - CU_ASSERT(12 == oframe.pri_spec.weight); - CU_ASSERT(1 == oframe.pri_spec.exclusive); + assert_int32(1000000009, ==, oframe.pri_spec.stream_id); + assert_int32(12, ==, oframe.pri_spec.weight); + assert_true(oframe.pri_spec.exclusive); hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN - nghttp2_frame_priority_len(oframe.hd.flags); - CU_ASSERT((ssize_t)hdblocklen == - inflate_hd(&inflater, &out, &bufs, - NGHTTP2_FRAME_HDLEN + - nghttp2_frame_priority_len(oframe.hd.flags), - mem)); + assert_ptrdiff((nghttp2_ssize)hdblocklen, ==, + inflate_hd(&inflater, &out, &bufs, + NGHTTP2_FRAME_HDLEN + + nghttp2_frame_priority_len(oframe.hd.flags), + mem)); nghttp2_nv_array_sort(out.nva, out.nvlen); - CU_ASSERT(nvnameeq("method", &out.nva[0])); + assert_true(nvnameeq("method", &out.nva[0])); nghttp2_frame_headers_free(&oframe, mem); nva_out_reset(&out, mem); @@ -196,7 +218,7 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void) { &frame, NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS, 1000000007, NGHTTP2_HCAT_REQUEST, NULL, nva, big_hdslen); rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == rv); + assert_int(NGHTTP2_ERR_HEADER_COMP, ==, rv); nghttp2_frame_headers_free(&frame, mem); nghttp2_bufs_free(&bufs); @@ -219,14 +241,14 @@ void test_nghttp2_frame_pack_priority(void) { nghttp2_frame_priority_init(&frame, 1000000007, &pri_spec); nghttp2_frame_pack_priority(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 5 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + 5, ==, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(5, NGHTTP2_PRIORITY, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(1000000009 == oframe.pri_spec.stream_id); - CU_ASSERT(12 == oframe.pri_spec.weight); - CU_ASSERT(1 == oframe.pri_spec.exclusive); + assert_int32(1000000009, ==, oframe.pri_spec.stream_id); + assert_int32(12, ==, oframe.pri_spec.weight); + assert_true(oframe.pri_spec.exclusive); nghttp2_frame_priority_free(&oframe); nghttp2_bufs_reset(&bufs); @@ -244,11 +266,11 @@ void test_nghttp2_frame_pack_rst_stream(void) { nghttp2_frame_rst_stream_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR); nghttp2_frame_pack_rst_stream(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + 4, ==, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, oframe.error_code); nghttp2_frame_rst_stream_free(&oframe); nghttp2_bufs_reset(&bufs); @@ -257,12 +279,12 @@ void test_nghttp2_frame_pack_rst_stream(void) { frame.error_code = 1000000009; nghttp2_frame_pack_rst_stream(&bufs, &frame); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(1000000009 == oframe.error_code); + assert_uint32(1000000009, ==, oframe.error_code); nghttp2_frame_rst_stream_free(&oframe); @@ -288,17 +310,17 @@ void test_nghttp2_frame_pack_settings(void) { nghttp2_frame_iv_copy(iv, 3, mem), 3); rv = nghttp2_frame_pack_settings(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH == - nghttp2_bufs_len(&bufs)); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + 3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH, ==, + nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH, NGHTTP2_SETTINGS, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(3 == oframe.niv); + assert_size(3, ==, oframe.niv); for (i = 0; i < 3; ++i) { - CU_ASSERT(iv[i].settings_id == oframe.iv[i].settings_id); - CU_ASSERT(iv[i].value == oframe.iv[i].value); + assert_int32(iv[i].settings_id, ==, oframe.iv[i].settings_id); + assert_uint32(iv[i].value, ==, oframe.iv[i].value); } nghttp2_bufs_free(&bufs); @@ -331,22 +353,23 @@ void test_nghttp2_frame_pack_push_promise(void) { (1U << 31) - 1, nva, nvlen); rv = nghttp2_frame_pack_push_promise(&bufs, &frame, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN, NGHTTP2_PUSH_PROMISE, NGHTTP2_FLAG_END_HEADERS, 1000000007, &oframe.hd); - CU_ASSERT((1U << 31) - 1 == oframe.promised_stream_id); + assert_int32((1U << 31) - 1, ==, oframe.promised_stream_id); hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN - 4; - CU_ASSERT((ssize_t)hdblocklen == - inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN + 4, mem)); + assert_ptrdiff( + (nghttp2_ssize)hdblocklen, ==, + inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN + 4, mem)); - CU_ASSERT(7 == out.nvlen); - CU_ASSERT(nvnameeq("method", &out.nva[0])); - CU_ASSERT(nvvalueeq("GET", &out.nva[0])); + assert_size(7, ==, out.nvlen); + assert_true(nvnameeq("method", &out.nva[0])); + assert_true(nvvalueeq("GET", &out.nva[0])); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); @@ -366,11 +389,10 @@ void test_nghttp2_frame_pack_ping(void) { nghttp2_frame_ping_init(&frame, NGHTTP2_FLAG_ACK, opaque_data); nghttp2_frame_pack_ping(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 8 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + 8, ==, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(8, NGHTTP2_PING, NGHTTP2_FLAG_ACK, 0, &oframe.hd); - CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, sizeof(opaque_data) - 1) == - 0); + assert_memory_equal(sizeof(opaque_data) - 1, opaque_data, oframe.opaque_data); nghttp2_bufs_free(&bufs); nghttp2_frame_ping_free(&oframe); @@ -394,16 +416,16 @@ void test_nghttp2_frame_pack_goaway(void) { opaque_data, opaque_data_len); rv = nghttp2_frame_pack_goaway(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 8 + opaque_data_len == - nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + 8 + opaque_data_len, ==, + nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(1000000007 == oframe.last_stream_id); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code); + assert_int32(1000000007, ==, oframe.last_stream_id); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, oframe.error_code); - CU_ASSERT(opaque_data_len == oframe.opaque_data_len); - CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, opaque_data_len) == 0); + assert_size(opaque_data_len, ==, oframe.opaque_data_len); + assert_memory_equal(opaque_data_len, opaque_data, oframe.opaque_data); nghttp2_frame_goaway_free(&oframe, mem); nghttp2_bufs_reset(&bufs); @@ -413,10 +435,10 @@ void test_nghttp2_frame_pack_goaway(void) { rv = nghttp2_frame_pack_goaway(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(1000000009 == oframe.error_code); + assert_uint32(1000000009, ==, oframe.error_code); nghttp2_frame_goaway_free(&oframe, mem); @@ -434,11 +456,11 @@ void test_nghttp2_frame_pack_window_update(void) { nghttp2_frame_window_update_init(&frame, NGHTTP2_FLAG_NONE, 1000000007, 4096); nghttp2_frame_pack_window_update(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + 4, ==, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(4, NGHTTP2_WINDOW_UPDATE, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(4096 == oframe.window_size_increment); + assert_int32(4096, ==, oframe.window_size_increment); nghttp2_bufs_free(&bufs); nghttp2_frame_window_update_free(&oframe); @@ -478,20 +500,20 @@ void test_nghttp2_frame_pack_altsvc(void) { nghttp2_frame_pack_altsvc(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + payloadlen == nghttp2_bufs_len(&bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + payloadlen, ==, nghttp2_bufs_len(&bufs)); rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); check_frame_header(payloadlen, NGHTTP2_ALTSVC, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(sizeof(origin) - 1 == oaltsvc.origin_len); - CU_ASSERT(0 == memcmp(origin, oaltsvc.origin, sizeof(origin) - 1)); - CU_ASSERT(sizeof(field_value) - 1 == oaltsvc.field_value_len); - CU_ASSERT(0 == - memcmp(field_value, oaltsvc.field_value, sizeof(field_value) - 1)); + assert_size(sizeof(origin) - 1, ==, oaltsvc.origin_len); + assert_memory_equal(sizeof(origin) - 1, origin, oaltsvc.origin); + assert_size(sizeof(field_value) - 1, ==, oaltsvc.field_value_len); + assert_memory_equal(sizeof(field_value) - 1, field_value, + oaltsvc.field_value); nghttp2_frame_altsvc_free(&oframe, mem); nghttp2_frame_altsvc_free(&frame, mem); @@ -536,21 +558,21 @@ void test_nghttp2_frame_pack_origin(void) { rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + payloadlen == nghttp2_bufs_len(&bufs)); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + payloadlen, ==, nghttp2_bufs_len(&bufs)); rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); check_frame_header(payloadlen, NGHTTP2_ORIGIN, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(2 == oorigin.nov); - CU_ASSERT(sizeof(example) - 1 == oorigin.ov[0].origin_len); - CU_ASSERT(0 == memcmp(example, oorigin.ov[0].origin, sizeof(example) - 1)); - CU_ASSERT(sizeof(nghttp2) - 1 == oorigin.ov[1].origin_len); - CU_ASSERT(0 == memcmp(nghttp2, oorigin.ov[1].origin, sizeof(nghttp2) - 1)); + assert_size(2, ==, oorigin.nov); + assert_size(sizeof(example) - 1, ==, oorigin.ov[0].origin_len); + assert_memory_equal(sizeof(example) - 1, example, oorigin.ov[0].origin); + assert_size(sizeof(nghttp2) - 1, ==, oorigin.ov[1].origin_len); + assert_memory_equal(sizeof(nghttp2) - 1, nghttp2, oorigin.ov[1].origin); nghttp2_frame_origin_free(&oframe, mem); @@ -561,7 +583,7 @@ void test_nghttp2_frame_pack_origin(void) { rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR == rv); + assert_int(NGHTTP2_ERR_FRAME_SIZE_ERROR, ==, rv); nghttp2_bufs_reset(&bufs); memset(&oframe, 0, sizeof(oframe)); @@ -573,17 +595,17 @@ void test_nghttp2_frame_pack_origin(void) { rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN == nghttp2_bufs_len(&bufs)); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN, ==, nghttp2_bufs_len(&bufs)); rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); check_frame_header(0, NGHTTP2_ORIGIN, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(0 == oorigin.nov); - CU_ASSERT(NULL == oorigin.ov); + assert_size(0, ==, oorigin.nov); + assert_null(oorigin.ov); nghttp2_frame_origin_free(&oframe, mem); @@ -610,25 +632,25 @@ void test_nghttp2_frame_pack_priority_update(void) { nghttp2_frame_pack_priority_update(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + payloadlen == nghttp2_bufs_len(&bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + payloadlen, ==, nghttp2_bufs_len(&bufs)); rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); check_frame_header(payloadlen, NGHTTP2_PRIORITY_UPDATE, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(sizeof(field_value) - 1 == opriority_update.field_value_len); - CU_ASSERT(0 == memcmp(field_value, opriority_update.field_value, - sizeof(field_value) - 1)); + assert_size(sizeof(field_value) - 1, ==, opriority_update.field_value_len); + assert_memory_equal(sizeof(field_value) - 1, field_value, + opriority_update.field_value); nghttp2_bufs_free(&bufs); } void test_nghttp2_nv_array_copy(void) { nghttp2_nv *nva; - ssize_t rv; + int rv; nghttp2_nv emptynv[] = {MAKE_NV("", ""), MAKE_NV("", "")}; nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; nghttp2_nv bignv; @@ -644,34 +666,34 @@ void test_nghttp2_nv_array_copy(void) { memset(bignv.value, '0', bignv.valuelen); rv = nghttp2_nv_array_copy(&nva, NULL, 0, mem); - CU_ASSERT(0 == rv); - CU_ASSERT(NULL == nva); + assert_int(0, ==, rv); + assert_null(nva); rv = nghttp2_nv_array_copy(&nva, emptynv, ARRLEN(emptynv), mem); - CU_ASSERT(0 == rv); - CU_ASSERT(nva[0].namelen == 0); - CU_ASSERT(nva[0].valuelen == 0); - CU_ASSERT(nva[1].namelen == 0); - CU_ASSERT(nva[1].valuelen == 0); + assert_int(0, ==, rv); + assert_size(0, ==, nva[0].namelen); + assert_size(0, ==, nva[0].valuelen); + assert_size(0, ==, nva[1].namelen); + assert_size(0, ==, nva[1].valuelen); nghttp2_nv_array_del(nva, mem); rv = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv), mem); - CU_ASSERT(0 == rv); - CU_ASSERT(nva[0].namelen == 5); - CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5)); - CU_ASSERT(nva[0].valuelen == 5); - CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5)); - CU_ASSERT(nva[1].namelen == 7); - CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7)); - CU_ASSERT(nva[1].valuelen == 5); - CU_ASSERT(0 == memcmp("delta", nva[1].value, 5)); + assert_int(0, ==, rv); + assert_size(5, ==, nva[0].namelen); + assert_memory_equal(5, "alpha", nva[0].name); + assert_size(5, ==, nva[0].valuelen); + assert_memory_equal(5, "bravo", nva[0].value); + assert_size(7, ==, nva[1].namelen); + assert_memory_equal(7, "charlie", nva[1].name); + assert_size(5, ==, nva[1].valuelen); + assert_memory_equal(5, "delta", nva[1].value); nghttp2_nv_array_del(nva, mem); /* Large header field is acceptable */ rv = nghttp2_nv_array_copy(&nva, &bignv, 1, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_nv_array_del(nva, mem); @@ -686,50 +708,50 @@ void test_nghttp2_iv_check(void) { iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[1].value = 1024; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; iv[1].value = NGHTTP2_MAX_WINDOW_SIZE; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); /* Too large window size */ iv[1].value = (uint32_t)NGHTTP2_MAX_WINDOW_SIZE + 1; - CU_ASSERT(0 == nghttp2_iv_check(iv, 2)); + assert_false(nghttp2_iv_check(iv, 2)); /* ENABLE_PUSH only allows 0 or 1 */ iv[1].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; iv[1].value = 0; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); iv[1].value = 1; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); iv[1].value = 3; - CU_ASSERT(!nghttp2_iv_check(iv, 2)); + assert_false(nghttp2_iv_check(iv, 2)); /* Undefined SETTINGS ID is allowed */ iv[1].settings_id = 1000000009; iv[1].value = 0; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); /* Full size SETTINGS_HEADER_TABLE_SIZE (UINT32_MAX) must be accepted */ iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[1].value = UINT32_MAX; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); /* Too small SETTINGS_MAX_FRAME_SIZE */ iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE; iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN - 1; - CU_ASSERT(!nghttp2_iv_check(iv, 1)); + assert_false(nghttp2_iv_check(iv, 1)); /* Too large SETTINGS_MAX_FRAME_SIZE */ iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE; iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MAX + 1; - CU_ASSERT(!nghttp2_iv_check(iv, 1)); + assert_false(nghttp2_iv_check(iv, 1)); /* Max and min SETTINGS_MAX_FRAME_SIZE */ iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE; iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN; iv[1].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE; iv[1].value = NGHTTP2_MAX_FRAME_SIZE_MAX; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); } diff --git a/yass/third_party/nghttp2/tests/nghttp2_frame_test.h b/yass/third_party/nghttp2/tests/nghttp2_frame_test.h index dc0762573b..ae7842c1ab 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_frame_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_frame_test.h @@ -29,19 +29,25 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_frame_pack_headers(void); -void test_nghttp2_frame_pack_headers_frame_too_large(void); -void test_nghttp2_frame_pack_priority(void); -void test_nghttp2_frame_pack_rst_stream(void); -void test_nghttp2_frame_pack_settings(void); -void test_nghttp2_frame_pack_push_promise(void); -void test_nghttp2_frame_pack_ping(void); -void test_nghttp2_frame_pack_goaway(void); -void test_nghttp2_frame_pack_window_update(void); -void test_nghttp2_frame_pack_altsvc(void); -void test_nghttp2_frame_pack_origin(void); -void test_nghttp2_frame_pack_priority_update(void); -void test_nghttp2_nv_array_copy(void); -void test_nghttp2_iv_check(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite frame_suite; + +munit_void_test_decl(test_nghttp2_frame_pack_headers); +munit_void_test_decl(test_nghttp2_frame_pack_headers_frame_too_large); +munit_void_test_decl(test_nghttp2_frame_pack_priority); +munit_void_test_decl(test_nghttp2_frame_pack_rst_stream); +munit_void_test_decl(test_nghttp2_frame_pack_settings); +munit_void_test_decl(test_nghttp2_frame_pack_push_promise); +munit_void_test_decl(test_nghttp2_frame_pack_ping); +munit_void_test_decl(test_nghttp2_frame_pack_goaway); +munit_void_test_decl(test_nghttp2_frame_pack_window_update); +munit_void_test_decl(test_nghttp2_frame_pack_altsvc); +munit_void_test_decl(test_nghttp2_frame_pack_origin); +munit_void_test_decl(test_nghttp2_frame_pack_priority_update); +munit_void_test_decl(test_nghttp2_nv_array_copy); +munit_void_test_decl(test_nghttp2_iv_check); #endif /* NGHTTP2_FRAME_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_hd_test.c b/yass/third_party/nghttp2/tests/nghttp2_hd_test.c index 657d895fab..d57127f3e6 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_hd_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_hd_test.c @@ -27,11 +27,42 @@ #include #include -#include +#include "munit.h" #include "nghttp2_hd.h" #include "nghttp2_frame.h" #include "nghttp2_test_helper.h" +#include "nghttp2_assertion.h" + +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_hd_deflate), + munit_void_test(test_nghttp2_hd_deflate_same_indexed_repr), + munit_void_test(test_nghttp2_hd_inflate_indexed), + munit_void_test(test_nghttp2_hd_inflate_indname_noinc), + munit_void_test(test_nghttp2_hd_inflate_indname_inc), + munit_void_test(test_nghttp2_hd_inflate_indname_inc_eviction), + munit_void_test(test_nghttp2_hd_inflate_newname_noinc), + munit_void_test(test_nghttp2_hd_inflate_newname_inc), + munit_void_test(test_nghttp2_hd_inflate_clearall_inc), + munit_void_test(test_nghttp2_hd_inflate_zero_length_huffman), + munit_void_test(test_nghttp2_hd_inflate_expect_table_size_update), + munit_void_test(test_nghttp2_hd_inflate_unexpected_table_size_update), + munit_void_test(test_nghttp2_hd_ringbuf_reserve), + munit_void_test(test_nghttp2_hd_change_table_size), + munit_void_test(test_nghttp2_hd_deflate_inflate), + munit_void_test(test_nghttp2_hd_no_index), + munit_void_test(test_nghttp2_hd_deflate_bound), + munit_void_test(test_nghttp2_hd_public_api), + munit_void_test(test_nghttp2_hd_deflate_hd_vec), + munit_void_test(test_nghttp2_hd_decode_length), + munit_void_test(test_nghttp2_hd_huff_encode), + munit_void_test(test_nghttp2_hd_huff_decode), + munit_test_end(), +}; + +const MunitSuite hd_suite = { + "/hd", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; void test_nghttp2_hd_deflate(void) { nghttp2_hd_deflater deflater; @@ -47,7 +78,7 @@ void test_nghttp2_hd_deflate(void) { nghttp2_nv nva5[] = {MAKE_NV(":path", "/style.css"), MAKE_NV("x-nghttp2", "")}; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nva_out out; int rv; nghttp2_mem *mem; @@ -56,17 +87,17 @@ void test_nghttp2_hd_deflate(void) { frame_pack_bufs_init(&bufs); nva_out_init(&out); - CU_ASSERT(0 == nghttp2_hd_deflate_init(&deflater, mem)); - CU_ASSERT(0 == nghttp2_hd_inflate_init(&inflater, mem)); + assert_int(0, ==, nghttp2_hd_deflate_init(&deflater, mem)); + assert_int(0, ==, nghttp2_hd_inflate_init(&inflater, mem)); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva1, ARRLEN(nva1)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3 == out.nvlen); + assert_size(3, ==, out.nvlen); assert_nv_equal(nva1, out.nva, 3, mem); nva_out_reset(&out, mem); @@ -74,13 +105,13 @@ void test_nghttp2_hd_deflate(void) { /* Second headers */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, ARRLEN(nva2)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == out.nvlen); + assert_size(2, ==, out.nvlen); assert_nv_equal(nva2, out.nva, 2, mem); nva_out_reset(&out, mem); @@ -89,13 +120,13 @@ void test_nghttp2_hd_deflate(void) { /* Third headers, including same header field name, but value is not the same. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva3, ARRLEN(nva3)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3 == out.nvlen); + assert_size(3, ==, out.nvlen); assert_nv_equal(nva3, out.nva, 3, mem); nva_out_reset(&out, mem); @@ -103,13 +134,13 @@ void test_nghttp2_hd_deflate(void) { /* Fourth headers, including duplicate header fields. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva4, ARRLEN(nva4)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3 == out.nvlen); + assert_size(3, ==, out.nvlen); assert_nv_equal(nva4, out.nva, 3, mem); nva_out_reset(&out, mem); @@ -117,13 +148,13 @@ void test_nghttp2_hd_deflate(void) { /* Fifth headers includes empty value */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva5, ARRLEN(nva5)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == out.nvlen); + assert_size(2, ==, out.nvlen); assert_nv_equal(nva5, out.nva, 2, mem); nva_out_reset(&out, mem); @@ -142,7 +173,7 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void) { nghttp2_nv nva2[] = {MAKE_NV("host", "alpha"), MAKE_NV("host", "alpha"), MAKE_NV("host", "alpha")}; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nva_out out; int rv; nghttp2_mem *mem; @@ -151,18 +182,18 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void) { frame_pack_bufs_init(&bufs); nva_out_init(&out); - CU_ASSERT(0 == nghttp2_hd_deflate_init(&deflater, mem)); - CU_ASSERT(0 == nghttp2_hd_inflate_init(&inflater, mem)); + assert_int(0, ==, nghttp2_hd_deflate_init(&deflater, mem)); + assert_int(0, ==, nghttp2_hd_inflate_init(&inflater, mem)); /* Encode 2 same headers. Emit 1 literal reprs and 1 index repr. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva1, ARRLEN(nva1)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == out.nvlen); + assert_size(2, ==, out.nvlen); assert_nv_equal(nva1, out.nva, 2, mem); nva_out_reset(&out, mem); @@ -170,13 +201,13 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void) { /* Encode 3 same headers. This time, emits 3 index reprs. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, ARRLEN(nva2)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen == 3); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(3, ==, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3 == out.nvlen); + assert_size(3, ==, out.nvlen); assert_nv_equal(nva2, out.nva, 3, mem); nva_out_reset(&out, mem); @@ -191,7 +222,7 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void) { void test_nghttp2_hd_inflate_indexed(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv = MAKE_NV(":path", "/"); nva_out out; nghttp2_mem *mem; @@ -204,12 +235,12 @@ void test_nghttp2_hd_inflate_indexed(void) { nghttp2_bufs_addb(&bufs, (1 << 7) | 4); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(1 == blocklen); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(1, ==, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); @@ -219,11 +250,11 @@ void test_nghttp2_hd_inflate_indexed(void) { /* index = 0 is error */ nghttp2_bufs_addb(&bufs, 1 << 7); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(1 == blocklen); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(1, ==, blocklen); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); @@ -232,7 +263,7 @@ void test_nghttp2_hd_inflate_indexed(void) { void test_nghttp2_hd_inflate_indname_noinc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv[] = {/* Huffman */ MAKE_NV("user-agent", "nghttp2"), /* Expecting no huffman */ @@ -248,18 +279,19 @@ void test_nghttp2_hd_inflate_indname_noinc(void) { nghttp2_hd_inflate_init(&inflater, mem); for (i = 0; i < ARRLEN(nv); ++i) { - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 57, &nv[i], - NGHTTP2_HD_WITHOUT_INDEXING)); + assert_int(0, ==, + nghttp2_hd_emit_indname_block(&bufs, 57, &nv[i], + NGHTTP2_HD_WITHOUT_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv[i], out.nva, 1, mem); - CU_ASSERT(0 == inflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(0, ==, inflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -272,7 +304,7 @@ void test_nghttp2_hd_inflate_indname_noinc(void) { void test_nghttp2_hd_inflate_indname_inc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv = MAKE_NV("user-agent", "nghttp2"); nva_out out; nghttp2_mem *mem; @@ -283,18 +315,19 @@ void test_nghttp2_hd_inflate_indname_inc(void) { nva_out_init(&out); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 57, &nv, - NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 57, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(1 == inflater.ctx.hd_table.len); - CU_ASSERT(62 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(1, ==, inflater.ctx.hd_table.len); + assert_size(62, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); assert_nv_equal( &nv, nghttp2_hd_inflate_get_table_entry( @@ -309,7 +342,7 @@ void test_nghttp2_hd_inflate_indname_inc(void) { void test_nghttp2_hd_inflate_indname_inc_eviction(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; uint8_t value[1025]; nva_out out; nghttp2_nv nv; @@ -328,31 +361,35 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void) { nv.flags = NGHTTP2_NV_FLAG_NONE; - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 14, &nv, - NGHTTP2_HD_WITH_INDEXING)); - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 15, &nv, - NGHTTP2_HD_WITH_INDEXING)); - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 16, &nv, - NGHTTP2_HD_WITH_INDEXING)); - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 17, &nv, - NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 14, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 15, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 16, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 17, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(4 == out.nvlen); - CU_ASSERT(14 == out.nva[0].namelen); - CU_ASSERT(0 == memcmp("accept-charset", out.nva[0].name, out.nva[0].namelen)); - CU_ASSERT(sizeof(value) - 1 == out.nva[0].valuelen); + assert_size(4, ==, out.nvlen); + assert_size(14, ==, out.nva[0].namelen); + assert_memory_equal(out.nva[0].namelen, "accept-charset", out.nva[0].name); + assert_size(sizeof(value) - 1, ==, out.nva[0].valuelen); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); - CU_ASSERT(3 == inflater.ctx.hd_table.len); - CU_ASSERT(64 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(3, ==, inflater.ctx.hd_table.len); + assert_size(64, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); @@ -361,7 +398,7 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void) { void test_nghttp2_hd_inflate_newname_noinc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv[] = {/* Expecting huffman for both */ MAKE_NV("my-long-content-length", "nghttp2"), /* Expecting no huffman for both */ @@ -380,17 +417,18 @@ void test_nghttp2_hd_inflate_newname_noinc(void) { nva_out_init(&out); nghttp2_hd_inflate_init(&inflater, mem); for (i = 0; i < ARRLEN(nv); ++i) { - CU_ASSERT(0 == nghttp2_hd_emit_newname_block(&bufs, &nv[i], - NGHTTP2_HD_WITHOUT_INDEXING)); + assert_int(0, ==, + nghttp2_hd_emit_newname_block(&bufs, &nv[i], + NGHTTP2_HD_WITHOUT_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv[i], out.nva, 1, mem); - CU_ASSERT(0 == inflater.ctx.hd_table.len); + assert_size(0, ==, inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -403,7 +441,7 @@ void test_nghttp2_hd_inflate_newname_noinc(void) { void test_nghttp2_hd_inflate_newname_inc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv = MAKE_NV("x-rel", "nghttp2"); nva_out out; nghttp2_mem *mem; @@ -414,17 +452,18 @@ void test_nghttp2_hd_inflate_newname_inc(void) { nva_out_init(&out); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT( - 0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(1 == inflater.ctx.hd_table.len); + assert_size(1, ==, inflater.ctx.hd_table.len); assert_nv_equal( &nv, nghttp2_hd_inflate_get_table_entry( @@ -439,7 +478,7 @@ void test_nghttp2_hd_inflate_newname_inc(void) { void test_nghttp2_hd_inflate_clearall_inc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv; uint8_t value[4061]; nva_out out; @@ -461,26 +500,27 @@ void test_nghttp2_hd_inflate_clearall_inc(void) { nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT( - 0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(0 == inflater.ctx.hd_table.len); + assert_size(0, ==, inflater.ctx.hd_table.len); nva_out_reset(&out, mem); /* Do it again */ - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(0 == inflater.ctx.hd_table.len); + assert_size(0, ==, inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -489,17 +529,18 @@ void test_nghttp2_hd_inflate_clearall_inc(void) { header table */ nv.valuelen = sizeof(value) - 2; - CU_ASSERT( - 0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(1 == inflater.ctx.hd_table.len); + assert_size(1, ==, inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -530,13 +571,13 @@ void test_nghttp2_hd_inflate_zero_length_huffman(void) { /* ptr[3] = 0x80; */ nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(4 == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(4, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); - CU_ASSERT(1 == out.nva[0].namelen); - CU_ASSERT('x' == out.nva[0].name[0]); - CU_ASSERT(NULL == out.nva[0].value); - CU_ASSERT(0 == out.nva[0].valuelen); + assert_size(1, ==, out.nvlen); + assert_size(1, ==, out.nva[0].namelen); + assert_uint8('x', ==, out.nva[0].name[0]); + assert_null(out.nva[0].value); + assert_size(0, ==, out.nva[0].valuelen); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); @@ -561,8 +602,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { inflation. */ nghttp2_hd_inflate_change_table_size(&inflater, 4095); nghttp2_hd_inflate_change_table_size(&inflater, 4096); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -571,8 +612,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { * size is not changed. */ nghttp2_hd_inflate_init(&inflater, mem); nghttp2_hd_inflate_change_table_size(&inflater, 4096); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -581,8 +622,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { new size is larger than current size. */ nghttp2_hd_inflate_init(&inflater, mem); nghttp2_hd_inflate_change_table_size(&inflater, 4097); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -595,8 +636,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { nghttp2_bufs_reset(&bufs); nghttp2_hd_emit_table_size(&bufs, 112); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -610,8 +651,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { nghttp2_hd_emit_table_size(&bufs, 111); nghttp2_hd_emit_table_size(&bufs, 4096); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -625,8 +666,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { nghttp2_hd_emit_table_size(&bufs, 111); nghttp2_hd_emit_table_size(&bufs, 4096); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -649,8 +690,8 @@ void test_nghttp2_hd_inflate_unexpected_table_size_update(void) { nghttp2_bufs_add(&bufs, data, sizeof(data)); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); @@ -664,8 +705,8 @@ void test_nghttp2_hd_ringbuf_reserve(void) { nghttp2_bufs bufs; nva_out out; int i; - ssize_t rv; - ssize_t blocklen; + nghttp2_ssize rv; + nghttp2_ssize blocklen; nghttp2_mem *mem; mem = nghttp2_mem_default(); @@ -688,14 +729,14 @@ void test_nghttp2_hd_ringbuf_reserve(void) { for (i = 0; i < 150; ++i) { memcpy(nv.value, &i, sizeof(i)); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, &nv, 1); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, ==, rv); + assert_ptrdiff(0, <, blocklen); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); nva_out_reset(&out, mem); @@ -715,9 +756,9 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_nv nva[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; nghttp2_nv nva2[] = {MAKE_NV(":path", "/")}; nghttp2_bufs bufs; - ssize_t rv; + int rv; nva_out out; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_mem *mem; mem = nghttp2_mem_default(); @@ -729,87 +770,87 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_inflate_init(&inflater, mem); /* inflater changes notifies 8000 max header table size */ - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 8000)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 8000)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 8000)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 8000)); - CU_ASSERT(4096 == deflater.ctx.hd_table_bufsize_max); + assert_size(4096, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(4096 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max); + assert_size(4096, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, inflater.settings_hd_table_bufsize_max); /* This will emit encoding context update with header table size 4096 */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(63 == nghttp2_hd_deflate_get_num_table_entries(&deflater)); - CU_ASSERT(4096 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(63, ==, nghttp2_hd_deflate_get_num_table_entries(&deflater)); + assert_size(4096, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(63 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - CU_ASSERT(4096 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(63, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(4096, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); /* inflater changes header table size to 1024 */ - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 1024)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 1024)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 1024)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 1024)); - CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max); + assert_size(1024, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(1024 == inflater.settings_hd_table_bufsize_max); + assert_size(1024, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(1024, ==, inflater.settings_hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(63 == nghttp2_hd_deflate_get_num_table_entries(&deflater)); - CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(63, ==, nghttp2_hd_deflate_get_num_table_entries(&deflater)); + assert_size(1024, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(63 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(1024 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(63, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(1024, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(1024, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); /* inflater changes header table size to 0 */ - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 0)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 0)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 0)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 0)); - CU_ASSERT(0 == deflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_deflate_get_num_table_entries(&deflater)); - CU_ASSERT(0 == deflater.ctx.hd_table_bufsize_max); + assert_size(0, ==, deflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_deflate_get_num_table_entries(&deflater)); + assert_size(0, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(0 == inflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - CU_ASSERT(0 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(0 == inflater.settings_hd_table_bufsize_max); + assert_size(0, ==, inflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(0, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(0, ==, inflater.settings_hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(0 == deflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_deflate_get_num_table_entries(&deflater)); - CU_ASSERT(0 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(0, ==, deflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_deflate_get_num_table_entries(&deflater)); + assert_size(0, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(0 == inflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - CU_ASSERT(0 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(0 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(0, ==, inflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(0, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(0, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -825,53 +866,57 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_inflate_init(&inflater, mem); /* First inflater changes header table size to 8000 */ - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 8000)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 8000)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 8000)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 8000)); - CU_ASSERT(8000 == deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater)); - CU_ASSERT(4096 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(4096 == nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater)); - CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max); + assert_size(8000, ==, deflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, + nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater)); + assert_size(4096, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(4096, ==, + nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater)); + assert_size(8000, ==, inflater.settings_hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(8000 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(8000, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(8000 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(8000, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 16383)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 16383)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 16383)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 16383)); - CU_ASSERT(8192 == deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8192 == nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater)); + assert_size(8192, ==, deflater.ctx.hd_table_bufsize_max); + assert_size(8192, ==, + nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater)); - CU_ASSERT(8000 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater)); - CU_ASSERT(16383 == inflater.settings_hd_table_bufsize_max); + assert_size(8000, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, + nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater)); + assert_size(16383, ==, inflater.settings_hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(8192 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(8192, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(8192 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(16383 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(8192, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(16383, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -879,9 +924,9 @@ void test_nghttp2_hd_change_table_size(void) { /* Lastly, check the error condition */ rv = nghttp2_hd_emit_table_size(&bufs, 25600); - CU_ASSERT(rv == 0); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -894,21 +939,21 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_deflate_init2(&deflater, 1024, mem); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max); + assert_size(1024, ==, deflater.ctx.hd_table_bufsize_max); /* This emits context update with buffer size 1024 */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(1024, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(4096 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(1024, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(4096, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -920,18 +965,20 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_deflate_init2(&deflater, UINT32_MAX, mem); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, UINT32_MAX)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, UINT32_MAX)); + assert_int(0, ==, + nghttp2_hd_inflate_change_table_size(&inflater, UINT32_MAX)); + assert_int(0, ==, + nghttp2_hd_deflate_change_table_size(&deflater, UINT32_MAX)); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(UINT32_MAX == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_size(UINT32_MAX, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(UINT32_MAX == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(UINT32_MAX == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(UINT32_MAX, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(UINT32_MAX, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -943,25 +990,25 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_deflate_init2(&deflater, 4096, mem); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 0)); - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 3000)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 0)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 3000)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 0)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 3000)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 0)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 3000)); - CU_ASSERT(0 == deflater.min_hd_table_bufsize_max); - CU_ASSERT(3000 == deflater.ctx.hd_table_bufsize_max); + assert_size(0, ==, deflater.min_hd_table_bufsize_max); + assert_size(3000, ==, deflater.ctx.hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, 1); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(3 < blocklen); - CU_ASSERT(3000 == deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(UINT32_MAX == deflater.min_hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(3, <, blocklen); + assert_size(3000, ==, deflater.ctx.hd_table_bufsize_max); + assert_size(UINT32_MAX, ==, deflater.min_hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3000 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(3000 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(3000, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(3000, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -977,7 +1024,7 @@ static void check_deflate_inflate(nghttp2_hd_deflater *deflater, nghttp2_nv *nva, size_t nvlen, nghttp2_mem *mem) { nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nva_out out; int rv; @@ -985,14 +1032,14 @@ static void check_deflate_inflate(nghttp2_hd_deflater *deflater, nva_out_init(&out); rv = nghttp2_hd_deflate_hd_bufs(deflater, &bufs, nva, nvlen); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen >= 0); + assert_int(0, ==, rv); + assert_ptrdiff(0, <=, blocklen); - CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, &out, &bufs, 0, mem)); - CU_ASSERT(nvlen == out.nvlen); + assert_size(nvlen, ==, out.nvlen); assert_nv_equal(nva, out.nva, nvlen, mem); nva_out_reset(&out, mem); @@ -1161,7 +1208,7 @@ void test_nghttp2_hd_no_index(void) { nghttp2_hd_deflater deflater; nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nva[] = { MAKE_NV(":method", "GET"), MAKE_NV(":method", "POST"), MAKE_NV(":path", "/foo"), MAKE_NV("version", "HTTP/1.1"), @@ -1187,18 +1234,18 @@ void test_nghttp2_hd_no_index(void) { nghttp2_hd_inflate_init(&inflater, mem); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(ARRLEN(nva) == out.nvlen); + assert_size(ARRLEN(nva), ==, out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); - CU_ASSERT(out.nva[0].flags == NGHTTP2_NV_FLAG_NONE); + assert_uint8(NGHTTP2_NV_FLAG_NONE, ==, out.nva[0].flags); for (i = 1; i < ARRLEN(nva); ++i) { - CU_ASSERT(out.nva[i].flags == NGHTTP2_NV_FLAG_NO_INDEX); + assert_uint8(NGHTTP2_NV_FLAG_NO_INDEX, ==, out.nva[i].flags); } nva_out_reset(&out, mem); @@ -1222,17 +1269,17 @@ void test_nghttp2_hd_deflate_bound(void) { bound = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva)); - CU_ASSERT(12 + 6 * 2 * 2 + nva[0].namelen + nva[0].valuelen + nva[1].namelen + - nva[1].valuelen == - bound); + assert_size(12 + 6 * 2 * 2 + nva[0].namelen + nva[0].valuelen + + nva[1].namelen + nva[1].valuelen, + ==, bound); nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva)); - CU_ASSERT(bound > (size_t)nghttp2_bufs_len(&bufs)); + assert_size((size_t)nghttp2_bufs_len(&bufs), <, bound); bound2 = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva)); - CU_ASSERT(bound == bound2); + assert_size(bound, ==, bound2); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -1244,25 +1291,25 @@ void test_nghttp2_hd_public_api(void) { nghttp2_nv nva[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; uint8_t buf[4096]; size_t buflen; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_bufs bufs; nghttp2_mem *mem; mem = nghttp2_mem_default(); - CU_ASSERT(0 == nghttp2_hd_deflate_new(&deflater, 4096)); - CU_ASSERT(0 == nghttp2_hd_inflate_new(&inflater)); + assert_int(0, ==, nghttp2_hd_deflate_new(&deflater, 4096)); + assert_int(0, ==, nghttp2_hd_inflate_new(&inflater)); buflen = nghttp2_hd_deflate_bound(deflater, nva, ARRLEN(nva)); - blocklen = nghttp2_hd_deflate_hd(deflater, buf, buflen, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd2(deflater, buf, buflen, nva, ARRLEN(nva)); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem); bufs.head->buf.last += blocklen; - CU_ASSERT(blocklen == inflate_hd(inflater, NULL, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, NULL, &bufs, 0, mem)); nghttp2_bufs_wrap_free(&bufs); @@ -1270,12 +1317,12 @@ void test_nghttp2_hd_public_api(void) { nghttp2_hd_deflate_del(deflater); /* See NGHTTP2_ERR_INSUFF_BUFSIZE */ - CU_ASSERT(0 == nghttp2_hd_deflate_new(&deflater, 4096)); + assert_int(0, ==, nghttp2_hd_deflate_new(&deflater, 4096)); - blocklen = nghttp2_hd_deflate_hd(deflater, buf, (size_t)(blocklen - 1), nva, - ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd2(deflater, buf, (size_t)(blocklen - 1), nva, + ARRLEN(nva)); - CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen); + assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, blocklen); nghttp2_hd_deflate_del(deflater); } @@ -1292,7 +1339,7 @@ void test_nghttp2_hd_deflate_hd_vec(void) { MAKE_NV("content-length", "1000000007"), }; uint8_t buf[4096]; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_mem *mem; nghttp2_vec vec[256]; size_t buflen; @@ -1314,16 +1361,16 @@ void test_nghttp2_hd_deflate_hd_vec(void) { vec[1].base = &buf[buflen / 2]; vec[1].len = buflen / 2; - blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd_vec2(deflater, vec, 2, nva, ARRLEN(nva)); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem); bufs.head->buf.last += blocklen; - CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, &out, &bufs, 0, mem)); - CU_ASSERT(ARRLEN(nva) == out.nvlen); + assert_size(ARRLEN(nva), ==, out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); nghttp2_bufs_wrap_free(&bufs); @@ -1336,9 +1383,9 @@ void test_nghttp2_hd_deflate_hd_vec(void) { nghttp2_hd_deflate_new(&deflater, 4096); nghttp2_hd_inflate_new(&inflater); - blocklen = nghttp2_hd_deflate_hd_vec(deflater, NULL, 0, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd_vec2(deflater, NULL, 0, nva, ARRLEN(nva)); - CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen); + assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, blocklen); nghttp2_hd_inflate_del(inflater); nghttp2_hd_deflate_del(deflater); @@ -1352,9 +1399,9 @@ void test_nghttp2_hd_deflate_hd_vec(void) { nghttp2_hd_deflate_new(&deflater, 4096); nghttp2_hd_inflate_new(&inflater); - blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd_vec2(deflater, vec, 2, nva, ARRLEN(nva)); - CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen); + assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, blocklen); nghttp2_hd_inflate_del(inflater); nghttp2_hd_deflate_del(deflater); @@ -1370,15 +1417,15 @@ void test_nghttp2_hd_deflate_hd_vec(void) { vec[1].base = &buf[buflen / 2]; vec[1].len = (buflen / 2) + 1; - blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd_vec2(deflater, vec, 2, nva, ARRLEN(nva)); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem); bufs.head->buf.last += blocklen; - CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem)); - CU_ASSERT(ARRLEN(nva) == out.nvlen); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, &out, &bufs, 0, mem)); + assert_size(ARRLEN(nva), ==, out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); nghttp2_bufs_wrap_free(&bufs); @@ -1400,15 +1447,16 @@ void test_nghttp2_hd_deflate_hd_vec(void) { vec[i].len = 1; } - blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, buflen, nva, ARRLEN(nva)); + blocklen = + nghttp2_hd_deflate_hd_vec2(deflater, vec, buflen, nva, ARRLEN(nva)); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem); bufs.head->buf.last += blocklen; - CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem)); - CU_ASSERT(ARRLEN(nva) == out.nvlen); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, &out, &bufs, 0, mem)); + assert_size(ARRLEN(nva), ==, out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); nghttp2_bufs_wrap_free(&bufs); @@ -1453,7 +1501,7 @@ void test_nghttp2_hd_decode_length(void) { uint8_t buf[16]; uint8_t *bufp; size_t len; - ssize_t rv; + nghttp2_ssize rv; size_t i; memset(buf, 0, sizeof(buf)); @@ -1461,9 +1509,9 @@ void test_nghttp2_hd_decode_length(void) { rv = nghttp2_hd_decode_length(&out, &shift, &fin, 0, 0, buf, buf + len, 7); - CU_ASSERT((ssize_t)len == rv); - CU_ASSERT(0 != fin); - CU_ASSERT(UINT32_MAX == out); + assert_ptrdiff((nghttp2_ssize)len, ==, rv); + assert_true(fin); + assert_uint32(UINT32_MAX, ==, out); /* Make sure that we can decode integer if we feed 1 byte at a time */ @@ -1476,16 +1524,16 @@ void test_nghttp2_hd_decode_length(void) { rv = nghttp2_hd_decode_length(&out, &shift, &fin, out, shift, bufp, bufp + 1, 7); - CU_ASSERT(rv == 1); + assert_ptrdiff(1, ==, rv); if (fin) { break; } } - CU_ASSERT(i == len - 1); - CU_ASSERT(0 != fin); - CU_ASSERT(UINT32_MAX == out); + assert_size(len - 1, ==, i); + assert_true(fin); + assert_size(UINT32_MAX, ==, out); /* Check overflow case */ memset(buf, 0, sizeof(buf)); @@ -1493,7 +1541,7 @@ void test_nghttp2_hd_decode_length(void) { rv = nghttp2_hd_decode_length(&out, &shift, &fin, 0, 0, buf, buf + len, 7); - CU_ASSERT(-1 == rv); + assert_ptrdiff(-1, ==, rv); /* Check the case that shift goes beyond 32 bits */ buf[0] = 255; @@ -1506,12 +1554,12 @@ void test_nghttp2_hd_decode_length(void) { rv = nghttp2_hd_decode_length(&out, &shift, &fin, 0, 0, buf, buf + 7, 8); - CU_ASSERT(-1 == rv); + assert_ptrdiff(-1, ==, rv); } void test_nghttp2_hd_huff_encode(void) { int rv; - ssize_t len; + nghttp2_ssize len; nghttp2_buf outbuf; nghttp2_bufs bufs; nghttp2_hd_huff_decode_context ctx; @@ -1524,17 +1572,17 @@ void test_nghttp2_hd_huff_encode(void) { rv = nghttp2_hd_huff_encode(&bufs, t1, sizeof(t1)); - CU_ASSERT(rv == 0); + assert_int(0, ==, rv); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, bufs.cur->buf.pos, nghttp2_bufs_len(&bufs), 1); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == len); - CU_ASSERT((ssize_t)sizeof(t1) == nghttp2_buf_len(&outbuf)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, len); + assert_size(sizeof(t1), ==, nghttp2_buf_len(&outbuf)); - CU_ASSERT(0 == memcmp(t1, outbuf.pos, sizeof(t1))); + assert_memory_equal(sizeof(t1), t1, outbuf.pos); nghttp2_bufs_free(&bufs); } @@ -1544,34 +1592,34 @@ void test_nghttp2_hd_huff_decode(void) { nghttp2_hd_huff_decode_context ctx; nghttp2_buf outbuf; uint8_t b[256]; - ssize_t len; + nghttp2_ssize len; nghttp2_buf_wrap_init(&outbuf, b, sizeof(b)); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, e, 1, 1); - CU_ASSERT(1 == len); - CU_ASSERT(0 == memcmp("a", outbuf.pos, 1)); + assert_ptrdiff(1, ==, len); + assert_memory_equal(1, "a", outbuf.pos); /* Premature sequence must elicit decoding error */ nghttp2_buf_wrap_init(&outbuf, b, sizeof(b)); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, e, 2, 1); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == len); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, len); /* Fully decoding EOS is error */ nghttp2_buf_wrap_init(&outbuf, b, sizeof(b)); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, e, 2, 6); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == len); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, len); /* Check failure state */ nghttp2_buf_wrap_init(&outbuf, b, sizeof(b)); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, e, 5, 0); - CU_ASSERT(5 == len); - CU_ASSERT(nghttp2_hd_huff_decode_failure_state(&ctx)); + assert_ptrdiff(5, ==, len); + assert_true(nghttp2_hd_huff_decode_failure_state(&ctx)); } diff --git a/yass/third_party/nghttp2/tests/nghttp2_hd_test.h b/yass/third_party/nghttp2/tests/nghttp2_hd_test.h index ab0117cb9c..9d5ec8fc1b 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_hd_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_hd_test.h @@ -29,27 +29,33 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_hd_deflate(void); -void test_nghttp2_hd_deflate_same_indexed_repr(void); -void test_nghttp2_hd_inflate_indexed(void); -void test_nghttp2_hd_inflate_indname_noinc(void); -void test_nghttp2_hd_inflate_indname_inc(void); -void test_nghttp2_hd_inflate_indname_inc_eviction(void); -void test_nghttp2_hd_inflate_newname_noinc(void); -void test_nghttp2_hd_inflate_newname_inc(void); -void test_nghttp2_hd_inflate_clearall_inc(void); -void test_nghttp2_hd_inflate_zero_length_huffman(void); -void test_nghttp2_hd_inflate_expect_table_size_update(void); -void test_nghttp2_hd_inflate_unexpected_table_size_update(void); -void test_nghttp2_hd_ringbuf_reserve(void); -void test_nghttp2_hd_change_table_size(void); -void test_nghttp2_hd_deflate_inflate(void); -void test_nghttp2_hd_no_index(void); -void test_nghttp2_hd_deflate_bound(void); -void test_nghttp2_hd_public_api(void); -void test_nghttp2_hd_deflate_hd_vec(void); -void test_nghttp2_hd_decode_length(void); -void test_nghttp2_hd_huff_encode(void); -void test_nghttp2_hd_huff_decode(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite hd_suite; + +munit_void_test_decl(test_nghttp2_hd_deflate); +munit_void_test_decl(test_nghttp2_hd_deflate_same_indexed_repr); +munit_void_test_decl(test_nghttp2_hd_inflate_indexed); +munit_void_test_decl(test_nghttp2_hd_inflate_indname_noinc); +munit_void_test_decl(test_nghttp2_hd_inflate_indname_inc); +munit_void_test_decl(test_nghttp2_hd_inflate_indname_inc_eviction); +munit_void_test_decl(test_nghttp2_hd_inflate_newname_noinc); +munit_void_test_decl(test_nghttp2_hd_inflate_newname_inc); +munit_void_test_decl(test_nghttp2_hd_inflate_clearall_inc); +munit_void_test_decl(test_nghttp2_hd_inflate_zero_length_huffman); +munit_void_test_decl(test_nghttp2_hd_inflate_expect_table_size_update); +munit_void_test_decl(test_nghttp2_hd_inflate_unexpected_table_size_update); +munit_void_test_decl(test_nghttp2_hd_ringbuf_reserve); +munit_void_test_decl(test_nghttp2_hd_change_table_size); +munit_void_test_decl(test_nghttp2_hd_deflate_inflate); +munit_void_test_decl(test_nghttp2_hd_no_index); +munit_void_test_decl(test_nghttp2_hd_deflate_bound); +munit_void_test_decl(test_nghttp2_hd_public_api); +munit_void_test_decl(test_nghttp2_hd_deflate_hd_vec); +munit_void_test_decl(test_nghttp2_hd_decode_length); +munit_void_test_decl(test_nghttp2_hd_huff_encode); +munit_void_test_decl(test_nghttp2_hd_huff_decode); #endif /* NGHTTP2_HD_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_helper_test.c b/yass/third_party/nghttp2/tests/nghttp2_helper_test.c index 377f49d766..8c3f116098 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_helper_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_helper_test.c @@ -26,10 +26,22 @@ #include -#include +#include "munit.h" #include "nghttp2_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_adjust_local_window_size), + munit_void_test(test_nghttp2_check_header_name), + munit_void_test(test_nghttp2_check_header_value), + munit_void_test(test_nghttp2_check_header_value_rfc9113), + munit_test_end(), +}; + +const MunitSuite helper_suite = { + "/helper", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_adjust_local_window_size(void) { int32_t local_window_size = 100; int32_t recv_window_size = 50; @@ -37,123 +49,132 @@ void test_nghttp2_adjust_local_window_size(void) { int32_t delta; delta = 0; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(50 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(50, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(0, ==, delta); delta = 49; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(1 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(49 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(1, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(49, ==, delta); delta = 1; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(0 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(1 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(0, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(1, ==, delta); delta = 1; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(101 == local_window_size); - CU_ASSERT(0 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(1 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(101, ==, local_window_size); + assert_int32(0, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(1, ==, delta); delta = -1; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(-1 == recv_window_size); - CU_ASSERT(1 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(-1, ==, recv_window_size); + assert_int32(1, ==, recv_reduction); + assert_int32(0, ==, delta); delta = 1; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(101 == local_window_size); - CU_ASSERT(0 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(101, ==, local_window_size); + assert_int32(0, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(0, ==, delta); delta = 100; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(201 == local_window_size); - CU_ASSERT(0 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(100 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(201, ==, local_window_size); + assert_int32(0, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(100, ==, delta); delta = -3; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(198 == local_window_size); - CU_ASSERT(-3 == recv_window_size); - CU_ASSERT(3 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(198, ==, local_window_size); + assert_int32(-3, ==, recv_window_size); + assert_int32(3, ==, recv_reduction); + assert_int32(0, ==, delta); recv_window_size += 3; delta = 3; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(201 == local_window_size); - CU_ASSERT(3 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(201, ==, local_window_size); + assert_int32(3, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(0, ==, delta); local_window_size = 100; recv_window_size = 50; recv_reduction = 0; delta = INT32_MAX; - CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL == - nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, &recv_reduction, - &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(50 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(INT32_MAX == delta); + assert_int(NGHTTP2_ERR_FLOW_CONTROL, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(50, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(INT32_MAX, ==, delta); delta = INT32_MIN; - CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL == - nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, &recv_reduction, - &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(50 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(INT32_MIN == delta); + assert_int(NGHTTP2_ERR_FLOW_CONTROL, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(50, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(INT32_MIN, ==, delta); } #define check_header_name(S) \ nghttp2_check_header_name((const uint8_t *)S, sizeof(S) - 1) void test_nghttp2_check_header_name(void) { - CU_ASSERT(check_header_name(":path")); - CU_ASSERT(check_header_name("path")); - CU_ASSERT(check_header_name("!#$%&'*+-.^_`|~")); - CU_ASSERT(!check_header_name(":PATH")); - CU_ASSERT(!check_header_name("path:")); - CU_ASSERT(!check_header_name("")); - CU_ASSERT(!check_header_name(":")); + assert_true(check_header_name(":path")); + assert_true(check_header_name("path")); + assert_true(check_header_name("!#$%&'*+-.^_`|~")); + assert_false(check_header_name(":PATH")); + assert_false(check_header_name("path:")); + assert_false(check_header_name("")); + assert_false(check_header_name(":")); } #define check_header_value(S) \ @@ -164,13 +185,13 @@ void test_nghttp2_check_header_value(void) { uint8_t badval1[] = {'a', 0x1fu, 'b'}; uint8_t badval2[] = {'a', 0x7fu, 'b'}; - CU_ASSERT(check_header_value(" !|}~")); - CU_ASSERT(check_header_value(goodval)); - CU_ASSERT(!check_header_value(badval1)); - CU_ASSERT(!check_header_value(badval2)); - CU_ASSERT(check_header_value("")); - CU_ASSERT(check_header_value(" ")); - CU_ASSERT(check_header_value("\t")); + assert_true(check_header_value(" !|}~")); + assert_true(check_header_value(goodval)); + assert_false(check_header_value(badval1)); + assert_false(check_header_value(badval2)); + assert_true(check_header_value("")); + assert_true(check_header_value(" ")); + assert_true(check_header_value("\t")); } #define check_header_value_rfc9113(S) \ @@ -181,15 +202,15 @@ void test_nghttp2_check_header_value_rfc9113(void) { uint8_t badval1[] = {'a', 0x1fu, 'b'}; uint8_t badval2[] = {'a', 0x7fu, 'b'}; - CU_ASSERT(check_header_value_rfc9113("!|}~")); - CU_ASSERT(!check_header_value_rfc9113(" !|}~")); - CU_ASSERT(!check_header_value_rfc9113("!|}~ ")); - CU_ASSERT(!check_header_value_rfc9113("\t!|}~")); - CU_ASSERT(!check_header_value_rfc9113("!|}~\t")); - CU_ASSERT(check_header_value_rfc9113(goodval)); - CU_ASSERT(!check_header_value_rfc9113(badval1)); - CU_ASSERT(!check_header_value_rfc9113(badval2)); - CU_ASSERT(check_header_value_rfc9113("")); - CU_ASSERT(!check_header_value_rfc9113(" ")); - CU_ASSERT(!check_header_value_rfc9113("\t")); + assert_true(check_header_value_rfc9113("!|}~")); + assert_false(check_header_value_rfc9113(" !|}~")); + assert_false(check_header_value_rfc9113("!|}~ ")); + assert_false(check_header_value_rfc9113("\t!|}~")); + assert_false(check_header_value_rfc9113("!|}~\t")); + assert_true(check_header_value_rfc9113(goodval)); + assert_false(check_header_value_rfc9113(badval1)); + assert_false(check_header_value_rfc9113(badval2)); + assert_true(check_header_value_rfc9113("")); + assert_false(check_header_value_rfc9113(" ")); + assert_false(check_header_value_rfc9113("\t")); } diff --git a/yass/third_party/nghttp2/tests/nghttp2_helper_test.h b/yass/third_party/nghttp2/tests/nghttp2_helper_test.h index 8790dcf6d5..b81c7b3c61 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_helper_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_helper_test.h @@ -29,9 +29,15 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_adjust_local_window_size(void); -void test_nghttp2_check_header_name(void); -void test_nghttp2_check_header_value(void); -void test_nghttp2_check_header_value_rfc9113(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite helper_suite; + +munit_void_test_decl(test_nghttp2_adjust_local_window_size); +munit_void_test_decl(test_nghttp2_check_header_name); +munit_void_test_decl(test_nghttp2_check_header_value); +munit_void_test_decl(test_nghttp2_check_header_value_rfc9113); #endif /* NGHTTP2_HELPER_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_http_test.c b/yass/third_party/nghttp2/tests/nghttp2_http_test.c index 19f345bae7..86880d58cc 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_http_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_http_test.c @@ -28,11 +28,20 @@ #include #include -#include +#include "munit.h" #include "nghttp2_http.h" #include "nghttp2_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_http_parse_priority), + munit_test_end(), +}; + +const MunitSuite http_suite = { + "/http", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_http_parse_priority(void) { int rv; @@ -42,9 +51,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)-1 == pri.urgency); - CU_ASSERT(-1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)-1, ==, pri.urgency); + assert_int(-1, ==, pri.inc); } { @@ -53,9 +62,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)7 == pri.urgency); - CU_ASSERT(1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)7, ==, pri.urgency); + assert_int(1, ==, pri.inc); } { @@ -64,9 +73,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)0 == pri.urgency); - CU_ASSERT(0 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)0, ==, pri.urgency); + assert_int(0, ==, pri.inc); } { @@ -75,9 +84,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)3 == pri.urgency); - CU_ASSERT(1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)3, ==, pri.urgency); + assert_int(1, ==, pri.inc); } { @@ -86,9 +95,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)6 == pri.urgency); - CU_ASSERT(0 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)6, ==, pri.urgency); + assert_int(0, ==, pri.inc); } { @@ -97,7 +106,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -106,7 +115,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -115,7 +124,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -124,7 +133,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -133,9 +142,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)-1 == pri.urgency); - CU_ASSERT(1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)-1, ==, pri.urgency); + assert_int(1, ==, pri.inc); } { @@ -144,7 +153,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -153,7 +162,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -162,7 +171,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -171,7 +180,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -180,7 +189,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -190,9 +199,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)2 == pri.urgency); - CU_ASSERT(1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)2, ==, pri.urgency); + assert_int(1, ==, pri.inc); } { @@ -201,6 +210,6 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v)); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } } diff --git a/yass/third_party/nghttp2/tests/nghttp2_http_test.h b/yass/third_party/nghttp2/tests/nghttp2_http_test.h index e616cdcf49..b2589057cd 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_http_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_http_test.h @@ -30,6 +30,12 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_http_parse_priority(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite http_suite; + +munit_void_test_decl(test_nghttp2_http_parse_priority); #endif /* NGHTTP2_HTTP_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_map_test.c b/yass/third_party/nghttp2/tests/nghttp2_map_test.c index 7ba9bd6b66..3b79b8a6b1 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_map_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_map_test.c @@ -27,10 +27,22 @@ #include -#include +#include "munit.h" #include "nghttp2_map.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_map), + munit_void_test(test_nghttp2_map_functional), + munit_void_test(test_nghttp2_map_each_free), + munit_void_test(test_nghttp2_map_clear), + munit_test_end(), +}; + +const MunitSuite map_suite = { + "/map", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct strentry { nghttp2_map_key_type key; const char *str; @@ -53,43 +65,43 @@ void test_nghttp2_map(void) { strentry_init(&baz, 3, "baz"); strentry_init(&shrubbery, 4, "shrubbery"); - CU_ASSERT(0 == nghttp2_map_insert(&map, foo.key, &foo)); - CU_ASSERT(strcmp("foo", ((strentry *)nghttp2_map_find(&map, 1))->str) == 0); - CU_ASSERT(1 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, foo.key, &foo)); + assert_string_equal("foo", ((strentry *)nghttp2_map_find(&map, 1))->str); + assert_size(1, ==, nghttp2_map_size(&map)); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_map_insert(&map, FOO.key, &FOO)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_map_insert(&map, FOO.key, &FOO)); - CU_ASSERT(1 == nghttp2_map_size(&map)); - CU_ASSERT(strcmp("foo", ((strentry *)nghttp2_map_find(&map, 1))->str) == 0); + assert_size(1, ==, nghttp2_map_size(&map)); + assert_string_equal("foo", ((strentry *)nghttp2_map_find(&map, 1))->str); - CU_ASSERT(0 == nghttp2_map_insert(&map, bar.key, &bar)); - CU_ASSERT(2 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, bar.key, &bar)); + assert_size(2, ==, nghttp2_map_size(&map)); - CU_ASSERT(0 == nghttp2_map_insert(&map, baz.key, &baz)); - CU_ASSERT(3 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, baz.key, &baz)); + assert_size(3, ==, nghttp2_map_size(&map)); - CU_ASSERT(0 == nghttp2_map_insert(&map, shrubbery.key, &shrubbery)); - CU_ASSERT(4 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, shrubbery.key, &shrubbery)); + assert_size(4, ==, nghttp2_map_size(&map)); - CU_ASSERT(strcmp("baz", ((strentry *)nghttp2_map_find(&map, 3))->str) == 0); + assert_string_equal("baz", ((strentry *)nghttp2_map_find(&map, 3))->str); nghttp2_map_remove(&map, 3); - CU_ASSERT(3 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 3)); + assert_size(3, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 3)); nghttp2_map_remove(&map, 1); - CU_ASSERT(2 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 1)); + assert_size(2, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 1)); /* Erasing non-existent entry */ nghttp2_map_remove(&map, 1); - CU_ASSERT(2 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 1)); + assert_size(2, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 1)); - CU_ASSERT(strcmp("bar", ((strentry *)nghttp2_map_find(&map, 2))->str) == 0); - CU_ASSERT(strcmp("shrubbery", ((strentry *)nghttp2_map_find(&map, 4))->str) == - 0); + assert_string_equal("bar", ((strentry *)nghttp2_map_find(&map, 2))->str); + assert_string_equal("shrubbery", + ((strentry *)nghttp2_map_find(&map, 4))->str); nghttp2_map_free(&map); } @@ -129,21 +141,21 @@ void test_nghttp2_map_functional(void) { shuffle(order, NUM_ENT); for (i = 0; i < NUM_ENT; ++i) { ent = &arr[order[i] - 1]; - CU_ASSERT(0 == nghttp2_map_insert(&map, ent->key, ent)); + assert_int(0, ==, nghttp2_map_insert(&map, ent->key, ent)); } - CU_ASSERT(NUM_ENT == nghttp2_map_size(&map)); + assert_size(NUM_ENT, ==, nghttp2_map_size(&map)); /* traverse */ nghttp2_map_each(&map, eachfun, NULL); /* find */ shuffle(order, NUM_ENT); for (i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(NULL != nghttp2_map_find(&map, (nghttp2_map_key_type)order[i])); + assert_not_null(nghttp2_map_find(&map, (nghttp2_map_key_type)order[i])); } /* remove */ for (i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(0 == nghttp2_map_remove(&map, (nghttp2_map_key_type)order[i])); + assert_int(0, ==, nghttp2_map_remove(&map, (nghttp2_map_key_type)order[i])); } /* each_free (but no op function for testing purpose) */ @@ -153,7 +165,7 @@ void test_nghttp2_map_functional(void) { /* insert once again */ for (i = 0; i < NUM_ENT; ++i) { ent = &arr[i]; - CU_ASSERT(0 == nghttp2_map_insert(&map, ent->key, ent)); + assert_int(0, ==, nghttp2_map_insert(&map, ent->key, ent)); } nghttp2_map_each_free(&map, eachfun, NULL); nghttp2_map_free(&map); @@ -198,11 +210,11 @@ void test_nghttp2_map_clear(void) { nghttp2_map_init(&map, mem); - CU_ASSERT(0 == nghttp2_map_insert(&map, foo.key, &foo)); + assert_int(0, ==, nghttp2_map_insert(&map, foo.key, &foo)); nghttp2_map_clear(&map); - CU_ASSERT(0 == nghttp2_map_size(&map)); + assert_size(0, ==, nghttp2_map_size(&map)); nghttp2_map_free(&map); } diff --git a/yass/third_party/nghttp2/tests/nghttp2_map_test.h b/yass/third_party/nghttp2/tests/nghttp2_map_test.h index 235624de18..ba06175390 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_map_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_map_test.h @@ -30,9 +30,15 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_map(void); -void test_nghttp2_map_functional(void); -void test_nghttp2_map_each_free(void); -void test_nghttp2_map_clear(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite map_suite; + +munit_void_test_decl(test_nghttp2_map); +munit_void_test_decl(test_nghttp2_map_functional); +munit_void_test_decl(test_nghttp2_map_each_free); +munit_void_test_decl(test_nghttp2_map_clear); #endif /* NGHTTP2_MAP_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_pq_test.c b/yass/third_party/nghttp2/tests/nghttp2_pq_test.c index 90db26de39..aa84af12f6 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_pq_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_pq_test.c @@ -26,10 +26,19 @@ #include -#include - #include "nghttp2_pq.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_pq), + munit_void_test(test_nghttp2_pq_update), + munit_void_test(test_nghttp2_pq_remove), + munit_test_end(), +}; + +const MunitSuite pq_suite = { + "/pq", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct { nghttp2_pq_entry ent; const char *s; @@ -59,59 +68,59 @@ void test_nghttp2_pq(void) { string_entry *top; nghttp2_pq_init(&pq, pq_less, nghttp2_mem_default()); - CU_ASSERT(nghttp2_pq_empty(&pq)); - CU_ASSERT(0 == nghttp2_pq_size(&pq)); - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("foo")->ent)); - CU_ASSERT(0 == nghttp2_pq_empty(&pq)); - CU_ASSERT(1 == nghttp2_pq_size(&pq)); + assert_true(nghttp2_pq_empty(&pq)); + assert_size(0, ==, nghttp2_pq_size(&pq)); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("foo")->ent)); + assert_false(nghttp2_pq_empty(&pq)); + assert_size(1, ==, nghttp2_pq_size(&pq)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("foo", top->s) == 0); - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("bar")->ent)); + assert_string_equal("foo", top->s); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("bar")->ent)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("bar", top->s) == 0); - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("baz")->ent)); + assert_string_equal("bar", top->s); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("baz")->ent)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("bar", top->s) == 0); - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("C")->ent)); - CU_ASSERT(4 == nghttp2_pq_size(&pq)); + assert_string_equal("bar", top->s); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("C")->ent)); + assert_size(4, ==, nghttp2_pq_size(&pq)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("C", top->s) == 0); + assert_string_equal("C", top->s); string_entry_del(top); nghttp2_pq_pop(&pq); - CU_ASSERT(3 == nghttp2_pq_size(&pq)); + assert_size(3, ==, nghttp2_pq_size(&pq)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("bar", top->s) == 0); + assert_string_equal("bar", top->s); nghttp2_pq_pop(&pq); string_entry_del(top); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("baz", top->s) == 0); + assert_string_equal("baz", top->s); nghttp2_pq_pop(&pq); string_entry_del(top); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("foo", top->s) == 0); + assert_string_equal("foo", top->s); nghttp2_pq_pop(&pq); string_entry_del(top); - CU_ASSERT(nghttp2_pq_empty(&pq)); - CU_ASSERT(0 == nghttp2_pq_size(&pq)); - CU_ASSERT(NULL == nghttp2_pq_top(&pq)); + assert_true(nghttp2_pq_empty(&pq)); + assert_size(0, ==, nghttp2_pq_size(&pq)); + assert_null(nghttp2_pq_top(&pq)); /* Add bunch of entry to see realloc works */ for (i = 0; i < 10000; ++i) { - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("foo")->ent)); - CU_ASSERT((size_t)(i + 1) == nghttp2_pq_size(&pq)); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("foo")->ent)); + assert_size((size_t)(i + 1), ==, nghttp2_pq_size(&pq)); } for (i = 10000; i > 0; --i) { top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(NULL != top); + assert_not_null(top); nghttp2_pq_pop(&pq); string_entry_del(top); - CU_ASSERT((size_t)(i - 1) == nghttp2_pq_size(&pq)); + assert_size((size_t)(i - 1), ==, nghttp2_pq_size(&pq)); } nghttp2_pq_free(&pq); @@ -160,7 +169,7 @@ void test_nghttp2_pq_update(void) { for (i = 0; i < (int)(sizeof(nodes) / sizeof(nodes[0])); ++i) { nd = (node *)nghttp2_pq_top(&pq); - CU_ASSERT(ans[i] == nd->key); + assert_int(ans[i], ==, nd->key); nghttp2_pq_pop(&pq); } @@ -180,8 +189,8 @@ static void check_nodes(nghttp2_pq *pq, size_t n, int *ans_key, int *ans_val) { size_t i; for (i = 0; i < n; ++i) { node *nd = (node *)nghttp2_pq_top(pq); - CU_ASSERT(ans_key[i] == nd->key); - CU_ASSERT(ans_val[i] == nd->val); + assert_int(ans_key[i], ==, nd->key); + assert_int(ans_val[i], ==, nd->val); nghttp2_pq_pop(pq); } } diff --git a/yass/third_party/nghttp2/tests/nghttp2_pq_test.h b/yass/third_party/nghttp2/tests/nghttp2_pq_test.h index 969662a954..1386528954 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_pq_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_pq_test.h @@ -29,8 +29,14 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_pq(void); -void test_nghttp2_pq_update(void); -void test_nghttp2_pq_remove(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite pq_suite; + +munit_void_test_decl(test_nghttp2_pq); +munit_void_test_decl(test_nghttp2_pq_update); +munit_void_test_decl(test_nghttp2_pq_remove); #endif /* NGHTTP2_PQ_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_queue_test.c b/yass/third_party/nghttp2/tests/nghttp2_queue_test.c index cb993a81b0..9837b61a84 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_queue_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_queue_test.c @@ -26,25 +26,34 @@ #include -#include +#include "munit.h" #include "nghttp2_queue.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_queue), + munit_test_end(), +}; + +const MunitSuite queue_suite = { + "/queue", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_queue(void) { int ints[] = {1, 2, 3, 4, 5}; int i; nghttp2_queue queue; nghttp2_queue_init(&queue); - CU_ASSERT(nghttp2_queue_empty(&queue)); + assert_true(nghttp2_queue_empty(&queue)); for (i = 0; i < 5; ++i) { nghttp2_queue_push(&queue, &ints[i]); - CU_ASSERT_EQUAL(ints[0], *(int *)(nghttp2_queue_front(&queue))); - CU_ASSERT(!nghttp2_queue_empty(&queue)); + assert_int(ints[0], ==, *(int *)(nghttp2_queue_front(&queue))); + assert_false(nghttp2_queue_empty(&queue)); } for (i = 0; i < 5; ++i) { - CU_ASSERT_EQUAL(ints[i], *(int *)(nghttp2_queue_front(&queue))); + assert_int(ints[i], ==, *(int *)(nghttp2_queue_front(&queue))); nghttp2_queue_pop(&queue); } - CU_ASSERT(nghttp2_queue_empty(&queue)); + assert_true(nghttp2_queue_empty(&queue)); nghttp2_queue_free(&queue); } diff --git a/yass/third_party/nghttp2/tests/nghttp2_queue_test.h b/yass/third_party/nghttp2/tests/nghttp2_queue_test.h index 64f8ce85a7..ba33d38f64 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_queue_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_queue_test.h @@ -29,6 +29,12 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_queue(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite queue_suite; + +munit_void_test_decl(test_nghttp2_queue); #endif /* NGHTTP2_QUEUE_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_ratelim_test.c b/yass/third_party/nghttp2/tests/nghttp2_ratelim_test.c index 6abece9529..5be2f22481 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_ratelim_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_ratelim_test.c @@ -26,67 +26,77 @@ #include -#include +#include "munit.h" #include "nghttp2_ratelim.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_ratelim_update), + munit_void_test(test_nghttp2_ratelim_drain), + munit_test_end(), +}; + +const MunitSuite ratelim_suite = { + "/ratelim", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_ratelim_update(void) { nghttp2_ratelim rl; nghttp2_ratelim_init(&rl, 1000, 21); - CU_ASSERT(1000 == rl.val); - CU_ASSERT(1000 == rl.burst); - CU_ASSERT(21 == rl.rate); - CU_ASSERT(0 == rl.tstamp); + assert_uint64(1000, ==, rl.val); + assert_uint64(1000, ==, rl.burst); + assert_uint64(21, ==, rl.rate); + assert_uint64(0, ==, rl.tstamp); nghttp2_ratelim_update(&rl, 999); - CU_ASSERT(1000 == rl.val); - CU_ASSERT(999 == rl.tstamp); + assert_uint64(1000, ==, rl.val); + assert_uint64(999, ==, rl.tstamp); nghttp2_ratelim_drain(&rl, 100); - CU_ASSERT(900 == rl.val); + assert_uint64(900, ==, rl.val); nghttp2_ratelim_update(&rl, 1000); - CU_ASSERT(921 == rl.val); + assert_uint64(921, ==, rl.val); nghttp2_ratelim_update(&rl, 1002); - CU_ASSERT(963 == rl.val); + assert_uint64(963, ==, rl.val); nghttp2_ratelim_update(&rl, 1004); - CU_ASSERT(1000 == rl.val); - CU_ASSERT(1004 == rl.tstamp); + assert_uint64(1000, ==, rl.val); + assert_uint64(1004, ==, rl.tstamp); /* timer skew */ nghttp2_ratelim_init(&rl, 1000, 21); nghttp2_ratelim_update(&rl, 1); - CU_ASSERT(1000 == rl.val); + assert_uint64(1000, ==, rl.val); nghttp2_ratelim_update(&rl, 0); - CU_ASSERT(1000 == rl.val); + assert_uint64(1000, ==, rl.val); /* rate * duration overflow */ nghttp2_ratelim_init(&rl, 1000, 100); nghttp2_ratelim_drain(&rl, 999); - CU_ASSERT(1 == rl.val); + assert_uint64(1, ==, rl.val); nghttp2_ratelim_update(&rl, UINT64_MAX); - CU_ASSERT(1000 == rl.val); + assert_uint64(1000, ==, rl.val); /* val + rate * duration overflow */ nghttp2_ratelim_init(&rl, UINT64_MAX - 1, 2); nghttp2_ratelim_update(&rl, 1); - CU_ASSERT(UINT64_MAX - 1 == rl.val); + assert_uint64(UINT64_MAX - 1, ==, rl.val); } void test_nghttp2_ratelim_drain(void) { @@ -94,8 +104,8 @@ void test_nghttp2_ratelim_drain(void) { nghttp2_ratelim_init(&rl, 100, 7); - CU_ASSERT(-1 == nghttp2_ratelim_drain(&rl, 101)); - CU_ASSERT(0 == nghttp2_ratelim_drain(&rl, 51)); - CU_ASSERT(0 == nghttp2_ratelim_drain(&rl, 49)); - CU_ASSERT(-1 == nghttp2_ratelim_drain(&rl, 1)); + assert_int(-1, ==, nghttp2_ratelim_drain(&rl, 101)); + assert_int(0, ==, nghttp2_ratelim_drain(&rl, 51)); + assert_int(0, ==, nghttp2_ratelim_drain(&rl, 49)); + assert_int(-1, ==, nghttp2_ratelim_drain(&rl, 1)); } diff --git a/yass/third_party/nghttp2/tests/nghttp2_ratelim_test.h b/yass/third_party/nghttp2/tests/nghttp2_ratelim_test.h index 02b2f2b207..fe10fe18f5 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_ratelim_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_ratelim_test.h @@ -29,7 +29,13 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_ratelim_update(void); -void test_nghttp2_ratelim_drain(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite ratelim_suite; + +munit_void_test_decl(test_nghttp2_ratelim_update); +munit_void_test_decl(test_nghttp2_ratelim_drain); #endif /* NGHTTP2_RATELIM_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_session_test.c b/yass/third_party/nghttp2/tests/nghttp2_session_test.c index b1043be2d5..bb505c261f 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_session_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_session_test.c @@ -27,16 +27,179 @@ #include #include -#include +#include "munit.h" #include "nghttp2_session.h" #include "nghttp2_stream.h" #include "nghttp2_net.h" #include "nghttp2_helper.h" #include "nghttp2_test_helper.h" +#include "nghttp2_assertion.h" #include "nghttp2_priority_spec.h" #include "nghttp2_extpri.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_session_recv), + munit_void_test(test_nghttp2_session_recv_invalid_stream_id), + munit_void_test(test_nghttp2_session_recv_invalid_frame), + munit_void_test(test_nghttp2_session_recv_eof), + munit_void_test(test_nghttp2_session_recv_data), + munit_void_test(test_nghttp2_session_recv_data_no_auto_flow_control), + munit_void_test(test_nghttp2_session_recv_continuation), + munit_void_test(test_nghttp2_session_recv_headers_with_priority), + munit_void_test(test_nghttp2_session_recv_headers_with_padding), + munit_void_test(test_nghttp2_session_recv_headers_early_response), + munit_void_test(test_nghttp2_session_recv_headers_for_closed_stream), + munit_void_test(test_nghttp2_session_recv_headers_with_extpri), + munit_void_test(test_nghttp2_session_server_recv_push_response), + munit_void_test(test_nghttp2_session_recv_premature_headers), + munit_void_test(test_nghttp2_session_recv_unknown_frame), + munit_void_test(test_nghttp2_session_recv_unexpected_continuation), + munit_void_test(test_nghttp2_session_recv_settings_header_table_size), + munit_void_test(test_nghttp2_session_recv_too_large_frame_length), + munit_void_test(test_nghttp2_session_recv_extension), + munit_void_test(test_nghttp2_session_recv_altsvc), + munit_void_test(test_nghttp2_session_recv_origin), + munit_void_test(test_nghttp2_session_recv_priority_update), + munit_void_test(test_nghttp2_session_continue), + munit_void_test(test_nghttp2_session_add_frame), + munit_void_test(test_nghttp2_session_on_request_headers_received), + munit_void_test(test_nghttp2_session_on_response_headers_received), + munit_void_test(test_nghttp2_session_on_headers_received), + munit_void_test(test_nghttp2_session_on_push_response_headers_received), + munit_void_test(test_nghttp2_session_on_priority_received), + munit_void_test(test_nghttp2_session_on_rst_stream_received), + munit_void_test(test_nghttp2_session_on_settings_received), + munit_void_test(test_nghttp2_session_on_push_promise_received), + munit_void_test(test_nghttp2_session_on_ping_received), + munit_void_test(test_nghttp2_session_on_goaway_received), + munit_void_test(test_nghttp2_session_on_window_update_received), + munit_void_test(test_nghttp2_session_on_data_received), + munit_void_test(test_nghttp2_session_on_data_received_fail_fast), + munit_void_test(test_nghttp2_session_on_altsvc_received), + munit_void_test(test_nghttp2_session_send_headers_start_stream), + munit_void_test(test_nghttp2_session_send_headers_reply), + munit_void_test(test_nghttp2_session_send_headers_frame_size_error), + munit_void_test(test_nghttp2_session_send_headers_push_reply), + munit_void_test(test_nghttp2_session_send_rst_stream), + munit_void_test(test_nghttp2_session_send_push_promise), + munit_void_test(test_nghttp2_session_is_my_stream_id), + munit_void_test(test_nghttp2_session_upgrade2), + munit_void_test(test_nghttp2_session_reprioritize_stream), + munit_void_test( + test_nghttp2_session_reprioritize_stream_with_idle_stream_dep), + munit_void_test(test_nghttp2_submit_data), + munit_void_test(test_nghttp2_submit_data_read_length_too_large), + munit_void_test(test_nghttp2_submit_data_read_length_smallest), + munit_void_test(test_nghttp2_submit_data_twice), + munit_void_test(test_nghttp2_submit_request_with_data), + munit_void_test(test_nghttp2_submit_request_without_data), + munit_void_test(test_nghttp2_submit_response_with_data), + munit_void_test(test_nghttp2_submit_response_without_data), + munit_void_test(test_nghttp2_submit_response_push_response), + munit_void_test(test_nghttp2_submit_trailer), + munit_void_test(test_nghttp2_submit_headers_start_stream), + munit_void_test(test_nghttp2_submit_headers_reply), + munit_void_test(test_nghttp2_submit_headers_push_reply), + munit_void_test(test_nghttp2_submit_headers), + munit_void_test(test_nghttp2_submit_headers_continuation), + munit_void_test(test_nghttp2_submit_headers_continuation_extra_large), + munit_void_test(test_nghttp2_submit_priority), + munit_void_test(test_nghttp2_submit_settings), + munit_void_test(test_nghttp2_submit_settings_update_local_window_size), + munit_void_test(test_nghttp2_submit_settings_multiple_times), + munit_void_test(test_nghttp2_submit_push_promise), + munit_void_test(test_nghttp2_submit_window_update), + munit_void_test(test_nghttp2_submit_window_update_local_window_size), + munit_void_test(test_nghttp2_submit_shutdown_notice), + munit_void_test(test_nghttp2_submit_invalid_nv), + munit_void_test(test_nghttp2_submit_extension), + munit_void_test(test_nghttp2_submit_altsvc), + munit_void_test(test_nghttp2_submit_origin), + munit_void_test(test_nghttp2_submit_priority_update), + munit_void_test(test_nghttp2_submit_rst_stream), + munit_void_test(test_nghttp2_session_open_stream), + munit_void_test(test_nghttp2_session_open_stream_with_idle_stream_dep), + munit_void_test(test_nghttp2_session_get_next_ob_item), + munit_void_test(test_nghttp2_session_pop_next_ob_item), + munit_void_test(test_nghttp2_session_reply_fail), + munit_void_test(test_nghttp2_session_max_concurrent_streams), + munit_void_test(test_nghttp2_session_stop_data_with_rst_stream), + munit_void_test(test_nghttp2_session_defer_data), + munit_void_test(test_nghttp2_session_flow_control), + munit_void_test(test_nghttp2_session_flow_control_data_recv), + munit_void_test(test_nghttp2_session_flow_control_data_with_padding_recv), + munit_void_test(test_nghttp2_session_data_read_temporal_failure), + munit_void_test(test_nghttp2_session_on_stream_close), + munit_void_test(test_nghttp2_session_on_ctrl_not_send), + munit_void_test(test_nghttp2_session_get_outbound_queue_size), + munit_void_test(test_nghttp2_session_get_effective_local_window_size), + munit_void_test(test_nghttp2_session_set_option), + munit_void_test(test_nghttp2_session_data_backoff_by_high_pri_frame), + munit_void_test(test_nghttp2_session_pack_data_with_padding), + munit_void_test(test_nghttp2_session_pack_headers_with_padding), + munit_void_test(test_nghttp2_pack_settings_payload), + munit_void_test(test_nghttp2_session_stream_dep_add), + munit_void_test(test_nghttp2_session_stream_dep_remove), + munit_void_test(test_nghttp2_session_stream_dep_add_subtree), + munit_void_test(test_nghttp2_session_stream_dep_remove_subtree), + munit_void_test( + test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us), + munit_void_test(test_nghttp2_session_stream_attach_item), + munit_void_test(test_nghttp2_session_stream_attach_item_subtree), + munit_void_test(test_nghttp2_session_stream_get_state), + munit_void_test(test_nghttp2_session_stream_get_something), + munit_void_test(test_nghttp2_session_find_stream), + munit_void_test(test_nghttp2_session_keep_closed_stream), + munit_void_test(test_nghttp2_session_keep_idle_stream), + munit_void_test(test_nghttp2_session_detach_idle_stream), + munit_void_test(test_nghttp2_session_large_dep_tree), + munit_void_test(test_nghttp2_session_graceful_shutdown), + munit_void_test(test_nghttp2_session_on_header_temporal_failure), + munit_void_test(test_nghttp2_session_recv_client_magic), + munit_void_test(test_nghttp2_session_delete_data_item), + munit_void_test(test_nghttp2_session_open_idle_stream), + munit_void_test(test_nghttp2_session_cancel_reserved_remote), + munit_void_test(test_nghttp2_session_reset_pending_headers), + munit_void_test(test_nghttp2_session_send_data_callback), + munit_void_test(test_nghttp2_session_on_begin_headers_temporal_failure), + munit_void_test(test_nghttp2_session_defer_then_close), + munit_void_test(test_nghttp2_session_detach_item_from_closed_stream), + munit_void_test(test_nghttp2_session_flooding), + munit_void_test(test_nghttp2_session_change_stream_priority), + munit_void_test(test_nghttp2_session_change_extpri_stream_priority), + munit_void_test(test_nghttp2_session_create_idle_stream), + munit_void_test(test_nghttp2_session_repeated_priority_change), + munit_void_test(test_nghttp2_session_repeated_priority_submission), + munit_void_test(test_nghttp2_session_set_local_window_size), + munit_void_test(test_nghttp2_session_cancel_from_before_frame_send), + munit_void_test(test_nghttp2_session_too_many_settings), + munit_void_test(test_nghttp2_session_removed_closed_stream), + munit_void_test(test_nghttp2_session_pause_data), + munit_void_test(test_nghttp2_session_no_closed_streams), + munit_void_test(test_nghttp2_session_set_stream_user_data), + munit_void_test(test_nghttp2_session_no_rfc7540_priorities), + munit_void_test(test_nghttp2_session_server_fallback_rfc7540_priorities), + munit_void_test(test_nghttp2_session_stream_reset_ratelim), + munit_void_test(test_nghttp2_http_mandatory_headers), + munit_void_test(test_nghttp2_http_content_length), + munit_void_test(test_nghttp2_http_content_length_mismatch), + munit_void_test(test_nghttp2_http_non_final_response), + munit_void_test(test_nghttp2_http_trailer_headers), + munit_void_test(test_nghttp2_http_ignore_regular_header), + munit_void_test(test_nghttp2_http_ignore_content_length), + munit_void_test(test_nghttp2_http_record_request_method), + munit_void_test(test_nghttp2_http_push_promise), + munit_void_test(test_nghttp2_http_head_method_upgrade_workaround), + munit_void_test( + test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation), + munit_test_end(), +}; + +const MunitSuite session_suite = { + "/session", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct { uint8_t buf[65535]; size_t length; @@ -121,18 +284,20 @@ static void scripted_data_feed_init2(scripted_data_feed *df, df->feedseq[0] = len; } -static ssize_t null_send_callback(nghttp2_session *session, const uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize null_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { (void)session; (void)data; (void)flags; (void)user_data; - return (ssize_t)len; + return (nghttp2_ssize)len; } -static ssize_t fail_send_callback(nghttp2_session *session, const uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize fail_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { (void)session; (void)data; (void)len; @@ -142,19 +307,20 @@ static ssize_t fail_send_callback(nghttp2_session *session, const uint8_t *data, return NGHTTP2_ERR_CALLBACK_FAILURE; } -static ssize_t fixed_bytes_send_callback(nghttp2_session *session, - const uint8_t *data, size_t len, - int flags, void *user_data) { +static nghttp2_ssize fixed_bytes_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { size_t fixed_sendlen = ((my_user_data *)user_data)->fixed_sendlen; (void)session; (void)data; (void)flags; - return (ssize_t)(fixed_sendlen < len ? fixed_sendlen : len); + return (nghttp2_ssize)(fixed_sendlen < len ? fixed_sendlen : len); } -static ssize_t scripted_recv_callback(nghttp2_session *session, uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize scripted_recv_callback(nghttp2_session *session, + uint8_t *data, size_t len, + int flags, void *user_data) { scripted_data_feed *df = ((my_user_data *)user_data)->df; size_t wlen = df->feedseq[df->seqidx] > len ? len : df->feedseq[df->seqidx]; (void)session; @@ -166,11 +332,11 @@ static ssize_t scripted_recv_callback(nghttp2_session *session, uint8_t *data, if (df->feedseq[df->seqidx] == 0) { ++df->seqidx; } - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } -static ssize_t eof_recv_callback(nghttp2_session *session, uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize eof_recv_callback(nghttp2_session *session, uint8_t *data, + size_t len, int flags, void *user_data) { (void)session; (void)data; (void)len; @@ -180,9 +346,9 @@ static ssize_t eof_recv_callback(nghttp2_session *session, uint8_t *data, return NGHTTP2_ERR_EOF; } -static ssize_t accumulator_send_callback(nghttp2_session *session, - const uint8_t *buf, size_t len, - int flags, void *user_data) { +static nghttp2_ssize accumulator_send_callback(nghttp2_session *session, + const uint8_t *buf, size_t len, + int flags, void *user_data) { accumulator *acc = ((my_user_data *)user_data)->acc; (void)session; (void)flags; @@ -190,7 +356,7 @@ static ssize_t accumulator_send_callback(nghttp2_session *session, assert(acc->length + len < sizeof(acc->buf)); memcpy(acc->buf + acc->length, buf, len); acc->length += len; - return (ssize_t)len; + return (nghttp2_ssize)len; } static int on_begin_frame_callback(nghttp2_session *session, @@ -290,16 +456,18 @@ static int pause_on_data_chunk_recv_callback(nghttp2_session *session, return NGHTTP2_ERR_PAUSE; } -static ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, - size_t max_payloadlen, void *user_data) { +static nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payloadlen, + void *user_data) { my_user_data *ud = (my_user_data *)user_data; (void)session; - return (ssize_t)nghttp2_min(max_payloadlen, frame->hd.length + ud->padlen); + return (nghttp2_ssize)nghttp2_min(max_payloadlen, + frame->hd.length + ud->padlen); } -static ssize_t too_large_data_source_length_callback( +static nghttp2_ssize too_large_data_source_length_callback( nghttp2_session *session, uint8_t frame_type, int32_t stream_id, int32_t session_remote_window_size, int32_t stream_remote_window_size, uint32_t remote_max_frame_size, void *user_data) { @@ -314,7 +482,7 @@ static ssize_t too_large_data_source_length_callback( return NGHTTP2_MAX_FRAME_SIZE_MAX + 1; } -static ssize_t smallest_length_data_source_length_callback( +static nghttp2_ssize smallest_length_data_source_length_callback( nghttp2_session *session, uint8_t frame_type, int32_t stream_id, int32_t session_remote_window_size, int32_t stream_remote_window_size, uint32_t remote_max_frame_size, void *user_data) { @@ -329,7 +497,7 @@ static ssize_t smallest_length_data_source_length_callback( return 1; } -static ssize_t fixed_length_data_source_read_callback( +static nghttp2_ssize fixed_length_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { my_user_data *ud = (my_user_data *)user_data; @@ -348,10 +516,10 @@ static ssize_t fixed_length_data_source_read_callback( if (ud->data_source_length == 0) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; } - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } -static ssize_t temporal_failure_data_source_read_callback( +static nghttp2_ssize temporal_failure_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { (void)session; @@ -365,11 +533,10 @@ static ssize_t temporal_failure_data_source_read_callback( return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } -static ssize_t fail_data_source_read_callback(nghttp2_session *session, - int32_t stream_id, uint8_t *buf, - size_t len, uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) { +static nghttp2_ssize +fail_data_source_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t len, uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { (void)session; (void)stream_id; (void)buf; @@ -381,7 +548,7 @@ static ssize_t fail_data_source_read_callback(nghttp2_session *session, return NGHTTP2_ERR_CALLBACK_FAILURE; } -static ssize_t no_end_stream_data_source_read_callback( +static nghttp2_ssize no_end_stream_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { (void)session; @@ -395,7 +562,7 @@ static ssize_t no_end_stream_data_source_read_callback( return 0; } -static ssize_t no_copy_data_source_read_callback( +static nghttp2_ssize no_copy_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { my_user_data *ud = (my_user_data *)user_data; @@ -418,7 +585,7 @@ static ssize_t no_copy_data_source_read_callback( if (ud->data_source_length == 0) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; } - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } static int send_data_callback(nghttp2_session *session, nghttp2_frame *frame, @@ -444,9 +611,9 @@ static int send_data_callback(nghttp2_session *session, nghttp2_frame *frame, return 0; } -static ssize_t block_count_send_callback(nghttp2_session *session, - const uint8_t *data, size_t len, - int flags, void *user_data) { +static nghttp2_ssize block_count_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { my_user_data *ud = (my_user_data *)user_data; (void)session; (void)data; @@ -457,7 +624,7 @@ static ssize_t block_count_send_callback(nghttp2_session *session, } --ud->block_count; - return (ssize_t)len; + return (nghttp2_ssize)len; } static int on_header_callback(nghttp2_session *session, @@ -555,11 +722,10 @@ static int temporal_failure_on_begin_headers_callback( return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } -static ssize_t defer_data_source_read_callback(nghttp2_session *session, - int32_t stream_id, uint8_t *buf, - size_t len, uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) { +static nghttp2_ssize +defer_data_source_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t len, uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { (void)session; (void)stream_id; (void)buf; @@ -593,9 +759,10 @@ static int fatal_error_on_stream_close_callback(nghttp2_session *session, return NGHTTP2_ERR_CALLBACK_FAILURE; } -static ssize_t pack_extension_callback(nghttp2_session *session, uint8_t *buf, - size_t len, const nghttp2_frame *frame, - void *user_data) { +static nghttp2_ssize pack_extension_callback(nghttp2_session *session, + uint8_t *buf, size_t len, + const nghttp2_frame *frame, + void *user_data) { nghttp2_buf *p = frame->ext.payload; (void)session; (void)len; @@ -603,7 +770,7 @@ static ssize_t pack_extension_callback(nghttp2_session *session, uint8_t *buf, memcpy(buf, p->pos, nghttp2_buf_len(p)); - return (ssize_t)nghttp2_buf_len(p); + return (nghttp2_ssize)nghttp2_buf_len(p); } static int on_extension_chunk_recv_callback(nghttp2_session *session, @@ -686,8 +853,8 @@ void test_nghttp2_session_recv(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.recv_callback = scripted_recv_callback; + callbacks.send_callback2 = null_send_callback; + callbacks.recv_callback2 = scripted_recv_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; callbacks.on_begin_frame_callback = on_begin_frame_callback; @@ -702,7 +869,7 @@ void test_nghttp2_session_recv(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); scripted_data_feed_init2(&df, &bufs); @@ -719,10 +886,10 @@ void test_nghttp2_session_recv(void) { user_data.begin_frame_cb_called = 0; while (df.seqidx < framelen) { - CU_ASSERT(0 == nghttp2_session_recv(session)); + assert_int(0, ==, nghttp2_session_recv(session)); } - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(1 == user_data.begin_frame_cb_called); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int(1, ==, user_data.begin_frame_cb_called); nghttp2_bufs_reset(&bufs); @@ -738,9 +905,9 @@ void test_nghttp2_session_recv(void) { user_data.frame_recv_cb_called = 0; user_data.begin_frame_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(1 == user_data.begin_frame_cb_called); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int(1, ==, user_data.begin_frame_cb_called); nghttp2_bufs_reset(&bufs); @@ -770,14 +937,14 @@ void test_nghttp2_session_recv(void) { user_data.frame_recv_cb_called = 0; user_data.begin_frame_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(0 == user_data.frame_recv_cb_called); - CU_ASSERT(0 == user_data.begin_frame_cb_called); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(0, ==, user_data.frame_recv_cb_called); + assert_int(0, ==, user_data.begin_frame_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_FRAME_SIZE_ERROR == item->frame.goaway.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_FRAME_SIZE_ERROR, ==, item->frame.goaway.error_code); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_free(&bufs); nghttp2_session_del(session); @@ -800,7 +967,7 @@ void test_nghttp2_session_recv_invalid_stream_id(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.recv_callback = scripted_recv_callback; + callbacks.recv_callback2 = scripted_recv_callback; callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; user_data.df = &df; @@ -814,14 +981,14 @@ void test_nghttp2_session_recv_invalid_stream_id(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); scripted_data_feed_init2(&df, &bufs); nghttp2_frame_headers_free(&frame.headers, mem); - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -845,8 +1012,8 @@ void test_nghttp2_session_recv_invalid_frame(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.recv_callback = scripted_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.recv_callback2 = scripted_recv_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; user_data.df = &df; @@ -859,23 +1026,23 @@ void test_nghttp2_session_recv_invalid_frame(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); scripted_data_feed_init2(&df, &bufs); - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == user_data.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, user_data.frame_send_cb_called); /* Receive exactly same bytes of HEADERS is treated as error, because it has * pseudo headers and without END_STREAM flag set */ scripted_data_feed_init2(&df, &bufs); - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_send_cb_called); - CU_ASSERT(NGHTTP2_RST_STREAM == user_data.sent_frame_type); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_send_cb_called); + assert_uint8(NGHTTP2_RST_STREAM, ==, user_data.sent_frame_type); nghttp2_bufs_free(&bufs); nghttp2_frame_headers_free(&frame.headers, mem); @@ -889,11 +1056,11 @@ void test_nghttp2_session_recv_eof(void) { nghttp2_session_callbacks callbacks; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.recv_callback = eof_recv_callback; + callbacks.send_callback2 = null_send_callback; + callbacks.recv_callback2 = eof_recv_callback; nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(NGHTTP2_ERR_EOF == nghttp2_session_recv(session)); + assert_int(NGHTTP2_ERR_EOF, ==, nghttp2_session_recv(session)); nghttp2_session_del(session); } @@ -903,14 +1070,14 @@ void test_nghttp2_session_recv_data(void) { nghttp2_session_callbacks callbacks; my_user_data ud; uint8_t data[8092]; - ssize_t rv; + nghttp2_ssize rv; nghttp2_outbound_item *item; nghttp2_stream *stream; nghttp2_frame_hd hd; int i; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; callbacks.on_frame_send_callback = on_frame_send_callback; @@ -929,13 +1096,13 @@ void test_nghttp2_session_recv_data(void) { error. This is not mandated by the spec */ ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); - CU_ASSERT(0 == ud.data_chunk_recv_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, ud.data_chunk_recv_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); @@ -950,40 +1117,40 @@ void test_nghttp2_session_recv_data(void) { ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); - CU_ASSERT(0 == ud.data_chunk_recv_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, ud.data_chunk_recv_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); /* This is normal case. DATA is acceptable. */ stream->state = NGHTTP2_STREAM_OPENED; ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); - CU_ASSERT(1 == ud.data_chunk_recv_cb_called); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_int(1, ==, ud.data_chunk_recv_cb_called); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); /* Now we got data more than initial-window-size / 2, WINDOW_UPDATE must be queued */ - CU_ASSERT(1 == ud.data_chunk_recv_cb_called); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_int(1, ==, ud.data_chunk_recv_cb_called); + assert_int(1, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(1 == item->frame.window_update.hd.stream_id); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.window_update.hd.stream_id); + assert_int(0, ==, nghttp2_session_send(session)); /* Set initial window size to 1MiB, so that we can check connection flow control individually */ @@ -993,13 +1160,13 @@ void test_nghttp2_session_recv_data(void) { DATA. Additional 4 DATA frames, connection flow control will kick in. */ for (i = 0; i < 5; ++i) { - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); } item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.window_update.hd.stream_id); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.window_update.hd.stream_id); + assert_int(0, ==, nghttp2_session_send(session)); /* Reception of DATA with stream ID = 0 causes connection error */ hd.length = 4096; @@ -1010,14 +1177,14 @@ void test_nghttp2_session_recv_data(void) { ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); - CU_ASSERT(0 == ud.data_chunk_recv_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, ud.data_chunk_recv_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_session_del(session); @@ -1036,20 +1203,20 @@ void test_nghttp2_session_recv_data(void) { it triggers first WINDOW_UPDATE of window_size_increment 32767. */ for (i = 0; i < 7; ++i) { - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); } hd.length = 4095; nghttp2_frame_pack_frame_hd(data, &hd); - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4095); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4095 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4095); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4095, ==, rv); /* Now 2 WINDOW_UPDATEs for session and stream should be queued. */ - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(1 == stream->window_update_queued); - CU_ASSERT(1 == session->window_update_queued); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(0, ==, session->recv_window_size); + assert_true(stream->window_update_queued); + assert_true(session->window_update_queued); /* Then send 32768 bytes of DATA. Since we have not sent queued WINDOW_UDPATE frame, recv_window_size should not be decreased */ @@ -1057,29 +1224,29 @@ void test_nghttp2_session_recv_data(void) { nghttp2_frame_pack_frame_hd(data, &hd); for (i = 0; i < 8; ++i) { - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); } /* WINDOW_UPDATE is blocked for session and stream, so recv_window_size must not be decreased. */ - CU_ASSERT(32768 == stream->recv_window_size); - CU_ASSERT(32768 == session->recv_window_size); - CU_ASSERT(1 == stream->window_update_queued); - CU_ASSERT(1 == session->window_update_queued); + assert_int32(32768, ==, stream->recv_window_size); + assert_int32(32768, ==, session->recv_window_size); + assert_true(stream->window_update_queued); + assert_true(session->window_update_queued); ud.frame_send_cb_called = 0; /* This sends queued WINDOW_UPDATES. And then check recv_window_size, and queue WINDOW_UPDATEs for both session and stream, and send them at once. */ - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(4 == ud.frame_send_cb_called); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(0 == stream->window_update_queued); - CU_ASSERT(0 == session->window_update_queued); + assert_int(4, ==, ud.frame_send_cb_called); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(0, ==, session->recv_window_size); + assert_false(stream->window_update_queued); + assert_false(session->window_update_queued); nghttp2_session_del(session); } @@ -1092,13 +1259,13 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { nghttp2_frame_hd hd; size_t padlen; uint8_t data[8192]; - ssize_t rv; + nghttp2_ssize rv; size_t sendlen; nghttp2_stream *stream; size_t i; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; nghttp2_option_new(&option); @@ -1122,11 +1289,11 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { /* Receive first 100 bytes */ sendlen = 100; - rv = nghttp2_session_mem_recv(session, data, sendlen); - CU_ASSERT((ssize_t)sendlen == rv); + rv = nghttp2_session_mem_recv2(session, data, sendlen); + assert_ptrdiff((nghttp2_ssize)sendlen, ==, rv); /* We consumed pad length field (1 byte) */ - CU_ASSERT(1 == session->consumed_size); + assert_int32(1, ==, session->consumed_size); /* close stream here */ nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); @@ -1134,13 +1301,14 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { /* stream 1 has been closed, and we disabled auto flow-control, so data must be immediately consumed for connection. */ - rv = nghttp2_session_mem_recv(session, data + sendlen, - NGHTTP2_FRAME_HDLEN + hd.length - sendlen); - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen) == rv); + rv = nghttp2_session_mem_recv2(session, data + sendlen, + NGHTTP2_FRAME_HDLEN + hd.length - sendlen); + assert_ptrdiff((nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen), ==, + rv); /* We already consumed pad length field (1 byte), so do +1 here */ - CU_ASSERT((int32_t)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen + 1) == - session->consumed_size); + assert_int32((int32_t)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen + 1), ==, + session->consumed_size); nghttp2_session_del(session); @@ -1153,12 +1321,13 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { stream = open_recv_stream(session, 1); stream->http_flags |= NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + hd.length); - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length) == rv); + rv = + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + hd.length); + assert_ptrdiff((nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + hd.length), ==, rv); /* Whole payload must be consumed now because HTTP messaging rule was not honored. */ - CU_ASSERT((int32_t)hd.length == session->consumed_size); + assert_int32((int32_t)hd.length, ==, session->consumed_size); nghttp2_session_del(session); @@ -1175,57 +1344,57 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { /* Receive up to 65535 bytes of DATA */ for (i = 0; i < 15; ++i) { - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); } hd.length = 4095; nghttp2_frame_pack_frame_hd(data, &hd); - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4095); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4095 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4095); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4095, ==, rv); - CU_ASSERT(65535 == session->recv_window_size); - CU_ASSERT(65535 == stream->recv_window_size); + assert_int32(65535, ==, session->recv_window_size); + assert_int32(65535, ==, stream->recv_window_size); /* The first call of nghttp2_session_consume_connection() will queue WINDOW_UPDATE. Next call does not. */ nghttp2_session_consume_connection(session, 32767); nghttp2_session_consume_connection(session, 32768); - CU_ASSERT(32768 == session->recv_window_size); - CU_ASSERT(65535 == stream->recv_window_size); - CU_ASSERT(1 == session->window_update_queued); - CU_ASSERT(0 == stream->window_update_queued); + assert_int32(32768, ==, session->recv_window_size); + assert_int32(65535, ==, stream->recv_window_size); + assert_true(session->window_update_queued); + assert_false(stream->window_update_queued); ud.frame_send_cb_called = 0; /* This will send WINDOW_UPDATE, and check whether we should send WINDOW_UPDATE, and queue and send it at once. */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(65535 == stream->recv_window_size); - CU_ASSERT(0 == session->window_update_queued); - CU_ASSERT(0 == stream->window_update_queued); - CU_ASSERT(2 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(0, ==, session->recv_window_size); + assert_int32(65535, ==, stream->recv_window_size); + assert_false(session->window_update_queued); + assert_false(stream->window_update_queued); + assert_int(2, ==, ud.frame_send_cb_called); /* Do the same for stream */ nghttp2_session_consume_stream(session, 1, 32767); nghttp2_session_consume_stream(session, 1, 32768); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(32768 == stream->recv_window_size); - CU_ASSERT(0 == session->window_update_queued); - CU_ASSERT(1 == stream->window_update_queued); + assert_int32(0, ==, session->recv_window_size); + assert_int32(32768, ==, stream->recv_window_size); + assert_false(session->window_update_queued); + assert_true(stream->window_update_queued); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == session->window_update_queued); - CU_ASSERT(0 == stream->window_update_queued); - CU_ASSERT(2 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(0, ==, session->recv_window_size); + assert_int32(0, ==, stream->recv_window_size); + assert_false(session->window_update_queued); + assert_false(stream->window_update_queued); + assert_int(2, ==, ud.frame_send_cb_called); nghttp2_session_del(session); nghttp2_option_del(option); @@ -1239,7 +1408,7 @@ void test_nghttp2_session_recv_continuation(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_hd_deflater deflater; uint8_t data[1024]; @@ -1267,8 +1436,8 @@ void test_nghttp2_session_recv_continuation(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); /* make sure that all data is in the first buf */ buf = &bufs.head->buf; @@ -1305,15 +1474,15 @@ void test_nghttp2_session_recv_continuation(void) { datalen += cont_hd.length; buf->pos += cont_hd.length; - CU_ASSERT(0 == nghttp2_buf_len(buf)); + assert_size(0, ==, nghttp2_buf_len(buf)); ud.header_cb_called = 0; ud.begin_frame_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, datalen); - CU_ASSERT((ssize_t)datalen == rv); - CU_ASSERT(4 == ud.header_cb_called); - CU_ASSERT(3 == ud.begin_frame_cb_called); + rv = nghttp2_session_mem_recv2(session, data, datalen); + assert_ptrdiff((nghttp2_ssize)datalen, ==, rv); + assert_int(4, ==, ud.header_cb_called); + assert_int(3, ==, ud.begin_frame_cb_called); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1331,7 +1500,7 @@ void test_nghttp2_session_recv_continuation(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1361,16 +1530,16 @@ void test_nghttp2_session_recv_continuation(void) { datalen += cont_hd.length; buf->pos += cont_hd.length; - CU_ASSERT(0 == nghttp2_buf_len(buf)); + assert_size(0, ==, nghttp2_buf_len(buf)); ud.header_cb_called = 0; ud.begin_frame_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, datalen); + rv = nghttp2_session_mem_recv2(session, data, datalen); - CU_ASSERT((ssize_t)datalen == rv); - CU_ASSERT(4 == ud.header_cb_called); - CU_ASSERT(2 == ud.begin_frame_cb_called); + assert_ptrdiff((nghttp2_ssize)datalen, ==, rv); + assert_int(4, ==, ud.header_cb_called); + assert_int(2, ==, ud.begin_frame_cb_called); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1388,8 +1557,8 @@ void test_nghttp2_session_recv_continuation(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1408,18 +1577,18 @@ void test_nghttp2_session_recv_continuation(void) { nghttp2_frame_pack_priority(&bufs, &frame.priority); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_size(0, <, nghttp2_bufs_len(&bufs)); memcpy(data + datalen, buf->pos, nghttp2_buf_len(buf)); datalen += nghttp2_buf_len(buf); ud.begin_headers_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, datalen); - CU_ASSERT((ssize_t)datalen == rv); + rv = nghttp2_session_mem_recv2(session, data, datalen); + assert_ptrdiff((nghttp2_ssize)datalen, ==, rv); - CU_ASSERT(1 == ud.begin_headers_cb_called); - CU_ASSERT(NGHTTP2_GOAWAY == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_int(1, ==, ud.begin_headers_cb_called); + assert_uint8(NGHTTP2_GOAWAY, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -1434,7 +1603,7 @@ void test_nghttp2_session_recv_headers_with_priority(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_hd_deflater deflater; nghttp2_outbound_item *item; @@ -1466,8 +1635,8 @@ void test_nghttp2_session_recv_headers_with_priority(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1476,15 +1645,15 @@ void test_nghttp2_session_recv_headers_with_priority(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream(session, 3); - CU_ASSERT(99 == stream->weight); - CU_ASSERT(1 == stream->dep_prev->stream_id); + assert_int32(99, ==, stream->weight); + assert_int32(1, ==, stream->dep_prev->stream_id); nghttp2_bufs_reset(&bufs); @@ -1501,8 +1670,8 @@ void test_nghttp2_session_recv_headers_with_priority(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > NGHTTP2_FRAME_HDLEN + 5); + assert_ptrdiff(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + 5, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1513,19 +1682,19 @@ void test_nghttp2_session_recv_headers_with_priority(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream(session, 5); - CU_ASSERT(NULL == stream); + assert_null(stream); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_FRAME_SIZE_ERROR == item->frame.goaway.error_code); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_FRAME_SIZE_ERROR, ==, item->frame.goaway.error_code); nghttp2_bufs_reset(&bufs); @@ -1548,8 +1717,8 @@ void test_nghttp2_session_recv_headers_with_priority(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1558,19 +1727,19 @@ void test_nghttp2_session_recv_headers_with_priority(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NULL == stream); + assert_null(stream); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_bufs_reset(&bufs); @@ -1587,13 +1756,13 @@ void test_nghttp2_session_recv_headers_with_padding(void) { nghttp2_frame_hd hd; nghttp2_outbound_item *item; my_user_data ud; - ssize_t rv; + nghttp2_ssize rv; frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* HEADERS: Wrong padding length */ nghttp2_session_server_new(&session, &callbacks, &ud); @@ -1618,15 +1787,15 @@ void test_nghttp2_session_recv_headers_with_padding(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_bufs_reset(&bufs); nghttp2_session_del(session); @@ -1653,15 +1822,15 @@ void test_nghttp2_session_recv_headers_with_padding(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_bufs_free(&bufs); nghttp2_session_del(session); @@ -1677,10 +1846,10 @@ static int response_on_begin_frame_callback(nghttp2_session *session, return 0; } - rv = nghttp2_submit_response(session, hd->stream_id, resnv, ARRLEN(resnv), - NULL); + rv = nghttp2_submit_response2(session, hd->stream_id, resnv, ARRLEN(resnv), + NULL); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); return 0; } @@ -1695,14 +1864,14 @@ void test_nghttp2_session_recv_headers_early_response(void) { nghttp2_nv *nva; size_t nvlen; nghttp2_frame frame; - ssize_t rv; + nghttp2_ssize rv; nghttp2_stream *stream; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_begin_frame_callback = response_on_begin_frame_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -1717,7 +1886,7 @@ void test_nghttp2_session_recv_headers_early_response(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1725,22 +1894,22 @@ void test_nghttp2_session_recv_headers_early_response(void) { /* Only receive 9 bytes headers, and invoke on_begin_frame_callback */ - rv = nghttp2_session_mem_recv(session, buf->pos, 9); + rv = nghttp2_session_mem_recv2(session, buf->pos, 9); - CU_ASSERT(9 == rv); + assert_ptrdiff(9, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = - nghttp2_session_mem_recv(session, buf->pos + 9, nghttp2_buf_len(buf) - 9); + rv = nghttp2_session_mem_recv2(session, buf->pos + 9, + nghttp2_buf_len(buf) - 9); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) - 9 == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf) - 9, ==, rv); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(stream->flags & NGHTTP2_STREAM_FLAG_CLOSED); + assert_true(stream->flags & NGHTTP2_STREAM_FLAG_CLOSED); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1755,7 +1924,7 @@ void test_nghttp2_session_recv_headers_for_closed_stream(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_hd_deflater deflater; nghttp2_stream *stream; @@ -1783,8 +1952,8 @@ void test_nghttp2_session_recv_headers_for_closed_stream(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1794,38 +1963,39 @@ void test_nghttp2_session_recv_headers_for_closed_stream(void) { ud.header_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, NGHTTP2_FRAME_HDLEN); + rv = nghttp2_session_mem_recv2(session, buf->pos, NGHTTP2_FRAME_HDLEN); - CU_ASSERT(NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(0 == ud.header_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN, ==, rv); + assert_int(0, ==, ud.header_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NULL != stream); + assert_not_null(stream); rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_send(session, &data); + rv = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(rv > 0); + assert_ptrdiff(0, <, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NULL == stream); + assert_null(stream); ud.header_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos + NGHTTP2_FRAME_HDLEN, - nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN); + rv = nghttp2_session_mem_recv2(session, buf->pos + NGHTTP2_FRAME_HDLEN, + nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(0 == ud.header_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN, ==, + rv); + assert_int(0, ==, ud.header_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -1840,7 +2010,7 @@ void test_nghttp2_session_recv_headers_with_extpri(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; nghttp2_hd_deflater deflater; nghttp2_stream *stream; nghttp2_mem *mem; @@ -1873,20 +2043,20 @@ void test_nghttp2_session_recv_headers_with_extpri(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); buf = &bufs.head->buf; assert(nghttp2_bufs_len(&bufs) == nghttp2_buf_len(buf)); - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(2 == nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_uint32(2, ==, nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1911,22 +2081,22 @@ void test_nghttp2_session_recv_headers_with_extpri(void) { rv = nghttp2_frame_pack_push_promise(&bufs, &frame.push_promise, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_push_promise_free(&frame.push_promise, mem); buf = &bufs.head->buf; assert(nghttp2_bufs_len(&bufs) == nghttp2_buf_len(buf)); - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_EXTPRI_DEFAULT_URGENCY == - nghttp2_extpri_uint8_urgency(stream->http_extpri)); - CU_ASSERT(NGHTTP2_EXTPRI_DEFAULT_URGENCY == - nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, + nghttp2_extpri_uint8_urgency(stream->http_extpri)); + assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, + nghttp2_extpri_uint8_urgency(stream->extpri)); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1938,7 +2108,7 @@ void test_nghttp2_session_server_recv_push_response(void) { nghttp2_session_callbacks callbacks; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_mem *mem; nghttp2_frame frame; @@ -1965,8 +2135,8 @@ void test_nghttp2_session_server_recv_push_response(void) { nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1974,10 +2144,10 @@ void test_nghttp2_session_server_recv_push_response(void) { ud.invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.invalid_frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.invalid_frame_recv_cb_called); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -1989,7 +2159,7 @@ void test_nghttp2_session_recv_premature_headers(void) { nghttp2_session_callbacks callbacks; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_hd_deflater deflater; nghttp2_outbound_item *item; @@ -2000,7 +2170,7 @@ void test_nghttp2_session_recv_premature_headers(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); @@ -2013,17 +2183,18 @@ void test_nghttp2_session_recv_premature_headers(void) { /* Intentionally feed payload cutting last 1 byte off */ payloadlen = nghttp2_get_uint32(buf->pos) >> 8; nghttp2_put_uint32be(buf->pos, ((payloadlen - 1) << 8) + buf->pos[3]); - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf) - 1); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf) - 1); - CU_ASSERT((ssize_t)(nghttp2_buf_len(buf) - 1) == rv); + assert_ptrdiff((nghttp2_ssize)(nghttp2_buf_len(buf) - 1), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_COMPRESSION_ERROR == item->frame.rst_stream.error_code); - CU_ASSERT(1 == item->frame.hd.stream_id); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_COMPRESSION_ERROR, ==, + item->frame.rst_stream.error_code); + assert_int32(1, ==, item->frame.hd.stream_id); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -2039,23 +2210,24 @@ void test_nghttp2_session_recv_premature_headers(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); buf = &bufs.head->buf; payloadlen = nghttp2_get_uint32(buf->pos) >> 8; /* Intentionally feed payload cutting last 1 byte off */ nghttp2_put_uint32be(buf->pos, ((payloadlen - 1) << 8) + buf->pos[3]); - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf) - 1); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf) - 1); - CU_ASSERT((ssize_t)(nghttp2_buf_len(buf) - 1) == rv); + assert_ptrdiff((nghttp2_ssize)(nghttp2_buf_len(buf) - 1), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_COMPRESSION_ERROR == item->frame.rst_stream.error_code); - CU_ASSERT(2 == item->frame.hd.stream_id); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_COMPRESSION_ERROR, ==, + item->frame.rst_stream.error_code); + assert_int32(2, ==, item->frame.hd.stream_id); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -2069,7 +2241,7 @@ void test_nghttp2_session_recv_unknown_frame(void) { uint8_t data[16384]; size_t datalen; nghttp2_frame_hd hd; - ssize_t rv; + nghttp2_ssize rv; nghttp2_frame_hd_init(&hd, 16000, 99, NGHTTP2_FLAG_NONE, 0); @@ -2084,11 +2256,11 @@ void test_nghttp2_session_recv_unknown_frame(void) { ud.frame_recv_cb_called = 0; /* Unknown frame must be ignored */ - rv = nghttp2_session_mem_recv(session, data, datalen); + rv = nghttp2_session_mem_recv2(session, data, datalen); - CU_ASSERT(rv == (ssize_t)datalen); - CU_ASSERT(0 == ud.frame_recv_cb_called); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_ptrdiff(rv, ==, (nghttp2_ssize)datalen); + assert_int(0, ==, ud.frame_recv_cb_called); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_session_del(session); } @@ -2100,7 +2272,7 @@ void test_nghttp2_session_recv_unexpected_continuation(void) { uint8_t data[16384]; size_t datalen; nghttp2_frame_hd hd; - ssize_t rv; + nghttp2_ssize rv; nghttp2_outbound_item *item; nghttp2_frame_hd_init(&hd, 16000, NGHTTP2_CONTINUATION, @@ -2119,14 +2291,14 @@ void test_nghttp2_session_recv_unexpected_continuation(void) { ud.frame_recv_cb_called = 0; /* unexpected CONTINUATION must be treated as connection error */ - rv = nghttp2_session_mem_recv(session, data, datalen); + rv = nghttp2_session_mem_recv2(session, data, datalen); - CU_ASSERT(rv == (ssize_t)datalen); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff(rv, ==, (nghttp2_ssize)datalen); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); } @@ -2137,7 +2309,7 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_settings_entry iv[3]; nghttp2_nv nv = MAKE_NV(":authority", "example.org"); @@ -2148,7 +2320,7 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); @@ -2163,8 +2335,8 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -2173,13 +2345,13 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(3000 == session->remote_settings.header_table_size); - CU_ASSERT(16384 == session->remote_settings.initial_window_size); + assert_uint32(3000, ==, session->remote_settings.header_table_size); + assert_uint32(16384, ==, session->remote_settings.initial_window_size); nghttp2_bufs_reset(&bufs); @@ -2198,8 +2370,8 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -2208,23 +2380,23 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)(nghttp2_buf_len(buf)) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)(nghttp2_buf_len(buf)), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(3001 == session->remote_settings.header_table_size); - CU_ASSERT(16383 == session->remote_settings.initial_window_size); + assert_uint32(3001, ==, session->remote_settings.header_table_size); + assert_uint32(16383, ==, session->remote_settings.initial_window_size); nghttp2_bufs_reset(&bufs); /* 2 SETTINGS_HEADER_TABLE_SIZE; first entry clears dynamic header table. */ - nghttp2_submit_request(session, NULL, &nv, 1, NULL, NULL); + nghttp2_submit_request2(session, NULL, &nv, 1, NULL, NULL); nghttp2_session_send(session); - CU_ASSERT(0 < session->hd_deflater.ctx.hd_table.len); + assert_size(0, <, session->hd_deflater.ctx.hd_table.len); iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[0].value = 0; @@ -2240,8 +2412,8 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -2250,24 +2422,24 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(4096 == session->remote_settings.header_table_size); - CU_ASSERT(16382 == session->remote_settings.initial_window_size); - CU_ASSERT(0 == session->hd_deflater.ctx.hd_table.len); + assert_uint32(4096, ==, session->remote_settings.header_table_size); + assert_uint32(16382, ==, session->remote_settings.initial_window_size); + assert_size(0, ==, session->hd_deflater.ctx.hd_table.len); nghttp2_bufs_reset(&bufs); /* 2 SETTINGS_HEADER_TABLE_SIZE; second entry clears dynamic header table. */ - nghttp2_submit_request(session, NULL, &nv, 1, NULL, NULL); + nghttp2_submit_request2(session, NULL, &nv, 1, NULL, NULL); nghttp2_session_send(session); - CU_ASSERT(0 < session->hd_deflater.ctx.hd_table.len); + assert_size(0, <, session->hd_deflater.ctx.hd_table.len); iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[0].value = 3000; @@ -2283,8 +2455,8 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -2293,14 +2465,14 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(0 == session->remote_settings.header_table_size); - CU_ASSERT(16381 == session->remote_settings.initial_window_size); - CU_ASSERT(0 == session->hd_deflater.ctx.hd_table.len); + assert_uint32(0, ==, session->remote_settings.header_table_size); + assert_uint32(16381, ==, session->remote_settings.initial_window_size); + assert_size(0, ==, session->hd_deflater.ctx.hd_table.len); nghttp2_bufs_reset(&bufs); @@ -2325,12 +2497,13 @@ void test_nghttp2_session_recv_too_large_frame_length(void) { nghttp2_frame_pack_frame_hd(buf, &hd); - CU_ASSERT(sizeof(buf) == nghttp2_session_mem_recv(session, buf, sizeof(buf))); + assert_ptrdiff(sizeof(buf), ==, + nghttp2_session_mem_recv2(session, buf, sizeof(buf))); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item != NULL); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); } @@ -2343,7 +2516,7 @@ void test_nghttp2_session_recv_extension(void) { nghttp2_frame_hd hd; nghttp2_mem *mem; const char data[] = "Hello World!"; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; mem = nghttp2_mem_default(); @@ -2368,13 +2541,13 @@ void test_nghttp2_session_recv_extension(void) { nghttp2_session_client_new2(&session, &callbacks, &ud, option); nghttp2_frame_hd_init(&ud.recv_frame_hd, 0, 0, 0, 0); - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + hd.length == (size_t)rv); - CU_ASSERT(111 == ud.recv_frame_hd.type); - CU_ASSERT(0xab == ud.recv_frame_hd.flags); - CU_ASSERT(1000000007 == ud.recv_frame_hd.stream_id); - CU_ASSERT(0 == memcmp(data, ud.scratchbuf.pos, sizeof(data))); + assert_size(NGHTTP2_FRAME_HDLEN + hd.length, ==, (size_t)rv); + assert_uint8(111, ==, ud.recv_frame_hd.type); + assert_uint8(0xab, ==, ud.recv_frame_hd.flags); + assert_int32(1000000007, ==, ud.recv_frame_hd.stream_id); + assert_memory_equal(sizeof(data), data, ud.scratchbuf.pos); nghttp2_session_del(session); @@ -2387,10 +2560,10 @@ void test_nghttp2_session_recv_extension(void) { nghttp2_session_server_new2(&session, &callbacks, &ud, option); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + hd.length == (size_t)rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_size(NGHTTP2_FRAME_HDLEN + hd.length, ==, (size_t)rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2403,10 +2576,10 @@ void test_nghttp2_session_recv_extension(void) { nghttp2_session_server_new2(&session, &callbacks, &ud, option); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + hd.length == (size_t)rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_size(NGHTTP2_FRAME_HDLEN + hd.length, ==, (size_t)rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2423,7 +2596,7 @@ void test_nghttp2_session_recv_altsvc(void) { nghttp2_buf buf; nghttp2_frame_hd hd; nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; static const uint8_t origin[] = "nghttp2.org"; static const uint8_t field_value[] = "h2=\":443\""; @@ -2453,13 +2626,13 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_ALTSVC == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == ud.recv_frame_hd.flags); - CU_ASSERT(0 == ud.recv_frame_hd.stream_id); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_ALTSVC, ==, ud.recv_frame_hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, ud.recv_frame_hd.flags); + assert_int32(0, ==, ud.recv_frame_hd.stream_id); nghttp2_session_del(session); @@ -2477,10 +2650,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, origin, sizeof(origin) - 1 - 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2498,10 +2671,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, origin, sizeof(origin) - 1); ud.invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.invalid_frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.invalid_frame_recv_cb_called); nghttp2_session_del(session); @@ -2522,10 +2695,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1); ud.invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.invalid_frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.invalid_frame_recv_cb_called); nghttp2_session_del(session); @@ -2543,10 +2716,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1); ud.invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.invalid_frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.invalid_frame_recv_cb_called); nghttp2_session_del(session); @@ -2566,12 +2739,12 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last += nghttp2_buf_avail(&buf); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_ALTSVC == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_MAX_FRAME_SIZE_MIN == ud.recv_frame_hd.length); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_ALTSVC, ==, ud.recv_frame_hd.type); + assert_size(NGHTTP2_MAX_FRAME_SIZE_MIN, ==, ud.recv_frame_hd.length); nghttp2_session_del(session); @@ -2593,10 +2766,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last += nghttp2_buf_avail(&buf); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2615,10 +2788,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2631,7 +2804,7 @@ void test_nghttp2_session_recv_origin(void) { nghttp2_session_callbacks callbacks; my_user_data ud; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; nghttp2_extension frame; nghttp2_ext_origin origin; @@ -2658,17 +2831,17 @@ void test_nghttp2_session_recv_origin(void) { rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_ORIGIN == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == ud.recv_frame_hd.flags); - CU_ASSERT(0 == ud.recv_frame_hd.stream_id); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_ORIGIN, ==, ud.recv_frame_hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, ud.recv_frame_hd.flags); + assert_int32(0, ==, ud.recv_frame_hd.stream_id); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2679,17 +2852,17 @@ void test_nghttp2_session_recv_origin(void) { nghttp2_frame_origin_init(&frame, &ov, 1); rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_put_uint16be(bufs.head->buf.pos + NGHTTP2_FRAME_HDLEN, (uint16_t)sizeof(nghttp2)); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2702,14 +2875,14 @@ void test_nghttp2_session_recv_origin(void) { frame.hd.stream_id = 1; rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2721,14 +2894,14 @@ void test_nghttp2_session_recv_origin(void) { frame.hd.flags = 0xf0; rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2739,14 +2912,14 @@ void test_nghttp2_session_recv_origin(void) { nghttp2_frame_origin_init(&frame, &ov, 1); rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2757,15 +2930,15 @@ void test_nghttp2_session_recv_origin(void) { nghttp2_frame_origin_init(&frame, NULL, 0); rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_ORIGIN == ud.recv_frame_hd.type); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_ORIGIN, ==, ud.recv_frame_hd.type); nghttp2_session_del(session); @@ -2778,7 +2951,7 @@ void test_nghttp2_session_recv_priority_update(void) { nghttp2_session_callbacks callbacks; my_user_data ud; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; nghttp2_extension frame; nghttp2_ext_priority_update priority_update; @@ -2820,19 +2993,19 @@ void test_nghttp2_session_recv_priority_update(void) { open_recv_stream(session, 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == ud.recv_frame_hd.flags); - CU_ASSERT(0 == ud.recv_frame_hd.stream_id); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, ud.recv_frame_hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, ud.recv_frame_hd.flags); + assert_int32(0, ==, ud.recv_frame_hd.stream_id); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(2 == nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_uint32(2, ==, nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2849,38 +3022,38 @@ void test_nghttp2_session_recv_priority_update(void) { nghttp2_frame_pack_priority_update(&bufs, &frame); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == ud.recv_frame_hd.flags); - CU_ASSERT(0 == ud.recv_frame_hd.stream_id); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, ud.recv_frame_hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, ud.recv_frame_hd.flags); + assert_int32(0, ==, ud.recv_frame_hd.stream_id); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(2 == nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_uint32(2, ==, nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_hd_deflate_init(&deflater, mem); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(2 == nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.recv_frame_hd.type); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_uint32(2, ==, nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_hd_deflate_free(&deflater); @@ -2900,15 +3073,15 @@ void test_nghttp2_session_recv_priority_update(void) { open_recv_stream(session, 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(NGHTTP2_EXTPRI_DEFAULT_URGENCY == stream->extpri); + assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, stream->extpri); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2926,15 +3099,15 @@ void test_nghttp2_session_recv_priority_update(void) { open_sent_stream(session, 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2953,23 +3126,23 @@ void test_nghttp2_session_recv_priority_update(void) { nghttp2_frame_pack_priority_update(&bufs, &frame); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); if (i < 100) { - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == ud.recv_frame_hd.type); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, ud.recv_frame_hd.type); } else { - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); } nghttp2_bufs_reset(&bufs); } item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_session_del(session); nghttp2_option_del(option); @@ -2986,7 +3159,7 @@ void test_nghttp2_session_continue(void) { nghttp2_bufs bufs; nghttp2_buf *buf; size_t framelen1, framelen2; - ssize_t rv; + nghttp2_ssize rv; uint8_t buffer[4096]; nghttp2_buf databuf; nghttp2_frame frame; @@ -3002,7 +3175,7 @@ void test_nghttp2_session_continue(void) { nghttp2_buf_wrap_init(&databuf, buffer, sizeof(buffer)); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; callbacks.on_data_chunk_recv_callback = pause_on_data_chunk_recv_callback; callbacks.on_header_callback = pause_on_header_callback; @@ -3021,8 +3194,8 @@ void test_nghttp2_session_continue(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3039,8 +3212,8 @@ void test_nghttp2_session_continue(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3052,80 +3225,80 @@ void test_nghttp2_session_continue(void) { /* Receive 1st HEADERS and pause */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; recv_frame = user_data.frame; - CU_ASSERT(NGHTTP2_HEADERS == recv_frame->hd.type); - CU_ASSERT(framelen1 - NGHTTP2_FRAME_HDLEN == recv_frame->hd.length); + assert_uint8(NGHTTP2_HEADERS, ==, recv_frame->hd.type); + assert_size(framelen1 - NGHTTP2_FRAME_HDLEN, ==, recv_frame->hd.length); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.header_cb_called); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&nv1[0], &user_data.nv)); + assert_true(nghttp2_nv_equal(&nv1[0], &user_data.nv)); /* get 2nd header field */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.header_cb_called); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&nv1[1], &user_data.nv)); + assert_true(nghttp2_nv_equal(&nv1[1], &user_data.nv)); /* will call end_headers_callback and receive 2nd HEADERS and pause */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; recv_frame = user_data.frame; - CU_ASSERT(NGHTTP2_HEADERS == recv_frame->hd.type); - CU_ASSERT(framelen2 - NGHTTP2_FRAME_HDLEN == recv_frame->hd.length); + assert_uint8(NGHTTP2_HEADERS, ==, recv_frame->hd.type); + assert_size(framelen2 - NGHTTP2_FRAME_HDLEN, ==, recv_frame->hd.length); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.header_cb_called); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&nv2[0], &user_data.nv)); + assert_true(nghttp2_nv_equal(&nv2[0], &user_data.nv)); /* get 2nd header field */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.header_cb_called); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&nv2[1], &user_data.nv)); + assert_true(nghttp2_nv_equal(&nv2[1], &user_data.nv)); /* No input data, frame_recv_callback is called */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; user_data.frame_recv_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == user_data.header_cb_called); - CU_ASSERT(1 == user_data.frame_recv_cb_called); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(0, ==, user_data.header_cb_called); + assert_int(1, ==, user_data.frame_recv_cb_called); /* Receive DATA */ nghttp2_frame_hd_init(&data_hd, 16, NGHTTP2_DATA, NGHTTP2_FLAG_NONE, 1); @@ -3138,26 +3311,26 @@ void test_nghttp2_session_continue(void) { databuf.last = databuf.end; user_data.frame_recv_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(16 + NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(0 == user_data.frame_recv_cb_called); + assert_ptrdiff(16 + NGHTTP2_FRAME_HDLEN, ==, rv); + assert_int(0, ==, user_data.frame_recv_cb_called); - /* Next nghttp2_session_mem_recv invokes on_frame_recv_callback and + /* Next nghttp2_session_mem_recv2 invokes on_frame_recv_callback and pause again in on_data_chunk_recv_callback since we pass same DATA frame. */ user_data.frame_recv_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); - CU_ASSERT(16 + NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(1 == user_data.frame_recv_cb_called); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); + assert_ptrdiff(16 + NGHTTP2_FRAME_HDLEN, ==, rv); + assert_int(1, ==, user_data.frame_recv_cb_called); /* And finally call on_frame_recv_callback with 0 size input */ user_data.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, NULL, 0); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == user_data.frame_recv_cb_called); + rv = nghttp2_session_mem_recv2(session, NULL, 0); + assert_ptrdiff(0, ==, rv); + assert_int(1, ==, user_data.frame_recv_cb_called); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -3177,12 +3350,13 @@ void test_nghttp2_session_add_frame(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; acc.length = 0; user_data.acc = &acc; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &user_data)); + assert_int(0, ==, + nghttp2_session_client_new(&session, &callbacks, &user_data)); item = mem->malloc(sizeof(nghttp2_outbound_item), NULL); @@ -3199,13 +3373,14 @@ void test_nghttp2_session_add_frame(void) { session->next_stream_id += 2; - CU_ASSERT(0 == nghttp2_session_add_item(session, item)); - CU_ASSERT(NULL != nghttp2_outbound_queue_top(&session->ob_syn)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_HEADERS == acc.buf[3]); - CU_ASSERT((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY) == acc.buf[4]); + assert_int(0, ==, nghttp2_session_add_item(session, item)); + assert_not_null(nghttp2_outbound_queue_top(&session->ob_syn)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_HEADERS, ==, acc.buf[3]); + assert_uint8((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY), ==, + acc.buf[4]); /* check stream id */ - CU_ASSERT(1 == nghttp2_get_uint32(&acc.buf[5])); + assert_uint32(1, ==, nghttp2_get_uint32(&acc.buf[5])); nghttp2_session_del(session); } @@ -3239,11 +3414,12 @@ void test_nghttp2_session_on_request_headers_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); + assert_int(0, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.begin_headers_cb_called); stream = nghttp2_session_get_stream(session, stream_id); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(255 == stream->weight); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_int32(255, ==, stream->weight); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3253,10 +3429,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, 3, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); session->local_settings.max_concurrent_streams = @@ -3268,10 +3444,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, 3, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3281,10 +3457,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, 2, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3300,9 +3476,10 @@ void test_nghttp2_session_on_request_headers_received(void) { 1, NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); + assert_int(0, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3316,10 +3493,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3332,10 +3509,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3352,10 +3529,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3369,7 +3546,8 @@ void test_nghttp2_session_on_request_headers_received(void) { nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 3, NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(0, ==, + nghttp2_session_on_request_headers_received(session, &frame)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3379,10 +3557,10 @@ void test_nghttp2_session_on_request_headers_received(void) { session->goaway_flags |= NGHTTP2_GOAWAY_SENT; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3398,9 +3576,9 @@ void test_nghttp2_session_on_request_headers_received(void) { nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1, NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3428,10 +3606,11 @@ void test_nghttp2_session_on_response_headers_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_response_headers_received(session, &frame, - stream)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_int( + 0, ==, + nghttp2_session_on_response_headers_received(session, &frame, stream)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); nghttp2_frame_headers_free(&frame.headers, mem); nghttp2_session_del(session); @@ -3459,26 +3638,28 @@ void test_nghttp2_session_on_headers_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_int(0, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); /* stream closed */ frame.hd.flags |= NGHTTP2_FLAG_END_STREAM; - CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream)); - CU_ASSERT(2 == user_data.begin_headers_cb_called); + assert_int(0, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(2, ==, user_data.begin_headers_cb_called); /* Check to see when NGHTTP2_STREAM_CLOSING, incoming HEADERS is discarded. */ stream = open_sent_stream2(session, 3, NGHTTP2_STREAM_CLOSING); frame.hd.stream_id = 3; frame.hd.flags = NGHTTP2_FLAG_END_HEADERS; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); /* See no counters are updated */ - CU_ASSERT(2 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); + assert_int(2, ==, user_data.begin_headers_cb_called); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); /* Server initiated stream */ stream = open_recv_stream(session, 2); @@ -3486,16 +3667,17 @@ void test_nghttp2_session_on_headers_received(void) { frame.hd.flags = NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM; frame.hd.stream_id = 2; - CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream)); - CU_ASSERT(3 == user_data.begin_headers_cb_called); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_int(0, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(3, ==, user_data.begin_headers_cb_called); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); /* Further reception of HEADERS is subject to stream error */ - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_headers_received(session, &frame, stream)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3513,7 +3695,7 @@ void test_nghttp2_session_on_push_response_headers_received(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_begin_headers_callback = on_begin_headers_callback; callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; @@ -3528,31 +3710,32 @@ void test_nghttp2_session_on_push_response_headers_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(0 == nghttp2_session_on_push_response_headers_received( - session, &frame, stream)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == session->num_incoming_reserved_streams); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(0 == (stream->flags & NGHTTP2_STREAM_FLAG_PUSH)); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_int(0, ==, + nghttp2_session_on_push_response_headers_received(session, &frame, + stream)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_size(0, ==, session->num_incoming_reserved_streams); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); + assert_size(1, ==, session->num_incoming_streams); + assert_false(stream->flags & NGHTTP2_STREAM_FLAG_PUSH); /* If un-ACKed max concurrent streams limit is exceeded, RST_STREAMed */ session->pending_local_max_concurrent_stream = 1; stream = open_recv_stream2(session, 4, NGHTTP2_STREAM_RESERVED); frame.hd.stream_id = 4; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_response_headers_received(session, &frame, - stream)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_response_headers_received(session, &frame, + stream)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_REFUSED_STREAM == item->frame.rst_stream.error_code); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_REFUSED_STREAM, ==, item->frame.rst_stream.error_code); + assert_size(1, ==, session->num_incoming_streams); + assert_size(1, ==, session->num_incoming_reserved_streams); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == session->num_incoming_streams); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(1, ==, session->num_incoming_streams); /* If ACKed max concurrent streams limit is exceeded, GOAWAY is issued */ @@ -3561,14 +3744,14 @@ void test_nghttp2_session_on_push_response_headers_received(void) { stream = open_recv_stream2(session, 6, NGHTTP2_STREAM_RESERVED); frame.hd.stream_id = 6; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_response_headers_received(session, &frame, - stream)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_response_headers_received(session, &frame, + stream)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); + assert_size(1, ==, session->num_incoming_streams); + assert_size(1, ==, session->num_incoming_reserved_streams); nghttp2_frame_headers_free(&frame.headers, mem); nghttp2_session_del(session); @@ -3595,9 +3778,9 @@ void test_nghttp2_session_on_priority_received(void) { nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); /* depend on stream 0 */ - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - CU_ASSERT(2 == stream->weight); + assert_int32(2, ==, stream->weight); stream = open_sent_stream(session, 2); dep_stream = open_recv_stream(session, 3); @@ -3607,19 +3790,19 @@ void test_nghttp2_session_on_priority_received(void) { /* using dependency stream */ nghttp2_priority_spec_init(&frame.priority.pri_spec, 3, 1, 0); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); - CU_ASSERT(dep_stream == stream->dep_prev); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); + assert_ptr_equal(dep_stream, stream->dep_prev); /* PRIORITY against idle stream */ frame.hd.stream_id = 100; - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); stream = nghttp2_session_get_stream_raw(session, frame.hd.stream_id); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(dep_stream == stream->dep_prev); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_ptr_equal(dep_stream, stream->dep_prev); nghttp2_frame_priority_free(&frame.priority); nghttp2_session_del(session); @@ -3632,11 +3815,11 @@ void test_nghttp2_session_on_priority_received(void) { nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_priority_free(&frame.priority); nghttp2_session_del(session); @@ -3648,11 +3831,11 @@ void test_nghttp2_session_on_priority_received(void) { nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_priority_free(&frame.priority); nghttp2_session_del(session); @@ -3669,8 +3852,8 @@ void test_nghttp2_session_on_rst_stream_received(void) { nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_PROTOCOL_ERROR); - CU_ASSERT(0 == nghttp2_session_on_rst_stream_received(session, &frame)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + assert_int(0, ==, nghttp2_session_on_rst_stream_received(session, &frame)); + assert_null(nghttp2_session_get_stream(session, 1)); nghttp2_frame_rst_stream_free(&frame.rst_stream); nghttp2_session_del(session); @@ -3691,7 +3874,7 @@ void test_nghttp2_session_on_settings_received(void) { uint8_t data[2048]; nghttp2_frame_hd hd; int rv; - ssize_t nread; + nghttp2_ssize nread; nghttp2_stream *stream; mem = nghttp2_mem_default(); @@ -3712,7 +3895,7 @@ void test_nghttp2_session_on_settings_received(void) { iv[4].value = 0; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &user_data); session->remote_settings.initial_window_size = 16 * 1024; @@ -3728,26 +3911,29 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, niv), niv); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(1000000009 == session->remote_settings.max_concurrent_streams); - CU_ASSERT(64 * 1024 == session->remote_settings.initial_window_size); - CU_ASSERT(1024 == session->remote_settings.header_table_size); - CU_ASSERT(0 == session->remote_settings.enable_push); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); + assert_uint32(1000000009, ==, + session->remote_settings.max_concurrent_streams); + assert_uint32(64 * 1024, ==, session->remote_settings.initial_window_size); + assert_uint32(1024, ==, session->remote_settings.header_table_size); + assert_uint32(0, ==, session->remote_settings.enable_push); - CU_ASSERT(64 * 1024 == stream1->remote_window_size); - CU_ASSERT(0 == stream2->remote_window_size); + assert_int32(64 * 1024, ==, stream1->remote_window_size); + assert_int32(0, ==, stream2->remote_window_size); frame.settings.iv[2].value = 16 * 1024; - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(16 * 1024 == stream1->remote_window_size); - CU_ASSERT(-48 * 1024 == stream2->remote_window_size); + assert_int32(16 * 1024, ==, stream1->remote_window_size); + assert_int32(-48 * 1024, ==, stream2->remote_window_size); - CU_ASSERT(16 * 1024 == nghttp2_session_get_stream_remote_window_size( - session, stream1->stream_id)); - CU_ASSERT(0 == nghttp2_session_get_stream_remote_window_size( - session, stream2->stream_id)); + assert_int32(16 * 1024, ==, + nghttp2_session_get_stream_remote_window_size( + session, stream1->stream_id)); + assert_int32(0, ==, + nghttp2_session_get_stream_remote_window_size( + session, stream2->stream_id)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -3757,10 +3943,10 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_session_server_new(&session, &callbacks, NULL); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_ACK, dup_iv(iv, 1), 1); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item != NULL); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3769,10 +3955,10 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_session_server_new(&session, &callbacks, NULL); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_ACK, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item != NULL); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3781,11 +3967,11 @@ void test_nghttp2_session_on_settings_received(void) { and header table size is once cleared to 0. */ nghttp2_session_client_new(&session, &callbacks, NULL); - nghttp2_submit_request(session, NULL, &nv, 1, NULL, NULL); + nghttp2_submit_request2(session, NULL, &nv, 1, NULL, NULL); nghttp2_session_send(session); - CU_ASSERT(session->hd_deflater.ctx.hd_table.len > 0); + assert_size(0, <, session->hd_deflater.ctx.hd_table.len); iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[0].value = 0; @@ -3796,11 +3982,11 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, 2), 2); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(0 == session->hd_deflater.ctx.hd_table.len); - CU_ASSERT(2048 == session->hd_deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(2048 == session->remote_settings.header_table_size); + assert_size(0, ==, session->hd_deflater.ctx.hd_table.len); + assert_size(2048, ==, session->hd_deflater.ctx.hd_table_bufsize_max); + assert_uint32(2048, ==, session->remote_settings.header_table_size); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3811,12 +3997,12 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_option_new(&option); nghttp2_option_set_peer_max_concurrent_streams(option, 1000); nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(1000 == session->remote_settings.max_concurrent_streams); + assert_uint32(1000, ==, session->remote_settings.max_concurrent_streams); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS == - session->remote_settings.max_concurrent_streams); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); + assert_uint32(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS, ==, + session->remote_settings.max_concurrent_streams); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3831,12 +4017,12 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, 1), 1); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item != NULL); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3850,7 +4036,7 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 1, 1); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); nghttp2_frame_window_update_free(&frame.window_update); @@ -3862,20 +4048,20 @@ void test_nghttp2_session_on_settings_received(void) { /* Now window size gets NGHTTP2_MAX_WINDOW_SIZE + 1, which is unacceptable situation in protocol spec. */ - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); nghttp2_frame_settings_free(&frame.settings, mem); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_SETTINGS == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_SETTINGS, ==, item->frame.hd.type); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_STREAM_CLOSING == stream1->state); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_CLOSING, ==, stream1->state); nghttp2_session_del(session); @@ -3891,14 +4077,14 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, 1), 1); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); nghttp2_frame_settings_free(&frame.settings, mem); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); @@ -3915,11 +4101,11 @@ void test_nghttp2_session_on_settings_received(void) { rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream = open_recv_stream(session, 1); @@ -3931,31 +4117,31 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_pack_frame_hd(data, &hd); nread = - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + hd.length); + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + hd.length); - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length) == nread); + assert_ptrdiff((nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + hd.length), ==, nread); rv = nghttp2_session_consume(session, 1, hd.length); - CU_ASSERT(0 == rv); - CU_ASSERT((int32_t)hd.length == stream->recv_window_size); - CU_ASSERT((int32_t)hd.length == stream->consumed_size); + assert_int(0, ==, rv); + assert_int32((int32_t)hd.length, ==, stream->recv_window_size); + assert_int32((int32_t)hd.length, ==, stream->consumed_size); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_ACK, NULL, 0); rv = nghttp2_session_on_settings_received(session, &frame, 0); - CU_ASSERT(0 == rv); - CU_ASSERT(1024 == stream->local_window_size); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == stream->consumed_size); + assert_int(0, ==, rv); + assert_int32(1024, ==, stream->local_window_size); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(0, ==, stream->consumed_size); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT((int32_t)hd.length == - item->frame.window_update.window_size_increment); + assert_not_null(item); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32((int32_t)hd.length, ==, + item->frame.window_update.window_size_increment); nghttp2_session_del(session); nghttp2_option_del(option); @@ -3972,14 +4158,14 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, 1), 1); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); nghttp2_frame_settings_free(&frame.settings, mem); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); } @@ -3999,7 +4185,7 @@ void test_nghttp2_session_on_push_promise_received(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_begin_headers_callback = on_begin_headers_callback; callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; @@ -4013,13 +4199,14 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); promised_stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_RESERVED == promised_stream->state); - CU_ASSERT(2 == session->last_recv_stream_id); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_RESERVED, ==, + promised_stream->state); + assert_int32(2, ==, session->last_recv_stream_id); /* Attempt to PUSH_PROMISE against half close (remote) */ nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); @@ -4027,18 +4214,18 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 4)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 4)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_STREAM_CLOSED == item->frame.goaway.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(4 == session->last_recv_stream_id); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_STREAM_CLOSED, ==, item->frame.goaway.error_code); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(4, ==, session->last_recv_stream_id); nghttp2_session_del(session); @@ -4052,17 +4239,17 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 6)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_size(0, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 6)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(6 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_CANCEL == item->frame.rst_stream.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(6, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_CANCEL, ==, item->frame.rst_stream.error_code); + assert_int(0, ==, nghttp2_session_send(session)); /* Attempt to PUSH_PROMISE against idle stream */ frame.hd.stream_id = 3; @@ -4070,17 +4257,17 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 8)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_size(0, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 8)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(0 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_session_del(session); @@ -4094,37 +4281,37 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 2)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_not_null(nghttp2_session_get_stream(session, 2)); user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 8)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 8)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); + assert_int(0, ==, nghttp2_session_send(session)); /* After GOAWAY, PUSH_PROMISE will be discarded */ frame.push_promise.promised_stream_id = 10; user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 10)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 10)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4139,12 +4326,12 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4161,12 +4348,12 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == session->num_incoming_reserved_streams); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_size(0, ==, session->num_incoming_reserved_streams); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4182,10 +4369,10 @@ void test_nghttp2_session_on_push_promise_received(void) { 1, 2, nva, nvlen); user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4202,10 +4389,10 @@ void test_nghttp2_session_on_push_promise_received(void) { nghttp2_frame_push_promise_init(&frame.push_promise, NGHTTP2_FLAG_END_HEADERS, 1, 2, NULL, 0); - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == session->num_incoming_reserved_streams); + assert_size(0, ==, session->num_incoming_reserved_streams); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4217,20 +4404,20 @@ void test_nghttp2_session_on_push_promise_received(void) { open_sent_stream(session, 1); open_recv_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_size(1, ==, session->num_incoming_reserved_streams); nghttp2_frame_push_promise_init(&frame.push_promise, NGHTTP2_FLAG_END_HEADERS, 1, 4, NULL, 0); - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_size(1, ==, session->num_incoming_reserved_streams); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_CANCEL == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_CANCEL, ==, item->frame.rst_stream.error_code); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4255,22 +4442,22 @@ void test_nghttp2_session_on_ping_received(void) { nghttp2_session_client_new(&session, &callbacks, &user_data); nghttp2_frame_ping_init(&frame.ping, NGHTTP2_FLAG_ACK, opaque_data); - CU_ASSERT(0 == nghttp2_session_on_ping_received(session, &frame)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); + assert_int(0, ==, nghttp2_session_on_ping_received(session, &frame)); + assert_int(1, ==, user_data.frame_recv_cb_called); /* Since this ping frame has ACK flag set, no further action is performed. */ - CU_ASSERT(NULL == nghttp2_outbound_queue_top(&session->ob_urgent)); + assert_null(nghttp2_outbound_queue_top(&session->ob_urgent)); /* Clear the flag, and receive it again */ frame.hd.flags = NGHTTP2_FLAG_NONE; - CU_ASSERT(0 == nghttp2_session_on_ping_received(session, &frame)); - CU_ASSERT(2 == user_data.frame_recv_cb_called); + assert_int(0, ==, nghttp2_session_on_ping_received(session, &frame)); + assert_int(2, ==, user_data.frame_recv_cb_called); top = nghttp2_outbound_queue_top(&session->ob_urgent); - CU_ASSERT(NGHTTP2_PING == top->frame.hd.type); - CU_ASSERT(NGHTTP2_FLAG_ACK == top->frame.hd.flags); - CU_ASSERT(memcmp(opaque_data, top->frame.ping.opaque_data, 8) == 0); + assert_uint8(NGHTTP2_PING, ==, top->frame.hd.type); + assert_uint8(NGHTTP2_FLAG_ACK, ==, top->frame.hd.flags); + assert_memory_equal(8, opaque_data, top->frame.ping.opaque_data); nghttp2_frame_ping_free(&frame.ping); nghttp2_session_del(session); @@ -4284,9 +4471,9 @@ void test_nghttp2_session_on_ping_received(void) { user_data.frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_ping_received(session, &frame)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(NULL == nghttp2_outbound_queue_top(&session->ob_urgent)); + assert_int(0, ==, nghttp2_session_on_ping_received(session, &frame)); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_null(nghttp2_outbound_queue_top(&session->ob_urgent)); nghttp2_frame_ping_free(&frame.ping); nghttp2_session_del(session); @@ -4301,7 +4488,7 @@ void test_nghttp2_session_on_goaway_received(void) { int i; nghttp2_mem *mem; const uint8_t *data; - ssize_t datalen; + nghttp2_ssize datalen; mem = nghttp2_mem_default(); user_data.frame_recv_cb_called = 0; @@ -4326,20 +4513,20 @@ void test_nghttp2_session_on_goaway_received(void) { user_data.stream_close_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_goaway_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_goaway_received(session, &frame)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(3 == session->remote_last_stream_id); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int32(3, ==, session->remote_last_stream_id); /* on_stream_close should be callsed for 2 times (stream 5 and 7) */ - CU_ASSERT(2 == user_data.stream_close_cb_called); + assert_int(2, ==, user_data.stream_close_cb_called); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 1)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 2)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 3)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 4)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 5)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 6)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 7)); + assert_not_null(nghttp2_session_get_stream(session, 1)); + assert_not_null(nghttp2_session_get_stream(session, 2)); + assert_not_null(nghttp2_session_get_stream(session, 3)); + assert_not_null(nghttp2_session_get_stream(session, 4)); + assert_null(nghttp2_session_get_stream(session, 5)); + assert_not_null(nghttp2_session_get_stream(session, 6)); + assert_null(nghttp2_session_get_stream(session, 7)); nghttp2_frame_goaway_free(&frame.goaway, mem); nghttp2_session_del(session); @@ -4355,14 +4542,14 @@ void test_nghttp2_session_on_goaway_received(void) { nghttp2_frame_goaway_init(&frame.goaway, 0, NGHTTP2_NO_ERROR, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_goaway_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_goaway_received(session, &frame)); - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - datalen = nghttp2_session_mem_send(session, &data); + datalen = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == datalen); - CU_ASSERT(1 == user_data.stream_close_cb_called); + assert_ptrdiff(NGHTTP2_ERR_CALLBACK_FAILURE, ==, datalen); + assert_int(1, ==, user_data.stream_close_cb_called); nghttp2_frame_goaway_free(&frame.goaway, mem); nghttp2_session_del(session); @@ -4391,23 +4578,23 @@ void test_nghttp2_session_on_window_update_received(void) { data_item = create_data_ob_item(mem); - CU_ASSERT(0 == nghttp2_stream_attach_item(stream, data_item)); + assert_int(0, ==, nghttp2_stream_attach_item(stream, data_item)); nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 1, 16 * 1024); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 16 * 1024 == - stream->remote_window_size); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 16 * 1024, ==, + stream->remote_window_size); nghttp2_stream_defer_item(stream, NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); - CU_ASSERT(2 == user_data.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 16 * 1024 * 2 == - stream->remote_window_size); - CU_ASSERT(0 == (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL)); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); + assert_int(2, ==, user_data.frame_recv_cb_called); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 16 * 1024 * 2, ==, + stream->remote_window_size); + assert_false(stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL); nghttp2_frame_window_update_free(&frame.window_update); @@ -4418,9 +4605,9 @@ void test_nghttp2_session_on_window_update_received(void) { nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 2, 4096); - CU_ASSERT(!(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_window_update_free(&frame.window_update); @@ -4434,10 +4621,11 @@ void test_nghttp2_session_on_window_update_received(void) { nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 2, 4096); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); - CU_ASSERT(!(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 4096 == stream->remote_window_size); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 4096, ==, + stream->remote_window_size); nghttp2_frame_window_update_free(&frame.window_update); @@ -4459,13 +4647,13 @@ void test_nghttp2_session_on_data_received(void) { nghttp2_frame_hd_init(&frame.hd, 4096, NGHTTP2_DATA, NGHTTP2_FLAG_NONE, 2); - CU_ASSERT(0 == nghttp2_session_on_data_received(session, &frame)); - CU_ASSERT(0 == stream->shut_flags); + assert_int(0, ==, nghttp2_session_on_data_received(session, &frame)); + assert_uint8(0, ==, stream->shut_flags); frame.hd.flags = NGHTTP2_FLAG_END_STREAM; - CU_ASSERT(0 == nghttp2_session_on_data_received(session, &frame)); - CU_ASSERT(NGHTTP2_SHUT_RD == stream->shut_flags); + assert_int(0, ==, nghttp2_session_on_data_received(session, &frame)); + assert_uint8(NGHTTP2_SHUT_RD, ==, stream->shut_flags); /* If NGHTTP2_STREAM_CLOSING state, DATA frame is discarded. */ open_sent_stream2(session, 1, NGHTTP2_STREAM_CLOSING); @@ -4473,18 +4661,18 @@ void test_nghttp2_session_on_data_received(void) { frame.hd.flags = NGHTTP2_FLAG_NONE; frame.hd.stream_id = 1; - CU_ASSERT(0 == nghttp2_session_on_data_received(session, &frame)); - CU_ASSERT(NULL == nghttp2_outbound_queue_top(&session->ob_reg)); + assert_int(0, ==, nghttp2_session_on_data_received(session, &frame)); + assert_null(nghttp2_outbound_queue_top(&session->ob_reg)); /* Check INVALID_STREAM case: DATA frame with stream ID which does not exist. */ frame.hd.stream_id = 3; - CU_ASSERT(0 == nghttp2_session_on_data_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_data_received(session, &frame)); top = nghttp2_outbound_queue_top(&session->ob_reg); /* DATA against nonexistent stream is just ignored for now. */ - CU_ASSERT(top == NULL); + assert_null(top); nghttp2_session_del(session); } @@ -4508,13 +4696,13 @@ void test_nghttp2_session_on_data_received_fail_fast(void) { stream = open_recv_stream(session, 1); nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); - CU_ASSERT((ssize_t)sizeof(buf) == - nghttp2_session_mem_recv(session, buf, sizeof(buf))); + assert_ptrdiff((nghttp2_ssize)sizeof(buf), ==, + nghttp2_session_mem_recv2(session, buf, sizeof(buf))); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); @@ -4525,13 +4713,13 @@ void test_nghttp2_session_on_data_received_fail_fast(void) { nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); - CU_ASSERT((ssize_t)sizeof(buf) == - nghttp2_session_mem_recv(session, buf, sizeof(buf))); + assert_ptrdiff((nghttp2_ssize)sizeof(buf), ==, + nghttp2_session_mem_recv2(session, buf, sizeof(buf))); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); } @@ -4564,8 +4752,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4580,8 +4768,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4598,8 +4786,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4616,8 +4804,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4632,8 +4820,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4651,7 +4839,7 @@ void test_nghttp2_session_send_headers_start_stream(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -4667,9 +4855,9 @@ void test_nghttp2_session_send_headers_start_stream(void) { session->next_stream_id += 2; nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); nghttp2_session_del(session); } @@ -4685,9 +4873,9 @@ void test_nghttp2_session_send_headers_reply(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, NULL)); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); item = mem->malloc(sizeof(nghttp2_outbound_item), NULL); @@ -4699,9 +4887,9 @@ void test_nghttp2_session_send_headers_reply(void) { nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, 1, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); nghttp2_session_del(session); } @@ -4733,7 +4921,7 @@ void test_nghttp2_session_send_headers_frame_size_error(void) { } memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); @@ -4756,11 +4944,11 @@ void test_nghttp2_session_send_headers_frame_size_error(void) { ud.frame_not_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR == ud.not_sent_error); + assert_int(1, ==, ud.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.not_sent_frame_type); + assert_int(NGHTTP2_ERR_FRAME_SIZE_ERROR, ==, ud.not_sent_error); for (i = 0; i < nnv; ++i) { mem->free(nv[i].value, NULL); @@ -4779,9 +4967,9 @@ void test_nghttp2_session_send_headers_push_reply(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, NULL)); open_sent_stream2(session, 2, NGHTTP2_STREAM_RESERVED); item = mem->malloc(sizeof(nghttp2_outbound_item), NULL); @@ -4793,12 +4981,12 @@ void test_nghttp2_session_send_headers_push_reply(void) { nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, 2, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); nghttp2_session_add_item(session, item); - CU_ASSERT(0 == session->num_outgoing_streams); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == session->num_outgoing_streams); + assert_size(0, ==, session->num_outgoing_streams); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(1, ==, session->num_outgoing_streams); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); - CU_ASSERT(0 == (stream->flags & NGHTTP2_STREAM_FLAG_PUSH)); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); + assert_false(stream->flags & NGHTTP2_STREAM_FLAG_PUSH); nghttp2_session_del(session); } @@ -4813,7 +5001,7 @@ void test_nghttp2_session_send_rst_stream(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &user_data); open_sent_stream(session, 1); @@ -4825,9 +5013,9 @@ void test_nghttp2_session_send_rst_stream(void) { nghttp2_frame_rst_stream_init(&frame->rst_stream, 1, NGHTTP2_PROTOCOL_ERROR); nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + assert_null(nghttp2_session_get_stream(session, 1)); nghttp2_session_del(session); } @@ -4844,7 +5032,7 @@ void test_nghttp2_session_send_push_promise(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); @@ -4864,9 +5052,9 @@ void test_nghttp2_session_send_push_promise(void) { nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_RESERVED == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_RESERVED, ==, stream->state); /* Received ENABLE_PUSH = 0 */ iv.settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; @@ -4889,11 +5077,11 @@ void test_nghttp2_session_send_push_promise(void) { nghttp2_session_add_item(session, item); ud.frame_not_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_PUSH_PROMISE == ud.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_PUSH_DISABLED == ud.not_sent_error); + assert_int(1, ==, ud.frame_not_send_cb_called); + assert_uint8(NGHTTP2_PUSH_PROMISE, ==, ud.not_sent_frame_type); + assert_int(NGHTTP2_ERR_PUSH_DISABLED, ==, ud.not_sent_error); nghttp2_session_del(session); @@ -4910,8 +5098,8 @@ void test_nghttp2_session_send_push_promise(void) { NGHTTP2_FLAG_END_HEADERS, 1, -1, NULL, 0); nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 3)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_null(nghttp2_session_get_stream(session, 3)); nghttp2_session_del(session); } @@ -4922,17 +5110,17 @@ void test_nghttp2_session_is_my_stream_id(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); nghttp2_session_server_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 0)); - CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 1)); - CU_ASSERT(1 == nghttp2_session_is_my_stream_id(session, 2)); + assert_false(nghttp2_session_is_my_stream_id(session, 0)); + assert_false(nghttp2_session_is_my_stream_id(session, 1)); + assert_true(nghttp2_session_is_my_stream_id(session, 2)); nghttp2_session_del(session); nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 0)); - CU_ASSERT(1 == nghttp2_session_is_my_stream_id(session, 1)); - CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 2)); + assert_false(nghttp2_session_is_my_stream_id(session, 0)); + assert_true(nghttp2_session_is_my_stream_id(session, 1)); + assert_false(nghttp2_session_is_my_stream_id(session, 2)); nghttp2_session_del(session); } @@ -4945,7 +5133,7 @@ void test_nghttp2_session_upgrade2(void) { nghttp2_settings_entry iv[16]; nghttp2_stream *stream; nghttp2_outbound_item *item; - ssize_t rv; + nghttp2_ssize rv; nghttp2_bufs bufs; nghttp2_buf *buf; nghttp2_hd_deflater deflater; @@ -4955,61 +5143,63 @@ void test_nghttp2_session_upgrade2(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; iv[0].value = 1; iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; iv[1].value = 4095; - settings_payloadlen = (size_t)nghttp2_pack_settings_payload( + settings_payloadlen = (size_t)nghttp2_pack_settings_payload2( settings_payload, sizeof(settings_payload), iv, 2); /* Check client side */ nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); - CU_ASSERT(1 == session->last_sent_stream_id); + assert_int(0, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); + assert_int32(1, ==, session->last_sent_stream_id); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(stream != NULL); - CU_ASSERT(&callbacks == stream->stream_user_data); - CU_ASSERT(NGHTTP2_SHUT_WR == stream->shut_flags); + assert_not_null(stream); + assert_ptr_equal(&callbacks, stream->stream_user_data); + assert_uint8(NGHTTP2_SHUT_WR, ==, stream->shut_flags); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_SETTINGS == item->frame.hd.type); - CU_ASSERT(2 == item->frame.settings.niv); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - item->frame.settings.iv[0].settings_id); - CU_ASSERT(1 == item->frame.settings.iv[0].value); - CU_ASSERT(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE == - item->frame.settings.iv[1].settings_id); - CU_ASSERT(4095 == item->frame.settings.iv[1].value); + assert_uint8(NGHTTP2_SETTINGS, ==, item->frame.hd.type); + assert_size(2, ==, item->frame.settings.niv); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + item->frame.settings.iv[0].settings_id); + assert_uint32(1, ==, item->frame.settings.iv[0].value); + assert_int32(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, ==, + item->frame.settings.iv[1].settings_id); + assert_uint32(4095, ==, item->frame.settings.iv[1].value); /* Call nghttp2_session_upgrade2() again is error */ - CU_ASSERT(NGHTTP2_ERR_PROTO == - nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); + assert_int(NGHTTP2_ERR_PROTO, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); nghttp2_session_del(session); /* Make sure that response from server can be received */ nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); + assert_int(0, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); nghttp2_hd_deflate_init(&deflater, mem); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, resnv, ARRLEN(resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT(rv == (ssize_t)nghttp2_buf_len(buf)); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -5018,29 +5208,31 @@ void test_nghttp2_session_upgrade2(void) { /* Check server side */ nghttp2_session_server_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); - CU_ASSERT(1 == session->last_recv_stream_id); + assert_int(0, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); + assert_int32(1, ==, session->last_recv_stream_id); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(stream != NULL); - CU_ASSERT(NULL == stream->stream_user_data); - CU_ASSERT(NGHTTP2_SHUT_RD == stream->shut_flags); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(1 == session->remote_settings.max_concurrent_streams); - CU_ASSERT(4095 == session->remote_settings.initial_window_size); + assert_not_null(stream); + assert_null(stream->stream_user_data); + assert_uint8(NGHTTP2_SHUT_RD, ==, stream->shut_flags); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_uint32(1, ==, session->remote_settings.max_concurrent_streams); + assert_uint32(4095, ==, session->remote_settings.initial_window_size); /* Call nghttp2_session_upgrade2() again is error */ - CU_ASSERT(NGHTTP2_ERR_PROTO == - nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); + assert_int(NGHTTP2_ERR_PROTO, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); nghttp2_session_del(session); /* Empty SETTINGS is OK */ - settings_payloadlen = (size_t)nghttp2_pack_settings_payload( + settings_payloadlen = (size_t)nghttp2_pack_settings_payload2( settings_payload, sizeof(settings_payload), NULL, 0); nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, NULL)); + assert_int(0, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, NULL)); nghttp2_session_del(session); nghttp2_bufs_free(&bufs); } @@ -5054,7 +5246,7 @@ void test_nghttp2_session_reprioritize_stream(void) { int rv; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -5064,9 +5256,9 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(10 == stream->weight); - CU_ASSERT(&session->root == stream->dep_prev); + assert_int(0, ==, rv); + assert_int32(10, ==, stream->weight); + assert_ptr_equal(&session->root, stream->dep_prev); /* If dependency to idle stream which is not in dependency tree yet */ @@ -5074,13 +5266,13 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(99 == stream->weight); - CU_ASSERT(3 == stream->dep_prev->stream_id); + assert_int(0, ==, rv); + assert_int32(99, ==, stream->weight); + assert_int32(3, ==, stream->dep_prev->stream_id); dep_stream = nghttp2_session_get_stream_raw(session, 3); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == dep_stream->weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, dep_stream->weight); dep_stream = open_recv_stream(session, 3); @@ -5089,19 +5281,19 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(128 == stream->weight); - CU_ASSERT(dep_stream == stream->dep_prev); + assert_int(0, ==, rv); + assert_int32(128, ==, stream->weight); + assert_ptr_equal(dep_stream, stream->dep_prev); /* Change weight again to test short-path case */ pri_spec.weight = 100; rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(100 == stream->weight); - CU_ASSERT(dep_stream == stream->dep_prev); - CU_ASSERT(100 == dep_stream->sum_dep_weight); + assert_int(0, ==, rv); + assert_int32(100, ==, stream->weight); + assert_ptr_equal(dep_stream, stream->dep_prev); + assert_int32(100, ==, dep_stream->sum_dep_weight); /* Test circular dependency; stream 1 is first removed and becomes root. Then stream 3 depends on it. */ @@ -5109,9 +5301,9 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, dep_stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == dep_stream->weight); - CU_ASSERT(stream == dep_stream->dep_prev); + assert_int(0, ==, rv); + assert_int32(1, ==, dep_stream->weight); + assert_ptr_equal(stream, dep_stream->dep_prev); /* Making priority to closed stream will result in default priority */ @@ -5121,8 +5313,8 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); + assert_int(0, ==, rv); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); nghttp2_session_del(session); @@ -5141,20 +5333,20 @@ void test_nghttp2_session_reprioritize_stream(void) { stream = nghttp2_session_get_stream(session, 3); rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(7 == stream->dep_prev->stream_id); + assert_int(0, ==, rv); + assert_int32(7, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 7); - CU_ASSERT(1 == stream->dep_prev->stream_id); + assert_int32(1, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 9); - CU_ASSERT(3 == stream->dep_prev->stream_id); + assert_int32(3, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 5); - CU_ASSERT(3 == stream->dep_prev->stream_id); + assert_int32(3, ==, stream->dep_prev->stream_id); nghttp2_session_del(session); @@ -5173,20 +5365,20 @@ void test_nghttp2_session_reprioritize_stream(void) { stream = nghttp2_session_get_stream(session, 3); rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(7 == stream->dep_prev->stream_id); + assert_int(0, ==, rv); + assert_int32(7, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 7); - CU_ASSERT(1 == stream->dep_prev->stream_id); + assert_int32(1, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 9); - CU_ASSERT(7 == stream->dep_prev->stream_id); + assert_int32(7, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 5); - CU_ASSERT(3 == stream->dep_prev->stream_id); + assert_int32(3, ==, stream->dep_prev->stream_id); nghttp2_session_del(session); } @@ -5198,7 +5390,7 @@ void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void) { nghttp2_priority_spec pri_spec; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -5212,12 +5404,12 @@ void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void) { /* idle stream is not counteed to max concurrent streams */ - CU_ASSERT(10 == stream->weight); - CU_ASSERT(101 == stream->dep_prev->stream_id); + assert_int32(10, ==, stream->weight); + assert_int32(101, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream_raw(session, 101); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); nghttp2_session_del(session); } @@ -5225,7 +5417,7 @@ void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void) { void test_nghttp2_submit_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_frame *frame; nghttp2_frame_hd hd; @@ -5234,30 +5426,31 @@ void test_nghttp2_submit_data(void) { nghttp2_buf *buf; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = NGHTTP2_DATA_PAYLOADLEN * 2; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); aob = &session->aob; framebufs = &aob->framebufs; open_sent_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.block_count = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); frame = &aob->item->frame; buf = &framebufs->head->buf; nghttp2_frame_unpack_frame_hd(&hd, buf->pos); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); - CU_ASSERT(NGHTTP2_FLAG_NONE == frame->hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, frame->hd.flags); /* aux_data.data.flags has these flags */ - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == aob->item->aux_data.data.flags); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, aob->item->aux_data.data.flags); nghttp2_session_del(session); } @@ -5265,7 +5458,7 @@ void test_nghttp2_submit_data(void) { void test_nghttp2_submit_data_read_length_too_large(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_frame *frame; nghttp2_frame_hd hd; @@ -5275,37 +5468,38 @@ void test_nghttp2_submit_data_read_length_too_large(void) { size_t payloadlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; - callbacks.read_length_callback = too_large_data_source_length_callback; + callbacks.send_callback2 = block_count_send_callback; + callbacks.read_length_callback2 = too_large_data_source_length_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = NGHTTP2_DATA_PAYLOADLEN * 2; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); aob = &session->aob; framebufs = &aob->framebufs; open_sent_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.block_count = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); frame = &aob->item->frame; buf = &framebufs->head->buf; nghttp2_frame_unpack_frame_hd(&hd, buf->pos); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); - CU_ASSERT(NGHTTP2_FLAG_NONE == frame->hd.flags); - CU_ASSERT(16384 == hd.length) + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, frame->hd.flags); + assert_size(16384, ==, hd.length); /* aux_data.data.flags has these flags */ - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == aob->item->aux_data.data.flags); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, aob->item->aux_data.data.flags); nghttp2_session_del(session); /* Check that buffers are expanded */ - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); ud.data_source_length = NGHTTP2_MAX_FRAME_SIZE_MAX; @@ -5313,11 +5507,12 @@ void test_nghttp2_submit_data_read_length_too_large(void) { open_sent_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.block_count = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); aob = &session->aob; @@ -5331,13 +5526,13 @@ void test_nghttp2_submit_data_read_length_too_large(void) { payloadlen = nghttp2_min(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE, NGHTTP2_INITIAL_WINDOW_SIZE); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 1 + payloadlen == - (size_t)nghttp2_buf_cap(buf)); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); - CU_ASSERT(NGHTTP2_FLAG_NONE == frame->hd.flags); - CU_ASSERT(payloadlen == hd.length); + assert_size(NGHTTP2_FRAME_HDLEN + 1 + payloadlen, ==, + (size_t)nghttp2_buf_cap(buf)); + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, frame->hd.flags); + assert_size(payloadlen, ==, hd.length); /* aux_data.data.flags has these flags */ - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == aob->item->aux_data.data.flags); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, aob->item->aux_data.data.flags); nghttp2_session_del(session); } @@ -5345,7 +5540,7 @@ void test_nghttp2_submit_data_read_length_too_large(void) { void test_nghttp2_submit_data_read_length_smallest(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_frame *frame; nghttp2_frame_hd hd; @@ -5354,37 +5549,38 @@ void test_nghttp2_submit_data_read_length_smallest(void) { nghttp2_buf *buf; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; - callbacks.read_length_callback = smallest_length_data_source_length_callback; + callbacks.send_callback2 = block_count_send_callback; + callbacks.read_length_callback2 = smallest_length_data_source_length_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = NGHTTP2_DATA_PAYLOADLEN * 2; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); aob = &session->aob; framebufs = &aob->framebufs; open_sent_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.block_count = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); frame = &aob->item->frame; buf = &framebufs->head->buf; nghttp2_frame_unpack_frame_hd(&hd, buf->pos); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); - CU_ASSERT(NGHTTP2_FLAG_NONE == frame->hd.flags); - CU_ASSERT(1 == hd.length) + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, frame->hd.flags); + assert_size(1, ==, hd.length); /* aux_data.data.flags has these flags */ - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == aob->item->aux_data.data.flags); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, aob->item->aux_data.data.flags); nghttp2_session_del(session); } -static ssize_t submit_data_twice_data_source_read_callback( +static nghttp2_ssize submit_data_twice_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { (void)session; @@ -5394,7 +5590,7 @@ static ssize_t submit_data_twice_data_source_read_callback( (void)user_data; *data_flags |= NGHTTP2_DATA_FLAG_EOF; - return (ssize_t)nghttp2_min(len, 16); + return (nghttp2_ssize)nghttp2_min(len, 16); } static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, @@ -5402,7 +5598,7 @@ static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, void *user_data) { static int called = 0; int rv; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; (void)user_data; if (called == 0) { @@ -5410,9 +5606,9 @@ static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, data_prd.read_callback = submit_data_twice_data_source_read_callback; - rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, - frame->hd.stream_id, &data_prd); - CU_ASSERT(0 == rv); + rv = nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, + frame->hd.stream_id, &data_prd); + assert_int(0, ==, rv); } return 0; @@ -5421,12 +5617,12 @@ static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, void test_nghttp2_submit_data_twice(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; accumulator acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; callbacks.on_frame_send_callback = submit_data_twice_on_frame_send_callback; data_prd.read_callback = submit_data_twice_data_source_read_callback; @@ -5434,15 +5630,16 @@ void test_nghttp2_submit_data_twice(void) { acc.length = 0; ud.acc = &acc; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); open_sent_stream(session, 1); - CU_ASSERT(0 == nghttp2_submit_data(session, NGHTTP2_FLAG_NONE, 1, &data_prd)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_NONE, 1, &data_prd)); + assert_int(0, ==, nghttp2_session_send(session)); /* We should have sent 2 DATA frame with 16 bytes payload each */ - CU_ASSERT(NGHTTP2_FRAME_HDLEN * 2 + 16 * 2 == acc.length); + assert_size(NGHTTP2_FRAME_HDLEN * 2 + 16 * 2, ==, acc.length); nghttp2_session_del(session); } @@ -5450,7 +5647,7 @@ void test_nghttp2_submit_data_twice(void) { void test_nghttp2_submit_request_with_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_outbound_item *item; nghttp2_mem *mem; @@ -5458,28 +5655,29 @@ void test_nghttp2_submit_request_with_data(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64 * 1024 - 1; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), - &data_prd, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int32(1, ==, + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), + &data_prd, NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(reqnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(reqnv), ==, item->frame.headers.nvlen); assert_nv_equal(reqnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(0, ==, ud.data_source_length); nghttp2_session_del(session); - /* nghttp2_submit_request() with server session is error */ + /* nghttp2_submit_request2() with server session is error */ nghttp2_session_server_new(&session, &callbacks, NULL); - CU_ASSERT(NGHTTP2_ERR_PROTO == nghttp2_submit_request(session, NULL, reqnv, - ARRLEN(reqnv), NULL, - NULL)); + assert_int32( + NGHTTP2_ERR_PROTO, ==, + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL)); nghttp2_session_del(session); } @@ -5488,7 +5686,7 @@ void test_nghttp2_submit_request_without_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; accumulator acc; - nghttp2_data_provider data_prd = {{-1}, NULL}; + nghttp2_data_provider2 data_prd = {{-1}, NULL}; nghttp2_outbound_item *item; my_user_data ud; nghttp2_frame frame; @@ -5505,25 +5703,26 @@ void test_nghttp2_submit_request_without_data(void) { acc.length = 0; ud.acc = &acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + callbacks.send_callback2 = accumulator_send_callback; + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), - &data_prd, NULL)); + assert_int32(1, ==, + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), + &data_prd, NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(reqnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(reqnv), ==, item->frame.headers.nvlen); assert_nv_equal(reqnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); + assert_true(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, unpack_frame(&frame, acc.buf, acc.length)); nghttp2_bufs_add(&bufs, acc.buf, acc.length); inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(ARRLEN(reqnv) == out.nvlen); + assert_size(ARRLEN(reqnv), ==, out.nvlen); assert_nv_equal(reqnv, out.nva, out.nvlen, mem); nghttp2_frame_headers_free(&frame.headers, mem); nva_out_reset(&out, mem); @@ -5535,9 +5734,9 @@ void test_nghttp2_submit_request_without_data(void) { nghttp2_priority_spec_init(&pri_spec, (int32_t)session->next_stream_id, 16, 0); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_request(session, &pri_spec, reqnv, ARRLEN(reqnv), - NULL, NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_request2(session, &pri_spec, reqnv, ARRLEN(reqnv), + NULL, NULL)); nghttp2_session_del(session); } @@ -5545,7 +5744,7 @@ void test_nghttp2_submit_request_without_data(void) { void test_nghttp2_submit_response_with_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_outbound_item *item; nghttp2_mem *mem; @@ -5553,33 +5752,34 @@ void test_nghttp2_submit_response_with_data(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64 * 1024 - 1; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), - &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), &data_prd)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(resnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(resnv), ==, item->frame.headers.nvlen); assert_nv_equal(resnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(0, ==, ud.data_source_length); nghttp2_session_del(session); /* Various error cases */ nghttp2_session_client_new(&session, &callbacks, NULL); - /* Calling nghttp2_submit_response() with client session is error */ - CU_ASSERT(NGHTTP2_ERR_PROTO == - nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), NULL)); + /* Calling nghttp2_submit_response2() with client session is error */ + assert_int(NGHTTP2_ERR_PROTO, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), NULL)); /* Stream ID <= 0 is error */ - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_response(session, 0, resnv, ARRLEN(resnv), NULL)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_response2(session, 0, resnv, ARRLEN(resnv), NULL)); nghttp2_session_del(session); } @@ -5588,7 +5788,7 @@ void test_nghttp2_submit_response_without_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; accumulator acc; - nghttp2_data_provider data_prd = {{-1}, NULL}; + nghttp2_data_provider2 data_prd = {{-1}, NULL}; nghttp2_outbound_item *item; my_user_data ud; nghttp2_frame frame; @@ -5604,26 +5804,27 @@ void test_nghttp2_submit_response_without_data(void) { acc.length = 0; ud.acc = &acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + callbacks.send_callback2 = accumulator_send_callback; + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, mem); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), - &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), &data_prd)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(resnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(resnv), ==, item->frame.headers.nvlen); assert_nv_equal(resnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); + assert_true(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, unpack_frame(&frame, acc.buf, acc.length)); nghttp2_bufs_add(&bufs, acc.buf, acc.length); inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(ARRLEN(resnv) == out.nvlen); + assert_size(ARRLEN(resnv), ==, out.nvlen); assert_nv_equal(resnv, out.nva, out.nvlen, mem); nva_out_reset(&out, mem); @@ -5639,7 +5840,7 @@ void test_nghttp2_submit_response_push_response(void) { my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); @@ -5648,13 +5849,13 @@ void test_nghttp2_submit_response_push_response(void) { session->goaway_flags |= NGHTTP2_GOAWAY_RECV; - CU_ASSERT(0 == - nghttp2_submit_response(session, 2, resnv, ARRLEN(resnv), NULL)); + assert_int(0, ==, + nghttp2_submit_response2(session, 2, resnv, ARRLEN(resnv), NULL)); ud.frame_not_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_not_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_not_send_cb_called); nghttp2_session_del(session); } @@ -5663,7 +5864,7 @@ void test_nghttp2_submit_trailer(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; accumulator acc; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_outbound_item *item; my_user_data ud; nghttp2_frame frame; @@ -5680,32 +5881,34 @@ void test_nghttp2_submit_trailer(void) { acc.length = 0; ud.acc = &acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + callbacks.send_callback2 = null_send_callback; + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, mem); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), - &data_prd)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int( + 0, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), &data_prd)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(0 == - nghttp2_submit_trailer(session, 1, trailernv, ARRLEN(trailernv))); + assert_int(0, ==, + nghttp2_submit_trailer(session, 1, trailernv, ARRLEN(trailernv))); - session->callbacks.send_callback = accumulator_send_callback; + session->callbacks.send_callback2 = accumulator_send_callback; item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(NGHTTP2_HCAT_HEADERS == item->frame.headers.cat); - CU_ASSERT(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_enum(nghttp2_headers_category, NGHTTP2_HCAT_HEADERS, ==, + item->frame.headers.cat); + assert_true(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, unpack_frame(&frame, acc.buf, acc.length)); nghttp2_bufs_add(&bufs, acc.buf, acc.length); inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(ARRLEN(trailernv) == out.nvlen); + assert_size(ARRLEN(trailernv), ==, out.nvlen); assert_nv_equal(trailernv, out.nva, out.nvlen, mem); nva_out_reset(&out, mem); @@ -5718,11 +5921,11 @@ void test_nghttp2_submit_trailer(void) { nghttp2_session_server_new(&session, &callbacks, NULL); open_recv_stream(session, 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_trailer(session, 0, trailernv, ARRLEN(trailernv))); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_trailer(session, 0, trailernv, ARRLEN(trailernv))); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_trailer(session, -1, trailernv, ARRLEN(trailernv))); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_trailer(session, -1, trailernv, ARRLEN(trailernv))); nghttp2_session_del(session); } @@ -5736,16 +5939,17 @@ void test_nghttp2_submit_headers_start_stream(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); - CU_ASSERT(1 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NULL, reqnv, ARRLEN(reqnv), NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int32(1, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, reqnv, ARRLEN(reqnv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(reqnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(reqnv), ==, item->frame.headers.nvlen); assert_nv_equal(reqnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM) == - item->frame.hd.flags); - CU_ASSERT(0 == (item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY)); + assert_uint8((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM), ==, + item->frame.hd.flags); + assert_false(item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY); nghttp2_session_del(session); } @@ -5761,34 +5965,36 @@ void test_nghttp2_submit_headers_reply(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, resnv, ARRLEN(resnv), NULL)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + resnv, ARRLEN(resnv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(resnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(resnv), ==, item->frame.headers.nvlen); assert_nv_equal(resnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == - item->frame.hd.flags); + assert_uint8((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS), ==, + item->frame.hd.flags); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; /* The transimission will be canceled because the stream 1 is not open. */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, ud.frame_send_cb_called); stream = open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, resnv, ARRLEN(resnv), NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); - CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + resnv, ARRLEN(resnv), NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); + assert_true(stream->shut_flags & NGHTTP2_SHUT_WR); nghttp2_session_del(session); } @@ -5801,35 +6007,37 @@ void test_nghttp2_submit_headers_push_reply(void) { int foo; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); stream = open_sent_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NULL, - resnv, ARRLEN(resnv), &foo)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NULL, + resnv, ARRLEN(resnv), &foo)); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); - CU_ASSERT(&foo == stream->stream_user_data); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); + assert_ptr_equal(&foo, stream->stream_user_data); nghttp2_session_del(session); /* Sending HEADERS from client against stream in reserved state is error */ - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); open_recv_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NULL, - reqnv, ARRLEN(reqnv), NULL)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NULL, + reqnv, ARRLEN(reqnv), NULL)); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, ud.frame_send_cb_called); nghttp2_session_del(session); } @@ -5855,43 +6063,45 @@ void test_nghttp2_submit_headers(void) { acc.length = 0; ud.acc = &acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, reqnv, ARRLEN(reqnv), NULL)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + reqnv, ARRLEN(reqnv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(reqnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(reqnv), ==, item->frame.headers.nvlen); assert_nv_equal(reqnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == - item->frame.hd.flags); + assert_uint8((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS), ==, + item->frame.hd.flags); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; /* The transimission will be canceled because the stream 1 is not open. */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, ud.frame_send_cb_called); stream = open_sent_stream(session, 1); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, reqnv, ARRLEN(reqnv), NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); - CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + reqnv, ARRLEN(reqnv), NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); + assert_true(stream->shut_flags & NGHTTP2_SHUT_WR); - CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length)); + assert_int(0, ==, unpack_frame(&frame, acc.buf, acc.length)); nghttp2_bufs_add(&bufs, acc.buf, acc.length); inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(ARRLEN(reqnv) == out.nvlen); + assert_size(ARRLEN(reqnv), ==, out.nvlen); assert_nv_equal(reqnv, out.nva, out.nvlen, mem); nva_out_reset(&out, mem); @@ -5903,16 +6113,16 @@ void test_nghttp2_submit_headers(void) { /* Try to depend on itself */ nghttp2_priority_spec_init(&pri_spec, 3, 16, 0); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, &pri_spec, - reqnv, ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, &pri_spec, + reqnv, ARRLEN(reqnv), NULL)); session->next_stream_id = 5; nghttp2_priority_spec_init(&pri_spec, 5, 16, 0); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, &pri_spec, - reqnv, ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, &pri_spec, + reqnv, ARRLEN(reqnv), NULL)); nghttp2_session_del(session); @@ -5921,14 +6131,14 @@ void test_nghttp2_submit_headers(void) { /* Sending nghttp2_submit_headers() with stream_id == 1 and server session is error */ - CU_ASSERT(NGHTTP2_ERR_PROTO == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, reqnv, - ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_PROTO, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, + reqnv, ARRLEN(reqnv), NULL)); /* Sending stream ID <= 0 is error */ - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 0, NULL, resnv, - ARRLEN(resnv), NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 0, NULL, + resnv, ARRLEN(resnv), NULL)); nghttp2_session_del(session); } @@ -5953,21 +6163,22 @@ void test_nghttp2_submit_headers_continuation(void) { } memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); - CU_ASSERT(1 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NULL, nv, ARRLEN(nv), NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int32(1, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, nv, ARRLEN(nv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == - item->frame.hd.flags); - CU_ASSERT(0 == (item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY)); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_uint8((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS), ==, + item->frame.hd.flags); + assert_false(item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_session_del(session); } @@ -5992,7 +6203,7 @@ void test_nghttp2_submit_headers_continuation_extra_large(void) { } memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; /* The default size of max send header block length is too small to @@ -6000,18 +6211,20 @@ void test_nghttp2_submit_headers_continuation_extra_large(void) { nghttp2_option_new(&opt); nghttp2_option_set_max_send_header_block_length(opt, 102400); - CU_ASSERT(0 == nghttp2_session_client_new2(&session, &callbacks, &ud, opt)); - CU_ASSERT(1 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NULL, nv, ARRLEN(nv), NULL)); + assert_int(0, ==, + nghttp2_session_client_new2(&session, &callbacks, &ud, opt)); + assert_int32(1, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, nv, ARRLEN(nv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == - item->frame.hd.flags); - CU_ASSERT(0 == (item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY)); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_uint8((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS), ==, + item->frame.hd.flags); + assert_false(item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_session_del(session); nghttp2_option_del(opt); @@ -6025,7 +6238,7 @@ void test_nghttp2_submit_priority(void) { nghttp2_priority_spec pri_spec; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); @@ -6034,18 +6247,18 @@ void test_nghttp2_submit_priority(void) { nghttp2_priority_spec_init(&pri_spec, 0, 3, 0); /* depends on stream 0 */ - CU_ASSERT(0 == - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(3 == stream->weight); + assert_int(0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(3, ==, stream->weight); /* submit against idle stream */ - CU_ASSERT(0 == - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 3, &pri_spec)); + assert_int(0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 3, &pri_spec)); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_session_del(session); } @@ -6085,70 +6298,73 @@ void test_nghttp2_submit_settings(void) { iv[6].value = (uint32_t)NGHTTP2_MAX_WINDOW_SIZE + 1; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 7)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 7)); /* Make sure that local settings are not changed */ - CU_ASSERT(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS == - session->local_settings.max_concurrent_streams); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - session->local_settings.initial_window_size); + assert_uint32(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS, ==, + session->local_settings.max_concurrent_streams); + assert_uint32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + session->local_settings.initial_window_size); /* Now sends without 6th one */ - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 6)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 6)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_SETTINGS == item->frame.hd.type); + assert_uint8(NGHTTP2_SETTINGS, ==, item->frame.hd.type); frame = &item->frame; - CU_ASSERT(6 == frame->settings.niv); - CU_ASSERT(5 == frame->settings.iv[0].value); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - frame->settings.iv[0].settings_id); + assert_size(6, ==, frame->settings.niv); + assert_uint32(5, ==, frame->settings.iv[0].value); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + frame->settings.iv[0].settings_id); - CU_ASSERT(16 * 1024 == frame->settings.iv[1].value); - CU_ASSERT(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE == - frame->settings.iv[1].settings_id); + assert_uint32(16 * 1024, ==, frame->settings.iv[1].value); + assert_int32(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, ==, + frame->settings.iv[1].settings_id); - CU_ASSERT(UNKNOWN_ID == frame->settings.iv[4].settings_id); - CU_ASSERT(999 == frame->settings.iv[4].value); + assert_int32(UNKNOWN_ID, ==, frame->settings.iv[4].settings_id); + assert_uint32(999, ==, frame->settings.iv[4].value); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); - CU_ASSERT(50 == session->pending_local_max_concurrent_stream); + assert_uint32(50, ==, session->pending_local_max_concurrent_stream); /* before receiving SETTINGS ACK, local settings have still default values */ - CU_ASSERT(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS == - nghttp2_session_get_local_settings( - session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - nghttp2_session_get_local_settings( - session, NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE)); + assert_uint32(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS, ==, + nghttp2_session_get_local_settings( + session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)); + assert_uint32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + nghttp2_session_get_local_settings( + session, NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE)); nghttp2_frame_settings_init(&ack_frame.settings, NGHTTP2_FLAG_ACK, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &ack_frame, 0)); + assert_int(0, ==, + nghttp2_session_on_settings_received(session, &ack_frame, 0)); nghttp2_frame_settings_free(&ack_frame.settings, mem); - CU_ASSERT(16 * 1024 == session->local_settings.initial_window_size); - CU_ASSERT(111 == session->hd_inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(111 == session->hd_inflater.min_hd_table_bufsize_max); - CU_ASSERT(50 == session->local_settings.max_concurrent_streams); + assert_uint32(16 * 1024, ==, session->local_settings.initial_window_size); + assert_size(111, ==, session->hd_inflater.ctx.hd_table_bufsize_max); + assert_size(111, ==, session->hd_inflater.min_hd_table_bufsize_max); + assert_uint32(50, ==, session->local_settings.max_concurrent_streams); - CU_ASSERT(50 == nghttp2_session_get_local_settings( - session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)); - CU_ASSERT(16 * 1024 == nghttp2_session_get_local_settings( - session, NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE)); + assert_uint32(50, ==, + nghttp2_session_get_local_settings( + session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)); + assert_uint32(16 * 1024, ==, + nghttp2_session_get_local_settings( + session, NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE)); /* We just keep the last seen value */ - CU_ASSERT(50 == session->pending_local_max_concurrent_stream); + assert_uint32(50, ==, session->pending_local_max_concurrent_stream); nghttp2_session_del(session); @@ -6161,8 +6377,8 @@ void test_nghttp2_submit_settings(void) { iv[1].settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv[1].value = 0; - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2)); nghttp2_session_del(session); @@ -6173,13 +6389,13 @@ void test_nghttp2_submit_settings(void) { iv[0].settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv[0].value = 1; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); iv[0].settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv[0].value = 0; - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); nghttp2_session_del(session); } @@ -6201,7 +6417,7 @@ void test_nghttp2_submit_settings_update_local_window_size(void) { iv[0].value = 16 * 1024; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -6211,20 +6427,21 @@ void test_nghttp2_submit_settings_update_local_window_size(void) { open_recv_stream(session, 3); - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &ack_frame, 0)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_session_on_settings_received(session, &ack_frame, 0)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(16 * 1024 + 100 == stream->local_window_size); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(16 * 1024 + 100, ==, stream->local_window_size); stream = nghttp2_session_get_stream(session, 3); - CU_ASSERT(16 * 1024 == stream->local_window_size); + assert_int32(16 * 1024, ==, stream->local_window_size); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(32768 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(32768, ==, item->frame.window_update.window_size_increment); nghttp2_session_del(session); @@ -6240,17 +6457,18 @@ void test_nghttp2_submit_settings_update_local_window_size(void) { stream->local_window_size = NGHTTP2_INITIAL_WINDOW_SIZE + 100; stream->recv_window_size = 32768; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &ack_frame, 0)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_session_on_settings_received(session, &ack_frame, 0)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(32768 == stream->recv_window_size); - CU_ASSERT(16 * 1024 + 100 == stream->local_window_size); + assert_int32(32768, ==, stream->recv_window_size); + assert_int32(16 * 1024 + 100, ==, stream->local_window_size); /* Check that we can handle the case where local_window_size < recv_window_size */ - CU_ASSERT(0 == nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int32(0, ==, nghttp2_session_get_stream_local_window_size(session, 1)); nghttp2_session_del(session); @@ -6260,13 +6478,15 @@ void test_nghttp2_submit_settings_update_local_window_size(void) { stream = open_recv_stream(session, 1); stream->local_window_size = NGHTTP2_MAX_WINDOW_SIZE; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &ack_frame, 0)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_session_on_settings_received(session, &ack_frame, 0)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_FLOW_CONTROL_ERROR == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_FLOW_CONTROL_ERROR, ==, + item->frame.rst_stream.error_code); nghttp2_session_del(session); nghttp2_frame_settings_free(&ack_frame.settings, mem); @@ -6280,7 +6500,7 @@ void test_nghttp2_submit_settings_multiple_times(void) { nghttp2_inflight_settings *inflight_settings; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -6291,60 +6511,60 @@ void test_nghttp2_submit_settings_multiple_times(void) { iv[1].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; iv[1].value = 0; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2)); inflight_settings = session->inflight_settings_head; - CU_ASSERT(NULL != inflight_settings); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - inflight_settings->iv[0].settings_id); - CU_ASSERT(100 == inflight_settings->iv[0].value); - CU_ASSERT(2 == inflight_settings->niv); - CU_ASSERT(NULL == inflight_settings->next); + assert_not_null(inflight_settings); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + inflight_settings->iv[0].settings_id); + assert_uint32(100, ==, inflight_settings->iv[0].value); + assert_size(2, ==, inflight_settings->niv); + assert_null(inflight_settings->next); - CU_ASSERT(100 == session->pending_local_max_concurrent_stream); - CU_ASSERT(0 == session->pending_enable_push); + assert_uint32(100, ==, session->pending_local_max_concurrent_stream); + assert_uint8(0, ==, session->pending_enable_push); /* second SETTINGS */ iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; iv[0].value = 99; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); inflight_settings = session->inflight_settings_head->next; - CU_ASSERT(NULL != inflight_settings); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - inflight_settings->iv[0].settings_id); - CU_ASSERT(99 == inflight_settings->iv[0].value); - CU_ASSERT(1 == inflight_settings->niv); - CU_ASSERT(NULL == inflight_settings->next); + assert_not_null(inflight_settings); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + inflight_settings->iv[0].settings_id); + assert_uint32(99, ==, inflight_settings->iv[0].value); + assert_size(1, ==, inflight_settings->niv); + assert_null(inflight_settings->next); - CU_ASSERT(99 == session->pending_local_max_concurrent_stream); - CU_ASSERT(0 == session->pending_enable_push); + assert_uint32(99, ==, session->pending_local_max_concurrent_stream); + assert_uint8(0, ==, session->pending_enable_push); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_ACK, NULL, 0); /* receive SETTINGS ACK */ - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); inflight_settings = session->inflight_settings_head; /* first inflight SETTINGS was removed */ - CU_ASSERT(NULL != inflight_settings); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - inflight_settings->iv[0].settings_id); - CU_ASSERT(99 == inflight_settings->iv[0].value); - CU_ASSERT(1 == inflight_settings->niv); - CU_ASSERT(NULL == inflight_settings->next); + assert_not_null(inflight_settings); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + inflight_settings->iv[0].settings_id); + assert_uint32(99, ==, inflight_settings->iv[0].value); + assert_size(1, ==, inflight_settings->niv); + assert_null(inflight_settings->next); - CU_ASSERT(100 == session->local_settings.max_concurrent_streams); + assert_uint32(100, ==, session->local_settings.max_concurrent_streams); /* receive SETTINGS ACK again */ - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(NULL == session->inflight_settings_head); - CU_ASSERT(99 == session->local_settings.max_concurrent_streams); + assert_null(session->inflight_settings_head); + assert_uint32(99, ==, session->local_settings.max_concurrent_streams); nghttp2_session_del(session); } @@ -6356,42 +6576,43 @@ void test_nghttp2_submit_push_promise(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); open_recv_stream(session, 1); - CU_ASSERT(2 == nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, - reqnv, ARRLEN(reqnv), &ud)); + assert_int32(2, ==, + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, reqnv, + ARRLEN(reqnv), &ud)); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NULL != stream); - CU_ASSERT(NGHTTP2_STREAM_RESERVED == stream->state); - CU_ASSERT(&ud == nghttp2_session_get_stream_user_data(session, 2)); + assert_not_null(stream); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_RESERVED, ==, stream->state); + assert_ptr_equal(&ud, nghttp2_session_get_stream_user_data(session, 2)); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_PUSH_PROMISE == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_PUSH_PROMISE, ==, ud.sent_frame_type); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_RESERVED == stream->state); - CU_ASSERT(&ud == nghttp2_session_get_stream_user_data(session, 2)); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_RESERVED, ==, stream->state); + assert_ptr_equal(&ud, nghttp2_session_get_stream_user_data(session, 2)); /* submit PUSH_PROMISE while associated stream is not opened */ - CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED == - nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 3, reqnv, - ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_STREAM_CLOSED, ==, + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 3, reqnv, + ARRLEN(reqnv), NULL)); /* Stream ID <= 0 is error */ - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 0, reqnv, - ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 0, reqnv, + ARRLEN(reqnv), NULL)); nghttp2_session_del(session); } @@ -6404,42 +6625,42 @@ void test_nghttp2_submit_window_update(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); stream = open_recv_stream(session, 2); stream->recv_window_size = 4096; - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 1024)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 1024)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(1024 == item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(3072 == stream->recv_window_size); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(1024, ==, item->frame.window_update.window_size_increment); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(3072, ==, stream->recv_window_size); - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 4096)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 4096)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(4096 == item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == stream->recv_window_size); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(4096, ==, item->frame.window_update.window_size_increment); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(0, ==, stream->recv_window_size); - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 4096)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 4096)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(4096 == item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == stream->recv_window_size); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(4096, ==, item->frame.window_update.window_size_increment); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(0, ==, stream->recv_window_size); - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 0)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 0)); /* It is ok if stream is closed or does not exist at the call time */ - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 4, 4096)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 4, 4096)); nghttp2_session_del(session); } @@ -6451,81 +6672,87 @@ void test_nghttp2_submit_window_update_local_window_size(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); stream = open_recv_stream(session, 2); stream->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, - stream->recv_window_size + 1)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1 == stream->local_window_size); - CU_ASSERT(0 == stream->recv_window_size); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, + stream->recv_window_size + 1)); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 1, ==, stream->local_window_size); + assert_int32(0, ==, stream->recv_window_size); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(4097 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(4097, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Let's decrement local window size */ stream->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, - -stream->local_window_size / 2)); - CU_ASSERT(32768 == stream->local_window_size); - CU_ASSERT(-28672 == stream->recv_window_size); - CU_ASSERT(32768 == stream->recv_reduction); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, + -stream->local_window_size / 2)); + assert_int32(32768, ==, stream->local_window_size); + assert_int32(-28672, ==, stream->recv_window_size); + assert_int32(32768, ==, stream->recv_reduction); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item == NULL); + assert_null(item); /* Increase local window size */ - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 16384)); - CU_ASSERT(49152 == stream->local_window_size); - CU_ASSERT(-12288 == stream->recv_window_size); - CU_ASSERT(16384 == stream->recv_reduction); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int( + 0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 16384)); + assert_int32(49152, ==, stream->local_window_size); + assert_int32(-12288, ==, stream->recv_window_size); + assert_int32(16384, ==, stream->recv_reduction); + assert_null(nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, - NGHTTP2_MAX_WINDOW_SIZE)); + assert_int(NGHTTP2_ERR_FLOW_CONTROL, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, + NGHTTP2_MAX_WINDOW_SIZE)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Check connection-level flow control */ session->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, - session->recv_window_size + 1)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1 == - session->local_window_size); - CU_ASSERT(0 == session->recv_window_size); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, + session->recv_window_size + 1)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1, ==, + session->local_window_size); + assert_int32(0, ==, session->recv_window_size); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(4097 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(4097, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Go decrement part */ session->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, - -session->local_window_size / 2)); - CU_ASSERT(32768 == session->local_window_size); - CU_ASSERT(-28672 == session->recv_window_size); - CU_ASSERT(32768 == session->recv_reduction); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, + -session->local_window_size / 2)); + assert_int32(32768, ==, session->local_window_size); + assert_int32(-28672, ==, session->recv_window_size); + assert_int32(32768, ==, session->recv_reduction); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item == NULL); + assert_null(item); /* Increase local window size */ - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 16384)); - CU_ASSERT(49152 == session->local_window_size); - CU_ASSERT(-12288 == session->recv_window_size); - CU_ASSERT(16384 == session->recv_reduction); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int( + 0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 16384)); + assert_int32(49152, ==, session->local_window_size); + assert_int32(-12288, ==, session->recv_window_size); + assert_int32(16384, ==, session->recv_reduction); + assert_null(nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, - NGHTTP2_MAX_WINDOW_SIZE)); + assert_int(NGHTTP2_ERR_FLOW_CONTROL, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, + NGHTTP2_MAX_WINDOW_SIZE)); nghttp2_session_del(session); } @@ -6536,43 +6763,44 @@ void test_nghttp2_submit_shutdown_notice(void) { my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); - CU_ASSERT(0 == nghttp2_submit_shutdown_notice(session)); + assert_int(0, ==, nghttp2_submit_shutdown_notice(session)); ud.frame_send_cb_called = 0; nghttp2_session_send(session); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_GOAWAY == ud.sent_frame_type); - CU_ASSERT((1u << 31) - 1 == session->local_last_stream_id); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_GOAWAY, ==, ud.sent_frame_type); + assert_int32((1u << 31) - 1, ==, session->local_last_stream_id); /* After another GOAWAY, nghttp2_submit_shutdown_notice() is noop. */ - CU_ASSERT(0 == nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR)); + assert_int(0, ==, + nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR)); ud.frame_send_cb_called = 0; nghttp2_session_send(session); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_GOAWAY == ud.sent_frame_type); - CU_ASSERT(0 == session->local_last_stream_id); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_GOAWAY, ==, ud.sent_frame_type); + assert_int32(0, ==, session->local_last_stream_id); - CU_ASSERT(0 == nghttp2_submit_shutdown_notice(session)); + assert_int(0, ==, nghttp2_submit_shutdown_notice(session)); ud.frame_send_cb_called = 0; ud.frame_not_send_cb_called = 0; nghttp2_session_send(session); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(0 == ud.frame_not_send_cb_called); + assert_int(0, ==, ud.frame_send_cb_called); + assert_int(0, ==, ud.frame_not_send_cb_called); nghttp2_session_del(session); @@ -6580,8 +6808,8 @@ void test_nghttp2_submit_shutdown_notice(void) { is error */ nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(NGHTTP2_ERR_INVALID_STATE == - nghttp2_submit_shutdown_notice(session)); + assert_int(NGHTTP2_ERR_INVALID_STATE, ==, + nghttp2_submit_shutdown_notice(session)); nghttp2_session_del(session); } @@ -6597,31 +6825,35 @@ void test_nghttp2_submit_invalid_nv(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, NULL)); /* nghttp2_submit_response */ - CU_ASSERT(0 == nghttp2_submit_response(session, 2, empty_name_nv, - ARRLEN(empty_name_nv), NULL)); + assert_int(0, ==, + nghttp2_submit_response2(session, 2, empty_name_nv, + ARRLEN(empty_name_nv), NULL)); /* nghttp2_submit_push_promise */ open_recv_stream(session, 1); - CU_ASSERT(0 < nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, - empty_name_nv, - ARRLEN(empty_name_nv), NULL)); + assert_int32(0, <, + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, + empty_name_nv, ARRLEN(empty_name_nv), + NULL)); nghttp2_session_del(session); - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); /* nghttp2_submit_request */ - CU_ASSERT(0 < nghttp2_submit_request(session, NULL, empty_name_nv, + assert_int32(0, <, + nghttp2_submit_request2(session, NULL, empty_name_nv, ARRLEN(empty_name_nv), NULL, NULL)); /* nghttp2_submit_headers */ - CU_ASSERT(0 < nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, - empty_name_nv, ARRLEN(empty_name_nv), - NULL)); + assert_int32(0, <, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, + empty_name_nv, ARRLEN(empty_name_nv), + NULL)); nghttp2_session_del(session); } @@ -6641,8 +6873,8 @@ void test_nghttp2_submit_extension(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.pack_extension_callback = pack_extension_callback; - callbacks.send_callback = accumulator_send_callback; + callbacks.pack_extension_callback2 = pack_extension_callback; + callbacks.send_callback2 = accumulator_send_callback; nghttp2_buf_init2(&ud.scratchbuf, 4096, mem); @@ -6653,25 +6885,25 @@ void test_nghttp2_submit_extension(void) { rv = nghttp2_submit_extension(session, 211, 0x01, 3, &ud.scratchbuf); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); acc.length = 0; rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + sizeof(data) == acc.length); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + sizeof(data), ==, acc.length); len = nghttp2_get_uint32(acc.buf) >> 8; - CU_ASSERT(sizeof(data) == len); - CU_ASSERT(211 == acc.buf[3]); - CU_ASSERT(0x01 == acc.buf[4]); + assert_size(sizeof(data), ==, len); + assert_uint8(211, ==, acc.buf[3]); + assert_uint8(0x01, ==, acc.buf[4]); stream_id = (int32_t)nghttp2_get_uint32(acc.buf + 5); - CU_ASSERT(3 == stream_id); - CU_ASSERT(0 == memcmp(data, &acc.buf[NGHTTP2_FRAME_HDLEN], sizeof(data))); + assert_int32(3, ==, stream_id); + assert_memory_equal(sizeof(data), data, &acc.buf[NGHTTP2_FRAME_HDLEN]); nghttp2_session_del(session); @@ -6681,7 +6913,7 @@ void test_nghttp2_submit_extension(void) { rv = nghttp2_submit_extension(session, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, NULL); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); nghttp2_session_del(session); nghttp2_buf_free(&ud.scratchbuf, mem); @@ -6692,7 +6924,7 @@ void test_nghttp2_submit_altsvc(void) { nghttp2_session_callbacks callbacks; my_user_data ud; int rv; - ssize_t len; + nghttp2_ssize len; const uint8_t *data; nghttp2_frame_hd hd; size_t origin_len; @@ -6707,42 +6939,42 @@ void test_nghttp2_submit_altsvc(void) { sizeof(origin) - 1, field_value, sizeof(field_value) - 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); ud.frame_send_cb_called = 0; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len == NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1 + - sizeof(field_value) - 1); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1 + + sizeof(field_value) - 1, + ==, len); nghttp2_frame_unpack_frame_hd(&hd, data); - CU_ASSERT(2 + sizeof(origin) - 1 + sizeof(field_value) - 1 == hd.length); - CU_ASSERT(NGHTTP2_ALTSVC == hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); + assert_size(2 + sizeof(origin) - 1 + sizeof(field_value) - 1, ==, hd.length); + assert_uint8(NGHTTP2_ALTSVC, ==, hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); origin_len = nghttp2_get_uint16(data + NGHTTP2_FRAME_HDLEN); - CU_ASSERT(sizeof(origin) - 1 == origin_len); - CU_ASSERT(0 == - memcmp(origin, data + NGHTTP2_FRAME_HDLEN + 2, sizeof(origin) - 1)); - CU_ASSERT(0 == memcmp(field_value, - data + NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1, - hd.length - (sizeof(origin) - 1) - 2)); + assert_size(sizeof(origin) - 1, ==, origin_len); + assert_memory_equal(sizeof(origin) - 1, origin, + data + NGHTTP2_FRAME_HDLEN + 2); + assert_memory_equal(hd.length - (sizeof(origin) - 1) - 2, field_value, + data + NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1); /* submitting empty origin with stream_id == 0 is error */ rv = nghttp2_submit_altsvc(session, NGHTTP2_FLAG_NONE, 0, NULL, 0, field_value, sizeof(field_value) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* submitting non-empty origin with stream_id != 0 is error */ rv = nghttp2_submit_altsvc(session, NGHTTP2_FLAG_NONE, 1, origin, sizeof(origin) - 1, field_value, sizeof(field_value) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); nghttp2_session_del(session); @@ -6753,7 +6985,7 @@ void test_nghttp2_submit_altsvc(void) { sizeof(origin) - 1, field_value, sizeof(field_value) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_STATE == rv); + assert_int(NGHTTP2_ERR_INVALID_STATE, ==, rv); nghttp2_session_del(session); } @@ -6763,7 +6995,7 @@ void test_nghttp2_submit_origin(void) { nghttp2_session_callbacks callbacks; my_user_data ud; int rv; - ssize_t len; + nghttp2_ssize len; const uint8_t *data; static const uint8_t nghttp2[] = "https://nghttp2.org"; static const uint8_t examples[] = "https://examples.com"; @@ -6792,27 +7024,27 @@ void test_nghttp2_submit_origin(void) { rv = nghttp2_submit_origin(session, NGHTTP2_FLAG_NONE, ov, 2); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); ud.frame_send_cb_called = 0; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_ptrdiff(0, <, len); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_frame_unpack_frame_hd(&frame.hd, data); rv = nghttp2_frame_unpack_origin_payload( &frame.ext, data + NGHTTP2_FRAME_HDLEN, (size_t)len - NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == frame.hd.stream_id); - CU_ASSERT(NGHTTP2_ORIGIN == frame.hd.type); - CU_ASSERT(2 == origin.nov); - CU_ASSERT(0 == memcmp(nghttp2, origin.ov[0].origin, sizeof(nghttp2) - 1)); - CU_ASSERT(sizeof(nghttp2) - 1 == origin.ov[0].origin_len); - CU_ASSERT(0 == memcmp(examples, origin.ov[1].origin, sizeof(examples) - 1)); - CU_ASSERT(sizeof(examples) - 1 == origin.ov[1].origin_len); + assert_int(0, ==, rv); + assert_int32(0, ==, frame.hd.stream_id); + assert_uint8(NGHTTP2_ORIGIN, ==, frame.hd.type); + assert_size(2, ==, origin.nov); + assert_memory_equal(sizeof(nghttp2) - 1, nghttp2, origin.ov[0].origin); + assert_size(sizeof(nghttp2) - 1, ==, origin.ov[0].origin_len); + assert_memory_equal(sizeof(examples) - 1, examples, origin.ov[1].origin); + assert_size(sizeof(examples) - 1, ==, origin.ov[1].origin_len); nghttp2_frame_origin_free(&frame.ext, mem); @@ -6823,7 +7055,7 @@ void test_nghttp2_submit_origin(void) { rv = nghttp2_submit_origin(session, NGHTTP2_FLAG_NONE, ov, 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_STATE == rv); + assert_int(NGHTTP2_ERR_INVALID_STATE, ==, rv); nghttp2_session_del(session); @@ -6832,17 +7064,17 @@ void test_nghttp2_submit_origin(void) { rv = nghttp2_submit_origin(session, NGHTTP2_FLAG_NONE, NULL, 0); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); ud.frame_send_cb_called = 0; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len == NGHTTP2_FRAME_HDLEN); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN, ==, len); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_frame_unpack_frame_hd(&frame.hd, data); - CU_ASSERT(NGHTTP2_ORIGIN == frame.hd.type); + assert_uint8(NGHTTP2_ORIGIN, ==, frame.hd.type); nghttp2_session_del(session); } @@ -6856,7 +7088,7 @@ void test_nghttp2_submit_priority_update(void) { int rv; nghttp2_frame frame; nghttp2_ext_priority_update priority_update; - ssize_t len; + nghttp2_ssize len; int32_t stream_id; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); @@ -6867,38 +7099,38 @@ void test_nghttp2_submit_priority_update(void) { session->pending_no_rfc7540_priorities = 1; stream_id = - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(1 == stream_id); + assert_int32(1, ==, stream_id); - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); + assert_ptrdiff(0, <, len); rv = nghttp2_submit_priority_update(session, NGHTTP2_FLAG_NONE, stream_id, field_value, sizeof(field_value) - 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); frame.ext.payload = &priority_update; ud.frame_send_cb_called = 0; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_ptrdiff(0, <, len); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_frame_unpack_frame_hd(&frame.hd, data); nghttp2_frame_unpack_priority_update_payload( &frame.ext, (uint8_t *)(data + NGHTTP2_FRAME_HDLEN), (size_t)len - NGHTTP2_FRAME_HDLEN); - CU_ASSERT(0 == frame.hd.stream_id); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == frame.hd.type); - CU_ASSERT(stream_id == priority_update.stream_id); - CU_ASSERT(sizeof(field_value) - 1 == priority_update.field_value_len); - CU_ASSERT(0 == memcmp(field_value, priority_update.field_value, - sizeof(field_value) - 1)); + assert_int32(0, ==, frame.hd.stream_id); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, frame.hd.type); + assert_int32(stream_id, ==, priority_update.stream_id); + assert_size(sizeof(field_value) - 1, ==, priority_update.field_value_len); + assert_memory_equal(sizeof(field_value) - 1, field_value, + priority_update.field_value); nghttp2_session_del(session); @@ -6910,7 +7142,7 @@ void test_nghttp2_submit_priority_update(void) { rv = nghttp2_submit_priority_update(session, NGHTTP2_FLAG_NONE, 1, field_value, sizeof(field_value) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_STATE == rv); + assert_int(NGHTTP2_ERR_INVALID_STATE, ==, rv); nghttp2_session_del(session); @@ -6918,35 +7150,35 @@ void test_nghttp2_submit_priority_update(void) { nghttp2_session_client_new(&session, &callbacks, &ud); stream_id = - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(1 == stream_id); + assert_int32(1, ==, stream_id); - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); + assert_ptrdiff(0, <, len); rv = nghttp2_submit_priority_update(session, NGHTTP2_FLAG_NONE, stream_id, NULL, 0); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); frame.ext.payload = &priority_update; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); + assert_ptrdiff(0, <, len); nghttp2_frame_unpack_frame_hd(&frame.hd, data); nghttp2_frame_unpack_priority_update_payload( &frame.ext, (uint8_t *)(data + NGHTTP2_FRAME_HDLEN), (size_t)len - NGHTTP2_FRAME_HDLEN); - CU_ASSERT(0 == frame.hd.stream_id); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == frame.hd.type); - CU_ASSERT(stream_id == priority_update.stream_id); - CU_ASSERT(0 == priority_update.field_value_len); - CU_ASSERT(NULL == priority_update.field_value); + assert_int32(0, ==, frame.hd.stream_id); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, frame.hd.type); + assert_int32(stream_id, ==, priority_update.stream_id); + assert_size(0, ==, priority_update.field_value_len); + assert_null(priority_update.field_value); nghttp2_session_del(session); } @@ -6966,11 +7198,11 @@ void test_nghttp2_submit_rst_stream(void) { rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_session_del(session); @@ -6980,11 +7212,11 @@ void test_nghttp2_submit_rst_stream(void) { rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 2, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_session_del(session); @@ -6996,13 +7228,13 @@ void test_nghttp2_submit_rst_stream(void) { rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); nghttp2_session_del(session); @@ -7014,13 +7246,13 @@ void test_nghttp2_submit_rst_stream(void) { rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 2, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(2 == item->frame.hd.stream_id); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(2, ==, item->frame.hd.stream_id); nghttp2_session_del(session); @@ -7028,26 +7260,26 @@ void test_nghttp2_submit_rst_stream(void) { nghttp2_session_client_new(&session, &callbacks, NULL); stream_id = - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(stream_id > 0); + assert_int32(0, <, stream_id); item = nghttp2_outbound_queue_top(&session->ob_syn); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(0 == item->aux_data.headers.canceled); + assert_not_null(item); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_false(item->aux_data.headers.canceled); rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, stream_id, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_syn); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(1 == item->aux_data.headers.canceled); + assert_not_null(item); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_true(item->aux_data.headers.canceled); nghttp2_session_del(session); } @@ -7065,50 +7297,50 @@ void test_nghttp2_session_open_stream(void) { stream = nghttp2_session_open_stream(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(0 == session->num_outgoing_streams); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); - CU_ASSERT(245 == stream->weight); - CU_ASSERT(&session->root == stream->dep_prev); - CU_ASSERT(NGHTTP2_SHUT_NONE == stream->shut_flags); + assert_size(1, ==, session->num_incoming_streams); + assert_size(0, ==, session->num_outgoing_streams); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); + assert_int32(245, ==, stream->weight); + assert_ptr_equal(&session->root, stream->dep_prev); + assert_uint8(NGHTTP2_SHUT_NONE, ==, stream->shut_flags); stream = nghttp2_session_open_stream(session, 2, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_OPENING, NULL); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(1 == session->num_outgoing_streams); - CU_ASSERT(&session->root == stream->dep_prev); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(NGHTTP2_SHUT_NONE == stream->shut_flags); + assert_size(1, ==, session->num_incoming_streams); + assert_size(1, ==, session->num_outgoing_streams); + assert_ptr_equal(&session->root, stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_uint8(NGHTTP2_SHUT_NONE, ==, stream->shut_flags); stream = nghttp2_session_open_stream(session, 4, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_RESERVED, NULL); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(1 == session->num_outgoing_streams); - CU_ASSERT(&session->root == stream->dep_prev); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(NGHTTP2_SHUT_RD == stream->shut_flags); + assert_size(1, ==, session->num_incoming_streams); + assert_size(1, ==, session->num_outgoing_streams); + assert_ptr_equal(&session->root, stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_uint8(NGHTTP2_SHUT_RD, ==, stream->shut_flags); nghttp2_priority_spec_init(&pri_spec, 1, 17, 1); stream = nghttp2_session_open_stream(session, 3, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(17 == stream->weight); - CU_ASSERT(1 == stream->dep_prev->stream_id); + assert_int32(17, ==, stream->weight); + assert_int32(1, ==, stream->dep_prev->stream_id); /* Dependency to idle stream */ nghttp2_priority_spec_init(&pri_spec, 1000000007, 240, 1); stream = nghttp2_session_open_stream(session, 5, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(240 == stream->weight); - CU_ASSERT(1000000007 == stream->dep_prev->stream_id); + assert_int32(240, ==, stream->weight); + assert_int32(1000000007, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream_raw(session, 1000000007); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(&session->root == stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_ptr_equal(&session->root, stream->dep_prev); /* Dependency to closed stream which is not in dependency tree */ session->last_recv_stream_id = 7; @@ -7118,8 +7350,8 @@ void test_nghttp2_session_open_stream(void) { stream = nghttp2_session_open_stream(session, 9, NGHTTP2_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(&session->root == stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_ptr_equal(&session->root, stream->dep_prev); nghttp2_session_del(session); @@ -7127,11 +7359,11 @@ void test_nghttp2_session_open_stream(void) { stream = nghttp2_session_open_stream(session, 4, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_RESERVED, NULL); - CU_ASSERT(0 == session->num_incoming_streams); - CU_ASSERT(0 == session->num_outgoing_streams); - CU_ASSERT(&session->root == stream->dep_prev); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(NGHTTP2_SHUT_WR == stream->shut_flags); + assert_size(0, ==, session->num_incoming_streams); + assert_size(0, ==, session->num_outgoing_streams); + assert_ptr_equal(&session->root, stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_uint8(NGHTTP2_SHUT_WR, ==, stream->shut_flags); nghttp2_session_del(session); } @@ -7151,13 +7383,13 @@ void test_nghttp2_session_open_stream_with_idle_stream_dep(void) { stream = nghttp2_session_open_stream(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(245 == stream->weight); - CU_ASSERT(101 == stream->dep_prev->stream_id); + assert_int32(245, ==, stream->weight); + assert_int32(101, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream_raw(session, 101); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); nghttp2_priority_spec_init(&pri_spec, 211, 1, 0); @@ -7165,13 +7397,13 @@ void test_nghttp2_session_open_stream_with_idle_stream_dep(void) { stream = nghttp2_session_open_stream(session, 101, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(1 == stream->weight); - CU_ASSERT(211 == stream->dep_prev->stream_id); + assert_int32(1, ==, stream->weight); + assert_int32(211, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream_raw(session, 211); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); nghttp2_session_del(session); } @@ -7182,22 +7414,23 @@ void test_nghttp2_session_get_next_ob_item(void) { nghttp2_priority_spec pri_spec; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); session->remote_settings.max_concurrent_streams = 2; - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); - CU_ASSERT(NGHTTP2_PING == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_uint8(NGHTTP2_PING, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, NULL, 0, NULL, NULL)); - CU_ASSERT(NGHTTP2_PING == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_int32(1, ==, + nghttp2_submit_request2(session, NULL, NULL, 0, NULL, NULL)); + assert_uint8(NGHTTP2_PING, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); /* Incoming stream does not affect the number of outgoing max concurrent streams. */ @@ -7205,20 +7438,20 @@ void test_nghttp2_session_get_next_ob_item(void) { nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_MAX_WEIGHT, 0); - CU_ASSERT(3 == - nghttp2_submit_request(session, &pri_spec, NULL, 0, NULL, NULL)); - CU_ASSERT(NGHTTP2_HEADERS == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(3, ==, + nghttp2_submit_request2(session, &pri_spec, NULL, 0, NULL, NULL)); + assert_uint8(NGHTTP2_HEADERS, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(5 == - nghttp2_submit_request(session, &pri_spec, NULL, 0, NULL, NULL)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(5, ==, + nghttp2_submit_request2(session, &pri_spec, NULL, 0, NULL, NULL)); + assert_null(nghttp2_session_get_next_ob_item(session)); session->remote_settings.max_concurrent_streams = 3; - CU_ASSERT(NGHTTP2_HEADERS == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_uint8(NGHTTP2_HEADERS, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); nghttp2_session_del(session); @@ -7226,10 +7459,11 @@ void test_nghttp2_session_get_next_ob_item(void) { nghttp2_session_server_new(&session, &callbacks, NULL); session->remote_settings.max_concurrent_streams = 0; open_sent_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 2, - NULL, NULL, 0, NULL)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(1 == nghttp2_outbound_queue_size(&session->ob_syn)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 2, NULL, + NULL, 0, NULL)); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_size(1, ==, nghttp2_outbound_queue_size(&session->ob_syn)); nghttp2_session_del(session); } @@ -7242,30 +7476,30 @@ void test_nghttp2_session_pop_next_ob_item(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); session->remote_settings.max_concurrent_streams = 1; - CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + assert_null(nghttp2_session_pop_next_ob_item(session)); nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); nghttp2_priority_spec_init(&pri_spec, 0, 254, 0); - nghttp2_submit_request(session, &pri_spec, NULL, 0, NULL, NULL); + nghttp2_submit_request2(session, &pri_spec, NULL, 0, NULL, NULL); item = nghttp2_session_pop_next_ob_item(session); - CU_ASSERT(NGHTTP2_PING == item->frame.hd.type); + assert_uint8(NGHTTP2_PING, ==, item->frame.hd.type); nghttp2_outbound_item_free(item, mem); mem->free(item, NULL); item = nghttp2_session_pop_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); nghttp2_outbound_item_free(item, mem); mem->free(item, NULL); - CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + assert_null(nghttp2_session_pop_next_ob_item(session)); /* Incoming stream does not affect the number of outgoing max concurrent streams. */ @@ -7275,14 +7509,14 @@ void test_nghttp2_session_pop_next_ob_item(void) { nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_MAX_WEIGHT, 0); - nghttp2_submit_request(session, &pri_spec, NULL, 0, NULL, NULL); + nghttp2_submit_request2(session, &pri_spec, NULL, 0, NULL, NULL); - CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + assert_null(nghttp2_session_pop_next_ob_item(session)); session->remote_settings.max_concurrent_streams = 2; item = nghttp2_session_pop_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); nghttp2_outbound_item_free(item, mem); mem->free(item, NULL); @@ -7292,28 +7526,29 @@ void test_nghttp2_session_pop_next_ob_item(void) { nghttp2_session_server_new(&session, &callbacks, NULL); session->remote_settings.max_concurrent_streams = 0; open_sent_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 2, - NULL, NULL, 0, NULL)); - CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); - CU_ASSERT(1 == nghttp2_outbound_queue_size(&session->ob_syn)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 2, NULL, + NULL, 0, NULL)); + assert_null(nghttp2_session_pop_next_ob_item(session)); + assert_size(1, ==, nghttp2_outbound_queue_size(&session->ob_syn)); nghttp2_session_del(session); } void test_nghttp2_session_reply_fail(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = fail_send_callback; + callbacks.send_callback2 = fail_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 4 * 1024; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, NULL, 0, &data_prd)); - CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_submit_response2(session, 1, NULL, 0, &data_prd)); + assert_int(NGHTTP2_ERR_CALLBACK_FAILURE, ==, nghttp2_session_send(session)); nghttp2_session_del(session); } @@ -7326,7 +7561,7 @@ void test_nghttp2_session_max_concurrent_streams(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); open_recv_stream(session, 1); @@ -7336,25 +7571,25 @@ void test_nghttp2_session_max_concurrent_streams(void) { NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); session->pending_local_max_concurrent_stream = 1; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_REFUSED_STREAM == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_REFUSED_STREAM, ==, item->frame.rst_stream.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Check ACKed SETTINGS_MAX_CONCURRENT_STREAMS */ session->local_settings.max_concurrent_streams = 1; frame.hd.stream_id = 5; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_frame_headers_free(&frame.headers, mem); nghttp2_session_del(session); @@ -7364,12 +7599,12 @@ void test_nghttp2_session_stop_data_with_rst_stream(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_frame frame; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_send_callback = on_frame_send_callback; - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.frame_send_cb_called = 0; @@ -7377,28 +7612,28 @@ void test_nghttp2_session_stop_data_with_rst_stream(void) { nghttp2_session_server_new(&session, &callbacks, &ud); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - nghttp2_submit_response(session, 1, NULL, 0, &data_prd); + nghttp2_submit_response2(session, 1, NULL, 0, &data_prd); ud.block_count = 2; /* Sends response HEADERS + DATA[0] */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_DATA == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_DATA, ==, ud.sent_frame_type); /* data for DATA[1] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_CANCEL); - CU_ASSERT(0 == nghttp2_session_on_rst_stream_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_rst_stream_received(session, &frame)); nghttp2_frame_rst_stream_free(&frame.rst_stream); /* Big enough number to send all DATA frames potentially. */ ud.block_count = 100; /* Nothing will be sent in the following call. */ - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* With RST_STREAM, stream is canceled and further DATA on that stream are not sent. */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + assert_null(nghttp2_session_get_stream(session, 1)); nghttp2_session_del(session); } @@ -7407,13 +7642,13 @@ void test_nghttp2_session_defer_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_outbound_item *item; nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_send_callback = on_frame_send_callback; - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; data_prd.read_callback = defer_data_source_read_callback; ud.frame_send_cb_called = 0; @@ -7425,47 +7660,48 @@ void test_nghttp2_session_defer_data(void) { session->remote_window_size = 1 << 20; stream->remote_window_size = 1 << 20; - nghttp2_submit_response(session, 1, NULL, 0, &data_prd); + nghttp2_submit_response2(session, 1, NULL, 0, &data_prd); ud.block_count = 1; /* Sends HEADERS reply */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); /* No data is read */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 4); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 4); ud.block_count = 1; nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); /* Sends PING */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_PING == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_PING, ==, ud.sent_frame_type); /* Resume deferred DATA */ - CU_ASSERT(0 == nghttp2_session_resume_data(session, 1)); + assert_int(0, ==, nghttp2_session_resume_data(session, 1)); item = stream->item; - item->aux_data.data.data_prd.read_callback = + item->aux_data.data.dpw.data_prd.v1.read_callback = fixed_length_data_source_read_callback; ud.block_count = 1; /* Reads 2 DATA chunks */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); /* Deferred again */ - item->aux_data.data.data_prd.read_callback = defer_data_source_read_callback; + item->aux_data.data.dpw.data_prd.v1.read_callback = + defer_data_source_read_callback; /* This is needed since 16KiB block is already read and waiting to be sent. No read_callback invocation. */ ud.block_count = 1; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); /* Resume deferred DATA */ - CU_ASSERT(0 == nghttp2_session_resume_data(session, 1)); - item->aux_data.data.data_prd.read_callback = + assert_int(0, ==, nghttp2_session_resume_data(session, 1)); + item->aux_data.data.dpw.data_prd.v1.read_callback = fixed_length_data_source_read_callback; ud.block_count = 1; /* Reads 2 16KiB blocks */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(ud.data_source_length == 0); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(ud.data_source_length, ==, 0); nghttp2_session_del(session); } @@ -7474,7 +7710,7 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_frame frame; nghttp2_stream *stream; int32_t new_initial_window_size; @@ -7484,7 +7720,7 @@ void test_nghttp2_session_flow_control(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = fixed_bytes_send_callback; + callbacks.send_callback2 = fixed_bytes_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; @@ -7500,11 +7736,11 @@ void test_nghttp2_session_flow_control(void) { session->remote_window_size = 64 * 1024; session->remote_settings.initial_window_size = 64 * 1024; - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); /* Sends 64KiB - 1 data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(64 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(64 * 1024, ==, ud.data_source_length); /* Back 32KiB in stream window */ nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 1, @@ -7512,16 +7748,16 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session_on_window_update_received(session, &frame); /* Send nothing because of connection-level window */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(64 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(64 * 1024, ==, ud.data_source_length); /* Back 32KiB in connection-level window */ frame.hd.stream_id = 0; nghttp2_session_on_window_update_received(session, &frame); /* Sends another 32KiB data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(32 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(32 * 1024, ==, ud.data_source_length); stream = nghttp2_session_get_stream(session, 1); /* Change initial window size to 16KiB. The window_size becomes @@ -7533,7 +7769,7 @@ void test_nghttp2_session_flow_control(void) { stream->remote_window_size); session->remote_settings.initial_window_size = (uint32_t)new_initial_window_size; - CU_ASSERT(-48 * 1024 == stream->remote_window_size); + assert_int32(-48 * 1024, ==, stream->remote_window_size); /* Back 48KiB to stream window */ frame.hd.stream_id = 1; @@ -7541,8 +7777,8 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session_on_window_update_received(session, &frame); /* Nothing is sent because window_size is 0 */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(32 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(32 * 1024, ==, ud.data_source_length); /* Back 16KiB in stream window */ frame.hd.stream_id = 1; @@ -7555,8 +7791,8 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session_on_window_update_received(session, &frame); /* Sends another 16KiB data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(16 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(16 * 1024, ==, ud.data_source_length); /* Increase initial window size to 32KiB */ iv[0].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; @@ -7568,8 +7804,8 @@ void test_nghttp2_session_flow_control(void) { nghttp2_frame_settings_free(&settings_frame.settings, mem); /* Sends another 8KiB data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(8 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(8 * 1024, ==, ud.data_source_length); /* Back 8KiB in connection-level window */ frame.hd.stream_id = 0; @@ -7577,10 +7813,10 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session_on_window_update_received(session, &frame); /* Sends last 8KiB data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); - CU_ASSERT(nghttp2_session_get_stream(session, 1)->shut_flags & - NGHTTP2_SHUT_WR); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(0, ==, ud.data_source_length); + assert_true(nghttp2_session_get_stream(session, 1)->shut_flags & + NGHTTP2_SHUT_WR); nghttp2_frame_window_update_free(&frame.window_update); nghttp2_session_del(session); @@ -7595,7 +7831,7 @@ void test_nghttp2_session_flow_control_data_recv(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* Initial window size to 64KiB - 1*/ nghttp2_session_client_new(&session, &callbacks, NULL); @@ -7613,34 +7849,36 @@ void test_nghttp2_session_flow_control_data_recv(void) { NGHTTP2_FLAG_END_STREAM, 1); nghttp2_frame_pack_frame_hd(data, &hd); - CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN == - nghttp2_session_mem_recv( - session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); + assert_ptrdiff( + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN, ==, + nghttp2_session_mem_recv2(session, data, + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); item = nghttp2_session_get_next_ob_item(session); /* Since this is the last frame, stream-level WINDOW_UPDATE is not issued, but connection-level is. */ - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN == - item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.hd.stream_id); + assert_int32(NGHTTP2_MAX_PAYLOADLEN, ==, + item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Receive DATA for closed stream. They are still subject to under connection-level flow control, since this situation arises when RST_STREAM is issued by the remote, but the local side keeps sending DATA frames. Without calculating connection-level window, the subsequent flow control gets confused. */ - CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN == - nghttp2_session_mem_recv( - session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); + assert_ptrdiff( + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN, ==, + nghttp2_session_mem_recv2(session, data, + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN == - item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.hd.stream_id); + assert_int32(NGHTTP2_MAX_PAYLOADLEN, ==, + item->frame.window_update.window_size_increment); nghttp2_session_del(session); } @@ -7654,7 +7892,7 @@ void test_nghttp2_session_flow_control_data_with_padding_recv(void) { nghttp2_option *option; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_option_new(&option); /* Disable auto window update so that we can check padding is @@ -7676,66 +7914,69 @@ void test_nghttp2_session_flow_control_data_with_padding_recv(void) { /* Set Pad Length field, which itself is padding */ data[NGHTTP2_FRAME_HDLEN] = 255; - CU_ASSERT( - (ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length) == - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + hd.length)); + assert_ptrdiff((nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + hd.length), ==, + nghttp2_session_mem_recv2(session, data, + NGHTTP2_FRAME_HDLEN + hd.length)); - CU_ASSERT((int32_t)hd.length == session->recv_window_size); - CU_ASSERT((int32_t)hd.length == stream->recv_window_size); - CU_ASSERT(256 == session->consumed_size); - CU_ASSERT(256 == stream->consumed_size); - CU_ASSERT(357 == session->recv_window_size); - CU_ASSERT(357 == stream->recv_window_size); + assert_int32((int32_t)hd.length, ==, session->recv_window_size); + assert_int32((int32_t)hd.length, ==, stream->recv_window_size); + assert_int32(256, ==, session->consumed_size); + assert_int32(256, ==, stream->consumed_size); + assert_int32(357, ==, session->recv_window_size); + assert_int32(357, ==, stream->recv_window_size); /* Receive the same DATA frame, but in 2 parts: first 9 + 1 + 102 bytes which includes 1st padding byte, and remainder */ - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + 103) == - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 103)); - CU_ASSERT(258 == session->consumed_size); - CU_ASSERT(258 == stream->consumed_size); - CU_ASSERT(460 == session->recv_window_size); - CU_ASSERT(460 == stream->recv_window_size); + assert_ptrdiff( + (nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + 103), ==, + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 103)); + assert_int32(258, ==, session->consumed_size); + assert_int32(258, ==, stream->consumed_size); + assert_int32(460, ==, session->recv_window_size); + assert_int32(460, ==, stream->recv_window_size); /* 357 - 103 = 254 bytes left */ - CU_ASSERT(254 == nghttp2_session_mem_recv(session, data, 254)); - CU_ASSERT(512 == session->consumed_size); - CU_ASSERT(512 == stream->consumed_size); - CU_ASSERT(714 == session->recv_window_size); - CU_ASSERT(714 == stream->recv_window_size); + assert_ptrdiff(254, ==, nghttp2_session_mem_recv2(session, data, 254)); + assert_int32(512, ==, session->consumed_size); + assert_int32(512, ==, stream->consumed_size); + assert_int32(714, ==, session->recv_window_size); + assert_int32(714, ==, stream->recv_window_size); /* Receive the same DATA frame, but in 2 parts: first 9 = 1 + 101 bytes which only includes data without padding, 2nd part is padding only */ - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + 102) == - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 102)); - CU_ASSERT(513 == session->consumed_size); - CU_ASSERT(513 == stream->consumed_size); - CU_ASSERT(816 == session->recv_window_size); - CU_ASSERT(816 == stream->recv_window_size); + assert_ptrdiff( + (nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + 102), ==, + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 102)); + assert_int32(513, ==, session->consumed_size); + assert_int32(513, ==, stream->consumed_size); + assert_int32(816, ==, session->recv_window_size); + assert_int32(816, ==, stream->recv_window_size); /* 357 - 102 = 255 bytes left */ - CU_ASSERT(255 == nghttp2_session_mem_recv(session, data, 255)); - CU_ASSERT(768 == session->consumed_size); - CU_ASSERT(768 == stream->consumed_size); - CU_ASSERT(1071 == session->recv_window_size); - CU_ASSERT(1071 == stream->recv_window_size); + assert_ptrdiff(255, ==, nghttp2_session_mem_recv2(session, data, 255)); + assert_int32(768, ==, session->consumed_size); + assert_int32(768, ==, stream->consumed_size); + assert_int32(1071, ==, session->recv_window_size); + assert_int32(1071, ==, stream->recv_window_size); /* Receive the same DATA frame, but in 2 parts: first 9 = 1 + 50 bytes which includes byte up to middle of data, 2nd part is the remainder */ - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + 51) == - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 51)); - CU_ASSERT(769 == session->consumed_size); - CU_ASSERT(769 == stream->consumed_size); - CU_ASSERT(1122 == session->recv_window_size); - CU_ASSERT(1122 == stream->recv_window_size); + assert_ptrdiff( + (nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + 51), ==, + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 51)); + assert_int32(769, ==, session->consumed_size); + assert_int32(769, ==, stream->consumed_size); + assert_int32(1122, ==, session->recv_window_size); + assert_int32(1122, ==, stream->recv_window_size); /* 357 - 51 = 306 bytes left */ - CU_ASSERT(306 == nghttp2_session_mem_recv(session, data, 306)); - CU_ASSERT(1024 == session->consumed_size); - CU_ASSERT(1024 == stream->consumed_size); - CU_ASSERT(1428 == session->recv_window_size); - CU_ASSERT(1428 == stream->recv_window_size); + assert_ptrdiff(306, ==, nghttp2_session_mem_recv2(session, data, 306)); + assert_int32(1024, ==, session->consumed_size); + assert_int32(1024, ==, stream->consumed_size); + assert_int32(1428, ==, session->recv_window_size); + assert_int32(1428, ==, stream->recv_window_size); nghttp2_session_del(session); } @@ -7744,13 +7985,13 @@ void test_nghttp2_session_data_read_temporal_failure(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_frame frame; nghttp2_stream *stream; size_t data_size = 128 * 1024; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; @@ -7758,17 +7999,18 @@ void test_nghttp2_session_data_read_temporal_failure(void) { /* Initial window size is 64KiB - 1 */ nghttp2_session_client_new(&session, &callbacks, &ud); - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); /* Sends NGHTTP2_INITIAL_WINDOW_SIZE data, assuming, it is equal to or smaller than NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(data_size - NGHTTP2_INITIAL_WINDOW_SIZE == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(data_size - NGHTTP2_INITIAL_WINDOW_SIZE, ==, + ud.data_source_length); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_DATA == stream->item->frame.hd.type); + assert_uint8(NGHTTP2_DATA, ==, stream->item->frame.hd.type); - stream->item->aux_data.data.data_prd.read_callback = + stream->item->aux_data.data.dpw.data_prd.v1.read_callback = temporal_failure_data_source_read_callback; /* Back NGHTTP2_INITIAL_WINDOW_SIZE to both connection-level and @@ -7782,16 +8024,17 @@ void test_nghttp2_session_data_read_temporal_failure(void) { /* Sending data will fail (soft fail) and treated as stream error */ ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(data_size - NGHTTP2_INITIAL_WINDOW_SIZE == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(data_size - NGHTTP2_INITIAL_WINDOW_SIZE, ==, + ud.data_source_length); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_RST_STREAM == ud.sent_frame_type); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_RST_STREAM, ==, ud.sent_frame_type); data_prd.read_callback = fail_data_source_read_callback; - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); /* Sending data will fail (hard fail) and session tear down */ - CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == nghttp2_session_send(session)); + assert_int(NGHTTP2_ERR_CALLBACK_FAILURE, ==, nghttp2_session_send(session)); nghttp2_session_del(session); } @@ -7810,9 +8053,9 @@ void test_nghttp2_session_on_stream_close(void) { stream = open_sent_stream3(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_OPENED, &user_data); - CU_ASSERT(stream != NULL); - CU_ASSERT(nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR) == 0); - CU_ASSERT(user_data.stream_close_cb_called == 1); + assert_not_null(stream); + assert_int(0, ==, nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR)); + assert_int(1, ==, user_data.stream_close_cb_called); nghttp2_session_del(session); } @@ -7824,7 +8067,7 @@ void test_nghttp2_session_on_ctrl_not_send(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_not_send_callback = on_frame_not_send_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; user_data.frame_not_send_cb_called = 0; user_data.not_sent_frame_type = 0; user_data.not_sent_error = 0; @@ -7836,57 +8079,64 @@ void test_nghttp2_session_on_ctrl_not_send(void) { /* Check response HEADERS */ /* Send bogus stream ID */ - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 3, - NULL, NULL, 0, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED == user_data.not_sent_error); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 3, NULL, + NULL, 0, NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, user_data.not_sent_frame_type); + assert_int(NGHTTP2_ERR_STREAM_CLOSED, ==, user_data.not_sent_error); user_data.frame_not_send_cb_called = 0; /* Shutdown transmission */ stream->shut_flags |= NGHTTP2_SHUT_WR; - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, NULL, 0, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_STREAM_SHUT_WR == user_data.not_sent_error); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + NULL, 0, NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, user_data.not_sent_frame_type); + assert_int(NGHTTP2_ERR_STREAM_SHUT_WR, ==, user_data.not_sent_error); stream->shut_flags = NGHTTP2_SHUT_NONE; user_data.frame_not_send_cb_called = 0; /* Queue RST_STREAM */ - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, NULL, 0, NULL)); - CU_ASSERT(0 == nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, - NGHTTP2_INTERNAL_ERROR)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSING == user_data.not_sent_error); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + NULL, 0, NULL)); + assert_int(0, ==, + nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, + NGHTTP2_INTERNAL_ERROR)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, user_data.not_sent_frame_type); + assert_int(NGHTTP2_ERR_STREAM_CLOSING, ==, user_data.not_sent_error); nghttp2_session_del(session); /* Check request HEADERS */ user_data.frame_not_send_cb_called = 0; - CU_ASSERT(nghttp2_session_client_new(&session, &callbacks, &user_data) == 0); + assert_int(0, ==, + nghttp2_session_client_new(&session, &callbacks, &user_data)); /* Maximum Stream ID is reached */ session->next_stream_id = (1u << 31) + 1; - CU_ASSERT(NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE == - nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, NULL, - NULL, 0, NULL)); + assert_int32(NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, NULL, 0, NULL)); user_data.frame_not_send_cb_called = 0; /* GOAWAY received */ session->goaway_flags |= NGHTTP2_GOAWAY_RECV; session->next_stream_id = 9; - CU_ASSERT(0 < nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NULL, NULL, 0, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_START_STREAM_NOT_ALLOWED == user_data.not_sent_error); + assert_int32(0, <, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, NULL, 0, NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, user_data.not_sent_frame_type); + assert_int(NGHTTP2_ERR_START_STREAM_NOT_ALLOWED, ==, + user_data.not_sent_error); nghttp2_session_del(session); } @@ -7896,15 +8146,16 @@ void test_nghttp2_session_get_outbound_queue_size(void) { nghttp2_session_callbacks callbacks; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); - CU_ASSERT(0 == nghttp2_session_get_outbound_queue_size(session)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_size(0, ==, nghttp2_session_get_outbound_queue_size(session)); - CU_ASSERT(0 == nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL)); - CU_ASSERT(1 == nghttp2_session_get_outbound_queue_size(session)); + assert_int(0, ==, nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL)); + assert_size(1, ==, nghttp2_session_get_outbound_queue_size(session)); - CU_ASSERT(0 == nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 2, - NGHTTP2_NO_ERROR, NULL, 0)); - CU_ASSERT(2 == nghttp2_session_get_outbound_queue_size(session)); + assert_int(0, ==, + nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 2, + NGHTTP2_NO_ERROR, NULL, 0)); + assert_size(2, ==, nghttp2_session_get_outbound_queue_size(session)); nghttp2_session_del(session); } @@ -7915,84 +8166,89 @@ void test_nghttp2_session_get_effective_local_window_size(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); stream = open_sent_stream(session, 1); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE == - nghttp2_session_get_effective_local_window_size(session)); - CU_ASSERT(0 == nghttp2_session_get_effective_recv_data_length(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE, ==, + nghttp2_session_get_effective_local_window_size(session)); + assert_int32(0, ==, nghttp2_session_get_effective_recv_data_length(session)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - nghttp2_session_get_stream_effective_local_window_size(session, 1)); - CU_ASSERT(0 == - nghttp2_session_get_stream_effective_recv_data_length(session, 1)); + assert_int32( + NGHTTP2_INITIAL_WINDOW_SIZE, ==, + nghttp2_session_get_stream_effective_local_window_size(session, 1)); + assert_int32( + 0, ==, nghttp2_session_get_stream_effective_recv_data_length(session, 1)); /* Check connection flow control */ session->recv_window_size = 100; nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 1100); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000 == - nghttp2_session_get_effective_local_window_size(session)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000 == - nghttp2_session_get_local_window_size(session)); - CU_ASSERT(0 == nghttp2_session_get_effective_recv_data_length(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_effective_local_window_size(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_local_window_size(session)); + assert_int32(0, ==, nghttp2_session_get_effective_recv_data_length(session)); nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, -50); /* Now session->recv_window_size = -50 */ - CU_ASSERT(-50 == session->recv_window_size); - CU_ASSERT(50 == session->recv_reduction); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 950 == - nghttp2_session_get_effective_local_window_size(session)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000 == - nghttp2_session_get_local_window_size(session)); - CU_ASSERT(0 == nghttp2_session_get_effective_recv_data_length(session)); + assert_int32(-50, ==, session->recv_window_size); + assert_int32(50, ==, session->recv_reduction); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 950, ==, + nghttp2_session_get_effective_local_window_size(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_local_window_size(session)); + assert_int32(0, ==, nghttp2_session_get_effective_recv_data_length(session)); session->recv_window_size += 50; /* Now session->recv_window_size = 0 */ - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 950 == - nghttp2_session_get_local_window_size(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 950, ==, + nghttp2_session_get_local_window_size(session)); nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 100); - CU_ASSERT(50 == session->recv_window_size); - CU_ASSERT(0 == session->recv_reduction); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1050 == - nghttp2_session_get_effective_local_window_size(session)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000 == - nghttp2_session_get_local_window_size(session)); - CU_ASSERT(50 == nghttp2_session_get_effective_recv_data_length(session)); + assert_int32(50, ==, session->recv_window_size); + assert_int32(0, ==, session->recv_reduction); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1050, ==, + nghttp2_session_get_effective_local_window_size(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_local_window_size(session)); + assert_int32(50, ==, nghttp2_session_get_effective_recv_data_length(session)); /* Check stream flow control */ stream->recv_window_size = 100; nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 1, 1100); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1000 == - nghttp2_session_get_stream_effective_local_window_size(session, 1)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1000 == - nghttp2_session_get_stream_local_window_size(session, 1)); - CU_ASSERT(0 == - nghttp2_session_get_stream_effective_recv_data_length(session, 1)); + assert_int32( + NGHTTP2_INITIAL_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_stream_effective_local_window_size(session, 1)); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int32( + 0, ==, nghttp2_session_get_stream_effective_recv_data_length(session, 1)); nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 1, -50); /* Now stream->recv_window_size = -50 */ - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 950 == - nghttp2_session_get_stream_effective_local_window_size(session, 1)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1000 == - nghttp2_session_get_stream_local_window_size(session, 1)); - CU_ASSERT(0 == - nghttp2_session_get_stream_effective_recv_data_length(session, 1)); + assert_int32( + NGHTTP2_INITIAL_WINDOW_SIZE + 950, ==, + nghttp2_session_get_stream_effective_local_window_size(session, 1)); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int32( + 0, ==, nghttp2_session_get_stream_effective_recv_data_length(session, 1)); stream->recv_window_size += 50; /* Now stream->recv_window_size = 0 */ nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 1, 100); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1050 == - nghttp2_session_get_stream_effective_local_window_size(session, 1)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1000 == - nghttp2_session_get_stream_local_window_size(session, 1)); - CU_ASSERT(50 == - nghttp2_session_get_stream_effective_recv_data_length(session, 1)); + assert_int32( + NGHTTP2_INITIAL_WINDOW_SIZE + 1050, ==, + nghttp2_session_get_stream_effective_local_window_size(session, 1)); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int32( + 50, ==, + nghttp2_session_get_stream_effective_recv_data_length(session, 1)); nghttp2_session_del(session); } @@ -8005,7 +8261,7 @@ void test_nghttp2_session_set_option(void) { int rv; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* Test for nghttp2_option_set_no_auto_window_update */ nghttp2_option_new(&option); @@ -8013,7 +8269,7 @@ void test_nghttp2_session_set_option(void) { nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE); + assert_true(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8024,7 +8280,7 @@ void test_nghttp2_session_set_option(void) { nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(100 == session->remote_settings.max_concurrent_streams); + assert_uint32(100, ==, session->remote_settings.max_concurrent_streams); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8034,7 +8290,7 @@ void test_nghttp2_session_set_option(void) { nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(99 == session->max_incoming_reserved_streams); + assert_size(99, ==, session->max_incoming_reserved_streams); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8044,7 +8300,7 @@ void test_nghttp2_session_set_option(void) { nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_PING_ACK); + assert_true(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_PING_ACK); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8057,15 +8313,15 @@ void test_nghttp2_session_set_option(void) { deflater = &session->hd_deflater; - rv = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + rv = nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(1 == rv); + assert_int(1, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == deflater->deflate_hd_table_bufsize_max); - CU_ASSERT(0 == deflater->ctx.hd_table_bufsize); + assert_int(0, ==, rv); + assert_size(0, ==, deflater->deflate_hd_table_bufsize_max); + assert_size(0, ==, deflater->ctx.hd_table_bufsize); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8075,11 +8331,11 @@ void test_nghttp2_session_data_backoff_by_high_pri_frame(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; @@ -8087,34 +8343,34 @@ void test_nghttp2_session_data_backoff_by_high_pri_frame(void) { ud.data_source_length = NGHTTP2_DATA_PAYLOADLEN * 4; nghttp2_session_client_new(&session, &callbacks, &ud); - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); session->remote_window_size = 1 << 20; ud.block_count = 2; /* Sends request HEADERS + DATA[0] */ - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); stream->remote_window_size = 1 << 20; - CU_ASSERT(NGHTTP2_DATA == ud.sent_frame_type); + assert_uint8(NGHTTP2_DATA, ==, ud.sent_frame_type); /* data for DATA[1] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); ud.block_count = 2; /* Sends DATA[1] + PING, PING is interleaved in DATA sequence */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_PING == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_PING, ==, ud.sent_frame_type); /* data for DATA[2] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN); ud.block_count = 2; /* Sends DATA[2..3] */ - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + assert_true(stream->shut_flags & NGHTTP2_SHUT_WR); nghttp2_session_del(session); } @@ -8140,10 +8396,11 @@ static void check_session_recv_data_with_padding(nghttp2_bufs *bufs, ud.frame_recv_cb_called = 0; ud.data_chunk_len = 0; - CU_ASSERT((ssize_t)inlen == nghttp2_session_mem_recv(session, in, inlen)); + assert_ptrdiff((nghttp2_ssize)inlen, ==, + nghttp2_session_mem_recv2(session, in, inlen)); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(datalen == ud.data_chunk_len); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_size(datalen, ==, ud.data_chunk_len); mem->free(in, NULL); nghttp2_session_del(session); @@ -8153,7 +8410,7 @@ void test_nghttp2_session_pack_data_with_padding(void) { nghttp2_session *session; my_user_data ud; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_frame *frame; size_t datalen = 55; nghttp2_mem *mem; @@ -8161,9 +8418,9 @@ void test_nghttp2_session_pack_data_with_padding(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - callbacks.select_padding_callback = select_padding_callback; + callbacks.select_padding_callback2 = select_padding_callback; data_prd.read_callback = fixed_length_data_source_read_callback; @@ -8171,17 +8428,17 @@ void test_nghttp2_session_pack_data_with_padding(void) { ud.padlen = 63; - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); ud.block_count = 1; ud.data_source_length = datalen; /* Sends HEADERS */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); frame = &session->aob.item->frame; - CU_ASSERT(ud.padlen == frame->data.padlen); - CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PADDED); + assert_size(ud.padlen, ==, frame->data.padlen); + assert_true(frame->hd.flags & NGHTTP2_FLAG_PADDED); /* Check reception of this DATA frame */ check_session_recv_data_with_padding(&session->aob.framebufs, datalen, mem); @@ -8196,9 +8453,9 @@ void test_nghttp2_session_pack_headers_with_padding(void) { nghttp2_session_callbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - callbacks.select_padding_callback = select_padding_callback; + callbacks.select_padding_callback2 = select_padding_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; acc.length = 0; @@ -8209,16 +8466,17 @@ void test_nghttp2_session_pack_headers_with_padding(void) { ud.padlen = 163; - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), - NULL, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int32( + 1, ==, + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(acc.length < NGHTTP2_MAX_PAYLOADLEN); + assert_size(NGHTTP2_MAX_PAYLOADLEN, >, acc.length); ud.frame_recv_cb_called = 0; - CU_ASSERT((ssize_t)acc.length == - nghttp2_session_mem_recv(sv_session, acc.buf, acc.length)); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(sv_session)); + assert_ptrdiff((nghttp2_ssize)acc.length, ==, + nghttp2_session_mem_recv2(sv_session, acc.buf, acc.length)); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_null(nghttp2_session_get_next_ob_item(sv_session)); nghttp2_session_del(sv_session); nghttp2_session_del(session); @@ -8227,7 +8485,7 @@ void test_nghttp2_session_pack_headers_with_padding(void) { void test_nghttp2_pack_settings_payload(void) { nghttp2_settings_entry iv[2]; uint8_t buf[64]; - ssize_t len; + nghttp2_ssize len; nghttp2_settings_entry *resiv; size_t resniv; nghttp2_mem *mem; @@ -8239,28 +8497,29 @@ void test_nghttp2_pack_settings_payload(void) { iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; iv[1].value = 4095; - len = nghttp2_pack_settings_payload(buf, sizeof(buf), iv, 2); - CU_ASSERT(2 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH == len); - CU_ASSERT(0 == nghttp2_frame_unpack_settings_payload2(&resiv, &resniv, buf, - (size_t)len, mem)); - CU_ASSERT(2 == resniv); - CU_ASSERT(NGHTTP2_SETTINGS_HEADER_TABLE_SIZE == resiv[0].settings_id); - CU_ASSERT(1023 == resiv[0].value); - CU_ASSERT(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE == resiv[1].settings_id); - CU_ASSERT(4095 == resiv[1].value); + len = nghttp2_pack_settings_payload2(buf, sizeof(buf), iv, 2); + assert_ptrdiff(2 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH, ==, len); + assert_int(0, ==, + nghttp2_frame_unpack_settings_payload2(&resiv, &resniv, buf, + (size_t)len, mem)); + assert_size(2, ==, resniv); + assert_int32(NGHTTP2_SETTINGS_HEADER_TABLE_SIZE, ==, resiv[0].settings_id); + assert_uint32(1023, ==, resiv[0].value); + assert_int32(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, ==, resiv[1].settings_id); + assert_uint32(4095, ==, resiv[1].value); mem->free(resiv, NULL); - len = nghttp2_pack_settings_payload(buf, 9 /* too small */, iv, 2); - CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == len); + len = nghttp2_pack_settings_payload2(buf, 9 /* too small */, iv, 2); + assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, len); } #define check_stream_dep_sib(STREAM, DEP_PREV, DEP_NEXT, SIB_PREV, SIB_NEXT) \ do { \ - CU_ASSERT(DEP_PREV == STREAM->dep_prev); \ - CU_ASSERT(DEP_NEXT == STREAM->dep_next); \ - CU_ASSERT(SIB_PREV == STREAM->sib_prev); \ - CU_ASSERT(SIB_NEXT == STREAM->sib_next); \ + assert_ptr_equal(DEP_PREV, STREAM->dep_prev); \ + assert_ptr_equal(DEP_NEXT, STREAM->dep_next); \ + assert_ptr_equal(SIB_PREV, STREAM->sib_prev); \ + assert_ptr_equal(SIB_NEXT, STREAM->sib_next); \ } while (0) /* nghttp2_stream_dep_add() and its families functions should be @@ -8290,17 +8549,17 @@ void test_nghttp2_session_stream_dep_add(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, root, b, NULL, NULL); check_stream_dep_sib(b, a, NULL, NULL, c); check_stream_dep_sib(c, a, d, b, NULL); check_stream_dep_sib(d, c, NULL, NULL, NULL); - CU_ASSERT(a == session->root.dep_next); + assert_ptr_equal(a, session->root.dep_next); e = open_stream_with_dep_excl(session, 9, a); @@ -8313,11 +8572,11 @@ void test_nghttp2_session_stream_dep_add(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == e->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, e->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, root, e, NULL, NULL); check_stream_dep_sib(e, a, b, NULL, NULL); @@ -8325,7 +8584,7 @@ void test_nghttp2_session_stream_dep_add(void) { check_stream_dep_sib(c, e, d, b, NULL); check_stream_dep_sib(d, c, NULL, NULL, NULL); - CU_ASSERT(a == session->root.dep_next); + assert_ptr_equal(a, session->root.dep_next); nghttp2_session_del(session); } @@ -8362,17 +8621,17 @@ void test_nghttp2_session_stream_dep_remove(void) { * d */ - CU_ASSERT(0 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(0, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, NULL, NULL, NULL, NULL); check_stream_dep_sib(b, root, NULL, c, NULL); check_stream_dep_sib(c, root, d, NULL, b); check_stream_dep_sib(d, c, NULL, NULL, NULL); - CU_ASSERT(c == session->root.dep_next); + assert_ptr_equal(c, session->root.dep_next); nghttp2_session_del(session); @@ -8403,17 +8662,17 @@ void test_nghttp2_session_stream_dep_remove(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); check_stream_dep_sib(a, root, c, NULL, NULL); check_stream_dep_sib(b, NULL, NULL, NULL, NULL); check_stream_dep_sib(c, a, d, NULL, NULL); check_stream_dep_sib(d, c, NULL, NULL, NULL); - CU_ASSERT(a == session->root.dep_next); + assert_ptr_equal(a, session->root.dep_next); nghttp2_session_del(session); @@ -8443,11 +8702,11 @@ void test_nghttp2_session_stream_dep_remove(void) { * e--d--b */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == c->sum_dep_weight); - CU_ASSERT(0 == e->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, c->sum_dep_weight); + assert_int32(0, ==, e->sum_dep_weight); check_stream_dep_sib(a, root, e, NULL, NULL); check_stream_dep_sib(b, a, NULL, d, NULL); @@ -8476,12 +8735,12 @@ void test_nghttp2_session_stream_dep_remove(void) { * f--e */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 3 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == e->sum_dep_weight); - CU_ASSERT(0 == f->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, e->sum_dep_weight); + assert_int32(0, ==, f->sum_dep_weight); nghttp2_stream_dep_remove(c); @@ -8493,12 +8752,12 @@ void test_nghttp2_session_stream_dep_remove(void) { /* c's weight 16 is distributed evenly to e and f. Each weight of e and f becomes 8. */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 + 8 * 2 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(0 == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == e->sum_dep_weight); - CU_ASSERT(0 == f->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2 + 8 * 2, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(0, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, e->sum_dep_weight); + assert_int32(0, ==, f->sum_dep_weight); check_stream_dep_sib(a, root, d, NULL, NULL); check_stream_dep_sib(b, a, NULL, e, NULL); @@ -8548,12 +8807,12 @@ void test_nghttp2_session_stream_dep_add_subtree(void) { * f d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 3 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == e->sum_dep_weight); - CU_ASSERT(0 == f->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, e->sum_dep_weight); + assert_int32(0, ==, f->sum_dep_weight); check_stream_dep_sib(a, root, e, NULL, NULL); check_stream_dep_sib(b, a, NULL, c, NULL); @@ -8597,12 +8856,12 @@ void test_nghttp2_session_stream_dep_add_subtree(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 3 == e->sum_dep_weight); - CU_ASSERT(0 == f->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, e->sum_dep_weight); + assert_int32(0, ==, f->sum_dep_weight); check_stream_dep_sib(a, root, e, NULL, NULL); check_stream_dep_sib(e, a, f, NULL, NULL); @@ -8646,10 +8905,10 @@ void test_nghttp2_session_stream_dep_remove_subtree(void) { * b d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, root, b, NULL, NULL); check_stream_dep_sib(b, a, NULL, NULL, NULL); @@ -8685,10 +8944,10 @@ void test_nghttp2_session_stream_dep_remove_subtree(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, root, c, NULL, NULL); check_stream_dep_sib(c, a, d, NULL, NULL); @@ -8723,11 +8982,11 @@ void test_nghttp2_session_stream_dep_remove_subtree(void) { * b--e d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == e->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, e->sum_dep_weight); check_stream_dep_sib(a, root, b, NULL, NULL); check_stream_dep_sib(b, a, NULL, NULL, e); @@ -8764,7 +9023,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { */ nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8774,13 +9033,13 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); check_stream_dep_sib(c, root, a, NULL, NULL); check_stream_dep_sib(a, c, b, NULL, NULL); @@ -8801,7 +9060,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { */ nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8809,13 +9068,13 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b--a */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == c->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(0 == a->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(0, ==, a->sum_dep_weight); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); check_stream_dep_sib(c, root, b, NULL, NULL); check_stream_dep_sib(b, c, NULL, NULL, a); @@ -8839,7 +9098,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { */ nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8849,15 +9108,15 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); check_stream_dep_sib(c, root, d, NULL, NULL); check_stream_dep_sib(d, c, NULL, NULL, a); @@ -8886,7 +9145,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { nghttp2_stream_attach_item(b, db); nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8896,14 +9155,14 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b */ - CU_ASSERT(c->queued); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!d->queued); + assert_true(c->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); check_stream_dep_sib(c, root, d, NULL, NULL); check_stream_dep_sib(d, c, NULL, NULL, a); @@ -8934,7 +9193,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { nghttp2_stream_attach_item(c, dc); nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8944,10 +9203,10 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b */ - CU_ASSERT(c->queued); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!d->queued); + assert_true(c->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!d->queued); check_stream_dep_sib(c, root, d, NULL, NULL); check_stream_dep_sib(d, c, NULL, NULL, a); @@ -8986,80 +9245,80 @@ void test_nghttp2_session_stream_attach_item(void) { nghttp2_stream_attach_item(b, db); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); /* Attach item to c */ dc = create_data_ob_item(mem); nghttp2_stream_attach_item(c, dc); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); /* Attach item to a */ da = create_data_ob_item(mem); nghttp2_stream_attach_item(a, da); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); /* Detach item from a */ nghttp2_stream_detach_item(a); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); /* Attach item to d */ dd = create_data_ob_item(mem); nghttp2_stream_attach_item(d, dd); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); /* Detach item from c */ nghttp2_stream_detach_item(c); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); /* Detach item from b */ nghttp2_stream_detach_item(b); - CU_ASSERT(a->queued); - CU_ASSERT(!b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(!b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); /* exercises insertion */ e = open_stream_with_dep_excl(session, 9, a); @@ -9073,17 +9332,17 @@ void test_nghttp2_session_stream_attach_item(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(e->queued); + assert_true(!b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&e->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); /* exercises deletion */ nghttp2_stream_dep_remove(e); @@ -9095,20 +9354,20 @@ void test_nghttp2_session_stream_attach_item(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(!b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(!b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); /* e's weight 16 is distributed equally among c and b, both now have weight 8 each. */ - CU_ASSERT(8 == b->weight); - CU_ASSERT(8 == c->weight); + assert_int32(8, ==, b->weight); + assert_int32(8, ==, c->weight); /* da, db, dc have been detached */ nghttp2_outbound_item_free(da, mem); @@ -9142,28 +9401,28 @@ void test_nghttp2_session_stream_attach_item(void) { nghttp2_stream_attach_item(b, db); nghttp2_stream_attach_item(c, dc); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); /* Detach item from a */ nghttp2_stream_detach_item(a); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); /* da has been detached */ nghttp2_outbound_item_free(da, mem); @@ -9209,19 +9468,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { nghttp2_stream_attach_item(b, db); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Insert subtree e under a */ @@ -9238,25 +9497,25 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree b */ nghttp2_stream_dep_remove_subtree(b); - CU_ASSERT(0 == nghttp2_stream_dep_add_subtree(&session->root, b)); + assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, b)); /* * a b @@ -9268,45 +9527,45 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree a, and add it to root again */ nghttp2_stream_dep_remove_subtree(a); - CU_ASSERT(0 == nghttp2_stream_dep_add_subtree(&session->root, a)); + assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, a)); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree c */ nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_add_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, c)); /* * a b c @@ -9316,19 +9575,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * f */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); dd = create_data_ob_item(mem); @@ -9347,19 +9606,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d f */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Insert b under a */ @@ -9376,24 +9635,24 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d f */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(2 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree b */ nghttp2_stream_dep_remove_subtree(b); - CU_ASSERT(0 == nghttp2_stream_dep_add_subtree(&session->root, b)); + assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, b)); /* * b a @@ -9403,19 +9662,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * f d */ - CU_ASSERT(!a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(!a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(2 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree c, and detach item from b, and then re-add subtree c under b */ @@ -9432,19 +9691,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * f d */ - CU_ASSERT(!a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(!a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(2 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Attach data to a, and add subtree a under b */ @@ -9461,19 +9720,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * f d */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(3 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_size(3, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree c, and add under f */ nghttp2_stream_dep_remove_subtree(c); @@ -9491,19 +9750,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(f->queued); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(2 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&e->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&f->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&e->obq)); + assert_size(1, ==, nghttp2_pq_size(&f->obq)); /* db has been detached */ nghttp2_outbound_item_free(db, mem); @@ -9520,8 +9779,8 @@ void test_nghttp2_session_stream_get_state(void) { nghttp2_bufs bufs; nghttp2_buf *buf; nghttp2_stream *stream; - ssize_t rv; - nghttp2_data_provider data_prd; + nghttp2_ssize rv; + nghttp2_data_provider2 data_prd; nghttp2_frame frame; mem = nghttp2_mem_default(); @@ -9529,28 +9788,30 @@ void test_nghttp2_session_stream_get_state(void) { memset(&data_prd, 0, sizeof(data_prd)); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); nghttp2_hd_deflate_init(&deflater, mem); - CU_ASSERT(NGHTTP2_STREAM_STATE_IDLE == - nghttp2_stream_get_state(nghttp2_session_get_root_stream(session))); + assert_enum( + nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_IDLE, ==, + nghttp2_stream_get_state(nghttp2_session_get_root_stream(session))); /* stream 1 HEADERS; without END_STREAM flag set */ pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 1); - CU_ASSERT(NULL != stream); - CU_ASSERT(1 == stream->stream_id); - CU_ASSERT(NGHTTP2_STREAM_STATE_OPEN == nghttp2_stream_get_state(stream)); + assert_not_null(stream); + assert_int32(1, ==, stream->stream_id); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_OPEN, ==, + nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); @@ -9560,41 +9821,44 @@ void test_nghttp2_session_stream_get_state(void) { ARRLEN(reqnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 3); - CU_ASSERT(NULL != stream); - CU_ASSERT(3 == stream->stream_id); - CU_ASSERT(NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE == - nghttp2_stream_get_state(stream)); + assert_not_null(stream); + assert_int32(3, ==, stream->stream_id); + assert_enum(nghttp2_stream_proto_state, + NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE, ==, + nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); /* Respond to stream 1 */ - nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), NULL); + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), NULL); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, + NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL, ==, + nghttp2_stream_get_state(stream)); /* Respond to stream 3 */ - nghttp2_submit_response(session, 3, resnv, ARRLEN(resnv), NULL); + nghttp2_submit_response2(session, 3, resnv, ARRLEN(resnv), NULL); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 3); - CU_ASSERT(NGHTTP2_STREAM_STATE_CLOSED == nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_CLOSED, ==, + nghttp2_stream_get_state(stream)); /* stream 5 HEADERS; with END_STREAM flag set */ pack_headers(&bufs, &deflater, 5, @@ -9602,9 +9866,9 @@ void test_nghttp2_session_stream_get_state(void) { ARRLEN(reqnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); nghttp2_bufs_reset(&bufs); @@ -9612,57 +9876,58 @@ void test_nghttp2_session_stream_get_state(void) { rv = nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 5, reqnv, ARRLEN(reqnv), NULL); - CU_ASSERT(2 == rv); + assert_ptrdiff(2, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_STATE_RESERVED_LOCAL == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_RESERVED_LOCAL, + ==, nghttp2_stream_get_state(stream)); /* Send response to push stream 2 with END_STREAM set */ - nghttp2_submit_response(session, 2, resnv, ARRLEN(resnv), NULL); + nghttp2_submit_response2(session, 2, resnv, ARRLEN(resnv), NULL); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 2); /* At server, pushed stream object is not retained after closed */ - CU_ASSERT(NULL == stream); + assert_null(stream); /* Push stream 4 associated to stream 5 */ rv = nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 5, reqnv, ARRLEN(reqnv), NULL); - CU_ASSERT(4 == rv); + assert_ptrdiff(4, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 4); - CU_ASSERT(NGHTTP2_STREAM_STATE_RESERVED_LOCAL == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_RESERVED_LOCAL, + ==, nghttp2_stream_get_state(stream)); /* Send response to push stream 4 without closing */ data_prd.read_callback = defer_data_source_read_callback; - nghttp2_submit_response(session, 4, resnv, ARRLEN(resnv), &data_prd); + nghttp2_submit_response2(session, 4, resnv, ARRLEN(resnv), &data_prd); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 4); - CU_ASSERT(NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, + NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE, ==, + nghttp2_stream_get_state(stream)); /* Create idle stream by PRIORITY frame */ nghttp2_frame_priority_init(&frame.priority, 7, &pri_spec_default); @@ -9672,13 +9937,14 @@ void test_nghttp2_session_stream_get_state(void) { nghttp2_frame_priority_free(&frame.priority); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 7); - CU_ASSERT(NGHTTP2_STREAM_STATE_IDLE == nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_IDLE, ==, + nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); @@ -9690,25 +9956,25 @@ void test_nghttp2_session_stream_get_state(void) { nghttp2_session_client_new(&session, &callbacks, NULL); nghttp2_hd_deflate_init(&deflater, mem); - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); /* Receive PUSH_PROMISE 2 associated to stream 1 */ pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_STATE_RESERVED_REMOTE == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_RESERVED_REMOTE, + ==, nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); @@ -9717,14 +9983,15 @@ void test_nghttp2_session_stream_get_state(void) { ARRLEN(resnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, + NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL, ==, + nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); @@ -9745,28 +10012,28 @@ void test_nghttp2_session_stream_get_something(void) { a = open_stream(session, 1); - CU_ASSERT(nghttp2_session_get_root_stream(session) == - nghttp2_stream_get_parent(a)); - CU_ASSERT(NULL == nghttp2_stream_get_previous_sibling(a)); - CU_ASSERT(NULL == nghttp2_stream_get_next_sibling(a)); - CU_ASSERT(NULL == nghttp2_stream_get_first_child(a)); + assert_ptr_equal(nghttp2_session_get_root_stream(session), + nghttp2_stream_get_parent(a)); + assert_null(nghttp2_stream_get_previous_sibling(a)); + assert_null(nghttp2_stream_get_next_sibling(a)); + assert_null(nghttp2_stream_get_first_child(a)); b = open_stream_with_dep(session, 3, a); c = open_stream_with_dep_weight(session, 5, 11, a); - CU_ASSERT(a == nghttp2_stream_get_parent(c)); - CU_ASSERT(a == nghttp2_stream_get_parent(b)); + assert_ptr_equal(a, nghttp2_stream_get_parent(c)); + assert_ptr_equal(a, nghttp2_stream_get_parent(b)); - CU_ASSERT(c == nghttp2_stream_get_first_child(a)); + assert_ptr_equal(c, nghttp2_stream_get_first_child(a)); - CU_ASSERT(b == nghttp2_stream_get_next_sibling(c)); - CU_ASSERT(c == nghttp2_stream_get_previous_sibling(b)); + assert_ptr_equal(b, nghttp2_stream_get_next_sibling(c)); + assert_ptr_equal(c, nghttp2_stream_get_previous_sibling(b)); - CU_ASSERT(27 == nghttp2_stream_get_sum_dependency_weight(a)); + assert_int32(27, ==, nghttp2_stream_get_sum_dependency_weight(a)); - CU_ASSERT(11 == nghttp2_stream_get_weight(c)); - CU_ASSERT(5 == nghttp2_stream_get_stream_id(c)); - CU_ASSERT(0 == nghttp2_stream_get_stream_id(&session->root)); + assert_int32(11, ==, nghttp2_stream_get_weight(c)); + assert_int32(5, ==, nghttp2_stream_get_stream_id(c)); + assert_int32(0, ==, nghttp2_stream_get_stream_id(&session->root)); nghttp2_session_del(session); } @@ -9784,17 +10051,17 @@ void test_nghttp2_session_find_stream(void) { stream = nghttp2_session_find_stream(session, 1); - CU_ASSERT(NULL != stream); - CU_ASSERT(1 == stream->stream_id); + assert_not_null(stream); + assert_int32(1, ==, stream->stream_id); stream = nghttp2_session_find_stream(session, 0); - CU_ASSERT(&session->root == stream); - CU_ASSERT(0 == stream->stream_id); + assert_ptr_equal(&session->root, stream); + assert_int32(0, ==, stream->stream_id); stream = nghttp2_session_find_stream(session, 2); - CU_ASSERT(NULL == stream); + assert_null(stream); nghttp2_session_del(session); } @@ -9808,7 +10075,7 @@ void test_nghttp2_session_keep_closed_stream(void) { size_t i; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -9818,58 +10085,58 @@ void test_nghttp2_session_keep_closed_stream(void) { open_recv_stream(session, (int32_t)i * 2 + 1); } - CU_ASSERT(0 == session->num_closed_streams); + assert_size(0, ==, session->num_closed_streams); nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(1 == session->closed_stream_tail->stream_id); - CU_ASSERT(session->closed_stream_tail == session->closed_stream_head); + assert_size(1, ==, session->num_closed_streams); + assert_int32(1, ==, session->closed_stream_tail->stream_id); + assert_ptr_equal(session->closed_stream_tail, session->closed_stream_head); nghttp2_session_close_stream(session, 5, NGHTTP2_NO_ERROR); - CU_ASSERT(2 == session->num_closed_streams); - CU_ASSERT(5 == session->closed_stream_tail->stream_id); - CU_ASSERT(1 == session->closed_stream_head->stream_id); - CU_ASSERT(session->closed_stream_head == - session->closed_stream_tail->closed_prev); - CU_ASSERT(NULL == session->closed_stream_tail->closed_next); - CU_ASSERT(session->closed_stream_tail == - session->closed_stream_head->closed_next); - CU_ASSERT(NULL == session->closed_stream_head->closed_prev); + assert_size(2, ==, session->num_closed_streams); + assert_int32(5, ==, session->closed_stream_tail->stream_id); + assert_int32(1, ==, session->closed_stream_head->stream_id); + assert_ptr_equal(session->closed_stream_head, + session->closed_stream_tail->closed_prev); + assert_null(session->closed_stream_tail->closed_next); + assert_ptr_equal(session->closed_stream_tail, + session->closed_stream_head->closed_next); + assert_null(session->closed_stream_head->closed_prev); open_recv_stream(session, 11); nghttp2_session_adjust_closed_stream(session); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(5 == session->closed_stream_tail->stream_id); - CU_ASSERT(session->closed_stream_tail == session->closed_stream_head); - CU_ASSERT(NULL == session->closed_stream_head->closed_prev); - CU_ASSERT(NULL == session->closed_stream_head->closed_next); + assert_size(1, ==, session->num_closed_streams); + assert_int32(5, ==, session->closed_stream_tail->stream_id); + assert_ptr_equal(session->closed_stream_tail, session->closed_stream_head); + assert_null(session->closed_stream_head->closed_prev); + assert_null(session->closed_stream_head->closed_next); open_recv_stream(session, 13); nghttp2_session_adjust_closed_stream(session); - CU_ASSERT(0 == session->num_closed_streams); - CU_ASSERT(NULL == session->closed_stream_tail); - CU_ASSERT(NULL == session->closed_stream_head); + assert_size(0, ==, session->num_closed_streams); + assert_null(session->closed_stream_tail); + assert_null(session->closed_stream_head); nghttp2_session_close_stream(session, 3, NGHTTP2_NO_ERROR); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(3 == session->closed_stream_head->stream_id); + assert_size(1, ==, session->num_closed_streams); + assert_int32(3, ==, session->closed_stream_head->stream_id); /* server initiated stream is not counted to max concurrent limit */ open_sent_stream(session, 2); nghttp2_session_adjust_closed_stream(session); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(3 == session->closed_stream_head->stream_id); + assert_size(1, ==, session->num_closed_streams); + assert_int32(3, ==, session->closed_stream_head->stream_id); nghttp2_session_close_stream(session, 2, NGHTTP2_NO_ERROR); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(3 == session->closed_stream_head->stream_id); + assert_size(1, ==, session->num_closed_streams); + assert_int32(3, ==, session->closed_stream_head->stream_id); nghttp2_session_del(session); } @@ -9884,7 +10151,7 @@ void test_nghttp2_session_keep_idle_stream(void) { int32_t stream_id; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -9897,20 +10164,20 @@ void test_nghttp2_session_keep_idle_stream(void) { nghttp2_session_adjust_idle_stream(session); } - CU_ASSERT(NGHTTP2_MIN_IDLE_STREAMS == session->num_idle_streams); + assert_size(NGHTTP2_MIN_IDLE_STREAMS, ==, session->num_idle_streams); stream_id = (NGHTTP2_MIN_IDLE_STREAMS - 1) * 2 + 1; - CU_ASSERT(1 == session->idle_stream_head->stream_id); - CU_ASSERT(stream_id == session->idle_stream_tail->stream_id); + assert_int32(1, ==, session->idle_stream_head->stream_id); + assert_int32(stream_id, ==, session->idle_stream_tail->stream_id); stream_id += 2; open_recv_stream2(session, stream_id, NGHTTP2_STREAM_IDLE); nghttp2_session_adjust_idle_stream(session); - CU_ASSERT(NGHTTP2_MIN_IDLE_STREAMS == session->num_idle_streams); - CU_ASSERT(3 == session->idle_stream_head->stream_id); - CU_ASSERT(stream_id == session->idle_stream_tail->stream_id); + assert_size(NGHTTP2_MIN_IDLE_STREAMS, ==, session->num_idle_streams); + assert_int32(3, ==, session->idle_stream_head->stream_id); + assert_int32(stream_id, ==, session->idle_stream_tail->stream_id); nghttp2_session_del(session); } @@ -9922,7 +10189,7 @@ void test_nghttp2_session_detach_idle_stream(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -9931,38 +10198,38 @@ void test_nghttp2_session_detach_idle_stream(void) { &pri_spec_default, NGHTTP2_STREAM_IDLE, NULL); } - CU_ASSERT(3 == session->num_idle_streams); + assert_size(3, ==, session->num_idle_streams); /* Detach middle stream */ stream = nghttp2_session_get_stream_raw(session, 2); - CU_ASSERT(session->idle_stream_head == stream->closed_prev); - CU_ASSERT(session->idle_stream_tail == stream->closed_next); - CU_ASSERT(stream == session->idle_stream_head->closed_next); - CU_ASSERT(stream == session->idle_stream_tail->closed_prev); + assert_ptr_equal(session->idle_stream_head, stream->closed_prev); + assert_ptr_equal(session->idle_stream_tail, stream->closed_next); + assert_ptr_equal(stream, session->idle_stream_head->closed_next); + assert_ptr_equal(stream, session->idle_stream_tail->closed_prev); nghttp2_session_detach_idle_stream(session, stream); - CU_ASSERT(2 == session->num_idle_streams); + assert_size(2, ==, session->num_idle_streams); - CU_ASSERT(NULL == stream->closed_prev); - CU_ASSERT(NULL == stream->closed_next); + assert_null(stream->closed_prev); + assert_null(stream->closed_next); - CU_ASSERT(session->idle_stream_head == - session->idle_stream_tail->closed_prev); - CU_ASSERT(session->idle_stream_tail == - session->idle_stream_head->closed_next); + assert_ptr_equal(session->idle_stream_head, + session->idle_stream_tail->closed_prev); + assert_ptr_equal(session->idle_stream_tail, + session->idle_stream_head->closed_next); /* Detach head stream */ stream = session->idle_stream_head; nghttp2_session_detach_idle_stream(session, stream); - CU_ASSERT(1 == session->num_idle_streams); + assert_size(1, ==, session->num_idle_streams); - CU_ASSERT(session->idle_stream_head == session->idle_stream_tail); - CU_ASSERT(NULL == session->idle_stream_head->closed_prev); - CU_ASSERT(NULL == session->idle_stream_head->closed_next); + assert_ptr_equal(session->idle_stream_head, session->idle_stream_tail); + assert_null(session->idle_stream_head->closed_prev); + assert_null(session->idle_stream_head->closed_next); /* Detach last stream */ @@ -9970,17 +10237,17 @@ void test_nghttp2_session_detach_idle_stream(void) { nghttp2_session_detach_idle_stream(session, stream); - CU_ASSERT(0 == session->num_idle_streams); + assert_size(0, ==, session->num_idle_streams); - CU_ASSERT(NULL == session->idle_stream_head); - CU_ASSERT(NULL == session->idle_stream_tail); + assert_null(session->idle_stream_head); + assert_null(session->idle_stream_tail); for (i = 4; i <= 5; ++i) { nghttp2_session_open_stream(session, i, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_IDLE, NULL); } - CU_ASSERT(2 == session->num_idle_streams); + assert_size(2, ==, session->num_idle_streams); /* Detach tail stream */ @@ -9988,11 +10255,11 @@ void test_nghttp2_session_detach_idle_stream(void) { nghttp2_session_detach_idle_stream(session, stream); - CU_ASSERT(1 == session->num_idle_streams); + assert_size(1, ==, session->num_idle_streams); - CU_ASSERT(session->idle_stream_head == session->idle_stream_tail); - CU_ASSERT(NULL == session->idle_stream_head->closed_prev); - CU_ASSERT(NULL == session->idle_stream_head->closed_next); + assert_ptr_equal(session->idle_stream_head, session->idle_stream_tail); + assert_null(session->idle_stream_head->closed_prev); + assert_null(session->idle_stream_head->closed_next); nghttp2_session_del(session); } @@ -10006,7 +10273,7 @@ void test_nghttp2_session_large_dep_tree(void) { int32_t stream_id; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -10018,8 +10285,8 @@ void test_nghttp2_session_large_dep_tree(void) { stream_id = 1; for (i = 0; i < 250; ++i, stream_id += 2) { stream = nghttp2_session_get_stream(session, stream_id); - CU_ASSERT(nghttp2_stream_dep_find_ancestor(stream, &session->root)); - CU_ASSERT(nghttp2_stream_in_dep_tree(stream)); + assert_true(nghttp2_stream_dep_find_ancestor(stream, &session->root)); + assert_true(nghttp2_stream_in_dep_tree(stream)); } nghttp2_session_del(session); @@ -10031,7 +10298,7 @@ void test_nghttp2_session_graceful_shutdown(void) { my_user_data ud; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; callbacks.on_stream_close_callback = on_stream_close_callback; @@ -10043,44 +10310,46 @@ void test_nghttp2_session_graceful_shutdown(void) { open_recv_stream(session, 311); open_recv_stream(session, 319); - CU_ASSERT(0 == nghttp2_submit_shutdown_notice(session)); + assert_int(0, ==, nghttp2_submit_shutdown_notice(session)); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT((1u << 31) - 1 == session->local_last_stream_id); + assert_int(1, ==, ud.frame_send_cb_called); + assert_int32((1u << 31) - 1, ==, session->local_last_stream_id); - CU_ASSERT(0 == nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 311, - NGHTTP2_NO_ERROR, NULL, 0)); + assert_int(0, ==, + nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 311, + NGHTTP2_NO_ERROR, NULL, 0)); ud.frame_send_cb_called = 0; ud.stream_close_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(311 == session->local_last_stream_id); - CU_ASSERT(1 == ud.stream_close_cb_called); + assert_int(1, ==, ud.frame_send_cb_called); + assert_int32(311, ==, session->local_last_stream_id); + assert_int(1, ==, ud.stream_close_cb_called); - CU_ASSERT(0 == - nghttp2_session_terminate_session2(session, 301, NGHTTP2_NO_ERROR)); + assert_int( + 0, ==, + nghttp2_session_terminate_session2(session, 301, NGHTTP2_NO_ERROR)); ud.frame_send_cb_called = 0; ud.stream_close_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(301 == session->local_last_stream_id); - CU_ASSERT(2 == ud.stream_close_cb_called); + assert_int(1, ==, ud.frame_send_cb_called); + assert_int32(301, ==, session->local_last_stream_id); + assert_int(2, ==, ud.stream_close_cb_called); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 301)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 302)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 309)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 311)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 319)); + assert_not_null(nghttp2_session_get_stream(session, 301)); + assert_not_null(nghttp2_session_get_stream(session, 302)); + assert_null(nghttp2_session_get_stream(session, 309)); + assert_null(nghttp2_session_get_stream(session, 311)); + assert_null(nghttp2_session_get_stream(session, 319)); nghttp2_session_del(session); } @@ -10095,7 +10364,7 @@ void test_nghttp2_session_on_header_temporal_failure(void) { nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; nghttp2_nv *nva; size_t hdpos; - ssize_t rv; + nghttp2_ssize rv; nghttp2_frame frame; nghttp2_frame_hd hd; nghttp2_outbound_item *item; @@ -10134,18 +10403,18 @@ void test_nghttp2_session_on_header_temporal_failure(void) { nghttp2_frame_pack_frame_hd(&buf->pos[hdpos], &hd); ud.header_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.header_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.header_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); /* Make sure no header decompression error occurred */ - CU_ASSERT(NGHTTP2_GOAWAY_NONE == session->goaway_flags); + assert_uint8(NGHTTP2_GOAWAY_NONE, ==, session->goaway_flags); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -10160,18 +10429,18 @@ void test_nghttp2_session_on_header_temporal_failure(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.header_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.header_cb_called); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.header_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(2 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INTERNAL_ERROR == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(2, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_INTERNAL_ERROR, ==, item->frame.rst_stream.error_code); nghttp2_session_del(session); nghttp2_hd_deflate_free(&deflater); @@ -10181,7 +10450,7 @@ void test_nghttp2_session_on_header_temporal_failure(void) { void test_nghttp2_session_recv_client_magic(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - ssize_t rv; + nghttp2_ssize rv; nghttp2_frame ping_frame; uint8_t buf[16]; @@ -10193,21 +10462,23 @@ void test_nghttp2_session_recv_client_magic(void) { /* Check success case */ nghttp2_session_server_new(&session, &callbacks, NULL); - rv = nghttp2_session_mem_recv(session, (const uint8_t *)NGHTTP2_CLIENT_MAGIC, - NGHTTP2_CLIENT_MAGIC_LEN); + rv = nghttp2_session_mem_recv2(session, (const uint8_t *)NGHTTP2_CLIENT_MAGIC, + NGHTTP2_CLIENT_MAGIC_LEN); - CU_ASSERT(rv == NGHTTP2_CLIENT_MAGIC_LEN); - CU_ASSERT(NGHTTP2_IB_READ_FIRST_SETTINGS == session->iframe.state); + assert_ptrdiff(NGHTTP2_CLIENT_MAGIC_LEN, ==, rv); + assert_enum(nghttp2_inbound_state, NGHTTP2_IB_READ_FIRST_SETTINGS, ==, + session->iframe.state); /* Receiving PING is error because we want SETTINGS. */ nghttp2_frame_ping_init(&ping_frame.ping, NGHTTP2_FLAG_NONE, NULL); nghttp2_frame_pack_frame_hd(buf, &ping_frame.ping.hd); - rv = nghttp2_session_mem_recv(session, buf, NGHTTP2_FRAME_HDLEN); - CU_ASSERT(NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(NGHTTP2_IB_IGN_ALL == session->iframe.state); - CU_ASSERT(0 == session->iframe.payloadleft); + rv = nghttp2_session_mem_recv2(session, buf, NGHTTP2_FRAME_HDLEN); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN, ==, rv); + assert_enum(nghttp2_inbound_state, NGHTTP2_IB_IGN_ALL, ==, + session->iframe.state); + assert_size(0, ==, session->iframe.payloadleft); nghttp2_frame_ping_free(&ping_frame.ping); @@ -10217,16 +10488,17 @@ void test_nghttp2_session_recv_client_magic(void) { nghttp2_session_server_new(&session, &callbacks, NULL); /* Feed magic with one byte less */ - rv = nghttp2_session_mem_recv(session, (const uint8_t *)NGHTTP2_CLIENT_MAGIC, - NGHTTP2_CLIENT_MAGIC_LEN - 1); + rv = nghttp2_session_mem_recv2(session, (const uint8_t *)NGHTTP2_CLIENT_MAGIC, + NGHTTP2_CLIENT_MAGIC_LEN - 1); - CU_ASSERT(rv == NGHTTP2_CLIENT_MAGIC_LEN - 1); - CU_ASSERT(NGHTTP2_IB_READ_CLIENT_MAGIC == session->iframe.state); - CU_ASSERT(1 == session->iframe.payloadleft); + assert_ptrdiff(NGHTTP2_CLIENT_MAGIC_LEN - 1, ==, rv); + assert_enum(nghttp2_inbound_state, NGHTTP2_IB_READ_CLIENT_MAGIC, ==, + session->iframe.state); + assert_size(1, ==, session->iframe.payloadleft); - rv = nghttp2_session_mem_recv(session, (const uint8_t *)"\0", 1); + rv = nghttp2_session_mem_recv2(session, (const uint8_t *)"\0", 1); - CU_ASSERT(NGHTTP2_ERR_BAD_CLIENT_MAGIC == rv); + assert_ptrdiff(NGHTTP2_ERR_BAD_CLIENT_MAGIC, ==, rv); nghttp2_session_del(session); @@ -10238,7 +10510,7 @@ void test_nghttp2_session_delete_data_item(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; nghttp2_stream *a; - nghttp2_data_provider prd; + nghttp2_data_provider2 prd; memset(&callbacks, 0, sizeof(callbacks)); @@ -10251,8 +10523,8 @@ void test_nghttp2_session_delete_data_item(void) { prd.source.ptr = NULL; prd.read_callback = fail_data_source_read_callback; - CU_ASSERT(0 == nghttp2_submit_data(session, NGHTTP2_FLAG_NONE, 1, &prd)); - CU_ASSERT(0 == nghttp2_submit_data(session, NGHTTP2_FLAG_NONE, 3, &prd)); + assert_int(0, ==, nghttp2_submit_data2(session, NGHTTP2_FLAG_NONE, 1, &prd)); + assert_int(0, ==, nghttp2_submit_data2(session, NGHTTP2_FLAG_NONE, 3, &prd)); nghttp2_session_del(session); } @@ -10264,6 +10536,7 @@ void test_nghttp2_session_open_idle_stream(void) { nghttp2_stream *opened_stream; nghttp2_priority_spec pri_spec; nghttp2_frame frame; + nghttp2_ext_priority_update priority_update; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); @@ -10273,24 +10546,53 @@ void test_nghttp2_session_open_idle_stream(void) { nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(NULL == stream->closed_prev); - CU_ASSERT(NULL == stream->closed_next); - CU_ASSERT(1 == session->num_idle_streams); - CU_ASSERT(session->idle_stream_head == stream); - CU_ASSERT(session->idle_stream_tail == stream); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_null(stream->closed_prev); + assert_null(stream->closed_next); + assert_size(1, ==, session->num_idle_streams); + assert_ptr_equal(session->idle_stream_head, stream); + assert_ptr_equal(session->idle_stream_tail, stream); opened_stream = open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(stream == opened_stream); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(0 == session->num_idle_streams); - CU_ASSERT(NULL == session->idle_stream_head); - CU_ASSERT(NULL == session->idle_stream_tail); + assert_ptr_equal(stream, opened_stream); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_size(0, ==, session->num_idle_streams); + assert_null(session->idle_stream_head); + assert_null(session->idle_stream_tail); + + nghttp2_frame_priority_free(&frame.priority); + + nghttp2_session_del(session); + + /* No RFC 7540 priorities */ + nghttp2_session_server_new(&session, &callbacks, NULL); + + session->pending_no_rfc7540_priorities = 1; + + frame.ext.payload = &priority_update; + + nghttp2_frame_priority_update_init(&frame.ext, 1, (uint8_t *)"u=3", + strlen("u=3")); + + assert_int(0, ==, + nghttp2_session_on_priority_update_received(session, &frame)); + + stream = nghttp2_session_get_stream_raw(session, 1); + + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_null(stream->closed_next); + assert_size(1, ==, session->num_idle_streams); + + opened_stream = open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); + + assert_ptr_equal(stream, opened_stream); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_size(0, ==, session->num_idle_streams); nghttp2_frame_priority_free(&frame.priority); @@ -10307,13 +10609,13 @@ void test_nghttp2_session_cancel_reserved_remote(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -10323,9 +10625,9 @@ void test_nghttp2_session_cancel_reserved_remote(void) { nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 2, NGHTTP2_CANCEL); - CU_ASSERT(NGHTTP2_STREAM_CLOSING == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_CLOSING, ==, stream->state); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nvlen = ARRLEN(resnv); nghttp2_nv_array_copy(&nva, resnv, nvlen, mem); @@ -10334,19 +10636,19 @@ void test_nghttp2_session_cancel_reserved_remote(void) { NGHTTP2_HCAT_PUSH_RESPONSE, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); /* stream is not dangling, so assign NULL */ stream = NULL; /* No RST_STREAM or GOAWAY is generated since stream should be in NGHTTP2_STREAM_CLOSING and push response should be ignored. */ - CU_ASSERT(0 == nghttp2_outbound_queue_size(&session->ob_reg)); + assert_size(0, ==, nghttp2_outbound_queue_size(&session->ob_reg)); /* Check that we can receive push response HEADERS while RST_STREAM is just queued. */ @@ -10359,14 +10661,14 @@ void test_nghttp2_session_cancel_reserved_remote(void) { frame.hd.stream_id = 4; rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(1 == nghttp2_outbound_queue_size(&session->ob_reg)); + assert_size(1, ==, nghttp2_outbound_queue_size(&session->ob_reg)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -10385,15 +10687,15 @@ void test_nghttp2_session_reset_pending_headers(void) { my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; callbacks.on_stream_close_callback = on_stream_close_callback; nghttp2_session_client_new(&session, &callbacks, &ud); - stream_id = nghttp2_submit_request(session, NULL, NULL, 0, NULL, NULL); - CU_ASSERT(stream_id >= 1); + stream_id = nghttp2_submit_request2(session, NULL, NULL, 0, NULL, NULL); + assert_int32(1, <=, stream_id); nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, stream_id, NGHTTP2_CANCEL); @@ -10402,13 +10704,13 @@ void test_nghttp2_session_reset_pending_headers(void) { /* RST_STREAM cancels pending HEADERS and is not actually sent. */ ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); + assert_int(0, ==, ud.frame_send_cb_called); stream = nghttp2_session_get_stream(session, stream_id); - CU_ASSERT(NULL == stream); + assert_null(stream); /* See HEADERS is not sent. on_stream_close is called just like transmission failure. */ @@ -10416,15 +10718,15 @@ void test_nghttp2_session_reset_pending_headers(void) { ud.frame_not_send_cb_called = 0; ud.stream_close_error_code = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.not_sent_frame_type); - CU_ASSERT(NGHTTP2_CANCEL == ud.stream_close_error_code); + assert_int(1, ==, ud.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.not_sent_frame_type); + assert_uint32(NGHTTP2_CANCEL, ==, ud.stream_close_error_code); stream = nghttp2_session_get_stream(session, stream_id); - CU_ASSERT(NULL == stream); + assert_null(stream); nghttp2_session_del(session); } @@ -10432,13 +10734,13 @@ void test_nghttp2_session_reset_pending_headers(void) { void test_nghttp2_session_send_data_callback(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; accumulator acc; nghttp2_frame_hd hd; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; callbacks.send_data_callback = send_data_callback; data_prd.read_callback = no_copy_data_source_read_callback; @@ -10452,23 +10754,24 @@ void test_nghttp2_session_send_data_callback(void) { open_sent_stream(session, 1); - nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd); + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT((NGHTTP2_FRAME_HDLEN + NGHTTP2_DATA_PAYLOADLEN) * 2 == acc.length); + assert_size((NGHTTP2_FRAME_HDLEN + NGHTTP2_DATA_PAYLOADLEN) * 2, ==, + acc.length); nghttp2_frame_unpack_frame_hd(&hd, acc.buf); - CU_ASSERT(16384 == hd.length); - CU_ASSERT(NGHTTP2_DATA == hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); + assert_size(16384, ==, hd.length); + assert_uint8(NGHTTP2_DATA, ==, hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); nghttp2_frame_unpack_frame_hd(&hd, acc.buf + NGHTTP2_FRAME_HDLEN + hd.length); - CU_ASSERT(16384 == hd.length); - CU_ASSERT(NGHTTP2_DATA == hd.type); - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == hd.flags); + assert_size(16384, ==, hd.length); + assert_uint8(NGHTTP2_DATA, ==, hd.type); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, hd.flags); nghttp2_session_del(session); } @@ -10479,7 +10782,7 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) { my_user_data ud; nghttp2_bufs bufs; nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_hd_deflater deflater; nghttp2_outbound_item *item; @@ -10492,25 +10795,25 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) { temporal_failure_on_begin_headers_callback; callbacks.on_header_callback = on_header_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.header_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.header_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.header_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INTERNAL_ERROR == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_INTERNAL_ERROR, ==, item->frame.rst_stream.error_code); nghttp2_session_del(session); nghttp2_hd_deflate_free(&deflater); @@ -10524,20 +10827,20 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.header_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.header_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.header_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(2 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INTERNAL_ERROR == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(2, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_INTERNAL_ERROR, ==, item->frame.rst_stream.error_code); nghttp2_session_del(session); nghttp2_hd_deflate_free(&deflater); @@ -10547,38 +10850,38 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) { void test_nghttp2_session_defer_then_close(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider prd; + nghttp2_data_provider2 prd; int rv; const uint8_t *datap; - ssize_t datalen; + nghttp2_ssize datalen; nghttp2_frame frame; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); prd.read_callback = defer_data_source_read_callback; - rv = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), &prd, NULL); - CU_ASSERT(rv > 0); + rv = nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), &prd, NULL); + assert_ptrdiff(0, <, rv); /* This sends HEADERS */ - datalen = nghttp2_session_mem_send(session, &datap); + datalen = nghttp2_session_mem_send2(session, &datap); - CU_ASSERT(datalen > 0); + assert_ptrdiff(0, <, datalen); /* This makes DATA item deferred */ - datalen = nghttp2_session_mem_send(session, &datap); + datalen = nghttp2_session_mem_send2(session, &datap); - CU_ASSERT(datalen == 0); + assert_ptrdiff(0, ==, datalen); nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_CANCEL); /* Assertion failure; GH-264 */ rv = nghttp2_session_on_rst_stream_received(session, &frame); - CU_ASSERT(rv == 0); + assert_int(0, ==, rv); nghttp2_session_del(session); } @@ -10587,7 +10890,7 @@ static int submit_response_on_stream_close(nghttp2_session *session, int32_t stream_id, uint32_t error_code, void *user_data) { - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; (void)error_code; (void)user_data; @@ -10596,12 +10899,14 @@ static int submit_response_on_stream_close(nghttp2_session *session, // Attempt to submit response or data to the stream being closed switch (stream_id) { case 1: - CU_ASSERT(0 == nghttp2_submit_response(session, stream_id, resnv, - ARRLEN(resnv), &data_prd)); + assert_int(0, ==, + nghttp2_submit_response2(session, stream_id, resnv, + ARRLEN(resnv), &data_prd)); break; case 3: - CU_ASSERT(0 == nghttp2_submit_data(session, NGHTTP2_FLAG_NONE, stream_id, - &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_NONE, stream_id, &data_prd)); break; } @@ -10614,7 +10919,7 @@ void test_nghttp2_session_detach_item_from_closed_stream(void) { memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_stream_close_callback = submit_response_on_stream_close; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -10625,7 +10930,22 @@ void test_nghttp2_session_detach_item_from_closed_stream(void) { nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); nghttp2_session_close_stream(session, 3, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); + + nghttp2_session_del(session); + + /* No RFC 7540 priorities */ + nghttp2_session_server_new(&session, &callbacks, NULL); + + session->pending_no_rfc7540_priorities = 1; + + open_recv_stream(session, 1); + open_recv_stream(session, 3); + + nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); + nghttp2_session_close_stream(session, 3, NGHTTP2_NO_ERROR); + + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_session_del(session); } @@ -10655,13 +10975,14 @@ void test_nghttp2_session_flooding(void) { buf = &bufs.head->buf; for (i = 0; i < NGHTTP2_DEFAULT_MAX_OBQ_FLOOD_ITEM; ++i) { - CU_ASSERT( - (ssize_t)nghttp2_buf_len(buf) == - nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf))); + assert_ptrdiff( + (nghttp2_ssize)nghttp2_buf_len(buf), ==, + nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf))); } - CU_ASSERT(NGHTTP2_ERR_FLOODED == - nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf))); + assert_ptrdiff( + NGHTTP2_ERR_FLOODED, ==, + nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf))); nghttp2_session_del(session); @@ -10677,13 +10998,14 @@ void test_nghttp2_session_flooding(void) { buf = &bufs.head->buf; for (i = 0; i < NGHTTP2_DEFAULT_MAX_OBQ_FLOOD_ITEM; ++i) { - CU_ASSERT( - (ssize_t)nghttp2_buf_len(buf) == - nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf))); + assert_ptrdiff( + (nghttp2_ssize)nghttp2_buf_len(buf), ==, + nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf))); } - CU_ASSERT(NGHTTP2_ERR_FLOODED == - nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf))); + assert_ptrdiff( + NGHTTP2_ERR_FLOODED, ==, + nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf))); nghttp2_session_del(session); nghttp2_bufs_free(&bufs); @@ -10708,22 +11030,22 @@ void test_nghttp2_session_change_stream_priority(void) { rv = nghttp2_session_change_stream_priority(session, 2, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(stream1 == stream2->dep_prev); - CU_ASSERT(256 == stream2->weight); + assert_ptr_equal(stream1, stream2->dep_prev); + assert_int32(256, ==, stream2->weight); /* Cannot change stream which does not exist */ rv = nghttp2_session_change_stream_priority(session, 5, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to depend on itself */ rv = nghttp2_session_change_stream_priority(session, 1, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to change priority of root stream (0) */ rv = nghttp2_session_change_stream_priority(session, 0, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* Depends on the non-existing idle stream. This creates that idle stream. */ @@ -10731,14 +11053,14 @@ void test_nghttp2_session_change_stream_priority(void) { rv = nghttp2_session_change_stream_priority(session, 2, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream5 = nghttp2_session_get_stream_raw(session, 5); - CU_ASSERT(NULL != stream5); - CU_ASSERT(&session->root == stream5->dep_prev); - CU_ASSERT(stream5 == stream2->dep_prev); - CU_ASSERT(9 == stream2->weight); + assert_not_null(stream5); + assert_ptr_equal(&session->root, stream5->dep_prev); + assert_ptr_equal(stream5, stream2->dep_prev); + assert_int32(9, ==, stream2->weight); nghttp2_session_del(session); @@ -10751,14 +11073,14 @@ void test_nghttp2_session_change_stream_priority(void) { rv = nghttp2_session_change_stream_priority(session, 1, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream5 = nghttp2_session_get_stream_raw(session, 5); - CU_ASSERT(NULL != stream5); - CU_ASSERT(&session->root == stream5->dep_prev); - CU_ASSERT(stream5 == stream1->dep_prev); - CU_ASSERT(9 == stream1->weight); + assert_not_null(stream5); + assert_ptr_equal(&session->root, stream5->dep_prev); + assert_ptr_equal(stream5, stream1->dep_prev); + assert_int32(9, ==, stream1->weight); nghttp2_session_del(session); } @@ -10768,11 +11090,11 @@ void test_nghttp2_session_change_extpri_stream_priority(void) { nghttp2_session_callbacks callbacks; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; nghttp2_extension frame; nghttp2_ext_priority_update priority_update; - nghttp2_extpri extpri; + nghttp2_extpri extpri, nextpri; nghttp2_stream *stream; static const uint8_t field_value[] = "u=2"; @@ -10796,13 +11118,19 @@ void test_nghttp2_session_change_extpri_stream_priority(void) { rv = nghttp2_session_change_extpri_stream_priority( session, 1, &extpri, /* ignore_client_signal = */ 0); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_EXTPRI_URGENCY_LOW == - nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_uint32(NGHTTP2_EXTPRI_URGENCY_LOW, ==, + nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); + + rv = nghttp2_session_get_extpri_stream_priority(session, &nextpri, 1); + + assert_ptrdiff(0, ==, rv); + assert_uint32(NGHTTP2_EXTPRI_URGENCY_LOW, ==, nextpri.urgency); + assert_true(nextpri.inc); /* Client can still update stream priority. */ frame.payload = &priority_update; @@ -10811,30 +11139,30 @@ void test_nghttp2_session_change_extpri_stream_priority(void) { nghttp2_frame_pack_priority_update(&bufs, &frame); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(2 == stream->extpri); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_uint8(2, ==, stream->extpri); /* Start to ignore client priority signal for this stream. */ rv = nghttp2_session_change_extpri_stream_priority( session, 1, &extpri, /* ignore_client_signal = */ 1); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_EXTPRI_URGENCY_LOW == - nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_uint32(NGHTTP2_EXTPRI_URGENCY_LOW, ==, + nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(NGHTTP2_EXTPRI_URGENCY_LOW == - nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_uint32(NGHTTP2_EXTPRI_URGENCY_LOW, ==, + nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_session_del(session); nghttp2_option_del(option); @@ -10850,7 +11178,7 @@ void test_nghttp2_session_create_idle_stream(void) { int i; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -10860,14 +11188,14 @@ void test_nghttp2_session_create_idle_stream(void) { rv = nghttp2_session_create_idle_stream(session, 4, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream4 = nghttp2_session_get_stream_raw(session, 4); - CU_ASSERT(4 == stream4->stream_id); - CU_ASSERT(111 == stream4->weight); - CU_ASSERT(stream2 == stream4->dep_prev); - CU_ASSERT(stream4 == stream2->dep_next); + assert_int32(4, ==, stream4->stream_id); + assert_int32(111, ==, stream4->weight); + assert_ptr_equal(stream2, stream4->dep_prev); + assert_ptr_equal(stream4, stream2->dep_next); /* If pri_spec->stream_id does not exist, and it is idle stream, it is created too */ @@ -10875,33 +11203,33 @@ void test_nghttp2_session_create_idle_stream(void) { rv = nghttp2_session_create_idle_stream(session, 8, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream8 = nghttp2_session_get_stream_raw(session, 8); stream10 = nghttp2_session_get_stream_raw(session, 10); - CU_ASSERT(8 == stream8->stream_id); - CU_ASSERT(109 == stream8->weight); - CU_ASSERT(10 == stream10->stream_id); - CU_ASSERT(16 == stream10->weight); - CU_ASSERT(stream10 == stream8->dep_prev); - CU_ASSERT(&session->root == stream10->dep_prev); + assert_int32(8, ==, stream8->stream_id); + assert_int32(109, ==, stream8->weight); + assert_int32(10, ==, stream10->stream_id); + assert_int32(16, ==, stream10->weight); + assert_ptr_equal(stream10, stream8->dep_prev); + assert_ptr_equal(&session->root, stream10->dep_prev); /* It is an error to attempt to create already existing idle stream */ rv = nghttp2_session_create_idle_stream(session, 4, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to depend on itself */ pri_spec.stream_id = 6; rv = nghttp2_session_create_idle_stream(session, 6, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to create root stream (0) as idle stream */ rv = nghttp2_session_create_idle_stream(session, 0, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to create non-idle stream */ session->last_sent_stream_id = 20; @@ -10909,7 +11237,7 @@ void test_nghttp2_session_create_idle_stream(void) { rv = nghttp2_session_create_idle_stream(session, 18, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); nghttp2_session_del(session); @@ -10920,17 +11248,17 @@ void test_nghttp2_session_create_idle_stream(void) { rv = nghttp2_session_create_idle_stream(session, 2, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream4 = nghttp2_session_get_stream_raw(session, 4); stream2 = nghttp2_session_get_stream_raw(session, 2); - CU_ASSERT(NULL != stream4); - CU_ASSERT(NULL != stream2); - CU_ASSERT(&session->root == stream4->dep_prev); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream4->weight); - CU_ASSERT(stream4 == stream2->dep_prev); - CU_ASSERT(99 == stream2->weight); + assert_not_null(stream4); + assert_not_null(stream2); + assert_ptr_equal(&session->root, stream4->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream4->weight); + assert_ptr_equal(stream4, stream2->dep_prev); + assert_int32(99, ==, stream2->weight); nghttp2_session_del(session); @@ -10944,19 +11272,19 @@ void test_nghttp2_session_create_idle_stream(void) { for (i = 0; i < 100; ++i) { rv = nghttp2_session_create_idle_stream(session, i * 2 + 1, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_priority_spec_init(&pri_spec, i * 2 + 1, 16, 0); } - CU_ASSERT(100 == session->num_idle_streams); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(30 == session->num_idle_streams); - CU_ASSERT(141 == session->idle_stream_head->stream_id); + assert_size(100, ==, session->num_idle_streams); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(30, ==, session->num_idle_streams); + assert_int32(141, ==, session->idle_stream_head->stream_id); nghttp2_session_del(session); - /* Check that idle stream is reduced when nghttp2_session_mem_recv() is + /* Check that idle stream is reduced when nghttp2_session_mem_recv2() is called. */ nghttp2_session_client_new(&session, &callbacks, NULL); @@ -10966,15 +11294,15 @@ void test_nghttp2_session_create_idle_stream(void) { for (i = 0; i < 100; ++i) { rv = nghttp2_session_create_idle_stream(session, i * 2 + 1, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_priority_spec_init(&pri_spec, i * 2 + 1, 16, 0); } - CU_ASSERT(100 == session->num_idle_streams); - CU_ASSERT(0 == nghttp2_session_mem_recv(session, NULL, 0)); - CU_ASSERT(30 == session->num_idle_streams); - CU_ASSERT(141 == session->idle_stream_head->stream_id); + assert_size(100, ==, session->num_idle_streams); + assert_ptrdiff(0, ==, nghttp2_session_mem_recv2(session, NULL, 0)); + assert_size(30, ==, session->num_idle_streams); + assert_int32(141, ==, session->idle_stream_head->stream_id); nghttp2_session_del(session); } @@ -10997,7 +11325,7 @@ void test_nghttp2_session_repeated_priority_change(void) { nghttp2_priority_spec_init(&pri_spec, 0, 16, 0); nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); nghttp2_frame_priority_free(&frame.priority); @@ -11008,24 +11336,24 @@ void test_nghttp2_session_repeated_priority_change(void) { nghttp2_priority_spec_init(&pri_spec, stream_id, 16, 0); nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); nghttp2_frame_priority_free(&frame.priority); } - CU_ASSERT(20 == session->num_idle_streams); - CU_ASSERT(1 == session->idle_stream_head->stream_id); + assert_size(20, ==, session->num_idle_streams); + assert_int32(1, ==, session->idle_stream_head->stream_id); /* 1 -> last_stream_id */ nghttp2_priority_spec_init(&pri_spec, last_stream_id, 16, 0); nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); nghttp2_frame_priority_free(&frame.priority); - CU_ASSERT(20 == session->num_idle_streams); - CU_ASSERT(3 == session->idle_stream_head->stream_id); + assert_size(20, ==, session->num_idle_streams); + assert_int32(3, ==, session->idle_stream_head->stream_id); nghttp2_session_del(session); } @@ -11039,7 +11367,7 @@ void test_nghttp2_session_repeated_priority_submission(void) { memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -11048,8 +11376,8 @@ void test_nghttp2_session_repeated_priority_submission(void) { /* 1 -> 0 */ nghttp2_priority_spec_init(&pri_spec, 0, 16, 0); - CU_ASSERT(0 == - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); + assert_int(0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); last_stream_id = (int32_t)(max_streams * 2 + 1); @@ -11057,23 +11385,24 @@ void test_nghttp2_session_repeated_priority_submission(void) { /* 1 -> stream_id */ nghttp2_priority_spec_init(&pri_spec, stream_id, 16, 0); - CU_ASSERT( - 0 == nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); + assert_int( + 0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); } - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(max_streams == session->num_idle_streams); - CU_ASSERT(1 == session->idle_stream_head->stream_id); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(max_streams, ==, session->num_idle_streams); + assert_int32(1, ==, session->idle_stream_head->stream_id); /* 1 -> last_stream_id */ nghttp2_priority_spec_init(&pri_spec, last_stream_id, 16, 0); - CU_ASSERT(0 == - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); + assert_int(0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(max_streams == session->num_idle_streams); - CU_ASSERT(3 == session->idle_stream_head->stream_id); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(max_streams, ==, session->num_idle_streams); + assert_int32(3, ==, session->idle_stream_head->stream_id); nghttp2_session_del(session); } @@ -11085,117 +11414,129 @@ void test_nghttp2_session_set_local_window_size(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); stream = open_sent_stream(session, 1); stream->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 65536)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1 == - stream->local_window_size); - CU_ASSERT(4096 == stream->recv_window_size); - CU_ASSERT(65536 - 4096 == - nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 1, 65536)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1, ==, + stream->local_window_size); + assert_int32(4096, ==, stream->recv_window_size); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(1 == item->frame.window_update.hd.stream_id); - CU_ASSERT(1 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.window_update.hd.stream_id); + assert_int32(1, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Go decrement part */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 32768)); - CU_ASSERT(32768 == stream->local_window_size); - CU_ASSERT(-28672 == stream->recv_window_size); - CU_ASSERT(32768 == stream->recv_reduction); - CU_ASSERT(65536 - 4096 == - nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 1, 32768)); + assert_int32(32768, ==, stream->local_window_size); + assert_int32(-28672, ==, stream->recv_window_size); + assert_int32(32768, ==, stream->recv_reduction); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item == NULL); + assert_null(item); /* Increase local window size */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 49152)); - CU_ASSERT(49152 == stream->local_window_size); - CU_ASSERT(-12288 == stream->recv_window_size); - CU_ASSERT(16384 == stream->recv_reduction); - CU_ASSERT(65536 - 4096 == - nghttp2_session_get_stream_local_window_size(session, 1)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 1, 49152)); + assert_int32(49152, ==, stream->local_window_size); + assert_int32(-12288, ==, stream->recv_window_size); + assert_int32(16384, ==, stream->recv_reduction); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); + assert_null(nghttp2_session_get_next_ob_item(session)); /* Increase local window again */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 65537)); - CU_ASSERT(65537 == stream->local_window_size); - CU_ASSERT(4096 == stream->recv_window_size); - CU_ASSERT(0 == stream->recv_reduction); - CU_ASSERT(65537 - 4096 == - nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 1, 65537)); + assert_int32(65537, ==, stream->local_window_size); + assert_int32(4096, ==, stream->recv_window_size); + assert_int32(0, ==, stream->recv_reduction); + assert_int32(65537 - 4096, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(1 == item->frame.window_update.window_size_increment); + assert_int32(1, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Check connection-level flow control */ session->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 65536)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1 == - session->local_window_size); - CU_ASSERT(4096 == session->recv_window_size); - CU_ASSERT(65536 - 4096 == nghttp2_session_get_local_window_size(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 0, 65536)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1, ==, + session->local_window_size); + assert_int32(4096, ==, session->recv_window_size); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_local_window_size(session)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.window_update.hd.stream_id); - CU_ASSERT(1 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.window_update.hd.stream_id); + assert_int32(1, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Go decrement part */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 32768)); - CU_ASSERT(32768 == session->local_window_size); - CU_ASSERT(-28672 == session->recv_window_size); - CU_ASSERT(32768 == session->recv_reduction); - CU_ASSERT(65536 - 4096 == nghttp2_session_get_local_window_size(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 0, 32768)); + assert_int32(32768, ==, session->local_window_size); + assert_int32(-28672, ==, session->recv_window_size); + assert_int32(32768, ==, session->recv_reduction); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_local_window_size(session)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item == NULL); + assert_null(item); /* Increase local window size */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 49152)); - CU_ASSERT(49152 == session->local_window_size); - CU_ASSERT(-12288 == session->recv_window_size); - CU_ASSERT(16384 == session->recv_reduction); - CU_ASSERT(65536 - 4096 == nghttp2_session_get_local_window_size(session)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 0, 49152)); + assert_int32(49152, ==, session->local_window_size); + assert_int32(-12288, ==, session->recv_window_size); + assert_int32(16384, ==, session->recv_reduction); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_local_window_size(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); /* Increase local window again */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 65537)); - CU_ASSERT(65537 == session->local_window_size); - CU_ASSERT(4096 == session->recv_window_size); - CU_ASSERT(0 == session->recv_reduction); - CU_ASSERT(65537 - 4096 == nghttp2_session_get_local_window_size(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 0, 65537)); + assert_int32(65537, ==, session->local_window_size); + assert_int32(4096, ==, session->recv_window_size); + assert_int32(0, ==, session->recv_reduction); + assert_int32(65537 - 4096, ==, + nghttp2_session_get_local_window_size(session)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(1 == item->frame.window_update.window_size_increment); + assert_int32(1, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_session_del(session); @@ -11205,25 +11546,26 @@ void test_nghttp2_session_set_local_window_size(void) { stream = open_sent_stream(session, 1); stream->recv_window_size = NGHTTP2_INITIAL_WINDOW_SIZE; - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 0)); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int( + 0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, 1, 0)); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(0, ==, nghttp2_session_get_stream_local_window_size(session, 1)); /* This should submit WINDOW_UPDATE frame because stream-level receiving window is now full. */ - CU_ASSERT(0 == - nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, 1, - NGHTTP2_INITIAL_WINDOW_SIZE)); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int(0, ==, + nghttp2_session_set_local_window_size( + session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_INITIAL_WINDOW_SIZE)); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + item->frame.window_update.window_size_increment); nghttp2_session_del(session); @@ -11233,25 +11575,26 @@ void test_nghttp2_session_set_local_window_size(void) { nghttp2_session_client_new(&session, &callbacks, NULL); session->recv_window_size = NGHTTP2_INITIAL_WINDOW_SIZE; - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 0)); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(0 == nghttp2_session_get_local_window_size(session)); + assert_int( + 0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, 0, 0)); + assert_int32(0, ==, session->recv_window_size); + assert_int32(0, ==, nghttp2_session_get_local_window_size(session)); /* This should submit WINDOW_UPDATE frame because connection-level receiving window is now full. */ - CU_ASSERT(0 == - nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, 0, - NGHTTP2_INITIAL_WINDOW_SIZE)); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - nghttp2_session_get_local_window_size(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size( + session, NGHTTP2_FLAG_NONE, 0, NGHTTP2_INITIAL_WINDOW_SIZE)); + assert_int32(0, ==, session->recv_window_size); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + nghttp2_session_get_local_window_size(session)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.hd.stream_id); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + item->frame.window_update.window_size_increment); nghttp2_session_del(session); } @@ -11262,7 +11605,7 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { nghttp2_session_callbacks callbacks; my_user_data ud; nghttp2_settings_entry iv; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; int32_t stream_id; nghttp2_stream *stream; @@ -11270,7 +11613,7 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { callbacks.before_frame_send_callback = cancel_before_frame_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); @@ -11279,7 +11622,7 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); ud.frame_send_cb_called = 0; ud.before_frame_send_cb_called = 0; @@ -11287,18 +11630,18 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(1 == ud.before_frame_send_cb_called); - CU_ASSERT(1 == ud.frame_not_send_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_send_cb_called); + assert_int(1, ==, ud.before_frame_send_cb_called); + assert_int(1, ==, ud.frame_not_send_cb_called); data_prd.source.ptr = NULL; data_prd.read_callback = temporal_failure_data_source_read_callback; - stream_id = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), - &data_prd, NULL); + stream_id = nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), + &data_prd, NULL); - CU_ASSERT(stream_id > 0); + assert_int32(0, <, stream_id); ud.frame_send_cb_called = 0; ud.before_frame_send_cb_called = 0; @@ -11306,14 +11649,14 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(1 == ud.before_frame_send_cb_called); - CU_ASSERT(1 == ud.frame_not_send_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_send_cb_called); + assert_int(1, ==, ud.before_frame_send_cb_called); + assert_int(1, ==, ud.frame_not_send_cb_called); stream = nghttp2_session_get_stream_raw(session, stream_id); - CU_ASSERT(NULL == stream); + assert_null(stream); nghttp2_session_del(session); @@ -11324,7 +11667,7 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { stream_id = nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, reqnv, ARRLEN(reqnv), NULL); - CU_ASSERT(stream_id > 0); + assert_int32(0, <, stream_id); ud.frame_send_cb_called = 0; ud.before_frame_send_cb_called = 0; @@ -11332,14 +11675,14 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(1 == ud.before_frame_send_cb_called); - CU_ASSERT(1 == ud.frame_not_send_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_send_cb_called); + assert_int(1, ==, ud.before_frame_send_cb_called); + assert_int(1, ==, ud.frame_not_send_cb_called); stream = nghttp2_session_get_stream_raw(session, stream_id); - CU_ASSERT(NULL == stream); + assert_null(stream); nghttp2_session_del(session); } @@ -11351,7 +11694,7 @@ void test_nghttp2_session_too_many_settings(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_settings_entry iv[3]; nghttp2_mem *mem; @@ -11362,14 +11705,14 @@ void test_nghttp2_session_too_many_settings(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_option_new(&option); nghttp2_option_set_max_settings(option, 1); nghttp2_session_client_new2(&session, &callbacks, &ud, option); - CU_ASSERT(1 == session->max_settings); + assert_size(1, ==, session->max_settings); nghttp2_option_del(option); @@ -11384,8 +11727,8 @@ void test_nghttp2_session_too_many_settings(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -11394,11 +11737,11 @@ void test_nghttp2_session_too_many_settings(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_bufs_reset(&bufs); nghttp2_bufs_free(&bufs); @@ -11412,7 +11755,7 @@ prepare_session_removed_closed_stream(nghttp2_session *session, nghttp2_settings_entry iv; nghttp2_bufs bufs; nghttp2_mem *mem; - ssize_t nread; + nghttp2_ssize nread; int i; nghttp2_stream *stream; nghttp2_frame_hd hd; @@ -11426,23 +11769,23 @@ prepare_session_removed_closed_stream(nghttp2_session *session, rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); for (i = 1; i <= 3; i += 2) { rv = pack_headers(&bufs, deflater, i, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); nghttp2_bufs_reset(&bufs); } @@ -11453,17 +11796,17 @@ prepare_session_removed_closed_stream(nghttp2_session *session, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); /* Receiving stream 5 will erase stream 3 from closed stream list */ - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); stream = nghttp2_session_get_stream_raw(session, 3); - CU_ASSERT(NULL == stream); + assert_null(stream); /* Since the current max concurrent streams is NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS, receiving frame on stream @@ -11473,24 +11816,24 @@ prepare_session_removed_closed_stream(nghttp2_session *session, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, trailernv, ARRLEN(trailernv), mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_NONE, 3); nghttp2_bufs_reset(&bufs); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); + assert_null(nghttp2_session_get_next_ob_item(session)); /* Now server receives SETTINGS ACK */ nghttp2_frame_hd_init(&hd, 0, NGHTTP2_SETTINGS, NGHTTP2_FLAG_ACK, 0); @@ -11498,10 +11841,10 @@ prepare_session_removed_closed_stream(nghttp2_session *session, nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); nghttp2_bufs_free(&bufs); } @@ -11513,7 +11856,7 @@ void test_nghttp2_session_removed_closed_stream(void) { nghttp2_hd_deflater deflater; nghttp2_bufs bufs; nghttp2_mem *mem; - ssize_t nread; + nghttp2_ssize nread; nghttp2_frame_hd hd; nghttp2_outbound_item *item; @@ -11523,7 +11866,7 @@ void test_nghttp2_session_removed_closed_stream(void) { memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -11542,16 +11885,16 @@ void test_nghttp2_session_removed_closed_stream(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, trailernv, ARRLEN(trailernv), mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -11567,14 +11910,14 @@ void test_nghttp2_session_removed_closed_stream(void) { nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -11582,7 +11925,7 @@ void test_nghttp2_session_removed_closed_stream(void) { nghttp2_bufs_free(&bufs); } -static ssize_t pause_once_data_source_read_callback( +static nghttp2_ssize pause_once_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { my_user_data *ud = user_data; @@ -11598,11 +11941,11 @@ static ssize_t pause_once_data_source_read_callback( void test_nghttp2_session_pause_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; data_prd.read_callback = pause_once_data_source_read_callback; @@ -11612,19 +11955,20 @@ void test_nghttp2_session_pause_data(void) { open_recv_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.frame_send_cb_called = 0; ud.data_source_read_cb_paused = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(NULL == session->aob.item); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_DATA == ud.sent_frame_type); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, ud.frame_send_cb_called); + assert_null(session->aob.item); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_DATA, ==, ud.sent_frame_type); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_session_del(session); } @@ -11645,7 +11989,7 @@ void test_nghttp2_session_no_closed_streams(void) { nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == session->num_closed_streams); + assert_size(0, ==, session->num_closed_streams); nghttp2_session_del(session); nghttp2_option_del(option); @@ -11658,28 +12002,28 @@ void test_nghttp2_session_set_stream_user_data(void) { int user_data1, user_data2; int rv; const uint8_t *datap; - ssize_t datalen; + nghttp2_ssize datalen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); nghttp2_session_client_new(&session, &callbacks, NULL); - stream_id = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, - &user_data1); + stream_id = nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, + &user_data1); rv = nghttp2_session_set_stream_user_data(session, stream_id, &user_data2); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - datalen = nghttp2_session_mem_send(session, &datap); + datalen = nghttp2_session_mem_send2(session, &datap); - CU_ASSERT(datalen > 0); + assert_ptrdiff(0, <, datalen); - CU_ASSERT(&user_data2 == - nghttp2_session_get_stream_user_data(session, stream_id)); + assert_ptr_equal(&user_data2, + nghttp2_session_get_stream_user_data(session, stream_id)); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_session_set_stream_user_data(session, 2, NULL)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_session_set_stream_user_data(session, 2, NULL)); nghttp2_session_del(session); } @@ -11687,7 +12031,7 @@ void test_nghttp2_session_set_stream_user_data(void) { void test_nghttp2_session_no_rfc7540_priorities(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_outbound_item *item; nghttp2_mem *mem; @@ -11697,70 +12041,76 @@ void test_nghttp2_session_no_rfc7540_priorities(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* Do not use a dependency tree if SETTINGS_NO_RFC7540_PRIORITIES = 1. */ data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 128 * 1024; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv.value = 1; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); + assert_int(0, ==, nghttp2_session_send(session)); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), - &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), &data_prd)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(resnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(resnv), ==, item->frame.headers.nvlen); assert_nv_equal(resnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == nghttp2_pq_size( - &session->sched[NGHTTP2_EXTPRI_DEFAULT_URGENCY].ob_data)); - CU_ASSERT(nghttp2_pq_empty(&session->root.obq)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size( + 1, ==, + nghttp2_pq_size(&session->sched[NGHTTP2_EXTPRI_DEFAULT_URGENCY].ob_data)); + assert_true(nghttp2_pq_empty(&session->root.obq)); nghttp2_session_del(session); /* Priorities are sent as is before client receives SETTINGS_NO_RFC7540_PRIORITIES = 1 from server. */ - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv.value = 1; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); + assert_int(0, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); pri_spec.stream_id = 5; pri_spec.weight = 111; pri_spec.exclusive = 1; - CU_ASSERT(1 == nghttp2_submit_request(session, &pri_spec, reqnv, - ARRLEN(reqnv), NULL, NULL)); + assert_int32(1, ==, + nghttp2_submit_request2(session, &pri_spec, reqnv, ARRLEN(reqnv), + NULL, NULL)); item = nghttp2_outbound_queue_top(&session->ob_syn); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(pri_spec.stream_id == item->frame.headers.pri_spec.stream_id); - CU_ASSERT(pri_spec.weight == item->frame.headers.pri_spec.weight); - CU_ASSERT(pri_spec.exclusive == item->frame.headers.pri_spec.exclusive); + assert_not_null(item); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_int32(pri_spec.stream_id, ==, item->frame.headers.pri_spec.stream_id); + assert_int32(pri_spec.weight, ==, item->frame.headers.pri_spec.weight); + assert_uint8(pri_spec.exclusive, ==, item->frame.headers.pri_spec.exclusive); nghttp2_session_del(session); /* Priorities are defaulted if client received SETTINGS_NO_RFC7540_PRIORITIES = 1 from server. */ - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv.value = 1; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); + assert_int(0, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); session->remote_settings.no_rfc7540_priorities = 1; @@ -11768,14 +12118,16 @@ void test_nghttp2_session_no_rfc7540_priorities(void) { pri_spec.weight = 111; pri_spec.exclusive = 1; - CU_ASSERT(1 == nghttp2_submit_request(session, &pri_spec, reqnv, - ARRLEN(reqnv), NULL, NULL)); + assert_int32(1, ==, + nghttp2_submit_request2(session, &pri_spec, reqnv, ARRLEN(reqnv), + NULL, NULL)); item = nghttp2_outbound_queue_top(&session->ob_syn); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(nghttp2_priority_spec_check_default(&item->frame.headers.pri_spec)); + assert_not_null(item); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_true( + nghttp2_priority_spec_check_default(&item->frame.headers.pri_spec)); nghttp2_session_del(session); } @@ -11787,7 +12139,7 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; nghttp2_settings_entry iv; nghttp2_mem *mem; nghttp2_hd_deflater deflater; @@ -11803,7 +12155,7 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; nghttp2_option_new(&option); @@ -11817,24 +12169,24 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, NULL, 0); rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_settings_free(&frame.settings, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == session->fallback_rfc7540_priorities); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_true(session->fallback_rfc7540_priorities); nghttp2_hd_deflate_init(&deflater, mem); @@ -11847,27 +12199,28 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); anchor_stream = nghttp2_session_get_stream_raw(session, 3); - CU_ASSERT(NGHTTP2_STREAM_IDLE == anchor_stream->state); - CU_ASSERT( - !(anchor_stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)); - CU_ASSERT(&session->root == anchor_stream->dep_prev); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, + anchor_stream->state); + assert_false(anchor_stream->flags & + NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); + assert_ptr_equal(&session->root, anchor_stream->dep_prev); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)); - CU_ASSERT(anchor_stream == stream->dep_prev); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_false(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); + assert_ptr_equal(anchor_stream, stream->dep_prev); /* Make sure that PRIORITY frame updates stream priority. */ nghttp2_priority_spec_init(&pri_spec, 5, 1, 0); @@ -11878,15 +12231,16 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_frame_priority_free(&frame.priority); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); anchor_stream = nghttp2_session_get_stream_raw(session, 5); - CU_ASSERT(NGHTTP2_STREAM_IDLE == anchor_stream->state); - CU_ASSERT(&session->root == anchor_stream->dep_prev); - CU_ASSERT(anchor_stream == stream->dep_prev); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, + anchor_stream->state); + assert_ptr_equal(&session->root, anchor_stream->dep_prev); + assert_ptr_equal(anchor_stream, stream->dep_prev); /* Make sure that PRIORITY_UPDATE frame is ignored. */ frame.ext.payload = &priority_update; @@ -11897,11 +12251,11 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { ud.frame_recv_cb_called = 0; buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_EXTPRI_DEFAULT_URGENCY == stream->extpri); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); + assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, stream->extpri); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -11911,11 +12265,11 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv.value = 0; @@ -11925,15 +12279,15 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_settings_free(&frame.settings, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == session->fallback_rfc7540_priorities); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_false(session->fallback_rfc7540_priorities); nghttp2_hd_deflate_init(&deflater, mem); @@ -11946,20 +12300,20 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(NULL == nghttp2_session_get_stream_raw(session, 3)); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_null(nghttp2_session_get_stream_raw(session, 3)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_true(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -11972,7 +12326,7 @@ void test_nghttp2_session_stream_reset_ratelim(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; nghttp2_frame frame; - ssize_t rv; + nghttp2_ssize rv; nghttp2_bufs bufs; nghttp2_buf *buf; nghttp2_mem *mem; @@ -11988,7 +12342,7 @@ void test_nghttp2_session_stream_reset_ratelim(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_option_new(&option); nghttp2_option_set_stream_reset_rate_limit( @@ -11999,19 +12353,19 @@ void test_nghttp2_session_stream_reset_ratelim(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, NULL, 0); rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_settings_free(&frame.settings, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); /* Send SETTINGS ACK */ rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_hd_deflate_init(&deflater, mem); @@ -12028,14 +12382,14 @@ void test_nghttp2_session_stream_reset_ratelim(void) { nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); nghttp2_bufs_reset(&bufs); @@ -12046,23 +12400,23 @@ void test_nghttp2_session_stream_reset_ratelim(void) { nghttp2_frame_rst_stream_free(&frame.rst_stream); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); if (i < NGHTTP2_DEFAULT_STREAM_RESET_BURST) { - CU_ASSERT(0 == nghttp2_outbound_queue_size(&session->ob_reg)); + assert_size(0, ==, nghttp2_outbound_queue_size(&session->ob_reg)); continue; } - CU_ASSERT(1 == nghttp2_outbound_queue_size(&session->ob_reg)); + assert_size(1, ==, nghttp2_outbound_queue_size(&session->ob_reg)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_DEFAULT_STREAM_RESET_BURST * 2 + 1 == - item->frame.goaway.last_stream_id); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_int32(NGHTTP2_DEFAULT_STREAM_RESET_BURST * 2 + 1, ==, + item->frame.goaway.last_stream_id); } nghttp2_hd_deflate_free(&deflater); @@ -12075,7 +12429,7 @@ static void check_nghttp2_http_recv_headers_fail( nghttp2_session *session, nghttp2_hd_deflater *deflater, int32_t stream_id, int stream_state, const nghttp2_nv *nva, size_t nvlen) { nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_outbound_item *item; nghttp2_bufs bufs; my_user_data *ud; @@ -12095,21 +12449,21 @@ static void check_nghttp2_http_recv_headers_fail( rv = pack_headers(&bufs, deflater, stream_id, NGHTTP2_FLAG_END_HEADERS, nva, nvlen, mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud->invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == ud->invalid_frame_recv_cb_called); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_ptrdiff(1, ==, ud->invalid_frame_recv_cb_called); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_free(&bufs); } @@ -12118,7 +12472,7 @@ static void check_nghttp2_http_recv_headers_ok( nghttp2_session *session, nghttp2_hd_deflater *deflater, int32_t stream_id, int stream_state, const nghttp2_nv *nva, size_t nvlen) { nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_bufs bufs; my_user_data *ud; @@ -12137,16 +12491,16 @@ static void check_nghttp2_http_recv_headers_ok( rv = pack_headers(&bufs, deflater, stream_id, NGHTTP2_FLAG_END_HEADERS, nva, nvlen, mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud->frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(1 == ud->frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_int(1, ==, ud->frame_recv_cb_called); nghttp2_bufs_free(&bufs); } @@ -12249,7 +12603,7 @@ void test_nghttp2_http_mandatory_headers(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; @@ -12453,7 +12807,7 @@ void test_nghttp2_http_content_length(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; nghttp2_stream *stream; const nghttp2_nv cl_resnv[] = {MAKE_NV(":status", "200"), MAKE_NV("te", "trailers"), @@ -12467,7 +12821,7 @@ void test_nghttp2_http_content_length(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -12477,15 +12831,15 @@ void test_nghttp2_http_content_length(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(9000000000LL == stream->content_length); - CU_ASSERT(200 == stream->status_code); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_int64(9000000000LL, ==, stream->content_length); + assert_int16(200, ==, stream->status_code); nghttp2_hd_deflate_free(&deflater); @@ -12500,17 +12854,17 @@ void test_nghttp2_http_content_length(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, cl_reqnv, ARRLEN(cl_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(9000000000LL == stream->content_length); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_int64(9000000000LL, ==, stream->content_length); nghttp2_hd_deflate_free(&deflater); @@ -12525,7 +12879,7 @@ void test_nghttp2_http_content_length_mismatch(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv cl_reqnv[] = { MAKE_NV(":path", "/"), MAKE_NV(":method", "PUT"), MAKE_NV(":authority", "localhost"), MAKE_NV(":scheme", "https"), @@ -12539,7 +12893,7 @@ void test_nghttp2_http_content_length_mismatch(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -12549,59 +12903,59 @@ void test_nghttp2_http_content_length_mismatch(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, cl_reqnv, ARRLEN(cl_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); /* header says content-length: 20, but DATA has 0 byte */ rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, cl_reqnv, ARRLEN(cl_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 3); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); /* header says content-length: 20, but DATA has 21 bytes */ rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, cl_reqnv, ARRLEN(cl_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 21, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 5); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN + 21; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12615,83 +12969,83 @@ void test_nghttp2_http_content_length_mismatch(void) { nghttp2_hd_deflate_init(&deflater, mem); /* header says content-length: 20, but HEADERS has END_STREAM flag set */ - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(nghttp2_session_get_stream(session, 1)); + assert_int(0, ==, nghttp2_session_send(session)); /* After sending RST_STREAM, stream must be closed */ - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + assert_null(nghttp2_session_get_stream(session, 1)); nghttp2_bufs_reset(&bufs); /* header says content-length: 20, but DATA has 0 byte */ - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 3); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 3)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(nghttp2_session_get_stream(session, 3)); + assert_int(0, ==, nghttp2_session_send(session)); /* After sending RST_STREAM, stream must be closed */ - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 3)); + assert_null(nghttp2_session_get_stream(session, 3)); nghttp2_bufs_reset(&bufs); /* header says content-length: 20, but DATA has 21 bytes */ - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 21, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 5); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN + 21; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 5)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(nghttp2_session_get_stream(session, 5)); + assert_int(0, ==, nghttp2_session_send(session)); /* After sending RST_STREAM, stream must be closed */ - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 5)); + assert_null(nghttp2_session_get_stream(session, 5)); nghttp2_bufs_reset(&bufs); @@ -12708,7 +13062,7 @@ void test_nghttp2_http_non_final_response(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv nonfinal_resnv[] = { MAKE_NV(":status", "100"), }; @@ -12719,7 +13073,7 @@ void test_nghttp2_http_non_final_response(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -12731,17 +13085,17 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12750,21 +13104,21 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 10, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 3); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN + 10; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12774,18 +13128,18 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_NONE, 5); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_bufs_reset(&bufs); @@ -12795,22 +13149,22 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 7, NGHTTP2_FLAG_END_HEADERS, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 7); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12819,25 +13173,25 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 9, NGHTTP2_FLAG_END_HEADERS, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 9, NGHTTP2_FLAG_END_HEADERS, resnv, ARRLEN(resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_bufs_reset(&bufs); @@ -12854,7 +13208,7 @@ void test_nghttp2_http_trailer_headers(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv trailer_reqnv[] = { MAKE_NV("foo", "bar"), }; @@ -12864,7 +13218,7 @@ void test_nghttp2_http_trailer_headers(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -12873,84 +13227,84 @@ void test_nghttp2_http_trailer_headers(void) { /* good trailer header */ rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, trailer_reqnv, ARRLEN(trailer_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_bufs_reset(&bufs); /* trailer header without END_STREAM is illegal */ rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, trailer_reqnv, ARRLEN(trailer_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); /* trailer header including pseudo header field is illegal */ rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12967,7 +13321,7 @@ void test_nghttp2_http_ignore_regular_header(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; const nghttp2_nv bad_reqnv[] = { MAKE_NV(":authority", "localhost"), @@ -12988,7 +13342,7 @@ void test_nghttp2_http_ignore_regular_header(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_header_callback = pause_on_header_callback; nghttp2_session_server_new(&session, &callbacks, &ud); @@ -12998,32 +13352,32 @@ void test_nghttp2_http_ignore_regular_header(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, bad_reqnv, ARRLEN(bad_reqnv), mem); - CU_ASSERT_FATAL(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_hd_deflate_free(&deflater); proclen = 0; for (i = 0; i < 4; ++i) { - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT_FATAL(rv > 0); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); + assert_ptrdiff(0, <, rv); proclen += (size_t)rv; - CU_ASSERT(nghttp2_nv_equal(&bad_ansnv[i], &ud.nv)); + assert_true(nghttp2_nv_equal(&bad_ansnv[i], &ud.nv)); } - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT_FATAL(rv > 0); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); + assert_ptrdiff(0, <, rv); /* Without on_invalid_frame_recv_callback, bad header causes stream reset */ item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); proclen += (size_t)rv; - CU_ASSERT(nghttp2_buf_len(&bufs.head->buf) == proclen); + assert_size(nghttp2_buf_len(&bufs.head->buf), ==, proclen); nghttp2_session_del(session); @@ -13037,29 +13391,29 @@ void test_nghttp2_http_ignore_regular_header(void) { ud.invalid_header_cb_called = 0; for (i = 0; i < 4; ++i) { - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT_FATAL(rv > 0); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); + assert_ptrdiff(0, <, rv); proclen += (size_t)rv; - CU_ASSERT(nghttp2_nv_equal(&bad_ansnv[i], &ud.nv)); + assert_true(nghttp2_nv_equal(&bad_ansnv[i], &ud.nv)); } - CU_ASSERT(0 == ud.invalid_header_cb_called); + assert_int(0, ==, ud.invalid_header_cb_called); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT_FATAL(rv > 0); - CU_ASSERT(1 == ud.invalid_header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&bad_reqnv[4], &ud.nv)); + assert_ptrdiff(0, <, rv); + assert_int(1, ==, ud.invalid_header_cb_called); + assert_true(nghttp2_nv_equal(&bad_reqnv[4], &ud.nv)); proclen += (size_t)rv; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT(rv > 0); - CU_ASSERT(nghttp2_nv_equal(&bad_ansnv[4], &ud.nv)); + assert_ptrdiff(0, <, rv); + assert_true(nghttp2_nv_equal(&bad_ansnv[4], &ud.nv)); nghttp2_session_del(session); @@ -13070,15 +13424,15 @@ void test_nghttp2_http_ignore_regular_header(void) { nghttp2_session_server_new(&session, &callbacks, &ud); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT(rv == (ssize_t)nghttp2_buf_len(&bufs.head->buf)); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); nghttp2_session_del(session); nghttp2_bufs_free(&bufs); @@ -13090,7 +13444,7 @@ void test_nghttp2_http_ignore_content_length(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv cl_resnv[] = {MAKE_NV(":status", "304"), MAKE_NV("content-length", "20")}; const nghttp2_nv conn_reqnv[] = {MAKE_NV(":authority", "localhost"), @@ -13104,7 +13458,7 @@ void test_nghttp2_http_ignore_content_length(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -13116,14 +13470,14 @@ void test_nghttp2_http_ignore_content_length(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_bufs_reset(&bufs); @@ -13133,15 +13487,15 @@ void test_nghttp2_http_ignore_content_length(void) { rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, conn_cl_resnv, ARRLEN(conn_cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(-1 == stream->content_length); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_int64(-1, ==, stream->content_length); nghttp2_bufs_reset(&bufs); @@ -13156,19 +13510,19 @@ void test_nghttp2_http_ignore_content_length(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, conn_reqnv, ARRLEN(conn_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(-1 == stream->content_length); - CU_ASSERT((stream->http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT) > 0); + assert_int64(-1, ==, stream->content_length); + assert_true(stream->http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -13183,7 +13537,7 @@ void test_nghttp2_http_record_request_method(void) { const nghttp2_nv conn_resnv[] = {MAKE_NV(":status", "200"), MAKE_NV("content-length", "9999")}; nghttp2_stream *stream; - ssize_t rv; + nghttp2_ssize rv; nghttp2_bufs bufs; nghttp2_hd_deflater deflater; nghttp2_mem *mem; @@ -13193,37 +13547,38 @@ void test_nghttp2_http_record_request_method(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); nghttp2_hd_deflate_init(&deflater, mem); - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, conn_reqnv, - ARRLEN(conn_reqnv), NULL, NULL)); + assert_int32(1, ==, + nghttp2_submit_request2(session, NULL, conn_reqnv, + ARRLEN(conn_reqnv), NULL, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_HTTP_FLAG_METH_CONNECT == stream->http_flags); + assert_uint32(NGHTTP2_HTTP_FLAG_METH_CONNECT, ==, stream->http_flags); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, conn_resnv, ARRLEN(conn_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT((NGHTTP2_HTTP_FLAG_METH_CONNECT & stream->http_flags) > 0); - CU_ASSERT(-1 == stream->content_length); + assert_true(NGHTTP2_HTTP_FLAG_METH_CONNECT & stream->http_flags); + assert_int64(-1, ==, stream->content_length); /* content-length is ignored in 200 response to a CONNECT request */ item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -13236,7 +13591,7 @@ void test_nghttp2_http_push_promise(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; nghttp2_stream *stream; const nghttp2_nv bad_reqnv[] = {MAKE_NV(":method", "GET")}; nghttp2_outbound_item *item; @@ -13245,7 +13600,7 @@ void test_nghttp2_http_push_promise(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* good PUSH_PROMISE case */ nghttp2_session_client_new(&session, &callbacks, NULL); @@ -13256,33 +13611,33 @@ void test_nghttp2_http_push_promise(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NULL != stream); + assert_not_null(stream); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 2, NGHTTP2_FLAG_END_HEADERS, resnv, ARRLEN(resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(200 == stream->status_code); + assert_int16(200, ==, stream->status_code); nghttp2_bufs_reset(&bufs); @@ -13290,17 +13645,17 @@ void test_nghttp2_http_push_promise(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 4, bad_reqnv, ARRLEN(bad_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(4 == item->frame.hd.stream_id); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(4, ==, item->frame.hd.stream_id); nghttp2_bufs_reset(&bufs); @@ -13317,14 +13672,14 @@ void test_nghttp2_http_head_method_upgrade_workaround(void) { nghttp2_bufs bufs; nghttp2_hd_deflater deflater; nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_stream *stream; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -13335,16 +13690,16 @@ void test_nghttp2_http_head_method_upgrade_workaround(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(-1 == stream->content_length); + assert_int64(-1, ==, stream->content_length); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -13357,7 +13712,7 @@ void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv ws_reqnv[] = { MAKE_NV(":path", "/"), MAKE_NV(":method", "GET"), @@ -13372,7 +13727,7 @@ void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* By default, the leading and trailing white spaces validation is enabled as per RFC 9113. */ @@ -13384,17 +13739,17 @@ void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, ws_reqnv, ARRLEN(ws_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -13412,16 +13767,16 @@ void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, ws_reqnv, ARRLEN(ws_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_bufs_reset(&bufs); nghttp2_hd_deflate_free(&deflater); diff --git a/yass/third_party/nghttp2/tests/nghttp2_session_test.h b/yass/third_party/nghttp2/tests/nghttp2_session_test.h index be4fdf8976..43befbeb01 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_session_test.h +++ b/yass/third_party/nghttp2/tests/nghttp2_session_test.h @@ -29,156 +29,165 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp2_session_recv(void); -void test_nghttp2_session_recv_invalid_stream_id(void); -void test_nghttp2_session_recv_invalid_frame(void); -void test_nghttp2_session_recv_eof(void); -void test_nghttp2_session_recv_data(void); -void test_nghttp2_session_recv_data_no_auto_flow_control(void); -void test_nghttp2_session_recv_continuation(void); -void test_nghttp2_session_recv_headers_with_priority(void); -void test_nghttp2_session_recv_headers_with_padding(void); -void test_nghttp2_session_recv_headers_early_response(void); -void test_nghttp2_session_recv_headers_for_closed_stream(void); -void test_nghttp2_session_recv_headers_with_extpri(void); -void test_nghttp2_session_server_recv_push_response(void); -void test_nghttp2_session_recv_premature_headers(void); -void test_nghttp2_session_recv_unknown_frame(void); -void test_nghttp2_session_recv_unexpected_continuation(void); -void test_nghttp2_session_recv_settings_header_table_size(void); -void test_nghttp2_session_recv_too_large_frame_length(void); -void test_nghttp2_session_recv_extension(void); -void test_nghttp2_session_recv_altsvc(void); -void test_nghttp2_session_recv_origin(void); -void test_nghttp2_session_recv_priority_update(void); -void test_nghttp2_session_continue(void); -void test_nghttp2_session_add_frame(void); -void test_nghttp2_session_on_request_headers_received(void); -void test_nghttp2_session_on_response_headers_received(void); -void test_nghttp2_session_on_headers_received(void); -void test_nghttp2_session_on_push_response_headers_received(void); -void test_nghttp2_session_on_priority_received(void); -void test_nghttp2_session_on_rst_stream_received(void); -void test_nghttp2_session_on_settings_received(void); -void test_nghttp2_session_on_push_promise_received(void); -void test_nghttp2_session_on_ping_received(void); -void test_nghttp2_session_on_goaway_received(void); -void test_nghttp2_session_on_window_update_received(void); -void test_nghttp2_session_on_data_received(void); -void test_nghttp2_session_on_data_received_fail_fast(void); -void test_nghttp2_session_on_altsvc_received(void); -void test_nghttp2_session_send_headers_start_stream(void); -void test_nghttp2_session_send_headers_reply(void); -void test_nghttp2_session_send_headers_frame_size_error(void); -void test_nghttp2_session_send_headers_push_reply(void); -void test_nghttp2_session_send_rst_stream(void); -void test_nghttp2_session_send_push_promise(void); -void test_nghttp2_session_is_my_stream_id(void); -void test_nghttp2_session_upgrade2(void); -void test_nghttp2_session_reprioritize_stream(void); -void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void); -void test_nghttp2_submit_data(void); -void test_nghttp2_submit_data_read_length_too_large(void); -void test_nghttp2_submit_data_read_length_smallest(void); -void test_nghttp2_submit_data_twice(void); -void test_nghttp2_submit_request_with_data(void); -void test_nghttp2_submit_request_without_data(void); -void test_nghttp2_submit_response_with_data(void); -void test_nghttp2_submit_response_without_data(void); -void test_nghttp2_submit_response_push_response(void); -void test_nghttp2_submit_trailer(void); -void test_nghttp2_submit_headers_start_stream(void); -void test_nghttp2_submit_headers_reply(void); -void test_nghttp2_submit_headers_push_reply(void); -void test_nghttp2_submit_headers(void); -void test_nghttp2_submit_headers_continuation(void); -void test_nghttp2_submit_headers_continuation_extra_large(void); -void test_nghttp2_submit_priority(void); -void test_nghttp2_submit_settings(void); -void test_nghttp2_submit_settings_update_local_window_size(void); -void test_nghttp2_submit_settings_multiple_times(void); -void test_nghttp2_submit_push_promise(void); -void test_nghttp2_submit_window_update(void); -void test_nghttp2_submit_window_update_local_window_size(void); -void test_nghttp2_submit_shutdown_notice(void); -void test_nghttp2_submit_invalid_nv(void); -void test_nghttp2_submit_extension(void); -void test_nghttp2_submit_altsvc(void); -void test_nghttp2_submit_origin(void); -void test_nghttp2_submit_priority_update(void); -void test_nghttp2_submit_rst_stream(void); -void test_nghttp2_session_open_stream(void); -void test_nghttp2_session_open_stream_with_idle_stream_dep(void); -void test_nghttp2_session_get_next_ob_item(void); -void test_nghttp2_session_pop_next_ob_item(void); -void test_nghttp2_session_reply_fail(void); -void test_nghttp2_session_max_concurrent_streams(void); -void test_nghttp2_session_stop_data_with_rst_stream(void); -void test_nghttp2_session_defer_data(void); -void test_nghttp2_session_flow_control(void); -void test_nghttp2_session_flow_control_data_recv(void); -void test_nghttp2_session_flow_control_data_with_padding_recv(void); -void test_nghttp2_session_data_read_temporal_failure(void); -void test_nghttp2_session_on_stream_close(void); -void test_nghttp2_session_on_ctrl_not_send(void); -void test_nghttp2_session_get_outbound_queue_size(void); -void test_nghttp2_session_get_effective_local_window_size(void); -void test_nghttp2_session_set_option(void); -void test_nghttp2_session_data_backoff_by_high_pri_frame(void); -void test_nghttp2_session_pack_data_with_padding(void); -void test_nghttp2_session_pack_headers_with_padding(void); -void test_nghttp2_pack_settings_payload(void); -void test_nghttp2_session_stream_dep_add(void); -void test_nghttp2_session_stream_dep_remove(void); -void test_nghttp2_session_stream_dep_add_subtree(void); -void test_nghttp2_session_stream_dep_remove_subtree(void); -void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void); -void test_nghttp2_session_stream_attach_item(void); -void test_nghttp2_session_stream_attach_item_subtree(void); -void test_nghttp2_session_stream_get_state(void); -void test_nghttp2_session_stream_get_something(void); -void test_nghttp2_session_find_stream(void); -void test_nghttp2_session_keep_closed_stream(void); -void test_nghttp2_session_keep_idle_stream(void); -void test_nghttp2_session_detach_idle_stream(void); -void test_nghttp2_session_large_dep_tree(void); -void test_nghttp2_session_graceful_shutdown(void); -void test_nghttp2_session_on_header_temporal_failure(void); -void test_nghttp2_session_recv_client_magic(void); -void test_nghttp2_session_delete_data_item(void); -void test_nghttp2_session_open_idle_stream(void); -void test_nghttp2_session_cancel_reserved_remote(void); -void test_nghttp2_session_reset_pending_headers(void); -void test_nghttp2_session_send_data_callback(void); -void test_nghttp2_session_on_begin_headers_temporal_failure(void); -void test_nghttp2_session_defer_then_close(void); -void test_nghttp2_session_detach_item_from_closed_stream(void); -void test_nghttp2_session_flooding(void); -void test_nghttp2_session_change_stream_priority(void); -void test_nghttp2_session_change_extpri_stream_priority(void); -void test_nghttp2_session_create_idle_stream(void); -void test_nghttp2_session_repeated_priority_change(void); -void test_nghttp2_session_repeated_priority_submission(void); -void test_nghttp2_session_set_local_window_size(void); -void test_nghttp2_session_cancel_from_before_frame_send(void); -void test_nghttp2_session_too_many_settings(void); -void test_nghttp2_session_removed_closed_stream(void); -void test_nghttp2_session_pause_data(void); -void test_nghttp2_session_no_closed_streams(void); -void test_nghttp2_session_set_stream_user_data(void); -void test_nghttp2_session_no_rfc7540_priorities(void); -void test_nghttp2_session_server_fallback_rfc7540_priorities(void); -void test_nghttp2_session_stream_reset_ratelim(void); -void test_nghttp2_http_mandatory_headers(void); -void test_nghttp2_http_content_length(void); -void test_nghttp2_http_content_length_mismatch(void); -void test_nghttp2_http_non_final_response(void); -void test_nghttp2_http_trailer_headers(void); -void test_nghttp2_http_ignore_regular_header(void); -void test_nghttp2_http_ignore_content_length(void); -void test_nghttp2_http_record_request_method(void); -void test_nghttp2_http_push_promise(void); -void test_nghttp2_http_head_method_upgrade_workaround(void); -void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite session_suite; + +munit_void_test_decl(test_nghttp2_session_recv); +munit_void_test_decl(test_nghttp2_session_recv_invalid_stream_id); +munit_void_test_decl(test_nghttp2_session_recv_invalid_frame); +munit_void_test_decl(test_nghttp2_session_recv_eof); +munit_void_test_decl(test_nghttp2_session_recv_data); +munit_void_test_decl(test_nghttp2_session_recv_data_no_auto_flow_control); +munit_void_test_decl(test_nghttp2_session_recv_continuation); +munit_void_test_decl(test_nghttp2_session_recv_headers_with_priority); +munit_void_test_decl(test_nghttp2_session_recv_headers_with_padding); +munit_void_test_decl(test_nghttp2_session_recv_headers_early_response); +munit_void_test_decl(test_nghttp2_session_recv_headers_for_closed_stream); +munit_void_test_decl(test_nghttp2_session_recv_headers_with_extpri); +munit_void_test_decl(test_nghttp2_session_server_recv_push_response); +munit_void_test_decl(test_nghttp2_session_recv_premature_headers); +munit_void_test_decl(test_nghttp2_session_recv_unknown_frame); +munit_void_test_decl(test_nghttp2_session_recv_unexpected_continuation); +munit_void_test_decl(test_nghttp2_session_recv_settings_header_table_size); +munit_void_test_decl(test_nghttp2_session_recv_too_large_frame_length); +munit_void_test_decl(test_nghttp2_session_recv_extension); +munit_void_test_decl(test_nghttp2_session_recv_altsvc); +munit_void_test_decl(test_nghttp2_session_recv_origin); +munit_void_test_decl(test_nghttp2_session_recv_priority_update); +munit_void_test_decl(test_nghttp2_session_continue); +munit_void_test_decl(test_nghttp2_session_add_frame); +munit_void_test_decl(test_nghttp2_session_on_request_headers_received); +munit_void_test_decl(test_nghttp2_session_on_response_headers_received); +munit_void_test_decl(test_nghttp2_session_on_headers_received); +munit_void_test_decl(test_nghttp2_session_on_push_response_headers_received); +munit_void_test_decl(test_nghttp2_session_on_priority_received); +munit_void_test_decl(test_nghttp2_session_on_rst_stream_received); +munit_void_test_decl(test_nghttp2_session_on_settings_received); +munit_void_test_decl(test_nghttp2_session_on_push_promise_received); +munit_void_test_decl(test_nghttp2_session_on_ping_received); +munit_void_test_decl(test_nghttp2_session_on_goaway_received); +munit_void_test_decl(test_nghttp2_session_on_window_update_received); +munit_void_test_decl(test_nghttp2_session_on_data_received); +munit_void_test_decl(test_nghttp2_session_on_data_received_fail_fast); +munit_void_test_decl(test_nghttp2_session_on_altsvc_received); +munit_void_test_decl(test_nghttp2_session_send_headers_start_stream); +munit_void_test_decl(test_nghttp2_session_send_headers_reply); +munit_void_test_decl(test_nghttp2_session_send_headers_frame_size_error); +munit_void_test_decl(test_nghttp2_session_send_headers_push_reply); +munit_void_test_decl(test_nghttp2_session_send_rst_stream); +munit_void_test_decl(test_nghttp2_session_send_push_promise); +munit_void_test_decl(test_nghttp2_session_is_my_stream_id); +munit_void_test_decl(test_nghttp2_session_upgrade2); +munit_void_test_decl(test_nghttp2_session_reprioritize_stream); +munit_void_test_decl( + test_nghttp2_session_reprioritize_stream_with_idle_stream_dep); +munit_void_test_decl(test_nghttp2_submit_data); +munit_void_test_decl(test_nghttp2_submit_data_read_length_too_large); +munit_void_test_decl(test_nghttp2_submit_data_read_length_smallest); +munit_void_test_decl(test_nghttp2_submit_data_twice); +munit_void_test_decl(test_nghttp2_submit_request_with_data); +munit_void_test_decl(test_nghttp2_submit_request_without_data); +munit_void_test_decl(test_nghttp2_submit_response_with_data); +munit_void_test_decl(test_nghttp2_submit_response_without_data); +munit_void_test_decl(test_nghttp2_submit_response_push_response); +munit_void_test_decl(test_nghttp2_submit_trailer); +munit_void_test_decl(test_nghttp2_submit_headers_start_stream); +munit_void_test_decl(test_nghttp2_submit_headers_reply); +munit_void_test_decl(test_nghttp2_submit_headers_push_reply); +munit_void_test_decl(test_nghttp2_submit_headers); +munit_void_test_decl(test_nghttp2_submit_headers_continuation); +munit_void_test_decl(test_nghttp2_submit_headers_continuation_extra_large); +munit_void_test_decl(test_nghttp2_submit_priority); +munit_void_test_decl(test_nghttp2_submit_settings); +munit_void_test_decl(test_nghttp2_submit_settings_update_local_window_size); +munit_void_test_decl(test_nghttp2_submit_settings_multiple_times); +munit_void_test_decl(test_nghttp2_submit_push_promise); +munit_void_test_decl(test_nghttp2_submit_window_update); +munit_void_test_decl(test_nghttp2_submit_window_update_local_window_size); +munit_void_test_decl(test_nghttp2_submit_shutdown_notice); +munit_void_test_decl(test_nghttp2_submit_invalid_nv); +munit_void_test_decl(test_nghttp2_submit_extension); +munit_void_test_decl(test_nghttp2_submit_altsvc); +munit_void_test_decl(test_nghttp2_submit_origin); +munit_void_test_decl(test_nghttp2_submit_priority_update); +munit_void_test_decl(test_nghttp2_submit_rst_stream); +munit_void_test_decl(test_nghttp2_session_open_stream); +munit_void_test_decl(test_nghttp2_session_open_stream_with_idle_stream_dep); +munit_void_test_decl(test_nghttp2_session_get_next_ob_item); +munit_void_test_decl(test_nghttp2_session_pop_next_ob_item); +munit_void_test_decl(test_nghttp2_session_reply_fail); +munit_void_test_decl(test_nghttp2_session_max_concurrent_streams); +munit_void_test_decl(test_nghttp2_session_stop_data_with_rst_stream); +munit_void_test_decl(test_nghttp2_session_defer_data); +munit_void_test_decl(test_nghttp2_session_flow_control); +munit_void_test_decl(test_nghttp2_session_flow_control_data_recv); +munit_void_test_decl(test_nghttp2_session_flow_control_data_with_padding_recv); +munit_void_test_decl(test_nghttp2_session_data_read_temporal_failure); +munit_void_test_decl(test_nghttp2_session_on_stream_close); +munit_void_test_decl(test_nghttp2_session_on_ctrl_not_send); +munit_void_test_decl(test_nghttp2_session_get_outbound_queue_size); +munit_void_test_decl(test_nghttp2_session_get_effective_local_window_size); +munit_void_test_decl(test_nghttp2_session_set_option); +munit_void_test_decl(test_nghttp2_session_data_backoff_by_high_pri_frame); +munit_void_test_decl(test_nghttp2_session_pack_data_with_padding); +munit_void_test_decl(test_nghttp2_session_pack_headers_with_padding); +munit_void_test_decl(test_nghttp2_pack_settings_payload); +munit_void_test_decl(test_nghttp2_session_stream_dep_add); +munit_void_test_decl(test_nghttp2_session_stream_dep_remove); +munit_void_test_decl(test_nghttp2_session_stream_dep_add_subtree); +munit_void_test_decl(test_nghttp2_session_stream_dep_remove_subtree); +munit_void_test_decl( + test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us); +munit_void_test_decl(test_nghttp2_session_stream_attach_item); +munit_void_test_decl(test_nghttp2_session_stream_attach_item_subtree); +munit_void_test_decl(test_nghttp2_session_stream_get_state); +munit_void_test_decl(test_nghttp2_session_stream_get_something); +munit_void_test_decl(test_nghttp2_session_find_stream); +munit_void_test_decl(test_nghttp2_session_keep_closed_stream); +munit_void_test_decl(test_nghttp2_session_keep_idle_stream); +munit_void_test_decl(test_nghttp2_session_detach_idle_stream); +munit_void_test_decl(test_nghttp2_session_large_dep_tree); +munit_void_test_decl(test_nghttp2_session_graceful_shutdown); +munit_void_test_decl(test_nghttp2_session_on_header_temporal_failure); +munit_void_test_decl(test_nghttp2_session_recv_client_magic); +munit_void_test_decl(test_nghttp2_session_delete_data_item); +munit_void_test_decl(test_nghttp2_session_open_idle_stream); +munit_void_test_decl(test_nghttp2_session_cancel_reserved_remote); +munit_void_test_decl(test_nghttp2_session_reset_pending_headers); +munit_void_test_decl(test_nghttp2_session_send_data_callback); +munit_void_test_decl(test_nghttp2_session_on_begin_headers_temporal_failure); +munit_void_test_decl(test_nghttp2_session_defer_then_close); +munit_void_test_decl(test_nghttp2_session_detach_item_from_closed_stream); +munit_void_test_decl(test_nghttp2_session_flooding); +munit_void_test_decl(test_nghttp2_session_change_stream_priority); +munit_void_test_decl(test_nghttp2_session_change_extpri_stream_priority); +munit_void_test_decl(test_nghttp2_session_create_idle_stream); +munit_void_test_decl(test_nghttp2_session_repeated_priority_change); +munit_void_test_decl(test_nghttp2_session_repeated_priority_submission); +munit_void_test_decl(test_nghttp2_session_set_local_window_size); +munit_void_test_decl(test_nghttp2_session_cancel_from_before_frame_send); +munit_void_test_decl(test_nghttp2_session_too_many_settings); +munit_void_test_decl(test_nghttp2_session_removed_closed_stream); +munit_void_test_decl(test_nghttp2_session_pause_data); +munit_void_test_decl(test_nghttp2_session_no_closed_streams); +munit_void_test_decl(test_nghttp2_session_set_stream_user_data); +munit_void_test_decl(test_nghttp2_session_no_rfc7540_priorities); +munit_void_test_decl(test_nghttp2_session_server_fallback_rfc7540_priorities); +munit_void_test_decl(test_nghttp2_session_stream_reset_ratelim); +munit_void_test_decl(test_nghttp2_http_mandatory_headers); +munit_void_test_decl(test_nghttp2_http_content_length); +munit_void_test_decl(test_nghttp2_http_content_length_mismatch); +munit_void_test_decl(test_nghttp2_http_non_final_response); +munit_void_test_decl(test_nghttp2_http_trailer_headers); +munit_void_test_decl(test_nghttp2_http_ignore_regular_header); +munit_void_test_decl(test_nghttp2_http_ignore_content_length); +munit_void_test_decl(test_nghttp2_http_record_request_method); +munit_void_test_decl(test_nghttp2_http_push_promise); +munit_void_test_decl(test_nghttp2_http_head_method_upgrade_workaround); +munit_void_test_decl( + test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation); #endif /* NGHTTP2_SESSION_TEST_H */ diff --git a/yass/third_party/nghttp2/tests/nghttp2_stream_test.c b/yass/third_party/nghttp2/tests/nghttp2_stream_test.c index 75b4d68043..91be376229 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_stream_test.c +++ b/yass/third_party/nghttp2/tests/nghttp2_stream_test.c @@ -26,6 +26,4 @@ #include -#include - #include "nghttp2_stream.h" diff --git a/yass/third_party/nghttp2/tests/nghttp2_test_helper.c b/yass/third_party/nghttp2/tests/nghttp2_test_helper.c index 1bd4a63fc8..c1b912be85 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_test_helper.c +++ b/yass/third_party/nghttp2/tests/nghttp2_test_helper.c @@ -27,8 +27,6 @@ #include #include -#include - #include "nghttp2_helper.h" #include "nghttp2_priority_spec.h" @@ -155,9 +153,9 @@ void add_out(nva_out *out, nghttp2_nv *nv, nghttp2_mem *mem) { ++out->nvlen; } -ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, - nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem) { - ssize_t rv; +nghttp2_ssize inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, + nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem) { + nghttp2_ssize rv; nghttp2_nv nv; int inflate_flags; nghttp2_buf_chain *ci; @@ -183,7 +181,7 @@ ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, for (;;) { inflate_flags = 0; - rv = nghttp2_hd_inflate_hd2(inflater, &nv, &inflate_flags, bp.pos, + rv = nghttp2_hd_inflate_hd3(inflater, &nv, &inflate_flags, bp.pos, nghttp2_buf_len(&bp), fin); if (rv < 0) { @@ -210,7 +208,7 @@ ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, nghttp2_hd_inflate_end_headers(inflater); - return (ssize_t)processed; + return (nghttp2_ssize)processed; } int pack_headers(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater, diff --git a/yass/third_party/nghttp2/tests/nghttp2_test_helper.h b/yass/third_party/nghttp2/tests/nghttp2_test_helper.h index c66298a00a..c0ed0b313a 100644 --- a/yass/third_party/nghttp2/tests/nghttp2_test_helper.h +++ b/yass/third_party/nghttp2/tests/nghttp2_test_helper.h @@ -40,24 +40,6 @@ } #define ARRLEN(ARR) (sizeof(ARR) / sizeof(ARR[0])) -#define assert_nv_equal(A, B, len, mem) \ - do { \ - size_t alloclen = sizeof(nghttp2_nv) * len; \ - const nghttp2_nv *sa = A, *sb = B; \ - nghttp2_nv *a = mem->malloc(alloclen, NULL); \ - nghttp2_nv *b = mem->malloc(alloclen, NULL); \ - ssize_t i_; \ - memcpy(a, sa, alloclen); \ - memcpy(b, sb, alloclen); \ - nghttp2_nv_array_sort(a, len); \ - nghttp2_nv_array_sort(b, len); \ - for (i_ = 0; i_ < (ssize_t)len; ++i_) { \ - CU_ASSERT(nghttp2_nv_equal(&a[i_], &b[i_])); \ - } \ - mem->free(b, NULL); \ - mem->free(a, NULL); \ - } while (0); - int unpack_framebuf(nghttp2_frame *frame, nghttp2_bufs *bufs); int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len); @@ -78,8 +60,8 @@ void nva_out_reset(nva_out *out, nghttp2_mem *mem); void add_out(nva_out *out, nghttp2_nv *nv, nghttp2_mem *mem); -ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, - nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem); +nghttp2_ssize inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, + nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem); int pack_headers(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater, int32_t stream_id, uint8_t flags, const nghttp2_nv *nva, diff --git a/yass/third_party/nghttp2/third-party/Makefile.am b/yass/third_party/nghttp2/third-party/Makefile.am index 8b47532e2b..07c2f7864b 100644 --- a/yass/third_party/nghttp2/third-party/Makefile.am +++ b/yass/third_party/nghttp2/third-party/Makefile.am @@ -29,11 +29,15 @@ EXTRA_DIST = CMakeLists.txt build_config.rb # find mruby -type f ! -ipath 'mruby/.*' | awk '{print "\t"$0" \\"}' EXTRA_DIST += \ mruby/AUTHORS \ + mruby/docker-compose.yml \ mruby/codespell.txt \ mruby/CONTRIBUTING.md \ mruby/NEWS \ mruby/CODEOWNERS \ + mruby/Gemfile.lock \ mruby/appveyor.yml \ + mruby/Dockerfile \ + mruby/Gemfile \ mruby/benchmark/plot.gpl \ mruby/benchmark/bm_ao_render.rb \ mruby/benchmark/bm_fib.rb \ @@ -52,6 +56,7 @@ EXTRA_DIST += \ mruby/tasks/benchmark.rake \ mruby/tasks/mrbgems.rake \ mruby/tasks/presym.rake \ + mruby/tasks/install.rake \ mruby/tasks/bin.rake \ mruby/tasks/test.rake \ mruby/tasks/mrblib.rake \ @@ -66,6 +71,8 @@ EXTRA_DIST += \ mruby/oss-fuzz/proto_to_ruby.h \ mruby/build_config/cross-mingw-winetest.rb \ mruby/build_config/host-f32.rb \ + mruby/build_config/nintendo_wii.rb \ + mruby/build_config/i586-pc-msdosdjgpp.rb \ mruby/build_config/chipKITMax32.rb \ mruby/build_config/gameboyadvance.rb \ mruby/build_config/minimal.rb \ @@ -90,7 +97,6 @@ EXTRA_DIST += \ mruby/build_config/clang-asan.rb \ mruby/build_config/RX630.rb \ mruby/build_config/host-nofloat.rb \ - mruby/build_config/android_armeabi.rb \ mruby/build_config/android_arm64_v8a.rb \ mruby/build_config/cross-32bit.rb \ mruby/build_config/cross-mingw.rb \ @@ -170,7 +176,6 @@ EXTRA_DIST += \ mruby/test/t/standarderror.rb \ mruby/test/t/superclass.rb \ mruby/test/assert.rb \ - mruby/super-linter.report/.keep \ mruby/TODO.md \ mruby/Doxyfile \ mruby/mrblib/00kernel.rb \ @@ -220,11 +225,12 @@ EXTRA_DIST += \ mruby/src/array.c \ mruby/src/dump.c \ mruby/src/class.c \ - mruby/src/compar.c \ mruby/src/value_array.h \ + mruby/src/allocf.c \ mruby/src/pool.c \ mruby/mruby-source.gemspec \ mruby/mrbgems/mruby-eval/mrbgem.rake \ + mruby/mrbgems/mruby-eval/test/binding.rb \ mruby/mrbgems/mruby-eval/test/eval.rb \ mruby/mrbgems/mruby-eval/src/eval.c \ mruby/mrbgems/stdlib.gembox \ @@ -244,7 +250,6 @@ EXTRA_DIST += \ mruby/mrbgems/mruby-method/mrbgem.rake \ mruby/mrbgems/mruby-method/README.md \ mruby/mrbgems/mruby-method/test/method.rb \ - mruby/mrbgems/mruby-method/mrblib/kernel.rb \ mruby/mrbgems/mruby-method/mrblib/method.rb \ mruby/mrbgems/mruby-method/src/method.c \ mruby/mrbgems/mruby-random/mrbgem.rake \ @@ -368,7 +373,6 @@ EXTRA_DIST += \ mruby/mrbgems/mruby-test-inline-struct/test/inline.rb \ mruby/mrbgems/mruby-time/mrbgem.rake \ mruby/mrbgems/mruby-time/test/time.rb \ - mruby/mrbgems/mruby-time/mrblib/time.rb \ mruby/mrbgems/mruby-time/src/time.c \ mruby/mrbgems/mruby-time/include/mruby/time.h \ mruby/mrbgems/mruby-proc-binding/mrbgem.rake \ @@ -408,10 +412,9 @@ EXTRA_DIST += \ mruby/mrbgems/mruby-numeric-ext/test/numeric.rb \ mruby/mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb \ mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c \ - mruby/mrbgems/mruby-binding-core/mrbgem.rake \ - mruby/mrbgems/mruby-binding-core/test/binding-core.rb \ - mruby/mrbgems/mruby-binding-core/src/binding-core.c \ mruby/mrbgems/mruby-fiber/mrbgem.rake \ + mruby/mrbgems/mruby-fiber/test/fiber2.rb \ + mruby/mrbgems/mruby-fiber/test/fibertest.c \ mruby/mrbgems/mruby-fiber/test/fiber.rb \ mruby/mrbgems/mruby-fiber/src/fiber.c \ mruby/mrbgems/mruby-complex/mrbgem.rake \ @@ -496,7 +499,9 @@ EXTRA_DIST += \ mruby/doc/internal/boxing.md \ mruby/doc/limitations.md \ mruby/doc/mruby3.2.md \ + mruby/doc/mruby3.3.md \ mruby/doc/guides/compile.md \ + mruby/doc/guides/memory.md \ mruby/doc/guides/mrbgems.md \ mruby/doc/guides/debugger.md \ mruby/doc/guides/link.md \ @@ -558,7 +563,7 @@ libllhttp_la_CPPFLAGS = -I${srcdir}/llhttp/include if HAVE_NEVERBLEED noinst_LTLIBRARIES += libneverbleed.la -libneverbleed_la_CPPFLAGS = @OPENSSL_CFLAGS@ +libneverbleed_la_CPPFLAGS = @OPENSSL_CFLAGS@ -D_GNU_SOURCE libneverbleed_la_LIBADD = @OPENSSL_LIBS@ libneverbleed_la_SOURCES = neverbleed/neverbleed.c neverbleed/neverbleed.h endif # HAVE_NEVERBLEED diff --git a/yass/third_party/nghttp2/third-party/build_config.rb b/yass/third_party/nghttp2/third-party/build_config.rb index e06a4ccca4..5d003f21fa 100644 --- a/yass/third_party/nghttp2/third-party/build_config.rb +++ b/yass/third_party/nghttp2/third-party/build_config.rb @@ -18,8 +18,30 @@ def config(conf) conf.build_dir = ENV['BUILD_DIR'] - # include the default GEMs - conf.gembox 'default' + # Here is the mruby gems included in default.gembox minus + # mruby-bin-debugger which causes the application to crash. + conf.gembox "stdlib" + conf.gembox "stdlib-ext" + conf.gembox "stdlib-io" + conf.gembox "math" + conf.gembox "metaprog" + + # Generate mrbc command + conf.gem :core => "mruby-bin-mrbc" + + # Generate mirb command + conf.gem :core => "mruby-bin-mirb" + + # Generate mruby command + conf.gem :core => "mruby-bin-mruby" + + # Generate mruby-strip command + conf.gem :core => "mruby-bin-strip" + + # Generate mruby-config command + conf.gem :core => "mruby-bin-config" + + # Added by nghttp2 project conf.gem :core => 'mruby-eval' end diff --git a/yass/third_party/nghttp2/third-party/llhttp/README.md b/yass/third_party/nghttp2/third-party/llhttp/README.md index e982ed0ae7..28653aa035 100644 --- a/yass/third_party/nghttp2/third-party/llhttp/README.md +++ b/yass/third_party/nghttp2/third-party/llhttp/README.md @@ -363,6 +363,16 @@ With this flag only a CR is required to terminate such sections. **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!** +### `void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled)` + +Enables/disables lenient handling of line separators. + +Normally `llhttp` would error when a LF is not preceded by CR when terminating the +request line, the status line, the headers, a chunk header or a chunk data. +With this flag only a LF is required to terminate such sections. + +**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!** + ### `void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled)` Enables/disables lenient handling of chunks not separated via CRLF. @@ -373,12 +383,21 @@ With this flag the new chunk can start immediately after the previous one. **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!** +### `void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled)` + +Enables/disables lenient handling of spaces after chunk size. + +Normally `llhttp` would error when after a chunk size is followed by one or more spaces are present instead of a CRLF or `;`. +With this flag this check is disabled. + +**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!** + ## Build Instructions Make sure you have [Node.js](https://nodejs.org/), npm and npx installed. Then under project directory run: ```sh -npm install +npm ci make ``` @@ -432,7 +451,7 @@ _Note that using the git repo directly (e.g., via a git repo url and tag) will n 1. Ensure that `Clang` and `make` are in your system path. 2. Using Git Bash, clone the repo to your preferred location. -3. Cd into the cloned directory and run `npm install` +3. Cd into the cloned directory and run `npm ci` 5. Run `make` 6. Your `repo/build` directory should now have `libllhttp.a` and `libllhttp.so` static and dynamic libraries. 7. When building your executable, you can link to these libraries. Make sure to set the build folder as an include path when building so you can reference the declarations in `repo/build/llhttp.h`. diff --git a/yass/third_party/nghttp2/third-party/llhttp/include/llhttp.h b/yass/third_party/nghttp2/third-party/llhttp/include/llhttp.h index 6588ae5e36..691969367a 100644 --- a/yass/third_party/nghttp2/third-party/llhttp/include/llhttp.h +++ b/yass/third_party/nghttp2/third-party/llhttp/include/llhttp.h @@ -3,8 +3,8 @@ #define INCLUDE_LLHTTP_H_ #define LLHTTP_VERSION_MAJOR 9 -#define LLHTTP_VERSION_MINOR 0 -#define LLHTTP_VERSION_PATCH 1 +#define LLHTTP_VERSION_MINOR 2 +#define LLHTTP_VERSION_PATCH 0 #ifndef INCLUDE_LLHTTP_ITSELF_H_ #define INCLUDE_LLHTTP_ITSELF_H_ @@ -30,7 +30,7 @@ struct llhttp__internal_s { uint8_t http_major; uint8_t http_minor; uint8_t header_state; - uint8_t lenient_flags; + uint16_t lenient_flags; uint8_t upgrade; uint8_t finish; uint16_t flags; @@ -115,7 +115,9 @@ enum llhttp_lenient_flags { LENIENT_VERSION = 0x10, LENIENT_DATA_AFTER_CLOSE = 0x20, LENIENT_OPTIONAL_LF_AFTER_CR = 0x40, - LENIENT_OPTIONAL_CRLF_AFTER_CHUNK = 0x80 + LENIENT_OPTIONAL_CRLF_AFTER_CHUNK = 0x80, + LENIENT_OPTIONAL_CR_BEFORE_LF = 0x100, + LENIENT_SPACES_AFTER_CHUNK_SIZE = 0x200 }; typedef enum llhttp_lenient_flags llhttp_lenient_flags_t; @@ -179,7 +181,8 @@ enum llhttp_method { HTTP_SET_PARAMETER = 42, HTTP_REDIRECT = 43, HTTP_RECORD = 44, - HTTP_FLUSH = 45 + HTTP_FLUSH = 45, + HTTP_QUERY = 46 }; typedef enum llhttp_method llhttp_method_t; @@ -360,6 +363,7 @@ typedef enum llhttp_status llhttp_status_t; XX(31, LINK, LINK) \ XX(32, UNLINK, UNLINK) \ XX(33, SOURCE, SOURCE) \ + XX(46, QUERY, QUERY) \ #define RTSP_METHOD_MAP(XX) \ @@ -426,6 +430,7 @@ typedef enum llhttp_status llhttp_status_t; XX(43, REDIRECT, REDIRECT) \ XX(44, RECORD, RECORD) \ XX(45, FLUSH, FLUSH) \ + XX(46, QUERY, QUERY) \ #define HTTP_STATUS_MAP(XX) \ @@ -545,6 +550,8 @@ extern "C" { #if defined(__wasm__) #define LLHTTP_EXPORT __attribute__((visibility("default"))) +#elif defined(_WIN32) +#define LLHTTP_EXPORT __declspec(dllexport) #else #define LLHTTP_EXPORT #endif @@ -807,7 +814,7 @@ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled); * avoid request smuggling. * With this flag the extra value will be parsed normally. * - * **Enabling this flag can pose a security issue since you will be exposed to + * **Enabling this flag can pose a security issue since you will be exposed to * request smuggling attacks. USE WITH CAUTION!** */ LLHTTP_EXPORT @@ -850,6 +857,19 @@ void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled); LLHTTP_EXPORT void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled); +/* + * Enables/disables lenient handling of line separators. + * + * Normally `llhttp` would error when a LF is not preceded by CR when terminating the + * request line, the status line, the headers, a chunk header or a chunk data. + * With this flag only a LF is required to terminate such sections. + * + * **Enabling this flag can pose a security issue since you will be exposed to + * request smuggling attacks. USE WITH CAUTION!** + */ +LLHTTP_EXPORT +void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled); + /* Enables/disables lenient handling of chunks not separated via CRLF. * * Normally `llhttp` would error when after a chunk data a CRLF is missing before @@ -862,6 +882,18 @@ void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled); LLHTTP_EXPORT void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled); +/* Enables/disables lenient handling of spaces after chunk size. + * + * Normally `llhttp` would error when after a chunk size is followed by one or more + * spaces are present instead of a CRLF or `;`. + * With this flag this check is disabled. + * + * **Enabling this flag can pose a security issue since you will be exposed to + * request smuggling attacks. USE WITH CAUTION!** + */ +LLHTTP_EXPORT +void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/yass/third_party/nghttp2/third-party/llhttp/src/api.c b/yass/third_party/nghttp2/third-party/llhttp/src/api.c index e0d0385051..8c2ce3dc5c 100644 --- a/yass/third_party/nghttp2/third-party/llhttp/src/api.c +++ b/yass/third_party/nghttp2/third-party/llhttp/src/api.c @@ -126,7 +126,7 @@ void llhttp_reset(llhttp_t* parser) { llhttp_type_t type = parser->type; const llhttp_settings_t* settings = parser->settings; void* data = parser->data; - uint8_t lenient_flags = parser->lenient_flags; + uint16_t lenient_flags = parser->lenient_flags; llhttp__internal_init(parser); @@ -315,6 +315,22 @@ void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled) } } +void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled) { + if (enabled) { + parser->lenient_flags |= LENIENT_OPTIONAL_CR_BEFORE_LF; + } else { + parser->lenient_flags &= ~LENIENT_OPTIONAL_CR_BEFORE_LF; + } +} + +void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled) { + if (enabled) { + parser->lenient_flags |= LENIENT_SPACES_AFTER_CHUNK_SIZE; + } else { + parser->lenient_flags &= ~LENIENT_SPACES_AFTER_CHUNK_SIZE; + } +} + /* Callbacks */ diff --git a/yass/third_party/nghttp2/third-party/llhttp/src/http.c b/yass/third_party/nghttp2/third-party/llhttp/src/http.c index 3a66044f5f..1ab91a5579 100644 --- a/yass/third_party/nghttp2/third-party/llhttp/src/http.c +++ b/yass/third_party/nghttp2/third-party/llhttp/src/http.c @@ -39,13 +39,33 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p, int hasBody; hasBody = parser->flags & F_CHUNKED || parser->content_length > 0; - if (parser->upgrade && (parser->method == HTTP_CONNECT || - (parser->flags & F_SKIPBODY) || !hasBody)) { + if ( + (parser->upgrade && (parser->method == HTTP_CONNECT || + (parser->flags & F_SKIPBODY) || !hasBody)) || + /* See RFC 2616 section 4.4 - 1xx e.g. Continue */ + (parser->type == HTTP_RESPONSE && parser->status_code == 101) + ) { /* Exit, the rest of the message is in a different protocol. */ return 1; } - if (parser->flags & F_SKIPBODY) { + if (parser->type == HTTP_RESPONSE && parser->status_code == 100) { + /* No body, restart as the message is complete */ + return 0; + } + + /* See RFC 2616 section 4.4 */ + if ( + parser->flags & F_SKIPBODY || /* response to a HEAD request */ + ( + parser->type == HTTP_RESPONSE && ( + parser->status_code == 102 || /* Processing */ + parser->status_code == 103 || /* Early Hints */ + parser->status_code == 204 || /* No Content */ + parser->status_code == 304 /* Not Modified */ + ) + ) + ) { return 0; } else if (parser->flags & F_CHUNKED) { /* chunked encoding - ignore Content-Length header, prepare for a chunk */ diff --git a/yass/third_party/nghttp2/third-party/llhttp/src/llhttp.c b/yass/third_party/nghttp2/third-party/llhttp/src/llhttp.c index 03f6d57c8c..c08de6494f 100644 --- a/yass/third_party/nghttp2/third-party/llhttp/src/llhttp.c +++ b/yass/third_party/nghttp2/third-party/llhttp/src/llhttp.c @@ -22,148 +22,148 @@ typedef int (*llhttp__internal__span_cb)( llhttp__internal_t*, const char*, const char*); static const unsigned char llparse_blob0[] = { - 0xd, 0xa -}; -static const unsigned char llparse_blob1[] = { 'o', 'n' }; -static const unsigned char llparse_blob2[] = { +static const unsigned char llparse_blob1[] = { 'e', 'c', 't', 'i', 'o', 'n' }; -static const unsigned char llparse_blob3[] = { +static const unsigned char llparse_blob2[] = { 'l', 'o', 's', 'e' }; -static const unsigned char llparse_blob4[] = { +static const unsigned char llparse_blob3[] = { 'e', 'e', 'p', '-', 'a', 'l', 'i', 'v', 'e' }; -static const unsigned char llparse_blob5[] = { +static const unsigned char llparse_blob4[] = { 'p', 'g', 'r', 'a', 'd', 'e' }; -static const unsigned char llparse_blob6[] = { +static const unsigned char llparse_blob5[] = { 'c', 'h', 'u', 'n', 'k', 'e', 'd' }; #ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob7[] = { +static const unsigned char ALIGN(16) llparse_blob6[] = { 0x9, 0x9, ' ', '~', 0x80, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; #endif /* __SSE4_2__ */ #ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob8[] = { +static const unsigned char ALIGN(16) llparse_blob7[] = { '!', '!', '#', '\'', '*', '+', '-', '.', '0', '9', 'A', 'Z', '^', 'z', '|', '|' }; #endif /* __SSE4_2__ */ #ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob9[] = { +static const unsigned char ALIGN(16) llparse_blob8[] = { '~', '~', 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; #endif /* __SSE4_2__ */ -static const unsigned char llparse_blob10[] = { +static const unsigned char llparse_blob9[] = { 'e', 'n', 't', '-', 'l', 'e', 'n', 'g', 't', 'h' }; -static const unsigned char llparse_blob11[] = { +static const unsigned char llparse_blob10[] = { 'r', 'o', 'x', 'y', '-', 'c', 'o', 'n', 'n', 'e', 'c', 't', 'i', 'o', 'n' }; -static const unsigned char llparse_blob12[] = { +static const unsigned char llparse_blob11[] = { 'r', 'a', 'n', 's', 'f', 'e', 'r', '-', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g' }; -static const unsigned char llparse_blob13[] = { +static const unsigned char llparse_blob12[] = { 'p', 'g', 'r', 'a', 'd', 'e' }; -static const unsigned char llparse_blob14[] = { +static const unsigned char llparse_blob13[] = { 'T', 'T', 'P', '/' }; -static const unsigned char llparse_blob15[] = { +static const unsigned char llparse_blob14[] = { 0xd, 0xa, 0xd, 0xa, 'S', 'M', 0xd, 0xa, 0xd, 0xa }; -static const unsigned char llparse_blob16[] = { +static const unsigned char llparse_blob15[] = { 'C', 'E', '/' }; -static const unsigned char llparse_blob17[] = { +static const unsigned char llparse_blob16[] = { 'T', 'S', 'P', '/' }; -static const unsigned char llparse_blob18[] = { +static const unsigned char llparse_blob17[] = { 'N', 'O', 'U', 'N', 'C', 'E' }; -static const unsigned char llparse_blob19[] = { +static const unsigned char llparse_blob18[] = { 'I', 'N', 'D' }; -static const unsigned char llparse_blob20[] = { +static const unsigned char llparse_blob19[] = { 'E', 'C', 'K', 'O', 'U', 'T' }; -static const unsigned char llparse_blob21[] = { +static const unsigned char llparse_blob20[] = { 'N', 'E', 'C', 'T' }; -static const unsigned char llparse_blob22[] = { +static const unsigned char llparse_blob21[] = { 'E', 'T', 'E' }; -static const unsigned char llparse_blob23[] = { +static const unsigned char llparse_blob22[] = { 'C', 'R', 'I', 'B', 'E' }; -static const unsigned char llparse_blob24[] = { +static const unsigned char llparse_blob23[] = { 'L', 'U', 'S', 'H' }; -static const unsigned char llparse_blob25[] = { +static const unsigned char llparse_blob24[] = { 'E', 'T' }; -static const unsigned char llparse_blob26[] = { +static const unsigned char llparse_blob25[] = { 'P', 'A', 'R', 'A', 'M', 'E', 'T', 'E', 'R' }; -static const unsigned char llparse_blob27[] = { +static const unsigned char llparse_blob26[] = { 'E', 'A', 'D' }; -static const unsigned char llparse_blob28[] = { +static const unsigned char llparse_blob27[] = { 'N', 'K' }; -static const unsigned char llparse_blob29[] = { +static const unsigned char llparse_blob28[] = { 'C', 'K' }; -static const unsigned char llparse_blob30[] = { +static const unsigned char llparse_blob29[] = { 'S', 'E', 'A', 'R', 'C', 'H' }; -static const unsigned char llparse_blob31[] = { +static const unsigned char llparse_blob30[] = { 'R', 'G', 'E' }; -static const unsigned char llparse_blob32[] = { +static const unsigned char llparse_blob31[] = { 'C', 'T', 'I', 'V', 'I', 'T', 'Y' }; -static const unsigned char llparse_blob33[] = { +static const unsigned char llparse_blob32[] = { 'L', 'E', 'N', 'D', 'A', 'R' }; -static const unsigned char llparse_blob34[] = { +static const unsigned char llparse_blob33[] = { 'V', 'E' }; -static const unsigned char llparse_blob35[] = { +static const unsigned char llparse_blob34[] = { 'O', 'T', 'I', 'F', 'Y' }; -static const unsigned char llparse_blob36[] = { +static const unsigned char llparse_blob35[] = { 'P', 'T', 'I', 'O', 'N', 'S' }; -static const unsigned char llparse_blob37[] = { +static const unsigned char llparse_blob36[] = { 'C', 'H' }; -static const unsigned char llparse_blob38[] = { +static const unsigned char llparse_blob37[] = { 'S', 'E' }; -static const unsigned char llparse_blob39[] = { +static const unsigned char llparse_blob38[] = { 'A', 'Y' }; -static const unsigned char llparse_blob40[] = { +static const unsigned char llparse_blob39[] = { 'S', 'T' }; -static const unsigned char llparse_blob41[] = { +static const unsigned char llparse_blob40[] = { 'I', 'N', 'D' }; -static const unsigned char llparse_blob42[] = { +static const unsigned char llparse_blob41[] = { 'A', 'T', 'C', 'H' }; -static const unsigned char llparse_blob43[] = { +static const unsigned char llparse_blob42[] = { 'G', 'E' }; +static const unsigned char llparse_blob43[] = { + 'U', 'E', 'R', 'Y' +}; static const unsigned char llparse_blob44[] = { 'I', 'N', 'D' }; @@ -229,38 +229,6 @@ struct llparse_match_s { }; typedef struct llparse_match_s llparse_match_t; -static llparse_match_t llparse__match_sequence_id( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp, - const unsigned char* seq, uint32_t seq_len) { - uint32_t index; - llparse_match_t res; - - index = s->_index; - for (; p != endp; p++) { - unsigned char current; - - current = *p; - if (current == seq[index]) { - if (++index == seq_len) { - res.status = kMatchComplete; - goto reset; - } - } else { - res.status = kMatchMismatch; - goto reset; - } - } - s->_index = index; - res.status = kMatchPause; - res.current = p; - return res; -reset: - s->_index = 0; - res.current = p; - return res; -} - static llparse_match_t llparse__match_sequence_to_lower( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp, @@ -325,28 +293,69 @@ reset: return res; } +static llparse_match_t llparse__match_sequence_id( + llhttp__internal_t* s, const unsigned char* p, + const unsigned char* endp, + const unsigned char* seq, uint32_t seq_len) { + uint32_t index; + llparse_match_t res; + + index = s->_index; + for (; p != endp; p++) { + unsigned char current; + + current = *p; + if (current == seq[index]) { + if (++index == seq_len) { + res.status = kMatchComplete; + goto reset; + } + } else { + res.status = kMatchMismatch; + goto reset; + } + } + s->_index = index; + res.status = kMatchPause; + res.current = p; + return res; +reset: + s->_index = 0; + res.current = p; + return res; +} + enum llparse_state_e { s_error, s_n_llhttp__internal__n_closed, s_n_llhttp__internal__n_invoke_llhttp__after_message_complete, s_n_llhttp__internal__n_pause_1, + s_n_llhttp__internal__n_invoke_is_equal_upgrade, + s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2, + s_n_llhttp__internal__n_chunk_data_almost_done_1, s_n_llhttp__internal__n_chunk_data_almost_done, s_n_llhttp__internal__n_consume_content_length, s_n_llhttp__internal__n_span_start_llhttp__on_body, s_n_llhttp__internal__n_invoke_is_equal_content_length, s_n_llhttp__internal__n_chunk_size_almost_done, + s_n_llhttp__internal__n_invoke_test_lenient_flags_9, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1, + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2, + s_n_llhttp__internal__n_invoke_test_lenient_flags_10, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete, - s_n_llhttp__internal__n_chunk_extension_quoted_value_done, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1, - s_n_llhttp__internal__n_error_21, - s_n_llhttp__internal__n_chunk_extension_quoted_value, + s_n_llhttp__internal__n_chunk_extension_quoted_value_done, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2, - s_n_llhttp__internal__n_error_23, + s_n_llhttp__internal__n_error_30, + s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair, + s_n_llhttp__internal__n_error_31, + s_n_llhttp__internal__n_chunk_extension_quoted_value, + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3, + s_n_llhttp__internal__n_error_33, s_n_llhttp__internal__n_chunk_extension_value, s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_value, - s_n_llhttp__internal__n_error_24, + s_n_llhttp__internal__n_error_34, s_n_llhttp__internal__n_chunk_extension_name, s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name, s_n_llhttp__internal__n_chunk_extensions, @@ -354,8 +363,6 @@ enum llparse_state_e { s_n_llhttp__internal__n_chunk_size, s_n_llhttp__internal__n_chunk_size_digit, s_n_llhttp__internal__n_invoke_update_content_length_1, - s_n_llhttp__internal__n_invoke_is_equal_upgrade, - s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2, s_n_llhttp__internal__n_consume_content_length_1, s_n_llhttp__internal__n_span_start_llhttp__on_body_1, s_n_llhttp__internal__n_eof, @@ -370,8 +377,9 @@ enum llparse_state_e { s_n_llhttp__internal__n_header_value_discard_ws_almost_done, s_n_llhttp__internal__n_header_value_lws, s_n_llhttp__internal__n_header_value_almost_done, + s_n_llhttp__internal__n_invoke_test_lenient_flags_17, s_n_llhttp__internal__n_header_value_lenient, - s_n_llhttp__internal__n_error_41, + s_n_llhttp__internal__n_error_53, s_n_llhttp__internal__n_header_value_otherwise, s_n_llhttp__internal__n_header_value_connection_token, s_n_llhttp__internal__n_header_value_connection_ws, @@ -379,12 +387,12 @@ enum llparse_state_e { s_n_llhttp__internal__n_header_value_connection_2, s_n_llhttp__internal__n_header_value_connection_3, s_n_llhttp__internal__n_header_value_connection, - s_n_llhttp__internal__n_error_43, - s_n_llhttp__internal__n_error_44, + s_n_llhttp__internal__n_error_55, + s_n_llhttp__internal__n_error_56, s_n_llhttp__internal__n_header_value_content_length_ws, s_n_llhttp__internal__n_header_value_content_length, - s_n_llhttp__internal__n_error_46, - s_n_llhttp__internal__n_error_45, + s_n_llhttp__internal__n_error_58, + s_n_llhttp__internal__n_error_57, s_n_llhttp__internal__n_header_value_te_token_ows, s_n_llhttp__internal__n_header_value, s_n_llhttp__internal__n_header_value_te_token, @@ -392,6 +400,7 @@ enum llparse_state_e { s_n_llhttp__internal__n_header_value_te_chunked, s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1, s_n_llhttp__internal__n_header_value_discard_ws, + s_n_llhttp__internal__n_invoke_load_header_state, s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete, s_n_llhttp__internal__n_header_field_general_otherwise, s_n_llhttp__internal__n_header_field_general, @@ -416,12 +425,12 @@ enum llparse_state_e { s_n_llhttp__internal__n_req_http_complete, s_n_llhttp__internal__n_invoke_load_method_1, s_n_llhttp__internal__n_invoke_llhttp__on_version_complete, - s_n_llhttp__internal__n_error_51, - s_n_llhttp__internal__n_error_57, + s_n_llhttp__internal__n_error_65, + s_n_llhttp__internal__n_error_72, s_n_llhttp__internal__n_req_http_minor, - s_n_llhttp__internal__n_error_58, + s_n_llhttp__internal__n_error_73, s_n_llhttp__internal__n_req_http_dot, - s_n_llhttp__internal__n_error_59, + s_n_llhttp__internal__n_error_74, s_n_llhttp__internal__n_req_http_major, s_n_llhttp__internal__n_span_start_llhttp__on_version, s_n_llhttp__internal__n_req_http_start_1, @@ -497,48 +506,49 @@ enum llparse_state_e { s_n_llhttp__internal__n_after_start_req_45, s_n_llhttp__internal__n_after_start_req_44, s_n_llhttp__internal__n_after_start_req_33, - s_n_llhttp__internal__n_after_start_req_48, + s_n_llhttp__internal__n_after_start_req_46, s_n_llhttp__internal__n_after_start_req_49, s_n_llhttp__internal__n_after_start_req_50, s_n_llhttp__internal__n_after_start_req_51, - s_n_llhttp__internal__n_after_start_req_47, - s_n_llhttp__internal__n_after_start_req_46, - s_n_llhttp__internal__n_after_start_req_54, - s_n_llhttp__internal__n_after_start_req_56, - s_n_llhttp__internal__n_after_start_req_57, - s_n_llhttp__internal__n_after_start_req_55, - s_n_llhttp__internal__n_after_start_req_53, - s_n_llhttp__internal__n_after_start_req_58, - s_n_llhttp__internal__n_after_start_req_59, s_n_llhttp__internal__n_after_start_req_52, - s_n_llhttp__internal__n_after_start_req_61, - s_n_llhttp__internal__n_after_start_req_62, + s_n_llhttp__internal__n_after_start_req_48, + s_n_llhttp__internal__n_after_start_req_47, + s_n_llhttp__internal__n_after_start_req_55, + s_n_llhttp__internal__n_after_start_req_57, + s_n_llhttp__internal__n_after_start_req_58, + s_n_llhttp__internal__n_after_start_req_56, + s_n_llhttp__internal__n_after_start_req_54, + s_n_llhttp__internal__n_after_start_req_59, s_n_llhttp__internal__n_after_start_req_60, - s_n_llhttp__internal__n_after_start_req_65, - s_n_llhttp__internal__n_after_start_req_67, - s_n_llhttp__internal__n_after_start_req_68, - s_n_llhttp__internal__n_after_start_req_66, - s_n_llhttp__internal__n_after_start_req_69, - s_n_llhttp__internal__n_after_start_req_64, + s_n_llhttp__internal__n_after_start_req_53, + s_n_llhttp__internal__n_after_start_req_62, s_n_llhttp__internal__n_after_start_req_63, + s_n_llhttp__internal__n_after_start_req_61, + s_n_llhttp__internal__n_after_start_req_66, + s_n_llhttp__internal__n_after_start_req_68, + s_n_llhttp__internal__n_after_start_req_69, + s_n_llhttp__internal__n_after_start_req_67, + s_n_llhttp__internal__n_after_start_req_70, + s_n_llhttp__internal__n_after_start_req_65, + s_n_llhttp__internal__n_after_start_req_64, s_n_llhttp__internal__n_after_start_req, s_n_llhttp__internal__n_span_start_llhttp__on_method_1, s_n_llhttp__internal__n_res_line_almost_done, + s_n_llhttp__internal__n_invoke_test_lenient_flags_29, s_n_llhttp__internal__n_res_status, s_n_llhttp__internal__n_span_start_llhttp__on_status, - s_n_llhttp__internal__n_res_status_start, s_n_llhttp__internal__n_res_status_code_otherwise, s_n_llhttp__internal__n_res_status_code_digit_3, s_n_llhttp__internal__n_res_status_code_digit_2, s_n_llhttp__internal__n_res_status_code_digit_1, s_n_llhttp__internal__n_res_after_version, s_n_llhttp__internal__n_invoke_llhttp__on_version_complete_1, - s_n_llhttp__internal__n_error_73, - s_n_llhttp__internal__n_error_85, + s_n_llhttp__internal__n_error_88, + s_n_llhttp__internal__n_error_102, s_n_llhttp__internal__n_res_http_minor, - s_n_llhttp__internal__n_error_86, + s_n_llhttp__internal__n_error_103, s_n_llhttp__internal__n_res_http_dot, - s_n_llhttp__internal__n_error_87, + s_n_llhttp__internal__n_error_104, s_n_llhttp__internal__n_res_http_major, s_n_llhttp__internal__n_span_start_llhttp__on_version_1, s_n_llhttp__internal__n_start_res, @@ -669,7 +679,21 @@ int llhttp__internal__c_test_lenient_flags( return (state->lenient_flags & 1) == 1; } -int llhttp__after_headers_complete( +int llhttp__internal__c_test_lenient_flags_1( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->lenient_flags & 256) == 256; +} + +int llhttp__internal__c_test_flags( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->flags & 128) == 128; +} + +int llhttp__on_chunk_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); @@ -677,6 +701,13 @@ int llhttp__on_message_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); +int llhttp__internal__c_is_equal_upgrade( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return state->upgrade == 1; +} + int llhttp__after_message_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); @@ -719,6 +750,18 @@ int llhttp__internal__c_test_lenient_flags_3( return (state->lenient_flags & 32) == 32; } +int llhttp__before_headers_complete( + llhttp__internal_t* s, const unsigned char* p, + const unsigned char* endp); + +int llhttp__on_headers_complete( + llhttp__internal_t* s, const unsigned char* p, + const unsigned char* endp); + +int llhttp__after_headers_complete( + llhttp__internal_t* s, const unsigned char* p, + const unsigned char* endp); + int llhttp__internal__c_mul_add_content_length( llhttp__internal_t* state, const unsigned char* p, @@ -745,6 +788,13 @@ int llhttp__internal__c_mul_add_content_length( return 0; } +int llhttp__internal__c_test_lenient_flags_4( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->lenient_flags & 512) == 512; +} + int llhttp__on_chunk_header( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); @@ -756,11 +806,7 @@ int llhttp__internal__c_is_equal_content_length( return state->content_length == 0; } -int llhttp__on_chunk_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_test_lenient_flags_4( +int llhttp__internal__c_test_lenient_flags_7( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -775,7 +821,7 @@ int llhttp__internal__c_or_flags( return 0; } -int llhttp__internal__c_test_lenient_flags_5( +int llhttp__internal__c_test_lenient_flags_8( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -790,13 +836,6 @@ int llhttp__on_chunk_extension_value_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); -int llhttp__internal__c_is_equal_upgrade( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->upgrade == 1; -} - int llhttp__internal__c_update_finish_3( llhttp__internal_t* state, const unsigned char* p, @@ -805,35 +844,6 @@ int llhttp__internal__c_update_finish_3( return 0; } -int llhttp__internal__c_test_flags( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->flags & 128) == 128; -} - -int llhttp__internal__c_test_flags_1( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->flags & 544) == 544; -} - -int llhttp__internal__c_test_lenient_flags_6( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 2) == 2; -} - -int llhttp__before_headers_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_headers_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - int llhttp__internal__c_or_flags_1( llhttp__internal_t* state, const unsigned char* p, @@ -870,7 +880,21 @@ int llhttp__internal__c_load_header_state( return state->header_state; } -int llhttp__internal__c_or_flags_3( +int llhttp__internal__c_test_flags_4( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->flags & 512) == 512; +} + +int llhttp__internal__c_test_lenient_flags_21( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->lenient_flags & 2) == 2; +} + +int llhttp__internal__c_or_flags_5( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -890,7 +914,7 @@ int llhttp__on_header_value_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); -int llhttp__internal__c_or_flags_4( +int llhttp__internal__c_or_flags_6( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -898,7 +922,7 @@ int llhttp__internal__c_or_flags_4( return 0; } -int llhttp__internal__c_or_flags_5( +int llhttp__internal__c_or_flags_7( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -906,7 +930,7 @@ int llhttp__internal__c_or_flags_5( return 0; } -int llhttp__internal__c_or_flags_6( +int llhttp__internal__c_or_flags_8( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -979,7 +1003,7 @@ int llhttp__internal__c_mul_add_content_length_1( return 0; } -int llhttp__internal__c_or_flags_15( +int llhttp__internal__c_or_flags_17( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -994,14 +1018,14 @@ int llhttp__internal__c_test_flags_3( return (state->flags & 8) == 8; } -int llhttp__internal__c_test_lenient_flags_13( +int llhttp__internal__c_test_lenient_flags_19( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { return (state->lenient_flags & 8) == 8; } -int llhttp__internal__c_or_flags_16( +int llhttp__internal__c_or_flags_18( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -1025,7 +1049,7 @@ int llhttp__internal__c_update_header_state_8( return 0; } -int llhttp__internal__c_or_flags_18( +int llhttp__internal__c_or_flags_20( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -1058,7 +1082,7 @@ int llhttp__internal__c_store_http_minor( return 0; } -int llhttp__internal__c_test_lenient_flags_15( +int llhttp__internal__c_test_lenient_flags_23( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -1192,25 +1216,63 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_chunk_data_almost_done: - s_n_llhttp__internal__n_chunk_data_almost_done: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_chunk_data_almost_done; + case s_n_llhttp__internal__n_invoke_is_equal_upgrade: + s_n_llhttp__internal__n_invoke_is_equal_upgrade: { + switch (llhttp__internal__c_is_equal_upgrade(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_llhttp__after_message_complete; + default: + goto s_n_llhttp__internal__n_pause_1; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob0, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: + s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: { + switch (llhttp__on_message_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_is_equal_upgrade; + case 21: + goto s_n_llhttp__internal__n_pause_13; + default: + goto s_n_llhttp__internal__n_error_38; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_chunk_data_almost_done_1: + s_n_llhttp__internal__n_chunk_data_almost_done_1: { + if (p == endp) { + return s_n_llhttp__internal__n_chunk_data_almost_done_1; + } + switch (*p) { + case 10: { p++; goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; } - case kMatchPause: { - return s_n_llhttp__internal__n_chunk_data_almost_done; + default: { + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_7; } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_4; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_chunk_data_almost_done: + s_n_llhttp__internal__n_chunk_data_almost_done: { + if (p == endp) { + return s_n_llhttp__internal__n_chunk_data_almost_done; + } + switch (*p) { + case 10: { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_6; + } + case 13: { + p++; + goto s_n_llhttp__internal__n_chunk_data_almost_done_1; + } + default: { + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_7; } } /* UNREACHABLE */; @@ -1267,21 +1329,32 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_header; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_5; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_8; } } /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_test_lenient_flags_9: + s_n_llhttp__internal__n_invoke_test_lenient_flags_9: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_almost_done; + default: + goto s_n_llhttp__internal__n_error_20; + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete: s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete: { switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_chunk_size_almost_done; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_9; case 21: goto s_n_llhttp__internal__n_pause_5; default: - goto s_n_llhttp__internal__n_error_15; + goto s_n_llhttp__internal__n_error_19; } /* UNREACHABLE */; abort(); @@ -1290,24 +1363,61 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1: { switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_chunk_extensions; + goto s_n_llhttp__internal__n_chunk_size_almost_done; case 21: goto s_n_llhttp__internal__n_pause_6; default: - goto s_n_llhttp__internal__n_error_16; + goto s_n_llhttp__internal__n_error_21; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2: + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2: { + switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_chunk_extensions; + case 21: + goto s_n_llhttp__internal__n_pause_7; + default: + goto s_n_llhttp__internal__n_error_22; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_invoke_test_lenient_flags_10: + s_n_llhttp__internal__n_invoke_test_lenient_flags_10: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_almost_done; + default: + goto s_n_llhttp__internal__n_error_25; } /* UNREACHABLE */; abort(); } case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete: s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete: { + switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_10; + case 21: + goto s_n_llhttp__internal__n_pause_8; + default: + goto s_n_llhttp__internal__n_error_24; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: { switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { case 0: goto s_n_llhttp__internal__n_chunk_size_almost_done; case 21: - goto s_n_llhttp__internal__n_pause_7; + goto s_n_llhttp__internal__n_pause_9; default: - goto s_n_llhttp__internal__n_error_18; + goto s_n_llhttp__internal__n_error_26; } /* UNREACHABLE */; abort(); @@ -1318,6 +1428,9 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_chunk_extension_quoted_value_done; } switch (*p) { + case 10: { + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_11; + } case 13: { p++; goto s_n_llhttp__internal__n_chunk_size_almost_done; @@ -1327,27 +1440,72 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_chunk_extensions; } default: { - goto s_n_llhttp__internal__n_error_20; + goto s_n_llhttp__internal__n_error_29; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: { + case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: { switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { case 0: goto s_n_llhttp__internal__n_chunk_extension_quoted_value_done; case 21: - goto s_n_llhttp__internal__n_pause_8; + goto s_n_llhttp__internal__n_pause_10; default: - goto s_n_llhttp__internal__n_error_19; + goto s_n_llhttp__internal__n_error_27; } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_21: - s_n_llhttp__internal__n_error_21: { + case s_n_llhttp__internal__n_error_30: + s_n_llhttp__internal__n_error_30: { + state->error = 0x2; + state->reason = "Invalid quoted-pair in chunk extensions quoted value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair: + s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair: { + static uint8_t lookup_table[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + }; + if (p == endp) { + return s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair; + } + switch (lookup_table[(uint8_t) *p]) { + case 1: { + p++; + goto s_n_llhttp__internal__n_chunk_extension_quoted_value; + } + default: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_3; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_error_31: + s_n_llhttp__internal__n_error_31: { state->error = 0x2; state->reason = "Invalid character in chunk extensions quoted value"; state->error_pos = (const char*) p; @@ -1364,7 +1522,7 @@ static llparse_state_t llhttp__internal__run( 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -1386,30 +1544,34 @@ static llparse_state_t llhttp__internal__run( } case 2: { p++; - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_1; - } - default: { goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_2; } + case 3: { + p++; + goto s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair; + } + default: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_4; + } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: { + case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3: + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3: { switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_chunk_size_otherwise; + goto s_n_llhttp__internal__n_chunk_extensions; case 21: - goto s_n_llhttp__internal__n_pause_9; + goto s_n_llhttp__internal__n_pause_11; default: - goto s_n_llhttp__internal__n_error_22; + goto s_n_llhttp__internal__n_error_32; } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_23: - s_n_llhttp__internal__n_error_23: { + case s_n_llhttp__internal__n_error_33: + s_n_llhttp__internal__n_error_33: { state->error = 0x2; state->reason = "Invalid character in chunk extensions value"; state->error_pos = (const char*) p; @@ -1421,14 +1583,14 @@ static llparse_state_t llhttp__internal__run( case s_n_llhttp__internal__n_chunk_extension_value: s_n_llhttp__internal__n_chunk_extension_value: { static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 3, 2, 2, 2, 2, 2, 0, 0, 2, 2, 0, 2, 2, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 4, 0, 0, 0, 0, - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 0, 2, 0, + 0, 3, 4, 3, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3, 0, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 5, 0, 0, 0, 0, + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1446,18 +1608,21 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value; } case 2: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_value; + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_1; } case 3: { p++; - goto s_n_llhttp__internal__n_chunk_extension_quoted_value; + goto s_n_llhttp__internal__n_chunk_extension_value; } case 4: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_3; + p++; + goto s_n_llhttp__internal__n_chunk_extension_quoted_value; + } + case 5: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_5; } default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_4; + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_6; } } /* UNREACHABLE */; @@ -1470,12 +1635,12 @@ static llparse_state_t llhttp__internal__run( } state->_span_pos0 = (void*) p; state->_span_cb0 = llhttp__on_chunk_extension_value; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_3; /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_24: - s_n_llhttp__internal__n_error_24: { + case s_n_llhttp__internal__n_error_34: + s_n_llhttp__internal__n_error_34: { state->error = 0x2; state->reason = "Invalid character in chunk extensions name"; state->error_pos = (const char*) p; @@ -1487,14 +1652,14 @@ static llparse_state_t llhttp__internal__run( case s_n_llhttp__internal__n_chunk_extension_name: s_n_llhttp__internal__n_chunk_extension_name: { static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 0, 2, 2, 2, 2, 2, 0, 0, 2, 2, 0, 2, 2, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 3, 0, 4, 0, 0, - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 0, 2, 0, + 0, 3, 0, 3, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3, 0, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 4, 0, 5, 0, 0, + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1512,18 +1677,21 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name; } case 2: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_name; + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_1; } case 3: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_1; + p++; + goto s_n_llhttp__internal__n_chunk_extension_name; } case 4: { goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_2; } - default: { + case 5: { goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_3; } + default: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_4; + } } /* UNREACHABLE */; abort(); @@ -1547,11 +1715,11 @@ static llparse_state_t llhttp__internal__run( switch (*p) { case 13: { p++; - goto s_n_llhttp__internal__n_error_13; + goto s_n_llhttp__internal__n_error_17; } case ' ': { p++; - goto s_n_llhttp__internal__n_error_14; + goto s_n_llhttp__internal__n_error_18; } default: { goto s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name; @@ -1566,16 +1734,28 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_chunk_size_otherwise; } switch (*p) { + case 9: { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_4; + } + case 10: { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_5; + } case 13: { p++; goto s_n_llhttp__internal__n_chunk_size_almost_done; } + case ' ': { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_4; + } case ';': { p++; goto s_n_llhttp__internal__n_chunk_extensions; } default: { - goto s_n_llhttp__internal__n_error_25; + goto s_n_llhttp__internal__n_error_35; } } /* UNREACHABLE */; @@ -1821,7 +2001,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_mul_add_content_length; } default: { - goto s_n_llhttp__internal__n_error_27; + goto s_n_llhttp__internal__n_error_37; } } /* UNREACHABLE */; @@ -1836,30 +2016,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_invoke_is_equal_upgrade: - s_n_llhttp__internal__n_invoke_is_equal_upgrade: { - switch (llhttp__internal__c_is_equal_upgrade(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__after_message_complete; - default: - goto s_n_llhttp__internal__n_pause_1; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: - s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: { - switch (llhttp__on_message_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_is_equal_upgrade; - case 21: - goto s_n_llhttp__internal__n_pause_11; - default: - goto s_n_llhttp__internal__n_error_28; - } - /* UNREACHABLE */; - abort(); - } case s_n_llhttp__internal__n_consume_content_length_1: s_n_llhttp__internal__n_consume_content_length_1: { size_t avail; @@ -1922,7 +2078,7 @@ static llparse_state_t llhttp__internal__run( case 4: goto s_n_llhttp__internal__n_invoke_update_finish_3; case 5: - goto s_n_llhttp__internal__n_error_29; + goto s_n_llhttp__internal__n_error_39; default: goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete; } @@ -1947,10 +2103,10 @@ static llparse_state_t llhttp__internal__run( switch (*p) { case 10: { p++; - goto s_n_llhttp__internal__n_invoke_test_flags; + goto s_n_llhttp__internal__n_invoke_test_flags_1; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_7; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_12; } } /* UNREACHABLE */; @@ -1979,9 +2135,9 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_header_field_start; case 21: - goto s_n_llhttp__internal__n_pause_14; + goto s_n_llhttp__internal__n_pause_18; default: - goto s_n_llhttp__internal__n_error_37; + goto s_n_llhttp__internal__n_error_48; } /* UNREACHABLE */; abort(); @@ -2005,14 +2161,14 @@ static llparse_state_t llhttp__internal__run( switch (*p) { case 9: { p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_10; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_15; } case ' ': { p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_10; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_15; } default: { - goto s_n_llhttp__internal__n_invoke_load_header_state; + goto s_n_llhttp__internal__n_invoke_load_header_state_1; } } /* UNREACHABLE */; @@ -2029,7 +2185,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_header_value_discard_lws; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_11; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_16; } } /* UNREACHABLE */; @@ -2042,13 +2198,13 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case 9: { - goto s_n_llhttp__internal__n_invoke_load_header_state_3; + goto s_n_llhttp__internal__n_invoke_load_header_state_4; } case ' ': { - goto s_n_llhttp__internal__n_invoke_load_header_state_3; + goto s_n_llhttp__internal__n_invoke_load_header_state_4; } default: { - goto s_n_llhttp__internal__n_invoke_load_header_state_4; + goto s_n_llhttp__internal__n_invoke_load_header_state_5; } } /* UNREACHABLE */; @@ -2065,12 +2221,23 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_header_value_lws; } default: { - goto s_n_llhttp__internal__n_error_40; + goto s_n_llhttp__internal__n_error_52; } } /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_test_lenient_flags_17: + s_n_llhttp__internal__n_invoke_test_lenient_flags_17: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_header_value_almost_done; + default: + goto s_n_llhttp__internal__n_error_51; + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_header_value_lenient: s_n_llhttp__internal__n_header_value_lenient: { if (p == endp) { @@ -2078,10 +2245,10 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case 10: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_3; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4; } case 13: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5; } default: { p++; @@ -2091,8 +2258,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_41: - s_n_llhttp__internal__n_error_41: { + case s_n_llhttp__internal__n_error_53: + s_n_llhttp__internal__n_error_53: { state->error = 0xa; state->reason = "Invalid header value char"; state->error_pos = (const char*) p; @@ -2107,11 +2274,14 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_header_value_otherwise; } switch (*p) { - case 13: { + case 10: { goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_1; } + case 13: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2; + } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_12; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_18; } } /* UNREACHABLE */; @@ -2174,7 +2344,7 @@ static llparse_state_t llhttp__internal__run( } case ',': { p++; - goto s_n_llhttp__internal__n_invoke_load_header_state_5; + goto s_n_llhttp__internal__n_invoke_load_header_state_6; } default: { goto s_n_llhttp__internal__n_invoke_update_header_state_5; @@ -2190,7 +2360,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_value_connection_1; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob3, 4); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob2, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2214,7 +2384,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_value_connection_2; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob4, 9); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob3, 9); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2238,7 +2408,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_value_connection_3; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob5, 6); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob4, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2288,8 +2458,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_43: - s_n_llhttp__internal__n_error_43: { + case s_n_llhttp__internal__n_error_55: + s_n_llhttp__internal__n_error_55: { state->error = 0xb; state->reason = "Content-Length overflow"; state->error_pos = (const char*) p; @@ -2298,8 +2468,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_44: - s_n_llhttp__internal__n_error_44: { + case s_n_llhttp__internal__n_error_56: + s_n_llhttp__internal__n_error_56: { state->error = 0xb; state->reason = "Invalid character in Content-Length"; state->error_pos = (const char*) p; @@ -2315,17 +2485,17 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case 10: { - goto s_n_llhttp__internal__n_invoke_or_flags_15; + goto s_n_llhttp__internal__n_invoke_or_flags_17; } case 13: { - goto s_n_llhttp__internal__n_invoke_or_flags_15; + goto s_n_llhttp__internal__n_invoke_or_flags_17; } case ' ': { p++; goto s_n_llhttp__internal__n_header_value_content_length_ws; } default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_7; } } /* UNREACHABLE */; @@ -2394,8 +2564,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_46: - s_n_llhttp__internal__n_error_46: { + case s_n_llhttp__internal__n_error_58: + s_n_llhttp__internal__n_error_58: { state->error = 0xf; state->reason = "Invalid `Transfer-Encoding` header value"; state->error_pos = (const char*) p; @@ -2404,8 +2574,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_45: - s_n_llhttp__internal__n_error_45: { + case s_n_llhttp__internal__n_error_57: + s_n_llhttp__internal__n_error_57: { state->error = 0xf; state->reason = "Invalid `Transfer-Encoding` header value"; state->error_pos = (const char*) p; @@ -2467,7 +2637,7 @@ static llparse_state_t llhttp__internal__run( /* Load input */ input = _mm_loadu_si128((__m128i const*) p); - ranges = _mm_loadu_si128((__m128i const*) llparse_blob7); + ranges = _mm_loadu_si128((__m128i const*) llparse_blob6); /* Find first character that does not match `ranges` */ match_len = _mm_cmpestri(ranges, 6, @@ -2566,7 +2736,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_value_te_chunked; } - match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob6, 7); + match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob5, 7); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2590,7 +2760,7 @@ static llparse_state_t llhttp__internal__run( } state->_span_pos0 = (void*) p; state->_span_cb0 = llhttp__on_header_value; - goto s_n_llhttp__internal__n_invoke_load_header_state_2; + goto s_n_llhttp__internal__n_invoke_load_header_state_3; /* UNREACHABLE */; abort(); } @@ -2606,7 +2776,7 @@ static llparse_state_t llhttp__internal__run( } case 10: { p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_9; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_14; } case 13: { p++; @@ -2623,15 +2793,28 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_load_header_state: + s_n_llhttp__internal__n_invoke_load_header_state: { + switch (llhttp__internal__c_load_header_state(state, p, endp)) { + case 2: + goto s_n_llhttp__internal__n_invoke_test_flags_4; + case 3: + goto s_n_llhttp__internal__n_invoke_test_flags_5; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete: s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete: { switch (llhttp__on_header_field_complete(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_header_value_discard_ws; + goto s_n_llhttp__internal__n_invoke_load_header_state; case 21: - goto s_n_llhttp__internal__n_pause_15; + goto s_n_llhttp__internal__n_pause_19; default: - goto s_n_llhttp__internal__n_error_34; + goto s_n_llhttp__internal__n_error_45; } /* UNREACHABLE */; abort(); @@ -2646,7 +2829,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_end_llhttp__on_header_field_2; } default: { - goto s_n_llhttp__internal__n_error_47; + goto s_n_llhttp__internal__n_error_61; } } /* UNREACHABLE */; @@ -2684,7 +2867,7 @@ static llparse_state_t llhttp__internal__run( /* Load input */ input = _mm_loadu_si128((__m128i const*) p); - ranges = _mm_loadu_si128((__m128i const*) llparse_blob8); + ranges = _mm_loadu_si128((__m128i const*) llparse_blob7); /* Find first character that does not match `ranges` */ match_len = _mm_cmpestri(ranges, 16, @@ -2696,7 +2879,7 @@ static llparse_state_t llhttp__internal__run( p += match_len; goto s_n_llhttp__internal__n_header_field_general; } - ranges = _mm_loadu_si128((__m128i const*) llparse_blob9); + ranges = _mm_loadu_si128((__m128i const*) llparse_blob8); /* Find first character that does not match `ranges` */ match_len = _mm_cmpestri(ranges, 2, @@ -2730,7 +2913,7 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case ' ': { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_8; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_13; } case ':': { goto s_n_llhttp__internal__n_span_end_llhttp__on_header_field_1; @@ -2749,7 +2932,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_3; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob2, 6); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob1, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2774,7 +2957,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_4; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob10, 10); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob9, 10); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2820,7 +3003,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_1; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob1, 2); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob0, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2844,7 +3027,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_5; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob11, 15); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob10, 15); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2869,7 +3052,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_6; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob12, 16); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob11, 16); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2894,7 +3077,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_7; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob13, 6); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob12, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2966,6 +3149,9 @@ static llparse_state_t llhttp__internal__run( p++; goto s_n_llhttp__internal__n_headers_almost_done; } + case ':': { + goto s_n_llhttp__internal__n_error_44; + } default: { goto s_n_llhttp__internal__n_span_start_llhttp__on_header_field; } @@ -3044,7 +3230,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_to_http_09; } default: { - goto s_n_llhttp__internal__n_error_48; + goto s_n_llhttp__internal__n_error_62; } } /* UNREACHABLE */; @@ -3069,7 +3255,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_skip_lf_to_http09_1; } default: { - goto s_n_llhttp__internal__n_error_48; + goto s_n_llhttp__internal__n_error_62; } } /* UNREACHABLE */; @@ -3082,18 +3268,18 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_req_pri_upgrade; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob15, 10); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob14, 10); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - goto s_n_llhttp__internal__n_error_55; + goto s_n_llhttp__internal__n_error_70; } case kMatchPause: { return s_n_llhttp__internal__n_req_pri_upgrade; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_56; + goto s_n_llhttp__internal__n_error_71; } } /* UNREACHABLE */; @@ -3110,7 +3296,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_headers_start; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_16; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_25; } } /* UNREACHABLE */; @@ -3122,12 +3308,16 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_http_complete; } switch (*p) { + case 10: { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_24; + } case 13: { p++; goto s_n_llhttp__internal__n_req_http_complete_crlf; } default: { - goto s_n_llhttp__internal__n_error_54; + goto s_n_llhttp__internal__n_error_69; } } /* UNREACHABLE */; @@ -3150,15 +3340,15 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_invoke_load_method_1; case 21: - goto s_n_llhttp__internal__n_pause_17; + goto s_n_llhttp__internal__n_pause_21; default: - goto s_n_llhttp__internal__n_error_52; + goto s_n_llhttp__internal__n_error_66; } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_51: - s_n_llhttp__internal__n_error_51: { + case s_n_llhttp__internal__n_error_65: + s_n_llhttp__internal__n_error_65: { state->error = 0x9; state->reason = "Invalid HTTP version"; state->error_pos = (const char*) p; @@ -3167,8 +3357,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_57: - s_n_llhttp__internal__n_error_57: { + case s_n_llhttp__internal__n_error_72: + s_n_llhttp__internal__n_error_72: { state->error = 0x9; state->reason = "Invalid minor version"; state->error_pos = (const char*) p; @@ -3240,8 +3430,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_58: - s_n_llhttp__internal__n_error_58: { + case s_n_llhttp__internal__n_error_73: + s_n_llhttp__internal__n_error_73: { state->error = 0x9; state->reason = "Expected dot"; state->error_pos = (const char*) p; @@ -3267,8 +3457,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_59: - s_n_llhttp__internal__n_error_59: { + case s_n_llhttp__internal__n_error_74: + s_n_llhttp__internal__n_error_74: { state->error = 0x9; state->reason = "Invalid major version"; state->error_pos = (const char*) p; @@ -3358,7 +3548,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_req_http_start_1; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob14, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob13, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -3369,7 +3559,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_http_start_1; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_62; + goto s_n_llhttp__internal__n_error_77; } } /* UNREACHABLE */; @@ -3382,7 +3572,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_req_http_start_2; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob16, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob15, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -3393,7 +3583,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_http_start_2; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_62; + goto s_n_llhttp__internal__n_error_77; } } /* UNREACHABLE */; @@ -3406,7 +3596,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_req_http_start_3; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob17, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob16, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -3417,7 +3607,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_http_start_3; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_62; + goto s_n_llhttp__internal__n_error_77; } } /* UNREACHABLE */; @@ -3446,7 +3636,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_req_http_start_3; } default: { - goto s_n_llhttp__internal__n_error_62; + goto s_n_llhttp__internal__n_error_77; } } /* UNREACHABLE */; @@ -3537,7 +3727,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_fragment; } default: { - goto s_n_llhttp__internal__n_error_63; + goto s_n_llhttp__internal__n_error_78; } } /* UNREACHABLE */; @@ -3598,7 +3788,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_end_stub_query_3; } default: { - goto s_n_llhttp__internal__n_error_64; + goto s_n_llhttp__internal__n_error_79; } } /* UNREACHABLE */; @@ -3636,7 +3826,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_query; } default: { - goto s_n_llhttp__internal__n_error_65; + goto s_n_llhttp__internal__n_error_80; } } /* UNREACHABLE */; @@ -3761,10 +3951,10 @@ static llparse_state_t llhttp__internal__run( } case 8: { p++; - goto s_n_llhttp__internal__n_error_66; + goto s_n_llhttp__internal__n_error_81; } default: { - goto s_n_llhttp__internal__n_error_67; + goto s_n_llhttp__internal__n_error_82; } } /* UNREACHABLE */; @@ -3823,7 +4013,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_server_with_at; } default: { - goto s_n_llhttp__internal__n_error_68; + goto s_n_llhttp__internal__n_error_83; } } /* UNREACHABLE */; @@ -3840,7 +4030,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_server; } default: { - goto s_n_llhttp__internal__n_error_69; + goto s_n_llhttp__internal__n_error_84; } } /* UNREACHABLE */; @@ -3877,7 +4067,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_schema_delim_1; } default: { - goto s_n_llhttp__internal__n_error_69; + goto s_n_llhttp__internal__n_error_84; } } /* UNREACHABLE */; @@ -3929,7 +4119,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_schema; } default: { - goto s_n_llhttp__internal__n_error_70; + goto s_n_llhttp__internal__n_error_85; } } /* UNREACHABLE */; @@ -3970,7 +4160,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_schema; } default: { - goto s_n_llhttp__internal__n_error_71; + goto s_n_llhttp__internal__n_error_86; } } /* UNREACHABLE */; @@ -4068,7 +4258,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_req_spaces_before_url; } default: { - goto s_n_llhttp__internal__n_error_72; + goto s_n_llhttp__internal__n_error_87; } } /* UNREACHABLE */; @@ -4080,9 +4270,9 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_req_first_space_before_url; case 21: - goto s_n_llhttp__internal__n_pause_22; + goto s_n_llhttp__internal__n_pause_26; default: - goto s_n_llhttp__internal__n_error_89; + goto s_n_llhttp__internal__n_error_106; } /* UNREACHABLE */; abort(); @@ -4099,7 +4289,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4112,7 +4302,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_3; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob18, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob17, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4124,7 +4314,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_3; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4145,7 +4335,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_3; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4158,7 +4348,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_4; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob19, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob18, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4170,7 +4360,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_4; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4183,7 +4373,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_6; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob20, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob19, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4195,7 +4385,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_6; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4208,7 +4398,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_8; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob21, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob20, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4220,7 +4410,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_8; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4238,7 +4428,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4259,7 +4449,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_9; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4280,7 +4470,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_7; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4293,7 +4483,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_12; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob22, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob21, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4305,7 +4495,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_12; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4318,7 +4508,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_13; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob23, 5); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob22, 5); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4330,7 +4520,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_13; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4351,7 +4541,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_13; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4368,7 +4558,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_11; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4381,7 +4571,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_14; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob24, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob23, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4393,7 +4583,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_14; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4406,7 +4596,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_17; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob26, 9); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob25, 9); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4418,7 +4608,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_17; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4449,7 +4639,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_15; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob25, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob24, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4460,7 +4650,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_15; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4473,7 +4663,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_18; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob27, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob26, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4485,7 +4675,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_18; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4498,7 +4688,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_20; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob28, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob27, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4510,7 +4700,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_20; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4523,7 +4713,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_21; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob29, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob28, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4535,7 +4725,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_21; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4556,7 +4746,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_21; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4569,7 +4759,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_23; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob30, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob29, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4581,7 +4771,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_23; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4594,7 +4784,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_24; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob31, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob30, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4606,7 +4796,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_24; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4619,7 +4809,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_26; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob32, 7); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob31, 7); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4631,7 +4821,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_26; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4644,7 +4834,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_28; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob33, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob32, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4656,7 +4846,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_28; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4674,7 +4864,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4695,7 +4885,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_29; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4716,7 +4906,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_27; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4729,7 +4919,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_30; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob34, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob33, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4741,7 +4931,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_30; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4770,7 +4960,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_30; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4783,7 +4973,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_31; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob35, 5); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob34, 5); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4795,7 +4985,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_31; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4808,7 +4998,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_32; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob36, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob35, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4820,7 +5010,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_32; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4833,7 +5023,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_35; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob37, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob36, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4845,7 +5035,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_35; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4858,7 +5048,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_36; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob38, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob37, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4870,7 +5060,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_36; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4891,7 +5081,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_36; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4904,7 +5094,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_37; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob39, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob38, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4916,7 +5106,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_37; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4929,7 +5119,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_38; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob40, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob39, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4941,7 +5131,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_38; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4954,7 +5144,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_42; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob41, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob40, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4966,7 +5156,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_42; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4979,7 +5169,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_43; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob42, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob41, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4991,7 +5181,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_43; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5012,7 +5202,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_43; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5029,7 +5219,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_41; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5051,7 +5241,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_40; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5064,7 +5254,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_45; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob43, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob42, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -5076,7 +5266,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_45; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5098,7 +5288,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5131,32 +5321,32 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_44; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_48: - s_n_llhttp__internal__n_after_start_req_48: { + case s_n_llhttp__internal__n_after_start_req_46: + s_n_llhttp__internal__n_after_start_req_46: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_48; + return s_n_llhttp__internal__n_after_start_req_46; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob44, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob43, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - match = 17; + match = 46; goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_48; + return s_n_llhttp__internal__n_after_start_req_46; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5169,19 +5359,19 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_49; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob45, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob44, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - match = 44; + match = 17; goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { return s_n_llhttp__internal__n_after_start_req_49; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5194,19 +5384,19 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_50; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob46, 5); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob45, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - match = 43; + match = 44; goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { return s_n_llhttp__internal__n_after_start_req_50; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5219,6 +5409,31 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_51; } + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob46, 5); + p = match_seq.current; + switch (match_seq.status) { + case kMatchComplete: { + p++; + match = 43; + goto s_n_llhttp__internal__n_invoke_store_method_1; + } + case kMatchPause: { + return s_n_llhttp__internal__n_after_start_req_51; + } + case kMatchMismatch: { + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_52: + s_n_llhttp__internal__n_after_start_req_52: { + llparse_match_t match_seq; + + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_52; + } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob47, 3); p = match_seq.current; switch (match_seq.status) { @@ -5228,10 +5443,39 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_51; + return s_n_llhttp__internal__n_after_start_req_52; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_48: + s_n_llhttp__internal__n_after_start_req_48: { + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_48; + } + switch (*p) { + case 'B': { + p++; + goto s_n_llhttp__internal__n_after_start_req_49; + } + case 'C': { + p++; + goto s_n_llhttp__internal__n_after_start_req_50; + } + case 'D': { + p++; + goto s_n_llhttp__internal__n_after_start_req_51; + } + case 'P': { + p++; + goto s_n_llhttp__internal__n_after_start_req_52; + } + default: { + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5243,52 +5487,23 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_47; } switch (*p) { - case 'B': { + case 'E': { p++; goto s_n_llhttp__internal__n_after_start_req_48; } - case 'C': { - p++; - goto s_n_llhttp__internal__n_after_start_req_49; - } - case 'D': { - p++; - goto s_n_llhttp__internal__n_after_start_req_50; - } - case 'P': { - p++; - goto s_n_llhttp__internal__n_after_start_req_51; - } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_46: - s_n_llhttp__internal__n_after_start_req_46: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_46; - } - switch (*p) { - case 'E': { - p++; - goto s_n_llhttp__internal__n_after_start_req_47; - } - default: { - goto s_n_llhttp__internal__n_error_90; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_54: - s_n_llhttp__internal__n_after_start_req_54: { + case s_n_llhttp__internal__n_after_start_req_55: + s_n_llhttp__internal__n_after_start_req_55: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_54; + return s_n_llhttp__internal__n_after_start_req_55; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob48, 3); p = match_seq.current; @@ -5299,19 +5514,19 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_54; + return s_n_llhttp__internal__n_after_start_req_55; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_56: - s_n_llhttp__internal__n_after_start_req_56: { + case s_n_llhttp__internal__n_after_start_req_57: + s_n_llhttp__internal__n_after_start_req_57: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_56; + return s_n_llhttp__internal__n_after_start_req_57; } switch (*p) { case 'P': { @@ -5320,74 +5535,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_57: - s_n_llhttp__internal__n_after_start_req_57: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_57; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob49, 9); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 42; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_57; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_55: - s_n_llhttp__internal__n_after_start_req_55: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_55; - } - switch (*p) { - case 'U': { - p++; - goto s_n_llhttp__internal__n_after_start_req_56; - } - case '_': { - p++; - goto s_n_llhttp__internal__n_after_start_req_57; - } - default: { - goto s_n_llhttp__internal__n_error_90; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_53: - s_n_llhttp__internal__n_after_start_req_53: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_53; - } - switch (*p) { - case 'A': { - p++; - goto s_n_llhttp__internal__n_after_start_req_54; - } - case 'T': { - p++; - goto s_n_llhttp__internal__n_after_start_req_55; - } - default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5400,19 +5548,61 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_58; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob50, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob49, 9); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - match = 33; + match = 42; goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { return s_n_llhttp__internal__n_after_start_req_58; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_56: + s_n_llhttp__internal__n_after_start_req_56: { + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_56; + } + switch (*p) { + case 'U': { + p++; + goto s_n_llhttp__internal__n_after_start_req_57; + } + case '_': { + p++; + goto s_n_llhttp__internal__n_after_start_req_58; + } + default: { + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_54: + s_n_llhttp__internal__n_after_start_req_54: { + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_54; + } + switch (*p) { + case 'A': { + p++; + goto s_n_llhttp__internal__n_after_start_req_55; + } + case 'T': { + p++; + goto s_n_llhttp__internal__n_after_start_req_56; + } + default: { + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5425,6 +5615,31 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_59; } + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob50, 4); + p = match_seq.current; + switch (match_seq.status) { + case kMatchComplete: { + p++; + match = 33; + goto s_n_llhttp__internal__n_invoke_store_method_1; + } + case kMatchPause: { + return s_n_llhttp__internal__n_after_start_req_59; + } + case kMatchMismatch: { + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_60: + s_n_llhttp__internal__n_after_start_req_60: { + llparse_match_t match_seq; + + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_60; + } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob51, 7); p = match_seq.current; switch (match_seq.status) { @@ -5434,60 +5649,35 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_59; + return s_n_llhttp__internal__n_after_start_req_60; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_52: - s_n_llhttp__internal__n_after_start_req_52: { + case s_n_llhttp__internal__n_after_start_req_53: + s_n_llhttp__internal__n_after_start_req_53: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_52; + return s_n_llhttp__internal__n_after_start_req_53; } switch (*p) { case 'E': { p++; - goto s_n_llhttp__internal__n_after_start_req_53; + goto s_n_llhttp__internal__n_after_start_req_54; } case 'O': { p++; - goto s_n_llhttp__internal__n_after_start_req_58; + goto s_n_llhttp__internal__n_after_start_req_59; } case 'U': { p++; - goto s_n_llhttp__internal__n_after_start_req_59; + goto s_n_llhttp__internal__n_after_start_req_60; } default: { - goto s_n_llhttp__internal__n_error_90; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_61: - s_n_llhttp__internal__n_after_start_req_61: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_61; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob52, 6); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 40; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_61; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5500,6 +5690,31 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_62; } + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob52, 6); + p = match_seq.current; + switch (match_seq.status) { + case kMatchComplete: { + p++; + match = 40; + goto s_n_llhttp__internal__n_invoke_store_method_1; + } + case kMatchPause: { + return s_n_llhttp__internal__n_after_start_req_62; + } + case kMatchMismatch: { + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_63: + s_n_llhttp__internal__n_after_start_req_63: { + llparse_match_t match_seq; + + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_63; + } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob53, 3); p = match_seq.current; switch (match_seq.status) { @@ -5509,42 +5724,42 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_62; + return s_n_llhttp__internal__n_after_start_req_63; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_60: - s_n_llhttp__internal__n_after_start_req_60: { + case s_n_llhttp__internal__n_after_start_req_61: + s_n_llhttp__internal__n_after_start_req_61: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_60; + return s_n_llhttp__internal__n_after_start_req_61; } switch (*p) { case 'E': { p++; - goto s_n_llhttp__internal__n_after_start_req_61; + goto s_n_llhttp__internal__n_after_start_req_62; } case 'R': { p++; - goto s_n_llhttp__internal__n_after_start_req_62; + goto s_n_llhttp__internal__n_after_start_req_63; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_65: - s_n_llhttp__internal__n_after_start_req_65: { + case s_n_llhttp__internal__n_after_start_req_66: + s_n_llhttp__internal__n_after_start_req_66: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_65; + return s_n_llhttp__internal__n_after_start_req_66; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob54, 3); p = match_seq.current; @@ -5555,35 +5770,10 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_65; + return s_n_llhttp__internal__n_after_start_req_66; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_67: - s_n_llhttp__internal__n_after_start_req_67: { - llparse_match_t match_seq; - - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_67; - } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob55, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { - p++; - match = 32; - goto s_n_llhttp__internal__n_invoke_store_method_1; - } - case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_67; - } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5596,40 +5786,19 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_68; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob56, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob55, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - match = 15; + match = 32; goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { return s_n_llhttp__internal__n_after_start_req_68; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_66: - s_n_llhttp__internal__n_after_start_req_66: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_66; - } - switch (*p) { - case 'I': { - p++; - goto s_n_llhttp__internal__n_after_start_req_67; - } - case 'O': { - p++; - goto s_n_llhttp__internal__n_after_start_req_68; - } - default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5642,6 +5811,52 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_69; } + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob56, 2); + p = match_seq.current; + switch (match_seq.status) { + case kMatchComplete: { + p++; + match = 15; + goto s_n_llhttp__internal__n_invoke_store_method_1; + } + case kMatchPause: { + return s_n_llhttp__internal__n_after_start_req_69; + } + case kMatchMismatch: { + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_67: + s_n_llhttp__internal__n_after_start_req_67: { + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_67; + } + switch (*p) { + case 'I': { + p++; + goto s_n_llhttp__internal__n_after_start_req_68; + } + case 'O': { + p++; + goto s_n_llhttp__internal__n_after_start_req_69; + } + default: { + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_70: + s_n_llhttp__internal__n_after_start_req_70: { + llparse_match_t match_seq; + + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_70; + } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob57, 8); p = match_seq.current; switch (match_seq.status) { @@ -5651,10 +5866,35 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_69; + return s_n_llhttp__internal__n_after_start_req_70; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_65: + s_n_llhttp__internal__n_after_start_req_65: { + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_65; + } + switch (*p) { + case 'B': { + p++; + goto s_n_llhttp__internal__n_after_start_req_66; + } + case 'L': { + p++; + goto s_n_llhttp__internal__n_after_start_req_67; + } + case 'S': { + p++; + goto s_n_llhttp__internal__n_after_start_req_70; + } + default: { + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5666,37 +5906,12 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_64; } switch (*p) { - case 'B': { + case 'N': { p++; goto s_n_llhttp__internal__n_after_start_req_65; } - case 'L': { - p++; - goto s_n_llhttp__internal__n_after_start_req_66; - } - case 'S': { - p++; - goto s_n_llhttp__internal__n_after_start_req_69; - } default: { - goto s_n_llhttp__internal__n_error_90; - } - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_after_start_req_63: - s_n_llhttp__internal__n_after_start_req_63: { - if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_63; - } - switch (*p) { - case 'N': { - p++; - goto s_n_llhttp__internal__n_after_start_req_64; - } - default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5756,24 +5971,28 @@ static llparse_state_t llhttp__internal__run( p++; goto s_n_llhttp__internal__n_after_start_req_33; } - case 'R': { + case 'Q': { p++; goto s_n_llhttp__internal__n_after_start_req_46; } + case 'R': { + p++; + goto s_n_llhttp__internal__n_after_start_req_47; + } case 'S': { p++; - goto s_n_llhttp__internal__n_after_start_req_52; + goto s_n_llhttp__internal__n_after_start_req_53; } case 'T': { p++; - goto s_n_llhttp__internal__n_after_start_req_60; + goto s_n_llhttp__internal__n_after_start_req_61; } case 'U': { p++; - goto s_n_llhttp__internal__n_after_start_req_63; + goto s_n_llhttp__internal__n_after_start_req_64; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5805,12 +6024,23 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_18; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_28; } } /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_test_lenient_flags_29: + s_n_llhttp__internal__n_invoke_test_lenient_flags_29: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; + default: + goto s_n_llhttp__internal__n_error_93; + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_res_status: s_n_llhttp__internal__n_res_status: { if (p == endp) { @@ -5842,27 +6072,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_res_status_start: - s_n_llhttp__internal__n_res_status_start: { - if (p == endp) { - return s_n_llhttp__internal__n_res_status_start; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_res_line_almost_done; - } - default: { - goto s_n_llhttp__internal__n_span_start_llhttp__on_status; - } - } - /* UNREACHABLE */; - abort(); - } case s_n_llhttp__internal__n_res_status_code_otherwise: s_n_llhttp__internal__n_res_status_code_otherwise: { if (p == endp) { @@ -5870,17 +6079,19 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case 10: { - goto s_n_llhttp__internal__n_res_status_start; + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_27; } case 13: { - goto s_n_llhttp__internal__n_res_status_start; + p++; + goto s_n_llhttp__internal__n_res_line_almost_done; } case ' ': { p++; - goto s_n_llhttp__internal__n_res_status_start; + goto s_n_llhttp__internal__n_span_start_llhttp__on_status; } default: { - goto s_n_llhttp__internal__n_error_77; + goto s_n_llhttp__internal__n_error_94; } } /* UNREACHABLE */; @@ -5943,7 +6154,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; } default: { - goto s_n_llhttp__internal__n_error_79; + goto s_n_llhttp__internal__n_error_96; } } /* UNREACHABLE */; @@ -6006,7 +6217,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; } default: { - goto s_n_llhttp__internal__n_error_81; + goto s_n_llhttp__internal__n_error_98; } } /* UNREACHABLE */; @@ -6069,7 +6280,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_mul_add_status_code; } default: { - goto s_n_llhttp__internal__n_error_83; + goto s_n_llhttp__internal__n_error_100; } } /* UNREACHABLE */; @@ -6086,7 +6297,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_update_status_code; } default: { - goto s_n_llhttp__internal__n_error_84; + goto s_n_llhttp__internal__n_error_101; } } /* UNREACHABLE */; @@ -6098,15 +6309,15 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_res_after_version; case 21: - goto s_n_llhttp__internal__n_pause_21; + goto s_n_llhttp__internal__n_pause_25; default: - goto s_n_llhttp__internal__n_error_74; + goto s_n_llhttp__internal__n_error_89; } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_73: - s_n_llhttp__internal__n_error_73: { + case s_n_llhttp__internal__n_error_88: + s_n_llhttp__internal__n_error_88: { state->error = 0x9; state->reason = "Invalid HTTP version"; state->error_pos = (const char*) p; @@ -6115,8 +6326,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_85: - s_n_llhttp__internal__n_error_85: { + case s_n_llhttp__internal__n_error_102: + s_n_llhttp__internal__n_error_102: { state->error = 0x9; state->reason = "Invalid minor version"; state->error_pos = (const char*) p; @@ -6188,8 +6399,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_86: - s_n_llhttp__internal__n_error_86: { + case s_n_llhttp__internal__n_error_103: + s_n_llhttp__internal__n_error_103: { state->error = 0x9; state->reason = "Expected dot"; state->error_pos = (const char*) p; @@ -6215,8 +6426,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_87: - s_n_llhttp__internal__n_error_87: { + case s_n_llhttp__internal__n_error_104: + s_n_llhttp__internal__n_error_104: { state->error = 0x9; state->reason = "Invalid major version"; state->error_pos = (const char*) p; @@ -6317,7 +6528,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_start_res; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_91; + goto s_n_llhttp__internal__n_error_108; } } /* UNREACHABLE */; @@ -6329,7 +6540,7 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_req_first_space_before_url; case 21: - goto s_n_llhttp__internal__n_pause_19; + goto s_n_llhttp__internal__n_pause_23; default: goto s_n_llhttp__internal__n_error_1; } @@ -6355,7 +6566,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_or_res_method_2; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_88; + goto s_n_llhttp__internal__n_error_105; } } /* UNREACHABLE */; @@ -6388,7 +6599,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_or_res_method_3; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_88; + goto s_n_llhttp__internal__n_error_105; } } /* UNREACHABLE */; @@ -6409,7 +6620,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_req_or_res_method_3; } default: { - goto s_n_llhttp__internal__n_error_88; + goto s_n_llhttp__internal__n_error_105; } } /* UNREACHABLE */; @@ -6426,7 +6637,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_req_or_res_method_1; } default: { - goto s_n_llhttp__internal__n_error_88; + goto s_n_llhttp__internal__n_error_105; } } /* UNREACHABLE */; @@ -6539,7 +6750,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_7: { + s_n_llhttp__internal__n_error_8: { state->error = 0x5; state->reason = "Data after `Connection: close`"; state->error_pos = (const char*) p; @@ -6553,7 +6764,7 @@ static llparse_state_t llhttp__internal__run( case 1: goto s_n_llhttp__internal__n_closed; default: - goto s_n_llhttp__internal__n_error_7; + goto s_n_llhttp__internal__n_error_8; } /* UNREACHABLE */; abort(); @@ -6576,6 +6787,54 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_pause_13: { + state->error = 0x15; + state->reason = "on_message_complete pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_is_equal_upgrade; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_38: { + state->error = 0x12; + state->reason = "`on_message_complete` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_15: { + state->error = 0x15; + state->reason = "on_chunk_complete pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_40: { + state->error = 0x14; + state->reason = "`on_chunk_complete` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1: { + switch (llhttp__on_chunk_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; + case 21: + goto s_n_llhttp__internal__n_pause_15; + default: + goto s_n_llhttp__internal__n_error_40; + } + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_pause_2: { state->error = 0x15; state->reason = "on_message_complete pause"; @@ -6585,7 +6844,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_8: { + s_n_llhttp__internal__n_error_9: { state->error = 0x12; state->reason = "`on_message_complete` callback error"; state->error_pos = (const char*) p; @@ -6601,12 +6860,12 @@ static llparse_state_t llhttp__internal__run( case 21: goto s_n_llhttp__internal__n_pause_2; default: - goto s_n_llhttp__internal__n_error_8; + goto s_n_llhttp__internal__n_error_9; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_26: { + s_n_llhttp__internal__n_error_36: { state->error = 0xc; state->reason = "Chunk size overflow"; state->error_pos = (const char*) p; @@ -6615,6 +6874,25 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_10: { + state->error = 0xc; + state->reason = "Invalid character in chunk size"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_4: { + switch (llhttp__internal__c_test_lenient_flags_4(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_otherwise; + default: + goto s_n_llhttp__internal__n_error_10; + } + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_pause_3: { state->error = 0x15; state->reason = "on_chunk_complete pause"; @@ -6624,7 +6902,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_10: { + s_n_llhttp__internal__n_error_14: { state->error = 0x14; state->reason = "`on_chunk_complete` callback error"; state->error_pos = (const char*) p; @@ -6640,12 +6918,31 @@ static llparse_state_t llhttp__internal__run( case 21: goto s_n_llhttp__internal__n_pause_3; default: - goto s_n_llhttp__internal__n_error_10; + goto s_n_llhttp__internal__n_error_14; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_11: { + s_n_llhttp__internal__n_error_13: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk data"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_6: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; + default: + goto s_n_llhttp__internal__n_error_13; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_15: { state->error = 0x2; state->reason = "Expected LF after chunk data"; state->error_pos = (const char*) p; @@ -6654,12 +6951,12 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_4: { - switch (llhttp__internal__c_test_lenient_flags_4(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_7: { + switch (llhttp__internal__c_test_lenient_flags_7(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; default: - goto s_n_llhttp__internal__n_error_11; + goto s_n_llhttp__internal__n_error_15; } /* UNREACHABLE */; abort(); @@ -6698,7 +6995,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_9: { + s_n_llhttp__internal__n_error_12: { state->error = 0x13; state->reason = "`on_chunk_header` callback error"; state->error_pos = (const char*) p; @@ -6714,12 +7011,12 @@ static llparse_state_t llhttp__internal__run( case 21: goto s_n_llhttp__internal__n_pause_4; default: - goto s_n_llhttp__internal__n_error_9; + goto s_n_llhttp__internal__n_error_12; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_12: { + s_n_llhttp__internal__n_error_16: { state->error = 0x2; state->reason = "Expected LF after chunk size"; state->error_pos = (const char*) p; @@ -6728,17 +7025,36 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_5: { - switch (llhttp__internal__c_test_lenient_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_8: { + switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_header; default: - goto s_n_llhttp__internal__n_error_12; + goto s_n_llhttp__internal__n_error_16; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_13: { + s_n_llhttp__internal__n_error_11: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk size"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_5: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_almost_done; + default: + goto s_n_llhttp__internal__n_error_11; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_17: { state->error = 0x2; state->reason = "Invalid character in chunk extensions"; state->error_pos = (const char*) p; @@ -6747,7 +7063,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_14: { + s_n_llhttp__internal__n_error_18: { state->error = 0x2; state->reason = "Invalid character in chunk extensions"; state->error_pos = (const char*) p; @@ -6756,16 +7072,25 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_20: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk extension name"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_pause_5: { state->error = 0x15; state->reason = "on_chunk_extension_name pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_9; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_15: { + s_n_llhttp__internal__n_error_19: { state->error = 0x22; state->reason = "`on_chunk_extension_name` callback error"; state->error_pos = (const char*) p; @@ -6783,11 +7108,10 @@ static llparse_state_t llhttp__internal__run( err = llhttp__on_chunk_extension_name(state, start, p); if (err != 0) { state->error = err; - state->error_pos = (const char*) (p + 1); + state->error_pos = (const char*) p; state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete; return s_error; } - p++; goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete; /* UNREACHABLE */; abort(); @@ -6796,12 +7120,12 @@ static llparse_state_t llhttp__internal__run( state->error = 0x15; state->reason = "on_chunk_extension_name pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extensions; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_16: { + s_n_llhttp__internal__n_error_21: { state->error = 0x22; state->reason = "`on_chunk_extension_name` callback error"; state->error_pos = (const char*) p; @@ -6830,14 +7154,59 @@ static llparse_state_t llhttp__internal__run( } s_n_llhttp__internal__n_pause_7: { state->error = 0x15; - state->reason = "on_chunk_extension_value pause"; + state->reason = "on_chunk_extension_name pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extensions; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_18: { + s_n_llhttp__internal__n_error_22: { + state->error = 0x22; + state->reason = "`on_chunk_extension_name` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_2: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_chunk_extension_name(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_25: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk extension value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_8: { + state->error = 0x15; + state->reason = "on_chunk_extension_value pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_10; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_24: { state->error = 0x23; state->reason = "`on_chunk_extension_value` callback error"; state->error_pos = (const char*) p; @@ -6855,34 +7224,24 @@ static llparse_state_t llhttp__internal__run( err = llhttp__on_chunk_extension_value(state, start, p); if (err != 0) { state->error = err; - state->error_pos = (const char*) (p + 1); + state->error_pos = (const char*) p; state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete; return s_error; } - p++; goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_20: { - state->error = 0x2; - state->reason = "Invalid character in chunk extensions quote value"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_8: { + s_n_llhttp__internal__n_pause_9: { state->error = 0x15; state->reason = "on_chunk_extension_value pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extension_quoted_value_done; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_19: { + s_n_llhttp__internal__n_error_26: { state->error = 0x23; state->reason = "`on_chunk_extension_value` callback error"; state->error_pos = (const char*) p; @@ -6900,14 +7259,61 @@ static llparse_state_t llhttp__internal__run( err = llhttp__on_chunk_extension_value(state, start, p); if (err != 0) { state->error = err; - state->error_pos = (const char*) p; + state->error_pos = (const char*) (p + 1); state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1; return s_error; } + p++; goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1; /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_28: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk extension value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_11: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_almost_done; + default: + goto s_n_llhttp__internal__n_error_28; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_29: { + state->error = 0x2; + state->reason = "Invalid character in chunk extensions quote value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_10: { + state->error = 0x15; + state->reason = "on_chunk_extension_value pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extension_quoted_value_done; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_27: { + state->error = 0x23; + state->reason = "`on_chunk_extension_value` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_2: { const unsigned char* start; int err; @@ -6917,30 +7323,11 @@ static llparse_state_t llhttp__internal__run( err = llhttp__on_chunk_extension_value(state, start, p); if (err != 0) { state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_21; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; return s_error; } - p++; - goto s_n_llhttp__internal__n_error_21; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_9: { - state->error = 0x15; - state->reason = "on_chunk_extension_value pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_otherwise; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_22: { - state->error = 0x23; - state->reason = "`on_chunk_extension_value` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; /* UNREACHABLE */; abort(); } @@ -6954,11 +7341,11 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_30; return s_error; } p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; + goto s_n_llhttp__internal__n_error_30; /* UNREACHABLE */; abort(); } @@ -6972,15 +7359,69 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_23; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_31; return s_error; } p++; - goto s_n_llhttp__internal__n_error_23; + goto s_n_llhttp__internal__n_error_31; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_10: { + s_n_llhttp__internal__n_pause_11: { + state->error = 0x15; + state->reason = "on_chunk_extension_value pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extensions; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_32: { + state->error = 0x23; + state->reason = "`on_chunk_extension_value` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_5: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_chunk_extension_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_6: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_chunk_extension_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_33; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_error_33; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_12: { state->error = 0x15; state->reason = "on_chunk_extension_name pause"; state->error_pos = (const char*) p; @@ -6989,7 +7430,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_17: { + s_n_llhttp__internal__n_error_23: { state->error = 0x22; state->reason = "`on_chunk_extension_name` callback error"; state->error_pos = (const char*) p; @@ -6998,19 +7439,19 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2: { + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_3: { switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { case 0: goto s_n_llhttp__internal__n_chunk_extension_value; case 21: - goto s_n_llhttp__internal__n_pause_10; + goto s_n_llhttp__internal__n_pause_12; default: - goto s_n_llhttp__internal__n_error_17; + goto s_n_llhttp__internal__n_error_23; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_2: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_3: { const unsigned char* start; int err; @@ -7028,7 +7469,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_3: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_4: { const unsigned char* start; int err; @@ -7038,15 +7479,15 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_24; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_34; return s_error; } p++; - goto s_n_llhttp__internal__n_error_24; + goto s_n_llhttp__internal__n_error_34; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_25: { + s_n_llhttp__internal__n_error_35: { state->error = 0xc; state->reason = "Invalid character in chunk size"; state->error_pos = (const char*) p; @@ -7058,14 +7499,14 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_mul_add_content_length: { switch (llhttp__internal__c_mul_add_content_length(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_error_26; + goto s_n_llhttp__internal__n_error_36; default: goto s_n_llhttp__internal__n_chunk_size; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_27: { + s_n_llhttp__internal__n_error_37: { state->error = 0xc; state->reason = "Invalid character in chunk size"; state->error_pos = (const char*) p; @@ -7074,24 +7515,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_11: { - state->error = 0x15; - state->reason = "on_message_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_is_equal_upgrade; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_28: { - state->error = 0x12; - state->reason = "`on_message_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } s_n_llhttp__internal__n_span_end_llhttp__on_body_1: { const unsigned char* start; int err; @@ -7117,7 +7540,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_29: { + s_n_llhttp__internal__n_error_39: { state->error = 0xf; state->reason = "Request has invalid `Transfer-Encoding`"; state->error_pos = (const char*) p; @@ -7135,7 +7558,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_6: { + s_n_llhttp__internal__n_error_7: { state->error = 0x12; state->reason = "`on_message_complete` callback error"; state->error_pos = (const char*) p; @@ -7151,60 +7574,11 @@ static llparse_state_t llhttp__internal__run( case 21: goto s_n_llhttp__internal__n_pause; default: - goto s_n_llhttp__internal__n_error_6; + goto s_n_llhttp__internal__n_error_7; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_1: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; - default: - goto s_n_llhttp__internal__n_error_5; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_pause_13: { - state->error = 0x15; - state->reason = "on_chunk_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_32: { - state->error = 0x14; - state->reason = "`on_chunk_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1: { - switch (llhttp__on_chunk_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; - case 21: - goto s_n_llhttp__internal__n_pause_13; - default: - goto s_n_llhttp__internal__n_error_32; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_31: { - state->error = 0x4; - state->reason = "Content-Length can't be present with Transfer-Encoding"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } s_n_llhttp__internal__n_invoke_or_flags_1: { switch (llhttp__internal__c_or_flags_1(state, p, endp)) { default: @@ -7229,7 +7603,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_12: { + s_n_llhttp__internal__n_pause_14: { state->error = 0x15; state->reason = "Paused by on_headers_complete"; state->error_pos = (const char*) p; @@ -7238,7 +7612,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_30: { + s_n_llhttp__internal__n_error_6: { state->error = 0x11; state->reason = "User callback error"; state->error_pos = (const char*) p; @@ -7256,9 +7630,9 @@ static llparse_state_t llhttp__internal__run( case 2: goto s_n_llhttp__internal__n_invoke_update_upgrade; case 21: - goto s_n_llhttp__internal__n_pause_12; + goto s_n_llhttp__internal__n_pause_14; default: - goto s_n_llhttp__internal__n_error_30; + goto s_n_llhttp__internal__n_error_6; } /* UNREACHABLE */; abort(); @@ -7271,37 +7645,133 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_6: { - switch (llhttp__internal__c_test_lenient_flags_6(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_error_31; - default: - goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags_1: { - switch (llhttp__internal__c_test_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_6; - default: - goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete; - } - /* UNREACHABLE */; - abort(); - } s_n_llhttp__internal__n_invoke_test_flags: { switch (llhttp__internal__c_test_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1; default: - goto s_n_llhttp__internal__n_invoke_test_flags_1; + goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_33: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_1: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_test_flags; + default: + goto s_n_llhttp__internal__n_error_5; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_17: { + state->error = 0x15; + state->reason = "on_chunk_complete pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_42: { + state->error = 0x14; + state->reason = "`on_chunk_complete` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_2: { + switch (llhttp__on_chunk_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; + case 21: + goto s_n_llhttp__internal__n_pause_17; + default: + goto s_n_llhttp__internal__n_error_42; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_3: { + switch (llhttp__internal__c_or_flags_1(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_4: { + switch (llhttp__internal__c_or_flags_1(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_update_upgrade_1: { + switch (llhttp__internal__c_update_upgrade(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_or_flags_4; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_16: { + state->error = 0x15; + state->reason = "Paused by on_headers_complete"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_41: { + state->error = 0x11; + state->reason = "User callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete_1: { + switch (llhttp__on_headers_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + case 1: + goto s_n_llhttp__internal__n_invoke_or_flags_3; + case 2: + goto s_n_llhttp__internal__n_invoke_update_upgrade_1; + case 21: + goto s_n_llhttp__internal__n_pause_16; + default: + goto s_n_llhttp__internal__n_error_41; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete_1: { + switch (llhttp__before_headers_complete(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete_1; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_flags_1: { + switch (llhttp__internal__c_test_flags(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_2; + default: + goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete_1; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_43: { state->error = 0x2; state->reason = "Expected LF after headers"; state->error_pos = (const char*) p; @@ -7310,16 +7780,25 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_7: { - switch (llhttp__internal__c_test_lenient_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_12: { + switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { case 1: - goto s_n_llhttp__internal__n_invoke_test_flags; + goto s_n_llhttp__internal__n_invoke_test_flags_1; default: - goto s_n_llhttp__internal__n_error_33; + goto s_n_llhttp__internal__n_error_43; } /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_44: { + state->error = 0xa; + state->reason = "Invalid header token"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_span_end_llhttp__on_header_field: { const unsigned char* start; int err; @@ -7338,7 +7817,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_8: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_13: { switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_field_colon_discard_ws; @@ -7348,7 +7827,16 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_36: { + s_n_llhttp__internal__n_error_59: { + state->error = 0xb; + state->reason = "Content-Length can't be present with Transfer-Encoding"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_47: { state->error = 0xa; state->reason = "Invalid header value char"; state->error_pos = (const char*) p; @@ -7357,17 +7845,17 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_10: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_15: { switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_discard_ws; default: - goto s_n_llhttp__internal__n_error_36; + goto s_n_llhttp__internal__n_error_47; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_38: { + s_n_llhttp__internal__n_error_49: { state->error = 0xb; state->reason = "Empty Content-Length"; state->error_pos = (const char*) p; @@ -7376,7 +7864,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_14: { + s_n_llhttp__internal__n_pause_18: { state->error = 0x15; state->reason = "on_header_value_complete pause"; state->error_pos = (const char*) p; @@ -7385,7 +7873,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_37: { + s_n_llhttp__internal__n_error_48: { state->error = 0x1d; state->reason = "`on_header_value_complete` callback error"; state->error_pos = (const char*) p; @@ -7419,22 +7907,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_3: { - switch (llhttp__internal__c_or_flags_3(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_4: { - switch (llhttp__internal__c_or_flags_4(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state; - } - /* UNREACHABLE */; - abort(); - } s_n_llhttp__internal__n_invoke_or_flags_5: { switch (llhttp__internal__c_or_flags_5(state, p, endp)) { default: @@ -7445,6 +7917,38 @@ static llparse_state_t llhttp__internal__run( } s_n_llhttp__internal__n_invoke_or_flags_6: { switch (llhttp__internal__c_or_flags_6(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_update_header_state; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_7: { + switch (llhttp__internal__c_or_flags_7(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_update_header_state; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_8: { + switch (llhttp__internal__c_or_flags_8(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_load_header_state_2: { + switch (llhttp__internal__c_load_header_state(state, p, endp)) { + case 5: + goto s_n_llhttp__internal__n_invoke_or_flags_5; + case 6: + goto s_n_llhttp__internal__n_invoke_or_flags_6; + case 7: + goto s_n_llhttp__internal__n_invoke_or_flags_7; + case 8: + goto s_n_llhttp__internal__n_invoke_or_flags_8; default: goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value; } @@ -7452,32 +7956,16 @@ static llparse_state_t llhttp__internal__run( abort(); } s_n_llhttp__internal__n_invoke_load_header_state_1: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_3; - case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_4; - case 7: - goto s_n_llhttp__internal__n_invoke_or_flags_5; - case 8: - goto s_n_llhttp__internal__n_invoke_or_flags_6; - default: - goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_load_header_state: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 2: - goto s_n_llhttp__internal__n_error_38; + goto s_n_llhttp__internal__n_error_49; default: - goto s_n_llhttp__internal__n_invoke_load_header_state_1; + goto s_n_llhttp__internal__n_invoke_load_header_state_2; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_35: { + s_n_llhttp__internal__n_error_46: { state->error = 0xa; state->reason = "Invalid header value char"; state->error_pos = (const char*) p; @@ -7486,17 +7974,17 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_9: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_14: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_discard_lws; default: - goto s_n_llhttp__internal__n_error_35; + goto s_n_llhttp__internal__n_error_46; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_39: { + s_n_llhttp__internal__n_error_50: { state->error = 0x2; state->reason = "Expected LF after CR"; state->error_pos = (const char*) p; @@ -7505,12 +7993,12 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_11: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_16: { switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_discard_lws; default: - goto s_n_llhttp__internal__n_error_39; + goto s_n_llhttp__internal__n_error_50; } /* UNREACHABLE */; abort(); @@ -7523,7 +8011,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_3: { + s_n_llhttp__internal__n_invoke_load_header_state_4: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 8: goto s_n_llhttp__internal__n_invoke_update_header_state_1; @@ -7541,22 +8029,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_7: { - switch (llhttp__internal__c_or_flags_3(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_2; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_8: { - switch (llhttp__internal__c_or_flags_4(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_2; - } - /* UNREACHABLE */; - abort(); - } s_n_llhttp__internal__n_invoke_or_flags_9: { switch (llhttp__internal__c_or_flags_5(state, p, endp)) { default: @@ -7568,28 +8040,44 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_or_flags_10: { switch (llhttp__internal__c_or_flags_6(state, p, endp)) { default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; + goto s_n_llhttp__internal__n_invoke_update_header_state_2; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_4: { - switch (llhttp__internal__c_load_header_state(state, p, endp)) { - case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_7; - case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_8; - case 7: - goto s_n_llhttp__internal__n_invoke_or_flags_9; - case 8: - goto s_n_llhttp__internal__n_invoke_or_flags_10; + s_n_llhttp__internal__n_invoke_or_flags_11: { + switch (llhttp__internal__c_or_flags_7(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_update_header_state_2; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_12: { + switch (llhttp__internal__c_or_flags_8(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_40: { + s_n_llhttp__internal__n_invoke_load_header_state_5: { + switch (llhttp__internal__c_load_header_state(state, p, endp)) { + case 5: + goto s_n_llhttp__internal__n_invoke_or_flags_9; + case 6: + goto s_n_llhttp__internal__n_invoke_or_flags_10; + case 7: + goto s_n_llhttp__internal__n_invoke_or_flags_11; + case 8: + goto s_n_llhttp__internal__n_invoke_or_flags_12; + default: + goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_52: { state->error = 0x3; state->reason = "Missing expected LF after header value"; state->error_pos = (const char*) p; @@ -7598,10 +8086,71 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_51: { + state->error = 0x19; + state->reason = "Missing expected CR after header value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_span_end_llhttp__on_header_value_1: { const unsigned char* start; int err; + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_header_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_17; + return s_error; + } + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_17; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_header_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_almost_done; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_header_value_almost_done; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_header_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_almost_done; + return s_error; + } + goto s_n_llhttp__internal__n_header_value_almost_done; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5: { + const unsigned char* start; + int err; + start = state->_span_pos0; state->_span_pos0 = NULL; err = llhttp__on_header_value(state, start, p); @@ -7626,54 +8175,19 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_almost_done; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_53; return s_error; } - goto s_n_llhttp__internal__n_header_value_almost_done; + goto s_n_llhttp__internal__n_error_53; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_almost_done; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_header_value_almost_done; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_41; - return s_error; - } - goto s_n_llhttp__internal__n_error_41; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_12: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_18: { switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_lenient; default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_3; } /* UNREACHABLE */; abort(); @@ -7686,22 +8200,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_11: { - switch (llhttp__internal__c_or_flags_3(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_4; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_12: { - switch (llhttp__internal__c_or_flags_4(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_invoke_update_header_state_4; - } - /* UNREACHABLE */; - abort(); - } s_n_llhttp__internal__n_invoke_or_flags_13: { switch (llhttp__internal__c_or_flags_5(state, p, endp)) { default: @@ -7712,22 +8210,38 @@ static llparse_state_t llhttp__internal__run( } s_n_llhttp__internal__n_invoke_or_flags_14: { switch (llhttp__internal__c_or_flags_6(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_update_header_state_4; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_15: { + switch (llhttp__internal__c_or_flags_7(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_update_header_state_4; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_16: { + switch (llhttp__internal__c_or_flags_8(state, p, endp)) { default: goto s_n_llhttp__internal__n_header_value_connection; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_5: { + s_n_llhttp__internal__n_invoke_load_header_state_6: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_11; - case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_12; - case 7: goto s_n_llhttp__internal__n_invoke_or_flags_13; - case 8: + case 6: goto s_n_llhttp__internal__n_invoke_or_flags_14; + case 7: + goto s_n_llhttp__internal__n_invoke_or_flags_15; + case 8: + goto s_n_llhttp__internal__n_invoke_or_flags_16; default: goto s_n_llhttp__internal__n_header_value_connection; } @@ -7766,41 +8280,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_43; - return s_error; - } - goto s_n_llhttp__internal__n_error_43; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_mul_add_content_length_1: { - switch (llhttp__internal__c_mul_add_content_length_1(state, p, endp, match)) { - case 1: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5; - default: - goto s_n_llhttp__internal__n_header_value_content_length; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_15: { - switch (llhttp__internal__c_or_flags_15(state, p, endp)) { - default: - goto s_n_llhttp__internal__n_header_value_otherwise; - } - /* UNREACHABLE */; - abort(); - } s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6: { const unsigned char* start; int err; @@ -7811,52 +8290,25 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_44; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_55; return s_error; } - goto s_n_llhttp__internal__n_error_44; + goto s_n_llhttp__internal__n_error_55; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_42: { - state->error = 0x4; - state->reason = "Duplicate Content-Length"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags_2: { - switch (llhttp__internal__c_test_flags_2(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_header_value_content_length; + s_n_llhttp__internal__n_invoke_mul_add_content_length_1: { + switch (llhttp__internal__c_mul_add_content_length_1(state, p, endp, match)) { + case 1: + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6; default: - goto s_n_llhttp__internal__n_error_42; + goto s_n_llhttp__internal__n_header_value_content_length; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8: { - const unsigned char* start; - int err; - - start = state->_span_pos0; - state->_span_pos0 = NULL; - err = llhttp__on_header_value(state, start, p); - if (err != 0) { - state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_46; - return s_error; - } - p++; - goto s_n_llhttp__internal__n_error_46; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_update_header_state_8: { - switch (llhttp__internal__c_update_header_state_8(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_17: { + switch (llhttp__internal__c_or_flags_17(state, p, endp)) { default: goto s_n_llhttp__internal__n_header_value_otherwise; } @@ -7872,19 +8324,81 @@ static llparse_state_t llhttp__internal__run( err = llhttp__on_header_value(state, start, p); if (err != 0) { state->error = err; - state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_45; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_56; return s_error; } - p++; - goto s_n_llhttp__internal__n_error_45; + goto s_n_llhttp__internal__n_error_56; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_13: { - switch (llhttp__internal__c_test_lenient_flags_13(state, p, endp)) { + s_n_llhttp__internal__n_error_54: { + state->error = 0x4; + state->reason = "Duplicate Content-Length"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_flags_2: { + switch (llhttp__internal__c_test_flags_2(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_7; + goto s_n_llhttp__internal__n_header_value_content_length; + default: + goto s_n_llhttp__internal__n_error_54; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_9: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_header_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_58; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_error_58; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_update_header_state_8: { + switch (llhttp__internal__c_update_header_state_8(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_header_value_otherwise; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_header_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_57; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_error_57; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_19: { + switch (llhttp__internal__c_test_lenient_flags_19(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8; default: goto s_n_llhttp__internal__n_header_value_te_chunked; } @@ -7894,7 +8408,7 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_load_type_1: { switch (llhttp__internal__c_load_type(state, p, endp)) { case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_13; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_19; default: goto s_n_llhttp__internal__n_header_value_te_chunked; } @@ -7917,20 +8431,20 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_17: { - switch (llhttp__internal__c_or_flags_16(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_19: { + switch (llhttp__internal__c_or_flags_18(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_and_flags; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_14: { - switch (llhttp__internal__c_test_lenient_flags_13(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_20: { + switch (llhttp__internal__c_test_lenient_flags_19(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_9; default: - goto s_n_llhttp__internal__n_invoke_or_flags_17; + goto s_n_llhttp__internal__n_invoke_or_flags_19; } /* UNREACHABLE */; abort(); @@ -7938,15 +8452,15 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_load_type_2: { switch (llhttp__internal__c_load_type(state, p, endp)) { case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_14; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_20; default: - goto s_n_llhttp__internal__n_invoke_or_flags_17; + goto s_n_llhttp__internal__n_invoke_or_flags_19; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_16: { - switch (llhttp__internal__c_or_flags_16(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_18: { + switch (llhttp__internal__c_or_flags_18(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_and_flags; } @@ -7958,20 +8472,20 @@ static llparse_state_t llhttp__internal__run( case 1: goto s_n_llhttp__internal__n_invoke_load_type_2; default: - goto s_n_llhttp__internal__n_invoke_or_flags_16; + goto s_n_llhttp__internal__n_invoke_or_flags_18; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_18: { - switch (llhttp__internal__c_or_flags_18(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_20: { + switch (llhttp__internal__c_or_flags_20(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state_9; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_2: { + s_n_llhttp__internal__n_invoke_load_header_state_3: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_connection; @@ -7980,23 +8494,72 @@ static llparse_state_t llhttp__internal__run( case 3: goto s_n_llhttp__internal__n_invoke_test_flags_3; case 4: - goto s_n_llhttp__internal__n_invoke_or_flags_18; + goto s_n_llhttp__internal__n_invoke_or_flags_20; default: goto s_n_llhttp__internal__n_header_value; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_15: { - state->error = 0x15; - state->reason = "on_header_field_complete pause"; + s_n_llhttp__internal__n_invoke_test_lenient_flags_21: { + switch (llhttp__internal__c_test_lenient_flags_21(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_error_59; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_flags_4: { + switch (llhttp__internal__c_test_flags_4(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_21; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_60: { + state->error = 0xf; + state->reason = "Transfer-Encoding can't be present with Content-Length"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_discard_ws; + state->_current = (void*) (intptr_t) s_error; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_34: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_22: { + switch (llhttp__internal__c_test_lenient_flags_21(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_error_60; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_flags_5: { + switch (llhttp__internal__c_test_flags_2(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_22; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_19: { + state->error = 0x15; + state->reason = "on_header_field_complete pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_load_header_state; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_45: { state->error = 0x1c; state->reason = "`on_header_field_complete` callback error"; state->error_pos = (const char*) p; @@ -8041,7 +8604,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_47: { + s_n_llhttp__internal__n_error_61: { state->error = 0xa; state->reason = "Invalid header token"; state->error_pos = (const char*) p; @@ -8093,7 +8656,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_16: { + s_n_llhttp__internal__n_pause_20: { state->error = 0x15; state->reason = "on_url_complete pause"; state->error_pos = (const char*) p; @@ -8116,7 +8679,7 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_headers_start; case 21: - goto s_n_llhttp__internal__n_pause_16; + goto s_n_llhttp__internal__n_pause_20; default: goto s_n_llhttp__internal__n_error_3; } @@ -8156,7 +8719,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_48: { + s_n_llhttp__internal__n_error_62: { state->error = 0x7; state->reason = "Expected CRLF"; state->error_pos = (const char*) p; @@ -8182,7 +8745,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_55: { + s_n_llhttp__internal__n_error_70: { state->error = 0x17; state->reason = "Pause on PRI/Upgrade"; state->error_pos = (const char*) p; @@ -8191,7 +8754,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_56: { + s_n_llhttp__internal__n_error_71: { state->error = 0x9; state->reason = "Expected HTTP/2 Connection Preface"; state->error_pos = (const char*) p; @@ -8200,7 +8763,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_53: { + s_n_llhttp__internal__n_error_68: { state->error = 0x2; state->reason = "Expected CRLF after version"; state->error_pos = (const char*) p; @@ -8209,17 +8772,17 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_16: { - switch (llhttp__internal__c_test_lenient_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_25: { + switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_headers_start; default: - goto s_n_llhttp__internal__n_error_53; + goto s_n_llhttp__internal__n_error_68; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_54: { + s_n_llhttp__internal__n_error_67: { state->error = 0x9; state->reason = "Expected CRLF after version"; state->error_pos = (const char*) p; @@ -8228,7 +8791,26 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_17: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_24: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_req_http_complete_crlf; + default: + goto s_n_llhttp__internal__n_error_67; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_69: { + state->error = 0x9; + state->reason = "Expected CRLF after version"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_21: { state->error = 0x15; state->reason = "on_version_complete pause"; state->error_pos = (const char*) p; @@ -8237,7 +8819,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_52: { + s_n_llhttp__internal__n_error_66: { state->error = 0x21; state->reason = "`on_version_complete` callback error"; state->error_pos = (const char*) p; @@ -8273,10 +8855,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_51; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_65; return s_error; } - goto s_n_llhttp__internal__n_error_51; + goto s_n_llhttp__internal__n_error_65; /* UNREACHABLE */; abort(); } @@ -8326,8 +8908,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_15: { - switch (llhttp__internal__c_test_lenient_flags_15(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_23: { + switch (llhttp__internal__c_test_lenient_flags_23(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_span_end_llhttp__on_version_1; default: @@ -8339,7 +8921,7 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_store_http_minor: { switch (llhttp__internal__c_store_http_minor(state, p, endp, match)) { default: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_15; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_23; } /* UNREACHABLE */; abort(); @@ -8354,10 +8936,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_57; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_72; return s_error; } - goto s_n_llhttp__internal__n_error_57; + goto s_n_llhttp__internal__n_error_72; /* UNREACHABLE */; abort(); } @@ -8371,10 +8953,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_58; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_73; return s_error; } - goto s_n_llhttp__internal__n_error_58; + goto s_n_llhttp__internal__n_error_73; /* UNREACHABLE */; abort(); } @@ -8396,14 +8978,14 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_59; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_74; return s_error; } - goto s_n_llhttp__internal__n_error_59; + goto s_n_llhttp__internal__n_error_74; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_50: { + s_n_llhttp__internal__n_error_64: { state->error = 0x8; state->reason = "Invalid method for HTTP/x.x request"; state->error_pos = (const char*) p; @@ -8484,13 +9066,15 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_start_llhttp__on_version; case 34: goto s_n_llhttp__internal__n_span_start_llhttp__on_version; + case 46: + goto s_n_llhttp__internal__n_span_start_llhttp__on_version; default: - goto s_n_llhttp__internal__n_error_50; + goto s_n_llhttp__internal__n_error_64; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_62: { + s_n_llhttp__internal__n_error_77: { state->error = 0x8; state->reason = "Expected HTTP/"; state->error_pos = (const char*) p; @@ -8499,7 +9083,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_60: { + s_n_llhttp__internal__n_error_75: { state->error = 0x8; state->reason = "Expected SOURCE method for ICE/x.x request"; state->error_pos = (const char*) p; @@ -8513,12 +9097,12 @@ static llparse_state_t llhttp__internal__run( case 33: goto s_n_llhttp__internal__n_span_start_llhttp__on_version; default: - goto s_n_llhttp__internal__n_error_60; + goto s_n_llhttp__internal__n_error_75; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_61: { + s_n_llhttp__internal__n_error_76: { state->error = 0x8; state->reason = "Invalid method for RTSP/x.x request"; state->error_pos = (const char*) p; @@ -8558,12 +9142,12 @@ static llparse_state_t llhttp__internal__run( case 45: goto s_n_llhttp__internal__n_span_start_llhttp__on_version; default: - goto s_n_llhttp__internal__n_error_61; + goto s_n_llhttp__internal__n_error_76; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_18: { + s_n_llhttp__internal__n_pause_22: { state->error = 0x15; state->reason = "on_url_complete pause"; state->error_pos = (const char*) p; @@ -8572,7 +9156,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_49: { + s_n_llhttp__internal__n_error_63: { state->error = 0x1a; state->reason = "`on_url_complete` callback error"; state->error_pos = (const char*) p; @@ -8586,9 +9170,9 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_req_http_start; case 21: - goto s_n_llhttp__internal__n_pause_18; + goto s_n_llhttp__internal__n_pause_22; default: - goto s_n_llhttp__internal__n_error_49; + goto s_n_llhttp__internal__n_error_63; } /* UNREACHABLE */; abort(); @@ -8661,7 +9245,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_63: { + s_n_llhttp__internal__n_error_78: { state->error = 0x7; state->reason = "Invalid char in url fragment start"; state->error_pos = (const char*) p; @@ -8721,7 +9305,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_64: { + s_n_llhttp__internal__n_error_79: { state->error = 0x7; state->reason = "Invalid char in url query"; state->error_pos = (const char*) p; @@ -8730,7 +9314,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_65: { + s_n_llhttp__internal__n_error_80: { state->error = 0x7; state->reason = "Invalid char in url path"; state->error_pos = (const char*) p; @@ -8841,7 +9425,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_66: { + s_n_llhttp__internal__n_error_81: { state->error = 0x7; state->reason = "Double @ in url"; state->error_pos = (const char*) p; @@ -8850,7 +9434,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_67: { + s_n_llhttp__internal__n_error_82: { state->error = 0x7; state->reason = "Unexpected char in url server"; state->error_pos = (const char*) p; @@ -8859,7 +9443,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_68: { + s_n_llhttp__internal__n_error_83: { state->error = 0x7; state->reason = "Unexpected char in url server"; state->error_pos = (const char*) p; @@ -8868,7 +9452,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_69: { + s_n_llhttp__internal__n_error_84: { state->error = 0x7; state->reason = "Unexpected char in url schema"; state->error_pos = (const char*) p; @@ -8877,7 +9461,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_70: { + s_n_llhttp__internal__n_error_85: { state->error = 0x7; state->reason = "Unexpected char in url schema"; state->error_pos = (const char*) p; @@ -8886,7 +9470,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_71: { + s_n_llhttp__internal__n_error_86: { state->error = 0x7; state->reason = "Unexpected start char in url"; state->error_pos = (const char*) p; @@ -8905,7 +9489,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_72: { + s_n_llhttp__internal__n_error_87: { state->error = 0x6; state->reason = "Expected space after method"; state->error_pos = (const char*) p; @@ -8914,7 +9498,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_22: { + s_n_llhttp__internal__n_pause_26: { state->error = 0x15; state->reason = "on_method_complete pause"; state->error_pos = (const char*) p; @@ -8923,7 +9507,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_89: { + s_n_llhttp__internal__n_error_106: { state->error = 0x20; state->reason = "`on_method_complete` callback error"; state->error_pos = (const char*) p; @@ -8957,7 +9541,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_90: { + s_n_llhttp__internal__n_error_107: { state->error = 0x6; state->reason = "Invalid method encountered"; state->error_pos = (const char*) p; @@ -8966,7 +9550,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_82: { + s_n_llhttp__internal__n_error_99: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -8975,7 +9559,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_80: { + s_n_llhttp__internal__n_error_97: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -8984,7 +9568,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_78: { + s_n_llhttp__internal__n_error_95: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -8993,7 +9577,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_20: { + s_n_llhttp__internal__n_pause_24: { state->error = 0x15; state->reason = "on_status_complete pause"; state->error_pos = (const char*) p; @@ -9002,7 +9586,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_75: { + s_n_llhttp__internal__n_error_91: { state->error = 0x1b; state->reason = "`on_status_complete` callback error"; state->error_pos = (const char*) p; @@ -9016,14 +9600,33 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_headers_start; case 21: - goto s_n_llhttp__internal__n_pause_20; + goto s_n_llhttp__internal__n_pause_24; default: - goto s_n_llhttp__internal__n_error_75; + goto s_n_llhttp__internal__n_error_91; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_76: { + s_n_llhttp__internal__n_error_90: { + state->error = 0xd; + state->reason = "Invalid response status"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_27: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; + default: + goto s_n_llhttp__internal__n_error_90; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_92: { state->error = 0x2; state->reason = "Expected LF after CR"; state->error_pos = (const char*) p; @@ -9032,16 +9635,25 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_18: { - switch (llhttp__internal__c_test_lenient_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_28: { + switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; default: - goto s_n_llhttp__internal__n_error_76; + goto s_n_llhttp__internal__n_error_92; } /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_93: { + state->error = 0x19; + state->reason = "Missing expected CR after response line"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_span_end_llhttp__on_status: { const unsigned char* start; int err; @@ -9052,11 +9664,11 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_res_line_almost_done; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_29; return s_error; } p++; - goto s_n_llhttp__internal__n_res_line_almost_done; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_29; /* UNREACHABLE */; abort(); } @@ -9078,7 +9690,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_77: { + s_n_llhttp__internal__n_error_94: { state->error = 0xd; state->reason = "Invalid response status"; state->error_pos = (const char*) p; @@ -9090,14 +9702,14 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_mul_add_status_code_2: { switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_error_78; + goto s_n_llhttp__internal__n_error_95; default: goto s_n_llhttp__internal__n_res_status_code_otherwise; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_79: { + s_n_llhttp__internal__n_error_96: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -9109,14 +9721,14 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_mul_add_status_code_1: { switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_error_80; + goto s_n_llhttp__internal__n_error_97; default: goto s_n_llhttp__internal__n_res_status_code_digit_3; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_81: { + s_n_llhttp__internal__n_error_98: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -9128,14 +9740,14 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_mul_add_status_code: { switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_error_82; + goto s_n_llhttp__internal__n_error_99; default: goto s_n_llhttp__internal__n_res_status_code_digit_2; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_83: { + s_n_llhttp__internal__n_error_100: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -9152,7 +9764,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_84: { + s_n_llhttp__internal__n_error_101: { state->error = 0x9; state->reason = "Expected space after version"; state->error_pos = (const char*) p; @@ -9161,7 +9773,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_21: { + s_n_llhttp__internal__n_pause_25: { state->error = 0x15; state->reason = "on_version_complete pause"; state->error_pos = (const char*) p; @@ -9170,7 +9782,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_74: { + s_n_llhttp__internal__n_error_89: { state->error = 0x21; state->reason = "`on_version_complete` callback error"; state->error_pos = (const char*) p; @@ -9206,10 +9818,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_73; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_88; return s_error; } - goto s_n_llhttp__internal__n_error_73; + goto s_n_llhttp__internal__n_error_88; /* UNREACHABLE */; abort(); } @@ -9259,8 +9871,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_17: { - switch (llhttp__internal__c_test_lenient_flags_15(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_26: { + switch (llhttp__internal__c_test_lenient_flags_23(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_span_end_llhttp__on_version_6; default: @@ -9272,7 +9884,7 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_store_http_minor_1: { switch (llhttp__internal__c_store_http_minor(state, p, endp, match)) { default: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_17; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_26; } /* UNREACHABLE */; abort(); @@ -9287,10 +9899,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_85; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_102; return s_error; } - goto s_n_llhttp__internal__n_error_85; + goto s_n_llhttp__internal__n_error_102; /* UNREACHABLE */; abort(); } @@ -9304,10 +9916,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_86; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_103; return s_error; } - goto s_n_llhttp__internal__n_error_86; + goto s_n_llhttp__internal__n_error_103; /* UNREACHABLE */; abort(); } @@ -9329,14 +9941,14 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_87; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_104; return s_error; } - goto s_n_llhttp__internal__n_error_87; + goto s_n_llhttp__internal__n_error_104; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_91: { + s_n_llhttp__internal__n_error_108: { state->error = 0x8; state->reason = "Expected HTTP/"; state->error_pos = (const char*) p; @@ -9345,7 +9957,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_19: { + s_n_llhttp__internal__n_pause_23: { state->error = 0x15; state->reason = "on_method_complete pause"; state->error_pos = (const char*) p; @@ -9396,7 +10008,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_88: { + s_n_llhttp__internal__n_error_105: { state->error = 0x8; state->reason = "Invalid word encountered"; state->error_pos = (const char*) p; @@ -9430,7 +10042,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_23: { + s_n_llhttp__internal__n_pause_27: { state->error = 0x15; state->reason = "on_message_begin pause"; state->error_pos = (const char*) p; @@ -9453,14 +10065,14 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_invoke_load_type; case 21: - goto s_n_llhttp__internal__n_pause_23; + goto s_n_llhttp__internal__n_pause_27; default: goto s_n_llhttp__internal__n_error; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_24: { + s_n_llhttp__internal__n_pause_28: { state->error = 0x15; state->reason = "on_reset pause"; state->error_pos = (const char*) p; @@ -9469,7 +10081,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_92: { + s_n_llhttp__internal__n_error_109: { state->error = 0x1f; state->reason = "`on_reset` callback error"; state->error_pos = (const char*) p; @@ -9483,9 +10095,9 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_invoke_update_finish; case 21: - goto s_n_llhttp__internal__n_pause_24; + goto s_n_llhttp__internal__n_pause_28; default: - goto s_n_llhttp__internal__n_error_92; + goto s_n_llhttp__internal__n_error_109; } /* UNREACHABLE */; abort(); diff --git a/yass/third_party/nghttp2/third-party/mruby/.dockerignore b/yass/third_party/nghttp2/third-party/mruby/.dockerignore new file mode 100644 index 0000000000..627d921ea0 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/.dockerignore @@ -0,0 +1,14 @@ +.DS_Store +.idea +.vscode +*.bak +*.iml +*.ipr +*.swp +*.tmp + +/.yardoc +/bin +/build +/doc/api +/doc/capi diff --git a/yass/third_party/nghttp2/third-party/mruby/.editorconfig b/yass/third_party/nghttp2/third-party/mruby/.editorconfig index f966739faa..a5145badd6 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.editorconfig +++ b/yass/third_party/nghttp2/third-party/mruby/.editorconfig @@ -8,37 +8,27 @@ root = true [*] charset = utf-8 end_of_line = lf -indent_size = 8 -indent_style = tab +indent_size = 2 +indent_style = space insert_final_newline = true tab_width = 8 +trim_trailing_whitespace = true [{Makefile,Makefile.*,makefile,*.mk}] -trim_trailing_whitespace = true +indent_style = tab #max_line_length = 80 -[*.{c,cc,C,cxx,cpp,h,hh,H,hxx,hpp,inc,y}] -indent_size = 2 -indent_style = space -trim_trailing_whitespace = true +#[*.{c,cc,C,cxx,cpp,h,hh,H,hxx,hpp,inc,y}] #max_line_length = 120 -[{*.rb,Rakefile,rakefile,*.rake,*.gemspec,*.gembox}] -indent_size = 2 -indent_style = space -trim_trailing_whitespace = true +#[{*.rb,Rakefile,rakefile,*.rake,*.gemspec,*.gembox}] #max_line_length = 120 # limitation to US-ASCII [*.bat] end_of_line = crlf -indent_style = space #max_line_length = 80 -[*.{yaml,yml}] -indent_size = 2 -indent_style = space +#[*.{yaml,yml}] -[*.md] -indent_size = 2 -indent_style = space +#[*.md] diff --git a/yass/third_party/nghttp2/third-party/mruby/.gitattributes b/yass/third_party/nghttp2/third-party/mruby/.gitattributes new file mode 100644 index 0000000000..0f776312d9 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/.gitattributes @@ -0,0 +1,4 @@ +* text=auto eol=lf +*.bat text eol=crlf +*.cmd text eol=crlf +*.png binary diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/dependabot.yml b/yass/third_party/nghttp2/third-party/mruby/.github/dependabot.yml index dac4cac336..ff902ec0eb 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.github/dependabot.yml +++ b/yass/third_party/nghttp2/third-party/mruby/.github/dependabot.yml @@ -1,8 +1,11 @@ # Basic set up - version: 2 updates: - + # Maintain dependencies for Ruby + - package-ecosystem: "bundler" + directory: "/" + schedule: + interval: "daily" # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/" diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/labeler.yml b/yass/third_party/nghttp2/third-party/mruby/.github/labeler.yml new file mode 100644 index 0000000000..742fc2b3f5 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/.github/labeler.yml @@ -0,0 +1,50 @@ +benchmark: + - any: + - changed-files: + - any-glob-to-any-file: + - benchmark/**/* +build: + - any: + - changed-files: + - any-glob-to-any-file: + - Makefile + - Rakefile + - build_config/**/* + - lib/**/* + - tasks/**/* +core: + - any: + - changed-files: + - any-glob-to-any-file: + - include/**/* + - mrblib/**/* + - src/**/* + - test/**/* +doc: + - any: + - changed-files: + - any-glob-to-any-file: + - CONTRIBUTING.md + - LEGAL + - LICENSE + - NEWS + - README.md + - SECURITY.md + - TODO.md + - doc/**/* + - examples/**/* +github: + - any: + - changed-files: + - any-glob-to-any-file: + - .github/**/* +mrbgems: + - any: + - changed-files: + - any-glob-to-any-file: + - mrbgems/**/* +oss-fuzz: + - any: + - changed-files: + - any-glob-to-any-file: + - oss-fuzz/**/* diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/linters/.markdown-lint.yml b/yass/third_party/nghttp2/third-party/mruby/.github/linters/.markdown-lint.yml index 5c6cbec4a3..f6c3cdd268 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.github/linters/.markdown-lint.yml +++ b/yass/third_party/nghttp2/third-party/mruby/.github/linters/.markdown-lint.yml @@ -19,5 +19,11 @@ MD025: false # MD026 no-trailing-punctuation - Trailing punctuation in heading MD026: false +# MD033/no-inline-html - Inline HTML +MD033: false + # MD040 fenced-code-language - Fenced code blocks should have a language specified MD040: false + +# MD041 first-line-heading/first-line-h1 - First line in a file should be a top-level heading +MD041: false diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/linters/.yaml-lint.yml b/yass/third_party/nghttp2/third-party/mruby/.github/linters/.yaml-lint.yml index be4c887988..f5e0ee4623 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.github/linters/.yaml-lint.yml +++ b/yass/third_party/nghttp2/third-party/mruby/.github/linters/.yaml-lint.yml @@ -4,6 +4,8 @@ extends: default rules: + comments: + min-spaces-from-content: 1 document-start: disable line-length: disable truthy: false diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/build.yml b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/build.yml index ec82c0de5f..c0a7024ecc 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/build.yml +++ b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/build.yml @@ -27,7 +27,8 @@ jobs: CXX: ${{ matrix.cxx }} LD: ${{ matrix.cc }} steps: - - uses: actions/checkout@v3 + - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" + uses: actions/checkout@v4 - name: Ruby version run: ruby -v - name: Compiler version @@ -41,7 +42,8 @@ jobs: env: MRUBY_CONFIG: ci/msvc steps: - - uses: actions/checkout@v3 + - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" + uses: actions/checkout@v4 - name: Ruby version run: ruby -v - name: Build and test diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/codeql-analysis.yml b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 10117d547f..0000000000 --- a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Code scanning - action - -on: - push: - branches-ignore: - - dependabot/** - pull_request: - schedule: - - cron: '0 19 * * 4' - -permissions: - contents: read - -jobs: - CodeQL-Build: - permissions: - actions: read # for github/codeql-action/init to get workflow details - contents: read # for actions/checkout to fetch code - security-events: write # for github/codeql-action/autobuild to send a status report - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - # Override language selection by uncommenting this and choosing your languages - # with: - # languages: go, javascript, csharp, python, cpp, java - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # ℹ️ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - # - run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/labeler.yml b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/labeler.yml new file mode 100644 index 0000000000..4d14936892 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/labeler.yml @@ -0,0 +1,15 @@ +# https://github.com/actions/labeler +name: Pull Request Labeler +on: + - pull_request_target +jobs: + triage: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + sync-labels: true diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/lint.yml b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/lint.yml index c31b74119b..b95005f2dc 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/lint.yml +++ b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/lint.yml @@ -1,3 +1,4 @@ +# https://pre-commit.com/ name: Lint on: [pull_request] @@ -6,22 +7,12 @@ permissions: contents: read jobs: - misspell: - name: Check spelling with misspell - runs-on: ubuntu-latest - steps: - - name: Check Out - uses: actions/checkout@v3 - - name: Install - run: wget -O - -q https://git.io/misspell | sh -s -- -b . - - name: Run misspell - run: git ls-files --empty-directory | xargs ./misspell -error pre-commit: name: Run pre-commit runs-on: ubuntu-latest steps: - - name: Check Out - uses: actions/checkout@v3 + - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" + uses: actions/checkout@v4 - name: Install run: | python -m pip install --upgrade pip diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/oss-fuzz.yml b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/oss-fuzz.yml index 414c750ea5..c4e0b3d10d 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/oss-fuzz.yml +++ b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/oss-fuzz.yml @@ -1,3 +1,4 @@ +# https://github.com/google/oss-fuzz name: CIFuzz on: [pull_request] permissions: @@ -10,16 +11,16 @@ jobs: - name: Build Fuzzers uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master with: - oss-fuzz-project-name: 'mruby' + oss-fuzz-project-name: "mruby" dry-run: false - name: Run Fuzzers uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master with: - oss-fuzz-project-name: 'mruby' + oss-fuzz-project-name: "mruby" fuzz-seconds: 600 dry-run: false - name: Upload Crash - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() with: name: artifacts diff --git a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/super-linter.yml b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/super-linter.yml index 538ccf072d..d250a7f98b 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.github/workflows/super-linter.yml +++ b/yass/third_party/nghttp2/third-party/mruby/.github/workflows/super-linter.yml @@ -1,3 +1,4 @@ +# https://github.com/super-linter/super-linter name: Super-Linter on: [pull_request] @@ -8,18 +9,18 @@ permissions: jobs: build: permissions: - contents: read # for actions/checkout to fetch code - statuses: write # for github/super-linter/slim to mark status of each linter run + contents: read # for actions/checkout to fetch code + statuses: write # for github/super-linter/slim to mark status of each linter run name: Lint Code Base runs-on: ubuntu-latest steps: - - name: Checkout Code - uses: actions/checkout@v3 + - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" + uses: actions/checkout@v4 with: # Full git history is needed to get a proper list of changed files within `super-linter` fetch-depth: 0 - name: Lint Code Base - uses: github/super-linter/slim@v4.10.1 + uses: super-linter/super-linter/slim@v5.7.2 env: ERROR_ON_MISSING_EXEC_BIT: true VALIDATE_BASH: true diff --git a/yass/third_party/nghttp2/third-party/mruby/.gitignore b/yass/third_party/nghttp2/third-party/mruby/.gitignore index 6a0e7e46b8..e604347b97 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.gitignore +++ b/yass/third_party/nghttp2/third-party/mruby/.gitignore @@ -1,8 +1,8 @@ -*.lock *.bak *.bc *.d *.i +*.lock *.o *.orig *.pdb @@ -13,25 +13,24 @@ *.tmp *~ .DS_Store +.ccls* .ccmalloc .svn .vscode .yardoc -.ccls* -compile_flags.txt -compile_commands.json -cscope.files -cscope.out -tags - /.git -/bin -/build -/mruby-source-*.gem - /benchmark/**/*.dat /benchmark/*.pdf /benchmark/*.png - +/bin +/build /doc/api /doc/capi +/mruby-source-*.gem +compile_commands.json +compile_flags.txt +cscope.files +cscope.out +node_modules +tags +!Gemfile.lock diff --git a/yass/third_party/nghttp2/third-party/mruby/.pre-commit-config.yaml b/yass/third_party/nghttp2/third-party/mruby/.pre-commit-config.yaml index 4c7bc52ed1..d344920fd1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/.pre-commit-config.yaml +++ b/yass/third_party/nghttp2/third-party/mruby/.pre-commit-config.yaml @@ -3,14 +3,14 @@ default_stages: [commit, push] default_language_version: # force all unspecified Python hooks to run python3 python: python3 -minimum_pre_commit_version: '2.18.1' +minimum_pre_commit_version: "2.18.1" repos: - repo: meta hooks: - id: identity - id: check-hooks-apply - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-added-large-files - id: check-case-conflict @@ -23,20 +23,22 @@ repos: - id: detect-private-key - id: end-of-file-fixer - id: file-contents-sorter + args: [--unique] files: ^codespell\.txt$ - id: fix-byte-order-marker + - id: forbid-submodules - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.3.1 + rev: v1.5.4 hooks: - id: forbid-tabs exclude: Makefile$|Makefile\..+$|makefile$|\.mk$ - id: remove-tabs - args: [--whitespaces-count, '2'] + args: [--whitespaces-count, "2"] exclude: Makefile$|Makefile\..+$|makefile$|\.mk$ - repo: https://github.com/codespell-project/codespell - rev: v2.2.2 + rev: v2.2.6 hooks: - id: codespell name: Run codespell @@ -48,8 +50,13 @@ repos: - id: script-must-not-have-extension name: Local policy is to exclude extension from all shell files types: [shell] + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 + hooks: + - id: prettier + exclude: ^doc/internal/opcode\.md$ - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.33.0 + rev: v0.38.0 hooks: - id: markdownlint name: Run markdownlint @@ -57,8 +64,17 @@ repos: entry: markdownlint -c .github/linters/.markdown-lint.yml . types: [markdown] files: \.(md|mdown|markdown)$ + - repo: https://github.com/tcort/markdown-link-check + rev: v3.11.2 + hooks: + - id: markdown-link-check + name: Run markdown-link-check + description: Checks hyperlinks in Markdown files + args: [-q] + types: [markdown] + files: \.(md|mdown|markdown)$ - repo: https://github.com/adrienverge/yamllint - rev: v1.28.0 + rev: v1.33.0 hooks: - id: yamllint name: Run yamllint diff --git a/yass/third_party/nghttp2/third-party/mruby/.prettierrc b/yass/third_party/nghttp2/third-party/mruby/.prettierrc new file mode 100644 index 0000000000..81b81d20de --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/.prettierrc @@ -0,0 +1,3 @@ +{ + "bracketSpacing": false +} diff --git a/yass/third_party/nghttp2/third-party/mruby/AUTHORS b/yass/third_party/nghttp2/third-party/mruby/AUTHORS index fce97efc9b..d21c88a0cc 100644 --- a/yass/third_party/nghttp2/third-party/mruby/AUTHORS +++ b/yass/third_party/nghttp2/third-party/mruby/AUTHORS @@ -1,10 +1,10 @@ # Authors of mruby (mruby developers) -## The List of Contributors sorted by number of commits (as of 2022-01-08 4462e3d) +## The List of Contributors sorted by number of commits (as of 2023-12-28 67cb987) - 8860 Yukihiro "Matz" Matsumoto (@matz)* + 9477 Yukihiro "Matz" Matsumoto (@matz)* 586 KOBAYASHI Shuji (@shuujii) - 441 dearblue (@dearblue)* + 533 dearblue (@dearblue)* 378 Daniel Bovensiepen (@bovi)* 346 Takeshi Watanabe (@take-cheeze)* 334 Masaki Muranaka (@monaka) @@ -12,15 +12,15 @@ 234 Jun Hiroe (@suzukaze) 220 Cremno (@cremno)* 209 Yuki Kurihara (@ksss)+ + 166 John Bampton (@jbampton) 151 Yasuhiro Matsumoto (@mattn)* 113 Carson McDonald (@carsonmcdonald) - 113 John Bampton (@jbampton) 103 Tomasz Dąbrowski (@dabroz)* 84 Akira Yumiyama (@akiray03)* 84 skandhas (@skandhas) + 81 Hiroshi Mimaki (@mimaki)* 80 Masamitsu MURASE (@masamitsu-murase) 74 Yuichiro MASUI (@masuidrive) - 73 Hiroshi Mimaki (@mimaki)* 71 Tatsuhiko Kubo (@cubicdaiya)* 65 Yuichiro Kaneko (@yui-knk)+ 64 Paolo Bosetti (@pbosetti)* @@ -63,6 +63,7 @@ 12 Kouki Ooyatsu (kaishuu0123)* 12 NAKAMURA Usaku (@unak)* 12 RIZAL Reckordp (@Reckordp)+ + 12 Ray Chason (@chasonr)* 12 Takashi Sawanaka (@sdottaka)* 12 Ukrainskiy Sergey (@ukrainskiysergey) 12 Xuejie "Rafael" Xiao (@xxuejie)* @@ -73,7 +74,6 @@ 11 takkaw (@takkaw) 10 Miura Hideki (@miura1729) 10 Narihiro Nakamura (@authorNari) - 10 Ray Chason (@chasonr)* 10 Yuichi Nishiwaki (@nyuichi) 9 Akira Mitsui (@murasesyuka)* 9 Frank Celler (@fceller) @@ -82,6 +82,7 @@ 7 Bhargava Shastry (@bshastry)* 7 Kouichi Nakanishi (@keizo042) 7 Rubyist (@expeditiousRubyist) + 7 SiZiOUS (@sizious) 7 Simon Génier (@simon-shopify) 7 Terence Lee (@hone) 7 Wataru Ashihara (@wataash)* @@ -96,6 +97,7 @@ 6 Kenji Okimoto (@okkez)+ 6 Selman ULUG (@selman) 6 Yusuke Endoh (@mame)* + 6 masahino (@masahino) 5 Chris Reuter (@suetanvil) 5 Davide D'Agostino (@DAddYE) 5 Eric Hodel (@drbrain) @@ -104,20 +106,20 @@ 5 Keita Obo (@ktaobo)* 5 Max Anselm (@silverhammermba) 5 Rodrigo Malizia (@rmalizia44)+ - 5 SiZiOUS (@sizious) 5 Syohei YOSHIDA (@syohex) 5 TOMITA Masahiro (@tmtm) 5 Yurie Yamane (@yurie)+ 5 dreamedge (@dreamedge) - 5 masahino (@masahino) 5 nkshigeru (@nkshigeru) 5 xuejianqing (@joans321) 4 Dante Catalfamo (@dantecatalfamo) 4 Goro Kikuchi (@gorogit) 4 Herwin Weststrate (@herwinw) + 4 Horimoto Yasuhiro (@komainu8) 4 Jon Moss (@maclover7) 4 Ken Muramatsu (@ken-mu)+ 4 Kohei Suzuki (@eagletmt) + 4 Lanza (@LanzaSchneider) 4 Li Yazhou (@flaneur2020) 4 Marcus Stollsteimer (@stomar) 4 NARUSE, Yui (@nurse) @@ -132,7 +134,6 @@ 3 David Turnbull (@AE9RB) 3 Franck Verrot (@franckverrot) 3 HASUMI Hitoshi (@hasumikin) - 3 Horimoto Yasuhiro (@komainu8) 3 J. Mutua (@katmutua)+ 3 Jan Berdajs (@mrbrdo) 3 Jonas Minnberg (@sasq64) @@ -141,6 +142,7 @@ 3 Nobuhiro Iwamatsu (@iwamatsu) 3 Per Lundberg (@perlun)* 3 Rob Fors (@robfors)* + 3 Robert Rowe (@CaptainJet) 3 Sebastián Katzer (@katzer)* 3 Shouji Kuboyama (@Shokuji)* 3 Shuta Kimura (@kimushu)+ @@ -173,7 +175,6 @@ 2 Kazuhiko Yamashita (@pyama86)+ 2 Kazuhiro Sera (@seratch) 2 Kuroda Daisuke (@dycoon)+ - 2 Lanza (@LanzaSchneider) 2 Lothar Scholz (@llothar) 2 Lukas Joeressen (@kext) 2 Masahiro Wakame (@vvkame)+ @@ -196,11 +197,13 @@ 1 A-Sat (@asatou)+ 1 Abinoam Praxedes Marques Junior (@abinoam) 1 Alex Wang (@nanamiwang)+ + 1 AlexDenisov (@AlexDenisov) 1 Andrew Nordman (@cadwallion) 1 Ashish Kurmi (@boahc077) 1 Atsushi Morimoto (@mynz) 1 Ben A Morgan (@BenMorganIO) 1 Benoit Daloze (@eregon) + 1 Colin MacKenzie IV (@sinisterchipmunk) 1 Daehyub Kim (@lateau) 1 Daniel Varga (@vargad) 1 Edgar Boda-Majer (@eboda) @@ -257,7 +260,6 @@ 1 Prayag Verma (@pra85) 1 Ranmocy (@ranmocy) 1 Robert McNally (@wolfmcnally) - 1 Robert Rowe (@CaptainJet) 1 Ryan Scott Lewis (@RyanScottLewis) 1 Ryo Okubo (@syucream) 1 SAkira a.k.a. Akira Suzuki (@sakisakira) @@ -281,10 +283,12 @@ 1 Yevhen Viktorov (@yevgenko) 1 Yoji SHIDARA (@darashi) 1 Yoshiori SHOJI (@yoshiori) + 1 Yuji Yokoo (@yujiyokoo) 1 Yukang (@chenyukang) 1 Yurii Nakonechnyi (@inobelar) 1 Yusuke Suzuki (@Constellation)+ 1 Yusuke Tanaka (@csouls) + 1 alpha.netzilla (@alpha-netzilla) 1 arton (@arton) 1 duangsuse (@duangsuse) 1 fl0l0u (@fl0l0u) diff --git a/yass/third_party/nghttp2/third-party/mruby/CONTRIBUTING.md b/yass/third_party/nghttp2/third-party/mruby/CONTRIBUTING.md index 61d6731223..a797b13708 100644 --- a/yass/third_party/nghttp2/third-party/mruby/CONTRIBUTING.md +++ b/yass/third_party/nghttp2/third-party/mruby/CONTRIBUTING.md @@ -26,8 +26,8 @@ A framework for managing and maintaining multi-language `pre-commit` hooks. You need to first install `pre-commit` and then install the `pre-commit` hooks with `pre-commit install`. Now `pre-commit` will run automatically on git commit! -It's usually a good idea to run the hooks against all the files when adding new hooks (usually `pre-commit` will only run on the changed files during git hooks). -Use `pre-commit run --all-files` to check all files. +It's usually a good idea to run the hooks against all the files when adding new hooks (usually `pre-commit` +will only run on the changed files during git hooks). Use `pre-commit run --all-files` to check all files. To run a single hook use `pre-commit run --all-files ` @@ -37,12 +37,16 @@ Sometimes you might need to skip one or more hooks which can be done with the `S `$ SKIP=yamllint git commit -m "foo"` -For convenience, we have added `pre-commit run --all-files` and `pre-commit autoupdate` +For convenience, we have added `pre-commit run --all-files`, `pre-commit install` and `pre-commit autoupdate` to both the Makefile and the Rakefile. Run them with: - `make check` or `rake check` +- `make checkinstall` or `rake checkinstall` - `make checkupdate` or `rake checkupdate` +To configure `pre-commit` you can modify the config file [.pre-commit-config.yaml](.pre-commit-config.yaml). +We use [GitHub Actions](.github/workflows/lint.yml) to run `pre-commit` on every pull request. + ### pre-commit quick links - [Quick start](https://pre-commit.com/#quick-start) @@ -50,21 +54,73 @@ to both the Makefile and the Rakefile. Run them with: - [pre-commit autoupdate](https://pre-commit.com/#pre-commit-autoupdate) - [Temporarily disabling hooks](https://pre-commit.com/#temporarily-disabling-hooks) -## Spell Checking +## Docker -We are running [misspell](https://github.com/client9/misspell) which is mainly written in -[Golang](https://golang.org/) to check spelling with [GitHub Actions](.github/workflows/lint.yml). -Correct commonly misspelled English words quickly with `misspell`. You can run `misspell` locally -against all files with: +We have both a `Dockerfile` and `docker-compose.yml` files in the repository root. +You can run these with the command line or use +[Docker Desktop](https://www.docker.com/products/docker-desktop/). -```bash -find . -type f | xargs ./misspell -error +The Docker image is running Debian bullseye with Ruby and Python installed. +You can build the Docker image with: + +`$ docker-compose build test` + +So far we just have one service: `test`. Running the default `docker-compose` +command will create the Docker image, spin up a container and then build and +run all mruby tests. + +The default `docker-compose` command is: + +`$ docker-compose -p mruby run test` + +You can also use Make or Rake to run the default `docker-compose` +command from above: + +- `make composetest` +- `rake composetest` + +List your Docker images with: + +```console +$ docker images +REPOSITORY TAG IMAGE ID CREATED SIZE +mruby-test latest ec60f9536948 29 seconds ago 1.29GB ``` -Notable `misspell` help options or flags are: +You can also run any custom `docker-compose` command which will override +the default. For example to run `pre-commit run --all-files` type: -- `-i` string: ignore the following corrections, comma separated -- `-w`: Overwrite file with corrections (default is just to display) +`$ docker-compose -p mruby run test pre-commit run --all-files` + +For convenience, you can also run `pre-commit` with: + +- `make composecheck` +- `rake composecheck` + +The bonus of running `pre-commit` with `docker-compose` is that you won't need +to install `pre-commit` and the hooks on your local machine. And that also +means you won't need to install `brew`, `conda` or `pip`. + +Note limitation: currently running `pre-commit` with `docker-compose` we +skip the `check-executables-have-shebangs` hook. + +Two more examples of custom `docker-compose` commands are: + +- `$ docker-compose -p mruby run test ls` +- `$ docker-compose -p mruby run test rake doc:api` + +If you want to test using a different `docker-compose` YAML config file you +can use the `-f` flag: + +`$ docker-compose -p mruby -f docker-compose.test.yml run test` + +- +- + +## Spell Checking + +We are using `pre-commit` to run [codespell](https://github.com/codespell-project/codespell) +to check code for common misspellings. We have a small custom dictionary file [codespell.txt](codespell.txt). ## Coding conventions @@ -120,7 +176,7 @@ unless there's a clear reason, e.g. the latest Ruby has changed behavior from IS ### mruby API - [YARD](https://yardoc.org/) - YARD is a documentation generation tool for the Ruby programming language -- [yard-mruby](https://rubygems.org/gems/yard-mruby) - Document MRuby sources with YARD +- [yard-mruby](https://rubygems.org/gems/yard-mruby) - Document mruby sources with YARD - [yard-coderay](https://rubygems.org/gems/yard-coderay) - Adds coderay syntax highlighting to YARD docs ### C API diff --git a/yass/third_party/nghttp2/third-party/mruby/Dockerfile b/yass/third_party/nghttp2/third-party/mruby/Dockerfile new file mode 100644 index 0000000000..c4419b4f6d --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/Dockerfile @@ -0,0 +1,13 @@ +FROM ruby:3.2.2-bullseye + +RUN apt-get update && apt-get install --no-install-recommends -y python3-pip shellcheck \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY Gemfile Gemfile.lock .pre-commit-config.yaml ./ + +RUN bundle install && pip3 install pre-commit && git init . && pre-commit install-hooks + +COPY . . diff --git a/yass/third_party/nghttp2/third-party/mruby/Doxyfile b/yass/third_party/nghttp2/third-party/mruby/Doxyfile index ece327c803..2df76d8c3c 100644 --- a/yass/third_party/nghttp2/third-party/mruby/Doxyfile +++ b/yass/third_party/nghttp2/third-party/mruby/Doxyfile @@ -1,82 +1,97 @@ -# Doxyfile 1.8.13 +# Doxyfile 1.9.6 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). +# +# Note: +# +# Use doxygen to compare the used configuration file with the template +# configuration file: +# doxygen -x [configFile] +# Use doxygen to compare the used configuration file with the template +# configuration file without replacing the environment variables or CMake type +# replacement variables: +# doxygen -x_noenv [configFile] #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- +# This tag specifies the encoding used for all characters in the configuration +# file that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# https://www.gnu.org/software/libiconv/ for the list of possible encodings. +# The default value is: UTF-8. + DOXYFILE_ENCODING = UTF-8 -PROJECT_NAME = "mruby" -PROJECT_NUMBER = 3.1.0 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = mruby + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = 3.3.0 + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = "mruby is the lightweight implementation of the Ruby language" +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + PROJECT_LOGO = doc/mruby_logo_red_icon.png +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + OUTPUT_DIRECTORY = doc/capi -USE_MDFILE_AS_MAINPAGE = README.md - -INPUT = CONTRIBUTING.md \ - README.md \ - SECURITY.md \ - TODO.md \ - src \ - include \ - include/mruby \ - mrblib \ - doc \ - doc/guides \ - doc/internal \ - LEGAL \ - LICENSE \ - NEWS - -# Red for Ruby -HTML_COLORSTYLE_HUE = 359 - -# The following expansions -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = YES -EXPAND_ONLY_PREDEF = NO -PREDEFINED = -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = NO - -# This tells doxygen to search the places that make sense -SEARCH_INCLUDES = YES -INCLUDE_PATH = include include/mruby -INCLUDE_FILE_PATTERNS = *.h - -CLANG_ASSISTED_PARSING = NO -CLANG_OPTIONS = -I./include - -# This thing creates documentation elements for everything, even when its not documented. Its a little ugly to do it right now because huge swathes of code aren't documented. -EXTRACT_ALL = NO - -# Document MRB_INLINE functions -EXTRACT_STATIC = YES - -JAVADOC_AUTOBRIEF = YES -QT_AUTOBRIEF = NO - -QUIET = YES -WARN_IF_UNDOCUMENTED = NO - -#=========================================================================== -# BELOW THIS LINE IS CRUFT GENERATED BY doxygen -g -# If you edit anything below this, bring it up here so its easier to read. -#=========================================================================== - -# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- -# directories (in 2 levels) under the output directory of each output format and -# will distribute the generated files over these directories. Enabling this +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 +# sub-directories (in 2 levels) under the output directory of each output format +# and will distribute the generated files over these directories. Enabling this # option can be useful when feeding doxygen a huge amount of source files, where # putting all generated files in the same directory would otherwise causes -# performance problems for the file system. +# performance problems for the file system. Adapt CREATE_SUBDIRS_LEVEL to +# control the number of sub-directories. # The default value is: NO. CREATE_SUBDIRS = NO +# Controls the number of sub-directories that will be created when +# CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every +# level increment doubles the number of directories, resulting in 4096 +# directories at level 8 which is the default and also the maximum value. The +# sub-directories are organized in 2 levels, the first level always has a fixed +# number of 16 directories. +# Minimum value: 0, maximum value: 8, default value: 8. +# This tag requires that the tag CREATE_SUBDIRS is set to YES. + +CREATE_SUBDIRS_LEVEL = 8 + # If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII # characters to appear in the names of generated files. If set to NO, non-ASCII # characters will be escaped, for example _xE3_x81_x84 will be used for Unicode @@ -88,14 +103,14 @@ ALLOW_UNICODE_NAMES = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, -# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), -# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, -# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), -# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, -# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, -# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, -# Ukrainian and Vietnamese. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Bulgarian, +# Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, English +# (United States), Esperanto, Farsi (Persian), Finnish, French, German, Greek, +# Hindi, Hungarian, Indonesian, Italian, Japanese, Japanese-en (Japanese with +# English messages), Korean, Korean-en (Korean with English messages), Latvian, +# Lithuanian, Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, +# Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, +# Swedish, Turkish, Ukrainian and Vietnamese. # The default value is: English. OUTPUT_LANGUAGE = English @@ -187,6 +202,32 @@ STRIP_FROM_INC_PATH = SHORT_NAMES = NO +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = YES + +# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line +# such as +# /*************** +# as being the beginning of a Javadoc-style comment "banner". If set to NO, the +# Javadoc-style will behave just like regular comments and it will not be +# interpreted by doxygen. +# The default value is: NO. + +JAVADOC_BANNER = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a # multi-line C++ special comment block (i.e. a block of //! or /// comments) as @@ -200,6 +241,14 @@ SHORT_NAMES = NO MULTILINE_CPP_IS_BRIEF = NO +# By default Python docstrings are displayed as preformatted text and doxygen's +# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the +# doxygen's special commands can be used and the contents of the docstring +# documentation blocks is shown as doxygen documentation. +# The default value is: YES. + +PYTHON_DOCSTRING = YES + # If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the # documentation from any documented member that it re-implements. # The default value is: YES. @@ -223,20 +272,19 @@ TAB_SIZE = 4 # the documentation. An alias has the form: # name=value # For example adding -# "sideeffect=@par Side Effects:\n" +# "sideeffect=@par Side Effects:^^" # will allow you to put the command \sideeffect (or @sideeffect) in the # documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. +# "Side Effects:". Note that you cannot put \n's in the value part of an alias +# to insert newlines (in the resulting output). You can put ^^ in the value part +# of an alias to insert a newline as if a physical newline was in the original +# file. When you need a literal { or } or , in the value part of an alias you +# have to escape them by means of a backslash (\), this can lead to conflicts +# with the commands \{ and \} for these it is advised to use the version @{ and +# @} or use a double escape (\\{ and \\}) ALIASES = -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. - -TCL_SUBST = - # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For # instance, some of the names that are used will be different. The list of all @@ -265,28 +313,40 @@ OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO +# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice +# sources only. Doxygen will then generate output that is more tailored for that +# language. For instance, namespaces will be presented as modules, types will be +# separated into more groups, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_SLICE = NO + # Doxygen selects the parser to use depending on the extension of the files it # parses. With this tag you can assign which parser to use for a given # extension. Doxygen has a built-in mapping, but you can override or extend it # using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: -# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: -# Fortran. In the later case the parser tries to guess whether the code is fixed -# or free formatted code, this is the default for Fortran type files), VHDL. For -# instance to make doxygen treat .inc files as Fortran files (default is PHP), -# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, +# Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice, +# VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: +# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser +# tries to guess whether the code is fixed or free formatted code, this is the +# default for Fortran type files). For instance to make doxygen treat .inc files +# as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. # # Note: For files without extension you can use no_extension as a placeholder. # # Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. +# the files are not read by doxygen. When specifying no_extension you should add +# * to the FILE_PATTERNS. +# +# Note see also the list of default file extension mappings. EXTENSION_MAPPING = no_extension=md # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. +# documentation. See https://daringfireball.net/projects/markdown/ for details. # The output of markdown processing is further processed by doxygen, so you can # mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in # case of backward compatibilities issues. @@ -298,7 +358,7 @@ MARKDOWN_SUPPORT = YES # to that level are automatically included in the table of contents, even if # they do not have an id attribute. # Note: This feature currently applies only to Markdown headings. -# Minimum value: 0, maximum value: 99, default value: 0. +# Minimum value: 0, maximum value: 99, default value: 5. # This tag requires that the tag MARKDOWN_SUPPORT is set to YES. TOC_INCLUDE_HEADINGS = 0 @@ -328,7 +388,7 @@ BUILTIN_STL_SUPPORT = NO CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen # will parse them like normal C++ but will assume all classes use public instead # of private inheritance when no explicit protection keyword is present. # The default value is: NO. @@ -414,6 +474,19 @@ TYPEDEF_HIDES_STRUCT = NO LOOKUP_CACHE_SIZE = 0 +# The NUM_PROC_THREADS specifies the number of threads doxygen is allowed to use +# during processing. When set to 0 doxygen will based this on the number of +# cores available in the system. You can set it explicitly to a value larger +# than 0 to get more control over the balance between CPU load and processing +# speed. At this moment only the input processing can be done using multiple +# threads. Since this is still an experimental feature the default is set to 1, +# which effectively disables parallel processing. Please report any issues you +# encounter. Generating dot graphs in parallel is controlled by the +# DOT_NUM_THREADS setting. +# Minimum value: 0, maximum value: 32, default value: 1. + +NUM_PROC_THREADS = 1 + #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- @@ -426,6 +499,7 @@ LOOKUP_CACHE_SIZE = 0 # normally produced when WARNINGS is set to YES. # The default value is: NO. +EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. @@ -433,6 +507,12 @@ LOOKUP_CACHE_SIZE = 0 EXTRACT_PRIVATE = NO +# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual +# methods of a class will be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIV_VIRTUAL = NO + # If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal # scope will be included in the documentation. # The default value is: NO. @@ -443,6 +523,7 @@ EXTRACT_PACKAGE = NO # included in the documentation. # The default value is: NO. +EXTRACT_STATIC = YES # If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined # locally in source files will be included in the documentation. If set to NO, @@ -469,6 +550,13 @@ EXTRACT_LOCAL_METHODS = NO EXTRACT_ANON_NSPACES = NO +# If this flag is set to YES, the name of an unnamed parameter in a declaration +# will be determined by the corresponding definition. By default unnamed +# parameters remain unnamed in the output. +# The default value is: YES. + +RESOLVE_UNNAMED_PARAMS = YES + # If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all # undocumented members inside documented classes or files. If set to NO these # members will be included in the various overviews, but no documentation @@ -480,14 +568,15 @@ HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. If set # to NO, these classes will be included in the various overviews. This option -# has no effect if EXTRACT_ALL is enabled. +# will also hide undocumented C++ concepts if enabled. This option has no effect +# if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO, these declarations will be -# included in the documentation. +# declarations. If set to NO, these declarations will be included in the +# documentation. # The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO @@ -506,12 +595,20 @@ HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = NO -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES, upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. -# The default value is: system dependent. +# With the correct setting of option CASE_SENSE_NAMES doxygen will better be +# able to match the capabilities of the underlying filesystem. In case the +# filesystem is case sensitive (i.e. it supports files in the same directory +# whose names only differ in casing), the option must be set to YES to properly +# deal with such files in case they appear in the input. For filesystems that +# are not case sensitive the option should be set to NO to properly deal with +# output files written for symbols that only differ in casing, such as for two +# classes, one named CLASS and the other named Class, and to also support +# references to files without having to specify the exact matching casing. On +# Windows (including Cygwin) and MacOS, users should typically set this option +# to NO, whereas on Linux or other Unix flavors it should typically be set to +# YES. +# Possible values are: SYSTEM, NO and YES. +# The default value is: SYSTEM. CASE_SENSE_NAMES = YES @@ -529,6 +626,12 @@ HIDE_SCOPE_NAMES = NO HIDE_COMPOUND_REFERENCE= NO +# If the SHOW_HEADERFILE tag is set to YES then the documentation for a class +# will show which file needs to be included to use the class. +# The default value is: YES. + +SHOW_HEADERFILE = YES + # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. # The default value is: YES. @@ -686,7 +789,8 @@ FILE_VERSION_FILTER = # output files in an output format independent way. To create the layout file # that represents doxygen's defaults, run doxygen with the -l option. You can # optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. +# will be used as the name of the layout file. See also section "Changing the +# layout of pages" for information. # # Note that if you run doxygen from a directory containing a file called # DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE @@ -697,7 +801,7 @@ LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files containing # the reference definitions. This must be a list of .bib files. The .bib # extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. # For LaTeX the style of the bibliography can be controlled using # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the # search path. See also \cite for info how to create references. @@ -708,6 +812,12 @@ CITE_BIB_FILES = # Configuration options related to warning and progress messages #--------------------------------------------------------------------------- +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = YES # The WARNINGS tag can be used to turn on/off the warning messages that are # generated to standard error (stderr) by doxygen. If WARNINGS is set to YES @@ -718,25 +828,51 @@ CITE_BIB_FILES = WARNINGS = YES +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = NO # If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some parameters -# in a documented function, or documenting parameters that don't exist or using -# markup commands wrongly. +# potential errors in the documentation, such as documenting some parameters in +# a documented function twice, or documenting parameters that don't exist or +# using markup commands wrongly. # The default value is: YES. WARN_IF_DOC_ERROR = YES +# If WARN_IF_INCOMPLETE_DOC is set to YES, doxygen will warn about incomplete +# function parameter documentation. If set to NO, doxygen will accept that some +# parameters have no documentation without warning. +# The default value is: YES. + +WARN_IF_INCOMPLETE_DOC = YES + # This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that # are documented, but have no documentation for their parameters or return -# value. If set to NO, doxygen will only warn about wrong or incomplete -# parameter documentation, but not about the absence of documentation. +# value. If set to NO, doxygen will only warn about wrong parameter +# documentation, but not about the absence of documentation. If EXTRACT_ALL is +# set to YES then this flag will automatically be disabled. See also +# WARN_IF_INCOMPLETE_DOC # The default value is: NO. WARN_NO_PARAMDOC = NO +# If WARN_IF_UNDOC_ENUM_VAL option is set to YES, doxygen will warn about +# undocumented enumeration values. If set to NO, doxygen will accept +# undocumented enumeration values. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: NO. + +WARN_IF_UNDOC_ENUM_VAL = NO + # If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when -# a warning is encountered. +# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS +# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but +# at the end of the doxygen process doxygen will return with a non-zero status. +# Possible values are: NO, YES and FAIL_ON_WARNINGS. # The default value is: NO. WARN_AS_ERROR = NO @@ -747,13 +883,27 @@ WARN_AS_ERROR = NO # and the warning text. Optionally the format may contain $version, which will # be replaced by the version of the file (if it could be obtained via # FILE_VERSION_FILTER) +# See also: WARN_LINE_FORMAT # The default value is: $file:$line: $text. WARN_FORMAT = "$file:$line: $text" +# In the $text part of the WARN_FORMAT command it is possible that a reference +# to a more specific place is given. To make it easier to jump to this place +# (outside of doxygen) the user can define a custom "cut" / "paste" string. +# Example: +# WARN_LINE_FORMAT = "'vi $file +$line'" +# See also: WARN_FORMAT +# The default value is: at line $line of file $file. + +WARN_LINE_FORMAT = "at line $line of file $file" + # The WARN_LOGFILE tag can be used to specify a file to which warning and error # messages should be written. If left blank the output is written to standard -# error (stderr). +# error (stderr). In case the file specified cannot be opened for writing the +# warning and error messages are written to standard error. When as file - is +# specified the warning and error messages are written to standard output +# (stdout). WARN_LOGFILE = @@ -767,16 +917,41 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. +INPUT = CONTRIBUTING.md \ + README.md \ + SECURITY.md \ + TODO.md \ + src \ + include \ + include/mruby \ + mrblib \ + doc \ + doc/guides \ + doc/internal \ + LEGAL \ + LICENSE \ + NEWS # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of -# possible encodings. +# documentation (see: +# https://www.gnu.org/software/libiconv/) for the list of possible encodings. +# See also: INPUT_FILE_ENCODING # The default value is: UTF-8. INPUT_ENCODING = UTF-8 +# This tag can be used to specify the character encoding of the source files +# that doxygen parses The INPUT_FILE_ENCODING tag can be used to specify +# character encoding on a per file pattern basis. Doxygen will compare the file +# name with each pattern and apply the encoding instead of the default +# INPUT_ENCODING) if there is a match. The character encodings are a list of the +# form: pattern=encoding (like *.php=ISO-8859-1). See cfg_input_encoding +# "INPUT_ENCODING" for further information on supported encodings. + +INPUT_FILE_ENCODING = + # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and # *.h) to filter out the source-files in the directories. @@ -785,11 +960,15 @@ INPUT_ENCODING = UTF-8 # need to set EXTENSION_MAPPING for the extension otherwise the files are not # read by doxygen. # +# Note the list of default checked file patterns might differ from the list of +# default file extension mappings. +# # If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, # *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, -# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, -# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, -# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf. +# *.hh, *.hxx, *.hpp, *.h++, *.l, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, +# *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C +# comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, +# *.vhdl, *.ucf, *.qsf and *.ice. FILE_PATTERNS = *.c \ *.cc \ @@ -871,7 +1050,7 @@ EXCLUDE_PATTERNS = # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test +# ANamespace::AClass, ANamespace::*Test # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories use the pattern */test/* @@ -919,6 +1098,11 @@ IMAGE_PATH = # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. # +# Note that doxygen will use the data processed and written to standard output +# for further processing, therefore nothing else, like debug statements or used +# commands (so in case of a Windows batch file always use @echo OFF), should be +# written to standard output. +# # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # properly processed by doxygen. @@ -953,6 +1137,22 @@ FILTER_SOURCE_FILES = NO FILTER_SOURCE_PATTERNS = +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = README.md + +# The Fortran standard specifies that for fixed formatted Fortran code all +# characters from position 72 are to be considered as comment. A common +# extension is to allow longer lines before the automatic comment starts. The +# setting FORTRAN_COMMENT_AFTER will also make it possible that longer lines can +# be processed before the automatic comment starts. +# Minimum value: 7, maximum value: 10000, default value: 72. + +FORTRAN_COMMENT_AFTER = 72 + #--------------------------------------------------------------------------- # Configuration options related to source browsing #--------------------------------------------------------------------------- @@ -980,7 +1180,7 @@ INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. +# entity all documented functions referencing it will be listed. # The default value is: NO. REFERENCED_BY_RELATION = NO @@ -1012,12 +1212,12 @@ SOURCE_TOOLTIPS = YES # If the USE_HTAGS tag is set to YES then the references to source code will # point to the HTML generated by the htags(1) tool instead of doxygen built-in # source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version +# (see https://www.gnu.org/software/global/global.html). You will need version # 4.8.6 or higher. # # To use it do the following: # - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file # - Make sure the INPUT points to the root of the source tree # - Run doxygen as normal # @@ -1039,23 +1239,6 @@ USE_HTAGS = NO VERBATIM_HEADERS = YES -# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the -# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the -# cost of reduced performance. This can be particularly helpful with template -# rich C++ code for which doxygen's built-in parser lacks the necessary type -# information. -# Note: The availability of this option depends on whether or not doxygen was -# generated with the -Duse-libclang=ON option for CMake. -# The default value is: NO. - - -# If clang assisted parsing is enabled you can provide the compiler with command -# line options that you would normally use when invoking the compiler. Note that -# the include paths will already be set by doxygen for the files and directories -# specified with INPUT and INCLUDE_PATH. -# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. - - #--------------------------------------------------------------------------- # Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- @@ -1067,17 +1250,11 @@ VERBATIM_HEADERS = YES ALPHABETICAL_INDEX = YES -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all classes will -# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag -# can be used to specify a prefix (or a list of prefixes) that should be ignored -# while generating the index headers. +# The IGNORE_PREFIX tag can be used to specify a prefix (or a list of prefixes) +# that should be ignored while generating the index headers. The IGNORE_PREFIX +# tag works for classes, function and member names. The entity will be placed in +# the alphabetical list under the first letter of the entity name that remains +# after removing the prefix. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. IGNORE_PREFIX = @@ -1156,7 +1333,12 @@ HTML_STYLESHEET = # Doxygen will copy the style sheet files to the output directory. # Note: The order of the extra style sheet files is of importance (e.g. the last # style sheet in the list overrules the setting of the previous ones in the -# list). For an example see the documentation. +# list). +# Note: Since the styling of scrollbars can currently not be overruled in +# Webkit/Chromium, the styling will be left out of the default doxygen.css if +# one or more extra stylesheets have been specified. So if scrollbar +# customization is desired it has to be added explicitly. For an example see the +# documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_STYLESHEET = @@ -1171,8 +1353,32 @@ HTML_EXTRA_STYLESHEET = HTML_EXTRA_FILES = +# The HTML_COLORSTYLE tag can be used to specify if the generated HTML output +# should be rendered with a dark or light theme. +# Possible values are: LIGHT always generate light mode output, DARK always +# generate dark mode output, AUTO_LIGHT automatically set the mode according to +# the user preference, use light mode if no preference is set (the default), +# AUTO_DARK automatically set the mode according to the user preference, use +# dark mode if no preference is set and TOGGLE allow to user to switch between +# light and dark mode via a button. +# The default value is: AUTO_LIGHT. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE = AUTO_LIGHT + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a color-wheel, see +# https://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 359 + # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use grayscales only. A +# in the HTML output. For a value of 0 the output will use gray-scales only. A # value of 255 will produce the most vivid colors. # Minimum value: 0, maximum value: 255, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. @@ -1199,6 +1405,17 @@ HTML_COLORSTYLE_GAMMA = 80 HTML_TIMESTAMP = NO +# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML +# documentation will contain a main index with vertical navigation menus that +# are dynamically created via JavaScript. If disabled, the navigation index will +# consists of multiple levels of tabs that are statically embedded in every HTML +# page. Disable this option to support browsers that do not have JavaScript, +# like the Qt help browser. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_MENUS = YES + # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. @@ -1222,13 +1439,14 @@ HTML_INDEX_NUM_ENTRIES = 100 # If the GENERATE_DOCSET tag is set to YES, additional index files will be # generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in +# environment (see: +# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To +# create a documentation set, doxygen will generate a Makefile in the HTML +# output directory. Running make will produce the docset in that directory and +# running make install will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. +# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy +# genXcode/_index.html for more information. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. @@ -1242,6 +1460,13 @@ GENERATE_DOCSET = NO DOCSET_FEEDNAME = "Doxygen generated docs" +# This tag determines the URL of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDURL = + # This tag specifies a string that should uniquely identify the documentation # set bundle. This should be a reverse domain-name style string, e.g. # com.mycompany.MyDocSet. Doxygen will append .docset to the name. @@ -1267,8 +1492,12 @@ DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three # additional HTML index files: index.hhp, index.hhc, and index.hhk. The # index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. +# on Windows. In the beginning of 2021 Microsoft took the original page, with +# a.o. the download links, offline the HTML help workshop was already many years +# in maintenance mode). You can download the HTML help workshop from the web +# archives at Installation executable (see: +# http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo +# ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe). # # The HTML Help Workshop contains a compiler that can convert all HTML output # generated by doxygen into a single compiled HTML file (.chm). Compiled HTML @@ -1298,7 +1527,7 @@ CHM_FILE = HHC_LOCATION = # The GENERATE_CHI flag controls if a separate .chi index file is generated -# (YES) or that it should be included in the master .chm file (NO). +# (YES) or that it should be included in the main .chm file (NO). # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. @@ -1343,7 +1572,8 @@ QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. @@ -1351,8 +1581,8 @@ QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). +# Folders (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. @@ -1360,30 +1590,30 @@ QHP_VIRTUAL_FOLDER = doc # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_SECT_FILTER_ATTRS = -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. +# The QHG_LOCATION tag can be used to specify the location (absolute path +# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to +# run qhelpgenerator on the generated .qhp file. # This tag requires that the tag GENERATE_QHP is set to YES. QHG_LOCATION = @@ -1426,16 +1656,28 @@ DISABLE_INDEX = NO # to work a browser that supports JavaScript, DHTML, CSS and frames is required # (i.e. any modern browser). Windows users are probably better off using the # HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can -# further fine-tune the look of the index. As an example, the default style -# sheet generated by doxygen has an example that shows how to put an image at -# the root of the tree instead of the PROJECT_NAME. Since the tree basically has -# the same information as the tab index, you could consider setting -# DISABLE_INDEX to YES when enabling this option. +# further fine tune the look of the index (see "Fine-tuning the output"). As an +# example, the default style sheet generated by doxygen has an example that +# shows how to put an image at the root of the tree instead of the PROJECT_NAME. +# Since the tree basically has the same information as the tab index, you could +# consider setting DISABLE_INDEX to YES when enabling this option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_TREEVIEW = NO +# When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the +# FULL_SIDEBAR option determines if the side bar is limited to only the treeview +# area (value NO) or if it should extend to the full height of the window (value +# YES). Setting this to YES gives a layout similar to +# https://docs.readthedocs.io with more room for contents, but less room for the +# project logo, title, and description. If either GENERATE_TREEVIEW or +# DISABLE_INDEX is set to NO, this option has no effect. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FULL_SIDEBAR = NO + # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. # @@ -1460,6 +1702,24 @@ TREEVIEW_WIDTH = 250 EXT_LINKS_IN_WINDOW = NO +# If the OBFUSCATE_EMAILS tag is set to YES, doxygen will obfuscate email +# addresses. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +OBFUSCATE_EMAILS = YES + +# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg +# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see +# https://inkscape.org) to generate formulas as SVG images instead of PNGs for +# the HTML output. These images will generally look nicer at scaled resolutions. +# Possible values are: png (the default) and svg (looks nicer but requires the +# pdf2svg or inkscape tool). +# The default value is: png. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FORMULA_FORMAT = png + # Use this tag to change the font size of LaTeX formulas included as images in # the HTML documentation. When you change the font size after a successful # doxygen run you need to manually remove any form_*.png images from the HTML @@ -1469,19 +1729,14 @@ EXT_LINKS_IN_WINDOW = NO FORMULA_FONTSIZE = 10 -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are not -# supported properly for IE 6.0, but are supported on all modern browsers. -# -# Note that when changing this option you need to delete any form_*.png files in -# the HTML output directory before the changes have effect. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. +# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands +# to create new LaTeX commands to be used in formulas as building blocks. See +# the section "Including formulas" for details. -FORMULA_TRANSPARENT = YES +FORMULA_MACROFILE = # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering +# https://www.mathjax.org) which uses client side JavaScript for the rendering # instead of using pre-rendered bitmaps. Use this if you do not have LaTeX # installed or if you want to formulas look prettier in the HTML output. When # enabled you may also need to install MathJax separately and configure the path @@ -1491,11 +1746,29 @@ FORMULA_TRANSPARENT = YES USE_MATHJAX = NO +# With MATHJAX_VERSION it is possible to specify the MathJax version to be used. +# Note that the different versions of MathJax have different requirements with +# regards to the different settings, so it is possible that also other MathJax +# settings have to be changed when switching between the different MathJax +# versions. +# Possible values are: MathJax_2 and MathJax_3. +# The default value is: MathJax_2. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_VERSION = MathJax_2 + # When MathJax is enabled you can set the default output format to be used for -# the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. +# the MathJax output. For more details about the output format see MathJax +# version 2 (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3 +# (see: +# http://docs.mathjax.org/en/latest/web/components/output.html). # Possible values are: HTML-CSS (which is slower, but has the best -# compatibility), NativeMML (i.e. MathML) and SVG. +# compatibility. This is the name for Mathjax version 2, for MathJax version 3 +# this will be translated into chtml), NativeMML (i.e. MathML. Only supported +# for NathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This +# is the name for Mathjax version 3, for MathJax version 2 this will be +# translated into HTML-CSS) and SVG. # The default value is: HTML-CSS. # This tag requires that the tag USE_MATHJAX is set to YES. @@ -1508,22 +1781,29 @@ MATHJAX_FORMAT = HTML-CSS # MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax # Content Delivery Network so you can quickly see the result without installing # MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. +# MathJax from https://www.mathjax.org before deployment. The default value is: +# - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2 +# - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3 # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest # The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax # extension names that should be enabled during MathJax rendering. For example +# for MathJax version 2 (see +# https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions): # MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# For example for MathJax version 3 (see +# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html): +# MATHJAX_EXTENSIONS = ams # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. @@ -1551,7 +1831,7 @@ MATHJAX_CODEFILE = SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be -# implemented using a web server instead of a web client using Javascript. There +# implemented using a web server instead of a web client using JavaScript. There # are two flavors of web server based searching depending on the EXTERNAL_SEARCH # setting. When disabled, doxygen will generate a PHP script for searching and # an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing @@ -1570,7 +1850,8 @@ SERVER_BASED_SEARCH = NO # # Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: http://xapian.org/). +# Xapian (see: +# https://xapian.org/). # # See the section "External Indexing and Searching" for details. # The default value is: NO. @@ -1583,8 +1864,9 @@ EXTERNAL_SEARCH = NO # # Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: http://xapian.org/). See the section "External Indexing and -# Searching" for details. +# Xapian (see: +# https://xapian.org/). See the section "External Indexing and Searching" for +# details. # This tag requires that the tag SEARCHENGINE is set to YES. SEARCHENGINE_URL = @@ -1635,21 +1917,35 @@ LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. # -# Note that when enabling USE_PDFLATEX this option is only used for generating -# bitmaps for formulas in the HTML output, but not in the Makefile that is -# written to the output directory. -# The default file is: latex. +# Note that when not enabling USE_PDFLATEX the default is latex when enabling +# USE_PDFLATEX the default is pdflatex and when in the later case latex is +# chosen this is overwritten by pdflatex. For specific output languages the +# default can have been set differently, this depends on the implementation of +# the output language. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_CMD_NAME = latex # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate # index for LaTeX. +# Note: This tag is used in the Makefile / make.bat. +# See also: LATEX_MAKEINDEX_CMD for the part in the generated output file +# (.tex). # The default file is: makeindex. # This tag requires that the tag GENERATE_LATEX is set to YES. MAKEINDEX_CMD_NAME = makeindex +# The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to +# generate index for LaTeX. In case there is no backslash (\) as first character +# it will be automatically added in the LaTeX code. +# Note: This tag is used in the generated output file (.tex). +# See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat. +# The default value is: makeindex. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_MAKEINDEX_CMD = makeindex + # If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX # documents. This may be useful for small projects and may help to save some # trees in general. @@ -1679,29 +1975,31 @@ PAPER_TYPE = a4 EXTRA_PACKAGES = -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the -# generated LaTeX document. The header should contain everything until the first -# chapter. If it is left blank doxygen will generate a standard header. See -# section "Doxygen usage" for information on how to let doxygen write the -# default header to a separate file. +# The LATEX_HEADER tag can be used to specify a user-defined LaTeX header for +# the generated LaTeX document. The header should contain everything until the +# first chapter. If it is left blank doxygen will generate a standard header. It +# is highly recommended to start with a default header using +# doxygen -w latex new_header.tex new_footer.tex new_stylesheet.sty +# and then modify the file new_header.tex. See also section "Doxygen usage" for +# information on how to generate the default header that doxygen normally uses. # -# Note: Only use a user-defined header if you know what you are doing! The -# following commands have a special meaning inside the header: $title, -# $datetime, $date, $doxygenversion, $projectname, $projectnumber, -# $projectbrief, $projectlogo. Doxygen will replace $title with the empty -# string, for the replacement values of the other commands the user is referred -# to HTML_HEADER. +# Note: Only use a user-defined header if you know what you are doing! +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. The following +# commands have a special meaning inside the header (and footer): For a +# description of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_HEADER = -# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the -# generated LaTeX document. The footer should contain everything after the last -# chapter. If it is left blank doxygen will generate a standard footer. See +# The LATEX_FOOTER tag can be used to specify a user-defined LaTeX footer for +# the generated LaTeX document. The footer should contain everything after the +# last chapter. If it is left blank doxygen will generate a standard footer. See # LATEX_HEADER for more information on how to generate a default footer and what -# special commands can be used inside the footer. -# -# Note: Only use a user-defined footer if you know what you are doing! +# special commands can be used inside the footer. See also section "Doxygen +# usage" for information on how to generate the default footer that doxygen +# normally uses. Note: Only use a user-defined footer if you know what you are +# doing! # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_FOOTER = @@ -1734,9 +2032,11 @@ LATEX_EXTRA_FILES = PDF_HYPERLINKS = YES -# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate -# the PDF file directly from the LaTeX files. Set this option to YES, to get a -# higher quality PDF documentation. +# If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as +# specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX +# files. Set this option to YES, to get a higher quality PDF documentation. +# +# See also section LATEX_CMD_NAME for selecting the engine. # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -1744,8 +2044,7 @@ USE_PDFLATEX = YES # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode # command to the generated LaTeX files. This will instruct LaTeX to keep running -# if errors occur, instead of asking the user for help. This option is also used -# when generating formulas in HTML. +# if errors occur, instead of asking the user for help. # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -1758,19 +2057,9 @@ LATEX_BATCHMODE = NO LATEX_HIDE_INDICES = NO -# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source -# code with syntax highlighting in the LaTeX output. -# -# Note that which sources are shown also depends on other settings such as -# SOURCE_BROWSER. -# The default value is: NO. -# This tag requires that the tag GENERATE_LATEX is set to YES. - -LATEX_SOURCE_CODE = NO - # The LATEX_BIB_STYLE tag can be used to specify the style to use for the # bibliography, e.g. plainnat, or ieeetr. See -# http://en.wikipedia.org/wiki/BibTeX and \cite for more info. +# https://en.wikipedia.org/wiki/BibTeX and \cite for more info. # The default value is: plain. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -1784,6 +2073,14 @@ LATEX_BIB_STYLE = plain LATEX_TIMESTAMP = NO +# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute) +# path from which the emoji images will be read. If a relative path is entered, +# it will be relative to the LATEX_OUTPUT directory. If left blank the +# LATEX_OUTPUT directory will be used. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_EMOJI_DIRECTORY = + #--------------------------------------------------------------------------- # Configuration options related to the RTF output #--------------------------------------------------------------------------- @@ -1823,9 +2120,9 @@ COMPACT_RTF = NO RTF_HYPERLINKS = NO -# Load stylesheet definitions from file. Syntax is similar to doxygen's config -# file, i.e. a series of assignments. You only have to provide replacements, -# missing definitions are set to their default value. +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# configuration file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. # # See also section "Doxygen usage" for information on how to generate the # default style sheet that doxygen normally uses. @@ -1834,22 +2131,12 @@ RTF_HYPERLINKS = NO RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an RTF document. Syntax is -# similar to doxygen's config file. A template extensions file can be generated -# using doxygen -e rtf extensionFile. +# similar to doxygen's configuration file. A template extensions file can be +# generated using doxygen -e rtf extensionFile. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_EXTENSIONS_FILE = -# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code -# with syntax highlighting in the RTF output. -# -# Note that which sources are shown also depends on other settings such as -# SOURCE_BROWSER. -# The default value is: NO. -# This tag requires that the tag GENERATE_RTF is set to YES. - -RTF_SOURCE_CODE = NO - #--------------------------------------------------------------------------- # Configuration options related to the man page output #--------------------------------------------------------------------------- @@ -1921,6 +2208,13 @@ XML_OUTPUT = xml XML_PROGRAMLISTING = YES +# If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include +# namespace members in file scope as well, matching the HTML output. +# The default value is: NO. +# This tag requires that the tag GENERATE_XML is set to YES. + +XML_NS_MEMB_FILE_SCOPE = NO + #--------------------------------------------------------------------------- # Configuration options related to the DOCBOOK output #--------------------------------------------------------------------------- @@ -1939,23 +2233,14 @@ GENERATE_DOCBOOK = NO DOCBOOK_OUTPUT = docbook -# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the -# program listings (including syntax highlighting and cross-referencing -# information) to the DOCBOOK output. Note that enabling this will significantly -# increase the size of the DOCBOOK output. -# The default value is: NO. -# This tag requires that the tag GENERATE_DOCBOOK is set to YES. - -DOCBOOK_PROGRAMLISTING = NO - #--------------------------------------------------------------------------- # Configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- # If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an -# AutoGen Definitions (see http://autogen.sf.net) file that captures the -# structure of the code including all documentation. Note that this feature is -# still experimental and incomplete at the moment. +# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures +# the structure of the code including all documentation. Note that this feature +# is still experimental and incomplete at the moment. # The default value is: NO. GENERATE_AUTOGEN_DEF = NO @@ -2006,6 +2291,16 @@ PERLMOD_MAKEVAR_PREFIX = # C-preprocessor directives found in the sources and include files. # The default value is: YES. +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names +# in the source code. If set to NO, only conditional compilation will be +# performed. Macro expansion can be done in a controlled way by setting +# EXPAND_ONLY_PREDEF to YES. +# The default value is: NO. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then # the macro expansion is limited to the macros specified with the PREDEFINED and @@ -2013,7 +2308,31 @@ PERLMOD_MAKEVAR_PREFIX = # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. +EXPAND_ONLY_PREDEF = NO +# If the SEARCH_INCLUDES tag is set to YES, the include files in the +# INCLUDE_PATH will be searched if a #include is found. +# The default value is: YES. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by the +# preprocessor. Note that the INCLUDE_PATH is not recursive, so the setting of +# RECURSIVE has no effect here. +# This tag requires that the tag SEARCH_INCLUDES is set to YES. + +INCLUDE_PATH = include \ + include/mruby + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will be +# used. +# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. + +INCLUDE_FILE_PATTERNS = *.h # The PREDEFINED tag can be used to specify one or more macro names that are # defined before the preprocessor is started (similar to the -D option of e.g. @@ -2023,6 +2342,7 @@ PERLMOD_MAKEVAR_PREFIX = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. +PREDEFINED = # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The @@ -2031,6 +2351,7 @@ PERLMOD_MAKEVAR_PREFIX = # definition found in the source code. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. +EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will # remove all references to function-like macros that are alone on a line, have @@ -2040,6 +2361,7 @@ PERLMOD_MAKEVAR_PREFIX = # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. +SKIP_FUNCTION_MACROS = NO #--------------------------------------------------------------------------- # Configuration options related to external references @@ -2087,34 +2409,10 @@ EXTERNAL_GROUPS = YES EXTERNAL_PAGES = YES -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of 'which perl'). -# The default file (with absolute path) is: /usr/bin/perl. - -PERL_PATH = /usr/bin/perl - #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- -# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram -# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to -# NO turns the diagrams off. Note that this option also works with HAVE_DOT -# disabled, but it is recommended to install and use dot, since it yields more -# powerful graphs. -# The default value is: YES. - -CLASS_DIAGRAMS = YES - -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see: -# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the -# documentation. The MSCGEN_PATH tag allows you to specify the directory where -# the mscgen tool resides. If left empty the tool is assumed to be found in the -# default search path. - -MSCGEN_PATH = - # You can include diagrams made with dia in doxygen documentation. Doxygen will # then run dia to produce the diagram and insert it in the documentation. The # DIA_PATH tag allows you to specify the directory where the dia binary resides. @@ -2133,7 +2431,7 @@ HIDE_UNDOC_RELATIONS = YES # http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent # Bell Labs. The other options in this section have no effect if this option is # set to NO -# The default value is: YES. +# The default value is: NO. HAVE_DOT = YES @@ -2147,35 +2445,50 @@ HAVE_DOT = YES DOT_NUM_THREADS = 0 -# When you want a differently looking font in the dot files that doxygen -# generates you can specify the font name using DOT_FONTNAME. You need to make -# sure dot is able to find the font, which can be done by putting it in a -# standard location or by setting the DOTFONTPATH environment variable or by -# setting DOT_FONTPATH to the directory containing the font. -# The default value is: Helvetica. +# DOT_COMMON_ATTR is common attributes for nodes, edges and labels of +# subgraphs. When you want a differently looking font in the dot files that +# doxygen generates you can specify fontname, fontcolor and fontsize attributes. +# For details please see Node, +# Edge and Graph Attributes specification You need to make sure dot is able +# to find the font, which can be done by putting it in a standard location or by +# setting the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the +# directory containing the font. Default graphviz fontsize is 14. +# The default value is: fontname=Helvetica,fontsize=10. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_FONTNAME = Helvetica +DOT_COMMON_ATTR = "fontname=Helvetica,fontsize=10" -# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of -# dot graphs. -# Minimum value: 4, maximum value: 24, default value: 10. +# DOT_EDGE_ATTR is concatenated with DOT_COMMON_ATTR. For elegant style you can +# add 'arrowhead=open, arrowtail=open, arrowsize=0.5'. Complete documentation about +# arrows shapes. +# The default value is: labelfontname=Helvetica,labelfontsize=10. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_FONTSIZE = 10 +DOT_EDGE_ATTR = "labelfontname=Helvetica,labelfontsize=10" -# By default doxygen will tell dot to use the default font as specified with -# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set -# the path where dot can find it using this tag. +# DOT_NODE_ATTR is concatenated with DOT_COMMON_ATTR. For view without boxes +# around nodes set 'shape=plain' or 'shape=plaintext' Shapes specification +# The default value is: shape=box,height=0.2,width=0.4. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_NODE_ATTR = "shape=box,height=0.2,width=0.4" + +# You can set the path where dot can find font specified with fontname in +# DOT_COMMON_ATTR and others dot attributes. # This tag requires that the tag HAVE_DOT is set to YES. DOT_FONTPATH = -# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for -# each documented class showing the direct and indirect inheritance relations. -# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO. +# If the CLASS_GRAPH tag is set to YES (or GRAPH) then doxygen will generate a +# graph for each documented class showing the direct and indirect inheritance +# relations. In case HAVE_DOT is set as well dot will be used to draw the graph, +# otherwise the built-in generator will be used. If the CLASS_GRAPH tag is set +# to TEXT the direct and indirect inheritance relations will be shown as texts / +# links. +# Possible values are: NO, YES, TEXT and GRAPH. # The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. CLASS_GRAPH = YES @@ -2189,7 +2502,8 @@ CLASS_GRAPH = YES COLLABORATION_GRAPH = YES # If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for -# groups, showing the direct groups dependencies. +# groups, showing the direct groups dependencies. See also the chapter Grouping +# in the manual. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. @@ -2212,10 +2526,32 @@ UML_LOOK = NO # but if the number exceeds 15, the total amount of fields shown is limited to # 10. # Minimum value: 0, maximum value: 100, default value: 10. -# This tag requires that the tag HAVE_DOT is set to YES. +# This tag requires that the tag UML_LOOK is set to YES. UML_LIMIT_NUM_FIELDS = 10 +# If the DOT_UML_DETAILS tag is set to NO, doxygen will show attributes and +# methods without types and arguments in the UML graphs. If the DOT_UML_DETAILS +# tag is set to YES, doxygen will add type and arguments for attributes and +# methods in the UML graphs. If the DOT_UML_DETAILS tag is set to NONE, doxygen +# will not generate fields with class member information in the UML graphs. The +# class diagrams will look similar to the default class diagrams but using UML +# notation for the relationships. +# Possible values are: NO, YES and NONE. +# The default value is: NO. +# This tag requires that the tag UML_LOOK is set to YES. + +DOT_UML_DETAILS = NO + +# The DOT_WRAP_THRESHOLD tag can be used to set the maximum number of characters +# to display on a single line. If the actual line length exceeds this threshold +# significantly it will wrapped across multiple lines. Some heuristics are apply +# to avoid ugly line breaks. +# Minimum value: 0, maximum value: 1000, default value: 17. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_WRAP_THRESHOLD = 17 + # If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and # collaboration graphs will show the relations between templates and their # instances. @@ -2282,6 +2618,13 @@ GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES +# The DIR_GRAPH_MAX_DEPTH tag can be used to limit the maximum number of levels +# of child directories generated in directory dependency graphs by dot. +# Minimum value: 1, maximum value: 25, default value: 1. +# This tag requires that the tag DIRECTORY_GRAPH is set to YES. + +DIR_GRAPH_MAX_DEPTH = 1 + # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. For an explanation of the image formats see the section # output formats in the documentation of the dot tool (Graphviz (see: @@ -2289,9 +2632,7 @@ DIRECTORY_GRAPH = YES # Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order # to make the SVG files visible in IE 9+ (other browsers do not have this # requirement). -# Possible values are: png, png:cairo, png:cairo:cairo, png:cairo:gd, png:gd, -# png:gd:gd, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd, gif, gif:cairo, -# gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd, png:cairo, +# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo, # png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and # png:gdiplus:gdiplus. # The default value is: png. @@ -2337,10 +2678,10 @@ MSCFILE_DIRS = DIAFILE_DIRS = # When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the -# path where java can find the plantuml.jar file. If left blank, it is assumed -# PlantUML is not used or called during a preprocessing step. Doxygen will -# generate a warning when it encounters a \startuml command in this case and -# will not generate output for the diagram. +# path where java can find the plantuml.jar file or to the filename of jar file +# to be used. If left blank, it is assumed PlantUML is not used or called during +# a preprocessing step. Doxygen will generate a warning when it encounters a +# \startuml command in this case and will not generate output for the diagram. PLANTUML_JAR_PATH = @@ -2378,18 +2719,6 @@ DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 0 -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, because dot on Windows does not seem -# to support this out of the box. -# -# Warning: Depending on the platform used, enabling this option may lead to -# badly anti-aliased labels on the edges of a graph (i.e. they become hard to -# read). -# The default value is: NO. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_TRANSPARENT = NO - # Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) support @@ -2402,14 +2731,18 @@ DOT_MULTI_TARGETS = NO # If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page # explaining the meaning of the various boxes and arrows in the dot generated # graphs. +# Note: This tag requires that UML_LOOK isn't set, i.e. the doxygen internal +# graphical representation for inheritance and collaboration diagrams is used. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. GENERATE_LEGEND = YES -# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot +# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate # files that are used to generate the various graphs. +# +# Note: This setting is not only used for dot files but also for msc temporary +# files. # The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. DOT_CLEANUP = YES diff --git a/yass/third_party/nghttp2/third-party/mruby/Gemfile b/yass/third_party/nghttp2/third-party/mruby/Gemfile new file mode 100644 index 0000000000..497e42ffc2 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/Gemfile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +gem 'rake' +gem 'yard' +gem 'yard-coderay' +gem 'yard-mruby' diff --git a/yass/third_party/nghttp2/third-party/mruby/Gemfile.lock b/yass/third_party/nghttp2/third-party/mruby/Gemfile.lock new file mode 100644 index 0000000000..37e5d651fd --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/Gemfile.lock @@ -0,0 +1,27 @@ +GEM + remote: https://rubygems.org/ + specs: + coderay (1.1.3) + rake (13.0.6) + webrick (1.7.0) + yard (0.9.28) + webrick (~> 1.7.0) + yard-coderay (0.1.0) + coderay + yard + yard-mruby (0.3.0) + yard (~> 0.9.0) + +PLATFORMS + ruby + x86_64-darwin-21 + x86_64-linux + +DEPENDENCIES + rake + yard + yard-coderay + yard-mruby + +BUNDLED WITH + 2.4.10 diff --git a/yass/third_party/nghttp2/third-party/mruby/LICENSE b/yass/third_party/nghttp2/third-party/mruby/LICENSE index 7461282a34..b21dbf39e0 100644 --- a/yass/third_party/nghttp2/third-party/mruby/LICENSE +++ b/yass/third_party/nghttp2/third-party/mruby/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2010-2023 mruby developers +Copyright (c) 2010- mruby developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/yass/third_party/nghttp2/third-party/mruby/NEWS b/yass/third_party/nghttp2/third-party/mruby/NEWS index 34cf845288..7144b3a86b 100644 --- a/yass/third_party/nghttp2/third-party/mruby/NEWS +++ b/yass/third_party/nghttp2/third-party/mruby/NEWS @@ -1,64 +1,189 @@ NEWS ---- -# User visible changes in `mruby3.2` +# User visible changes in `mruby3.3` from `mruby3.2` + +"**_NOTE_**:" are changes to be aware of. # The language -- Now `a::B = c` should evaluate `a` then `c`. -- Anonymous arguments `*`, `**`, `&` can be passed for forwarding. -- Multi-precision integer is available now via `mruby-bigint` gem. +- aliases work properly with `super` ([2ad3f0e](https://github.com/mruby/mruby/commit/2ad3f0e)) +- `callee` method work differently with aliases in mruby ([f2dc76e](https://github.com/mruby/mruby/commit/f2dc76e)) +- define `Kernel#respond_to_missing?` method ([347586e](https://github.com/mruby/mruby/commit/347586e)) +- `_inspect` method (`inspect` with recursive check) is removed + ([e2bbf75](https://github.com/mruby/mruby/commit/e2bbf75), [5cb0c74](https://github.com/mruby/mruby/commit/5cb0c74), [113565a](https://github.com/mruby/mruby/commit/113565a), + [0713f2a](https://github.com/mruby/mruby/commit/0713f2a), [6ae6b63](https://github.com/mruby/mruby/commit/6ae6b63), [fc9fffc](https://github.com/mruby/mruby/commit/fc9fffc)) +- `__printstr__` method is removed; use `print` instead + ([acecee0](https://github.com/mruby/mruby/commit/acecee0), [192e6e3](https://github.com/mruby/mruby/commit/192e6e3)) +- New method `String#bytesplice` ([5274647](https://github.com/mruby/mruby/commit/5274647), [a2e2e83](https://github.com/mruby/mruby/commit/a2e2e83)) +- Allow `return` in blocks to cross C boundaries ([#6125](https://github.com/mruby/mruby/pull/6125)) -# mruby VM and bytecode +# Configuration -- `OP_ARYDUP` was renamed to `OP_ARYSPLAT`. The instruction name - was changed but instruction number and basic behavior have not - changed (except that `ARYDUP nil` makes `[]`). +- mruby can be built using Docker now. Try `docker-compose build` for example. ([#5961](https://github.com/mruby/mruby/pull/5961)) +- New Platform: DJGPP (MS-DOS) ([#6022](https://github.com/mruby/mruby/pull/6022)) +- New Platform: Nintendo Wii ([#6086](https://github.com/mruby/mruby/pull/6086)) +- Improved Platform: Android ([#6013](https://github.com/mruby/mruby/pull/6013)) +- Improved Platform: Dreamcast ([#6130](https://github.com/mruby/mruby/pull/6130)) +- Allow tests to be disabled for specific gems; warn about disabled tests ([#6012](https://github.com/mruby/mruby/pull/6012)) +- Replace `MRB_NO_DIRECT_THREADING` with `MRB_USE_VM_SWITCH_DISPATCH` ([#5902](https://github.com/mruby/mruby/pull/5902)) -# Tools +# mruby memory API -## `mruby` +- `mrb_default_allocf` can be overridden by the application ([34c5d96](https://github.com/mruby/mruby/commit/34c5d96)) +- `mrb_open_allocf` will be deprecated ([cfee5c2](https://github.com/mruby/mruby/commit/cfee5c2)) -- `-b` only specifies the script is the binary. The files loaded by `-r` are not affected by the option. -- `mruby` now loads complied binary if the suffix is `.mrb`. +# Changes in C API -## `mrbc` +- add new error handling API functions ([8c8bbd9](https://github.com/mruby/mruby/commit/8c8bbd9)) +- Add `mrb_vm_ci_env_clear()` function with `MRB_API` ([#5945](https://github.com/mruby/mruby/pull/5945)) +- a new function `mrb_check_frozen_value()` ([ccdf75c](https://github.com/mruby/mruby/commit/ccdf75c)) +- avoid formatting in `mrb_bug()` ([82a48bd](https://github.com/mruby/mruby/commit/82a48bd))
+ **_NOTE_**: If you are using it, you must give a simple string or replace it with a call to `mrb_raise()` series. +- stop using `mrbc_` prefix for compiler context ([c5e3cbe](https://github.com/mruby/mruby/commit/c5e3cbe))
+ The same names are provided as before, but we recommend replacing them. +- Allow `Class#allocate` to be prohibited + ([#5979](https://github.com/mruby/mruby/pull/5979), [#6122](https://github.com/mruby/mruby/pull/6122), [#6123](https://github.com/mruby/mruby/pull/6123))
+ To disable `#allocate`, use `MRB_UNDEF_ALLOCATOR()`. + This is also automatically applied when the subclass is created, but to explicitly allow it, use `MRB_DEFINE_ALLOCATOR()`. -- Add `--no-optimize` option to disable optimization. +# Changes in mrbgems -# mrbgems +- **default.gembox**: Add mruby debugger mrdb (`mruby-bin-debugger`) ([#5966](https://github.com/mruby/mruby/pull/5966)) +- **mruby-bin-config**: new options `--cxx`, `--cxxflags`, `--as`, `--asflags`, `--objc`, `--objcflags` ([#6054](https://github.com/mruby/mruby/pull/6054)) +- **mruby-binding**: renamed from `mruby-binding-core` of mruby3.2 ([11af5db](https://github.com/mruby/mruby/commit/11af5db))
+ **_NOTE_**: If using `mruby-binding-core` of mruby 3.2, replace it with `mruby-binding`. +- **mruby-binding**: implemented `Binding#initialize_copy` method ([#5517](https://github.com/mruby/mruby/pull/5517)) +- **mruby-binding**: `Kernel#binding` responds only to calls from Ruby ([#5981](https://github.com/mruby/mruby/pull/5981)) +- **mruby-compar-ext**: Comparable#clamp to accept nil as arguments ([836bebc](https://github.com/mruby/mruby/commit/836bebc)) +- **mruby-compiler**: add print name for identifier tokens ([d7b2e3a](https://github.com/mruby/mruby/commit/d7b2e3a)) +- **mruby-data**: allow empty Data ([927a9df](https://github.com/mruby/mruby/commit/927a9df)) +- **mruby-enumerator**: remove internal attribute methods `obj`, `args`, `kwd`, `meth`, `fib`. ([735fa24](https://github.com/mruby/mruby/commit/735fa24)) +- **mruby-enumerator**: add Enumerator#size ([861f8bd](https://github.com/mruby/mruby/commit/861f8bd)) +- **mruby-eval**: merged `mruby-binding` of mruby3.2 ([501b22a](https://github.com/mruby/mruby/commit/501b22a), [#5989](https://github.com/mruby/mruby/pull/5989))
+ **_NOTE_**: If using `mruby-binding` of mruby 3.2, replace it with `mruby-eval`. +- **mruby-fiber**: Add a new `mrb_fiber_new()` with `MRB_API` ([#6097](https://github.com/mruby/mruby/pull/6097)) +- **mruby-fiber**: Allows calling `Fiber#resume` from C ([#6106](https://github.com/mruby/mruby/pull/6106)) +- **mruby-fiber**: `Fiber#to_s` format changed ([#6105](https://github.com/mruby/mruby/pull/6105)) +- **mruby-io**: add File#atime and File#ctime ([321cfe9](https://github.com/mruby/mruby/commit/321cfe9)) +- **mruby-io**: Add "x" mode option for `IO.open` ([#6081](https://github.com/mruby/mruby/pull/6081)) +- **mruby-io**: File.new should not take blocks ([53de964](https://github.com/mruby/mruby/commit/53de964)) +- **mruby-method**: `Method#to_s` format changed ([f5bc82f](https://github.com/mruby/mruby/commit/f5bc82f), [02f189c](https://github.com/mruby/mruby/commit/02f189c)) +- **mruby-numeric-ext**: `int.pow(n,m)` to take bigint as exponential ([d482eab](https://github.com/mruby/mruby/commit/d482eab)) +- **mruby-pack**: support new directives `j`, `J`, `b`, `B`, `#` + ([2a1e3a5](https://github.com/mruby/mruby/commit/2a1e3a5), [e7021f1](https://github.com/mruby/mruby/commit/e7021f1), [e17f325](https://github.com/mruby/mruby/commit/e17f325)) +- **mruby-range-ext**: new method `Range#overlap?` ([384d0e2](https://github.com/mruby/mruby/commit/384d0e2)) +- **mruby-string-ext**: Add `String#valid_encoding?` method ([eabe2d9](https://github.com/mruby/mruby/commit/eabe2d9)) +- **mruby-struct**: allow empty Struct when a name is not given ([c212ede](https://github.com/mruby/mruby/commit/c212ede)) +- **mruby-time**: should allow year before 1900 ([e5de08b](https://github.com/mruby/mruby/commit/e5de08b)) +- **mruby-time**: support bigint to time_t if necessary ([7096d27](https://github.com/mruby/mruby/commit/7096d27)) +- **mruby-time**: need to handle negative time_t ([b064d7e](https://github.com/mruby/mruby/commit/b064d7e)) -## mruby-class-ext +# Changes in build system -- Add `Class#subclasses` method. -- Add `Module#undefined_instance_methods` method. +- Extended `rake install` task ([#5928](https://github.com/mruby/mruby/pull/5928))
+ **_NOTE_**: Due to this impact, executable files in the `mruby/bin/` directory by default are now symbolic links (batch files on Windows). + If previously relied on those executables, should be replaced with direct references to the entity created under the build directory (e.g. `mruby/build/host/bin/`). +- Encode and decode escape characters for presym ([#6011](https://github.com/mruby/mruby/pull/6011)) +- Rakefile: remove default build target directories in `deep_clean` ([#6032](https://github.com/mruby/mruby/pull/6032), [1e38569](https://github.com/mruby/mruby/commit/1e38569)) -## New bundled gems +# Other breaking changes -- mruby-errno from [https://github.com/iij/mruby-errno.git] -- mruby-set from [https://github.com/yui-knk/mruby-set.git] -- mruby-dir from [https://github.com/iij/mruby-dir.git] +- `mrb_f_raise()` is now an internal function + ([#5923](https://github.com/mruby/mruby/pull/5923), [#6070](https://github.com/mruby/mruby/pull/6070)) +- `mrb_make_exception()` is now an internal function with different parameters + ([431f83e](https://github.com/mruby/mruby/commit/431f83e), [78137f3](https://github.com/mruby/mruby/commit/78137f3)) +- The `File#path` method no longer uses the `#to_path` method for implicit conversion + ([d86c4a7](https://github.com/mruby/mruby/commit/d86c4a7)) +- stop mrb isolation for each test file ([a20fbe5](https://github.com/mruby/mruby/commit/a20fbe5)) +- RBreak remembers the CI location ([#6103](https://github.com/mruby/mruby/pull/6103)) -# CVEs +# Bugs Fixed -Following CVEs are fixed. +- [#5724](https://github.com/mruby/mruby/issues/5724) Rational#\*\* is missing +- [#5725](https://github.com/mruby/mruby/issues/5725) weird const_missing exceptions in mrblib code +- [#5789](https://github.com/mruby/mruby/issues/5789) No memory release of backtrace information due to stack error +- [#5932](https://github.com/mruby/mruby/issues/5932) How to create a block using the C API? mrb_yield keeps crashing! +- [#5943](https://github.com/mruby/mruby/issues/5943) TCPSocket#write is failed +- [#5944](https://github.com/mruby/mruby/issues/5944) Behavior of calling method with a hash variable +- [#5946](https://github.com/mruby/mruby/pull/5946) Don't switch constant search path from modules to Object +- [#5949](https://github.com/mruby/mruby/issues/5949) Caller appears to report wrong line when block passed and brackets omitted +- [0906cd7](https://github.com/mruby/mruby/commit/0906cd7) numeric.c: fix rounding function issues with big numbers +- [#5974](https://github.com/mruby/mruby/issues/5974) Invalid escape sequences in gem_init.c on windows +- [#5975](https://github.com/mruby/mruby/issues/5975) Equals comparison fails on extreme ends of 64-bit integers +- [#5985](https://github.com/mruby/mruby/issues/5985) Sign extension with OP_LOADI32 in get_int_operand() +- [#5986](https://github.com/mruby/mruby/issues/5986) Fix bugs in String#bytesplice +- [#5987](https://github.com/mruby/mruby/issues/5987) ~(-1 << 64) is incorrect +- [#5991](https://github.com/mruby/mruby/issues/5991) 'gets' method not working in mruby-3.2.0 +- [#5994](https://github.com/mruby/mruby/pull/5994) fix typo in mrbgems/mruby-io/src/io.c +- [#5995](https://github.com/mruby/mruby/issues/5995) One seemingly unnecessary parameter is passed in the block parameters +- [#6008](https://github.com/mruby/mruby/pull/6008) Make "bintest" independent of directory +- [b47c8b7](https://github.com/mruby/mruby/commit/b47c8b7) gc.c (clear_all_old): fix a generational GC bug +- [#6029](https://github.com/mruby/mruby/issues/6029) mruby build fails under mrbgems directory +- [a264965](https://github.com/mruby/mruby/commit/a264965) mruby-os-memsize/memsize.c: fix irep size calculation +- [3310e10](https://github.com/mruby/mruby/commit/3310e10) mruby-test/mrbgem.rake: fix mrb_state handling bug +- [#6041](https://github.com/mruby/mruby/issues/6041) GC Performance may have degraded +- [#6044](https://github.com/mruby/mruby/issues/6044) Generated presym/table.h contains invalid characters +- [#6051](https://github.com/mruby/mruby/issues/6051) Null pointer dereference in mrb_addrinfo_unix_path +- [#6052](https://github.com/mruby/mruby/issues/6052) Null pointer dereference while handling the Proc class +- [#6055](https://github.com/mruby/mruby/pull/6055) Fix libmruby name for VisualC++ +- [#6060](https://github.com/mruby/mruby/issues/6060) SEGFAULT Issue Related to Fiber Usage in ngx_mruby Development +- [#6061](https://github.com/mruby/mruby/issues/6061) Performance issue in String#codepoints +- [#6064](https://github.com/mruby/mruby/issues/6064) MRUBY_PACKAGE_DIR does not always have a value. +- [#6065](https://github.com/mruby/mruby/issues/6065) Null pointer dereference while handling the Proc class +- [#6066](https://github.com/mruby/mruby/issues/6066) Null pointer dereference involving Struct.new() +- [#6067](https://github.com/mruby/mruby/issues/6067) Null pointer dereference in mrb_string_value_cstr +- [#6068](https://github.com/mruby/mruby/issues/6068) Stack overflow in mrb_vm_exec +- [#6076](https://github.com/mruby/mruby/pull/6076) Fixed unwinding block that could point to invalid PC +- [#6084](https://github.com/mruby/mruby/issues/6084) Incorrect symbolic sinks in binary built on Linux +- [#6087](https://github.com/mruby/mruby/issues/6087) 'Remote branch HEAD not found in upstream origin' error on build +- [#6089](https://github.com/mruby/mruby/issues/6089) binding.eval() handles def expressions differently from CRuby +- [#6098](https://github.com/mruby/mruby/issues/6098) Fails to call superclass of wrapped method +- [#6099](https://github.com/mruby/mruby/issues/6099) `ensure` section is not executed if the function exits via a return in a proc +- [#6108](https://github.com/mruby/mruby/issues/6108) VM crashes with break +- [#6118](https://github.com/mruby/mruby/pull/6118) Fixed IO#read with buf +- [#6120](https://github.com/mruby/mruby/pull/6120) Set EBADF if check_file_descriptor() fails +- [#6126](https://github.com/mruby/mruby/pull/6126) Fixed return value of `OP_RETURN_BLK` called directly under C function +- [#6134](https://github.com/mruby/mruby/issues/6134) String#unpack1 returns an array instead of a single string +- [#6136](https://github.com/mruby/mruby/pull/6136) Fixed when combined `mrb_fiber_resume()` and `Fiber#transfer` -- [CVE-2022-0080](https://nvd.nist.gov/vuln/detail/CVE-2022-0080) -- [CVE-2022-0240](https://nvd.nist.gov/vuln/detail/CVE-2022-0240) -- [CVE-2022-0326](https://nvd.nist.gov/vuln/detail/CVE-2022-0326) -- [CVE-2022-0631](https://nvd.nist.gov/vuln/detail/CVE-2022-0631) -- [CVE-2022-0481](https://nvd.nist.gov/vuln/detail/CVE-2022-0481) -- [CVE-2022-0525](https://nvd.nist.gov/vuln/detail/CVE-2022-0525) -- [CVE-2022-0570](https://nvd.nist.gov/vuln/detail/CVE-2022-0570) -- [CVE-2022-0614](https://nvd.nist.gov/vuln/detail/CVE-2022-0614) -- [CVE-2022-0623](https://nvd.nist.gov/vuln/detail/CVE-2022-0623) -- [CVE-2022-0630](https://nvd.nist.gov/vuln/detail/CVE-2022-0630) -- [CVE-2022-0631](https://nvd.nist.gov/vuln/detail/CVE-2022-0631) -- [CVE-2022-0632](https://nvd.nist.gov/vuln/detail/CVE-2022-0632) -- [CVE-2022-0717](https://nvd.nist.gov/vuln/detail/CVE-2022-0717) -- [CVE-2022-0890](https://nvd.nist.gov/vuln/detail/CVE-2022-0890) -- [CVE-2022-1106](https://nvd.nist.gov/vuln/detail/CVE-2022-1106) -- [CVE-2022-1212](https://nvd.nist.gov/vuln/detail/CVE-2022-1212) -- [CVE-2022-1276](https://nvd.nist.gov/vuln/detail/CVE-2022-1276) -- [CVE-2022-1286](https://nvd.nist.gov/vuln/detail/CVE-2022-1286) -- [CVE-2022-1934](https://nvd.nist.gov/vuln/detail/CVE-2022-1934) +# Pull Requests (User Visible Ones) + +- [#5517](https://github.com/mruby/mruby/pull/5517) Fixed local variables not separated between copied binding objects +- [#5902](https://github.com/mruby/mruby/pull/5902) Replace `MRB_NO_DIRECT_THREADING` with `MRB_USE_VM_SWITCH_DISPATCH` +- [#5923](https://github.com/mruby/mruby/pull/5923) Demotion `mrb_f_raise()` from `MRB_API` +- [#5928](https://github.com/mruby/mruby/pull/5928) Improved `rake install` +- [#5945](https://github.com/mruby/mruby/pull/5945) Avoid exposure for `REnv` objects +- [#5946](https://github.com/mruby/mruby/pull/5946) Don't switch constant search path from modules to Object +- [#5966](https://github.com/mruby/mruby/pull/5966) Update default.gembox add mruby debugger mrdb +- [#5979](https://github.com/mruby/mruby/pull/5979) Allow Class#allocate to be prohibited +- [#5981](https://github.com/mruby/mruby/pull/5981) `Kernel#binding` responds only to calls from Ruby +- [#5989](https://github.com/mruby/mruby/pull/5989) Integrate mruby-binding-eval into mruby-eval +- [#5961](https://github.com/mruby/mruby/pull/5961) Add Docker to build and run all mruby tests. Run pre-commit and generate YARD docs with Docker +- [#5994](https://github.com/mruby/mruby/pull/5994) fix typo in mrbgems/mruby-io/src/io.c +- [#6008](https://github.com/mruby/mruby/pull/6008) Make "bintest" independent of directory +- [#6009](https://github.com/mruby/mruby/pull/6009) Avoid adding /bintest which does not exist +- [#6011](https://github.com/mruby/mruby/pull/6011) Encode and decode escape characters for presym +- [#6012](https://github.com/mruby/mruby/pull/6012) Allow tests to be disabled for specific gems; warn about disabled tests +- [#6013](https://github.com/mruby/mruby/pull/6013) Fix Android toolchain +- [#6022](https://github.com/mruby/mruby/pull/6022) Build configuration for MS-DOS and DJGPP +- [#6032](https://github.com/mruby/mruby/pull/6032) Rake: update task clean to remove bin and build folders +- [#6045](https://github.com/mruby/mruby/pull/6045) Fixes escape sequence bug and enhancements in Presym scanning +- [#6054](https://github.com/mruby/mruby/pull/6054) Extends `bin/mruby-config` +- [#6055](https://github.com/mruby/mruby/pull/6055) Fix libmruby name for VisualC++ +- [#6070](https://github.com/mruby/mruby/pull/6070) Demotion mrb_f_raise() in kernel.c from MRB_API too +- [#6076](https://github.com/mruby/mruby/pull/6076) Fixed unwinding block that could point to invalid PC +- [#6081](https://github.com/mruby/mruby/pull/6081) Add "x" mode option for IO.open +- [#6086](https://github.com/mruby/mruby/pull/6086) Add build config for Nintendo Wii +- [#6097](https://github.com/mruby/mruby/pull/6097) Add a new mrb_fiber_new() with MRB_API +- [#6103](https://github.com/mruby/mruby/pull/6103) RBreak remembers the CI location +- [#6105](https://github.com/mruby/mruby/pull/6105) Implement `Fiber#to_s` method +- [#6106](https://github.com/mruby/mruby/pull/6106) Ease fiber limitations +- [#6118](https://github.com/mruby/mruby/pull/6118) Fixed IO#read with buf +- [#6120](https://github.com/mruby/mruby/pull/6120) Set EBADF if check_file_descriptor() fails +- [#6122](https://github.com/mruby/mruby/pull/6122) Prohibit `Class#allocate` in a different way +- [#6123](https://github.com/mruby/mruby/pull/6123) Inherit `MRB_FL_UNDEF_ALLOCATE` in subclasses +- [#6125](https://github.com/mruby/mruby/pull/6125) Allow `OP_RETURN_BLK` to cross C boundaries +- [#6126](https://github.com/mruby/mruby/pull/6126) Fixed return value of `OP_RETURN_BLK` called directly under C function +- [#6130](https://github.com/mruby/mruby/pull/6130) `dreamcast_shelf build config`: complete overhaul +- [#6136](https://github.com/mruby/mruby/pull/6136) Fixed when combined `mrb_fiber_resume()` and `Fiber#transfer` diff --git a/yass/third_party/nghttp2/third-party/mruby/README.md b/yass/third_party/nghttp2/third-party/mruby/README.md index cf310e01ab..21ee55c6f2 100644 --- a/yass/third_party/nghttp2/third-party/mruby/README.md +++ b/yass/third_party/nghttp2/third-party/mruby/README.md @@ -1,6 +1,16 @@ -# mruby - -[![GitHub Super-Linter](https://github.com/mruby/mruby/workflows/Lint%20Code%20Base/badge.svg)](https://github.com/marketplace/actions/super-linter) +
+

+ + The mruby programming language + +

+

mruby

+ + GitHub Super-Linter + +
## What is mruby @@ -8,34 +18,34 @@ mruby is the lightweight implementation of the Ruby language complying to (part of) the [ISO standard][ISO-standard] with more recent features provided by Ruby 3.x. Also, its syntax is Ruby 3.x compatible except for pattern matching. -mruby can be linked and embedded within your application. We provide the -interpreter program "mruby", and the interactive mruby shell "mirb" as examples. -You can also compile Ruby programs into compiled byte code using the mruby -compiler "mrbc". All those tools reside in the "bin" directory. "mrbc" is -also able to generate compiled byte code in a C source file, see the "mrbtest" -program under the "test" directory for an example. +You can link and embed mruby within your application. The "mruby" interpreter +program and the interactive "mirb" shell are provided as examples. You can also +compile Ruby programs into compiled byte code using the "mrbc" compiler. All +these tools are located in the "bin" directory. "mrbc" can also generate +compiled byte code in a C source file. See the "mrbtest" program under the +"test" directory for an example. This achievement was sponsored by the Regional Innovation Creation R&D Programs of the Ministry of Economy, Trade and Industry of Japan. ## How to get mruby -The stable version 3.2.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/3.2.0.zip](https://github.com/mruby/mruby/archive/3.2.0.zip) +To get mruby, you can download the stable version 3.3.0 from the official mruby +GitHub repository or clone the trunk of the mruby source tree with the "git +clone" command. You can also install and compile mruby using [ruby-install](https://github.com/postmodern/ruby-install), [ruby-build](https://github.com/rbenv/ruby-build) or [rvm](https://github.com/rvm/rvm). The latest development version of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/zipball/master](https://github.com/mruby/mruby/zipball/master) The trunk of the mruby source tree can be checked out with the following command: -``` +```console $ git clone https://github.com/mruby/mruby.git ``` -You can also install and compile mruby using [ruby-install](https://github.com/postmodern/ruby-install), [ruby-build](https://github.com/rbenv/ruby-build) or [rvm](https://github.com/rvm/rvm). +## mruby homepage -## mruby home-page - -The URL of the mruby home-page is: . +The URL of the mruby homepage is: . ## Mailing list @@ -45,7 +55,7 @@ We don't have a mailing list, but you can use [GitHub issues](https://github.com For the simplest case, type -``` +```console rake all test ``` @@ -53,27 +63,27 @@ See the [compile.md](doc/guides/compile.md) file for the detail. ## Building documentation -There are two sets of documentation in mruby: the mruby API (generated by yard) and C API (Doxygen and Graphviz) +There are two sets of documentation in mruby: the mruby API (generated by YARD) and C API (Doxygen and Graphviz) To build both of them, simply go -``` +```console rake doc ``` You can also view them in your browser -``` +```console rake view_api rake view_capi ``` ## How to customize mruby (mrbgems) -mruby contains a package manager called *mrbgems*. To create extensions -in C and/or Ruby you should create a *GEM*. For a documentation of how to -use mrbgems consult the file [mrbgems.md](doc/guides/mrbgems.md). -For example code of how to use mrbgems look into the folder [examples/mrbgems/](examples/mrbgems). +mruby contains a package manager called "mrbgems" that you can use to create +extensions in C and/or Ruby. For a guide on how to use mrbgems, consult the +[mrbgems.md](doc/guides/mrbgems.md) file, and for example code, refer to the +[examples/mrbgems/](examples/mrbgems) folder. ## License @@ -98,9 +108,8 @@ Please ask us if you want to distribute your code under another license. ## How to Contribute -See the [contribution guidelines][contribution-guidelines], and then send a pull -request to . We consider you have granted -non-exclusive right to your contributed code under MIT license. +To contribute to mruby, please refer to the [contribution guidelines][contribution-guidelines] and send a pull request to the [mruby GitHub repository](https://github.com/mruby/mruby). +By contributing, you grant non-exclusive rights to your code under the MIT License. [ISO-standard]: https://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579 -[contribution-guidelines]: https://github.com/mruby/mruby/blob/master/CONTRIBUTING.md +[contribution-guidelines]: CONTRIBUTING.md diff --git a/yass/third_party/nghttp2/third-party/mruby/Rakefile b/yass/third_party/nghttp2/third-party/mruby/Rakefile index 5a8fbdb503..79ec84f679 100644 --- a/yass/third_party/nghttp2/third-party/mruby/Rakefile +++ b/yass/third_party/nghttp2/third-party/mruby/Rakefile @@ -31,6 +31,7 @@ load "#{MRUBY_ROOT}/tasks/presym.rake" load "#{MRUBY_ROOT}/tasks/test.rake" load "#{MRUBY_ROOT}/tasks/benchmark.rake" load "#{MRUBY_ROOT}/tasks/doc.rake" +load "#{MRUBY_ROOT}/tasks/install.rake" ############################## # generic build targets, rules @@ -56,7 +57,7 @@ task :clean do rm_rf build.build_dir rm_f build.products end - puts "Cleaned up target build folder" + puts "Cleaned up target build directory" end desc "clean everything!" @@ -64,35 +65,9 @@ task :deep_clean => %w[clean doc:clean] do MRuby.each_target do |build| rm_rf build.gem_clone_dir end - puts "Cleaned up mrbgems build folder" -end - -PREFIX = ENV['PREFIX'] || ENV['INSTALL_PREFIX'] || '/usr/local' - -desc "install compiled products" -task :install => :install_bin do - if host = MRuby.targets['host'] - install_D host.libmruby_static, File.join(PREFIX, "lib", File.basename(host.libmruby_static)) - # install mruby.h and mrbconf.h - Dir.glob(File.join(MRUBY_ROOT, "include", "*.h")) do |src| - install_D src, File.join(PREFIX, "include", File.basename(src)) - end - Dir.glob(File.join(MRUBY_ROOT, "include", "mruby", "*.h")) do |src| - install_D src, File.join(PREFIX, "include", "mruby", File.basename(src)) - end - Dir.glob(File.join(File.join(MRUBY_ROOT, "build", "host", "include", "mruby", "presym", "*.h"))) do |src| - install_D src, File.join(PREFIX, "include", "mruby", "presym", File.basename(src)) - end - end -end - -desc "install compiled executable (on host)" -task :install_bin => :all do - if host = MRuby.targets['host'] - Dir.glob(File.join(MRUBY_ROOT, "bin", "*")) do |src| - install_D src, File.join(PREFIX, "bin", File.basename(src)) - end - end + rm_rf "#{MRUBY_ROOT}/bin" + rm_rf "#{MRUBY_ROOT}/build" + puts "Cleaned up mrbgems build directory" end desc "run all pre-commit hooks against all files" @@ -100,7 +75,22 @@ task :check do sh "pre-commit run --all-files" end +desc "install the pre-commit hooks" +task :checkinstall do + sh "pre-commit install" +end + desc "check the pre-commit hooks for updates" task :checkupdate do sh "pre-commit autoupdate" end + +desc "run all pre-commit hooks against all files with docker-compose" +task :composecheck do + sh "docker-compose -p mruby run test pre-commit run --all-files" +end + +desc "build and run all mruby tests with docker-compose" +task :composetest do + sh "docker-compose -p mruby run test" +end diff --git a/yass/third_party/nghttp2/third-party/mruby/SECURITY.md b/yass/third_party/nghttp2/third-party/mruby/SECURITY.md index 779b06c322..bd80d2dd92 100644 --- a/yass/third_party/nghttp2/third-party/mruby/SECURITY.md +++ b/yass/third_party/nghttp2/third-party/mruby/SECURITY.md @@ -11,7 +11,7 @@ We consider the following issues as vulnerabilities: - Remote code execution - Crash caused by a valid Ruby script -We *don't* consider the following issues as vulnerabilities: +We _don't_ consider the following issues as vulnerabilities: - Runtime C undefined behavior (including integer overflow) - Crash caused by misused API diff --git a/yass/third_party/nghttp2/third-party/mruby/appveyor.yml b/yass/third_party/nghttp2/third-party/mruby/appveyor.yml index 8782f59aa4..3a063dd78f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/appveyor.yml +++ b/yass/third_party/nghttp2/third-party/mruby/appveyor.yml @@ -4,6 +4,10 @@ shallow_clone: true environment: matrix: + - job_name: Visual Studio 2022 64bit + visualcpp: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat + appveyor_build_worker_image: Visual Studio 2022 + - job_name: Visual Studio 2019 64bit visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat appveyor_build_worker_image: Visual Studio 2019 @@ -38,7 +42,6 @@ init: - set PATH=C:\Ruby26-x64\bin;%PATH% - ruby --version - build_script: - set MRUBY_CONFIG=ci/msvc - rake -m test:build diff --git a/yass/third_party/nghttp2/third-party/mruby/benchmark/bm_ao_render.rb b/yass/third_party/nghttp2/third-party/mruby/benchmark/bm_ao_render.rb index 91e2d34192..ddb42d5c6e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/benchmark/bm_ao_render.rb +++ b/yass/third_party/nghttp2/third-party/mruby/benchmark/bm_ao_render.rb @@ -253,6 +253,7 @@ class Scene def render(w, h, nsubsamples) nsf = nsubsamples.to_f + nsfs = nsf * nsf h.times do |y| w.times do |x| rad = Vec.new(0.0, 0.0, 0.0) @@ -288,9 +289,9 @@ class Scene end end - r = rad.x / (nsf * nsf) - g = rad.y / (nsf * nsf) - b = rad.z / (nsf * nsf) + r = rad.x / nsfs + g = rad.y / nsfs + b = rad.z / nsfs printf("%c", clamp(r)) printf("%c", clamp(g)) printf("%c", clamp(b)) diff --git a/yass/third_party/nghttp2/third-party/mruby/build_config/android_arm64_v8a.rb b/yass/third_party/nghttp2/third-party/mruby/build_config/android_arm64_v8a.rb index 8763b00842..6dda612dde 100644 --- a/yass/third_party/nghttp2/third-party/mruby/build_config/android_arm64_v8a.rb +++ b/yass/third_party/nghttp2/third-party/mruby/build_config/android_arm64_v8a.rb @@ -2,8 +2,8 @@ MRuby::CrossBuild.new('android-arm64-v8a') do |conf| params = { :arch => 'arm64-v8a', - :sdk_version => 26, - :toolchain => :clang, + :sdk_version => 33, + :toolchain => :clang } toolchain :android, params diff --git a/yass/third_party/nghttp2/third-party/mruby/build_config/android_armeabi.rb b/yass/third_party/nghttp2/third-party/mruby/build_config/android_armeabi.rb deleted file mode 100644 index cef0e3adca..0000000000 --- a/yass/third_party/nghttp2/third-party/mruby/build_config/android_armeabi.rb +++ /dev/null @@ -1,11 +0,0 @@ -# Requires Android NDK r13 or later. -MRuby::CrossBuild.new('android-armeabi') do |conf| - params = { - :arch => 'armeabi', - :sdk_version => 26, - :toolchain => :clang, - } - toolchain :android, params - - conf.gembox 'default' -end diff --git a/yass/third_party/nghttp2/third-party/mruby/build_config/android_armeabi_v7a_neon_hard.rb b/yass/third_party/nghttp2/third-party/mruby/build_config/android_armeabi_v7a_neon_hard.rb index 150d1d2043..3dae241851 100644 --- a/yass/third_party/nghttp2/third-party/mruby/build_config/android_armeabi_v7a_neon_hard.rb +++ b/yass/third_party/nghttp2/third-party/mruby/build_config/android_armeabi_v7a_neon_hard.rb @@ -4,8 +4,8 @@ MRuby::CrossBuild.new('android-armeabi-v7a-neon-hard') do |conf| :arch => 'armeabi-v7a', :mfpu => 'neon', :mfloat_abi => 'hard', - :sdk_version => 26, - :toolchain => :clang, + :sdk_version => 33, + :toolchain => :clang } toolchain :android, params diff --git a/yass/third_party/nghttp2/third-party/mruby/build_config/dreamcast_shelf.rb b/yass/third_party/nghttp2/third-party/mruby/build_config/dreamcast_shelf.rb index 092fde0d02..0edd9470c9 100644 --- a/yass/third_party/nghttp2/third-party/mruby/build_config/dreamcast_shelf.rb +++ b/yass/third_party/nghttp2/third-party/mruby/build_config/dreamcast_shelf.rb @@ -4,31 +4,31 @@ # Requires KallistiOS (KOS) # http://gamedev.allusion.net/softprj/kos/ # -# Tested on GNU/Linux, macOS and Windows (through MinGW-w64/MSYS2, Cygwin and DreamSDK). +# This configuration has been improved to be used as KallistiOS Port (kos-ports) +# Updated: 2023-12-24 +# +# Tested on GNU/Linux, macOS and Windows (MinGW-w64/MSYS2, Cygwin, DreamSDK) # DreamSDK is based on MinGW/MSYS: https://dreamsdk.org/ # -# Input this command on the directory where mruby is installed: -# make MRUBY_CONFIG=dreamcast_shelf +# Install mruby for Sega Dreamcast using the "mruby" kos-port. # MRuby::CrossBuild.new("dreamcast") do |conf| toolchain :gcc - # Support for DreamSDK (based on MinGW/MSYS) - # To compile mruby with DreamSDK, RubyInstaller for Windows should be installed - DREAMSDK_HOME = ENV["DREAMSDK_HOME"] - MSYS_ROOT = !(DREAMSDK_HOME.nil? || DREAMSDK_HOME.empty?) ? "#{DREAMSDK_HOME}/msys/1.0" : "" + # Getting critical environment variables + KOS_BASE = ENV["KOS_BASE"] + KOS_CC_BASE = ENV["KOS_CC_BASE"] - # Setting paths - DREAMCAST_PATH = "#{MSYS_ROOT}/opt/toolchains/dc" - KOS_PATH = "#{DREAMCAST_PATH}/kos" - BIN_PATH = "#{DREAMCAST_PATH}/sh-elf/bin" + if (KOS_BASE.nil? || KOS_BASE.empty? || KOS_CC_BASE.nil? || KOS_CC_BASE.empty?) + raise "Error: KallistiOS is required; KOS_BASE/KOS_CC_BASE needs to be declared; Stop." + end # C compiler - # Flags were extracted from KallistiOS environment files + # All flags and settings below were extracted from KallistiOS environment files conf.cc do |cc| - cc.command = "#{BIN_PATH}/sh-elf-gcc" - cc.include_paths << ["#{KOS_PATH}/include", "#{KOS_PATH}/kernel/arch/dreamcast/include", "#{KOS_PATH}/addons/include", "#{KOS_PATH}/../kos-ports/include"] - cc.flags << ["-O2", "-fomit-frame-pointer", "-ml", "-m4-single-only", "-ffunction-sections", "-fdata-sections", "-Wall", "-g", "-fno-builtin", "-ml", "-m4-single-only", "-Wl,-Ttext=0x8c010000", "-Wl,--gc-sections", "-T#{KOS_PATH}/utils/ldscripts/shlelf.xc", "-nodefaultlibs"] + cc.command = "#{KOS_CC_BASE}/bin/sh-elf-gcc" + cc.include_paths << ["#{KOS_BASE}/include", "#{KOS_BASE}/kernel/arch/dreamcast/include", "#{KOS_BASE}/addons/include", "#{KOS_BASE}/../kos-ports/include"] + cc.flags << ["-O2", "-fomit-frame-pointer", "-fno-builtin", "-ml", "-m4-single-only", "-ffunction-sections", "-fdata-sections", "-matomic-model=soft-imask", "-ftls-model=local-exec", "-Wall", "-g"] cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"] cc.defines << %w(_arch_dreamcast) cc.defines << %w(_arch_sub_pristine) @@ -39,79 +39,45 @@ MRuby::CrossBuild.new("dreamcast") do |conf| cxx.command = conf.cc.command.dup cxx.include_paths = conf.cc.include_paths.dup cxx.flags = conf.cc.flags.dup - cxx.flags << %w(-fno-rtti -fno-exceptions) + cxx.flags << %w(-fno-operator-names) cxx.defines = conf.cc.defines.dup cxx.compile_options = conf.cc.compile_options.dup end # Linker - # There is an issue when making the mruby library with KallistiOS: - # 'newlib_kill.o' and 'newlib_getpid.o' aren't found so they are explicitly - # specified here at least for now. conf.linker do |linker| - linker.command="#{BIN_PATH}/sh-elf-gcc" - linker.flags << ["#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_kill.o", "#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_getpid.o", "-Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group"] - linker.library_paths << ["#{KOS_PATH}/lib/dreamcast", "#{KOS_PATH}/addons/lib/dreamcast", "#{KOS_PATH}/../kos-ports/lib"] + linker.command = "#{KOS_CC_BASE}/bin/sh-elf-gcc" + linker.flags << ["-Wl,-Ttext=0x8c010000", "-Wl,--gc-sections", "-T#{KOS_BASE}/utils/ldscripts/shlelf.xc", "-nodefaultlibs", "-Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group"] + linker.library_paths << ["#{KOS_BASE}/lib/dreamcast", "#{KOS_BASE}/addons/lib/dreamcast", "#{KOS_BASE}/../kos-ports/lib"] end # Archiver conf.archiver do |archiver| - archiver.command = "#{BIN_PATH}/sh-elf-ar" + archiver.command = "#{KOS_CC_BASE}/bin/sh-elf-ar" archiver.archive_options = 'rcs "%{outfile}" %{objs}' end - # No executables + # No executables needed for KallistiOS conf.bins = [] - # Do not build executable test + # Do not build test binaries conf.build_mrbtest_lib_only - # Disable C++ exception - conf.disable_cxx_exception + # Gemboxes + conf.gembox "default-no-stdio" + conf.gembox "stdlib-ext" + conf.gembox "metaprog" - # Gems from core - # Some Gems are incompatible and were disabled. - - conf.gem :core => "mruby-array-ext" + # Additional Gems + # Currently unsupported on KallistiOS: "mruby-io", "mruby-dir", "mruby-socket" conf.gem :core => "mruby-binding" conf.gem :core => "mruby-catch" - conf.gem :core => "mruby-class-ext" - conf.gem :core => "mruby-cmath" - conf.gem :core => "mruby-compar-ext" - conf.gem :core => "mruby-compiler" - conf.gem :core => "mruby-complex" conf.gem :core => "mruby-enum-chain" - conf.gem :core => "mruby-enum-ext" - conf.gem :core => "mruby-enum-lazy" - conf.gem :core => "mruby-enumerator" + conf.gem :core => "mruby-errno" conf.gem :core => "mruby-error" - conf.gem :core => "mruby-eval" conf.gem :core => "mruby-exit" - conf.gem :core => "mruby-fiber" - conf.gem :core => "mruby-hash-ext" -# conf.gem :core => "mruby-io" - conf.gem :core => "mruby-kernel-ext" - conf.gem :core => "mruby-math" - conf.gem :core => "mruby-metaprog" - conf.gem :core => "mruby-method" - conf.gem :core => "mruby-numeric-ext" - conf.gem :core => "mruby-object-ext" - conf.gem :core => "mruby-objectspace" conf.gem :core => "mruby-os-memsize" - conf.gem :core => "mruby-pack" conf.gem :core => "mruby-print" conf.gem :core => "mruby-proc-binding" - conf.gem :core => "mruby-proc-ext" - conf.gem :core => "mruby-random" - conf.gem :core => "mruby-range-ext" - conf.gem :core => "mruby-rational" conf.gem :core => "mruby-sleep" -# conf.gem :core => "mruby-socket" - conf.gem :core => "mruby-sprintf" - conf.gem :core => "mruby-string-ext" - conf.gem :core => "mruby-struct" - conf.gem :core => "mruby-symbol-ext" -# conf.gem :core => "mruby-test" -# conf.gem :core => "mruby-time" - conf.gem :core => "mruby-toplevel-ext" end diff --git a/yass/third_party/nghttp2/third-party/mruby/build_config/host-shared.rb b/yass/third_party/nghttp2/third-party/mruby/build_config/host-shared.rb index 38cab8145b..76e3a07134 100644 --- a/yass/third_party/nghttp2/third-party/mruby/build_config/host-shared.rb +++ b/yass/third_party/nghttp2/third-party/mruby/build_config/host-shared.rb @@ -1,23 +1,20 @@ +# NOTE: Currently, this configuration file does not support VisualC++! +# Your help is needed! + MRuby::Build.new do |conf| # load specific toolchain settings - - # Gets set by the VS command prompts. - if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] - toolchain :visualcpp - else - toolchain :gcc - end + conf.toolchain # include the GEM box conf.gembox 'default' # C compiler settings - conf.cc do |cc| - cc.flags = '-fPIC' + conf.compilers.each do |cc| + cc.flags << '-fPIC' end conf.archiver do |archiver| - archiver.command = 'gcc' + archiver.command = cc.command archiver.archive_options = '-shared -o %{outfile} %{objs}' end @@ -29,6 +26,9 @@ MRuby::Build.new do |conf| # file separator # conf.file_separator = '/' + # enable this if better compatibility with C++ is desired + #conf.enable_cxx_exception + # Turn on `enable_debug` for better debugging conf.enable_debug conf.enable_bintest diff --git a/yass/third_party/nghttp2/third-party/mruby/build_config/i586-pc-msdosdjgpp.rb b/yass/third_party/nghttp2/third-party/mruby/build_config/i586-pc-msdosdjgpp.rb new file mode 100644 index 0000000000..4275423cd6 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/build_config/i586-pc-msdosdjgpp.rb @@ -0,0 +1,77 @@ +# Cross Compiling configuration for MS-DOS +# +# Requires DJGPP cross-compiler, see +# https://github.com/andrewwutw/build-djgpp/releases + +MRuby::CrossBuild.new("i586-pc-msdosdjgpp") do |conf| + toolchain :gcc + + # If DJGPP is not in the PATH, set this to the bin directory + DJGPP_PATH = nil + + GCC = 'i586-pc-msdosdjgpp-gcc' + GXX = 'i586-pc-msdosdjgpp-g++' + AR = 'i586-pc-msdosdjgpp-ar' + + conf.cc do |cc| + cc.command = DJGPP_PATH ? File.join(DJGPP_PATH, GCC) : GCC + cc.defines << 'MRB_WITHOUT_IO_PREAD_PWRITE' + cc.defines << 'MRB_UTF8_STRING' + end + + conf.cxx do |cxx| + cxx.command = DJGPP_PATH ? File.join(DJGPP_PATH, GXX) : GXX + cxx.defines << 'MRB_WITHOUT_IO_PREAD_PWRITE' + cxx.defines << 'MRB_UTF8_STRING' + end + + conf.linker do |linker| + linker.command = DJGPP_PATH ? File.join(DJGPP_PATH, GXX) : GXX + linker.libraries = %w(m) + end + + conf.archiver do |archiver| + archiver.command = DJGPP_PATH ? File.join(DJGPP_PATH, AR) : AR + end + + # All provided gems that can be reasonably made to compile: + # default.gembox, minus mruby-socket and replacing mruby-cmath with mruby-cmath-alt + conf.gembox "stdlib" + conf.gembox "stdlib-ext" + + conf.gem :core => 'mruby-io' # stdlib-io.gembox <- default.gembox +# No socket support in DJGPP +# conf.gem :core => 'mruby-socket' # stdlib-io.gembox <- default.gembox + conf.gem :core => 'mruby-print' # stdlib-io.gembox <- default.gembox + conf.gem :core => 'mruby-errno' # stdlib-io.gembox <- default.gembox + conf.gem :core => 'mruby-dir' # stdlib-io.gembox <- default.gembox + + conf.gem :core => 'mruby-bigint' # math.gembox <- default.gembox + conf.gem :core => 'mruby-complex' # math.gembox <- default.gembox + conf.gem :core => 'mruby-math' # math.gembox <- default.gembox + conf.gem :core => 'mruby-rational' # math.gembox <- default.gembox + # Alternative implementation of cmath, not requiring +# conf.gem :github => 'chasonr/mruby-cmath-alt' # math.gembox <- default.gembox + + conf.gembox "metaprog" + + conf.gem :core => 'mruby-bin-mrbc' # default.gembox + conf.gem :core => 'mruby-bin-debugger' # default.gembox + conf.gem :core => 'mruby-bin-mirb' # default.gembox + conf.gem :core => 'mruby-bin-mruby' # default.gembox + conf.gem :core => 'mruby-bin-strip' # default.gembox + conf.gem :core => 'mruby-bin-config' # default.gembox + + # Other compilable gems + conf.gem :core => 'mruby-binding' + conf.gem :core => 'mruby-catch' + conf.gem :core => 'mruby-enum-chain' + conf.gem :core => 'mruby-error' + conf.gem :core => 'mruby-exit' + conf.gem :core => 'mruby-os-memsize' + conf.gem :core => 'mruby-proc-binding' + conf.gem :core => 'mruby-sleep' + + # For Onigmo regular expression support + conf.gem :github => 'mattn/mruby-onig-regexp' +end diff --git a/yass/third_party/nghttp2/third-party/mruby/build_config/nintendo_wii.rb b/yass/third_party/nghttp2/third-party/mruby/build_config/nintendo_wii.rb new file mode 100644 index 0000000000..01ce547b2e --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/build_config/nintendo_wii.rb @@ -0,0 +1,96 @@ +# Cross Compiling configuration for the Nintendo Wii +# This configuration requires devkitPPC +# https://devkitpro.org/wiki/Getting_Started +# +# +MRuby::CrossBuild.new("wii") do |conf| + toolchain :gcc + + DEVKITPRO_PATH = "/opt/devkitpro" + BIN_PATH = "#{DEVKITPRO_PATH}/devkitPPC/bin" + + # C compiler + conf.cc do |cc| + cc.command = "#{BIN_PATH}/powerpc-eabi-gcc" + cc.compile_options = %(%{flags} -o "%{outfile}" -c "%{infile}") + end + + # C++ compiler + conf.cxx do |cxx| + cxx.command = "#{BIN_PATH}/powerpc-eabi-g++" + cxx.include_paths = conf.cc.include_paths.dup + cxx.flags = conf.cc.flags.dup + cxx.defines = conf.cc.defines.dup + cxx.compile_options = conf.cc.compile_options.dup + end + + # Linker + conf.linker do |linker| + linker.command = "#{BIN_PATH}/powerpc-eabi-gcc" + end + + # No executables + conf.bins = [] + + # Do not build executable test + conf.build_mrbtest_lib_only + + # Disable C++ exception + conf.disable_cxx_exception + + # All current core gems with ones with build issues commented out + conf.gem 'mrbgems/mruby-array-ext/' + conf.gem 'mrbgems/mruby-bigint/' + conf.gem 'mrbgems/mruby-bin-config/' + conf.gem 'mrbgems/mruby-bin-debugger/' + conf.gem 'mrbgems/mruby-bin-mirb/' + conf.gem 'mrbgems/mruby-bin-mrbc/' + conf.gem 'mrbgems/mruby-bin-mruby/' + conf.gem 'mrbgems/mruby-bin-strip/' + conf.gem 'mrbgems/mruby-binding/' + conf.gem 'mrbgems/mruby-catch/' + conf.gem 'mrbgems/mruby-class-ext/' + conf.gem 'mrbgems/mruby-cmath/' + conf.gem 'mrbgems/mruby-compar-ext/' + conf.gem 'mrbgems/mruby-compiler/' + conf.gem 'mrbgems/mruby-complex/' + conf.gem 'mrbgems/mruby-data/' + #conf.gem 'mrbgems/mruby-dir/' + conf.gem 'mrbgems/mruby-enum-chain/' + conf.gem 'mrbgems/mruby-enum-ext/' + conf.gem 'mrbgems/mruby-enum-lazy/' + conf.gem 'mrbgems/mruby-enumerator/' + conf.gem 'mrbgems/mruby-errno/' + conf.gem 'mrbgems/mruby-error/' + conf.gem 'mrbgems/mruby-eval/' + conf.gem 'mrbgems/mruby-exit/' + conf.gem 'mrbgems/mruby-fiber/' + conf.gem 'mrbgems/mruby-hash-ext/' + #conf.gem 'mrbgems/mruby-io/' + conf.gem 'mrbgems/mruby-kernel-ext/' + conf.gem 'mrbgems/mruby-math/' + conf.gem 'mrbgems/mruby-metaprog/' + conf.gem 'mrbgems/mruby-method/' + conf.gem 'mrbgems/mruby-numeric-ext/' + conf.gem 'mrbgems/mruby-object-ext/' + conf.gem 'mrbgems/mruby-objectspace/' + conf.gem 'mrbgems/mruby-os-memsize/' + conf.gem 'mrbgems/mruby-pack/' + conf.gem 'mrbgems/mruby-print/' + conf.gem 'mrbgems/mruby-proc-binding/' + conf.gem 'mrbgems/mruby-proc-ext/' + conf.gem 'mrbgems/mruby-random/' + conf.gem 'mrbgems/mruby-range-ext/' + conf.gem 'mrbgems/mruby-rational/' + conf.gem 'mrbgems/mruby-set/' + conf.gem 'mrbgems/mruby-sleep/' + #conf.gem 'mrbgems/mruby-socket/' + conf.gem 'mrbgems/mruby-sprintf/' + conf.gem 'mrbgems/mruby-string-ext/' + conf.gem 'mrbgems/mruby-struct/' + conf.gem 'mrbgems/mruby-symbol-ext/' + conf.gem 'mrbgems/mruby-test-inline-struct/' + #conf.gem 'mrbgems/mruby-test/' + conf.gem 'mrbgems/mruby-time/' + conf.gem 'mrbgems/mruby-toplevel-ext/' +end diff --git a/yass/third_party/nghttp2/third-party/mruby/codespell.txt b/yass/third_party/nghttp2/third-party/mruby/codespell.txt index d6d80b0791..9a4d7548ce 100644 --- a/yass/third_party/nghttp2/third-party/mruby/codespell.txt +++ b/yass/third_party/nghttp2/third-party/mruby/codespell.txt @@ -1,20 +1,16 @@ ans -ba +celler clen -creat delet disabl -falsy filetest fo hel -hist ist -methid nd quitt remore -ro runn sting -upto +strin +wronly diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/guides/compile.md b/yass/third_party/nghttp2/third-party/mruby/doc/guides/compile.md index 4302d1362a..dab1756136 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/guides/compile.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/guides/compile.md @@ -80,7 +80,7 @@ conf.toolchain :clang #### Visual Studio 2010, 2012 and 2013 Toolchain configuration for Visual Studio on Windows. If you use the -[Visual Studio Command Prompt](https://msdn.microsoft.com/en-us/library/ms229859\(v=vs.110\).aspx), +[Visual Studio Command Prompt](), you normally do not have to specify this manually, since it gets automatically detected by our build process. ```ruby @@ -177,7 +177,7 @@ conf.linker do |linker| linker.flags_before_libraries = ... linker.libraries = ... linker.flags_after_libraries = ... - linker.library_paths = .... + linker.library_paths = ... linker.option_library = ... linker.option_library_path = ... linker.link_options = ... @@ -265,7 +265,7 @@ There is a `RubyGem` (gem for CRuby) named `mgem` that help you to manage `mrbgems`. Try `gem install mgem`. `mgem` can show you the list of registered `mrbgems`. -See doc/mrbgems/README.md for more option about mrbgems. +See [doc/guides/mrbgems.md](mrbgems.md) for more option about mrbgems. ### Mrbtest @@ -376,7 +376,7 @@ end ## Build process -During the build process the directory `build` will be created in the +During the build process the `build` directory will be created in the root directory. The structure of this directory will look like this: ``` @@ -460,7 +460,7 @@ compile for `i386` a directory called `i386` is created under the build directory. The cross compilation workflow starts in the same way as the normal -compilation by compiling all *native* libraries and binaries, except +compilation by compiling all _native_ libraries and binaries, except for we don't have `host/mrbc` directory (`host` directory itself works as placeholder for `mrbc`). Afterwards the cross compilation process proceeds like this: @@ -527,7 +527,7 @@ After the build, you will get `libmruby.a`. You can link it to your application. For compiler options and library path, you can use `mruby-config` command for convenience. `mruby-config` command prints the configuration used for `libmruby.a`. -``` +```console $ mruby-config --help Usage: mruby-config [switches] switches: @@ -557,6 +557,56 @@ LDFLAGS = `$(MRB_CONFIG) --ldflags` LIBS = `$(MRB_CONFIG) --libs` ``` +## Install + +To install the files in the `bin`, `include` and `lib` directories generated by the "host" build target into a system directory, do the following: + +```console +$ rake install +``` + +If there are multiple build targets in the build configuration file, to install the products of all build targets, do the following: + +```console +$ rake install:full +``` + +To install only one of several build targets, e.g., the "its-mine" build target, do the following: + +```console +$ rake install:full:its-mine +``` + +To install only the executable files, do the following: + +```console +$ rake install_bin # only "host" build target +$ rake install:bin # all build targets +$ rake install:bin:its-mine # only "its-mine" build target +``` + +### Installation Directory + +The installation directory is `/usr/local` for the "host" build target and `/usr/local/mruby/` for the others. +To change them, you can set the environment variable `PREFIX` or use `MRuby::Build#install_prefix = dir` in your build configuration file. + +The `PREFIX` environment variable affects all build targets and changes the `/usr/local` part. + +The `MRuby::Build#install_prefix` can be set for each individual build target. +In this case, the environment variable `PREFIX` is ignored. + +Also, if the environment variable `DESTDIR` is set, it will prepend to the path obtained by `install_prefix` to determine the final write directory. +This is intended for temporary file expansion by the user's package work. + +--- + +To summarize: + +- The default value of the environment variable `PREFIX` is `/usr/local`. +- For the "host" build target, the default value of `MRuby::Build#install_prefix` is ``. +- For a build target other than "host", the default value of `MRuby::Build#install_prefix` is `/mruby/`. +- If the environment variable `DESTDIR` is set, the actual write directory is `/`. + ## Tips - If you see compilation troubles, try `rake clean` first. diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/guides/debugger.md b/yass/third_party/nghttp2/third-party/mruby/doc/guides/debugger.md index ef48005af6..4e52b7b8bb 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/guides/debugger.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/guides/debugger.md @@ -38,7 +38,7 @@ To confirm mrdb was installed properly, run mrdb with the `--version` option: ```bash $ mrdb --version -mruby 3.1.0 (2022-05-12) +mruby 3.3.0 (2024-02-14) ``` ## 2.2 Basic Operation @@ -61,20 +61,20 @@ $ mrdb sample.rb You can execute the shell commands listed below: -|command|description| -|:-:|:--| -|run|execute programs| -|step|execute stepping| -|continue|execute continuing program| -|break|configure the breaking point| -|delete|deleting the breaking points| -|disable|disabling the breaking points| -|enable|enabling the breaking points| -|info breakpoints|showing list of the breaking points| -|print|evaluating and printing the values of the mruby expressions in the script| -|list|displaying the source cords| -|help|showing help| -|quit|terminating the mruby debugger| +| command | description | +| :--------------: | :------------------------------------------------------------------------ | +| run | execute programs | +| step | execute stepping | +| continue | execute continuing program | +| break | configure the breaking point | +| delete | deleting the breaking points | +| disable | disabling the breaking points | +| enable | enabling the breaking points | +| info breakpoints | showing list of the breaking points | +| print | evaluating and printing the values of the mruby expressions in the script | +| list | displaying the source cords | +| help | showing help | +| quit | terminating the mruby debugger | ### 2.2.2 Debugging mruby Binary Files (mrb file) with mrdb @@ -83,7 +83,7 @@ You can debug the mruby binary files. #### 2.2.2.1 Debugging the binary files - notice -To debug mruby binary files, you need to compile mruby files with option `-g`. + To debug mruby binary files, you need to compile mruby files with option `-g`. ```bash $ mrbc -g sample.rb diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/guides/gc-arena-howto.md b/yass/third_party/nghttp2/third-party/mruby/doc/guides/gc-arena-howto.md index 22cd4ef1e9..2ac2bdfd4c 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/guides/gc-arena-howto.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/guides/gc-arena-howto.md @@ -3,7 +3,8 @@ _This is an English translation of [Matz's blog post][matz blog post] written in Japanese._ _Some parts are updated to reflect recent changes._ -[matz blog post]: + +[matz blog post]: https://www.rubyist.net/~matz/20130731.html When you are extending mruby using C language, you may encounter mysterious "arena overflow error" or memory leak or very slow @@ -62,7 +63,7 @@ memory leak. As of this writing, mruby automatically extend arena to remember objects (See `MRB_GC_FIXED_ARENA` and `MRB_GC_ARENA_SIZE` in -doc/guides/mrbconf.md). +[doc/guides/mrbconf.md](mrbconf.md)). If you create many objects in C functions, memory usage will increase, since GC never kicks in. This memory usage may look like memory leaks, but will also @@ -106,7 +107,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list) char tail[] = { ']' }; /* check recursive */ - for(i=0; i 0) { diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/guides/link.md b/yass/third_party/nghttp2/third-party/mruby/doc/guides/link.md index 861f713658..ac19aa234a 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/guides/link.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/guides/link.md @@ -51,10 +51,10 @@ for example: To retrieve compiler options used to build `mruby`, you can use `mruby-config` command with following options: -- `--cc` compiler name -- `--cflags` options passed to compiler +- `--cc` compiler name +- `--cflags` options passed to compiler -``` +```console $ mruby-config --cflags -std=gnu99 -g -O3 -Wall -DMRB_GC_FIXED_ARENA -I/home/matz/work/mruby/include -I/home/matz/work/mruby/build/host/include ``` @@ -66,12 +66,12 @@ compatible to mruby configuration. To retrieve linker options, you can use `mruby-config` with following options: -- `--ld` linker name -- `--ldflags` options passed to linker -- `--ldflags-before-libs` options passed to linker before linked libraries -- `--libs` linked libraries +- `--ld` linker name +- `--ldflags` options passed to linker +- `--ldflags-before-libs` options passed to linker before linked libraries +- `--libs` linked libraries -``` +```console $ mruby-config --ldflags -L/home/matz/work/mruby/build/host/lib diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/guides/memory.md b/yass/third_party/nghttp2/third-party/mruby/doc/guides/memory.md new file mode 100644 index 0000000000..8f78ffbe35 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/doc/guides/memory.md @@ -0,0 +1,21 @@ +# Memory Allocation + +There are three methods to customize memory allocation in mruby. + +1. Provide your own `realloc()`/`free()` +2. Redefine `mrb_default_allocf()` +3. Specify a function with `mrb_open_allocf()` + +## Provide your own `realloc()`/`free()` + +On some platforms, especially on microcontrollers, the standard library may not provide `malloc()`, `realloc()`, and `free()`. In such cases, it may be necessary to define memory allocation functions for the specific platform. mruby uses `realloc()` and `free()` from the standard C library for memory management. By defining these two functions of your own, you can make mruby work. However, note the following two points: + +First, `realloc(NULL, size)` behaves the same as malloc(size). Second, `free(NULL)` exits without doing anything. + +## Redefine `mrb_default_allocf()` + +The only function in mruby that uses the standard C library's memory allocation functions is `mrb_default_allocf()`, defined in `alloc.c`. By defining this function within your application, you can customize the memory management of your application. + +## Specify a function with `mrb_open_allocf()` + +If you want to perform different memory management for each `mrb_state` within your application, you can use the `mrb_open_allocf()` function to create the `mrb_state` structure. This allows you to specify a memory allocation function (which is compatible with `mrb_default_allocf`) for each `mrb_state`. Although this scheme is not recommended. It may become obsolete in the future, since I have never seen per mrb_state memory management use-case. diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/guides/mrbconf.md b/yass/third_party/nghttp2/third-party/mruby/doc/guides/mrbconf.md index 771922a4b8..823a0ba17d 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/guides/mrbconf.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/guides/mrbconf.md @@ -18,14 +18,14 @@ This is the same for `MRuby::CrossBuild`. # build_config.rb MRuby::Build.new do |conf| - ..... + ... conf.defines << 'MRB_GC_FIXED_ARENA' conf.defines << 'MRB_NO_METHOD_CACHE' - ..... + ... end ``` -***NOTE*** +**_NOTE_** - Use common definitions (`conf.defines`) instead of per-compiler definitions (e.g., `conf.cc.defines`) unless there is a special reason not to. - It is now deprecated to edit the `include/mruby/mrbconf.h` file or give it directly as a compiler flag, as was the case before. @@ -123,7 +123,7 @@ end - Defines value is `1024`. - Specifies number of `RBasic` per each heap page. -- To calculate the number of bytes per heap page, it is "(size of management data per heap page) + (size per object) * `MRB_HEAP_PAGE_SIZE`". +- To calculate the number of bytes per heap page, it is "(size of management data per heap page) + (size per object) \* `MRB_HEAP_PAGE_SIZE`". In mruby 3.1.0, the "size of management data per heap page" is 6 words, also "size per object" is 6 words. For a 32-bit CPU, `(6 * 4) + (6 * 4) * MRB_HEAP_PAGE_SIZE` gives the bytes of size per heap page. Conversely, for example, to keep the size per heap page to 4 Ki bytes, @@ -135,7 +135,7 @@ end - Default value is `4`. - If you're allocating data types that requires alignment more than default value define the -largest value of required alignment. + largest value of required alignment. `POOL_PAGE_SIZE` @@ -149,7 +149,7 @@ largest value of required alignment. - If defined enables fixed size `mrb_state` atexit stack. - Raises `RuntimeError` when `mrb_state_atexit` call count to same `mrb_state` exceeds -`MRB_FIXED_STATE_ATEXIT_STACK_SIZE`'s value. + `MRB_FIXED_STATE_ATEXIT_STACK_SIZE`'s value. `MRB_FIXED_STATE_ATEXIT_STACK_SIZE` @@ -247,6 +247,6 @@ largest value of required alignment. - Make it available `Symbol.all_symbols` in `mrbgems/mruby-symbol-ext` - Increase heap memory usage. -`MRB_NO_DIRECT_THREADING` +`MRB_USE_VM_SWITCH_DISPATCH` -- Turn off direct threading optimization in VM loop +- Turn on switch dispatch in VM loop diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/guides/mrbgems.md b/yass/third_party/nghttp2/third-party/mruby/doc/guides/mrbgems.md index e81a30ac00..fe086c1e93 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/guides/mrbgems.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/guides/mrbgems.md @@ -1,6 +1,6 @@ # mrbgems -mrbgems is a library manager to integrate C and Ruby extension in an easy and +mrbgems is a library manager to integrate C and Ruby extensions in an easy and standardised way into mruby. Conventionally, each mrbgem name is prefixed by `mruby-`, e.g. `mruby-time` for a gem that provides `Time` class functionality. @@ -92,6 +92,21 @@ end However, it should be used with caution, as it may deviate from the intent of the gem's author. +### Gem Testing + +If you enable unit tests in your build with `enable_test`, tests will be +generated for all gems and their dependencies by default. If necessary, it is +possible to suppress tests for a specific gem like so: + +```ruby +conf.gem 'mruby-noisygem' do |g| + g.skip_test = true +end +``` + +However, it is considered best practice to leave all tests enabled whenever +possible. A warning message will be generated for each gem with disabled tests. + ## GemBox There are instances when you wish to add a collection of mrbgems into mruby at @@ -160,9 +175,9 @@ The maximal GEM structure looks like this: +- test/ <- Test code (Ruby) ``` -The folder `mrblib` contains pure Ruby files to extend mruby. The folder `src` -contains C/C++ files to extend mruby. The folder `include` contains C/C++ header -files. The folder `test` contains C/C++ and pure Ruby files for testing purposes +The `mrblib` directory contains pure Ruby files to extend mruby. The `src` directory +contains C/C++ files to extend mruby. The `include` directory contains C/C++ header +files. The `test` directory contains C/C++ and pure Ruby files for testing purposes which will be used by `mrbtest`. `mrbgem.rake` contains the specification to compile C and Ruby files. `README.md` is a short description of your GEM. @@ -233,7 +248,7 @@ Version requirement supports following operators: - '<=': is equal or lesser - '~>': is equal or greater and is lesser than the next major version - example 1: '~> 2.2.2' means '>= 2.2.2' and '< 2.3.0' - - example 2: '~> 2.2' means '>= 2.2.0' and '< 3.0.0' + - example 2: '~> 2.2' means '>= 2.2.0' and '< 3.0.0' When more than one version requirements is passed, the dependency must satisfy all of it. @@ -349,7 +364,7 @@ mrb_c_extension_example_gem_final(mrb_state* mrb) { mruby can be extended with pure Ruby. It is possible to override existing classes or add new ones in this way. Put all Ruby files into the `mrblib` -folder. +directory. ### Pre-Conditions @@ -377,11 +392,11 @@ none mruby can be extended with C and Ruby at the same time. It is possible to override existing classes or add new ones in this way. Put all Ruby files -into the `mrblib` folder and all C files into the `src` folder. +into the `mrblib` directory and all C files into the `src` directory. mruby codes under `mrblib` directory would be executed after gem init C -function is called. Make sure *mruby script* depends on *C code* and -*C code* doesn't depend on *mruby script*. +function is called. Make sure _mruby script_ depends on _C code_ and +_C code_ doesn't depend on _mruby script_. ### Pre-Conditions diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/guides/symbol.md b/yass/third_party/nghttp2/third-party/mruby/doc/guides/symbol.md index c76420da96..bae789b648 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/guides/symbol.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/guides/symbol.md @@ -57,13 +57,13 @@ To save RAM, `mruby` can use compile-time allocation of some symbols. You can use following macros to get preallocated symbols by including `mruby/presym.h` header. -- `MRB_SYM(xor)` //=> xor (Word characters) -- `MRB_SYM_B(xor)` //=> xor! (Method with Bang) -- `MRB_SYM_Q(xor)` //=> xor? (Method with Question mark) -- `MRB_SYM_E(xor)` //=> xor= (Method with Equal) -- `MRB_CVSYM(xor)` //=> @@xor (Class Variable) -- `MRB_IVSYM(xor)` //=> @xor (Instance Variable) -- `MRB_OPSYM(xor)` //=> ^ (Operator) +- `MRB_SYM(xor)` //=> xor (Word characters) +- `MRB_SYM_B(xor)` //=> xor! (Method with Bang) +- `MRB_SYM_Q(xor)` //=> xor? (Method with Question mark) +- `MRB_SYM_E(xor)` //=> xor= (Method with Equal) +- `MRB_CVSYM(xor)` //=> @@xor (Class Variable) +- `MRB_IVSYM(xor)` //=> @xor (Instance Variable) +- `MRB_OPSYM(xor)` //=> ^ (Operator) For `MRB_OPSYM()`, specify the names corresponding to operators (see `MRuby::Presym::OPERATORS` in `lib/mruby/presym.rb` for the names that diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/internal/boxing.md b/yass/third_party/nghttp2/third-party/mruby/doc/internal/boxing.md index f3bd086e44..0cae591e61 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/internal/boxing.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/internal/boxing.md @@ -15,7 +15,7 @@ Some values (called immediate values, e.g. integers, booleans, symbols, etc.) ar The Word boxing packing bit patterns are like following: | Types | Bit Pattern | -|--------|---------------------------------------| +| ------ | ------------------------------------- | | object | `xxxxxxxx xxxxxxxx xxxxxxxx xxxxx000` | | fixnum | `xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxx1` | | nil | `00000000 00000000 00000000 00000000` | @@ -24,17 +24,17 @@ The Word boxing packing bit patterns are like following: | undef | `00000000 00000000 00000000 00010100` | | symbol | `xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx10` | -On 64 bit platform (unless `MRB_WORDBOX_NO_FLOAT_TRUNCATE`), float values are also packed in the `mrb_value`. In that case, we drop least significant 2 bits from mantissa. +On 64-bit platforms (unless `MRB_WORDBOX_NO_FLOAT_TRUNCATE`), float values are also packed in the `mrb_value`. In that case, we drop least significant 2 bits from mantissa. If you need full precision for floating-point numbers, define `MRB_WORDBOX_NO_FLOAT_TRUNCATE`. ## NaN Boxing -NaN boxing packs the Ruby data in a floating-point numbers, which represent NaN (Not a Number) values. Under IEEE753 definitions every value that exponent is all set are considered as NaN. That means NaN can represent `2^51` values. NaN boxing is a teaching to pack the values in those NaN representation. In theory, 64 bits pointers are too big to fit in NaN, but practically most OS uses only 48 bits at most for pointers (except for some OS e.g. Solaris). +NaN boxing packs the Ruby data in a floating-point numbers, which represent NaN (Not a Number) values. Under IEEE753 definitions every value that exponent is all set are considered as NaN. That means NaN can represent `2^51` values. NaN boxing is a teaching to pack the values in those NaN representation. In theory, 64 bit pointers are too big to fit in NaN, but practically most OS use only 48 bits at most for pointers (except for some OS e.g. Solaris). The NaN boxing packing bit patterns are like following: | Types | Bit Pattern | -|--------|---------------------------------------------------------------------------| +| ------ | ------------------------------------------------------------------------- | | float | `SEEEEEEE EEEEFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF` | | +/-inf | `S1111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000` | | nan | `01111111 11111000 00000000 00000000 00000000 00000000 00000000 00000000` | diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/limitations.md b/yass/third_party/nghttp2/third-party/mruby/doc/limitations.md index ae09ecf37e..3c65f76ecd 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/limitations.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/limitations.md @@ -64,7 +64,7 @@ p Liste.new "foobar" #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)] -` [] ` +`[]` #### mruby [3.1.0 (2022-05-12)] @@ -114,7 +114,7 @@ The declaration form of following visibility methods are not implemented. Especially, `module_function` method is not dummy, but no declaration form. -``` +```ruby module TestModule module_function def test_func @@ -170,7 +170,7 @@ alias $a $__a__ #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)] -` nil ` +`nil` #### mruby [3.1.0 (2022-05-12)] @@ -196,7 +196,7 @@ The re-defined `+` operator does not accept any arguments. #### mruby [3.1.0 (2022-05-12)] -` 'ab' ` +`'ab'` Behavior of the operator wasn't changed. ## `Kernel#binding` is not supported until [3.0.0 (2021-03-05)] @@ -205,26 +205,11 @@ Behavior of the operator wasn't changed. #### Ruby [ruby 2.5.1p57 (2018-03-29 revision 63029)] -``` +```shell $ ruby -e 'puts Proc.new {}.binding' # ``` -#### mruby [3.0.0 (2021-03-05)] - -``` -$ ./bin/mruby -e 'puts Proc.new {}.binding' -trace (most recent call last): - [0] -e:1 --e:1: undefined method 'binding' (NoMethodError) -``` - -#### mruby [3.1.0 (2022-05-12)] - -`binding` has been supported since 3.1.0. - -See also [mrbgems/mruby-binding](https://github.com/mruby/mruby/tree/master/mrbgems/mruby-binding) and [mrbgems/mruby-binding-core](https://github.com/mruby/mruby/tree/master/mrbgems/mruby-binding-core). - ## `nil?` redefinition in conditional expressions Redefinition of `nil?` is ignored in conditional expressions. @@ -259,3 +244,12 @@ f(1,[2,3]) ``` CRuby gives `[1,2,3,nil]`. mruby raises `NoMethodError` for `b`. + +Keyword argument expansion has similar restrictions. The following example, gives `[1, 1]` for CRuby, mruby raises `NoMethodError` for `b`. + +```ruby +def g(a: 1, b: a) + p [a,b] +end +g(a:1) +``` diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.0.md b/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.0.md index c1acb5ecec..9d211abb5a 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.0.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.0.md @@ -42,10 +42,10 @@ We have ported some new syntax from CRuby. ## Renamed for consistency Some configuration macro names are changed for consistency (use `MRB_USE_XXX` - or `MRB_NO_XXX`). +or `MRB_NO_XXX`). -| mruby2 | mruby3 | -|--------------------------------|---------------------------| +| mruby2 | mruby3 | +| ------------------------------ | ------------------------- | | `MRB_ENABLE_ALL_SYMBOLS` | `MRB_USE_ALL_SYMBOLS` | | `MRB_ENABLE_CXX_ABI` | `MRB_USE_CXX_ABI` | | `MRB_ENABLE_CXX_EXCEPTION` | `MRB_USE_CXX_EXCEPTION` | @@ -149,7 +149,8 @@ No more operand extension ## Changed Instructions -Jump addresses used to be specified by absolute offset from the start of `iseq`. Now they are relative offset from the address of the next instruction. +Jump addresses used to be specified by absolute offset from the start of `iseq`. Now they are relative offset from the +address of the next instruction. ## `Random` now use `xoshiro128++`. @@ -159,4 +160,4 @@ For better and faster random number generation. Preallocated symbols are interned at compile-time. They can be accessed via symbols macros (e.g. `MRB_SYM()`). -See [Symbols](https://github.com/mruby/mruby/blob/master/doc/guides/symbol.md). +See [Symbols](guides/symbol.md). diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.1.md b/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.1.md index 188cc8366e..3450a11e13 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.1.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.1.md @@ -141,8 +141,8 @@ Method calling instructions are unified. Now `OP_SEND` and `OP_SENDB` (method ca The brief description of the instructions: -|`OP_SEND` | BBB | `R[a] = R[a].call(Syms[b],R[a+1..n],R[a+n+1],R[a+n+2]..nk) c=n|nk<<4` | -|`OP_SENDB` | BBB | `R[a] = R[a].call(Syms[b],R[a+1..n],R[a+n+1..nk],R[a+n+2..nk],&R[a+n+2*nk+2]) c=n|nk<<4` | +|`OP_SEND` | BBB | `R[a] = R[a].call(Syms[b],R[a+1..n],R[a+n+1],R[a+n+2]..nk) c=n|nk<<4` | +|`OP_SENDB` | BBB | `R[a] = R[a].call(Syms[b],R[a+1..n],R[a+n+1..nk],R[a+n+2..nk],&R[a+n+2*nk+2]) c=n|nk<<4` | Operand C specifies the number of arguments. Lower 4 bits (`n`) represents the number of ordinal arguments, and higher 4 bits (`nk`) represents the number of keyword arguments. When `n == 15`, the method takes arguments packed in an array. When `nk == 15`, the method takes keyword arguments are packed in a hash. @@ -225,31 +225,31 @@ For better and faster hash values. Following CVEs are fixed in this release. -- [CVE-2021-4110](https://nvd.nist.gov/vuln/detail/CVE-2021-4110) -- [CVE-2021-4188](https://nvd.nist.gov/vuln/detail/CVE-2021-4188) -- [CVE-2022-0080](https://nvd.nist.gov/vuln/detail/CVE-2022-0080) -- [CVE-2022-0240](https://nvd.nist.gov/vuln/detail/CVE-2022-0240) -- [CVE-2022-0326](https://nvd.nist.gov/vuln/detail/CVE-2022-0326) -- [CVE-2022-0481](https://nvd.nist.gov/vuln/detail/CVE-2022-0481) -- [CVE-2022-0631](https://nvd.nist.gov/vuln/detail/CVE-2022-0631) -- [CVE-2022-0632](https://nvd.nist.gov/vuln/detail/CVE-2022-0632) -- [CVE-2022-0890](https://nvd.nist.gov/vuln/detail/CVE-2022-0890) -- [CVE-2022-1071](https://nvd.nist.gov/vuln/detail/CVE-2022-1071) -- [CVE-2022-1106](https://nvd.nist.gov/vuln/detail/CVE-2022-1106) -- [CVE-2022-1201](https://nvd.nist.gov/vuln/detail/CVE-2022-1201) -- [CVE-2022-1427](https://nvd.nist.gov/vuln/detail/CVE-2022-1427) +- [CVE-2021-4110](https://www.cve.org/CVERecord?id=CVE-2021-4110) +- [CVE-2021-4188](https://www.cve.org/CVERecord?id=CVE-2021-4188) +- [CVE-2022-0080](https://www.cve.org/CVERecord?id=CVE-2022-0080) +- [CVE-2022-0240](https://www.cve.org/CVERecord?id=CVE-2022-0240) +- [CVE-2022-0326](https://www.cve.org/CVERecord?id=CVE-2022-0326) +- [CVE-2022-0481](https://www.cve.org/CVERecord?id=CVE-2022-0481) +- [CVE-2022-0631](https://www.cve.org/CVERecord?id=CVE-2022-0631) +- [CVE-2022-0632](https://www.cve.org/CVERecord?id=CVE-2022-0632) +- [CVE-2022-0890](https://www.cve.org/CVERecord?id=CVE-2022-0890) +- [CVE-2022-1071](https://www.cve.org/CVERecord?id=CVE-2022-1071) +- [CVE-2022-1106](https://www.cve.org/CVERecord?id=CVE-2022-1106) +- [CVE-2022-1201](https://www.cve.org/CVERecord?id=CVE-2022-1201) +- [CVE-2022-1427](https://www.cve.org/CVERecord?id=CVE-2022-1427) ## Unaffected CVEs Following CVEs do not cause problems in this release. They are fixed in the later release. -- [CVE-2022-0481](https://nvd.nist.gov/vuln/detail/CVE-2022-0481) -- [CVE-2022-0525](https://nvd.nist.gov/vuln/detail/CVE-2022-0525) -- [CVE-2022-0570](https://nvd.nist.gov/vuln/detail/CVE-2022-0570) -- [CVE-2022-0614](https://nvd.nist.gov/vuln/detail/CVE-2022-0614) -- [CVE-2022-0623](https://nvd.nist.gov/vuln/detail/CVE-2022-0623) -- [CVE-2022-0630](https://nvd.nist.gov/vuln/detail/CVE-2022-0630) -- [CVE-2022-0717](https://nvd.nist.gov/vuln/detail/CVE-2022-0817) -- [CVE-2022-1212](https://nvd.nist.gov/vuln/detail/CVE-2022-1212) -- [CVE-2022-1276](https://nvd.nist.gov/vuln/detail/CVE-2022-1276) -- [CVE-2022-1286](https://nvd.nist.gov/vuln/detail/CVE-2022-1286) +- [CVE-2022-0481](https://www.cve.org/CVERecord?id=CVE-2022-0481) +- [CVE-2022-0525](https://www.cve.org/CVERecord?id=CVE-2022-0525) +- [CVE-2022-0570](https://www.cve.org/CVERecord?id=CVE-2022-0570) +- [CVE-2022-0614](https://www.cve.org/CVERecord?id=CVE-2022-0614) +- [CVE-2022-0623](https://www.cve.org/CVERecord?id=CVE-2022-0623) +- [CVE-2022-0630](https://www.cve.org/CVERecord?id=CVE-2022-0630) +- [CVE-2022-0717](https://www.cve.org/CVERecord?id=CVE-2022-0817) +- [CVE-2022-1212](https://www.cve.org/CVERecord?id=CVE-2022-1212) +- [CVE-2022-1276](https://www.cve.org/CVERecord?id=CVE-2022-1276) +- [CVE-2022-1286](https://www.cve.org/CVERecord?id=CVE-2022-1286) diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.2.md b/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.2.md index 1ca18d6b40..587a0e6d2d 100644 --- a/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.2.md +++ b/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.2.md @@ -32,9 +32,9 @@ ## New bundled gems -- mruby-errno from [https://github.com/iij/mruby-errno.git] -- mruby-set from [https://github.com/yui-knk/mruby-set.git] -- mruby-dir from [https://github.com/iij/mruby-dir.git] +- mruby-errno from +- mruby-set from +- mruby-dir from - mruby-data # Breaking Changes @@ -59,22 +59,21 @@ Intentional reliance on previous behavior may cause compatibility problems in yo Following CVEs are fixed. -- [CVE-2022-0080](https://nvd.nist.gov/vuln/detail/CVE-2022-0080) -- [CVE-2022-0240](https://nvd.nist.gov/vuln/detail/CVE-2022-0240) -- [CVE-2022-0326](https://nvd.nist.gov/vuln/detail/CVE-2022-0326) -- [CVE-2022-0631](https://nvd.nist.gov/vuln/detail/CVE-2022-0631) -- [CVE-2022-0481](https://nvd.nist.gov/vuln/detail/CVE-2022-0481) -- [CVE-2022-0525](https://nvd.nist.gov/vuln/detail/CVE-2022-0525) -- [CVE-2022-0570](https://nvd.nist.gov/vuln/detail/CVE-2022-0570) -- [CVE-2022-0614](https://nvd.nist.gov/vuln/detail/CVE-2022-0614) -- [CVE-2022-0623](https://nvd.nist.gov/vuln/detail/CVE-2022-0623) -- [CVE-2022-0630](https://nvd.nist.gov/vuln/detail/CVE-2022-0630) -- [CVE-2022-0631](https://nvd.nist.gov/vuln/detail/CVE-2022-0631) -- [CVE-2022-0632](https://nvd.nist.gov/vuln/detail/CVE-2022-0632) -- [CVE-2022-0717](https://nvd.nist.gov/vuln/detail/CVE-2022-0717) -- [CVE-2022-0890](https://nvd.nist.gov/vuln/detail/CVE-2022-0890) -- [CVE-2022-1106](https://nvd.nist.gov/vuln/detail/CVE-2022-1106) -- [CVE-2022-1212](https://nvd.nist.gov/vuln/detail/CVE-2022-1212) -- [CVE-2022-1276](https://nvd.nist.gov/vuln/detail/CVE-2022-1276) -- [CVE-2022-1286](https://nvd.nist.gov/vuln/detail/CVE-2022-1286) -- [CVE-2022-1934](https://nvd.nist.gov/vuln/detail/CVE-2022-1934) +- [CVE-2022-0080](https://www.cve.org/CVERecord?id=CVE-2022-0080) +- [CVE-2022-0240](https://www.cve.org/CVERecord?id=CVE-2022-0240) +- [CVE-2022-0326](https://www.cve.org/CVERecord?id=CVE-2022-0326) +- [CVE-2022-0481](https://www.cve.org/CVERecord?id=CVE-2022-0481) +- [CVE-2022-0525](https://www.cve.org/CVERecord?id=CVE-2022-0525) +- [CVE-2022-0570](https://www.cve.org/CVERecord?id=CVE-2022-0570) +- [CVE-2022-0614](https://www.cve.org/CVERecord?id=CVE-2022-0614) +- [CVE-2022-0623](https://www.cve.org/CVERecord?id=CVE-2022-0623) +- [CVE-2022-0630](https://www.cve.org/CVERecord?id=CVE-2022-0630) +- [CVE-2022-0631](https://www.cve.org/CVERecord?id=CVE-2022-0631) +- [CVE-2022-0632](https://www.cve.org/CVERecord?id=CVE-2022-0632) +- [CVE-2022-0717](https://www.cve.org/CVERecord?id=CVE-2022-0717) +- [CVE-2022-0890](https://www.cve.org/CVERecord?id=CVE-2022-0890) +- [CVE-2022-1106](https://www.cve.org/CVERecord?id=CVE-2022-1106) +- [CVE-2022-1212](https://www.cve.org/CVERecord?id=CVE-2022-1212) +- [CVE-2022-1276](https://www.cve.org/CVERecord?id=CVE-2022-1276) +- [CVE-2022-1286](https://www.cve.org/CVERecord?id=CVE-2022-1286) +- [CVE-2022-1934](https://www.cve.org/CVERecord?id=CVE-2022-1934) diff --git a/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.3.md b/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.3.md new file mode 100644 index 0000000000..eec7732fb3 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/doc/mruby3.3.md @@ -0,0 +1,186 @@ +# User visible changes in `mruby3.3` from `mruby3.2` + +"**_NOTE_**:" are changes to be aware of. + +# The language + +- aliases work properly with `super` ([2ad3f0e](https://github.com/mruby/mruby/commit/2ad3f0e)) +- `callee` method work differently with aliases in mruby ([f2dc76e](https://github.com/mruby/mruby/commit/f2dc76e)) +- define `Kernel#respond_to_missing?` method ([347586e](https://github.com/mruby/mruby/commit/347586e)) +- `_inspect` method (`inspect` with recursive check) is removed + ([e2bbf75](https://github.com/mruby/mruby/commit/e2bbf75), [5cb0c74](https://github.com/mruby/mruby/commit/5cb0c74), [113565a](https://github.com/mruby/mruby/commit/113565a), + [0713f2a](https://github.com/mruby/mruby/commit/0713f2a), [6ae6b63](https://github.com/mruby/mruby/commit/6ae6b63), [fc9fffc](https://github.com/mruby/mruby/commit/fc9fffc)) +- `__printstr__` method is removed; use `print` instead + ([acecee0](https://github.com/mruby/mruby/commit/acecee0), [192e6e3](https://github.com/mruby/mruby/commit/192e6e3)) +- New method `String#bytesplice` ([5274647](https://github.com/mruby/mruby/commit/5274647), [a2e2e83](https://github.com/mruby/mruby/commit/a2e2e83)) +- Allow `return` in blocks to cross C boundaries ([#6125](https://github.com/mruby/mruby/pull/6125)) + +# Configuration + +- mruby can be built using Docker now. Try `docker-compose build` for example. ([#5961](https://github.com/mruby/mruby/pull/5961)) +- New Platform: DJGPP (MS-DOS) ([#6022](https://github.com/mruby/mruby/pull/6022)) +- New Platform: Nintendo Wii ([#6086](https://github.com/mruby/mruby/pull/6086)) +- Improved Platform: Android ([#6013](https://github.com/mruby/mruby/pull/6013)) +- Improved Platform: Dreamcast ([#6130](https://github.com/mruby/mruby/pull/6130)) +- Allow tests to be disabled for specific gems; warn about disabled tests ([#6012](https://github.com/mruby/mruby/pull/6012)) +- Replace `MRB_NO_DIRECT_THREADING` with `MRB_USE_VM_SWITCH_DISPATCH` ([#5902](https://github.com/mruby/mruby/pull/5902)) + +# mruby memory API + +- `mrb_default_allocf` can be overridden by the application ([34c5d96](https://github.com/mruby/mruby/commit/34c5d96)) +- `mrb_open_allocf` will be deprecated ([cfee5c2](https://github.com/mruby/mruby/commit/cfee5c2)) + +# Changes in C API + +- add new error handling API functions ([8c8bbd9](https://github.com/mruby/mruby/commit/8c8bbd9)) +- Add `mrb_vm_ci_env_clear()` function with `MRB_API` ([#5945](https://github.com/mruby/mruby/pull/5945)) +- a new function `mrb_check_frozen_value()` ([ccdf75c](https://github.com/mruby/mruby/commit/ccdf75c)) +- avoid formatting in `mrb_bug()` ([82a48bd](https://github.com/mruby/mruby/commit/82a48bd))
+ **_NOTE_**: If you are using it, you must give a simple string or replace it with a call to `mrb_raise()` series. +- stop using `mrbc_` prefix for compiler context ([c5e3cbe](https://github.com/mruby/mruby/commit/c5e3cbe))
+ The same names are provided as before, but we recommend replacing them. +- Allow `Class#allocate` to be prohibited + ([#5979](https://github.com/mruby/mruby/pull/5979), [#6122](https://github.com/mruby/mruby/pull/6122), [#6123](https://github.com/mruby/mruby/pull/6123))
+ To disable `#allocate`, use `MRB_UNDEF_ALLOCATOR()`. + This is also automatically applied when the subclass is created, but to explicitly allow it, use `MRB_DEFINE_ALLOCATOR()`. + +# Changes in mrbgems + +- **default.gembox**: Add mruby debugger mrdb (`mruby-bin-debugger`) ([#5966](https://github.com/mruby/mruby/pull/5966)) +- **mruby-bin-config**: new options `--cxx`, `--cxxflags`, `--as`, `--asflags`, `--objc`, `--objcflags` ([#6054](https://github.com/mruby/mruby/pull/6054)) +- **mruby-binding**: renamed from `mruby-binding-core` of mruby3.2 ([11af5db](https://github.com/mruby/mruby/commit/11af5db))
+ **_NOTE_**: If using `mruby-binding-core` of mruby 3.2, replace it with `mruby-binding`. +- **mruby-binding**: implemented `Binding#initialize_copy` method ([#5517](https://github.com/mruby/mruby/pull/5517)) +- **mruby-binding**: `Kernel#binding` responds only to calls from Ruby ([#5981](https://github.com/mruby/mruby/pull/5981)) +- **mruby-compar-ext**: Comparable#clamp to accept nil as arguments ([836bebc](https://github.com/mruby/mruby/commit/836bebc)) +- **mruby-compiler**: add print name for identifier tokens ([d7b2e3a](https://github.com/mruby/mruby/commit/d7b2e3a)) +- **mruby-data**: allow empty Data ([927a9df](https://github.com/mruby/mruby/commit/927a9df)) +- **mruby-enumerator**: remove internal attribute methods `obj`, `args`, `kwd`, `meth`, `fib`. ([735fa24](https://github.com/mruby/mruby/commit/735fa24)) +- **mruby-enumerator**: add Enumerator#size ([861f8bd](https://github.com/mruby/mruby/commit/861f8bd)) +- **mruby-eval**: merged `mruby-binding` of mruby3.2 ([501b22a](https://github.com/mruby/mruby/commit/501b22a), [#5989](https://github.com/mruby/mruby/pull/5989))
+ **_NOTE_**: If using `mruby-binding` of mruby 3.2, replace it with `mruby-eval`. +- **mruby-fiber**: Add a new `mrb_fiber_new()` with `MRB_API` ([#6097](https://github.com/mruby/mruby/pull/6097)) +- **mruby-fiber**: Allows calling `Fiber#resume` from C ([#6106](https://github.com/mruby/mruby/pull/6106)) +- **mruby-fiber**: `Fiber#to_s` format changed ([#6105](https://github.com/mruby/mruby/pull/6105)) +- **mruby-io**: add File#atime and File#ctime ([321cfe9](https://github.com/mruby/mruby/commit/321cfe9)) +- **mruby-io**: Add "x" mode option for `IO.open` ([#6081](https://github.com/mruby/mruby/pull/6081)) +- **mruby-io**: File.new should not take blocks ([53de964](https://github.com/mruby/mruby/commit/53de964)) +- **mruby-method**: `Method#to_s` format changed ([f5bc82f](https://github.com/mruby/mruby/commit/f5bc82f), [02f189c](https://github.com/mruby/mruby/commit/02f189c)) +- **mruby-numeric-ext**: `int.pow(n,m)` to take bigint as exponential ([d482eab](https://github.com/mruby/mruby/commit/d482eab)) +- **mruby-pack**: support new directives `j`, `J`, `b`, `B`, `#` + ([2a1e3a5](https://github.com/mruby/mruby/commit/2a1e3a5), [e7021f1](https://github.com/mruby/mruby/commit/e7021f1), [e17f325](https://github.com/mruby/mruby/commit/e17f325)) +- **mruby-range-ext**: new method `Range#overlap?` ([384d0e2](https://github.com/mruby/mruby/commit/384d0e2)) +- **mruby-string-ext**: Add `String#valid_encoding?` method ([eabe2d9](https://github.com/mruby/mruby/commit/eabe2d9)) +- **mruby-struct**: allow empty Struct when a name is not given ([c212ede](https://github.com/mruby/mruby/commit/c212ede)) +- **mruby-time**: should allow year before 1900 ([e5de08b](https://github.com/mruby/mruby/commit/e5de08b)) +- **mruby-time**: support bigint to time_t if necessary ([7096d27](https://github.com/mruby/mruby/commit/7096d27)) +- **mruby-time**: need to handle negative time_t ([b064d7e](https://github.com/mruby/mruby/commit/b064d7e)) + +# Changes in build system + +- Extended `rake install` task ([#5928](https://github.com/mruby/mruby/pull/5928))
+ **_NOTE_**: Due to this impact, executable files in the `mruby/bin/` directory by default are now symbolic links (batch files on Windows). + If previously relied on those executables, should be replaced with direct references to the entity created under the build directory (e.g. `mruby/build/host/bin/`). +- Encode and decode escape characters for presym ([#6011](https://github.com/mruby/mruby/pull/6011)) +- Rakefile: remove default build target directories in `deep_clean` ([#6032](https://github.com/mruby/mruby/pull/6032), [1e38569](https://github.com/mruby/mruby/commit/1e38569)) + +# Other breaking changes + +- `mrb_f_raise()` is now an internal function + ([#5923](https://github.com/mruby/mruby/pull/5923), [#6070](https://github.com/mruby/mruby/pull/6070)) +- `mrb_make_exception()` is now an internal function with different parameters + ([431f83e](https://github.com/mruby/mruby/commit/431f83e), [78137f3](https://github.com/mruby/mruby/commit/78137f3)) +- The `File#path` method no longer uses the `#to_path` method for implicit conversion + ([d86c4a7](https://github.com/mruby/mruby/commit/d86c4a7)) +- stop mrb isolation for each test file ([a20fbe5](https://github.com/mruby/mruby/commit/a20fbe5)) +- RBreak remembers the CI location ([#6103](https://github.com/mruby/mruby/pull/6103)) + +# Bugs Fixed + +- [#5724](https://github.com/mruby/mruby/issues/5724) Rational#\*\* is missing +- [#5725](https://github.com/mruby/mruby/issues/5725) weird const_missing exceptions in mrblib code +- [#5789](https://github.com/mruby/mruby/issues/5789) No memory release of backtrace information due to stack error +- [#5932](https://github.com/mruby/mruby/issues/5932) How to create a block using the C API? mrb_yield keeps crashing! +- [#5943](https://github.com/mruby/mruby/issues/5943) TCPSocket#write is failed +- [#5944](https://github.com/mruby/mruby/issues/5944) Behavior of calling method with a hash variable +- [#5946](https://github.com/mruby/mruby/pull/5946) Don't switch constant search path from modules to Object +- [#5949](https://github.com/mruby/mruby/issues/5949) Caller appears to report wrong line when block passed and brackets omitted +- [0906cd7](https://github.com/mruby/mruby/commit/0906cd7) numeric.c: fix rounding function issues with big numbers +- [#5974](https://github.com/mruby/mruby/issues/5974) Invalid escape sequences in gem_init.c on windows +- [#5975](https://github.com/mruby/mruby/issues/5975) Equals comparison fails on extreme ends of 64-bit integers +- [#5985](https://github.com/mruby/mruby/issues/5985) Sign extension with OP_LOADI32 in get_int_operand() +- [#5986](https://github.com/mruby/mruby/issues/5986) Fix bugs in String#bytesplice +- [#5987](https://github.com/mruby/mruby/issues/5987) ~(-1 << 64) is incorrect +- [#5991](https://github.com/mruby/mruby/issues/5991) 'gets' method not working in mruby-3.2.0 +- [#5994](https://github.com/mruby/mruby/pull/5994) fix typo in mrbgems/mruby-io/src/io.c +- [#5995](https://github.com/mruby/mruby/issues/5995) One seemingly unnecessary parameter is passed in the block parameters +- [#6008](https://github.com/mruby/mruby/pull/6008) Make "bintest" independent of directory +- [b47c8b7](https://github.com/mruby/mruby/commit/b47c8b7) gc.c (clear_all_old): fix a generational GC bug +- [#6029](https://github.com/mruby/mruby/issues/6029) mruby build fails under mrbgems directory +- [a264965](https://github.com/mruby/mruby/commit/a264965) mruby-os-memsize/memsize.c: fix irep size calculation +- [3310e10](https://github.com/mruby/mruby/commit/3310e10) mruby-test/mrbgem.rake: fix mrb_state handling bug +- [#6041](https://github.com/mruby/mruby/issues/6041) GC Performance may have degraded +- [#6044](https://github.com/mruby/mruby/issues/6044) Generated presym/table.h contains invalid characters +- [#6051](https://github.com/mruby/mruby/issues/6051) Null pointer dereference in mrb_addrinfo_unix_path +- [#6052](https://github.com/mruby/mruby/issues/6052) Null pointer dereference while handling the Proc class +- [#6055](https://github.com/mruby/mruby/pull/6055) Fix libmruby name for VisualC++ +- [#6060](https://github.com/mruby/mruby/issues/6060) SEGFAULT Issue Related to Fiber Usage in ngx_mruby Development +- [#6061](https://github.com/mruby/mruby/issues/6061) Performance issue in String#codepoints +- [#6064](https://github.com/mruby/mruby/issues/6064) MRUBY_PACKAGE_DIR does not always have a value. +- [#6065](https://github.com/mruby/mruby/issues/6065) Null pointer dereference while handling the Proc class +- [#6066](https://github.com/mruby/mruby/issues/6066) Null pointer dereference involving Struct.new() +- [#6067](https://github.com/mruby/mruby/issues/6067) Null pointer dereference in mrb_string_value_cstr +- [#6068](https://github.com/mruby/mruby/issues/6068) Stack overflow in mrb_vm_exec +- [#6076](https://github.com/mruby/mruby/pull/6076) Fixed unwinding block that could point to invalid PC +- [#6084](https://github.com/mruby/mruby/issues/6084) Incorrect symbolic sinks in binary built on Linux +- [#6087](https://github.com/mruby/mruby/issues/6087) 'Remote branch HEAD not found in upstream origin' error on build +- [#6089](https://github.com/mruby/mruby/issues/6089) binding.eval() handles def expressions differently from CRuby +- [#6098](https://github.com/mruby/mruby/issues/6098) Fails to call superclass of wrapped method +- [#6099](https://github.com/mruby/mruby/issues/6099) `ensure` section is not executed if the function exits via a return in a proc +- [#6108](https://github.com/mruby/mruby/issues/6108) VM crashes with break +- [#6118](https://github.com/mruby/mruby/pull/6118) Fixed IO#read with buf +- [#6120](https://github.com/mruby/mruby/pull/6120) Set EBADF if check_file_descriptor() fails +- [#6126](https://github.com/mruby/mruby/pull/6126) Fixed return value of `OP_RETURN_BLK` called directly under C function +- [#6134](https://github.com/mruby/mruby/issues/6134) String#unpack1 returns an array instead of a single string +- [#6136](https://github.com/mruby/mruby/pull/6136) Fixed when combined `mrb_fiber_resume()` and `Fiber#transfer` + +# Pull Requests (User Visible Ones) + +- [#5517](https://github.com/mruby/mruby/pull/5517) Fixed local variables not separated between copied binding objects +- [#5902](https://github.com/mruby/mruby/pull/5902) Replace `MRB_NO_DIRECT_THREADING` with `MRB_USE_VM_SWITCH_DISPATCH` +- [#5923](https://github.com/mruby/mruby/pull/5923) Demotion `mrb_f_raise()` from `MRB_API` +- [#5928](https://github.com/mruby/mruby/pull/5928) Improved `rake install` +- [#5945](https://github.com/mruby/mruby/pull/5945) Avoid exposure for `REnv` objects +- [#5946](https://github.com/mruby/mruby/pull/5946) Don't switch constant search path from modules to Object +- [#5966](https://github.com/mruby/mruby/pull/5966) Update default.gembox add mruby debugger mrdb +- [#5979](https://github.com/mruby/mruby/pull/5979) Allow Class#allocate to be prohibited +- [#5981](https://github.com/mruby/mruby/pull/5981) `Kernel#binding` responds only to calls from Ruby +- [#5989](https://github.com/mruby/mruby/pull/5989) Integrate mruby-binding-eval into mruby-eval +- [#5961](https://github.com/mruby/mruby/pull/5961) Add Docker to build and run all mruby tests. Run pre-commit and generate YARD docs with Docker +- [#5994](https://github.com/mruby/mruby/pull/5994) fix typo in mrbgems/mruby-io/src/io.c +- [#6008](https://github.com/mruby/mruby/pull/6008) Make "bintest" independent of directory +- [#6009](https://github.com/mruby/mruby/pull/6009) Avoid adding /bintest which does not exist +- [#6011](https://github.com/mruby/mruby/pull/6011) Encode and decode escape characters for presym +- [#6012](https://github.com/mruby/mruby/pull/6012) Allow tests to be disabled for specific gems; warn about disabled tests +- [#6013](https://github.com/mruby/mruby/pull/6013) Fix Android toolchain +- [#6022](https://github.com/mruby/mruby/pull/6022) Build configuration for MS-DOS and DJGPP +- [#6032](https://github.com/mruby/mruby/pull/6032) Rake: update task clean to remove bin and build folders +- [#6045](https://github.com/mruby/mruby/pull/6045) Fixes escape sequence bug and enhancements in Presym scanning +- [#6054](https://github.com/mruby/mruby/pull/6054) Extends `bin/mruby-config` +- [#6055](https://github.com/mruby/mruby/pull/6055) Fix libmruby name for VisualC++ +- [#6070](https://github.com/mruby/mruby/pull/6070) Demotion mrb_f_raise() in kernel.c from MRB_API too +- [#6076](https://github.com/mruby/mruby/pull/6076) Fixed unwinding block that could point to invalid PC +- [#6081](https://github.com/mruby/mruby/pull/6081) Add "x" mode option for IO.open +- [#6086](https://github.com/mruby/mruby/pull/6086) Add build config for Nintendo Wii +- [#6097](https://github.com/mruby/mruby/pull/6097) Add a new mrb_fiber_new() with MRB_API +- [#6103](https://github.com/mruby/mruby/pull/6103) RBreak remembers the CI location +- [#6105](https://github.com/mruby/mruby/pull/6105) Implement `Fiber#to_s` method +- [#6106](https://github.com/mruby/mruby/pull/6106) Ease fiber limitations +- [#6118](https://github.com/mruby/mruby/pull/6118) Fixed IO#read with buf +- [#6120](https://github.com/mruby/mruby/pull/6120) Set EBADF if check_file_descriptor() fails +- [#6122](https://github.com/mruby/mruby/pull/6122) Prohibit `Class#allocate` in a different way +- [#6123](https://github.com/mruby/mruby/pull/6123) Inherit `MRB_FL_UNDEF_ALLOCATE` in subclasses +- [#6125](https://github.com/mruby/mruby/pull/6125) Allow `OP_RETURN_BLK` to cross C boundaries +- [#6126](https://github.com/mruby/mruby/pull/6126) Fixed return value of `OP_RETURN_BLK` called directly under C function +- [#6130](https://github.com/mruby/mruby/pull/6130) `dreamcast_shelf build config`: complete overhaul +- [#6136](https://github.com/mruby/mruby/pull/6136) Fixed when combined `mrb_fiber_resume()` and `Fiber#transfer` diff --git a/yass/third_party/nghttp2/third-party/mruby/docker-compose.yml b/yass/third_party/nghttp2/third-party/mruby/docker-compose.yml new file mode 100644 index 0000000000..009947b0f9 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.8" +services: + test: + build: + context: . + command: sh -c 'rake deep_clean && rake -m test:build && rake test:run' + environment: + - MRUBY_CONFIG=ci/gcc-clang + - CC=gcc + - CXX=g++ + - LD=gcc + - SKIP=check-executables-have-shebangs + working_dir: /app diff --git a/yass/third_party/nghttp2/third-party/mruby/examples/mrbgems/cdata_extension_example/src/example.c b/yass/third_party/nghttp2/third-party/mruby/examples/mrbgems/cdata_extension_example/src/example.c index ac5593e71e..4be26489dc 100644 --- a/yass/third_party/nghttp2/third-party/mruby/examples/mrbgems/cdata_extension_example/src/example.c +++ b/yass/third_party/nghttp2/third-party/mruby/examples/mrbgems/cdata_extension_example/src/example.c @@ -35,7 +35,7 @@ mrb_foo_get_bar(mrb_state *mrb, mrb_value self) struct Foo *f; f = (struct Foo*)mrb_data_get_ptr(mrb, self, &mrb_foo_type); - if(f == NULL) { + if (f == NULL) { mrb_raise(mrb, E_RUNTIME_ERROR, "uninitialized data"); } @@ -49,7 +49,7 @@ mrb_foo_set_bar(mrb_state *mrb, mrb_value self) int v; f = (struct Foo*)mrb_data_get_ptr(mrb, self, &mrb_foo_type); - if(f == NULL) { + if (f == NULL) { mrb_raise(mrb, E_RUNTIME_ERROR, "uninitialized data"); } diff --git a/yass/third_party/nghttp2/third-party/mruby/examples/mrbgems/mruby-YOUR-bigint/TODO-HINT.md b/yass/third_party/nghttp2/third-party/mruby/examples/mrbgems/mruby-YOUR-bigint/TODO-HINT.md index 4027df969b..4926afe15e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/examples/mrbgems/mruby-YOUR-bigint/TODO-HINT.md +++ b/yass/third_party/nghttp2/third-party/mruby/examples/mrbgems/mruby-YOUR-bigint/TODO-HINT.md @@ -10,7 +10,7 @@ The file structure in this example is as follows: +- mruby-YOUR-bigint/ <- Make this directory public if necessary. | Change the name of copied directory. | - +- TODO-HINT.md <- This file is currently viewing by you. + +- TODO-HINT.md <- You are currently viewing this file. | Remove this from copied directory. | +- core/ @@ -21,19 +21,19 @@ The file structure in this example is as follows: May be depended on by other GEMs. ``` -Implementors of own bigints should copy below this directory to another directory and do the following: +Implementers of their own bigints should copy below this directory to another directory and do the following: -- Rewrite `spec.author`, `spec.license`, `spec.homepage` and `spec.summary` in `/mrbgem.rake` file to those of your own implementors. +- Rewrite `spec.author`, `spec.license`, `spec.homepage` and `spec.summary` in `/mrbgem.rake` file to those of your own implementers. - Implement the respective functions in `/core/bigint.c`. - Define and use an object structure for `MRB_TT_BIGINT` type-tag. - It is recommended to use `mrb_static_assert_object_size()` to ensure that the size of the object structure is within 6 words. + It is recommended to use `mrb_static_assert_object_size()` to ensure that the size of the object structure is within six words. - Delete this file from the destination of the copy. If you wish to use it as an alternative to the `mruby-bigint` provided by mruby, please leave the GEM name in `/mrbgem.rake` as it is. This is an important factor when it is depended from other GEMs with `spec.add_dependency 'mruby-bigint'`. -The name of the top directory of GEM can be changed arbitrarily. -The name of the git repository can also be changed arbitrarily. +The name of the top directory of the GEM can be changed arbitrarily. +The name of the Git repository can also be changed arbitrarily. -Note that there is no need for an initialization function as there is in normal GEM. +Note that there is no need for an initialization function as there is in a normal GEM. If you need it, create a file `/src/bigint.c` for example, and implement the `mrb_mruby_bigint_gem_init()` function. diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mrbconf.h b/yass/third_party/nghttp2/third-party/mruby/include/mrbconf.h index 1629a5c456..122eb2b0e9 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mrbconf.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mrbconf.h @@ -176,8 +176,8 @@ #if defined(DISABLE_STDIO) || defined(MRB_DISABLE_STDIO) # define MRB_NO_STDIO #endif -#ifdef MRB_DISABLE_DIRECT_THREADING -# define MRB_NO_DIRECT_THREADING +#if defined(MRB_DISABLE_DIRECT_THREADING) || defined(MRB_NO_DIRECT_THREADING) +# define MRB_USE_VM_SWITCH_DISPATCH #endif #if defined(ENABLE_DEBUG) || defined(MRB_ENABLE_DEBUG_HOOK) # define MRB_USE_DEBUG_HOOK diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby.h index 2d96b25e04..4048edf694 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby.h @@ -1,7 +1,7 @@ /* ** mruby - An embeddable Ruby implementation ** -** Copyright (c) mruby developers 2010-2023 +** Copyright (c) mruby developers 2010- ** ** Permission is hereby granted, free of charge, to any person obtaining ** a copy of this software and associated documentation files (the @@ -139,7 +139,7 @@ #endif /** - * MRuby C API entry point + * mruby C API entry point */ MRB_BEGIN_DECL @@ -162,11 +162,11 @@ struct mrb_state; * * The function pointing it must behave similarly as realloc except: * - If ptr is NULL it must allocate new space. - * - If s is NULL, ptr must be freed. + * - If size is zero, ptr must be freed. * * See @see mrb_default_allocf for the default implementation. */ -typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud); +typedef void* (*mrb_allocf) (struct mrb_state *mrb, void *ptr, size_t size, void *ud); #ifndef MRB_FIXED_STATE_ATEXIT_STACK_SIZE #define MRB_FIXED_STATE_ATEXIT_STACK_SIZE 5 @@ -420,7 +420,7 @@ MRB_API void mrb_prepend_module(mrb_state *mrb, struct RClass *cla, struct RClas * mrb_define_method(mrb, mrb->kernel_module, "example_method", example_method, MRB_ARGS_NONE()); * } * - * @param mrb The MRuby state reference. + * @param mrb The mruby state reference. * @param cla The class pointer where the method will be defined. * @param name The name of the method being defined. * @param func The function pointer to the method definition. @@ -448,7 +448,7 @@ MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, * foo = mrb_define_class(mrb, "Foo", mrb->object_class); * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); * } - * @param mrb The MRuby state reference. + * @param mrb The mruby state reference. * @param cla The class where the class method will be defined. * @param name The name of the class method being defined. * @param fun The function pointer to the class method definition. @@ -484,7 +484,7 @@ MRB_API void mrb_define_singleton_method_id(mrb_state *mrb, struct RObject *cla, * foo = mrb_define_module(mrb, "Foo"); * mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); * } - * @param mrb The MRuby state reference. + * @param mrb The mruby state reference. * @param cla The module where the module function will be defined. * @param name The name of the module function being defined. * @param fun The function pointer to the module function definition. @@ -514,7 +514,7 @@ MRB_API void mrb_define_module_function_id(mrb_state *mrb, struct RClass *cla, m * mrb_value * mrb_example_gem_final(mrb_state* mrb){ * } - * @param mrb The MRuby state reference. + * @param mrb The mruby state reference. * @param cla A class or module the constant is defined in. * @param name The name of the constant being defined. * @param val The value for the constant. @@ -1017,7 +1017,7 @@ struct mrb_kwargs /** * Retrieve arguments from mrb_state. * - * @param mrb The current MRuby state. + * @param mrb The current mruby state. * @param format is a list of format specifiers * @param ... The passing variadic arguments must be a pointer of retrieving type. * @return the number of arguments retrieved. @@ -1248,7 +1248,7 @@ MRB_API mrb_state* mrb_open(void); MRB_API mrb_state* mrb_open_allocf(mrb_allocf f, void *ud); /** - * Create new mrb_state with just the MRuby core + * Create new mrb_state with just the mruby core * * @param f * Reference to the allocation function. @@ -1303,26 +1303,17 @@ MRB_API mrb_bool mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2); /* mrb_cmp(mrb, obj1, obj2): 1:0:-1; -2 for error */ MRB_API mrb_int mrb_cmp(mrb_state *mrb, mrb_value obj1, mrb_value obj2); -MRB_INLINE int -mrb_gc_arena_save(mrb_state *mrb) -{ - return mrb->gc.arena_idx; -} - -MRB_INLINE void -mrb_gc_arena_restore(mrb_state *mrb, int idx) -{ - mrb->gc.arena_idx = idx; -} +#define mrb_gc_arena_save(mrb) ((mrb)->gc.arena_idx) +#define mrb_gc_arena_restore(mrb, idx) ((mrb)->gc.arena_idx = (idx)) MRB_API void mrb_garbage_collect(mrb_state*); MRB_API void mrb_full_gc(mrb_state*); -MRB_API void mrb_incremental_gc(mrb_state *); +MRB_API void mrb_incremental_gc(mrb_state*); MRB_API void mrb_gc_mark(mrb_state*,struct RBasic*); #define mrb_gc_mark_value(mrb,val) do {\ if (!mrb_immediate_p(val)) mrb_gc_mark((mrb), mrb_basic_ptr(val)); \ } while (0) -MRB_API void mrb_field_write_barrier(mrb_state *, struct RBasic*, struct RBasic*); +MRB_API void mrb_field_write_barrier(mrb_state*, struct RBasic*, struct RBasic*); #define mrb_field_write_barrier_value(mrb, obj, val) do{\ if (!mrb_immediate_p(val)) mrb_field_write_barrier((mrb), (obj), mrb_basic_ptr(val)); \ } while (0) @@ -1366,7 +1357,7 @@ MRB_API mrb_noreturn void mrb_name_error(mrb_state *mrb, mrb_sym id, const char MRB_API mrb_noreturn void mrb_frozen_error(mrb_state *mrb, void *frozen_obj); MRB_API mrb_noreturn void mrb_argnum_error(mrb_state *mrb, mrb_int argc, int min, int max); MRB_API void mrb_warn(mrb_state *mrb, const char *fmt, ...); -MRB_API mrb_noreturn void mrb_bug(mrb_state *mrb, const char *fmt, ...); +MRB_API mrb_noreturn void mrb_bug(mrb_state *mrb, const char *mesg); MRB_API void mrb_print_backtrace(mrb_state *mrb); MRB_API void mrb_print_error(mrb_state *mrb); /* function for `raisef` formatting */ @@ -1378,6 +1369,8 @@ MRB_API mrb_value mrb_vformat(mrb_state *mrb, const char *format, va_list ap); + exception objects obtained from those macros are local to mrb */ #define MRB_ERROR_SYM(sym) mrb_intern_lit(mrb, #sym) +#define E_EXCEPTION mrb->eException_class +#define E_STANDARD_ERROR mrb->eStandardError_class #define E_RUNTIME_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RuntimeError)) #define E_TYPE_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(TypeError)) #define E_ZERODIV_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ZeroDivisionError)) @@ -1436,12 +1429,8 @@ MRB_API mrb_value mrb_ensure_int_type(mrb_state *mrb, mrb_value val); /* string type checking (contrary to the name, it doesn't convert) */ MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t); - -MRB_INLINE void mrb_check_frozen(mrb_state *mrb, void *o) -{ - if (mrb_frozen_p((struct RBasic*)o)) mrb_frozen_error(mrb, o); -} - +MRB_API void mrb_check_frozen(mrb_state *mrb, void *); +MRB_API void mrb_check_frozen_value(mrb_state *mrb, mrb_value v); MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass *c, const char *a, const char *b); MRB_API void mrb_define_alias_id(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b); MRB_API const char *mrb_class_name(mrb_state *mrb, struct RClass* klass); @@ -1456,14 +1445,19 @@ MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mr /* obsolete function(s); will be removed */ #define mrb_int(mrb, val) mrb_as_int(mrb, val) +/** + * Create a new Fiber from proc object + * + * Implemented in mruby-fiber + */ +MRB_API mrb_value mrb_fiber_new(mrb_state *mrb, const struct RProc *proc); + /** * Resume a Fiber * * Implemented in mruby-fiber * * Switches to the specified fiber and executes. Like the `Fiber#resume` method. - * - * @note It can only be called before entering the mruby VM (e.g. in the `main()` function). */ MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv); diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/class.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/class.h index ff16f1ac11..5be1b8e911 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/class.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/class.h @@ -26,6 +26,10 @@ struct RClass { MRB_INLINE struct RClass* mrb_class(mrb_state *mrb, mrb_value v) { + if (!mrb_immediate_p(v)) { + return mrb_obj_ptr(v)->c; + } + switch (mrb_type(v)) { case MRB_TT_FALSE: if (mrb_fixnum(v)) @@ -43,20 +47,19 @@ mrb_class(mrb_state *mrb, mrb_value v) #endif case MRB_TT_CPTR: return mrb->object_class; - case MRB_TT_ENV: - return NULL; default: - return mrb_obj_ptr(v)->c; + return NULL; } } /* flags: - 20: frozen - 19: is_prepended - 18: is_origin - 17: is_inherited (used by method cache) - 16: unused - 0-15: instance type + 20: frozen + 19: is_prepended + 18: is_origin + 17: is_inherited (used by method cache) + 7-16: unused + 6: prohibit Class#allocate + 0-5: instance type */ #define MRB_FL_CLASS_IS_PREPENDED (1 << 19) #define MRB_FL_CLASS_IS_ORIGIN (1 << 18) @@ -69,9 +72,13 @@ mrb_class(mrb_state *mrb, mrb_value v) }\ } while (0) #define MRB_FL_CLASS_IS_INHERITED (1 << 17) -#define MRB_INSTANCE_TT_MASK (0xFF) +#define MRB_INSTANCE_TT_MASK (0x1F) #define MRB_SET_INSTANCE_TT(c, tt) ((c)->flags = (((c)->flags & ~MRB_INSTANCE_TT_MASK) | (char)(tt))) #define MRB_INSTANCE_TT(c) (enum mrb_vtype)((c)->flags & MRB_INSTANCE_TT_MASK) +#define MRB_FL_UNDEF_ALLOCATE (1 << 6) +#define MRB_UNDEF_ALLOCATOR(c) (mrb_assert((c)->tt == MRB_TT_CLASS), (c)->flags |= MRB_FL_UNDEF_ALLOCATE) +#define MRB_UNDEF_ALLOCATOR_P(c) ((c)->flags & MRB_FL_UNDEF_ALLOCATE) +#define MRB_DEFINE_ALLOCATOR(c) ((c)->flags &= ~MRB_FL_UNDEF_ALLOCATE) MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t); MRB_API void mrb_alias_method(mrb_state*, struct RClass *c, mrb_sym a, mrb_sym b); diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/common.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/common.h index 59214d3c1e..fd5c110225 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/common.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/common.h @@ -67,7 +67,7 @@ MRB_BEGIN_DECL #endif #define MRB_INLINE static inline -/** Declare a public MRuby API function. */ +/** Declare a public mruby API function. */ #ifndef MRB_API #if defined(MRB_BUILD_AS_DLL) #if defined(MRB_CORE) || defined(MRB_LIB) diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/compile.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/compile.h index 70cf9a93b0..e3d0d619e1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/compile.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/compile.h @@ -10,7 +10,7 @@ #include "common.h" /** - * MRuby Compiler + * mruby Compiler */ MRB_BEGIN_DECL @@ -18,7 +18,7 @@ MRB_BEGIN_DECL struct mrb_parser_state; /* load context */ -typedef struct mrbc_context { +typedef struct mrb_ccontext { mrb_sym *syms; int slen; char *filename; @@ -35,13 +35,21 @@ typedef struct mrbc_context { const struct RProc *upper; size_t parser_nerr; -} mrbc_context; +} mrb_ccontext; /* compiler context */ -MRB_API mrbc_context* mrbc_context_new(mrb_state *mrb); -MRB_API void mrbc_context_free(mrb_state *mrb, mrbc_context *cxt); -MRB_API const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s); -MRB_API void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data); -MRB_API void mrbc_cleanup_local_variables(mrb_state *mrb, mrbc_context *c); +MRB_API mrb_ccontext* mrb_ccontext_new(mrb_state *mrb); +MRB_API void mrb_ccontext_free(mrb_state *mrb, mrb_ccontext *cxt); +MRB_API const char *mrb_ccontext_filename(mrb_state *mrb, mrb_ccontext *c, const char *s); +MRB_API void mrb_ccontext_partial_hook(mrb_state *mrb, mrb_ccontext *c, int (*partial_hook)(struct mrb_parser_state*), void*data); +MRB_API void mrb_ccontext_cleanup_local_variables(mrb_state *mrb, mrb_ccontext *c); + +/* compatibility macros */ +#define mrbc_context mrb_ccontext +#define mrbc_context_new mrb_ccontext_new +#define mrbc_context_free mrb_ccontext_free +#define mrbc_filename mrb_ccontext_filename +#define mrbc_partial_hook mrb_ccontext_partial_hook +#define mrbc_cleanup_local_variables mrb_ccontext_cleanup_local_variables /* AST node structure */ typedef struct mrb_ast_node { @@ -121,7 +129,7 @@ struct mrb_parser_state { /* If both f and s are non-null, it will be taken preferentially from s until s < send. */ FILE *f; #endif - mrbc_context *cxt; + mrb_ccontext *cxt; mrb_sym filename_sym; uint16_t lineno; int column; @@ -168,19 +176,19 @@ struct mrb_parser_state { MRB_API struct mrb_parser_state* mrb_parser_new(mrb_state*); MRB_API void mrb_parser_free(struct mrb_parser_state*); -MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrbc_context*); +MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrb_ccontext*); MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*); MRB_API mrb_sym mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx); /* utility functions */ #ifndef MRB_NO_STDIO -MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*); +MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrb_ccontext*); #endif -MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*); -MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t,mrbc_context*); +MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrb_ccontext*); +MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t,mrb_ccontext*); MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*); -MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c); +MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrb_ccontext *c); /** program load functions * Please note! Currently due to interactions with the GC calling these functions will @@ -193,13 +201,13 @@ MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc */ #ifndef MRB_NO_STDIO MRB_API mrb_value mrb_load_file(mrb_state*,FILE*); -MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt); -MRB_API mrb_value mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c); +MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrb_ccontext *cxt); +MRB_API mrb_value mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrb_ccontext *c); #endif MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s); MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, size_t len); -MRB_API mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *cxt); -MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrbc_context *cxt); +MRB_API mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *s, mrb_ccontext *cxt); +MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrb_ccontext *cxt); /** @} */ MRB_END_DECL diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/data.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/data.h index 7bdf1c34e8..a64301a57d 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/data.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/data.h @@ -41,12 +41,12 @@ MRB_API struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass #define Data_Make_Struct(mrb,klass,strct,type,sval,data_obj) do { \ (data_obj) = Data_Wrap_Struct(mrb,klass,type,NULL);\ - (sval) = (strct *)mrb_malloc(mrb, sizeof(strct)); \ + (sval) = (strct*)mrb_malloc(mrb, sizeof(strct)); \ { static const strct zero = { 0 }; *(sval) = zero; };\ (data_obj)->data = (sval);\ } while (0) -#define RDATA(obj) ((struct RData *)(mrb_ptr(obj))) +#define RDATA(obj) ((struct RData*)(mrb_ptr(obj))) #define DATA_PTR(d) (RDATA(d)->data) #define DATA_TYPE(d) (RDATA(d)->type) MRB_API void mrb_data_check_type(mrb_state *mrb, mrb_value, const mrb_data_type*); diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/debug.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/debug.h index 4a62cce426..f0409351b0 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/debug.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/debug.h @@ -10,7 +10,7 @@ #include "common.h" /** - * MRuby Debugging. + * mruby Debugging. */ MRB_BEGIN_DECL @@ -46,7 +46,7 @@ typedef struct mrb_irep_debug_info { } mrb_irep_debug_info; /* - * get line from irep's debug info and program counter + * get filename from irep's debug info and program counter * @return returns NULL if not found */ MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, const mrb_irep *irep, uint32_t pc); @@ -57,6 +57,12 @@ MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, const mrb_irep *irep, */ MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, const mrb_irep *irep, uint32_t pc); +/* + * get line and filename from irep's debug info and program counter + * @return returns FALSE if not found + */ +MRB_API mrb_bool mrb_debug_get_position(mrb_state *mrb, const mrb_irep *irep, uint32_t pc, int32_t *lp, const char **fp); + MRB_API mrb_irep_debug_info *mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep); MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file( mrb_state *mrb, mrb_irep_debug_info *info, diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/dump.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/dump.h index 863f22649e..c129015d9f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/dump.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/dump.h @@ -23,7 +23,7 @@ MRB_BEGIN_DECL #ifndef MRB_NO_STDIO MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*); -MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrbc_context*); +MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrb_ccontext*); mrb_irep *mrb_read_irep_file(mrb_state*, FILE*); int mrb_dump_irep_binary(mrb_state*, const mrb_irep*, uint8_t, FILE*); #endif diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/endian.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/endian.h index 477f3bc94e..940c47ea77 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/endian.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/endian.h @@ -34,7 +34,7 @@ static inline int check_little_endian(void) { unsigned int n = 1; - return (*(unsigned char *)&n == 1); + return (*(unsigned char*)&n == 1); } # define littleendian check_little_endian() #endif diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/error.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/error.h index ccf2cdb6e1..ee6fe8ffc1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/error.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/error.h @@ -10,7 +10,7 @@ #include "common.h" /** - * MRuby error handling. + * mruby error handling. */ MRB_BEGIN_DECL @@ -34,26 +34,33 @@ struct RException { MRB_API mrb_noreturn void mrb_sys_fail(mrb_state *mrb, const char *mesg); MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str); #define mrb_exc_new_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit)) -MRB_API mrb_value mrb_make_exception(mrb_state *mrb, mrb_int argc, const mrb_value *argv); MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...); -/* declaration for `fail` method */ -MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value); - #if defined(MRB_64BIT) || defined(MRB_USE_FLOAT32) || defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING) +#undef MRB_USE_RBREAK_VALUE_UNION +#else +#define MRB_USE_RBREAK_VALUE_UNION 1 +#endif + +/* + * flags: + * 0..7: enum mrb_vtype (only when defined MRB_USE_RBREAK_VALUE_UNION) + * 8..10: RBREAK_TAGs in src/vm.c (otherwise, set to 0) + */ struct RBreak { MRB_OBJECT_HEADER; - const struct RProc *proc; + uintptr_t ci_break_index; // The top-level ci index to break. One before the return destination. +#ifndef MRB_USE_RBREAK_VALUE_UNION mrb_value val; +#else + union mrb_value_union value; +#endif }; + +#ifndef MRB_USE_RBREAK_VALUE_UNION #define mrb_break_value_get(brk) ((brk)->val) #define mrb_break_value_set(brk, v) ((brk)->val = v) #else -struct RBreak { - MRB_OBJECT_HEADER; - const struct RProc *proc; - union mrb_value_union value; -}; #define RBREAK_VALUE_TT_MASK ((1 << 8) - 1) static inline mrb_value mrb_break_value_get(struct RBreak *brk) @@ -70,9 +77,16 @@ mrb_break_value_set(struct RBreak *brk, mrb_value val) brk->flags &= ~RBREAK_VALUE_TT_MASK; brk->flags |= val.tt; } -#endif /* MRB_64BIT || MRB_USE_FLOAT32 || MRB_NAN_BOXING || MRB_WORD_BOXING */ -#define mrb_break_proc_get(brk) ((brk)->proc) -#define mrb_break_proc_set(brk, p) ((brk)->proc = p) +#endif /* MRB_USE_RBREAK_VALUE_UNION */ + +/** + * Error check + * + */ +/* clear error status in the mrb_state structure */ +MRB_API void mrb_clear_error(mrb_state *mrb); +/* returns TRUE if error in the previous call; internally calls mrb_clear_error() */ +MRB_API mrb_bool mrb_check_error(mrb_state *mrb); /** * Protect diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/gc.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/gc.h index ba56cefd7a..ab50e08ad1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/gc.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/gc.h @@ -41,48 +41,37 @@ typedef enum { #pragma warning(disable : 4200) #endif -typedef struct mrb_heap_page { - struct RBasic *freelist; - struct mrb_heap_page *prev; - struct mrb_heap_page *next; - struct mrb_heap_page *free_next; - struct mrb_heap_page *free_prev; - mrb_bool old:1; - /* Flexible array members area a C99 feature, not C++ compatible */ - /* void* objects[]; */ -} mrb_heap_page; - #ifdef _MSC_VER #pragma warning(pop) #endif typedef struct mrb_gc { - mrb_heap_page *heaps; /* heaps for GC */ - mrb_heap_page *sweeps; - mrb_heap_page *free_heaps; - size_t live; /* count of live objects */ + struct mrb_heap_page *heaps; /* all heaps pages */ + struct mrb_heap_page *free_heaps;/* heaps for allocation */ + struct mrb_heap_page *sweeps; /* page where sweep starts */ + struct RBasic *gray_list; /* list of gray objects to be traversed incrementally */ + struct RBasic *atomic_gray_list; /* list of objects to be traversed atomically */ + size_t live; /* count of live objects */ + size_t live_after_mark; /* old generation objects */ + size_t threshold; /* threshold to start GC */ + size_t oldgen_threshold; /* threshold to kick major GC */ + mrb_gc_state state; /* current state of gc */ + int interval_ratio; + int step_ratio; + int current_white_part :2; /* make white object by white_part */ + mrb_bool iterating :1; /* currently iterating over objects */ + mrb_bool disabled :1; /* GC disabled */ + mrb_bool generational :1; /* generational GC mode */ + mrb_bool full :1; /* major GC mode */ + mrb_bool out_of_memory :1; /* out-of-memory error occurred */ + #ifdef MRB_GC_FIXED_ARENA struct RBasic *arena[MRB_GC_ARENA_SIZE]; /* GC protection array */ #else struct RBasic **arena; /* GC protection array */ - int arena_capa; + int arena_capa; /* size of protection array */ #endif int arena_idx; - - mrb_gc_state state; /* state of gc */ - int current_white_part; /* make white object by white_part */ - struct RBasic *gray_list; /* list of gray objects to be traversed incrementally */ - struct RBasic *atomic_gray_list; /* list of objects to be traversed atomically */ - size_t live_after_mark; - size_t threshold; - int interval_ratio; - int step_ratio; - mrb_bool iterating :1; - mrb_bool disabled :1; - mrb_bool full :1; - mrb_bool generational :1; - mrb_bool out_of_memory :1; - size_t majorgc_old_threshold; } mrb_gc; MRB_API mrb_bool mrb_object_dead_p(struct mrb_state *mrb, struct RBasic *object); diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/internal.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/internal.h index db64fd38f7..37c6fa1f01 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/internal.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/internal.h @@ -12,6 +12,8 @@ void mrb_ary_decref(mrb_state*, mrb_shared_array*); mrb_value mrb_ary_subseq(mrb_state *mrb, mrb_value ary, mrb_int beg, mrb_int len); #endif +mrb_bool mrb_inspect_recursive_p(mrb_state *mrb, mrb_value self); + #ifdef MRUBY_CLASS_H struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym); struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym); @@ -23,11 +25,16 @@ mrb_value mrb_mod_to_s(mrb_state *, mrb_value); void mrb_method_added(mrb_state *mrb, struct RClass *c, mrb_sym mid); mrb_noreturn void mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args); mrb_method_t mrb_vm_find_method(mrb_state *mrb, struct RClass *c, struct RClass **cp, mrb_sym mid); +mrb_value mrb_mod_const_missing(mrb_state *mrb, mrb_value mod); +mrb_value mrb_const_missing(mrb_state *mrb, mrb_value mod, mrb_sym sym); +size_t mrb_class_mt_memsize(mrb_state*, struct RClass*); #endif +mrb_value mrb_obj_equal_m(mrb_state *mrb, mrb_value); + /* debug */ size_t mrb_packed_int_len(uint32_t num); -size_t mrb_packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend); +size_t mrb_packed_int_encode(uint32_t num, uint8_t *p); uint32_t mrb_packed_int_decode(const uint8_t *p, const uint8_t **newpos); /* dump */ @@ -51,6 +58,8 @@ mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc); mrb_value mrb_get_backtrace(mrb_state *mrb); void mrb_exc_mesg_set(mrb_state *mrb, struct RException *exc, mrb_value mesg); mrb_value mrb_exc_mesg_get(mrb_state *mrb, struct RException *exc); +mrb_value mrb_f_raise(mrb_state*, mrb_value); +mrb_value mrb_make_exception(mrb_state *mrb, mrb_value exc, mrb_value mesg); /* gc */ void mrb_gc_mark_mt(mrb_state*, struct RClass*); @@ -89,6 +98,9 @@ mrb_value mrb_int_sub(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_int_mul(mrb_state *mrb, mrb_value x, mrb_value y); mrb_noreturn void mrb_int_zerodiv(mrb_state *mrb); mrb_noreturn void mrb_int_overflow(mrb_state *mrb, const char *reason); +#ifndef MRB_NO_FLOAT +void mrb_check_num_exact(mrb_state *mrb, mrb_float num); +#endif #ifdef MRB_USE_COMPLEX mrb_value mrb_complex_new(mrb_state *mrb, mrb_float x, mrb_float y); @@ -112,6 +124,11 @@ struct RProc *mrb_closure_new(mrb_state*, const mrb_irep*); void mrb_proc_copy(mrb_state *mrb, struct RProc *a, struct RProc *b); mrb_int mrb_proc_arity(const struct RProc *p); struct REnv *mrb_env_new(mrb_state *mrb, struct mrb_context *c, mrb_callinfo *ci, int nstacks, mrb_value *stack, struct RClass *tc); +void mrb_proc_merge_lvar(mrb_state *mrb, mrb_irep *irep, struct REnv *env, int num, const mrb_sym *lv, const mrb_value *stack); +mrb_value mrb_proc_local_variables(mrb_state *mrb, const struct RProc *proc); +const struct RProc *mrb_proc_get_caller(mrb_state *mrb, struct REnv **env); +mrb_value mrb_proc_get_self(mrb_state *mrb, struct RProc *p, struct RClass **target_class_p); +mrb_bool mrb_proc_eql(mrb_state *mrb, mrb_value self, mrb_value other); #endif /* range */ @@ -171,21 +188,28 @@ mrb_value mrb_f_send(mrb_state *mrb, mrb_value self); #ifdef MRB_USE_BIGINT mrb_value mrb_bint_new_int(mrb_state *mrb, mrb_int x); +#ifdef MRB_INT64 +#define mrb_bint_new_int64(mrb,x) mrb_bint_new_int((mrb),(mrb_int)(x)) +#else +mrb_value mrb_bint_new_int64(mrb_state *mrb, int64_t x); +#endif +mrb_value mrb_bint_new_uint64(mrb_state *mrb, uint64_t x); mrb_value mrb_bint_new_str(mrb_state *mrb, const char *x, mrb_int len, mrb_int base); mrb_value mrb_as_bint(mrb_state *mrb, mrb_value x); mrb_value mrb_bint_add(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_sub(mrb_state *mrb, mrb_value x, mrb_value y); +mrb_value mrb_bint_add_d(mrb_state *mrb, mrb_value x, mrb_value y); +mrb_value mrb_bint_sub_d(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_mul(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_div(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_divmod(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_add_ii(mrb_state *mrb, mrb_int x, mrb_int y); mrb_value mrb_bint_sub_ii(mrb_state *mrb, mrb_int x, mrb_int y); mrb_value mrb_bint_mul_ii(mrb_state *mrb, mrb_int x, mrb_int y); -mrb_value mrb_bint_div_ii(mrb_state *mrb, mrb_int x, mrb_int y); mrb_value mrb_bint_mod(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_rem(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_pow(mrb_state *mrb, mrb_value x, mrb_value y); -mrb_value mrb_bint_powm(mrb_state *mrb, mrb_value x, mrb_int y, mrb_value z); +mrb_value mrb_bint_powm(mrb_state *mrb, mrb_value x, mrb_value y, mrb_value z); mrb_value mrb_bint_and(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_or(mrb_state *mrb, mrb_value x, mrb_value y); mrb_value mrb_bint_xor(mrb_state *mrb, mrb_value x, mrb_value y); @@ -198,6 +222,12 @@ mrb_value mrb_bint_new_float(mrb_state *mrb, mrb_float x); mrb_float mrb_bint_as_float(mrb_state *mrb, mrb_value x); #endif mrb_int mrb_bint_as_int(mrb_state *mrb, mrb_value x); +#ifdef MRB_INT64 +#define mrb_bint_as_int64(mrb, x) mrb_bint_as_int((mrb), (x)) +#else +int64_t mrb_bint_as_int64(mrb_state *mrb, mrb_value x); +#endif +uint64_t mrb_bint_as_uint64(mrb_state *mrb, mrb_value x); mrb_int mrb_bint_cmp(mrb_state *mrb, mrb_value x, mrb_value y); void mrb_gc_free_bint(mrb_state *mrb, struct RBasic *x); void mrb_bint_copy(mrb_state *mrb, mrb_value x, mrb_value y); diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/irep.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/irep.h index ba390a05de..68e89257ad 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/irep.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/irep.h @@ -104,13 +104,13 @@ MRB_API mrb_value mrb_load_irep(mrb_state*, const uint8_t*); MRB_API mrb_value mrb_load_irep_buf(mrb_state*, const void*, size_t); /* @param [const uint8_t*] irep code, expected as a literal */ -MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrbc_context*); +MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrb_ccontext*); /* * @param [const void*] irep code * @param [size_t] size of irep buffer. */ -MRB_API mrb_value mrb_load_irep_buf_cxt(mrb_state*, const void*, size_t, mrbc_context*); +MRB_API mrb_value mrb_load_irep_buf_cxt(mrb_state*, const void*, size_t, mrb_ccontext*); struct mrb_insn_data { uint8_t insn; diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/khash.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/khash.h index 1fb6eecbba..c413ebbb71 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/khash.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/khash.h @@ -102,8 +102,8 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len) uint8_t *p = (uint8_t*)mrb_malloc_simple(mrb, sizeof(uint8_t)*sz/4+len*sz); \ if (!p) { return 1; } \ h->size = 0; \ - h->keys = (khkey_t *)p; \ - h->vals = kh_is_map ? (khval_t *)(p+sizeof(khkey_t)*sz) : NULL; \ + h->keys = (khkey_t*)p; \ + h->vals = kh_is_map ? (khval_t*)(p+sizeof(khkey_t)*sz) : NULL; \ h->ed_flags = p+len*sz; \ kh_fill_flags(h->ed_flags, 0xaa, sz/4); \ return 0; \ @@ -171,7 +171,7 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len) hh.n_buckets = new_n_buckets; \ kh_alloc_##name(mrb, &hh); \ /* relocate */ \ - for (i=0 ; iflags & MRB_PROC_SCOPE) != 0) #define MRB_PROC_NOARG 4096 /* for MRB_PROC_CFUNC_FL, it would be something like MRB_ARGS_NONE() or MRB_METHOD_NOARG_FL */ #define MRB_PROC_NOARG_P(p) (((p)->flags & MRB_PROC_NOARG) != 0) +#define MRB_PROC_ALIAS 8192 +#define MRB_PROC_ALIAS_P(p) (((p)->flags & MRB_PROC_ALIAS) != 0) #define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v))) @@ -136,6 +139,41 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx); MRB_API mrb_value mrb_load_proc(mrb_state *mrb, const struct RProc *proc); +/** + * It can be used to isolate top-level scopes referenced by blocks generated by + * `mrb_load_string_cxt()` or similar called before entering the mruby VM (e.g. from `main()`). + * In that case, the `ci` parameter should be `mrb->c->cibase`. + * + * #include + * #include + * #include + * + * int + * main(int argc, char **argv) + * { + * mrb_state *mrb; + * mrb_ccontext *cxt; + * mrb_value blk, ret; + * + * mrb = mrb_open(); + * cxt = mrb_ccontext_new(mrb); + * blk = mrb_load_string_cxt(mrb, "x, y, z = 1, 2, 3; proc { [x, y, z] }", cxt); + * mrb_vm_ci_env_clear(mrb, mrb->c->cibase); + * mrb_load_string_cxt(mrb, "x, y, z = 4, 5, 6", cxt); + * ret = mrb_funcall(mrb, blk, "call", 0); + * mrb_p(mrb, ret); // => [1, 2, 3] + * // => [4, 5, 6] if `mrb_vm_ci_env_clear()` is commented out + * mrb_ccontext_free(mrb, cxt); + * mrb_close(mrb); + * + * return 0; + * } + * + * The top-level local variable names stored in `mrb_ccontext` are retained. + * Use also `mrb_ccontext_cleanup_local_variables()` at the same time, if necessary. + */ +MRB_API void mrb_vm_ci_env_clear(mrb_state *mrb, mrb_callinfo *ci); + void mrb_vm_ci_proc_set(mrb_callinfo *ci, const struct RProc *p); struct RClass * mrb_vm_ci_target_class(const mrb_callinfo *ci); void mrb_vm_ci_target_class_set(mrb_callinfo *ci, struct RClass *tc); diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/value.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/value.h index 6666a9c147..71cdaca35e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/value.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/value.h @@ -10,7 +10,7 @@ #include "common.h" /* - * MRuby Value definition functions and macros. + * mruby Value definition functions and macros. */ MRB_BEGIN_DECL @@ -125,7 +125,7 @@ MRB_API int mrb_msvc_snprintf(char *s, size_t n, const char *format, ...); # define isinf(n) (!_finite(n) && !_isnan(n)) # define signbit(n) (_copysign(1.0, (n)) < 0.0) static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000; -# define INFINITY (*(float *)&IEEE754_INFINITY_BITS_SINGLE) +# define INFINITY (*(float*)&IEEE754_INFINITY_BITS_SINGLE) # define NAN ((float)(INFINITY - INFINITY)) # endif #endif @@ -186,7 +186,7 @@ MRB_VTYPE_FOREACH(MRB_VTYPE_TYPEDEF) /** * @abstract - * MRuby value boxing. + * mruby value boxing. * * Actual implementation depends on configured boxing type. * diff --git a/yass/third_party/nghttp2/third-party/mruby/include/mruby/version.h b/yass/third_party/nghttp2/third-party/mruby/include/mruby/version.h index 01492e0ca7..2562603c75 100644 --- a/yass/third_party/nghttp2/third-party/mruby/include/mruby/version.h +++ b/yass/third_party/nghttp2/third-party/mruby/include/mruby/version.h @@ -27,7 +27,7 @@ MRB_BEGIN_DECL /* * The version of Ruby used by mruby. */ -#define MRUBY_RUBY_VERSION "3.2" +#define MRUBY_RUBY_VERSION "3.3" /* * Ruby engine. @@ -42,7 +42,7 @@ MRB_BEGIN_DECL /* * Minor release version number. */ -#define MRUBY_RELEASE_MINOR 2 +#define MRUBY_RELEASE_MINOR 3 /* * Tiny release version number. @@ -80,7 +80,7 @@ MRB_BEGIN_DECL /* * Release year. */ -#define MRUBY_RELEASE_YEAR 2023 +#define MRUBY_RELEASE_YEAR 2024 /* * Release month. @@ -90,7 +90,7 @@ MRB_BEGIN_DECL /* * Release day. */ -#define MRUBY_RELEASE_DAY 24 +#define MRUBY_RELEASE_DAY 14 /* * Release date as a string. @@ -117,7 +117,7 @@ MRB_BEGIN_DECL #define MRUBY_BIRTH_YEAR 2010 /* - * MRuby's authors. + * mruby's authors. */ #define MRUBY_AUTHOR "mruby developers" diff --git a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build.rb b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build.rb index 4925cee33c..c4bb910b24 100644 --- a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build.rb +++ b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build.rb @@ -1,12 +1,16 @@ require "mruby/core_ext" require "mruby/build/load_gems" require "mruby/build/command" +autoload :Find, "find" module MRuby autoload :Gem, "mruby/gem" autoload :Lockfile, "mruby/lockfile" autoload :Presym, "mruby/presym" + INSTALL_PREFIX = ENV['PREFIX'] || ENV['INSTALL_PREFIX'] || '/usr/local' + INSTALL_DESTDIR = ENV['DESTDIR'] || '' + class << self def targets @targets ||= {} @@ -97,6 +101,7 @@ module MRuby @file_separator = '/' @build_dir = "#{build_dir}/#{@name}" @gem_clone_dir = "#{build_dir}/repos/#{@name}" + @install_prefix = nil @defines = [] @cc = Command::Compiler.new(self, %w(.c), label: "CC") @cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp), label: "CXX") @@ -162,9 +167,7 @@ module MRuby def enable_debug compilers.each do |c| c.defines += %w(MRB_DEBUG) - if toolchains.any? { |toolchain| toolchain == "gcc" } - c.flags += %w(-g3 -O0) - end + c.setup_debug(self) end @mrbc.compile_options += ' -g' @@ -370,14 +373,35 @@ EOS end end - def define_installer(src) - dst = "#{self.class.install_dir}/#{File.basename(src)}" + def define_installer_outline(src, dst) file dst => src do - install_D src, dst + _pp "GEN", src.relative_path, dst.relative_path + mkdir_p(File.dirname(dst)) + yield dst end dst end + if ENV['OS'] == 'Windows_NT' + def define_installer(src) + dst = "#{self.class.install_dir}/#{File.basename(src)}".pathmap("%X.bat") + define_installer_outline(src, dst) do + File.write dst, <<~BATCHFILE + @echo off + call "#{File.expand_path(src)}" %* + BATCHFILE + end + end + else + def define_installer(src) + dst = "#{self.class.install_dir}/#{File.basename(src)}" + define_installer_outline(src, dst) do + File.unlink(dst) rescue nil + File.symlink(src.relative_path_from(self.class.install_dir), dst) + end + end + end + def define_installer_if_needed(bin) exe = exefile("#{build_dir}/bin/#{bin}") host? ? define_installer(exe) : exe @@ -440,10 +464,10 @@ EOS def run_bintest puts ">>> Bintest #{name} <<<" targets = @gems.select { |v| File.directory? "#{v.dir}/bintest" }.map { |v| filename v.dir } - targets << filename(".") if File.directory? "./bintest" mrbc = @gems["mruby-bin-mrbc"] ? exefile("#{@build_dir}/bin/mrbc") : mrbcfile env = {"BUILD_DIR" => @build_dir, "MRBCFILE" => mrbc} - sh env, "ruby test/bintest.rb#{verbose_flag} #{targets.join ' '}" + bintest = File.join(MRUBY_ROOT, "test/bintest.rb") + sh env, "ruby #{bintest}#{verbose_flag} #{targets.join ' '}" end def print_build_summary @@ -485,6 +509,29 @@ EOS @internal end + def each_header_files(&block) + return to_enum(__method__) unless block + + basedir = File.join(MRUBY_ROOT, "include") + Find.find(basedir) do |d| + next unless File.file? d + yield d + end + + @gems.each { |g| g.each_header_files(&block) } + + self + end + + def install_prefix + @install_prefix || (self.name == "host" ? MRuby::INSTALL_PREFIX : + File.join(MRuby::INSTALL_PREFIX, "mruby/#{self.name}")) + end + + def install_prefix=(dir) + @install_prefix = dir&.to_s + end + protected attr_writer :presym @@ -554,7 +601,6 @@ EOS def run_bintest puts ">>> Bintest #{name} <<<" targets = @gems.select { |v| File.directory? "#{v.dir}/bintest" }.map { |v| filename v.dir } - targets << filename(".") if File.directory? "./bintest" mrbc = @gems["mruby-bin-mrbc"] ? exefile("#{@build_dir}/bin/mrbc") : mrbcfile emulator = @test_runner.command @@ -565,7 +611,8 @@ EOS "MRBCFILE" => mrbc, "EMULATOR" => @test_runner.emulator, } - sh env, "ruby test/bintest.rb#{verbose_flag} #{targets.join ' '}" + bintest = File.join(MRUBY_ROOT, "test/bintest.rb") + sh env, "ruby #{bintest}#{verbose_flag} #{targets.join ' '}" end protected diff --git a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build/command.rb b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build/command.rb index c8a3037ee5..e40b155334 100644 --- a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build/command.rb +++ b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build/command.rb @@ -99,12 +99,16 @@ module MRuby gemrake = File.join(source_dir, "mrbgem.rake") rakedep = File.exist?(gemrake) ? [ gemrake ] : [] - if build_dir.include? "mrbgems/" + bd = build_dir + if bd.start_with?(MRUBY_ROOT) + bd = bd.sub(MRUBY_ROOT, '') + end + if bd.include? "mrbgems/" generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(?!mrbc/)(.*)#{Regexp.escape out_ext}$") else generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(?!mrbc/|mrbgems/.+/)(.*)#{Regexp.escape out_ext}$") end - source_exts.each do |ext, compile| + source_exts.each do |ext| rule generated_file_matcher => [ proc { |file| file.sub(generated_file_matcher, "#{source_dir}/\\1#{ext}") @@ -129,6 +133,12 @@ module MRuby end end + # This method can be redefined as a singleton method where appropriate. + # Manipulate `flags`, `include_paths` and/or more if necessary. + def setup_debug(conf) + nil + end + private # @@ -335,7 +345,7 @@ module MRuby opt << " -s" if static cmd = %["#{filename @command}" #{opt} #{filename(infiles).map{|f| %["#{f}"]}.join(' ')}] puts cmd if Rake.verbose - IO.popen(cmd, 'r+') do |io| + IO.popen(cmd, 'r') do |io| out.puts io.read end # if mrbc execution fail, drop the file diff --git a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build/load_gems.rb b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build/load_gems.rb index 34d35ebdd5..bc7fd9010b 100644 --- a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build/load_gems.rb +++ b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/build/load_gems.rb @@ -299,7 +299,7 @@ module MRuby @build.gem_dir_to_repo_url[repo_dir] = url @build.locks[url] = { 'url' => url, - 'branch' => @build.git.current_branch(repo_dir), + 'branch' => branch || @build.git.current_branch(repo_dir), 'commit' => @build.git.commit_hash(repo_dir), } end diff --git a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/core_ext.rb b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/core_ext.rb index 1ad528c263..ac27376431 100644 --- a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/core_ext.rb +++ b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/core_ext.rb @@ -22,6 +22,27 @@ class String def remove_leading_parents Pathname.new(".#{Pathname.new("/#{self}").cleanpath}").cleanpath.to_s end + + def replace_prefix_by(dirmap) + [self].replace_prefix_by(dirmap)[0] + end +end + +class Array + # Replace the prefix of each string that is a file path that contains in its own array. + # + # dirmap is a hash whose elements are `{ "path/to/old-prefix" => "path/to/new-prefix", ... }`. + # If it does not match any element of dirmap, the file path is not replaced. + def replace_prefix_by(dirmap) + dirmap = dirmap.map { |older, newer| [File.join(older, "/"), File.join(newer, "/")] } + dirmap.sort! + dirmap.reverse! + self.flatten.map do |e| + map = dirmap.find { |older, newer| e.start_with?(older) } + e = e.sub(map[0], map[1]) if map + e + end + end end def install_D(src, dst) diff --git a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/gem.rb b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/gem.rb index 64c6f3dee4..35aa2bd52e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/gem.rb +++ b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/gem.rb @@ -36,6 +36,7 @@ module MRuby attr_accessor :export_include_paths attr_reader :generate_functions + attr_writer :skip_test attr_block MRuby::Build::COMMANDS @@ -62,6 +63,7 @@ module MRuby @test_preload = nil # 'test/assert.rb' @test_args = {} + @skip_test = false @bins = [] @cdump = true @@ -87,6 +89,10 @@ module MRuby build.locks[repo_url]['version'] = version if repo_url end + def skip_test? + @skip_test + end + def setup_compilers (core? ? [@cc, *(@cxx if build.cxx_exception_enabled?)] : compilers).each do |compiler| compiler.define_rules build_dir, @dir, @build.exts.presym_preprocessed if build.presym_enabled? @@ -209,7 +215,6 @@ module MRuby f.puts %Q[void mrb_#{funcname}_gem_final(mrb_state *mrb);] f.puts %Q[] f.puts %Q[void GENERATED_TMP_mrb_#{funcname}_gem_init(mrb_state *mrb) {] - f.puts %Q[ int ai = mrb_gc_arena_save(mrb);] f.puts %Q[ gem_mrblib_#{funcname}_proc_init_syms(mrb);] if !rbfiles.empty? && cdump? f.puts %Q[ mrb_#{funcname}_gem_init(mrb);] if objs != [objfile("#{build_dir}/gem_init")] unless rbfiles.empty? @@ -218,16 +223,7 @@ module MRuby else f.puts %Q[ mrb_load_irep(mrb, gem_mrblib_irep_#{funcname});] end - f.puts %Q[ if (mrb->exc) {] - f.puts %Q[ mrb_print_error(mrb);] - f.puts %Q[ mrb_close(mrb);] - f.puts %Q[ exit(EXIT_FAILURE);] - f.puts %Q[ }] - f.puts %Q[ struct REnv *e = mrb_vm_ci_env(mrb->c->cibase);] - f.puts %Q[ mrb_vm_ci_env_set(mrb->c->cibase, NULL);] - f.puts %Q[ mrb_env_unshare(mrb, e, FALSE);] end - f.puts %Q[ mrb_gc_arena_restore(mrb, ai);] f.puts %Q[}] f.puts %Q[] f.puts %Q[void GENERATED_TMP_mrb_#{funcname}_gem_final(mrb_state *mrb) {] @@ -241,6 +237,8 @@ module MRuby f.puts %Q[ * This file is loading the irep] f.puts %Q[ * Ruby GEM code.] f.puts %Q[ *] + f.puts %Q[ * This file was generated by mruby/#{__FILE__.relative_path_from(MRUBY_ROOT)}.] + f.puts %Q[ *] f.puts %Q[ * IMPORTANT:] f.puts %Q[ * This file was generated!] f.puts %Q[ * All manual changes will get lost.] @@ -292,6 +290,19 @@ module MRuby end end.all? end + + def each_header_files(&block) + return to_enum(__method__) unless block + + self.export_include_paths.flatten.uniq.compact.each do |dir| + Find.find(dir) do |d| + next unless File.file? d + yield d + end + end + + self + end end # Specification class Version diff --git a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/presym.rb b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/presym.rb index 7f74569fac..8ade2480d4 100644 --- a/yass/third_party/nghttp2/third-party/mruby/lib/mruby/presym.rb +++ b/yass/third_party/nghttp2/third-party/mruby/lib/mruby/presym.rb @@ -46,6 +46,18 @@ module MRuby C_STR_LITERAL_RE = /"(?:[^\\\"]|\\.)*"/ + ESCAPE_SEQUENCE_MAP = { + "a" => "\a", + "b" => "\b", + "e" => "\e", + "f" => "\f", + "n" => "\n", + "r" => "\r", + "t" => "\t", + "v" => "\v", + } + ESCAPE_SEQUENCE_MAP.keys.each { |k| ESCAPE_SEQUENCE_MAP[ESCAPE_SEQUENCE_MAP[k]] = k } + def initialize(build) @build = build end @@ -93,7 +105,18 @@ module MRuby f.puts "};" f.puts f.puts "static const char * const presym_name_table[] = {" - presyms.each{|sym| f.puts %| "#{sym}",|} + presyms.each do |sym| + sym = sym.gsub(/([\x01-\x1f\x7f-\xff])|("|\\)/n) { + case + when $1 + e = ESCAPE_SEQUENCE_MAP[$1] + e ? "\\#{e}" : '\\x%02x""' % $1.ord + when $2 + "\\#$2" + end + } + f.puts %| "#{sym}",| + end f.puts "};" end end @@ -119,7 +142,20 @@ module MRuby def read_preprocessed(presym_hash, path) File.binread(path).scan(/<@! (.*?) !@>/) do |part,| literals = part.scan(C_STR_LITERAL_RE) - presym_hash[literals.map{|l| l[1..-2]}.join] = true unless literals.empty? + unless literals.empty? + literals = literals.map{|l| l[1..-2]} + literals.each do |e| + e.gsub!(/\\x([0-9A-Fa-f]{1,2})|\\(0[0-7]{,3})|\\([abefnrtv])|\\(.)/) do + case + when $1; $1.hex.chr(Encoding::BINARY) + when $2; $2.oct.chr(Encoding::BINARY) + when $3; ESCAPE_SEQUENCE_MAP[$3] + when $4; $4 + end + end + end + presym_hash[literals.join] = true + end end end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/default.gembox b/yass/third_party/nghttp2/third-party/mruby/mrbgems/default.gembox index ae2de2ac2b..1143b19831 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/default.gembox +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/default.gembox @@ -8,6 +8,9 @@ MRuby::GemBox.new do |conf| # Generate mrbc command conf.gem :core => "mruby-bin-mrbc" + # Generate mrdb command + conf.gem :core => "mruby-bin-debugger" + # Generate mirb command conf.gem :core => "mruby-bin-mirb" diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/full-core.gembox b/yass/third_party/nghttp2/third-party/mruby/mrbgems/full-core.gembox index e0d008f062..fdee3268e1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/full-core.gembox +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/full-core.gembox @@ -1,6 +1,6 @@ MRuby::GemBox.new do |conf| Dir.glob("#{root}/mrbgems/mruby-*/mrbgem.rake") do |x| - g = File.basename File.dirname x + g = File.basename(File.dirname(x)) conf.gem :core => g unless g =~ /^mruby-(?:bin-debugger|test)$/ end end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-array-ext/mrblib/array.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-array-ext/mrblib/array.rb index d493a06513..7a9a0ac08e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-array-ext/mrblib/array.rb @@ -820,7 +820,7 @@ class Array return to_enum(:combination, n) unless block size = self.size if n == 0 - yield [] + yield [] elsif n == 1 i = 0 while i nil */ static mrb_value -mrb_ary_compact_bang(mrb_state *mrb, mrb_value self) +ary_compact_bang(mrb_state *mrb, mrb_value self) { struct RArray *a = mrb_ary_ptr(self); mrb_int i, j = 0; mrb_int len = ARY_LEN(a); - mrb_value *p = ARY_PTR(a); mrb_ary_modify(mrb, a); + mrb_value *p = ARY_PTR(a); for (i = 0; i < len; i++) { if (!mrb_nil_p(p[i])) { if (i != j) p[j] = p[i]; @@ -228,7 +227,7 @@ mrb_ary_compact_bang(mrb_state *mrb, mrb_value self) } } if (i == j) return mrb_nil_value(); - if (j < len) ARY_SET_LEN(RARRAY(self), j); + ARY_SET_LEN(RARRAY(self), j); return self; } @@ -250,7 +249,7 @@ mrb_ary_compact_bang(mrb_state *mrb, mrb_value self) * a.rotate(-3) #=> ["b", "c", "d", "a"] */ static mrb_value -mrb_ary_rotate(mrb_state *mrb, mrb_value self) +ary_rotate(mrb_state *mrb, mrb_value self) { mrb_int count=1; mrb_get_args(mrb, "|i", &count); @@ -301,17 +300,17 @@ rev(mrb_value *p, mrb_int beg, mrb_int end) * a.rotate!(-3) #=> ["a", "b", "c", "d"] */ static mrb_value -mrb_ary_rotate_bang(mrb_state *mrb, mrb_value self) +ary_rotate_bang(mrb_state *mrb, mrb_value self) { mrb_int count=1; mrb_get_args(mrb, "|i", &count); struct RArray *a = mrb_ary_ptr(self); mrb_int len = ARY_LEN(a); - mrb_value *p = ARY_PTR(a); mrb_int idx; mrb_ary_modify(mrb, a); + mrb_value *p = ARY_PTR(a); if (len == 0 || count == 0) return self; if (count == 1) { mrb_value v = p[0]; @@ -347,15 +346,15 @@ mrb_mruby_array_ext_gem_init(mrb_state* mrb) { struct RClass * a = mrb->array_class; - mrb_define_method(mrb, a, "assoc", mrb_ary_assoc, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, a, "at", mrb_ary_at, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, a, "rassoc", mrb_ary_rassoc, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, a, "values_at", mrb_ary_values_at, MRB_ARGS_ANY()); - mrb_define_method(mrb, a, "slice!", mrb_ary_slice_bang, MRB_ARGS_ARG(1,1)); - mrb_define_method(mrb, a, "compact", mrb_ary_compact, MRB_ARGS_NONE()); - mrb_define_method(mrb, a, "compact!", mrb_ary_compact_bang, MRB_ARGS_NONE()); - mrb_define_method(mrb, a, "rotate", mrb_ary_rotate, MRB_ARGS_OPT(1)); - mrb_define_method(mrb, a, "rotate!", mrb_ary_rotate_bang, MRB_ARGS_OPT(1)); + mrb_define_method(mrb, a, "assoc", ary_assoc, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, a, "at", ary_at, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, a, "rassoc", ary_rassoc, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, a, "values_at", ary_values_at, MRB_ARGS_ANY()); + mrb_define_method(mrb, a, "slice!", ary_slice_bang, MRB_ARGS_ARG(1,1)); + mrb_define_method(mrb, a, "compact", ary_compact, MRB_ARGS_NONE()); + mrb_define_method(mrb, a, "compact!", ary_compact_bang, MRB_ARGS_NONE()); + mrb_define_method(mrb, a, "rotate", ary_rotate, MRB_ARGS_OPT(1)); + mrb_define_method(mrb, a, "rotate!", ary_rotate_bang, MRB_ARGS_OPT(1)); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bigint/README-fgmp.md b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bigint/README-fgmp.md index 24e131ba9c..7693f3c1f3 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bigint/README-fgmp.md +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bigint/README-fgmp.md @@ -56,7 +56,7 @@ Thanks also to Erick Gallesio for a fix to mpz_init_set_str Define B64 if your "long" type is 64 bits. Otherwise we assume 32 -bit longs. (The 64 bit version hasn't been tested enough) +bit longs. (The 64-bit version hasn't been tested enough) ``` Platforms: @@ -73,18 +73,18 @@ MS-DOS 286 C compiler (see credits above) 1. fgmp is considerably slower than gmp 2. fgmp does not implement the following: - all mpq_* - internal mpn_* functions - mpz_perfect_square_p - mpz_inp_raw, mpz_out_raw - mp_set_memory_functions, mpz_out_str, mpz_inp_str + - all mpq\_\* + - internal mpn\_\* functions + - mpz_perfect_square_p + - mpz_inp_raw, mpz_out_raw + - mp_set_memory_functions, mpz_out_str, mpz_inp_str 3. fgmp implements the following in addition to the routines in GNU gmp. - `int mpz_jacobi(MP_INT *a, MP_INT *b)` - - finds the jacobi symbol (a/b) + `int mpz_jacobi(MP_INT *a, MP_INT *b)` + - finds the jacobi symbol (a/b) 4. mpz_sizeinbase often overestimates the exact value 5. To convert your gmp based program to fgmp (subject to the -above) + above) - recompile your source. Make sure to include the gmp.h file included with fgmp rather than that included with gmp. (The point is to recompile diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bigint/core/bigint.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bigint/core/bigint.c index 5c757729c4..97f5454735 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bigint/core/bigint.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bigint/core/bigint.c @@ -78,7 +78,7 @@ mpz_set_int(mrb_state *mrb, mpz_t *y, mrb_int v) y->sn = 1; u = v; } - if (v < 0) { + else /* if (v < 0) */ { y->sn = -1; if (v == MRB_INT_MIN) u = v; else u = -v; @@ -97,6 +97,39 @@ mpz_set_int(mrb_state *mrb, mpz_t *y, mrb_int v) } } +static void +mpz_set_uint64(mrb_state *mrb, mpz_t *y, uint64_t u) +{ + const size_t len = sizeof(uint64_t) / sizeof(mp_limb); + + y->sn = (u != 0); + mpz_realloc(mrb, y, len); + for (size_t i=0; ip[i++] = (mp_limb)LOW(u); + u >>= DIG_SIZE; + } +} + +#ifdef MRB_INT32 +static void +mpz_set_int64(mrb_state *mrb, mpz_t *y, int64_t v) +{ + uint64_t u; + + if (v < 0) { + if (v == INT64_MIN) u = v; + else u = -v; + } + else { + u = v; + } + mpz_set_uint64(mrb, y, u); + if (v < 0) { + y->sn = -1; + } +} +#endif + static void mpz_init_set_int(mrb_state *mrb, mpz_t *y, mrb_int v) { @@ -131,7 +164,7 @@ digits(mpz_t *x) size_t i; if (x->sz == 0) return 0; - for (i = x->sz - 1; x->p[i] == 0 ; i--) + for (i = x->sz - 1; x->p[i] == 0; i--) if (i == 0) break; return i+1; } @@ -362,7 +395,7 @@ lzb(mp_limb x) int j=0; - for (mp_limb i = ((mp_limb)1 << (DIG_SIZE-1)); i && !(x&i) ; j++,i>>=1) + for (mp_limb i = ((mp_limb)1 << (DIG_SIZE-1)); i && !(x&i); j++,i>>=1) ; return j; } @@ -909,7 +942,41 @@ mpz_pow(mrb_state *mrb, mpz_t *zz, mpz_t *x, mrb_int e) } static void -mpz_powm(mrb_state *mrb, mpz_t *zz, mpz_t *x, mrb_int ex, mpz_t *n) +mpz_powm(mrb_state *mrb, mpz_t *zz, mpz_t *x, mpz_t *ex, mpz_t *n) +{ + mpz_t t, b; + + if (uzero(ex)) { + mpz_set_int(mrb, zz, 1); + return; + } + + if (ex->sn < 0) { + return; + } + + mpz_init_set_int(mrb, &t, 1); + mpz_init_set(mrb, &b, x); + + size_t len = digits(ex); + for (size_t i=0; ip[i]; + for (size_t j=0; j>= 1; + mpz_mul(mrb, &b, &b, &b); + mpz_mod(mrb, &b, &b, n); + } + } + mpz_move(mrb, zz, &t); + mpz_clear(mrb, &b); +} + +static void +mpz_powm_i(mrb_state *mrb, mpz_t *zz, mpz_t *x, mrb_int ex, mpz_t *n) { mpz_t t, b; @@ -955,13 +1022,6 @@ bint_new_int(mrb_state *mrb, mrb_int x) return b; } -mrb_value -mrb_bint_new(mrb_state *mrb) -{ - struct RBigint *b = bint_new(mrb); - return mrb_obj_value(b); -} - mrb_value mrb_bint_new_int(mrb_state *mrb, mrb_int x) { @@ -969,6 +1029,26 @@ mrb_bint_new_int(mrb_state *mrb, mrb_int x) return mrb_obj_value(b); } +#ifdef MRB_INT32 +mrb_value +mrb_bint_new_int64(mrb_state *mrb, int64_t x) +{ + struct RBigint *b = bint_new(mrb); + mpz_init(mrb, &b->mp); + mpz_set_int64(mrb, &b->mp, x); + return mrb_obj_value(b); +} +#endif + +mrb_value +mrb_bint_new_uint64(mrb_state *mrb, uint64_t x) +{ + struct RBigint *b = bint_new(mrb); + mpz_init(mrb, &b->mp); + mpz_set_uint64(mrb, &b->mp, x); + return mrb_obj_value(b); +} + mrb_value mrb_bint_new_str(mrb_state *mrb, const char *x, mrb_int len, mrb_int base) { @@ -1086,6 +1166,61 @@ mrb_bint_as_int(mrb_state *mrb, mrb_value x) return i; } +#ifdef MRB_INT32 +int64_t +mrb_bint_as_int64(mrb_state *mrb, mrb_value x) +{ + struct RBigint *b = RBIGINT(x); + mpz_t *m = &b->mp; + uint64_t u = 0; + size_t len = digits(m); + + if (len*sizeof(mp_limb) > sizeof(uint64_t)) { + out_of_range: + mrb_raise(mrb, E_RANGE_ERROR, "integer out of range"); + } + for (size_t i=len-1; ; i--) { + u <<= DIG_SIZE; + u |= m->p[i]; + if (i==0) break; + } + if (u > INT64_MAX) goto out_of_range; + if (m->sn < 0) return -(int64_t)u; + return (int64_t)u; +} +#endif + +uint64_t +mrb_bint_as_uint64(mrb_state *mrb, mrb_value x) +{ + struct RBigint *b = RBIGINT(x); + mpz_t *m = &b->mp; + uint64_t u = 0; + size_t len = digits(m); + + if (m->sn < 0 || len*sizeof(mp_limb) > sizeof(uint64_t)) { + mrb_raise(mrb, E_RANGE_ERROR, "integer out of range"); + } + for (size_t i=len-1; ; i--) { + u <<= DIG_SIZE; + u |= m->p[i]; + if (i==0) break; + } + return u; +} + +/* unnormalize version of mrb_bint_add */ +mrb_value +mrb_bint_add_d(mrb_state *mrb, mrb_value x, mrb_value y) +{ + y = mrb_as_bint(mrb, y); + struct RBigint *b = RBIGINT(x); + struct RBigint *b2 = RBIGINT(y); + struct RBigint *b3 = bint_new(mrb); + mpz_add(mrb, &b3->mp, &b->mp, &b2->mp); + return mrb_obj_value(b3); +} + mrb_value mrb_bint_add(mrb_state *mrb, mrb_value x, mrb_value y) { @@ -1096,12 +1231,20 @@ mrb_bint_add(mrb_state *mrb, mrb_value x, mrb_value y) return mrb_float_value(mrb,v1+v2); } #endif + x = mrb_bint_add_d(mrb, x, y); + return bint_norm(mrb, RBIGINT(x)); +} + +/* unnormalize version of mrb_bint_sub */ +mrb_value +mrb_bint_sub_d(mrb_state *mrb, mrb_value x, mrb_value y) +{ y = mrb_as_bint(mrb, y); struct RBigint *b = RBIGINT(x); struct RBigint *b2 = RBIGINT(y); struct RBigint *b3 = bint_new(mrb); - mpz_add(mrb, &b3->mp, &b->mp, &b2->mp); - return bint_norm(mrb, b3); + mpz_sub(mrb, &b3->mp, &b->mp, &b2->mp); + return mrb_obj_value(b3); } mrb_value @@ -1114,12 +1257,8 @@ mrb_bint_sub(mrb_state *mrb, mrb_value x, mrb_value y) return mrb_float_value(mrb,v1-v2); } #endif - y = mrb_as_bint(mrb, y); - struct RBigint *b = RBIGINT(x); - struct RBigint *b2 = RBIGINT(y); - struct RBigint *b3 = bint_new(mrb); - mpz_sub(mrb, &b3->mp, &b->mp, &b2->mp); - return bint_norm(mrb, b3); + x = mrb_bint_sub_d(mrb, x, y); + return bint_norm(mrb, RBIGINT(x)); } mrb_value @@ -1206,20 +1345,6 @@ mrb_bint_mul_ii(mrb_state *mrb, mrb_int x, mrb_int y) return bint_norm(mrb, b); } -mrb_value -mrb_bint_div_ii(mrb_state *mrb, mrb_int x, mrb_int y) -{ - struct RBigint *b = bint_new(mrb); - mpz_t z1, z2; - - mpz_init_set_int(mrb, &z1, x); - mpz_init_set_int(mrb, &z2, y); - mpz_mdiv(mrb, &b->mp, &z1, &z2); - mpz_clear(mrb, &z1); - mpz_clear(mrb, &z2); - return bint_norm(mrb, b); -} - mrb_value mrb_bint_mod(mrb_state *mrb, mrb_value x, mrb_value y) { @@ -1334,32 +1459,36 @@ mrb_bint_pow(mrb_state *mrb, mrb_value x, mrb_value y) } mrb_value -mrb_bint_powm(mrb_state *mrb, mrb_value x, mrb_int exp, mrb_value mod) +mrb_bint_powm(mrb_state *mrb, mrb_value x, mrb_value exp, mrb_value mod) { struct RBigint *b = RBIGINT(x); - switch (mrb_type(mod)) { - case MRB_TT_INTEGER: - { - mrb_int m = mrb_integer(mod); - if (m == 0) mrb_int_zerodiv(mrb); - struct RBigint *b2 = bint_new_int(mrb, m); - struct RBigint *b3 = bint_new(mrb); - mpz_powm(mrb, &b3->mp, &b->mp, exp, &b2->mp); - return bint_norm(mrb, b3); - } - case MRB_TT_BIGINT: - { - struct RBigint *b2 = RBIGINT(mod); - struct RBigint *b3 = bint_new(mrb); - if (uzero(&b2->mp)) mrb_int_zerodiv(mrb); - mpz_powm(mrb, &b3->mp, &b->mp, exp, &b2->mp); - return bint_norm(mrb, b3); - } - mrb_raise(mrb, E_TYPE_ERROR, "too big power"); - default: - mrb_raisef(mrb, E_TYPE_ERROR, "%v cannot be convert to integer", mod); + struct RBigint *b2, *b3; + + if (mrb_bigint_p(mod)) { + b2 = RBIGINT(mod); + if (uzero(&b2->mp)) mrb_int_zerodiv(mrb); } - return mrb_nil_value(); + else { + mrb_int m = mrb_integer(mod); + if (m == 0) mrb_int_zerodiv(mrb); + b2 = bint_new_int(mrb, m); + } + b3 = bint_new(mrb); + if (mrb_bigint_p(exp)) { + struct RBigint *be = RBIGINT(exp); + if (be->mp.sn < 0) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "int.pow(n,m): n must be positive"); + } + mpz_powm(mrb, &b3->mp, &b->mp, &be->mp, &b2->mp); + } + else { + mrb_int e = mrb_integer(exp); + if (e < 0) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "int.pow(n,m): n must be positive"); + } + mpz_powm_i(mrb, &b3->mp, &b->mp, e, &b2->mp); + } + return bint_norm(mrb, b3); } mrb_value diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mrbgem.rake index b4c437640a..8a484d69c9 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mrbgem.rake @@ -11,7 +11,16 @@ MRuby::Gem::Specification.new('mruby-bin-config') do |spec| else mruby_config_dir = "#{build.build_dir}/bin" end - mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '') + + if ENV['OS'] == 'Windows_NT' + suffix = '.bat' + refvar = '%\\1%' + else + suffix = '' + refvar = '${\\1}' + end + + mruby_config = name + suffix mruby_config_path = "#{mruby_config_dir}/#{mruby_config}" make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak" tmplt_path = "#{__dir__}/#{mruby_config}" @@ -24,11 +33,16 @@ MRuby::Gem::Specification.new('mruby-bin-config') do |spec| directory mruby_config_dir - file mruby_config_path => [mruby_config_dir, make_cfg, tmplt_path] do |t| + file mruby_config_path => [__FILE__, mruby_config_dir, make_cfg, tmplt_path] do |t| config = Hash[File.readlines(make_cfg).map!(&:chomp).map! {|l| + l.gsub!(/\$\((\w+)\)/, refvar) l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')} }] tmplt = File.read(tmplt_path) + tmplt.sub!(%r((?<=\A#!/bin/sh\n\n)), <<~SETDIR) + MRUBY_PACKAGE_DIR=$(dirname "$(dirname "$(readlink -f "$0")")") + + SETDIR File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config)) chmod(0755, t.name) end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mruby-config b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mruby-config index 3adda9e1a6..27365e650a 100755 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mruby-config +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mruby-config @@ -4,8 +4,14 @@ print_help() { echo "Usage: mruby-config [switches]" echo " switches:" - echo " --cc print compiler name" - echo " --cflags print flags passed to compiler" + echo " --cc print C compiler name" + echo " --cflags print flags passed to C compiler" + echo " --cxx print C++ compiler name" + echo " --cxxflags print flags passed to C++ compiler" + echo " --as print assembler name" + echo " --asflags print flags passed to assembler" + echo " --objc print Objective C compiler name" + echo " --objcflags print flags passed to Objective C compiler" echo " --ld print linker name" echo " --ldflags print flags passed to linker" echo " --ldflags-before-libs print flags passed to linker before linked libraries" @@ -23,6 +29,12 @@ while [ $# -gt 0 ]; do case $1 in --cc) echo MRUBY_CC;; --cflags) echo MRUBY_CFLAGS;; + --cxx) echo MRUBY_CXX;; + --cxxflags) echo MRUBY_CXXFLAGS;; + --as) echo MRUBY_AS;; + --asflags) echo MRUBY_ASFLAGS;; + --objc) echo MRUBY_OBJC;; + --objcflags) echo MRUBY_OBJCFLAGS;; --ld) echo MRUBY_LD;; --ldflags) echo MRUBY_LDFLAGS;; --ldflags-before-libs) echo MRUBY_LDFLAGS_BEFORE_LIBS;; diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mruby-config.bat b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mruby-config.bat index 949fea06f0..fa7ad2a635 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mruby-config.bat +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-config/mruby-config.bat @@ -1,10 +1,28 @@ @echo off +call :init "%~dp0." +goto top + +:init +rem call init2 for treatments last directory separator +call :init2 "%~dp1." +goto :eof + +:init2 +set MRUBY_PACKAGE_DIR=%~f1 +goto :eof + :top shift if "%0" equ "" goto :eof if "%0" equ "--cc" goto cc if "%0" equ "--cflags" goto cflags +if "%0" equ "--cxx" goto cxx +if "%0" equ "--cxxflags" goto cxxflags +if "%0" equ "--as" goto as +if "%0" equ "--asflags" goto asflags +if "%0" equ "--objc" goto objc +if "%0" equ "--objcflags" goto objcflags if "%0" equ "--ld" goto ld if "%0" equ "--ldflags" goto ldflags if "%0" equ "--ldflags-before-libs" goto ldflagsbeforelibs @@ -22,6 +40,30 @@ goto top echo MRUBY_CFLAGS goto top +:cxx +echo MRUBY_CXX +goto top + +:cxxflags +echo MRUBY_CXXFLAGS +goto top + +:as +echo MRUBY_AS +goto top + +:asflags +echo MRUBY_ASFLAGS +goto top + +:objc +echo MRUBY_OBJC +goto top + +:objcflags +echo MRUBY_OBJCFLAGS +goto top + :ld echo MRUBY_LD goto top @@ -45,8 +87,14 @@ goto top :showhelp echo Usage: mruby-config [switches] echo switches: -echo --cc print compiler name -echo --cflags print flags passed to compiler +echo --cc print C compiler name +echo --cflags print flags passed to C compiler +echo --cxx print C++ compiler name +echo --cxxflags print flags passed to C++ compiler +echo --as print assembler name +echo --asflags print flags passed to assembler +echo --objc print Objective C compiler name +echo --objcflags print flags passed to Objective C compiler echo --ld print linker name echo --ldflags print flags passed to linker echo --ldflags-before-libs print flags passed to linker before linked libraries diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/mrbgem.rake index 091851dd43..f51c9a3db4 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/mrbgem.rake @@ -2,7 +2,7 @@ MRuby::Gem::Specification.new('mruby-bin-debugger') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'mruby debugger command' - spec.build.defines |= %w(MRB_USE_DEBUG_HOOK) + spec.build.defines << "MRB_USE_DEBUG_HOOK" spec.add_dependency('mruby-eval', :core => 'mruby-eval') spec.bins = %w(mrdb) diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c index a69d65dd9c..e3e0e666a3 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c @@ -68,7 +68,7 @@ get_break_index(mrb_debug_context *dbg, uint32_t bpno) int32_t index; char hit = FALSE; - for(i = 0 ; i < dbg->bpnum; i++) { + for (i = 0; i < dbg->bpnum; i++) { if (dbg->bp[i].bpno == bpno) { hit = TRUE; index = i; @@ -341,7 +341,7 @@ mrb_debug_delete_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno) free_breakpoint(mrb, &dbg->bp[index]); - for(i = index ; i < dbg->bpnum; i++) { + for (i = index; i < dbg->bpnum; i++) { if ((i + 1) == dbg->bpnum) { dbg->bp[i] = (mrb_debug_breakpoint){0}; } @@ -364,7 +364,7 @@ mrb_debug_delete_break_all(mrb_state *mrb, mrb_debug_context *dbg) return MRB_DEBUG_INVALID_ARGUMENT; } - for(i = 0 ; i < dbg->bpnum ; i++) { + for (i = 0; i < dbg->bpnum; i++) { free_breakpoint(mrb, &dbg->bp[i]); } @@ -401,7 +401,7 @@ mrb_debug_enable_break_all(mrb_state *mrb, mrb_debug_context *dbg) return MRB_DEBUG_INVALID_ARGUMENT; } - for(i = 0 ; i < dbg->bpnum; i++) { + for (i = 0; i < dbg->bpnum; i++) { dbg->bp[i].enable = TRUE; } @@ -436,7 +436,7 @@ mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg) return MRB_DEBUG_INVALID_ARGUMENT; } - for(i = 0 ; i < dbg->bpnum; i++) { + for (i = 0; i < dbg->bpnum; i++) { dbg->bp[i].enable = FALSE; } @@ -470,7 +470,7 @@ mrb_debug_check_breakpoint_line(mrb_state *mrb, mrb_debug_context *dbg, const ch } bp = dbg->bp; - for(i=0; ibpnum; i++) { + for (i=0; ibpnum; i++) { switch (bp->type) { case MRB_DEBUG_BPTYPE_LINE: if (bp->enable == TRUE) { @@ -504,7 +504,7 @@ mrb_debug_check_breakpoint_method(mrb_state *mrb, mrb_debug_context *dbg, struct } bp = dbg->bp; - for(i=0; ibpnum; i++) { + for (i=0; ibpnum; i++) { if (bp->type == MRB_DEBUG_BPTYPE_METHOD) { if (bp->enable == TRUE) { bpno = compare_break_method(mrb, bp, class_obj, method_sym, isCfunc); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.h b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.h index 08f1d8080f..cc272cbebc 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.h +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.h @@ -9,18 +9,18 @@ #include #include "mrdb.h" -int32_t mrb_debug_set_break_line(mrb_state *, mrb_debug_context *, const char *, uint16_t); -int32_t mrb_debug_set_break_method(mrb_state *, mrb_debug_context *, const char *, const char *); -int32_t mrb_debug_get_breaknum(mrb_state *, mrb_debug_context *); -int32_t mrb_debug_get_break_all(mrb_state *, mrb_debug_context *, uint32_t, mrb_debug_breakpoint bp[]); -int32_t mrb_debug_get_break(mrb_state *, mrb_debug_context *, uint32_t, mrb_debug_breakpoint *); -int32_t mrb_debug_delete_break(mrb_state *, mrb_debug_context *, uint32_t); -int32_t mrb_debug_delete_break_all(mrb_state *, mrb_debug_context *); -int32_t mrb_debug_enable_break(mrb_state *, mrb_debug_context *, uint32_t); -int32_t mrb_debug_enable_break_all(mrb_state *, mrb_debug_context *); -int32_t mrb_debug_disable_break(mrb_state *, mrb_debug_context *, uint32_t); -int32_t mrb_debug_disable_break_all(mrb_state *, mrb_debug_context *); -int32_t mrb_debug_check_breakpoint_line(mrb_state *, mrb_debug_context *, const char *, uint16_t); -int32_t mrb_debug_check_breakpoint_method(mrb_state *, mrb_debug_context *, struct RClass *, mrb_sym, mrb_bool*); +int32_t mrb_debug_set_break_line(mrb_state*, mrb_debug_context*, const char*, uint16_t); +int32_t mrb_debug_set_break_method(mrb_state*, mrb_debug_context*, const char*, const char*); +int32_t mrb_debug_get_breaknum(mrb_state*, mrb_debug_context*); +int32_t mrb_debug_get_break_all(mrb_state*, mrb_debug_context*, uint32_t, mrb_debug_breakpoint bp[]); +int32_t mrb_debug_get_break(mrb_state*, mrb_debug_context*, uint32_t, mrb_debug_breakpoint*); +int32_t mrb_debug_delete_break(mrb_state*, mrb_debug_context*, uint32_t); +int32_t mrb_debug_delete_break_all(mrb_state*, mrb_debug_context*); +int32_t mrb_debug_enable_break(mrb_state*, mrb_debug_context*, uint32_t); +int32_t mrb_debug_enable_break_all(mrb_state*, mrb_debug_context*); +int32_t mrb_debug_disable_break(mrb_state*, mrb_debug_context*, uint32_t); +int32_t mrb_debug_disable_break_all(mrb_state*, mrb_debug_context*); +int32_t mrb_debug_check_breakpoint_line(mrb_state*, mrb_debug_context*, const char*, uint16_t); +int32_t mrb_debug_check_breakpoint_method(mrb_state*, mrb_debug_context*, struct RClass*, mrb_sym, mrb_bool*); #endif /* APIBREAK_H_ */ diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c index 27db02b48e..0fc087bdf9 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c @@ -200,7 +200,7 @@ mrb_debug_get_source(mrb_state *mrb, mrdb_state *mrdb, const char *srcpath, cons break; } - mrb_free(mrb, (void *)search_path[1]); + mrb_free(mrb, (void*)search_path[1]); return path; } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.h b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.h index 6c41078851..542fda1049 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.h +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.h @@ -8,7 +8,7 @@ #include #include "mrdb.h" -int32_t mrb_debug_list(mrb_state *, mrb_debug_context *, char *, uint16_t, uint16_t); -char* mrb_debug_get_source(mrb_state *, mrdb_state *, const char *, const char *); +int32_t mrb_debug_list(mrb_state*, mrb_debug_context*, char*, uint16_t, uint16_t); +char* mrb_debug_get_source(mrb_state*, mrdb_state*, const char*, const char *); #endif /* APILIST_H_ */ diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c index 9093a4f0ee..49c93e21c5 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c @@ -17,24 +17,24 @@ static void mrdb_check_syntax(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len) { - mrbc_context *c; + mrb_ccontext *c; - c = mrbc_context_new(mrb); + c = mrb_ccontext_new(mrb); c->no_exec = TRUE; c->capture_errors = TRUE; - mrbc_filename(mrb, c, (const char*)dbg->prvfile); + mrb_ccontext_filename(mrb, c, (const char*)dbg->prvfile); c->lineno = dbg->prvline; /* Load program */ mrb_load_nstring_cxt(mrb, expr, len, c); - mrbc_context_free(mrb, c); + mrb_ccontext_free(mrb, c); } mrb_value mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len, mrb_bool *exc, int direct_eval) { - void (*tmp)(struct mrb_state *, const struct mrb_irep *, const mrb_code *, mrb_value *); + void (*tmp)(struct mrb_state*, const struct mrb_irep*, const mrb_code*, mrb_value*); mrb_value ruby_code; mrb_value s; mrb_value v; @@ -68,11 +68,11 @@ mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t recv = dbg->regs[0]; - v = mrb_funcall_id(mrb, recv, MRB_SYM(instance_eval), 1, ruby_code); + v = mrb_funcall_argv(mrb, recv, MRB_SYM(instance_eval), 1, &ruby_code); } if (exc) { - *exc = mrb_obj_is_kind_of(mrb, v, mrb->eException_class); + *exc = mrb_obj_is_kind_of(mrb, v, E_EXCEPTION); } s = mrb_inspect(mrb, v); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c index bc9937e947..621bb45276 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c @@ -42,8 +42,8 @@ #define LINENO_MAX_DIGIT 6 #define BPNO_LETTER_NUM 9 -typedef int32_t (*all_command_func)(mrb_state *, mrb_debug_context *); -typedef int32_t (*select_command_func)(mrb_state *, mrb_debug_context *, uint32_t); +typedef int32_t (*all_command_func)(mrb_state*, mrb_debug_context*); +typedef int32_t (*select_command_func)(mrb_state*, mrb_debug_context*, uint32_t); static void print_api_common_error(int32_t error) @@ -61,7 +61,7 @@ print_api_common_error(int32_t error) #define STRTOUL(ul,s) { \ int i; \ ul = 0; \ - for(i=0; ISDIGIT(s[i]); i++) ul = 10*ul + (s[i] -'0'); \ + for (i=0; ISDIGIT(s[i]); i++) ul = 10*ul + (s[i] -'0'); \ } static int32_t @@ -106,7 +106,7 @@ exe_set_command_select(mrb_state *mrb, mrdb_state *mrdb, select_command_func fun int32_t bpno = 0; int32_t i; - for(i=1; iwcnt; i++) { + for (i=1; iwcnt; i++) { ps = mrdb->words[i]; bpno = parse_breakpoint_no(ps); if (bpno == 0) { @@ -199,7 +199,7 @@ info_break_all(mrb_state *mrb, mrdb_state *mrdb) return; } puts(BREAK_INFO_MSG_HEADER); - for(i = 0 ; i < bpnum ; i++) { + for (i = 0; i < bpnum; i++) { print_breakpoint(&bp_list[i]); } @@ -216,7 +216,7 @@ info_break_select(mrb_state *mrb, mrdb_state *mrdb) mrb_bool isFirst = TRUE; int32_t i; - for(i=2; iwcnt; i++) { + for (i=2; iwcnt; i++) { ps = mrdb->words[i]; bpno = parse_breakpoint_no(ps); if (bpno == 0) { diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c index 0714f3f213..4cf635b41b 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c @@ -167,7 +167,8 @@ parse_uint(char **sp, uint16_t *n) return FALSE; } - for (p = *sp; *p != '\0' && ISDIGIT(*p); p++) ; + for (p = *sp; *p != '\0' && ISDIGIT(*p); p++) + ; if (p != *sp && (i = atoi(*sp)) >= 0) { *n = (uint16_t)i; @@ -350,9 +351,9 @@ check_cmd_pattern(const char *pattern, const char *cmd) } p = lbracket + 1; - q = (char *)cmd + (lbracket - pattern); + q = (char*)cmd + (lbracket - pattern); - for ( ; p < rbracket && *q != '\0'; p++, q++) { + for (; p < rbracket && *q != '\0'; p++, q++) { if (*p != *q) { break; } @@ -479,7 +480,8 @@ dbgcmd_quit(mrb_state *mrb, mrdb_state *mrdb) break; } c = buf; - while (buf != '\n' && (buf = getchar()) != EOF) ; + while (buf != '\n' && (buf = getchar()) != EOF) + ; if (c == 'y' || c == 'Y') { mrdb->dbg->xm = DBG_QUIT; @@ -500,7 +502,7 @@ dbgcmd_quit(mrb_state *mrb, mrdb_state *mrdb) if (mrdb->dbg->xm == DBG_QUIT) { struct RClass *exc; - exc = mrb_define_class(mrb, "DebuggerExit", mrb->eException_class); + exc = mrb_define_class(mrb, "DebuggerExit", E_EXCEPTION); mrb_raise(mrb, exc, "Exit mrdb"); } return DBGST_PROMPT; diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c index fe8cf0aa7f..1cd463eb0e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c @@ -19,7 +19,7 @@ dbgcmd_run(mrb_state *mrb, mrdb_state *mrdb) if (dbg->xphase == DBG_PHASE_RUNNING){ struct RClass *exc; puts("Start it from the beginning"); - exc = mrb_define_class(mrb, "DebuggerRestart", mrb->eException_class); + exc = mrb_define_class(mrb, "DebuggerRestart", E_EXCEPTION); mrb_raise(mrb, exc, "Restart mrdb"); } } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c index 340a57b56c..6516c50a9a 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c @@ -20,7 +20,7 @@ #include "apibreak.h" #include "apilist.h" -void mrdb_state_free(mrb_state *); +void mrdb_state_free(mrb_state*); static mrb_debug_context *_debug_context = NULL; static mrdb_state *_mrdb_state = NULL; @@ -113,7 +113,7 @@ append_srcpath: char *buf; buflen = strlen(item) + 1; - buf = (char *)mrb_malloc(mrb, buflen); + buf = (char*)mrb_malloc(mrb, buflen); memcpy(buf, item, buflen); args->srcpath = buf; } @@ -123,8 +123,7 @@ append_srcpath: srcpathlen = strlen(args->srcpath); itemlen = strlen(item); - args->srcpath = - (char *)mrb_realloc(mrb, args->srcpath, srcpathlen + itemlen + 2); + args->srcpath = (char*)mrb_realloc(mrb, args->srcpath, srcpathlen + itemlen + 2); args->srcpath[srcpathlen] = '\n'; memcpy(args->srcpath + srcpathlen + 1, item, itemlen + 1); } @@ -280,7 +279,7 @@ get_command(mrb_state *mrb, mrdb_state *mrdb) } if (i == MAX_COMMAND_LINE) { - for ( ; (c=getchar()) != EOF && c !='\n'; i++) ; + for (; (c=getchar()) != EOF && c !='\n'; i++) ; } if (i > MAX_COMMAND_LINE) { @@ -297,7 +296,8 @@ pick_out_word(mrb_state *mrb, char **pp) { char *ps; - for (ps=*pp; ISBLANK(*ps); ps++) ; + for (ps=*pp; ISBLANK(*ps); ps++) + ; if (*ps == '\0') { return NULL; } @@ -336,7 +336,8 @@ parse_command(mrb_state *mrb, mrdb_state *mrdb, char *buf) } mrdb->wcnt = 1; /* set remain parameter */ - for ( ; *p && ISBLANK(*p); p++) ; + for (; *p && ISBLANK(*p); p++) + ; if (*p) { mrdb->words[mrdb->wcnt++] = p; } @@ -356,7 +357,8 @@ parse_command(mrb_state *mrb, mrdb_state *mrdb, char *buf) mrdb->words[1] = pick_out_word(mrb, &p); if (mrdb->words[1]) { /* update remain parameter */ - for ( ; *p && ISBLANK(*p); p++) ; + for (; *p && ISBLANK(*p); p++) + ; if (*p) { mrdb->words[mrdb->wcnt++] = p; } @@ -364,7 +366,7 @@ parse_command(mrb_state *mrb, mrdb_state *mrdb, char *buf) } /* check word #1,#2 */ - for ( ; cmd->cmd1; cmd++) { + for (; cmd->cmd1; cmd++) { wlen = strlen(mrdb->words[0]); if (wlen < cmd->len1 || strncmp(mrdb->words[0], cmd->cmd1, wlen)) { @@ -386,7 +388,7 @@ parse_command(mrb_state *mrb, mrdb_state *mrdb, char *buf) /* divide remain parameters */ if (cmd->cmd1 && cmd->div) { p = mrdb->words[--mrdb->wcnt]; - for ( ; mrdb->wcntwcnt++) { + for (; mrdb->wcntwcnt++) { mrdb->words[mrdb->wcnt] = pick_out_word(mrb, &p); if (!mrdb->words[mrdb->wcnt]) { break; @@ -704,10 +706,10 @@ main(int argc, char **argv) v = mrb_load_irep_file(mrb, args.rfp); } else { /* .rb */ - mrbc_context *cc = mrbc_context_new(mrb); - mrbc_filename(mrb, cc, args.fname); + mrb_ccontext *cc = mrb_ccontext_new(mrb); + mrb_ccontext_filename(mrb, cc, args.fname); v = mrb_load_file_cxt(mrb, args.rfp, cc); - mrbc_context_free(mrb, cc); + mrb_ccontext_free(mrb, cc); } if (mrdb->dbg->xm == DBG_QUIT && !mrb_undef_p(v) && mrb->exc) { const char *classname = mrb_obj_classname(mrb, mrb_obj_value(mrb->exc)); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h index 24ccad1261..1d379f4c78 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h @@ -74,10 +74,6 @@ typedef enum { MRB_DEBUG_BPTYPE_METHOD, } mrb_debug_bptype; -struct mrb_irep; -struct mrbc_context; -struct mrb_debug_context; - typedef struct mrb_debug_linepoint { const char *file; uint16_t lineno; diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index 78c3ed40fc..5f32539d8f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -95,7 +95,7 @@ get_history_path(mrb_state *mrb) int len = snprintf(NULL, 0, "%s/%s", home, history_file_name); if (len >= 0) { size_t size = len + 1; - path = (char *)mrb_malloc_simple(mrb, size); + path = (char*)mrb_malloc_simple(mrb, size); if (path != NULL) { int n = snprintf(path, size, "%s/%s", home, history_file_name); if (n != len) { @@ -117,7 +117,7 @@ p(mrb_state *mrb, mrb_value obj, int prompt) mrb_value val; char* msg; - val = mrb_funcall_id(mrb, obj, MRB_SYM(inspect), 0); + val = mrb_funcall_argv(mrb, obj, MRB_SYM(inspect), 0, NULL); if (prompt) { if (!mrb->exc) { fputs(" => ", stdout); @@ -422,7 +422,7 @@ ctrl_c_handler(int signo) #endif #ifndef MRB_NO_MIRB_UNDERSCORE -void decl_lv_underscore(mrb_state *mrb, mrbc_context *cxt) +void decl_lv_underscore(mrb_state *mrb, mrb_ccontext *cxt) { struct RProc *proc; struct mrb_parser_state *parser; @@ -453,7 +453,7 @@ main(int argc, char **argv) char *history_path; char* line; #endif - mrbc_context *cxt; + mrb_ccontext *cxt; struct mrb_parser_state *parser; mrb_state *mrb; mrb_value result; @@ -504,11 +504,10 @@ main(int argc, char **argv) print_hint(); - cxt = mrbc_context_new(mrb); + cxt = mrb_ccontext_new(mrb); /* Load libraries */ for (i = 0; i < args.libc; i++) { - struct REnv *e; FILE *lfp = fopen(args.libv[i], "r"); if (lfp == NULL) { printf("Cannot open library file. (%s)\n", args.libv[i]); @@ -517,10 +516,8 @@ main(int argc, char **argv) } mrb_load_file_cxt(mrb, lfp, cxt); fclose(lfp); - e = mrb_vm_ci_env(mrb->c->cibase); - mrb_vm_ci_env_set(mrb->c->cibase, NULL); - mrb_env_unshare(mrb, e, FALSE); - mrbc_cleanup_local_variables(mrb, cxt); + mrb_vm_ci_env_clear(mrb, mrb->c->cibase); + mrb_ccontext_cleanup_local_variables(mrb, cxt); } #ifndef MRB_NO_MIRB_UNDERSCORE @@ -529,7 +526,7 @@ main(int argc, char **argv) cxt->capture_errors = TRUE; cxt->lineno = 1; - mrbc_filename(mrb, cxt, "(mirb)"); + mrb_ccontext_filename(mrb, cxt, "(mirb)"); if (args.verbose) cxt->dump_result = TRUE; ai = mrb_gc_arena_save(mrb); @@ -710,7 +707,7 @@ main(int argc, char **argv) } mrb_free(mrb, args.libv); } - mrbc_context_free(mrb, cxt); + mrb_ccontext_free(mrb, cxt); mrb_close(mrb); return 0; diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c index 505d450926..8856beab61 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c @@ -198,8 +198,8 @@ cleanup(mrb_state *mrb, struct mrbc_args *args) static int partial_hook(struct mrb_parser_state *p) { - mrbc_context *c = p->cxt; - struct mrbc_args *args = (struct mrbc_args *)c->partial_data; + mrb_ccontext *c = p->cxt; + struct mrbc_args *args = (struct mrbc_args*)c->partial_data; const char *fn; if (p->f) fclose(p->f); @@ -220,13 +220,13 @@ partial_hook(struct mrb_parser_state *p) static mrb_value load_file(mrb_state *mrb, struct mrbc_args *args) { - mrbc_context *c; + mrb_ccontext *c; mrb_value result; char *input = args->argv[args->idx]; FILE *infile; mrb_bool need_close = FALSE; - c = mrbc_context_new(mrb); + c = mrb_ccontext_new(mrb); if (args->verbose) c->dump_result = TRUE; c->no_exec = TRUE; @@ -242,16 +242,16 @@ load_file(mrb_state *mrb, struct mrbc_args *args) return mrb_nil_value(); } } - mrbc_filename(mrb, c, input); + mrb_ccontext_filename(mrb, c, input); args->idx++; if (args->idx < args->argc) { need_close = FALSE; - mrbc_partial_hook(mrb, c, partial_hook, (void*)args); + mrb_ccontext_partial_hook(mrb, c, partial_hook, (void*)args); } result = mrb_load_file_cxt(mrb, infile, c); if (need_close) fclose(infile); - mrbc_context_free(mrb, c); + mrb_ccontext_free(mrb, c); if (mrb_undef_p(result)) { return mrb_nil_value(); } @@ -368,9 +368,4 @@ void mrb_init_mrbgems(mrb_state *mrb) { } - -void -mrb_final_mrbgems(mrb_state *mrb) -{ -} #endif diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c index 3faaaccd35..10522011a6 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c @@ -172,8 +172,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) cmdlinelen = strlen(args->cmdline); itemlen = strlen(item); - args->cmdline = - (char *)mrb_realloc(mrb, args->cmdline, cmdlinelen + itemlen + 2); + args->cmdline = (char*)mrb_realloc(mrb, args->cmdline, cmdlinelen + itemlen + 2); args->cmdline[cmdlinelen] = '\n'; memcpy(args->cmdline + cmdlinelen + 1, item, itemlen + 1); } @@ -282,7 +281,7 @@ main(int argc, char **argv) int i; struct _args args; mrb_value ARGV; - mrbc_context *c; + mrb_ccontext *c; mrb_value v; if (mrb == NULL) { @@ -308,7 +307,7 @@ main(int argc, char **argv) mrb_define_global_const(mrb, "ARGV", ARGV); mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug)); - c = mrbc_context_new(mrb); + c = mrb_ccontext_new(mrb); if (args.verbose) c->dump_result = TRUE; if (args.check_syntax) @@ -326,15 +325,14 @@ main(int argc, char **argv) /* Load libraries */ for (i = 0; i < args.libc; i++) { - struct REnv *e; FILE *lfp = fopen(args.libv[i], "rb"); if (lfp == NULL) { fprintf(stderr, "%s: Cannot open library file: %s\n", *argv, args.libv[i]); - mrbc_context_free(mrb, c); + mrb_ccontext_free(mrb, c); cleanup(mrb, &args); return EXIT_FAILURE; } - mrbc_filename(mrb, c, args.libv[i]); + mrb_ccontext_filename(mrb, c, args.libv[i]); if (mrb_extension_p(args.libv[i])) { v = mrb_load_irep_file_cxt(mrb, lfp, c); } @@ -342,14 +340,12 @@ main(int argc, char **argv) v = mrb_load_detect_file_cxt(mrb, lfp, c); } fclose(lfp); - e = mrb_vm_ci_env(mrb->c->cibase); - mrb_vm_ci_env_set(mrb->c->cibase, NULL); - mrb_env_unshare(mrb, e, FALSE); - mrbc_cleanup_local_variables(mrb, c); + mrb_vm_ci_env_clear(mrb, mrb->c->cibase); + mrb_ccontext_cleanup_local_variables(mrb, c); } /* set program file name */ - mrbc_filename(mrb, c, cmdline); + mrb_ccontext_filename(mrb, c, cmdline); /* Load program */ if (args.mrbfile || mrb_extension_p(cmdline)) { @@ -366,7 +362,7 @@ main(int argc, char **argv) } mrb_gc_arena_restore(mrb, ai); - mrbc_context_free(mrb, c); + mrb_ccontext_free(mrb, c); if (mrb->exc) { MRB_EXC_CHECK_EXIT(mrb, mrb->exc); if (!mrb_undef_p(v)) { diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-strip/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-strip/mrbgem.rake index 2abd25eea6..b98fbafcf7 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-strip/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-bin-strip/mrbgem.rake @@ -2,5 +2,6 @@ MRuby::Gem::Specification.new('mruby-bin-strip') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'irep dump debug section remover command' + spec.add_dependency 'mruby-compiler', :core => 'mruby-compiler' spec.bins = %w(mruby-strip) end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/mrbgem.rake deleted file mode 100644 index c0ba48207f..0000000000 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/mrbgem.rake +++ /dev/null @@ -1,7 +0,0 @@ -MRuby::Gem::Specification.new('mruby-binding-core') do |spec| - spec.license = 'MIT' - spec.author = 'mruby developers' - spec.summary = 'Binding class (core features only)' - - spec.add_test_dependency('mruby-proc-ext', :core => 'mruby-proc-ext') -end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/src/binding-core.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/src/binding-core.c deleted file mode 100644 index 47ec34f80b..0000000000 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/src/binding-core.c +++ /dev/null @@ -1,309 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -void mrb_proc_merge_lvar(mrb_state *mrb, mrb_irep *irep, struct REnv *env, int num, const mrb_sym *lv, const mrb_value *stack); -mrb_value mrb_proc_local_variables(mrb_state *mrb, const struct RProc *proc); -const struct RProc *mrb_proc_get_caller(mrb_state *mrb, struct REnv **env); - -static mrb_int -binding_extract_pc(mrb_state *mrb, mrb_value binding) -{ - mrb_value obj = mrb_iv_get(mrb, binding, MRB_SYM(pc)); - if (mrb_nil_p(obj)) { - return -1; - } - else { - mrb_check_type(mrb, obj, MRB_TT_INTEGER); - return mrb_int(mrb, obj); - } -} - -const struct RProc * -mrb_binding_extract_proc(mrb_state *mrb, mrb_value binding) -{ - mrb_value obj = mrb_iv_get(mrb, binding, MRB_SYM(proc)); - mrb_check_type(mrb, obj, MRB_TT_PROC); - return mrb_proc_ptr(obj); -} - -struct REnv * -mrb_binding_extract_env(mrb_state *mrb, mrb_value binding) -{ - mrb_value obj = mrb_iv_get(mrb, binding, MRB_SYM(env)); - if (mrb_nil_p(obj)) { - return NULL; - } - else { - mrb_check_type(mrb, obj, MRB_TT_ENV); - return (struct REnv *)mrb_obj_ptr(obj); - } -} - -static void -binding_local_variable_name_check(mrb_state *mrb, mrb_sym id) -{ - if (id == 0) { - badname: - mrb_raisef(mrb, E_NAME_ERROR, "wrong local variable name %!n for binding", id); - } - - mrb_int len; - const char *name = mrb_sym_name_len(mrb, id, &len); - if (len == 0) { - goto badname; - } - - if (ISASCII(*name) && !(*name == '_' || ISLOWER(*name))) { - goto badname; - } - len--; - name++; - - for (; len > 0; len--, name++) { - if (ISASCII(*name) && !(*name == '_' || ISALNUM(*name))) { - goto badname; - } - } -} - -static mrb_value * -binding_local_variable_search(mrb_state *mrb, const struct RProc *proc, struct REnv *env, mrb_sym varname) -{ - binding_local_variable_name_check(mrb, varname); - - while (proc) { - if (MRB_PROC_CFUNC_P(proc)) break; - - const mrb_irep *irep = proc->body.irep; - const mrb_sym *lv; - if (irep && (lv = irep->lv)) { - for (int i = 0; i + 1 < irep->nlocals; i++, lv++) { - if (varname == *lv) { - return (env && MRB_ENV_LEN(env) > i) ? &env->stack[i + 1] : NULL; - } - } - } - - if (MRB_PROC_SCOPE_P(proc)) break; - env = MRB_PROC_ENV(proc); - proc = proc->upper; - } - - return NULL; -} - -/* - * call-seq: - * local_variable_defined?(symbol) -> bool - */ -static mrb_value -binding_local_variable_defined_p(mrb_state *mrb, mrb_value self) -{ - mrb_sym varname; - mrb_get_args(mrb, "n", &varname); - - const struct RProc *proc = mrb_binding_extract_proc(mrb, self); - struct REnv *env = mrb_binding_extract_env(mrb, self); - mrb_value *e = binding_local_variable_search(mrb, proc, env, varname); - if (e) { - return mrb_true_value(); - } - else { - return mrb_false_value(); - } -} - -/* - * call-seq: - * local_variable_get(symbol) -> object - */ -static mrb_value -binding_local_variable_get(mrb_state *mrb, mrb_value self) -{ - mrb_sym varname; - mrb_get_args(mrb, "n", &varname); - - const struct RProc *proc = mrb_binding_extract_proc(mrb, self); - struct REnv *env = mrb_binding_extract_env(mrb, self); - mrb_value *e = binding_local_variable_search(mrb, proc, env, varname); - if (!e) { - mrb_raisef(mrb, E_NAME_ERROR, "local variable %!n is not defined", varname); - } - - return *e; -} - -static mrb_value -binding_local_variable_set(mrb_state *mrb, mrb_value self) -{ - mrb_sym varname; - mrb_value obj; - mrb_get_args(mrb, "no", &varname, &obj); - - const struct RProc *proc = mrb_binding_extract_proc(mrb, self); - struct REnv *env = mrb_binding_extract_env(mrb, self); - mrb_value *e = binding_local_variable_search(mrb, proc, env, varname); - if (e) { - *e = obj; - if (!mrb_immediate_p(obj)) { - mrb_field_write_barrier(mrb, (struct RBasic*)env, (struct RBasic*)mrb_obj_ptr(obj)); - } - } - else { - mrb_proc_merge_lvar(mrb, (mrb_irep*)proc->body.irep, env, 1, &varname, &obj); - } - - return obj; -} - -static mrb_value -binding_local_variables(mrb_state *mrb, mrb_value self) -{ - const struct RProc *proc = mrb_proc_ptr(mrb_iv_get(mrb, self, MRB_SYM(proc))); - return mrb_proc_local_variables(mrb, proc); -} - -static mrb_value -binding_receiver(mrb_state *mrb, mrb_value self) -{ - return mrb_iv_get(mrb, self, MRB_SYM(recv)); -} - -/* - * call-seq: - * source_location -> [String, Integer] - */ -static mrb_value -binding_source_location(mrb_state *mrb, mrb_value self) -{ - if (mrb_iv_defined(mrb, self, MRB_SYM(source_location))) { - return mrb_iv_get(mrb, self, MRB_SYM(source_location)); - } - - mrb_value srcloc; - const struct RProc *proc = mrb_binding_extract_proc(mrb, self); - if (!proc || MRB_PROC_CFUNC_P(proc) || - !proc->upper || MRB_PROC_CFUNC_P(proc->upper)) { - srcloc = mrb_nil_value(); - } - else { - const mrb_irep *irep = proc->upper->body.irep; - mrb_int pc = binding_extract_pc(mrb, self); - if (pc < 0) { - srcloc = mrb_nil_value(); - } - else { - const char *fname = mrb_debug_get_filename(mrb, irep, (uint32_t)pc); - mrb_int fline = mrb_debug_get_line(mrb, irep, (uint32_t)pc); - - if (fname && fline >= 0) { - srcloc = mrb_assoc_new(mrb, mrb_str_new_cstr(mrb, fname), mrb_fixnum_value(fline)); - } - else { - srcloc = mrb_nil_value(); - } - } - } - - if (!mrb_frozen_p(mrb_obj_ptr(self))) { - mrb_iv_set(mrb, self, MRB_SYM(source_location), srcloc); - } - return srcloc; -} - -mrb_value -mrb_binding_alloc(mrb_state *mrb) -{ - struct RObject *obj = MRB_OBJ_ALLOC(mrb, MRB_TT_OBJECT, mrb_class_get_id(mrb, MRB_SYM(Binding))); - return mrb_obj_value(obj); -} - -struct RProc* -mrb_binding_wrap_lvspace(mrb_state *mrb, const struct RProc *proc, struct REnv **envp) -{ - /* - * local variable space: It is a space to hold the top-level variable of - * binding.eval and binding.local_variable_set. - */ - - static const mrb_code iseq_dummy[] = { OP_RETURN, 0 }; - - struct RProc *lvspace = MRB_OBJ_ALLOC(mrb, MRB_TT_PROC, mrb->proc_class); - mrb_irep *irep = mrb_add_irep(mrb); - irep->flags = MRB_ISEQ_NO_FREE; - irep->iseq = iseq_dummy; - irep->ilen = sizeof(iseq_dummy) / sizeof(iseq_dummy[0]); - irep->lv = (mrb_sym*)mrb_calloc(mrb, 1, sizeof(mrb_sym)); /* initial allocation for dummy */ - irep->nlocals = 1; - irep->nregs = 1; - lvspace->body.irep = irep; - lvspace->upper = proc; - if (*envp) { - lvspace->e.env = *envp; - lvspace->flags |= MRB_PROC_ENVSET; - } - - *envp = MRB_OBJ_ALLOC(mrb, MRB_TT_ENV, NULL); - (*envp)->stack = (mrb_value*)mrb_calloc(mrb, 1, sizeof(mrb_value)); - (*envp)->stack[0] = lvspace->e.env ? lvspace->e.env->stack[0] : mrb_nil_value(); - (*envp)->cxt = lvspace->e.env ? lvspace->e.env->cxt : mrb->c; - (*envp)->mid = 0; - (*envp)->flags = MRB_ENV_CLOSED; - MRB_ENV_SET_LEN(*envp, 1); - - return lvspace; -} - -static mrb_value -mrb_f_binding(mrb_state *mrb, mrb_value self) -{ - mrb_value binding; - struct RProc *proc; - struct REnv *env; - - binding = mrb_binding_alloc(mrb); - proc = (struct RProc*)mrb_proc_get_caller(mrb, &env); - if (!env || MRB_PROC_CFUNC_P(proc)) { - proc = NULL; - env = NULL; - } - - if (proc && !MRB_PROC_CFUNC_P(proc)) { - const mrb_irep *irep = proc->body.irep; - mrb_iv_set(mrb, binding, MRB_SYM(pc), mrb_fixnum_value(mrb->c->ci[-1].pc - irep->iseq - 1 /* step back */)); - } - proc = mrb_binding_wrap_lvspace(mrb, proc, &env); - mrb_iv_set(mrb, binding, MRB_SYM(proc), mrb_obj_value(proc)); - mrb_iv_set(mrb, binding, MRB_SYM(recv), self); - mrb_iv_set(mrb, binding, MRB_SYM(env), mrb_obj_value(env)); - return binding; -} - -void -mrb_mruby_binding_core_gem_init(mrb_state *mrb) -{ - struct RClass *binding = mrb_define_class(mrb, "Binding", mrb->object_class); - mrb_undef_class_method(mrb, binding, "new"); - mrb_undef_class_method(mrb, binding, "allocate"); - - mrb_define_method(mrb, mrb->kernel_module, "binding", mrb_f_binding, MRB_ARGS_NONE()); - - mrb_define_method(mrb, binding, "local_variable_defined?", binding_local_variable_defined_p, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, binding, "local_variable_get", binding_local_variable_get, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, binding, "local_variable_set", binding_local_variable_set, MRB_ARGS_REQ(2)); - mrb_define_method(mrb, binding, "local_variables", binding_local_variables, MRB_ARGS_NONE()); - mrb_define_method(mrb, binding, "receiver", binding_receiver, MRB_ARGS_NONE()); - mrb_define_method(mrb, binding, "source_location", binding_source_location, MRB_ARGS_NONE()); - mrb_define_method(mrb, binding, "inspect", mrb_any_to_s, MRB_ARGS_NONE()); -} - -void -mrb_mruby_binding_core_gem_final(mrb_state *mrb) -{ -} diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/test/binding-core.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/test/binding-core.rb deleted file mode 100644 index 066e79b181..0000000000 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding-core/test/binding-core.rb +++ /dev/null @@ -1,40 +0,0 @@ -assert("Kernel.#binding") do - assert_kind_of Binding, binding -end - -assert("Binding#local_variables") do - block = Proc.new do |a| - b = 1 - binding - end - assert_equal [:a, :b, :block], block.call(0).local_variables.sort -end - -assert("Binding#local_variable_set") do - bind = binding - 1.times { - assert_equal(9, bind.local_variable_set(:x, 9)) - assert_raise(NameError) { x } - assert_equal([:bind, :x], bind.local_variables.sort) - } -end - -assert("Binding#local_variable_get") do - bind = binding - x = 1 - 1.times { - y = 2 - assert_equal(1, bind.local_variable_get(:x)) - x = 10 - assert_equal(10, bind.local_variable_get(:x)) - assert_raise(NameError) { bind.local_variable_get(:y) } - assert_equal([:bind, :x], bind.local_variables.sort) - } -end - -assert("Binding#source_location") do - skip unless -> {}.source_location - - bind, source_location = binding, [__FILE__, __LINE__] - assert_equal source_location, bind.source_location -end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/mrbgem.rake index 4ad5638ea9..fe48f3add0 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/mrbgem.rake @@ -1,11 +1,7 @@ MRuby::Gem::Specification.new('mruby-binding') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' - spec.summary = 'Binding class' + spec.summary = 'Binding class (core features only)' - spec.add_dependency('mruby-binding-core', :core => 'mruby-binding-core') - spec.add_dependency('mruby-eval', :core => 'mruby-eval') - spec.add_test_dependency('mruby-metaprog', :core => 'mruby-metaprog') - spec.add_test_dependency('mruby-method', :core => 'mruby-method') spec.add_test_dependency('mruby-proc-ext', :core => 'mruby-proc-ext') end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/src/binding.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/src/binding.c index de3147f68e..c269facfc0 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/src/binding.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/src/binding.c @@ -1,166 +1,417 @@ #include #include #include -#include -#include +#include #include -#include -#include +#include #include +#include +#include +#include -void mrb_proc_merge_lvar(mrb_state *mrb, mrb_irep *irep, struct REnv *env, int num, const mrb_sym *lv, const mrb_value *stack); -const struct RProc *mrb_binding_extract_proc(mrb_state *mrb, mrb_value binding); -struct REnv *mrb_binding_extract_env(mrb_state *mrb, mrb_value binding); -typedef mrb_bool mrb_parser_foreach_top_variable_func(mrb_state *mrb, mrb_sym sym, void *user); -void mrb_parser_foreach_top_variable(mrb_state *mrb, struct mrb_parser_state *p, mrb_parser_foreach_top_variable_func *func, void *user); +#define BINDING_UPPER_DEFAULT 20 +#define BINDING_UPPER_MINIMUM 10 +#define BINDING_UPPER_MAXIMUM 100 -static void -binding_eval_error_check(mrb_state *mrb, struct mrb_parser_state *p, const char *file) +#ifndef MRB_BINDING_UPPER_MAX +# define BINDING_UPPER_MAX BINDING_UPPER_DEFAULT +#else +# if (MRB_BINDING_UPPER_MAX) > BINDING_UPPER_MAXIMUM +# define BINDING_UPPER_MAX BINDING_UPPER_MAXIMUM +# elif (MRB_BINDING_UPPER_MAX) < BINDING_UPPER_MINIMUM +# define BINDING_UPPER_MAX BINDING_UPPER_MINIMUM +# else +# define BINDING_UPPER_MAX MRB_BINDING_UPPER_MAX +# endif +#endif + +static mrb_int +binding_extract_pc(mrb_state *mrb, mrb_value binding) { - if (!p) { - mrb_raise(mrb, E_RUNTIME_ERROR, "Failed to create parser state (out of memory)"); + mrb_value obj = mrb_iv_get(mrb, binding, MRB_SYM(pc)); + if (mrb_nil_p(obj)) { + return -1; } - - if (0 < p->nerr) { - mrb_value str; - - if (file) { - str = mrb_format(mrb, "file %s line %d: %s", - file, - p->error_buffer[0].lineno, - p->error_buffer[0].message); - } - else { - str = mrb_format(mrb, "line %d: %s", - p->error_buffer[0].lineno, - p->error_buffer[0].message); - } - mrb_exc_raise(mrb, mrb_exc_new_str(mrb, E_SYNTAX_ERROR, str)); + else { + mrb_check_type(mrb, obj, MRB_TT_INTEGER); + return mrb_int(mrb, obj); } } -#define LV_BUFFERS 8 - -struct expand_lvspace { - mrb_irep *irep; - struct REnv *env; - int numvar; - mrb_sym syms[LV_BUFFERS]; -}; - -static mrb_bool -expand_lvspace(mrb_state *mrb, mrb_sym sym, void *user) +const struct RProc * +mrb_binding_extract_proc(mrb_state *mrb, mrb_value binding) { - struct expand_lvspace *p = (struct expand_lvspace*)user; - mrb_int symlen; - const char *symname = mrb_sym_name_len(mrb, sym, &symlen); + mrb_value obj = mrb_iv_get(mrb, binding, MRB_SYM(proc)); + mrb_check_type(mrb, obj, MRB_TT_PROC); + return mrb_proc_ptr(obj); +} - if (symname && symlen > 0) { - if (symname[0] != '&' && symname[0] != '*') { - p->syms[p->numvar++] = sym; - if (p->numvar >= LV_BUFFERS) { - mrb_proc_merge_lvar(mrb, p->irep, p->env, p->numvar, p->syms, NULL); - p->numvar = 0; +struct REnv * +mrb_binding_extract_env(mrb_state *mrb, mrb_value binding) +{ + mrb_value obj = mrb_iv_get(mrb, binding, MRB_SYM(env)); + if (mrb_nil_p(obj)) { + return NULL; + } + else { + mrb_check_type(mrb, obj, MRB_TT_ENV); + return (struct REnv*)mrb_obj_ptr(obj); + } +} + +static mrb_irep * +binding_irep_new_lvspace(mrb_state *mrb) +{ + static const mrb_code iseq_dummy[] = { OP_RETURN, 0 }; + + mrb_irep *irep = mrb_add_irep(mrb); + irep->flags = MRB_ISEQ_NO_FREE; + irep->iseq = iseq_dummy; + irep->ilen = sizeof(iseq_dummy) / sizeof(iseq_dummy[0]); + irep->lv = (mrb_sym*)mrb_calloc(mrb, 1, sizeof(mrb_sym)); /* initial allocation for dummy */ + irep->nlocals = 1; + irep->nregs = 1; + return irep; +} + +static struct RProc * +binding_proc_new_lvspace(mrb_state *mrb, const struct RProc *upper, struct REnv *env) +{ + struct RProc *lvspace = MRB_OBJ_ALLOC(mrb, MRB_TT_PROC, mrb->proc_class); + lvspace->body.irep = binding_irep_new_lvspace(mrb); + lvspace->upper = upper; + if (env && env->tt == MRB_TT_ENV) { + lvspace->e.env = env; + lvspace->flags |= MRB_PROC_ENVSET; + } + return lvspace; +} + +static struct REnv * +binding_env_new_lvspace(mrb_state *mrb, const struct REnv *e) +{ + struct REnv *env = MRB_OBJ_ALLOC(mrb, MRB_TT_ENV, NULL); + mrb_value *stacks = (mrb_value*)mrb_calloc(mrb, 1, sizeof(mrb_value)); + env->cxt = e ? e->cxt : mrb->c; + env->mid = 0; + env->stack = stacks; + if (e && e->stack && MRB_ENV_LEN(e) > 0) { + env->stack[0] = e->stack[0]; + } + else { + env->stack[0] = mrb_nil_value(); + } + env->flags = MRB_ENV_CLOSED; + MRB_ENV_SET_LEN(env, 1); + return env; +} + +static void +binding_check_proc_upper_count(mrb_state *mrb, const struct RProc *proc) +{ + for (size_t count = 0; proc && !MRB_PROC_CFUNC_P(proc); proc = proc->upper) { + count++; + if (count > BINDING_UPPER_MAX) { + mrb_raise(mrb, E_RUNTIME_ERROR, + "too many upper procs for local variables (mruby limitation; maximum is " MRB_STRINGIZE(BINDING_UPPER_MAX) ")"); + } + if (MRB_PROC_SCOPE_P(proc)) break; + } +} + +mrb_bool +mrb_binding_p(mrb_state *mrb, mrb_value obj) +{ + if (!mrb_obj_is_kind_of(mrb, obj, mrb_class_get_id(mrb, MRB_SYM(Binding)))) return FALSE; + if (mrb_type(obj) != MRB_TT_OBJECT) return FALSE; + if (!mrb_obj_iv_defined(mrb, mrb_obj_ptr(obj), MRB_SYM(proc))) return FALSE; + if (!mrb_obj_iv_defined(mrb, mrb_obj_ptr(obj), MRB_SYM(recv))) return FALSE; + if (!mrb_obj_iv_defined(mrb, mrb_obj_ptr(obj), MRB_SYM(env))) return FALSE; + return TRUE; +} + +static void +binding_type_ensure(mrb_state *mrb, mrb_value obj) +{ + if (mrb_binding_p(mrb, obj)) return; + mrb_raise(mrb, E_TYPE_ERROR, "not a binding"); +} + +static struct RProc* +binding_wrap_lvspace(mrb_state *mrb, const struct RProc *proc, struct REnv **envp) +{ + /* + * local variable space: It is a space to hold the top-level variable of + * binding.eval and binding.local_variable_set. + */ + + struct RProc *lvspace = binding_proc_new_lvspace(mrb, proc, *envp); + *envp = binding_env_new_lvspace(mrb, *envp); + return lvspace; +} + +static mrb_value +binding_initialize_copy(mrb_state *mrb, mrb_value binding) +{ + mrb_value src = mrb_get_arg1(mrb); + binding_type_ensure(mrb, src); + const struct RProc *src_proc = mrb_binding_extract_proc(mrb, src); + struct REnv *src_env = mrb_binding_extract_env(mrb, src); + + mrb_check_frozen(mrb, mrb_obj_ptr(binding)); + + struct RProc *lvspace; + struct REnv *env; + if (MRB_ENV_LEN(src_env) < 2) { + /* when local variables of src are self only */ + env = src_proc->e.env; + lvspace = binding_wrap_lvspace(mrb, src_proc->upper, &env); + } + else { + binding_check_proc_upper_count(mrb, src_proc); + + env = src_env; + lvspace = binding_wrap_lvspace(mrb, src_proc, &env); + + // The reason for using the mrb_obj_iv_set_force() function is to allow local + // variables to be modified even if src is frozen. This behavior is CRuby imitation. + src_proc = binding_wrap_lvspace(mrb, src_proc, &src_env); + struct RObject *o = mrb_obj_ptr(src); + mrb_obj_iv_set_force(mrb, o, MRB_SYM(proc), mrb_obj_value((struct RProc*)src_proc)); + mrb_obj_iv_set_force(mrb, o, MRB_SYM(env), mrb_obj_value(src_env)); + } + mrb_iv_set(mrb, binding, MRB_SYM(proc), mrb_obj_value(lvspace)); + mrb_iv_set(mrb, binding, MRB_SYM(env), mrb_obj_value(env)); + + return binding; +} + +static void +binding_local_variable_name_check(mrb_state *mrb, mrb_sym id) +{ + if (id == 0) { + badname: + mrb_raisef(mrb, E_NAME_ERROR, "wrong local variable name %!n for binding", id); + } + + mrb_int len; + const char *name = mrb_sym_name_len(mrb, id, &len); + if (len == 0) { + goto badname; + } + + if (ISASCII(*name) && !(*name == '_' || ISLOWER(*name))) { + goto badname; + } + len--; + name++; + + for (; len > 0; len--, name++) { + if (ISASCII(*name) && !(*name == '_' || ISALNUM(*name))) { + goto badname; + } + } +} + +static mrb_value * +binding_local_variable_search(mrb_state *mrb, const struct RProc *proc, struct REnv *env, mrb_sym varname) +{ + binding_local_variable_name_check(mrb, varname); + + while (proc) { + if (MRB_PROC_CFUNC_P(proc)) break; + + const mrb_irep *irep = proc->body.irep; + const mrb_sym *lv; + if (irep && (lv = irep->lv)) { + for (int i = 0; i + 1 < irep->nlocals; i++, lv++) { + if (varname == *lv) { + return (env && MRB_ENV_LEN(env) > i) ? &env->stack[i + 1] : NULL; + } + } + } + + if (MRB_PROC_SCOPE_P(proc)) break; + env = MRB_PROC_ENV(proc); + proc = proc->upper; + } + + return NULL; +} + +/* + * call-seq: + * local_variable_defined?(symbol) -> bool + */ +static mrb_value +binding_local_variable_defined_p(mrb_state *mrb, mrb_value self) +{ + mrb_sym varname; + mrb_get_args(mrb, "n", &varname); + + const struct RProc *proc = mrb_binding_extract_proc(mrb, self); + struct REnv *env = mrb_binding_extract_env(mrb, self); + mrb_value *e = binding_local_variable_search(mrb, proc, env, varname); + if (e) { + return mrb_true_value(); + } + else { + return mrb_false_value(); + } +} + +/* + * call-seq: + * local_variable_get(symbol) -> object + */ +static mrb_value +binding_local_variable_get(mrb_state *mrb, mrb_value self) +{ + mrb_sym varname; + mrb_get_args(mrb, "n", &varname); + + const struct RProc *proc = mrb_binding_extract_proc(mrb, self); + struct REnv *env = mrb_binding_extract_env(mrb, self); + mrb_value *e = binding_local_variable_search(mrb, proc, env, varname); + if (!e) { + mrb_raisef(mrb, E_NAME_ERROR, "local variable %!n is not defined", varname); + } + + return *e; +} + +static mrb_value +binding_local_variable_set(mrb_state *mrb, mrb_value self) +{ + mrb_sym varname; + mrb_value obj; + mrb_get_args(mrb, "no", &varname, &obj); + + const struct RProc *proc = mrb_binding_extract_proc(mrb, self); + struct REnv *env = mrb_binding_extract_env(mrb, self); + mrb_value *e = binding_local_variable_search(mrb, proc, env, varname); + if (e) { + *e = obj; + if (!mrb_immediate_p(obj)) { + mrb_field_write_barrier(mrb, (struct RBasic*)env, (struct RBasic*)mrb_obj_ptr(obj)); + } + } + else { + mrb_proc_merge_lvar(mrb, (mrb_irep*)proc->body.irep, env, 1, &varname, &obj); + } + + return obj; +} + +static mrb_value +binding_local_variables(mrb_state *mrb, mrb_value self) +{ + const struct RProc *proc = mrb_proc_ptr(mrb_iv_get(mrb, self, MRB_SYM(proc))); + return mrb_proc_local_variables(mrb, proc); +} + +static mrb_value +binding_receiver(mrb_state *mrb, mrb_value self) +{ + return mrb_iv_get(mrb, self, MRB_SYM(recv)); +} + +/* + * call-seq: + * source_location -> [String, Integer] + */ +static mrb_value +binding_source_location(mrb_state *mrb, mrb_value self) +{ + if (mrb_iv_defined(mrb, self, MRB_SYM(source_location))) { + return mrb_iv_get(mrb, self, MRB_SYM(source_location)); + } + + mrb_value srcloc; + const struct RProc *proc = mrb_binding_extract_proc(mrb, self); + if (!proc || MRB_PROC_CFUNC_P(proc) || + !proc->upper || MRB_PROC_CFUNC_P(proc->upper)) { + srcloc = mrb_nil_value(); + } + else { + const mrb_irep *irep = proc->upper->body.irep; + mrb_int pc = binding_extract_pc(mrb, self); + if (pc < 0) { + srcloc = mrb_nil_value(); + } + else { + const char *fname; + int32_t line; + + if (!mrb_debug_get_position(mrb, irep, (uint32_t)pc, &line, &fname)) { + srcloc = mrb_nil_value(); + } + else { + srcloc = mrb_assoc_new(mrb, mrb_str_new_cstr(mrb, fname), mrb_fixnum_value(line)); } } } - return TRUE; -} - -struct binding_eval_prepare_body { - mrb_value binding; - const char *file; - const char *expr; - mrb_int exprlen; - mrbc_context *mrbc; - struct mrb_parser_state *pstate; -}; - -static mrb_value -binding_eval_prepare_body(mrb_state *mrb, void *opaque) -{ - struct binding_eval_prepare_body *p = (struct binding_eval_prepare_body*)opaque; - - const struct RProc *proc = mrb_binding_extract_proc(mrb, p->binding); - mrb_assert(!MRB_PROC_CFUNC_P(proc)); - - p->mrbc = mrbc_context_new(mrb); - mrbc_filename(mrb, p->mrbc, p->file ? p->file : "(eval)"); - p->mrbc->upper = proc; - p->mrbc->capture_errors = TRUE; - p->pstate = mrb_parse_nstring(mrb, p->expr, p->exprlen, p->mrbc); - binding_eval_error_check(mrb, p->pstate, p->file); - - struct expand_lvspace args = { - (mrb_irep*)proc->body.irep, - mrb_binding_extract_env(mrb, p->binding), - 0, - { 0 } - }; - mrb_parser_foreach_top_variable(mrb, p->pstate, expand_lvspace, &args); - if (args.numvar > 0) { - mrb_proc_merge_lvar(mrb, args.irep, args.env, args.numvar, args.syms, NULL); + if (!mrb_frozen_p(mrb_obj_ptr(self))) { + mrb_iv_set(mrb, self, MRB_SYM(source_location), srcloc); } - - return mrb_nil_value(); + return srcloc; } -static void -binding_eval_prepare(mrb_state *mrb, mrb_value binding) +mrb_value +mrb_binding_new(mrb_state *mrb, const struct RProc *proc, mrb_value recv, struct REnv *env) { - struct binding_eval_prepare_body d = { binding, NULL, NULL, 0, NULL, NULL }; - mrb_int argc; - mrb_value *argv; - mrb_get_args(mrb, "s|z*!", &d.expr, &d.exprlen, &d.file, &argv, &argc); + struct RObject *binding = MRB_OBJ_ALLOC(mrb, MRB_TT_OBJECT, mrb_class_get_id(mrb, MRB_SYM(Binding))); - /* `eval` should take (string[, file, line]) */ - if (argc > 3) mrb_argnum_error(mrb, argc, 1, 3); - mrb_bool error; - mrb_value ret = mrb_protect_error(mrb, binding_eval_prepare_body, &d, &error); - if (d.pstate) mrb_parser_free(d.pstate); - if (d.mrbc) mrbc_context_free(mrb, d.mrbc); - if (error) mrb_exc_raise(mrb, ret); + if (proc && !MRB_PROC_CFUNC_P(proc)) { + const mrb_irep *irep = proc->body.irep; + mrb_obj_iv_set(mrb, binding, MRB_SYM(pc), mrb_fixnum_value(mrb->c->ci[-1].pc - irep->iseq - 1 /* step back */)); + } + proc = binding_wrap_lvspace(mrb, proc, &env); + + mrb_obj_iv_set(mrb, binding, MRB_SYM(proc), mrb_obj_value((void*)proc)); + mrb_obj_iv_set(mrb, binding, MRB_SYM(recv), recv); + mrb_obj_iv_set(mrb, binding, MRB_SYM(env), mrb_obj_value(env)); + + return mrb_obj_value(binding); } static mrb_value -mrb_binding_eval(mrb_state *mrb, mrb_value binding) +mrb_f_binding(mrb_state *mrb, mrb_value self) { - binding_eval_prepare(mrb, binding); - - struct RClass *c = mrb->kernel_module; - mrb_method_t m = mrb_method_search_vm(mrb, &c, MRB_SYM(eval)); - mrb_callinfo *ci = mrb->c->ci; - int argc = ci->n; - mrb_value *argv = ci->stack + 1; struct RProc *proc; + struct REnv *env; - if (argc < 15) { - argv[0] = mrb_ary_new_from_values(mrb, argc, argv); - argv[1] = argv[argc]; /* copy block */ - ci->n = 15; + if (mrb->c->ci->cci != 0) { + caller_err: + mrb_raise(mrb, E_RUNTIME_ERROR, "Cannot create Binding object for non-Ruby caller"); } - if (MRB_METHOD_UNDEF_P(m)) { - mrb_method_missing(mrb, MRB_SYM(eval), binding, argv[0]); + proc = (struct RProc*)mrb_proc_get_caller(mrb, &env); + if (!env || MRB_PROC_CFUNC_P(proc)) { + goto caller_err; } - - mrb_ary_splice(mrb, argv[0], 1, 0, binding); /* insert binding as 2nd argument */ - if (MRB_METHOD_FUNC_P(m)) { - proc = mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m)); - MRB_PROC_SET_TARGET_CLASS(proc, c); - } - else { - proc = MRB_METHOD_PROC(m); - } - ci->u.target_class = c; - return mrb_exec_irep(mrb, binding, proc); + return mrb_binding_new(mrb, proc, self, env); } void mrb_mruby_binding_gem_init(mrb_state *mrb) { - struct RClass *binding = mrb_class_get_id(mrb, MRB_SYM(Binding)); - mrb_define_method(mrb, binding, "eval", mrb_binding_eval, MRB_ARGS_ANY()); + struct RClass *binding = mrb_define_class(mrb, "Binding", mrb->object_class); + MRB_SET_INSTANCE_TT(binding, MRB_TT_OBJECT); + MRB_UNDEF_ALLOCATOR(binding); + mrb_undef_class_method(mrb, binding, "new"); + mrb_undef_class_method(mrb, binding, "allocate"); + + mrb_define_method(mrb, mrb->kernel_module, "binding", mrb_f_binding, MRB_ARGS_NONE()); + + mrb_define_method(mrb, binding, "initialize_copy", binding_initialize_copy, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, binding, "local_variable_defined?", binding_local_variable_defined_p, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, binding, "local_variable_get", binding_local_variable_get, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, binding, "local_variable_set", binding_local_variable_set, MRB_ARGS_REQ(2)); + mrb_define_method(mrb, binding, "local_variables", binding_local_variables, MRB_ARGS_NONE()); + mrb_define_method(mrb, binding, "receiver", binding_receiver, MRB_ARGS_NONE()); + mrb_define_method(mrb, binding, "source_location", binding_source_location, MRB_ARGS_NONE()); + mrb_define_method(mrb, binding, "inspect", mrb_any_to_s, MRB_ARGS_NONE()); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/test/binding.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/test/binding.rb index bfae84c596..1f76b29fae 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/test/binding.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-binding/test/binding.rb @@ -1,9 +1,5 @@ -assert("Binding#eval") do - b = nil - 1.times { x, y, z = 1, 2, 3; [x,y,z]; b = binding } - assert_equal([1, 2, 3], b.eval("[x, y, z]")) - here = self - assert_equal(here, b.eval("self")) +assert("Kernel.#binding") do + assert_kind_of Binding, binding end assert("Binding#local_variables") do @@ -11,18 +7,15 @@ assert("Binding#local_variables") do b = 1 binding end - bind = block.call(0) - assert_equal [:a, :b, :bind, :block], bind.local_variables.sort - bind.eval("x = 2") - assert_equal [:a, :b, :bind, :block, :x], bind.local_variables.sort + assert_equal [:a, :b, :block], block.call(0).local_variables.sort end assert("Binding#local_variable_set") do bind = binding 1.times { assert_equal(9, bind.local_variable_set(:x, 9)) - assert_equal(9, bind.eval("x")) - assert_equal([:bind, :x], bind.eval("local_variables.sort")) + assert_raise(NameError) { x } + assert_equal([:bind, :x], bind.local_variables.sort) } end @@ -35,36 +28,37 @@ assert("Binding#local_variable_get") do x = 10 assert_equal(10, bind.local_variable_get(:x)) assert_raise(NameError) { bind.local_variable_get(:y) } - bind.eval("z = 3") - assert_equal(3, bind.local_variable_get(:z)) - bind.eval("y = 5") - assert_equal(5, bind.local_variable_get(:y)) - assert_equal(2, y) + assert_equal([:bind, :x], bind.local_variables.sort) } end +assert("Binding#source_location") do + skip unless -> {}.source_location + + bind, source_location = binding, [__FILE__, __LINE__] + assert_equal source_location, bind.source_location +end + +assert("Binding#dup") do + x = 5 + bind1 = binding + bind1.local_variable_set(:y, 10) + bind2 = bind1.dup + assert_equal 5, bind2.local_variable_get(:x) + assert_equal 10, bind2.local_variable_get(:y) + x = 50 + assert_equal 50, bind1.local_variable_get(:x) + assert_equal 50, bind2.local_variable_get(:x) + bind1.local_variable_set(:y, 20) + assert_equal 20, bind1.local_variable_get(:y) + assert_equal 20, bind2.local_variable_get(:y) + bind1.local_variable_set(:z, 30) + assert_raise(NameError) { bind2.local_variable_get(:z) } + bind2.local_variable_set(:z, 40) + assert_equal 30, bind1.local_variable_get(:z) + assert_equal 40, bind2.local_variable_get(:z) +end + assert "Kernel#binding and .eval from C" do - bind = binding_in_c - assert_equal 5, bind.eval("2 + 3") - assert_nothing_raised { bind.eval("self") } -end - -assert "Binding#eval with Binding.new via UnboundMethod" do - assert_raise(NoMethodError) { Class.instance_method(:new).bind_call(Binding) } -end - -assert "Binding#eval with Binding.new via Method" do - # The following test is OK if SIGSEGV does not occur - cx = Class.new(Binding) - cx.define_singleton_method(:allocate, &Object.method(:allocate)) - Class.instance_method(:new).bind_call(cx).eval("") - - assert_true true -end - -assert "access local variables into procs" do - bx = binding - block = bx.eval("a = 1; proc { a }") - bx.eval("a = 2") - assert_equal 2, block.call + assert_raise(RuntimeError) { binding_in_c } end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-catch/src/catch.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-catch/src/catch.c index 048a44738e..d655ada900 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-catch/src/catch.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-catch/src/catch.c @@ -6,95 +6,71 @@ #include #include +MRB_PRESYM_DEFINE_VAR_AND_INITER(catch_syms, 3, MRB_SYM(Object), MRB_SYM(new), MRB_SYM(call)) +/* + * def catch(r1 = Object.new, &r2) + * r2.call(r1) + * end + */ +static const mrb_code catch_iseq[] = { + OP_ENTER, 0x00, 0x20, 0x01, // 000 ENTER 0:1:0:0:0:0:1 (0x2001) + OP_JMP, 0x00, 0x06, // 004 JMP 013 -MRB_PRESYM_DEFINE_VAR_AND_INITER(catch_syms_3, 1, MRB_SYM(call)) -static const mrb_code catch_iseq_3[18] = { - OP_ENTER, 0x00, 0x00, 0x00, - OP_GETUPVAR, 0x02, 0x02, 0x01, - OP_GETUPVAR, 0x03, 0x01, 0x01, - OP_SEND, 0x02, 0x00, 0x01, - OP_RETURN, 0x02,}; -static const mrb_irep catch_irep_3 = { - 2,5,0, - MRB_IREP_STATIC,catch_iseq_3, - NULL,catch_syms_3,NULL, - NULL, - NULL, - 18,0,1,0,0 + // copy for block parameter "tag" when method argument are given + OP_MOVE, 0x03, 0x01, // 007 MOVE R3 R1 + OP_JMP, 0x00, 0x0a, // 010 JMP 023 + + // create a tag for default parameter + OP_GETCONST, 0x03, 0x00, // 013 GETCONST R3 Object + OP_SEND, 0x03, 0x01, 0x00, // 016 SEND R3 :new n=0 + OP_MOVE, 0x01, 0x03, // 020 MOVE R1 R3 + + // to save on the stack, block variables are used as is + OP_SEND, 0x02, 0x02, 0x01, // 023 SEND R2 :call n=1 + OP_RETURN, 0x02, // 027 RETURN R2 }; -static const mrb_irep *catch_reps_2[1] = { - &catch_irep_3, -}; -static const mrb_code catch_iseq_2[13] = { - OP_ENTER, 0x00, 0x00, 0x00, - OP_LAMBDA, 0x02, 0x00, - OP_SEND, 0x02, 0x00, 0x00, - OP_RETURN, 0x02,}; -static const mrb_irep catch_irep_2 = { - 2,4,0, - MRB_IREP_STATIC,catch_iseq_2, - NULL,catch_syms_3,catch_reps_2, - NULL, - NULL, - 13,0,1,1,0 -}; -static const mrb_irep *catch_reps_1[1] = { - &catch_irep_2, -}; -MRB_PRESYM_DEFINE_VAR_AND_INITER(catch_syms_1, 3, MRB_SYM(Object), MRB_SYM(new), MRB_SYM(call)) -static const mrb_code catch_iseq_1[29] = { - OP_ENTER, 0x00, 0x20, 0x01, - OP_JMP, 0x00, 0x03, - OP_JMP, 0x00, 0x0a, - OP_GETCONST, 0x03, 0x00, - OP_SEND, 0x03, 0x01, 0x00, - OP_MOVE, 0x01, 0x03, - OP_LAMBDA, 0x03, 0x00, - OP_SEND, 0x03, 0x02, 0x00, - OP_RETURN, 0x03,}; static const mrb_irep catch_irep = { 3,5,0, - MRB_IREP_STATIC,catch_iseq_1, - NULL,catch_syms_1,catch_reps_1, + MRB_IREP_STATIC,catch_iseq, + NULL,catch_syms,NULL, NULL, NULL, - 29,0,3,1,0 + sizeof(catch_iseq),0,3,0,0 }; - static const struct RProc catch_proc = { NULL, NULL, MRB_TT_PROC, MRB_GC_RED, MRB_FL_OBJ_IS_FROZEN | MRB_PROC_SCOPE | MRB_PROC_STRICT, { &catch_irep }, NULL, { NULL } }; -static const mrb_callinfo * +static uintptr_t find_catcher(mrb_state *mrb, mrb_value tag) { - const mrb_callinfo *ci = mrb->c->ci; - size_t n = ci - mrb->c->cibase; - ci--; + const mrb_callinfo *ci = mrb->c->ci - 1; // skip ownself throw + ptrdiff_t n = ci - mrb->c->cibase; + for (; n > 0; n--, ci--) { const mrb_value *arg1 = ci->stack + 1; if (ci->proc == &catch_proc && mrb_obj_eq(mrb, *arg1, tag)) { - return ci; + return (uintptr_t)n; } } - return NULL; + return 0; } static mrb_value -mrb_f_throw(mrb_state *mrb, mrb_value self) +throw_m(mrb_state *mrb, mrb_value self) { mrb_value tag, obj; if (mrb_get_args(mrb, "o|o", &tag, &obj) == 1) { obj = mrb_nil_value(); } - const mrb_callinfo *ci = find_catcher(mrb, tag); - if (ci) { + uintptr_t ci_index = find_catcher(mrb, tag); + if (ci_index > 0) { struct RBreak *b = MRB_OBJ_ALLOC(mrb, MRB_TT_BREAK, NULL); mrb_break_value_set(b, obj); - mrb_break_proc_set(b, ci[2].proc); /* Back to the closure in `catch` method */ + b->ci_break_index = ci_index; /* Back to the caller directly */ mrb_exc_raise(mrb, mrb_obj_value(b)); } else { @@ -110,12 +86,11 @@ mrb_mruby_catch_gem_init(mrb_state *mrb) { mrb_method_t m; - MRB_PRESYM_INIT_SYMBOLS(mrb, catch_syms_3); - MRB_PRESYM_INIT_SYMBOLS(mrb, catch_syms_1); + MRB_PRESYM_INIT_SYMBOLS(mrb, catch_syms); MRB_METHOD_FROM_PROC(m, &catch_proc); mrb_define_method_raw(mrb, mrb->kernel_module, MRB_SYM(catch), m); - mrb_define_method(mrb, mrb->kernel_module, "throw", mrb_f_throw, MRB_ARGS_ARG(1,1)); + mrb_define_method(mrb, mrb->kernel_module, "throw", throw_m, MRB_ARGS_ARG(1,1)); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-class-ext/src/class.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-class-ext/src/class.c index dbe061524e..0fa0a4afea 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-class-ext/src/class.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-class-ext/src/class.c @@ -7,7 +7,7 @@ #include "mruby/presym.h" static mrb_value -mrb_mod_name(mrb_state *mrb, mrb_value self) +mod_name(mrb_state *mrb, mrb_value self) { mrb_value name = mrb_class_path(mrb, mrb_class_ptr(self)); if (mrb_string_p(name)) { @@ -17,7 +17,7 @@ mrb_mod_name(mrb_state *mrb, mrb_value self) } static mrb_value -mrb_mod_singleton_class_p(mrb_state *mrb, mrb_value self) +mod_singleton_class_p(mrb_state *mrb, mrb_value self) { return mrb_bool_value(mrb_sclass_p(self)); } @@ -42,7 +42,7 @@ mrb_mod_singleton_class_p(mrb_state *mrb, mrb_value self) */ static mrb_value -mrb_mod_module_exec(mrb_state *mrb, mrb_value self) +mod_module_exec(mrb_state *mrb, mrb_value self) { const mrb_value *argv; mrb_int argc; @@ -95,7 +95,7 @@ add_subclasses(mrb_state *mrb, struct RBasic *obj, void *data) * C.subclasses #=> [] */ static mrb_value -mrb_class_subclasses(mrb_state *mrb, mrb_value self) +class_subclasses(mrb_state *mrb, mrb_value self) { struct RClass *c; mrb_value ary; @@ -126,7 +126,7 @@ mrb_class_subclasses(mrb_state *mrb, mrb_value self) * NilClass.attached_object #=> TypeError: not a singleton class */ static mrb_value -mrb_class_attached_object(mrb_state *mrb, mrb_value self) +class_attached_object(mrb_state *mrb, mrb_value self) { struct RClass *c; @@ -142,14 +142,14 @@ mrb_mruby_class_ext_gem_init(mrb_state *mrb) { struct RClass *mod = mrb->module_class; - mrb_define_method(mrb, mod, "name", mrb_mod_name, MRB_ARGS_NONE()); - mrb_define_method(mrb, mod, "singleton_class?", mrb_mod_singleton_class_p, MRB_ARGS_NONE()); - mrb_define_method(mrb, mod, "module_exec", mrb_mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK()); - mrb_define_method(mrb, mod, "class_exec", mrb_mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK()); + mrb_define_method(mrb, mod, "name", mod_name, MRB_ARGS_NONE()); + mrb_define_method(mrb, mod, "singleton_class?", mod_singleton_class_p, MRB_ARGS_NONE()); + mrb_define_method(mrb, mod, "module_exec", mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK()); + mrb_define_method(mrb, mod, "class_exec", mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK()); struct RClass *cls = mrb->class_class; - mrb_define_method(mrb, cls, "subclasses", mrb_class_subclasses, MRB_ARGS_NONE()); - mrb_define_method(mrb, cls, "attached_object", mrb_class_attached_object, MRB_ARGS_NONE()); + mrb_define_method(mrb, cls, "subclasses", class_subclasses, MRB_ARGS_NONE()); + mrb_define_method(mrb, cls, "attached_object", class_attached_object, MRB_ARGS_NONE()); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-cmath/src/cmath.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-cmath/src/cmath.c index de59adf96c..b0b8d5f180 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-cmath/src/cmath.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-cmath/src/cmath.c @@ -33,7 +33,7 @@ cmath_get_complex(mrb_state *mrb, mrb_value c, mrb_float *r, mrb_float *i) *i = 0; return FALSE; } - else if (mrb_obj_is_kind_of(mrb, c, mrb_class_get(mrb, "Complex"))) { + else if (mrb_type(c) == MRB_TT_COMPLEX) { mrb_complex_get(mrb, c, r, i); return TRUE; } @@ -76,13 +76,13 @@ CXDIVc(mrb_complex a, mrb_complex b) if ((abi = cimag(b)) < 0) abi = - abi; if (abr <= abi) { - ratio = creal(b) / cimag(b) ; + ratio = creal(b) / cimag(b); den = cimag(a) * (1 + ratio*ratio); cr = (creal(a)*ratio + cimag(a)) / den; ci = (cimag(a)*ratio - creal(a)) / den; } else { - ratio = cimag(b) / creal(b) ; + ratio = cimag(b) / creal(b); den = creal(a) * (1 + ratio*ratio); cr = (creal(a) + cimag(a)*ratio) / den; ci = (cimag(a) - creal(a)*ratio) / den; diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compar-ext/mrblib/compar.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compar-ext/mrblib/compar.rb index 18bba79193..cc40223d72 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compar-ext/mrblib/compar.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compar-ext/mrblib/compar.rb @@ -53,8 +53,17 @@ module Comparable if min.nil? min = self end + elsif min.nil? or min < self + return self else - raise TypeError, "wrong argument type #{min.class}" + return min + end + end + if min.nil? + if self < max + return self + else + return max end end c = min <=> max diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/codegen.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/codegen.c index 41e269e668..7315832bad 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/codegen.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/codegen.c @@ -771,7 +771,7 @@ get_int_operand(codegen_scope *s, struct mrb_insn_data *data, mrb_int *n) return TRUE; case OP_LOADI32: - *n = (mrb_int)((uint32_t)data->b<<16)+data->c; + *n = (int32_t)((uint32_t)data->b<<16)+data->c; return TRUE; case OP_LOADL: diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/parse.y b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/parse.y index 20d8648060..4522296c8c 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/parse.y +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/parse.y @@ -139,7 +139,7 @@ cons_gen(parser_state *p, node *car, node *cdr) c->filename_index = p->current_filename_index; /* beginning of next partial file; need to point the previous file */ if (p->lineno == 0 && p->current_filename_index > 0) { - c->filename_index-- ; + c->filename_index--; } return c; } @@ -1101,8 +1101,8 @@ concat_string(parser_state *p, node *a, node *b) } else { node *c; /* last node of a */ - for (c = a; c->cdr != NULL; c = c->cdr) ; - + for (c = a; c->cdr != NULL; c = c->cdr) + ; if (string_node_p(b)) { /* a == NODE_DSTR && b == NODE_STR */ if (string_node_p(c->car)) { @@ -1460,56 +1460,56 @@ heredoc_end(parser_state *p) } %token - keyword_class - keyword_module - keyword_def - keyword_begin - keyword_if - keyword_unless - keyword_while - keyword_until - keyword_for + keyword_class "'class'" + keyword_module "'module'" + keyword_def "'def'" + keyword_begin "'begin'" + keyword_if "'if'" + keyword_unless "'unless'" + keyword_while "'while'" + keyword_until "'until'" + keyword_for "'for'" %token - keyword_undef - keyword_rescue - keyword_ensure - keyword_end - keyword_then - keyword_elsif - keyword_else - keyword_case - keyword_when - keyword_break - keyword_next - keyword_redo - keyword_retry - keyword_in - keyword_do - keyword_do_cond - keyword_do_block - keyword_do_LAMBDA - keyword_return - keyword_yield - keyword_super - keyword_self - keyword_nil - keyword_true - keyword_false - keyword_and - keyword_or - keyword_not - modifier_if - modifier_unless - modifier_while - modifier_until - modifier_rescue - keyword_alias - keyword_BEGIN - keyword_END - keyword__LINE__ - keyword__FILE__ - keyword__ENCODING__ + keyword_undef "'undef'" + keyword_rescue "'rescue'" + keyword_ensure "'ensure'" + keyword_end "'end'" + keyword_then "'then'" + keyword_elsif "'elsif'" + keyword_else "'else'" + keyword_case "'case'" + keyword_when "'when'" + keyword_break "'break'" + keyword_next "'next'" + keyword_redo "'redo'" + keyword_retry "'retry'" + keyword_in "'in'" + keyword_do "'do'" + keyword_do_cond "'do' for condition" + keyword_do_block "'do' for block" + keyword_do_LAMBDA "'do' for lambda" + keyword_return "'return'" + keyword_yield "'yield'" + keyword_super "'super'" + keyword_self "'self'" + keyword_nil "'nil'" + keyword_true "'true'" + keyword_false "'false'" + keyword_and "'and'" + keyword_or "'or'" + keyword_not "'not'" + modifier_if "'if' modifier" + modifier_unless "'unless' modifier" + modifier_while "'while' modifier" + modifier_until "'until' modifier" + modifier_rescue "'rescue' modifier" + keyword_alias "'alis'" + keyword_BEGIN "'BEGIN'" + keyword_END "'END'" + keyword__LINE__ "'__LINE__'" + keyword__FILE__ "'__FILE__'" + keyword__ENCODING__ "'__ENCODING__'" %token tIDENTIFIER "local variable or method" %token tFID "method" @@ -3175,12 +3175,14 @@ do_block : keyword_do_block { local_nest(p); nvars_nest(p); + $$ = p->lineno; } opt_block_param bodystmt keyword_end { $$ = new_block(p,$3,$4); + SET_LINENO($$, $2); local_unnest(p); nvars_unnest(p); } @@ -4826,7 +4828,8 @@ heredoc_remove_indent(parser_state *p, parser_heredoc_info *hinfo) newstr[newlen] = '\0'; pair->car = (node*)newstr; pair->cdr = (node*)newlen; - } else { + } + else { spaces = (size_t)nspaces->car; heredoc_count_indent(hinfo, str, len, spaces, &offset); pair->car = (node*)(str + offset); @@ -4901,7 +4904,8 @@ parse_string(parser_state *p) if (sizeof(s1)+sizeof(s2)+strlen(hinfo->term)+1 >= sizeof(buf)) { yyerror(p, "can't find heredoc delimiter anywhere before EOF"); - } else { + } + else { strcpy(buf, s1); strcat(buf, hinfo->term); strcat(buf, s2); @@ -6584,7 +6588,7 @@ yylex(void *lval, parser_state *p) } static void -parser_init_cxt(parser_state *p, mrbc_context *cxt) +parser_init_cxt(parser_state *p, mrb_ccontext *cxt) { if (!cxt) return; if (cxt->filename) mrb_parser_set_filename(p, cxt->filename); @@ -6607,7 +6611,7 @@ parser_init_cxt(parser_state *p, mrbc_context *cxt) } static void -parser_update_cxt(parser_state *p, mrbc_context *cxt) +parser_update_cxt(parser_state *p, mrb_ccontext *cxt) { node *n, *n0; int i = 0; @@ -6630,7 +6634,7 @@ parser_update_cxt(parser_state *p, mrbc_context *cxt) void mrb_parser_dump(mrb_state *mrb, node *tree, int offset); MRB_API void -mrb_parser_parse(parser_state *p, mrbc_context *c) +mrb_parser_parse(parser_state *p, mrb_ccontext *c) { struct mrb_jmpbuf buf1; struct mrb_jmpbuf *prev = p->mrb->jmp; @@ -6718,14 +6722,14 @@ mrb_parser_free(parser_state *p) { mrb_pool_close(p->pool); } -MRB_API mrbc_context* -mrbc_context_new(mrb_state *mrb) +MRB_API mrb_ccontext* +mrb_ccontext_new(mrb_state *mrb) { - return (mrbc_context*)mrb_calloc(mrb, 1, sizeof(mrbc_context)); + return (mrb_ccontext*)mrb_calloc(mrb, 1, sizeof(mrb_ccontext)); } MRB_API void -mrbc_context_free(mrb_state *mrb, mrbc_context *cxt) +mrb_ccontext_free(mrb_state *mrb, mrb_ccontext *cxt) { mrb_free(mrb, cxt->filename); mrb_free(mrb, cxt->syms); @@ -6733,12 +6737,13 @@ mrbc_context_free(mrb_state *mrb, mrbc_context *cxt) } MRB_API const char* -mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s) +mrb_ccontext_filename(mrb_state *mrb, mrb_ccontext *c, const char *s) { if (s) { size_t len = strlen(s); - char *p = (char*)mrb_malloc(mrb, len + 1); + char *p = (char*)mrb_malloc_simple(mrb, len + 1); + if (p == NULL) return NULL; memcpy(p, s, len + 1); if (c->filename) { mrb_free(mrb, c->filename); @@ -6749,14 +6754,14 @@ mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s) } MRB_API void -mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*func)(struct mrb_parser_state*), void *data) +mrb_ccontext_partial_hook(mrb_state *mrb, mrb_ccontext *c, int (*func)(struct mrb_parser_state*), void *data) { c->partial_hook = func; c->partial_data = data; } MRB_API void -mrbc_cleanup_local_variables(mrb_state *mrb, mrbc_context *c) +mrb_ccontext_cleanup_local_variables(mrb_state *mrb, mrb_ccontext *c) { if (c->syms) { mrb_free(mrb, c->syms); @@ -6808,7 +6813,7 @@ mrb_parser_get_filename(struct mrb_parser_state* p, uint16_t idx) { #ifndef MRB_NO_STDIO static struct mrb_parser_state * -mrb_parse_file_continue(mrb_state *mrb, FILE *f, const void *prebuf, size_t prebufsize, mrbc_context *c) +mrb_parse_file_continue(mrb_state *mrb, FILE *f, const void *prebuf, size_t prebufsize, mrb_ccontext *c) { parser_state *p; @@ -6828,14 +6833,14 @@ mrb_parse_file_continue(mrb_state *mrb, FILE *f, const void *prebuf, size_t preb } MRB_API parser_state* -mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c) +mrb_parse_file(mrb_state *mrb, FILE *f, mrb_ccontext *c) { return mrb_parse_file_continue(mrb, f, NULL, 0, c); } #endif MRB_API parser_state* -mrb_parse_nstring(mrb_state *mrb, const char *s, size_t len, mrbc_context *c) +mrb_parse_nstring(mrb_state *mrb, const char *s, size_t len, mrb_ccontext *c) { parser_state *p; @@ -6849,13 +6854,13 @@ mrb_parse_nstring(mrb_state *mrb, const char *s, size_t len, mrbc_context *c) } MRB_API parser_state* -mrb_parse_string(mrb_state *mrb, const char *s, mrbc_context *c) +mrb_parse_string(mrb_state *mrb, const char *s, mrb_ccontext *c) { return mrb_parse_nstring(mrb, s, strlen(s), c); } MRB_API mrb_value -mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c) +mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrb_ccontext *c) { struct RClass *target = mrb->object_class; struct RProc *proc; @@ -6918,7 +6923,7 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c) #ifndef MRB_NO_STDIO MRB_API mrb_value -mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrbc_context *c) +mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrb_ccontext *c) { return mrb_load_exec(mrb, mrb_parse_file(mrb, f, c), c); } @@ -6938,7 +6943,7 @@ mrb_load_file(mrb_state *mrb, FILE *f) * - `NUL` is included in the first 64 bytes of the file */ MRB_API mrb_value -mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c) +mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrb_ccontext *c) { union { char b[DETECT_SIZE]; @@ -6981,7 +6986,7 @@ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c) #endif MRB_API mrb_value -mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrbc_context *c) +mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrb_ccontext *c) { return mrb_load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c); } @@ -6993,7 +6998,7 @@ mrb_load_nstring(mrb_state *mrb, const char *s, size_t len) } MRB_API mrb_value -mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *c) +mrb_load_string_cxt(mrb_state *mrb, const char *s, mrb_ccontext *c) { return mrb_load_nstring_cxt(mrb, s, strlen(s), c); } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/y.tab.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/y.tab.c index 794b5cf913..7706d58f69 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/y.tab.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-compiler/core/y.tab.c @@ -203,7 +203,7 @@ cons_gen(parser_state *p, node *car, node *cdr) c->filename_index = p->current_filename_index; /* beginning of next partial file; need to point the previous file */ if (p->lineno == 0 && p->current_filename_index > 0) { - c->filename_index-- ; + c->filename_index--; } return c; } @@ -1165,8 +1165,8 @@ concat_string(parser_state *p, node *a, node *b) } else { node *c; /* last node of a */ - for (c = a; c->cdr != NULL; c = c->cdr) ; - + for (c = a; c->cdr != NULL; c = c->cdr) + ; if (string_node_p(b)) { /* a == NODE_DSTR && b == NODE_STR */ if (string_node_p(c->car)) { @@ -1550,54 +1550,54 @@ extern int yydebug; YYEOF = 0, /* "end of file" */ YYerror = 256, /* error */ YYUNDEF = 257, /* "invalid token" */ - keyword_class = 258, /* keyword_class */ - keyword_module = 259, /* keyword_module */ - keyword_def = 260, /* keyword_def */ - keyword_begin = 261, /* keyword_begin */ - keyword_if = 262, /* keyword_if */ - keyword_unless = 263, /* keyword_unless */ - keyword_while = 264, /* keyword_while */ - keyword_until = 265, /* keyword_until */ - keyword_for = 266, /* keyword_for */ - keyword_undef = 267, /* keyword_undef */ - keyword_rescue = 268, /* keyword_rescue */ - keyword_ensure = 269, /* keyword_ensure */ - keyword_end = 270, /* keyword_end */ - keyword_then = 271, /* keyword_then */ - keyword_elsif = 272, /* keyword_elsif */ - keyword_else = 273, /* keyword_else */ - keyword_case = 274, /* keyword_case */ - keyword_when = 275, /* keyword_when */ - keyword_break = 276, /* keyword_break */ - keyword_next = 277, /* keyword_next */ - keyword_redo = 278, /* keyword_redo */ - keyword_retry = 279, /* keyword_retry */ - keyword_in = 280, /* keyword_in */ - keyword_do = 281, /* keyword_do */ - keyword_do_cond = 282, /* keyword_do_cond */ - keyword_do_block = 283, /* keyword_do_block */ - keyword_do_LAMBDA = 284, /* keyword_do_LAMBDA */ - keyword_return = 285, /* keyword_return */ - keyword_yield = 286, /* keyword_yield */ - keyword_super = 287, /* keyword_super */ - keyword_self = 288, /* keyword_self */ - keyword_nil = 289, /* keyword_nil */ - keyword_true = 290, /* keyword_true */ - keyword_false = 291, /* keyword_false */ - keyword_and = 292, /* keyword_and */ - keyword_or = 293, /* keyword_or */ - keyword_not = 294, /* keyword_not */ - modifier_if = 295, /* modifier_if */ - modifier_unless = 296, /* modifier_unless */ - modifier_while = 297, /* modifier_while */ - modifier_until = 298, /* modifier_until */ - modifier_rescue = 299, /* modifier_rescue */ - keyword_alias = 300, /* keyword_alias */ - keyword_BEGIN = 301, /* keyword_BEGIN */ - keyword_END = 302, /* keyword_END */ - keyword__LINE__ = 303, /* keyword__LINE__ */ - keyword__FILE__ = 304, /* keyword__FILE__ */ - keyword__ENCODING__ = 305, /* keyword__ENCODING__ */ + keyword_class = 258, /* "'class'" */ + keyword_module = 259, /* "'module'" */ + keyword_def = 260, /* "'def'" */ + keyword_begin = 261, /* "'begin'" */ + keyword_if = 262, /* "'if'" */ + keyword_unless = 263, /* "'unless'" */ + keyword_while = 264, /* "'while'" */ + keyword_until = 265, /* "'until'" */ + keyword_for = 266, /* "'for'" */ + keyword_undef = 267, /* "'undef'" */ + keyword_rescue = 268, /* "'rescue'" */ + keyword_ensure = 269, /* "'ensure'" */ + keyword_end = 270, /* "'end'" */ + keyword_then = 271, /* "'then'" */ + keyword_elsif = 272, /* "'elsif'" */ + keyword_else = 273, /* "'else'" */ + keyword_case = 274, /* "'case'" */ + keyword_when = 275, /* "'when'" */ + keyword_break = 276, /* "'break'" */ + keyword_next = 277, /* "'next'" */ + keyword_redo = 278, /* "'redo'" */ + keyword_retry = 279, /* "'retry'" */ + keyword_in = 280, /* "'in'" */ + keyword_do = 281, /* "'do'" */ + keyword_do_cond = 282, /* "'do' for condition" */ + keyword_do_block = 283, /* "'do' for block" */ + keyword_do_LAMBDA = 284, /* "'do' for lambda" */ + keyword_return = 285, /* "'return'" */ + keyword_yield = 286, /* "'yield'" */ + keyword_super = 287, /* "'super'" */ + keyword_self = 288, /* "'self'" */ + keyword_nil = 289, /* "'nil'" */ + keyword_true = 290, /* "'true'" */ + keyword_false = 291, /* "'false'" */ + keyword_and = 292, /* "'and'" */ + keyword_or = 293, /* "'or'" */ + keyword_not = 294, /* "'not'" */ + modifier_if = 295, /* "'if' modifier" */ + modifier_unless = 296, /* "'unless' modifier" */ + modifier_while = 297, /* "'while' modifier" */ + modifier_until = 298, /* "'until' modifier" */ + modifier_rescue = 299, /* "'rescue' modifier" */ + keyword_alias = 300, /* "'alis'" */ + keyword_BEGIN = 301, /* "'BEGIN'" */ + keyword_END = 302, /* "'END'" */ + keyword__LINE__ = 303, /* "'__LINE__'" */ + keyword__FILE__ = 304, /* "'__FILE__'" */ + keyword__ENCODING__ = 305, /* "'__ENCODING__'" */ tIDENTIFIER = 306, /* "local variable or method" */ tFID = 307, /* "method" */ tGVAR = 308, /* "global variable" */ @@ -1708,54 +1708,54 @@ enum yysymbol_kind_t YYSYMBOL_YYEOF = 0, /* "end of file" */ YYSYMBOL_YYerror = 1, /* error */ YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ - YYSYMBOL_keyword_class = 3, /* keyword_class */ - YYSYMBOL_keyword_module = 4, /* keyword_module */ - YYSYMBOL_keyword_def = 5, /* keyword_def */ - YYSYMBOL_keyword_begin = 6, /* keyword_begin */ - YYSYMBOL_keyword_if = 7, /* keyword_if */ - YYSYMBOL_keyword_unless = 8, /* keyword_unless */ - YYSYMBOL_keyword_while = 9, /* keyword_while */ - YYSYMBOL_keyword_until = 10, /* keyword_until */ - YYSYMBOL_keyword_for = 11, /* keyword_for */ - YYSYMBOL_keyword_undef = 12, /* keyword_undef */ - YYSYMBOL_keyword_rescue = 13, /* keyword_rescue */ - YYSYMBOL_keyword_ensure = 14, /* keyword_ensure */ - YYSYMBOL_keyword_end = 15, /* keyword_end */ - YYSYMBOL_keyword_then = 16, /* keyword_then */ - YYSYMBOL_keyword_elsif = 17, /* keyword_elsif */ - YYSYMBOL_keyword_else = 18, /* keyword_else */ - YYSYMBOL_keyword_case = 19, /* keyword_case */ - YYSYMBOL_keyword_when = 20, /* keyword_when */ - YYSYMBOL_keyword_break = 21, /* keyword_break */ - YYSYMBOL_keyword_next = 22, /* keyword_next */ - YYSYMBOL_keyword_redo = 23, /* keyword_redo */ - YYSYMBOL_keyword_retry = 24, /* keyword_retry */ - YYSYMBOL_keyword_in = 25, /* keyword_in */ - YYSYMBOL_keyword_do = 26, /* keyword_do */ - YYSYMBOL_keyword_do_cond = 27, /* keyword_do_cond */ - YYSYMBOL_keyword_do_block = 28, /* keyword_do_block */ - YYSYMBOL_keyword_do_LAMBDA = 29, /* keyword_do_LAMBDA */ - YYSYMBOL_keyword_return = 30, /* keyword_return */ - YYSYMBOL_keyword_yield = 31, /* keyword_yield */ - YYSYMBOL_keyword_super = 32, /* keyword_super */ - YYSYMBOL_keyword_self = 33, /* keyword_self */ - YYSYMBOL_keyword_nil = 34, /* keyword_nil */ - YYSYMBOL_keyword_true = 35, /* keyword_true */ - YYSYMBOL_keyword_false = 36, /* keyword_false */ - YYSYMBOL_keyword_and = 37, /* keyword_and */ - YYSYMBOL_keyword_or = 38, /* keyword_or */ - YYSYMBOL_keyword_not = 39, /* keyword_not */ - YYSYMBOL_modifier_if = 40, /* modifier_if */ - YYSYMBOL_modifier_unless = 41, /* modifier_unless */ - YYSYMBOL_modifier_while = 42, /* modifier_while */ - YYSYMBOL_modifier_until = 43, /* modifier_until */ - YYSYMBOL_modifier_rescue = 44, /* modifier_rescue */ - YYSYMBOL_keyword_alias = 45, /* keyword_alias */ - YYSYMBOL_keyword_BEGIN = 46, /* keyword_BEGIN */ - YYSYMBOL_keyword_END = 47, /* keyword_END */ - YYSYMBOL_keyword__LINE__ = 48, /* keyword__LINE__ */ - YYSYMBOL_keyword__FILE__ = 49, /* keyword__FILE__ */ - YYSYMBOL_keyword__ENCODING__ = 50, /* keyword__ENCODING__ */ + YYSYMBOL_keyword_class = 3, /* "'class'" */ + YYSYMBOL_keyword_module = 4, /* "'module'" */ + YYSYMBOL_keyword_def = 5, /* "'def'" */ + YYSYMBOL_keyword_begin = 6, /* "'begin'" */ + YYSYMBOL_keyword_if = 7, /* "'if'" */ + YYSYMBOL_keyword_unless = 8, /* "'unless'" */ + YYSYMBOL_keyword_while = 9, /* "'while'" */ + YYSYMBOL_keyword_until = 10, /* "'until'" */ + YYSYMBOL_keyword_for = 11, /* "'for'" */ + YYSYMBOL_keyword_undef = 12, /* "'undef'" */ + YYSYMBOL_keyword_rescue = 13, /* "'rescue'" */ + YYSYMBOL_keyword_ensure = 14, /* "'ensure'" */ + YYSYMBOL_keyword_end = 15, /* "'end'" */ + YYSYMBOL_keyword_then = 16, /* "'then'" */ + YYSYMBOL_keyword_elsif = 17, /* "'elsif'" */ + YYSYMBOL_keyword_else = 18, /* "'else'" */ + YYSYMBOL_keyword_case = 19, /* "'case'" */ + YYSYMBOL_keyword_when = 20, /* "'when'" */ + YYSYMBOL_keyword_break = 21, /* "'break'" */ + YYSYMBOL_keyword_next = 22, /* "'next'" */ + YYSYMBOL_keyword_redo = 23, /* "'redo'" */ + YYSYMBOL_keyword_retry = 24, /* "'retry'" */ + YYSYMBOL_keyword_in = 25, /* "'in'" */ + YYSYMBOL_keyword_do = 26, /* "'do'" */ + YYSYMBOL_keyword_do_cond = 27, /* "'do' for condition" */ + YYSYMBOL_keyword_do_block = 28, /* "'do' for block" */ + YYSYMBOL_keyword_do_LAMBDA = 29, /* "'do' for lambda" */ + YYSYMBOL_keyword_return = 30, /* "'return'" */ + YYSYMBOL_keyword_yield = 31, /* "'yield'" */ + YYSYMBOL_keyword_super = 32, /* "'super'" */ + YYSYMBOL_keyword_self = 33, /* "'self'" */ + YYSYMBOL_keyword_nil = 34, /* "'nil'" */ + YYSYMBOL_keyword_true = 35, /* "'true'" */ + YYSYMBOL_keyword_false = 36, /* "'false'" */ + YYSYMBOL_keyword_and = 37, /* "'and'" */ + YYSYMBOL_keyword_or = 38, /* "'or'" */ + YYSYMBOL_keyword_not = 39, /* "'not'" */ + YYSYMBOL_modifier_if = 40, /* "'if' modifier" */ + YYSYMBOL_modifier_unless = 41, /* "'unless' modifier" */ + YYSYMBOL_modifier_while = 42, /* "'while' modifier" */ + YYSYMBOL_modifier_until = 43, /* "'until' modifier" */ + YYSYMBOL_modifier_rescue = 44, /* "'rescue' modifier" */ + YYSYMBOL_keyword_alias = 45, /* "'alis'" */ + YYSYMBOL_keyword_BEGIN = 46, /* "'BEGIN'" */ + YYSYMBOL_keyword_END = 47, /* "'END'" */ + YYSYMBOL_keyword__LINE__ = 48, /* "'__LINE__'" */ + YYSYMBOL_keyword__FILE__ = 49, /* "'__FILE__'" */ + YYSYMBOL_keyword__ENCODING__ = 50, /* "'__ENCODING__'" */ YYSYMBOL_tIDENTIFIER = 51, /* "local variable or method" */ YYSYMBOL_tFID = 52, /* "method" */ YYSYMBOL_tGVAR = 53, /* "global variable" */ @@ -1945,7 +1945,7 @@ enum yysymbol_kind_t YYSYMBOL_f_larglist = 237, /* f_larglist */ YYSYMBOL_lambda_body = 238, /* lambda_body */ YYSYMBOL_do_block = 239, /* do_block */ - YYSYMBOL_240_26 = 240, /* $@26 */ + YYSYMBOL_240_26 = 240, /* @26 */ YYSYMBOL_block_call = 241, /* block_call */ YYSYMBOL_method_call = 242, /* method_call */ YYSYMBOL_brace_block = 243, /* brace_block */ @@ -2467,28 +2467,28 @@ static const yytype_int16 yyrline[] = 3037, 3042, 3046, 3050, 3054, 3058, 3062, 3066, 3070, 3074, 3078, 3082, 3086, 3090, 3094, 3098, 3104, 3109, 3116, 3116, 3120, 3125, 3132, 3136, 3142, 3143, 3146, 3151, 3154, 3158, - 3164, 3168, 3175, 3174, 3189, 3199, 3203, 3208, 3215, 3219, - 3223, 3227, 3231, 3235, 3239, 3243, 3247, 3254, 3253, 3268, - 3267, 3283, 3291, 3300, 3303, 3310, 3313, 3317, 3318, 3321, - 3325, 3328, 3332, 3335, 3336, 3337, 3338, 3341, 3342, 3348, - 3349, 3350, 3354, 3367, 3368, 3374, 3379, 3378, 3388, 3392, - 3398, 3402, 3415, 3419, 3425, 3428, 3429, 3432, 3438, 3444, - 3445, 3448, 3455, 3454, 3467, 3471, 3485, 3490, 3504, 3510, - 3511, 3512, 3513, 3514, 3518, 3524, 3528, 3538, 3539, 3540, - 3544, 3550, 3554, 3558, 3562, 3566, 3572, 3576, 3582, 3586, - 3590, 3594, 3598, 3602, 3610, 3617, 3623, 3624, 3628, 3632, - 3631, 3648, 3649, 3652, 3658, 3662, 3668, 3669, 3673, 3677, - 3683, 3687, 3693, 3699, 3706, 3712, 3719, 3723, 3729, 3733, - 3739, 3740, 3743, 3747, 3753, 3757, 3761, 3765, 3771, 3776, - 3781, 3785, 3789, 3793, 3797, 3801, 3805, 3809, 3813, 3817, - 3821, 3825, 3829, 3833, 3838, 3844, 3849, 3854, 3859, 3864, - 3871, 3875, 3882, 3887, 3886, 3898, 3902, 3908, 3916, 3924, - 3932, 3936, 3942, 3946, 3952, 3953, 3956, 3961, 3968, 3969, - 3972, 3976, 3982, 3986, 3992, 3997, 3997, 4022, 4023, 4029, - 4034, 4040, 4046, 4051, 4055, 4060, 4065, 4075, 4080, 4086, - 4087, 4088, 4091, 4092, 4093, 4094, 4097, 4098, 4099, 4102, - 4103, 4106, 4110, 4116, 4117, 4123, 4124, 4127, 4128, 4131, - 4134, 4135, 4136, 4139, 4140, 4143, 4148, 4151, 4152, 4156 + 3164, 3168, 3175, 3174, 3191, 3201, 3205, 3210, 3217, 3221, + 3225, 3229, 3233, 3237, 3241, 3245, 3249, 3256, 3255, 3270, + 3269, 3285, 3293, 3302, 3305, 3312, 3315, 3319, 3320, 3323, + 3327, 3330, 3334, 3337, 3338, 3339, 3340, 3343, 3344, 3350, + 3351, 3352, 3356, 3369, 3370, 3376, 3381, 3380, 3390, 3394, + 3400, 3404, 3417, 3421, 3427, 3430, 3431, 3434, 3440, 3446, + 3447, 3450, 3457, 3456, 3469, 3473, 3487, 3492, 3506, 3512, + 3513, 3514, 3515, 3516, 3520, 3526, 3530, 3540, 3541, 3542, + 3546, 3552, 3556, 3560, 3564, 3568, 3574, 3578, 3584, 3588, + 3592, 3596, 3600, 3604, 3612, 3619, 3625, 3626, 3630, 3634, + 3633, 3650, 3651, 3654, 3660, 3664, 3670, 3671, 3675, 3679, + 3685, 3689, 3695, 3701, 3708, 3714, 3721, 3725, 3731, 3735, + 3741, 3742, 3745, 3749, 3755, 3759, 3763, 3767, 3773, 3778, + 3783, 3787, 3791, 3795, 3799, 3803, 3807, 3811, 3815, 3819, + 3823, 3827, 3831, 3835, 3840, 3846, 3851, 3856, 3861, 3866, + 3873, 3877, 3884, 3889, 3888, 3900, 3904, 3910, 3918, 3926, + 3934, 3938, 3944, 3948, 3954, 3955, 3958, 3963, 3970, 3971, + 3974, 3978, 3984, 3988, 3994, 3999, 3999, 4024, 4025, 4031, + 4036, 4042, 4048, 4053, 4057, 4062, 4067, 4077, 4082, 4088, + 4089, 4090, 4093, 4094, 4095, 4096, 4099, 4100, 4101, 4104, + 4105, 4108, 4112, 4118, 4119, 4125, 4126, 4129, 4130, 4133, + 4136, 4137, 4138, 4141, 4142, 4145, 4150, 4153, 4154, 4158 }; #endif @@ -2504,68 +2504,67 @@ static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "\"end of file\"", "error", "\"invalid token\"", "keyword_class", - "keyword_module", "keyword_def", "keyword_begin", "keyword_if", - "keyword_unless", "keyword_while", "keyword_until", "keyword_for", - "keyword_undef", "keyword_rescue", "keyword_ensure", "keyword_end", - "keyword_then", "keyword_elsif", "keyword_else", "keyword_case", - "keyword_when", "keyword_break", "keyword_next", "keyword_redo", - "keyword_retry", "keyword_in", "keyword_do", "keyword_do_cond", - "keyword_do_block", "keyword_do_LAMBDA", "keyword_return", - "keyword_yield", "keyword_super", "keyword_self", "keyword_nil", - "keyword_true", "keyword_false", "keyword_and", "keyword_or", - "keyword_not", "modifier_if", "modifier_unless", "modifier_while", - "modifier_until", "modifier_rescue", "keyword_alias", "keyword_BEGIN", - "keyword_END", "keyword__LINE__", "keyword__FILE__", - "keyword__ENCODING__", "\"local variable or method\"", "\"method\"", - "\"global variable\"", "\"instance variable\"", "\"constant\"", - "\"class variable\"", "\"label\"", "\"integer literal\"", - "\"float literal\"", "\"character literal\"", "tXSTRING", "tREGEXP", - "tSTRING", "tSTRING_PART", "tSTRING_MID", "tNTH_REF", "tBACK_REF", - "tREGEXP_END", "\"numbered parameter\"", "\"unary plus\"", - "\"unary minus\"", "\"<=>\"", "\"==\"", "\"===\"", "\"!=\"", "\">=\"", - "\"<=\"", "\"&&\"", "\"||\"", "\"=~\"", "\"!~\"", "\"..\"", "\"...\"", - "tBDOT2", "tBDOT3", "tAREF", "tASET", "\"<<\"", "\">>\"", "\"::\"", - "tCOLON3", "tOP_ASGN", "\"=>\"", "tLPAREN", "\"(\"", "\")\"", "\"[\"", - "tLBRACE", "\"{\"", "\"*\"", "tPOW", "\"**\"", "\"&\"", "\"->\"", - "\"&.\"", "\"symbol\"", "\"string literal\"", "tXSTRING_BEG", - "tSTRING_DVAR", "tREGEXP_BEG", "tWORDS_BEG", "tSYMBOLS_BEG", "tLAMBEG", - "\"here document\"", "tHEREDOC_END", "tLITERAL_DELIM", - "tHD_LITERAL_DELIM", "tHD_STRING_PART", "tHD_STRING_MID", "tLOWEST", - "'='", "'?'", "':'", "'>'", "'<'", "'|'", "'^'", "'&'", "'+'", "'-'", - "'*'", "'/'", "'%'", "tUMINUS_NUM", "'!'", "'~'", "tLAST_TOKEN", "'{'", - "'}'", "'['", "']'", "','", "'`'", "'('", "')'", "';'", "'.'", "'\\n'", - "$accept", "program", "$@1", "top_compstmt", "top_stmts", "top_stmt", - "@2", "bodystmt", "compstmt", "stmts", "stmt", "$@3", "command_asgn", - "command_rhs", "expr", "defn_head", "defs_head", "$@4", "expr_value", - "command_call", "block_command", "cmd_brace_block", "$@5", "command", - "mlhs", "mlhs_inner", "mlhs_basic", "mlhs_item", "mlhs_list", - "mlhs_post", "mlhs_node", "lhs", "cname", "cpath", "fname", "fsym", - "undef_list", "$@6", "op", "reswords", "arg", "aref_args", "arg_rhs", - "paren_args", "opt_paren_args", "opt_call_args", "call_args", - "command_args", "@7", "block_arg", "opt_block_arg", "comma", "args", - "mrhs", "primary", "@8", "@9", "$@10", "$@11", "@12", "@13", "$@14", - "$@15", "$@16", "$@17", "$@18", "$@19", "@20", "@21", "@22", "@23", - "primary_value", "then", "do", "if_tail", "opt_else", "for_var", - "f_margs", "$@24", "block_args_tail", "opt_block_args_tail", - "block_param", "opt_block_param", "block_param_def", "$@25", - "opt_bv_decl", "bv_decls", "bvar", "f_larglist", "lambda_body", - "do_block", "$@26", "block_call", "method_call", "brace_block", "@27", - "@28", "case_body", "cases", "opt_rescue", "exc_list", "exc_var", - "opt_ensure", "literal", "string", "string_fragment", "string_rep", - "string_interp", "@29", "xstring", "regexp", "heredoc", "heredoc_bodies", - "heredoc_body", "heredoc_string_rep", "heredoc_string_interp", "@30", - "words", "symbol", "basic_symbol", "sym", "symbols", "numeric", - "variable", "var_lhs", "var_ref", "backref", "superclass", "$@31", - "f_opt_arglist_paren", "f_arglist_paren", "f_arglist", "f_label", "f_kw", - "f_block_kw", "f_block_kwarg", "f_kwarg", "kwrest_mark", "f_kwrest", - "args_tail", "opt_args_tail", "f_args", "f_bad_arg", "f_norm_arg", - "f_arg_item", "@32", "f_arg", "f_opt_asgn", "f_opt", "f_block_opt", - "f_block_optarg", "f_optarg", "restarg_mark", "f_rest_arg", - "blkarg_mark", "f_block_arg", "opt_f_block_arg", "singleton", "$@33", - "assoc_list", "assocs", "assoc", "operation", "operation2", "operation3", - "dot_or_colon", "call_op", "call_op2", "opt_terms", "opt_nl", "rparen", - "trailer", "term", "nl", "terms", "none", YY_NULLPTR + "\"end of file\"", "error", "\"invalid token\"", "\"'class'\"", + "\"'module'\"", "\"'def'\"", "\"'begin'\"", "\"'if'\"", "\"'unless'\"", + "\"'while'\"", "\"'until'\"", "\"'for'\"", "\"'undef'\"", "\"'rescue'\"", + "\"'ensure'\"", "\"'end'\"", "\"'then'\"", "\"'elsif'\"", "\"'else'\"", + "\"'case'\"", "\"'when'\"", "\"'break'\"", "\"'next'\"", "\"'redo'\"", + "\"'retry'\"", "\"'in'\"", "\"'do'\"", "\"'do' for condition\"", + "\"'do' for block\"", "\"'do' for lambda\"", "\"'return'\"", + "\"'yield'\"", "\"'super'\"", "\"'self'\"", "\"'nil'\"", "\"'true'\"", + "\"'false'\"", "\"'and'\"", "\"'or'\"", "\"'not'\"", "\"'if' modifier\"", + "\"'unless' modifier\"", "\"'while' modifier\"", "\"'until' modifier\"", + "\"'rescue' modifier\"", "\"'alis'\"", "\"'BEGIN'\"", "\"'END'\"", + "\"'__LINE__'\"", "\"'__FILE__'\"", "\"'__ENCODING__'\"", + "\"local variable or method\"", "\"method\"", "\"global variable\"", + "\"instance variable\"", "\"constant\"", "\"class variable\"", + "\"label\"", "\"integer literal\"", "\"float literal\"", + "\"character literal\"", "tXSTRING", "tREGEXP", "tSTRING", + "tSTRING_PART", "tSTRING_MID", "tNTH_REF", "tBACK_REF", "tREGEXP_END", + "\"numbered parameter\"", "\"unary plus\"", "\"unary minus\"", "\"<=>\"", + "\"==\"", "\"===\"", "\"!=\"", "\">=\"", "\"<=\"", "\"&&\"", "\"||\"", + "\"=~\"", "\"!~\"", "\"..\"", "\"...\"", "tBDOT2", "tBDOT3", "tAREF", + "tASET", "\"<<\"", "\">>\"", "\"::\"", "tCOLON3", "tOP_ASGN", "\"=>\"", + "tLPAREN", "\"(\"", "\")\"", "\"[\"", "tLBRACE", "\"{\"", "\"*\"", + "tPOW", "\"**\"", "\"&\"", "\"->\"", "\"&.\"", "\"symbol\"", + "\"string literal\"", "tXSTRING_BEG", "tSTRING_DVAR", "tREGEXP_BEG", + "tWORDS_BEG", "tSYMBOLS_BEG", "tLAMBEG", "\"here document\"", + "tHEREDOC_END", "tLITERAL_DELIM", "tHD_LITERAL_DELIM", "tHD_STRING_PART", + "tHD_STRING_MID", "tLOWEST", "'='", "'?'", "':'", "'>'", "'<'", "'|'", + "'^'", "'&'", "'+'", "'-'", "'*'", "'/'", "'%'", "tUMINUS_NUM", "'!'", + "'~'", "tLAST_TOKEN", "'{'", "'}'", "'['", "']'", "','", "'`'", "'('", + "')'", "';'", "'.'", "'\\n'", "$accept", "program", "$@1", + "top_compstmt", "top_stmts", "top_stmt", "@2", "bodystmt", "compstmt", + "stmts", "stmt", "$@3", "command_asgn", "command_rhs", "expr", + "defn_head", "defs_head", "$@4", "expr_value", "command_call", + "block_command", "cmd_brace_block", "$@5", "command", "mlhs", + "mlhs_inner", "mlhs_basic", "mlhs_item", "mlhs_list", "mlhs_post", + "mlhs_node", "lhs", "cname", "cpath", "fname", "fsym", "undef_list", + "$@6", "op", "reswords", "arg", "aref_args", "arg_rhs", "paren_args", + "opt_paren_args", "opt_call_args", "call_args", "command_args", "@7", + "block_arg", "opt_block_arg", "comma", "args", "mrhs", "primary", "@8", + "@9", "$@10", "$@11", "@12", "@13", "$@14", "$@15", "$@16", "$@17", + "$@18", "$@19", "@20", "@21", "@22", "@23", "primary_value", "then", + "do", "if_tail", "opt_else", "for_var", "f_margs", "$@24", + "block_args_tail", "opt_block_args_tail", "block_param", + "opt_block_param", "block_param_def", "$@25", "opt_bv_decl", "bv_decls", + "bvar", "f_larglist", "lambda_body", "do_block", "@26", "block_call", + "method_call", "brace_block", "@27", "@28", "case_body", "cases", + "opt_rescue", "exc_list", "exc_var", "opt_ensure", "literal", "string", + "string_fragment", "string_rep", "string_interp", "@29", "xstring", + "regexp", "heredoc", "heredoc_bodies", "heredoc_body", + "heredoc_string_rep", "heredoc_string_interp", "@30", "words", "symbol", + "basic_symbol", "sym", "symbols", "numeric", "variable", "var_lhs", + "var_ref", "backref", "superclass", "$@31", "f_opt_arglist_paren", + "f_arglist_paren", "f_arglist", "f_label", "f_kw", "f_block_kw", + "f_block_kwarg", "f_kwarg", "kwrest_mark", "f_kwrest", "args_tail", + "opt_args_tail", "f_args", "f_bad_arg", "f_norm_arg", "f_arg_item", + "@32", "f_arg", "f_opt_asgn", "f_opt", "f_block_opt", "f_block_optarg", + "f_optarg", "restarg_mark", "f_rest_arg", "blkarg_mark", "f_block_arg", + "opt_f_block_arg", "singleton", "$@33", "assoc_list", "assocs", "assoc", + "operation", "operation2", "operation3", "dot_or_colon", "call_op", + "call_op2", "opt_terms", "opt_nl", "rparen", "trailer", "term", "nl", + "terms", "none", YY_NULLPTR }; static const char * @@ -6486,7 +6485,7 @@ yyreduce: p->lstate = EXPR_BEG; if (!p->locals) p->locals = cons(0,0); } -#line 6490 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6489 "mrbgems/mruby-compiler/core/y.tab.c" break; case 3: /* program: $@1 top_compstmt */ @@ -6495,7 +6494,7 @@ yyreduce: p->tree = new_scope(p, (yyvsp[0].nd)); NODE_LINENO(p->tree, (yyvsp[0].nd)); } -#line 6499 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6498 "mrbgems/mruby-compiler/core/y.tab.c" break; case 4: /* top_compstmt: top_stmts opt_terms */ @@ -6503,7 +6502,7 @@ yyreduce: { (yyval.nd) = (yyvsp[-1].nd); } -#line 6507 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6506 "mrbgems/mruby-compiler/core/y.tab.c" break; case 5: /* top_stmts: none */ @@ -6511,7 +6510,7 @@ yyreduce: { (yyval.nd) = new_begin(p, 0); } -#line 6515 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6514 "mrbgems/mruby-compiler/core/y.tab.c" break; case 6: /* top_stmts: top_stmt */ @@ -6520,7 +6519,7 @@ yyreduce: (yyval.nd) = new_begin(p, (yyvsp[0].nd)); NODE_LINENO((yyval.nd), (yyvsp[0].nd)); } -#line 6524 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6523 "mrbgems/mruby-compiler/core/y.tab.c" break; case 7: /* top_stmts: top_stmts terms top_stmt */ @@ -6528,7 +6527,7 @@ yyreduce: { (yyval.nd) = push((yyvsp[-2].nd), newline_node((yyvsp[0].nd))); } -#line 6532 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6531 "mrbgems/mruby-compiler/core/y.tab.c" break; case 8: /* top_stmts: error top_stmt */ @@ -6536,7 +6535,7 @@ yyreduce: { (yyval.nd) = new_begin(p, 0); } -#line 6540 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6539 "mrbgems/mruby-compiler/core/y.tab.c" break; case 10: /* @2: %empty */ @@ -6545,10 +6544,10 @@ yyreduce: (yyval.nd) = local_switch(p); nvars_block(p); } -#line 6549 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6548 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 11: /* top_stmt: keyword_BEGIN @2 '{' top_compstmt '}' */ + case 11: /* top_stmt: "'BEGIN'" @2 '{' top_compstmt '}' */ #line 1668 "mrbgems/mruby-compiler/core/parse.y" { yyerror(p, "BEGIN not supported"); @@ -6556,7 +6555,7 @@ yyreduce: nvars_unnest(p); (yyval.nd) = 0; } -#line 6560 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6559 "mrbgems/mruby-compiler/core/y.tab.c" break; case 12: /* bodystmt: compstmt opt_rescue opt_else opt_ensure */ @@ -6582,7 +6581,7 @@ yyreduce: } } } -#line 6586 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6585 "mrbgems/mruby-compiler/core/y.tab.c" break; case 13: /* compstmt: stmts opt_terms */ @@ -6590,7 +6589,7 @@ yyreduce: { (yyval.nd) = (yyvsp[-1].nd); } -#line 6594 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6593 "mrbgems/mruby-compiler/core/y.tab.c" break; case 14: /* stmts: none */ @@ -6598,7 +6597,7 @@ yyreduce: { (yyval.nd) = new_begin(p, 0); } -#line 6602 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6601 "mrbgems/mruby-compiler/core/y.tab.c" break; case 15: /* stmts: stmt */ @@ -6607,7 +6606,7 @@ yyreduce: (yyval.nd) = new_begin(p, (yyvsp[0].nd)); NODE_LINENO((yyval.nd), (yyvsp[0].nd)); } -#line 6611 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6610 "mrbgems/mruby-compiler/core/y.tab.c" break; case 16: /* stmts: stmts terms stmt */ @@ -6615,7 +6614,7 @@ yyreduce: { (yyval.nd) = push((yyvsp[-2].nd), newline_node((yyvsp[0].nd))); } -#line 6619 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6618 "mrbgems/mruby-compiler/core/y.tab.c" break; case 17: /* stmts: error stmt */ @@ -6623,78 +6622,78 @@ yyreduce: { (yyval.nd) = new_begin(p, (yyvsp[0].nd)); } -#line 6627 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6626 "mrbgems/mruby-compiler/core/y.tab.c" break; case 18: /* $@3: %empty */ #line 1728 "mrbgems/mruby-compiler/core/parse.y" {p->lstate = EXPR_FNAME;} -#line 6633 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6632 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 19: /* stmt: keyword_alias fsym $@3 fsym */ + case 19: /* stmt: "'alis'" fsym $@3 fsym */ #line 1729 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_alias(p, (yyvsp[-2].id), (yyvsp[0].id)); } -#line 6641 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6640 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 20: /* stmt: keyword_undef undef_list */ + case 20: /* stmt: "'undef'" undef_list */ #line 1733 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); } -#line 6649 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6648 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 21: /* stmt: stmt modifier_if expr_value */ + case 21: /* stmt: stmt "'if' modifier" expr_value */ #line 1737 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_if(p, cond((yyvsp[0].nd)), (yyvsp[-2].nd), 0); } -#line 6657 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6656 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 22: /* stmt: stmt modifier_unless expr_value */ + case 22: /* stmt: stmt "'unless' modifier" expr_value */ #line 1741 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_unless(p, cond((yyvsp[0].nd)), (yyvsp[-2].nd), 0); } -#line 6665 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6664 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 23: /* stmt: stmt modifier_while expr_value */ + case 23: /* stmt: stmt "'while' modifier" expr_value */ #line 1745 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_while(p, cond((yyvsp[0].nd)), (yyvsp[-2].nd)); } -#line 6673 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6672 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 24: /* stmt: stmt modifier_until expr_value */ + case 24: /* stmt: stmt "'until' modifier" expr_value */ #line 1749 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_until(p, cond((yyvsp[0].nd)), (yyvsp[-2].nd)); } -#line 6681 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6680 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 25: /* stmt: stmt modifier_rescue stmt */ + case 25: /* stmt: stmt "'rescue' modifier" stmt */ #line 1753 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_mod_rescue(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 6689 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6688 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 26: /* stmt: keyword_END '{' compstmt '}' */ + case 26: /* stmt: "'END'" '{' compstmt '}' */ #line 1757 "mrbgems/mruby-compiler/core/parse.y" { yyerror(p, "END not supported"); (yyval.nd) = new_postexe(p, (yyvsp[-1].nd)); } -#line 6698 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6697 "mrbgems/mruby-compiler/core/y.tab.c" break; case 28: /* stmt: mlhs '=' command_call */ @@ -6702,7 +6701,7 @@ yyreduce: { (yyval.nd) = new_masgn(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 6706 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6705 "mrbgems/mruby-compiler/core/y.tab.c" break; case 29: /* stmt: lhs '=' mrhs */ @@ -6710,7 +6709,7 @@ yyreduce: { (yyval.nd) = new_asgn(p, (yyvsp[-2].nd), new_array(p, (yyvsp[0].nd))); } -#line 6714 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6713 "mrbgems/mruby-compiler/core/y.tab.c" break; case 30: /* stmt: mlhs '=' arg */ @@ -6718,7 +6717,7 @@ yyreduce: { (yyval.nd) = new_masgn(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 6722 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6721 "mrbgems/mruby-compiler/core/y.tab.c" break; case 31: /* stmt: mlhs '=' mrhs */ @@ -6726,7 +6725,7 @@ yyreduce: { (yyval.nd) = new_masgn(p, (yyvsp[-2].nd), new_array(p, (yyvsp[0].nd))); } -#line 6730 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6729 "mrbgems/mruby-compiler/core/y.tab.c" break; case 32: /* stmt: arg "=>" "local variable or method" */ @@ -6736,7 +6735,7 @@ yyreduce: assignable(p, lhs); (yyval.nd) = new_asgn(p, lhs, (yyvsp[-2].nd)); } -#line 6740 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6739 "mrbgems/mruby-compiler/core/y.tab.c" break; case 34: /* command_asgn: lhs '=' command_rhs */ @@ -6744,7 +6743,7 @@ yyreduce: { (yyval.nd) = new_asgn(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 6748 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6747 "mrbgems/mruby-compiler/core/y.tab.c" break; case 35: /* command_asgn: var_lhs tOP_ASGN command_rhs */ @@ -6752,7 +6751,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, (yyvsp[-2].nd), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 6756 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6755 "mrbgems/mruby-compiler/core/y.tab.c" break; case 36: /* command_asgn: primary_value '[' opt_call_args ']' tOP_ASGN command_rhs */ @@ -6760,7 +6759,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, new_call(p, (yyvsp[-5].nd), intern_op(aref), (yyvsp[-3].nd), '.'), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 6764 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6763 "mrbgems/mruby-compiler/core/y.tab.c" break; case 37: /* command_asgn: primary_value call_op "local variable or method" tOP_ASGN command_rhs */ @@ -6768,7 +6767,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), 0, (yyvsp[-3].num)), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 6772 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6771 "mrbgems/mruby-compiler/core/y.tab.c" break; case 38: /* command_asgn: primary_value call_op "constant" tOP_ASGN command_rhs */ @@ -6776,7 +6775,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), 0, (yyvsp[-3].num)), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 6780 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6779 "mrbgems/mruby-compiler/core/y.tab.c" break; case 39: /* command_asgn: primary_value "::" "constant" tOP_ASGN command_call */ @@ -6785,7 +6784,7 @@ yyreduce: yyerror(p, "constant re-assignment"); (yyval.nd) = 0; } -#line 6789 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6788 "mrbgems/mruby-compiler/core/y.tab.c" break; case 40: /* command_asgn: primary_value "::" "local variable or method" tOP_ASGN command_rhs */ @@ -6793,7 +6792,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), 0, tCOLON2), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 6797 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6796 "mrbgems/mruby-compiler/core/y.tab.c" break; case 41: /* command_asgn: defn_head f_opt_arglist_paren '=' command */ @@ -6806,10 +6805,10 @@ yyreduce: nvars_unnest(p); p->in_def--; } -#line 6810 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6809 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 42: /* command_asgn: defn_head f_opt_arglist_paren '=' command modifier_rescue arg */ + case 42: /* command_asgn: defn_head f_opt_arglist_paren '=' command "'rescue' modifier" arg */ #line 1826 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-5].nd); @@ -6819,7 +6818,7 @@ yyreduce: nvars_unnest(p); p->in_def--; } -#line 6823 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6822 "mrbgems/mruby-compiler/core/y.tab.c" break; case 43: /* command_asgn: defs_head f_opt_arglist_paren '=' command */ @@ -6832,10 +6831,10 @@ yyreduce: p->in_def--; p->in_single--; } -#line 6836 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6835 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 44: /* command_asgn: defs_head f_opt_arglist_paren '=' command modifier_rescue arg */ + case 44: /* command_asgn: defs_head f_opt_arglist_paren '=' command "'rescue' modifier" arg */ #line 1844 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-5].nd); @@ -6845,7 +6844,7 @@ yyreduce: p->in_def--; p->in_single--; } -#line 6849 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6848 "mrbgems/mruby-compiler/core/y.tab.c" break; case 45: /* command_asgn: backref tOP_ASGN command_rhs */ @@ -6854,39 +6853,39 @@ yyreduce: backref_error(p, (yyvsp[-2].nd)); (yyval.nd) = new_begin(p, 0); } -#line 6858 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6857 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 47: /* command_rhs: command_call modifier_rescue stmt */ + case 47: /* command_rhs: command_call "'rescue' modifier" stmt */ #line 1861 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_mod_rescue(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 6866 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6865 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 50: /* expr: expr keyword_and expr */ + case 50: /* expr: expr "'and'" expr */ #line 1870 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_and(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 6874 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6873 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 51: /* expr: expr keyword_or expr */ + case 51: /* expr: expr "'or'" expr */ #line 1874 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_or(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 6882 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6881 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 52: /* expr: keyword_not opt_nl expr */ + case 52: /* expr: "'not'" opt_nl expr */ #line 1878 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = call_uni_op(p, cond((yyvsp[0].nd)), "!"); } -#line 6890 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6889 "mrbgems/mruby-compiler/core/y.tab.c" break; case 53: /* expr: '!' command_call */ @@ -6894,10 +6893,10 @@ yyreduce: { (yyval.nd) = call_uni_op(p, cond((yyvsp[0].nd)), "!"); } -#line 6898 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6897 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 55: /* defn_head: keyword_def fname */ + case 55: /* defn_head: "'def'" fname */ #line 1890 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_def(p, (yyvsp[0].id), nint(p->cmdarg_stack), local_switch(p)); @@ -6905,7 +6904,7 @@ yyreduce: p->in_def++; nvars_block(p); } -#line 6909 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6908 "mrbgems/mruby-compiler/core/y.tab.c" break; case 56: /* $@4: %empty */ @@ -6913,10 +6912,10 @@ yyreduce: { p->lstate = EXPR_FNAME; } -#line 6917 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6916 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 57: /* defs_head: keyword_def singleton dot_or_colon $@4 fname */ + case 57: /* defs_head: "'def'" singleton dot_or_colon $@4 fname */ #line 1903 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_sdef(p, (yyvsp[-3].nd), (yyvsp[0].id), nint(p->cmdarg_stack), local_switch(p)); @@ -6926,7 +6925,7 @@ yyreduce: nvars_block(p); p->lstate = EXPR_ENDFN; /* force for args */ } -#line 6930 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6929 "mrbgems/mruby-compiler/core/y.tab.c" break; case 58: /* expr_value: expr */ @@ -6937,7 +6936,7 @@ yyreduce: (yyval.nd) = (yyvsp[0].nd); } } -#line 6941 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6940 "mrbgems/mruby-compiler/core/y.tab.c" break; case 62: /* block_command: block_call call_op2 operation2 command_args */ @@ -6945,7 +6944,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-3].nd), (yyvsp[-1].id), (yyvsp[0].nd), (yyvsp[-2].num)); } -#line 6949 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6948 "mrbgems/mruby-compiler/core/y.tab.c" break; case 63: /* $@5: %empty */ @@ -6954,7 +6953,7 @@ yyreduce: local_nest(p); nvars_nest(p); } -#line 6958 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6957 "mrbgems/mruby-compiler/core/y.tab.c" break; case 64: /* cmd_brace_block: "{" $@5 opt_block_param compstmt '}' */ @@ -6964,7 +6963,7 @@ yyreduce: local_unnest(p); nvars_unnest(p); } -#line 6968 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6967 "mrbgems/mruby-compiler/core/y.tab.c" break; case 65: /* command: operation command_args */ @@ -6972,7 +6971,7 @@ yyreduce: { (yyval.nd) = new_fcall(p, (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 6976 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6975 "mrbgems/mruby-compiler/core/y.tab.c" break; case 66: /* command: operation command_args cmd_brace_block */ @@ -6981,7 +6980,7 @@ yyreduce: args_with_block(p, (yyvsp[-1].nd), (yyvsp[0].nd)); (yyval.nd) = new_fcall(p, (yyvsp[-2].id), (yyvsp[-1].nd)); } -#line 6985 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6984 "mrbgems/mruby-compiler/core/y.tab.c" break; case 67: /* command: primary_value call_op operation2 command_args */ @@ -6989,7 +6988,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-3].nd), (yyvsp[-1].id), (yyvsp[0].nd), (yyvsp[-2].num)); } -#line 6993 "mrbgems/mruby-compiler/core/y.tab.c" +#line 6992 "mrbgems/mruby-compiler/core/y.tab.c" break; case 68: /* command: primary_value call_op operation2 command_args cmd_brace_block */ @@ -6998,7 +6997,7 @@ yyreduce: args_with_block(p, (yyvsp[-1].nd), (yyvsp[0].nd)); (yyval.nd) = new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), (yyvsp[-1].nd), (yyvsp[-3].num)); } -#line 7002 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7001 "mrbgems/mruby-compiler/core/y.tab.c" break; case 69: /* command: primary_value "::" operation2 command_args */ @@ -7006,7 +7005,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-3].nd), (yyvsp[-1].id), (yyvsp[0].nd), tCOLON2); } -#line 7010 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7009 "mrbgems/mruby-compiler/core/y.tab.c" break; case 70: /* command: primary_value "::" operation2 command_args cmd_brace_block */ @@ -7015,47 +7014,47 @@ yyreduce: args_with_block(p, (yyvsp[-1].nd), (yyvsp[0].nd)); (yyval.nd) = new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), (yyvsp[-1].nd), tCOLON2); } -#line 7019 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7018 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 71: /* command: keyword_super command_args */ + case 71: /* command: "'super'" command_args */ #line 1976 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_super(p, (yyvsp[0].nd)); } -#line 7027 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7026 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 72: /* command: keyword_yield command_args */ + case 72: /* command: "'yield'" command_args */ #line 1980 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_yield(p, (yyvsp[0].nd)); } -#line 7035 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7034 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 73: /* command: keyword_return call_args */ + case 73: /* command: "'return'" call_args */ #line 1984 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_return(p, ret_args(p, (yyvsp[0].nd))); } -#line 7043 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7042 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 74: /* command: keyword_break call_args */ + case 74: /* command: "'break'" call_args */ #line 1988 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_break(p, ret_args(p, (yyvsp[0].nd))); } -#line 7051 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7050 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 75: /* command: keyword_next call_args */ + case 75: /* command: "'next'" call_args */ #line 1992 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_next(p, ret_args(p, (yyvsp[0].nd))); } -#line 7059 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7058 "mrbgems/mruby-compiler/core/y.tab.c" break; case 76: /* mlhs: mlhs_basic */ @@ -7063,7 +7062,7 @@ yyreduce: { (yyval.nd) = (yyvsp[0].nd); } -#line 7067 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7066 "mrbgems/mruby-compiler/core/y.tab.c" break; case 77: /* mlhs: tLPAREN mlhs_inner rparen */ @@ -7071,7 +7070,7 @@ yyreduce: { (yyval.nd) = (yyvsp[-1].nd); } -#line 7075 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7074 "mrbgems/mruby-compiler/core/y.tab.c" break; case 79: /* mlhs_inner: tLPAREN mlhs_inner rparen */ @@ -7079,7 +7078,7 @@ yyreduce: { (yyval.nd) = (yyvsp[-1].nd); } -#line 7083 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7082 "mrbgems/mruby-compiler/core/y.tab.c" break; case 80: /* mlhs_basic: mlhs_list */ @@ -7087,7 +7086,7 @@ yyreduce: { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 7091 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7090 "mrbgems/mruby-compiler/core/y.tab.c" break; case 81: /* mlhs_basic: mlhs_list mlhs_item */ @@ -7095,7 +7094,7 @@ yyreduce: { (yyval.nd) = list1(push((yyvsp[-1].nd),(yyvsp[0].nd))); } -#line 7099 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7098 "mrbgems/mruby-compiler/core/y.tab.c" break; case 82: /* mlhs_basic: mlhs_list "*" mlhs_node */ @@ -7103,7 +7102,7 @@ yyreduce: { (yyval.nd) = list2((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 7107 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7106 "mrbgems/mruby-compiler/core/y.tab.c" break; case 83: /* mlhs_basic: mlhs_list "*" mlhs_node ',' mlhs_post */ @@ -7111,7 +7110,7 @@ yyreduce: { (yyval.nd) = list3((yyvsp[-4].nd), (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 7115 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7114 "mrbgems/mruby-compiler/core/y.tab.c" break; case 84: /* mlhs_basic: mlhs_list "*" */ @@ -7119,7 +7118,7 @@ yyreduce: { (yyval.nd) = list2((yyvsp[-1].nd), new_nil(p)); } -#line 7123 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7122 "mrbgems/mruby-compiler/core/y.tab.c" break; case 85: /* mlhs_basic: mlhs_list "*" ',' mlhs_post */ @@ -7127,7 +7126,7 @@ yyreduce: { (yyval.nd) = list3((yyvsp[-3].nd), new_nil(p), (yyvsp[0].nd)); } -#line 7131 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7130 "mrbgems/mruby-compiler/core/y.tab.c" break; case 86: /* mlhs_basic: "*" mlhs_node */ @@ -7135,7 +7134,7 @@ yyreduce: { (yyval.nd) = list2(0, (yyvsp[0].nd)); } -#line 7139 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7138 "mrbgems/mruby-compiler/core/y.tab.c" break; case 87: /* mlhs_basic: "*" mlhs_node ',' mlhs_post */ @@ -7143,7 +7142,7 @@ yyreduce: { (yyval.nd) = list3(0, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 7147 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7146 "mrbgems/mruby-compiler/core/y.tab.c" break; case 88: /* mlhs_basic: "*" */ @@ -7151,7 +7150,7 @@ yyreduce: { (yyval.nd) = list2(0, new_nil(p)); } -#line 7155 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7154 "mrbgems/mruby-compiler/core/y.tab.c" break; case 89: /* mlhs_basic: "*" ',' mlhs_post */ @@ -7159,7 +7158,7 @@ yyreduce: { (yyval.nd) = list3(0, new_nil(p), (yyvsp[0].nd)); } -#line 7163 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7162 "mrbgems/mruby-compiler/core/y.tab.c" break; case 91: /* mlhs_item: tLPAREN mlhs_inner rparen */ @@ -7167,7 +7166,7 @@ yyreduce: { (yyval.nd) = new_masgn(p, (yyvsp[-1].nd), NULL); } -#line 7171 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7170 "mrbgems/mruby-compiler/core/y.tab.c" break; case 92: /* mlhs_list: mlhs_item ',' */ @@ -7175,7 +7174,7 @@ yyreduce: { (yyval.nd) = list1((yyvsp[-1].nd)); } -#line 7179 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7178 "mrbgems/mruby-compiler/core/y.tab.c" break; case 93: /* mlhs_list: mlhs_list mlhs_item ',' */ @@ -7183,7 +7182,7 @@ yyreduce: { (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[-1].nd)); } -#line 7187 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7186 "mrbgems/mruby-compiler/core/y.tab.c" break; case 94: /* mlhs_post: mlhs_item */ @@ -7191,7 +7190,7 @@ yyreduce: { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 7195 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7194 "mrbgems/mruby-compiler/core/y.tab.c" break; case 95: /* mlhs_post: mlhs_list mlhs_item */ @@ -7199,7 +7198,7 @@ yyreduce: { (yyval.nd) = push((yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 7203 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7202 "mrbgems/mruby-compiler/core/y.tab.c" break; case 96: /* mlhs_node: variable */ @@ -7207,7 +7206,7 @@ yyreduce: { assignable(p, (yyvsp[0].nd)); } -#line 7211 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7210 "mrbgems/mruby-compiler/core/y.tab.c" break; case 97: /* mlhs_node: primary_value '[' opt_call_args ']' */ @@ -7215,7 +7214,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-3].nd), intern_op(aref), (yyvsp[-1].nd), '.'); } -#line 7219 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7218 "mrbgems/mruby-compiler/core/y.tab.c" break; case 98: /* mlhs_node: primary_value call_op "local variable or method" */ @@ -7223,7 +7222,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-2].nd), (yyvsp[0].id), 0, (yyvsp[-1].num)); } -#line 7227 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7226 "mrbgems/mruby-compiler/core/y.tab.c" break; case 99: /* mlhs_node: primary_value "::" "local variable or method" */ @@ -7231,7 +7230,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-2].nd), (yyvsp[0].id), 0, tCOLON2); } -#line 7235 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7234 "mrbgems/mruby-compiler/core/y.tab.c" break; case 100: /* mlhs_node: primary_value call_op "constant" */ @@ -7239,7 +7238,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-2].nd), (yyvsp[0].id), 0, (yyvsp[-1].num)); } -#line 7243 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7242 "mrbgems/mruby-compiler/core/y.tab.c" break; case 101: /* mlhs_node: primary_value "::" "constant" */ @@ -7249,7 +7248,7 @@ yyreduce: yyerror(p, "dynamic constant assignment"); (yyval.nd) = new_colon2(p, (yyvsp[-2].nd), (yyvsp[0].id)); } -#line 7253 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7252 "mrbgems/mruby-compiler/core/y.tab.c" break; case 102: /* mlhs_node: tCOLON3 "constant" */ @@ -7259,7 +7258,7 @@ yyreduce: yyerror(p, "dynamic constant assignment"); (yyval.nd) = new_colon3(p, (yyvsp[0].id)); } -#line 7263 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7262 "mrbgems/mruby-compiler/core/y.tab.c" break; case 103: /* mlhs_node: backref */ @@ -7268,7 +7267,7 @@ yyreduce: backref_error(p, (yyvsp[0].nd)); (yyval.nd) = 0; } -#line 7272 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7271 "mrbgems/mruby-compiler/core/y.tab.c" break; case 104: /* lhs: variable */ @@ -7276,7 +7275,7 @@ yyreduce: { assignable(p, (yyvsp[0].nd)); } -#line 7280 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7279 "mrbgems/mruby-compiler/core/y.tab.c" break; case 105: /* lhs: primary_value '[' opt_call_args ']' */ @@ -7284,7 +7283,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-3].nd), intern_op(aref), (yyvsp[-1].nd), '.'); } -#line 7288 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7287 "mrbgems/mruby-compiler/core/y.tab.c" break; case 106: /* lhs: primary_value call_op "local variable or method" */ @@ -7292,7 +7291,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-2].nd), (yyvsp[0].id), 0, (yyvsp[-1].num)); } -#line 7296 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7295 "mrbgems/mruby-compiler/core/y.tab.c" break; case 107: /* lhs: primary_value "::" "local variable or method" */ @@ -7300,7 +7299,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-2].nd), (yyvsp[0].id), 0, tCOLON2); } -#line 7304 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7303 "mrbgems/mruby-compiler/core/y.tab.c" break; case 108: /* lhs: primary_value call_op "constant" */ @@ -7308,7 +7307,7 @@ yyreduce: { (yyval.nd) = new_call(p, (yyvsp[-2].nd), (yyvsp[0].id), 0, (yyvsp[-1].num)); } -#line 7312 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7311 "mrbgems/mruby-compiler/core/y.tab.c" break; case 109: /* lhs: primary_value "::" "constant" */ @@ -7318,7 +7317,7 @@ yyreduce: yyerror(p, "dynamic constant assignment"); (yyval.nd) = new_colon2(p, (yyvsp[-2].nd), (yyvsp[0].id)); } -#line 7322 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7321 "mrbgems/mruby-compiler/core/y.tab.c" break; case 110: /* lhs: tCOLON3 "constant" */ @@ -7328,7 +7327,7 @@ yyreduce: yyerror(p, "dynamic constant assignment"); (yyval.nd) = new_colon3(p, (yyvsp[0].id)); } -#line 7332 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7331 "mrbgems/mruby-compiler/core/y.tab.c" break; case 111: /* lhs: backref */ @@ -7337,7 +7336,7 @@ yyreduce: backref_error(p, (yyvsp[0].nd)); (yyval.nd) = 0; } -#line 7341 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7340 "mrbgems/mruby-compiler/core/y.tab.c" break; case 112: /* lhs: "numbered parameter" */ @@ -7345,7 +7344,7 @@ yyreduce: { yyerror(p, "can't assign to numbered parameter"); } -#line 7349 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7348 "mrbgems/mruby-compiler/core/y.tab.c" break; case 113: /* cname: "local variable or method" */ @@ -7353,7 +7352,7 @@ yyreduce: { yyerror(p, "class/module name must be CONSTANT"); } -#line 7357 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7356 "mrbgems/mruby-compiler/core/y.tab.c" break; case 115: /* cpath: tCOLON3 cname */ @@ -7361,7 +7360,7 @@ yyreduce: { (yyval.nd) = cons(nint(1), nsym((yyvsp[0].id))); } -#line 7365 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7364 "mrbgems/mruby-compiler/core/y.tab.c" break; case 116: /* cpath: cname */ @@ -7369,7 +7368,7 @@ yyreduce: { (yyval.nd) = cons(nint(0), nsym((yyvsp[0].id))); } -#line 7373 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7372 "mrbgems/mruby-compiler/core/y.tab.c" break; case 117: /* cpath: primary_value "::" cname */ @@ -7378,7 +7377,7 @@ yyreduce: void_expr_error(p, (yyvsp[-2].nd)); (yyval.nd) = cons((yyvsp[-2].nd), nsym((yyvsp[0].id))); } -#line 7382 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7381 "mrbgems/mruby-compiler/core/y.tab.c" break; case 121: /* fname: op */ @@ -7387,7 +7386,7 @@ yyreduce: p->lstate = EXPR_ENDFN; (yyval.id) = (yyvsp[0].id); } -#line 7391 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7390 "mrbgems/mruby-compiler/core/y.tab.c" break; case 122: /* fname: reswords */ @@ -7396,7 +7395,7 @@ yyreduce: p->lstate = EXPR_ENDFN; (yyval.id) = (yyvsp[0].id); } -#line 7400 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7399 "mrbgems/mruby-compiler/core/y.tab.c" break; case 125: /* undef_list: fsym */ @@ -7404,13 +7403,13 @@ yyreduce: { (yyval.nd) = new_undef(p, (yyvsp[0].id)); } -#line 7408 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7407 "mrbgems/mruby-compiler/core/y.tab.c" break; case 126: /* $@6: %empty */ #line 2210 "mrbgems/mruby-compiler/core/parse.y" {p->lstate = EXPR_FNAME;} -#line 7414 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7413 "mrbgems/mruby-compiler/core/y.tab.c" break; case 127: /* undef_list: undef_list ',' $@6 fsym */ @@ -7418,187 +7417,187 @@ yyreduce: { (yyval.nd) = push((yyvsp[-3].nd), nsym((yyvsp[0].id))); } -#line 7422 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7421 "mrbgems/mruby-compiler/core/y.tab.c" break; case 128: /* op: '|' */ #line 2216 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(or); } -#line 7428 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7427 "mrbgems/mruby-compiler/core/y.tab.c" break; case 129: /* op: '^' */ #line 2217 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(xor); } -#line 7434 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7433 "mrbgems/mruby-compiler/core/y.tab.c" break; case 130: /* op: '&' */ #line 2218 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(and); } -#line 7440 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7439 "mrbgems/mruby-compiler/core/y.tab.c" break; case 131: /* op: "<=>" */ #line 2219 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(cmp); } -#line 7446 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7445 "mrbgems/mruby-compiler/core/y.tab.c" break; case 132: /* op: "==" */ #line 2220 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(eq); } -#line 7452 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7451 "mrbgems/mruby-compiler/core/y.tab.c" break; case 133: /* op: "===" */ #line 2221 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(eqq); } -#line 7458 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7457 "mrbgems/mruby-compiler/core/y.tab.c" break; case 134: /* op: "=~" */ #line 2222 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(match); } -#line 7464 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7463 "mrbgems/mruby-compiler/core/y.tab.c" break; case 135: /* op: "!~" */ #line 2223 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(nmatch); } -#line 7470 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7469 "mrbgems/mruby-compiler/core/y.tab.c" break; case 136: /* op: '>' */ #line 2224 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(gt); } -#line 7476 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7475 "mrbgems/mruby-compiler/core/y.tab.c" break; case 137: /* op: ">=" */ #line 2225 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(ge); } -#line 7482 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7481 "mrbgems/mruby-compiler/core/y.tab.c" break; case 138: /* op: '<' */ #line 2226 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(lt); } -#line 7488 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7487 "mrbgems/mruby-compiler/core/y.tab.c" break; case 139: /* op: "<=" */ #line 2227 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(le); } -#line 7494 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7493 "mrbgems/mruby-compiler/core/y.tab.c" break; case 140: /* op: "!=" */ #line 2228 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(neq); } -#line 7500 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7499 "mrbgems/mruby-compiler/core/y.tab.c" break; case 141: /* op: "<<" */ #line 2229 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(lshift); } -#line 7506 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7505 "mrbgems/mruby-compiler/core/y.tab.c" break; case 142: /* op: ">>" */ #line 2230 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(rshift); } -#line 7512 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7511 "mrbgems/mruby-compiler/core/y.tab.c" break; case 143: /* op: '+' */ #line 2231 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(add); } -#line 7518 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7517 "mrbgems/mruby-compiler/core/y.tab.c" break; case 144: /* op: '-' */ #line 2232 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(sub); } -#line 7524 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7523 "mrbgems/mruby-compiler/core/y.tab.c" break; case 145: /* op: '*' */ #line 2233 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(mul); } -#line 7530 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7529 "mrbgems/mruby-compiler/core/y.tab.c" break; case 146: /* op: "*" */ #line 2234 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(mul); } -#line 7536 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7535 "mrbgems/mruby-compiler/core/y.tab.c" break; case 147: /* op: '/' */ #line 2235 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(div); } -#line 7542 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7541 "mrbgems/mruby-compiler/core/y.tab.c" break; case 148: /* op: '%' */ #line 2236 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(mod); } -#line 7548 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7547 "mrbgems/mruby-compiler/core/y.tab.c" break; case 149: /* op: tPOW */ #line 2237 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(pow); } -#line 7554 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7553 "mrbgems/mruby-compiler/core/y.tab.c" break; case 150: /* op: "**" */ #line 2238 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(pow); } -#line 7560 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7559 "mrbgems/mruby-compiler/core/y.tab.c" break; case 151: /* op: '!' */ #line 2239 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(not); } -#line 7566 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7565 "mrbgems/mruby-compiler/core/y.tab.c" break; case 152: /* op: '~' */ #line 2240 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(neg); } -#line 7572 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7571 "mrbgems/mruby-compiler/core/y.tab.c" break; case 153: /* op: "unary plus" */ #line 2241 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(plus); } -#line 7578 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7577 "mrbgems/mruby-compiler/core/y.tab.c" break; case 154: /* op: "unary minus" */ #line 2242 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(minus); } -#line 7584 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7583 "mrbgems/mruby-compiler/core/y.tab.c" break; case 155: /* op: tAREF */ #line 2243 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(aref); } -#line 7590 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7589 "mrbgems/mruby-compiler/core/y.tab.c" break; case 156: /* op: tASET */ #line 2244 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(aset); } -#line 7596 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7595 "mrbgems/mruby-compiler/core/y.tab.c" break; case 157: /* op: '`' */ #line 2245 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(tick); } -#line 7602 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7601 "mrbgems/mruby-compiler/core/y.tab.c" break; case 198: /* arg: lhs '=' arg_rhs */ @@ -7606,7 +7605,7 @@ yyreduce: { (yyval.nd) = new_asgn(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 7610 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7609 "mrbgems/mruby-compiler/core/y.tab.c" break; case 199: /* arg: var_lhs tOP_ASGN arg_rhs */ @@ -7614,7 +7613,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, (yyvsp[-2].nd), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 7618 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7617 "mrbgems/mruby-compiler/core/y.tab.c" break; case 200: /* arg: primary_value '[' opt_call_args ']' tOP_ASGN arg_rhs */ @@ -7622,7 +7621,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, new_call(p, (yyvsp[-5].nd), intern_op(aref), (yyvsp[-3].nd), '.'), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 7626 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7625 "mrbgems/mruby-compiler/core/y.tab.c" break; case 201: /* arg: primary_value call_op "local variable or method" tOP_ASGN arg_rhs */ @@ -7630,7 +7629,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), 0, (yyvsp[-3].num)), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 7634 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7633 "mrbgems/mruby-compiler/core/y.tab.c" break; case 202: /* arg: primary_value call_op "constant" tOP_ASGN arg_rhs */ @@ -7638,7 +7637,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), 0, (yyvsp[-3].num)), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 7642 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7641 "mrbgems/mruby-compiler/core/y.tab.c" break; case 203: /* arg: primary_value "::" "local variable or method" tOP_ASGN arg_rhs */ @@ -7646,7 +7645,7 @@ yyreduce: { (yyval.nd) = new_op_asgn(p, new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), 0, tCOLON2), (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 7650 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7649 "mrbgems/mruby-compiler/core/y.tab.c" break; case 204: /* arg: primary_value "::" "constant" tOP_ASGN arg_rhs */ @@ -7655,7 +7654,7 @@ yyreduce: yyerror(p, "constant re-assignment"); (yyval.nd) = new_begin(p, 0); } -#line 7659 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7658 "mrbgems/mruby-compiler/core/y.tab.c" break; case 205: /* arg: tCOLON3 "constant" tOP_ASGN arg_rhs */ @@ -7664,7 +7663,7 @@ yyreduce: yyerror(p, "constant re-assignment"); (yyval.nd) = new_begin(p, 0); } -#line 7668 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7667 "mrbgems/mruby-compiler/core/y.tab.c" break; case 206: /* arg: backref tOP_ASGN arg_rhs */ @@ -7673,7 +7672,7 @@ yyreduce: backref_error(p, (yyvsp[-2].nd)); (yyval.nd) = new_begin(p, 0); } -#line 7677 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7676 "mrbgems/mruby-compiler/core/y.tab.c" break; case 207: /* arg: arg ".." arg */ @@ -7681,7 +7680,7 @@ yyreduce: { (yyval.nd) = new_dot2(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 7685 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7684 "mrbgems/mruby-compiler/core/y.tab.c" break; case 208: /* arg: arg ".." */ @@ -7689,7 +7688,7 @@ yyreduce: { (yyval.nd) = new_dot2(p, (yyvsp[-1].nd), new_nil(p)); } -#line 7693 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7692 "mrbgems/mruby-compiler/core/y.tab.c" break; case 209: /* arg: tBDOT2 arg */ @@ -7697,7 +7696,7 @@ yyreduce: { (yyval.nd) = new_dot2(p, new_nil(p), (yyvsp[0].nd)); } -#line 7701 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7700 "mrbgems/mruby-compiler/core/y.tab.c" break; case 210: /* arg: arg "..." arg */ @@ -7705,7 +7704,7 @@ yyreduce: { (yyval.nd) = new_dot3(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 7709 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7708 "mrbgems/mruby-compiler/core/y.tab.c" break; case 211: /* arg: arg "..." */ @@ -7713,7 +7712,7 @@ yyreduce: { (yyval.nd) = new_dot3(p, (yyvsp[-1].nd), new_nil(p)); } -#line 7717 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7716 "mrbgems/mruby-compiler/core/y.tab.c" break; case 212: /* arg: tBDOT3 arg */ @@ -7721,7 +7720,7 @@ yyreduce: { (yyval.nd) = new_dot3(p, new_nil(p), (yyvsp[0].nd)); } -#line 7725 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7724 "mrbgems/mruby-compiler/core/y.tab.c" break; case 213: /* arg: arg '+' arg */ @@ -7729,7 +7728,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "+", (yyvsp[0].nd)); } -#line 7733 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7732 "mrbgems/mruby-compiler/core/y.tab.c" break; case 214: /* arg: arg '-' arg */ @@ -7737,7 +7736,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "-", (yyvsp[0].nd)); } -#line 7741 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7740 "mrbgems/mruby-compiler/core/y.tab.c" break; case 215: /* arg: arg '*' arg */ @@ -7745,7 +7744,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "*", (yyvsp[0].nd)); } -#line 7749 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7748 "mrbgems/mruby-compiler/core/y.tab.c" break; case 216: /* arg: arg '/' arg */ @@ -7753,7 +7752,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "/", (yyvsp[0].nd)); } -#line 7757 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7756 "mrbgems/mruby-compiler/core/y.tab.c" break; case 217: /* arg: arg '%' arg */ @@ -7761,7 +7760,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "%", (yyvsp[0].nd)); } -#line 7765 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7764 "mrbgems/mruby-compiler/core/y.tab.c" break; case 218: /* arg: arg tPOW arg */ @@ -7769,7 +7768,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "**", (yyvsp[0].nd)); } -#line 7773 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7772 "mrbgems/mruby-compiler/core/y.tab.c" break; case 219: /* arg: tUMINUS_NUM "integer literal" tPOW arg */ @@ -7777,7 +7776,7 @@ yyreduce: { (yyval.nd) = new_negate(p, call_bin_op(p, (yyvsp[-2].nd), "**", (yyvsp[0].nd))); } -#line 7781 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7780 "mrbgems/mruby-compiler/core/y.tab.c" break; case 220: /* arg: tUMINUS_NUM "float literal" tPOW arg */ @@ -7785,7 +7784,7 @@ yyreduce: { (yyval.nd) = new_negate(p, call_bin_op(p, (yyvsp[-2].nd), "**", (yyvsp[0].nd))); } -#line 7789 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7788 "mrbgems/mruby-compiler/core/y.tab.c" break; case 221: /* arg: "unary plus" arg */ @@ -7793,7 +7792,7 @@ yyreduce: { (yyval.nd) = call_uni_op(p, (yyvsp[0].nd), "+@"); } -#line 7797 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7796 "mrbgems/mruby-compiler/core/y.tab.c" break; case 222: /* arg: "unary minus" arg */ @@ -7801,7 +7800,7 @@ yyreduce: { (yyval.nd) = new_negate(p, (yyvsp[0].nd)); } -#line 7805 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7804 "mrbgems/mruby-compiler/core/y.tab.c" break; case 223: /* arg: arg '|' arg */ @@ -7809,7 +7808,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "|", (yyvsp[0].nd)); } -#line 7813 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7812 "mrbgems/mruby-compiler/core/y.tab.c" break; case 224: /* arg: arg '^' arg */ @@ -7817,7 +7816,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "^", (yyvsp[0].nd)); } -#line 7821 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7820 "mrbgems/mruby-compiler/core/y.tab.c" break; case 225: /* arg: arg '&' arg */ @@ -7825,7 +7824,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "&", (yyvsp[0].nd)); } -#line 7829 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7828 "mrbgems/mruby-compiler/core/y.tab.c" break; case 226: /* arg: arg "<=>" arg */ @@ -7833,7 +7832,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "<=>", (yyvsp[0].nd)); } -#line 7837 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7836 "mrbgems/mruby-compiler/core/y.tab.c" break; case 227: /* arg: arg '>' arg */ @@ -7841,7 +7840,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), ">", (yyvsp[0].nd)); } -#line 7845 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7844 "mrbgems/mruby-compiler/core/y.tab.c" break; case 228: /* arg: arg ">=" arg */ @@ -7849,7 +7848,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), ">=", (yyvsp[0].nd)); } -#line 7853 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7852 "mrbgems/mruby-compiler/core/y.tab.c" break; case 229: /* arg: arg '<' arg */ @@ -7857,7 +7856,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "<", (yyvsp[0].nd)); } -#line 7861 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7860 "mrbgems/mruby-compiler/core/y.tab.c" break; case 230: /* arg: arg "<=" arg */ @@ -7865,7 +7864,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "<=", (yyvsp[0].nd)); } -#line 7869 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7868 "mrbgems/mruby-compiler/core/y.tab.c" break; case 231: /* arg: arg "==" arg */ @@ -7873,7 +7872,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "==", (yyvsp[0].nd)); } -#line 7877 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7876 "mrbgems/mruby-compiler/core/y.tab.c" break; case 232: /* arg: arg "===" arg */ @@ -7881,7 +7880,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "===", (yyvsp[0].nd)); } -#line 7885 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7884 "mrbgems/mruby-compiler/core/y.tab.c" break; case 233: /* arg: arg "!=" arg */ @@ -7889,7 +7888,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "!=", (yyvsp[0].nd)); } -#line 7893 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7892 "mrbgems/mruby-compiler/core/y.tab.c" break; case 234: /* arg: arg "=~" arg */ @@ -7897,7 +7896,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "=~", (yyvsp[0].nd)); } -#line 7901 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7900 "mrbgems/mruby-compiler/core/y.tab.c" break; case 235: /* arg: arg "!~" arg */ @@ -7905,7 +7904,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "!~", (yyvsp[0].nd)); } -#line 7909 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7908 "mrbgems/mruby-compiler/core/y.tab.c" break; case 236: /* arg: '!' arg */ @@ -7913,7 +7912,7 @@ yyreduce: { (yyval.nd) = call_uni_op(p, cond((yyvsp[0].nd)), "!"); } -#line 7917 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7916 "mrbgems/mruby-compiler/core/y.tab.c" break; case 237: /* arg: '~' arg */ @@ -7921,7 +7920,7 @@ yyreduce: { (yyval.nd) = call_uni_op(p, cond((yyvsp[0].nd)), "~"); } -#line 7925 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7924 "mrbgems/mruby-compiler/core/y.tab.c" break; case 238: /* arg: arg "<<" arg */ @@ -7929,7 +7928,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), "<<", (yyvsp[0].nd)); } -#line 7933 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7932 "mrbgems/mruby-compiler/core/y.tab.c" break; case 239: /* arg: arg ">>" arg */ @@ -7937,7 +7936,7 @@ yyreduce: { (yyval.nd) = call_bin_op(p, (yyvsp[-2].nd), ">>", (yyvsp[0].nd)); } -#line 7941 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7940 "mrbgems/mruby-compiler/core/y.tab.c" break; case 240: /* arg: arg "&&" arg */ @@ -7945,7 +7944,7 @@ yyreduce: { (yyval.nd) = new_and(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 7949 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7948 "mrbgems/mruby-compiler/core/y.tab.c" break; case 241: /* arg: arg "||" arg */ @@ -7953,7 +7952,7 @@ yyreduce: { (yyval.nd) = new_or(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 7957 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7956 "mrbgems/mruby-compiler/core/y.tab.c" break; case 242: /* arg: arg '?' arg opt_nl ':' arg */ @@ -7961,7 +7960,7 @@ yyreduce: { (yyval.nd) = new_if(p, cond((yyvsp[-5].nd)), (yyvsp[-3].nd), (yyvsp[0].nd)); } -#line 7965 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7964 "mrbgems/mruby-compiler/core/y.tab.c" break; case 243: /* arg: arg '?' arg opt_nl "label" arg */ @@ -7969,7 +7968,7 @@ yyreduce: { (yyval.nd) = new_if(p, cond((yyvsp[-5].nd)), (yyvsp[-3].nd), (yyvsp[0].nd)); } -#line 7973 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7972 "mrbgems/mruby-compiler/core/y.tab.c" break; case 244: /* arg: defn_head f_opt_arglist_paren '=' arg */ @@ -7982,10 +7981,10 @@ yyreduce: nvars_unnest(p); p->in_def--; } -#line 7986 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7985 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 245: /* arg: defn_head f_opt_arglist_paren '=' arg modifier_rescue arg */ + case 245: /* arg: defn_head f_opt_arglist_paren '=' arg "'rescue' modifier" arg */ #line 2459 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-5].nd); @@ -7995,7 +7994,7 @@ yyreduce: nvars_unnest(p); p->in_def--; } -#line 7999 "mrbgems/mruby-compiler/core/y.tab.c" +#line 7998 "mrbgems/mruby-compiler/core/y.tab.c" break; case 246: /* arg: defs_head f_opt_arglist_paren '=' arg */ @@ -8008,10 +8007,10 @@ yyreduce: p->in_def--; p->in_single--; } -#line 8012 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8011 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 247: /* arg: defs_head f_opt_arglist_paren '=' arg modifier_rescue arg */ + case 247: /* arg: defs_head f_opt_arglist_paren '=' arg "'rescue' modifier" arg */ #line 2477 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-5].nd); @@ -8021,7 +8020,7 @@ yyreduce: p->in_def--; p->in_single--; } -#line 8025 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8024 "mrbgems/mruby-compiler/core/y.tab.c" break; case 248: /* arg: primary */ @@ -8029,7 +8028,7 @@ yyreduce: { (yyval.nd) = (yyvsp[0].nd); } -#line 8033 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8032 "mrbgems/mruby-compiler/core/y.tab.c" break; case 250: /* aref_args: args trailer */ @@ -8038,7 +8037,7 @@ yyreduce: (yyval.nd) = (yyvsp[-1].nd); NODE_LINENO((yyval.nd), (yyvsp[-1].nd)); } -#line 8042 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8041 "mrbgems/mruby-compiler/core/y.tab.c" break; case 251: /* aref_args: args comma assocs trailer */ @@ -8046,7 +8045,7 @@ yyreduce: { (yyval.nd) = push((yyvsp[-3].nd), new_hash(p, (yyvsp[-1].nd))); } -#line 8050 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8049 "mrbgems/mruby-compiler/core/y.tab.c" break; case 252: /* aref_args: assocs trailer */ @@ -8055,7 +8054,7 @@ yyreduce: (yyval.nd) = cons(new_kw_hash(p, (yyvsp[-1].nd)), 0); NODE_LINENO((yyval.nd), (yyvsp[-1].nd)); } -#line 8059 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8058 "mrbgems/mruby-compiler/core/y.tab.c" break; case 253: /* arg_rhs: arg */ @@ -8063,16 +8062,16 @@ yyreduce: { (yyval.nd) = (yyvsp[0].nd); } -#line 8067 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8066 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 254: /* arg_rhs: arg modifier_rescue arg */ + case 254: /* arg_rhs: arg "'rescue' modifier" arg */ #line 2513 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[-2].nd)); (yyval.nd) = new_mod_rescue(p, (yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 8076 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8075 "mrbgems/mruby-compiler/core/y.tab.c" break; case 255: /* paren_args: '(' opt_call_args ')' */ @@ -8080,7 +8079,7 @@ yyreduce: { (yyval.nd) = (yyvsp[-1].nd); } -#line 8084 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8083 "mrbgems/mruby-compiler/core/y.tab.c" break; case 256: /* paren_args: '(' args comma tBDOT3 rparen */ @@ -8093,7 +8092,7 @@ yyreduce: new_kw_hash(p, list1(cons(new_kw_rest_args(p, 0), new_lvar(p, k)))), new_block_arg(p, new_lvar(p, b))); } -#line 8097 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8096 "mrbgems/mruby-compiler/core/y.tab.c" break; case 257: /* paren_args: '(' tBDOT3 rparen */ @@ -8112,7 +8111,7 @@ yyreduce: (yyval.nd) = 0; } } -#line 8116 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8115 "mrbgems/mruby-compiler/core/y.tab.c" break; case 262: /* opt_call_args: args comma */ @@ -8121,7 +8120,7 @@ yyreduce: (yyval.nd) = new_callargs(p,(yyvsp[-1].nd),0,0); NODE_LINENO((yyval.nd), (yyvsp[-1].nd)); } -#line 8125 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8124 "mrbgems/mruby-compiler/core/y.tab.c" break; case 263: /* opt_call_args: args comma assocs comma */ @@ -8130,7 +8129,7 @@ yyreduce: (yyval.nd) = new_callargs(p,(yyvsp[-3].nd),new_kw_hash(p,(yyvsp[-1].nd)),0); NODE_LINENO((yyval.nd), (yyvsp[-3].nd)); } -#line 8134 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8133 "mrbgems/mruby-compiler/core/y.tab.c" break; case 264: /* opt_call_args: assocs comma */ @@ -8139,7 +8138,7 @@ yyreduce: (yyval.nd) = new_callargs(p,0,new_kw_hash(p,(yyvsp[-1].nd)),0); NODE_LINENO((yyval.nd), (yyvsp[-1].nd)); } -#line 8143 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8142 "mrbgems/mruby-compiler/core/y.tab.c" break; case 265: /* call_args: command */ @@ -8149,7 +8148,7 @@ yyreduce: (yyval.nd) = new_callargs(p, list1((yyvsp[0].nd)), 0, 0); NODE_LINENO((yyval.nd), (yyvsp[0].nd)); } -#line 8153 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8152 "mrbgems/mruby-compiler/core/y.tab.c" break; case 266: /* call_args: args opt_block_arg */ @@ -8158,7 +8157,7 @@ yyreduce: (yyval.nd) = new_callargs(p, (yyvsp[-1].nd), 0, (yyvsp[0].nd)); NODE_LINENO((yyval.nd), (yyvsp[-1].nd)); } -#line 8162 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8161 "mrbgems/mruby-compiler/core/y.tab.c" break; case 267: /* call_args: assocs opt_block_arg */ @@ -8167,7 +8166,7 @@ yyreduce: (yyval.nd) = new_callargs(p, 0, new_kw_hash(p, (yyvsp[-1].nd)), (yyvsp[0].nd)); NODE_LINENO((yyval.nd), (yyvsp[-1].nd)); } -#line 8171 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8170 "mrbgems/mruby-compiler/core/y.tab.c" break; case 268: /* call_args: args comma assocs opt_block_arg */ @@ -8176,7 +8175,7 @@ yyreduce: (yyval.nd) = new_callargs(p, (yyvsp[-3].nd), new_kw_hash(p, (yyvsp[-1].nd)), (yyvsp[0].nd)); NODE_LINENO((yyval.nd), (yyvsp[-3].nd)); } -#line 8180 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8179 "mrbgems/mruby-compiler/core/y.tab.c" break; case 269: /* call_args: block_arg */ @@ -8185,7 +8184,7 @@ yyreduce: (yyval.nd) = new_callargs(p, 0, 0, (yyvsp[0].nd)); NODE_LINENO((yyval.nd), (yyvsp[0].nd)); } -#line 8189 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8188 "mrbgems/mruby-compiler/core/y.tab.c" break; case 270: /* @7: %empty */ @@ -8194,7 +8193,7 @@ yyreduce: (yyval.stack) = p->cmdarg_stack; CMDARG_PUSH(1); } -#line 8198 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8197 "mrbgems/mruby-compiler/core/y.tab.c" break; case 271: /* command_args: @7 call_args */ @@ -8203,7 +8202,7 @@ yyreduce: p->cmdarg_stack = (yyvsp[-1].stack); (yyval.nd) = (yyvsp[0].nd); } -#line 8207 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8206 "mrbgems/mruby-compiler/core/y.tab.c" break; case 272: /* block_arg: "&" arg */ @@ -8211,7 +8210,7 @@ yyreduce: { (yyval.nd) = new_block_arg(p, (yyvsp[0].nd)); } -#line 8215 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8214 "mrbgems/mruby-compiler/core/y.tab.c" break; case 273: /* block_arg: "&" */ @@ -8219,7 +8218,7 @@ yyreduce: { (yyval.nd) = new_block_arg(p, 0); } -#line 8223 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8222 "mrbgems/mruby-compiler/core/y.tab.c" break; case 274: /* opt_block_arg: comma block_arg */ @@ -8227,7 +8226,7 @@ yyreduce: { (yyval.nd) = (yyvsp[0].nd); } -#line 8231 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8230 "mrbgems/mruby-compiler/core/y.tab.c" break; case 275: /* opt_block_arg: none */ @@ -8235,7 +8234,7 @@ yyreduce: { (yyval.nd) = 0; } -#line 8239 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8238 "mrbgems/mruby-compiler/core/y.tab.c" break; case 277: /* args: arg */ @@ -8245,7 +8244,7 @@ yyreduce: (yyval.nd) = list1((yyvsp[0].nd)); NODE_LINENO((yyval.nd), (yyvsp[0].nd)); } -#line 8249 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8248 "mrbgems/mruby-compiler/core/y.tab.c" break; case 278: /* args: "*" */ @@ -8253,7 +8252,7 @@ yyreduce: { (yyval.nd) = list1(new_splat(p, new_lvar(p, intern_op(mul)))); } -#line 8257 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8256 "mrbgems/mruby-compiler/core/y.tab.c" break; case 279: /* args: "*" arg */ @@ -8262,7 +8261,7 @@ yyreduce: (yyval.nd) = list1(new_splat(p, (yyvsp[0].nd))); NODE_LINENO((yyval.nd), (yyvsp[0].nd)); } -#line 8266 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8265 "mrbgems/mruby-compiler/core/y.tab.c" break; case 280: /* args: args comma arg */ @@ -8271,7 +8270,7 @@ yyreduce: void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 8275 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8274 "mrbgems/mruby-compiler/core/y.tab.c" break; case 281: /* args: args comma "*" */ @@ -8279,7 +8278,7 @@ yyreduce: { (yyval.nd) = push((yyvsp[-2].nd), new_splat(p, new_lvar(p, intern_op(mul)))); } -#line 8283 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8282 "mrbgems/mruby-compiler/core/y.tab.c" break; case 282: /* args: args comma "*" arg */ @@ -8287,7 +8286,7 @@ yyreduce: { (yyval.nd) = push((yyvsp[-3].nd), new_splat(p, (yyvsp[0].nd))); } -#line 8291 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8290 "mrbgems/mruby-compiler/core/y.tab.c" break; case 283: /* mrhs: args comma arg */ @@ -8296,7 +8295,7 @@ yyreduce: void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 8300 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8299 "mrbgems/mruby-compiler/core/y.tab.c" break; case 284: /* mrhs: args comma "*" arg */ @@ -8304,7 +8303,7 @@ yyreduce: { (yyval.nd) = push((yyvsp[-3].nd), new_splat(p, (yyvsp[0].nd))); } -#line 8308 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8307 "mrbgems/mruby-compiler/core/y.tab.c" break; case 285: /* mrhs: "*" arg */ @@ -8312,7 +8311,7 @@ yyreduce: { (yyval.nd) = list1(new_splat(p, (yyvsp[0].nd))); } -#line 8316 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8315 "mrbgems/mruby-compiler/core/y.tab.c" break; case 293: /* primary: "numbered parameter" */ @@ -8320,7 +8319,7 @@ yyreduce: { (yyval.nd) = new_nvar(p, (yyvsp[0].num)); } -#line 8324 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8323 "mrbgems/mruby-compiler/core/y.tab.c" break; case 294: /* primary: "method" */ @@ -8328,7 +8327,7 @@ yyreduce: { (yyval.nd) = new_fcall(p, (yyvsp[0].id), 0); } -#line 8332 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8331 "mrbgems/mruby-compiler/core/y.tab.c" break; case 295: /* @8: %empty */ @@ -8337,16 +8336,16 @@ yyreduce: (yyval.stack) = p->cmdarg_stack; p->cmdarg_stack = 0; } -#line 8341 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8340 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 296: /* primary: keyword_begin @8 bodystmt keyword_end */ + case 296: /* primary: "'begin'" @8 bodystmt "'end'" */ #line 2701 "mrbgems/mruby-compiler/core/parse.y" { p->cmdarg_stack = (yyvsp[-2].stack); (yyval.nd) = (yyvsp[-1].nd); } -#line 8350 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8349 "mrbgems/mruby-compiler/core/y.tab.c" break; case 297: /* @9: %empty */ @@ -8355,13 +8354,13 @@ yyreduce: (yyval.stack) = p->cmdarg_stack; p->cmdarg_stack = 0; } -#line 8359 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8358 "mrbgems/mruby-compiler/core/y.tab.c" break; case 298: /* $@10: %empty */ #line 2710 "mrbgems/mruby-compiler/core/parse.y" {p->lstate = EXPR_ENDARG;} -#line 8365 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8364 "mrbgems/mruby-compiler/core/y.tab.c" break; case 299: /* primary: "(" @9 stmt $@10 rparen */ @@ -8370,13 +8369,13 @@ yyreduce: p->cmdarg_stack = (yyvsp[-3].stack); (yyval.nd) = (yyvsp[-2].nd); } -#line 8374 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8373 "mrbgems/mruby-compiler/core/y.tab.c" break; case 300: /* $@11: %empty */ #line 2715 "mrbgems/mruby-compiler/core/parse.y" {p->lstate = EXPR_ENDARG;} -#line 8380 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8379 "mrbgems/mruby-compiler/core/y.tab.c" break; case 301: /* primary: "(" $@11 rparen */ @@ -8384,7 +8383,7 @@ yyreduce: { (yyval.nd) = new_nil(p); } -#line 8388 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8387 "mrbgems/mruby-compiler/core/y.tab.c" break; case 302: /* primary: tLPAREN compstmt ')' */ @@ -8392,7 +8391,7 @@ yyreduce: { (yyval.nd) = (yyvsp[-1].nd); } -#line 8396 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8395 "mrbgems/mruby-compiler/core/y.tab.c" break; case 303: /* primary: primary_value "::" "constant" */ @@ -8400,7 +8399,7 @@ yyreduce: { (yyval.nd) = new_colon2(p, (yyvsp[-2].nd), (yyvsp[0].id)); } -#line 8404 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8403 "mrbgems/mruby-compiler/core/y.tab.c" break; case 304: /* primary: tCOLON3 "constant" */ @@ -8408,7 +8407,7 @@ yyreduce: { (yyval.nd) = new_colon3(p, (yyvsp[0].id)); } -#line 8412 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8411 "mrbgems/mruby-compiler/core/y.tab.c" break; case 305: /* primary: "[" aref_args ']' */ @@ -8417,7 +8416,7 @@ yyreduce: (yyval.nd) = new_array(p, (yyvsp[-1].nd)); NODE_LINENO((yyval.nd), (yyvsp[-1].nd)); } -#line 8421 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8420 "mrbgems/mruby-compiler/core/y.tab.c" break; case 306: /* primary: tLBRACE assoc_list '}' */ @@ -8426,39 +8425,39 @@ yyreduce: (yyval.nd) = new_hash(p, (yyvsp[-1].nd)); NODE_LINENO((yyval.nd), (yyvsp[-1].nd)); } -#line 8430 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8429 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 307: /* primary: keyword_return */ + case 307: /* primary: "'return'" */ #line 2742 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_return(p, 0); } -#line 8438 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8437 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 308: /* primary: keyword_yield opt_paren_args */ + case 308: /* primary: "'yield'" opt_paren_args */ #line 2746 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_yield(p, (yyvsp[0].nd)); } -#line 8446 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8445 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 309: /* primary: keyword_not '(' expr rparen */ + case 309: /* primary: "'not'" '(' expr rparen */ #line 2750 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = call_uni_op(p, cond((yyvsp[-1].nd)), "!"); } -#line 8454 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8453 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 310: /* primary: keyword_not '(' rparen */ + case 310: /* primary: "'not'" '(' rparen */ #line 2754 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = call_uni_op(p, new_nil(p), "!"); } -#line 8462 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8461 "mrbgems/mruby-compiler/core/y.tab.c" break; case 311: /* primary: operation brace_block */ @@ -8466,7 +8465,7 @@ yyreduce: { (yyval.nd) = new_fcall(p, (yyvsp[-1].id), new_callargs(p, 0, 0, (yyvsp[0].nd))); } -#line 8470 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8469 "mrbgems/mruby-compiler/core/y.tab.c" break; case 313: /* primary: method_call brace_block */ @@ -8475,7 +8474,7 @@ yyreduce: call_with_block(p, (yyvsp[-1].nd), (yyvsp[0].nd)); (yyval.nd) = (yyvsp[-1].nd); } -#line 8479 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8478 "mrbgems/mruby-compiler/core/y.tab.c" break; case 314: /* @12: %empty */ @@ -8486,7 +8485,7 @@ yyreduce: (yyval.num) = p->lpar_beg; p->lpar_beg = ++p->paren_nest; } -#line 8490 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8489 "mrbgems/mruby-compiler/core/y.tab.c" break; case 315: /* @13: %empty */ @@ -8495,7 +8494,7 @@ yyreduce: (yyval.stack) = p->cmdarg_stack; p->cmdarg_stack = 0; } -#line 8499 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8498 "mrbgems/mruby-compiler/core/y.tab.c" break; case 316: /* primary: "->" @12 f_larglist @13 lambda_body */ @@ -8508,104 +8507,104 @@ yyreduce: p->cmdarg_stack = (yyvsp[-1].stack); CMDARG_LEXPOP(); } -#line 8512 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8511 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 317: /* primary: keyword_if expr_value then compstmt if_tail keyword_end */ + case 317: /* primary: "'if'" expr_value then compstmt if_tail "'end'" */ #line 2792 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_if(p, cond((yyvsp[-4].nd)), (yyvsp[-2].nd), (yyvsp[-1].nd)); SET_LINENO((yyval.nd), (yyvsp[-5].num)); } -#line 8521 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8520 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 318: /* primary: keyword_unless expr_value then compstmt opt_else keyword_end */ + case 318: /* primary: "'unless'" expr_value then compstmt opt_else "'end'" */ #line 2800 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_unless(p, cond((yyvsp[-4].nd)), (yyvsp[-2].nd), (yyvsp[-1].nd)); SET_LINENO((yyval.nd), (yyvsp[-5].num)); } -#line 8530 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8529 "mrbgems/mruby-compiler/core/y.tab.c" break; case 319: /* $@14: %empty */ #line 2804 "mrbgems/mruby-compiler/core/parse.y" {COND_PUSH(1);} -#line 8536 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8535 "mrbgems/mruby-compiler/core/y.tab.c" break; case 320: /* $@15: %empty */ #line 2804 "mrbgems/mruby-compiler/core/parse.y" {COND_POP();} -#line 8542 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8541 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 321: /* primary: keyword_while $@14 expr_value do $@15 compstmt keyword_end */ + case 321: /* primary: "'while'" $@14 expr_value do $@15 compstmt "'end'" */ #line 2807 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_while(p, cond((yyvsp[-4].nd)), (yyvsp[-1].nd)); SET_LINENO((yyval.nd), (yyvsp[-6].num)); } -#line 8551 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8550 "mrbgems/mruby-compiler/core/y.tab.c" break; case 322: /* $@16: %empty */ #line 2811 "mrbgems/mruby-compiler/core/parse.y" {COND_PUSH(1);} -#line 8557 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8556 "mrbgems/mruby-compiler/core/y.tab.c" break; case 323: /* $@17: %empty */ #line 2811 "mrbgems/mruby-compiler/core/parse.y" {COND_POP();} -#line 8563 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8562 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 324: /* primary: keyword_until $@16 expr_value do $@17 compstmt keyword_end */ + case 324: /* primary: "'until'" $@16 expr_value do $@17 compstmt "'end'" */ #line 2814 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_until(p, cond((yyvsp[-4].nd)), (yyvsp[-1].nd)); SET_LINENO((yyval.nd), (yyvsp[-6].num)); } -#line 8572 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8571 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 325: /* primary: keyword_case expr_value opt_terms case_body keyword_end */ + case 325: /* primary: "'case'" expr_value opt_terms case_body "'end'" */ #line 2821 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_case(p, (yyvsp[-3].nd), (yyvsp[-1].nd)); } -#line 8580 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8579 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 326: /* primary: keyword_case opt_terms case_body keyword_end */ + case 326: /* primary: "'case'" opt_terms case_body "'end'" */ #line 2825 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_case(p, 0, (yyvsp[-1].nd)); } -#line 8588 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8587 "mrbgems/mruby-compiler/core/y.tab.c" break; case 327: /* $@18: %empty */ #line 2829 "mrbgems/mruby-compiler/core/parse.y" {COND_PUSH(1);} -#line 8594 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8593 "mrbgems/mruby-compiler/core/y.tab.c" break; case 328: /* $@19: %empty */ #line 2831 "mrbgems/mruby-compiler/core/parse.y" {COND_POP();} -#line 8600 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8599 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 329: /* primary: keyword_for for_var keyword_in $@18 expr_value do $@19 compstmt keyword_end */ + case 329: /* primary: "'for'" for_var "'in'" $@18 expr_value do $@19 compstmt "'end'" */ #line 2834 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_for(p, (yyvsp[-7].nd), (yyvsp[-4].nd), (yyvsp[-1].nd)); SET_LINENO((yyval.nd), (yyvsp[-8].num)); } -#line 8609 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8608 "mrbgems/mruby-compiler/core/y.tab.c" break; case 330: /* @20: %empty */ @@ -8616,10 +8615,10 @@ yyreduce: (yyval.nd) = local_switch(p); nvars_block(p); } -#line 8620 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8619 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 331: /* primary: keyword_class cpath superclass @20 bodystmt keyword_end */ + case 331: /* primary: "'class'" cpath superclass @20 bodystmt "'end'" */ #line 2848 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_class(p, (yyvsp[-4].nd), (yyvsp[-3].nd), (yyvsp[-1].nd)); @@ -8627,7 +8626,7 @@ yyreduce: local_resume(p, (yyvsp[-2].nd)); nvars_unnest(p); } -#line 8631 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8630 "mrbgems/mruby-compiler/core/y.tab.c" break; case 332: /* @21: %empty */ @@ -8636,7 +8635,7 @@ yyreduce: (yyval.num) = p->in_def; p->in_def = 0; } -#line 8640 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8639 "mrbgems/mruby-compiler/core/y.tab.c" break; case 333: /* @22: %empty */ @@ -8646,10 +8645,10 @@ yyreduce: nvars_block(p); p->in_single = 0; } -#line 8650 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8649 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 334: /* primary: keyword_class "<<" expr @21 term @22 bodystmt keyword_end */ + case 334: /* primary: "'class'" "<<" expr @21 term @22 bodystmt "'end'" */ #line 2868 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_sclass(p, (yyvsp[-5].nd), (yyvsp[-1].nd)); @@ -8659,7 +8658,7 @@ yyreduce: p->in_def = (yyvsp[-4].num); p->in_single = intn((yyvsp[-2].nd)->cdr); } -#line 8663 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8662 "mrbgems/mruby-compiler/core/y.tab.c" break; case 335: /* @23: %empty */ @@ -8670,10 +8669,10 @@ yyreduce: (yyval.nd) = local_switch(p); nvars_block(p); } -#line 8674 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8673 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 336: /* primary: keyword_module cpath @23 bodystmt keyword_end */ + case 336: /* primary: "'module'" cpath @23 bodystmt "'end'" */ #line 2886 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_module(p, (yyvsp[-3].nd), (yyvsp[-1].nd)); @@ -8681,10 +8680,10 @@ yyreduce: local_resume(p, (yyvsp[-2].nd)); nvars_unnest(p); } -#line 8685 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8684 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 337: /* primary: defn_head f_arglist bodystmt keyword_end */ + case 337: /* primary: defn_head f_arglist bodystmt "'end'" */ #line 2896 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-3].nd); @@ -8692,10 +8691,10 @@ yyreduce: nvars_unnest(p); p->in_def--; } -#line 8696 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8695 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 338: /* primary: defs_head f_arglist bodystmt keyword_end */ + case 338: /* primary: defs_head f_arglist bodystmt "'end'" */ #line 2906 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-3].nd); @@ -8704,39 +8703,39 @@ yyreduce: p->in_def--; p->in_single--; } -#line 8708 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8707 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 339: /* primary: keyword_break */ + case 339: /* primary: "'break'" */ #line 2914 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_break(p, 0); } -#line 8716 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8715 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 340: /* primary: keyword_next */ + case 340: /* primary: "'next'" */ #line 2918 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_next(p, 0); } -#line 8724 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8723 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 341: /* primary: keyword_redo */ + case 341: /* primary: "'redo'" */ #line 2922 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_redo(p); } -#line 8732 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8731 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 342: /* primary: keyword_retry */ + case 342: /* primary: "'retry'" */ #line 2926 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_retry(p); } -#line 8740 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8739 "mrbgems/mruby-compiler/core/y.tab.c" break; case 343: /* primary_value: primary */ @@ -8745,23 +8744,23 @@ yyreduce: (yyval.nd) = (yyvsp[0].nd); if (!(yyval.nd)) (yyval.nd) = new_nil(p); } -#line 8749 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8748 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 350: /* if_tail: keyword_elsif expr_value then compstmt if_tail */ + case 350: /* if_tail: "'elsif'" expr_value then compstmt if_tail */ #line 2951 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_if(p, cond((yyvsp[-3].nd)), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 8757 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8756 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 352: /* opt_else: keyword_else compstmt */ + case 352: /* opt_else: "'else'" compstmt */ #line 2958 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); } -#line 8765 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8764 "mrbgems/mruby-compiler/core/y.tab.c" break; case 353: /* for_var: lhs */ @@ -8769,7 +8768,7 @@ yyreduce: { (yyval.nd) = list1(list1((yyvsp[0].nd))); } -#line 8773 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8772 "mrbgems/mruby-compiler/core/y.tab.c" break; case 355: /* f_margs: f_arg */ @@ -8777,7 +8776,7 @@ yyreduce: { (yyval.nd) = list3((yyvsp[0].nd),0,0); } -#line 8781 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8780 "mrbgems/mruby-compiler/core/y.tab.c" break; case 356: /* f_margs: f_arg ',' "*" f_norm_arg */ @@ -8785,7 +8784,7 @@ yyreduce: { (yyval.nd) = list3((yyvsp[-3].nd), new_arg(p, (yyvsp[0].id)), 0); } -#line 8789 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8788 "mrbgems/mruby-compiler/core/y.tab.c" break; case 357: /* f_margs: f_arg ',' "*" f_norm_arg ',' f_arg */ @@ -8793,7 +8792,7 @@ yyreduce: { (yyval.nd) = list3((yyvsp[-5].nd), new_arg(p, (yyvsp[-2].id)), (yyvsp[0].nd)); } -#line 8797 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8796 "mrbgems/mruby-compiler/core/y.tab.c" break; case 358: /* f_margs: f_arg ',' "*" */ @@ -8802,7 +8801,7 @@ yyreduce: local_add_f(p, intern_op(mul)); (yyval.nd) = list3((yyvsp[-2].nd), nint(-1), 0); } -#line 8806 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8805 "mrbgems/mruby-compiler/core/y.tab.c" break; case 359: /* f_margs: f_arg ',' "*" ',' f_arg */ @@ -8810,7 +8809,7 @@ yyreduce: { (yyval.nd) = list3((yyvsp[-4].nd), nint(-1), (yyvsp[0].nd)); } -#line 8814 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8813 "mrbgems/mruby-compiler/core/y.tab.c" break; case 360: /* f_margs: "*" f_norm_arg */ @@ -8818,7 +8817,7 @@ yyreduce: { (yyval.nd) = list3(0, new_arg(p, (yyvsp[0].id)), 0); } -#line 8822 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8821 "mrbgems/mruby-compiler/core/y.tab.c" break; case 361: /* f_margs: "*" f_norm_arg ',' f_arg */ @@ -8826,7 +8825,7 @@ yyreduce: { (yyval.nd) = list3(0, new_arg(p, (yyvsp[-2].id)), (yyvsp[0].nd)); } -#line 8830 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8829 "mrbgems/mruby-compiler/core/y.tab.c" break; case 362: /* f_margs: "*" */ @@ -8835,7 +8834,7 @@ yyreduce: local_add_f(p, intern_op(mul)); (yyval.nd) = list3(0, nint(-1), 0); } -#line 8839 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8838 "mrbgems/mruby-compiler/core/y.tab.c" break; case 363: /* $@24: %empty */ @@ -8843,7 +8842,7 @@ yyreduce: { local_add_f(p, intern_op(mul)); } -#line 8847 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8846 "mrbgems/mruby-compiler/core/y.tab.c" break; case 364: /* f_margs: "*" ',' $@24 f_arg */ @@ -8851,7 +8850,7 @@ yyreduce: { (yyval.nd) = list3(0, nint(-1), (yyvsp[0].nd)); } -#line 8855 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8854 "mrbgems/mruby-compiler/core/y.tab.c" break; case 365: /* block_args_tail: f_block_kwarg ',' f_kwrest opt_f_block_arg */ @@ -8859,7 +8858,7 @@ yyreduce: { (yyval.nd) = new_args_tail(p, (yyvsp[-3].nd), (yyvsp[-1].nd), (yyvsp[0].id)); } -#line 8863 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8862 "mrbgems/mruby-compiler/core/y.tab.c" break; case 366: /* block_args_tail: f_block_kwarg opt_f_block_arg */ @@ -8867,7 +8866,7 @@ yyreduce: { (yyval.nd) = new_args_tail(p, (yyvsp[-1].nd), 0, (yyvsp[0].id)); } -#line 8871 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8870 "mrbgems/mruby-compiler/core/y.tab.c" break; case 367: /* block_args_tail: f_kwrest opt_f_block_arg */ @@ -8875,7 +8874,7 @@ yyreduce: { (yyval.nd) = new_args_tail(p, 0, (yyvsp[-1].nd), (yyvsp[0].id)); } -#line 8879 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8878 "mrbgems/mruby-compiler/core/y.tab.c" break; case 368: /* block_args_tail: f_block_arg */ @@ -8883,7 +8882,7 @@ yyreduce: { (yyval.nd) = new_args_tail(p, 0, 0, (yyvsp[0].id)); } -#line 8887 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8886 "mrbgems/mruby-compiler/core/y.tab.c" break; case 369: /* opt_block_args_tail: ',' block_args_tail */ @@ -8891,7 +8890,7 @@ yyreduce: { (yyval.nd) = (yyvsp[0].nd); } -#line 8895 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8894 "mrbgems/mruby-compiler/core/y.tab.c" break; case 370: /* opt_block_args_tail: %empty */ @@ -8899,7 +8898,7 @@ yyreduce: { (yyval.nd) = new_args_tail(p, 0, 0, 0); } -#line 8903 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8902 "mrbgems/mruby-compiler/core/y.tab.c" break; case 371: /* block_param: f_arg ',' f_block_optarg ',' f_rest_arg opt_block_args_tail */ @@ -8907,7 +8906,7 @@ yyreduce: { (yyval.nd) = new_args(p, (yyvsp[-5].nd), (yyvsp[-3].nd), (yyvsp[-1].id), 0, (yyvsp[0].nd)); } -#line 8911 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8910 "mrbgems/mruby-compiler/core/y.tab.c" break; case 372: /* block_param: f_arg ',' f_block_optarg ',' f_rest_arg ',' f_arg opt_block_args_tail */ @@ -8915,7 +8914,7 @@ yyreduce: { (yyval.nd) = new_args(p, (yyvsp[-7].nd), (yyvsp[-5].nd), (yyvsp[-3].id), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 8919 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8918 "mrbgems/mruby-compiler/core/y.tab.c" break; case 373: /* block_param: f_arg ',' f_block_optarg opt_block_args_tail */ @@ -8923,7 +8922,7 @@ yyreduce: { (yyval.nd) = new_args(p, (yyvsp[-3].nd), (yyvsp[-1].nd), 0, 0, (yyvsp[0].nd)); } -#line 8927 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8926 "mrbgems/mruby-compiler/core/y.tab.c" break; case 374: /* block_param: f_arg ',' f_block_optarg ',' f_arg opt_block_args_tail */ @@ -8931,7 +8930,7 @@ yyreduce: { (yyval.nd) = new_args(p, (yyvsp[-5].nd), (yyvsp[-3].nd), 0, (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 8935 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8934 "mrbgems/mruby-compiler/core/y.tab.c" break; case 375: /* block_param: f_arg ',' f_rest_arg opt_block_args_tail */ @@ -8939,7 +8938,7 @@ yyreduce: { (yyval.nd) = new_args(p, (yyvsp[-3].nd), 0, (yyvsp[-1].id), 0, (yyvsp[0].nd)); } -#line 8943 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8942 "mrbgems/mruby-compiler/core/y.tab.c" break; case 376: /* block_param: f_arg ',' opt_block_args_tail */ @@ -8947,7 +8946,7 @@ yyreduce: { (yyval.nd) = new_args(p, (yyvsp[-2].nd), 0, 0, 0, (yyvsp[0].nd)); } -#line 8951 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8950 "mrbgems/mruby-compiler/core/y.tab.c" break; case 377: /* block_param: f_arg ',' f_rest_arg ',' f_arg opt_block_args_tail */ @@ -8955,7 +8954,7 @@ yyreduce: { (yyval.nd) = new_args(p, (yyvsp[-5].nd), 0, (yyvsp[-3].id), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 8959 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8958 "mrbgems/mruby-compiler/core/y.tab.c" break; case 378: /* block_param: f_arg opt_block_args_tail */ @@ -8963,7 +8962,7 @@ yyreduce: { (yyval.nd) = new_args(p, (yyvsp[-1].nd), 0, 0, 0, (yyvsp[0].nd)); } -#line 8967 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8966 "mrbgems/mruby-compiler/core/y.tab.c" break; case 379: /* block_param: f_block_optarg ',' f_rest_arg opt_block_args_tail */ @@ -8971,7 +8970,7 @@ yyreduce: { (yyval.nd) = new_args(p, 0, (yyvsp[-3].nd), (yyvsp[-1].id), 0, (yyvsp[0].nd)); } -#line 8975 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8974 "mrbgems/mruby-compiler/core/y.tab.c" break; case 380: /* block_param: f_block_optarg ',' f_rest_arg ',' f_arg opt_block_args_tail */ @@ -8979,7 +8978,7 @@ yyreduce: { (yyval.nd) = new_args(p, 0, (yyvsp[-5].nd), (yyvsp[-3].id), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 8983 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8982 "mrbgems/mruby-compiler/core/y.tab.c" break; case 381: /* block_param: f_block_optarg opt_block_args_tail */ @@ -8987,7 +8986,7 @@ yyreduce: { (yyval.nd) = new_args(p, 0, (yyvsp[-1].nd), 0, 0, (yyvsp[0].nd)); } -#line 8991 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8990 "mrbgems/mruby-compiler/core/y.tab.c" break; case 382: /* block_param: f_block_optarg ',' f_arg opt_block_args_tail */ @@ -8995,7 +8994,7 @@ yyreduce: { (yyval.nd) = new_args(p, 0, (yyvsp[-3].nd), 0, (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 8999 "mrbgems/mruby-compiler/core/y.tab.c" +#line 8998 "mrbgems/mruby-compiler/core/y.tab.c" break; case 383: /* block_param: f_rest_arg opt_block_args_tail */ @@ -9003,7 +9002,7 @@ yyreduce: { (yyval.nd) = new_args(p, 0, 0, (yyvsp[-1].id), 0, (yyvsp[0].nd)); } -#line 9007 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9006 "mrbgems/mruby-compiler/core/y.tab.c" break; case 384: /* block_param: f_rest_arg ',' f_arg opt_block_args_tail */ @@ -9011,7 +9010,7 @@ yyreduce: { (yyval.nd) = new_args(p, 0, 0, (yyvsp[-3].id), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 9015 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9014 "mrbgems/mruby-compiler/core/y.tab.c" break; case 385: /* block_param: block_args_tail */ @@ -9019,7 +9018,7 @@ yyreduce: { (yyval.nd) = new_args(p, 0, 0, 0, 0, (yyvsp[0].nd)); } -#line 9023 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9022 "mrbgems/mruby-compiler/core/y.tab.c" break; case 386: /* opt_block_param: none */ @@ -9028,7 +9027,7 @@ yyreduce: local_add_blk(p, 0); (yyval.nd) = 0; } -#line 9032 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9031 "mrbgems/mruby-compiler/core/y.tab.c" break; case 387: /* opt_block_param: block_param_def */ @@ -9037,13 +9036,13 @@ yyreduce: p->cmd_start = TRUE; (yyval.nd) = (yyvsp[0].nd); } -#line 9041 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9040 "mrbgems/mruby-compiler/core/y.tab.c" break; case 388: /* $@25: %empty */ #line 3116 "mrbgems/mruby-compiler/core/parse.y" {local_add_blk(p, 0);} -#line 9047 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9046 "mrbgems/mruby-compiler/core/y.tab.c" break; case 389: /* block_param_def: '|' $@25 opt_bv_decl '|' */ @@ -9051,7 +9050,7 @@ yyreduce: { (yyval.nd) = 0; } -#line 9055 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9054 "mrbgems/mruby-compiler/core/y.tab.c" break; case 390: /* block_param_def: "||" */ @@ -9060,7 +9059,7 @@ yyreduce: local_add_blk(p, 0); (yyval.nd) = 0; } -#line 9064 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9063 "mrbgems/mruby-compiler/core/y.tab.c" break; case 391: /* block_param_def: '|' block_param opt_bv_decl '|' */ @@ -9068,7 +9067,7 @@ yyreduce: { (yyval.nd) = (yyvsp[-2].nd); } -#line 9072 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9071 "mrbgems/mruby-compiler/core/y.tab.c" break; case 392: /* opt_bv_decl: opt_nl */ @@ -9076,7 +9075,7 @@ yyreduce: { (yyval.nd) = 0; } -#line 9080 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9079 "mrbgems/mruby-compiler/core/y.tab.c" break; case 393: /* opt_bv_decl: opt_nl ';' bv_decls opt_nl */ @@ -9084,7 +9083,7 @@ yyreduce: { (yyval.nd) = 0; } -#line 9088 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9087 "mrbgems/mruby-compiler/core/y.tab.c" break; case 396: /* bvar: "local variable or method" */ @@ -9093,7 +9092,7 @@ yyreduce: local_add_f(p, (yyvsp[0].id)); new_bv(p, (yyvsp[0].id)); } -#line 9097 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9096 "mrbgems/mruby-compiler/core/y.tab.c" break; case 398: /* f_larglist: '(' f_args opt_bv_decl ')' */ @@ -9101,7 +9100,7 @@ yyreduce: { (yyval.nd) = (yyvsp[-2].nd); } -#line 9105 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9104 "mrbgems/mruby-compiler/core/y.tab.c" break; case 399: /* f_larglist: f_args */ @@ -9109,7 +9108,7 @@ yyreduce: { (yyval.nd) = (yyvsp[0].nd); } -#line 9113 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9112 "mrbgems/mruby-compiler/core/y.tab.c" break; case 400: /* lambda_body: tLAMBEG compstmt '}' */ @@ -9117,38 +9116,40 @@ yyreduce: { (yyval.nd) = (yyvsp[-1].nd); } -#line 9121 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9120 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 401: /* lambda_body: keyword_do_LAMBDA bodystmt keyword_end */ + case 401: /* lambda_body: "'do' for lambda" bodystmt "'end'" */ #line 3169 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-1].nd); } -#line 9129 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9128 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 402: /* $@26: %empty */ + case 402: /* @26: %empty */ #line 3175 "mrbgems/mruby-compiler/core/parse.y" { local_nest(p); nvars_nest(p); + (yyval.num) = p->lineno; } #line 9138 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 403: /* do_block: keyword_do_block $@26 opt_block_param bodystmt keyword_end */ -#line 3182 "mrbgems/mruby-compiler/core/parse.y" + case 403: /* do_block: "'do' for block" @26 opt_block_param bodystmt "'end'" */ +#line 3183 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_block(p,(yyvsp[-2].nd),(yyvsp[-1].nd)); + SET_LINENO((yyval.nd), (yyvsp[-3].num)); local_unnest(p); nvars_unnest(p); } -#line 9148 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9149 "mrbgems/mruby-compiler/core/y.tab.c" break; case 404: /* block_call: command do_block */ -#line 3190 "mrbgems/mruby-compiler/core/parse.y" +#line 3192 "mrbgems/mruby-compiler/core/parse.y" { if (typen((yyvsp[-1].nd)->car) == NODE_YIELD) { yyerror(p, "block given to yield"); @@ -9158,159 +9159,159 @@ yyreduce: } (yyval.nd) = (yyvsp[-1].nd); } -#line 9162 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9163 "mrbgems/mruby-compiler/core/y.tab.c" break; case 405: /* block_call: block_call call_op2 operation2 opt_paren_args */ -#line 3200 "mrbgems/mruby-compiler/core/parse.y" +#line 3202 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-3].nd), (yyvsp[-1].id), (yyvsp[0].nd), (yyvsp[-2].num)); } -#line 9170 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9171 "mrbgems/mruby-compiler/core/y.tab.c" break; case 406: /* block_call: block_call call_op2 operation2 opt_paren_args brace_block */ -#line 3204 "mrbgems/mruby-compiler/core/parse.y" +#line 3206 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), (yyvsp[-1].nd), (yyvsp[-3].num)); call_with_block(p, (yyval.nd), (yyvsp[0].nd)); } -#line 9179 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9180 "mrbgems/mruby-compiler/core/y.tab.c" break; case 407: /* block_call: block_call call_op2 operation2 command_args do_block */ -#line 3209 "mrbgems/mruby-compiler/core/parse.y" +#line 3211 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-4].nd), (yyvsp[-2].id), (yyvsp[-1].nd), (yyvsp[-3].num)); call_with_block(p, (yyval.nd), (yyvsp[0].nd)); } -#line 9188 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9189 "mrbgems/mruby-compiler/core/y.tab.c" break; case 408: /* method_call: operation paren_args */ -#line 3216 "mrbgems/mruby-compiler/core/parse.y" +#line 3218 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_fcall(p, (yyvsp[-1].id), (yyvsp[0].nd)); } -#line 9196 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9197 "mrbgems/mruby-compiler/core/y.tab.c" break; case 409: /* method_call: primary_value call_op operation2 opt_paren_args */ -#line 3220 "mrbgems/mruby-compiler/core/parse.y" +#line 3222 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-3].nd), (yyvsp[-1].id), (yyvsp[0].nd), (yyvsp[-2].num)); } -#line 9204 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9205 "mrbgems/mruby-compiler/core/y.tab.c" break; case 410: /* method_call: primary_value "::" operation2 paren_args */ -#line 3224 "mrbgems/mruby-compiler/core/parse.y" +#line 3226 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-3].nd), (yyvsp[-1].id), (yyvsp[0].nd), tCOLON2); } -#line 9212 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9213 "mrbgems/mruby-compiler/core/y.tab.c" break; case 411: /* method_call: primary_value "::" operation3 */ -#line 3228 "mrbgems/mruby-compiler/core/parse.y" +#line 3230 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-2].nd), (yyvsp[0].id), 0, tCOLON2); } -#line 9220 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9221 "mrbgems/mruby-compiler/core/y.tab.c" break; case 412: /* method_call: primary_value call_op paren_args */ -#line 3232 "mrbgems/mruby-compiler/core/parse.y" +#line 3234 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-2].nd), MRB_SYM_2(p->mrb, call), (yyvsp[0].nd), (yyvsp[-1].num)); } -#line 9228 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9229 "mrbgems/mruby-compiler/core/y.tab.c" break; case 413: /* method_call: primary_value "::" paren_args */ -#line 3236 "mrbgems/mruby-compiler/core/parse.y" +#line 3238 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-2].nd), MRB_SYM_2(p->mrb, call), (yyvsp[0].nd), tCOLON2); } -#line 9236 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9237 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 414: /* method_call: keyword_super paren_args */ -#line 3240 "mrbgems/mruby-compiler/core/parse.y" + case 414: /* method_call: "'super'" paren_args */ +#line 3242 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_super(p, (yyvsp[0].nd)); } -#line 9244 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9245 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 415: /* method_call: keyword_super */ -#line 3244 "mrbgems/mruby-compiler/core/parse.y" + case 415: /* method_call: "'super'" */ +#line 3246 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_zsuper(p); } -#line 9252 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9253 "mrbgems/mruby-compiler/core/y.tab.c" break; case 416: /* method_call: primary_value '[' opt_call_args ']' */ -#line 3248 "mrbgems/mruby-compiler/core/parse.y" +#line 3250 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_call(p, (yyvsp[-3].nd), intern_op(aref), (yyvsp[-1].nd), '.'); } -#line 9260 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9261 "mrbgems/mruby-compiler/core/y.tab.c" break; case 417: /* @27: %empty */ -#line 3254 "mrbgems/mruby-compiler/core/parse.y" +#line 3256 "mrbgems/mruby-compiler/core/parse.y" { local_nest(p); nvars_nest(p); (yyval.num) = p->lineno; } -#line 9270 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9271 "mrbgems/mruby-compiler/core/y.tab.c" break; case 418: /* brace_block: '{' @27 opt_block_param compstmt '}' */ -#line 3261 "mrbgems/mruby-compiler/core/parse.y" +#line 3263 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_block(p,(yyvsp[-2].nd),(yyvsp[-1].nd)); SET_LINENO((yyval.nd), (yyvsp[-3].num)); local_unnest(p); nvars_unnest(p); } -#line 9281 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9282 "mrbgems/mruby-compiler/core/y.tab.c" break; case 419: /* @28: %empty */ -#line 3268 "mrbgems/mruby-compiler/core/parse.y" +#line 3270 "mrbgems/mruby-compiler/core/parse.y" { local_nest(p); nvars_nest(p); (yyval.num) = p->lineno; } -#line 9291 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9292 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 420: /* brace_block: keyword_do @28 opt_block_param bodystmt keyword_end */ -#line 3275 "mrbgems/mruby-compiler/core/parse.y" + case 420: /* brace_block: "'do'" @28 opt_block_param bodystmt "'end'" */ +#line 3277 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_block(p,(yyvsp[-2].nd),(yyvsp[-1].nd)); SET_LINENO((yyval.nd), (yyvsp[-3].num)); local_unnest(p); nvars_unnest(p); } -#line 9302 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9303 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 421: /* case_body: keyword_when args then compstmt cases */ -#line 3286 "mrbgems/mruby-compiler/core/parse.y" + case 421: /* case_body: "'when'" args then compstmt cases */ +#line 3288 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = cons(cons((yyvsp[-3].nd), (yyvsp[-1].nd)), (yyvsp[0].nd)); } -#line 9310 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9311 "mrbgems/mruby-compiler/core/y.tab.c" break; case 422: /* cases: opt_else */ -#line 3292 "mrbgems/mruby-compiler/core/parse.y" +#line 3294 "mrbgems/mruby-compiler/core/parse.y" { if ((yyvsp[0].nd)) { (yyval.nd) = cons(cons(0, (yyvsp[0].nd)), 0); @@ -9319,60 +9320,60 @@ yyreduce: (yyval.nd) = 0; } } -#line 9323 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9324 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 424: /* opt_rescue: keyword_rescue exc_list exc_var then compstmt opt_rescue */ -#line 3306 "mrbgems/mruby-compiler/core/parse.y" + case 424: /* opt_rescue: "'rescue'" exc_list exc_var then compstmt opt_rescue */ +#line 3308 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1(list3((yyvsp[-4].nd), (yyvsp[-3].nd), (yyvsp[-1].nd))); if ((yyvsp[0].nd)) (yyval.nd) = append((yyval.nd), (yyvsp[0].nd)); } -#line 9332 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9333 "mrbgems/mruby-compiler/core/y.tab.c" break; case 426: /* exc_list: arg */ -#line 3314 "mrbgems/mruby-compiler/core/parse.y" +#line 3316 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 9340 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9341 "mrbgems/mruby-compiler/core/y.tab.c" break; case 429: /* exc_var: "=>" lhs */ -#line 3322 "mrbgems/mruby-compiler/core/parse.y" +#line 3324 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); } -#line 9348 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9349 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 431: /* opt_ensure: keyword_ensure compstmt */ -#line 3329 "mrbgems/mruby-compiler/core/parse.y" + case 431: /* opt_ensure: "'ensure'" compstmt */ +#line 3331 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); } -#line 9356 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9357 "mrbgems/mruby-compiler/core/y.tab.c" break; case 438: /* string: string string_fragment */ -#line 3343 "mrbgems/mruby-compiler/core/parse.y" +#line 3345 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = concat_string(p, (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 9364 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9365 "mrbgems/mruby-compiler/core/y.tab.c" break; case 441: /* string_fragment: "string literal" tSTRING */ -#line 3351 "mrbgems/mruby-compiler/core/parse.y" +#line 3353 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); } -#line 9372 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9373 "mrbgems/mruby-compiler/core/y.tab.c" break; case 442: /* string_fragment: "string literal" string_rep tSTRING */ -#line 3355 "mrbgems/mruby-compiler/core/parse.y" +#line 3357 "mrbgems/mruby-compiler/core/parse.y" { node *n = (yyvsp[-1].nd); if (intn((yyvsp[0].nd)->cdr->cdr) > 0) { @@ -9383,68 +9384,68 @@ yyreduce: } (yyval.nd) = new_dstr(p, n); } -#line 9387 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9388 "mrbgems/mruby-compiler/core/y.tab.c" break; case 444: /* string_rep: string_rep string_interp */ -#line 3369 "mrbgems/mruby-compiler/core/parse.y" +#line 3371 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = append((yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 9395 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9396 "mrbgems/mruby-compiler/core/y.tab.c" break; case 445: /* string_interp: tSTRING_MID */ -#line 3375 "mrbgems/mruby-compiler/core/parse.y" +#line 3377 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 9403 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9404 "mrbgems/mruby-compiler/core/y.tab.c" break; case 446: /* @29: %empty */ -#line 3379 "mrbgems/mruby-compiler/core/parse.y" +#line 3381 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = push_strterm(p); } -#line 9411 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9412 "mrbgems/mruby-compiler/core/y.tab.c" break; case 447: /* string_interp: tSTRING_PART @29 compstmt '}' */ -#line 3384 "mrbgems/mruby-compiler/core/parse.y" +#line 3386 "mrbgems/mruby-compiler/core/parse.y" { pop_strterm(p,(yyvsp[-2].nd)); (yyval.nd) = list2((yyvsp[-3].nd), (yyvsp[-1].nd)); } -#line 9420 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9421 "mrbgems/mruby-compiler/core/y.tab.c" break; case 448: /* string_interp: tLITERAL_DELIM */ -#line 3389 "mrbgems/mruby-compiler/core/parse.y" +#line 3391 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1(new_literal_delim(p)); } -#line 9428 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9429 "mrbgems/mruby-compiler/core/y.tab.c" break; case 449: /* string_interp: tHD_LITERAL_DELIM heredoc_bodies */ -#line 3393 "mrbgems/mruby-compiler/core/parse.y" +#line 3395 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1(new_literal_delim(p)); } -#line 9436 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9437 "mrbgems/mruby-compiler/core/y.tab.c" break; case 450: /* xstring: tXSTRING_BEG tXSTRING */ -#line 3399 "mrbgems/mruby-compiler/core/parse.y" +#line 3401 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); } -#line 9444 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9445 "mrbgems/mruby-compiler/core/y.tab.c" break; case 451: /* xstring: tXSTRING_BEG string_rep tXSTRING */ -#line 3403 "mrbgems/mruby-compiler/core/parse.y" +#line 3405 "mrbgems/mruby-compiler/core/parse.y" { node *n = (yyvsp[-1].nd); if (intn((yyvsp[0].nd)->cdr->cdr) > 0) { @@ -9455,81 +9456,81 @@ yyreduce: } (yyval.nd) = new_dxstr(p, n); } -#line 9459 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9460 "mrbgems/mruby-compiler/core/y.tab.c" break; case 452: /* regexp: tREGEXP_BEG tREGEXP */ -#line 3416 "mrbgems/mruby-compiler/core/parse.y" +#line 3418 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); } -#line 9467 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9468 "mrbgems/mruby-compiler/core/y.tab.c" break; case 453: /* regexp: tREGEXP_BEG string_rep tREGEXP */ -#line 3420 "mrbgems/mruby-compiler/core/parse.y" +#line 3422 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_dregx(p, (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 9475 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9476 "mrbgems/mruby-compiler/core/y.tab.c" break; case 457: /* heredoc_body: tHEREDOC_END */ -#line 3433 "mrbgems/mruby-compiler/core/parse.y" +#line 3435 "mrbgems/mruby-compiler/core/parse.y" { parser_heredoc_info *info = parsing_heredoc_info(p); info->doc = push(info->doc, new_str(p, "", 0)); heredoc_end(p); } -#line 9485 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9486 "mrbgems/mruby-compiler/core/y.tab.c" break; case 458: /* heredoc_body: heredoc_string_rep tHEREDOC_END */ -#line 3439 "mrbgems/mruby-compiler/core/parse.y" +#line 3441 "mrbgems/mruby-compiler/core/parse.y" { heredoc_end(p); } -#line 9493 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9494 "mrbgems/mruby-compiler/core/y.tab.c" break; case 461: /* heredoc_string_interp: tHD_STRING_MID */ -#line 3449 "mrbgems/mruby-compiler/core/parse.y" +#line 3451 "mrbgems/mruby-compiler/core/parse.y" { parser_heredoc_info *info = parsing_heredoc_info(p); info->doc = push(info->doc, (yyvsp[0].nd)); heredoc_treat_nextline(p); } -#line 9503 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9504 "mrbgems/mruby-compiler/core/y.tab.c" break; case 462: /* @30: %empty */ -#line 3455 "mrbgems/mruby-compiler/core/parse.y" +#line 3457 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = push_strterm(p); } -#line 9511 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9512 "mrbgems/mruby-compiler/core/y.tab.c" break; case 463: /* heredoc_string_interp: tHD_STRING_PART @30 compstmt '}' */ -#line 3460 "mrbgems/mruby-compiler/core/parse.y" +#line 3462 "mrbgems/mruby-compiler/core/parse.y" { pop_strterm(p, (yyvsp[-2].nd)); parser_heredoc_info *info = parsing_heredoc_info(p); info->doc = push(push(info->doc, (yyvsp[-3].nd)), (yyvsp[-1].nd)); } -#line 9521 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9522 "mrbgems/mruby-compiler/core/y.tab.c" break; case 464: /* words: tWORDS_BEG tSTRING */ -#line 3468 "mrbgems/mruby-compiler/core/parse.y" +#line 3470 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_words(p, list1((yyvsp[0].nd))); } -#line 9529 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9530 "mrbgems/mruby-compiler/core/y.tab.c" break; case 465: /* words: tWORDS_BEG string_rep tSTRING */ -#line 3472 "mrbgems/mruby-compiler/core/parse.y" +#line 3474 "mrbgems/mruby-compiler/core/parse.y" { node *n = (yyvsp[-1].nd); if (intn((yyvsp[0].nd)->cdr->cdr) > 0) { @@ -9540,20 +9541,20 @@ yyreduce: } (yyval.nd) = new_words(p, n); } -#line 9544 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9545 "mrbgems/mruby-compiler/core/y.tab.c" break; case 466: /* symbol: basic_symbol */ -#line 3486 "mrbgems/mruby-compiler/core/parse.y" +#line 3488 "mrbgems/mruby-compiler/core/parse.y" { p->lstate = EXPR_ENDARG; (yyval.nd) = new_sym(p, (yyvsp[0].id)); } -#line 9553 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9554 "mrbgems/mruby-compiler/core/y.tab.c" break; case 467: /* symbol: "symbol" "string literal" string_rep tSTRING */ -#line 3491 "mrbgems/mruby-compiler/core/parse.y" +#line 3493 "mrbgems/mruby-compiler/core/parse.y" { node *n = (yyvsp[-1].nd); p->lstate = EXPR_ENDARG; @@ -9565,43 +9566,43 @@ yyreduce: } (yyval.nd) = new_dsym(p, new_dstr(p, n)); } -#line 9569 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9570 "mrbgems/mruby-compiler/core/y.tab.c" break; case 468: /* basic_symbol: "symbol" sym */ -#line 3505 "mrbgems/mruby-compiler/core/parse.y" +#line 3507 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = (yyvsp[0].id); } -#line 9577 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9578 "mrbgems/mruby-compiler/core/y.tab.c" break; case 473: /* sym: tSTRING */ -#line 3515 "mrbgems/mruby-compiler/core/parse.y" +#line 3517 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = new_strsym(p, (yyvsp[0].nd)); } -#line 9585 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9586 "mrbgems/mruby-compiler/core/y.tab.c" break; case 474: /* sym: "string literal" tSTRING */ -#line 3519 "mrbgems/mruby-compiler/core/parse.y" +#line 3521 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = new_strsym(p, (yyvsp[0].nd)); } -#line 9593 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9594 "mrbgems/mruby-compiler/core/y.tab.c" break; case 475: /* symbols: tSYMBOLS_BEG tSTRING */ -#line 3525 "mrbgems/mruby-compiler/core/parse.y" +#line 3527 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_symbols(p, list1((yyvsp[0].nd))); } -#line 9601 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9602 "mrbgems/mruby-compiler/core/y.tab.c" break; case 476: /* symbols: tSYMBOLS_BEG string_rep tSTRING */ -#line 3529 "mrbgems/mruby-compiler/core/parse.y" +#line 3531 "mrbgems/mruby-compiler/core/parse.y" { node *n = (yyvsp[-1].nd); if (intn((yyvsp[0].nd)->cdr->cdr) > 0) { @@ -9609,123 +9610,123 @@ yyreduce: } (yyval.nd) = new_symbols(p, n); } -#line 9613 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9614 "mrbgems/mruby-compiler/core/y.tab.c" break; case 479: /* numeric: tUMINUS_NUM "integer literal" */ -#line 3541 "mrbgems/mruby-compiler/core/parse.y" +#line 3543 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_negate(p, (yyvsp[0].nd)); } -#line 9621 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9622 "mrbgems/mruby-compiler/core/y.tab.c" break; case 480: /* numeric: tUMINUS_NUM "float literal" */ -#line 3545 "mrbgems/mruby-compiler/core/parse.y" +#line 3547 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_negate(p, (yyvsp[0].nd)); } -#line 9629 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9630 "mrbgems/mruby-compiler/core/y.tab.c" break; case 481: /* variable: "local variable or method" */ -#line 3551 "mrbgems/mruby-compiler/core/parse.y" +#line 3553 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_lvar(p, (yyvsp[0].id)); } -#line 9637 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9638 "mrbgems/mruby-compiler/core/y.tab.c" break; case 482: /* variable: "instance variable" */ -#line 3555 "mrbgems/mruby-compiler/core/parse.y" +#line 3557 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_ivar(p, (yyvsp[0].id)); } -#line 9645 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9646 "mrbgems/mruby-compiler/core/y.tab.c" break; case 483: /* variable: "global variable" */ -#line 3559 "mrbgems/mruby-compiler/core/parse.y" +#line 3561 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_gvar(p, (yyvsp[0].id)); } -#line 9653 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9654 "mrbgems/mruby-compiler/core/y.tab.c" break; case 484: /* variable: "class variable" */ -#line 3563 "mrbgems/mruby-compiler/core/parse.y" +#line 3565 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_cvar(p, (yyvsp[0].id)); } -#line 9661 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9662 "mrbgems/mruby-compiler/core/y.tab.c" break; case 485: /* variable: "constant" */ -#line 3567 "mrbgems/mruby-compiler/core/parse.y" +#line 3569 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_const(p, (yyvsp[0].id)); } -#line 9669 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9670 "mrbgems/mruby-compiler/core/y.tab.c" break; case 486: /* var_lhs: variable */ -#line 3573 "mrbgems/mruby-compiler/core/parse.y" +#line 3575 "mrbgems/mruby-compiler/core/parse.y" { assignable(p, (yyvsp[0].nd)); } -#line 9677 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9678 "mrbgems/mruby-compiler/core/y.tab.c" break; case 487: /* var_lhs: "numbered parameter" */ -#line 3577 "mrbgems/mruby-compiler/core/parse.y" +#line 3579 "mrbgems/mruby-compiler/core/parse.y" { yyerror(p, "can't assign to numbered parameter"); } -#line 9685 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9686 "mrbgems/mruby-compiler/core/y.tab.c" break; case 488: /* var_ref: variable */ -#line 3583 "mrbgems/mruby-compiler/core/parse.y" +#line 3585 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = var_reference(p, (yyvsp[0].nd)); } -#line 9693 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9694 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 489: /* var_ref: keyword_nil */ -#line 3587 "mrbgems/mruby-compiler/core/parse.y" + case 489: /* var_ref: "'nil'" */ +#line 3589 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_nil(p); } -#line 9701 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9702 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 490: /* var_ref: keyword_self */ -#line 3591 "mrbgems/mruby-compiler/core/parse.y" + case 490: /* var_ref: "'self'" */ +#line 3593 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_self(p); } -#line 9709 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9710 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 491: /* var_ref: keyword_true */ -#line 3595 "mrbgems/mruby-compiler/core/parse.y" + case 491: /* var_ref: "'true'" */ +#line 3597 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_true(p); } -#line 9717 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9718 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 492: /* var_ref: keyword_false */ -#line 3599 "mrbgems/mruby-compiler/core/parse.y" + case 492: /* var_ref: "'false'" */ +#line 3601 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_false(p); } -#line 9725 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9726 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 493: /* var_ref: keyword__FILE__ */ -#line 3603 "mrbgems/mruby-compiler/core/parse.y" + case 493: /* var_ref: "'__FILE__'" */ +#line 3605 "mrbgems/mruby-compiler/core/parse.y" { const char *fn = mrb_sym_name_len(p->mrb, p->filename_sym, NULL); if (!fn) { @@ -9733,607 +9734,607 @@ yyreduce: } (yyval.nd) = new_str(p, fn, strlen(fn)); } -#line 9737 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9738 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 494: /* var_ref: keyword__LINE__ */ -#line 3611 "mrbgems/mruby-compiler/core/parse.y" + case 494: /* var_ref: "'__LINE__'" */ +#line 3613 "mrbgems/mruby-compiler/core/parse.y" { char buf[16]; dump_int(p->lineno, buf); (yyval.nd) = new_int(p, buf, 10, 0); } -#line 9748 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9749 "mrbgems/mruby-compiler/core/y.tab.c" break; - case 495: /* var_ref: keyword__ENCODING__ */ -#line 3618 "mrbgems/mruby-compiler/core/parse.y" + case 495: /* var_ref: "'__ENCODING__'" */ +#line 3620 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_fcall(p, MRB_SYM_2(p->mrb, __ENCODING__), 0); } -#line 9756 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9757 "mrbgems/mruby-compiler/core/y.tab.c" break; case 498: /* superclass: %empty */ -#line 3628 "mrbgems/mruby-compiler/core/parse.y" +#line 3630 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = 0; } -#line 9764 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9765 "mrbgems/mruby-compiler/core/y.tab.c" break; case 499: /* $@31: %empty */ -#line 3632 "mrbgems/mruby-compiler/core/parse.y" +#line 3634 "mrbgems/mruby-compiler/core/parse.y" { p->lstate = EXPR_BEG; p->cmd_start = TRUE; } -#line 9773 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9774 "mrbgems/mruby-compiler/core/y.tab.c" break; case 500: /* superclass: '<' $@31 expr_value term */ -#line 3637 "mrbgems/mruby-compiler/core/parse.y" +#line 3639 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-1].nd); } -#line 9781 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9782 "mrbgems/mruby-compiler/core/y.tab.c" break; case 503: /* f_arglist_paren: '(' f_args rparen */ -#line 3653 "mrbgems/mruby-compiler/core/parse.y" +#line 3655 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-1].nd); p->lstate = EXPR_BEG; p->cmd_start = TRUE; } -#line 9791 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9792 "mrbgems/mruby-compiler/core/y.tab.c" break; case 504: /* f_arglist_paren: '(' f_arg ',' tBDOT3 rparen */ -#line 3659 "mrbgems/mruby-compiler/core/parse.y" +#line 3661 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_dots(p, (yyvsp[-3].nd)); } -#line 9799 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9800 "mrbgems/mruby-compiler/core/y.tab.c" break; case 505: /* f_arglist_paren: '(' tBDOT3 rparen */ -#line 3663 "mrbgems/mruby-compiler/core/parse.y" +#line 3665 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_dots(p, 0); } -#line 9807 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9808 "mrbgems/mruby-compiler/core/y.tab.c" break; case 507: /* f_arglist: f_args term */ -#line 3670 "mrbgems/mruby-compiler/core/parse.y" +#line 3672 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-1].nd); } -#line 9815 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9816 "mrbgems/mruby-compiler/core/y.tab.c" break; case 508: /* f_arglist: f_arg ',' tBDOT3 term */ -#line 3674 "mrbgems/mruby-compiler/core/parse.y" +#line 3676 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_dots(p, (yyvsp[-3].nd)); } -#line 9823 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9824 "mrbgems/mruby-compiler/core/y.tab.c" break; case 509: /* f_arglist: "..." term */ -#line 3678 "mrbgems/mruby-compiler/core/parse.y" +#line 3680 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_dots(p, 0); } -#line 9831 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9832 "mrbgems/mruby-compiler/core/y.tab.c" break; case 510: /* f_label: "local variable or method" "label" */ -#line 3684 "mrbgems/mruby-compiler/core/parse.y" +#line 3686 "mrbgems/mruby-compiler/core/parse.y" { local_nest(p); } -#line 9839 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9840 "mrbgems/mruby-compiler/core/y.tab.c" break; case 511: /* f_label: "numbered parameter" "label" */ -#line 3688 "mrbgems/mruby-compiler/core/parse.y" +#line 3690 "mrbgems/mruby-compiler/core/parse.y" { local_nest(p); } -#line 9847 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9848 "mrbgems/mruby-compiler/core/y.tab.c" break; case 512: /* f_kw: f_label arg */ -#line 3694 "mrbgems/mruby-compiler/core/parse.y" +#line 3696 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = new_kw_arg(p, (yyvsp[-1].id), cons((yyvsp[0].nd), locals_node(p))); local_unnest(p); } -#line 9857 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9858 "mrbgems/mruby-compiler/core/y.tab.c" break; case 513: /* f_kw: f_label */ -#line 3700 "mrbgems/mruby-compiler/core/parse.y" +#line 3702 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_kw_arg(p, (yyvsp[0].id), 0); local_unnest(p); } -#line 9866 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9867 "mrbgems/mruby-compiler/core/y.tab.c" break; case 514: /* f_block_kw: f_label primary_value */ -#line 3707 "mrbgems/mruby-compiler/core/parse.y" +#line 3709 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = new_kw_arg(p, (yyvsp[-1].id), cons((yyvsp[0].nd), locals_node(p))); local_unnest(p); } -#line 9876 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9877 "mrbgems/mruby-compiler/core/y.tab.c" break; case 515: /* f_block_kw: f_label */ -#line 3713 "mrbgems/mruby-compiler/core/parse.y" +#line 3715 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_kw_arg(p, (yyvsp[0].id), 0); local_unnest(p); } -#line 9885 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9886 "mrbgems/mruby-compiler/core/y.tab.c" break; case 516: /* f_block_kwarg: f_block_kw */ -#line 3720 "mrbgems/mruby-compiler/core/parse.y" +#line 3722 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 9893 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9894 "mrbgems/mruby-compiler/core/y.tab.c" break; case 517: /* f_block_kwarg: f_block_kwarg ',' f_block_kw */ -#line 3724 "mrbgems/mruby-compiler/core/parse.y" +#line 3726 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 9901 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9902 "mrbgems/mruby-compiler/core/y.tab.c" break; case 518: /* f_kwarg: f_kw */ -#line 3730 "mrbgems/mruby-compiler/core/parse.y" +#line 3732 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 9909 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9910 "mrbgems/mruby-compiler/core/y.tab.c" break; case 519: /* f_kwarg: f_kwarg ',' f_kw */ -#line 3734 "mrbgems/mruby-compiler/core/parse.y" +#line 3736 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 9917 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9918 "mrbgems/mruby-compiler/core/y.tab.c" break; case 522: /* f_kwrest: kwrest_mark "local variable or method" */ -#line 3744 "mrbgems/mruby-compiler/core/parse.y" +#line 3746 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_kw_rest_args(p, (yyvsp[0].id)); } -#line 9925 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9926 "mrbgems/mruby-compiler/core/y.tab.c" break; case 523: /* f_kwrest: kwrest_mark */ -#line 3748 "mrbgems/mruby-compiler/core/parse.y" +#line 3750 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_kw_rest_args(p, 0); } -#line 9933 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9934 "mrbgems/mruby-compiler/core/y.tab.c" break; case 524: /* args_tail: f_kwarg ',' f_kwrest opt_f_block_arg */ -#line 3754 "mrbgems/mruby-compiler/core/parse.y" +#line 3756 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_tail(p, (yyvsp[-3].nd), (yyvsp[-1].nd), (yyvsp[0].id)); } -#line 9941 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9942 "mrbgems/mruby-compiler/core/y.tab.c" break; case 525: /* args_tail: f_kwarg opt_f_block_arg */ -#line 3758 "mrbgems/mruby-compiler/core/parse.y" +#line 3760 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_tail(p, (yyvsp[-1].nd), 0, (yyvsp[0].id)); } -#line 9949 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9950 "mrbgems/mruby-compiler/core/y.tab.c" break; case 526: /* args_tail: f_kwrest opt_f_block_arg */ -#line 3762 "mrbgems/mruby-compiler/core/parse.y" +#line 3764 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_tail(p, 0, (yyvsp[-1].nd), (yyvsp[0].id)); } -#line 9957 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9958 "mrbgems/mruby-compiler/core/y.tab.c" break; case 527: /* args_tail: f_block_arg */ -#line 3766 "mrbgems/mruby-compiler/core/parse.y" +#line 3768 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_tail(p, 0, 0, (yyvsp[0].id)); } -#line 9965 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9966 "mrbgems/mruby-compiler/core/y.tab.c" break; case 528: /* opt_args_tail: ',' args_tail */ -#line 3772 "mrbgems/mruby-compiler/core/parse.y" +#line 3774 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); } -#line 9973 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9974 "mrbgems/mruby-compiler/core/y.tab.c" break; case 529: /* opt_args_tail: %empty */ -#line 3776 "mrbgems/mruby-compiler/core/parse.y" +#line 3778 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args_tail(p, 0, 0, 0); } -#line 9981 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9982 "mrbgems/mruby-compiler/core/y.tab.c" break; case 530: /* f_args: f_arg ',' f_optarg ',' f_rest_arg opt_args_tail */ -#line 3782 "mrbgems/mruby-compiler/core/parse.y" +#line 3784 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, (yyvsp[-5].nd), (yyvsp[-3].nd), (yyvsp[-1].id), 0, (yyvsp[0].nd)); } -#line 9989 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9990 "mrbgems/mruby-compiler/core/y.tab.c" break; case 531: /* f_args: f_arg ',' f_optarg ',' f_rest_arg ',' f_arg opt_args_tail */ -#line 3786 "mrbgems/mruby-compiler/core/parse.y" +#line 3788 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, (yyvsp[-7].nd), (yyvsp[-5].nd), (yyvsp[-3].id), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 9997 "mrbgems/mruby-compiler/core/y.tab.c" +#line 9998 "mrbgems/mruby-compiler/core/y.tab.c" break; case 532: /* f_args: f_arg ',' f_optarg opt_args_tail */ -#line 3790 "mrbgems/mruby-compiler/core/parse.y" +#line 3792 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, (yyvsp[-3].nd), (yyvsp[-1].nd), 0, 0, (yyvsp[0].nd)); } -#line 10005 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10006 "mrbgems/mruby-compiler/core/y.tab.c" break; case 533: /* f_args: f_arg ',' f_optarg ',' f_arg opt_args_tail */ -#line 3794 "mrbgems/mruby-compiler/core/parse.y" +#line 3796 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, (yyvsp[-5].nd), (yyvsp[-3].nd), 0, (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 10013 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10014 "mrbgems/mruby-compiler/core/y.tab.c" break; case 534: /* f_args: f_arg ',' f_rest_arg opt_args_tail */ -#line 3798 "mrbgems/mruby-compiler/core/parse.y" +#line 3800 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, (yyvsp[-3].nd), 0, (yyvsp[-1].id), 0, (yyvsp[0].nd)); } -#line 10021 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10022 "mrbgems/mruby-compiler/core/y.tab.c" break; case 535: /* f_args: f_arg ',' f_rest_arg ',' f_arg opt_args_tail */ -#line 3802 "mrbgems/mruby-compiler/core/parse.y" +#line 3804 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, (yyvsp[-5].nd), 0, (yyvsp[-3].id), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 10029 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10030 "mrbgems/mruby-compiler/core/y.tab.c" break; case 536: /* f_args: f_arg opt_args_tail */ -#line 3806 "mrbgems/mruby-compiler/core/parse.y" +#line 3808 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, (yyvsp[-1].nd), 0, 0, 0, (yyvsp[0].nd)); } -#line 10037 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10038 "mrbgems/mruby-compiler/core/y.tab.c" break; case 537: /* f_args: f_optarg ',' f_rest_arg opt_args_tail */ -#line 3810 "mrbgems/mruby-compiler/core/parse.y" +#line 3812 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, 0, (yyvsp[-3].nd), (yyvsp[-1].id), 0, (yyvsp[0].nd)); } -#line 10045 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10046 "mrbgems/mruby-compiler/core/y.tab.c" break; case 538: /* f_args: f_optarg ',' f_rest_arg ',' f_arg opt_args_tail */ -#line 3814 "mrbgems/mruby-compiler/core/parse.y" +#line 3816 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, 0, (yyvsp[-5].nd), (yyvsp[-3].id), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 10053 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10054 "mrbgems/mruby-compiler/core/y.tab.c" break; case 539: /* f_args: f_optarg opt_args_tail */ -#line 3818 "mrbgems/mruby-compiler/core/parse.y" +#line 3820 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, 0, (yyvsp[-1].nd), 0, 0, (yyvsp[0].nd)); } -#line 10061 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10062 "mrbgems/mruby-compiler/core/y.tab.c" break; case 540: /* f_args: f_optarg ',' f_arg opt_args_tail */ -#line 3822 "mrbgems/mruby-compiler/core/parse.y" +#line 3824 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, 0, (yyvsp[-3].nd), 0, (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 10069 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10070 "mrbgems/mruby-compiler/core/y.tab.c" break; case 541: /* f_args: f_rest_arg opt_args_tail */ -#line 3826 "mrbgems/mruby-compiler/core/parse.y" +#line 3828 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, 0, 0, (yyvsp[-1].id), 0, (yyvsp[0].nd)); } -#line 10077 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10078 "mrbgems/mruby-compiler/core/y.tab.c" break; case 542: /* f_args: f_rest_arg ',' f_arg opt_args_tail */ -#line 3830 "mrbgems/mruby-compiler/core/parse.y" +#line 3832 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, 0, 0, (yyvsp[-3].id), (yyvsp[-1].nd), (yyvsp[0].nd)); } -#line 10085 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10086 "mrbgems/mruby-compiler/core/y.tab.c" break; case 543: /* f_args: args_tail */ -#line 3834 "mrbgems/mruby-compiler/core/parse.y" +#line 3836 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_args(p, 0, 0, 0, 0, (yyvsp[0].nd)); } -#line 10093 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10094 "mrbgems/mruby-compiler/core/y.tab.c" break; case 544: /* f_args: %empty */ -#line 3838 "mrbgems/mruby-compiler/core/parse.y" +#line 3840 "mrbgems/mruby-compiler/core/parse.y" { local_add_f(p, 0); (yyval.nd) = new_args(p, 0, 0, 0, 0, 0); } -#line 10102 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10103 "mrbgems/mruby-compiler/core/y.tab.c" break; case 545: /* f_bad_arg: "constant" */ -#line 3845 "mrbgems/mruby-compiler/core/parse.y" +#line 3847 "mrbgems/mruby-compiler/core/parse.y" { yyerror(p, "formal argument cannot be a constant"); (yyval.nd) = 0; } -#line 10111 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10112 "mrbgems/mruby-compiler/core/y.tab.c" break; case 546: /* f_bad_arg: "instance variable" */ -#line 3850 "mrbgems/mruby-compiler/core/parse.y" +#line 3852 "mrbgems/mruby-compiler/core/parse.y" { yyerror(p, "formal argument cannot be an instance variable"); (yyval.nd) = 0; } -#line 10120 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10121 "mrbgems/mruby-compiler/core/y.tab.c" break; case 547: /* f_bad_arg: "global variable" */ -#line 3855 "mrbgems/mruby-compiler/core/parse.y" +#line 3857 "mrbgems/mruby-compiler/core/parse.y" { yyerror(p, "formal argument cannot be a global variable"); (yyval.nd) = 0; } -#line 10129 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10130 "mrbgems/mruby-compiler/core/y.tab.c" break; case 548: /* f_bad_arg: "class variable" */ -#line 3860 "mrbgems/mruby-compiler/core/parse.y" +#line 3862 "mrbgems/mruby-compiler/core/parse.y" { yyerror(p, "formal argument cannot be a class variable"); (yyval.nd) = 0; } -#line 10138 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10139 "mrbgems/mruby-compiler/core/y.tab.c" break; case 549: /* f_bad_arg: "numbered parameter" */ -#line 3865 "mrbgems/mruby-compiler/core/parse.y" +#line 3867 "mrbgems/mruby-compiler/core/parse.y" { yyerror(p, "formal argument cannot be a numbered parameter"); (yyval.nd) = 0; } -#line 10147 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10148 "mrbgems/mruby-compiler/core/y.tab.c" break; case 550: /* f_norm_arg: f_bad_arg */ -#line 3872 "mrbgems/mruby-compiler/core/parse.y" +#line 3874 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = 0; } -#line 10155 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10156 "mrbgems/mruby-compiler/core/y.tab.c" break; case 551: /* f_norm_arg: "local variable or method" */ -#line 3876 "mrbgems/mruby-compiler/core/parse.y" +#line 3878 "mrbgems/mruby-compiler/core/parse.y" { local_add_f(p, (yyvsp[0].id)); (yyval.id) = (yyvsp[0].id); } -#line 10164 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10165 "mrbgems/mruby-compiler/core/y.tab.c" break; case 552: /* f_arg_item: f_norm_arg */ -#line 3883 "mrbgems/mruby-compiler/core/parse.y" +#line 3885 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_arg(p, (yyvsp[0].id)); } -#line 10172 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10173 "mrbgems/mruby-compiler/core/y.tab.c" break; case 553: /* @32: %empty */ -#line 3887 "mrbgems/mruby-compiler/core/parse.y" +#line 3889 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = local_switch(p); } -#line 10180 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10181 "mrbgems/mruby-compiler/core/y.tab.c" break; case 554: /* f_arg_item: tLPAREN @32 f_margs rparen */ -#line 3891 "mrbgems/mruby-compiler/core/parse.y" +#line 3893 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = new_masgn_param(p, (yyvsp[-1].nd), p->locals->car); local_resume(p, (yyvsp[-2].nd)); local_add_f(p, 0); } -#line 10190 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10191 "mrbgems/mruby-compiler/core/y.tab.c" break; case 555: /* f_arg: f_arg_item */ -#line 3899 "mrbgems/mruby-compiler/core/parse.y" +#line 3901 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 10198 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10199 "mrbgems/mruby-compiler/core/y.tab.c" break; case 556: /* f_arg: f_arg ',' f_arg_item */ -#line 3903 "mrbgems/mruby-compiler/core/parse.y" +#line 3905 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 10206 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10207 "mrbgems/mruby-compiler/core/y.tab.c" break; case 557: /* f_opt_asgn: "local variable or method" '=' */ -#line 3909 "mrbgems/mruby-compiler/core/parse.y" +#line 3911 "mrbgems/mruby-compiler/core/parse.y" { local_add_f(p, (yyvsp[-1].id)); local_nest(p); (yyval.id) = (yyvsp[-1].id); } -#line 10216 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10217 "mrbgems/mruby-compiler/core/y.tab.c" break; case 558: /* f_opt: f_opt_asgn arg */ -#line 3917 "mrbgems/mruby-compiler/core/parse.y" +#line 3919 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = cons(nsym((yyvsp[-1].id)), cons((yyvsp[0].nd), locals_node(p))); local_unnest(p); } -#line 10226 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10227 "mrbgems/mruby-compiler/core/y.tab.c" break; case 559: /* f_block_opt: f_opt_asgn primary_value */ -#line 3925 "mrbgems/mruby-compiler/core/parse.y" +#line 3927 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = cons(nsym((yyvsp[-1].id)), cons((yyvsp[0].nd), locals_node(p))); local_unnest(p); } -#line 10236 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10237 "mrbgems/mruby-compiler/core/y.tab.c" break; case 560: /* f_block_optarg: f_block_opt */ -#line 3933 "mrbgems/mruby-compiler/core/parse.y" +#line 3935 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 10244 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10245 "mrbgems/mruby-compiler/core/y.tab.c" break; case 561: /* f_block_optarg: f_block_optarg ',' f_block_opt */ -#line 3937 "mrbgems/mruby-compiler/core/parse.y" +#line 3939 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 10252 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10253 "mrbgems/mruby-compiler/core/y.tab.c" break; case 562: /* f_optarg: f_opt */ -#line 3943 "mrbgems/mruby-compiler/core/parse.y" +#line 3945 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1((yyvsp[0].nd)); } -#line 10260 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10261 "mrbgems/mruby-compiler/core/y.tab.c" break; case 563: /* f_optarg: f_optarg ',' f_opt */ -#line 3947 "mrbgems/mruby-compiler/core/parse.y" +#line 3949 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 10268 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10269 "mrbgems/mruby-compiler/core/y.tab.c" break; case 566: /* f_rest_arg: restarg_mark "local variable or method" */ -#line 3957 "mrbgems/mruby-compiler/core/parse.y" +#line 3959 "mrbgems/mruby-compiler/core/parse.y" { local_add_f(p, (yyvsp[0].id)); (yyval.id) = (yyvsp[0].id); } -#line 10277 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10278 "mrbgems/mruby-compiler/core/y.tab.c" break; case 567: /* f_rest_arg: restarg_mark */ -#line 3962 "mrbgems/mruby-compiler/core/parse.y" +#line 3964 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(mul); local_add_f(p, (yyval.id)); } -#line 10286 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10287 "mrbgems/mruby-compiler/core/y.tab.c" break; case 570: /* f_block_arg: blkarg_mark "local variable or method" */ -#line 3973 "mrbgems/mruby-compiler/core/parse.y" +#line 3975 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = (yyvsp[0].id); } -#line 10294 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10295 "mrbgems/mruby-compiler/core/y.tab.c" break; case 571: /* f_block_arg: blkarg_mark */ -#line 3977 "mrbgems/mruby-compiler/core/parse.y" +#line 3979 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = intern_op(and); } -#line 10302 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10303 "mrbgems/mruby-compiler/core/y.tab.c" break; case 572: /* opt_f_block_arg: ',' f_block_arg */ -#line 3983 "mrbgems/mruby-compiler/core/parse.y" +#line 3985 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = (yyvsp[0].id); } -#line 10310 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10311 "mrbgems/mruby-compiler/core/y.tab.c" break; case 573: /* opt_f_block_arg: none */ -#line 3987 "mrbgems/mruby-compiler/core/parse.y" +#line 3989 "mrbgems/mruby-compiler/core/parse.y" { (yyval.id) = 0; } -#line 10318 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10319 "mrbgems/mruby-compiler/core/y.tab.c" break; case 574: /* singleton: var_ref */ -#line 3993 "mrbgems/mruby-compiler/core/parse.y" +#line 3995 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[0].nd); if (!(yyval.nd)) (yyval.nd) = new_nil(p); } -#line 10327 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10328 "mrbgems/mruby-compiler/core/y.tab.c" break; case 575: /* $@33: %empty */ -#line 3997 "mrbgems/mruby-compiler/core/parse.y" +#line 3999 "mrbgems/mruby-compiler/core/parse.y" {p->lstate = EXPR_BEG;} -#line 10333 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10334 "mrbgems/mruby-compiler/core/y.tab.c" break; case 576: /* singleton: '(' $@33 expr rparen */ -#line 3998 "mrbgems/mruby-compiler/core/parse.y" +#line 4000 "mrbgems/mruby-compiler/core/parse.y" { if ((yyvsp[-1].nd) == 0) { yyerror(p, "can't define singleton method for ()."); @@ -10356,81 +10357,81 @@ yyreduce: } (yyval.nd) = (yyvsp[-1].nd); } -#line 10360 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10361 "mrbgems/mruby-compiler/core/y.tab.c" break; case 578: /* assoc_list: assocs trailer */ -#line 4024 "mrbgems/mruby-compiler/core/parse.y" +#line 4026 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = (yyvsp[-1].nd); } -#line 10368 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10369 "mrbgems/mruby-compiler/core/y.tab.c" break; case 579: /* assocs: assoc */ -#line 4030 "mrbgems/mruby-compiler/core/parse.y" +#line 4032 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = list1((yyvsp[0].nd)); NODE_LINENO((yyval.nd), (yyvsp[0].nd)); } -#line 10377 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10378 "mrbgems/mruby-compiler/core/y.tab.c" break; case 580: /* assocs: assocs comma assoc */ -#line 4035 "mrbgems/mruby-compiler/core/parse.y" +#line 4037 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = push((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 10385 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10386 "mrbgems/mruby-compiler/core/y.tab.c" break; case 581: /* assoc: arg "=>" arg */ -#line 4041 "mrbgems/mruby-compiler/core/parse.y" +#line 4043 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[-2].nd)); void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = cons((yyvsp[-2].nd), (yyvsp[0].nd)); } -#line 10395 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10396 "mrbgems/mruby-compiler/core/y.tab.c" break; case 582: /* assoc: "local variable or method" "label" arg */ -#line 4047 "mrbgems/mruby-compiler/core/parse.y" +#line 4049 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = cons(new_sym(p, (yyvsp[-2].id)), (yyvsp[0].nd)); } -#line 10404 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10405 "mrbgems/mruby-compiler/core/y.tab.c" break; case 583: /* assoc: "local variable or method" "label" */ -#line 4052 "mrbgems/mruby-compiler/core/parse.y" +#line 4054 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = cons(new_sym(p, (yyvsp[-1].id)), label_reference(p, (yyvsp[-1].id))); } -#line 10412 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10413 "mrbgems/mruby-compiler/core/y.tab.c" break; case 584: /* assoc: "numbered parameter" "label" */ -#line 4056 "mrbgems/mruby-compiler/core/parse.y" +#line 4058 "mrbgems/mruby-compiler/core/parse.y" { mrb_sym sym = intern_numparam((yyvsp[-1].num)); (yyval.nd) = cons(new_sym(p, sym), label_reference(p, sym)); } -#line 10421 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10422 "mrbgems/mruby-compiler/core/y.tab.c" break; case 585: /* assoc: "numbered parameter" "label" arg */ -#line 4061 "mrbgems/mruby-compiler/core/parse.y" +#line 4063 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = cons(new_sym(p, intern_numparam((yyvsp[-2].num))), (yyvsp[0].nd)); } -#line 10430 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10431 "mrbgems/mruby-compiler/core/y.tab.c" break; case 586: /* assoc: string_fragment "label" arg */ -#line 4066 "mrbgems/mruby-compiler/core/parse.y" +#line 4068 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[0].nd)); if (typen((yyvsp[-2].nd)->car) == NODE_DSTR) { @@ -10440,75 +10441,75 @@ yyreduce: (yyval.nd) = cons(new_sym(p, new_strsym(p, (yyvsp[-2].nd))), (yyvsp[0].nd)); } } -#line 10444 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10445 "mrbgems/mruby-compiler/core/y.tab.c" break; case 587: /* assoc: "**" arg */ -#line 4076 "mrbgems/mruby-compiler/core/parse.y" +#line 4078 "mrbgems/mruby-compiler/core/parse.y" { void_expr_error(p, (yyvsp[0].nd)); (yyval.nd) = cons(new_kw_rest_args(p, 0), (yyvsp[0].nd)); } -#line 10453 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10454 "mrbgems/mruby-compiler/core/y.tab.c" break; case 588: /* assoc: "**" */ -#line 4081 "mrbgems/mruby-compiler/core/parse.y" +#line 4083 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = cons(new_kw_rest_args(p, 0), new_lvar(p, intern_op(pow))); } -#line 10461 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10462 "mrbgems/mruby-compiler/core/y.tab.c" break; case 601: /* call_op: '.' */ -#line 4107 "mrbgems/mruby-compiler/core/parse.y" +#line 4109 "mrbgems/mruby-compiler/core/parse.y" { (yyval.num) = '.'; } -#line 10469 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10470 "mrbgems/mruby-compiler/core/y.tab.c" break; case 602: /* call_op: "&." */ -#line 4111 "mrbgems/mruby-compiler/core/parse.y" +#line 4113 "mrbgems/mruby-compiler/core/parse.y" { (yyval.num) = 0; } -#line 10477 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10478 "mrbgems/mruby-compiler/core/y.tab.c" break; case 604: /* call_op2: "::" */ -#line 4118 "mrbgems/mruby-compiler/core/parse.y" +#line 4120 "mrbgems/mruby-compiler/core/parse.y" { (yyval.num) = tCOLON2; } -#line 10485 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10486 "mrbgems/mruby-compiler/core/y.tab.c" break; case 613: /* term: ';' */ -#line 4139 "mrbgems/mruby-compiler/core/parse.y" +#line 4141 "mrbgems/mruby-compiler/core/parse.y" {yyerrok;} -#line 10491 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10492 "mrbgems/mruby-compiler/core/y.tab.c" break; case 615: /* nl: '\n' */ -#line 4144 "mrbgems/mruby-compiler/core/parse.y" +#line 4146 "mrbgems/mruby-compiler/core/parse.y" { p->lineno += (yyvsp[0].num); p->column = 0; } -#line 10500 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10501 "mrbgems/mruby-compiler/core/y.tab.c" break; case 619: /* none: %empty */ -#line 4156 "mrbgems/mruby-compiler/core/parse.y" +#line 4158 "mrbgems/mruby-compiler/core/parse.y" { (yyval.nd) = 0; } -#line 10508 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10509 "mrbgems/mruby-compiler/core/y.tab.c" break; -#line 10512 "mrbgems/mruby-compiler/core/y.tab.c" +#line 10513 "mrbgems/mruby-compiler/core/y.tab.c" default: break; } @@ -10732,7 +10733,7 @@ yyreturnlab: return yyresult; } -#line 4160 "mrbgems/mruby-compiler/core/parse.y" +#line 4162 "mrbgems/mruby-compiler/core/parse.y" #define pylval (*((YYSTYPE*)(p->ylval))) @@ -11402,7 +11403,8 @@ heredoc_remove_indent(parser_state *p, parser_heredoc_info *hinfo) newstr[newlen] = '\0'; pair->car = (node*)newstr; pair->cdr = (node*)newlen; - } else { + } + else { spaces = (size_t)nspaces->car; heredoc_count_indent(hinfo, str, len, spaces, &offset); pair->car = (node*)(str + offset); @@ -11477,7 +11479,8 @@ parse_string(parser_state *p) if (sizeof(s1)+sizeof(s2)+strlen(hinfo->term)+1 >= sizeof(buf)) { yyerror(p, "can't find heredoc delimiter anywhere before EOF"); - } else { + } + else { strcpy(buf, s1); strcat(buf, hinfo->term); strcat(buf, s2); @@ -13160,7 +13163,7 @@ yylex(void *lval, parser_state *p) } static void -parser_init_cxt(parser_state *p, mrbc_context *cxt) +parser_init_cxt(parser_state *p, mrb_ccontext *cxt) { if (!cxt) return; if (cxt->filename) mrb_parser_set_filename(p, cxt->filename); @@ -13183,7 +13186,7 @@ parser_init_cxt(parser_state *p, mrbc_context *cxt) } static void -parser_update_cxt(parser_state *p, mrbc_context *cxt) +parser_update_cxt(parser_state *p, mrb_ccontext *cxt) { node *n, *n0; int i = 0; @@ -13206,7 +13209,7 @@ parser_update_cxt(parser_state *p, mrbc_context *cxt) void mrb_parser_dump(mrb_state *mrb, node *tree, int offset); MRB_API void -mrb_parser_parse(parser_state *p, mrbc_context *c) +mrb_parser_parse(parser_state *p, mrb_ccontext *c) { struct mrb_jmpbuf buf1; struct mrb_jmpbuf *prev = p->mrb->jmp; @@ -13294,14 +13297,14 @@ mrb_parser_free(parser_state *p) { mrb_pool_close(p->pool); } -MRB_API mrbc_context* -mrbc_context_new(mrb_state *mrb) +MRB_API mrb_ccontext* +mrb_ccontext_new(mrb_state *mrb) { - return (mrbc_context*)mrb_calloc(mrb, 1, sizeof(mrbc_context)); + return (mrb_ccontext*)mrb_calloc(mrb, 1, sizeof(mrb_ccontext)); } MRB_API void -mrbc_context_free(mrb_state *mrb, mrbc_context *cxt) +mrb_ccontext_free(mrb_state *mrb, mrb_ccontext *cxt) { mrb_free(mrb, cxt->filename); mrb_free(mrb, cxt->syms); @@ -13309,12 +13312,13 @@ mrbc_context_free(mrb_state *mrb, mrbc_context *cxt) } MRB_API const char* -mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s) +mrb_ccontext_filename(mrb_state *mrb, mrb_ccontext *c, const char *s) { if (s) { size_t len = strlen(s); - char *p = (char*)mrb_malloc(mrb, len + 1); + char *p = (char*)mrb_malloc_simple(mrb, len + 1); + if (p == NULL) return NULL; memcpy(p, s, len + 1); if (c->filename) { mrb_free(mrb, c->filename); @@ -13325,14 +13329,14 @@ mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s) } MRB_API void -mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*func)(struct mrb_parser_state*), void *data) +mrb_ccontext_partial_hook(mrb_state *mrb, mrb_ccontext *c, int (*func)(struct mrb_parser_state*), void *data) { c->partial_hook = func; c->partial_data = data; } MRB_API void -mrbc_cleanup_local_variables(mrb_state *mrb, mrbc_context *c) +mrb_ccontext_cleanup_local_variables(mrb_state *mrb, mrb_ccontext *c) { if (c->syms) { mrb_free(mrb, c->syms); @@ -13384,7 +13388,7 @@ mrb_parser_get_filename(struct mrb_parser_state* p, uint16_t idx) { #ifndef MRB_NO_STDIO static struct mrb_parser_state * -mrb_parse_file_continue(mrb_state *mrb, FILE *f, const void *prebuf, size_t prebufsize, mrbc_context *c) +mrb_parse_file_continue(mrb_state *mrb, FILE *f, const void *prebuf, size_t prebufsize, mrb_ccontext *c) { parser_state *p; @@ -13404,14 +13408,14 @@ mrb_parse_file_continue(mrb_state *mrb, FILE *f, const void *prebuf, size_t preb } MRB_API parser_state* -mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c) +mrb_parse_file(mrb_state *mrb, FILE *f, mrb_ccontext *c) { return mrb_parse_file_continue(mrb, f, NULL, 0, c); } #endif MRB_API parser_state* -mrb_parse_nstring(mrb_state *mrb, const char *s, size_t len, mrbc_context *c) +mrb_parse_nstring(mrb_state *mrb, const char *s, size_t len, mrb_ccontext *c) { parser_state *p; @@ -13425,13 +13429,13 @@ mrb_parse_nstring(mrb_state *mrb, const char *s, size_t len, mrbc_context *c) } MRB_API parser_state* -mrb_parse_string(mrb_state *mrb, const char *s, mrbc_context *c) +mrb_parse_string(mrb_state *mrb, const char *s, mrb_ccontext *c) { return mrb_parse_nstring(mrb, s, strlen(s), c); } MRB_API mrb_value -mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c) +mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrb_ccontext *c) { struct RClass *target = mrb->object_class; struct RProc *proc; @@ -13494,7 +13498,7 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c) #ifndef MRB_NO_STDIO MRB_API mrb_value -mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrbc_context *c) +mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrb_ccontext *c) { return mrb_load_exec(mrb, mrb_parse_file(mrb, f, c), c); } @@ -13514,7 +13518,7 @@ mrb_load_file(mrb_state *mrb, FILE *f) * - `NUL` is included in the first 64 bytes of the file */ MRB_API mrb_value -mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c) +mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrb_ccontext *c) { union { char b[DETECT_SIZE]; @@ -13557,7 +13561,7 @@ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c) #endif MRB_API mrb_value -mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrbc_context *c) +mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrb_ccontext *c) { return mrb_load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c); } @@ -13569,7 +13573,7 @@ mrb_load_nstring(mrb_state *mrb, const char *s, size_t len) } MRB_API mrb_value -mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *c) +mrb_load_string_cxt(mrb_state *mrb, const char *s, mrb_ccontext *c) { return mrb_load_nstring_cxt(mrb, s, strlen(s), c); } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-complex/src/complex.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-complex/src/complex.c index ad88a67eca..a2c5790585 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-complex/src/complex.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-complex/src/complex.c @@ -284,12 +284,15 @@ add_pair(struct float_pair *s, struct float_pair const *a, { if (b->s == 0.0F) { *s = *a; - } else if (a->s == 0.0F) { + } + else if (a->s == 0.0F) { *s = *b; - } else if (a->x >= b->x) { + } + else if (a->x >= b->x) { s->s = a->s + F(ldexp)(b->s, b->x - a->x); s->x = a->x; - } else { + } + else { s->s = F(ldexp)(a->s, a->x - b->x) + b->s; s->x = b->x; } @@ -393,6 +396,7 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb) comp = mrb_define_class_id(mrb, MRB_SYM(Complex), mrb_class_get_id(mrb, MRB_SYM(Numeric))); MRB_SET_INSTANCE_TT(comp, MRB_TT_COMPLEX); + MRB_UNDEF_ALLOCATOR(comp); mrb_undef_class_method(mrb, comp, "new"); mrb_define_class_method(mrb, comp, "rectangular", complex_s_rect, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1)); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-data/src/data.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-data/src/data.c index 91bc55a0c9..46f3c0255f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-data/src/data.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-data/src/data.c @@ -94,15 +94,60 @@ mrb_data_members(mrb_state *mrb, mrb_value obj) } static mrb_value -mrb_data_ref(mrb_state *mrb, mrb_value obj) +data_ref(mrb_state *mrb, mrb_value obj, mrb_int i) { - mrb_int i = mrb_integer(mrb_proc_cfunc_env_get(mrb, 0)); + mrb_int len = RDATA_LEN(obj); mrb_value *ptr = RDATA_PTR(obj); - if (!ptr) return mrb_nil_value(); + if (!ptr || len <= i) + return mrb_nil_value(); return ptr[i]; } +static mrb_value +mrb_data_ref(mrb_state *mrb, mrb_value obj) +{ + mrb_int argc = mrb_get_argc(mrb); + if (argc != 0) { + mrb_argnum_error(mrb, argc, 0, 0); + } + mrb_int i = mrb_integer(mrb_proc_cfunc_env_get(mrb, 0)); + return data_ref(mrb, obj, i); +} + +static mrb_value +data_ref_0(mrb_state *mrb, mrb_value obj) +{ + return data_ref(mrb, obj, 0); +} + +static mrb_value +data_ref_1(mrb_state *mrb, mrb_value obj) +{ + return data_ref(mrb, obj, 1); +} + +static mrb_value +data_ref_2(mrb_state *mrb, mrb_value obj) +{ + return data_ref(mrb, obj, 2); +} + +static mrb_value +data_ref_3(mrb_state *mrb, mrb_value obj) +{ + return data_ref(mrb, obj, 3); +} + +#define DATA_DIRECT_REF_MAX 4 + +static mrb_func_t aref[DATA_DIRECT_REF_MAX] = { + data_ref_0, + data_ref_1, + data_ref_2, + data_ref_3, +}; + static void make_data_define_accessors(mrb_state *mrb, mrb_value members, struct RClass *c) { @@ -112,12 +157,18 @@ make_data_define_accessors(mrb_state *mrb, mrb_value members, struct RClass *c) for (mrb_int i=0; i0) mrb_str_cat_lit(mrb, ret, ", "); mrb_str_cat(mrb, ret, name, len); mrb_str_cat_lit(mrb, ret, "="); - mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, vals[i])); + mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, RARRAY_PTR(self)[i])); mrb_gc_arena_restore(mrb, ai); } mrb_str_cat_lit(mrb, ret, ">"); @@ -441,6 +494,7 @@ mrb_mruby_data_gem_init(mrb_state* mrb) struct RClass *d; d = mrb_define_class(mrb, "Data", mrb->object_class); MRB_SET_INSTANCE_TT(d, MRB_TT_STRUCT); + MRB_UNDEF_ALLOCATOR(d); mrb_undef_class_method(mrb, d, "new"); mrb_define_class_method(mrb, d, "define", mrb_data_s_def, MRB_ARGS_ANY()); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/README.md b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/README.md index 2be9d03c05..7cd9fcc3a4 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/README.md +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/README.md @@ -1,6 +1,6 @@ # mruby-dir -Dir class for mruby. Supported methods are: +Dir class for mruby. Supported methods are: `.chdir` `.delete` diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/mrbgem.rake index 6951c49db4..ed05e14d1e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/mrbgem.rake @@ -1,4 +1,4 @@ MRuby::Gem::Specification.new('mruby-dir') do |spec| spec.license = 'MIT and MIT-like license' - spec.authors = [ 'Internet Initiative Japan Inc.', 'Kevlin Henney'] + spec.authors = ['Internet Initiative Japan Inc.', 'Kevlin Henney'] end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/src/Win/dirent.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/src/Win/dirent.c index 1b43a99249..086aaf9723 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/src/Win/dirent.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/src/Win/dirent.c @@ -39,38 +39,31 @@ DIR *opendir(const char *name) { DIR *dir = 0; - if(name && name[0]) - { + if (name && name[0]) { size_t base_length = strlen(name); const char *all = /* search pattern must end with suitable wildcard */ strchr("/\\", name[base_length - 1]) ? "*" : "/*"; - if((dir = (DIR *) malloc(sizeof *dir)) != 0 && - (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0) - { + if ((dir = (DIR *) malloc(sizeof *dir)) != 0 && + (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0) { strcat(strcpy(dir->name, name), all); - if((dir->handle = - (handle_type) _findfirst(dir->name, &dir->info)) != -1) - { + if ((dir->handle = (handle_type) _findfirst(dir->name, &dir->info)) != -1) { dir->result.d_name = 0; } - else /* rollback */ - { + else { /* rollback */ free(dir->name); free(dir); dir = 0; } } - else /* rollback */ - { + else { /* rollback */ free(dir); dir = 0; errno = ENOMEM; } } - else - { + else { errno = EINVAL; } @@ -81,9 +74,8 @@ int closedir(DIR *dir) { int result = -1; - if(dir) - { - if(dir->handle != -1) + if (dir) { + if (dir->handle != -1) { result = _findclose(dir->handle); } @@ -92,8 +84,7 @@ int closedir(DIR *dir) free(dir); } - if(result == -1) /* map all errors to EBADF */ - { + if (result == -1) { /* map all errors to EBADF */ errno = EBADF; } @@ -104,16 +95,13 @@ struct dirent *readdir(DIR *dir) { struct dirent *result = 0; - if(dir && dir->handle != -1) - { - if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) - { + if (dir && dir->handle != -1) { + if (!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) { result = &dir->result; result->d_name = dir->info.name; } } - else - { + else { errno = EBADF; } @@ -122,14 +110,12 @@ struct dirent *readdir(DIR *dir) void rewinddir(DIR *dir) { - if(dir && dir->handle != -1) - { + if (dir && dir->handle != -1) { _findclose(dir->handle); dir->handle = (handle_type) _findfirst(dir->name, &dir->info); dir->result.d_name = 0; } - else - { + else { errno = EBADF; } } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/src/dir.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/src/dir.c index 455c17bd3c..52d100f2b5 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/src/dir.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-dir/src/dir.c @@ -34,6 +34,7 @@ #include #include #include +#include #define E_IO_ERROR mrb_exc_get_id(mrb, MRB_SYM(IOError)) @@ -128,10 +129,16 @@ static mrb_value mrb_dir_getwd(mrb_state *mrb, mrb_value klass) { mrb_value path; + mrb_int size = 64; - path = mrb_str_buf_new(mrb, MAXPATHLEN); - if (getcwd(RSTRING_PTR(path), MAXPATHLEN) == NULL) { - mrb_sys_fail(mrb, "getcwd(2)"); + path = mrb_str_buf_new(mrb, size); + while (getcwd(RSTRING_PTR(path), size) == NULL) { + int e = errno; + if (e != ERANGE) { + mrb_sys_fail(mrb, "getcwd(2)"); + } + size *= 2; + mrb_str_resize(mrb, path, size); } mrb_str_resize(mrb, path, strlen(RSTRING_PTR(path))); return path; @@ -166,7 +173,7 @@ mrb_dir_chdir(mrb_state *mrb, mrb_value klass) static mrb_value mrb_dir_chroot(mrb_state *mrb, mrb_value self) { -#if defined(_WIN32) || defined(_WIN64) || defined(__ANDROID__) +#if defined(_WIN32) || defined(_WIN64) || defined(__ANDROID__) || defined(__MSDOS__) mrb_raise(mrb, E_NOTIMP_ERROR, "chroot() unreliable on your system"); return mrb_fixnum_value(0); #else @@ -312,7 +319,7 @@ mrb_mruby_dir_gem_init(mrb_state *mrb) mrb_define_method(mrb, d, "seek", mrb_dir_seek, MRB_ARGS_REQ(1)); mrb_define_method(mrb, d, "tell", mrb_dir_tell, MRB_ARGS_NONE()); - mrb_define_class(mrb, "IOError", mrb->eStandardError_class); + mrb_define_class(mrb, "IOError", E_STANDARD_ERROR); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-enum-lazy/mrblib/lazy.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-enum-lazy/mrblib/lazy.rb index e4f116a933..2b50ff3144 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-enum-lazy/mrblib/lazy.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-enum-lazy/mrblib/lazy.rb @@ -47,9 +47,12 @@ class Enumerator raise ArgumentError, "undefined method #{meth}" end lz = Lazy.new(self, &block) - lz.obj = self - lz.meth = meth - lz.args = args + obj = self + lz.instance_eval { + @obj = obj + @meth = meth + @args = args + } lz end alias enum_for to_enum diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb index 65cddbdac8..faaabf18a8 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb @@ -132,16 +132,20 @@ class Enumerator @stop_exc = false end - attr_accessor :obj, :meth, :args, :kwd - attr_reader :fib - def initialize_copy(obj) raise TypeError, "can't copy type #{obj.class}" unless obj.kind_of? Enumerator - raise TypeError, "can't copy execution context" if obj.fib - @obj = obj.obj - @meth = obj.meth - @args = obj.args - @kwd = obj.kwd + raise TypeError, "can't copy execution context" if obj.instance_eval{@fib} + meth = args = kwd = fib = nil + obj.instance_eval { + obj = @obj + meth = @meth + args = @args + kwd = @kwd + } + @obj = obj + @meth = meth + @args = args + @kwd = kwd @fib = nil @lookahead = nil @feedvalue = nil @@ -169,7 +173,7 @@ class Enumerator end n = offset - 1 - enumerator_block_call do |*i| + __enumerator_block_call do |*i| n += 1 block.call i.__svalue, n end @@ -219,7 +223,7 @@ class Enumerator def with_object(object, &block) return to_enum(:with_object, object) unless block - enumerator_block_call do |i| + __enumerator_block_call do |i| block.call [i,object] end object @@ -234,6 +238,14 @@ class Enumerator end end + def size + if @size + @size + elsif @obj.respond_to?(:size) + @obj.size + end + end + ## # call-seq: # enum.each { |elm| block } -> obj @@ -274,23 +286,23 @@ class Enumerator obj = self if 0 < argv.length obj = self.dup - args = obj.args + args = obj.instance_eval{@args} if !args.empty? args = args.dup args.concat argv else args = argv.dup end - obj.args = args + obj.instance_eval{@args = args} end return obj unless block - enumerator_block_call(&block) + __enumerator_block_call(&block) end - def enumerator_block_call(&block) + def __enumerator_block_call(&block) @obj.__send__ @meth, *@args, **@kwd, &block end - private :enumerator_block_call + private :__enumerator_block_call ## # call-seq: @@ -574,7 +586,7 @@ class Enumerator # # Examples of usage: # - # Enumerator.produce(1, &:succ) # => enumerator of 1, 2, 3, 4, .... + # Enumerator.produce(1, &:succ) # => enumerator of 1, 2, 3, 4, ... # # Enumerator.produce { rand(10) } # => infinite random number sequence # diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-errno/src/errno.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-errno/src/errno.c index 97132b4b53..b2059f4656 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-errno/src/errno.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-errno/src/errno.c @@ -265,7 +265,8 @@ mrb_sce_errno(mrb_state *mrb, mrb_value self) sym = MRB_SYM(Errno); if (mrb_const_defined_at(mrb, mrb_obj_value(c), sym)) { return mrb_const_get(mrb, mrb_obj_value(c), sym); - } else { + } + else { sym = MRB_SYM(errno); return mrb_attr_get(mrb, self, sym); } @@ -296,11 +297,9 @@ mrb_sce_sys_fail(mrb_state *mrb, mrb_value cls) void mrb_mruby_errno_gem_init(mrb_state *mrb) { - struct RClass *e, *eno, *sce, *ste; + struct RClass *e, *eno, *sce; - ste = mrb->eStandardError_class; - - sce = mrb_define_class(mrb, "SystemCallError", ste); + sce = mrb_define_class(mrb, "SystemCallError", E_STANDARD_ERROR); mrb_define_class_method(mrb, sce, "_sys_fail", mrb_sce_sys_fail, MRB_ARGS_REQ(1)); mrb_define_method(mrb, sce, "errno", mrb_sce_errno, MRB_ARGS_NONE()); mrb_define_method(mrb, sce, "initialize", mrb_sce_init_m, MRB_ARGS_ARG(1, 1)); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/mrbgem.rake index cb8835b324..d2986fd3b9 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/mrbgem.rake @@ -4,4 +4,7 @@ MRuby::Gem::Specification.new('mruby-eval') do |spec| spec.summary = 'standard Kernel#eval method' add_dependency 'mruby-compiler', :core => 'mruby-compiler' + add_dependency 'mruby-binding', :core => 'mruby-binding' + spec.add_test_dependency('mruby-metaprog', :core => 'mruby-metaprog') + spec.add_test_dependency('mruby-method', :core => 'mruby-method') end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/src/eval.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/src/eval.c index ff65b0fa11..fe16458226 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/src/eval.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/src/eval.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -9,10 +10,19 @@ #include #include +/* provided by mruby-binding */ +mrb_bool mrb_binding_p(mrb_state *mrb, mrb_value binding); +const struct RProc * mrb_binding_extract_proc(mrb_state *mrb, mrb_value binding); +struct REnv * mrb_binding_extract_env(mrb_state *mrb, mrb_value binding); + +/* provided by mruby-compiler */ +typedef mrb_bool mrb_parser_foreach_top_variable_func(mrb_state *mrb, mrb_sym sym, void *user); +void mrb_parser_foreach_top_variable(mrb_state *mrb, struct mrb_parser_state *p, mrb_parser_foreach_top_variable_func *func, void *user); + static struct RProc* create_proc_from_string(mrb_state *mrb, const char *s, mrb_int len, mrb_value binding, const char *file, mrb_int line) { - mrbc_context *cxt; + mrb_ccontext *cxt; struct mrb_parser_state *p; struct RProc *proc; const struct RProc *scope; @@ -22,22 +32,16 @@ create_proc_from_string(mrb_state *mrb, const char *s, mrb_int len, mrb_value bi struct mrb_context *c = mrb->c; if (!mrb_nil_p(binding)) { - mrb_value scope_obj; - if (!mrb_class_defined_id(mrb, MRB_SYM(Binding)) - || !mrb_obj_is_kind_of(mrb, binding, mrb_class_get_id(mrb, MRB_SYM(Binding)))) { + if (!mrb_binding_p(mrb, binding)) { mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %C (expected binding)", - mrb_obj_class(mrb, binding)); + mrb_obj_class(mrb, binding)); } - scope_obj = mrb_iv_get(mrb, binding, MRB_SYM(proc)); - mrb_check_type(mrb, scope_obj, MRB_TT_PROC); - scope = mrb_proc_ptr(scope_obj); + scope = mrb_binding_extract_proc(mrb, binding); if (MRB_PROC_CFUNC_P(scope)) { e = NULL; } else { - mrb_value env = mrb_iv_get(mrb, binding, MRB_SYM(env)); - mrb_check_type(mrb, env, MRB_TT_ENV); - e = (struct REnv *)mrb_obj_ptr(env); + e = mrb_binding_extract_env(mrb, binding); mrb_assert(e != NULL); } } @@ -56,10 +60,10 @@ create_proc_from_string(mrb_state *mrb, const char *s, mrb_int len, mrb_value bi file = "(eval)"; } - cxt = mrbc_context_new(mrb); + cxt = mrb_ccontext_new(mrb); cxt->lineno = (uint16_t)line; - mrbc_filename(mrb, cxt, file); + mrb_ccontext_filename(mrb, cxt, file); cxt->capture_errors = TRUE; cxt->no_optimize = TRUE; cxt->upper = scope && MRB_PROC_CFUNC_P(scope) ? NULL : scope; @@ -68,7 +72,7 @@ create_proc_from_string(mrb_state *mrb, const char *s, mrb_int len, mrb_value bi /* only occur when memory ran out */ if (!p) { - mrbc_context_free(mrb, cxt); + mrb_ccontext_free(mrb, cxt); mrb_raise(mrb, E_RUNTIME_ERROR, "Failed to create parser state (out of memory)"); } @@ -76,7 +80,7 @@ create_proc_from_string(mrb_state *mrb, const char *s, mrb_int len, mrb_value bi /* parse error */ mrb_value str; - mrbc_context_free(mrb, cxt); + mrb_ccontext_free(mrb, cxt); if (!p->error_buffer[0].message) { mrb_parser_free(p); mrb_raise(mrb, E_SYNTAX_ERROR, "compile error"); @@ -100,7 +104,7 @@ create_proc_from_string(mrb_state *mrb, const char *s, mrb_int len, mrb_value bi if (proc == NULL) { /* codegen error */ mrb_parser_free(p); - mrbc_context_free(mrb, cxt); + mrb_ccontext_free(mrb, cxt); mrb_raise(mrb, E_SCRIPT_ERROR, "codegen error"); } if (c->ci > c->cibase) { @@ -130,7 +134,7 @@ create_proc_from_string(mrb_state *mrb, const char *s, mrb_int len, mrb_value bi /* mrb_codedump_all(mrb, proc); */ mrb_parser_free(p); - mrbc_context_free(mrb, cxt); + mrb_ccontext_free(mrb, cxt); return proc; } @@ -146,6 +150,108 @@ exec_irep(mrb_state *mrb, mrb_value self, struct RProc *proc) return mrb_exec_irep(mrb, self, proc); } +static void +binding_eval_error_check(mrb_state *mrb, struct mrb_parser_state *p, const char *file) +{ + if (!p) { + mrb_raise(mrb, E_RUNTIME_ERROR, "Failed to create parser state (out of memory)"); + } + + if (0 < p->nerr) { + mrb_value str; + + if (file) { + str = mrb_format(mrb, "file %s line %d: %s", + file, + p->error_buffer[0].lineno, + p->error_buffer[0].message); + } + else { + str = mrb_format(mrb, "line %d: %s", + p->error_buffer[0].lineno, + p->error_buffer[0].message); + } + mrb_exc_raise(mrb, mrb_exc_new_str(mrb, E_SYNTAX_ERROR, str)); + } +} + +#define LV_BUFFERS 8 + +struct expand_lvspace { + mrb_irep *irep; + struct REnv *env; + int numvar; + mrb_sym syms[LV_BUFFERS]; +}; + +static mrb_bool +expand_lvspace(mrb_state *mrb, mrb_sym sym, void *user) +{ + struct expand_lvspace *p = (struct expand_lvspace*)user; + mrb_int symlen; + const char *symname = mrb_sym_name_len(mrb, sym, &symlen); + + if (symname && symlen > 0) { + if (symname[0] != '&' && symname[0] != '*') { + p->syms[p->numvar++] = sym; + if (p->numvar >= LV_BUFFERS) { + mrb_proc_merge_lvar(mrb, p->irep, p->env, p->numvar, p->syms, NULL); + p->numvar = 0; + } + } + } + + return TRUE; +} + +struct binding_eval_prepare_body { + mrb_value binding; + const char *file; + mrb_ccontext *cxt; + struct mrb_parser_state *pstate; +}; + +static mrb_value +binding_eval_prepare_body(mrb_state *mrb, void *opaque) +{ + struct binding_eval_prepare_body *p = (struct binding_eval_prepare_body*)opaque; + + const struct RProc *proc = mrb_binding_extract_proc(mrb, p->binding); + mrb_assert(!MRB_PROC_CFUNC_P(proc)); + p->cxt->upper = proc; + binding_eval_error_check(mrb, p->pstate, p->file); + + struct expand_lvspace args = { + (mrb_irep*)proc->body.irep, + mrb_binding_extract_env(mrb, p->binding), + 0, + { 0 } + }; + mrb_parser_foreach_top_variable(mrb, p->pstate, expand_lvspace, &args); + if (args.numvar > 0) { + mrb_proc_merge_lvar(mrb, args.irep, args.env, args.numvar, args.syms, NULL); + } + + return mrb_nil_value(); +} + +static void +binding_eval_prepare(mrb_state *mrb, mrb_value binding, const char *expr, mrb_int exprlen, const char *file) +{ + struct binding_eval_prepare_body d = { binding }; + + d.cxt = mrb_ccontext_new(mrb); + d.file = mrb_ccontext_filename(mrb, d.cxt, file ? file : "(eval)"); + d.cxt->capture_errors = TRUE; + d.pstate = mrb_parse_nstring(mrb, expr, exprlen, d.cxt); + + mrb_bool error; + mrb_value ret = mrb_protect_error(mrb, binding_eval_prepare_body, &d, &error); + if (d.pstate) mrb_parser_free(d.pstate); + if (d.cxt) mrb_ccontext_free(mrb, d.cxt); + if (error) mrb_exc_raise(mrb, ret); +} + static mrb_value f_eval(mrb_state *mrb, mrb_value self) { @@ -158,6 +264,9 @@ f_eval(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "s|ozi", &s, &len, &binding, &file, &line); + if (!mrb_nil_p(binding)) { + binding_eval_prepare(mrb, binding, s, len, file); + } proc = create_proc_from_string(mrb, s, len, binding, file, line); if (!mrb_nil_p(binding)) { self = mrb_iv_get(mrb, binding, MRB_SYM(recv)); @@ -214,6 +323,22 @@ f_class_eval(mrb_state *mrb, mrb_value self) } } +static mrb_value +mrb_binding_eval(mrb_state *mrb, mrb_value binding) +{ + mrb_callinfo *ci = mrb->c->ci; + int argc = ci->n; + mrb_value *argv = ci->stack + 1; + + if (argc < 15) { + argv[0] = mrb_ary_new_from_values(mrb, argc, argv); + argv[1] = argv[argc]; /* copy block */ + ci->n = 15; + } + mrb_ary_splice(mrb, argv[0], 1, 0, binding); /* insert binding as 2nd argument */ + return f_eval(mrb, binding); +} + void mrb_mruby_eval_gem_init(mrb_state* mrb) { @@ -221,6 +346,9 @@ mrb_mruby_eval_gem_init(mrb_state* mrb) mrb_define_method_id(mrb, mrb_class_get_id(mrb, MRB_SYM(BasicObject)), MRB_SYM(instance_eval), f_instance_eval, MRB_ARGS_OPT(3)|MRB_ARGS_BLOCK()); mrb_define_method_id(mrb, mrb_class_get_id(mrb, MRB_SYM(Module)), MRB_SYM(module_eval), f_class_eval, MRB_ARGS_OPT(3)|MRB_ARGS_BLOCK()); mrb_define_method_id(mrb, mrb_class_get_id(mrb, MRB_SYM(Module)), MRB_SYM(class_eval), f_class_eval, MRB_ARGS_OPT(3)|MRB_ARGS_BLOCK()); + + struct RClass *binding = mrb_class_get_id(mrb, MRB_SYM(Binding)); + mrb_define_method(mrb, binding, "eval", mrb_binding_eval, MRB_ARGS_ANY()); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/test/binding.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/test/binding.rb new file mode 100644 index 0000000000..1a470329b5 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-eval/test/binding.rb @@ -0,0 +1,81 @@ +assert("Binding#eval") do + b = nil + 1.times { x, y, z = 1, 2, 3; [x,y,z]; b = binding } + assert_equal([1, 2, 3], b.eval("[x, y, z]")) + here = self + assert_equal(here, b.eval("self")) +end + +assert("Binding#local_variables") do + block = Proc.new do |a| + b = 1 + binding + end + bind = block.call(0) + assert_equal [:a, :b, :bind, :block], bind.local_variables.sort + bind.eval("x = 2") + assert_equal [:a, :b, :bind, :block, :x], bind.local_variables.sort +end + +assert("Binding#local_variable_set") do + bind = binding + 1.times { + assert_equal(9, bind.local_variable_set(:x, 9)) + assert_equal(9, bind.eval("x")) + assert_equal([:bind, :x], bind.eval("local_variables.sort")) + } +end + +assert("Binding#local_variable_get") do + bind = binding + x = 1 + 1.times { + y = 2 + assert_equal(1, bind.local_variable_get(:x)) + x = 10 + assert_equal(10, bind.local_variable_get(:x)) + assert_raise(NameError) { bind.local_variable_get(:y) } + bind.eval("z = 3") + assert_equal(3, bind.local_variable_get(:z)) + bind.eval("y = 5") + assert_equal(5, bind.local_variable_get(:y)) + assert_equal(2, y) + } +end + +assert "Binding#eval with Binding.new via UnboundMethod" do + assert_raise(NoMethodError) { Class.instance_method(:new).bind_call(Binding) } +end + +assert "Binding#eval with Binding.new via Method" do + # The following test is OK if SIGSEGV does not occur + cx = Class.new(Binding) + cx.define_singleton_method(:allocate, &Object.method(:allocate)) + Class.instance_method(:new).bind_call(cx).eval("") + + assert_true true +end + +assert "access local variables into procs" do + bx = binding + block = bx.eval("a = 1; proc { a }") + bx.eval("a = 2") + assert_equal 2, block.call +end + +assert "Binding#eval on another target class" do + obj = Object.new + Module.new do + self::BINDING = obj.instance_eval { binding } + + def self.eval(code) + self::BINDING.eval code + end + + self.eval "def self.m1; :m1; end" + self.eval "def m2; :m2; end" + end + + assert_equal :m1, obj.m1 + assert_equal :m2, obj.m2 +end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-exit/src/mruby-exit.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-exit/src/mruby-exit.c index 658d188e67..24311f12f1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-exit/src/mruby-exit.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-exit/src/mruby-exit.c @@ -72,7 +72,7 @@ f_exit_bang(mrb_state *mrb, mrb_value self) void mrb_mruby_exit_gem_init(mrb_state* mrb) { - mrb_define_class_id(mrb, MRB_SYM(SystemExit), mrb->eException_class); + mrb_define_class_id(mrb, MRB_SYM(SystemExit), E_EXCEPTION); mrb_define_method_id(mrb, mrb->kernel_module, MRB_SYM(exit), f_exit, MRB_ARGS_OPT(1)); mrb_define_method_id(mrb, mrb->kernel_module, MRB_SYM_B(exit), f_exit_bang, MRB_ARGS_OPT(1)); } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/src/fiber.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/src/fiber.c index 33913c1085..baddf65cee 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/src/fiber.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/src/fiber.c @@ -1,8 +1,12 @@ #include #include #include +#include #include +#include #include +#include +#include #define fiber_ptr(o) ((struct RFiber*)mrb_ptr(o)) @@ -11,6 +15,66 @@ /* copied from vm.c */ #define CINFO_RESUMED 3 +static mrb_value +fiber_init_fiber(mrb_state *mrb, struct RFiber *f, const struct RProc *p) +{ + static const struct mrb_context mrb_context_zero = { 0 }; + struct mrb_context *c; + mrb_callinfo *ci; + size_t slen; + + if (f->cxt) { + mrb_raise(mrb, E_RUNTIME_ERROR, "cannot initialize twice"); + } + if (MRB_PROC_CFUNC_P(p)) { + mrb_raise(mrb, E_FIBER_ERROR, "tried to create Fiber from C defined method"); + } + + c = (struct mrb_context*)mrb_malloc(mrb, sizeof(struct mrb_context)); + *c = mrb_context_zero; + f->cxt = c; + + /* initialize VM stack */ + slen = FIBER_STACK_INIT_SIZE; + if (p->body.irep->nregs > slen) { + slen += p->body.irep->nregs; + } + c->stbase = (mrb_value*)mrb_malloc(mrb, slen*sizeof(mrb_value)); + c->stend = c->stbase + slen; + + { + mrb_value *p = c->stbase; + mrb_value *pend = c->stend; + + while (p < pend) { + SET_NIL_VALUE(*p); + p++; + } + } + + /* copy receiver from a block */ + c->stbase[0] = mrb->c->ci->stack[0]; + + /* initialize callinfo stack */ + c->cibase = (mrb_callinfo*)mrb_calloc(mrb, FIBER_CI_INIT_SIZE, sizeof(mrb_callinfo)); + c->ciend = c->cibase + FIBER_CI_INIT_SIZE; + c->ci = c->cibase; + + /* adjust return callinfo */ + ci = c->ci; + mrb_vm_ci_target_class_set(ci, MRB_PROC_TARGET_CLASS(p)); + mrb_vm_ci_proc_set(ci, p); + mrb_field_write_barrier(mrb, (struct RBasic*)f, (struct RBasic*)p); + ci->stack = c->stbase; + ci[1] = ci[0]; + c->ci++; /* push dummy callinfo */ + + c->fib = f; + c->status = MRB_FIBER_CREATED; + + return mrb_obj_value(f); +} + /* * call-seq: * Fiber.new{...} -> obj @@ -66,67 +130,9 @@ static mrb_value fiber_init(mrb_state *mrb, mrb_value self) { - static const struct mrb_context mrb_context_zero = { 0 }; - struct RFiber *f = fiber_ptr(self); - struct mrb_context *c; - struct RProc *p; - mrb_callinfo *ci; mrb_value blk; - size_t slen; - mrb_get_args(mrb, "&!", &blk); - - if (f->cxt) { - mrb_raise(mrb, E_RUNTIME_ERROR, "cannot initialize twice"); - } - p = mrb_proc_ptr(blk); - if (MRB_PROC_CFUNC_P(p)) { - mrb_raise(mrb, E_FIBER_ERROR, "tried to create Fiber from C defined method"); - } - - c = (struct mrb_context*)mrb_malloc(mrb, sizeof(struct mrb_context)); - *c = mrb_context_zero; - f->cxt = c; - - /* initialize VM stack */ - slen = FIBER_STACK_INIT_SIZE; - if (p->body.irep->nregs > slen) { - slen += p->body.irep->nregs; - } - c->stbase = (mrb_value *)mrb_malloc(mrb, slen*sizeof(mrb_value)); - c->stend = c->stbase + slen; - - { - mrb_value *p = c->stbase; - mrb_value *pend = c->stend; - - while (p < pend) { - SET_NIL_VALUE(*p); - p++; - } - } - - /* copy receiver from a block */ - c->stbase[0] = mrb->c->ci->stack[0]; - - /* initialize callinfo stack */ - c->cibase = (mrb_callinfo *)mrb_calloc(mrb, FIBER_CI_INIT_SIZE, sizeof(mrb_callinfo)); - c->ciend = c->cibase + FIBER_CI_INIT_SIZE; - c->ci = c->cibase; - - /* adjust return callinfo */ - ci = c->ci; - mrb_vm_ci_target_class_set(ci, MRB_PROC_TARGET_CLASS(p)); - mrb_vm_ci_proc_set(ci, p); - mrb_field_write_barrier(mrb, (struct RBasic*)mrb_obj_ptr(self), (struct RBasic*)p); - ci->stack = c->stbase; - ci[1] = ci[0]; - c->ci++; /* push dummy callinfo */ - - c->fib = f; - c->status = MRB_FIBER_CREATED; - - return self; + return fiber_init_fiber(mrb, fiber_ptr(self), mrb_proc_ptr(blk)); } static struct mrb_context* @@ -164,6 +170,17 @@ fiber_check_cfunc(mrb_state *mrb, struct mrb_context *c) } } +static void +fiber_check_cfunc_recursive(mrb_state *mrb, struct mrb_context *c) +{ + for (;; c = c->prev) { + fiber_check_cfunc(mrb, c); + if (c == mrb->root_c || !c->prev) { + break; + } + } +} + static void fiber_switch_context(mrb_state *mrb, struct mrb_context *c) { @@ -257,19 +274,29 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr } } c->cibase->n = (uint8_t)len; - value = c->stbase[0] = MRB_PROC_ENV(c->cibase->proc)->stack[0]; + struct REnv *env = MRB_PROC_ENV(c->cibase->proc); + if (env && env->stack) { + value = env->stack[0]; + } + else { + value = mrb_top_self(mrb); + } + c->stbase[0] = value; } else { value = fiber_result(mrb, a, len); if (vmexec) { + if (c->ci > c->cibase) c->ci--; /* pop dummy callinfo */ c->ci[1].stack[0] = value; } } if (vmexec) { + int cci = old_c->ci->cci; c->vmexec = TRUE; value = mrb_vm_exec(mrb, c->ci->proc, c->ci->pc); mrb->c = old_c; + old_c->ci->cci = cci; /* restore values as they may have changed in Fiber.yield */ } else { MARK_CONTEXT_MODIFY(c); @@ -291,9 +318,6 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr * to the next Fiber.yield statement inside the fiber's block * or to the block value if it runs to completion without any * Fiber.yield - * - * This method cannot be called from C using mrb_funcall(). - * Use mrb_fiber_resume() function instead. */ static mrb_value fiber_resume(mrb_state *mrb, mrb_value self) @@ -302,7 +326,6 @@ fiber_resume(mrb_state *mrb, mrb_value self) mrb_int len; mrb_bool vmexec = FALSE; - fiber_check_cfunc(mrb, mrb->c); mrb_get_args(mrb, "*!", &a, &len); if (mrb->c->ci->cci > 0) { vmexec = TRUE; @@ -342,6 +365,62 @@ fiber_eq(mrb_state *mrb, mrb_value self) return mrb_bool_value(fiber_ptr(self) == fiber_ptr(other)); } +/* + * call-seq: + * fiber.to_s -> string + * fiber.inspect -> string + * + * Returns fiber object information as a string. + * + * If the file information cannot be obtained, it is replaced with `(unknown):0`. + * Also, if the fiber is terminated, it will be replaced in the same way (mruby limitation). + */ +static mrb_value +fiber_to_s(mrb_state *mrb, mrb_value self) +{ + fiber_check(mrb, self); + const struct RFiber *f = fiber_ptr(self); + + mrb_value s = mrb_str_new_lit(mrb, "#<"); + mrb_value cname = mrb_class_path(mrb, mrb_class_real(mrb_class(mrb, self))); + if (mrb_nil_p(cname)) { + mrb_str_cat_lit(mrb, s, "Fiber:"); + } + else { + mrb_str_cat_str(mrb, s, cname); + mrb_str_cat_lit(mrb, s, ":"); + } + mrb_str_cat_str(mrb, s, mrb_ptr_to_str(mrb, mrb_ptr(self))); + + const char *file; + int32_t line; + const struct RProc *p = f->cxt->cibase->proc; + if (f->cxt->status != MRB_FIBER_TERMINATED && !MRB_PROC_CFUNC_P(p) && !MRB_PROC_ALIAS_P(p) && + mrb_debug_get_position(mrb, p->body.irep, 0, &line, &file)) { + mrb_str_cat_lit(mrb, s, " "); + mrb_str_cat_cstr(mrb, s, file); + mrb_str_cat_lit(mrb, s, ":"); + char buf[16]; + mrb_str_cat_cstr(mrb, s, mrb_int_to_cstr(buf, sizeof(buf), line, 10)); + } + + const char *st; + switch (fiber_ptr(self)->cxt->status) { + case MRB_FIBER_CREATED: st = "created"; break; + case MRB_FIBER_RUNNING: st = "resumed"; break; + case MRB_FIBER_RESUMED: st = "suspended by resuming"; break; + case MRB_FIBER_SUSPENDED: st = "suspended"; break; + case MRB_FIBER_TRANSFERRED: st = "suspended"; break; + case MRB_FIBER_TERMINATED: st = "terminated"; break; + default: st = "UNKNOWN STATUS (BUG)"; break; + } + mrb_str_cat_lit(mrb, s, " ("); + mrb_str_cat_cstr(mrb, s, st); + mrb_str_cat_lit(mrb, s, ")>"); + + return s; +} + /* * call-seq: * fiber.transfer(args, ...) -> obj @@ -361,7 +440,7 @@ fiber_transfer(mrb_state *mrb, mrb_value self) const mrb_value* a; mrb_int len; - fiber_check_cfunc(mrb, mrb->c); + fiber_check_cfunc_recursive(mrb, mrb->c); mrb_get_args(mrb, "*!", &a, &len); if (c->status == MRB_FIBER_RESUMED) { @@ -404,7 +483,6 @@ mrb_fiber_yield(mrb_state *mrb, mrb_int len, const mrb_value *a) if (c->vmexec) { c->vmexec = FALSE; mrb->c->ci->cci = CINFO_RESUMED; - c->ci--; /* pop callinfo for yield */ } MARK_CONTEXT_MODIFY(mrb->c); return fiber_result(mrb, a, len); @@ -454,6 +532,18 @@ fiber_current(mrb_state *mrb, mrb_value self) return mrb_obj_value(mrb->c->fib); } +MRB_API mrb_value +mrb_fiber_new(mrb_state *mrb, const struct RProc *p) +{ + struct RClass *c = mrb_class_get_id(mrb, MRB_SYM(Fiber)); + if (MRB_INSTANCE_TT(c) != MRB_TT_FIBER) { + mrb_raise(mrb, E_TYPE_ERROR, "wrong Fiber class"); + } + + struct RFiber *f = MRB_OBJ_ALLOC(mrb, MRB_TT_FIBER, c); + return fiber_init_fiber(mrb, f, p); +} + void mrb_mruby_fiber_gem_init(mrb_state* mrb) { @@ -467,11 +557,13 @@ mrb_mruby_fiber_gem_init(mrb_state* mrb) mrb_define_method(mrb, c, "transfer", fiber_transfer, MRB_ARGS_ANY()); mrb_define_method(mrb, c, "alive?", fiber_alive_p, MRB_ARGS_NONE()); mrb_define_method(mrb, c, "==", fiber_eq, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, c, "to_s", fiber_to_s, MRB_ARGS_NONE()); + mrb_define_alias(mrb, c, "inspect", "to_s"); mrb_define_class_method(mrb, c, "yield", fiber_yield, MRB_ARGS_ANY()); mrb_define_class_method(mrb, c, "current", fiber_current, MRB_ARGS_NONE()); - mrb_define_class(mrb, "FiberError", mrb->eStandardError_class); + mrb_define_class(mrb, "FiberError", E_STANDARD_ERROR); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fiber.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fiber.rb index 64b9d8175c..ea541acf37 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fiber.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fiber.rb @@ -1,204 +1,210 @@ -assert('Fiber.new') do - f = Fiber.new{} - assert_kind_of Fiber, f -end +begin + $fiber_test_activity = __FILE__ -assert('Fiber#resume') do - f = Fiber.new{|x| x } - assert_equal 2, f.resume(2) -end - -assert('Fiber#transfer') do - ary = [] - f2 = nil - f1 = Fiber.new{ - ary << f2.transfer(:foo) - :ok - } - f2 = Fiber.new{ - ary << f1.transfer(:baz) - :ng - } - assert_equal(:ok, f1.transfer) - assert_equal([:baz], ary) - assert_false f1.alive? -end - -assert('Fiber#alive?') do - f = Fiber.new{ Fiber.yield } - f.resume - assert_true f.alive? - f.resume - assert_false f.alive? -end - -assert('Fiber#==') do - root = Fiber.current - assert_equal root, root - assert_equal root, Fiber.current - assert_false root != Fiber.current - f = Fiber.new { - assert_false root == Fiber.current - } - f.resume - assert_false f == root - assert_true f != root -end - -assert('Fiber.yield') do - f = Fiber.new{|x| Fiber.yield x } - assert_equal 3, f.resume(3) - assert_true f.alive? -end - -assert('FiberError') do - assert_equal StandardError, FiberError.superclass -end - -assert('Fiber iteration') do - f1 = Fiber.new{ - [1,2,3].each{|x| Fiber.yield(x)} - } - f2 = Fiber.new{ - [9,8,7].each{|x| Fiber.yield(x)} - } - a = [] - 3.times { - a << f1.resume - a << f2.resume - } - assert_equal [1,9,2,8,3,7], a -end - -assert('Fiber with splat in the block argument list') { - assert_equal([1], Fiber.new{|*x|x}.resume(1)) -} - -assert('Fiber raises on resume when dead') do - assert_raise(FiberError) do + assert('Fiber.new') do f = Fiber.new{} + assert_kind_of Fiber, f + end + + assert('Fiber#resume') do + f = Fiber.new{|x| x } + assert_equal 2, f.resume(2) + end + + assert('Fiber#transfer') do + ary = [] + f2 = nil + f1 = Fiber.new{ + ary << f2.transfer(:foo) + :ok + } + f2 = Fiber.new{ + ary << f1.transfer(:baz) + :ng + } + assert_equal(:ok, f1.transfer) + assert_equal([:baz], ary) + assert_false f1.alive? + end + + assert('Fiber#alive?') do + f = Fiber.new{ Fiber.yield } + f.resume + assert_true f.alive? f.resume assert_false f.alive? - f.resume end -end -assert('Yield raises when called on root fiber') do - assert_raise(FiberError) { Fiber.yield } -end + assert('Fiber#==') do + root = Fiber.current + assert_equal root, root + assert_equal root, Fiber.current + assert_false root != Fiber.current + f = Fiber.new { + assert_false root == Fiber.current + } + f.resume + assert_false f == root + assert_true f != root + end -assert('Double resume of Fiber') do - f1 = Fiber.new {} - f2 = Fiber.new { - f1.resume - assert_raise(FiberError) { f2.resume } - Fiber.yield 0 + assert('Fiber.yield') do + f = Fiber.new{|x| Fiber.yield x } + assert_equal 3, f.resume(3) + assert_true f.alive? + end + + assert('FiberError') do + assert_equal StandardError, FiberError.superclass + end + + assert('Fiber iteration') do + f1 = Fiber.new{ + [1,2,3].each{|x| Fiber.yield(x)} + } + f2 = Fiber.new{ + [9,8,7].each{|x| Fiber.yield(x)} + } + a = [] + 3.times { + a << f1.resume + a << f2.resume + } + assert_equal [1,9,2,8,3,7], a + end + + assert('Fiber with splat in the block argument list') { + assert_equal([1], Fiber.new{|*x|x}.resume(1)) } - assert_equal 0, f2.resume - f2.resume - assert_false f1.alive? - assert_false f2.alive? -end -assert('Recursive resume of Fiber') do - f1, f2 = nil, nil - f1 = Fiber.new { assert_raise(FiberError) { f2.resume } } - f2 = Fiber.new { - f1.resume - Fiber.yield 0 - } - f3 = Fiber.new { + assert('Fiber raises on resume when dead') do + assert_raise(FiberError) do + f = Fiber.new{} + f.resume + assert_false f.alive? + f.resume + end + end + + assert('Yield raises when called on root fiber') do + assert_raise(FiberError) { Fiber.yield } + end + + assert('Double resume of Fiber') do + f1 = Fiber.new {} + f2 = Fiber.new { + f1.resume + assert_raise(FiberError) { f2.resume } + Fiber.yield 0 + } + assert_equal 0, f2.resume f2.resume - } - assert_equal 0, f3.resume - f2.resume - assert_false f1.alive? - assert_false f2.alive? - assert_false f3.alive? -end + assert_false f1.alive? + assert_false f2.alive? + end -assert('Root fiber resume') do - root = Fiber.current - assert_raise(FiberError) { root.resume } - f = Fiber.new { + assert('Recursive resume of Fiber') do + f1, f2 = nil, nil + f1 = Fiber.new { assert_raise(FiberError) { f2.resume } } + f2 = Fiber.new { + f1.resume + Fiber.yield 0 + } + f3 = Fiber.new { + f2.resume + } + assert_equal 0, f3.resume + f2.resume + assert_false f1.alive? + assert_false f2.alive? + assert_false f3.alive? + end + + assert('Root fiber resume') do + root = Fiber.current assert_raise(FiberError) { root.resume } - } - f.resume - assert_false f.alive? -end - -assert('Fiber without block') do - assert_raise(ArgumentError) { Fiber.new } -end - - -assert('Transfer to self.') do - result = [] - f = Fiber.new { result << :start; f.transfer; result << :end } - f.transfer - assert_equal [:start, :end], result - - result = [] - f = Fiber.new { result << :start; f.transfer; result << :end } - f.resume - assert_equal [:start, :end], result -end - -assert('Resume transferred fiber') do - f = Fiber.new { - assert_raise(FiberError) { f.resume } - } - f.transfer -end - -assert('Root fiber transfer.') do - result = nil - root = Fiber.current - f = Fiber.new { - result = :ok - root.transfer - } - f.transfer - assert_true f.alive? - assert_equal :ok, result -end - -assert('Break nested fiber with root fiber transfer') do - root = Fiber.current - - result = nil - f2 = nil - f1 = Fiber.new { - root.transfer(f2.transfer) - result = :f1 - } - f2 = Fiber.new { - result = :to_root - root.transfer :from_f2 - result = :f2 - } - assert_equal :from_f2, f1.transfer - assert_equal :to_root, result - assert_equal :f2, f2.transfer - assert_equal :f2, result - assert_false f2.alive? - assert_equal nil, f1.transfer - assert_equal :f1, f1.transfer - assert_equal :f1, result - assert_false f1.alive? -end - -assert('CRuby Fiber#transfer test.') do - ary = [] - f2 = nil - f1 = Fiber.new{ - ary << f2.transfer(:foo) - :ok - } - f2 = Fiber.new{ - ary << f1.transfer(:baz) - :ng - } - assert_equal :ok, f1.transfer - assert_equal [:baz], ary + f = Fiber.new { + assert_raise(FiberError) { root.resume } + } + f.resume + assert_false f.alive? + end + + assert('Fiber without block') do + assert_raise(ArgumentError) { Fiber.new } + end + + + assert('Transfer to self.') do + result = [] + f = Fiber.new { result << :start; f.transfer; result << :end } + f.transfer + assert_equal [:start, :end], result + + result = [] + f = Fiber.new { result << :start; f.transfer; result << :end } + f.resume + assert_equal [:start, :end], result + end + + assert('Resume transferred fiber') do + f = Fiber.new { + assert_raise(FiberError) { f.resume } + } + f.transfer + end + + assert('Root fiber transfer.') do + result = nil + root = Fiber.current + f = Fiber.new { + result = :ok + root.transfer + } + f.transfer + assert_true f.alive? + assert_equal :ok, result + end + + assert('Break nested fiber with root fiber transfer') do + root = Fiber.current + + result = nil + f2 = nil + f1 = Fiber.new { + root.transfer(f2.transfer) + result = :f1 + } + f2 = Fiber.new { + result = :to_root + root.transfer :from_f2 + result = :f2 + } + assert_equal :from_f2, f1.transfer + assert_equal :to_root, result + assert_equal :f2, f2.transfer + assert_equal :f2, result + assert_false f2.alive? + assert_equal nil, f1.transfer + assert_equal :f1, f1.transfer + assert_equal :f1, result + assert_false f1.alive? + end + + assert('CRuby Fiber#transfer test.') do + ary = [] + f2 = nil + f1 = Fiber.new{ + ary << f2.transfer(:foo) + :ok + } + f2 = Fiber.new{ + ary << f1.transfer(:baz) + :ng + } + assert_equal :ok, f1.transfer + assert_equal [:baz], ary + end +ensure + $fiber_test_activity = nil end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fiber2.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fiber2.rb new file mode 100644 index 0000000000..a6ff8a791d --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fiber2.rb @@ -0,0 +1,155 @@ +# This file tests fiber switching crossing C functions + +unless RUBY_ENGINE == "mruby" + class Fiber + alias resume_by_c_func resume + alias resume_by_c_method resume + + class << self + alias yield_by_c_func yield + + def yield_by_c_method(*args) + raise FiberError, "ycan't cross C function boundary" + end + end + end + + def Proc.c_tunnel + yield + end +end + +begin + $fiber_test_activity = __FILE__ + + assert('Call Fiber#resume nested with C') do + assert_equal "ok1", Fiber.new { Fiber.new { "ok1" }.resume_by_c_func }.resume_by_c_func + assert_equal "ok2", Fiber.new { Fiber.new { "ok2" }.resume_by_c_method }.resume_by_c_func + assert_equal "ok3", Fiber.new { Fiber.new { "ok3" }.resume_by_c_func }.resume_by_c_method + assert_equal "ok4", Fiber.new { Fiber.new { "ok4" }.resume_by_c_method }.resume_by_c_method + assert_equal "ok5", Fiber.new { Proc.c_tunnel { Fiber.new { "ok5" }.resume_by_c_func } }.resume_by_c_func + assert_equal "ok6", Fiber.new { Proc.c_tunnel { Fiber.new { "ok6" }.resume_by_c_method } }.resume_by_c_func + assert_equal "ok7", Fiber.new { Proc.c_tunnel { Fiber.new { "ok7" }.resume_by_c_func } }.resume_by_c_method + assert_equal "ok8", Fiber.new { Proc.c_tunnel { Fiber.new { "ok8" }.resume_by_c_method } }.resume_by_c_method + assert_equal "ok9", Fiber.new { Proc.c_tunnel { Fiber.new { "ok9" }.resume } }.resume_by_c_func + assert_equal "ok10", Fiber.new { Proc.c_tunnel { Fiber.new { "ok10" }.resume } }.resume_by_c_method + end + + assert('Call Fiber#resume and Fiber.yield mixed with C.') do + assert_equal 1, Fiber.new { Fiber.yield 1 }.resume_by_c_func + assert_equal 2, Fiber.new { Fiber.yield 2 }.resume_by_c_method + assert_equal 3, Fiber.new { Fiber.yield_by_c_func 3 }.resume + assert_equal 4, Fiber.new { Fiber.yield_by_c_func 4 }.resume_by_c_func + assert_equal 5, Fiber.new { Fiber.yield_by_c_func 5 }.resume_by_c_method + assert_raise(FiberError) { Fiber.new { Fiber.yield_by_c_method "bad" }.resume } + assert_raise(FiberError) { Fiber.new { Fiber.yield_by_c_method "bad" }.resume_by_c_func } + assert_raise(FiberError) { Fiber.new { Fiber.yield_by_c_method "bad" }.resume_by_c_method } + + result = [] + f1 = Fiber.new { result << Fiber.new { Fiber.yield 1; "bad" }.resume_by_c_func; 2 } + f2 = Fiber.new { result << f1.resume; 3 } + result << f2.resume + assert_equal [1, 2, 3], result + + f1 = Fiber.new { + -> { + Fiber.yield 1 + Fiber.yield_by_c_func 2 + f2 = Fiber.new { + -> { + Fiber.yield_by_c_func 3 + Fiber.yield 4 + Fiber.yield_by_c_func 5 + Fiber.yield 6 + }.call + 7 + } + Fiber.yield f2.resume_by_c_func + Fiber.yield f2.resume + Fiber.yield f2.resume_by_c_method + Fiber.yield f2.resume + Fiber.yield f2.resume_by_c_func + Fiber.yield 8 + }.call + Fiber.yield 9 + 10 + } + result = [] + 10.times { result << f1.resume } + assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], result + end + + assert('Call Fiber#resume and Fiber.yield mixed with C and raising exceptions') do + f = Fiber.new do + raise ZeroDivisionError + rescue + Fiber.yield "rescue" + "pass1" + ensure + Fiber.yield "ensure" + end + assert_equal "rescue", f.resume_by_c_method + assert_equal "ensure", f.resume_by_c_method + assert_equal "pass1", f.resume_by_c_method + assert_raise(FiberError) { f.resume_by_c_method } + + f = Fiber.new do + raise ZeroDivisionError + rescue + Fiber.yield "rescue" + "pass2" + ensure + Fiber.yield "ensure" + end + assert_equal "rescue", f.resume_by_c_func + assert_equal "ensure", f.resume_by_c_func + assert_equal "pass2", f.resume_by_c_func + assert_raise(FiberError) { f.resume_by_c_func } + + f2 = Fiber.new do + -> do + Fiber.yield 1 + raise "3" + ensure + Fiber.yield 2 + end.call + "NOT REACH 1" + end + f1 = Fiber.new do + Fiber.yield f2.resume_by_c_func + begin + Fiber.yield f2.resume + Fiber.yield f2.resume_by_c_method + Fiber.yield "NOT REACH 2" + rescue => e + Fiber.yield e.message + Fiber.yield 4 + ensure + Fiber.yield 5 + end + Fiber.yield 6 + 7 + end + result = [] + 7.times { result << f1.resume } + assert_equal [1, 2, "3", 4, 5, 6, 7], result + end + + assert('Call Fiber#transfer with C') do + assert_equal "ok1", Fiber.new { Fiber.new { "ok1" }.resume_by_c_method }.transfer + assert_equal "ok2", Fiber.new { Fiber.new { "ok2" }.resume_by_c_func }.transfer + assert_raise(FiberError) { Proc.c_tunnel { Fiber.new { "BAD!" }.transfer } } + + b = Fiber.current + a = Fiber.new { + Proc.c_tunnel { + Fiber.new { + b.transfer + }.resume + } + } + assert_raise(FiberError) { a.transfer } + end +ensure + $fiber_test_activity = nil +end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fibertest.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fibertest.c new file mode 100644 index 0000000000..69680aecbb --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-fiber/test/fibertest.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include + +static mrb_value +fiber_s_yield_by_c_func(mrb_state *mrb, mrb_value self) +{ + mrb_value a = mrb_get_arg1(mrb); + return mrb_fiber_yield(mrb, 1, &a); +} + +static mrb_value +fiber_s_yield_by_c_method(mrb_state *mrb, mrb_value self) +{ + mrb_value a = mrb_get_arg1(mrb); + return mrb_funcall_argv(mrb, self, mrb_intern_lit(mrb, "yield"), 1, &a); +} + +static mrb_value +fiber_resume_by_c_func(mrb_state *mrb, mrb_value self) +{ + int ci_index = mrb->c->ci - mrb->c->cibase; + mrb_value ret = mrb_fiber_resume(mrb, self, 0, NULL); + if (ci_index != mrb->c->ci - mrb->c->cibase) { + mrb_raisef(mrb, E_EXCEPTION, + "[BUG] INVALID CI POSITION (expected %d, but actual %d) [BUG]", + (int)ci_index, (int)(mrb->c->ci - mrb->c->cibase)); + } + return ret; +} + +static mrb_value +fiber_resume_by_c_method(mrb_state *mrb, mrb_value self) +{ + int ci_index = mrb->c->ci - mrb->c->cibase; + mrb_value ret = mrb_funcall_argv(mrb, self, mrb_intern_lit(mrb, "resume"), 0, NULL); + if (ci_index != mrb->c->ci - mrb->c->cibase) { + mrb_raisef(mrb, E_EXCEPTION, + "[BUG] INVALID CI POSITION (expected %d, but actual %d) [BUG]", + (int)ci_index, (int)(mrb->c->ci - mrb->c->cibase)); + } + return ret; +} + +static mrb_value +fiber_transfer_by_c(mrb_state *mrb, mrb_value self) +{ + return mrb_funcall_argv(mrb, self, mrb_intern_lit(mrb, "transfer"), 0, NULL); +} + +static mrb_value +proc_s_c_tunnel(mrb_state *mrb, mrb_value self) +{ + mrb_value b; + mrb_get_args(mrb, "&!", &b); + return mrb_yield_argv(mrb, b, 0, NULL); +} + +static void +check_activity(mrb_state *mrb) +{ + mrb_value act = mrb_gv_get(mrb, mrb_intern_lit(mrb, "$fiber_test_activity")); + if (mrb_test(act)) { + act = mrb_obj_as_string(mrb, act); + fprintf(stderr, "\n\t<<<%s%.*s>>>\n", + "mruby VM has an unexpected outage in ", (int)RSTRING_LEN(act), RSTRING_PTR(act)); + abort(); + } +} + +void +mrb_mruby_fiber_gem_test(mrb_state *mrb) +{ + struct RClass *fiber_class = mrb_class_get(mrb, "Fiber"); + mrb_define_class_method(mrb, fiber_class, "yield_by_c_func", fiber_s_yield_by_c_func, MRB_ARGS_ANY()); + mrb_define_class_method(mrb, fiber_class, "yield_by_c_method", fiber_s_yield_by_c_method, MRB_ARGS_ANY()); + mrb_define_method(mrb, fiber_class, "resume_by_c_func", fiber_resume_by_c_func, MRB_ARGS_NONE()); + mrb_define_method(mrb, fiber_class, "resume_by_c_method", fiber_resume_by_c_method, MRB_ARGS_NONE()); + mrb_define_method(mrb, fiber_class, "transfer_by_c", fiber_transfer_by_c, MRB_ARGS_NONE()); + + mrb_define_class_method(mrb, mrb->proc_class, "c_tunnel", proc_s_c_tunnel, MRB_ARGS_NONE() | MRB_ARGS_BLOCK()); + + mrb_gv_set(mrb, mrb_intern_lit(mrb, "$fiber_test_activity"), mrb_nil_value()); + mrb_state_atexit(mrb, check_activity); +} diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb index 5a8b53778b..11537093fc 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -113,16 +113,7 @@ class Hash # def compact! - keys = self.keys - nk = keys.select{|k| - self[k] != nil - } - return nil if (keys.size == nk.size) - h = {} - nk.each {|k| - h[k] = self[k] - } - self.replace(h) + self.__compact end ## @@ -136,12 +127,8 @@ class Hash # h #=> { a: 1, b: false, c: nil } # def compact - h = {} - self.keys.select{|k| - self[k] != nil - }.each {|k| - h[k] = self[k] - } + h=self.dup + h.__compact h end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-hash-ext/test/hash.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-hash-ext/test/hash.rb index a705af6587..60a2123eab 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-hash-ext/test/hash.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-hash-ext/test/hash.rb @@ -89,8 +89,8 @@ end assert('Hash#compact!') do h = { "cat" => "feline", "dog" => nil, "cow" => false } - h.compact! - assert_equal({ "cat" => "feline", "cow" => false }, h) + assert_equal({ "cat" => "feline", "cow" => false }, h.compact!) + assert_nil(h.compact!) end assert('Hash#fetch') do diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/README.md b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/README.md index 525785fa0e..99c48f3d68 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/README.md +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/README.md @@ -17,7 +17,7 @@ Add the line below to your build configuration. - | method | mruby-io | memo | -|----------------------------|----------|----------| +| -------------------------- | -------- | -------- | | IO.binread | | | | IO.binwrite | | | | IO.copy_stream | | | @@ -102,7 +102,7 @@ Add the line below to your build configuration. - | method | mruby-io | memo | -|-----------------------------|----------|----------| +| --------------------------- | -------- | -------- | | File.absolute_path | | | | File.atime | | | | File.basename | o | | @@ -158,14 +158,14 @@ Add the line below to your build configuration. | File.writable? | | FileTest | | File.writable_real? | | FileTest | | File.zero? | o | FileTest | -| File#atime | | | +| File#atime | o | | | File#chmod | | | | File#chown | | | -| File#ctime | | | +| File#ctime | o | | | File#flock | o | | | File#lstat | | | -| File#mtime | | | -| File#path, File#to_path | o | | +| File#mtime | o | | +| File#path | o | | | File#size | | | | File#truncate | | | diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/mrblib/file.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/mrblib/file.rb index 9398acef67..719f4e6293 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/mrblib/file.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/mrblib/file.rb @@ -11,11 +11,25 @@ class File < IO end end + def atime + t = self._atime + t && Time.at(t) + end + + def ctime + t = self._ctime + t && Time.at(t) + end + def mtime t = self._mtime t && Time.at(t) end + def inspect + "<#{self.class}:#{@path}>" + end + def self.join(*names) return "" if names.empty? @@ -199,8 +213,6 @@ class File < IO def self.path(filename) if filename.kind_of?(String) filename - elsif filename.respond_to?(:to_path) - filename.to_path else raise TypeError, "no implicit conversion of #{filename.class} into String" end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/file.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/file.c index e0957ffa69..2bfef3030f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/file.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/file.c @@ -38,7 +38,9 @@ #define GETCWD getcwd #define CHMOD(a, b) chmod(a,b) #include +#ifndef __DJGPP__ #include +#endif #include #include #endif @@ -105,7 +107,8 @@ mrb_file_s_umask(mrb_state *mrb, mrb_value klass) if (mrb_get_args(mrb, "|i", &mask) == 0) { omask = umask(0); umask(omask); - } else { + } + else { omask = umask(mask); } return mrb_fixnum_value(omask); @@ -179,7 +182,8 @@ mrb_file_dirname(mrb_state *mrb, mrb_value klass) ridx = strlen(buffer); if (ridx == 0) { strncpy(buffer, ".", 2); /* null terminated */ - } else if (ridx > 1) { + } + else if (ridx > 1) { ridx--; while (ridx > 0 && (buffer[ridx] == '/' || buffer[ridx] == '\\')) { buffer[ridx] = '\0'; /* remove last char */ @@ -275,6 +279,7 @@ mrb_file__getwd(mrb_state *mrb, mrb_value klass) mrb_value path; char buf[MAXPATHLEN], *utf8; + mrb->c->ci->mid = 0; if (GETCWD(buf, MAXPATHLEN) == NULL) { mrb_sys_fail(mrb, "getcwd(2)"); } @@ -344,6 +349,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass) char *home; mrb_value path; + mrb->c->ci->mid = 0; #ifndef _WIN32 mrb_value username; @@ -356,7 +362,8 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass) if (!mrb_file_is_absolute_path(home)) { mrb_raise(mrb, E_ARGUMENT_ERROR, "non-absolute home"); } - } else { + } + else { const char *cuser = RSTRING_CSTR(mrb, username); struct passwd *pwd = getpwnam(cuser); if (pwd == NULL) { @@ -381,7 +388,8 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass) if (!mrb_file_is_absolute_path(home)) { mrb_raise(mrb, E_ARGUMENT_ERROR, "non-absolute home"); } - } else { + } + else { return mrb_nil_value(); } home = mrb_locale_from_utf8(home, -1); @@ -391,14 +399,60 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass) #endif } +#define TIME_OVERFLOW_P(a) (sizeof(time_t) >= sizeof(mrb_int) && ((a) > MRB_INT_MAX || (a) < MRB_INT_MIN)) +#define TIME_T_UINT (~(time_t)0 > 0) +#if defined(MRB_USE_BITINT) +#define TIME_BIGTIME(mrb, a) \ + return (TIME_T_UINT ? mrb_bint_new_uint64((mrb), (uint64_t)(a)) \ + : mrb_bint_new_int64(mrb, (int64_t)(a))) +#elif !defined(MRB_NO_FLOAT) +#define TIME_BIGTIME(mrb,a) return mrb_float_value((mrb), (mrb_float)(a)) +#else +#define TIME_BIGTIME(mrb, a) mrb_raise(mrb, E_IO_ERROR, #a " overflow") +#endif + +static mrb_value +mrb_file_atime(mrb_state *mrb, mrb_value self) +{ + int fd = mrb_io_fileno(mrb, self); + mrb_stat st; + + mrb->c->ci->mid = 0; + if (mrb_fstat(fd, &st) == -1) + mrb_sys_fail(mrb, "atime"); + if (TIME_OVERFLOW_P(st.st_atime)) { + TIME_BIGTIME(mrb, st.st_atime); + } + return mrb_int_value(mrb, (mrb_int)st.st_atime); +} + +static mrb_value +mrb_file_ctime(mrb_state *mrb, mrb_value self) +{ + int fd = mrb_io_fileno(mrb, self); + mrb_stat st; + + mrb->c->ci->mid = 0; + if (mrb_fstat(fd, &st) == -1) + mrb_sys_fail(mrb, "ctime"); + if (TIME_OVERFLOW_P(st.st_ctime)) { + TIME_BIGTIME(mrb, st. st_ctime); + } + return mrb_int_value(mrb, (mrb_int)st.st_ctime); +} + static mrb_value mrb_file_mtime(mrb_state *mrb, mrb_value self) { int fd = mrb_io_fileno(mrb, self); mrb_stat st; + mrb->c->ci->mid = 0; if (mrb_fstat(fd, &st) == -1) - return mrb_false_value(); + mrb_sys_fail(mrb, "mtime"); + if (TIME_OVERFLOW_P(st.st_mtime)) { + TIME_BIGTIME(mrb, st. st_mtime); + } return mrb_int_value(mrb, (mrb_int)st.st_mtime); } @@ -567,10 +621,10 @@ mrb_file_s_readlink(mrb_state *mrb, mrb_value klass) { mrb_get_args(mrb, "z", &path); tmp = mrb_locale_from_utf8(path, -1); - buf = (char *)mrb_malloc(mrb, bufsize); + buf = (char*)mrb_malloc(mrb, bufsize); while ((rc = readlink(tmp, buf, bufsize)) == (ssize_t)bufsize && rc != -1) { bufsize *= 2; - buf = (char *)mrb_realloc(mrb, buf, bufsize); + buf = (char*)mrb_realloc(mrb, buf, bufsize); } mrb_locale_free(tmp); if (rc == -1) { @@ -610,6 +664,8 @@ mrb_init_file(mrb_state *mrb) mrb_define_class_method(mrb, file, "_gethome", mrb_file__gethome, MRB_ARGS_OPT(1)); mrb_define_method(mrb, file, "flock", mrb_file_flock, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, file, "_atime", mrb_file_atime, MRB_ARGS_NONE()); + mrb_define_method(mrb, file, "_ctime", mrb_file_ctime, MRB_ARGS_NONE()); mrb_define_method(mrb, file, "_mtime", mrb_file_mtime, MRB_ARGS_NONE()); mrb_define_method(mrb, file, "size", mrb_file_size, MRB_ARGS_NONE()); mrb_define_method(mrb, file, "truncate", mrb_file_truncate, MRB_ARGS_REQ(1)); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/file_test.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/file_test.c index f1762369a9..1d7aa564ee 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/file_test.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/file_test.c @@ -20,7 +20,9 @@ #include #include #include +#ifndef __DJGPP__ #include +#endif #include #include #endif @@ -38,7 +40,7 @@ mrb_stat0(mrb_state *mrb, mrb_value obj, struct stat *st, int do_lstat) { if (mrb_obj_is_kind_of(mrb, obj, mrb_class_get(mrb, "IO"))) { struct mrb_io *fptr; - fptr = (struct mrb_io *)mrb_data_get_ptr(mrb, obj, &mrb_io_type); + fptr = (struct mrb_io*)mrb_data_get_ptr(mrb, obj, &mrb_io_type); if (fptr && fptr->fd >= 0) { return fstat(fptr->fd, st); @@ -52,7 +54,8 @@ mrb_stat0(mrb_state *mrb, mrb_value obj, struct stat *st, int do_lstat) int ret; if (do_lstat) { ret = LSTAT(path, st); - } else { + } + else { ret = stat(path, st); } mrb_locale_free(path); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/io.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/io.c index ebe19930aa..1767f66baf 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/io.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/src/io.c @@ -46,7 +46,11 @@ #include typedef size_t fsize_t; typedef time_t ftime_t; +#ifdef __DJGPP__ + typedef long fsuseconds_t; +#else typedef suseconds_t fsuseconds_t; +#endif typedef mode_t fmode_t; typedef ssize_t fssize_t; #endif @@ -94,7 +98,7 @@ io_get_open_fptr(mrb_state *mrb, mrb_value io) # define MRB_NO_IO_POPEN 1 #endif -#ifndef MRB_NO_IO_POEPN +#ifndef MRB_NO_IO_POPEN static void io_set_process_status(mrb_state *mrb, pid_t pid, int status) { @@ -110,7 +114,8 @@ io_set_process_status(mrb_state *mrb, pid_t pid, int status) } if (c_status != NULL) { v = mrb_funcall_id(mrb, mrb_obj_value(c_status), MRB_SYM(new), 2, mrb_fixnum_value(pid), mrb_fixnum_value(status)); - } else { + } + else { v = mrb_fixnum_value(WEXITSTATUS(status)); } mrb_gv_set(mrb, mrb_intern_lit(mrb, "$?"), v); @@ -134,8 +139,7 @@ io_modestr_to_flags(mrb_state *mrb, const char *mode) flags = O_WRONLY | O_CREAT | O_APPEND; break; default: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %s", mode); - flags = 0; /* not reached */ + goto modeerr; } while (*m) { @@ -145,17 +149,25 @@ io_modestr_to_flags(mrb_state *mrb, const char *mode) flags |= O_BINARY; #endif break; + case 'x': + if (mode[0] != 'w') goto modeerr; + flags |= O_EXCL; + break; case '+': flags = (flags & ~OPEN_ACCESS_MODE_FLAGS) | O_RDWR; break; case ':': /* XXX: PASSTHROUGH*/ default: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %s", mode); + goto modeerr; } } return flags; + + modeerr: + mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %s", mode); + return 0; /* not reached */ } static int @@ -308,7 +320,7 @@ io_free(mrb_state *mrb, void *ptr) } static void -io_buf_init(mrb_state *mrb, struct mrb_io *fptr) +io_init_buf(mrb_state *mrb, struct mrb_io *fptr) { if (fptr->readable) { fptr->buf = (struct mrb_io_buf*)mrb_malloc(mrb, sizeof(struct mrb_io_buf)); @@ -466,7 +478,7 @@ io_s_popen(mrb_state *mrb, mrb_value klass) fptr->pid = pid; fptr->readable = OPEN_READABLE_P(flags); fptr->writable = OPEN_WRITABLE_P(flags); - io_buf_init(mrb, fptr); + io_init_buf(mrb, fptr); DATA_TYPE(io) = &mrb_io_type; DATA_PTR(io) = fptr; @@ -559,10 +571,12 @@ io_s_popen(mrb_state *mrb, mrb_value klass) fd = pr[0]; close(pw[0]); write_fd = pw[1]; - } else if (OPEN_RDONLY_P(flags)) { + } + else if (OPEN_RDONLY_P(flags)) { close(pr[1]); fd = pr[0]; - } else { + } + else { close(pw[0]); fd = pw[1]; } @@ -573,7 +587,7 @@ io_s_popen(mrb_state *mrb, mrb_value klass) fptr->pid = pid; fptr->readable = OPEN_READABLE_P(flags); fptr->writable = OPEN_WRITABLE_P(flags); - io_buf_init(mrb, fptr); + io_init_buf(mrb, fptr); DATA_TYPE(io) = &mrb_io_type; DATA_PTR(io) = fptr; @@ -629,10 +643,16 @@ io_init_copy(mrb_state *mrb, mrb_value copy) mrb_free(mrb, fptr_copy); } fptr_copy = (struct mrb_io*)io_alloc(mrb); + fptr_copy->pid = fptr_orig->pid; + fptr_copy->readable = fptr_orig->readable; + fptr_copy->writable = fptr_orig->writable; + fptr_copy->sync = fptr_orig->sync; + fptr_copy->is_socket = fptr_orig->is_socket; + + io_init_buf(mrb, fptr_copy); DATA_TYPE(copy) = &mrb_io_type; DATA_PTR(copy) = fptr_copy; - io_buf_init(mrb, fptr_copy); fptr_copy->fd = symdup(mrb, fptr_orig->fd, &failed); if (failed) { @@ -649,12 +669,6 @@ io_init_copy(mrb_state *mrb, mrb_value copy) io_fd_cloexec(mrb, fptr_copy->fd2); } - fptr_copy->pid = fptr_orig->pid; - fptr_copy->readable = fptr_orig->readable; - fptr_copy->writable = fptr_orig->writable; - fptr_copy->sync = fptr_orig->sync; - fptr_copy->is_socket = fptr_orig->is_socket; - return copy; } @@ -666,6 +680,7 @@ check_file_descriptor(mrb_state *mrb, mrb_int fd) #if MRB_INT_MIN < INT_MIN || MRB_INT_MAX > INT_MAX if (fdi != fd) { + errno = EBADF; goto badfd; } #endif @@ -681,14 +696,13 @@ check_file_descriptor(mrb_state *mrb, mrb_int fd) } if (fdi < 0 || fdi > _getmaxstdio()) { + errno = EBADF; goto badfd; } #endif /* _WIN32 */ - if (fstat(fdi, &sb) != 0) { - goto badfd; - } - + if (fstat(fdi, &sb) == 0) return; + if (errno == EBADF) goto badfd; return; badfd: @@ -705,6 +719,9 @@ io_init(mrb_state *mrb, mrb_value io) mode = opt = mrb_nil_value(); + if (mrb_block_given_p(mrb)) { + mrb_warn(mrb, "File.new() does not take block; use File.open() instead"); + } mrb_get_args(mrb, "i|oH", &fd, &mode, &opt); switch (fd) { case 0: /* STDIN_FILENO */ @@ -730,7 +747,7 @@ io_init(mrb_state *mrb, mrb_value io) fptr->fd = (int)fd; fptr->readable = OPEN_READABLE_P(flags); fptr->writable = OPEN_WRITABLE_P(flags); - io_buf_init(mrb, fptr); + io_init_buf(mrb, fptr); return io; } @@ -1029,13 +1046,13 @@ io_seek(mrb_state *mrb, mrb_value io) static mrb_value io_write_common(mrb_state *mrb, fssize_t (*writefunc)(int, const void*, fsize_t, off_t), - struct mrb_io *fptr, const void *buf, fsize_t blen, off_t offset) + struct mrb_io *fptr, const void *buf, mrb_ssize blen, off_t offset) { int fd; fssize_t length; fd = io_get_write_fd(fptr); - length = writefunc(fd, buf, blen, offset); + length = writefunc(fd, buf, (fsize_t)blen, offset); if (length == -1) { mrb_sys_fail(mrb, "syswrite"); } @@ -1222,7 +1239,7 @@ io_s_pipe(mrb_state *mrb, mrb_value klass) fptr_r->readable = 1; DATA_TYPE(r) = &mrb_io_type; DATA_PTR(r) = fptr_r; - io_buf_init(mrb, fptr_r); + io_init_buf(mrb, fptr_r); w = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type)); fptr_w = io_alloc(mrb); @@ -1278,7 +1295,8 @@ io_s_select(mrb_state *mrb, mrb_value klass) if (mrb_nil_p(timeout)) { tp = NULL; - } else { + } + else { timerec = time2timeval(mrb, timeout); tp = &timerec; } @@ -1304,7 +1322,8 @@ io_s_select(mrb_state *mrb, mrb_value klass) timerec.tv_sec = timerec.tv_usec = 0; tp = &timerec; } - } else { + } + else { rp = NULL; } @@ -1324,7 +1343,8 @@ io_s_select(mrb_state *mrb, mrb_value klass) max = fptr->fd2; } } - } else { + } + else { wp = NULL; } @@ -1344,7 +1364,8 @@ io_s_select(mrb_state *mrb, mrb_value klass) max = fptr->fd2; } } - } else { + } + else { ep = NULL; } @@ -1392,7 +1413,8 @@ retry: fptr = io_get_open_fptr(mrb, RARRAY_PTR(write)[i]); if (FD_ISSET(fptr->fd, wp)) { mrb_ary_push(mrb, list, RARRAY_PTR(write)[i]); - } else if (fptr->fd2 >= 0 && FD_ISSET(fptr->fd2, wp)) { + } + else if (fptr->fd2 >= 0 && FD_ISSET(fptr->fd2, wp)) { mrb_ary_push(mrb, list, RARRAY_PTR(write)[i]); } } @@ -1404,7 +1426,8 @@ retry: fptr = io_get_open_fptr(mrb, RARRAY_PTR(except)[i]); if (FD_ISSET(fptr->fd, ep)) { mrb_ary_push(mrb, list, RARRAY_PTR(except)[i]); - } else if (fptr->fd2 >= 0 && FD_ISSET(fptr->fd2, ep)) { + } + else if (fptr->fd2 >= 0 && FD_ISSET(fptr->fd2, ep)) { mrb_ary_push(mrb, list, RARRAY_PTR(except)[i]); } } @@ -1557,6 +1580,9 @@ io_ungetc(mrb_state *mrb, mrb_value io) mrb_get_args(mrb, "S", &str); len = RSTRING_LEN(str); + if (len > SHRT_MAX) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "string too long to ungetc"); + } if (len > MRB_IO_BUF_SIZE - buf->len) { fptr->buf = (struct mrb_io_buf*)mrb_realloc(mrb, buf, sizeof(struct mrb_io_buf)+buf->len+len-MRB_IO_BUF_SIZE); buf = fptr->buf; @@ -1564,31 +1590,28 @@ io_ungetc(mrb_state *mrb, mrb_value io) memmove(buf->mem+len, buf->mem+buf->start, buf->len); memcpy(buf->mem, RSTRING_PTR(str), len); buf->start = 0; - buf->len += len; + buf->len += (short)len; return mrb_nil_value(); } static void -io_buf_reset(struct mrb_io *fptr) +io_buf_reset(struct mrb_io_buf *buf) { - struct mrb_io_buf *buf = fptr->buf; - buf->start = 0; buf->len = 0; } static void -io_buf_shift(struct mrb_io *fptr, mrb_int n) +io_buf_shift(struct mrb_io_buf *buf, mrb_int n) { - struct mrb_io_buf *buf = fptr->buf; - - buf->start += n; - buf->len -= n; + mrb_assert(n <= SHRT_MAX); + buf->start += (short)n; + buf->len -= (short)n; } #ifdef MRB_UTF8_STRING static void -io_buf_fill_comp(mrb_state *mrb, struct mrb_io *fptr) +io_fill_buf_comp(mrb_state *mrb, struct mrb_io *fptr) { struct mrb_io_buf *buf = fptr->buf; int keep = buf->len; @@ -1603,7 +1626,7 @@ io_buf_fill_comp(mrb_state *mrb, struct mrb_io *fptr) #endif static void -io_buf_fill(mrb_state *mrb, struct mrb_io *fptr) +io_fill_buf(mrb_state *mrb, struct mrb_io *fptr) { struct mrb_io_buf *buf = fptr->buf; @@ -1621,42 +1644,52 @@ io_eof(mrb_state *mrb, mrb_value io) { struct mrb_io *fptr = io_get_read_fptr(mrb, io); - io_buf_fill(mrb, fptr); + if (fptr->eof) return mrb_true_value(); if (fptr->buf->len > 0) return mrb_false_value(); + io_fill_buf(mrb, fptr); return mrb_bool_value(fptr->eof); } static void -io_buf_cat(mrb_state *mrb, mrb_value outbuf, struct mrb_io *fptr, mrb_int n) +io_buf_cat(mrb_state *mrb, mrb_value outbuf, struct mrb_io_buf *buf, mrb_int n) { - struct mrb_io_buf *buf = fptr->buf; - mrb_assert(n <= buf->len); mrb_str_cat(mrb, outbuf, buf->mem+buf->start, n); - io_buf_shift(fptr, n); + io_buf_shift(buf, n); } static void -io_buf_cat_all(mrb_state *mrb, mrb_value outbuf, struct mrb_io *fptr) +io_buf_cat_all(mrb_state *mrb, mrb_value outbuf, struct mrb_io_buf *buf) { - struct mrb_io_buf *buf = fptr->buf; - mrb_str_cat(mrb, outbuf, buf->mem+buf->start, buf->len); - io_buf_reset(fptr); + io_buf_reset(buf); } static mrb_value io_read_all(mrb_state *mrb, struct mrb_io *fptr, mrb_value outbuf) { for (;;) { - io_buf_fill(mrb, fptr); + io_fill_buf(mrb, fptr); if (fptr->eof) { return outbuf; } - io_buf_cat_all(mrb, outbuf, fptr); + io_buf_cat_all(mrb, outbuf, fptr->buf); } } +static mrb_value +io_reset_outbuf(mrb_state *mrb, mrb_value outbuf, mrb_int len) +{ + if (mrb_nil_p(outbuf)) { + outbuf = mrb_str_new(mrb, NULL, 0); + } + else { + mrb_str_modify(mrb, mrb_str_ptr(outbuf)); + RSTR_SET_LEN(mrb_str_ptr(outbuf), 0); + } + return outbuf; +} + static mrb_value io_read(mrb_state *mrb, mrb_value io) { @@ -1677,30 +1710,31 @@ io_read(mrb_state *mrb, mrb_value io) mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative length %d given", length); } if (length == 0) { - return mrb_str_new(mrb, NULL, 0); + return io_reset_outbuf(mrb, outbuf, 0); } } } - if (mrb_nil_p(outbuf)) { - outbuf = mrb_str_new_capa(mrb, MRB_IO_BUF_SIZE); - } + outbuf = io_reset_outbuf(mrb, outbuf, MRB_IO_BUF_SIZE); if (!length_given) { /* read as much as possible */ return io_read_all(mrb, fptr, outbuf); } + + struct mrb_io_buf *buf = fptr->buf; + for (;;) { - io_buf_fill(mrb, fptr); + io_fill_buf(mrb, fptr); if (fptr->eof || length == 0) { if (RSTRING_LEN(outbuf) == 0) return mrb_nil_value(); return outbuf; } - if (fptr->buf->len < length) { - length -= fptr->buf->len; - io_buf_cat_all(mrb, outbuf, fptr); + if (buf->len < length) { + length -= buf->len; + io_buf_cat_all(mrb, outbuf, buf); } else { - io_buf_cat(mrb, outbuf, fptr, length); + io_buf_cat(mrb, outbuf, buf, length); return outbuf; } } @@ -1713,7 +1747,7 @@ io_find_index(struct mrb_io *fptr, const char *rs, mrb_int rslen) mrb_assert(rslen > 0); const char c = rs[0]; - const mrb_int limit = buf->len - rslen; + const mrb_int limit = buf->len - rslen + 1; const char *p = buf->mem+buf->start; for (mrb_int i=0; ieof) return mrb_nil_value(); if (limit_given) { @@ -1792,19 +1826,19 @@ io_gets(mrb_state *mrb, mrb_value io) if (limit_given && limit < n) { n = limit; } - io_buf_cat(mrb, outbuf, fptr, n); - return outbuf; + io_buf_cat(mrb, outbuf, buf, n); + return outbuf; } } if (limit_given) { if (limit <= buf->len) { - io_buf_cat(mrb, outbuf, fptr, limit); + io_buf_cat(mrb, outbuf, buf, limit); return outbuf; } limit -= buf->len; } - io_buf_cat_all(mrb, outbuf, fptr); - io_buf_fill(mrb, fptr); + io_buf_cat_all(mrb, outbuf, buf); + io_fill_buf(mrb, fptr); if (fptr->eof) { if (RSTRING_LEN(outbuf) == 0) return mrb_nil_value(); return outbuf; @@ -1839,23 +1873,23 @@ io_getc(mrb_state *mrb, mrb_value io) { mrb_int len = 1; struct mrb_io *fptr = io_get_read_fptr(mrb, io); + struct mrb_io_buf *buf = fptr->buf; - io_buf_fill(mrb, fptr); + io_fill_buf(mrb, fptr); if (fptr->eof) return mrb_nil_value(); #ifdef MRB_UTF8_STRING - struct mrb_io_buf *buf = fptr->buf; const char *p = &buf->mem[buf->start]; if ((*p) & 0x80) { len = mrb_utf8len(p, p+buf->len); if (len == 1 && buf->len < 4) { /* partial UTF-8 */ - io_buf_fill_comp(mrb, fptr); + io_fill_buf_comp(mrb, fptr); p = &buf->mem[buf->start]; len = mrb_utf8len(p, p+buf->len); } } #endif - mrb_value str = mrb_str_new(mrb, fptr->buf->mem+fptr->buf->start, len); - io_buf_shift(fptr, len); + mrb_value str = mrb_str_new(mrb, buf->mem+buf->start, len); + io_buf_shift(buf, len); return str; } @@ -1873,12 +1907,13 @@ static mrb_value io_getbyte(mrb_state *mrb, mrb_value io) { struct mrb_io *fptr = io_get_read_fptr(mrb, io); + struct mrb_io_buf *buf = fptr->buf; - io_buf_fill(mrb, fptr); + io_fill_buf(mrb, fptr); if (fptr->eof) return mrb_nil_value(); - unsigned char c = fptr->buf->mem[fptr->buf->start]; - io_buf_shift(fptr, 1); + unsigned char c = buf->mem[buf->start]; + io_buf_shift(buf, 1); return mrb_int_value(mrb, (mrb_int)c); } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/file.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/file.rb index 5a8a8dface..5746986ade 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/file.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/file.rb @@ -69,6 +69,32 @@ assert('File#flock') do end end +assert('File#atime') do + begin + File.open("#{$mrbtest_io_wfname}.atime", 'w') do |f| + assert_equal Time, f.mtime.class + File.open("#{$mrbtest_io_wfname}.atime", 'r') do |f2| + assert_equal true, f.atime == f2.atime + end + end + ensure + File.delete("#{$mrbtest_io_wfname}.atime") + end +end + +assert('File#ctime') do + begin + File.open("#{$mrbtest_io_wfname}.ctime", 'w') do |f| + assert_equal Time, f.ctime.class + File.open("#{$mrbtest_io_wfname}.ctime", 'r') do |f2| + assert_equal true, f.ctime == f2.ctime + end + end + ensure + File.delete("#{$mrbtest_io_wfname}.ctime") + end +end + assert('File#mtime') do begin File.open("#{$mrbtest_io_wfname}.mtime", 'w') do |f| @@ -234,4 +260,30 @@ assert('File.chmod') do end end +assert('File.open with "x" mode') do + File.unlink $mrbtest_io_wfname rescue nil + assert_nothing_raised do + File.open($mrbtest_io_wfname, "wx") {} + end + assert_raise(RuntimeError) do + File.open($mrbtest_io_wfname, "wx") {} + end + + File.unlink $mrbtest_io_wfname rescue nil + assert_nothing_raised do + File.open($mrbtest_io_wfname, "w+x") {} + end + assert_raise(RuntimeError) do + File.open($mrbtest_io_wfname, "w+x") {} + end + + assert_raise(ArgumentError) do + File.open($mrbtest_io_wfname, "rx") {} + end + + assert_raise(ArgumentError) do + File.open($mrbtest_io_wfname, "ax") {} + end +end + MRubyIOTestUtil.io_test_cleanup diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/io.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/io.rb index 024a71acd1..811038ff44 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/io.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/io.rb @@ -16,14 +16,15 @@ def assert_io_open(meth) io1.close end - io2 = IO.__send__(meth, IO.sysopen($mrbtest_io_rfname))do |io| - if meth == :open - assert_equal $mrbtest_io_msg, io.read - else - flunk "IO.#{meth} does not take block" + if meth == :open + io2 = IO.__send__(meth, IO.sysopen($mrbtest_io_rfname))do |io| + if meth == :open + assert_equal $mrbtest_io_msg, io.read + else + flunk "IO.#{meth} does not take block" + end end end - io2.close unless meth == :open assert_raise(RuntimeError) { IO.__send__(meth, 1023) } # For Windows assert_raise(RuntimeError) { IO.__send__(meth, 1 << 26) } @@ -149,6 +150,30 @@ assert "IO#read(n) with n > IO::BUF_SIZE" do end end +assert "IO#read(n, buf)" do + IO.open(IO.sysopen($mrbtest_io_rfname)) do |io| + buf = "12345" + assert_same buf, io.read(0, buf) + assert_equal "", buf + + buf = "12345" + assert_same buf, io.read(5, buf) + assert_equal "mruby", buf + + buf = "12345" + assert_same buf, io.read(nil, buf) + assert_equal " io test\n", buf + + buf = "12345" + assert_nil io.read(99, buf) + assert_equal "", buf + + buf = "12345" + assert_same buf, io.read(0, buf) + assert_equal "", buf + end +end + assert('IO#readchar', '15.2.20.5.15') do # almost same as IO#getc IO.open(IO.sysopen($mrbtest_io_rfname)) do |io| diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/mruby_io_test.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/mruby_io_test.c index cf99260e24..bf801323cc 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/mruby_io_test.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-io/test/mruby_io_test.c @@ -97,7 +97,8 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self) if (tmpdir && strlen(tmpdir) > 0) { mrb_str_cat_cstr(mrb, fname, tmpdir); if (*(RSTRING_END(fname)-1) != '/') mrb_str_cat_lit(mrb, fname, "/"); - } else { + } + else { mrb_str_cat_lit(mrb, fname, "/tmp/"); } #endif @@ -142,7 +143,7 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self) sun0.sun_family = AF_UNIX; strncpy(sun0.sun_path, fnames[IDX_SOCKET], sizeof(sun0.sun_path)-1); sun0.sun_path[sizeof(sun0.sun_path)-1] = 0; - if (bind(fds[IDX_SOCKET], (struct sockaddr *)&sun0, sizeof(sun0)) == -1) { + if (bind(fds[IDX_SOCKET], (struct sockaddr*)&sun0, sizeof(sun0)) == -1) { mrb_raisef(mrb, E_RUNTIME_ERROR, "can't bind AF_UNIX socket to %s: %d", sun0.sun_path, errno); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-kernel-ext/test/kernel.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-kernel-ext/test/kernel.rb index e5876f9762..0bec08f71f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-kernel-ext/test/kernel.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-kernel-ext/test/kernel.rb @@ -50,17 +50,19 @@ assert('Kernel#__method__') do assert_equal(:m2, c.new.m4) end +# CRuby __callee__ always gives the calling method name +# mruby __callee__ gives the original method name for aliases assert('Kernel#__callee__') do c = Class.new do def m1; __callee__ end define_method(:m2) {__callee__} - alias m3 m1 - alias_method :m4, :m2 +# alias m3 m1 +# alias_method :m4, :m2 end assert_equal(:m1, c.new.m1) assert_equal(:m2, c.new.m2) - assert_equal(:m3, c.new.m3) - assert_equal(:m4, c.new.m4) +# assert_equal(:m3, c.new.m3) +# assert_equal(:m4, c.new.m4) end assert('Kernel#Integer') do diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-math/src/math.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-math/src/math.c index 1f6f88e830..75f0a2202c 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-math/src/math.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-math/src/math.c @@ -174,6 +174,8 @@ log2(double x) #endif +#define get_float_arg(mrb) mrb_as_float((mrb), mrb_get_arg1(mrb)) + /* TRIGONOMETRIC FUNCTIONS */ @@ -188,11 +190,7 @@ log2(double x) static mrb_value math_sin(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = sin(x); - + mrb_float x = sin(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -206,11 +204,7 @@ math_sin(mrb_state *mrb, mrb_value obj) static mrb_value math_cos(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = cos(x); - + mrb_float x = cos(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -223,11 +217,7 @@ math_cos(mrb_state *mrb, mrb_value obj) static mrb_value math_tan(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = tan(x); - + mrb_float x = tan(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -245,9 +235,8 @@ math_tan(mrb_state *mrb, mrb_value obj) static mrb_value math_asin(mrb_state *mrb, mrb_value obj) { - mrb_float x; + mrb_float x = get_float_arg(mrb); - mrb_get_args(mrb, "f", &x); if (x < -1.0 || x > 1.0) { domain_error(mrb, "asin"); } @@ -265,9 +254,8 @@ math_asin(mrb_state *mrb, mrb_value obj) static mrb_value math_acos(mrb_state *mrb, mrb_value obj) { - mrb_float x; + mrb_float x = get_float_arg(mrb); - mrb_get_args(mrb, "f", &x); if (x < -1.0 || x > 1.0) { domain_error(mrb, "acos"); } @@ -285,11 +273,7 @@ math_acos(mrb_state *mrb, mrb_value obj) static mrb_value math_atan(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = atan(x); - + mrb_float x = atan(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -336,11 +320,7 @@ math_atan2(mrb_state *mrb, mrb_value obj) static mrb_value math_sinh(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = sinh(x); - + mrb_float x = sinh(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -353,11 +333,7 @@ math_sinh(mrb_state *mrb, mrb_value obj) static mrb_value math_cosh(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = cosh(x); - + mrb_float x = cosh(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -371,11 +347,7 @@ math_cosh(mrb_state *mrb, mrb_value obj) static mrb_value math_tanh(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = tanh(x); - + mrb_float x = tanh(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -393,12 +365,7 @@ math_tanh(mrb_state *mrb, mrb_value obj) static mrb_value math_asinh(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - - x = asinh(x); - + mrb_float x = asinh(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -411,9 +378,8 @@ math_asinh(mrb_state *mrb, mrb_value obj) static mrb_value math_acosh(mrb_state *mrb, mrb_value obj) { - mrb_float x; + mrb_float x = get_float_arg(mrb); - mrb_get_args(mrb, "f", &x); if (x < 1.0) { domain_error(mrb, "acosh"); } @@ -431,9 +397,8 @@ math_acosh(mrb_state *mrb, mrb_value obj) static mrb_value math_atanh(mrb_state *mrb, mrb_value obj) { - mrb_float x; + mrb_float x = get_float_arg(mrb); - mrb_get_args(mrb, "f", &x); if (x < -1.0 || x > 1.0) { domain_error(mrb, "atanh"); } @@ -460,11 +425,7 @@ math_atanh(mrb_state *mrb, mrb_value obj) static mrb_value math_exp(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = exp(x); - + mrb_float x = exp(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -518,9 +479,8 @@ math_log(mrb_state *mrb, mrb_value obj) static mrb_value math_log2(mrb_state *mrb, mrb_value obj) { - mrb_float x; + mrb_float x = get_float_arg(mrb); - mrb_get_args(mrb, "f", &x); if (x < 0.0) { domain_error(mrb, "log2"); } @@ -543,9 +503,8 @@ math_log2(mrb_state *mrb, mrb_value obj) static mrb_value math_log10(mrb_state *mrb, mrb_value obj) { - mrb_float x; + mrb_float x = get_float_arg(mrb); - mrb_get_args(mrb, "f", &x); if (x < 0.0) { domain_error(mrb, "log10"); } @@ -564,9 +523,8 @@ math_log10(mrb_state *mrb, mrb_value obj) static mrb_value math_sqrt(mrb_state *mrb, mrb_value obj) { - mrb_float x; + mrb_float x = get_float_arg(mrb); - mrb_get_args(mrb, "f", &x); if (x < 0.0) { domain_error(mrb, "sqrt"); } @@ -610,11 +568,7 @@ math_sqrt(mrb_state *mrb, mrb_value obj) static mrb_value math_cbrt(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = cbrt(x); - + mrb_float x = cbrt(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -633,10 +587,9 @@ math_cbrt(mrb_state *mrb, mrb_value obj) static mrb_value math_frexp(mrb_state *mrb, mrb_value obj) { - mrb_float x; + mrb_float x = get_float_arg(mrb); int exp; - mrb_get_args(mrb, "f", &x); x = frexp(x, &exp); return mrb_assoc_new(mrb, mrb_float_value(mrb, x), mrb_fixnum_value(exp)); @@ -692,11 +645,7 @@ math_hypot(mrb_state *mrb, mrb_value obj) static mrb_value math_erf(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = erf(x); - + mrb_float x = erf(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -710,11 +659,7 @@ math_erf(mrb_state *mrb, mrb_value obj) static mrb_value math_erfc(mrb_state *mrb, mrb_value obj) { - mrb_float x; - - mrb_get_args(mrb, "f", &x); - x = erfc(x); - + mrb_float x = erfc(get_float_arg(mrb)); return mrb_float_value(mrb, x); } @@ -725,7 +670,7 @@ mrb_mruby_math_gem_init(mrb_state* mrb) struct RClass *mrb_math; mrb_math = mrb_define_module(mrb, "Math"); - mrb_define_class_under_id(mrb, mrb_math, MRB_SYM(DomainError), mrb->eStandardError_class); + mrb_define_class_under_id(mrb, mrb_math, MRB_SYM(DomainError), E_STANDARD_ERROR); #ifdef M_PI mrb_define_const_id(mrb, mrb_math, MRB_SYM(PI), mrb_float_value(mrb, M_PI)); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-metaprog/src/metaprog.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-metaprog/src/metaprog.c index 67da9cd995..3b93574c1b 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-metaprog/src/metaprog.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-metaprog/src/metaprog.c @@ -22,8 +22,6 @@ typedef enum { NOEX_RESPONDS = 0x80 } mrb_method_flag_t; -mrb_value mrb_proc_local_variables(mrb_state *mrb, const struct RProc *proc); - static mrb_value mrb_f_nil(mrb_state *mrb, mrb_value cv) { @@ -296,7 +294,6 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self) static mrb_value mrb_obj_singleton_methods(mrb_state *mrb, mrb_bool recur, mrb_value obj) { - khint_t i; mrb_value ary; struct RClass *klass; khash_t(st) *set = kh_init(st, mrb); @@ -316,7 +313,7 @@ mrb_obj_singleton_methods(mrb_state *mrb, mrb_bool recur, mrb_value obj) } ary = mrb_ary_new(mrb); - for (i=0;ibody.func != other_rproc->body.func) - return mrb_false_value(); + if (mrb_nil_p(orig_proc) || mrb_nil_p(other_proc)) { + return mrb_false_value(); } - else { - if (MRB_PROC_CFUNC_P(other_rproc)) - return mrb_false_value(); - if (orig_rproc->body.irep != other_rproc->body.irep) - return mrb_false_value(); - } - - return mrb_true_value(); + return mrb_bool_value(mrb_proc_eql(mrb, orig_proc, other_proc)); } #undef IV_GET @@ -276,13 +267,12 @@ method_bcall(mrb_state *mrb, mrb_value self) static mrb_value method_unbind(mrb_state *mrb, mrb_value self) { - struct RObject *ume; mrb_value owner = mrb_iv_get(mrb, self, MRB_SYM(_owner)); mrb_value name = mrb_iv_get(mrb, self, MRB_SYM(_name)); mrb_value proc = mrb_iv_get(mrb, self, MRB_SYM(_proc)); mrb_value klass = mrb_iv_get(mrb, self, MRB_SYM(_klass)); - ume = method_object_alloc(mrb, mrb_class_get_id(mrb, MRB_SYM(UnboundMethod))); + struct RObject *ume = method_object_alloc(mrb, mrb_class_get_id(mrb, MRB_SYM(UnboundMethod))); mrb_obj_iv_set(mrb, ume, MRB_SYM(_owner), owner); mrb_obj_iv_set(mrb, ume, MRB_SYM(_recv), mrb_nil_value()); mrb_obj_iv_set(mrb, ume, MRB_SYM(_name), name); @@ -316,8 +306,6 @@ method_super_method(mrb_state *mrb, mrb_value self) mrb_value owner = mrb_iv_get(mrb, self, MRB_SYM(_owner)); mrb_value name = mrb_iv_get(mrb, self, MRB_SYM(_name)); struct RClass *super, *rklass; - struct RProc *proc; - struct RObject *me; if (mrb_type(owner) == MRB_TT_MODULE) { struct RClass *m = mrb_class_ptr(owner); @@ -332,19 +320,18 @@ method_super_method(mrb_state *mrb, mrb_value self) super = mrb_class_ptr(owner)->super; } - proc = method_search_vm(mrb, &super, mrb_symbol(name)); + struct RProc *proc = method_search_vm(mrb, &super, mrb_symbol(name)); if (!proc) return mrb_nil_value(); - rklass = super; - super = mrb_class_real(super); if (!super) return mrb_nil_value(); + super = mrb_class_real(super); - me = method_object_alloc(mrb, mrb_obj_class(mrb, self)); + struct RObject *me = method_object_alloc(mrb, mrb_obj_class(mrb, self)); mrb_obj_iv_set(mrb, me, MRB_SYM(_owner), mrb_obj_value(super)); mrb_obj_iv_set(mrb, me, MRB_SYM(_recv), recv); mrb_obj_iv_set(mrb, me, MRB_SYM(_name), name); mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), mrb_obj_value(proc)); - mrb_obj_iv_set(mrb, me, MRB_SYM(_klass), mrb_obj_value(rklass)); + mrb_obj_iv_set(mrb, me, MRB_SYM(_klass), mrb_obj_value(super)); return mrb_obj_value(me); } @@ -389,7 +376,7 @@ method_to_s(mrb_state *mrb, mrb_value self) mrb_value klass = mrb_iv_get(mrb, self, MRB_SYM(_klass)); mrb_value name = mrb_iv_get(mrb, self, MRB_SYM(_name)); mrb_value str = mrb_str_new_lit(mrb, "#<"); - struct RClass *rklass; + mrb_value proc = mrb_iv_get(mrb, self, MRB_SYM(_proc)); mrb_str_cat_cstr(mrb, str, mrb_obj_classname(mrb, self)); mrb_str_cat_lit(mrb, str, ": "); @@ -402,22 +389,37 @@ method_to_s(mrb_state *mrb, mrb_value self) goto finish; } } - - rklass = mrb_class_ptr(klass); - if (mrb_class_ptr(owner) == rklass) { - mrb_str_concat(mrb, str, owner); - mrb_str_cat_lit(mrb, str, "#"); - mrb_str_concat(mrb, str, name); - } - else { - rklass = mrb_class_real(rklass); /* skip internal class */ - mrb_str_concat(mrb, str, mrb_obj_value(rklass)); - mrb_str_cat_lit(mrb, str, "("); - mrb_str_concat(mrb, str, owner); - mrb_str_cat_lit(mrb, str, ")#"); - mrb_str_concat(mrb, str, name); + { + struct RClass *ok = mrb_class_ptr(owner); + struct RClass *rk = mrb_class_ptr(klass); + struct RClass *rklass = mrb_class_real(rk); /* skip internal class */ + if (ok == rk || ok == rklass) { + mrb_str_concat(mrb, str, owner); + mrb_str_cat_lit(mrb, str, "#"); + mrb_str_concat(mrb, str, name); + } + else { + mrb_str_concat(mrb, str, mrb_obj_value(rklass)); + mrb_str_cat_lit(mrb, str, "("); + mrb_str_concat(mrb, str, owner); + mrb_str_cat_lit(mrb, str, ")#"); + mrb_str_concat(mrb, str, name); + } } finish:; + if (!mrb_nil_p(proc)) { + const struct RProc *p = mrb_proc_ptr(proc); + if (MRB_PROC_ALIAS_P(p)) { + mrb_sym mid; + while (MRB_PROC_ALIAS_P(p)) { + mid = p->body.mid; + p = p->upper; + } + mrb_str_cat_lit(mrb, str, "("); + mrb_str_concat(mrb, str, mrb_symbol_value(mid)); + mrb_str_cat_lit(mrb, str, ")"); + } + } mrb_value loc = method_source_location(mrb, self); if (mrb_array_p(loc) && RARRAY_LEN(loc) == 2) { mrb_str_cat_lit(mrb, str, " "); @@ -429,23 +431,21 @@ method_to_s(mrb_state *mrb, mrb_value self) return str; } -static void -mrb_search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, struct RClass **owner, struct RProc **proc, mrb_bool unbound) +static mrb_bool +search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, struct RClass **owner, struct RProc **proc, mrb_bool unbound) { - mrb_value ret; - *owner = c; *proc = method_search_vm(mrb, owner, name); if (!*proc) { if (unbound) { - goto name_error; + return FALSE; } if (!mrb_respond_to(mrb, obj, MRB_SYM_Q(respond_to_missing))) { - goto name_error; + return FALSE; } - ret = mrb_funcall_id(mrb, obj, MRB_SYM_Q(respond_to_missing), 2, mrb_symbol_value(name), mrb_true_value()); + mrb_value ret = mrb_funcall_id(mrb, obj, MRB_SYM_Q(respond_to_missing), 2, mrb_symbol_value(name), mrb_true_value()); if (!mrb_test(ret)) { - goto name_error; + return FALSE; } *owner = c; } @@ -453,54 +453,73 @@ mrb_search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym while ((*owner)->tt == MRB_TT_ICLASS) *owner = (*owner)->c; - return; + return TRUE; +} -name_error: - mrb_raisef(mrb, E_NAME_ERROR, "undefined method '%n' for class '%C'", name, c); +static mrb_noreturn void +singleton_method_error(mrb_state *mrb, mrb_sym name, mrb_value obj) +{ + mrb_raisef(mrb, E_NAME_ERROR, "undefined singleton method '%n' for '%!v'", name, obj); } static mrb_value -mrb_kernel_method(mrb_state *mrb, mrb_value self) +method_alloc(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, mrb_bool unbound, mrb_bool singleton) { struct RClass *owner; struct RProc *proc; - struct RObject *me; - mrb_sym name; - mrb_get_args(mrb, "n", &name); + if (!search_method_owner(mrb, c, obj, name, &owner, &proc, unbound)) { + if (singleton) { + singleton_method_error(mrb, name, obj); + } + else { + mrb_raisef(mrb, E_NAME_ERROR, "undefined method '%n' for class '%C'", name, c); + } + } + if (singleton && owner != c) { + singleton_method_error(mrb, name, obj); + } - mrb_search_method_owner(mrb, mrb_class(mrb, self), self, name, &owner, &proc, FALSE); - - me = method_object_alloc(mrb, mrb_class_get_id(mrb, MRB_SYM(Method))); + struct RObject *me = method_object_alloc(mrb, mrb_class_get_id(mrb, unbound ? MRB_SYM(UnboundMethod) : MRB_SYM(Method))); mrb_obj_iv_set(mrb, me, MRB_SYM(_owner), mrb_obj_value(owner)); - mrb_obj_iv_set(mrb, me, MRB_SYM(_recv), self); + mrb_obj_iv_set(mrb, me, MRB_SYM(_recv), unbound ? mrb_nil_value() : obj); mrb_obj_iv_set(mrb, me, MRB_SYM(_name), mrb_symbol_value(name)); mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), proc ? mrb_obj_value(proc) : mrb_nil_value()); - mrb_obj_iv_set(mrb, me, MRB_SYM(_klass), mrb_obj_value(mrb_class(mrb, self))); + mrb_obj_iv_set(mrb, me, MRB_SYM(_klass), mrb_obj_value(c)); return mrb_obj_value(me); } static mrb_value -mrb_module_instance_method(mrb_state *mrb, mrb_value self) +mrb_kernel_method(mrb_state *mrb, mrb_value self) +{ + mrb_sym name; + + mrb_get_args(mrb, "n", &name); + return method_alloc(mrb, mrb_class(mrb, self), self, name, FALSE, FALSE); +} + +static mrb_value +mrb_kernel_singleton_method(mrb_state *mrb, mrb_value self) { - struct RClass *owner; - struct RProc *proc; - struct RObject *ume; mrb_sym name; mrb_get_args(mrb, "n", &name); - mrb_search_method_owner(mrb, mrb_class_ptr(self), self, name, &owner, &proc, TRUE); + struct RClass *c = mrb_class(mrb, self); + if (c->tt != MRB_TT_SCLASS) { + singleton_method_error(mrb, name, self); + } + return method_alloc(mrb, c, self, name, FALSE, TRUE); +} - ume = method_object_alloc(mrb, mrb_class_get_id(mrb, MRB_SYM(UnboundMethod))); - mrb_obj_iv_set(mrb, ume, MRB_SYM(_owner), mrb_obj_value(owner)); - mrb_obj_iv_set(mrb, ume, MRB_SYM(_recv), mrb_nil_value()); - mrb_obj_iv_set(mrb, ume, MRB_SYM(_name), mrb_symbol_value(name)); - mrb_obj_iv_set(mrb, ume, MRB_SYM(_proc), proc ? mrb_obj_value(proc) : mrb_nil_value()); - mrb_obj_iv_set(mrb, ume, MRB_SYM(_klass), self); +static mrb_value +mrb_module_instance_method(mrb_state *mrb, mrb_value self) +{ + mrb_sym name; - return mrb_obj_value(ume); + mrb_get_args(mrb, "n", &name); + return method_alloc(mrb, mrb_class_ptr(self), self, name, TRUE, FALSE); } static mrb_value @@ -527,6 +546,8 @@ mrb_mruby_method_gem_init(mrb_state* mrb) struct RClass *unbound_method = mrb_define_class_id(mrb, MRB_SYM(UnboundMethod), mrb->object_class); struct RClass *method = mrb_define_class_id(mrb, MRB_SYM(Method), mrb->object_class); + MRB_SET_INSTANCE_TT(unbound_method, MRB_TT_OBJECT); + MRB_UNDEF_ALLOCATOR(unbound_method); mrb_undef_class_method(mrb, unbound_method, "new"); mrb_define_method(mrb, unbound_method, "bind", unbound_method_bind, MRB_ARGS_REQ(1)); mrb_define_method(mrb, unbound_method, "super_method", method_super_method, MRB_ARGS_NONE()); @@ -541,6 +562,8 @@ mrb_mruby_method_gem_init(mrb_state* mrb) mrb_define_method(mrb, unbound_method, "owner", method_owner, MRB_ARGS_NONE()); mrb_define_method(mrb, unbound_method, "name", method_name, MRB_ARGS_NONE()); + MRB_SET_INSTANCE_TT(method, MRB_TT_OBJECT); + MRB_UNDEF_ALLOCATOR(method); mrb_undef_class_method(mrb, method, "new"); mrb_define_method(mrb, method, "==", method_eql, MRB_ARGS_REQ(1)); mrb_define_method(mrb, method, "eql?", method_eql, MRB_ARGS_REQ(1)); @@ -558,6 +581,7 @@ mrb_mruby_method_gem_init(mrb_state* mrb) mrb_define_method(mrb, method, "name", method_name, MRB_ARGS_NONE()); mrb_define_method(mrb, mrb->kernel_module, "method", mrb_kernel_method, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, mrb->kernel_module, "singleton_method", mrb_kernel_singleton_method, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->module_class, "instance_method", mrb_module_instance_method, MRB_ARGS_REQ(1)); } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c index 5fa4e5fb1d..4833f05fdf 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c @@ -59,29 +59,36 @@ mrb_value mrb_int_pow(mrb_state *mrb, mrb_value x, mrb_value y); static mrb_value int_powm(mrb_state *mrb, mrb_value x) { - mrb_value m; - mrb_int e, exp, mod, result = 1; + mrb_value m, e; + mrb_int exp, mod, result = 1; if (mrb_get_argc(mrb) == 1) { return mrb_int_pow(mrb, x, mrb_get_arg1(mrb)); } - mrb_get_args(mrb, "io", &e, &m); - if (e < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "int.pow(n,m): n must be positive"); + mrb_get_args(mrb, "oo", &e, &m); + if (!mrb_integer_p(e) +#ifdef MRB_USE_BIGINT + && !mrb_bigint_p(e) +#endif + ) { + mrb_raise(mrb, E_TYPE_ERROR, "int.pow(n,m): 2nd argument not allowed unless 1st argument is an integer"); + } #ifdef MRB_USE_BIGINT if (mrb_bigint_p(x)) { return mrb_bint_powm(mrb, x, e, m); } - if (mrb_bigint_p(m)) { + if (mrb_bigint_p(e) || mrb_bigint_p(m)) { return mrb_bint_powm(mrb, mrb_bint_new_int(mrb, mrb_integer(x)), e, m); } #endif + exp = mrb_integer(e); + if (exp < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "int.pow(n,m): n must be positive"); if (!mrb_integer_p(m)) mrb_raise(mrb, E_TYPE_ERROR, "int.pow(n,m): m must be integer"); mod = mrb_integer(m); if (mod < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "int.pow(n,m): m must be positive when 2nd argument specified"); if (mod == 0) mrb_int_zerodiv(mrb); if (mod == 1) return mrb_fixnum_value(0); mrb_int base = mrb_integer(x); - exp = e; for (;;) { mrb_int tmp; if (exp & 1) { @@ -211,30 +218,30 @@ flo_remainder(mrb_state *mrb, mrb_value self) void mrb_mruby_numeric_ext_gem_init(mrb_state* mrb) { - struct RClass *i = mrb->integer_class; + struct RClass *ic = mrb->integer_class; - mrb_define_alias(mrb, i, "modulo", "%"); - mrb_define_method(mrb, i, "remainder", int_remainder, MRB_ARGS_REQ(1)); + mrb_define_alias(mrb, ic, "modulo", "%"); + mrb_define_method(mrb, ic, "remainder", int_remainder, MRB_ARGS_REQ(1)); - mrb_define_method_id(mrb, i, MRB_SYM(pow), int_powm, MRB_ARGS_ARG(1,1)); - mrb_define_method_id(mrb, i, MRB_SYM(digits), int_digits, MRB_ARGS_OPT(1)); + mrb_define_method_id(mrb, ic, MRB_SYM(pow), int_powm, MRB_ARGS_ARG(1,1)); + mrb_define_method_id(mrb, ic, MRB_SYM(digits), int_digits, MRB_ARGS_OPT(1)); #ifndef MRB_NO_FLOAT - struct RClass *f = mrb->float_class; + struct RClass *fc = mrb->float_class; - mrb_define_alias(mrb, f, "modulo", "%"); - mrb_define_method(mrb, f, "remainder", flo_remainder, MRB_ARGS_REQ(1)); + mrb_define_alias(mrb, fc, "modulo", "%"); + mrb_define_method(mrb, fc, "remainder", flo_remainder, MRB_ARGS_REQ(1)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(RADIX), mrb_fixnum_value(MRB_FLT_RADIX)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MANT_DIG), mrb_fixnum_value(MRB_FLT_MANT_DIG)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(EPSILON), mrb_float_value(mrb, MRB_FLT_EPSILON)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(DIG), mrb_fixnum_value(MRB_FLT_DIG)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MIN_EXP), mrb_fixnum_value(MRB_FLT_MIN_EXP)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MIN), mrb_float_value(mrb, MRB_FLT_MIN)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MIN_10_EXP), mrb_fixnum_value(MRB_FLT_MIN_10_EXP)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX_EXP), mrb_fixnum_value(MRB_FLT_MAX_EXP)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX), mrb_float_value(mrb, MRB_FLT_MAX)); - mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX_10_EXP), mrb_fixnum_value(MRB_FLT_MAX_10_EXP)); + mrb_define_const_id(mrb, fc, MRB_SYM(RADIX), mrb_fixnum_value(MRB_FLT_RADIX)); + mrb_define_const_id(mrb, fc, MRB_SYM(MANT_DIG), mrb_fixnum_value(MRB_FLT_MANT_DIG)); + mrb_define_const_id(mrb, fc, MRB_SYM(EPSILON), mrb_float_value(mrb, MRB_FLT_EPSILON)); + mrb_define_const_id(mrb, fc, MRB_SYM(DIG), mrb_fixnum_value(MRB_FLT_DIG)); + mrb_define_const_id(mrb, fc, MRB_SYM(MIN_EXP), mrb_fixnum_value(MRB_FLT_MIN_EXP)); + mrb_define_const_id(mrb, fc, MRB_SYM(MIN), mrb_float_value(mrb, MRB_FLT_MIN)); + mrb_define_const_id(mrb, fc, MRB_SYM(MIN_10_EXP), mrb_fixnum_value(MRB_FLT_MIN_10_EXP)); + mrb_define_const_id(mrb, fc, MRB_SYM(MAX_EXP), mrb_fixnum_value(MRB_FLT_MAX_EXP)); + mrb_define_const_id(mrb, fc, MRB_SYM(MAX), mrb_float_value(mrb, MRB_FLT_MAX)); + mrb_define_const_id(mrb, fc, MRB_SYM(MAX_10_EXP), mrb_fixnum_value(MRB_FLT_MAX_10_EXP)); #endif /* MRB_NO_FLOAT */ } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-object-ext/src/object.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-object-ext/src/object.c index 69f1763cef..f0b50bf139 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-object-ext/src/object.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-object-ext/src/object.c @@ -70,7 +70,7 @@ nil_to_i(mrb_state *mrb, mrb_value obj) * */ static mrb_value -mrb_f_itself(mrb_state *mrb, mrb_value self) +f_itself(mrb_state *mrb, mrb_value self) { return self; } @@ -94,7 +94,7 @@ mrb_f_itself(mrb_state *mrb, mrb_value self) */ static mrb_value -mrb_obj_instance_exec(mrb_state *mrb, mrb_value self) +obj_instance_exec(mrb_state *mrb, mrb_value self) { const mrb_value *argv; mrb_int argc; @@ -122,9 +122,9 @@ mrb_mruby_object_ext_gem_init(mrb_state* mrb) mrb_define_method(mrb, n, "to_h", nil_to_h, MRB_ARGS_NONE()); mrb_define_method(mrb, n, "to_i", nil_to_i, MRB_ARGS_NONE()); - mrb_define_method(mrb, mrb->kernel_module, "itself", mrb_f_itself, MRB_ARGS_NONE()); + mrb_define_method(mrb, mrb->kernel_module, "itself", f_itself, MRB_ARGS_NONE()); - mrb_define_method(mrb, mrb_class_get_id(mrb, MRB_SYM(BasicObject)), "instance_exec", mrb_obj_instance_exec, MRB_ARGS_ANY() | MRB_ARGS_BLOCK()); + mrb_define_method(mrb, mrb_class_get_id(mrb, MRB_SYM(BasicObject)), "instance_exec", obj_instance_exec, MRB_ARGS_ANY() | MRB_ARGS_BLOCK()); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-os-memsize/src/memsize.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-os-memsize/src/memsize.c index b95515cc64..10f77beea0 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-os-memsize/src/memsize.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-os-memsize/src/memsize.c @@ -16,13 +16,24 @@ static size_t os_memsize_of_irep(mrb_state* state, const struct mrb_irep *irep) { size_t size; - int i; size = (irep->slen * sizeof(mrb_sym)) + - (irep->plen * sizeof(mrb_code)) + - (irep->ilen * sizeof(mrb_code)); + (irep->plen * sizeof(mrb_pool_value)) + + (irep->ilen * sizeof(mrb_code)) + + (irep->rlen * sizeof(struct mrb_irep*)); - for(i = 0; i < irep->rlen; i++) { + for (int i = 0; i < irep->plen; i++) { + const mrb_pool_value *p = &irep->pool[i]; + if ((p->tt & IREP_TT_NFLAG) == 0) { /* string pool value */ + size += (p->tt>>2); + } + else if (p->tt == IREP_TT_BIGINT) { /* bigint pool value */ + size += p->u.str[0]; + } + } + + for (int i = 0; i < irep->rlen; i++) { + size += sizeof(struct mrb_irep); /* size of irep structure */ size += os_memsize_of_irep(state, irep->reps[i]); } return size; @@ -72,7 +83,7 @@ os_memsize_of_object(mrb_state* mrb, mrb_value obj) case MRB_TT_MODULE: case MRB_TT_SCLASS: case MRB_TT_ICLASS: - size += mrb_gc_mark_mt_size(mrb, mrb_class_ptr(obj)) * sizeof(mrb_method_t); + size += mrb_class_mt_memsize(mrb, mrb_class_ptr(obj)); /* fall through */ case MRB_TT_EXCEPTION: case MRB_TT_OBJECT: { @@ -95,14 +106,16 @@ os_memsize_of_object(mrb_state* mrb, mrb_value obj) /* Arrays that do not fit within an RArray perform a heap allocation * storing an array of pointers to the original objects*/ size += mrb_objspace_page_slot_size(); - if(len > MRB_ARY_EMBED_LEN_MAX) size += sizeof(mrb_value *) * len; + if (len > MRB_ARY_EMBED_LEN_MAX) + size += sizeof(mrb_value*) * len; break; } case MRB_TT_PROC: { struct RProc* proc = mrb_proc_ptr(obj); size += mrb_objspace_page_slot_size(); size += MRB_ENV_LEN(proc->e.env) * sizeof(mrb_value); - if(!MRB_PROC_CFUNC_P(proc)) size += os_memsize_of_irep(mrb, proc->body.irep); + if (!MRB_PROC_CFUNC_P(proc)) + size += os_memsize_of_irep(mrb, proc->body.irep); break; } case MRB_TT_RANGE: @@ -112,7 +125,7 @@ os_memsize_of_object(mrb_state* mrb, mrb_value obj) #endif break; case MRB_TT_FIBER: { - struct RFiber* f = (struct RFiber *)mrb_ptr(obj); + struct RFiber* f = (struct RFiber*)mrb_ptr(obj); ptrdiff_t stack_size = f->cxt->stend - f->cxt->stbase; ptrdiff_t ci_size = f->cxt->ciend - f->cxt->cibase; @@ -192,9 +205,7 @@ static mrb_value os_memsize_of(mrb_state *mrb, mrb_value self) { size_t total; - mrb_value obj; - - mrb_get_args(mrb, "o", &obj); + mrb_value obj = mrb_get_arg1(mrb); total = os_memsize_of_object(mrb, obj); return mrb_fixnum_value((mrb_int)total); @@ -208,7 +219,7 @@ struct os_memsize_of_all_cb_data { static int os_memsize_of_all_cb(mrb_state *mrb, struct RBasic *obj, void *d) { - struct os_memsize_of_all_cb_data *data = (struct os_memsize_of_all_cb_data *)d; + struct os_memsize_of_all_cb_data *data = (struct os_memsize_of_all_cb_data*)d; switch (obj->tt) { case MRB_TT_FREE: case MRB_TT_ENV: case MRB_TT_BREAK: case MRB_TT_ICLASS: diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/README.md b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/README.md index 712cf8e1c7..d108f2a091 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/README.md +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/README.md @@ -16,6 +16,8 @@ There is no dependency on other mrbgems. - A : arbitrary binary string (space padded, count is width) - a : arbitrary binary string (null padded, count is width) +- B : bit string (descending) +- b : bit string (ascending) - C : 8-bit unsigned (unsigned char) - c : 8-bit signed (signed char) - D, d: 64-bit float, native format @@ -28,6 +30,8 @@ There is no dependency on other mrbgems. - h : hex string (low nibble first) - I : unsigned integer, native endian (`unsigned int` in C) - i : signed integer, native endian (`int` in C) +- J : unsigned integer, native endian (`uintptr_t` in C) +- j : signed integer, native endian (`intptr_t` in C) - L : 32-bit unsigned, native endian (`uint32_t`) - l : 32-bit signed, native endian (`int32_t`) - m : base64 encoded string (see RFC 2045, count is width) @@ -41,7 +45,7 @@ There is no dependency on other mrbgems. - V : 32-bit unsigned, VAX (little-endian) byte order - v : 16-bit unsigned, VAX (little-endian) byte order - x : null byte -- Z : same as "a", except that null is added with * +- Z : same as "a", except that null is added with \* ## License diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/src/pack.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/src/pack.c index b5ecdc6479..75d8e1a942 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/src/pack.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/src/pack.c @@ -35,17 +35,17 @@ enum pack_dir { //PACK_DIR_VAX, PACK_DIR_BER, /* w */ PACK_DIR_UTF8, /* U */ - //PACK_DIR_BER, PACK_DIR_DOUBLE, /* E */ PACK_DIR_FLOAT, /* f */ PACK_DIR_STR, /* A */ PACK_DIR_HEX, /* h */ + PACK_DIR_BSTR, /* b */ PACK_DIR_BASE64, /* m */ PACK_DIR_QENC, /* M */ PACK_DIR_NUL, /* x */ PACK_DIR_BACK, /* X */ PACK_DIR_ABS, /* @ */ - PACK_DIR_INVALID + PACK_DIR_NONE, /* - */ }; enum pack_type { @@ -123,9 +123,9 @@ static int unpack_char(mrb_state *mrb, const void *src, int srclen, mrb_value ary, unsigned int flags) { if (flags & PACK_FLAG_SIGNED) - mrb_ary_push(mrb, ary, mrb_fixnum_value(*(signed char *)src)); + mrb_ary_push(mrb, ary, mrb_fixnum_value(*(signed char*)src)); else - mrb_ary_push(mrb, ary, mrb_fixnum_value(*(unsigned char *)src)); + mrb_ary_push(mrb, ary, mrb_fixnum_value(*(unsigned char*)src)); return 1; } @@ -139,7 +139,8 @@ pack_short(mrb_state *mrb, mrb_value o, mrb_value str, mrb_int sidx, unsigned in if (flags & PACK_FLAG_LITTLEENDIAN) { RSTRING_PTR(str)[sidx+0] = n % 256; RSTRING_PTR(str)[sidx+1] = n / 256; - } else { + } + else { RSTRING_PTR(str)[sidx+0] = n / 256; RSTRING_PTR(str)[sidx+1] = n % 256; } @@ -153,7 +154,8 @@ unpack_short(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary if (flags & PACK_FLAG_LITTLEENDIAN) { n = src[1] * 256 + src[0]; - } else { + } + else { n = src[0] * 256 + src[1]; } if ((flags & PACK_FLAG_SIGNED) && (n >= 0x8000)) { @@ -175,7 +177,8 @@ pack_long(mrb_state *mrb, mrb_value o, mrb_value str, mrb_int sidx, unsigned int RSTRING_PTR(str)[sidx+1] = (char)(n >> 8); RSTRING_PTR(str)[sidx+2] = (char)(n >> 16); RSTRING_PTR(str)[sidx+3] = (char)(n >> 24); - } else { + } + else { RSTRING_PTR(str)[sidx+0] = (char)(n >> 24); RSTRING_PTR(str)[sidx+1] = (char)(n >> 16); RSTRING_PTR(str)[sidx+2] = (char)(n >> 8); @@ -231,7 +234,8 @@ unpack_long(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, ul += (uint32_t)src[2] *256*256; ul += (uint32_t)src[1] *256; ul += (uint32_t)src[0]; - } else { + } + else { ul = (uint32_t)src[0] * 256*256*256; ul += (uint32_t)src[1] *256*256; ul += (uint32_t)src[2] *256; @@ -239,7 +243,8 @@ unpack_long(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, } if (flags & PACK_FLAG_SIGNED) { n = (int32_t)ul; - } else { + } + else { #ifndef MRB_INT64 if (UINT_OVERFLOW_P(ul)) { u32tostr(msg, sizeof(msg), ul); @@ -268,7 +273,8 @@ pack_quad(mrb_state *mrb, mrb_value o, mrb_value str, mrb_int sidx, unsigned int RSTRING_PTR(str)[sidx+5] = (char)(n >> 40); RSTRING_PTR(str)[sidx+6] = (char)(n >> 48); RSTRING_PTR(str)[sidx+7] = (char)(n >> 56); - } else { + } + else { RSTRING_PTR(str)[sidx+0] = (char)(n >> 56); RSTRING_PTR(str)[sidx+1] = (char)(n >> 48); RSTRING_PTR(str)[sidx+2] = (char)(n >> 40); @@ -345,7 +351,8 @@ unpack_quad(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, if (flags & PACK_FLAG_LITTLEENDIAN) { pos = 7; step = -1; - } else { + } + else { pos = 0; step = 1; } @@ -363,7 +370,8 @@ unpack_quad(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, } #endif n = (mrb_int)sll; - } else { + } + else { if (UINT_OVERFLOW_P(ull)) { u64tostr(msg, sizeof(msg), ull); mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg); @@ -425,7 +433,7 @@ pack_double(mrb_state *mrb, mrb_value o, mrb_value str, mrb_int sidx, unsigned i { int i; double d; - uint8_t *buffer = (uint8_t *)&d; + uint8_t *buffer = (uint8_t*)&d; str = str_len_ensure(mrb, str, sidx + 8); d = mrb_float(o); @@ -438,7 +446,8 @@ pack_double(mrb_state *mrb, mrb_value o, mrb_value str, mrb_int sidx, unsigned i RSTRING_PTR(str)[sidx + i] = buffer[8 - i - 1]; } } - } else { + } + else { if (littleendian) { for (i = 0; i < 8; i++) { RSTRING_PTR(str)[sidx + i] = buffer[8 - i - 1]; @@ -457,7 +466,7 @@ unpack_double(mrb_state *mrb, const unsigned char * src, int srclen, mrb_value a { int i; double d; - uint8_t *buffer = (uint8_t *)&d; + uint8_t *buffer = (uint8_t*)&d; if (flags & PACK_FLAG_LITTLEENDIAN) { if (littleendian) { @@ -468,7 +477,8 @@ unpack_double(mrb_state *mrb, const unsigned char * src, int srclen, mrb_value a buffer[8 - i - 1] = src[i]; } } - } else { + } + else { if (littleendian) { for (i = 0; i < 8; i++) { buffer[8 - i - 1] = src[i]; @@ -488,7 +498,7 @@ pack_float(mrb_state *mrb, mrb_value o, mrb_value str, mrb_int sidx, unsigned in { int i; float f; - uint8_t *buffer = (uint8_t *)&f; + uint8_t *buffer = (uint8_t*)&f; str = str_len_ensure(mrb, str, sidx + 4); f = (float)mrb_float(o); @@ -501,7 +511,8 @@ pack_float(mrb_state *mrb, mrb_value o, mrb_value str, mrb_int sidx, unsigned in RSTRING_PTR(str)[sidx + i] = buffer[4 - i - 1]; } } - } else { + } + else { if (littleendian) { for (i = 0; i < 4; i++) { RSTRING_PTR(str)[sidx + i] = buffer[4 - i - 1]; @@ -520,7 +531,7 @@ unpack_float(mrb_state *mrb, const unsigned char * src, int srclen, mrb_value ar { int i; float f; - uint8_t *buffer = (uint8_t *)&f; + uint8_t *buffer = (uint8_t*)&f; if (flags & PACK_FLAG_LITTLEENDIAN) { if (littleendian) { @@ -531,7 +542,8 @@ unpack_float(mrb_state *mrb, const unsigned char * src, int srclen, mrb_value ar buffer[4 - i - 1] = src[i]; } } - } else { + } + else { if (littleendian) { for (i = 0; i < 4; i++) { buffer[4 - i - 1] = src[i]; @@ -660,7 +672,7 @@ unpack_utf8(mrb_state *mrb, const unsigned char * src, int srclen, mrb_value ary if (srclen == 0) { return 1; } - uv = utf8_to_uv(mrb, (const char *)src, &lenp); + uv = utf8_to_uv(mrb, (const char*)src, &lenp); mrb_ary_push(mrb, ary, mrb_fixnum_value((mrb_int)uv)); return (int)lenp; } @@ -681,13 +693,16 @@ pack_str(mrb_state *mrb, mrb_value src, mrb_value dst, mrb_int didx, int count, if (count == 0) { return 0; - } else if (count == -1) { + } + else if (count == -1) { copylen = slen; padlen = (flags & PACK_FLAG_Z) ? 1 : 0; - } else if (count < slen) { + } + else if (count < slen) { copylen = count; padlen = 0; - } else { + } + else { copylen = slen; padlen = count - slen; } @@ -719,14 +734,14 @@ unpack_str(mrb_state *mrb, const void *src, int slen, mrb_value ary, int count, const char *cp, *sptr; int copylen; - sptr = (const char *)src; + sptr = (const char*)src; if (count != -1 && count < slen) { slen = count; } copylen = slen; if (slen >= 0 && flags & PACK_FLAG_Z) { /* "Z" */ - if ((cp = (const char *)memchr(sptr, '\0', slen)) != NULL) { + if ((cp = (const char*)memchr(sptr, '\0', slen)) != NULL) { copylen = (int)(cp - sptr); if (count == -1) { slen = copylen + 1; @@ -760,14 +775,16 @@ pack_hex(mrb_state *mrb, mrb_value src, mrb_value dst, mrb_int didx, int count, if (flags & PACK_FLAG_LSB) { ashift = 0; bshift = 4; - } else { + } + else { ashift = 4; bshift = 0; } if (count == -1) { count = slen; - } else if (slen > count) { + } + else if (slen > count) { slen = count; } @@ -807,12 +824,13 @@ unpack_hex(mrb_state *mrb, const void *src, int slen, mrb_value ary, int count, if (flags & PACK_FLAG_LSB) { ashift = 0; bshift = 4; - } else { + } + else { ashift = 4; bshift = 0; } - sptr = (const char *)src; + sptr = (const char*)src; if (count == -1) count = slen * 2; @@ -842,6 +860,92 @@ unpack_hex(mrb_state *mrb, const void *src, int slen, mrb_value ary, int count, return (int)(sptr - sptr0); } +static int +pack_bstr(mrb_state *mrb, mrb_value src, mrb_value dst, mrb_int didx, int count, unsigned int flags) +{ + const char *sptr = RSTRING_PTR(src); + int slen = (int)RSTRING_LEN(src); + + if (count == -1) { + count = slen; + } + else if (slen > count) { + slen = count; + } + + dst = str_len_ensure(mrb, dst, didx + count); + char *dptr = RSTRING_PTR(dst) + didx; + char *dptr0 = dptr; + + unsigned int byte = 0; + for (int i=0; i++ < slen; sptr++) { + if (flags & PACK_FLAG_LSB) { + if (*sptr & 1) + byte |= 128; + if (i & 7) + byte >>= 1; + else { + char c = (char)(byte&0xff); + *dptr++ = c; + byte = 0; + } + } + else { + byte |= *sptr & 1; + if (i & 7) + byte <<= 1; + else { + char c = (char)(byte&0xff); + *dptr++ = c; + byte = 0; + } + } + } + if (slen & 7) { + if (flags & PACK_FLAG_LSB) { + byte >>= 7 - (slen & 7); + } + else { + byte <<= 7 - (slen & 7); + } + char c = (char)(byte&0xff); + *dptr++ = c; + } + return (int)(dptr - dptr0); +} + +static int +unpack_bstr(mrb_state *mrb, const void *src, int slen, mrb_value ary, int count, unsigned int flags) +{ + CHECK_UNPACK_LEN(mrb, slen, ary); + + const char *sptr0 = (const char*)src; + const char *sptr = sptr0; + if (count == -1 || count > slen * 8) + count = slen * 8; + + mrb_value dst = mrb_str_new(mrb, NULL, count); + char *dptr = RSTRING_PTR(dst); + const char *dptr0 = dptr; + int bits = 0; + + for (int i=0; i>= 1; + else bits = (unsigned char)*sptr++; + *dptr++ = (bits & 1) ? '1' : '0'; + } + else { + if (i & 7) bits <<= 1; + else bits = (unsigned char)*sptr++; + *dptr++ = (bits & 128) ? '1' : '0'; + } + } + dst = mrb_str_resize(mrb, dst, (mrb_int)(dptr - dptr0)); + mrb_ary_push(mrb, ary, dst); + return (int)(sptr - sptr0); +} + static int pack_base64(mrb_state *mrb, mrb_value src, mrb_value dst, mrb_int didx, int count) { @@ -858,7 +962,8 @@ pack_base64(mrb_state *mrb, mrb_value src, mrb_value dst, mrb_int didx, int coun if (count != 0 && count < 3) { /* -1, 1 or 2 */ count = 45; - } else if (count >= 3) { + } + else if (count >= 3) { count -= count % 3; } @@ -892,7 +997,8 @@ pack_base64(mrb_state *mrb, mrb_value src, mrb_value dst, mrb_int didx, int coun *dstptr++ = '='; *dstptr++ = '='; column += 3; - } else if (srclen == 2) { + } + else if (srclen == 2) { l = (unsigned char)*srcptr++ << 16; l += (unsigned char)*srcptr++ << 8; *dstptr++ = base64chars[(l >> 18) & 0x3f]; @@ -921,7 +1027,7 @@ unpack_base64(mrb_state *mrb, const void *src, int slen, mrb_value ary) const char *sptr, *sptr0; char *dptr, *dptr0; - sptr0 = sptr = (const char *)src; + sptr0 = sptr = (const char*)src; dlen = slen / 4 * 3; /* an estimated value - may be shorter */ dst = mrb_str_new(mrb, NULL, dlen); @@ -950,11 +1056,13 @@ unpack_base64(mrb_state *mrb, const void *src, int slen, mrb_value ary) *dptr++ = (l >> 16) & 0xff; *dptr++ = (l >> 8) & 0xff; *dptr++ = l & 0xff; - } else if (padding == 1) { + } + else if (padding == 1) { *dptr++ = (l >> 16) & 0xff; *dptr++ = (l >> 8) & 0xff; break; - } else { + } + else { *dptr++ = (l >> 16) & 0xff; break; } @@ -1095,8 +1203,8 @@ has_tmpl(const struct tmpl *tmpl) return (tmpl->idx < RSTRING_LEN(tmpl->str)); } -static void -read_tmpl(mrb_state *mrb, struct tmpl *tmpl, enum pack_dir *dirp, enum pack_type *typep, int *sizep, int *countp, unsigned int *flagsp) +static enum pack_dir +read_tmpl(mrb_state *mrb, struct tmpl *tmpl, enum pack_type *typep, int *sizep, int *countp, unsigned int *flagsp) { mrb_int t, tlen; int ch, size = 0; @@ -1109,8 +1217,10 @@ read_tmpl(mrb_state *mrb, struct tmpl *tmpl, enum pack_dir *dirp, enum pack_type tptr = RSTRING_PTR(tmpl->str); tlen = RSTRING_LEN(tmpl->str); + restart: + if (tmpl->idx >= tlen) return PACK_DIR_NONE; t = tptr[tmpl->idx++]; -alias: + alias: switch (t) { case 'A': dir = PACK_DIR_STR; @@ -1179,6 +1289,16 @@ alias: type = PACK_TYPE_STRING; flags |= PACK_FLAG_COUNT2 | PACK_FLAG_LSB; break; + case 'B': + dir = PACK_DIR_BSTR; + type = PACK_TYPE_STRING; + flags |= PACK_FLAG_COUNT2; + break; + case 'b': + dir = PACK_DIR_BSTR; + type = PACK_TYPE_STRING; + flags |= PACK_FLAG_COUNT2 | PACK_FLAG_LSB; + break; case 'I': switch (sizeof(int)) { case 2: t = 'S'; goto alias; @@ -1197,6 +1317,22 @@ alias: mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(int) == %d", (int)sizeof(int)); } break; + case 'J': + switch (sizeof(intptr_t)) { + case 4: t = 'L'; goto alias; + case 8: t = 'Q'; goto alias; + default: + mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(uintptr_t) == %d", (int)sizeof(uintptr_t)); + } + break; + case 'j': + switch (sizeof(intptr_t)) { + case 4: t = 'l'; goto alias; + case 8: t = 'q'; goto alias; + default: + mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(intptr_t) == %d", (int)sizeof(intptr_t)); + } + break; case 'L': dir = PACK_DIR_LONG; type = PACK_TYPE_INTEGER; @@ -1290,14 +1426,22 @@ alias: type = PACK_TYPE_STRING; flags |= PACK_FLAG_WIDTH | PACK_FLAG_COUNT2 | PACK_FLAG_Z; break; + case '#': + while (++tmpl->idx < tlen && tptr[tmpl->idx] != '\n') + ; + goto restart; + case 'p': case 'P': case '%': mrb_raisef(mrb, E_ARGUMENT_ERROR, "%c is not supported", (char)t); break; default: - dir = PACK_DIR_INVALID; - type = PACK_TYPE_NONE; - break; + if (!ISSPACE((char)t)) { + char c = (char)t; + mrb_value s = mrb_str_new(mrb, &c, 1); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "unknown unpack directive %!v", s); + } + goto restart; } /* read suffix [0-9*_!<>] */ @@ -1312,20 +1456,24 @@ alias: count = (int)n; tmpl->idx = (int)(e - tptr); continue; - } else if (ch == '*') { + } + else if (ch == '*') { if (type == PACK_TYPE_NONE) count = 0; else count = -1; - } else if (ch == '_' || ch == '!' || ch == '<' || ch == '>') { + } + else if (ch == '_' || ch == '!' || ch == '<' || ch == '>') { if (strchr("sSiIlLqQ", (int)t) == NULL) { mrb_raisef(mrb, E_ARGUMENT_ERROR, "'%c' allowed only after types sSiIlLqQ", ch); } if (ch == '_' || ch == '!') { flags |= PACK_FLAG_s; - } else if (ch == '<') { + } + else if (ch == '<') { flags |= PACK_FLAG_LT; - } else if (ch == '>') { + } + else if (ch == '>') { flags |= PACK_FLAG_GT; } } @@ -1339,11 +1487,11 @@ alias: flags |= PACK_FLAG_LITTLEENDIAN; } - *dirp = dir; *typep = type; *sizep = size; *countp = count; *flagsp = flags; + return dir; } static mrb_value @@ -1364,11 +1512,10 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary) aidx = 0; ridx = 0; while (has_tmpl(&tmpl)) { - read_tmpl(mrb, &tmpl, &dir, &type, &size, &count, &flags); + dir = read_tmpl(mrb, &tmpl, &type, &size, &count, &flags); - if (dir == PACK_DIR_INVALID) - continue; - else if (dir == PACK_DIR_NUL) { + if (dir == PACK_DIR_NONE) break; + if (dir == PACK_DIR_NUL) { grow: if (ridx > INT_MAX - count) goto overflow; ridx += pack_nul(mrb, result, ridx, count); @@ -1395,7 +1542,7 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary) if (count == 0 && !(flags & PACK_FLAG_WIDTH)) break; - o = mrb_ary_ref(mrb, ary, aidx); + o = RARRAY_PTR(ary)[aidx]; if (type == PACK_TYPE_INTEGER) { o = mrb_ensure_int_type(mrb, o); } @@ -1437,6 +1584,9 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary) case PACK_DIR_HEX: ridx += pack_hex(mrb, o, result, ridx, count, flags); break; + case PACK_DIR_BSTR: + ridx += pack_bstr(mrb, o, result, ridx, count, flags); + break; case PACK_DIR_STR: ridx += pack_str(mrb, o, result, ridx, count, flags); break; @@ -1493,11 +1643,10 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single) result = mrb_ary_new(mrb); while (has_tmpl(&tmpl)) { - read_tmpl(mrb, &tmpl, &dir, &type, &size, &count, &flags); + dir = read_tmpl(mrb, &tmpl, &type, &size, &count, &flags); - if (dir == PACK_DIR_INVALID) - continue; - else if (dir == PACK_DIR_NUL) { + if (dir == PACK_DIR_NONE) break; + if (dir == PACK_DIR_NUL) { check_x(mrb, srclen-srcidx, count, 'x'); srcidx += count; continue; @@ -1514,11 +1663,14 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single) } /* PACK_FLAG_COUNT2 directions */ - sptr = (const unsigned char *)RSTRING_PTR(str) + srcidx; + sptr = (const unsigned char*)RSTRING_PTR(str) + srcidx; switch (dir) { case PACK_DIR_HEX: srcidx += unpack_hex(mrb, sptr, srclen - srcidx, result, count, flags); continue; + case PACK_DIR_BSTR: + srcidx += unpack_bstr(mrb, sptr, srclen - srcidx, result, count, flags); + continue; case PACK_DIR_STR: srcidx += unpack_str(mrb, sptr, srclen - srcidx, result, count, flags); continue; @@ -1575,12 +1727,12 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single) count--; } } - if (single) { - if (RARRAY_LEN(result) > 0) { - return RARRAY_PTR(result)[0]; - } - return mrb_nil_value(); + } + if (single) { + if (RARRAY_LEN(result) > 0) { + return RARRAY_PTR(result)[0]; } + return mrb_nil_value(); } return result; } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/test/pack.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/test/pack.rb index 4dd7f4a900..6045f788f6 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/test/pack.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-pack/test/pack.rb @@ -38,6 +38,16 @@ assert('pack("M")') do assert_equal ["あ"], "=E3=81=82=\n".unpack("M") end +# pack & unpack 'B'/'b' +assert('pack("B/b")') do + assert_pack "b*", "\xFF\x00", ["1111111100000000"] + assert_pack "b*", "\x01\x02", ["1000000001000000"] + assert_pack "b3", "\x01", ["100"] + + assert_pack "B*", "\xFF\x00", ["1111111100000000"] + assert_pack "B*", "\x01\x02", ["0000000100000010"] +end + # pack & unpack 'H' assert('pack("H")') do assert_pack "H*", "01", ["3031"] diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-print/mrblib/print.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-print/mrblib/print.rb index a8a23ea907..9047f5e8fd 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-print/mrblib/print.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-print/mrblib/print.rb @@ -6,32 +6,20 @@ module Kernel ## # Print human readable object description # - # ISO 15.3.1.2.9 - # ISO 15.3.1.3.34 + # ISO 15.3.1.2.9 Kernel.p + # ISO 15.3.1.3.34 Kernel#p def p(*args) i = 0 len = args.size while i < len - __printstr__ args[i].inspect - __printstr__ "\n" + print args[i].inspect, "\n" i += 1 end args.__svalue end - # 15.3.1.2.10 - # 15.3.1.3.35 - def print(*args) - i = 0 - len = args.size - while i < len - __printstr__ args[i].to_s - i += 1 - end - end - - # 15.3.1.2.11 - # 15.3.1.3.39 + # ISO 15.3.1.2.11 Kernel.puts + # ISO 15.3.1.3.39 Kernel#puts def puts(*args) i = 0 len = args.size @@ -41,15 +29,15 @@ module Kernel puts(*s) else s = s.to_s - __printstr__ s - __printstr__ "\n" if (s[-1] != "\n") + print s + print "\n" if (s[-1] != "\n") end i += 1 end - __printstr__ "\n" if len == 0 + print "\n" if len == 0 end def printf(*args) - __printstr__(sprintf(*args)) + print(sprintf(*args)) end end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-print/src/print.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-print/src/print.c index f6d6d46f05..94cab36ef2 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-print/src/print.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-print/src/print.c @@ -13,13 +13,13 @@ # define isatty(x) _isatty(x) # define fileno(x) _fileno(x) #endif +#else +# include #endif -static mrb_value -mrb_printstr(mrb_state *mrb, mrb_value self) +static void +printstr(mrb_state *mrb, mrb_value s) { - mrb_value s = mrb_get_arg1(mrb); - if (mrb_string_p(s)) { const char *p = RSTRING_PTR(s); mrb_int len = RSTRING_LEN(s); @@ -35,21 +35,33 @@ mrb_printstr(mrb_state *mrb, mrb_value self) utf16, (DWORD)wlen, &written, NULL); } mrb_free(mrb, utf16); + return; } - else #endif - { - fwrite(p, (size_t)len, 1, stdout); - } - fflush(stdout); + fwrite(p, (size_t)len, 1, stdout); } +} + +// ISO 15.3.1.2.10 Kernel.print +// ISO 15.3.1.3.35 Kernel#print +static mrb_value +mrb_print(mrb_state *mrb, mrb_value self) +{ + mrb_int argc = mrb_get_argc(mrb); + const mrb_value *argv = mrb_get_argv(mrb); + + for (mrb_int i=0; ikernel_module, "__printstr__", mrb_printstr, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, mrb->kernel_module, "print", mrb_print, MRB_ARGS_ANY()); /* 15.3.1.3.35 */ } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-binding/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-binding/mrbgem.rake index 4aa8829734..53e6faaef0 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-binding/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-binding/mrbgem.rake @@ -3,8 +3,8 @@ MRuby::Gem::Specification.new('mruby-proc-binding') do |spec| spec.author = 'mruby developers' spec.summary = 'Proc#binding method' - spec.add_dependency('mruby-binding-core', :core => 'mruby-binding-core') + spec.add_dependency('mruby-binding', :core => 'mruby-binding') spec.add_dependency('mruby-proc-ext', :core => 'mruby-proc-ext') - spec.add_test_dependency('mruby-binding', :core => 'mruby-binding') + spec.add_test_dependency('mruby-eval', :core => 'mruby-eval') spec.add_test_dependency('mruby-compiler', :core => 'mruby-compiler') end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-binding/src/proc-binding.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-binding/src/proc-binding.c index d176034d2d..fd494efcde 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-binding/src/proc-binding.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-binding/src/proc-binding.c @@ -4,16 +4,14 @@ #include /* provided by mruby-proc-ext */ -mrb_value mrb_proc_source_location(mrb_state *mrb, struct RProc *p); +mrb_value mrb_proc_source_location(mrb_state *mrb, const struct RProc *p); -/* provided by mruby-binding-core */ -mrb_value mrb_binding_alloc(mrb_state *mrb); -struct RProc *mrb_binding_wrap_lvspace(mrb_state *mrb, const struct RProc *proc, struct REnv **envp); +/* provided by mruby-binding */ +mrb_value mrb_binding_new(mrb_state *mrb, const struct RProc *proc, mrb_value recv, struct REnv *env); static mrb_value mrb_proc_binding(mrb_state *mrb, mrb_value procval) { - mrb_value binding = mrb_binding_alloc(mrb); const struct RProc *proc = mrb_proc_ptr(procval); struct REnv *env; @@ -30,10 +28,7 @@ mrb_proc_binding(mrb_state *mrb, mrb_value procval) receiver = MRB_ENV_LEN(env) > 0 ? env->stack[0] : mrb_nil_value(); } - proc = mrb_binding_wrap_lvspace(mrb, proc, &env); - mrb_iv_set(mrb, binding, MRB_SYM(proc), mrb_obj_value((void *)proc)); - mrb_iv_set(mrb, binding, MRB_SYM(recv), receiver); - mrb_iv_set(mrb, binding, MRB_SYM(env), mrb_obj_value(env)); + mrb_value binding = mrb_binding_new(mrb, proc, receiver, env); mrb_iv_set(mrb, binding, MRB_SYM(source_location), mrb_proc_source_location(mrb, mrb_proc_ptr(procval))); return binding; } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-ext/src/proc.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-ext/src/proc.c index 4e90371c5a..b022d5d28f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-ext/src/proc.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-ext/src/proc.c @@ -7,39 +7,42 @@ #include static mrb_value -mrb_proc_lambda_p(mrb_state *mrb, mrb_value self) +proc_lambda_p(mrb_state *mrb, mrb_value self) { struct RProc *p = mrb_proc_ptr(self); return mrb_bool_value(MRB_PROC_STRICT_P(p)); } mrb_value -mrb_proc_source_location(mrb_state *mrb, struct RProc *p) +mrb_proc_source_location(mrb_state *mrb, const struct RProc *p) { if (MRB_PROC_CFUNC_P(p)) { return mrb_nil_value(); } - else { - const mrb_irep *irep = p->body.irep; - int32_t line; - const char *filename; - filename = mrb_debug_get_filename(mrb, irep, 0); - line = mrb_debug_get_line(mrb, irep, 0); - - return (!filename && line == -1)? mrb_nil_value() - : mrb_assoc_new(mrb, mrb_str_new_cstr(mrb, filename), mrb_fixnum_value(line)); + /* handle alias */ + if (MRB_PROC_ALIAS_P(p)) { + p = p->upper; } + + const mrb_irep *irep = p->body.irep; + int32_t line; + const char *filename; + + if (!mrb_debug_get_position(mrb, irep, 0, &line, &filename)) { + return mrb_nil_value(); + } + return mrb_assoc_new(mrb, mrb_str_new_cstr(mrb, filename), mrb_fixnum_value(line)); } static mrb_value -mrb_proc_source_location_m(mrb_state *mrb, mrb_value self) +proc_source_location(mrb_state *mrb, mrb_value self) { return mrb_proc_source_location(mrb, mrb_proc_ptr(self)); } static mrb_value -mrb_proc_inspect(mrb_state *mrb, mrb_value self) +proc_inspect(mrb_state *mrb, mrb_value self) { struct RProc *p = mrb_proc_ptr(self); mrb_value str = mrb_str_new_lit(mrb, "#proc_class; - mrb_define_method(mrb, p, "lambda?", mrb_proc_lambda_p, MRB_ARGS_NONE()); - mrb_define_method(mrb, p, "source_location", mrb_proc_source_location_m, MRB_ARGS_NONE()); - mrb_define_method(mrb, p, "to_s", mrb_proc_inspect, MRB_ARGS_NONE()); - mrb_define_method(mrb, p, "inspect", mrb_proc_inspect, MRB_ARGS_NONE()); - mrb_define_method(mrb, p, "parameters", mrb_proc_parameters, MRB_ARGS_NONE()); + mrb_define_method(mrb, p, "lambda?", proc_lambda_p, MRB_ARGS_NONE()); + mrb_define_method(mrb, p, "source_location", proc_source_location, MRB_ARGS_NONE()); + mrb_define_method(mrb, p, "to_s", proc_inspect, MRB_ARGS_NONE()); + mrb_define_method(mrb, p, "inspect", proc_inspect, MRB_ARGS_NONE()); + mrb_define_method(mrb, p, "parameters", mrb_proc_parameters, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, mrb->kernel_module, "proc", mrb_kernel_proc, MRB_ARGS_NONE()|MRB_ARGS_BLOCK()); - mrb_define_method(mrb, mrb->kernel_module, "proc", mrb_kernel_proc, MRB_ARGS_NONE()|MRB_ARGS_BLOCK()); + mrb_define_method(mrb, mrb->kernel_module, "proc", kernel_proc, MRB_ARGS_NONE()|MRB_ARGS_BLOCK()); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-ext/test/proc.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-ext/test/proc.rb index 7ac5084063..13e7058f91 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-ext/test/proc.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-proc-ext/test/proc.rb @@ -7,8 +7,8 @@ def enable_debug_info? raise rescue => e @enable_debug_info = !e.backtrace.empty? - if(@enable_debug_info && e.backtrace[0].include?("(unknown)")) - @enable_debug_info = false + if @enable_debug_info && e.backtrace[0].include?("(unknown)") + @enable_debug_info = false end return @enable_debug_info end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-random/src/random.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-random/src/random.c index d16ef3329a..c47702e944 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-random/src/random.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-random/src/random.c @@ -222,8 +222,7 @@ random_m_bytes(mrb_state *mrb, mrb_value self) { rand_state *t = random_ptr(self); - mrb_int i; - mrb_get_args(mrb, "i", &i); + mrb_int i = mrb_as_int(mrb, mrb_get_arg1(mrb)); mrb_value bytes = mrb_str_new(mrb, NULL, i); uint8_t *p = (uint8_t*)RSTRING_PTR(bytes); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/mrblib/range.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/mrblib/range.rb index 8b670afeec..7fc05c1903 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/mrblib/range.rb @@ -96,4 +96,29 @@ class Range # delegate to Enumerable super() end + + # Compare two ranges and see if they overlap each other + # (1..5).overlap?(4..6) # => true + # (1..5).overlap?(7..9) # => false + def overlap?(other) + raise TypeError, "argument must be a range" unless other.kind_of?(Range) + + self_begin = self.begin + other_end = other.end + other_excl = other.exclude_end? + + return false if __empty_range?(self_begin, other_end, other_excl) + + other_begin = other.begin + self_end = self.end + self_excl = self.exclude_end? + + return false if __empty_range?(other_begin, self_end, self_excl) + return true if self_begin == other_begin + + return false if __empty_range?(self_begin, self_end, self_excl) + return false if __empty_range?(other_begin, other_end, other_excl) + + true + end end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/src/range.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/src/range.c index 9aaeac810a..d1d331069e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/src/range.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/src/range.c @@ -189,6 +189,20 @@ range_size(mrb_state *mrb, mrb_value range) } #endif /* MRB_NO_FLOAT */ +static mrb_value +range_empty_p(mrb_state *mrb, mrb_value range) +{ + mrb_value b, e; + mrb_bool excl; + + mrb_get_args(mrb, "oob", &b, &e, &excl); + if (mrb_nil_p(b) || mrb_nil_p(e)) + return mrb_false_value(); + + mrb_int comp = mrb_cmp(mrb, b, e); + return mrb_bool_value(comp == -2 || comp > 0 || (comp == 0 && excl)); +} + void mrb_mruby_range_ext_gem_init(mrb_state* mrb) { @@ -196,6 +210,7 @@ mrb_mruby_range_ext_gem_init(mrb_state* mrb) mrb_define_method(mrb, s, "cover?", range_cover, MRB_ARGS_REQ(1)); mrb_define_method(mrb, s, "size", range_size, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "__empty_range?", range_empty_p, MRB_ARGS_REQ(3)); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/test/range.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/test/range.rb index 4ae575669a..d377129265 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/test/range.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-range-ext/test/range.rb @@ -178,3 +178,37 @@ assert('Range#min given a block') do assert_equal nil, ((100..10).min { |x, y| x <=> y }) assert_equal nil, ((5...5).min { |x, y| x <=> y }) end + +assert('Range#overlap?') do + assert_false((0..2).overlap?(-2..-1)) + assert_false((0..2).overlap?(-2...0)) + assert_true((0..2).overlap?(-1..0)) + assert_true((0..2).overlap?(1..2)) + assert_true((0..2).overlap?(2..3)) + assert_false((0..2).overlap?(3...4)) + assert_false((0...2).overlap?(2..3)) + + assert_true((..0).overlap?(-1..0)) + assert_true((...0).overlap?(-1..0)) + assert_true((..0).overlap?(0..1)) + assert_true((..0).overlap?(..1)) + assert_false((..0).overlap?(1..2)) + assert_false((...0).overlap?(0..1)) + + assert_false((0..).overlap?(-2..-1)) + assert_false((0..).overlap?(...0)) + assert_true((0..).overlap?(..0)) + assert_true((0..).overlap?(0..1)) + assert_true((0..).overlap?(1..2)) + assert_true((0..).overlap?(-1..0)) + assert_true((0..).overlap?(1..)) + + assert_true((0..).overlap?(-1..0)) + assert_true((0..).overlap?(..0)) + assert_true((0..).overlap?(0..1)) + assert_true((0..).overlap?(1..2)) + assert_true((0..).overlap?(1..)) + + assert_raise(TypeError) { (0..).overlap?(1) } + assert_raise(TypeError) { (0..).overlap?(nil) } +end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-rational/src/rational.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-rational/src/rational.c index 3b13fb57c0..b3a5f945c3 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-rational/src/rational.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-rational/src/rational.c @@ -202,8 +202,6 @@ float_decode_internal(mrb_state *mrb, mrb_float f, mrb_float *rf, int *n) *rf = f; } -void mrb_check_num_exact(mrb_state *mrb, mrb_float num); - static mrb_value rational_new_f(mrb_state *mrb, mrb_float f0) { @@ -487,7 +485,7 @@ rational_cmp(mrb_state *mrb, mrb_value x) } #endif default: - x = mrb_funcall_id(mrb, y, MRB_OPSYM(cmp), 1, x); + x = mrb_funcall_argv(mrb, y, MRB_OPSYM(cmp), 1, &x); if (mrb_integer_p(x)) { mrb_int z = mrb_integer(x); return mrb_fixnum_value(-z); @@ -544,7 +542,7 @@ mrb_rational_add(mrb_state *mrb, mrb_value x, mrb_value y) #endif default: - return mrb_funcall_id(mrb, y, MRB_OPSYM(add), 1, x); + return mrb_funcall_argv(mrb, y, MRB_OPSYM(add), 1, &x); } } @@ -642,7 +640,7 @@ mrb_rational_mul(mrb_state *mrb, mrb_value x, mrb_value y) #endif default: - return mrb_funcall_id(mrb, y, MRB_OPSYM(mul), 1, x); + return mrb_funcall_argv(mrb, y, MRB_OPSYM(mul), 1, &x); } } @@ -770,6 +768,7 @@ void mrb_mruby_rational_gem_init(mrb_state *mrb) rat = mrb_define_class_id(mrb, MRB_SYM(Rational), mrb_class_get_id(mrb, MRB_SYM(Numeric))); MRB_SET_INSTANCE_TT(rat, MRB_TT_RATIONAL); + MRB_UNDEF_ALLOCATOR(rat); mrb_undef_class_method(mrb, rat, "new"); mrb_define_class_method(mrb, rat, "_new", rational_s_new, MRB_ARGS_REQ(2)); mrb_define_method(mrb, rat, "numerator", rational_numerator, MRB_ARGS_NONE()); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-set/mrblib/set.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-set/mrblib/set.rb index 0116e187e5..b0594663fc 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-set/mrblib/set.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-set/mrblib/set.rb @@ -140,9 +140,9 @@ class Set end end - def disjoint?(set) - !intersect?(set) - end + def disjoint?(set) + !intersect?(set) + end def each(&block) return to_enum :each unless block_given? @@ -190,10 +190,10 @@ class Set end def collect! - return to_enum :collect! unless block_given? - set = self.class.new - each { |o| set << yield(o) } - replace(set) + return to_enum :collect! unless block_given? + set = self.class.new + each { |o| set << yield(o) } + replace(set) end alias map! collect! @@ -306,17 +306,13 @@ class Set to_a.join(separator) end - def _inspect(recur_list) + def inspect return "#<#{self.class}: {}>" if empty? - return "#<#{self.class}: {...}>" if recur_list[self.object_id] - recur_list[self.object_id] = true - ary = map { |o| o._inspect(recur_list) } + return "#<#{self.class}: {...}>" if self.__inspect_recursive? + ary = map {|o| o.inspect } "#<#{self.class}: {#{ary.join(", ")}}>" end - def inspect - _inspect({}) - end alias to_s inspect def reset diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-sleep/src/sleep.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-sleep/src/sleep.c index d05bc1944d..4b30ceaea1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-sleep/src/sleep.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-sleep/src/sleep.c @@ -40,7 +40,7 @@ /* not implemented forever sleep (called without an argument)*/ static mrb_value -mrb_f_sleep(mrb_state *mrb, mrb_value self) +f_sleep(mrb_state *mrb, mrb_value self) { time_t beg = time(0); time_t end; @@ -60,7 +60,8 @@ mrb_f_sleep(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "i", &sec); if (sec >= 0) { sleep(sec); - } else { + } + else { mrb_raise(mrb, E_ARGUMENT_ERROR, "time interval must not be negative"); } #endif @@ -71,7 +72,7 @@ mrb_f_sleep(mrb_state *mrb, mrb_value self) /* mruby special; needed for mruby without float numbers */ static mrb_value -mrb_f_usleep(mrb_state *mrb, mrb_value self) +f_usleep(mrb_state *mrb, mrb_value self) { mrb_int usec; #ifdef _WIN32 @@ -94,7 +95,8 @@ mrb_f_usleep(mrb_state *mrb, mrb_value self) if (usec >= 0) { usleep(usec); - } else { + } + else { mrb_raise(mrb, E_ARGUMENT_ERROR, "time interval must not be negative"); } @@ -126,8 +128,8 @@ mrb_f_usleep(mrb_state *mrb, mrb_value self) void mrb_mruby_sleep_gem_init(mrb_state *mrb) { - mrb_define_method(mrb, mrb->kernel_module, "sleep", mrb_f_sleep, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, mrb->kernel_module, "usleep", mrb_f_usleep, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, mrb->kernel_module, "sleep", f_sleep, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, mrb->kernel_module, "usleep", f_usleep, MRB_ARGS_REQ(1)); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/README.md b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/README.md index f88ae35054..f7ff8ca320 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/README.md +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/README.md @@ -20,8 +20,8 @@ Date: Tue, 21 May 2013 04:31:30 GMT ## Requirement -- [mruby-io](https://github.com/mruby/mruby/tree/master/mrbgems/mruby-io) mrbgem -- [iij/mruby-mtest](https://github.com/iij/mruby-mtest) mrgbem to run tests +- [mruby-io](../mruby-io) mrbgem +- [iij/mruby-mtest](https://github.com/iij/mruby-mtest) mrbgem to run tests - system must have RFC3493 basic socket interface - and some POSIX API... diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/mrbgem.rake index dba00c646a..c3684cd0c1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/mrbgem.rake @@ -1,6 +1,6 @@ MRuby::Gem::Specification.new('mruby-socket') do |spec| spec.license = 'MIT' - spec.authors = ['Internet Initiative Japan', 'mruby developers'] + spec.authors = ['Internet Initiative Japan Inc.', 'mruby developers'] spec.summary = 'standard socket class' #spec.cc.defines << "HAVE_SA_LEN=0" @@ -12,6 +12,6 @@ MRuby::Gem::Specification.new('mruby-socket') do |spec| end spec.add_dependency('mruby-io', :core => 'mruby-io') - spec.add_dependency('mruby-pack', :core => 'mruby-pack') + spec.add_dependency('mruby-error', :core => 'mruby-error') # spec.add_dependency('mruby-mtest') end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/mrblib/socket.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/mrblib/socket.rb index 0e7bbdcc1c..43b57952b1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/mrblib/socket.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/mrblib/socket.rb @@ -19,7 +19,6 @@ class Addrinfo end @socktype = socktype @protocol = protocol - @canonname = nil end def self.foreach(nodename, service, family=nil, socktype=nil, protocol=nil, flags=0, &block) @@ -49,9 +48,7 @@ class Addrinfo end #def bind - - attr_reader :canonname - + #def canonname #def connect #def connect_from #def connect_to @@ -70,10 +67,10 @@ class Addrinfo else proto = '???' end - "#" else - "#" + proto = "SOCK_STREAM" end + "#" end def inspect_sockaddr @@ -254,7 +251,7 @@ class TCPSocket < IPSocket end end - def self.new_with_prelude pre, *args + def self._new_with_prelude(*args, &pre) o = self._allocate o.instance_eval(&pre) o.initialize(*args) @@ -280,7 +277,9 @@ class TCPServer < TCPSocket def accept fd = self.sysaccept begin - TCPSocket.new_with_prelude(proc { @init_with_fd = true }, fd, "r+") + TCPSocket._new_with_prelude(fd, "r+") { + @init_with_fd = true + } rescue IO._sysclose(fd) rescue nil raise @@ -570,52 +569,4 @@ class UNIXServer < UNIXSocket end end -class Socket - include Constants -end - -class Socket - class Option - def initialize(family, level, optname, data) - @family = family - @level = level - @optname = optname - @data = data - end - - def self.bool(family, level, optname, bool) - self.new(family, level, optname, [(bool ? 1 : 0)].pack('i')) - end - - def self.int(family, level, optname, integer) - self.new(family, level, optname, [integer].pack('i')) - end - - #def self.linger(family, level, optname, integer) - #end - - attr_reader :data, :family, :level, :optname - - def bool - @data.unpack('i')[0] != 0 - end - - def inspect - "#" - end - - def int - @data.unpack('i')[0] - end - - def linger - raise NotImplementedError.new - end - - def unpack(template) - raise NotImplementedError.new - end - end -end - class SocketError < StandardError; end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/src/socket.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/src/socket.c index a9ce33d2e9..73d89e6c3d 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/src/socket.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-socket/src/socket.c @@ -56,24 +56,22 @@ #ifdef _WIN32 static const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { - if (af == AF_INET) - { + if (af == AF_INET) { struct sockaddr_in in = {0}; in.sin_family = AF_INET; memcpy(&in.sin_addr, src, sizeof(struct in_addr)); - getnameinfo((struct sockaddr *)&in, sizeof(struct - sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST); + getnameinfo((struct sockaddr*)&in, sizeof(struct sockaddr_in), + dst, cnt, NULL, 0, NI_NUMERICHOST); return dst; } - else if (af == AF_INET6) - { + else if (af == AF_INET6) { struct sockaddr_in6 in = {0}; in.sin6_family = AF_INET6; memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); - getnameinfo((struct sockaddr *)&in, sizeof(struct - sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST); + getnameinfo((struct sockaddr*)&in, sizeof(struct sockaddr_in6), + dst, cnt, NULL, 0, NI_NUMERICHOST); return dst; } return NULL; @@ -86,16 +84,14 @@ static int inet_pton(int af, const char *src, void *dst) hints.ai_family = af; - if (getaddrinfo(src, NULL, &hints, &res) != 0) - { + if (getaddrinfo(src, NULL, &hints, &res) != 0) { printf("Couldn't resolve host %s\n", src); return -1; } ressave = res; - while (res) - { + while (res) { memcpy(dst, res->ai_addr, res->ai_addrlen); res = res->ai_next; } @@ -106,37 +102,57 @@ static int inet_pton(int af, const char *src, void *dst) #endif +struct gen_addrinfo_args { + struct RClass *klass; + struct addrinfo *addrinfo; +}; + +static mrb_value +gen_addrinfo(mrb_state *mrb, mrb_value args) +{ + mrb_value ary = mrb_ary_new(mrb); + int arena_idx = mrb_gc_arena_save(mrb); /* ary must be on arena! */ + struct gen_addrinfo_args *a = (struct gen_addrinfo_args*)mrb_cptr(args); + + for (struct addrinfo *res = a->addrinfo; res != NULL; res = res->ai_next) { + mrb_value sa = mrb_str_new(mrb, (char*)res->ai_addr, res->ai_addrlen); + mrb_value args[4] = {sa, mrb_fixnum_value(res->ai_family), mrb_fixnum_value(res->ai_socktype), mrb_fixnum_value(res->ai_protocol)}; + mrb_value ai = mrb_obj_new(mrb, a->klass, 4, args); + mrb_ary_push(mrb, ary, ai); + mrb_gc_arena_restore(mrb, arena_idx); + } + return ary; +} + +static mrb_value +free_addrinfo(mrb_state *mrb, mrb_value addrinfo) +{ + freeaddrinfo((struct addrinfo*)mrb_cptr(addrinfo)); + return mrb_nil_value(); +} + static mrb_value mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass) { - struct addrinfo hints = {0}, *res0, *res; - mrb_value ai, ary, family, lastai, nodename, protocol, sa, service, socktype; + struct addrinfo hints = {0}, *addr; + mrb_value family, protocol, service, socktype; mrb_int flags; - int arena_idx, error; - const char *hostname = NULL, *servname = NULL; - - ary = mrb_ary_new(mrb); - arena_idx = mrb_gc_arena_save(mrb); /* ary must be on arena! */ + const char *hostname, *servname = NULL; family = socktype = protocol = mrb_nil_value(); flags = 0; - mrb_get_args(mrb, "oo|oooi", &nodename, &service, &family, &socktype, &protocol, &flags); - - if (mrb_string_p(nodename)) { - hostname = RSTRING_CSTR(mrb, nodename); - } else if (mrb_nil_p(nodename)) { - hostname = NULL; - } else { - mrb_raise(mrb, E_TYPE_ERROR, "nodename must be String or nil"); - } + mrb_get_args(mrb, "z!o|oooi", &hostname, &service, &family, &socktype, &protocol, &flags); if (mrb_string_p(service)) { servname = RSTRING_CSTR(mrb, service); - } else if (mrb_integer_p(service)) { + } + else if (mrb_integer_p(service)) { servname = RSTRING_PTR(mrb_integer_to_str(mrb, service, 10)); - } else if (mrb_nil_p(service)) { + } + else if (mrb_nil_p(service)) { servname = NULL; - } else { + } + else { mrb_raise(mrb, E_TYPE_ERROR, "service must be String, Integer, or nil"); } @@ -154,29 +170,13 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass) hints.ai_protocol = (int)mrb_integer(protocol); } - lastai = mrb_cv_get(mrb, klass, MRB_SYM(_lastai)); - if (mrb_cptr_p(lastai)) { - freeaddrinfo((struct addrinfo*)mrb_cptr(lastai)); - mrb_cv_set(mrb, klass, MRB_SYM(_lastai), mrb_nil_value()); - } - - error = getaddrinfo(hostname, servname, &hints, &res0); + int error = getaddrinfo(hostname, servname, &hints, &addr); if (error) { mrb_raisef(mrb, E_SOCKET_ERROR, "getaddrinfo: %s", gai_strerror(error)); } - mrb_cv_set(mrb, klass, MRB_SYM(_lastai), mrb_cptr_value(mrb, res0)); - for (res = res0; res != NULL; res = res->ai_next) { - sa = mrb_str_new(mrb, (char*)res->ai_addr, res->ai_addrlen); - ai = mrb_funcall_id(mrb, klass, MRB_SYM(new), 4, sa, mrb_fixnum_value(res->ai_family), mrb_fixnum_value(res->ai_socktype), mrb_fixnum_value(res->ai_protocol)); - mrb_ary_push(mrb, ary, ai); - mrb_gc_arena_restore(mrb, arena_idx); - } - - freeaddrinfo(res0); - mrb_cv_set(mrb, klass, MRB_SYM(_lastai), mrb_nil_value()); - - return ary; + struct gen_addrinfo_args args = {mrb_class_ptr(klass), addr}; + return mrb_ensure(mrb, gen_addrinfo, mrb_cptr_value(mrb, &args), free_addrinfo, mrb_cptr_value(mrb, addr)); } static mrb_value @@ -195,7 +195,7 @@ mrb_addrinfo_getnameinfo(mrb_state *mrb, mrb_value self) if (!mrb_string_p(sastr)) { mrb_raise(mrb, E_SOCKET_ERROR, "invalid sockaddr"); } - error = getnameinfo((struct sockaddr *)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr), RSTRING_PTR(host), NI_MAXHOST, RSTRING_PTR(serv), NI_MAXSERV, (int)flags); + error = getnameinfo((struct sockaddr*)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr), RSTRING_PTR(host), NI_MAXHOST, RSTRING_PTR(serv), NI_MAXSERV, (int)flags); if (error) { mrb_raisef(mrb, E_SOCKET_ERROR, "getnameinfo: %s", gai_strerror(error)); } @@ -214,12 +214,13 @@ mrb_addrinfo_unix_path(mrb_state *mrb, mrb_value self) mrb_value sastr; sastr = mrb_iv_get(mrb, self, MRB_IVSYM(sockaddr)); - if (((struct sockaddr *)RSTRING_PTR(sastr))->sa_family != AF_UNIX) + if (!mrb_string_p(sastr) || ((struct sockaddr*)RSTRING_PTR(sastr))->sa_family != AF_UNIX) mrb_raise(mrb, E_SOCKET_ERROR, "need AF_UNIX address"); if (RSTRING_LEN(sastr) < (mrb_int)offsetof(struct sockaddr_un, sun_path) + 1) { return mrb_str_new(mrb, "", 0); - } else { - return mrb_str_new_cstr(mrb, ((struct sockaddr_un *)RSTRING_PTR(sastr))->sun_path); + } + else { + return mrb_str_new_cstr(mrb, ((struct sockaddr_un*)RSTRING_PTR(sastr))->sun_path); } } #endif @@ -234,11 +235,11 @@ sa2addrlist(mrb_state *mrb, const struct sockaddr *sa, socklen_t salen) switch (sa->sa_family) { case AF_INET: afstr = "AF_INET"; - port = ((struct sockaddr_in *)sa)->sin_port; + port = ((struct sockaddr_in*)sa)->sin_port; break; case AF_INET6: afstr = "AF_INET6"; - port = ((struct sockaddr_in6 *)sa)->sin6_port; + port = ((struct sockaddr_in6*)sa)->sin6_port; break; default: mrb_raise(mrb, E_ARGUMENT_ERROR, "bad af"); @@ -272,7 +273,7 @@ socket_family(int s) socklen_t salen; salen = sizeof(ss); - if (getsockname(s, (struct sockaddr *)&ss, &salen) == -1) + if (getsockname(s, (struct sockaddr*)&ss, &salen) == -1) return AF_UNSPEC; return ss.ss_family; } @@ -307,7 +308,7 @@ mrb_basicsocket_getpeername(mrb_state *mrb, mrb_value self) socklen_t salen; salen = sizeof(ss); - if (getpeername(socket_fd(mrb, self), (struct sockaddr *)&ss, &salen) != 0) + if (getpeername(socket_fd(mrb, self), (struct sockaddr*)&ss, &salen) != 0) mrb_sys_fail(mrb, "getpeername"); return mrb_str_new(mrb, (char*)&ss, salen); @@ -320,19 +321,180 @@ mrb_basicsocket_getsockname(mrb_state *mrb, mrb_value self) socklen_t salen; salen = sizeof(ss); - if (getsockname(socket_fd(mrb, self), (struct sockaddr *)&ss, &salen) != 0) + if (getsockname(socket_fd(mrb, self), (struct sockaddr*)&ss, &salen) != 0) mrb_sys_fail(mrb, "getsockname"); return mrb_str_new(mrb, (char*)&ss, salen); } +static struct RClass * +socket_option_class(mrb_state *mrb) +{ + return mrb_class_get_under_id(mrb, mrb_class_get_id(mrb, MRB_SYM(Socket)), MRB_SYM(Option)); +} + +static mrb_value +socket_option_init(mrb_state *mrb, mrb_value self) +{ + mrb_int family, level, optname; + mrb_value data; + + mrb_get_args(mrb, "iiio", &family, &level, &optname, &data); + mrb_iv_set(mrb, self, MRB_SYM(family), mrb_int_value(mrb, family)); + mrb_iv_set(mrb, self, MRB_SYM(level), mrb_int_value(mrb, level)); + mrb_iv_set(mrb, self, MRB_SYM(optname), mrb_int_value(mrb, optname)); + mrb_iv_set(mrb, self, MRB_SYM(data), data); + + return self; +} + +static mrb_value +socket_option_s_bool(mrb_state *mrb, mrb_value klass) +{ + mrb_value args[4]; + mrb_bool data; + int tmp; + + mrb_get_args(mrb, "ooob", &args[0], &args[1], &args[2], &data); + tmp = (int)data; + args[3] = mrb_str_new(mrb, (char*)&tmp, sizeof(int)); + return mrb_obj_new(mrb, mrb_class_ptr(klass), 4, args); +} + +static mrb_value +socket_option_s_int(mrb_state *mrb, mrb_value klass) +{ + mrb_value args[4]; + mrb_int data; + int tmp; + + mrb_get_args(mrb, "oooi", &args[0], &args[1], &args[2], &data); + tmp = (int)data; + args[3] = mrb_str_new(mrb, (char*)&tmp, sizeof(int)); + return mrb_obj_new(mrb, mrb_class_ptr(klass), 4, args); +} + +static mrb_value +socket_option_family(mrb_state *mrb, mrb_value self) +{ + return mrb_iv_get(mrb, self, MRB_SYM(family)); +} + +static mrb_value +socket_option_level(mrb_state *mrb, mrb_value self) +{ + return mrb_iv_get(mrb, self, MRB_SYM(level)); +} + +static mrb_value +socket_option_optname(mrb_state *mrb, mrb_value self) +{ + return mrb_iv_get(mrb, self, MRB_SYM(optname)); +} + +static mrb_value +socket_option_data(mrb_state *mrb, mrb_value self) +{ + return mrb_iv_get(mrb, self, MRB_SYM(data)); +} + +static int +option_int(mrb_state *mrb, mrb_value self) +{ + mrb_value data = mrb_obj_as_string(mrb, mrb_iv_get(mrb, self, MRB_SYM(data))); + int tmp; + + if (RSTRING_LEN(data) != sizeof(int)) { + mrb_raisef(mrb, E_TYPE_ERROR, "size differ; expected as sizeof(int)=%i but %i", (mrb_int)sizeof(int), RSTRING_LEN(data)); + } + memcpy((char*)&tmp, RSTRING_PTR(data), sizeof(int)); + return tmp; +} + +static mrb_value +socket_option_int(mrb_state *mrb, mrb_value self) +{ + int i = option_int(mrb, self); + return mrb_int_value(mrb, (mrb_int)i); +} + +static mrb_value +socket_option_bool(mrb_state *mrb, mrb_value self) +{ + int i = option_int(mrb, self); + return mrb_bool_value((mrb_bool)i); +} + +static mrb_value +socket_option_notimp(mrb_state *mrb, mrb_value self) +{ + mrb_notimplement(mrb); + return mrb_nil_value(); +} + +static mrb_value +socket_option_inspect(mrb_state *mrb, mrb_value self) +{ + mrb_value str = mrb_str_new_cstr(mrb, "#"); + + return str; +} + static mrb_value mrb_basicsocket_getsockopt(mrb_state *mrb, mrb_value self) { char opt[8]; int s; mrb_int family, level, optname; - mrb_value c, data; + mrb_value data; socklen_t optlen; mrb_get_args(mrb, "ii", &level, &optname); @@ -340,10 +502,10 @@ mrb_basicsocket_getsockopt(mrb_state *mrb, mrb_value self) optlen = sizeof(opt); if (getsockopt(s, (int)level, (int)optname, opt, &optlen) == -1) mrb_sys_fail(mrb, "getsockopt"); - c = mrb_const_get(mrb, mrb_obj_value(mrb_class_get_id(mrb, MRB_SYM(Socket))), MRB_SYM(Option)); family = socket_family(s); data = mrb_str_new(mrb, opt, optlen); - return mrb_funcall_id(mrb, c, MRB_SYM(new), 4, mrb_fixnum_value(family), mrb_fixnum_value(level), mrb_fixnum_value(optname), data); + mrb_value args[4] = {mrb_fixnum_value(family), mrb_fixnum_value(level), mrb_fixnum_value(optname), data}; + return mrb_obj_new(mrb, socket_option_class(mrb), 4, args); } static mrb_value @@ -374,7 +536,7 @@ mrb_basicsocket_recvfrom(mrb_state *mrb, mrb_value self) buf = mrb_str_new_capa(mrb, maxlen); socklen = sizeof(struct sockaddr_storage); sa = mrb_str_new_capa(mrb, socklen); - n = recvfrom(socket_fd(mrb, self), RSTRING_PTR(buf), (fsize_t)maxlen, (int)flags, (struct sockaddr *)RSTRING_PTR(sa), &socklen); + n = recvfrom(socket_fd(mrb, self), RSTRING_PTR(buf), (fsize_t)maxlen, (int)flags, (struct sockaddr*)RSTRING_PTR(sa), &socklen); if (n == -1) mrb_sys_fail(mrb, "recvfrom"); mrb_str_resize(mrb, buf, (mrb_int)n); @@ -396,7 +558,8 @@ mrb_basicsocket_send(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "Si|S", &mesg, &flags, &dest); if (mrb_nil_p(dest)) { n = send(socket_fd(mrb, self), RSTRING_PTR(mesg), (fsize_t)RSTRING_LEN(mesg), (int)flags); - } else { + } + else { n = sendto(socket_fd(mrb, self), RSTRING_PTR(mesg), (fsize_t)RSTRING_LEN(mesg), (int)flags, (const struct sockaddr*)RSTRING_PTR(dest), (fsize_t)RSTRING_LEN(dest)); } if (n == -1) @@ -442,34 +605,38 @@ mrb_basicsocket_setsockopt(mrb_state *mrb, mrb_value self) argc = mrb_get_args(mrb, "o|io", &so, &optname, &optval); if (argc == 3) { - if (!mrb_integer_p(so)) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "level is not an integer"); - } + mrb_ensure_int_type(mrb, so); level = mrb_integer(so); if (mrb_string_p(optval)) { /* that's good */ - } else if (mrb_true_p(optval) || mrb_false_p(optval)) { + } + else if (mrb_true_p(optval) || mrb_false_p(optval)) { mrb_int i = mrb_test(optval) ? 1 : 0; optval = mrb_str_new(mrb, (char*)&i, sizeof(i)); - } else if (mrb_integer_p(optval)) { + } + else if (mrb_integer_p(optval)) { if (optname == IP_MULTICAST_TTL || optname == IP_MULTICAST_LOOP) { char uc = (char)mrb_integer(optval); optval = mrb_str_new(mrb, &uc, sizeof(uc)); - } else { + } + else { mrb_int i = mrb_integer(optval); optval = mrb_str_new(mrb, (char*)&i, sizeof(i)); } - } else { + } + else { mrb_raise(mrb, E_ARGUMENT_ERROR, "optval should be true, false, an integer, or a string"); } - } else if (argc == 1) { - if (strcmp(mrb_obj_classname(mrb, so), "Socket::Option") != 0) + } + else if (argc == 1) { + if (!mrb_obj_is_instance_of(mrb, so, socket_option_class(mrb))) mrb_raise(mrb, E_ARGUMENT_ERROR, "not an instance of Socket::Option"); - level = mrb_as_int(mrb, mrb_funcall_id(mrb, so, MRB_SYM(level), 0)); - optname = mrb_as_int(mrb, mrb_funcall_id(mrb, so, MRB_SYM(optname), 0)); - optval = mrb_funcall_id(mrb, so, MRB_SYM(data), 0); + level = mrb_as_int(mrb, mrb_iv_get(mrb, so, MRB_SYM(level))); + optname = mrb_as_int(mrb, mrb_iv_get(mrb, so, MRB_SYM(optname))); + optval = mrb_iv_get(mrb, so, MRB_SYM(data)); mrb_ensure_string_type(mrb, optval); - } else { + } + else { mrb_argnum_error(mrb, argc, 3, 3); } @@ -533,16 +700,19 @@ mrb_ipsocket_pton(mrb_state *mrb, mrb_value klass) if (af == AF_INET) { struct in_addr in; - if (inet_pton(AF_INET, buf, (void *)&in.s_addr) != 1) + if (inet_pton(AF_INET, buf, (void*)&in.s_addr) != 1) goto invalid; return mrb_str_new(mrb, (char*)&in.s_addr, 4); - } else if (af == AF_INET6) { + } + else if (af == AF_INET6) { struct in6_addr in6; - if (inet_pton(AF_INET6, buf, (void *)&in6.s6_addr) != 1) + if (inet_pton(AF_INET6, buf, (void*)&in6.s6_addr) != 1) goto invalid; return mrb_str_new(mrb, (char*)&in6.s6_addr, 16); - } else + } + else { mrb_raise(mrb, E_ARGUMENT_ERROR, "unsupported address family"); + } invalid: mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid address"); @@ -565,12 +735,12 @@ mrb_ipsocket_recvfrom(mrb_state *mrb, mrb_value self) buf = mrb_str_new_capa(mrb, maxlen); socklen = sizeof(ss); n = recvfrom(fd, RSTRING_PTR(buf), (fsize_t)maxlen, (int)flags, - (struct sockaddr *)&ss, &socklen); + (struct sockaddr*)&ss, &socklen); if (n == -1) { mrb_sys_fail(mrb, "recvfrom"); } mrb_str_resize(mrb, buf, (mrb_int)n); - a = sa2addrlist(mrb, (struct sockaddr *)&ss, socklen); + a = sa2addrlist(mrb, (struct sockaddr*)&ss, socklen); pair = mrb_ary_new_capa(mrb, 2); mrb_ary_push(mrb, pair, buf); mrb_ary_push(mrb, pair, a); @@ -620,7 +790,7 @@ mrb_socket_accept2(mrb_state *mrb, mrb_value klass) mrb_get_args(mrb, "i", &s0); socklen = sizeof(struct sockaddr_storage); sastr = mrb_str_new_capa(mrb, (mrb_int)socklen); - s1 = (int)accept(s0, (struct sockaddr *)RSTRING_PTR(sastr), &socklen); + s1 = (int)accept(s0, (struct sockaddr*)RSTRING_PTR(sastr), &socklen); if (s1 == -1) { mrb_sys_fail(mrb, "accept"); } @@ -639,7 +809,7 @@ mrb_socket_bind(mrb_state *mrb, mrb_value klass) mrb_int s; mrb_get_args(mrb, "iS", &s, &sastr); - if (bind((int)s, (struct sockaddr *)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr)) == -1) { + if (bind((int)s, (struct sockaddr*)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr)) == -1) { mrb_sys_fail(mrb, "bind"); } return mrb_nil_value(); @@ -652,7 +822,7 @@ mrb_socket_connect(mrb_state *mrb, mrb_value klass) mrb_int s; mrb_get_args(mrb, "iS", &s, &sastr); - if (connect((int)s, (struct sockaddr *)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr)) == -1) { + if (connect((int)s, (struct sockaddr*)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr)) == -1) { mrb_sys_fail(mrb, "connect"); } return mrb_nil_value(); @@ -680,7 +850,7 @@ mrb_socket_sockaddr_family(mrb_state *mrb, mrb_value klass) if ((size_t)RSTRING_LEN(str) < offsetof(struct sockaddr, sa_family) + sizeof(sa->sa_family)) { mrb_raise(mrb, E_SOCKET_ERROR, "invalid sockaddr (too short)"); } - sa = (const struct sockaddr *)RSTRING_PTR(str); + sa = (const struct sockaddr*)RSTRING_PTR(str); return mrb_fixnum_value(sa->sa_family); } @@ -699,7 +869,7 @@ mrb_socket_sockaddr_un(mrb_state *mrb, mrb_value klass) mrb_raisef(mrb, E_ARGUMENT_ERROR, "too long unix socket path (max: %d bytes)", (int)sizeof(sunp->sun_path) - 1); } s = mrb_str_new_capa(mrb, sizeof(struct sockaddr_un)); - sunp = (struct sockaddr_un *)RSTRING_PTR(s); + sunp = (struct sockaddr_un*)RSTRING_PTR(s); #if HAVE_SA_LEN sunp->sun_len = sizeof(struct sockaddr_un); #endif @@ -798,7 +968,8 @@ mrb_win32_basicsocket_sysread(mrb_state *mrb, mrb_value self) case 0: /* EOF */ if (maxlen == 0) { buf = mrb_str_new_cstr(mrb, ""); - } else { + } + else { mrb_raise(mrb, E_EOF_ERROR, "sysread failed: End of File"); } break; @@ -843,7 +1014,7 @@ void mrb_mruby_socket_gem_init(mrb_state* mrb) { struct RClass *io, *ai, *sock, *bsock, *ipsock, *tcpsock; - struct RClass *constants; + struct RClass *constants, *option; #ifdef _WIN32 WSADATA wsaData; @@ -854,7 +1025,6 @@ mrb_mruby_socket_gem_init(mrb_state* mrb) #endif ai = mrb_define_class(mrb, "Addrinfo", mrb->object_class); - mrb_mod_cv_set(mrb, ai, MRB_SYM(_lastai), mrb_nil_value()); mrb_define_class_method(mrb, ai, "getaddrinfo", mrb_addrinfo_getaddrinfo, MRB_ARGS_REQ(2)|MRB_ARGS_OPT(4)); mrb_define_method(mrb, ai, "getnameinfo", mrb_addrinfo_getnameinfo, MRB_ARGS_OPT(1)); #ifndef _WIN32 @@ -924,8 +1094,25 @@ mrb_mruby_socket_gem_init(mrb_state* mrb) mrb_define_method(mrb, bsock, "sysread", mrb_win32_basicsocket_sysread, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1)); mrb_define_method(mrb, bsock, "sysseek", mrb_win32_basicsocket_sysseek, MRB_ARGS_REQ(1)); mrb_define_method(mrb, bsock, "syswrite", mrb_win32_basicsocket_syswrite, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, bsock, "read", mrb_win32_basicsocket_sysread, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1)); + mrb_define_method(mrb, bsock, "write", mrb_win32_basicsocket_syswrite, MRB_ARGS_REQ(1)); #endif + option = mrb_define_class_under(mrb, sock, "Option", mrb->object_class); + mrb_define_class_method(mrb, option, "bool", socket_option_s_bool, MRB_ARGS_REQ(4)); + mrb_define_class_method(mrb, option, "int", socket_option_s_int, MRB_ARGS_REQ(4)); + mrb_define_method(mrb, option, "initialize", socket_option_init, MRB_ARGS_REQ(4)); + mrb_define_method(mrb, option, "inspect", socket_option_inspect, MRB_ARGS_REQ(0)); + mrb_define_method(mrb, option, "family", socket_option_family, MRB_ARGS_REQ(0)); + mrb_define_method(mrb, option, "level", socket_option_level, MRB_ARGS_REQ(0)); + mrb_define_method(mrb, option, "optname", socket_option_optname, MRB_ARGS_REQ(0)); + mrb_define_method(mrb, option, "data", socket_option_data, MRB_ARGS_REQ(0)); + mrb_define_method(mrb, option, "bool", socket_option_bool, MRB_ARGS_REQ(0)); + mrb_define_method(mrb, option, "int", socket_option_int, MRB_ARGS_REQ(0)); + + mrb_define_method(mrb, option, "linger", socket_option_notimp, MRB_ARGS_REQ(0)); + mrb_define_method(mrb, option, "unpack", socket_option_notimp, MRB_ARGS_REQ(1)); + constants = mrb_define_module_under(mrb, sock, "Constants"); #define define_const(SYM) \ @@ -934,16 +1121,13 @@ mrb_mruby_socket_gem_init(mrb_state* mrb) } while (0) #include "const.cstub" + + mrb_include_module(mrb, sock, constants); } void mrb_mruby_socket_gem_final(mrb_state* mrb) { - mrb_value ai; - ai = mrb_mod_cv_get(mrb, mrb_class_get_id(mrb, MRB_SYM(Addrinfo)), MRB_SYM(_lastai)); - if (mrb_cptr_p(ai)) { - freeaddrinfo((struct addrinfo*)mrb_cptr(ai)); - } #ifdef _WIN32 WSACleanup(); #endif diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-sprintf/src/sprintf.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-sprintf/src/sprintf.c index 71a3e90d45..9f7fb59d15 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-sprintf/src/sprintf.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-sprintf/src/sprintf.c @@ -146,7 +146,8 @@ fmt_float(char *buf, size_t buf_size, char fmt, int flags, int width, int prec, memmove(&buf[width - len], buf, len); if (zero_pad) { memset(buf, '0', width - len); - } else { + } + else { memset(buf, ' ', width - len); } return width; @@ -604,7 +605,8 @@ mrb_str_format(mrb_state *mrb, mrb_int argc, const mrb_value *argv, mrb_value fm mrb_sym id = 0; int flags = FNONE; - for (t = p; t < end && *t != '%'; t++) ; + for (t = p; t < end && *t != '%'; t++) + ; if (t + 1 == end) t++; PUSH(p, t - p); if (t >= end) @@ -761,7 +763,7 @@ retry: tmp = mrb_str_new(mrb, buf, 1); } else { - tmp = mrb_funcall_id(mrb, val, MRB_SYM(chr), 0); + tmp = mrb_funcall_argv(mrb, val, MRB_SYM(chr), 0, NULL); mrb_check_type(mrb, tmp, MRB_TT_STRING); } #endif @@ -994,7 +996,8 @@ retry: if ((flags & (FMINUS|FPREC)) != FMINUS) { char c = '0'; FILL(c, prec - len); - } else if (v < 0) { + } + else if (v < 0) { char c = sign_bits(base, p); FILL(c, prec - len); } diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/mrblib/string.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/mrblib/string.rb index 87f8ab9a01..9f940ca322 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/mrblib/string.rb @@ -314,13 +314,14 @@ class String end def codepoints(&block) + cp = __codepoints() if block_given? - self.split('').each do|x| - block.call(x.ord) + cp.each do|x| + block.call(x) end self else - self.split('').map{|x| x.ord} + cp end end alias each_codepoint codepoints diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/src/string.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/src/string.c index 881409adab..79b4743ac0 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/src/string.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/src/string.c @@ -11,10 +11,10 @@ #define ENC_UTF8 "UTF-8" #define ENC_COMP_P(enc, enc_lit) \ - str_casecmp_p(RSTRING_PTR(enc), RSTRING_LEN(enc), enc_lit, sizeof(enc_lit"")-1) + casecmp_p(RSTRING_PTR(enc), RSTRING_LEN(enc), enc_lit, sizeof(enc_lit"")-1) static mrb_bool -str_casecmp_p(const char *s1, mrb_int len1, const char *s2, mrb_int len2) +casecmp_p(const char *s1, mrb_int len1, const char *s2, mrb_int len2) { const char *e1, *e2; @@ -96,7 +96,7 @@ int_chr_utf8(mrb_state *mrb, mrb_value num) * Note: case conversion is effective only in ASCII region. */ static mrb_value -mrb_str_swapcase_bang(mrb_state *mrb, mrb_value str) +str_swapcase_bang(mrb_state *mrb, mrb_value str) { char *p, *pend; int modify = 0; @@ -133,12 +133,12 @@ mrb_str_swapcase_bang(mrb_state *mrb, mrb_value str) * "cYbEr_PuNk11".swapcase #=> "CyBeR_pUnK11" */ static mrb_value -mrb_str_swapcase(mrb_state *mrb, mrb_value self) +str_swapcase(mrb_state *mrb, mrb_value self) { mrb_value str; str = mrb_str_dup(mrb, self); - mrb_str_swapcase_bang(mrb, str); + str_swapcase_bang(mrb, str); return str; } @@ -173,7 +173,7 @@ str_concat(mrb_state *mrb, mrb_value self, mrb_value str) * */ static mrb_value -mrb_str_concat_m(mrb_state *mrb, mrb_value self) +str_concat_m(mrb_state *mrb, mrb_value self) { if (mrb_get_argc(mrb) == 1) { str_concat(mrb, self, mrb_get_arg1(mrb)); @@ -204,7 +204,7 @@ mrb_str_concat_m(mrb_state *mrb, mrb_value self) * "h".start_with?("heaven", "hell") #=> false */ static mrb_value -mrb_str_start_with(mrb_state *mrb, mrb_value self) +str_start_with(mrb_state *mrb, mrb_value self) { const mrb_value *argv; mrb_int argc, i; @@ -234,7 +234,7 @@ mrb_str_start_with(mrb_state *mrb, mrb_value self) * Returns true if +str+ ends with one of the +suffixes+ given. */ static mrb_value -mrb_str_end_with(mrb_state *mrb, mrb_value self) +str_end_with(mrb_state *mrb, mrb_value self) { const mrb_value *argv; mrb_int argc, i; @@ -308,7 +308,7 @@ tr_parse_pattern(mrb_state *mrb, struct tr_pattern *ret, const mrb_value v_patte struct tr_pattern *pat1; mrb_int i = 0; - if(flag_reverse_enable && pattern_length >= 2 && pattern[0] == '^') { + if (flag_reverse_enable && pattern_length >= 2 && pattern[0] == '^') { flag_reverse = TRUE; i++; } @@ -580,7 +580,7 @@ str_tr(mrb_state *mrb, mrb_value str, mrb_value p1, mrb_value p2, mrb_bool squee * Note: conversion is effective only in ASCII region. */ static mrb_value -mrb_str_tr(mrb_state *mrb, mrb_value str) +str_tr_m(mrb_state *mrb, mrb_value str) { mrb_value dup; mrb_value p1, p2; @@ -599,7 +599,7 @@ mrb_str_tr(mrb_state *mrb, mrb_value str) * Returns str, or nil if no changes were made. */ static mrb_value -mrb_str_tr_bang(mrb_state *mrb, mrb_value str) +str_tr_bang(mrb_state *mrb, mrb_value str) { mrb_value p1, p2; @@ -622,7 +622,7 @@ mrb_str_tr_bang(mrb_state *mrb, mrb_value str) * "hello".tr_s('el', 'hx') #=> "hhxo" */ static mrb_value -mrb_str_tr_s(mrb_state *mrb, mrb_value str) +str_tr_s(mrb_state *mrb, mrb_value str) { mrb_value dup; mrb_value p1, p2; @@ -641,7 +641,7 @@ mrb_str_tr_s(mrb_state *mrb, mrb_value str) * str, or nil if no changes were made. */ static mrb_value -mrb_str_tr_s_bang(mrb_state *mrb, mrb_value str) +str_tr_s_bang(mrb_state *mrb, mrb_value str) { mrb_value p1, p2; @@ -716,7 +716,7 @@ str_squeeze(mrb_state *mrb, mrb_value str, mrb_value v_pat) * "putters shoot balls".squeeze("m-z") #=> "puters shot balls" */ static mrb_value -mrb_str_squeeze(mrb_state *mrb, mrb_value str) +str_squeeze_m(mrb_state *mrb, mrb_value str) { mrb_value pat = mrb_nil_value(); mrb_value dup; @@ -735,7 +735,7 @@ mrb_str_squeeze(mrb_state *mrb, mrb_value str) * changes were made. */ static mrb_value -mrb_str_squeeze_bang(mrb_state *mrb, mrb_value str) +str_squeeze_bang(mrb_state *mrb, mrb_value str) { mrb_value pat = mrb_nil_value(); @@ -779,7 +779,7 @@ str_delete(mrb_state *mrb, mrb_value str, mrb_value v_pat) } static mrb_value -mrb_str_delete(mrb_state *mrb, mrb_value str) +str_delete_m(mrb_state *mrb, mrb_value str) { mrb_value pat; mrb_value dup; @@ -791,7 +791,7 @@ mrb_str_delete(mrb_state *mrb, mrb_value str) } static mrb_value -mrb_str_delete_bang(mrb_state *mrb, mrb_value str) +str_delete_bang(mrb_state *mrb, mrb_value str) { mrb_value pat; @@ -814,7 +814,7 @@ mrb_str_delete_bang(mrb_state *mrb, mrb_value str) * the end of a sequence or the end of a other_str. */ static mrb_value -mrb_str_count(mrb_state *mrb, mrb_value str) +str_count(mrb_state *mrb, mrb_value str) { mrb_value v_pat = mrb_nil_value(); mrb_int i; @@ -838,13 +838,13 @@ mrb_str_count(mrb_state *mrb, mrb_value str) } static mrb_value -mrb_str_hex(mrb_state *mrb, mrb_value self) +str_hex(mrb_state *mrb, mrb_value self) { return mrb_str_to_integer(mrb, self, 16, FALSE); } static mrb_value -mrb_str_oct(mrb_state *mrb, mrb_value self) +str_oct(mrb_state *mrb, mrb_value self) { return mrb_str_to_integer(mrb, self, 8, FALSE); } @@ -859,7 +859,7 @@ mrb_str_oct(mrb_state *mrb, mrb_value self) * a.chr #=> "a" */ static mrb_value -mrb_str_chr(mrb_state *mrb, mrb_value self) +str_chr(mrb_state *mrb, mrb_value self) { return mrb_str_substr(mrb, self, 0, 1); } @@ -879,7 +879,7 @@ mrb_str_chr(mrb_state *mrb, mrb_value self) * 230.chr("UTF-8") #=> "\u00E6" */ static mrb_value -mrb_int_chr(mrb_state *mrb, mrb_value num) +int_chr(mrb_state *mrb, mrb_value num) { mrb_value enc; mrb_bool enc_given; @@ -912,7 +912,7 @@ mrb_int_chr(mrb_state *mrb, mrb_value num) * a.succ #=> "abd" */ static mrb_value -mrb_str_succ_bang(mrb_state *mrb, mrb_value self) +str_succ_bang(mrb_state *mrb, mrb_value self) { mrb_value result; unsigned char *p, *e, *b, *t; @@ -990,20 +990,20 @@ mrb_str_succ_bang(mrb_state *mrb, mrb_value self) } static mrb_value -mrb_str_succ(mrb_state *mrb, mrb_value self) +str_succ(mrb_state *mrb, mrb_value self) { mrb_value str; str = mrb_str_dup(mrb, self); - mrb_str_succ_bang(mrb, str); + str_succ_bang(mrb, str); return str; } #ifdef MRB_UTF8_STRING extern const char mrb_utf8len_table[]; -static mrb_int -utf8code(unsigned char* p, mrb_int limit) +MRB_INLINE mrb_int +utf8code(mrb_state* mrb, const unsigned char* p, const unsigned char *e) { mrb_int len; @@ -1011,7 +1011,7 @@ utf8code(unsigned char* p, mrb_int limit) return p[0]; len = mrb_utf8len_table[p[0]>>3]; - if (len <= limit && len > 1 && (p[1] & 0xc0) == 0x80) { + if (p+len <= e && len > 1 && (p[1] & 0xc0) == 0x80) { if (len == 2) return ((p[0] & 0x1f) << 6) + (p[1] & 0x3f); if ((p[2] & 0xc0) == 0x80) { @@ -1025,26 +1025,63 @@ utf8code(unsigned char* p, mrb_int limit) } } } + mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid UTF-8 byte sequence"); + /* not reached */ return -1; } static mrb_value -mrb_str_ord(mrb_state* mrb, mrb_value str) +str_ord(mrb_state* mrb, mrb_value str) { if (RSTRING_LEN(str) == 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "empty string"); - mrb_int c = utf8code((unsigned char*)RSTRING_PTR(str), RSTRING_LEN(str)); - if (c < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid UTF-8 byte sequence"); + const unsigned char *p = (unsigned char*)RSTRING_PTR(str); + const unsigned char *e = p + RSTRING_LEN(str); + + mrb_int c = utf8code(mrb, p, e); return mrb_fixnum_value(c); } + +static mrb_value +str_codepoints(mrb_state *mrb, mrb_value str) +{ + mrb_value result; + const unsigned char *p = (unsigned char*)RSTRING_PTR(str); + const unsigned char *e = p + RSTRING_LEN(str); + + mrb->c->ci->mid = 0; + result = mrb_ary_new(mrb); + while (p < e) { + mrb_int c = utf8code(mrb, p, e); + mrb_ary_push(mrb, result, mrb_int_value(mrb, c)); + p += mrb_utf8len_table[p[0]>>3]; + } + return result; +} #else static mrb_value -mrb_str_ord(mrb_state* mrb, mrb_value str) +str_ord(mrb_state* mrb, mrb_value str) { if (RSTRING_LEN(str) == 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "empty string"); return mrb_fixnum_value((unsigned char)RSTRING_PTR(str)[0]); } + +static mrb_value +str_codepoints(mrb_state *mrb, mrb_value self) +{ + mrb_value result; + char *p = RSTRING_PTR(self); + char *e = p + RSTRING_LEN(self); + + mrb->c->ci->mid = 0; + result = mrb_ary_new(mrb); + while (p < e) { + mrb_ary_push(mrb, result, mrb_int_value(mrb, (mrb_int)*p)); + p++; + } + return result; +} #endif /* @@ -1058,7 +1095,7 @@ mrb_str_ord(mrb_state* mrb, mrb_value str) * "hello".delete_prefix!("llo") #=> nil */ static mrb_value -mrb_str_del_prefix_bang(mrb_state *mrb, mrb_value self) +str_del_prefix_bang(mrb_state *mrb, mrb_value self) { mrb_int plen, slen; const char *ptr; @@ -1092,7 +1129,7 @@ mrb_str_del_prefix_bang(mrb_state *mrb, mrb_value self) * "hello".delete_prefix("llo") #=> "hello" */ static mrb_value -mrb_str_del_prefix(mrb_state *mrb, mrb_value self) +str_del_prefix(mrb_state *mrb, mrb_value self) { mrb_int plen, slen; const char *ptr; @@ -1116,7 +1153,7 @@ mrb_str_del_prefix(mrb_state *mrb, mrb_value self) * "hello".delete_suffix!("hel") #=> nil */ static mrb_value -mrb_str_del_suffix_bang(mrb_state *mrb, mrb_value self) +str_del_suffix_bang(mrb_state *mrb, mrb_value self) { mrb_int plen, slen; const char *ptr; @@ -1148,7 +1185,7 @@ mrb_str_del_suffix_bang(mrb_state *mrb, mrb_value self) * "hello".delete_suffix("llo") #=> "hello" */ static mrb_value -mrb_str_del_suffix(mrb_state *mrb, mrb_value self) +str_del_suffix(mrb_state *mrb, mrb_value self) { mrb_int plen, slen; const char *ptr; @@ -1175,18 +1212,21 @@ mrb_str_del_suffix(mrb_state *mrb, mrb_value self) * "abcdef".casecmp("ABCDEF") #=> 0 */ static mrb_value -mrb_str_casecmp(mrb_state *mrb, mrb_value self) +str_casecmp(mrb_state *mrb, mrb_value self) { - mrb_value str; + mrb_value str = mrb_get_arg1(mrb); - mrb_get_args(mrb, "o", &str); if (!mrb_string_p(str)) return mrb_nil_value(); struct RString *s1 = mrb_str_ptr(self); struct RString *s2 = mrb_str_ptr(str); - mrb_int len = lesser(RSTR_LEN(s1), RSTR_LEN(s2)); + + mrb_int len1 = RSTR_LEN(s1); + mrb_int len2 = RSTR_LEN(s2); + mrb_int len = lesser(len1, len2); char *p1 = RSTR_PTR(s1); char *p2 = RSTR_PTR(s2); + if (p1 == p2) return mrb_fixnum_value(0); for (mrb_int i=0; i c2) return mrb_fixnum_value(1); if (c1 < c2) return mrb_fixnum_value(-1); } - if (RSTR_LEN(s1) == RSTR_LEN(s2)) return mrb_fixnum_value(0); - if (RSTR_LEN(s1) > RSTR_LEN(s2)) return mrb_fixnum_value(1); + if (len1 == len2) return mrb_fixnum_value(0); + if (len1 > len2) return mrb_fixnum_value(1); return mrb_fixnum_value(-1); } @@ -1208,15 +1248,15 @@ mrb_str_casecmp(mrb_state *mrb, mrb_value self) * false if they are not equal, and nil if other is not a string. */ static mrb_value -mrb_str_casecmp_p(mrb_state *mrb, mrb_value self) +str_casecmp_p(mrb_state *mrb, mrb_value self) { - mrb_value c = mrb_str_casecmp(mrb, self); + mrb_value c = str_casecmp(mrb, self); if (mrb_nil_p(c)) return c; return mrb_bool_value(mrb_fixnum(c) == 0); } static mrb_value -mrb_str_lines(mrb_state *mrb, mrb_value self) +str_lines(mrb_state *mrb, mrb_value self) { mrb_value result; int ai; @@ -1248,7 +1288,7 @@ mrb_str_lines(mrb_state *mrb, mrb_value self) * Otherwise returns self.dup, which is not frozen. */ static mrb_value -mrb_str_uplus(mrb_state *mrb, mrb_value str) +str_uplus(mrb_state *mrb, mrb_value str) { if (mrb_frozen_p(mrb_obj_ptr(str))) { return mrb_str_dup(mrb, str); @@ -1270,7 +1310,7 @@ mrb_str_uplus(mrb_state *mrb, mrb_value str) * String#dedup is an alias for String#-@. */ static mrb_value -mrb_str_uminus(mrb_state *mrb, mrb_value str) +str_uminus(mrb_state *mrb, mrb_value str) { if (mrb_frozen_p(mrb_obj_ptr(str))) { return str; @@ -1278,47 +1318,91 @@ mrb_str_uminus(mrb_state *mrb, mrb_value str) return mrb_obj_freeze(mrb, mrb_str_dup(mrb, str)); } +/* + * call-seq: + * string.valid_encoding? -> true or false + * + * Returns true for a string which is encoded correctly. + * + */ +static mrb_value +str_valid_enc_p(mrb_state *mrb, mrb_value str) +{ +#ifdef MRB_UTF8_STRING +#define utf8_islead(c) ((unsigned char)((c)&0xc0) != 0x80) + + struct RString *s = mrb_str_ptr(str); + if (RSTR_ASCII_P(s)) return mrb_true_value(); + + mrb_int byte_len = RSTR_LEN(s); + mrb_int utf8_len = 0; + const char *p = RSTR_PTR(s); + const char *e = p + byte_len; + while (p < e) { + mrb_int len = mrb_utf8len_table[(unsigned char)p[0] >> 3]; + if (len == 0 || len > e - p) + return mrb_false_value(); + switch (len) { + case 4: + if (utf8_islead(p[3])) return mrb_false_value(); + case 3: + if (utf8_islead(p[2])) return mrb_false_value(); + case 2: + if (utf8_islead(p[1])) return mrb_false_value(); + default: + break; + } + p += len; + utf8_len++; + } + if (byte_len == utf8_len) RSTR_SET_ASCII_FLAG(s); +#endif + return mrb_true_value(); +} + void mrb_mruby_string_ext_gem_init(mrb_state* mrb) { struct RClass * s = mrb->string_class; - mrb_define_method(mrb, s, "dump", mrb_str_dump, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "swapcase!", mrb_str_swapcase_bang, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "swapcase", mrb_str_swapcase, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "concat", mrb_str_concat_m, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "<<", mrb_str_concat_m, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "count", mrb_str_count, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "tr", mrb_str_tr, MRB_ARGS_REQ(2)); - mrb_define_method(mrb, s, "tr!", mrb_str_tr_bang, MRB_ARGS_REQ(2)); - mrb_define_method(mrb, s, "tr_s", mrb_str_tr_s, MRB_ARGS_REQ(2)); - mrb_define_method(mrb, s, "tr_s!", mrb_str_tr_s_bang, MRB_ARGS_REQ(2)); - mrb_define_method(mrb, s, "squeeze", mrb_str_squeeze, MRB_ARGS_OPT(1)); - mrb_define_method(mrb, s, "squeeze!", mrb_str_squeeze_bang, MRB_ARGS_OPT(1)); - mrb_define_method(mrb, s, "delete", mrb_str_delete, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "delete!", mrb_str_delete_bang, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "start_with?", mrb_str_start_with, MRB_ARGS_REST()); - mrb_define_method(mrb, s, "end_with?", mrb_str_end_with, MRB_ARGS_REST()); - mrb_define_method(mrb, s, "hex", mrb_str_hex, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "oct", mrb_str_oct, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "chr", mrb_str_chr, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "succ", mrb_str_succ, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "succ!", mrb_str_succ_bang, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "next", mrb_str_succ, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "next!", mrb_str_succ_bang, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "ord", mrb_str_ord, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "delete_prefix!", mrb_str_del_prefix_bang, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "delete_prefix", mrb_str_del_prefix, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "delete_suffix!", mrb_str_del_suffix_bang, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "delete_suffix", mrb_str_del_suffix, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "casecmp", mrb_str_casecmp, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "casecmp?", mrb_str_casecmp_p, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "+@", mrb_str_uplus, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "-@", mrb_str_uminus, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "dump", mrb_str_dump, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "swapcase!", str_swapcase_bang, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "swapcase", str_swapcase, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "concat", str_concat_m, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "<<", str_concat_m, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "count", str_count, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "tr", str_tr_m, MRB_ARGS_REQ(2)); + mrb_define_method(mrb, s, "tr!", str_tr_bang, MRB_ARGS_REQ(2)); + mrb_define_method(mrb, s, "tr_s", str_tr_s, MRB_ARGS_REQ(2)); + mrb_define_method(mrb, s, "tr_s!", str_tr_s_bang, MRB_ARGS_REQ(2)); + mrb_define_method(mrb, s, "squeeze", str_squeeze_m, MRB_ARGS_OPT(1)); + mrb_define_method(mrb, s, "squeeze!", str_squeeze_bang, MRB_ARGS_OPT(1)); + mrb_define_method(mrb, s, "delete", str_delete_m, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "delete!", str_delete_bang, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "start_with?", str_start_with, MRB_ARGS_REST()); + mrb_define_method(mrb, s, "end_with?", str_end_with, MRB_ARGS_REST()); + mrb_define_method(mrb, s, "hex", str_hex, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "oct", str_oct, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "chr", str_chr, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "succ", str_succ, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "succ!", str_succ_bang, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "next", str_succ, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "next!", str_succ_bang, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "ord", str_ord, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "delete_prefix!", str_del_prefix_bang, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "delete_prefix", str_del_prefix, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "delete_suffix!", str_del_suffix_bang, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "delete_suffix", str_del_suffix, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "casecmp", str_casecmp, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "casecmp?", str_casecmp_p, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "+@", str_uplus, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "-@", str_uminus, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, s, "valid_encoding?", str_valid_enc_p, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "__lines", mrb_str_lines, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "__lines", str_lines, MRB_ARGS_NONE()); + mrb_define_method(mrb, s, "__codepoints", str_codepoints, MRB_ARGS_NONE()); - mrb_define_method(mrb, mrb->integer_class, "chr", mrb_int_chr, MRB_ARGS_OPT(1)); + mrb_define_method(mrb, mrb->integer_class, "chr", int_chr, MRB_ARGS_OPT(1)); } void diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/test/string.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/test/string.rb index 0400a8da58..f36eeea683 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/test/string.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-string-ext/test/string.rb @@ -726,3 +726,14 @@ assert('String#-@') do a = -(a.freeze) assert_true(a.frozen?) end + +assert('String#valid_encoding?') do + assert_true "hello".valid_encoding? + if UTF8STRING + assert_true "あ".valid_encoding? + assert_false "\xfe".valid_encoding? + assert_false "あ\xfe".valid_encoding? + else + assert_true "\xfe".valid_encoding? + end +end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/mrblib/struct.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/mrblib/struct.rb index f80c545183..20d9bde86e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/mrblib/struct.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/mrblib/struct.rb @@ -45,35 +45,6 @@ class Struct ary end - def _inspect(recur_list) - return "#" if recur_list[self.object_id] - recur_list[self.object_id] = true - name = self.class.to_s - if name[0] == "#" - str = "#" - end - - ## - # call-seq: - # struct.to_s -> string - # struct.inspect -> string - # - # Describe the contents of this struct in a string. - # - # 15.2.18.4.10(x) - # - def inspect - self._inspect({}) - end - ## # 15.2.18.4.11(x) # diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/src/struct.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/src/struct.c index 6dc0b5b005..a615607a0a 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/src/struct.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/src/struct.c @@ -30,7 +30,7 @@ struct_class(mrb_state *mrb) static void struct_corrupted(mrb_state *mrb) { - mrb_raise(mrb, E_TYPE_ERROR, "corrupted data"); + mrb_raise(mrb, E_TYPE_ERROR, "corrupted struct"); } static mrb_value @@ -45,27 +45,28 @@ struct_s_members(mrb_state *mrb, struct RClass *c) if (!mrb_array_p(members)) { struct_corrupted(mrb); } - break; + return members; } c = c->super; if (c == sclass || c == 0) { mrb_raise(mrb, E_TYPE_ERROR, "uninitialized struct"); } } - return members; } static mrb_value struct_members(mrb_state *mrb, mrb_value s) { - if (!mrb_struct_p(s) || RSTRUCT_LEN(s) == 0) { + if (!mrb_struct_p(s)) { struct_corrupted(mrb); } mrb_value members = struct_s_members(mrb, mrb_obj_class(mrb, s)); - if (RSTRUCT_LEN(s) != RARRAY_LEN(members)) { + mrb_int len = RSTRUCT_LEN(s); + mrb_int mlen = RARRAY_LEN(members); + if (len > 0 && len != mlen) { mrb_raisef(mrb, E_TYPE_ERROR, "struct size differs (%i required %i given)", - RARRAY_LEN(members), RSTRUCT_LEN(s)); + mlen, len); } return members; } @@ -102,13 +103,25 @@ mrb_struct_members(mrb_state *mrb, mrb_value obj) return mrb_struct_s_members_m(mrb, mrb_obj_value(mrb_obj_class(mrb, obj))); } +static mrb_int +num_members(mrb_state *mrb, mrb_value self) +{ + mrb_value members = struct_members(mrb, self); + return RARRAY_LEN(members); +} + static mrb_value mrb_struct_ref(mrb_state *mrb, mrb_value obj) { + mrb_int argc = mrb_get_argc(mrb); + if (argc != 0) { + mrb_argnum_error(mrb, argc, 0, 0); + } mrb_int i = mrb_integer(mrb_proc_cfunc_env_get(mrb, 0)); + mrb_int len = num_members(mrb, obj); mrb_value *ptr = RSTRUCT_PTR(obj); - if (!ptr) return mrb_nil_value(); + if (!ptr || len <= i) return mrb_nil_value(); return ptr[i]; } @@ -126,7 +139,7 @@ mrb_id_attrset(mrb_state *mrb, mrb_sym id) name = mrb_sym_name_len(mrb, id, &len); if (len > ONSTACK_STRLEN_MAX) { - buf = (char *)mrb_malloc(mrb, (size_t)len+1); + buf = (char*)mrb_malloc(mrb, (size_t)len+1); } else { buf = onstack; @@ -145,18 +158,9 @@ static mrb_value mrb_struct_set_m(mrb_state *mrb, mrb_value obj) { mrb_int i = mrb_integer(mrb_proc_cfunc_env_get(mrb, 0)); - mrb_value *ptr; mrb_value val = mrb_get_arg1(mrb); - mrb_struct_modify(mrb, obj); - ptr = RSTRUCT_PTR(obj); - if (ptr == NULL || i >= RSTRUCT_LEN(obj)) { - mrb_ary_set(mrb, obj, i, val); - } - else { - ptr[i] = val; - mrb_field_write_barrier_value(mrb, mrb_basic_ptr(obj), val); - } + mrb_ary_set(mrb, obj, i, val); return val; } @@ -205,6 +209,8 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass *kl } c = mrb_define_class_under_id(mrb, klass, id, klass); } + MRB_SET_INSTANCE_TT(c, MRB_TT_STRUCT); + MRB_DEFINE_ALLOCATOR(c); nstr = mrb_obj_value(c); mrb_iv_set(mrb, nstr, MRB_SYM(__members__), members); @@ -253,55 +259,46 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass *kl static mrb_value mrb_struct_s_def(mrb_state *mrb, mrb_value klass) { - mrb_value name, rest; + mrb_value name = mrb_nil_value(); const mrb_value *pargv; mrb_int argcnt; - mrb_int i; mrb_value b, st; - mrb_sym id; const mrb_value *argv; mrb_int argc; - name = mrb_nil_value(); mrb_get_args(mrb, "*&", &argv, &argc, &b); - if (argc == 0) { /* special case to avoid crash */ - mrb_argnum_error(mrb, argc, 1, -1); + if (argc == 0) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (given 0, expected 1+)"); } - else { - pargv = argv; - argcnt = argc; - if (argc > 0) { - name = argv[0]; - if (mrb_symbol_p(name)) { - /* 1stArgument:symbol -> name=nil rest=argv[0..n] */ - name = mrb_nil_value(); - } - else { - pargv++; - argcnt--; + pargv = argv; + argcnt = argc; + if (argc > 0 && !mrb_symbol_p(argv[0])) { + /* 1stArgument:!symbol -> name=argv[0] rest=argv[0..n] */ + name = argv[0]; + pargv++; + argcnt--; + } + mrb_value members = mrb_ary_new_from_values(mrb, argcnt, pargv); + for (mrb_int i=0; i= RSTRUCT_LEN(s)) return mrb_nil_value(); return RSTRUCT_PTR(s)[idx]; } @@ -434,19 +433,16 @@ mrb_struct_aref(mrb_state *mrb, mrb_value s) static mrb_value mrb_struct_aset_sym(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val) { - mrb_value members, *ptr; + mrb_value members; const mrb_value *ptr_members; mrb_int i, len; members = struct_members(mrb, s); len = RARRAY_LEN(members); - ptr = RSTRUCT_PTR(s); ptr_members = RARRAY_PTR(members); for (i=0; i string + * struct.inspect -> string + * + * Returns a string representation of Data + */ +static mrb_value +mrb_struct_to_s(mrb_state *mrb, mrb_value self) +{ + mrb_value members, ret, cname; + mrb_value *mems; + mrb_int mlen; + + mrb->c->ci->mid = MRB_SYM(inspect); + ret = mrb_str_new_lit(mrb, "#"); + return ret; + } + members = struct_members(mrb, self); + mlen = RARRAY_LEN(members); + mems = RARRAY_PTR(members); + for (mrb_int i=0; i0) mrb_str_cat_lit(mrb, ret, ", "); + mrb_str_cat(mrb, ret, name, len); + mrb_str_cat_lit(mrb, ret, "="); + mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, mrb_ary_ref(mrb, self, i))); + mrb_gc_arena_restore(mrb, ai); + } + mrb_str_cat_lit(mrb, ret, ">"); + + return ret; +} + /* * A Struct is a convenient way to bundle a number of * attributes together, using accessor methods, without having to write @@ -657,6 +699,7 @@ mrb_mruby_struct_gem_init(mrb_state* mrb) struct RClass *st; st = mrb_define_class(mrb, "Struct", mrb->object_class); MRB_SET_INSTANCE_TT(st, MRB_TT_STRUCT); + MRB_UNDEF_ALLOCATOR(st); mrb_define_class_method(mrb, st, "new", mrb_struct_s_def, MRB_ARGS_ANY()); /* 15.2.18.3.1 */ @@ -667,6 +710,8 @@ mrb_mruby_struct_gem_init(mrb_state* mrb) mrb_define_method(mrb, st, "initialize", mrb_struct_initialize, MRB_ARGS_ANY()); /* 15.2.18.4.8 */ mrb_define_method(mrb, st, "initialize_copy", mrb_struct_init_copy, MRB_ARGS_REQ(1)); /* 15.2.18.4.9 */ mrb_define_method(mrb, st, "eql?", mrb_struct_eql, MRB_ARGS_REQ(1)); /* 15.2.18.4.12(x) */ + mrb_define_method(mrb, st, "to_s", mrb_struct_to_s, MRB_ARGS_NONE()); /* 15.2.18.4.11(x) */ + mrb_define_method(mrb, st, "inspect", mrb_struct_to_s, MRB_ARGS_NONE()); /* 15.2.18.4.10(x) */ mrb_define_method(mrb, st, "size", mrb_struct_len, MRB_ARGS_NONE()); mrb_define_method(mrb, st, "length", mrb_struct_len, MRB_ARGS_NONE()); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/test/struct.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/test/struct.rb index db0fa56d86..384a920638 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/test/struct.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-struct/test/struct.rb @@ -119,7 +119,7 @@ assert('struct inspect') do c = Struct.new(:m1, :m2, :m3, :m4, :m5, :recur) cc = c.new(1,2,3,4,5,nil) cc.recur = cc - assert_equal "#>", cc.inspect + assert_equal "#>", cc.inspect end assert('Struct#length, Struct#size') do diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test-inline-struct/test/inline.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test-inline-struct/test/inline.c index a54bf2b030..c92caa5da2 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test-inline-struct/test/inline.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test-inline-struct/test/inline.c @@ -56,9 +56,8 @@ istruct_test_test_receive(mrb_state *mrb, mrb_value self) static mrb_value istruct_test_test_receive_direct(mrb_state *mrb, mrb_value self) { - mrb_value is; + mrb_value is = mrb_get_arg1(mrb); struct RClass *klass = mrb_class_get(mrb, "InlineStructTest"); - mrb_get_args(mrb, "o", &is); /* if you need to protect istruct retrieval from untrusted code, you need to care about class replacing. See mrbgem/mruby-random/src/random.c for detail */ diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test/driver.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test/driver.c index 0ccba9ea8c..96ae3e0718 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test/driver.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test/driver.c @@ -172,7 +172,7 @@ str_match_p(mrb_state *mrb, if (lbrace && rbrace) { /* expand brace */ - char *ex_pat = (char *)mrb_malloc(mrb, pat_len-2); /* expanded pattern */ + char *ex_pat = (char*)mrb_malloc(mrb, pat_len-2); /* expanded pattern */ char *ex_p = ex_pat; COPY_AND_INC(ex_p, pat, lbrace-pat); diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test/mrbgem.rake b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test/mrbgem.rake index 927447b4f7..c8070dd014 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test/mrbgem.rake +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-test/mrbgem.rake @@ -66,37 +66,29 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| f.puts %Q[void mrb_t_pass_result(mrb_state *dst, mrb_state *src);] f.puts %Q[void GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb_state *mrb) {] unless g.test_rbfiles.empty? - f.puts %Q[ mrb_state *mrb2;] unless g.test_args.empty? f.puts %Q[ mrb_value test_args_hash;] end - f.puts %Q[ int ai;] + f.puts %Q[ mrb_state *mrb2 = mrb_open_core(mrb_default_allocf, NULL);] + f.puts %Q[ if (mrb2 == NULL) {] + f.puts %Q[ fprintf(stderr, "Invalid mrb_state, exiting \%s", __func__);] + f.puts %Q[ exit(EXIT_FAILURE);] + f.puts %Q[ }] + f.puts %Q[ mrb_const_set(mrb2, mrb_obj_value(mrb2->object_class), mrb_intern_lit(mrb2, "GEMNAME"), mrb_str_new(mrb2, "#{g.name}", #{g.name.length}));] + if test_preload.nil? + f.puts %Q[ mrb_load_irep(mrb2, mrbtest_assert_irep);] + else + f.puts %Q[ mrb_load_irep(mrb2, gem_test_irep_#{g.funcname}_preload);] + end + dep_list.each do |d| + f.puts %Q[ GENERATED_TMP_mrb_#{d.funcname}_gem_init(mrb2);] + f.puts %Q[ mrb_state_atexit(mrb2, GENERATED_TMP_mrb_#{d.funcname}_gem_final);] + end + f.puts %Q[ mrb_init_test_driver(mrb2, mrb_test(mrb_gv_get(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"))));] + f.puts %Q[ ] g.test_rbfiles.count.times do |i| - f.puts %Q[ ai = mrb_gc_arena_save(mrb);] - f.puts %Q[ mrb2 = mrb_open_core(mrb_default_allocf, NULL);] - f.puts %Q[ if (mrb2 == NULL) {] - f.puts %Q[ fprintf(stderr, "Invalid mrb_state, exiting \%s", __func__);] - f.puts %Q[ exit(EXIT_FAILURE);] - f.puts %Q[ }] - dep_list.each do |d| - f.puts %Q[ GENERATED_TMP_mrb_#{d.funcname}_gem_init(mrb2);] - f.puts %Q[ mrb_state_atexit(mrb2, GENERATED_TMP_mrb_#{d.funcname}_gem_final);] - end - f.puts %Q[ mrb_init_test_driver(mrb2, mrb_test(mrb_gv_get(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"))));] - if test_preload.nil? - f.puts %Q[ mrb_load_irep(mrb2, mrbtest_assert_irep);] - else - f.puts %Q[ mrb_load_irep(mrb2, gem_test_irep_#{g.funcname}_preload);] - end - f.puts %Q[ if (mrb2->exc) {] - f.puts %Q[ mrb_print_error(mrb2);] - f.puts %Q[ mrb_close(mrb2);] - f.puts %Q[ exit(EXIT_FAILURE);] - f.puts %Q[ }] - f.puts %Q[ mrb_const_set(mrb2, mrb_obj_value(mrb2->object_class), mrb_intern_lit(mrb2, "GEMNAME"), mrb_str_new(mrb2, "#{g.name}", #{g.name.length}));] - unless g.test_args.empty? - f.puts %Q[ test_args_hash = mrb_hash_new_capa(mrb, #{g.test_args.length}); ] + f.puts %Q[ test_args_hash = mrb_hash_new_capa(mrb2, #{g.test_args.length}); ] g.test_args.each do |arg_name, arg_value| escaped_arg_name = arg_name.gsub('\\', '\\\\\\\\').gsub('"', '\"') escaped_arg_value = arg_value.gsub('\\', '\\\\\\\\').gsub('"', '\"') @@ -106,14 +98,16 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| end f.puts %Q[ mrb_#{g.funcname}_gem_test(mrb2);] if g.custom_test_init? - f.puts %Q[ mrb_load_irep(mrb2, gem_test_irep_#{g.funcname}_#{i});] + f.puts %Q[ if (mrb2->exc) {] + f.puts %Q[ mrb_print_error(mrb2);] + f.puts %Q[ mrb_close(mrb2);] + f.puts %Q[ exit(EXIT_FAILURE);] + f.puts %Q[ }] f.puts %Q[ ] - - f.puts %Q[ mrb_t_pass_result(mrb, mrb2);] - f.puts %Q[ mrb_close(mrb2);] - f.puts %Q[ mrb_gc_arena_restore(mrb, ai);] end + f.puts %Q[ mrb_t_pass_result(mrb, mrb2);] + f.puts %Q[ mrb_close(mrb2);] end f.puts %Q[}] end @@ -144,14 +138,26 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| f.puts %Q[ * All manual changes will get lost.] f.puts %Q[ */] f.puts %Q[] - f.puts %Q[struct mrb_state;] - f.puts %Q[typedef struct mrb_state mrb_state;] + f.puts %Q[#include ] + f.puts %Q[#include ] + f.puts %Q[#include ] + f.puts %Q[] build.gems.each do |g| f.puts %Q[void GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb_state *mrb);] end f.puts %Q[void mrbgemtest_init(mrb_state* mrb) {] build.gems.each do |g| - f.puts %Q[ GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb);] + if g.skip_test? + f.puts %Q[ do {] + f.puts %Q[ mrb_value asserts = mrb_gv_get(mrb, mrb_intern_lit(mrb, "$asserts"));] + f.puts %Q[ mrb_ary_push(mrb, asserts, mrb_str_new_lit(mrb, ] + f.puts %Q[ "Warn: Skipping tests for gem (#{ + g.name == 'mruby-test' ? 'core' : "mrbgems: #{g.name}" + })"));] + f.puts %Q[ } while (0);] + else + f.puts %Q[ GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb);] + end end f.puts %Q[}] end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-time/mrblib/time.rb b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-time/mrblib/time.rb deleted file mode 100644 index df0d8ca82c..0000000000 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-time/mrblib/time.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Time - def sunday?; wday == 0 end - def monday?; wday == 1 end - def tuesday?; wday == 2 end - def wednesday?; wday == 3 end - def thursday?; wday == 4 end - def friday?; wday == 5 end - def saturday?; wday == 6 end -end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-time/src/time.c b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-time/src/time.c index 63a9d252fd..59dcd80be9 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-time/src/time.c +++ b/yass/third_party/nghttp2/third-party/mruby/mrbgems/mruby-time/src/time.c @@ -83,7 +83,8 @@ double round(double x) { /** end of Time class configuration */ -#if (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) && defined(CLOCK_REALTIME) +/* protection against incorrectly defined _POSIX_TIMERS */ +#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS + 0) > 0 && defined(CLOCK_REALTIME) # define USE_CLOCK_GETTIME #endif @@ -157,10 +158,11 @@ timegm(struct tm *tm) unsigned int *nday = (unsigned int*) ndays[is_leapyear(tm->tm_year+1900)]; static const int epoch_year = 70; - if(tm->tm_year >= epoch_year) { + if (tm->tm_year >= epoch_year) { for (i = epoch_year; i < tm->tm_year; ++i) r += is_leapyear(i+1900) ? 366*24*60*60 : 365*24*60*60; - } else { + } + else { for (i = tm->tm_year; i < epoch_year; ++i) r -= is_leapyear(i+1900) ? 366*24*60*60 : 365*24*60*60; } @@ -196,16 +198,7 @@ struct mrb_time { struct tm datetime; }; -static const struct mrb_data_type mrb_time_type = { "Time", mrb_free }; - -#ifndef MRB_NO_FLOAT -void mrb_check_num_exact(mrb_state *mrb, mrb_float num); -typedef mrb_float mrb_sec; -#define mrb_sec_value(mrb, sec) mrb_float_value(mrb, sec) -#else -typedef mrb_int mrb_sec; -#define mrb_sec_value(mrb, sec) mrb_int_value(mrb, sec) -#endif +static const struct mrb_data_type time_type = { "Time", mrb_free }; #define MRB_TIME_T_UINT (~(time_t)0 > 0) #define MRB_TIME_MIN ( \ @@ -217,7 +210,6 @@ typedef mrb_int mrb_sec; (sizeof(time_t) <= 4 ? INT32_MAX : INT64_MAX) \ ) -#ifndef MRB_NO_FLOAT /* return true if time_t is fit in mrb_int */ static mrb_bool fixable_time_t_p(time_t v) @@ -228,7 +220,6 @@ fixable_time_t_p(time_t v) if (MRB_INT_MIN > (mrb_int)v) return FALSE; return TRUE; } -#endif static time_t mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) @@ -247,16 +238,41 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) } if (usec) { - t = (time_t)f; - *usec = (time_t)llround((f - t) * 1.0e+6); + double tt = floor(f); + if (!isfinite(tt)) goto out_of_range; + t = (time_t)tt; + *usec = (time_t)trunc((f - tt) * 1.0e+6); } else { - t = (time_t)llround(f); + double tt = round(f); + if (!isfinite(tt)) goto out_of_range; + t = (time_t)tt; } } break; #endif /* MRB_NO_FLOAT */ - default: + +#ifdef MRB_USE_BIGINT + case MRB_TT_BIGINT: + { + if (sizeof(time_t) > sizeof(mrb_int)) { + if (MRB_TIME_T_UINT) { + t = (time_t)mrb_bint_as_uint64(mrb, obj); + } + else { + t = (time_t)mrb_bint_as_int64(mrb, obj); + } + if (usec) { *usec = 0; } + break; + } + else { + mrb_int i = mrb_bint_as_int(mrb, obj); + obj = mrb_int_value(mrb, i); + } + } + /* fall through */ +#endif /* MRB_USE_BIGINT */ + case MRB_TT_INTEGER: { mrb_int i = mrb_integer(obj); @@ -270,6 +286,10 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) if (usec) { *usec = 0; } } break; + + default: + mrb_raisef(mrb, E_TYPE_ERROR, "cannot convert %Y to time", obj); + return 0; } return t; @@ -278,10 +298,29 @@ out_of_range: mrb_raisef(mrb, E_ARGUMENT_ERROR, "%v out of Time range", obj); /* not reached */ - if (usec) { *usec = 0; } return 0; } +static mrb_value +time_value_from_time_t(mrb_state *mrb, time_t t) +{ + if (!fixable_time_t_p(t)) { +#if defined(MRB_USE_BIGINT) + if (MRB_TIME_T_UINT) { + return mrb_bint_new_uint64(mrb, (uint64_t)t); + } + else { + return mrb_bint_new_int64(mrb, (int64_t)t); + } +#elif !defined(MRB_NO_FLOAT) + return mrb_float_value(mrb, (mrb_float)t); +#else + mrb_raisef(mrb, E_ARGUMENT_ERROR, "Time too big"); +#endif + } + return mrb_int_value(mrb, (mrb_int)t); +} + /** Updates the datetime of a mrb_time based on it's timezone and seconds setting. Returns self on success, NULL of failure. if `dealloc` is set `true`, it frees `self` on error. */ @@ -298,10 +337,8 @@ time_update_datetime(mrb_state *mrb, struct mrb_time *self, int dealloc) aid = localtime_r(&t, &self->datetime); } if (!aid) { - mrb_sec sec = (mrb_sec)t; - if (dealloc) mrb_free(mrb, self); - mrb_raisef(mrb, E_ARGUMENT_ERROR, "%v out of Time range", mrb_sec_value(mrb, sec)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "%v out of Time range", time_value_from_time_t(mrb, t)); /* not reached */ return NULL; } @@ -313,9 +350,9 @@ time_update_datetime(mrb_state *mrb, struct mrb_time *self, int dealloc) } static mrb_value -mrb_time_wrap(mrb_state *mrb, struct RClass *tc, struct mrb_time *tm) +time_wrap(mrb_state *mrb, struct RClass *tc, struct mrb_time *tm) { - return mrb_obj_value(Data_Wrap_Struct(mrb, tc, &mrb_time_type, tm)); + return mrb_obj_value(Data_Wrap_Struct(mrb, tc, &time_type, tm)); } /* Allocates a mrb_time object and initializes it. */ @@ -324,10 +361,10 @@ time_alloc_time(mrb_state *mrb, time_t sec, time_t usec, enum mrb_timezone timez { struct mrb_time *tm; - tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time)); + tm = (struct mrb_time*)mrb_malloc(mrb, sizeof(struct mrb_time)); tm->sec = sec; tm->usec = usec; - if (MRB_TIME_T_UINT && tm->usec < 0) { + if (!MRB_TIME_T_UINT && tm->usec < 0) { long sec2 = (long)NDIV(tm->usec,1000000); /* negative div */ tm->usec -= sec2 * 1000000; tm->sec += sec2; @@ -355,15 +392,15 @@ time_alloc(mrb_state *mrb, mrb_value sec, mrb_value usec, enum mrb_timezone time } static mrb_value -mrb_time_make_time(mrb_state *mrb, struct RClass *c, time_t sec, time_t usec, enum mrb_timezone timezone) +time_make_time(mrb_state *mrb, struct RClass *c, time_t sec, time_t usec, enum mrb_timezone timezone) { - return mrb_time_wrap(mrb, c, time_alloc_time(mrb, sec, usec, timezone)); + return time_wrap(mrb, c, time_alloc_time(mrb, sec, usec, timezone)); } static mrb_value -mrb_time_make(mrb_state *mrb, struct RClass *c, mrb_value sec, mrb_value usec, enum mrb_timezone timezone) +time_make(mrb_state *mrb, struct RClass *c, mrb_value sec, mrb_value usec, enum mrb_timezone timezone) { - return mrb_time_wrap(mrb, c, time_alloc(mrb, sec, usec, timezone)); + return time_wrap(mrb, c, time_alloc(mrb, sec, usec, timezone)); } static struct mrb_time* @@ -411,7 +448,7 @@ current_mrb_time(mrb_state *mrb) usec = tv.tv_usec; } #endif - tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm)); + tm = (struct mrb_time*)mrb_malloc(mrb, sizeof(*tm)); *tm = tmzero; tm->sec = sec; tm->usec = usec; tm->timezone = MRB_TIMEZONE_LOCAL; @@ -422,28 +459,28 @@ current_mrb_time(mrb_state *mrb) /* Allocates a new Time object with given millis value. */ static mrb_value -mrb_time_now(mrb_state *mrb, mrb_value self) +time_now(mrb_state *mrb, mrb_value self) { - return mrb_time_wrap(mrb, mrb_class_ptr(self), current_mrb_time(mrb)); + return time_wrap(mrb, mrb_class_ptr(self), current_mrb_time(mrb)); } MRB_API mrb_value -mrb_time_at(mrb_state *mrb, time_t sec, time_t usec, enum mrb_timezone zone) +time_at(mrb_state *mrb, time_t sec, time_t usec, enum mrb_timezone zone) { - return mrb_time_make_time(mrb, mrb_class_get_id(mrb, MRB_SYM(Time)), sec, usec, zone); + return time_make_time(mrb, mrb_class_get_id(mrb, MRB_SYM(Time)), sec, usec, zone); } /* 15.2.19.6.1 */ /* Creates an instance of time at the given time in seconds, etc. */ static mrb_value -mrb_time_at_m(mrb_state *mrb, mrb_value self) +time_at_m(mrb_state *mrb, mrb_value self) { mrb_value sec; mrb_value usec = mrb_fixnum_value(0); mrb_get_args(mrb, "o|o", &sec, &usec); - return mrb_time_make(mrb, mrb_class_ptr(self), sec, usec, MRB_TIMEZONE_LOCAL); + return time_make(mrb, mrb_class_ptr(self), sec, usec, MRB_TIMEZONE_LOCAL); } static struct mrb_time* @@ -460,7 +497,8 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday, #define OUTINT(x) 0 #endif - if (ayear < 1900 || OUTINT(ayear-1900) || + ayear -= 1900; + if (OUTINT(ayear) || amonth < 1 || amonth > 12 || aday < 1 || aday > 31 || ahour < 0 || ahour > 24 || @@ -469,7 +507,7 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday, asec < 0 || asec > 60) mrb_raise(mrb, E_ARGUMENT_ERROR, "argument out of range"); - nowtime.tm_year = (int)(ayear - 1900); + nowtime.tm_year = (int)ayear; nowtime.tm_mon = (int)(amonth - 1); nowtime.tm_mday = (int)aday; nowtime.tm_hour = (int)ahour; @@ -500,13 +538,13 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday, /* 15.2.19.6.2 */ /* Creates an instance of time at the given time in UTC. */ static mrb_value -mrb_time_gm(mrb_state *mrb, mrb_value self) +time_gm(mrb_state *mrb, mrb_value self) { mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, amin = 0, asec = 0, ausec = 0; mrb_get_args(mrb, "i|iiiiii", &ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec); - return mrb_time_wrap(mrb, mrb_class_ptr(self), + return time_wrap(mrb, mrb_class_ptr(self), time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_UTC)); } @@ -514,13 +552,13 @@ mrb_time_gm(mrb_state *mrb, mrb_value self) /* 15.2.19.6.3 */ /* Creates an instance of time at the given time in local time zone. */ static mrb_value -mrb_time_local(mrb_state *mrb, mrb_value self) +time_local(mrb_state *mrb, mrb_value self) { mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, amin = 0, asec = 0, ausec = 0; mrb_get_args(mrb, "i|iiiiii", &ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec); - return mrb_time_wrap(mrb, mrb_class_ptr(self), + return time_wrap(mrb, mrb_class_ptr(self), time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_LOCAL)); } @@ -529,7 +567,7 @@ time_get_ptr(mrb_state *mrb, mrb_value time) { struct mrb_time *tm; - tm = DATA_GET_PTR(mrb, time, &mrb_time_type, struct mrb_time); + tm = DATA_GET_PTR(mrb, time, &time_type, struct mrb_time); if (!tm) { mrb_raise(mrb, E_ARGUMENT_ERROR, "uninitialized time"); } @@ -537,27 +575,27 @@ time_get_ptr(mrb_state *mrb, mrb_value time) } static mrb_value -mrb_time_eq(mrb_state *mrb, mrb_value self) +time_eq(mrb_state *mrb, mrb_value self) { mrb_value other = mrb_get_arg1(mrb); struct mrb_time *tm1, *tm2; mrb_bool eq_p; - tm1 = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time); - tm2 = DATA_CHECK_GET_PTR(mrb, other, &mrb_time_type, struct mrb_time); + tm1 = DATA_GET_PTR(mrb, self, &time_type, struct mrb_time); + tm2 = DATA_CHECK_GET_PTR(mrb, other, &time_type, struct mrb_time); eq_p = tm1 && tm2 && tm1->sec == tm2->sec && tm1->usec == tm2->usec; return mrb_bool_value(eq_p); } static mrb_value -mrb_time_cmp(mrb_state *mrb, mrb_value self) +time_cmp(mrb_state *mrb, mrb_value self) { mrb_value other = mrb_get_arg1(mrb); struct mrb_time *tm1, *tm2; - tm1 = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time); - tm2 = DATA_CHECK_GET_PTR(mrb, other, &mrb_time_type, struct mrb_time); + tm1 = DATA_GET_PTR(mrb, self, &time_type, struct mrb_time); + tm2 = DATA_CHECK_GET_PTR(mrb, other, &time_type, struct mrb_time); if (!tm1 || !tm2) return mrb_nil_value(); if (tm1->sec > tm2->sec) { return mrb_fixnum_value(1); @@ -582,7 +620,7 @@ int_overflow(mrb_state *mrb, const char *reason) } static mrb_value -mrb_time_plus(mrb_state *mrb, mrb_value self) +time_plus(mrb_state *mrb, mrb_value self) { mrb_value o = mrb_get_arg1(mrb); struct mrb_time *tm; @@ -607,22 +645,22 @@ mrb_time_plus(mrb_state *mrb, mrb_value self) } sec = tm->sec + sec; #endif - return mrb_time_make_time(mrb, mrb_obj_class(mrb, self), sec, tm->usec+usec, tm->timezone); + return time_make_time(mrb, mrb_obj_class(mrb, self), sec, tm->usec+usec, tm->timezone); } static mrb_value -mrb_time_minus(mrb_state *mrb, mrb_value self) +time_minus(mrb_state *mrb, mrb_value self) { mrb_value other = mrb_get_arg1(mrb); struct mrb_time *tm, *tm2; tm = time_get_ptr(mrb, self); - tm2 = DATA_CHECK_GET_PTR(mrb, other, &mrb_time_type, struct mrb_time); + tm2 = DATA_CHECK_GET_PTR(mrb, other, &time_type, struct mrb_time); if (tm2) { #ifndef MRB_NO_FLOAT mrb_float f; - f = (mrb_sec)(tm->sec - tm2->sec) - + (mrb_sec)(tm->usec - tm2->usec) / 1.0e6; + f = (mrb_float)(tm->sec - tm2->sec) + + (mrb_float)(tm->usec - tm2->usec) / 1.0e6; return mrb_float_value(mrb, f); #else mrb_int f; @@ -651,14 +689,14 @@ mrb_time_minus(mrb_state *mrb, mrb_value self) } sec = tm->sec - sec; #endif - return mrb_time_make_time(mrb, mrb_obj_class(mrb, self), sec, tm->usec-usec, tm->timezone); + return time_make_time(mrb, mrb_obj_class(mrb, self), sec, tm->usec-usec, tm->timezone); } } /* 15.2.19.7.30 */ /* Returns week day number of time. */ static mrb_value -mrb_time_wday(mrb_state *mrb, mrb_value self) +time_wday(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -669,7 +707,7 @@ mrb_time_wday(mrb_state *mrb, mrb_value self) /* 15.2.19.7.31 */ /* Returns year day number of time. */ static mrb_value -mrb_time_yday(mrb_state *mrb, mrb_value self) +time_yday(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -680,7 +718,7 @@ mrb_time_yday(mrb_state *mrb, mrb_value self) /* 15.2.19.7.32 */ /* Returns year of time. */ static mrb_value -mrb_time_year(mrb_state *mrb, mrb_value self) +time_year(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -708,7 +746,7 @@ time_zonename(mrb_state *mrb, struct mrb_time *tm, char *buf, size_t len) /* 15.2.19.7.33 */ /* Returns name of time's timezone. */ static mrb_value -mrb_time_zone(mrb_state *mrb, mrb_value self) +time_zone(mrb_state *mrb, mrb_value self) { struct mrb_time *tm = time_get_ptr(mrb, self); if (tm->timezone == MRB_TIMEZONE_UTC) { @@ -722,7 +760,7 @@ mrb_time_zone(mrb_state *mrb, mrb_value self) /* 15.2.19.7.4 */ /* Returns a string that describes the time. */ static mrb_value -mrb_time_asctime(mrb_state *mrb, mrb_value self) +time_asctime(mrb_state *mrb, mrb_value self) { struct mrb_time *tm = time_get_ptr(mrb, self); struct tm *d = &tm->datetime; @@ -750,7 +788,7 @@ mrb_time_asctime(mrb_state *mrb, mrb_value self) /* 15.2.19.7.6 */ /* Returns the day in the month of the time. */ static mrb_value -mrb_time_day(mrb_state *mrb, mrb_value self) +time_day(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -762,7 +800,7 @@ mrb_time_day(mrb_state *mrb, mrb_value self) /* 15.2.19.7.7 */ /* Returns true if daylight saving was applied for this time. */ static mrb_value -mrb_time_dst_p(mrb_state *mrb, mrb_value self) +time_dst_p(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -774,37 +812,37 @@ mrb_time_dst_p(mrb_state *mrb, mrb_value self) /* 15.2.19.7.10 */ /* Returns the Time object of the UTC(GMT) timezone. */ static mrb_value -mrb_time_getutc(mrb_state *mrb, mrb_value self) +time_getutc(mrb_state *mrb, mrb_value self) { struct mrb_time *tm, *tm2; tm = time_get_ptr(mrb, self); - tm2 = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm)); + tm2 = (struct mrb_time*)mrb_malloc(mrb, sizeof(*tm)); *tm2 = *tm; tm2->timezone = MRB_TIMEZONE_UTC; time_update_datetime(mrb, tm2, TRUE); - return mrb_time_wrap(mrb, mrb_obj_class(mrb, self), tm2); + return time_wrap(mrb, mrb_obj_class(mrb, self), tm2); } /* 15.2.19.7.9 */ /* Returns the Time object of the LOCAL timezone. */ static mrb_value -mrb_time_getlocal(mrb_state *mrb, mrb_value self) +time_getlocal(mrb_state *mrb, mrb_value self) { struct mrb_time *tm, *tm2; tm = time_get_ptr(mrb, self); - tm2 = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm)); + tm2 = (struct mrb_time*)mrb_malloc(mrb, sizeof(*tm)); *tm2 = *tm; tm2->timezone = MRB_TIMEZONE_LOCAL; time_update_datetime(mrb, tm2, TRUE); - return mrb_time_wrap(mrb, mrb_obj_class(mrb, self), tm2); + return time_wrap(mrb, mrb_obj_class(mrb, self), tm2); } /* 15.2.19.7.15 */ /* Returns hour of time. */ static mrb_value -mrb_time_hour(mrb_state *mrb, mrb_value self) +time_hour(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -815,7 +853,7 @@ mrb_time_hour(mrb_state *mrb, mrb_value self) /* 15.2.19.7.16 */ /* Initializes a time by setting the amount of milliseconds since the epoch.*/ static mrb_value -mrb_time_initialize(mrb_state *mrb, mrb_value self) +time_init(mrb_state *mrb, mrb_value self) { mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, amin = 0, asec = 0, ausec = 0; @@ -828,7 +866,7 @@ mrb_time_initialize(mrb_state *mrb, mrb_value self) if (tm) { mrb_free(mrb, tm); } - mrb_data_init(self, NULL, &mrb_time_type); + mrb_data_init(self, NULL, &time_type); if (n == 0) { tm = current_mrb_time(mrb); @@ -836,14 +874,14 @@ mrb_time_initialize(mrb_state *mrb, mrb_value self) else { tm = time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_LOCAL); } - mrb_data_init(self, tm, &mrb_time_type); + mrb_data_init(self, tm, &time_type); return self; } /* 15.2.19.7.17(x) */ /* Initializes a copy of this time object. */ static mrb_value -mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy) +time_init_copy(mrb_state *mrb, mrb_value copy) { mrb_value src = mrb_get_arg1(mrb); struct mrb_time *t1, *t2; @@ -852,14 +890,14 @@ mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy) if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) { mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class"); } - t1 = (struct mrb_time *)DATA_PTR(copy); - t2 = (struct mrb_time *)DATA_PTR(src); + t1 = (struct mrb_time*)DATA_PTR(copy); + t2 = (struct mrb_time*)DATA_PTR(src); if (!t2) { mrb_raise(mrb, E_ARGUMENT_ERROR, "uninitialized time"); } if (!t1) { - t1 = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time)); - mrb_data_init(copy, t1, &mrb_time_type); + t1 = (struct mrb_time*)mrb_malloc(mrb, sizeof(struct mrb_time)); + mrb_data_init(copy, t1, &time_type); } *t1 = *t2; return copy; @@ -868,7 +906,7 @@ mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy) /* 15.2.19.7.18 */ /* Sets the timezone attribute of the Time object to LOCAL. */ static mrb_value -mrb_time_localtime(mrb_state *mrb, mrb_value self) +time_localtime(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -881,7 +919,7 @@ mrb_time_localtime(mrb_state *mrb, mrb_value self) /* 15.2.19.7.19 */ /* Returns day of month of time. */ static mrb_value -mrb_time_mday(mrb_state *mrb, mrb_value self) +time_mday(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -892,7 +930,7 @@ mrb_time_mday(mrb_state *mrb, mrb_value self) /* 15.2.19.7.20 */ /* Returns minutes of time. */ static mrb_value -mrb_time_min(mrb_state *mrb, mrb_value self) +time_min(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -903,7 +941,7 @@ mrb_time_min(mrb_state *mrb, mrb_value self) /* 15.2.19.7.21 (mon) and 15.2.19.7.22 (month) */ /* Returns month of time. */ static mrb_value -mrb_time_mon(mrb_state *mrb, mrb_value self) +time_mon(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -914,7 +952,7 @@ mrb_time_mon(mrb_state *mrb, mrb_value self) /* 15.2.19.7.23 */ /* Returns seconds in minute of time. */ static mrb_value -mrb_time_sec(mrb_state *mrb, mrb_value self) +time_sec(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -926,7 +964,7 @@ mrb_time_sec(mrb_state *mrb, mrb_value self) /* 15.2.19.7.24 */ /* Returns a Float with the time since the epoch in seconds. */ static mrb_value -mrb_time_to_f(mrb_state *mrb, mrb_value self) +time_to_f(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -938,23 +976,18 @@ mrb_time_to_f(mrb_state *mrb, mrb_value self) /* 15.2.19.7.25 */ /* Returns an Integer with the time since the epoch in seconds. */ static mrb_value -mrb_time_to_i(mrb_state *mrb, mrb_value self) +time_to_i(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; tm = time_get_ptr(mrb, self); -#ifndef MRB_NO_FLOAT - if (!fixable_time_t_p(tm->sec)) { - return mrb_float_value(mrb, (mrb_float)tm->sec); - } -#endif - return mrb_int_value(mrb, (mrb_int)tm->sec); + return time_value_from_time_t(mrb, tm->sec); } /* 15.2.19.7.26 */ /* Returns the number of microseconds for time. */ static mrb_value -mrb_time_usec(mrb_state *mrb, mrb_value self) +time_usec(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -965,7 +998,7 @@ mrb_time_usec(mrb_state *mrb, mrb_value self) /* 15.2.19.7.27 */ /* Sets the timezone attribute of the Time object to UTC. */ static mrb_value -mrb_time_utc(mrb_state *mrb, mrb_value self) +time_utc(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -978,7 +1011,7 @@ mrb_time_utc(mrb_state *mrb, mrb_value self) /* 15.2.19.7.28 */ /* Returns true if this time is in the UTC timezone false if not. */ static mrb_value -mrb_time_utc_p(mrb_state *mrb, mrb_value self) +time_utc_p(mrb_state *mrb, mrb_value self) { struct mrb_time *tm; @@ -987,7 +1020,7 @@ mrb_time_utc_p(mrb_state *mrb, mrb_value self) } static mrb_value -mrb_time_to_s(mrb_state *mrb, mrb_value self) +time_to_s(mrb_state *mrb, mrb_value self) { struct mrb_time *tm = time_get_ptr(mrb, self); char buf[64]; @@ -1006,7 +1039,7 @@ mrb_time_to_s(mrb_state *mrb, mrb_value self) } static mrb_value -mrb_time_hash(mrb_state *mrb, mrb_value self) +time_hash(mrb_state *mrb, mrb_value self) { struct mrb_time *tm = time_get_ptr(mrb, self); uint32_t hash = mrb_byte_hash((uint8_t*)&tm->sec, sizeof(time_t)); @@ -1015,6 +1048,52 @@ mrb_time_hash(mrb_state *mrb, mrb_value self) return mrb_int_value(mrb, hash); } +#define wday_impl(num) \ + struct mrb_time *tm = time_get_ptr(mrb, self);\ + return mrb_bool_value(tm->datetime.tm_wday == (num)); + +static mrb_value +time_sunday(mrb_state *mrb, mrb_value self) +{ + wday_impl(0); +} + +static mrb_value +time_monday(mrb_state *mrb, mrb_value self) +{ + wday_impl(1); +} + +static mrb_value +time_tuesday(mrb_state *mrb, mrb_value self) +{ + wday_impl(2); +} + +static mrb_value +time_wednesday(mrb_state *mrb, mrb_value self) +{ + wday_impl(3); +} + +static mrb_value +time_thursday(mrb_state *mrb, mrb_value self) +{ + wday_impl(4); +} + +static mrb_value +time_friday(mrb_state *mrb, mrb_value self) +{ + wday_impl(5); +} + +static mrb_value +time_saturday(mrb_state *mrb, mrb_value self) +{ + wday_impl(6); +} + void mrb_mruby_time_gem_init(mrb_state* mrb) { @@ -1023,53 +1102,61 @@ mrb_mruby_time_gem_init(mrb_state* mrb) tc = mrb_define_class(mrb, "Time", mrb->object_class); MRB_SET_INSTANCE_TT(tc, MRB_TT_CDATA); mrb_include_module(mrb, tc, mrb_module_get(mrb, "Comparable")); - mrb_define_class_method(mrb, tc, "at", mrb_time_at_m, MRB_ARGS_ARG(1, 1)); /* 15.2.19.6.1 */ - mrb_define_class_method(mrb, tc, "gm", mrb_time_gm, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.2 */ - mrb_define_class_method(mrb, tc, "local", mrb_time_local, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.3 */ - mrb_define_class_method(mrb, tc, "mktime", mrb_time_local, MRB_ARGS_ARG(1,6));/* 15.2.19.6.4 */ - mrb_define_class_method(mrb, tc, "now", mrb_time_now, MRB_ARGS_NONE()); /* 15.2.19.6.5 */ - mrb_define_class_method(mrb, tc, "utc", mrb_time_gm, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.6 */ + mrb_define_class_method(mrb, tc, "at", time_at_m, MRB_ARGS_ARG(1, 1)); /* 15.2.19.6.1 */ + mrb_define_class_method(mrb, tc, "gm", time_gm, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.2 */ + mrb_define_class_method(mrb, tc, "local", time_local, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.3 */ + mrb_define_class_method(mrb, tc, "mktime", time_local, MRB_ARGS_ARG(1,6));/* 15.2.19.6.4 */ + mrb_define_class_method(mrb, tc, "now", time_now, MRB_ARGS_NONE()); /* 15.2.19.6.5 */ + mrb_define_class_method(mrb, tc, "utc", time_gm, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.6 */ - mrb_define_method(mrb, tc, "hash" , mrb_time_hash , MRB_ARGS_NONE()); - mrb_define_method(mrb, tc, "eql?" , mrb_time_eq , MRB_ARGS_REQ(1)); - mrb_define_method(mrb, tc, "==" , mrb_time_eq , MRB_ARGS_REQ(1)); - mrb_define_method(mrb, tc, "<=>" , mrb_time_cmp , MRB_ARGS_REQ(1)); /* 15.2.19.7.1 */ - mrb_define_method(mrb, tc, "+" , mrb_time_plus , MRB_ARGS_REQ(1)); /* 15.2.19.7.2 */ - mrb_define_method(mrb, tc, "-" , mrb_time_minus , MRB_ARGS_REQ(1)); /* 15.2.19.7.3 */ - mrb_define_method(mrb, tc, "to_s" , mrb_time_to_s , MRB_ARGS_NONE()); - mrb_define_method(mrb, tc, "inspect", mrb_time_to_s , MRB_ARGS_NONE()); - mrb_define_method(mrb, tc, "asctime", mrb_time_asctime, MRB_ARGS_NONE()); /* 15.2.19.7.4 */ - mrb_define_method(mrb, tc, "ctime" , mrb_time_asctime, MRB_ARGS_NONE()); /* 15.2.19.7.5 */ - mrb_define_method(mrb, tc, "day" , mrb_time_day , MRB_ARGS_NONE()); /* 15.2.19.7.6 */ - mrb_define_method(mrb, tc, "dst?" , mrb_time_dst_p , MRB_ARGS_NONE()); /* 15.2.19.7.7 */ - mrb_define_method(mrb, tc, "getgm" , mrb_time_getutc , MRB_ARGS_NONE()); /* 15.2.19.7.8 */ - mrb_define_method(mrb, tc, "getlocal",mrb_time_getlocal,MRB_ARGS_NONE()); /* 15.2.19.7.9 */ - mrb_define_method(mrb, tc, "getutc" , mrb_time_getutc , MRB_ARGS_NONE()); /* 15.2.19.7.10 */ - mrb_define_method(mrb, tc, "gmt?" , mrb_time_utc_p , MRB_ARGS_NONE()); /* 15.2.19.7.11 */ - mrb_define_method(mrb, tc, "gmtime" , mrb_time_utc , MRB_ARGS_NONE()); /* 15.2.19.7.13 */ - mrb_define_method(mrb, tc, "hour" , mrb_time_hour, MRB_ARGS_NONE()); /* 15.2.19.7.15 */ - mrb_define_method(mrb, tc, "localtime", mrb_time_localtime, MRB_ARGS_NONE()); /* 15.2.19.7.18 */ - mrb_define_method(mrb, tc, "mday" , mrb_time_mday, MRB_ARGS_NONE()); /* 15.2.19.7.19 */ - mrb_define_method(mrb, tc, "min" , mrb_time_min, MRB_ARGS_NONE()); /* 15.2.19.7.20 */ + mrb_define_method(mrb, tc, "hash" , time_hash , MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "eql?" , time_eq , MRB_ARGS_REQ(1)); + mrb_define_method(mrb, tc, "==" , time_eq , MRB_ARGS_REQ(1)); + mrb_define_method(mrb, tc, "<=>" , time_cmp , MRB_ARGS_REQ(1)); /* 15.2.19.7.1 */ + mrb_define_method(mrb, tc, "+" , time_plus , MRB_ARGS_REQ(1)); /* 15.2.19.7.2 */ + mrb_define_method(mrb, tc, "-" , time_minus , MRB_ARGS_REQ(1)); /* 15.2.19.7.3 */ + mrb_define_method(mrb, tc, "to_s" , time_to_s , MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "inspect", time_to_s , MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "asctime", time_asctime, MRB_ARGS_NONE()); /* 15.2.19.7.4 */ + mrb_define_method(mrb, tc, "ctime" , time_asctime, MRB_ARGS_NONE()); /* 15.2.19.7.5 */ + mrb_define_method(mrb, tc, "day" , time_day , MRB_ARGS_NONE()); /* 15.2.19.7.6 */ + mrb_define_method(mrb, tc, "dst?" , time_dst_p , MRB_ARGS_NONE()); /* 15.2.19.7.7 */ + mrb_define_method(mrb, tc, "getgm" , time_getutc , MRB_ARGS_NONE()); /* 15.2.19.7.8 */ + mrb_define_method(mrb, tc, "getlocal",time_getlocal,MRB_ARGS_NONE()); /* 15.2.19.7.9 */ + mrb_define_method(mrb, tc, "getutc" , time_getutc , MRB_ARGS_NONE()); /* 15.2.19.7.10 */ + mrb_define_method(mrb, tc, "gmt?" , time_utc_p , MRB_ARGS_NONE()); /* 15.2.19.7.11 */ + mrb_define_method(mrb, tc, "gmtime" , time_utc , MRB_ARGS_NONE()); /* 15.2.19.7.13 */ + mrb_define_method(mrb, tc, "hour" , time_hour, MRB_ARGS_NONE()); /* 15.2.19.7.15 */ + mrb_define_method(mrb, tc, "localtime", time_localtime, MRB_ARGS_NONE()); /* 15.2.19.7.18 */ + mrb_define_method(mrb, tc, "mday" , time_mday, MRB_ARGS_NONE()); /* 15.2.19.7.19 */ + mrb_define_method(mrb, tc, "min" , time_min, MRB_ARGS_NONE()); /* 15.2.19.7.20 */ - mrb_define_method(mrb, tc, "mon" , mrb_time_mon, MRB_ARGS_NONE()); /* 15.2.19.7.21 */ - mrb_define_method(mrb, tc, "month", mrb_time_mon, MRB_ARGS_NONE()); /* 15.2.19.7.22 */ + mrb_define_method(mrb, tc, "mon" , time_mon, MRB_ARGS_NONE()); /* 15.2.19.7.21 */ + mrb_define_method(mrb, tc, "month", time_mon, MRB_ARGS_NONE()); /* 15.2.19.7.22 */ - mrb_define_method(mrb, tc, "sec" , mrb_time_sec, MRB_ARGS_NONE()); /* 15.2.19.7.23 */ - mrb_define_method(mrb, tc, "to_i", mrb_time_to_i, MRB_ARGS_NONE()); /* 15.2.19.7.25 */ + mrb_define_method(mrb, tc, "sec" , time_sec, MRB_ARGS_NONE()); /* 15.2.19.7.23 */ + mrb_define_method(mrb, tc, "to_i", time_to_i, MRB_ARGS_NONE()); /* 15.2.19.7.25 */ #ifndef MRB_NO_FLOAT - mrb_define_method(mrb, tc, "to_f", mrb_time_to_f, MRB_ARGS_NONE()); /* 15.2.19.7.24 */ + mrb_define_method(mrb, tc, "to_f", time_to_f, MRB_ARGS_NONE()); /* 15.2.19.7.24 */ #endif - mrb_define_method(mrb, tc, "usec", mrb_time_usec, MRB_ARGS_NONE()); /* 15.2.19.7.26 */ - mrb_define_method(mrb, tc, "utc" , mrb_time_utc, MRB_ARGS_NONE()); /* 15.2.19.7.27 */ - mrb_define_method(mrb, tc, "utc?", mrb_time_utc_p,MRB_ARGS_NONE()); /* 15.2.19.7.28 */ - mrb_define_method(mrb, tc, "wday", mrb_time_wday, MRB_ARGS_NONE()); /* 15.2.19.7.30 */ - mrb_define_method(mrb, tc, "yday", mrb_time_yday, MRB_ARGS_NONE()); /* 15.2.19.7.31 */ - mrb_define_method(mrb, tc, "year", mrb_time_year, MRB_ARGS_NONE()); /* 15.2.19.7.32 */ - mrb_define_method(mrb, tc, "zone", mrb_time_zone, MRB_ARGS_NONE()); /* 15.2.19.7.33 */ + mrb_define_method(mrb, tc, "usec", time_usec, MRB_ARGS_NONE()); /* 15.2.19.7.26 */ + mrb_define_method(mrb, tc, "utc" , time_utc, MRB_ARGS_NONE()); /* 15.2.19.7.27 */ + mrb_define_method(mrb, tc, "utc?", time_utc_p,MRB_ARGS_NONE()); /* 15.2.19.7.28 */ + mrb_define_method(mrb, tc, "wday", time_wday, MRB_ARGS_NONE()); /* 15.2.19.7.30 */ + mrb_define_method(mrb, tc, "yday", time_yday, MRB_ARGS_NONE()); /* 15.2.19.7.31 */ + mrb_define_method(mrb, tc, "year", time_year, MRB_ARGS_NONE()); /* 15.2.19.7.32 */ + mrb_define_method(mrb, tc, "zone", time_zone, MRB_ARGS_NONE()); /* 15.2.19.7.33 */ - mrb_define_method(mrb, tc, "initialize", mrb_time_initialize, MRB_ARGS_REQ(1)); /* 15.2.19.7.16 */ - mrb_define_method(mrb, tc, "initialize_copy", mrb_time_initialize_copy, MRB_ARGS_REQ(1)); /* 15.2.19.7.17 */ + mrb_define_method(mrb, tc, "initialize", time_init, MRB_ARGS_REQ(1)); /* 15.2.19.7.16 */ + mrb_define_method(mrb, tc, "initialize_copy", time_init_copy, MRB_ARGS_REQ(1)); /* 15.2.19.7.17 */ + + mrb_define_method(mrb, tc, "sunday?", time_sunday, MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "monday?", time_monday, MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "tuesday?", time_tuesday, MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "wednesday?", time_wednesday, MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "thursday?", time_thursday, MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "friday?", time_friday, MRB_ARGS_NONE()); + mrb_define_method(mrb, tc, "saturday?", time_saturday, MRB_ARGS_NONE()); /* methods not available: diff --git a/yass/third_party/nghttp2/third-party/mruby/mrblib/array.rb b/yass/third_party/nghttp2/third-party/mruby/mrblib/array.rb index af3c17cb64..6c2b6cfee6 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrblib/array.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrblib/array.rb @@ -101,27 +101,6 @@ class Array self end - def _inspect(recur_list) - size = self.size - return "[]" if size == 0 - return "[...]" if recur_list[self.object_id] - recur_list[self.object_id] = true - ary=[] - i=0 - while i true or false diff --git a/yass/third_party/nghttp2/third-party/mruby/mrblib/compar.rb b/yass/third_party/nghttp2/third-party/mruby/mrblib/compar.rb index b39d619f4e..2ac70ac6ef 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrblib/compar.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrblib/compar.rb @@ -49,7 +49,7 @@ module Comparable # ISO 15.3.3.2.3 def == other cmp = self <=> other - cmp == 0 + cmp.equal?(0) end ## diff --git a/yass/third_party/nghttp2/third-party/mruby/mrblib/hash.rb b/yass/third_party/nghttp2/third-party/mruby/mrblib/hash.rb index bfec4c2a34..90b6736429 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrblib/hash.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrblib/hash.rb @@ -181,9 +181,9 @@ class Hash # # ISO 15.2.13.4.22 def merge(*others, &block) - i=0; len=others.size h = self.dup return h.__merge(*others) unless block + i=0; len=others.size while i" + vals[i]._inspect(recur_list)) - i+=1 - end - "{"+ary.join(", ")+"}" - end - ## - # Return the contents of this hash as a string. - # - def inspect - self._inspect({}) - end - alias to_s inspect - ## # call-seq: # hsh.reject! {| key, value | block } -> hsh or nil diff --git a/yass/third_party/nghttp2/third-party/mruby/mrblib/kernel.rb b/yass/third_party/nghttp2/third-party/mruby/mrblib/kernel.rb index 7c3ea94209..f72ab6106d 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrblib/kernel.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrblib/kernel.rb @@ -39,11 +39,6 @@ module Kernel !(self =~ y) end - # internal method for inspect - def _inspect(_recur_list) - self.inspect - end - def to_enum(*a) raise NotImplementedError.new("fiber required for enumerator") end diff --git a/yass/third_party/nghttp2/third-party/mruby/mrblib/numeric.rb b/yass/third_party/nghttp2/third-party/mruby/mrblib/numeric.rb index 67e76ece28..a047f019c1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/mrblib/numeric.rb +++ b/yass/third_party/nghttp2/third-party/mruby/mrblib/numeric.rb @@ -69,7 +69,7 @@ class Integer # Calls the given block +self+ times. # # ISO 15.2.8.3.22 - def times &block + def times(&block) return to_enum :times unless block i = 0 diff --git a/yass/third_party/nghttp2/third-party/mruby/oss-fuzz/mruby_proto_fuzzer.cpp b/yass/third_party/nghttp2/third-party/mruby/oss-fuzz/mruby_proto_fuzzer.cpp index f1ecb44efd..2d56b79c0f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +++ b/yass/third_party/nghttp2/third-party/mruby/oss-fuzz/mruby_proto_fuzzer.cpp @@ -18,7 +18,7 @@ int FuzzRB(const uint8_t *Data, size_t size) { if (!mrb) return 0; - char *code = (char *)malloc(size+1); + char *code = (char*)malloc(size+1); if (!code) return 0; memcpy(code, Data, size); diff --git a/yass/third_party/nghttp2/third-party/mruby/src/allocf.c b/yass/third_party/nghttp2/third-party/mruby/src/allocf.c new file mode 100644 index 0000000000..aa9ca646f0 --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/src/allocf.c @@ -0,0 +1,30 @@ +/* +** allocf.c - default memory allocation function +** +** See Copyright Notice in mruby.h +*/ + +#include +#include "mruby.h" + +/* This function serves as the default memory allocation function and accepts four arguments: + * + * - `mrb`: An instance of `mrb_state`. It's important to note that for the initial allocation (used to allocate the `mrb_state` itself), `mrb` is set to NULL. + * - `p`: The previous pointer to the memory region. For memory allocation, this parameter is NULL. + * - `size`: The new size of the memory region to be returned. + * - `ud`: User data, represented as a `void*`, which is passed to the `mrb_state`. + */ + +void* +mrb_default_allocf(mrb_state *mrb, void *p, size_t size, void *ud) +{ + if (size == 0) { + /* `free(NULL)` should be no-op */ + free(p); + return NULL; + } + else { + /* `ralloc(NULL, size)` works as `malloc(size)` */ + return realloc(p, size); + } +} diff --git a/yass/third_party/nghttp2/third-party/mruby/src/array.c b/yass/third_party/nghttp2/third-party/mruby/src/array.c index d841a9945d..01ccd85a82 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/array.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/array.c @@ -90,9 +90,7 @@ mrb_ary_new(mrb_state *mrb) static inline void array_copy(mrb_value *dst, const mrb_value *src, mrb_int size) { - mrb_int i; - - for (i = 0; i < size; i++) { + for (mrb_int i = 0; i < size; i++) { dst[i] = src[i]; } } @@ -160,7 +158,7 @@ ary_modify(mrb_state *mrb, struct RArray *a) p = a->as.heap.ptr; len = a->as.heap.len * sizeof(mrb_value); - ptr = (mrb_value *)mrb_malloc(mrb, len); + ptr = (mrb_value*)mrb_malloc(mrb, len); if (p) { array_copy(ptr, p, a->as.heap.len); } @@ -183,13 +181,13 @@ static void ary_make_shared(mrb_state *mrb, struct RArray *a) { if (!ARY_SHARED_P(a) && !ARY_EMBED_P(a)) { - mrb_shared_array *shared = (mrb_shared_array *)mrb_malloc(mrb, sizeof(mrb_shared_array)); + mrb_shared_array *shared = (mrb_shared_array*)mrb_malloc(mrb, sizeof(mrb_shared_array)); mrb_value *ptr = a->as.heap.ptr; mrb_int len = a->as.heap.len; shared->refcnt = 1; if (a->as.heap.aux.capa > len) { - a->as.heap.ptr = shared->ptr = (mrb_value *)mrb_realloc(mrb, ptr, sizeof(mrb_value)*len+1); + a->as.heap.ptr = shared->ptr = (mrb_value*)mrb_realloc(mrb, ptr, sizeof(mrb_value)*len+1); } else { shared->ptr = ptr; @@ -224,7 +222,7 @@ ary_expand_capa(mrb_state *mrb, struct RArray *a, mrb_int len) if (ARY_EMBED_P(a)) { mrb_value *ptr = ARY_EMBED_PTR(a); mrb_int len = ARY_EMBED_LEN(a); - mrb_value *expanded_ptr = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*capa); + mrb_value *expanded_ptr = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value)*capa); ARY_UNSET_EMBED_FLAG(a); array_copy(expanded_ptr, ptr, len); @@ -233,7 +231,7 @@ ary_expand_capa(mrb_state *mrb, struct RArray *a, mrb_int len) a->as.heap.ptr = expanded_ptr; } else if (capa > a->as.heap.aux.capa) { - mrb_value *expanded_ptr = (mrb_value *)mrb_realloc(mrb, a->as.heap.ptr, sizeof(mrb_value)*capa); + mrb_value *expanded_ptr = (mrb_value*)mrb_realloc(mrb, a->as.heap.ptr, sizeof(mrb_value)*capa); a->as.heap.aux.capa = capa; a->as.heap.ptr = expanded_ptr; @@ -262,7 +260,7 @@ ary_shrink_capa(mrb_state *mrb, struct RArray *a) if (capa > a->as.heap.len && capa < a->as.heap.aux.capa) { a->as.heap.aux.capa = capa; - a->as.heap.ptr = (mrb_value *)mrb_realloc(mrb, a->as.heap.ptr, sizeof(mrb_value)*capa); + a->as.heap.ptr = (mrb_value*)mrb_realloc(mrb, a->as.heap.ptr, sizeof(mrb_value)*capa); } } @@ -450,16 +448,16 @@ mrb_ary_times(mrb_state *mrb, mrb_value self) { struct RArray *a1 = mrb_ary_ptr(self); struct RArray *a2; - mrb_value *ptr, sep, tmp; + mrb_value *ptr, arg, tmp; mrb_int times, len1; - mrb_get_args(mrb, "o", &sep); - tmp = mrb_check_string_type(mrb, sep); + arg = mrb_get_arg1(mrb); + tmp = mrb_check_string_type(mrb, arg); if (!mrb_nil_p(tmp)) { return mrb_ary_join(mrb, self, tmp); } - mrb_get_args(mrb, "i", ×); + times = mrb_as_int(mrb, arg); if (times < 0) { mrb_raise(mrb, E_ARGUMENT_ERROR, "negative argument"); } @@ -543,9 +541,13 @@ mrb_ary_push_m(mrb_state *mrb, mrb_value self) mrb_int len, len2; struct RArray *a; + argc = mrb_get_argc(mrb); + if (argc == 1) { + mrb_ary_push(mrb, self, mrb_get_argv(mrb)[0]); + return self; + } a = mrb_ary_ptr(self); ary_modify(mrb, a); - argc = mrb_get_argc(mrb); len = ARY_LEN(a); len2 = len + argc; if (ARY_CAPA(a) < len2) { @@ -612,12 +614,12 @@ mrb_ary_shift(mrb_state *mrb, mrb_value self) static mrb_value mrb_ary_shift_m(mrb_state *mrb, mrb_value self) { - mrb_int n; - if (mrb_get_args(mrb, "|i", &n) == 0) { + if (mrb_get_argc(mrb) == 0) { return mrb_ary_shift(mrb, self); } + mrb_int n = mrb_as_int(mrb, mrb_get_arg1(mrb)); struct RArray *a = mrb_ary_ptr(self); mrb_int len = ARY_LEN(a); mrb_value val; @@ -1026,7 +1028,6 @@ mrb_ary_aset(mrb_state *mrb, mrb_value self) mrb_value v1, v2, v3; mrb_int i, len; - ary_modify(mrb, mrb_ary_ptr(self)); if (mrb_get_argc(mrb) == 2) { const mrb_value *vs = mrb_get_argv(mrb); v1 = vs[0]; v2 = vs[1]; @@ -1061,7 +1062,7 @@ mrb_ary_delete_at(mrb_state *mrb, mrb_value self) mrb_value *ptr; mrb_int len, alen; - mrb_get_args(mrb, "i", &index); + index = mrb_as_int(mrb, mrb_get_arg1(mrb)); alen = ARY_LEN(a); if (index < 0) index += alen; if (index < 0 || alen <= index) return mrb_nil_value(); @@ -1109,14 +1110,13 @@ static mrb_value mrb_ary_last(mrb_state *mrb, mrb_value self) { struct RArray *a = mrb_ary_ptr(self); - mrb_int n, size, alen; + mrb_int alen = ARY_LEN(a); - n = mrb_get_args(mrb, "|i", &size); - alen = ARY_LEN(a); - if (n == 0) { + if (mrb_get_argc(mrb) == 0) { return (alen > 0) ? ARY_PTR(a)[alen - 1]: mrb_nil_value(); } + mrb_int size = mrb_integer(mrb_get_arg1(mrb)); if (size < 0) { mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array size"); } @@ -1131,9 +1131,8 @@ static mrb_value mrb_ary_index_m(mrb_state *mrb, mrb_value self) { mrb_value obj = mrb_get_arg1(mrb); - mrb_int i; - for (i = 0; i < RARRAY_LEN(self); i++) { + for (mrb_int i = 0; i < RARRAY_LEN(self); i++) { if (mrb_equal(mrb, RARRAY_PTR(self)[i], obj)) { return mrb_int_value(mrb, i); } @@ -1145,9 +1144,10 @@ static mrb_value mrb_ary_rindex_m(mrb_state *mrb, mrb_value self) { mrb_value obj = mrb_get_arg1(mrb); - mrb_int i, len; - for (i = RARRAY_LEN(self) - 1; i >= 0; i--) { + for (mrb_int i = RARRAY_LEN(self) - 1; i >= 0; i--) { + mrb_int len; + if (mrb_equal(mrb, RARRAY_PTR(self)[i], obj)) { return mrb_int_value(mrb, i); } @@ -1173,7 +1173,7 @@ mrb_ary_splat(mrb_state *mrb, mrb_value v) return mrb_ary_new_from_values(mrb, 1, &v); } - ary = mrb_funcall_id(mrb, v, MRB_SYM(to_a), 0); + ary = mrb_funcall_argv(mrb, v, MRB_SYM(to_a), 0, NULL); if (mrb_nil_p(ary)) { return mrb_ary_new_from_values(mrb, 1, &v); } @@ -1245,11 +1245,10 @@ mrb_ary_entry(mrb_value ary, mrb_int n) static mrb_value join_ary(mrb_state *mrb, mrb_value ary, mrb_value sep, mrb_value list) { - mrb_int i; mrb_value result, val, tmp; /* check recursive */ - for (i=0; i 0 && !mrb_nil_p(sep)) { mrb_str_cat_str(mrb, result, sep); } @@ -1328,6 +1327,33 @@ mrb_ary_join_m(mrb_state *mrb, mrb_value ary) return mrb_ary_join(mrb, ary, sep); } +/* + * call-seq: + * ary.to_s -> string + * ary.inspect -> string + * + * Return the contents of this array as a string. + */ +static mrb_value +mrb_ary_to_s(mrb_state *mrb, mrb_value self) +{ + mrb->c->ci->mid = MRB_SYM(inspect); + mrb_value ret = mrb_str_new_lit(mrb, "["); + int ai = mrb_gc_arena_save(mrb); + if (mrb_inspect_recursive_p(mrb, self)) { + mrb_str_cat_lit(mrb, ret, "...]"); + return ret; + } + for (mrb_int i=0; i0) mrb_str_cat_lit(mrb, ret, ", "); + mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, RARRAY_PTR(self)[i])); + mrb_gc_arena_restore(mrb, ai); + } + mrb_str_cat_lit(mrb, ret, "]"); + + return ret; +} + static mrb_value mrb_ary_eq(mrb_state *mrb, mrb_value ary1) { @@ -1376,39 +1402,41 @@ mrb_init_array(mrb_state *mrb) { struct RClass *a; - mrb->array_class = a = mrb_define_class(mrb, "Array", mrb->object_class); /* 15.2.12 */ + mrb->array_class = a = mrb_define_class_id(mrb, MRB_SYM(Array), mrb->object_class); /* 15.2.12 */ MRB_SET_INSTANCE_TT(a, MRB_TT_ARRAY); - mrb_define_class_method(mrb, a, "[]", mrb_ary_s_create, MRB_ARGS_ANY()); /* 15.2.12.4.1 */ + mrb_define_class_method_id(mrb, a, MRB_OPSYM(aref), mrb_ary_s_create, MRB_ARGS_ANY()); /* 15.2.12.4.1 */ - mrb_define_method(mrb, a, "+", mrb_ary_plus, MRB_ARGS_REQ(1)); /* 15.2.12.5.1 */ - mrb_define_method(mrb, a, "*", mrb_ary_times, MRB_ARGS_REQ(1)); /* 15.2.12.5.2 */ - mrb_define_method(mrb, a, "<<", mrb_ary_push_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.3 */ - mrb_define_method(mrb, a, "[]", mrb_ary_aget, MRB_ARGS_ARG(1,1)); /* 15.2.12.5.4 */ - mrb_define_method(mrb, a, "[]=", mrb_ary_aset, MRB_ARGS_ARG(2,1)); /* 15.2.12.5.5 */ - mrb_define_method(mrb, a, "clear", mrb_ary_clear_m, MRB_ARGS_NONE()); /* 15.2.12.5.6 */ - mrb_define_method(mrb, a, "concat", mrb_ary_concat_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.8 */ - mrb_define_method(mrb, a, "delete_at", mrb_ary_delete_at, MRB_ARGS_REQ(1)); /* 15.2.12.5.9 */ - mrb_define_method(mrb, a, "empty?", mrb_ary_empty_p, MRB_ARGS_NONE()); /* 15.2.12.5.12 */ - mrb_define_method(mrb, a, "first", mrb_ary_first, MRB_ARGS_OPT(1)); /* 15.2.12.5.13 */ - mrb_define_method(mrb, a, "index", mrb_ary_index_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.14 */ - mrb_define_method(mrb, a, "initialize_copy", mrb_ary_replace_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.16 */ - mrb_define_method(mrb, a, "join", mrb_ary_join_m, MRB_ARGS_OPT(1)); /* 15.2.12.5.17 */ - mrb_define_method(mrb, a, "last", mrb_ary_last, MRB_ARGS_OPT(1)); /* 15.2.12.5.18 */ - mrb_define_method(mrb, a, "length", mrb_ary_size, MRB_ARGS_NONE()); /* 15.2.12.5.19 */ - mrb_define_method(mrb, a, "pop", mrb_ary_pop, MRB_ARGS_NONE()); /* 15.2.12.5.21 */ - mrb_define_method(mrb, a, "push", mrb_ary_push_m, MRB_ARGS_ANY()); /* 15.2.12.5.22 */ - mrb_define_method(mrb, a, "replace", mrb_ary_replace_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.23 */ - mrb_define_method(mrb, a, "reverse", mrb_ary_reverse, MRB_ARGS_NONE()); /* 15.2.12.5.24 */ - mrb_define_method(mrb, a, "reverse!", mrb_ary_reverse_bang, MRB_ARGS_NONE()); /* 15.2.12.5.25 */ - mrb_define_method(mrb, a, "rindex", mrb_ary_rindex_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.26 */ - mrb_define_method(mrb, a, "shift", mrb_ary_shift_m, MRB_ARGS_OPT(1)); /* 15.2.12.5.27 */ - mrb_define_method(mrb, a, "size", mrb_ary_size, MRB_ARGS_NONE()); /* 15.2.12.5.28 */ - mrb_define_method(mrb, a, "slice", mrb_ary_aget, MRB_ARGS_ARG(1,1)); /* 15.2.12.5.29 */ - mrb_define_method(mrb, a, "unshift", mrb_ary_unshift_m, MRB_ARGS_ANY()); /* 15.2.12.5.30 */ + mrb_define_method_id(mrb, a, MRB_OPSYM(add), mrb_ary_plus, MRB_ARGS_REQ(1)); /* 15.2.12.5.1 */ + mrb_define_method_id(mrb, a, MRB_OPSYM(mul), mrb_ary_times, MRB_ARGS_REQ(1)); /* 15.2.12.5.2 */ + mrb_define_method_id(mrb, a, MRB_OPSYM(lshift), mrb_ary_push_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.3 */ + mrb_define_method_id(mrb, a, MRB_OPSYM(aref), mrb_ary_aget, MRB_ARGS_ARG(1,1)); /* 15.2.12.5.4 */ + mrb_define_method_id(mrb, a, MRB_OPSYM(aset), mrb_ary_aset, MRB_ARGS_ARG(2,1)); /* 15.2.12.5.5 */ + mrb_define_method_id(mrb, a, MRB_SYM(clear), mrb_ary_clear_m, MRB_ARGS_NONE()); /* 15.2.12.5.6 */ + mrb_define_method_id(mrb, a, MRB_SYM(concat), mrb_ary_concat_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.8 */ + mrb_define_method_id(mrb, a, MRB_SYM(delete_at), mrb_ary_delete_at, MRB_ARGS_REQ(1)); /* 15.2.12.5.9 */ + mrb_define_method_id(mrb, a, MRB_SYM_Q(empty), mrb_ary_empty_p, MRB_ARGS_NONE()); /* 15.2.12.5.12 */ + mrb_define_method_id(mrb, a, MRB_SYM(first), mrb_ary_first, MRB_ARGS_OPT(1)); /* 15.2.12.5.13 */ + mrb_define_method_id(mrb, a, MRB_SYM(index), mrb_ary_index_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.14 */ + mrb_define_method_id(mrb, a, MRB_SYM(initialize_copy), mrb_ary_replace_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.16 */ + mrb_define_method_id(mrb, a, MRB_SYM(join), mrb_ary_join_m, MRB_ARGS_OPT(1)); /* 15.2.12.5.17 */ + mrb_define_method_id(mrb, a, MRB_SYM(last), mrb_ary_last, MRB_ARGS_OPT(1)); /* 15.2.12.5.18 */ + mrb_define_method_id(mrb, a, MRB_SYM(length), mrb_ary_size, MRB_ARGS_NONE()); /* 15.2.12.5.19 */ + mrb_define_method_id(mrb, a, MRB_SYM(pop), mrb_ary_pop, MRB_ARGS_NONE()); /* 15.2.12.5.21 */ + mrb_define_method_id(mrb, a, MRB_SYM(push), mrb_ary_push_m, MRB_ARGS_ANY()); /* 15.2.12.5.22 */ + mrb_define_method_id(mrb, a, MRB_SYM(replace), mrb_ary_replace_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.23 */ + mrb_define_method_id(mrb, a, MRB_SYM(reverse), mrb_ary_reverse, MRB_ARGS_NONE()); /* 15.2.12.5.24 */ + mrb_define_method_id(mrb, a, MRB_SYM_B(reverse), mrb_ary_reverse_bang, MRB_ARGS_NONE()); /* 15.2.12.5.25 */ + mrb_define_method_id(mrb, a, MRB_SYM(rindex), mrb_ary_rindex_m, MRB_ARGS_REQ(1)); /* 15.2.12.5.26 */ + mrb_define_method_id(mrb, a, MRB_SYM(shift), mrb_ary_shift_m, MRB_ARGS_OPT(1)); /* 15.2.12.5.27 */ + mrb_define_method_id(mrb, a, MRB_SYM(size), mrb_ary_size, MRB_ARGS_NONE()); /* 15.2.12.5.28 */ + mrb_define_method_id(mrb, a, MRB_SYM(slice), mrb_ary_aget, MRB_ARGS_ARG(1,1)); /* 15.2.12.5.29 */ + mrb_define_method_id(mrb, a, MRB_SYM(unshift), mrb_ary_unshift_m, MRB_ARGS_ANY()); /* 15.2.12.5.30 */ + mrb_define_method_id(mrb, a, MRB_SYM(to_s), mrb_ary_to_s, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, a, MRB_SYM(inspect), mrb_ary_to_s, MRB_ARGS_NONE()); - mrb_define_method(mrb, a, "__ary_eq", mrb_ary_eq, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, a, "__ary_cmp", mrb_ary_cmp, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, a, "__ary_index", mrb_ary_index_m, MRB_ARGS_REQ(1)); /* kept for mruby-array-ext */ - mrb_define_method(mrb, a, "__svalue", mrb_ary_svalue, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, a, MRB_SYM(__ary_eq), mrb_ary_eq, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, a, MRB_SYM(__ary_cmp), mrb_ary_cmp, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, a, MRB_SYM(__ary_index), mrb_ary_index_m, MRB_ARGS_REQ(1)); /* kept for mruby-array-ext */ + mrb_define_method_id(mrb, a, MRB_SYM(__svalue), mrb_ary_svalue, MRB_ARGS_NONE()); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/backtrace.c b/yass/third_party/nghttp2/third-party/mruby/src/backtrace.c index 4a0fdc118f..816b0e6dbe 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/backtrace.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/backtrace.c @@ -18,59 +18,54 @@ #include struct backtrace_location { - int32_t lineno; mrb_sym method_id; - const char *filename; + int32_t idx; + const mrb_irep *irep; }; typedef void (*each_backtrace_func)(mrb_state*, const struct backtrace_location*, void*); static const mrb_data_type bt_type = { "Backtrace", mrb_free }; -struct RObject *mrb_unpack_backtrace(mrb_state *mrb, struct RObject *backtrace); - -static void +static uint32_t each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void *data) { - if (ciidx >= mrb->c->ciend - mrb->c->cibase) - ciidx = 10; /* ciidx is broken... */ + uint32_t n = 0; for (ptrdiff_t i=ciidx; i >= 0; i--) { struct backtrace_location loc; mrb_callinfo *ci; - const mrb_irep *irep = 0; const mrb_code *pc; - uint32_t idx; ci = &mrb->c->cibase[i]; if (!ci->proc || MRB_PROC_CFUNC_P(ci->proc)) { if (!ci->mid) continue; - loc.lineno = -1; - idx = 0; + loc.irep = NULL; } else { - irep = ci->proc->body.irep; - if (!irep) continue; + loc.irep = ci->proc->body.irep; + if (!loc.irep) continue; + if (!loc.irep->debug_info) continue; if (mrb->c->cibase[i].pc) { pc = &mrb->c->cibase[i].pc[-1]; } else { continue; } - idx = (uint32_t)(pc - irep->iseq); - loc.lineno = mrb_debug_get_line(mrb, irep, idx); + loc.idx = (uint32_t)(pc - loc.irep->iseq); } loc.method_id = ci->mid; - if (loc.lineno == -1) { + if (loc.irep == NULL) { for (ptrdiff_t j=i-1; j >= 0; j--) { ci = &mrb->c->cibase[j]; if (!ci->proc) continue; if (MRB_PROC_CFUNC_P(ci->proc)) continue; - irep = ci->proc->body.irep; + const mrb_irep *irep = ci->proc->body.irep; if (!irep) continue; + if (!irep->debug_info) continue; if (mrb->c->cibase[j].pc) { pc = &mrb->c->cibase[j].pc[-1]; @@ -79,19 +74,139 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void * continue; } - idx = (uint32_t)(pc - irep->iseq); - loc.lineno = mrb_debug_get_line(mrb, irep, idx); - if (loc.lineno > 0) break; + loc.irep = irep; + loc.idx = (uint32_t)(pc - loc.irep->iseq); + break; } } - - loc.filename = mrb_debug_get_filename(mrb, irep, idx); - if (!loc.filename) { - loc.filename = "(unknown)"; - } - - func(mrb, &loc, data); + if (func) func(mrb, &loc, data); + n++; } + return n; +} + +static void +pack_backtrace_i(mrb_state *mrb, + const struct backtrace_location *loc, + void *data) +{ + struct backtrace_location **pptr = (struct backtrace_location**)data; + struct backtrace_location *ptr = *pptr; + + *ptr = *loc; + *pptr = ptr+1; +} + +static struct RObject* +packed_backtrace(mrb_state *mrb) +{ + struct RData *backtrace; + ptrdiff_t ciidx = mrb->c->ci - mrb->c->cibase; + + if (ciidx >= mrb->c->ciend - mrb->c->cibase) + ciidx = mrb->c->ciend - mrb->c->cibase; /* ciidx is broken... */ + + /* count the number of backtraces */ + int len = each_backtrace(mrb, ciidx, NULL, NULL); + backtrace = mrb_data_object_alloc(mrb, NULL, NULL, &bt_type); + if (len > 0) { + void *ptr = mrb_malloc(mrb, len * sizeof(struct backtrace_location)); + backtrace->data = ptr; + backtrace->flags = len; + each_backtrace(mrb, ciidx, pack_backtrace_i, &ptr); + } + else { + backtrace->data = NULL; + backtrace->flags = 0; + } + return (struct RObject*)backtrace; +} + +static void +store_backtrace(mrb_state *mrb, mrb_value exc, struct RObject *backtrace) +{ + struct RException *e = mrb_exc_ptr(exc); + e->backtrace = backtrace; + mrb_field_write_barrier(mrb, (struct RBasic*)e, (struct RBasic*)backtrace); +} + +void +mrb_keep_backtrace(mrb_state *mrb, mrb_value exc) +{ + int ai; + + if (mrb->c->ci == NULL) return; + if (mrb_exc_ptr(exc)->backtrace) return; + ai = mrb_gc_arena_save(mrb); + struct RObject *backtrace = packed_backtrace(mrb); + store_backtrace(mrb, exc, backtrace); + mrb_gc_arena_restore(mrb, ai); +} + +static struct RObject* +mrb_unpack_backtrace(mrb_state *mrb, struct RObject *backtrace) +{ + const struct backtrace_location *bt; + mrb_int n, i; + int ai; + + if (backtrace == NULL) { + empty_backtrace: + return mrb_obj_ptr(mrb_ary_new_capa(mrb, 0)); + } + if (backtrace->tt == MRB_TT_ARRAY) return backtrace; + bt = (struct backtrace_location*)mrb_data_check_get_ptr(mrb, mrb_obj_value(backtrace), &bt_type); + if (bt == NULL) goto empty_backtrace; + n = (mrb_int)backtrace->flags; + if (n == 0) goto empty_backtrace; + backtrace = mrb_obj_ptr(mrb_ary_new_capa(mrb, n)); + ai = mrb_gc_arena_save(mrb); + for (i = 0; i < n; i++) { + const struct backtrace_location *entry = &bt[i]; + mrb_value btline; + int32_t lineno; + const char *filename; + + if (!mrb_debug_get_position(mrb, entry->irep, entry->idx, &lineno, &filename)) { + btline = mrb_str_new_lit(mrb, "(unknown):0"); + } + else if (lineno != -1) {//debug info was available + btline = mrb_format(mrb, "%s:%d", filename, (int)lineno); + } + else { //all that was left was the stack frame + btline = mrb_format(mrb, "%s:0", filename); + } + if (entry->method_id != 0) { + mrb_str_cat_lit(mrb, btline, ":in "); + mrb_str_cat_cstr(mrb, btline, mrb_sym_name(mrb, entry->method_id)); + } + mrb_ary_push(mrb, mrb_obj_value(backtrace), btline); + mrb_gc_arena_restore(mrb, ai); + } + + return backtrace; +} + +mrb_value +mrb_exc_backtrace(mrb_state *mrb, mrb_value exc) +{ + struct RObject *backtrace = mrb_exc_ptr(exc)->backtrace; + if (backtrace == NULL) { + return mrb_nil_value(); + } + if (backtrace->tt == MRB_TT_ARRAY) { + return mrb_obj_value(backtrace); + } + /* unpack packed-backtrace */ + backtrace = mrb_unpack_backtrace(mrb, backtrace); + store_backtrace(mrb, exc, backtrace); + return mrb_obj_value(backtrace); +} + +mrb_value +mrb_get_backtrace(mrb_state *mrb) +{ + return mrb_obj_value(mrb_unpack_backtrace(mrb, packed_backtrace(mrb))); } #ifndef MRB_NO_STDIO @@ -151,132 +266,8 @@ mrb_print_backtrace(mrb_state *mrb) print_backtrace(mrb, mrb->exc, (struct RArray*)backtrace); } #else - MRB_API void mrb_print_backtrace(mrb_state *mrb) { } - #endif - -static void -count_backtrace_i(mrb_state *mrb, - const struct backtrace_location *loc, - void *data) -{ - int *lenp = (int*)data; - - (*lenp)++; -} - -static void -pack_backtrace_i(mrb_state *mrb, - const struct backtrace_location *loc, - void *data) -{ - struct backtrace_location **pptr = (struct backtrace_location**)data; - struct backtrace_location *ptr = *pptr; - - *ptr = *loc; - *pptr = ptr+1; -} - -static struct RObject* -packed_backtrace(mrb_state *mrb) -{ - struct RData *backtrace; - ptrdiff_t ciidx = mrb->c->ci - mrb->c->cibase; - int len = 0; - int size; - void *ptr; - - each_backtrace(mrb, ciidx, count_backtrace_i, &len); - size = len * sizeof(struct backtrace_location); - backtrace = mrb_data_object_alloc(mrb, NULL, NULL, &bt_type); - ptr = mrb_malloc(mrb, size); - backtrace->data = ptr; - backtrace->flags = (uint32_t)len; - each_backtrace(mrb, ciidx, pack_backtrace_i, &ptr); - return (struct RObject*)backtrace; -} - -static void -store_backtrace(mrb_state *mrb, mrb_value exc, struct RObject *backtrace) -{ - struct RException *e = mrb_exc_ptr(exc); - e->backtrace = backtrace; - mrb_field_write_barrier(mrb, (struct RBasic*)e, (struct RBasic*)backtrace); -} - -void -mrb_keep_backtrace(mrb_state *mrb, mrb_value exc) -{ - int ai; - - if (mrb_exc_ptr(exc)->backtrace) return; - ai = mrb_gc_arena_save(mrb); - struct RObject *backtrace = packed_backtrace(mrb); - store_backtrace(mrb, exc, backtrace); - mrb_gc_arena_restore(mrb, ai); -} - -struct RObject* -mrb_unpack_backtrace(mrb_state *mrb, struct RObject *backtrace) -{ - const struct backtrace_location *bt; - mrb_int n, i; - int ai; - - if (backtrace == NULL) { - empty_backtrace: - return mrb_obj_ptr(mrb_ary_new_capa(mrb, 0)); - } - if (backtrace->tt == MRB_TT_ARRAY) return backtrace; - bt = (struct backtrace_location*)mrb_data_check_get_ptr(mrb, mrb_obj_value(backtrace), &bt_type); - if (bt == NULL) goto empty_backtrace; - n = (mrb_int)backtrace->flags; - if (n == 0) goto empty_backtrace; - backtrace = mrb_obj_ptr(mrb_ary_new_capa(mrb, n)); - ai = mrb_gc_arena_save(mrb); - for (i = 0; i < n; i++) { - const struct backtrace_location *entry = &bt[i]; - mrb_value btline; - - if (entry->lineno != -1) {//debug info was available - btline = mrb_format(mrb, "%s:%d", entry->filename, (int)entry->lineno); - } - else { //all that was left was the stack frame - btline = mrb_format(mrb, "%s:0", entry->filename); - } - if (entry->method_id != 0) { - mrb_str_cat_lit(mrb, btline, ":in "); - mrb_str_cat_cstr(mrb, btline, mrb_sym_name(mrb, entry->method_id)); - } - mrb_ary_push(mrb, mrb_obj_value(backtrace), btline); - mrb_gc_arena_restore(mrb, ai); - } - - return backtrace; -} - -mrb_value -mrb_exc_backtrace(mrb_state *mrb, mrb_value exc) -{ - struct RObject *backtrace = mrb_exc_ptr(exc)->backtrace; - if (backtrace == NULL) { - return mrb_nil_value(); - } - if (backtrace->tt == MRB_TT_ARRAY) { - return mrb_obj_value(backtrace); - } - /* unpack packed-backtrace */ - backtrace = mrb_unpack_backtrace(mrb, backtrace); - store_backtrace(mrb, exc, backtrace); - return mrb_obj_value(backtrace); -} - -mrb_value -mrb_get_backtrace(mrb_state *mrb) -{ - return mrb_obj_value(mrb_unpack_backtrace(mrb, packed_backtrace(mrb))); -} diff --git a/yass/third_party/nghttp2/third-party/mruby/src/cdump.c b/yass/third_party/nghttp2/third-party/mruby/src/cdump.c index 251b39842a..92eb1f8674 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/cdump.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/cdump.c @@ -267,8 +267,9 @@ simple_debug_info(mrb_irep_debug_info *info) //adds filenames in init_syms_code block static int cdump_debug(mrb_state *mrb, const char *name, int n, mrb_irep_debug_info *info, - mrb_value init_syms_code, FILE *fp) + mrb_value init_syms_code, FILE *fp) { + int ai = mrb_gc_arena_save(mrb); char buffer[256]; const char *filename; mrb_int file_len; @@ -281,11 +282,10 @@ cdump_debug(mrb_state *mrb, const char *name, int n, mrb_irep_debug_info *info, len = info->files[0]->line_entry_count; filename = mrb_sym_name_len(mrb, info->files[0]->filename_sym, &file_len); - snprintf(buffer, sizeof(buffer), " %s_debug_file_%d.filename_sym = mrb_intern_lit(mrb,\"", - name, n); + snprintf(buffer, sizeof(buffer), " %s_debug_file_%d.filename_sym = mrb_intern_lit(mrb,", name, n); mrb_str_cat_cstr(mrb, init_syms_code, buffer); - mrb_str_cat_cstr(mrb, init_syms_code, filename); - mrb_str_cat_cstr(mrb, init_syms_code, "\");\n"); + mrb_str_cat_str(mrb, init_syms_code, mrb_str_dump(mrb, mrb_str_new_cstr(mrb, filename))); + mrb_str_cat_cstr(mrb, init_syms_code, ");\n"); switch (info->files[0]->line_type) { case mrb_debug_line_ary: @@ -329,6 +329,7 @@ cdump_debug(mrb_state *mrb, const char *name, int n, mrb_irep_debug_info *info, fprintf(fp, "static mrb_irep_debug_info %s_debug_%d = {\n", name, n); fprintf(fp, "%d, %d, &%s_debug_file_%d_};\n", info->pc_count, info->flen, name, n); + mrb_gc_arena_restore(mrb, ai); return MRB_DUMP_OK; } @@ -380,8 +381,7 @@ cdump_irep_struct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *fp, } /* dump debug */ if (flags & MRB_DUMP_DEBUG_INFO) { - if(cdump_debug(mrb, name, n, irep->debug_info, - init_syms_code, fp) == MRB_DUMP_OK) { + if (cdump_debug(mrb, name, n, irep->debug_info, init_syms_code, fp) == MRB_DUMP_OK) { debug_available = 1; } } @@ -415,7 +415,7 @@ cdump_irep_struct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *fp, else { fputs( " NULL,\t\t\t\t\t/* lv */\n", fp); } - if(debug_available) { + if (debug_available) { fprintf(fp, " &%s_debug_%d,\n", name, n); } else { diff --git a/yass/third_party/nghttp2/third-party/mruby/src/class.c b/yass/third_party/nghttp2/third-party/mruby/src/class.c index 6cd40cfd36..ab39a6fc4d 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/class.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/class.c @@ -219,7 +219,6 @@ static struct mt_tbl* mt_copy(mrb_state *mrb, mt_tbl *t) { mt_tbl *t2; - int i; if (t == NULL) return NULL; if (t->alloc == 0) return NULL; @@ -228,7 +227,7 @@ mt_copy(mrb_state *mrb, mt_tbl *t) t2 = mt_new(mrb); mrb_sym *keys = (mrb_sym*)&t->ptr[t->alloc]; union mt_ptr *vals = t->ptr; - for (i=0; ialloc; i++) { + for (int i=0; ialloc; i++) { if (MT_KEY_P(keys[i])) { mt_put(mrb, t2, MT_KEY_SYM(keys[i]), MT_KEY_FLG(keys[i]), vals[i]); } @@ -265,7 +264,6 @@ MRB_API void mrb_mt_foreach(mrb_state *mrb, struct RClass *c, mrb_mt_foreach_func *fn, void *p) { mt_tbl *t = c->mt; - int i; if (t == NULL) return; if (t->alloc == 0) return; @@ -273,7 +271,7 @@ mrb_mt_foreach(mrb_state *mrb, struct RClass *c, mrb_mt_foreach_func *fn, void * mrb_sym *keys = (mrb_sym*)&t->ptr[t->alloc]; union mt_ptr *vals = t->ptr; - for (i=0; ialloc; i++) { + for (int i=0; ialloc; i++) { mrb_sym key = keys[i]; if (MT_KEY_SYM(key)) { if (fn(mrb, MT_KEY_SYM(key), create_method_value(mrb, key, vals[i]), p) != 0) @@ -287,7 +285,6 @@ void mrb_gc_mark_mt(mrb_state *mrb, struct RClass *c) { mt_tbl *t = c->mt; - int i; if (t == NULL) return; if (t->alloc == 0) return; @@ -295,7 +292,7 @@ mrb_gc_mark_mt(mrb_state *mrb, struct RClass *c) mrb_sym *keys = (mrb_sym*)&t->ptr[t->alloc]; union mt_ptr *vals = t->ptr; - for (i=0; ialloc; i++) { + for (int i=0; ialloc; i++) { if (MT_KEY_P(keys[i]) && (keys[i] & MT_FUNC_P) == 0) { /* Proc pointer */ struct RProc *p = vals[i].proc; mrb_gc_mark(mrb, (struct RBasic*)p); @@ -313,6 +310,15 @@ mrb_gc_mark_mt_size(mrb_state *mrb, struct RClass *c) return (size_t)h->size; } +size_t +mrb_class_mt_memsize(mrb_state *mrb, struct RClass *c) +{ + struct mt_tbl *h = c->mt; + + if (!h) return 0; + return sizeof(struct mt_tbl) + (size_t)h->size * sizeof(mrb_method_t); +} + void mrb_gc_free_mt(mrb_state *mrb, struct RClass *c) { @@ -373,8 +379,8 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o) if (o->c->tt == MRB_TT_SCLASS) return; sc = MRB_OBJ_ALLOC(mrb, MRB_TT_SCLASS, mrb->class_class); sc->flags |= MRB_FL_CLASS_IS_INHERITED; - sc->mt = mt_new(mrb); - sc->iv = 0; + sc->mt = NULL; + sc->iv = NULL; if (o->tt == MRB_TT_CLASS) { c = (struct RClass*)o; if (!c->super) { @@ -595,7 +601,7 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id s = mrb_class_ptr(super); } else { - s = 0; + s = NULL; } check_if_class_or_module(mrb, outer); if (mrb_const_defined_at(mrb, outer, id)) { @@ -678,16 +684,16 @@ mrb_exc_get_id(mrb_state *mrb, mrb_sym name) mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class), name); if (!mrb_class_p(c)) { - mrb_raise(mrb, mrb->eException_class, "exception corrupted"); + mrb_raise(mrb, E_EXCEPTION, "exception corrupted"); } exc = e = mrb_class_ptr(c); while (e) { - if (e == mrb->eException_class) + if (e == E_EXCEPTION) return exc; e = e->super; } - return mrb->eException_class; + return E_EXCEPTION; } MRB_API struct RClass* @@ -759,7 +765,13 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_ MRB_CLASS_ORIGIN(c); h = c->mt; - mrb_check_frozen(mrb, c); + if (c->tt == MRB_TT_SCLASS && mrb_frozen_p(c)) { + mrb_value v = mrb_iv_get(mrb, mrb_obj_value(c), MRB_SYM(__attached__)); + mrb_check_frozen_value(mrb, v); + } + else { + mrb_check_frozen(mrb, c); + } if (!h) h = c->mt = mt_new(mrb); if (MRB_METHOD_PROC_P(m)) { struct RProc *p = MRB_METHOD_PROC(m); @@ -1014,10 +1026,7 @@ get_args_v(mrb_state *mrb, mrb_args_format format, void** ptr, va_list *ap) if (i < argc) { pickarg = &argv[i++]; if (needmodify && !mrb_nil_p(*pickarg)) { - if (mrb_immediate_p(*pickarg)) { - mrb_raisef(mrb, E_FROZEN_ERROR, "can't modify frozen %t", *pickarg); - } - mrb_check_frozen(mrb, mrb_obj_ptr(*pickarg)); + mrb_check_frozen_value(mrb, *pickarg); } } else { @@ -1072,8 +1081,8 @@ get_args_v(mrb_state *mrb, mrb_args_format format, void** ptr, va_list *ap) break; case 's': { - const char **ps = 0; - mrb_int *pl = 0; + const char **ps = NULL; + mrb_int *pl = NULL; ps = GET_ARG(const char**); pl = GET_ARG(mrb_int*); @@ -1119,7 +1128,7 @@ get_args_v(mrb_state *mrb, mrb_args_format format, void** ptr, va_list *ap) if (needmodify) goto bad_needmodify; if (pickarg) { if (altmode && mrb_nil_p(*pickarg)) { - *pb = 0; + *pb = NULL; *pl = 0; } else { @@ -1181,7 +1190,7 @@ get_args_v(mrb_state *mrb, mrb_args_format format, void** ptr, va_list *ap) type = GET_ARG(struct mrb_data_type const*); if (pickarg) { if (altmode && mrb_nil_p(*pickarg)) { - *datap = 0; + *datap = NULL; } else { *datap = mrb_data_get_ptr(mrb, *pickarg, type); @@ -1259,7 +1268,7 @@ get_args_v(mrb_state *mrb, mrb_args_format format, void** ptr, va_list *ap) const mrb_sym *kname = kwargs->table; mrb_value *values = kwargs->values; mrb_int j; - const uint32_t keyword_max = 40; + const mrb_int keyword_max = 40; mrb_assert(kwnum >= 0); mrb_assert(required >= 0); @@ -1334,7 +1343,7 @@ finish: s: String [const char*,mrb_int] Receive two arguments; s! gives (NULL,0) for nil z: String [const char*] NUL terminated string; z! gives NULL for nil a: Array [const mrb_value*,mrb_int] Receive two arguments; a! gives (NULL,0) for nil - c: Class/Module [strcut RClass*] c! gives NULL for nil + c: Class/Module [struct RClass*] c! gives NULL for nil f: Integer/Float [mrb_float] i: Integer/Float [mrb_int] b: boolean [mrb_bool] @@ -1442,7 +1451,8 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru } goto skip; } - } else if (p->tt == MRB_TT_CLASS) { + } + else if (p->tt == MRB_TT_CLASS) { if (!search_super) break; superclass_seen = TRUE; } @@ -1521,15 +1531,7 @@ mrb_prepend_module(mrb_state *mrb, struct RClass *c, struct RClass *m) mrb_check_frozen(mrb, c); if (!(c->flags & MRB_FL_CLASS_IS_PREPENDED)) { - struct RClass *c0; - - if (c->tt == MRB_TT_ICLASS) { - c0 = c->c; - } - else { - c0 = c; - } - origin = MRB_OBJ_ALLOC(mrb, MRB_TT_ICLASS, c0); + origin = MRB_OBJ_ALLOC(mrb, MRB_TT_ICLASS, c); origin->flags |= MRB_FL_CLASS_IS_ORIGIN | MRB_FL_CLASS_IS_INHERITED; origin->super = c->super; c->super = origin; @@ -1755,7 +1757,7 @@ mrb_mc_clear_by_class(mrb_state *mrb, struct RClass *c) struct mrb_cache_entry *mc = mrb->cache; for (int i=0; ic == c || mc->c0 == c) mc->c = 0; + if (mc->c == c || mc->c0 == c) mc->c = NULL; } } @@ -1765,7 +1767,7 @@ mc_clear_by_id(mrb_state *mrb, mrb_sym id) struct mrb_cache_entry *mc = mrb->cache; for (int i=0; imid == id) mc->c = 0; + if (mc->mid == id) mc->c = NULL; } } #endif @@ -1839,7 +1841,7 @@ prepare_name_common(mrb_state *mrb, mrb_sym sym, const char *prefix, const char size_t prefix_len = prefix ? strlen(prefix) : 0; size_t suffix_len = suffix ? strlen(suffix) : 0; size_t name_len = sym_len + prefix_len + suffix_len; - char *buf = name_len > sizeof(onstack) ? (char *)mrb_alloca(mrb, name_len) : onstack; + char *buf = name_len > sizeof(onstack) ? (char*)mrb_alloca(mrb, name_len) : onstack; char *p = buf; if (prefix_len > 0) { @@ -1877,12 +1879,12 @@ mod_attr_define(mrb_state *mrb, mrb_value mod, mrb_value (*accessor)(mrb_state * { struct RClass *c = mrb_class_ptr(mod); const mrb_value *argv; - mrb_int argc, i; + mrb_int argc; int ai; mrb_get_args(mrb, "*", &argv, &argc); ai = mrb_gc_arena_save(mrb); - for (i=0; iiv) { + mrb_raise(mrb, E_TYPE_ERROR, "already initialized class"); + } mrb_get_args(mrb, "|C&", &a, &b); if (!mrb_nil_p(b)) { - mrb_yield_with_class(mrb, b, 1, &c, c, mrb_class_ptr(c)); + mrb_yield_with_class(mrb, b, 1, &obj, obj, c); } - return c; + return obj; } static mrb_value @@ -2198,6 +2207,7 @@ mrb_class_new(mrb_state *mrb, struct RClass *super) c = boot_defclass(mrb, super); if (super) { MRB_SET_INSTANCE_TT(c, MRB_INSTANCE_TT(super)); + c->flags |= super->flags & MRB_FL_UNDEF_ALLOCATE; } make_metaclass(mrb, c); @@ -2243,22 +2253,14 @@ mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b) if (!MRB_METHOD_CFUNC_P(m)) { struct RProc *p = MRB_METHOD_PROC(m); + if (!MRB_PROC_CFUNC_P(p) && !MRB_PROC_ALIAS_P(p)) { + struct RProc *pnew = MRB_OBJ_ALLOC(mrb, MRB_TT_PROC, mrb->proc_class); - if (MRB_PROC_ENV_P(p)) { - MRB_PROC_ENV(p)->mid = b; - } - else if (p->color != MRB_GC_RED) { - struct RClass *tc = MRB_PROC_TARGET_CLASS(p); - struct REnv *e = MRB_OBJ_ALLOC(mrb, MRB_TT_ENV, NULL); - - e->mid = b; - if (tc) { - e->c = tc; - mrb_field_write_barrier(mrb, (struct RBasic*)e, (struct RBasic*)tc); - } - p->e.env = e; - p->flags |= MRB_PROC_ENVSET; - mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)e); + pnew->body.mid = b; + pnew->upper = p; + pnew->e.env = NULL; + pnew->flags |= MRB_PROC_ALIAS; + MRB_METHOD_FROM_PROC(m, pnew); } } mrb_define_method_raw(mrb, c, a, m); @@ -2486,14 +2488,9 @@ mrb_mod_remove_const(mrb_state *mrb, mrb_value mod) return val; } -static mrb_value -mrb_mod_const_missing(mrb_state *mrb, mrb_value mod) +mrb_value +mrb_const_missing(mrb_state *mrb, mrb_value mod, mrb_sym sym) { - mrb_sym sym; - - mrb_get_args(mrb, "n", &sym); - mrb->c->ci->mid = 0; - if (mrb_class_real(mrb_class_ptr(mod)) != mrb->object_class) { mrb_name_error(mrb, sym, "uninitialized constant %v::%n", mod, sym); } @@ -2504,6 +2501,16 @@ mrb_mod_const_missing(mrb_state *mrb, mrb_value mod) return mrb_nil_value(); } +mrb_value +mrb_mod_const_missing(mrb_state *mrb, mrb_value mod) +{ + mrb_sym sym; + + mrb_get_args(mrb, "n", &sym); + mrb->c->ci->mid = 0; + return mrb_const_missing(mrb, mod, sym); +} + /* 15.2.2.4.34 */ /* * call-seq: @@ -2553,7 +2560,10 @@ mrb_method_added(mrb_state *mrb, struct RClass *c, mrb_sym mid) else { added = MRB_SYM(method_added); } - mrb_funcall_id(mrb, recv, added, 1, mrb_symbol_value(mid)); + if (!mrb_func_basic_p(mrb, recv, added, mrb_do_nothing)) { + mrb_value sym = mrb_symbol_value(mid); + mrb_funcall_argv(mrb, recv, added, 1, &sym); + } } mrb_value @@ -2624,7 +2634,7 @@ static mrb_value mrb_mod_module_function(mrb_state *mrb, mrb_value mod) { const mrb_value *argv; - mrb_int argc, i; + mrb_int argc; mrb_sym mid; mrb_method_t m; struct RClass *rclass; @@ -2641,7 +2651,7 @@ mrb_mod_module_function(mrb_state *mrb, mrb_value mod) /* set PRIVATE method visibility if implemented */ /* mrb_mod_dummy_visibility(mrb, mod); */ - for (i=0; isuper->flags |= MRB_FL_CLASS_IS_ORIGIN; } if (sc->mt) { - dc->mt = mt_copy(mrb, sc->mt); - } - else { - dc->mt = mt_new(mrb); + if (sc->tt == MRB_TT_ICLASS && !(sc->flags & MRB_FL_CLASS_IS_ORIGIN)) { + dc->mt = sc->mt; + } + else { + dc->mt = mt_copy(mrb, sc->mt); + } } dc->super = sc->super; - MRB_SET_INSTANCE_TT(dc, MRB_INSTANCE_TT(sc)); + dc->flags = sc->flags; + dc->flags &= ~MRB_FL_OBJ_IS_FROZEN; } /* 15.3.1.3.16 */ @@ -2738,6 +2751,7 @@ mrb_obj_init_copy(mrb_state *mrb, mrb_value self) static void init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) { + mrb_assert((mrb_type(dest) == mrb_type(obj))); switch (mrb_type(obj)) { case MRB_TT_ICLASS: copy_class(mrb, dest, obj); @@ -2778,7 +2792,7 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) break; } if (!mrb_func_basic_p(mrb, dest, MRB_SYM(initialize_copy), mrb_obj_init_copy)) { - mrb_funcall_id(mrb, dest, MRB_SYM(initialize_copy), 1, obj); + mrb_funcall_argv(mrb, dest, MRB_SYM(initialize_copy), 1, &obj); } } @@ -2899,8 +2913,8 @@ mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args) * def romanToInt(str) * # ... * end - * def method_missing(methId) - * str = methId.to_s + * def method_missing(sym) + * str = sym.to_s * romanToInt(str) * end * end @@ -2997,68 +3011,65 @@ mrb_init_class(mrb_state *mrb) mrb_class_name_class(mrb, NULL, mod, MRB_SYM(Module)); /* 15.2.2 */ mrb_class_name_class(mrb, NULL, cls, MRB_SYM(Class)); /* 15.2.3 */ - mrb->proc_class = mrb_define_class(mrb, "Proc", mrb->object_class); /* 15.2.17 */ - MRB_SET_INSTANCE_TT(mrb->proc_class, MRB_TT_PROC); - MRB_SET_INSTANCE_TT(cls, MRB_TT_CLASS); - mrb_define_method(mrb, bob, "initialize", mrb_do_nothing, MRB_ARGS_NONE()); - mrb_define_method(mrb, bob, "!", mrb_bob_not, MRB_ARGS_NONE()); - mrb_define_method(mrb, bob, "==", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.1 */ - mrb_define_method(mrb, bob, "__id__", mrb_obj_id_m, MRB_ARGS_NONE()); /* 15.3.1.3.4 */ - mrb_define_method(mrb, bob, "__send__", mrb_f_send, MRB_ARGS_REQ(1)|MRB_ARGS_REST()|MRB_ARGS_BLOCK()); /* 15.3.1.3.5 */ - mrb_define_method(mrb, bob, "equal?", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.11 */ - mrb_define_method(mrb, bob, "instance_eval", mrb_obj_instance_eval, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK()); /* 15.3.1.3.18 */ - mrb_define_method(mrb, bob, "singleton_method_added", mrb_do_nothing, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, bob, "method_missing", mrb_obj_missing, MRB_ARGS_ANY()); /* 15.3.1.3.30 */ + mrb_define_method_id(mrb, bob, MRB_SYM(initialize), mrb_do_nothing, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, bob, MRB_OPSYM(not), mrb_bob_not, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, bob, MRB_OPSYM(eq), mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.1 */ + mrb_define_method_id(mrb, bob, MRB_SYM(__id__), mrb_obj_id_m, MRB_ARGS_NONE()); /* 15.3.1.3.4 */ + mrb_define_method_id(mrb, bob, MRB_SYM(__send__), mrb_f_send, MRB_ARGS_REQ(1)|MRB_ARGS_REST()|MRB_ARGS_BLOCK()); /* 15.3.1.3.5 */ + mrb_define_method_id(mrb, bob, MRB_SYM_Q(equal), mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.11 */ + mrb_define_method_id(mrb, bob, MRB_SYM(instance_eval), mrb_obj_instance_eval, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK()); /* 15.3.1.3.18 */ + mrb_define_method_id(mrb, bob, MRB_SYM(singleton_method_added), mrb_do_nothing, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, bob, MRB_SYM(method_missing), mrb_obj_missing, MRB_ARGS_ANY()); /* 15.3.1.3.30 */ - mrb_define_class_method(mrb, cls, "new", mrb_class_new_class, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK()); - mrb_define_method(mrb, cls, "allocate", mrb_instance_alloc, MRB_ARGS_NONE()); - mrb_define_method(mrb, cls, "superclass", mrb_class_superclass, MRB_ARGS_NONE()); /* 15.2.3.3.4 */ - mrb_define_method(mrb, cls, "initialize", mrb_class_initialize, MRB_ARGS_OPT(1)); /* 15.2.3.3.1 */ - mrb_define_method(mrb, cls, "inherited", mrb_do_nothing, MRB_ARGS_REQ(1)); + mrb_define_class_method_id(mrb, cls, MRB_SYM(new), mrb_class_new_class, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK()); + mrb_define_method_id(mrb, cls, MRB_SYM(allocate), mrb_instance_alloc, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, cls, MRB_SYM(superclass), mrb_class_superclass, MRB_ARGS_NONE()); /* 15.2.3.3.4 */ + mrb_define_method_id(mrb, cls, MRB_SYM(initialize), mrb_class_initialize, MRB_ARGS_OPT(1)); /* 15.2.3.3.1 */ + mrb_define_method_id(mrb, cls, MRB_SYM(inherited), mrb_do_nothing, MRB_ARGS_REQ(1)); init_class_new(mrb, cls); MRB_SET_INSTANCE_TT(mod, MRB_TT_MODULE); - mrb_define_method(mrb, mod, "extend_object", mrb_mod_extend_object, MRB_ARGS_REQ(1)); /* 15.2.2.4.25 */ - mrb_define_method(mrb, mod, "extended", mrb_do_nothing, MRB_ARGS_REQ(1)); /* 15.2.2.4.26 */ - mrb_define_method(mrb, mod, "prepended", mrb_do_nothing, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, mod, "prepend_features", mrb_mod_prepend_features, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, mod, "include?", mrb_mod_include_p, MRB_ARGS_REQ(1)); /* 15.2.2.4.28 */ - mrb_define_method(mrb, mod, "append_features", mrb_mod_append_features, MRB_ARGS_REQ(1)); /* 15.2.2.4.10 */ - mrb_define_method(mrb, mod, "class_eval", mrb_mod_module_eval, MRB_ARGS_ANY()); /* 15.2.2.4.15 */ - mrb_define_method(mrb, mod, "included", mrb_do_nothing, MRB_ARGS_REQ(1)); /* 15.2.2.4.29 */ - mrb_define_method(mrb, mod, "initialize", mrb_mod_initialize, MRB_ARGS_NONE()); /* 15.2.2.4.31 */ - mrb_define_method(mrb, mod, "module_eval", mrb_mod_module_eval, MRB_ARGS_ANY()); /* 15.2.2.4.35 */ - mrb_define_method(mrb, mod, "module_function", mrb_mod_module_function, MRB_ARGS_ANY()); - mrb_define_method(mrb, mod, "private", mrb_mod_dummy_visibility, MRB_ARGS_ANY()); /* 15.2.2.4.36 */ - mrb_define_method(mrb, mod, "protected", mrb_mod_dummy_visibility, MRB_ARGS_ANY()); /* 15.2.2.4.37 */ - mrb_define_method(mrb, mod, "public", mrb_mod_dummy_visibility, MRB_ARGS_ANY()); /* 15.2.2.4.38 */ - mrb_define_method(mrb, mod, "attr_reader", mrb_mod_attr_reader, MRB_ARGS_ANY()); /* 15.2.2.4.13 */ - mrb_define_method(mrb, mod, "attr_writer", mrb_mod_attr_writer, MRB_ARGS_ANY()); /* 15.2.2.4.14 */ - mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, MRB_ARGS_NONE()); - mrb_define_method(mrb, mod, "inspect", mrb_mod_to_s, MRB_ARGS_NONE()); - mrb_define_method(mrb, mod, "alias_method", mrb_mod_alias, MRB_ARGS_ANY()); /* 15.2.2.4.8 */ - mrb_define_method(mrb, mod, "ancestors", mrb_mod_ancestors, MRB_ARGS_NONE()); /* 15.2.2.4.9 */ - mrb_define_method(mrb, mod, "undef_method", mrb_mod_undef, MRB_ARGS_ANY()); /* 15.2.2.4.41 */ - mrb_define_method(mrb, mod, "const_defined?", mrb_mod_const_defined, MRB_ARGS_ARG(1,1)); /* 15.2.2.4.20 */ - mrb_define_method(mrb, mod, "const_get", mrb_mod_const_get, MRB_ARGS_REQ(1)); /* 15.2.2.4.21 */ - mrb_define_method(mrb, mod, "const_set", mrb_mod_const_set, MRB_ARGS_REQ(2)); /* 15.2.2.4.23 */ - mrb_define_method(mrb, mod, "remove_const", mrb_mod_remove_const, MRB_ARGS_REQ(1)); /* 15.2.2.4.40 */ - mrb_define_method(mrb, mod, "const_missing", mrb_mod_const_missing, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, mod, "method_defined?", mrb_mod_method_defined, MRB_ARGS_REQ(1)); /* 15.2.2.4.34 */ - mrb_define_method(mrb, mod, "define_method", mod_define_method, MRB_ARGS_ARG(1,1)); - mrb_define_method(mrb, mod, "===", mrb_mod_eqq, MRB_ARGS_REQ(1)); /* 15.2.2.4.7 */ - mrb_define_method(mrb, mod, "dup", mrb_mod_dup, MRB_ARGS_NONE()); - mrb_define_method(mrb, mod, "method_added", mrb_do_nothing, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, mod, MRB_SYM(extend_object), mrb_mod_extend_object, MRB_ARGS_REQ(1)); /* 15.2.2.4.25 */ + mrb_define_method_id(mrb, mod, MRB_SYM(extended), mrb_do_nothing, MRB_ARGS_REQ(1)); /* 15.2.2.4.26 */ + mrb_define_method_id(mrb, mod, MRB_SYM(prepended), mrb_do_nothing, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, mod, MRB_SYM(prepend_features), mrb_mod_prepend_features, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, mod, MRB_SYM_Q(include), mrb_mod_include_p, MRB_ARGS_REQ(1)); /* 15.2.2.4.28 */ + mrb_define_method_id(mrb, mod, MRB_SYM(append_features), mrb_mod_append_features, MRB_ARGS_REQ(1)); /* 15.2.2.4.10 */ + mrb_define_method_id(mrb, mod, MRB_SYM(class_eval), mrb_mod_module_eval, MRB_ARGS_ANY()); /* 15.2.2.4.15 */ + mrb_define_method_id(mrb, mod, MRB_SYM(included), mrb_do_nothing, MRB_ARGS_REQ(1)); /* 15.2.2.4.29 */ + mrb_define_method_id(mrb, mod, MRB_SYM(initialize), mrb_mod_initialize, MRB_ARGS_NONE()); /* 15.2.2.4.31 */ + mrb_define_method_id(mrb, mod, MRB_SYM(module_eval), mrb_mod_module_eval, MRB_ARGS_ANY()); /* 15.2.2.4.35 */ + mrb_define_method_id(mrb, mod, MRB_SYM(module_function), mrb_mod_module_function, MRB_ARGS_ANY()); + mrb_define_method_id(mrb, mod, MRB_SYM(private), mrb_mod_dummy_visibility, MRB_ARGS_ANY()); /* 15.2.2.4.36 */ + mrb_define_method_id(mrb, mod, MRB_SYM(protected), mrb_mod_dummy_visibility, MRB_ARGS_ANY()); /* 15.2.2.4.37 */ + mrb_define_method_id(mrb, mod, MRB_SYM(public), mrb_mod_dummy_visibility, MRB_ARGS_ANY()); /* 15.2.2.4.38 */ + mrb_define_method_id(mrb, mod, MRB_SYM(attr_reader), mrb_mod_attr_reader, MRB_ARGS_ANY()); /* 15.2.2.4.13 */ + mrb_define_method_id(mrb, mod, MRB_SYM(attr_writer), mrb_mod_attr_writer, MRB_ARGS_ANY()); /* 15.2.2.4.14 */ + mrb_define_method_id(mrb, mod, MRB_SYM(to_s), mrb_mod_to_s, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, mod, MRB_SYM(inspect), mrb_mod_to_s, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, mod, MRB_SYM(alias_method), mrb_mod_alias, MRB_ARGS_ANY()); /* 15.2.2.4.8 */ + mrb_define_method_id(mrb, mod, MRB_SYM(ancestors), mrb_mod_ancestors, MRB_ARGS_NONE()); /* 15.2.2.4.9 */ + mrb_define_method_id(mrb, mod, MRB_SYM(undef_method), mrb_mod_undef, MRB_ARGS_ANY()); /* 15.2.2.4.41 */ + mrb_define_method_id(mrb, mod, MRB_SYM_Q(const_defined), mrb_mod_const_defined, MRB_ARGS_ARG(1,1)); /* 15.2.2.4.20 */ + mrb_define_method_id(mrb, mod, MRB_SYM(const_get), mrb_mod_const_get, MRB_ARGS_REQ(1)); /* 15.2.2.4.21 */ + mrb_define_method_id(mrb, mod, MRB_SYM(const_set), mrb_mod_const_set, MRB_ARGS_REQ(2)); /* 15.2.2.4.23 */ + mrb_define_method_id(mrb, mod, MRB_SYM(remove_const), mrb_mod_remove_const, MRB_ARGS_REQ(1)); /* 15.2.2.4.40 */ + mrb_define_method_id(mrb, mod, MRB_SYM(const_missing), mrb_mod_const_missing, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, mod, MRB_SYM_Q(method_defined), mrb_mod_method_defined, MRB_ARGS_REQ(1)); /* 15.2.2.4.34 */ + mrb_define_method_id(mrb, mod, MRB_SYM(define_method), mod_define_method, MRB_ARGS_ARG(1,1)); + mrb_define_method_id(mrb, mod, MRB_OPSYM(eqq), mrb_mod_eqq, MRB_ARGS_REQ(1)); /* 15.2.2.4.7 */ + mrb_define_method_id(mrb, mod, MRB_SYM(dup), mrb_mod_dup, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, mod, MRB_SYM(method_added), mrb_do_nothing, MRB_ARGS_REQ(1)); - mrb_undef_method(mrb, cls, "append_features"); - mrb_undef_method(mrb, cls, "prepend_features"); - mrb_undef_method(mrb, cls, "extend_object"); - mrb_undef_method(mrb, cls, "module_function"); + mrb_undef_method_id(mrb, cls, MRB_SYM(append_features)); + mrb_undef_method_id(mrb, cls, MRB_SYM(prepend_features)); + mrb_undef_method_id(mrb, cls, MRB_SYM(extend_object)); + mrb_undef_method_id(mrb, cls, MRB_SYM(module_function)); mrb->top_self = MRB_OBJ_ALLOC(mrb, MRB_TT_OBJECT, mrb->object_class); - mrb_define_singleton_method(mrb, mrb->top_self, "inspect", inspect_main, MRB_ARGS_NONE()); - mrb_define_singleton_method(mrb, mrb->top_self, "to_s", inspect_main, MRB_ARGS_NONE()); - mrb_define_singleton_method(mrb, mrb->top_self, "define_method", top_define_method, MRB_ARGS_ARG(1,1)); + mrb_define_singleton_method_id(mrb, mrb->top_self, MRB_SYM(inspect), inspect_main, MRB_ARGS_NONE()); + mrb_define_singleton_method_id(mrb, mrb->top_self, MRB_SYM(to_s), inspect_main, MRB_ARGS_NONE()); + mrb_define_singleton_method_id(mrb, mrb->top_self, MRB_SYM(define_method), top_define_method, MRB_ARGS_ARG(1,1)); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/codedump.c b/yass/third_party/nghttp2/third-party/mruby/src/codedump.c index 1d19354f52..292527f273 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/codedump.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/codedump.c @@ -99,10 +99,9 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out) irep->nregs, irep->nlocals, (int)irep->plen, (int)irep->slen, (int)irep->rlen, (int)irep->ilen); if (irep->lv) { - int i; int head = FALSE; - for (i = 1; i < irep->nlocals; i++) { + for (int i = 1; i < irep->nlocals; i++) { char const *s = mrb_sym_dump(mrb, irep->lv[i - 1]); if (s) { if (!head) { @@ -115,10 +114,9 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out) } if (irep->clen > 0) { - int i = irep->clen; const struct mrb_irep_catch_handler *e = mrb_irep_catch_handler_table(irep); - for (; i > 0; i--,e++) { + for (int i = irep->clen; i > 0; i--,e++) { uint32_t begin = mrb_irep_catch_handler_unpack(e->begin); uint32_t end = mrb_irep_catch_handler_unpack(e->end); uint32_t target = mrb_irep_catch_handler_unpack(e->target); @@ -173,19 +171,19 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out) switch (irep->pool[b].tt) { #ifndef MRB_NO_FLOAT case IREP_TT_FLOAT: - fprintf(out, "LOADL\t\tR%d\tL(%d)\t; %f", a, b, (double)irep->pool[b].u.f); + fprintf(out, "LOADL\t\tR%d\tL[%d]\t; %f", a, b, (double)irep->pool[b].u.f); break; #endif case IREP_TT_INT32: - fprintf(out, "LOADL\t\tR%d\tL(%d)\t; %" PRId32, a, b, irep->pool[b].u.i32); + fprintf(out, "LOADL\t\tR%d\tL[%d]\t; %" PRId32, a, b, irep->pool[b].u.i32); break; #ifdef MRB_64BIT case IREP_TT_INT64: - fprintf(out, "LOADL\t\tR%d\tL(%d)\t; %" PRId64, a, b, irep->pool[b].u.i64); + fprintf(out, "LOADL\t\tR%d\tL[%d]\t; %" PRId64, a, b, irep->pool[b].u.i64); break; #endif default: - fprintf(out, "LOADL\t\tR%d\tL(%d)\t", a, b); + fprintf(out, "LOADL\t\tR%d\tL[%d]\t", a, b); break; } print_lv_a(mrb, irep, a, out); @@ -403,13 +401,13 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out) print_lv_a(mrb, irep, a, out); break; CASE(OP_LAMBDA, BB): - fprintf(out, "LAMBDA\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); + fprintf(out, "LAMBDA\tR%d\tI[%d]\n", a, b); break; CASE(OP_BLOCK, BB): - fprintf(out, "BLOCK\t\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); + fprintf(out, "BLOCK\t\tR%d\tI[%d]\n", a, b); break; CASE(OP_METHOD, BB): - fprintf(out, "METHOD\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); + fprintf(out, "METHOD\tR%d\tI[%d]\n", a, b); break; CASE(OP_RANGE_INC, B): fprintf(out, "RANGE_INC\tR%d\n", a); @@ -499,12 +497,12 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out) break; CASE(OP_SYMBOL, BB): mrb_assert((irep->pool[b].tt&IREP_TT_NFLAG)==0); - fprintf(out, "SYMBOL\tR%d\tL(%d)\t; %s", a, b, irep->pool[b].u.str); + fprintf(out, "SYMBOL\tR%d\tL[%d]\t; %s", a, b, irep->pool[b].u.str); print_lv_a(mrb, irep, a, out); break; CASE(OP_STRING, BB): mrb_assert((irep->pool[b].tt&IREP_TT_NFLAG)==0); - fprintf(out, "STRING\tR%d\tL(%d)\t; %s", a, b, irep->pool[b].u.str); + fprintf(out, "STRING\tR%d\tL[%d]\t; %s", a, b, irep->pool[b].u.str); print_lv_a(mrb, irep, a, out); break; CASE(OP_STRCAT, B): @@ -537,11 +535,11 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out) print_lv_a(mrb, irep, a, out); break; CASE(OP_EXEC, BB): - fprintf(out, "EXEC\t\tR%d\tI(%d:%p)", a, b, (void*)irep->reps[b]); + fprintf(out, "EXEC\t\tR%d\tI[%d]", a, b); print_lv_a(mrb, irep, a, out); break; CASE(OP_SCLASS, B): - fprintf(out, "SCLASS\t\tR%d\t", a); + fprintf(out, "SCLASS\tR%d\t", a); print_lv_a(mrb, irep, a, out); break; CASE(OP_TCLASS, B): @@ -553,7 +551,7 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out) fprintf(out, "ERR\t\t%s\n", irep->pool[a].u.str); } else { - fprintf(out, "ERR\tL(%d)\n", a); + fprintf(out, "ERR\tL[%d]\n", a); } break; CASE(OP_EXCEPT, B): @@ -620,11 +618,9 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out) static void codedump_recur(mrb_state *mrb, const mrb_irep *irep, FILE *out) { - int i; - codedump(mrb, irep, out); if (irep->reps) { - for (i=0; irlen; i++) { + for (int i=0; irlen; i++) { codedump_recur(mrb, irep->reps[i], out); } } @@ -634,6 +630,7 @@ void mrb_codedump_all_file(mrb_state *mrb, struct RProc *proc, FILE *out) { codedump_recur(mrb, proc->body.irep, out); + fflush(out); } #endif diff --git a/yass/third_party/nghttp2/third-party/mruby/src/compar.c b/yass/third_party/nghttp2/third-party/mruby/src/compar.c deleted file mode 100644 index 0032fc8592..0000000000 --- a/yass/third_party/nghttp2/third-party/mruby/src/compar.c +++ /dev/null @@ -1,13 +0,0 @@ -/* -** compar.c - Comparable module -** -** See Copyright Notice in mruby.h -*/ - -#include - -void -mrb_init_comparable(mrb_state *mrb) -{ - mrb_define_module(mrb, "Comparable"); /* 15.3.3 */ -} diff --git a/yass/third_party/nghttp2/third-party/mruby/src/debug.c b/yass/third_party/nghttp2/third-party/mruby/src/debug.c index 11af6fcfbf..c9c132e7ea 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/debug.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/debug.c @@ -47,7 +47,7 @@ mrb_packed_int_len(uint32_t num) } size_t -mrb_packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend) +mrb_packed_int_encode(uint32_t num, uint8_t *p) { size_t llen = 0; @@ -55,7 +55,7 @@ mrb_packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend) uint8_t byte = num & 0x7f; num >>= 7; if (num != 0) byte |= 0x80; - if (p < pend) *p++ = byte; + *p++ = byte; llen++; } while (num != 0); @@ -77,15 +77,46 @@ mrb_packed_int_decode(const uint8_t *p, const uint8_t **newpos) return n; } +static char const* +debug_get_filename(mrb_state *mrb, mrb_irep_debug_info_file* f) +{ + if (f == NULL) return NULL; + return mrb_sym_name_len(mrb, f->filename_sym, NULL); +} + +static int32_t +debug_get_line(mrb_state *mrb, mrb_irep_debug_info_file* f, uint32_t pc) +{ + if (f == NULL) return -1; + switch (f->line_type) { + case mrb_debug_line_ary: + case mrb_debug_line_flat_map: + default: + break; + + case mrb_debug_line_packed_map: + { + const uint8_t *p = f->lines.packed_map; + const uint8_t *pend = p + f->line_entry_count; + uint32_t pos = 0, line = 0, line_diff; + while (p < pend) { + pos += mrb_packed_int_decode(p, &p); + line_diff = mrb_packed_int_decode(p, &p); + if (pc < pos) break; + line += line_diff; + } + return line; + } + } + return -1; +} + MRB_API char const* mrb_debug_get_filename(mrb_state *mrb, const mrb_irep *irep, uint32_t pc) { if (irep && pc < irep->ilen) { - mrb_irep_debug_info_file* f = NULL; if (!irep->debug_info) return NULL; - else if ((f = get_file(irep->debug_info, pc))) { - return mrb_sym_name_len(mrb, f->filename_sym, NULL); - } + return debug_get_filename(mrb, get_file(irep->debug_info, pc)); } return NULL; } @@ -94,60 +125,27 @@ MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, const mrb_irep *irep, uint32_t pc) { if (irep && pc < irep->ilen) { - mrb_irep_debug_info_file* f = NULL; - if (!irep->debug_info) { - return -1; - } - else if ((f = get_file(irep->debug_info, pc))) { - switch (f->line_type) { - case mrb_debug_line_ary: - mrb_assert(f->start_pos <= pc && pc < (f->start_pos + f->line_entry_count)); - return f->lines.ary[pc - f->start_pos]; - - case mrb_debug_line_flat_map: { - /* get upper bound */ - const mrb_irep_debug_info_line *ret = f->lines.flat_map; - uint32_t count = f->line_entry_count; - while (count > 0) { - int32_t step = count / 2; - const mrb_irep_debug_info_line *it = ret + step; - if (!(pc < it->start_pos)) { - ret = it + 1; - count -= step + 1; - } - else { count = step; } - } - - --ret; - - /* check line entry pointer range */ - mrb_assert(f->lines.flat_map <= ret && ret < (f->lines.flat_map + f->line_entry_count)); - /* check pc range */ - mrb_assert(ret->start_pos <= pc && - pc < (((uint32_t)(ret + 1 - f->lines.flat_map) < f->line_entry_count) - ? (ret+1)->start_pos : irep->debug_info->pc_count)); - - return ret->line; - } - - case mrb_debug_line_packed_map: { - const uint8_t *p = f->lines.packed_map; - const uint8_t *pend = p + f->line_entry_count; - uint32_t pos = 0, line = 0, line_diff; - while (p < pend) { - pos += mrb_packed_int_decode(p, &p); - line_diff = mrb_packed_int_decode(p, &p); - if (pc < pos) break; - line += line_diff; - } - return line; - } - } - } + if (!irep->debug_info) return -1; + return debug_get_line(mrb, get_file(irep->debug_info, pc), pc); } return -1; } +MRB_API mrb_bool +mrb_debug_get_position(mrb_state *mrb, const mrb_irep *irep, uint32_t pc, int32_t *lp, const char **fp) +{ + if (irep && pc < irep->ilen && irep->debug_info) { + mrb_irep_debug_info_file *f = get_file(irep->debug_info, pc); + *lp = debug_get_line(mrb, f, pc); + if (*lp > 0) { + *fp = debug_get_filename(mrb, f); + if (*fp) return TRUE; + } + } + *lp = -1; *fp = NULL; + return FALSE; +} + MRB_API mrb_irep_debug_info* mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep) { @@ -155,7 +153,7 @@ mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep) mrb_irep_debug_info *ret; mrb_assert(!irep->debug_info); - ret = (mrb_irep_debug_info *)mrb_malloc(mrb, sizeof(*ret)); + ret = (mrb_irep_debug_info*)mrb_malloc(mrb, sizeof(*ret)); *ret = initial; irep->debug_info = ret; return ret; @@ -200,7 +198,7 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d, uint16_t prev_line = 0; uint32_t prev_pc = 0; size_t packed_size = 0; - uint8_t *p, *pend; + uint8_t *p; for (i = 0; i < file_pc_count; i++) { if (lines[start_pos + i] == prev_line) continue; @@ -210,13 +208,12 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d, prev_line = lines[start_pos + i]; } f->lines.packed_map = p = (uint8_t*)mrb_malloc(mrb, packed_size); - pend = p + packed_size; prev_line = 0; prev_pc = 0; for (i = 0; i < file_pc_count; i++) { if (lines[start_pos + i] == prev_line) continue; - p += mrb_packed_int_encode(start_pos+i-prev_pc, p, pend); + p += mrb_packed_int_encode(start_pos+i-prev_pc, p); prev_pc = start_pos + i; - p += mrb_packed_int_encode(lines[start_pos + i]-prev_line, p, pend); + p += mrb_packed_int_encode(lines[start_pos + i]-prev_line, p); prev_line = lines[start_pos + i]; } f->line_entry_count = (uint32_t)packed_size; diff --git a/yass/third_party/nghttp2/third-party/mruby/src/dump.c b/yass/third_party/nghttp2/third-party/mruby/src/dump.c index c0ad4b6899..093061bab6 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/dump.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/dump.c @@ -452,7 +452,7 @@ get_filename_table_size(mrb_state *mrb, const mrb_irep *irep, mrb_sym **fp, uint if (find_filename_index(filenames, *lp, file->filename_sym) == -1) { /* register filename */ *lp += 1; - *fp = filenames = (mrb_sym *)mrb_realloc(mrb, filenames, sizeof(mrb_sym) * (*lp)); + *fp = filenames = (mrb_sym*)mrb_realloc(mrb, filenames, sizeof(mrb_sym) * (*lp)); filenames[*lp - 1] = file->filename_sym; /* filename */ @@ -557,7 +557,7 @@ write_section_debug(mrb_state *mrb, const mrb_irep *irep, uint8_t *cur, mrb_sym return MRB_DUMP_INVALID_ARGUMENT; } - header = (struct rite_section_debug_header *)bin; + header = (struct rite_section_debug_header*)bin; cur += sizeof(struct rite_section_debug_header); section_size += sizeof(struct rite_section_debug_header); @@ -728,7 +728,7 @@ lv_section_exit: static int write_rite_binary_header(mrb_state *mrb, size_t binary_size, uint8_t *bin, uint8_t flags) { - struct rite_binary_header *header = (struct rite_binary_header *)bin; + struct rite_binary_header *header = (struct rite_binary_header*)bin; memcpy(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident)); memcpy(header->major_version, RITE_BINARY_MAJOR_VER, sizeof(header->major_version)); @@ -767,8 +767,8 @@ lv_defined_p(const mrb_irep *irep) return FALSE; } -static int -dump_irep(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size) +int +mrb_dump_irep(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size) { int result = MRB_DUMP_GENERAL_FAILURE; size_t malloc_size; @@ -855,12 +855,6 @@ error_exit: return result; } -int -mrb_dump_irep(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size) -{ - return dump_irep(mrb, irep, flags, bin, bin_size); -} - #ifndef MRB_NO_STDIO int @@ -874,7 +868,7 @@ mrb_dump_irep_binary(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE* return MRB_DUMP_INVALID_ARGUMENT; } - result = dump_irep(mrb, irep, flags, &bin, &bin_size); + result = mrb_dump_irep(mrb, irep, flags, &bin, &bin_size); if (result == MRB_DUMP_OK) { if (fwrite(bin, sizeof(bin[0]), bin_size, fp) != bin_size) { result = MRB_DUMP_WRITE_FAULT; @@ -895,7 +889,7 @@ mrb_dump_irep_cfunc(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *f if (fp == NULL || initname == NULL || initname[0] == '\0') { return MRB_DUMP_INVALID_ARGUMENT; } - result = dump_irep(mrb, irep, flags, &bin, &bin_size); + result = mrb_dump_irep(mrb, irep, flags, &bin, &bin_size); if (result == MRB_DUMP_OK) { if (fprintf(fp, "#include \n") < 0) { /* for uint8_t under at least Darwin */ mrb_free(mrb, bin); diff --git a/yass/third_party/nghttp2/third-party/mruby/src/enum.c b/yass/third_party/nghttp2/third-party/mruby/src/enum.c index b959567150..08b90d0512 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/enum.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/enum.c @@ -6,6 +6,7 @@ #include #include +#include /* internal method `__update_hash(oldhash, index, itemhash)` */ static mrb_value @@ -25,6 +26,6 @@ void mrb_init_enumerable(mrb_state *mrb) { struct RClass *enumerable; - enumerable = mrb_define_module(mrb, "Enumerable"); /* 15.3.2 */ - mrb_define_module_function(mrb, enumerable, "__update_hash", enum_update_hash, MRB_ARGS_REQ(3)); + enumerable = mrb_define_module_id(mrb, MRB_SYM(Enumerable)); /* 15.3.2 */ + mrb_define_module_function_id(mrb, enumerable, MRB_SYM(__update_hash), enum_update_hash, MRB_ARGS_REQ(3)); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/error.c b/yass/third_party/nghttp2/third-party/mruby/src/error.c index a0e23fad4d..c91725283e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/error.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/error.c @@ -208,7 +208,7 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc) mrb->exc = mrb_obj_ptr(exc); } else { - if (!mrb_obj_is_kind_of(mrb, exc, mrb->eException_class)) { + if (mrb_type(exc) != MRB_TT_EXCEPTION) { mrb_raise(mrb, E_TYPE_ERROR, "exception object expected"); } mrb_exc_set(mrb, exc); @@ -443,69 +443,40 @@ mrb_warn(mrb_state *mrb, const char *fmt, ...) } MRB_API mrb_noreturn void -mrb_bug(mrb_state *mrb, const char *fmt, ...) +mrb_bug(mrb_state *mrb, const char *mesg) { #ifndef MRB_NO_STDIO - va_list ap; - mrb_value str; - - va_start(ap, fmt); - str = mrb_vformat(mrb, fmt, ap); fputs("bug: ", stderr); - fwrite(RSTRING_PTR(str), RSTRING_LEN(str), 1, stderr); - va_end(ap); + fputs(mesg, stderr); + fputs("\n", stderr); #endif exit(EXIT_FAILURE); } -MRB_API mrb_value -mrb_make_exception(mrb_state *mrb, mrb_int argc, const mrb_value *argv) +mrb_value +mrb_make_exception(mrb_state *mrb, mrb_value exc, mrb_value mesg) { - mrb_value mesg; - int n; + mrb_int n = 1; - mesg = mrb_nil_value(); - switch (argc) { - case 0: - break; - case 1: - if (mrb_nil_p(argv[0])) - break; - if (mrb_string_p(argv[0])) { - mesg = mrb_exc_new_str(mrb, E_RUNTIME_ERROR, argv[0]); - break; - } - n = 0; - goto exception_call; - - case 2: - case 3: - n = 1; -exception_call: - { - mrb_sym exc = MRB_SYM(exception); - if (mrb_respond_to(mrb, argv[0], exc)) { - mesg = mrb_funcall_argv(mrb, argv[0], exc, n, argv+1); - } - else { - /* undef */ - mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); - } - } - - break; - default: - mrb_argnum_error(mrb, argc, 0, 3); - break; + if (mrb_nil_p(mesg)) { + n = 0; } - if (argc > 0) { - if (!mrb_obj_is_kind_of(mrb, mesg, mrb->eException_class)) - mrb_raise(mrb, mrb->eException_class, "exception object expected"); - if (argc > 2) - set_backtrace(mrb, mesg, argv[2]); + if (mrb_class_p(exc)) { + exc = mrb_funcall_argv(mrb, exc, MRB_SYM(new), n, &mesg); } - - return mesg; + else if (mrb_exception_p(exc)) { + if (n > 0) { + exc = mrb_obj_clone(mrb, exc); + mrb_exc_mesg_set(mrb, mrb_exc_ptr(exc), mesg); + } + } + else { + mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); + } + if (mrb_type(exc) != MRB_TT_EXCEPTION) { + mrb_raise(mrb, E_EXCEPTION, "exception object expected"); + } + return exc; } MRB_API mrb_noreturn void @@ -542,10 +513,32 @@ mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, char const* fmt, mrb_exc_raise(mrb, exc); } +static mrb_noreturn void +frozen_error(mrb_state *mrb, mrb_value v) +{ + mrb_raisef(mrb, E_FROZEN_ERROR, "can't modify frozen %T", v); +} + MRB_API mrb_noreturn void mrb_frozen_error(mrb_state *mrb, void *frozen_obj) { - mrb_raisef(mrb, E_FROZEN_ERROR, "can't modify frozen %t", mrb_obj_value(frozen_obj)); + frozen_error(mrb, mrb_obj_value(frozen_obj)); +} + +MRB_API void +mrb_check_frozen(mrb_state *mrb, void *o) +{ + if (mrb_frozen_p((struct RBasic*)o)) { + mrb_frozen_error(mrb, o); + } +} + +MRB_API void +mrb_check_frozen_value(mrb_state *mrb, mrb_value v) +{ + if (mrb_immediate_p(v) || mrb_frozen_p(mrb_basic_ptr(v))) { + frozen_error(mrb, v); + } } MRB_API mrb_noreturn void @@ -564,7 +557,7 @@ mrb_argnum_error(mrb_state *mrb, mrb_int argc, int min, int max) void mrb_core_init_printabort(void); int -mrb_core_init_protect(mrb_state *mrb, void (*body)(mrb_state *, void *), void *opaque) +mrb_core_init_protect(mrb_state *mrb, void (*body)(mrb_state*, void*), void *opaque) { struct mrb_jmpbuf *prev_jmp = mrb->jmp; struct mrb_jmpbuf c_jmp; @@ -649,29 +642,47 @@ mrb_print_error(mrb_state *mrb) #endif } +/* clear error status in the mrb_state structure */ +MRB_API void +mrb_clear_error(mrb_state *mrb) +{ + mrb->exc = NULL; +} + +/* returns TRUE if error in the previous call; internally calls mrb_clear_error() */ +MRB_API mrb_bool +mrb_check_error(mrb_state *mrb) +{ + if (mrb->exc) { + mrb_clear_error(mrb); + return TRUE; + } + return FALSE; +} + void mrb_init_exception(mrb_state *mrb) { struct RClass *exception, *script_error, *stack_error, *nomem_error; - mrb->eException_class = exception = mrb_define_class(mrb, "Exception", mrb->object_class); /* 15.2.22 */ + mrb->eException_class = exception = mrb_define_class_id(mrb, MRB_SYM(Exception), mrb->object_class); /* 15.2.22 */ MRB_SET_INSTANCE_TT(exception, MRB_TT_EXCEPTION); - mrb_define_class_method(mrb, exception, "exception", mrb_instance_new, MRB_ARGS_OPT(1)); - mrb_define_method(mrb, exception, "exception", exc_exception, MRB_ARGS_OPT(1)); - mrb_define_method(mrb, exception, "initialize", exc_initialize, MRB_ARGS_OPT(1)); - mrb_define_method(mrb, exception, "to_s", exc_to_s, MRB_ARGS_NONE()); - mrb_define_method(mrb, exception, "inspect", mrb_exc_inspect, MRB_ARGS_NONE()); - mrb_define_method(mrb, exception, "backtrace", mrb_exc_backtrace, MRB_ARGS_NONE()); - mrb_define_method(mrb, exception, "set_backtrace", exc_set_backtrace, MRB_ARGS_REQ(1)); + mrb_define_class_method_id(mrb, exception, MRB_SYM(exception), mrb_instance_new, MRB_ARGS_OPT(1)); + mrb_define_method_id(mrb, exception, MRB_SYM(exception), exc_exception, MRB_ARGS_OPT(1)); + mrb_define_method_id(mrb, exception, MRB_SYM(initialize), exc_initialize, MRB_ARGS_OPT(1)); + mrb_define_method_id(mrb, exception, MRB_SYM(to_s), exc_to_s, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, exception, MRB_SYM(inspect), mrb_exc_inspect, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, exception, MRB_SYM(backtrace), mrb_exc_backtrace, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, exception, MRB_SYM(set_backtrace), exc_set_backtrace, MRB_ARGS_REQ(1)); - mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */ - mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */ - script_error = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */ - mrb_define_class(mrb, "SyntaxError", script_error); /* 15.2.38 */ - stack_error = mrb_define_class(mrb, "SystemStackError", exception); + mrb->eStandardError_class = mrb_define_class_id(mrb, MRB_SYM(StandardError), mrb->eException_class); /* 15.2.23 */ + mrb_define_class_id(mrb, MRB_SYM(RuntimeError), E_STANDARD_ERROR); /* 15.2.28 */ + script_error = mrb_define_class_id(mrb, MRB_SYM(ScriptError), exception); /* 15.2.37 */ + mrb_define_class_id(mrb, MRB_SYM(SyntaxError), script_error); /* 15.2.38 */ + stack_error = mrb_define_class_id(mrb, MRB_SYM(SystemStackError), exception); mrb->stack_err = mrb_obj_ptr(mrb_exc_new_lit(mrb, stack_error, "stack level too deep")); - nomem_error = mrb_define_class(mrb, "NoMemoryError", exception); + nomem_error = mrb_define_class_id(mrb, MRB_SYM(NoMemoryError), exception); mrb->nomem_err = mrb_obj_ptr(mrb_exc_new_lit(mrb, nomem_error, "Out of memory")); #ifdef MRB_GC_FIXED_ARENA mrb->arena_err = mrb_obj_ptr(mrb_exc_new_lit(mrb, nomem_error, "arena overflow error")); diff --git a/yass/third_party/nghttp2/third-party/mruby/src/etc.c b/yass/third_party/nghttp2/third-party/mruby/src/etc.c index 8341922386..0c26624563 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/etc.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/etc.c @@ -71,7 +71,7 @@ mrb_obj_to_sym(mrb_state *mrb, mrb_value name) return 0; /* not reached */ } -#ifndef MRB_NO_FLOAT +#if !defined(MRB_NO_FLOAT) && !defined(MRB_NAN_BOXING) static mrb_int mrb_float_id(mrb_float f) { diff --git a/yass/third_party/nghttp2/third-party/mruby/src/fmt_fp.c b/yass/third_party/nghttp2/third-party/mruby/src/fmt_fp.c index 7c5b01a992..ae8020755b 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/fmt_fp.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/fmt_fp.c @@ -100,7 +100,8 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch if (signbit(f)) { *s++ = '-'; f = -f; - } else if (sign) { + } + else if (sign) { *s++ = sign; } buf_remaining -= (int)(s - buf); // Adjust for sign @@ -112,7 +113,8 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch *s++ = 'N' ^ uc; *s++ = 'F' ^ uc; goto ret; - } else if (isnan(f)) { + } + else if (isnan(f)) { *s++ = 'N' ^ uc; *s++ = 'A' ^ uc; *s++ = 'N' ^ uc; @@ -142,10 +144,12 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch e = 0; if (fmt == 'e') { e_sign = '+'; - } else if (fmt == 'f') { + } + else if (fmt == 'f') { num_digits = prec + 1; } - } else if (f < 1.0) { // f < 1.0 + } + else if (f < 1.0) { // f < 1.0 char first_dig = '0'; if (f >= FLT_ROUND_TO_ONE) { first_dig = '1'; @@ -165,7 +169,8 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch if (e == 0) { e_sign_char = '+'; } - } else { + } + else { e++; f *= 10.0; } @@ -194,7 +199,8 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch num_digits--; } } - } else { + } + else { // For e & g formats, we'll be printing the exponent, so set the // sign. e_sign = e_sign_char; @@ -207,7 +213,8 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch } } } - } else { + } + else { // Build positive exponent for (e = 0, e1 = FLT_DECEXP; e1; e1 >>= 1, pos_pow++, neg_pow++) { if (*pos_pow <= f) { @@ -223,7 +230,8 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch if (fmt == 'f') { if (e >= buf_remaining) { fmt = 'e'; - } else if ((e + prec + 2) > buf_remaining) { + } + else if ((e + prec + 2) > buf_remaining) { prec = buf_remaining - e - 2; if (prec < 0) { // This means no decimal point, so we can add one back @@ -245,7 +253,8 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch if (fmt == 'f') { dec = e; num_digits = prec + e + 1; - } else { + } + else { e_sign = '+'; } } @@ -267,10 +276,9 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch if (fmt == 'e') { num_digits = prec + 1; - } else if (fmt == 'g') { - if (prec == 0) { - prec = 1; - } + if (prec == 0) prec = 1; + } + else if (fmt == 'g') { num_digits = prec; } @@ -311,14 +319,15 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch } if (*rs == '0') { // We need to insert a 1 - if (rs[1] == '.' && fmt != 'f') { + if (fmt != 'f' && rs[1] == '.') { // We're going to round 9.99 to 10.00 // Move the decimal point rs[0] = '.'; rs[1] = '0'; if (e_sign == '-') { e--; - } else { + } + else { e++; } } @@ -356,8 +365,8 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch *s++ = '0' + (e / 10); *s++ = '0' + (e % 10); } - *s = '\0'; + *s = '\0'; return (int)(s - buf); } #endif diff --git a/yass/third_party/nghttp2/third-party/mruby/src/gc.c b/yass/third_party/nghttp2/third-party/mruby/src/gc.c index f1b50ad786..39f63c62b4 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/gc.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/gc.c @@ -138,49 +138,6 @@ typedef struct { } as; } RVALUE; -#ifdef GC_PROFILE -#include -#include - -static double program_invoke_time = 0; -static double gc_time = 0; -static double gc_total_time = 0; - -static double -gettimeofday_time(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return tv.tv_sec + tv.tv_usec * 1e-6; -} - -#define GC_INVOKE_TIME_REPORT(with) do {\ - fprintf(stderr, "%s\n", with);\ - fprintf(stderr, "gc_invoke: %19.3f\n", gettimeofday_time() - program_invoke_time);\ - fprintf(stderr, "is_generational: %d\n", is_generational(gc));\ - fprintf(stderr, "is_major_gc: %d\n", is_major_gc(gc));\ -} while(0) - -#define GC_TIME_START do {\ - gc_time = gettimeofday_time();\ -} while(0) - -#define GC_TIME_STOP_AND_REPORT do {\ - gc_time = gettimeofday_time() - gc_time;\ - gc_total_time += gc_time;\ - fprintf(stderr, "gc_state: %d\n", gc->state);\ - fprintf(stderr, "live: %zu\n", gc->live);\ - fprintf(stderr, "majorgc_old_threshold: %zu\n", gc->majorgc_old_threshold);\ - fprintf(stderr, "gc_threshold: %zu\n", gc->threshold);\ - fprintf(stderr, "gc_time: %30.20f\n", gc_time);\ - fprintf(stderr, "gc_total_time: %30.20f\n\n", gc_total_time);\ -} while(0) -#else -#define GC_INVOKE_TIME_REPORT(s) -#define GC_TIME_START -#define GC_TIME_STOP_AND_REPORT -#endif - #ifdef GC_DEBUG #define DEBUG(x) (x) #else @@ -191,13 +148,22 @@ gettimeofday_time(void) #define MRB_HEAP_PAGE_SIZE 1024 #endif +typedef struct mrb_heap_page { + struct RBasic *freelist; + struct mrb_heap_page *next; + struct mrb_heap_page *free_next; + mrb_bool old:1; + /* Flexible array members are not C++ compatible */ + /* void* objects[]; */ +} mrb_heap_page; + #define GC_STEP_SIZE 1024 /* white: 001 or 010, black: 100, gray: 000, red:111 */ #define GC_GRAY 0 #define GC_WHITE_A 1 -#define GC_WHITE_B (1 << 1) -#define GC_BLACK (1 << 2) +#define GC_WHITE_B 2 +#define GC_BLACK 4 #define GC_RED MRB_GC_RED #define GC_WHITES (GC_WHITE_A | GC_WHITE_B) #define GC_COLOR_MASK 7 @@ -218,8 +184,8 @@ mrb_static_assert(MRB_GC_RED <= GC_COLOR_MASK); /* We have removed `objects[]` from `mrb_heap_page` since it was not C++ * compatible. Using array index to get pointer after structure instead. */ -/* #define objects(p) ((RVALUE *)p->objects) */ -#define objects(p) ((RVALUE *)&p[1]) +/* #define objects(p) ((RVALUE*)p->objects) */ +#define objects(p) ((RVALUE*)&p[1]) mrb_noreturn void mrb_raise_nomemory(mrb_state *mrb); @@ -330,55 +296,10 @@ mrb_object_dead_p(mrb_state *mrb, struct RBasic *object) return is_dead(gc, object); } -static void -link_heap_page(mrb_gc *gc, mrb_heap_page *page) -{ - page->next = gc->heaps; - if (gc->heaps) - gc->heaps->prev = page; - gc->heaps = page; -} - -static void -unlink_heap_page(mrb_gc *gc, mrb_heap_page *page) -{ - if (page->prev) - page->prev->next = page->next; - if (page->next) - page->next->prev = page->prev; - if (gc->heaps == page) - gc->heaps = page->next; - page->prev = NULL; - page->next = NULL; -} - -static void -link_free_heap_page(mrb_gc *gc, mrb_heap_page *page) -{ - page->free_next = gc->free_heaps; - if (gc->free_heaps) { - gc->free_heaps->free_prev = page; - } - gc->free_heaps = page; -} - -static void -unlink_free_heap_page(mrb_gc *gc, mrb_heap_page *page) -{ - if (page->free_prev) - page->free_prev->free_next = page->free_next; - if (page->free_next) - page->free_next->free_prev = page->free_prev; - if (gc->free_heaps == page) - gc->free_heaps = page->free_next; - page->free_prev = NULL; - page->free_next = NULL; -} - static void add_heap(mrb_state *mrb, mrb_gc *gc) { - mrb_heap_page *page = (mrb_heap_page *)mrb_calloc(mrb, 1, sizeof(mrb_heap_page) + MRB_HEAP_PAGE_SIZE * sizeof(RVALUE)); + mrb_heap_page *page = (mrb_heap_page*)mrb_calloc(mrb, 1, sizeof(mrb_heap_page) + MRB_HEAP_PAGE_SIZE * sizeof(RVALUE)); RVALUE *p, *e; struct RBasic *prev = NULL; @@ -389,8 +310,11 @@ add_heap(mrb_state *mrb, mrb_gc *gc) } page->freelist = prev; - link_heap_page(gc, page); - link_free_heap_page(gc, page); + page->next = gc->heaps; + gc->heaps = page; + + page->free_next = gc->free_heaps; + gc->free_heaps = page; } #define DEFAULT_GC_INTERVAL_RATIO 200 @@ -419,10 +343,6 @@ mrb_gc_init(mrb_state *mrb, mrb_gc *gc) gc->generational = TRUE; gc->full = TRUE; #endif - -#ifdef GC_PROFILE - program_invoke_time = gettimeofday_time(); -#endif } static void obj_free(mrb_state *mrb, struct RBasic *obj, int end); @@ -497,15 +417,13 @@ mrb_gc_protect(mrb_state *mrb, mrb_value obj) MRB_API void mrb_gc_register(mrb_state *mrb, mrb_value obj) { - mrb_sym root; mrb_value table; if (mrb_immediate_p(obj)) return; - root = GC_ROOT_SYM; - table = mrb_gv_get(mrb, root); + table = mrb_gv_get(mrb, GC_ROOT_SYM); if (mrb_nil_p(table) || !mrb_array_p(table)) { table = mrb_ary_new(mrb); - mrb_gv_set(mrb, root, table); + mrb_gv_set(mrb, GC_ROOT_SYM, table); } mrb_ary_push(mrb, table, obj); } @@ -514,22 +432,19 @@ mrb_gc_register(mrb_state *mrb, mrb_value obj) MRB_API void mrb_gc_unregister(mrb_state *mrb, mrb_value obj) { - mrb_sym root; mrb_value table; struct RArray *a; - mrb_int i; if (mrb_immediate_p(obj)) return; - root = GC_ROOT_SYM; - table = mrb_gv_get(mrb, root); + table = mrb_gv_get(mrb, GC_ROOT_SYM); if (mrb_nil_p(table)) return; if (!mrb_array_p(table)) { - mrb_gv_set(mrb, root, mrb_nil_value()); + mrb_gv_set(mrb, GC_ROOT_SYM, mrb_nil_value()); return; } a = mrb_ary_ptr(table); mrb_ary_modify(mrb, a); - for (i = 0; i < ARY_LEN(a); i++) { + for (mrb_int i = 0; i < ARY_LEN(a); i++) { if (mrb_ptr(ARY_PTR(a)[i]) == mrb_ptr(obj)) { mrb_int len = ARY_LEN(a)-1; mrb_value *ptr = ARY_PTR(a); @@ -544,7 +459,6 @@ mrb_gc_unregister(mrb_state *mrb, mrb_value obj) MRB_API struct RBasic* mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls) { - struct RBasic *p; static const RVALUE RVALUE_zero = { { { NULL, NULL, MRB_TT_FALSE } } }; mrb_gc *gc = &mrb->gc; @@ -584,15 +498,15 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls) add_heap(mrb, gc); } - p = gc->free_heaps->freelist; + struct RBasic *p = gc->free_heaps->freelist; gc->free_heaps->freelist = ((struct free_obj*)p)->next; if (gc->free_heaps->freelist == NULL) { - unlink_free_heap_page(gc, gc->free_heaps); + gc->free_heaps = gc->free_heaps->free_next; } gc->live++; gc_protect(mrb, gc, p); - *(RVALUE *)p = RVALUE_zero; + *(RVALUE*)p = RVALUE_zero; p->tt = ttype; p->c = cls; paint_partial_white(gc, p); @@ -615,8 +529,7 @@ add_gray_list(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj) static void mark_context_stack(mrb_state *mrb, struct mrb_context *c) { - size_t i; - size_t e; + size_t i, e; mrb_value nil; if (c->stbase == NULL) return; @@ -712,13 +625,12 @@ gc_mark_children(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj) case MRB_TT_ENV: { struct REnv *e = (struct REnv*)obj; - mrb_int i, len; if (MRB_ENV_ONSTACK_P(e) && e->cxt && e->cxt->fib) { mrb_gc_mark(mrb, (struct RBasic*)e->cxt->fib); } - len = MRB_ENV_LEN(e); - for (i=0; istack[i]); } } @@ -736,10 +648,10 @@ gc_mark_children(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj) case MRB_TT_ARRAY: { struct RArray *a = (struct RArray*)obj; - size_t i, e=ARY_LEN(a); + size_t e=ARY_LEN(a); mrb_value *p = ARY_PTR(a); - for (i=0; icxt; - if (c && c != mrb->root_c) { - if (!end && c->status != MRB_FIBER_TERMINATED) { - mrb_callinfo *ci = c->ci; - mrb_callinfo *ce = c->cibase; - - while (ce <= ci) { - struct REnv *e = ci->u.env; - if (e && !mrb_object_dead_p(mrb, (struct RBasic*)e) && - e->tt == MRB_TT_ENV && MRB_ENV_ONSTACK_P(e)) { - mrb_env_unshare(mrb, e, TRUE); - } - ci--; - } - } + if (c != mrb->root_c) { mrb_free_context(mrb, c); } } @@ -877,7 +775,7 @@ obj_free(mrb_state *mrb, struct RBasic *obj, int end) { struct RProc *p = (struct RProc*)obj; - if (!MRB_PROC_CFUNC_P(p) && p->body.irep) { + if (!MRB_PROC_CFUNC_P(p) && !MRB_PROC_ALIAS_P(p) && p->body.irep) { mrb_irep *irep = (mrb_irep*)p->body.irep; if (end) { mrb_irep_cutref(mrb, irep); @@ -1082,6 +980,7 @@ gc_mark_gray_list(mrb_state *mrb, mrb_gc *gc) { while (gc->gray_list) { struct RBasic *obj = gc->gray_list; gc->gray_list = obj->gcnext; + obj->gcnext = NULL; gc_mark_children(mrb, gc, obj); } } @@ -1094,6 +993,7 @@ incremental_marking_phase(mrb_state *mrb, mrb_gc *gc, size_t limit) while (gc->gray_list && tried_marks < limit) { struct RBasic *obj = gc->gray_list; gc->gray_list = obj->gcnext; + obj->gcnext = NULL; gc_mark_children(mrb, gc, obj); tried_marks += gc_gray_counts(mrb, gc, obj); } @@ -1152,14 +1052,15 @@ prepare_incremental_sweep(mrb_state *mrb, mrb_gc *gc) // mrb_assert(gc->atomic_gray_list == NULL); // mrb_assert(gc->gray_list == NULL); gc->state = MRB_GC_STATE_SWEEP; - gc->sweeps = gc->heaps; + gc->sweeps = NULL; gc->live_after_mark = gc->live; } static size_t incremental_sweep_phase(mrb_state *mrb, mrb_gc *gc, size_t limit) { - mrb_heap_page *page = gc->sweeps; + mrb_heap_page *prev = gc->sweeps; + mrb_heap_page *page = prev ? prev->next : gc->heaps; size_t tried_sweep = 0; while (page && (tried_sweep < limit)) { @@ -1167,7 +1068,6 @@ incremental_sweep_phase(mrb_state *mrb, mrb_gc *gc, size_t limit) RVALUE *e = p + MRB_HEAP_PAGE_SIZE; size_t freed = 0; mrb_bool dead_slot = TRUE; - mrb_bool full = (page->freelist == NULL); if (is_minor_gc(gc) && page->old) { /* skip a slot which doesn't contain any young object */ @@ -1197,29 +1097,39 @@ incremental_sweep_phase(mrb_state *mrb, mrb_gc *gc, size_t limit) } /* free dead slot */ - if (dead_slot && freed < MRB_HEAP_PAGE_SIZE) { + if (dead_slot) { mrb_heap_page *next = page->next; - unlink_heap_page(gc, page); - unlink_free_heap_page(gc, page); + if (prev) prev->next = next; + if (gc->heaps == page) + gc->heaps = page->next; + mrb_free(mrb, page); page = next; } else { - if (full && freed > 0) { - link_free_heap_page(gc, page); - } if (page->freelist == NULL && is_minor_gc(gc)) page->old = TRUE; else page->old = FALSE; + prev = page; page = page->next; } tried_sweep += MRB_HEAP_PAGE_SIZE; gc->live -= freed; gc->live_after_mark -= freed; } - gc->sweeps = page; + gc->sweeps = prev; + + /* rebuild free_heaps link */ + gc->free_heaps = NULL; + for (mrb_heap_page *p = gc->heaps; p; p=p->next) { + if (p->freelist) { + p->free_next = gc->free_heaps; + gc->free_heaps = p; + } + } + return tried_sweep; } @@ -1280,22 +1190,17 @@ incremental_gc_step(mrb_state *mrb, mrb_gc *gc) static void clear_all_old(mrb_state *mrb, mrb_gc *gc) { - mrb_bool origin_mode = gc->generational; - mrb_assert(is_generational(gc)); - if (is_major_gc(gc)) { + if (gc->full) { /* finish the half baked GC */ incremental_gc_finish(mrb, gc); } - else { - /* Sweep the dead objects, then reset all the live objects - * (including all the old objects, of course) to white. */ - gc->generational = FALSE; - prepare_incremental_sweep(mrb, gc); - incremental_gc_finish(mrb, gc); - } - gc->generational = origin_mode; - + /* Sweep the dead objects, then reset all the live objects + * (including all the old objects, of course) to white. */ + gc->generational = FALSE; + prepare_incremental_sweep(mrb, gc); + incremental_gc_finish(mrb, gc); + gc->generational = TRUE; /* The gray objects have already been painted as white */ gc->atomic_gray_list = gc->gray_list = NULL; } @@ -1307,9 +1212,6 @@ mrb_incremental_gc(mrb_state *mrb) if (gc->disabled || gc->iterating) return; - GC_INVOKE_TIME_REPORT("mrb_incremental_gc()"); - GC_TIME_START; - if (is_minor_gc(gc)) { incremental_gc_finish(mrb, gc); } @@ -1329,7 +1231,7 @@ mrb_incremental_gc(mrb_state *mrb) gc->full = FALSE; if (threshold < MAJOR_GC_TOOMANY) { - gc->majorgc_old_threshold = threshold; + gc->oldgen_threshold = threshold; } else { /* too many objects allocated during incremental GC, */ @@ -1337,15 +1239,11 @@ mrb_incremental_gc(mrb_state *mrb) mrb_full_gc(mrb); } } - else if (is_minor_gc(gc)) { - if (gc->live > gc->majorgc_old_threshold) { - clear_all_old(mrb, gc); - gc->full = TRUE; - } + else if (is_minor_gc(gc) && gc->live > gc->oldgen_threshold) { + clear_all_old(mrb, gc); + gc->full = TRUE; } } - - GC_TIME_STOP_AND_REPORT; } /* Perform a full gc cycle */ @@ -1357,9 +1255,6 @@ mrb_full_gc(mrb_state *mrb) if (!mrb->c) return; if (gc->disabled || gc->iterating) return; - GC_INVOKE_TIME_REPORT("mrb_full_gc()"); - GC_TIME_START; - if (is_generational(gc)) { /* clear all the old objects back to young */ clear_all_old(mrb, gc); @@ -1374,14 +1269,13 @@ mrb_full_gc(mrb_state *mrb) gc->threshold = (gc->live_after_mark/100) * gc->interval_ratio; if (is_generational(gc)) { - gc->majorgc_old_threshold = gc->live_after_mark/100 * MAJOR_GC_INC_RATIO; + gc->oldgen_threshold = gc->live_after_mark/100 * MAJOR_GC_INC_RATIO; gc->full = FALSE; } #ifdef MRB_USE_MALLOC_TRIM malloc_trim(0); #endif - GC_TIME_STOP_AND_REPORT; } MRB_API void @@ -1580,7 +1474,7 @@ change_gen_gc_mode(mrb_state *mrb, mrb_gc *gc, mrb_bool enable) } else if (!is_generational(gc) && enable) { incremental_gc_finish(mrb, gc); - gc->majorgc_old_threshold = gc->live_after_mark/100 * MAJOR_GC_INC_RATIO; + gc->oldgen_threshold = gc->live_after_mark/100 * MAJOR_GC_INC_RATIO; gc->full = FALSE; } gc->generational = enable; @@ -1629,10 +1523,9 @@ gc_each_objects(mrb_state *mrb, mrb_gc *gc, mrb_each_object_callback *callback, page = gc->heaps; while (page != NULL) { RVALUE *p; - int i; p = objects(page); - for (i=0; i < MRB_HEAP_PAGE_SIZE; i++) { + for (int i=0; i < MRB_HEAP_PAGE_SIZE; i++) { if ((*callback)(mrb, &p[i].as.basic, data) == MRB_EACH_OBJ_BREAK) return; } @@ -1659,7 +1552,7 @@ mrb_objspace_each_objects(mrb_state *mrb, mrb_each_object_callback *callback, vo gc_each_objects(mrb, &mrb->gc, callback, data); mrb->jmp = prev_jmp; mrb->gc.iterating = iterating; - } MRB_CATCH(&c_jmp) { + } MRB_CATCH(&c_jmp) { mrb->gc.iterating = iterating; mrb->jmp = prev_jmp; MRB_THROW(prev_jmp); @@ -1681,15 +1574,15 @@ mrb_init_gc(mrb_state *mrb) mrb_static_assert_object_size(RVALUE); - gc = mrb_define_module(mrb, "GC"); + gc = mrb_define_module_id(mrb, MRB_SYM(GC)); - mrb_define_class_method(mrb, gc, "start", gc_start, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, gc, "enable", gc_enable, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, gc, "disable", gc_disable, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, gc, "interval_ratio", gc_interval_ratio_get, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, gc, "interval_ratio=", gc_interval_ratio_set, MRB_ARGS_REQ(1)); - mrb_define_class_method(mrb, gc, "step_ratio", gc_step_ratio_get, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, gc, "step_ratio=", gc_step_ratio_set, MRB_ARGS_REQ(1)); - mrb_define_class_method(mrb, gc, "generational_mode=", gc_generational_mode_set, MRB_ARGS_REQ(1)); - mrb_define_class_method(mrb, gc, "generational_mode", gc_generational_mode_get, MRB_ARGS_NONE()); + mrb_define_class_method_id(mrb, gc, MRB_SYM(start), gc_start, MRB_ARGS_NONE()); + mrb_define_class_method_id(mrb, gc, MRB_SYM(enable), gc_enable, MRB_ARGS_NONE()); + mrb_define_class_method_id(mrb, gc, MRB_SYM(disable), gc_disable, MRB_ARGS_NONE()); + mrb_define_class_method_id(mrb, gc, MRB_SYM(interval_ratio), gc_interval_ratio_get, MRB_ARGS_NONE()); + mrb_define_class_method_id(mrb, gc, MRB_SYM_E(interval_ratio), gc_interval_ratio_set, MRB_ARGS_REQ(1)); + mrb_define_class_method_id(mrb, gc, MRB_SYM(step_ratio), gc_step_ratio_get, MRB_ARGS_NONE()); + mrb_define_class_method_id(mrb, gc, MRB_SYM_E(step_ratio), gc_step_ratio_set, MRB_ARGS_REQ(1)); + mrb_define_class_method_id(mrb, gc, MRB_SYM_E(generational_mode), gc_generational_mode_set, MRB_ARGS_REQ(1)); + mrb_define_class_method_id(mrb, gc, MRB_SYM(generational_mode), gc_generational_mode_get, MRB_ARGS_NONE()); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/hash.c b/yass/third_party/nghttp2/third-party/mruby/src/hash.c index 40cfacf679..1aa12f6e81 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/hash.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/hash.c @@ -273,7 +273,7 @@ HT_ASSERT_SAFE_READ(ea_capa); } \ code; \ if (flags__ != (h__->flags & mask__) || \ - tbl__ != h__->hsh.ht || \ + tbl__ != h__->hsh.ht || \ ((H_CHECK_MODIFIED_USE_HT_EA_CAPA_FOR_AR || h_ht_p(h__)) && \ ht_ea_capa__ != ht_ea_capa(h__)) || \ ((H_CHECK_MODIFIED_USE_HT_EA_FOR_AR || h_ht_p(h__)) && \ @@ -382,7 +382,7 @@ obj_eql(mrb_state *mrb, mrb_value a, mrb_value b, struct RHash *h) } } -static mrb_bool +static inline mrb_bool entry_deleted_p(const hash_entry* entry) { return mrb_undef_p(entry->key); @@ -1109,7 +1109,11 @@ MRB_API void mrb_hash_foreach(mrb_state *mrb, struct RHash *h, mrb_hash_foreach_func *func, void *data) { h_each(h, entry, { - if (func(mrb, entry->key, entry->val, data) != 0) return; + int n; + h_check_modified(mrb, h, { + n = func(mrb, entry->key, entry->val, data); + }); + if (n != 0) return; }); } @@ -1560,10 +1564,16 @@ mrb_hash_clear(mrb_state *mrb, mrb_value hash) static mrb_value mrb_hash_aset(mrb_state *mrb, mrb_value self) { - mrb_value key, val; + mrb_int argc = mrb_get_argc(mrb); - mrb_get_args(mrb, "oo", &key, &val); - mrb_hash_set(mrb, self, key, val); + if (argc != 2) { + mrb_argnum_error(mrb, argc, 2, 2); + } + + const mrb_value *argv = mrb_get_argv(mrb); + mrb_value val = argv[1]; + + mrb_hash_set(mrb, self, argv[0], argv[1]); return val; } @@ -1742,8 +1752,8 @@ mrb_hash_merge(mrb_state *mrb, mrb_value hash1, mrb_value hash2) if (h_size(h2) == 0) return; h_each(h2, entry, { h_check_modified(mrb, h2, {h_set(mrb, h1, entry->key, entry->val);}); - mrb_field_write_barrier_value(mrb, (struct RBasic *)h1, entry->key); - mrb_field_write_barrier_value(mrb, (struct RBasic *)h1, entry->val); + mrb_field_write_barrier_value(mrb, (struct RBasic*)h1, entry->key); + mrb_field_write_barrier_value(mrb, (struct RBasic*)h1, entry->val); }); } @@ -1787,38 +1797,104 @@ mrb_hash_rehash(mrb_state *mrb, mrb_value self) return self; } +static mrb_value +mrb_hash_compact(mrb_state *mrb, mrb_value hash) +{ + struct RHash *h = mrb_hash_ptr(hash); + mrb_bool ht_p = h_ht_p(h); + uint32_t size = ht_p ? ht_size(h) : ar_size(h); + uint32_t dec = 0; + + mrb_check_frozen(mrb, h); + h_each(h, entry, { + if (mrb_nil_p(entry->val)) { + entry_delete(entry); + dec++; + } + }); + if (dec == 0) return mrb_nil_value(); + size -= dec; + if (ht_p) { + ht_set_size(h, size); + } + else { + ar_set_size(h, size); + } + return hash; +} + +/* + * call-seq: + * hash.to_s -> string + * hash.inspect -> string + * + * Return the contents of this hash as a string. + */ +static mrb_value +mrb_hash_to_s(mrb_state *mrb, mrb_value self) +{ + mrb->c->ci->mid = MRB_SYM(inspect); + mrb_value ret = mrb_str_new_lit(mrb, "{"); + int ai = mrb_gc_arena_save(mrb); + if (mrb_inspect_recursive_p(mrb, self)) { + mrb_str_cat_lit(mrb, ret, "...}"); + return ret; + } + + mrb_int i = 0; + struct RHash *h = mrb_hash_ptr(self); + h_each(h, entry, { + if (i++ > 0) mrb_str_cat_lit(mrb, ret, ", "); + h_check_modified(mrb, h, { + mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->key)); + }); + mrb_gc_arena_restore(mrb, ai); + mrb_str_cat_lit(mrb, ret, "=>"); + h_check_modified(mrb, h, { + mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->val)); + }); + mrb_gc_arena_restore(mrb, ai); + }); + mrb_str_cat_lit(mrb, ret, "}"); + + return ret; +} + void mrb_init_hash(mrb_state *mrb) { struct RClass *h; - mrb->hash_class = h = mrb_define_class(mrb, "Hash", mrb->object_class); /* 15.2.13 */ + mrb->hash_class = h = mrb_define_class_id(mrb, MRB_SYM(Hash), mrb->object_class); /* 15.2.13 */ MRB_SET_INSTANCE_TT(h, MRB_TT_HASH); - mrb_define_method(mrb, h, "[]", mrb_hash_aget, MRB_ARGS_REQ(1)); /* 15.2.13.4.2 */ - mrb_define_method(mrb, h, "[]=", mrb_hash_aset, MRB_ARGS_REQ(2)); /* 15.2.13.4.3 */ - mrb_define_method(mrb, h, "clear", mrb_hash_clear, MRB_ARGS_NONE()); /* 15.2.13.4.4 */ - mrb_define_method(mrb, h, "default", mrb_hash_default, MRB_ARGS_OPT(1)); /* 15.2.13.4.5 */ - mrb_define_method(mrb, h, "default=", mrb_hash_set_default, MRB_ARGS_REQ(1)); /* 15.2.13.4.6 */ - mrb_define_method(mrb, h, "default_proc", mrb_hash_default_proc,MRB_ARGS_NONE()); /* 15.2.13.4.7 */ - mrb_define_method(mrb, h, "default_proc=", mrb_hash_set_default_proc,MRB_ARGS_REQ(1)); /* 15.2.13.4.7 */ - mrb_define_method(mrb, h, "__delete", mrb_hash_delete, MRB_ARGS_REQ(1)); /* core of 15.2.13.4.8 */ - mrb_define_method(mrb, h, "empty?", mrb_hash_empty_m, MRB_ARGS_NONE()); /* 15.2.13.4.12 */ - mrb_define_method(mrb, h, "has_key?", mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.13 */ - mrb_define_method(mrb, h, "has_value?", mrb_hash_has_value, MRB_ARGS_REQ(1)); /* 15.2.13.4.14 */ - mrb_define_method(mrb, h, "include?", mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.15 */ - mrb_define_method(mrb, h, "initialize", mrb_hash_init, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK()); /* 15.2.13.4.16 */ - mrb_define_method(mrb, h, "initialize_copy", mrb_hash_init_copy, MRB_ARGS_REQ(1)); /* 15.2.13.4.17 */ - mrb_define_method(mrb, h, "key?", mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.18 */ - mrb_define_method(mrb, h, "keys", mrb_hash_keys, MRB_ARGS_NONE()); /* 15.2.13.4.19 */ - mrb_define_method(mrb, h, "length", mrb_hash_size_m, MRB_ARGS_NONE()); /* 15.2.13.4.20 */ - mrb_define_method(mrb, h, "member?", mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.21 */ - mrb_define_method(mrb, h, "replace", mrb_hash_init_copy, MRB_ARGS_REQ(1)); /* 15.2.13.4.23 */ - mrb_define_method(mrb, h, "shift", mrb_hash_shift, MRB_ARGS_NONE()); /* 15.2.13.4.24 */ - mrb_define_method(mrb, h, "size", mrb_hash_size_m, MRB_ARGS_NONE()); /* 15.2.13.4.25 */ - mrb_define_method(mrb, h, "store", mrb_hash_aset, MRB_ARGS_REQ(2)); /* 15.2.13.4.26 */ - mrb_define_method(mrb, h, "value?", mrb_hash_has_value, MRB_ARGS_REQ(1)); /* 15.2.13.4.27 */ - mrb_define_method(mrb, h, "values", mrb_hash_values, MRB_ARGS_NONE()); /* 15.2.13.4.28 */ - mrb_define_method(mrb, h, "rehash", mrb_hash_rehash, MRB_ARGS_NONE()); - mrb_define_method(mrb, h, "__merge", mrb_hash_merge_m, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, h, MRB_OPSYM(aref), mrb_hash_aget, MRB_ARGS_REQ(1)); /* 15.2.13.4.2 */ + mrb_define_method_id(mrb, h, MRB_OPSYM(aset), mrb_hash_aset, MRB_ARGS_REQ(2)); /* 15.2.13.4.3 */ + mrb_define_method_id(mrb, h, MRB_SYM(clear), mrb_hash_clear, MRB_ARGS_NONE()); /* 15.2.13.4.4 */ + mrb_define_method_id(mrb, h, MRB_SYM(default), mrb_hash_default, MRB_ARGS_OPT(1)); /* 15.2.13.4.5 */ + mrb_define_method_id(mrb, h, MRB_SYM_E(default), mrb_hash_set_default, MRB_ARGS_REQ(1)); /* 15.2.13.4.6 */ + mrb_define_method_id(mrb, h, MRB_SYM(default_proc), mrb_hash_default_proc,MRB_ARGS_NONE()); /* 15.2.13.4.7 */ + mrb_define_method_id(mrb, h, MRB_SYM_E(default_proc), mrb_hash_set_default_proc,MRB_ARGS_REQ(1)); /* 15.2.13.4.7 */ + mrb_define_method_id(mrb, h, MRB_SYM(__delete), mrb_hash_delete, MRB_ARGS_REQ(1)); /* core of 15.2.13.4.8 */ + mrb_define_method_id(mrb, h, MRB_SYM_Q(empty), mrb_hash_empty_m, MRB_ARGS_NONE()); /* 15.2.13.4.12 */ + mrb_define_method_id(mrb, h, MRB_SYM_Q(has_key), mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.13 */ + mrb_define_method_id(mrb, h, MRB_SYM_Q(has_value), mrb_hash_has_value, MRB_ARGS_REQ(1)); /* 15.2.13.4.14 */ + mrb_define_method_id(mrb, h, MRB_SYM_Q(include), mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.15 */ + mrb_define_method_id(mrb, h, MRB_SYM(initialize), mrb_hash_init, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK()); /* 15.2.13.4.16 */ + mrb_define_method_id(mrb, h, MRB_SYM(initialize_copy), mrb_hash_init_copy, MRB_ARGS_REQ(1)); /* 15.2.13.4.17 */ + mrb_define_method_id(mrb, h, MRB_SYM_Q(key), mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.18 */ + mrb_define_method_id(mrb, h, MRB_SYM(keys), mrb_hash_keys, MRB_ARGS_NONE()); /* 15.2.13.4.19 */ + mrb_define_method_id(mrb, h, MRB_SYM(length), mrb_hash_size_m, MRB_ARGS_NONE()); /* 15.2.13.4.20 */ + mrb_define_method_id(mrb, h, MRB_SYM_Q(member), mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.21 */ + mrb_define_method_id(mrb, h, MRB_SYM(replace), mrb_hash_init_copy, MRB_ARGS_REQ(1)); /* 15.2.13.4.23 */ + mrb_define_method_id(mrb, h, MRB_SYM(shift), mrb_hash_shift, MRB_ARGS_NONE()); /* 15.2.13.4.24 */ + mrb_define_method_id(mrb, h, MRB_SYM(size), mrb_hash_size_m, MRB_ARGS_NONE()); /* 15.2.13.4.25 */ + mrb_define_method_id(mrb, h, MRB_SYM(store), mrb_hash_aset, MRB_ARGS_REQ(2)); /* 15.2.13.4.26 */ + mrb_define_method_id(mrb, h, MRB_SYM_Q(value), mrb_hash_has_value, MRB_ARGS_REQ(1)); /* 15.2.13.4.27 */ + mrb_define_method_id(mrb, h, MRB_SYM(values), mrb_hash_values, MRB_ARGS_NONE()); /* 15.2.13.4.28 */ + mrb_define_method_id(mrb, h, MRB_SYM(to_s), mrb_hash_to_s, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, h, MRB_SYM(inspect), mrb_hash_to_s, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, h, MRB_SYM(rehash), mrb_hash_rehash, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, h, MRB_SYM(__merge), mrb_hash_merge_m, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, h, MRB_SYM(__compact), mrb_hash_compact, MRB_ARGS_NONE()); /* implementation of Hash#compact! */ } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/init.c b/yass/third_party/nghttp2/third-party/mruby/src/init.c index afd69975af..0e9875d643 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/init.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/init.c @@ -10,7 +10,6 @@ void mrb_init_symtbl(mrb_state*); void mrb_init_class(mrb_state*); void mrb_init_object(mrb_state*); void mrb_init_kernel(mrb_state*); -void mrb_init_comparable(mrb_state*); void mrb_init_enumerable(mrb_state*); void mrb_init_symbol(mrb_state*); void mrb_init_string(mrb_state*); @@ -34,7 +33,6 @@ mrb_init_core(mrb_state *mrb) mrb_init_class(mrb); DONE; mrb_init_object(mrb); DONE; mrb_init_kernel(mrb); DONE; - mrb_init_comparable(mrb); DONE; mrb_init_enumerable(mrb); DONE; mrb_init_symbol(mrb); DONE; diff --git a/yass/third_party/nghttp2/third-party/mruby/src/kernel.c b/yass/third_party/nghttp2/third-party/mruby/src/kernel.c index 250f01d2ce..bc161b594e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/kernel.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/kernel.c @@ -71,7 +71,7 @@ mrb_obj_inspect(mrb_state *mrb, mrb_value obj) * to provide meaningful semantics in case statements. */ static mrb_value -mrb_equal_m(mrb_state *mrb, mrb_value self) +mrb_eqq_m(mrb_state *mrb, mrb_value self) { mrb_value arg = mrb_get_arg1(mrb); @@ -83,11 +83,45 @@ mrb_cmp_m(mrb_state *mrb, mrb_value self) { mrb_value arg = mrb_get_arg1(mrb); + /* recursion check */ + for (mrb_callinfo *ci=&mrb->c->ci[-1]; ci>=mrb->c->cibase; ci--) { + if (ci->mid == MRB_OPSYM(cmp) && + mrb_obj_eq(mrb, self, ci->stack[0]) && + mrb_obj_eq(mrb, arg, ci->stack[1])) { + /* recursive <=> calling returns `nil` */ + return mrb_nil_value(); + } + } + if (mrb_equal(mrb, self, arg)) return mrb_fixnum_value(0); return mrb_nil_value(); } +static mrb_bool +inspect_recursive_p(mrb_state *mrb, mrb_value obj, int n) +{ + for (mrb_callinfo *ci=&mrb->c->ci[-1-n]; ci>=mrb->c->cibase; ci--) { + if (ci->mid == MRB_SYM(inspect) && + mrb_obj_eq(mrb, obj, ci->stack[0])) { + return TRUE; + } + } + return FALSE; +} + +mrb_bool +mrb_inspect_recursive_p(mrb_state *mrb, mrb_value obj) +{ + return inspect_recursive_p(mrb, obj, 0); +} + +static mrb_value +mrb_obj_inspect_recursive_p(mrb_state *mrb, mrb_value obj) +{ + return mrb_bool_value(inspect_recursive_p(mrb, obj, 1)); +} + /* 15.3.1.3.3 */ /* 15.3.1.3.33 */ /* @@ -377,27 +411,29 @@ mrb_false(mrb_state *mrb, mrb_value self) * raise "Failed to create socket" * raise ArgumentError, "No parameters", caller */ -MRB_API mrb_value +mrb_value mrb_f_raise(mrb_state *mrb, mrb_value self) { - mrb_value a[2], exc; + mrb_value exc, mesg; mrb_int argc; - argc = mrb_get_args(mrb, "|oo", &a[0], &a[1]); + argc = mrb_get_args(mrb, "|oo", &exc, &mesg); mrb->c->ci->mid = 0; switch (argc) { case 0: mrb_raise(mrb, E_RUNTIME_ERROR, ""); break; case 1: - if (mrb_string_p(a[0])) { - a[1] = a[0]; - argc = 2; - a[0] = mrb_obj_value(E_RUNTIME_ERROR); + if (mrb_string_p(exc)) { + mesg = exc; + exc = mrb_obj_value(E_RUNTIME_ERROR); + } + else { + mesg = mrb_nil_value(); } /* fall through */ default: - exc = mrb_make_exception(mrb, argc, a); + exc = mrb_make_exception(mrb, exc, mesg); mrb_exc_raise(mrb, exc); break; } @@ -441,12 +477,6 @@ mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self) return val; } -static inline mrb_bool -basic_obj_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym id, int pub) -{ - return mrb_respond_to(mrb, obj, id); -} - /* 15.3.1.3.43 */ /* * call-seq: @@ -466,18 +496,16 @@ basic_obj_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym id, int pub) static mrb_value obj_respond_to(mrb_state *mrb, mrb_value self) { - mrb_sym id, rtm_id; + mrb_sym id; mrb_bool priv = FALSE, respond_to_p; mrb_get_args(mrb, "n|b", &id, &priv); - respond_to_p = basic_obj_respond_to(mrb, self, id, !priv); + respond_to_p = mrb_respond_to(mrb, self, id); if (!respond_to_p) { - rtm_id = MRB_SYM_Q(respond_to_missing); - if (basic_obj_respond_to(mrb, self, rtm_id, !priv)) { - mrb_value args[2], v; - args[0] = mrb_symbol_value(id); - args[1] = mrb_bool_value(priv); - v = mrb_funcall_argv(mrb, self, rtm_id, 2, args); + mrb_sym rtm_id = MRB_SYM_Q(respond_to_missing); + if (!mrb_func_basic_p(mrb, self, rtm_id, mrb_false)) { + mrb_value v; + v = mrb_funcall_id(mrb, self, rtm_id, 2, mrb_symbol_value(id), mrb_bool_value(priv)); return mrb_bool_value(mrb_bool(v)); } } @@ -505,7 +533,7 @@ mrb_obj_ceqq(mrb_state *mrb, mrb_value self) return mrb_false_value(); } else { - ary = mrb_funcall_id(mrb, self, MRB_SYM(to_a), 0); + ary = mrb_funcall_argv(mrb, self, MRB_SYM(to_a), 0, NULL); if (mrb_nil_p(ary)) { return mrb_funcall_argv(mrb, self, eqq, 1, &v); } @@ -513,62 +541,49 @@ mrb_obj_ceqq(mrb_state *mrb, mrb_value self) } len = RARRAY_LEN(ary); for (i=0; ikernel_module = krn = mrb_define_module(mrb, "Kernel"); /* 15.3.1 */ - mrb_define_class_method(mrb, krn, "block_given?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.2.2 */ - mrb_define_class_method(mrb, krn, "iterator?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.2.5 */ - mrb_define_class_method(mrb, krn, "raise", mrb_f_raise, MRB_ARGS_OPT(2)); /* 15.3.1.2.12 */ + mrb->kernel_module = krn = mrb_define_module_id(mrb, MRB_SYM(Kernel)); /* 15.3.1 */ + mrb_define_class_method_id(mrb, krn, MRB_SYM_Q(block_given), mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.2.2 */ + mrb_define_class_method_id(mrb, krn, MRB_SYM_Q(iterator), mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.2.5 */ + mrb_define_class_method_id(mrb, krn, MRB_SYM(raise), mrb_f_raise, MRB_ARGS_OPT(2)); /* 15.3.1.2.12 */ + mrb_define_method_id(mrb, krn, MRB_OPSYM(eqq), mrb_eqq_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.2 */ + mrb_define_method_id(mrb, krn, MRB_OPSYM(cmp), mrb_cmp_m, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, krn, MRB_SYM_Q(block_given), mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.3.6 */ + mrb_define_method_id(mrb, krn, MRB_SYM(class), mrb_obj_class_m, MRB_ARGS_NONE()); /* 15.3.1.3.7 */ + mrb_define_method_id(mrb, krn, MRB_SYM(clone), mrb_obj_clone, MRB_ARGS_NONE()); /* 15.3.1.3.8 */ + mrb_define_method_id(mrb, krn, MRB_SYM(dup), mrb_obj_dup, MRB_ARGS_NONE()); /* 15.3.1.3.9 */ + mrb_define_method_id(mrb, krn, MRB_SYM_Q(eql), mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.10 */ + mrb_define_method_id(mrb, krn, MRB_SYM(freeze), mrb_obj_freeze, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, krn, MRB_SYM_Q(frozen), mrb_obj_frozen, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, krn, MRB_SYM(hash), mrb_obj_hash, MRB_ARGS_NONE()); /* 15.3.1.3.15 */ + mrb_define_method_id(mrb, krn, MRB_SYM(initialize_copy), mrb_obj_init_copy, MRB_ARGS_REQ(1)); /* 15.3.1.3.16 */ + mrb_define_method_id(mrb, krn, MRB_SYM(inspect), mrb_obj_inspect, MRB_ARGS_NONE()); /* 15.3.1.3.17 */ + mrb_define_method_id(mrb, krn, MRB_SYM_Q(instance_of), obj_is_instance_of, MRB_ARGS_REQ(1)); /* 15.3.1.3.19 */ - mrb_define_method(mrb, krn, "===", mrb_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.2 */ - mrb_define_method(mrb, krn, "<=>", mrb_cmp_m, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, krn, "block_given?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.3.6 */ - mrb_define_method(mrb, krn, "class", mrb_obj_class_m, MRB_ARGS_NONE()); /* 15.3.1.3.7 */ - mrb_define_method(mrb, krn, "clone", mrb_obj_clone, MRB_ARGS_NONE()); /* 15.3.1.3.8 */ - mrb_define_method(mrb, krn, "dup", mrb_obj_dup, MRB_ARGS_NONE()); /* 15.3.1.3.9 */ - mrb_define_method(mrb, krn, "eql?", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.10 */ - mrb_define_method(mrb, krn, "freeze", mrb_obj_freeze, MRB_ARGS_NONE()); - mrb_define_method(mrb, krn, "frozen?", mrb_obj_frozen, MRB_ARGS_NONE()); - mrb_define_method(mrb, krn, "hash", mrb_obj_hash, MRB_ARGS_NONE()); /* 15.3.1.3.15 */ - mrb_define_method(mrb, krn, "initialize_copy", mrb_obj_init_copy, MRB_ARGS_REQ(1)); /* 15.3.1.3.16 */ - mrb_define_method(mrb, krn, "inspect", mrb_obj_inspect, MRB_ARGS_NONE()); /* 15.3.1.3.17 */ - mrb_define_method(mrb, krn, "instance_of?", obj_is_instance_of, MRB_ARGS_REQ(1)); /* 15.3.1.3.19 */ - - mrb_define_method(mrb, krn, "is_a?", mrb_obj_is_kind_of_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.24 */ - mrb_define_method(mrb, krn, "iterator?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.3.25 */ - mrb_define_method(mrb, krn, "kind_of?", mrb_obj_is_kind_of_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.26 */ - mrb_define_method(mrb, krn, "nil?", mrb_false, MRB_ARGS_NONE()); /* 15.3.1.3.32 */ - mrb_define_method(mrb, krn, "object_id", mrb_obj_id_m, MRB_ARGS_NONE()); /* 15.3.1.3.33 */ - mrb_define_method(mrb, krn, "raise", mrb_f_raise, MRB_ARGS_ANY()); /* 15.3.1.3.40 */ - mrb_define_method(mrb, krn, "remove_instance_variable", mrb_obj_remove_instance_variable,MRB_ARGS_REQ(1)); /* 15.3.1.3.41 */ - mrb_define_method(mrb, krn, "respond_to?", obj_respond_to, MRB_ARGS_ARG(1,1)); /* 15.3.1.3.43 */ - mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, MRB_ARGS_NONE()); /* 15.3.1.3.46 */ - mrb_define_method(mrb, krn, "__case_eqq", mrb_obj_ceqq, MRB_ARGS_REQ(1)); /* internal */ - mrb_define_method(mrb, krn, "__to_int", mrb_ensure_int_type, MRB_ARGS_NONE()); /* internal */ - mrb_define_method(mrb, krn, "__ENCODING__", mrb_encoding, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, krn, MRB_SYM_Q(is_a), mrb_obj_is_kind_of_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.24 */ + mrb_define_method_id(mrb, krn, MRB_SYM_Q(iterator), mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.3.25 */ + mrb_define_method_id(mrb, krn, MRB_SYM_Q(kind_of), mrb_obj_is_kind_of_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.26 */ + mrb_define_method_id(mrb, krn, MRB_SYM_Q(nil), mrb_false, MRB_ARGS_NONE()); /* 15.3.1.3.32 */ + mrb_define_method_id(mrb, krn, MRB_SYM(object_id), mrb_obj_id_m, MRB_ARGS_NONE()); /* 15.3.1.3.33 */ + mrb_define_method_id(mrb, krn, MRB_SYM(raise), mrb_f_raise, MRB_ARGS_ANY()); /* 15.3.1.3.40 */ + mrb_define_method_id(mrb, krn, MRB_SYM(remove_instance_variable), mrb_obj_remove_instance_variable,MRB_ARGS_REQ(1)); /* 15.3.1.3.41 */ + mrb_define_method_id(mrb, krn, MRB_SYM_Q(respond_to), obj_respond_to, MRB_ARGS_ARG(1,1)); /* 15.3.1.3.43 */ + mrb_define_method_id(mrb, krn, MRB_SYM(to_s), mrb_any_to_s, MRB_ARGS_NONE()); /* 15.3.1.3.46 */ + mrb_define_method_id(mrb, krn, MRB_SYM(__case_eqq), mrb_obj_ceqq, MRB_ARGS_REQ(1)); /* internal */ + mrb_define_method_id(mrb, krn, MRB_SYM(__to_int), mrb_ensure_int_type, MRB_ARGS_NONE()); /* internal */ + mrb_define_method_id(mrb, krn, MRB_SYM_Q(respond_to_missing), mrb_false, MRB_ARGS_ARG(1,1)); + mrb_define_method_id(mrb, krn, MRB_SYM_Q(__inspect_recursive), mrb_obj_inspect_recursive_p, MRB_ARGS_NONE()); mrb_include_module(mrb, mrb->object_class, mrb->kernel_module); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/load.c b/yass/third_party/nghttp2/third-party/mruby/src/load.c index 52cb154b80..3008a4cd16 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/load.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/load.c @@ -110,7 +110,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, const uint8_t *end, size_ } else { void *buf = mrb_malloc(mrb, data_len); - irep->iseq = (mrb_code *)buf; + irep->iseq = (mrb_code*)buf; memcpy(buf, src, data_len); } src += data_len; @@ -220,7 +220,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, const uint8_t *end, size_ if (SIZE_ERROR_MUL(irep->slen, sizeof(mrb_sym))) { return FALSE; } - irep->syms = syms = (mrb_sym *)mrb_malloc(mrb, sizeof(mrb_sym) * irep->slen); + irep->syms = syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym) * irep->slen); for (i = 0; i < irep->slen; i++) { snl = bin_to_uint16(src); /* symbol name length */ @@ -233,10 +233,10 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, const uint8_t *end, size_ if (src + snl > end) return FALSE; if (flags & FLAG_SRC_MALLOC) { - syms[i] = mrb_intern(mrb, (char *)src, snl); + syms[i] = mrb_intern(mrb, (char*)src, snl); } else { - syms[i] = mrb_intern_static(mrb, (char *)src, snl); + syms[i] = mrb_intern_static(mrb, (char*)src, snl); } src += snl + 1; mrb_gc_arena_restore(mrb, ai); @@ -331,7 +331,7 @@ read_debug_record(mrb_state *mrb, const uint8_t *start, const uint8_t *end, mrb_ uint16_t filename_idx; if (bin > end) return MRB_DUMP_GENERAL_FAILURE; - file = (mrb_irep_debug_info_file *)mrb_calloc(mrb, 1, sizeof(*file)); + file = (mrb_irep_debug_info_file*)mrb_calloc(mrb, 1, sizeof(*file)); debug->files[f_idx] = file; file->start_pos = bin_to_uint32(bin); @@ -352,7 +352,7 @@ read_debug_record(mrb_state *mrb, const uint8_t *start, const uint8_t *end, mrb_ size_t l = sizeof(uint16_t) * (size_t)file->line_entry_count; if (bin + l > end) return MRB_DUMP_GENERAL_FAILURE; - uint16_t *ary = (uint16_t *)mrb_malloc(mrb, l); + uint16_t *ary = (uint16_t*)mrb_malloc(mrb, l); for (l = 0; l < file->line_entry_count; l++) { ary[l] = bin_to_uint16(bin); bin += sizeof(uint16_t); @@ -427,7 +427,7 @@ read_section_debug(mrb_state *mrb, const uint8_t *start, size_t size, mrb_irep * mrb_value filenames_obj; bin = start; - header = (struct rite_section_debug_header *)bin; + header = (struct rite_section_debug_header*)bin; bin += sizeof(struct rite_section_debug_header); filenames_len = bin_to_uint16(bin); @@ -443,10 +443,10 @@ read_section_debug(mrb_state *mrb, const uint8_t *start, size_t size, mrb_irep * goto debug_exit; } if (flags & FLAG_SRC_MALLOC) { - filenames[i] = mrb_intern(mrb, (const char *)bin, (size_t)f_len); + filenames[i] = mrb_intern(mrb, (const char*)bin, (size_t)f_len); } else { - filenames[i] = mrb_intern_static(mrb, (const char *)bin, (size_t)f_len); + filenames[i] = mrb_intern_static(mrb, (const char*)bin, (size_t)f_len); } bin += f_len; } @@ -558,7 +558,7 @@ lv_exit: static int read_binary_header(const uint8_t *bin, size_t bufsize, size_t *bin_size, uint8_t *flags) { - const struct rite_binary_header *header = (const struct rite_binary_header *)bin; + const struct rite_binary_header *header = (const struct rite_binary_header*)bin; if (bufsize < sizeof(struct rite_binary_header)) { return MRB_DUMP_READ_FAULT; @@ -607,7 +607,7 @@ read_irep(mrb_state *mrb, const uint8_t *bin, size_t bufsize, uint8_t flags) bin += sizeof(struct rite_binary_header); bin_size -= sizeof(struct rite_binary_header); while (bin_size > sizeof(struct rite_section_header)) { - section_header = (const struct rite_section_header *)bin; + section_header = (const struct rite_section_header*)bin; uint32_t section_size = bin_to_uint32(section_header->section_size); if (bin_size < section_size) return NULL; if (memcmp(section_header->section_ident, RITE_SECTION_IREP_IDENT, sizeof(section_header->section_ident)) == 0) { @@ -654,7 +654,7 @@ DEFINE_READ_IREP_FUNC( static struct RProc* mrb_proc_read_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize) { - return read_irep(mrb, (const uint8_t *)buf, bufsize, FLAG_SRC_MALLOC); + return read_irep(mrb, (const uint8_t*)buf, bufsize, FLAG_SRC_MALLOC); } DEFINE_READ_IREP_FUNC( @@ -670,7 +670,7 @@ irep_error(mrb_state *mrb) } static mrb_value -load_irep(mrb_state *mrb, struct RProc *proc, mrbc_context *c) +load_irep(mrb_state *mrb, struct RProc *proc, mrb_ccontext *c) { if (!proc || !proc->body.irep) { irep_error(mrb); @@ -683,7 +683,7 @@ load_irep(mrb_state *mrb, struct RProc *proc, mrbc_context *c) } MRB_API mrb_value -mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c) +mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrb_ccontext *c) { struct RProc *proc = mrb_proc_read_irep(mrb, bin); if (!proc) return mrb_undef_value(); @@ -691,7 +691,7 @@ mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c) } MRB_API mrb_value -mrb_load_irep_buf_cxt(mrb_state *mrb, const void *buf, size_t bufsize, mrbc_context *c) +mrb_load_irep_buf_cxt(mrb_state *mrb, const void *buf, size_t bufsize, mrb_ccontext *c) { return load_irep(mrb, mrb_proc_read_irep_buf(mrb, buf, bufsize), c); } @@ -755,7 +755,7 @@ DEFINE_READ_IREP_FUNC( mrb_proc_read_irep_file(mrb, fp)) MRB_API mrb_value -mrb_load_irep_file_cxt(mrb_state *mrb, FILE* fp, mrbc_context *c) +mrb_load_irep_file_cxt(mrb_state *mrb, FILE* fp, mrb_ccontext *c) { return load_irep(mrb, mrb_proc_read_irep_file(mrb, fp), c); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/numeric.c b/yass/third_party/nghttp2/third-party/mruby/src/numeric.c index a671eeba7a..743cdb3aec 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/numeric.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/numeric.c @@ -66,7 +66,7 @@ mrb_int_pow(mrb_state *mrb, mrb_value x, mrb_value y) else #endif { - mrb_get_args(mrb, "i", &exp); + exp = mrb_as_int(mrb, y); } if (exp < 0) { #ifndef MRB_NO_FLOAT @@ -130,7 +130,7 @@ mrb_div_int_value(mrb_state *mrb, mrb_int x, mrb_int y) if (y == 0) { mrb_int_zerodiv(mrb); } - else if(x == MRB_INT_MIN && y == -1) { + else if (x == MRB_INT_MIN && y == -1) { #ifdef MRB_USE_BIGINT return mrb_bint_mul_ii(mrb, x, y); #else @@ -208,9 +208,7 @@ int_idiv(mrb_state *mrb, mrb_value x) return mrb_bint_div(mrb, x, mrb_get_arg1(mrb)); } #endif - mrb_int y; - - mrb_get_args(mrb, "i", &y); + mrb_int y = mrb_as_int(mrb, mrb_get_arg1(mrb)); return mrb_div_int_value(mrb, mrb_integer(x), y); } @@ -221,9 +219,8 @@ int_quo(mrb_state *mrb, mrb_value x) #ifdef MRB_NO_FLOAT return int_idiv(mrb, x); #else - mrb_float y; + mrb_float y = mrb_as_float(mrb, mrb_get_arg1(mrb)); - mrb_get_args(mrb, "f", &y); if (y == 0) { mrb_int_zerodiv(mrb); } @@ -293,10 +290,10 @@ flo_pow(mrb_state *mrb, mrb_value x) static mrb_value flo_idiv(mrb_state *mrb, mrb_value xv) { - mrb_int y; - - mrb_get_args(mrb, "i", &y); - return mrb_div_int_value(mrb, (mrb_int)mrb_float(xv), y); + mrb_float x = mrb_float(xv); + mrb_check_num_exact(mrb, x); + mrb_int y = mrb_as_int(mrb, mrb_get_arg1(mrb)); + return mrb_div_int_value(mrb, (mrb_int)x, y); } mrb_float @@ -357,7 +354,8 @@ mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt) if (*p == '.') goto exit; if (*p == 'e') { memmove(p+2, p, strlen(p)+1); - memcpy(p, ".0", 2); + p[0] = '.'; + p[1] = '0'; goto exit; } } @@ -537,7 +535,7 @@ flo_mod(mrb_state *mrb, mrb_value x) mrb_value y = mrb_get_arg1(mrb); mrb_float mod; - flodivmod(mrb, mrb_float(x), mrb_as_float(mrb, y), 0, &mod); + flodivmod(mrb, mrb_float(x), mrb_as_float(mrb, y), NULL, &mod); return mrb_float_value(mrb, mod); } #endif @@ -709,9 +707,10 @@ flo_shift(mrb_state *mrb, mrb_value x, mrb_int width) val = trunc(val); #else if (val > 0){ - val = floor(val); - } else { - val = ceil(val); + val = floor(val); + } + else { + val = ceil(val); } #endif if (val == 0 && mrb_float(x) < 0) { @@ -731,9 +730,7 @@ flo_shift(mrb_state *mrb, mrb_value x, mrb_int width) static mrb_value flo_rshift(mrb_state *mrb, mrb_value x) { - mrb_int width; - - mrb_get_args(mrb, "i", &width); + mrb_int width = mrb_as_int(mrb, mrb_get_arg1(mrb)); if (width == MRB_INT_MIN) return flo_shift(mrb, x, -MRB_INT_BIT); return flo_shift(mrb, x, -width); } @@ -741,9 +738,7 @@ flo_rshift(mrb_state *mrb, mrb_value x) static mrb_value flo_lshift(mrb_state *mrb, mrb_value x) { - mrb_int width; - - mrb_get_args(mrb, "i", &width); + mrb_int width = mrb_as_int(mrb, mrb_get_arg1(mrb)); return flo_shift(mrb, x, width); } @@ -1204,7 +1199,7 @@ intdivmod(mrb_state *mrb, mrb_int x, mrb_int y, mrb_int *divp, mrb_int *modp) if (y == 0) { mrb_int_zerodiv(mrb); } - else if(x == MRB_INT_MIN && y == -1) { + else if (x == MRB_INT_MIN && y == -1) { mrb_int_overflow(mrb, "division"); } else { @@ -1374,13 +1369,12 @@ int_equal(mrb_state *mrb, mrb_value x) static mrb_value int_rev(mrb_state *mrb, mrb_value num) { - mrb_int val = mrb_integer(num); - #ifdef MRB_USE_BIGINT if (mrb_bigint_p(num)) { - mrb_bint_rev(mrb, num); + return mrb_bint_rev(mrb, num); } #endif + mrb_int val = mrb_integer(num); return mrb_int_value(mrb, ~val); } @@ -1521,7 +1515,7 @@ int_lshift(mrb_state *mrb, mrb_value x) { mrb_int width, val; - mrb_get_args(mrb, "i", &width); + width = mrb_as_int(mrb, mrb_get_arg1(mrb)); if (width == 0) { return x; } @@ -1556,7 +1550,7 @@ int_rshift(mrb_state *mrb, mrb_value x) { mrb_int width, val; - mrb_get_args(mrb, "i", &width); + width = mrb_as_int(mrb, mrb_get_arg1(mrb)); if (width == 0) { return x; } @@ -1620,16 +1614,26 @@ int_ceil(mrb_state *mrb, mrb_value x) if (mrb_nil_p(f)) return x; #ifdef MRB_USE_BIGINT if (mrb_bigint_p(x)) { - return mrb_bint_add(mrb, x, mrb_bint_sub(mrb, x, mrb_bint_mod(mrb, x, f))); + x = mrb_bint_add_d(mrb, x, f); + return mrb_bint_sub(mrb, x, mrb_bint_mod(mrb, x, f)); } #endif mrb_int a = mrb_integer(x); mrb_int b = mrb_integer(f); + mrb_int c = a % b; int neg = a < 0; - if (neg) a = -a; - else a += b - 1; - a = a / b * b; - if (neg) a = -a; + a -= c; + if (!neg) { + if (mrb_int_add_overflow(a, b, &c)) { +#ifdef MRB_USE_BIGINT + x = mrb_bint_new_int(mrb, a); + return mrb_bint_add(mrb, x, f); +#else + mrb_int_overflow(mrb, "ceil"); +#endif + } + a = c; + } return mrb_int_value(mrb, a); } @@ -1657,10 +1661,20 @@ int_floor(mrb_state *mrb, mrb_value x) #endif mrb_int a = mrb_integer(x); mrb_int b = mrb_integer(f); + mrb_int c = a % b; int neg = a < 0; - if (neg) a = -a + b - 1; - a = a / b * b; - if (neg) a = -a; + a -= c; + if (neg) { + if (mrb_int_sub_overflow(a, b, &c)) { +#ifdef MRB_USE_BIGINT + x = mrb_bint_new_int(mrb, a); + return mrb_bint_sub(mrb, x, f); +#else + mrb_int_overflow(mrb, "floor"); +#endif + } + a = c; + } return mrb_int_value(mrb, a); } @@ -1686,7 +1700,7 @@ int_round(mrb_state *mrb, mrb_value x) mrb_value r = mrb_bint_mod(mrb, x, f); mrb_value n = mrb_bint_sub(mrb, x, r); mrb_value h = mrb_bigint_p(f) ? mrb_bint_rshift(mrb, f, 1) : mrb_int_value(mrb, mrb_integer(f)>>1); - mrb_int cmp = mrb_bigint_p(r) ? mrb_bint_cmp(mrb, r, h) : (mrb_integer(r) - mrb_integer(h)); + mrb_int cmp = mrb_bigint_p(r) ? mrb_bint_cmp(mrb, r, h) : (mrb_bigint_p(h) ? -mrb_bint_cmp(mrb, h, r) : (mrb_integer(r)-mrb_integer(h))); if ((cmp > 0) || (cmp == 0 && mrb_bint_cmp(mrb, x, mrb_fixnum_value(0)) > 0)) { n = mrb_as_bint(mrb, n); n = mrb_bint_add(mrb, n, f); @@ -1696,10 +1710,35 @@ int_round(mrb_state *mrb, mrb_value x) #endif mrb_int a = mrb_integer(x); mrb_int b = mrb_integer(f); - int neg = a < 0; - if (neg) a = -a; - a = (a + b / 2) / b * b; - if (neg) a = -a; + mrb_int c = a % b; + a -= c; + if (c < 0) { + c = -c; + if (b/2 < c) { + if (mrb_int_sub_overflow(a, b, &c)) { +#ifdef MRB_USE_BIGINT + x = mrb_bint_new_int(mrb, a); + return mrb_bint_sub(mrb, x, f); +#else + mrb_int_overflow(mrb, "round"); +#endif + } + } + a = c; + } + else { + if (b/2 < c) { + if (mrb_int_add_overflow(a, b, &c)) { +#ifdef MRB_USE_BIGINT + x = mrb_bint_new_int(mrb, a); + return mrb_bint_add(mrb, x, f); +#else + mrb_int_overflow(mrb, "round"); +#endif + } + } + a = c; + } return mrb_int_value(mrb, a); } @@ -1723,21 +1762,16 @@ int_truncate(mrb_state *mrb, mrb_value x) #ifdef MRB_USE_BIGINT if (mrb_bigint_p(x)) { mrb_value m = mrb_bint_mod(mrb, x, f); + x = mrb_bint_sub_d(mrb, x, m); if (mrb_bint_cmp(mrb, x, mrb_fixnum_value(0)) < 0) { - return mrb_bint_add(mrb, x, mrb_bint_sub(mrb, x, m)); - } - else { - return mrb_bint_sub(mrb, x, m); + return mrb_bint_add(mrb, x, f); } + return x; } #endif mrb_int a = mrb_integer(x); mrb_int b = mrb_integer(f); - int neg = a < 0; - if (neg) a = -a; - a = a / b * b; - if (neg) a = -a; - return mrb_int_value(mrb, a); + return mrb_int_value(mrb, a - (a % b)); } /* 15.2.8.3.23 */ @@ -1978,9 +2012,14 @@ mrb_integer_to_str(mrb_state *mrb, mrb_value x, mrb_int base) static mrb_value int_to_s(mrb_state *mrb, mrb_value self) { - mrb_int base = 10; + mrb_int base; - mrb_get_args(mrb, "|i", &base); + if (mrb_get_argc(mrb) > 0) { + base = mrb_integer(mrb_get_arg1(mrb)); + } + else { + base = 10; + } return mrb_integer_to_str(mrb, self, base); } @@ -2141,7 +2180,7 @@ mrb_cmp(mrb_state *mrb, mrb_value obj1, mrb_value obj2) return mrb_str_cmp(mrb, obj1, obj2); default: if (!mrb_respond_to(mrb, obj1, MRB_OPSYM(cmp))) return -2; - v = mrb_funcall_id(mrb, obj1, MRB_OPSYM(cmp), 1, obj2); + v = mrb_funcall_argv(mrb, obj1, MRB_OPSYM(cmp), 1, &obj2); if (mrb_nil_p(v) || !mrb_integer_p(v)) return -2; return mrb_integer(v); @@ -2181,95 +2220,97 @@ mrb_init_numeric(mrb_state *mrb) #endif /* Numeric Class */ - numeric = mrb_define_class(mrb, "Numeric", mrb->object_class); /* 15.2.7 */ - mrb_define_method(mrb, numeric, "finite?", num_finite_p, MRB_ARGS_NONE()); - mrb_define_method(mrb, numeric, "infinite?",num_infinite_p, MRB_ARGS_NONE()); - mrb_define_method(mrb, numeric, "eql?", num_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */ + numeric = mrb_define_class_id(mrb, MRB_SYM(Numeric), mrb->object_class); /* 15.2.7 */ + mrb_define_method_id(mrb, numeric, MRB_SYM_Q(finite), num_finite_p, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, numeric, MRB_SYM_Q(infinite),num_infinite_p, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, numeric, MRB_SYM_Q(eql), num_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */ /* Integer Class */ - mrb->integer_class = integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */ + mrb->integer_class = integer = mrb_define_class_id(mrb, MRB_SYM(Integer), numeric); /* 15.2.8 */ MRB_SET_INSTANCE_TT(integer, MRB_TT_INTEGER); - mrb_undef_class_method(mrb, integer, "new"); - mrb_define_method(mrb, integer, "**", int_pow, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, integer, "<=>", num_cmp, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */ - mrb_define_method(mrb, integer, "<", num_lt, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, integer, "<=", num_le, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, integer, ">", num_gt, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, integer, ">=", num_ge, MRB_ARGS_REQ(1)); + MRB_UNDEF_ALLOCATOR(integer); + mrb_undef_class_method_id(mrb, integer, MRB_SYM(new)); + mrb_define_method_id(mrb, integer, MRB_OPSYM(pow), int_pow, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, integer, MRB_OPSYM(cmp), num_cmp, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(lt), num_lt, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, integer, MRB_OPSYM(le), num_le, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, integer, MRB_OPSYM(gt), num_gt, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, integer, MRB_OPSYM(ge), num_ge, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, integer, "to_i", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.24 */ - mrb_define_method(mrb, integer, "to_int", int_to_i, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, integer, MRB_SYM(to_i), int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.24 */ + mrb_define_method_id(mrb, integer, MRB_SYM(to_int), int_to_i, MRB_ARGS_NONE()); - mrb_define_method(mrb, integer, "+", int_add, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */ - mrb_define_method(mrb, integer, "-", int_sub, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */ - mrb_define_method(mrb, integer, "*", int_mul, MRB_ARGS_REQ(1)); /* 15.2.8.3.3 */ - mrb_define_method(mrb, integer, "%", int_mod, MRB_ARGS_REQ(1)); /* 15.2.8.3.5 */ - mrb_define_method(mrb, integer, "/", int_div, MRB_ARGS_REQ(1)); /* 15.2.8.3.6 */ - mrb_define_method(mrb, integer, "quo", int_quo, MRB_ARGS_REQ(1)); /* 15.2.7.4.5(x) */ - mrb_define_method(mrb, integer, "div", int_idiv, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, integer, "==", int_equal, MRB_ARGS_REQ(1)); /* 15.2.8.3.7 */ - mrb_define_method(mrb, integer, "~", int_rev, MRB_ARGS_NONE()); /* 15.2.8.3.8 */ - mrb_define_method(mrb, integer, "&", int_and, MRB_ARGS_REQ(1)); /* 15.2.8.3.9 */ - mrb_define_method(mrb, integer, "|", int_or, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */ - mrb_define_method(mrb, integer, "^", int_xor, MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */ - mrb_define_method(mrb, integer, "<<", int_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */ - mrb_define_method(mrb, integer, ">>", int_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */ - mrb_define_method(mrb, integer, "ceil", int_ceil, MRB_ARGS_OPT(1)); /* 15.2.8.3.14 */ - mrb_define_method(mrb, integer, "floor", int_floor, MRB_ARGS_OPT(1)); /* 15.2.8.3.17 */ - mrb_define_method(mrb, integer, "round", int_round, MRB_ARGS_OPT(1)); /* 15.2.8.3.20 */ - mrb_define_method(mrb, integer, "truncate", int_truncate, MRB_ARGS_OPT(1)); /* 15.2.8.3.26 */ - mrb_define_method(mrb, integer, "hash", int_hash, MRB_ARGS_NONE()); /* 15.2.8.3.18 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(add), int_add, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(sub), int_sub, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(mul), int_mul, MRB_ARGS_REQ(1)); /* 15.2.8.3.3 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(mod), int_mod, MRB_ARGS_REQ(1)); /* 15.2.8.3.5 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(div), int_div, MRB_ARGS_REQ(1)); /* 15.2.8.3.6 */ + mrb_define_method_id(mrb, integer, MRB_SYM(quo), int_quo, MRB_ARGS_REQ(1)); /* 15.2.7.4.5(x) */ + mrb_define_method_id(mrb, integer, MRB_SYM(div), int_idiv, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, integer, MRB_OPSYM(eq), int_equal, MRB_ARGS_REQ(1)); /* 15.2.8.3.7 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(neg), int_rev, MRB_ARGS_NONE()); /* 15.2.8.3.8 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(and), int_and, MRB_ARGS_REQ(1)); /* 15.2.8.3.9 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(or), int_or, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(xor), int_xor, MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(lshift), int_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */ + mrb_define_method_id(mrb, integer, MRB_OPSYM(rshift), int_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */ + mrb_define_method_id(mrb, integer, MRB_SYM(ceil), int_ceil, MRB_ARGS_OPT(1)); /* 15.2.8.3.14 */ + mrb_define_method_id(mrb, integer, MRB_SYM(floor), int_floor, MRB_ARGS_OPT(1)); /* 15.2.8.3.17 */ + mrb_define_method_id(mrb, integer, MRB_SYM(round), int_round, MRB_ARGS_OPT(1)); /* 15.2.8.3.20 */ + mrb_define_method_id(mrb, integer, MRB_SYM(truncate), int_truncate, MRB_ARGS_OPT(1)); /* 15.2.8.3.26 */ + mrb_define_method_id(mrb, integer, MRB_SYM(hash), int_hash, MRB_ARGS_NONE()); /* 15.2.8.3.18 */ #ifndef MRB_NO_FLOAT - mrb_define_method(mrb, integer, "to_f", int_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */ + mrb_define_method_id(mrb, integer, MRB_SYM(to_f), int_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */ #endif - mrb_define_method(mrb, integer, "to_s", int_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */ - mrb_define_method(mrb, integer, "inspect", int_to_s, MRB_ARGS_OPT(1)); - mrb_define_method(mrb, integer, "divmod", int_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30(x) */ - mrb_define_method(mrb, integer, "__coerce_step_counter", coerce_step_counter, MRB_ARGS_REQ(2)); + mrb_define_method_id(mrb, integer, MRB_SYM(to_s), int_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */ + mrb_define_method_id(mrb, integer, MRB_SYM(inspect), int_to_s, MRB_ARGS_OPT(1)); + mrb_define_method_id(mrb, integer, MRB_SYM(divmod), int_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30(x) */ + mrb_define_method_id(mrb, integer, MRB_SYM(__coerce_step_counter), coerce_step_counter, MRB_ARGS_REQ(2)); /* Fixnum Class for compatibility */ - mrb_define_const(mrb, mrb->object_class, "Fixnum", mrb_obj_value(integer)); + mrb_define_const_id(mrb, mrb->object_class, MRB_SYM(Fixnum), mrb_obj_value(integer)); #ifndef MRB_NO_FLOAT /* Float Class */ - mrb->float_class = fl = mrb_define_class(mrb, "Float", numeric); /* 15.2.9 */ + mrb->float_class = fl = mrb_define_class_id(mrb, MRB_SYM(Float), numeric); /* 15.2.9 */ MRB_SET_INSTANCE_TT(fl, MRB_TT_FLOAT); + MRB_UNDEF_ALLOCATOR(fl); mrb_undef_class_method(mrb, fl, "new"); - mrb_define_method(mrb, fl, "**", flo_pow, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "/", flo_div, MRB_ARGS_REQ(1)); /* 15.2.9.3.6 */ - mrb_define_method(mrb, fl, "quo", flo_div, MRB_ARGS_REQ(1)); /* 15.2.7.4.5(x) */ - mrb_define_method(mrb, fl, "div", flo_idiv, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "+", flo_add, MRB_ARGS_REQ(1)); /* 15.2.9.3.3 */ - mrb_define_method(mrb, fl, "-", flo_sub, MRB_ARGS_REQ(1)); /* 15.2.9.3.4 */ - mrb_define_method(mrb, fl, "*", flo_mul, MRB_ARGS_REQ(1)); /* 15.2.9.3.5 */ - mrb_define_method(mrb, fl, "%", flo_mod, MRB_ARGS_REQ(1)); /* 15.2.9.3.7 */ - mrb_define_method(mrb, fl, "<=>", num_cmp, MRB_ARGS_REQ(1)); /* 15.2.9.3.1 */ - mrb_define_method(mrb, fl, "<", num_lt, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "<=", num_le, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, ">", num_gt, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, ">=", num_ge, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "==", flo_eq, MRB_ARGS_REQ(1)); /* 15.2.9.3.2 */ - mrb_define_method(mrb, fl, "~", flo_rev, MRB_ARGS_NONE()); - mrb_define_method(mrb, fl, "&", flo_and, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "|", flo_or, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "^", flo_xor, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, ">>", flo_rshift, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "<<", flo_lshift, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "ceil", flo_ceil, MRB_ARGS_OPT(1)); /* 15.2.9.3.8 */ - mrb_define_method(mrb, fl, "finite?", flo_finite_p, MRB_ARGS_NONE()); /* 15.2.9.3.9 */ - mrb_define_method(mrb, fl, "floor", flo_floor, MRB_ARGS_OPT(1)); /* 15.2.9.3.10 */ - mrb_define_method(mrb, fl, "infinite?", flo_infinite_p, MRB_ARGS_NONE()); /* 15.2.9.3.11 */ - mrb_define_method(mrb, fl, "round", flo_round, MRB_ARGS_OPT(1)); /* 15.2.9.3.12 */ - mrb_define_method(mrb, fl, "to_f", flo_to_f, MRB_ARGS_NONE()); /* 15.2.9.3.13 */ - mrb_define_method(mrb, fl, "to_i", flo_to_i, MRB_ARGS_NONE()); /* 15.2.9.3.14 */ - mrb_define_method(mrb, fl, "truncate", flo_truncate, MRB_ARGS_OPT(1)); /* 15.2.9.3.15 */ - mrb_define_method(mrb, fl, "divmod", flo_divmod, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(pow), flo_pow, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(div), flo_div, MRB_ARGS_REQ(1)); /* 15.2.9.3.6 */ + mrb_define_method_id(mrb, fl, MRB_SYM(quo), flo_div, MRB_ARGS_REQ(1)); /* 15.2.7.4.5(x) */ + mrb_define_method_id(mrb, fl, MRB_SYM(div), flo_idiv, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(add), flo_add, MRB_ARGS_REQ(1)); /* 15.2.9.3.3 */ + mrb_define_method_id(mrb, fl, MRB_OPSYM(sub), flo_sub, MRB_ARGS_REQ(1)); /* 15.2.9.3.4 */ + mrb_define_method_id(mrb, fl, MRB_OPSYM(mul), flo_mul, MRB_ARGS_REQ(1)); /* 15.2.9.3.5 */ + mrb_define_method_id(mrb, fl, MRB_OPSYM(mod), flo_mod, MRB_ARGS_REQ(1)); /* 15.2.9.3.7 */ + mrb_define_method_id(mrb, fl, MRB_OPSYM(cmp), num_cmp, MRB_ARGS_REQ(1)); /* 15.2.9.3.1 */ + mrb_define_method_id(mrb, fl, MRB_OPSYM(lt), num_lt, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(le), num_le, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(gt), num_gt, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(ge), num_ge, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(eq), flo_eq, MRB_ARGS_REQ(1)); /* 15.2.9.3.2 */ + mrb_define_method_id(mrb, fl, MRB_OPSYM(neg), flo_rev, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, fl, MRB_OPSYM(and), flo_and, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(or), flo_or, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(xor), flo_xor, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(rshift), flo_rshift, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_OPSYM(lshift), flo_lshift, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, fl, MRB_SYM(ceil), flo_ceil, MRB_ARGS_OPT(1)); /* 15.2.9.3.8 */ + mrb_define_method_id(mrb, fl, MRB_SYM_Q(finite), flo_finite_p, MRB_ARGS_NONE()); /* 15.2.9.3.9 */ + mrb_define_method_id(mrb, fl, MRB_SYM(floor), flo_floor, MRB_ARGS_OPT(1)); /* 15.2.9.3.10 */ + mrb_define_method_id(mrb, fl, MRB_SYM_Q(infinite),flo_infinite_p, MRB_ARGS_NONE()); /* 15.2.9.3.11 */ + mrb_define_method_id(mrb, fl, MRB_SYM(round), flo_round, MRB_ARGS_OPT(1)); /* 15.2.9.3.12 */ + mrb_define_method_id(mrb, fl, MRB_SYM(to_f), flo_to_f, MRB_ARGS_NONE()); /* 15.2.9.3.13 */ + mrb_define_method_id(mrb, fl, MRB_SYM(to_i), flo_to_i, MRB_ARGS_NONE()); /* 15.2.9.3.14 */ + mrb_define_method_id(mrb, fl, MRB_SYM(truncate), flo_truncate, MRB_ARGS_OPT(1)); /* 15.2.9.3.15 */ + mrb_define_method_id(mrb, fl, MRB_SYM(divmod), flo_divmod, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, fl, "to_s", flo_to_s, MRB_ARGS_NONE()); /* 15.2.9.3.16(x) */ - mrb_define_method(mrb, fl, "inspect", flo_to_s, MRB_ARGS_NONE()); - mrb_define_method(mrb, fl, "nan?", flo_nan_p, MRB_ARGS_NONE()); - mrb_define_method(mrb, fl, "abs", flo_abs, MRB_ARGS_NONE()); /* 15.2.7.4.3 */ - mrb_define_method(mrb, fl, "hash", flo_hash, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, fl, MRB_SYM(to_s), flo_to_s, MRB_ARGS_NONE()); /* 15.2.9.3.16(x) */ + mrb_define_method_id(mrb, fl, MRB_SYM(inspect), flo_to_s, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, fl, MRB_SYM_Q(nan), flo_nan_p, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, fl, MRB_SYM(abs), flo_abs, MRB_ARGS_NONE()); /* 15.2.7.4.3 */ + mrb_define_method_id(mrb, fl, MRB_SYM(hash), flo_hash, MRB_ARGS_NONE()); #ifdef INFINITY mrb_define_const_id(mrb, fl, MRB_SYM(INFINITY), mrb_float_value(mrb, INFINITY)); diff --git a/yass/third_party/nghttp2/third-party/mruby/src/object.c b/yass/third_party/nghttp2/third-party/mruby/src/object.c index cc7ec644a5..f8e9c0b729 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/object.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/object.c @@ -53,32 +53,29 @@ mrb_obj_equal(mrb_state *mrb, mrb_value v1, mrb_value v2) MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2) { - mrb_value result; - if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE; #ifndef MRB_NO_FLOAT /* value mixing with integer and float */ - if (mrb_integer_p(obj1) && mrb_float_p(obj2)) { + else if (mrb_integer_p(obj1) && mrb_float_p(obj2)) { if ((mrb_float)mrb_integer(obj1) == mrb_float(obj2)) return TRUE; - return FALSE; } else if (mrb_float_p(obj1) && mrb_integer_p(obj2)) { if (mrb_float(obj1) == (mrb_float)mrb_integer(obj2)) return TRUE; - return FALSE; } #endif #ifdef MRB_USE_BIGINT - if (mrb_bigint_p(obj1) && + else if (mrb_bigint_p(obj1) && (mrb_integer_p(obj2) || mrb_bigint_p(obj2) || mrb_float_p(obj2))) { if (mrb_bint_cmp(mrb, obj1, obj2) == 0) return TRUE; - return FALSE; } #endif - result = mrb_funcall_id(mrb, obj1, MRB_OPSYM(eq), 1, obj2); - if (mrb_test(result)) return TRUE; + else if (!mrb_func_basic_p(mrb, obj1, MRB_OPSYM(eq), mrb_obj_equal_m)) { + mrb_value result = mrb_funcall_argv(mrb, obj1, MRB_OPSYM(eq), 1, &obj2); + if (mrb_test(result)) return TRUE; + } return FALSE; } @@ -305,33 +302,33 @@ mrb_init_object(mrb_state *mrb) struct RClass *t; struct RClass *f; - mrb->nil_class = n = mrb_define_class(mrb, "NilClass", mrb->object_class); + mrb->nil_class = n = mrb_define_class_id(mrb, MRB_SYM(NilClass), mrb->object_class); MRB_SET_INSTANCE_TT(n, MRB_TT_FALSE); - mrb_undef_class_method(mrb, n, "new"); - mrb_define_method(mrb, n, "&", false_and, MRB_ARGS_REQ(1)); /* 15.2.4.3.1 */ - mrb_define_method(mrb, n, "^", false_xor, MRB_ARGS_REQ(1)); /* 15.2.4.3.2 */ - mrb_define_method(mrb, n, "|", false_or, MRB_ARGS_REQ(1)); /* 15.2.4.3.3 */ - mrb_define_method(mrb, n, "nil?", mrb_true, MRB_ARGS_NONE()); /* 15.2.4.3.4 */ - mrb_define_method(mrb, n, "to_s", nil_to_s, MRB_ARGS_NONE()); /* 15.2.4.3.5 */ - mrb_define_method(mrb, n, "inspect", nil_inspect, MRB_ARGS_NONE()); + mrb_undef_class_method_id(mrb, n, MRB_SYM(new)); + mrb_define_method_id(mrb, n, MRB_OPSYM(and), false_and, MRB_ARGS_REQ(1)); /* 15.2.4.3.1 */ + mrb_define_method_id(mrb, n, MRB_OPSYM(or), false_or, MRB_ARGS_REQ(1)); /* 15.2.4.3.2 */ + mrb_define_method_id(mrb, n, MRB_OPSYM(xor), false_xor, MRB_ARGS_REQ(1)); /* 15.2.4.3.3 */ + mrb_define_method_id(mrb, n, MRB_SYM_Q(nil), mrb_true, MRB_ARGS_NONE()); /* 15.2.4.3.4 */ + mrb_define_method_id(mrb, n, MRB_SYM(to_s), nil_to_s, MRB_ARGS_NONE()); /* 15.2.4.3.5 */ + mrb_define_method_id(mrb, n, MRB_SYM(inspect), nil_inspect, MRB_ARGS_NONE()); - mrb->true_class = t = mrb_define_class(mrb, "TrueClass", mrb->object_class); + mrb->true_class = t = mrb_define_class_id(mrb, MRB_SYM(TrueClass), mrb->object_class); MRB_SET_INSTANCE_TT(t, MRB_TT_TRUE); - mrb_undef_class_method(mrb, t, "new"); - mrb_define_method(mrb, t, "&", true_and, MRB_ARGS_REQ(1)); /* 15.2.5.3.1 */ - mrb_define_method(mrb, t, "^", true_xor, MRB_ARGS_REQ(1)); /* 15.2.5.3.2 */ - mrb_define_method(mrb, t, "to_s", true_to_s, MRB_ARGS_NONE()); /* 15.2.5.3.3 */ - mrb_define_method(mrb, t, "|", true_or, MRB_ARGS_REQ(1)); /* 15.2.5.3.4 */ - mrb_define_method(mrb, t, "inspect", true_to_s, MRB_ARGS_NONE()); + mrb_undef_class_method_id(mrb, t, MRB_SYM(new)); + mrb_define_method_id(mrb, t, MRB_OPSYM(and), true_and, MRB_ARGS_REQ(1)); /* 15.2.5.3.1 */ + mrb_define_method_id(mrb, t, MRB_OPSYM(or), true_or, MRB_ARGS_REQ(1)); /* 15.2.5.3.2 */ + mrb_define_method_id(mrb, t, MRB_OPSYM(xor), true_xor, MRB_ARGS_REQ(1)); /* 15.2.5.3.3 */ + mrb_define_method_id(mrb, t, MRB_SYM(to_s), true_to_s, MRB_ARGS_NONE()); /* 15.2.5.3.4 */ + mrb_define_method_id(mrb, t, MRB_SYM(inspect), true_to_s, MRB_ARGS_NONE()); - mrb->false_class = f = mrb_define_class(mrb, "FalseClass", mrb->object_class); + mrb->false_class = f = mrb_define_class_id(mrb, MRB_SYM(FalseClass), mrb->object_class); MRB_SET_INSTANCE_TT(f, MRB_TT_FALSE); - mrb_undef_class_method(mrb, f, "new"); - mrb_define_method(mrb, f, "&", false_and, MRB_ARGS_REQ(1)); /* 15.2.6.3.1 */ - mrb_define_method(mrb, f, "^", false_xor, MRB_ARGS_REQ(1)); /* 15.2.6.3.2 */ - mrb_define_method(mrb, f, "to_s", false_to_s, MRB_ARGS_NONE()); /* 15.2.6.3.3 */ - mrb_define_method(mrb, f, "|", false_or, MRB_ARGS_REQ(1)); /* 15.2.6.3.4 */ - mrb_define_method(mrb, f, "inspect", false_to_s, MRB_ARGS_NONE()); + mrb_undef_class_method_id(mrb, f, MRB_SYM(new)); + mrb_define_method_id(mrb, f, MRB_OPSYM(and), false_and, MRB_ARGS_REQ(1)); /* 15.2.6.3.1 */ + mrb_define_method_id(mrb, f, MRB_OPSYM(or), false_or, MRB_ARGS_REQ(1)); /* 15.2.6.3.2 */ + mrb_define_method_id(mrb, f, MRB_OPSYM(xor), false_xor, MRB_ARGS_REQ(1)); /* 15.2.6.3.3 */ + mrb_define_method_id(mrb, f, MRB_SYM(to_s), false_to_s, MRB_ARGS_NONE()); /* 15.2.6.3.4 */ + mrb_define_method_id(mrb, f, MRB_SYM(inspect), false_to_s, MRB_ARGS_NONE()); } static const char* @@ -638,7 +635,7 @@ mrb_check_hash_type(mrb_state *mrb, mrb_value hash) MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj) { - mrb_value v = mrb_funcall_id(mrb, obj, MRB_SYM(inspect), 0); + mrb_value v = mrb_funcall_argv(mrb, obj, MRB_SYM(inspect), 0, NULL); if (!mrb_string_p(v)) { v = mrb_obj_as_string(mrb, obj); } @@ -649,5 +646,6 @@ MRB_API mrb_bool mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2) { if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE; - return mrb_test(mrb_funcall_id(mrb, obj1, MRB_SYM_Q(eql), 1, obj2)); + if (mrb_class(mrb, obj1) != mrb_class(mrb, obj2)) return FALSE; + return mrb_test(mrb_funcall_argv(mrb, obj1, MRB_SYM_Q(eql), 1, &obj2)); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/pool.c b/yass/third_party/nghttp2/third-party/mruby/src/pool.c index ab30be1d86..dbf1336776 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/pool.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/pool.c @@ -63,13 +63,12 @@ struct mrb_pool { MRB_API mrb_pool* mrb_pool_open(mrb_state *mrb) { - mrb_pool *pool = (mrb_pool *)mrb_malloc_simple(mrb, sizeof(mrb_pool)); + mrb_pool *pool = (mrb_pool*)mrb_malloc_simple(mrb, sizeof(mrb_pool)); if (pool) { pool->mrb = mrb; pool->pages = NULL; } - return pool; } @@ -95,7 +94,7 @@ page_alloc(mrb_pool *pool, size_t len) if (len < POOL_PAGE_SIZE) len = POOL_PAGE_SIZE; - page = (struct mrb_pool_page *)mrb_malloc_simple(pool->mrb, sizeof(struct mrb_pool_page)+len); + page = (struct mrb_pool_page*)mrb_malloc_simple(pool->mrb, sizeof(struct mrb_pool_page)+len); if (page) { page->offset = 0; page->len = len; @@ -108,19 +107,16 @@ MRB_API void* mrb_pool_alloc(mrb_pool *pool, size_t len) { struct mrb_pool_page *page; - size_t n; if (!pool) return NULL; len += ALIGN_PADDING(len); - page = pool->pages; - while (page) { + for (page = pool->pages; page; page = page->next) { if (page->offset + len <= page->len) { - n = page->offset; + size_t n = page->offset; page->offset += len; - page->last = (char*)page->page+n; + page->last = (void*)(page->page+n); return page->last; } - page = page->next; } page = page_alloc(pool, len); if (!page) return NULL; @@ -132,53 +128,31 @@ mrb_pool_alloc(mrb_pool *pool, size_t len) return page->last; } -MRB_API mrb_bool -mrb_pool_can_realloc(mrb_pool *pool, void *p, size_t len) -{ - struct mrb_pool_page *page; - - if (!pool) return FALSE; - len += ALIGN_PADDING(len); - page = pool->pages; - while (page) { - if (page->last == p) { - size_t beg; - - beg = (char*)p - page->page; - if (beg + len > page->len) return FALSE; - return TRUE; - } - page = page->next; - } - return FALSE; -} - MRB_API void* mrb_pool_realloc(mrb_pool *pool, void *p, size_t oldlen, size_t newlen) { - struct mrb_pool_page *page; - void *np; - if (!pool) return NULL; + if (newlen < oldlen) return p; oldlen += ALIGN_PADDING(oldlen); newlen += ALIGN_PADDING(newlen); - page = pool->pages; - while (page) { + for (struct mrb_pool_page *page = pool->pages; page; page = page->next) { if (page->last == p) { - size_t beg; - - beg = (char*)p - page->page; + /* if p is a last allocation from the page */ + size_t beg = (char*)p - page->page; + /* check beg + oldlen points bottom */ + /* assert(beg + oldlen == page->offset) */ if (beg + oldlen != page->offset) break; if (beg + newlen > page->len) { + /* new allocation need more space */ + /* abandon this space */ page->offset = beg; break; } page->offset = beg + newlen; return p; } - page = page->next; } - np = mrb_pool_alloc(pool, newlen); + void *np = mrb_pool_alloc(pool, newlen); if (np == NULL) { return NULL; } @@ -197,7 +171,7 @@ main(void) pool = mrb_pool_open(NULL); p = mrb_pool_alloc(pool, len); for (i=1; i<20; i++) { - printf("%p (len=%d) %ud\n", p, len, mrb_pool_can_realloc(pool, p, len*2)); + printf("%p (len=%d)\n", p, len); p = mrb_pool_realloc(pool, p, len, len*2); len *= 2; } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/proc.c b/yass/third_party/nghttp2/third-party/mruby/src/proc.c index c27e6ea7a0..6aca2b84e0 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/proc.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/proc.c @@ -102,6 +102,9 @@ closure_setup(mrb_state *mrb, struct RProc *p) else if (up) { struct RClass *tc = ci->u.target_class; + if (MRB_PROC_ALIAS_P(up)) { /* alias */ + up = up->upper; + } e = mrb_env_new(mrb, mrb->c, ci, up->body.irep->nlocals, ci->stack, tc); ci->u.env = e; if (MRB_PROC_ENV_P(up) && MRB_PROC_ENV(up)->cxt == NULL) { @@ -193,6 +196,29 @@ mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx) return e->stack[idx]; } +mrb_value +mrb_proc_get_self(mrb_state *mrb, struct RProc *p, struct RClass **target_class_p) +{ + if (MRB_PROC_CFUNC_P(p)) { + *target_class_p = mrb->object_class; + return mrb_nil_value(); + } + else { + struct REnv *e = p->e.env; + + if (!e || e->tt != MRB_TT_ENV) { + *target_class_p = mrb->object_class; + return mrb_top_self(mrb); + } + else if (MRB_ENV_LEN(e) < 1) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "self is lost (probably ran out of memory when the block became independent)"); + } + + *target_class_p = e->c; + return e->stack[0]; + } +} + void mrb_proc_copy(mrb_state *mrb, struct RProc *a, struct RProc *b) { @@ -248,13 +274,42 @@ mrb_proc_init_copy(mrb_state *mrb, mrb_value self) return self; } -/* 15.2.17.4.2 */ static mrb_value proc_arity(mrb_state *mrb, mrb_value self) { return mrb_int_value(mrb, mrb_proc_arity(mrb_proc_ptr(self))); } +mrb_bool +mrb_proc_eql(mrb_state *mrb, mrb_value self, mrb_value other) +{ + if (mrb_type(self) != MRB_TT_PROC) return FALSE; + if (mrb_type(other) != MRB_TT_PROC) return FALSE; + + struct RProc *p1 = mrb_proc_ptr(self); + struct RProc *p2 = mrb_proc_ptr(other); + if (MRB_PROC_CFUNC_P(p1)) { + if (!MRB_PROC_CFUNC_P(p1)) return FALSE; + if (p1->body.func != p2->body.func) return FALSE; + } + else if (MRB_PROC_CFUNC_P(p2)) return FALSE; + else if (p1->body.irep != p2->body.irep) return FALSE; + return TRUE; +} + +static mrb_value +proc_eql(mrb_state *mrb, mrb_value self) +{ + return mrb_bool_value(mrb_proc_eql(mrb, self, mrb_get_arg1(mrb))); +} + +static mrb_value +proc_hash(mrb_state *mrb, mrb_value self) +{ + struct RProc *p = mrb_proc_ptr(self); + return mrb_int_value(mrb, (mrb_int)(((intptr_t)p->body.irep)^MRB_TT_PROC)); +} + /* 15.3.1.2.6 */ /* 15.3.1.3.27 */ /* @@ -366,18 +421,13 @@ mrb_proc_get_caller(mrb_state *mrb, struct REnv **envp) if (envp) *envp = NULL; } else { - struct RClass *tc = MRB_PROC_TARGET_CLASS(proc); struct REnv *e = mrb_vm_ci_env(ci); if (e == NULL) { int nstacks = proc->body.irep->nlocals; - e = mrb_env_new(mrb, c, ci, nstacks, ci->stack, tc); + e = mrb_env_new(mrb, c, ci, nstacks, ci->stack, mrb_vm_ci_target_class(ci)); ci->u.env = e; } - else if (tc) { - e->c = tc; - mrb_field_write_barrier(mrb, (struct RBasic*)e, (struct RBasic*)tc); - } if (envp) *envp = e; } @@ -438,15 +488,20 @@ void mrb_init_proc(mrb_state *mrb) { mrb_method_t m; + struct RClass *pc = mrb->proc_class = mrb_define_class_id(mrb, MRB_SYM(Proc), mrb->object_class); /* 15.2.17 */ - mrb_define_class_method(mrb, mrb->proc_class, "new", mrb_proc_s_new, MRB_ARGS_NONE()|MRB_ARGS_BLOCK()); - mrb_define_method(mrb, mrb->proc_class, "initialize_copy", mrb_proc_init_copy, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, mrb->proc_class, "arity", proc_arity, MRB_ARGS_NONE()); + MRB_SET_INSTANCE_TT(pc, MRB_TT_PROC); + MRB_UNDEF_ALLOCATOR(pc); + mrb_define_class_method_id(mrb, pc, MRB_SYM(new), mrb_proc_s_new, MRB_ARGS_NONE()|MRB_ARGS_BLOCK()); + mrb_define_method_id(mrb, pc, MRB_SYM(initialize_copy), mrb_proc_init_copy, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, pc, MRB_SYM(arity), proc_arity, MRB_ARGS_NONE()); /* 15.2.17.4.2 */ + mrb_define_method_id(mrb, pc, MRB_OPSYM(eq), proc_eql, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, pc, MRB_SYM_Q(eql), proc_eql, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, pc, MRB_SYM(hash), proc_hash, MRB_ARGS_NONE()); /* 15.2.17.4.2 */ MRB_METHOD_FROM_PROC(m, &call_proc); - mrb_define_method_raw(mrb, mrb->proc_class, MRB_SYM(call), m); - mrb_define_method_raw(mrb, mrb->proc_class, MRB_OPSYM(aref), m); + mrb_define_method_raw(mrb, pc, MRB_SYM(call), m); /* 15.2.17.4.3 */ + mrb_define_method_raw(mrb, pc, MRB_OPSYM(aref), m); /* 15.2.17.4.1 */ - mrb_define_class_method(mrb, mrb->kernel_module, "lambda", proc_lambda, MRB_ARGS_NONE()|MRB_ARGS_BLOCK()); /* 15.3.1.2.6 */ mrb_define_method(mrb, mrb->kernel_module, "lambda", proc_lambda, MRB_ARGS_NONE()|MRB_ARGS_BLOCK()); /* 15.3.1.3.27 */ } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/range.c b/yass/third_party/nghttp2/third-party/mruby/src/range.c index a81bcd4286..367e4c996b 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/range.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/range.c @@ -70,7 +70,7 @@ static void range_ptr_alloc_edges(mrb_state *mrb, struct RRange *r) { #ifndef MRB_RANGE_EMBED - r->edges = (mrb_range_edges *)mrb_malloc(mrb, sizeof(mrb_range_edges)); + r->edges = (mrb_range_edges*)mrb_malloc(mrb, sizeof(mrb_range_edges)); #endif } @@ -311,7 +311,6 @@ range_eql(mrb_state *mrb, mrb_value range) struct RRange *r, *o; if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value(); - if (!mrb_obj_is_kind_of(mrb, obj, mrb->range_class)) return mrb_false_value(); if (!mrb_range_p(obj)) return mrb_false_value(); r = mrb_range_ptr(mrb, range); @@ -370,8 +369,10 @@ range_num_to_a(mrb_state *mrb, mrb_value range) len++; } ary = mrb_ary_new_capa(mrb, len); + mrb_value *ptr = RARRAY_PTR(ary); for (mrb_int i=0; i b) { + return mrb_ary_new_capa(mrb, 0); + } ary = mrb_ary_new_capa(mrb, (mrb_int)(b - a) + 1); + mrb_value *ptr = RARRAY_PTR(ary); + mrb_int i = 0; if (RANGE_EXCL(r)) { while (a < b) { - mrb_ary_push(mrb, ary, mrb_int_value(mrb, (mrb_int)a)); + ptr[i++] = mrb_int_value(mrb, (mrb_int)a); + ARY_SET_LEN(RARRAY(ary), i); a += 1.0; } } else { while (a <= b) { - mrb_ary_push(mrb, ary, mrb_int_value(mrb, (mrb_int)a)); + ptr[i++] = mrb_int_value(mrb, (mrb_int)a); + ARY_SET_LEN(RARRAY(ary), i); a += 1.0; } } @@ -496,23 +504,23 @@ mrb_init_range(mrb_state *mrb) { struct RClass *r; - r = mrb_define_class(mrb, "Range", mrb->object_class); /* 15.2.14 */ + r = mrb_define_class_id(mrb, MRB_SYM(Range), mrb->object_class); /* 15.2.14 */ mrb->range_class = r; MRB_SET_INSTANCE_TT(r, MRB_TT_RANGE); - mrb_define_method(mrb, r, "begin", range_beg, MRB_ARGS_NONE()); /* 15.2.14.4.3 */ - mrb_define_method(mrb, r, "end", range_end, MRB_ARGS_NONE()); /* 15.2.14.4.5 */ - mrb_define_method(mrb, r, "==", range_eq, MRB_ARGS_REQ(1)); /* 15.2.14.4.1 */ - mrb_define_method(mrb, r, "===", range_include, MRB_ARGS_REQ(1)); /* 15.2.14.4.2 */ - mrb_define_method(mrb, r, "exclude_end?", range_excl, MRB_ARGS_NONE()); /* 15.2.14.4.6 */ - mrb_define_method(mrb, r, "first", range_beg, MRB_ARGS_NONE()); /* 15.2.14.4.7 */ - mrb_define_method(mrb, r, "include?", range_include, MRB_ARGS_REQ(1)); /* 15.2.14.4.8 */ - mrb_define_method(mrb, r, "initialize", range_initialize, MRB_ARGS_ANY()); /* 15.2.14.4.9 */ - mrb_define_method(mrb, r, "last", range_end, MRB_ARGS_NONE()); /* 15.2.14.4.10 */ - mrb_define_method(mrb, r, "member?", range_include, MRB_ARGS_REQ(1)); /* 15.2.14.4.11 */ - mrb_define_method(mrb, r, "to_s", range_to_s, MRB_ARGS_NONE()); /* 15.2.14.4.12(x) */ - mrb_define_method(mrb, r, "inspect", range_inspect, MRB_ARGS_NONE()); /* 15.2.14.4.13(x) */ - mrb_define_method(mrb, r, "eql?", range_eql, MRB_ARGS_REQ(1)); /* 15.2.14.4.14(x) */ - mrb_define_method(mrb, r, "initialize_copy", range_initialize_copy, MRB_ARGS_REQ(1)); /* 15.2.14.4.15(x) */ - mrb_define_method(mrb, r, "__num_to_a", range_num_to_a, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, r, MRB_SYM(begin), range_beg, MRB_ARGS_NONE()); /* 15.2.14.4.3 */ + mrb_define_method_id(mrb, r, MRB_SYM(end), range_end, MRB_ARGS_NONE()); /* 15.2.14.4.5 */ + mrb_define_method_id(mrb, r, MRB_OPSYM(eq), range_eq, MRB_ARGS_REQ(1)); /* 15.2.14.4.1 */ + mrb_define_method_id(mrb, r, MRB_OPSYM(eqq), range_include, MRB_ARGS_REQ(1)); /* 15.2.14.4.2 */ + mrb_define_method_id(mrb, r, MRB_SYM_Q(exclude_end), range_excl, MRB_ARGS_NONE()); /* 15.2.14.4.6 */ + mrb_define_method_id(mrb, r, MRB_SYM(first), range_beg, MRB_ARGS_NONE()); /* 15.2.14.4.7 */ + mrb_define_method_id(mrb, r, MRB_SYM_Q(include), range_include, MRB_ARGS_REQ(1)); /* 15.2.14.4.8 */ + mrb_define_method_id(mrb, r, MRB_SYM(initialize), range_initialize, MRB_ARGS_ANY()); /* 15.2.14.4.9 */ + mrb_define_method_id(mrb, r, MRB_SYM(last), range_end, MRB_ARGS_NONE()); /* 15.2.14.4.10 */ + mrb_define_method_id(mrb, r, MRB_SYM_Q(member), range_include, MRB_ARGS_REQ(1)); /* 15.2.14.4.11 */ + mrb_define_method_id(mrb, r, MRB_SYM(to_s), range_to_s, MRB_ARGS_NONE()); /* 15.2.14.4.12(x) */ + mrb_define_method_id(mrb, r, MRB_SYM(inspect), range_inspect, MRB_ARGS_NONE()); /* 15.2.14.4.13(x) */ + mrb_define_method_id(mrb, r, MRB_SYM_Q(eql), range_eql, MRB_ARGS_REQ(1)); /* 15.2.14.4.14(x) */ + mrb_define_method_id(mrb, r, MRB_SYM(initialize_copy), range_initialize_copy, MRB_ARGS_REQ(1)); /* 15.2.14.4.15(x) */ + mrb_define_method_id(mrb, r, MRB_SYM(__num_to_a), range_num_to_a, MRB_ARGS_NONE()); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/readfloat.c b/yass/third_party/nghttp2/third-party/mruby/src/readfloat.c index a89fcafaa8..80d438ba95 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/readfloat.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/readfloat.c @@ -65,7 +65,7 @@ mrb_read_float(const char *str, char **endp, double *fp) if (ISDIGIT(*p)) { while (*p && ISDIGIT(*p)) { - f += base * (*p - '0') ; + f += base * (*p - '0'); base /= 10.0; p++; n++; diff --git a/yass/third_party/nghttp2/third-party/mruby/src/state.c b/yass/third_party/nghttp2/third-party/mruby/src/state.c index a1065a20aa..ced96cb885 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/state.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/state.c @@ -20,7 +20,7 @@ void mrb_init_mrbgems(mrb_state*); void mrb_gc_init(mrb_state*, mrb_gc *gc); void mrb_gc_destroy(mrb_state*, mrb_gc *gc); -int mrb_core_init_protect(mrb_state *mrb, void (*body)(mrb_state *, void *), void *opaque); +int mrb_core_init_protect(mrb_state *mrb, void (*body)(mrb_state*, void*), void *opaque); static void init_gc_and_core(mrb_state *mrb, void *opaque) @@ -42,7 +42,7 @@ mrb_open_core(mrb_allocf f, void *ud) mrb_state *mrb; if (f == NULL) f = mrb_default_allocf; - mrb = (mrb_state *)(f)(NULL, NULL, sizeof(mrb_state), ud); + mrb = (mrb_state*)(f)(NULL, NULL, sizeof(mrb_state), ud); if (mrb == NULL) return NULL; *mrb = mrb_state_zero; @@ -58,18 +58,6 @@ mrb_open_core(mrb_allocf f, void *ud) return mrb; } -void* -mrb_default_allocf(mrb_state *mrb, void *p, size_t size, void *ud) -{ - if (size == 0) { - free(p); - return NULL; - } - else { - return realloc(p, size); - } -} - MRB_API mrb_state* mrb_open(void) { @@ -207,7 +195,7 @@ mrb_add_irep(mrb_state *mrb) static const mrb_irep mrb_irep_zero = { 0 }; mrb_irep *irep; - irep = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep)); + irep = (mrb_irep*)mrb_malloc(mrb, sizeof(mrb_irep)); *irep = mrb_irep_zero; irep->refcnt = 1; diff --git a/yass/third_party/nghttp2/third-party/mruby/src/string.c b/yass/third_party/nghttp2/third-party/mruby/src/string.c index 3e82b1caa2..b7e3a65045 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/string.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/string.c @@ -29,14 +29,18 @@ const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz"; #define mrb_obj_alloc_string(mrb) MRB_OBJ_ALLOC((mrb), MRB_TT_STRING, (mrb)->string_class) #ifndef MRB_STR_LENGTH_MAX +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) +#define MRB_STR_LENGTH_MAX 0 +#else #define MRB_STR_LENGTH_MAX 1048576 #endif +#endif static void -str_check_too_big(mrb_state *mrb, mrb_int len) +str_check_length(mrb_state *mrb, mrb_int len) { if (len < 0) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "[BUG] negative string length"); + mrb_raise(mrb, E_ARGUMENT_ERROR, "negative (or overflowed) string size"); } #if MRB_STR_LENGTH_MAX != 0 if (len > MRB_STR_LENGTH_MAX-1) { @@ -49,8 +53,8 @@ static struct RString* str_init_normal_capa(mrb_state *mrb, struct RString *s, const char *p, mrb_int len, mrb_int capa) { - str_check_too_big(mrb, capa); - char *dst = (char *)mrb_malloc(mrb, capa + 1); + str_check_length(mrb, capa); + char *dst = (char*)mrb_malloc(mrb, capa + 1); if (p) memcpy(dst, p, len); dst[len] = '\0'; s->as.heap.ptr = dst; @@ -80,7 +84,7 @@ str_init_embed(struct RString *s, const char *p, mrb_int len) static struct RString* str_init_nofree(struct RString *s, const char *p, mrb_int len) { - s->as.heap.ptr = (char *)p; + s->as.heap.ptr = (char*)p; s->as.heap.len = len; s->as.heap.aux.capa = 0; /* nofree */ RSTR_SET_TYPE_FLAG(s, NOFREE); @@ -94,7 +98,7 @@ str_init_shared(mrb_state *mrb, const struct RString *orig, struct RString *s, m shared->refcnt++; } else { - shared = (mrb_shared_string *)mrb_malloc(mrb, sizeof(mrb_shared_string)); + shared = (mrb_shared_string*)mrb_malloc(mrb, sizeof(mrb_shared_string)); shared->refcnt = 1; shared->ptr = orig->as.heap.ptr; shared->capa = orig->as.heap.aux.capa; @@ -137,6 +141,7 @@ str_new_static(mrb_state *mrb, const char *p, mrb_int len) static struct RString* str_new(mrb_state *mrb, const char *p, mrb_int len) { + str_check_length(mrb, len); if (RSTR_EMBEDDABLE_P(len)) { return str_init_embed(mrb_obj_alloc_string(mrb), p, len); } @@ -169,7 +174,7 @@ resize_capa(mrb_state *mrb, struct RString *s, mrb_int capacity) } } else { - str_check_too_big(mrb, capacity); + str_check_length(mrb, capacity); s->as.heap.ptr = (char*)mrb_realloc(mrb, RSTR_PTR(s), capacity+1); s->as.heap.aux.capa = (mrb_ssize)capacity; } @@ -241,7 +246,8 @@ str_modify_keep_ascii(mrb_state *mrb, struct RString *s) static void check_null_byte(mrb_state *mrb, struct RString *str) { - if (memchr(RSTR_PTR(str), '\0', RSTR_LEN(str))) { + const char *p = RSTR_PTR(str); + if (p && memchr(p, '\0', RSTR_LEN(str))) { mrb_raise(mrb, E_ARGUMENT_ERROR, "string contains null byte"); } } @@ -466,11 +472,10 @@ mrb_memsearch_qs(const unsigned char *xs, mrb_int m, const unsigned char *ys, mr else { const unsigned char *x = xs, *xe = xs + m; const unsigned char *y = ys; - int i; ptrdiff_t qstable[256]; /* Preprocessing */ - for (i = 0; i < 256; i++) + for (int i = 0; i < 256; i++) qstable[i] = m + 1; for (; x < xe; x++) qstable[*x] = xe - x; @@ -486,7 +491,7 @@ mrb_memsearch_qs(const unsigned char *xs, mrb_int m, const unsigned char *ys, mr static mrb_int mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n) { - const unsigned char *x = (const unsigned char *)x0, *y = (const unsigned char *)y0; + const unsigned char *x = (const unsigned char*)x0, *y = (const unsigned char*)y0; if (m > n) return -1; else if (m == n) { @@ -496,14 +501,14 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n) return 0; } else if (m == 1) { - const unsigned char *ys = (const unsigned char *)memchr(y, *x, n); + const unsigned char *ys = (const unsigned char*)memchr(y, *x, n); if (ys) return (mrb_int)(ys - y); else return -1; } - return mrb_memsearch_qs((const unsigned char *)x0, m, (const unsigned char *)y0, n); + return mrb_memsearch_qs((const unsigned char*)x0, m, (const unsigned char*)y0, n); } static void @@ -523,7 +528,7 @@ str_share(mrb_state *mrb, struct RString *orig, struct RString *s) } else { if (orig->as.heap.aux.capa > orig->as.heap.len) { - orig->as.heap.ptr = (char *)mrb_realloc(mrb, orig->as.heap.ptr, len+1); + orig->as.heap.ptr = (char*)mrb_realloc(mrb, orig->as.heap.ptr, len+1); orig->as.heap.aux.capa = (mrb_ssize)len; } str_init_shared(mrb, orig, s, NULL); @@ -769,9 +774,7 @@ mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len) mrb_int slen; struct RString *s = mrb_str_ptr(str); - if (len < 0) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "negative (or overflowed) string size"); - } + str_check_length(mrb, len); mrb_str_modify(mrb, s); slen = RSTR_LEN(s); if (len != slen) { @@ -1249,19 +1252,16 @@ str_escape(mrb_state *mrb, mrb_value str, mrb_bool inspect) case 033: cc = 'e'; break; default: cc = 0; break; } + buf[0] = '\\'; if (cc) { - buf[0] = '\\'; buf[1] = (char)cc; mrb_str_cat(mrb, result, buf, 2); - continue; } else { - buf[0] = '\\'; buf[1] = 'x'; buf[3] = mrb_digitmap[c % 16]; c /= 16; buf[2] = mrb_digitmap[c % 16]; mrb_str_cat(mrb, result, buf, 4); - continue; } } mrb_str_cat_lit(mrb, result, "\""); @@ -2369,7 +2369,7 @@ mrb_str_len_to_integer(mrb_state *mrb, const char *str, size_t len, mrb_int base #ifdef MRB_USE_BIGINT p2 = p; #endif - for ( ;p= len2) { + memmove(RSTR_PTR(s)+idx1, RSTRING_PTR(replace)+idx2, len2); + if (len1 > len2) { + memmove(RSTR_PTR(s)+idx1+len2, RSTR_PTR(s)+idx1+len1, RSTR_LEN(s)-(idx1+len1)); + RSTR_SET_LEN(s, RSTR_LEN(s)-(len1-len2)); + } + } + else { /* len1 < len2 */ + mrb_int slen = RSTR_LEN(s); + mrb_str_resize(mrb, str, slen+len2-len1); + memmove(RSTR_PTR(s)+idx1+len2, RSTR_PTR(s)+idx1+len1, slen-(idx1+len1)); + memmove(RSTR_PTR(s)+idx1, RSTRING_PTR(replace)+idx2, len2); + } + return str; +} + +/* + * call-seq: + * bytesplice(index, length, str) -> string + * bytesplice(index, length, str, str_index, str_length) -> string + * bytesplice(range, str) -> string + * bytesplice(range, str, str_range) -> string + * + * Replaces some or all of the content of +self+ with +str+, and returns +self+. + * The portion of the string affected is determined using + * the same criteria as String#byteslice, except that +length+ cannot be omitted. + * If the replacement string is not the same length as the text it is replacing, + * the string will be adjusted accordingly. + * + * If +str_index+ and +str_length+, or +str_range+ are given, the content of +self+ is replaced by str.byteslice(str_index, str_length) or str.byteslice(str_range); however the substring of +str+ is not allocated as a new string. + * + * The form that take an Integer will raise an IndexError if the value is out + * of range; the Range form will raise a RangeError. + * If the beginning or ending offset does not land on character (codepoint) + * boundary, an IndexError will be raised. + */ +static mrb_value +mrb_str_bytesplice(mrb_state *mrb, mrb_value str) +{ + mrb_int idx1, len1, idx2, len2; + mrb_value range1, range2, replace; + switch (mrb_get_argc(mrb)) { + case 3: + mrb_get_args(mrb, "ooo", &range1, &replace, &range2); + if (mrb_integer_p(range1)) { + mrb_get_args(mrb, "iiS", &idx1, &len1, &replace); + return str_bytesplice(mrb, str, idx1, len1, replace, 0, RSTRING_LEN(replace)); + } + mrb_ensure_string_type(mrb, replace); + if (mrb_range_beg_len(mrb, range1, &idx1, &len1, RSTRING_LEN(str), FALSE) != MRB_RANGE_OK) break; + if (mrb_range_beg_len(mrb, range2, &idx2, &len2, RSTRING_LEN(replace), FALSE) != MRB_RANGE_OK) break; + return str_bytesplice(mrb, str, idx1, len1, replace, idx2, len2); + case 5: + mrb_get_args(mrb, "iiSii", &idx1, &len1, &replace, &idx2, &len2); + return str_bytesplice(mrb, str, idx1, len1, replace, idx2, len2); + case 2: + mrb_get_args(mrb, "oS", &range1, &replace); + if (mrb_range_beg_len(mrb, range1, &idx1, &len1, RSTRING_LEN(str), FALSE) == MRB_RANGE_OK) { + return str_bytesplice(mrb, str, idx1, len1, replace, 0, RSTRING_LEN(replace)); + } + default: + break; + } + mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arumgnts"); +} + +static mrb_value +mrb_encoding(mrb_state *mrb, mrb_value self) +{ + mrb_get_args(mrb, ""); +#ifdef MRB_UTF8_STRING + return mrb_str_new_lit(mrb, "UTF-8"); +#else + return mrb_str_new_lit(mrb, "ASCII-8BIT"); +#endif +} + /* ---------------------------*/ void mrb_init_string(mrb_state *mrb) @@ -2954,60 +3057,63 @@ mrb_init_string(mrb_state *mrb) mrb_static_assert(RSTRING_EMBED_LEN_MAX < (1 << MRB_STR_EMBED_LEN_BIT), "pointer size too big for embedded string"); - mrb->string_class = s = mrb_define_class(mrb, "String", mrb->object_class); /* 15.2.10 */ + mrb->string_class = s = mrb_define_class_id(mrb, MRB_SYM(String), mrb->object_class); /* 15.2.10 */ MRB_SET_INSTANCE_TT(s, MRB_TT_STRING); - mrb_define_method(mrb, s, "bytesize", mrb_str_bytesize, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, s, MRB_SYM(bytesize), mrb_str_bytesize, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "<=>", mrb_str_cmp_m, MRB_ARGS_REQ(1)); /* 15.2.10.5.1 */ - mrb_define_method(mrb, s, "==", mrb_str_equal_m, MRB_ARGS_REQ(1)); /* 15.2.10.5.2 */ - mrb_define_method(mrb, s, "+", mrb_str_plus_m, MRB_ARGS_REQ(1)); /* 15.2.10.5.4 */ - mrb_define_method(mrb, s, "*", mrb_str_times, MRB_ARGS_REQ(1)); /* 15.2.10.5.5 */ - mrb_define_method(mrb, s, "[]", mrb_str_aref_m, MRB_ARGS_ANY()); /* 15.2.10.5.6 */ - mrb_define_method(mrb, s, "[]=", mrb_str_aset_m, MRB_ARGS_ANY()); - mrb_define_method(mrb, s, "capitalize", mrb_str_capitalize, MRB_ARGS_NONE()); /* 15.2.10.5.7 */ - mrb_define_method(mrb, s, "capitalize!", mrb_str_capitalize_bang, MRB_ARGS_NONE()); /* 15.2.10.5.8 */ - mrb_define_method(mrb, s, "chomp", mrb_str_chomp, MRB_ARGS_ANY()); /* 15.2.10.5.9 */ - mrb_define_method(mrb, s, "chomp!", mrb_str_chomp_bang, MRB_ARGS_ANY()); /* 15.2.10.5.10 */ - mrb_define_method(mrb, s, "chop", mrb_str_chop, MRB_ARGS_NONE()); /* 15.2.10.5.11 */ - mrb_define_method(mrb, s, "chop!", mrb_str_chop_bang, MRB_ARGS_NONE()); /* 15.2.10.5.12 */ - mrb_define_method(mrb, s, "downcase", mrb_str_downcase, MRB_ARGS_NONE()); /* 15.2.10.5.13 */ - mrb_define_method(mrb, s, "downcase!", mrb_str_downcase_bang, MRB_ARGS_NONE()); /* 15.2.10.5.14 */ - mrb_define_method(mrb, s, "empty?", mrb_str_empty_p, MRB_ARGS_NONE()); /* 15.2.10.5.16 */ - mrb_define_method(mrb, s, "eql?", mrb_str_eql, MRB_ARGS_REQ(1)); /* 15.2.10.5.17 */ + mrb_define_method_id(mrb, s, MRB_OPSYM(cmp), mrb_str_cmp_m, MRB_ARGS_REQ(1)); /* 15.2.10.5.1 */ + mrb_define_method_id(mrb, s, MRB_OPSYM(eq), mrb_str_equal_m, MRB_ARGS_REQ(1)); /* 15.2.10.5.2 */ + mrb_define_method_id(mrb, s, MRB_OPSYM(add), mrb_str_plus_m, MRB_ARGS_REQ(1)); /* 15.2.10.5.4 */ + mrb_define_method_id(mrb, s, MRB_OPSYM(mul), mrb_str_times, MRB_ARGS_REQ(1)); /* 15.2.10.5.5 */ + mrb_define_method_id(mrb, s, MRB_OPSYM(aref), mrb_str_aref_m, MRB_ARGS_ANY()); /* 15.2.10.5.6 */ + mrb_define_method_id(mrb, s, MRB_OPSYM(aset), mrb_str_aset_m, MRB_ARGS_ANY()); + mrb_define_method_id(mrb, s, MRB_SYM(capitalize), mrb_str_capitalize, MRB_ARGS_NONE()); /* 15.2.10.5.7 */ + mrb_define_method_id(mrb, s, MRB_SYM_B(capitalize), mrb_str_capitalize_bang, MRB_ARGS_NONE()); /* 15.2.10.5.8 */ + mrb_define_method_id(mrb, s, MRB_SYM(chomp), mrb_str_chomp, MRB_ARGS_ANY()); /* 15.2.10.5.9 */ + mrb_define_method_id(mrb, s, MRB_SYM_B(chomp), mrb_str_chomp_bang, MRB_ARGS_ANY()); /* 15.2.10.5.10 */ + mrb_define_method_id(mrb, s, MRB_SYM(chop), mrb_str_chop, MRB_ARGS_NONE()); /* 15.2.10.5.11 */ + mrb_define_method_id(mrb, s, MRB_SYM_B(chop), mrb_str_chop_bang, MRB_ARGS_NONE()); /* 15.2.10.5.12 */ + mrb_define_method_id(mrb, s, MRB_SYM(downcase), mrb_str_downcase, MRB_ARGS_NONE()); /* 15.2.10.5.13 */ + mrb_define_method_id(mrb, s, MRB_SYM_B(downcase), mrb_str_downcase_bang, MRB_ARGS_NONE()); /* 15.2.10.5.14 */ + mrb_define_method_id(mrb, s, MRB_SYM_Q(empty), mrb_str_empty_p, MRB_ARGS_NONE()); /* 15.2.10.5.16 */ + mrb_define_method_id(mrb, s, MRB_SYM_Q(eql), mrb_str_eql, MRB_ARGS_REQ(1)); /* 15.2.10.5.17 */ - mrb_define_method(mrb, s, "hash", mrb_str_hash_m, MRB_ARGS_NONE()); /* 15.2.10.5.20 */ - mrb_define_method(mrb, s, "include?", mrb_str_include, MRB_ARGS_REQ(1)); /* 15.2.10.5.21 */ - mrb_define_method(mrb, s, "index", mrb_str_index_m, MRB_ARGS_ARG(1,1)); /* 15.2.10.5.22 */ - mrb_define_method(mrb, s, "initialize", mrb_str_init, MRB_ARGS_REQ(1)); /* 15.2.10.5.23 */ - mrb_define_method(mrb, s, "initialize_copy", mrb_str_replace, MRB_ARGS_REQ(1)); /* 15.2.10.5.24 */ - mrb_define_method(mrb, s, "intern", mrb_str_intern, MRB_ARGS_NONE()); /* 15.2.10.5.25 */ - mrb_define_method(mrb, s, "length", mrb_str_size, MRB_ARGS_NONE()); /* 15.2.10.5.26 */ - mrb_define_method(mrb, s, "replace", mrb_str_replace, MRB_ARGS_REQ(1)); /* 15.2.10.5.28 */ - mrb_define_method(mrb, s, "reverse", mrb_str_reverse, MRB_ARGS_NONE()); /* 15.2.10.5.29 */ - mrb_define_method(mrb, s, "reverse!", mrb_str_reverse_bang, MRB_ARGS_NONE()); /* 15.2.10.5.30 */ - mrb_define_method(mrb, s, "rindex", mrb_str_rindex_m, MRB_ARGS_ANY()); /* 15.2.10.5.31 */ - mrb_define_method(mrb, s, "size", mrb_str_size, MRB_ARGS_NONE()); /* 15.2.10.5.33 */ - mrb_define_method(mrb, s, "slice", mrb_str_aref_m, MRB_ARGS_ANY()); /* 15.2.10.5.34 */ - mrb_define_method(mrb, s, "split", mrb_str_split_m, MRB_ARGS_ANY()); /* 15.2.10.5.35 */ + mrb_define_method_id(mrb, s, MRB_SYM(hash), mrb_str_hash_m, MRB_ARGS_NONE()); /* 15.2.10.5.20 */ + mrb_define_method_id(mrb, s, MRB_SYM_Q(include), mrb_str_include, MRB_ARGS_REQ(1)); /* 15.2.10.5.21 */ + mrb_define_method_id(mrb, s, MRB_SYM(index), mrb_str_index_m, MRB_ARGS_ARG(1,1)); /* 15.2.10.5.22 */ + mrb_define_method_id(mrb, s, MRB_SYM(initialize), mrb_str_init, MRB_ARGS_REQ(1)); /* 15.2.10.5.23 */ + mrb_define_method_id(mrb, s, MRB_SYM(initialize_copy), mrb_str_replace, MRB_ARGS_REQ(1)); /* 15.2.10.5.24 */ + mrb_define_method_id(mrb, s, MRB_SYM(intern), mrb_str_intern, MRB_ARGS_NONE()); /* 15.2.10.5.25 */ + mrb_define_method_id(mrb, s, MRB_SYM(length), mrb_str_size, MRB_ARGS_NONE()); /* 15.2.10.5.26 */ + mrb_define_method_id(mrb, s, MRB_SYM(replace), mrb_str_replace, MRB_ARGS_REQ(1)); /* 15.2.10.5.28 */ + mrb_define_method_id(mrb, s, MRB_SYM(reverse), mrb_str_reverse, MRB_ARGS_NONE()); /* 15.2.10.5.29 */ + mrb_define_method_id(mrb, s, MRB_SYM_B(reverse), mrb_str_reverse_bang, MRB_ARGS_NONE()); /* 15.2.10.5.30 */ + mrb_define_method_id(mrb, s, MRB_SYM(rindex), mrb_str_rindex_m, MRB_ARGS_ANY()); /* 15.2.10.5.31 */ + mrb_define_method_id(mrb, s, MRB_SYM(size), mrb_str_size, MRB_ARGS_NONE()); /* 15.2.10.5.33 */ + mrb_define_method_id(mrb, s, MRB_SYM(slice), mrb_str_aref_m, MRB_ARGS_ANY()); /* 15.2.10.5.34 */ + mrb_define_method_id(mrb, s, MRB_SYM(split), mrb_str_split_m, MRB_ARGS_ANY()); /* 15.2.10.5.35 */ #ifndef MRB_NO_FLOAT - mrb_define_method(mrb, s, "to_f", mrb_str_to_f, MRB_ARGS_NONE()); /* 15.2.10.5.38 */ + mrb_define_method_id(mrb, s, MRB_SYM(to_f), mrb_str_to_f, MRB_ARGS_NONE()); /* 15.2.10.5.38 */ #endif - mrb_define_method(mrb, s, "to_i", mrb_str_to_i, MRB_ARGS_ANY()); /* 15.2.10.5.39 */ - mrb_define_method(mrb, s, "to_s", mrb_str_to_s, MRB_ARGS_NONE()); /* 15.2.10.5.40 */ - mrb_define_method(mrb, s, "to_str", mrb_str_to_s, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "to_sym", mrb_str_intern, MRB_ARGS_NONE()); /* 15.2.10.5.41 */ - mrb_define_method(mrb, s, "upcase", mrb_str_upcase, MRB_ARGS_NONE()); /* 15.2.10.5.42 */ - mrb_define_method(mrb, s, "upcase!", mrb_str_upcase_bang, MRB_ARGS_NONE()); /* 15.2.10.5.43 */ - mrb_define_method(mrb, s, "inspect", mrb_str_inspect, MRB_ARGS_NONE()); /* 15.2.10.5.46(x) */ - mrb_define_method(mrb, s, "bytes", mrb_str_bytes, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, s, MRB_SYM(to_i), mrb_str_to_i, MRB_ARGS_ANY()); /* 15.2.10.5.39 */ + mrb_define_method_id(mrb, s, MRB_SYM(to_s), mrb_str_to_s, MRB_ARGS_NONE()); /* 15.2.10.5.40 */ + mrb_define_method_id(mrb, s, MRB_SYM(to_str), mrb_str_to_s, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, s, MRB_SYM(to_sym), mrb_str_intern, MRB_ARGS_NONE()); /* 15.2.10.5.41 */ + mrb_define_method_id(mrb, s, MRB_SYM(upcase), mrb_str_upcase, MRB_ARGS_NONE()); /* 15.2.10.5.42 */ + mrb_define_method_id(mrb, s, MRB_SYM_B(upcase), mrb_str_upcase_bang, MRB_ARGS_NONE()); /* 15.2.10.5.43 */ + mrb_define_method_id(mrb, s, MRB_SYM(inspect), mrb_str_inspect, MRB_ARGS_NONE()); /* 15.2.10.5.46(x) */ + mrb_define_method_id(mrb, s, MRB_SYM(bytes), mrb_str_bytes, MRB_ARGS_NONE()); - mrb_define_method(mrb, s, "getbyte", mrb_str_getbyte, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, s, "setbyte", mrb_str_setbyte, MRB_ARGS_REQ(2)); - mrb_define_method(mrb, s, "byteindex", mrb_str_byteindex_m, MRB_ARGS_ARG(1,1)); - mrb_define_method(mrb, s, "byterindex", mrb_str_byterindex_m, MRB_ARGS_ARG(1,1)); - mrb_define_method(mrb, s, "byteslice", mrb_str_byteslice, MRB_ARGS_ARG(1,1)); + mrb_define_method_id(mrb, s, MRB_SYM(getbyte), mrb_str_getbyte, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, s, MRB_SYM(setbyte), mrb_str_setbyte, MRB_ARGS_REQ(2)); + mrb_define_method_id(mrb, s, MRB_SYM(byteindex), mrb_str_byteindex_m, MRB_ARGS_ARG(1,1)); + mrb_define_method_id(mrb, s, MRB_SYM(byterindex), mrb_str_byterindex_m, MRB_ARGS_ARG(1,1)); + mrb_define_method_id(mrb, s, MRB_SYM(byteslice), mrb_str_byteslice, MRB_ARGS_ARG(1,1)); + mrb_define_method_id(mrb, s, MRB_SYM(bytesplice), mrb_str_bytesplice, MRB_ARGS_ANY()); - mrb_define_method(mrb, s, "__sub_replace", sub_replace, MRB_ARGS_REQ(3)); /* internal */ + mrb_define_method_id(mrb, s, MRB_SYM(__sub_replace), sub_replace, MRB_ARGS_REQ(3)); /* internal */ + + mrb_define_method_id(mrb, mrb->kernel_module, MRB_SYM(__ENCODING__), mrb_encoding, MRB_ARGS_NONE()); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/symbol.c b/yass/third_party/nghttp2/third-party/mruby/src/symbol.c index c707a9d987..3f0ddb5359 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/symbol.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/symbol.c @@ -82,12 +82,11 @@ sym_inline_pack(const char *name, size_t len) char c; const char *p; - size_t i; mrb_sym sym = 0; if (len > pack_length_max) return 0; /* too long */ if (len == 0) return 0; /* empty string */ - for (i=0; isymflags[i>>3]&(1<<(i&7))) #define sym_lit_set(mrb, i) mrb->symflags[i>>3]|=(1<<(i&7)) #define sym_flags_clear(mrb, i) mrb->symflags[i>>3]&=~(1<<(i&7)) -#define sym_len(mrb, i) (size_t)(sym_lit_p(mrb, i)?strlen(mrb->symtbl[i]):mrb_packed_int_decode(mrb->symtbl[i],NULL)) static mrb_bool sym_check(mrb_state *mrb, const char *name, size_t len, mrb_sym i) @@ -208,15 +206,15 @@ sym_intern(mrb_state *mrb, const char *name, size_t len, mrb_bool lit) mrb->symcapa = symcapa; } sym_flags_clear(mrb, sym); - if ((lit || mrb_ro_data_p(name)) && strlen(name) == len) { + if ((lit || mrb_ro_data_p(name)) && name[len] == 0 && strlen(name) == len) { sym_lit_set(mrb, sym); mrb->symtbl[sym] = name; } else { uint32_t ulen = (uint32_t)len; size_t ilen = mrb_packed_int_len(ulen); - char *p = (char *)mrb_malloc(mrb, len+ilen+1); - mrb_packed_int_encode(ulen, (uint8_t*)p, (uint8_t*)p+ilen); + char *p = (char*)mrb_malloc(mrb, len+ilen+1); + mrb_packed_int_encode(ulen, (uint8_t*)p); memcpy(p+ilen, name, len); p[ilen+len] = 0; mrb->symtbl[sym] = p; @@ -353,7 +351,7 @@ mrb_free_symtbl(mrb_state *mrb) { mrb_sym i, lim; - for (i=1, lim=mrb->symidx+1; isymidx+1; isymtbl[i]); } @@ -692,13 +690,13 @@ mrb_init_symbol(mrb_state *mrb) { struct RClass *sym; - mrb->symbol_class = sym = mrb_define_class(mrb, "Symbol", mrb->object_class); /* 15.2.11 */ + mrb->symbol_class = sym = mrb_define_class_id(mrb, MRB_SYM(Symbol), mrb->object_class); /* 15.2.11 */ MRB_SET_INSTANCE_TT(sym, MRB_TT_SYMBOL); - mrb_undef_class_method(mrb, sym, "new"); + mrb_undef_class_method_id(mrb, sym, MRB_SYM(new)); - mrb_define_method(mrb, sym, "to_s", sym_to_s, MRB_ARGS_NONE()); /* 15.2.11.3.3 */ - mrb_define_method(mrb, sym, "name", sym_name, MRB_ARGS_NONE()); - mrb_define_method(mrb, sym, "to_sym", sym_to_sym, MRB_ARGS_NONE()); /* 15.2.11.3.4 */ - mrb_define_method(mrb, sym, "inspect", sym_inspect, MRB_ARGS_NONE()); /* 15.2.11.3.5(x) */ - mrb_define_method(mrb, sym, "<=>", sym_cmp, MRB_ARGS_REQ(1)); + mrb_define_method_id(mrb, sym, MRB_SYM(to_s), sym_to_s, MRB_ARGS_NONE()); /* 15.2.11.3.3 */ + mrb_define_method_id(mrb, sym, MRB_SYM(name), sym_name, MRB_ARGS_NONE()); + mrb_define_method_id(mrb, sym, MRB_SYM(to_sym), sym_to_sym, MRB_ARGS_NONE()); /* 15.2.11.3.4 */ + mrb_define_method_id(mrb, sym, MRB_SYM(inspect), sym_inspect, MRB_ARGS_NONE()); /* 15.2.11.3.5(x) */ + mrb_define_method_id(mrb, sym, MRB_OPSYM(cmp), sym_cmp, MRB_ARGS_REQ(1)); } diff --git a/yass/third_party/nghttp2/third-party/mruby/src/variable.c b/yass/third_party/nghttp2/third-party/mruby/src/variable.c index be27f0edaa..4c51a8a61c 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/variable.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/variable.c @@ -47,7 +47,6 @@ iv_rehash(mrb_state *mrb, iv_tbl *t) mrb_value *old_ptr = t->ptr; khash_power2(new_alloc); - if (old_alloc == new_alloc) return; t->ptr = (mrb_value*)mrb_calloc(mrb, sizeof(mrb_value)+sizeof(mrb_sym), new_alloc); t->size = 0; @@ -70,7 +69,6 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val) { int hash, pos, start, dpos = -1; - if (t == NULL) return; if (t->alloc == 0) { iv_rehash(mrb, t); } @@ -177,15 +175,13 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp) static void iv_foreach(mrb_state *mrb, iv_tbl *t, mrb_iv_foreach_func *func, void *p) { - int i; - if (t == NULL) return; if (t->alloc == 0) return; if (t->size == 0) return; mrb_sym *keys = (mrb_sym*)&t->ptr[t->alloc]; mrb_value *vals = t->ptr; - for (i=0; ialloc; i++) { + for (int i=0; ialloc; i++) { if (IV_KEY_P(keys[i])) { if ((*func)(mrb, keys[i], vals[i], p) != 0) { return; @@ -209,7 +205,6 @@ static iv_tbl* iv_copy(mrb_state *mrb, iv_tbl *t) { iv_tbl *t2; - int i; if (t == NULL) return NULL; if (t->alloc == 0) return NULL; @@ -218,7 +213,7 @@ iv_copy(mrb_state *mrb, iv_tbl *t) mrb_sym *keys = (mrb_sym*)&t->ptr[t->alloc]; mrb_value *vals = t->ptr; t2 = iv_new(mrb); - for (i=0; ialloc; i++) { + for (int i=0; ialloc; i++) { if (IV_KEY_P(keys[i])) { iv_put(mrb, t2, keys[i], vals[i]); } @@ -327,12 +322,44 @@ mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym) return mrb_nil_value(); } -static inline void assign_class_name(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v); +static inline mrb_bool +namespace_p(enum mrb_vtype tt) +{ + return tt == MRB_TT_CLASS || tt == MRB_TT_MODULE ? TRUE : FALSE; +} + +static inline void +assign_class_name(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) +{ + if (namespace_p(mrb_type(v))) { + struct RObject *c = mrb_obj_ptr(v); + if (obj != c && ISUPPER(mrb_sym_name_len(mrb, sym, NULL)[0])) { + mrb_sym id_classname = MRB_SYM(__classname__); + mrb_value o = mrb_obj_iv_get(mrb, c, id_classname); + + if (mrb_nil_p(o)) { + mrb_sym id_outer = MRB_SYM(__outer__); + o = mrb_obj_iv_get(mrb, c, id_outer); + + if (mrb_nil_p(o)) { + if ((struct RClass*)obj == mrb->object_class) { + mrb_obj_iv_set_force(mrb, c, id_classname, mrb_symbol_value(sym)); + } + else { + mrb_obj_iv_set_force(mrb, c, id_outer, mrb_obj_value(obj)); + } + } + } + } + } +} void mrb_obj_iv_set_force(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) { - assign_class_name(mrb, obj, sym, v); + if (namespace_p(obj->tt)) { + assign_class_name(mrb, obj, sym, v); + } if (!obj->iv) { obj->iv = iv_new(mrb); } @@ -355,38 +382,6 @@ mrb_iv_foreach(mrb_state *mrb, mrb_value obj, mrb_iv_foreach_func *func, void *p iv_foreach(mrb, mrb_obj_ptr(obj)->iv, func, p); } -static inline mrb_bool -namespace_p(enum mrb_vtype tt) -{ - return tt == MRB_TT_CLASS || tt == MRB_TT_MODULE ? TRUE : FALSE; -} - -static inline void -assign_class_name(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) -{ - if (namespace_p(obj->tt) && namespace_p(mrb_type(v))) { - struct RObject *c = mrb_obj_ptr(v); - if (obj != c && ISUPPER(mrb_sym_name_len(mrb, sym, NULL)[0])) { - mrb_sym id_classname = MRB_SYM(__classname__); - mrb_value o = mrb_obj_iv_get(mrb, c, id_classname); - - if (mrb_nil_p(o)) { - mrb_sym id_outer = MRB_SYM(__outer__); - o = mrb_obj_iv_get(mrb, c, id_outer); - - if (mrb_nil_p(o)) { - if ((struct RClass *)obj == mrb->object_class) { - mrb_obj_iv_set_force(mrb, c, id_classname, mrb_symbol_value(sym)); - } - else { - mrb_obj_iv_set_force(mrb, c, id_outer, mrb_obj_value(obj)); - } - } - } - } - } -} - MRB_API void mrb_iv_set(mrb_state *mrb, mrb_value obj, mrb_sym sym, mrb_value v) { @@ -472,12 +467,7 @@ inspect_i(mrb_state *mrb, mrb_sym sym, mrb_value v, void *p) s = mrb_sym_name_len(mrb, sym, &len); mrb_str_cat(mrb, str, s, len); mrb_str_cat_lit(mrb, str, "="); - if (mrb_object_p(v)) { - ins = mrb_any_to_s(mrb, v); - } - else { - ins = mrb_inspect(mrb, v); - } + ins = mrb_inspect(mrb, v); mrb_str_cat_str(mrb, str, ins); return 0; } @@ -497,6 +487,10 @@ mrb_obj_iv_inspect(mrb_state *mrb, struct RObject *obj) mrb_str_cat_lit(mrb, str, ":"); mrb_str_cat_str(mrb, str, mrb_ptr_to_str(mrb, obj)); + if (mrb_inspect_recursive_p(mrb, mrb_obj_value(obj))) { + mrb_str_cat_lit(mrb, str, " ...>"); + return str; + } iv_foreach(mrb, t, inspect_i, &str); mrb_str_cat_lit(mrb, str, ">"); return str; @@ -508,10 +502,11 @@ MRB_API mrb_value mrb_iv_remove(mrb_state *mrb, mrb_value obj, mrb_sym sym) { if (obj_iv_p(obj)) { - iv_tbl *t = mrb_obj_ptr(obj)->iv; + struct RObject *o = mrb_obj_ptr(obj); + iv_tbl *t = o->iv; mrb_value val; - mrb_check_frozen(mrb, mrb_obj_ptr(obj)); + mrb_check_frozen(mrb, o); if (iv_del(mrb, t, sym, &val)) { return val; } @@ -629,7 +624,7 @@ mrb_mod_cv_get(mrb_state *mrb, struct RClass *c, mrb_sym sym) if (cls && cls->tt == MRB_TT_SCLASS) { mrb_value klass; - klass = mrb_obj_iv_get(mrb, (struct RObject *)cls, MRB_SYM(__attached__)); + klass = mrb_obj_iv_get(mrb, (struct RObject*)cls, MRB_SYM(__attached__)); c = mrb_class_ptr(klass); if (c->tt == MRB_TT_CLASS || c->tt == MRB_TT_MODULE) { given = FALSE; @@ -772,26 +767,28 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym, mrb_bool skip) struct RClass *c = base; mrb_value v; mrb_bool retry = FALSE; - mrb_value name; /* if skip then skip the current class (already searched) */ if (skip) c = c->super; L_RETRY: while (c) { - if (!MRB_FLAG_TEST(c, MRB_FL_CLASS_IS_PREPENDED) && c->iv) { - if (iv_get(mrb, c->iv, sym, &v)) - return v; + if (!MRB_FLAG_TEST(c, MRB_FL_CLASS_IS_PREPENDED) && c->iv && iv_get(mrb, c->iv, sym, &v)) { + return v; } c = c->super; if (!skip && c == mrb->object_class) break; } - if (!retry && base->tt == MRB_TT_MODULE) { + if (!retry && base->tt == MRB_TT_MODULE && skip) { c = mrb->object_class; retry = TRUE; goto L_RETRY; } - name = mrb_symbol_value(sym); - return mrb_funcall_argv(mrb, mrb_obj_value(base), MRB_SYM(const_missing), 1, &name); + mrb_value mod = mrb_obj_value(base); + if (mrb_func_basic_p(mrb, mod, MRB_SYM(const_missing), mrb_mod_const_missing)) { + return mrb_const_missing(mrb, mod, sym); + } + mrb_value name = mrb_symbol_value(sym); + return mrb_funcall_argv(mrb, mod, MRB_SYM(const_missing), 1, &name); } MRB_API mrb_value @@ -1137,9 +1134,7 @@ mrb_obj_iv_tbl_memsize(mrb_value obj) mrb_bool mrb_ident_p(const char *s, mrb_int len) { - mrb_int i; - - for (i = 0; i < len; i++) { + for (mrb_int i = 0; i < len; i++) { if (!identchar(s[i])) return FALSE; } return TRUE; diff --git a/yass/third_party/nghttp2/third-party/mruby/src/vm.c b/yass/third_party/nghttp2/third-party/mruby/src/vm.c index 475f02ab12..a5c1dee9cb 100644 --- a/yass/third_party/nghttp2/third-party/mruby/src/vm.c +++ b/yass/third_party/nghttp2/third-party/mruby/src/vm.c @@ -41,9 +41,19 @@ void abort(void); #endif /* Maximum recursive depth. Should be set lower on memory constrained systems. */ +#ifdef __clang__ +#if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__) +#define __SANITIZE_ADDRESS__ +#endif +#endif + #ifndef MRB_CALL_LEVEL_MAX +#if defined(__SANITIZE_ADDRESS__) +#define MRB_CALL_LEVEL_MAX 128 +#else #define MRB_CALL_LEVEL_MAX 512 #endif +#endif /* Maximum stack depth. Should be set lower on memory constrained systems. The value below allows about 60000 recursive calls in the simplest case. */ @@ -65,7 +75,7 @@ mrb_gc_arena_shrink(mrb_state *mrb, int idx) mrb_gc *gc = &mrb->gc; int capa = gc->arena_capa; - mrb->gc.arena_idx = idx; + gc->arena_idx = idx; if (idx < capa / 4) { capa >>= 2; if (capa < MRB_GC_ARENA_SIZE) { @@ -106,11 +116,11 @@ stack_init(mrb_state *mrb) struct mrb_context *c = mrb->c; /* mrb_assert(mrb->stack == NULL); */ - c->stbase = (mrb_value *)mrb_calloc(mrb, STACK_INIT_SIZE, sizeof(mrb_value)); + c->stbase = (mrb_value*)mrb_calloc(mrb, STACK_INIT_SIZE, sizeof(mrb_value)); c->stend = c->stbase + STACK_INIT_SIZE; /* mrb_assert(ci == NULL); */ - c->cibase = (mrb_callinfo *)mrb_calloc(mrb, CALLINFO_INIT_SIZE, sizeof(mrb_callinfo)); + c->cibase = (mrb_callinfo*)mrb_calloc(mrb, CALLINFO_INIT_SIZE, sizeof(mrb_callinfo)); c->ciend = c->cibase + CALLINFO_INIT_SIZE; c->ci = c->cibase; c->ci->u.target_class = mrb->object_class; @@ -121,36 +131,33 @@ static inline void envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t oldsize) { mrb_callinfo *ci = mrb->c->cibase; + ptrdiff_t delta = newbase - oldbase; - if (newbase == oldbase) return; + if (delta == 0) return; while (ci <= mrb->c->ci) { struct REnv *e = mrb_vm_ci_env(ci); mrb_value *st; if (e && MRB_ENV_ONSTACK_P(e) && - (st = e->stack) && oldbase <= st && st < oldbase+oldsize) { - ptrdiff_t off = e->stack - oldbase; - - e->stack = newbase + off; + (st = e->stack) && (size_t)(st - oldbase) < oldsize) { + e->stack += delta; } if (ci->proc && MRB_PROC_ENV_P(ci->proc) && e != MRB_PROC_ENV(ci->proc)) { e = MRB_PROC_ENV(ci->proc); if (e && MRB_ENV_ONSTACK_P(e) && - (st = e->stack) && oldbase <= st && st < oldbase+oldsize) { - ptrdiff_t off = e->stack - oldbase; - - e->stack = newbase + off; + (st = e->stack) && (size_t)(st - oldbase) < oldsize) { + e->stack += delta; } } - ci->stack = newbase + (ci->stack - oldbase); + ci->stack += delta; ci++; } } -/** def rec ; $deep =+ 1 ; if $deep > 1000 ; return 0 ; end ; rec ; end */ +/** def rec; $deep =+ 1; if $deep > 1000; return 0; end; rec; end **/ static void stack_extend_alloc(mrb_state *mrb, mrb_int room) @@ -177,7 +184,7 @@ stack_extend_alloc(mrb_state *mrb, mrb_int room) size += room; #endif - newstack = (mrb_value *)mrb_realloc(mrb, mrb->c->stbase, sizeof(mrb_value) * size); + newstack = (mrb_value*)mrb_realloc(mrb, mrb->c->stbase, sizeof(mrb_value) * size); stack_clear(&(newstack[oldsize]), size - oldsize); envadjust(mrb, oldbase, newstack, oldsize); mrb->c->stbase = newstack; @@ -190,14 +197,20 @@ stack_extend_alloc(mrb_state *mrb, mrb_int room) } } -MRB_API void -mrb_stack_extend(mrb_state *mrb, mrb_int room) +static inline void +stack_extend(mrb_state *mrb, mrb_int room) { if (!mrb->c->ci->stack || mrb->c->ci->stack + room >= mrb->c->stend) { stack_extend_alloc(mrb, room); } } +MRB_API void +mrb_stack_extend(mrb_state *mrb, mrb_int room) +{ + stack_extend(mrb, room); +} + static void stack_extend_adjust(mrb_state *mrb, mrb_int room, const mrb_value **argp) { @@ -205,10 +218,10 @@ stack_extend_adjust(mrb_state *mrb, mrb_int room, const mrb_value **argp) ptrdiff_t voff = *argp - c->stbase; if (voff < 0 || voff >= c->stend - c->stbase) { - mrb_stack_extend(mrb, room); + stack_extend(mrb, room); } else { - mrb_stack_extend(mrb, room); + stack_extend(mrb, room); *argp = c->stbase + voff; } } @@ -252,7 +265,7 @@ top_proc(mrb_state *mrb, const struct RProc *proc) #define CI_PROC_SET(ci, p) do {\ ci->proc = p;\ - ci->pc = (p && !MRB_PROC_CFUNC_P(p)) ? p->body.irep->iseq : NULL;\ + ci->pc = (p && !MRB_PROC_CFUNC_P(p) && !MRB_PROC_ALIAS_P(p) && p->body.irep) ? p->body.irep->iseq : NULL; \ } while (0) void @@ -289,8 +302,8 @@ mrb_vm_ci_env(const mrb_callinfo *ci) return CI_ENV(ci); } -void -mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e) +static inline void +ci_env_set(mrb_callinfo *ci, struct REnv *e) { if (ci->u.env) { if (ci->u.env->tt == MRB_TT_ENV) { @@ -302,11 +315,9 @@ mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e) ci->u.target_class = ci->u.env->c; } } - else { - if (e) { - e->c = ci->u.target_class; - ci->u.env = e; - } + else if (e) { + e->c = ci->u.target_class; + ci->u.env = e; } } else { @@ -314,10 +325,26 @@ mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e) } } -#define CINFO_NONE 0 -#define CINFO_SKIP 1 -#define CINFO_DIRECT 2 -#define CINFO_RESUMED 3 +void +mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e) +{ + ci_env_set(ci, e); +} + +MRB_API void +mrb_vm_ci_env_clear(mrb_state *mrb, mrb_callinfo *ci) +{ + struct REnv *e = ci->u.env; + if (e && e->tt == MRB_TT_ENV) { + ci->u.target_class = e->c; + mrb_env_unshare(mrb, e, FALSE); + } +} + +#define CINFO_NONE 0 // called method from mruby VM (without C functions) +#define CINFO_SKIP 1 // ignited mruby VM from C +#define CINFO_DIRECT 2 // called method from C +#define CINFO_RESUMED 3 // resumed by `Fiber.yield` (probably the main call is `mrb_fiber_resume()`) #define BLK_PTR(b) ((mrb_proc_p(b)) ? mrb_proc_ptr(b) : NULL) @@ -334,7 +361,7 @@ cipush(mrb_state *mrb, mrb_int push_stacks, uint8_t cci, struct RClass *target_c if (size > MRB_CALL_LEVEL_MAX) { mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err)); } - c->cibase = (mrb_callinfo *)mrb_realloc(mrb, c->cibase, sizeof(mrb_callinfo)*size*2); + c->cibase = (mrb_callinfo*)mrb_realloc(mrb, c->cibase, sizeof(mrb_callinfo)*size*2); c->ci = c->cibase + size; c->ciend = c->cibase + size * 2; } @@ -367,8 +394,8 @@ mrb_env_unshare(mrb_state *mrb, struct REnv *e, mrb_bool noraise) } size_t live = mrb->gc.live; - mrb_value *p = (mrb_value *)mrb_malloc_simple(mrb, sizeof(mrb_value)*len); - if (live != mrb->gc.live && mrb_object_dead_p(mrb, (struct RBasic *)e)) { + mrb_value *p = (mrb_value*)mrb_malloc_simple(mrb, sizeof(mrb_value)*len); + if (live != mrb->gc.live && mrb_object_dead_p(mrb, (struct RBasic*)e)) { // The e object is now subject to GC inside mrb_malloc_simple(). // Moreover, if NULL is returned due to mrb_malloc_simple() failure, simply ignore it. mrb_free(mrb, p); @@ -378,7 +405,7 @@ mrb_env_unshare(mrb_state *mrb, struct REnv *e, mrb_bool noraise) stack_copy(p, e->stack, len); e->stack = p; MRB_ENV_CLOSE(e); - mrb_write_barrier(mrb, (struct RBasic *)e); + mrb_write_barrier(mrb, (struct RBasic*)e); return TRUE; } else { @@ -400,7 +427,7 @@ cipop(mrb_state *mrb) mrb_callinfo *ci = c->ci; struct REnv *env = CI_ENV(ci); - mrb_vm_ci_env_set(ci, NULL); // make possible to free by GC if env is not needed + ci_env_set(ci, NULL); // make possible to free env by GC if not needed struct RProc *b = ci->blk; if (b && !mrb_object_dead_p(mrb, (struct RBasic*)b) && b->tt == MRB_TT_PROC && !MRB_PROC_STRICT_P(b) && MRB_PROC_ENV(b) == CI_ENV(&ci[-1])) { @@ -469,7 +496,6 @@ mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, mrb_int argc, ...) { mrb_value argv[MRB_FUNCALL_ARGC_MAX]; va_list ap; - mrb_int i; mrb_sym mid = mrb_intern_cstr(mrb, name); if (argc > MRB_FUNCALL_ARGC_MAX) { @@ -477,7 +503,7 @@ mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, mrb_int argc, ...) } va_start(ap, argc); - for (i = 0; i < argc; i++) { + for (mrb_int i = 0; i < argc; i++) { argv[i] = va_arg(ap, mrb_value); } va_end(ap); @@ -489,14 +515,13 @@ mrb_funcall_id(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc, ...) { mrb_value argv[MRB_FUNCALL_ARGC_MAX]; va_list ap; - mrb_int i; if (argc > MRB_FUNCALL_ARGC_MAX) { mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=" MRB_STRINGIZE(MRB_FUNCALL_ARGC_MAX) ")"); } va_start(ap, argc); - for (i = 0; i < argc; i++) { + for (mrb_int i = 0; i < argc; i++) { argv[i] = va_arg(ap, mrb_value); } va_end(ap); @@ -519,10 +544,16 @@ mrb_bidx(uint8_t n, uint8_t k) return n + 1; /* self + args + kargs */ } +static inline mrb_int +ci_bidx(mrb_callinfo *ci) +{ + return mrb_bidx(ci->n, ci->nk); +} + mrb_int mrb_ci_bidx(mrb_callinfo *ci) { - return mrb_bidx(ci->n, ci->nk); + return ci_bidx(ci); } mrb_int @@ -531,7 +562,7 @@ mrb_ci_nregs(mrb_callinfo *ci) const struct RProc *p; if (!ci) return 4; - mrb_int nregs = mrb_ci_bidx(ci) + 1; /* self + args + kargs + blk */ + mrb_int nregs = ci_bidx(ci) + 1; /* self + args + kargs + blk */ p = ci->proc; if (p && !MRB_PROC_CFUNC_P(p) && p->body.irep && p->body.irep->nregs > nregs) { return p->body.irep->nregs; @@ -564,7 +595,7 @@ prepare_missing(mrb_state *mrb, mrb_callinfo *ci, mrb_value recv, mrb_sym mid, m } m = mrb_vm_find_method(mrb, ci->u.target_class, &ci->u.target_class, missing); if (MRB_METHOD_UNDEF_P(m)) goto method_missing; /* just in case */ - mrb_stack_extend(mrb, 4); + stack_extend(mrb, 4); argv = &ci->stack[1]; /* maybe reallocated */ argv[0] = args; @@ -611,7 +642,7 @@ funcall_args_capture(mrb_state *mrb, int stoff, mrb_int argc, const mrb_value *a } } -static mrb_value +static inline mrb_value ensure_block(mrb_state *mrb, mrb_value blk) { if (!mrb_nil_p(blk) && !mrb_proc_p(blk)) { @@ -635,7 +666,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc mrb->jmp = &c_jmp; /* recursive call */ val = mrb_funcall_with_block(mrb, self, mid, argc, argv, blk); - mrb->jmp = 0; + mrb->jmp = NULL; } MRB_CATCH(&c_jmp) { /* error */ while (nth_ci < (mrb->c->ci - mrb->c->cibase)) { @@ -645,7 +676,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc val = mrb_obj_value(mrb->exc); } MRB_END_EXC(&c_jmp); - mrb->jmp = 0; + mrb->jmp = NULL; } else { mrb_method_t m; @@ -677,6 +708,11 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc cipop(mrb); } else { + /* handle alias */ + if (MRB_PROC_ALIAS_P(ci->proc)) { + ci->mid = ci->proc->body.mid; + ci->proc = ci->proc->upper; + } ci->cci = CINFO_SKIP; val = mrb_run(mrb, ci->proc, self); } @@ -708,26 +744,31 @@ check_method_noarg(mrb_state *mrb, const mrb_callinfo *ci) } static mrb_value -exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p) +exec_irep(mrb_state *mrb, mrb_value self, const struct RProc *p) { mrb_callinfo *ci = mrb->c->ci; mrb_int keep, nregs; ci->stack[0] = self; + /* handle alias */ + if (MRB_PROC_ALIAS_P(p)) { + ci->mid = p->body.mid; + p = p->upper; + } CI_PROC_SET(ci, p); if (MRB_PROC_CFUNC_P(p)) { - if (MRB_PROC_NOARG_P(p)) { + if (MRB_PROC_NOARG_P(p) && (ci->n > 0 || ci->nk > 0)) { check_method_noarg(mrb, ci); } return MRB_PROC_CFUNC(p)(mrb, self); } nregs = p->body.irep->nregs; - keep = mrb_ci_bidx(ci)+1; + keep = ci_bidx(ci)+1; if (nregs < keep) { - mrb_stack_extend(mrb, keep); + stack_extend(mrb, keep); } else { - mrb_stack_extend(mrb, nregs); + stack_extend(mrb, nregs); stack_clear(ci->stack+keep, nregs-keep); } @@ -746,7 +787,7 @@ mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p) else { mrb_value ret; if (MRB_PROC_CFUNC_P(p)) { - if (MRB_PROC_NOARG_P(p)) { + if (MRB_PROC_NOARG_P(p) && (ci->n > 0 || ci->nk > 0)) { check_method_noarg(mrb, ci); } cipush(mrb, 0, CINFO_DIRECT, CI_TARGET_CLASS(ci), p, NULL, ci->mid, ci->n|(ci->nk<<4)); @@ -754,7 +795,7 @@ mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p) cipop(mrb); } else { - mrb_int keep = mrb_ci_bidx(ci) + 1; /* receiver + block */ + mrb_int keep = ci_bidx(ci) + 1; /* receiver + block */ ret = mrb_top_run(mrb, p, self, keep); } if (mrb->exc && mrb->jmp) { @@ -838,18 +879,23 @@ mrb_f_send(mrb_state *mrb, mrb_value self) ci->n--; } - if (MRB_METHOD_CFUNC_P(m)) { - if (MRB_METHOD_NOARG_P(m)) { - check_method_noarg(mrb, ci); + const struct RProc *p; + if (MRB_METHOD_PROC_P(m)) { + p = MRB_METHOD_PROC(m); + /* handle alias */ + if (MRB_PROC_ALIAS_P(p)) { + ci->mid = p->body.mid; + p = p->upper; } - - if (MRB_METHOD_PROC_P(m)) { - const struct RProc *p = MRB_METHOD_PROC(m); - CI_PROC_SET(ci, p); + CI_PROC_SET(ci, p); + } + if (MRB_METHOD_CFUNC_P(m)) { + if (MRB_METHOD_NOARG_P(m) && (ci->n > 0 || ci->nk > 0)) { + check_method_noarg(mrb, ci); } return MRB_METHOD_CFUNC(m)(mrb, self); } - return exec_irep(mrb, self, MRB_METHOD_PROC(m)); + return exec_irep(mrb, self, p); } static void @@ -877,12 +923,14 @@ eval_under(mrb_state *mrb, mrb_value self, mrb_value blk, struct RClass *c) } ci->u.target_class = c; p = mrb_proc_ptr(blk); + /* just in case irep is NULL; #6065 */ + if (p->body.irep == NULL) return mrb_nil_value(); CI_PROC_SET(ci, p); ci->n = 1; ci->nk = 0; ci->mid = ci[-1].mid; if (MRB_PROC_CFUNC_P(p)) { - mrb_stack_extend(mrb, 4); + stack_extend(mrb, 4); mrb->c->ci->stack[0] = self; mrb->c->ci->stack[1] = self; mrb->c->ci->stack[2] = mrb_nil_value(); @@ -890,7 +938,7 @@ eval_under(mrb_state *mrb, mrb_value self, mrb_value blk, struct RClass *c) } nregs = p->body.irep->nregs; if (nregs < 4) nregs = 4; - mrb_stack_extend(mrb, nregs); + stack_extend(mrb, nregs); mrb->c->ci->stack[0] = self; mrb->c->ci->stack[1] = self; stack_clear(mrb->c->ci->stack+2, nregs-2); @@ -956,7 +1004,7 @@ MRB_API mrb_value mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv, mrb_value self, struct RClass *c) { struct RProc *p; - mrb_sym mid = mrb->c->ci->mid; + mrb_sym mid; mrb_callinfo *ci; mrb_value val; mrb_int n; @@ -965,10 +1013,15 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value ci = mrb->c->ci; n = mrb_ci_nregs(ci); p = mrb_proc_ptr(b); - ci = cipush(mrb, n, CINFO_DIRECT, NULL, NULL, NULL, 0, 0); + if (MRB_PROC_ENV_P(p)) { + mid = p->e.env->mid; + } + else { + mid = ci->mid; + } + ci = cipush(mrb, n, CINFO_DIRECT, NULL, NULL, NULL, mid, 0); funcall_args_capture(mrb, 0, argc, argv, mrb_nil_value(), ci); ci->u.target_class = c; - ci->mid = mid; ci->proc = p; if (MRB_PROC_CFUNC_P(p)) { @@ -987,16 +1040,20 @@ MRB_API mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv) { struct RProc *p = mrb_proc_ptr(b); + struct RClass *tc; + mrb_value self = mrb_proc_get_self(mrb, p, &tc); - return mrb_yield_with_class(mrb, b, argc, argv, MRB_PROC_ENV(p)->stack[0], MRB_PROC_TARGET_CLASS(p)); + return mrb_yield_with_class(mrb, b, argc, argv, self, tc); } MRB_API mrb_value mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg) { struct RProc *p = mrb_proc_ptr(b); + struct RClass *tc; + mrb_value self = mrb_proc_get_self(mrb, p, &tc); - return mrb_yield_with_class(mrb, b, 1, &arg, MRB_PROC_ENV(p)->stack[0], MRB_PROC_TARGET_CLASS(p)); + return mrb_yield_with_class(mrb, b, 1, &arg, self, tc); } mrb_value @@ -1020,13 +1077,8 @@ mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const #define RBREAK_TAG_FOREACH(f) \ f(RBREAK_TAG_BREAK, 0) \ - f(RBREAK_TAG_BREAK_UPPER, 1) \ - f(RBREAK_TAG_BREAK_INTARGET, 2) \ - f(RBREAK_TAG_RETURN_BLOCK, 3) \ - f(RBREAK_TAG_RETURN, 4) \ - f(RBREAK_TAG_RETURN_TOPLEVEL, 5) \ - f(RBREAK_TAG_JUMP, 6) \ - f(RBREAK_TAG_STOP, 7) + f(RBREAK_TAG_JUMP, 1) \ + f(RBREAK_TAG_STOP, 2) #define RBREAK_TAG_DEFINE(tag, i) tag = i, enum { @@ -1052,12 +1104,12 @@ mrb_break_tag_set(struct RBreak *brk, uint32_t tag) } static struct RBreak* -break_new(mrb_state *mrb, uint32_t tag, const struct RProc *p, mrb_value val) +break_new(mrb_state *mrb, uint32_t tag, const mrb_callinfo *return_ci, mrb_value val) { - struct RBreak *brk; + mrb_assert((size_t)(return_ci - mrb->c->cibase) <= (size_t)(mrb->c->ci - mrb->c->cibase)); - brk = MRB_OBJ_ALLOC(mrb, MRB_TT_BREAK, NULL); - mrb_break_proc_set(brk, p); + struct RBreak *brk = MRB_OBJ_ALLOC(mrb, MRB_TT_BREAK, NULL); + brk->ci_break_index = return_ci - mrb->c->cibase; mrb_break_value_set(brk, val); mrb_break_tag_set(brk, tag); @@ -1069,9 +1121,8 @@ break_new(mrb_state *mrb, uint32_t tag, const struct RProc *p, mrb_value val) #define MRB_CATCH_FILTER_ALL (MRB_CATCH_FILTER_RESCUE | MRB_CATCH_FILTER_ENSURE) static const struct mrb_irep_catch_handler * -catch_handler_find(mrb_state *mrb, mrb_callinfo *ci, const mrb_code *pc, uint32_t filter) +catch_handler_find(const mrb_irep *irep, const mrb_code *pc, uint32_t filter) { - const mrb_irep *irep; ptrdiff_t xpc; size_t cnt; const struct mrb_irep_catch_handler *e; @@ -1079,9 +1130,7 @@ catch_handler_find(mrb_state *mrb, mrb_callinfo *ci, const mrb_code *pc, uint32_ /* The comparison operators use `>` and `<=` because pc already points to the next instruction */ #define catch_cover_p(pc, beg, end) ((pc) > (ptrdiff_t)(beg) && (pc) <= (ptrdiff_t)(end)) - if (ci->proc == NULL || MRB_PROC_CFUNC_P(ci->proc)) return NULL; - irep = ci->proc->body.irep; - if (irep->clen < 1) return NULL; + mrb_assert(irep && irep->clen > 0); xpc = pc - irep->iseq; /* If it retry at the top level, pc will be 0, so check with -1 as the start position */ mrb_assert(catch_cover_p(xpc, -1, irep->ilen)); @@ -1090,7 +1139,7 @@ catch_handler_find(mrb_state *mrb, mrb_callinfo *ci, const mrb_code *pc, uint32_ /* Currently uses a simple linear search to avoid processing complexity. */ cnt = irep->clen; e = mrb_irep_catch_handler_table(irep) + cnt - 1; - for (; cnt > 0; cnt --, e --) { + for (; cnt > 0; cnt--, e--) { if (((UINT32_C(1) << e->type) & filter) && catch_cover_p(xpc, mrb_irep_catch_handler_unpack(e->begin), mrb_irep_catch_handler_unpack(e->end))) { return e; @@ -1161,27 +1210,27 @@ break_tag_p(struct RBreak *brk, uint32_t tag) } static void -prepare_tagged_break(mrb_state *mrb, uint32_t tag, const struct RProc *proc, mrb_value val) +prepare_tagged_break(mrb_state *mrb, uint32_t tag, const mrb_callinfo *return_ci, mrb_value val) { if (break_tag_p((struct RBreak*)mrb->exc, tag)) { mrb_break_tag_set((struct RBreak*)mrb->exc, tag); } else { - mrb->exc = (struct RObject*)break_new(mrb, tag, proc, val); + mrb->exc = (struct RObject*)break_new(mrb, tag, return_ci, val); } } -#define THROW_TAGGED_BREAK(mrb, tag, proc, val) \ +#define THROW_TAGGED_BREAK(mrb, tag, return_ci, val) \ do { \ - prepare_tagged_break(mrb, tag, proc, val); \ + prepare_tagged_break(mrb, tag, return_ci, val); \ goto L_CATCH_TAGGED_BREAK; \ } while (0) -#define UNWIND_ENSURE(mrb, ci, pc, tag, proc, val) \ +#define UNWIND_ENSURE(mrb, ci, pc, tag, return_ci, val) \ do { \ - ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ENSURE); \ - if (ch) { \ - THROW_TAGGED_BREAK(mrb, tag, proc, val); \ + if ((proc = (ci)->proc) && !MRB_PROC_CFUNC_P(proc) && (irep = proc->body.irep) && irep->clen > 0 && \ + (ch = catch_handler_find(irep, pc, MRB_CATCH_FILTER_ENSURE))) { \ + THROW_TAGGED_BREAK(mrb, tag, return_ci, val); \ } \ } while (0) @@ -1230,13 +1279,13 @@ prepare_tagged_break(mrb_state *mrb, uint32_t tag, const struct RProc *proc, mrb #define BYTECODE_DECODER(x) (x) #endif -#ifndef MRB_NO_DIRECT_THREADING -#if defined __GNUC__ || defined __clang__ || defined __INTEL_COMPILER -#define DIRECT_THREADED +#ifndef MRB_USE_VM_SWITCH_DISPATCH +#if !defined __GNUC__ && !defined __clang__ && !defined __INTEL_COMPILER +#define MRB_USE_VM_SWITCH_DISPATCH #endif -#endif /* ifndef MRB_NO_DIRECT_THREADING */ +#endif /* ifndef MRB_USE_VM_SWITCH_DISPATCH */ -#ifndef DIRECT_THREADED +#ifdef MRB_USE_VM_SWITCH_DISPATCH #define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (insn) { #define CASE(insn,ops) case insn: pc++; FETCH_ ## ops (); mrb->c->ci->pc = pc; L_ ## insn ## _BODY: @@ -1272,11 +1321,11 @@ mrb_vm_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int sta else { struct REnv *e = CI_ENV(mrb->c->ci); if (stack_keep == 0 || (e && irep->nlocals < MRB_ENV_LEN(e))) { - mrb_vm_ci_env_set(mrb->c->ci, NULL); + ci_env_set(mrb->c->ci, NULL); mrb_env_unshare(mrb, e, FALSE); } } - mrb_stack_extend(mrb, nregs); + stack_extend(mrb, nregs); stack_clear(c->ci->stack + stack_keep, nregs - stack_keep); c->ci->stack[0] = self; result = mrb_vm_exec(mrb, proc, irep->iseq); @@ -1315,16 +1364,7 @@ hash_new_from_regs(mrb_state *mrb, mrb_int argc, mrb_int idx) return hash; } -static mrb_value -ary_new_from_regs(mrb_state *mrb, mrb_int argc, mrb_int idx) -{ - mrb_value ary = mrb_ary_new_capa(mrb, argc); - while (argc--) { - mrb_ary_push(mrb, ary, regs[idx]); - idx++; - } - return ary; -} +#define ary_new_from_regs(mrb, argc, idx) mrb_ary_new_from_values(mrb, (argc), ®s[idx]); MRB_API mrb_value mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc) @@ -1343,7 +1383,7 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc) mrb_sym mid; const struct mrb_irep_catch_handler *ch; -#ifdef DIRECT_THREADED +#ifndef MRB_USE_VM_SWITCH_DISPATCH static const void * const optable[] = { #define OPCODE(x,_) &&L_OP_ ## x, #include "mruby/ops.h" @@ -1526,7 +1566,15 @@ RETRY_TRY_BLOCK: switch (mrb_type(va)) { case MRB_TT_ARRAY: if (!mrb_integer_p(vb)) goto getidx_fallback; - regs[a] = mrb_ary_entry(va, mrb_integer(vb)); + else { + mrb_int idx = mrb_integer(vb); + if (0 <= idx && idx < RARRAY_LEN(va)) { + regs[a] = RARRAY_PTR(va)[idx]; + } + else { + regs[a] = mrb_ary_entry(va, idx); + } + } break; case MRB_TT_HASH: va = mrb_hash_get(mrb, va, vb); @@ -1582,14 +1630,13 @@ RETRY_TRY_BLOCK: } CASE(OP_GETUPVAR, BBB) { - mrb_value *regs_a = regs + a; struct REnv *e = uvenv(mrb, c); if (e && b < MRB_ENV_LEN(e)) { - *regs_a = e->stack[b]; + regs[a] = e->stack[b]; } else { - *regs_a = mrb_nil_value(); + regs[a] = mrb_nil_value(); } NEXT; } @@ -1598,10 +1645,8 @@ RETRY_TRY_BLOCK: struct REnv *e = uvenv(mrb, c); if (e) { - mrb_value *regs_a = regs + a; - if (b < MRB_ENV_LEN(e)) { - e->stack[b] = *regs_a; + e->stack[b] = regs[a]; mrb_write_barrier(mrb, (struct RBasic*)e); } } @@ -1644,11 +1689,11 @@ RETRY_TRY_BLOCK: mrb_assert(a >= 0 && a < irep->ilen); } CHECKPOINT_MAIN(RBREAK_TAG_JUMP) { - ch = catch_handler_find(mrb, mrb->c->ci, pc, MRB_CATCH_FILTER_ENSURE); - if (ch) { + if (irep->clen > 0 && + (ch = catch_handler_find(irep, pc, MRB_CATCH_FILTER_ENSURE))) { /* avoiding a jump from a catch handler into the same handler */ if (a < mrb_irep_catch_handler_unpack(ch->begin) || a >= mrb_irep_catch_handler_unpack(ch->end)) { - THROW_TAGGED_BREAK(mrb, RBREAK_TAG_JUMP, proc, mrb_fixnum_value(a)); + THROW_TAGGED_BREAK(mrb, RBREAK_TAG_JUMP, mrb->c->ci, mrb_fixnum_value(a)); } } } @@ -1699,14 +1744,67 @@ RETRY_TRY_BLOCK: } CASE(OP_RAISEIF, B) { - mrb_value exc = regs[a]; - if (mrb_break_p(exc)) { - mrb->exc = mrb_obj_ptr(exc); - goto L_BREAK; + mrb_value exc; + exc = regs[a]; + if (mrb_nil_p(exc)) { + mrb->exc = NULL; } - mrb_exc_set(mrb, exc); - if (mrb->exc) { - goto L_RAISE; + else if (mrb_break_p(exc)) { + struct RBreak *brk; + mrb->exc = mrb_obj_ptr(exc); + L_BREAK: + brk = (struct RBreak*)mrb->exc; + switch (mrb_break_tag_get(brk)) { +#define DISPATCH_CHECKPOINTS(n, i) case n: goto CHECKPOINT_LABEL_MAKE(n); + RBREAK_TAG_FOREACH(DISPATCH_CHECKPOINTS) +#undef DISPATCH_CHECKPOINTS + default: + mrb_assert(!"wrong break tag"); + } + } + else { + mrb_callinfo *ci; + mrb_exc_set(mrb, exc); + L_RAISE: + ci = mrb->c->ci; + while (!(proc = ci->proc) || MRB_PROC_CFUNC_P(ci->proc) || !(irep = proc->body.irep) || irep->clen < 1 || + (ch = catch_handler_find(irep, ci->pc, MRB_CATCH_FILTER_ALL)) == NULL) { + if (ci != mrb->c->cibase) { + ci = cipop(mrb); + if (ci[1].cci == CINFO_SKIP) { + mrb_assert(prev_jmp != NULL); + mrb->jmp = prev_jmp; + MRB_THROW(prev_jmp); + } + } + else if (mrb->c == mrb->root_c) { + mrb->c->ci->stack = mrb->c->stbase; + goto L_STOP; + } + else { + struct mrb_context *c = mrb->c; + + c->status = MRB_FIBER_TERMINATED; + mrb->c = c->prev; + if (!mrb->c) mrb->c = mrb->root_c; + else c->prev = NULL; + if (!c->vmexec) goto L_RAISE; + mrb->jmp = prev_jmp; + if (!prev_jmp) return mrb_obj_value(mrb->exc); + MRB_THROW(prev_jmp); + } + } + + if (FALSE) { + L_CATCH_TAGGED_BREAK: /* from THROW_TAGGED_BREAK() or UNWIND_ENSURE() */ + ci = mrb->c->ci; + } + proc = ci->proc; + irep = proc->body.irep; + pool = irep->pool; + syms = irep->syms; + stack_extend(mrb, irep->nregs); + pc = irep->iseq + mrb_irep_catch_handler_unpack(ch->target); } NEXT; } @@ -1742,6 +1840,7 @@ RETRY_TRY_BLOCK: int n = c&0xf; int nk = (c>>4)&0xf; mrb_int bidx = a + mrb_bidx(n,nk); + mrb_int new_bidx = bidx; if (nk == CALL_MAXARGS) { mrb_ensure_hash_type(mrb, regs[a+(n==CALL_MAXARGS?1:n)+1]); @@ -1752,10 +1851,10 @@ RETRY_TRY_BLOCK: regs[kidx] = kdict; nk = CALL_MAXARGS; c = n | (nk<<4); + new_bidx = a+mrb_bidx(n, nk); } mrb_assert(bidx < irep->nregs); - mrb_int new_bidx = a+mrb_bidx(n, nk); if (insn == OP_SEND) { /* clear block argument */ SET_NIL_VALUE(regs[new_bidx]); @@ -1777,69 +1876,84 @@ RETRY_TRY_BLOCK: ci->mid = mid; } ci->cci = CINFO_NONE; - if (!mrb_nil_p(blk)) ci->blk = mrb_proc_ptr(blk); - if (MRB_METHOD_CFUNC_P(m)) { - if (MRB_METHOD_PROC_P(m)) { - struct RProc *p = MRB_METHOD_PROC(m); - CI_PROC_SET(ci, p); - recv = p->body.func(mrb, recv); + if (MRB_METHOD_PROC_P(m)) { + const struct RProc *p = MRB_METHOD_PROC(m); + /* handle alias */ + if (MRB_PROC_ALIAS_P(p)) { + ci->mid = p->body.mid; + p = p->upper; + } + CI_PROC_SET(ci, p); + if (!MRB_PROC_CFUNC_P(p)) { + /* setup environment for calling method */ + proc = p; + irep = proc->body.irep; + pool = irep->pool; + syms = irep->syms; + stack_extend(mrb, (irep->nregs < 4) ? 4 : irep->nregs); + pc = irep->iseq; + JUMP; } else { - if (MRB_METHOD_NOARG_P(m)) { + if (MRB_PROC_NOARG_P(p) && (ci->n > 0 || ci->nk > 0)) { check_method_noarg(mrb, ci); } - recv = MRB_METHOD_FUNC(m)(mrb, recv); + recv = MRB_PROC_CFUNC(p)(mrb, recv); } - mrb_gc_arena_shrink(mrb, ai); - if (mrb->exc) goto L_RAISE; - ci = mrb->c->ci; - if (!ci->u.target_class) { /* return from context modifying method (resume/yield) */ - if (ci->cci == CINFO_RESUMED) { - mrb->jmp = prev_jmp; - return recv; - } - else { - mrb_assert(!MRB_PROC_CFUNC_P(ci[-1].proc)); - proc = ci[-1].proc; - irep = proc->body.irep; - pool = irep->pool; - syms = irep->syms; - } - } - ci->stack[0] = recv; - /* pop stackpos */ - ci = cipop(mrb); - pc = ci->pc; } else { - /* setup environment for calling method */ - proc = MRB_METHOD_PROC(m); - CI_PROC_SET(ci, proc); - irep = proc->body.irep; - pool = irep->pool; - syms = irep->syms; - mrb_stack_extend(mrb, (irep->nregs < 4) ? 4 : irep->nregs); - pc = irep->iseq; + if (MRB_METHOD_NOARG_P(m) && (ci->n > 0 || ci->nk > 0)) { + check_method_noarg(mrb, ci); + } + recv = MRB_METHOD_FUNC(m)(mrb, recv); } + + /* cfunc epilogue */ + mrb_assert(mrb->c->ci > mrb->c->cibase); + mrb_gc_arena_shrink(mrb, ai); + if (mrb->exc) goto L_RAISE; + ci = mrb->c->ci; + if (!ci->u.target_class) { /* return from context modifying method (resume/yield) */ + if (ci->cci == CINFO_RESUMED) { + mrb->jmp = prev_jmp; + return recv; + } + else { + mrb_assert(!MRB_PROC_CFUNC_P(ci[-1].proc)); + proc = ci[-1].proc; + irep = proc->body.irep; + pool = irep->pool; + syms = irep->syms; + } + } + ci->stack[0] = recv; + /* pop stackpos */ + ci = cipop(mrb); + pc = ci->pc; + JUMP; } - JUMP; CASE(OP_CALL, Z) { mrb_callinfo *ci = mrb->c->ci; mrb_value recv = ci->stack[0]; - struct RProc *m = mrb_proc_ptr(recv); + const struct RProc *p = mrb_proc_ptr(recv); - /* replace callinfo */ - ci->u.target_class = MRB_PROC_TARGET_CLASS(m); - CI_PROC_SET(ci, m); - if (MRB_PROC_ENV_P(m)) { - ci->mid = MRB_PROC_ENV(m)->mid; + /* handle alias */ + if (MRB_PROC_ALIAS_P(p)) { + ci->mid = p->body.mid; + p = p->upper; } + else if (MRB_PROC_ENV_P(p)) { + ci->mid = MRB_PROC_ENV(p)->mid; + } + /* replace callinfo */ + ci->u.target_class = MRB_PROC_TARGET_CLASS(p); + CI_PROC_SET(ci, p); /* prepare stack */ - if (MRB_PROC_CFUNC_P(m)) { - recv = MRB_PROC_CFUNC(m)(mrb, recv); + if (MRB_PROC_CFUNC_P(p)) { + recv = MRB_PROC_CFUNC(p)(mrb, recv); mrb_gc_arena_shrink(mrb, ai); if (mrb->exc) goto L_RAISE; /* pop stackpos */ @@ -1850,21 +1964,20 @@ RETRY_TRY_BLOCK: } else { /* setup environment for calling method */ - proc = m; - irep = m->body.irep; + proc = p; + irep = p->body.irep; if (!irep) { mrb->c->ci->stack[0] = mrb_nil_value(); a = 0; - c = OP_R_NORMAL; goto L_OP_RETURN_BODY; } - mrb_int nargs = mrb_ci_bidx(ci)+1; + mrb_int nargs = ci_bidx(ci)+1; if (nargs < irep->nregs) { - mrb_stack_extend(mrb, irep->nregs); + stack_extend(mrb, irep->nregs); stack_clear(regs+nargs, irep->nregs-nargs); } - if (MRB_PROC_ENV_P(m)) { - regs[0] = MRB_PROC_ENV(m)->stack[0]; + if (MRB_PROC_ENV_P(p)) { + regs[0] = MRB_PROC_ENV(p)->stack[0]; } pc = irep->iseq; } @@ -1876,14 +1989,9 @@ RETRY_TRY_BLOCK: CASE(OP_SUPER, BB) { mrb_callinfo *ci = mrb->c->ci; mrb_value recv; - const struct RProc *p = ci->proc; struct RClass* target_class = CI_TARGET_CLASS(ci); mid = ci->mid; - if (MRB_PROC_ENV_P(p) && p->e.env->mid && p->e.env->mid != mid) { /* alias support */ - mid = p->e.env->mid; /* restore old mid */ - } - if (mid == 0 || !target_class) { RAISE_LIT(mrb, E_NOMETHOD_ERROR, "super called outside of method"); } @@ -1968,7 +2076,7 @@ RETRY_TRY_BLOCK: /* no other args */ if ((a & ~0x7c0001) == 0 && argc < 15 && MRB_PROC_STRICT_P(proc)) { - if (argc != m1) { + if (argc+(ci->nk==15) != m1) { /* count kdict too */ argnum_error(mrb, m1); goto L_RAISE; } @@ -1990,7 +2098,7 @@ RETRY_TRY_BLOCK: mrb_int const len = m1 + o + r + m2; mrb_value * const argv0 = argv; - mrb_value blk = regs[mrb_ci_bidx(ci)]; + mrb_value blk = regs[ci_bidx(ci)]; mrb_value kdict = mrb_nil_value(); /* keyword arguments */ @@ -2019,6 +2127,9 @@ RETRY_TRY_BLOCK: else if (MRB_ASPEC_KEY(a) > 0 && !mrb_nil_p(kdict)) { kdict = mrb_hash_dup(mrb, kdict); } + else if (!mrb_nil_p(kdict)) { + mrb_gc_protect(mrb, kdict); + } /* arguments is passed with Array */ if (argc == 15) { @@ -2026,7 +2137,6 @@ RETRY_TRY_BLOCK: argv = ARY_PTR(ary); argc = (int)ARY_LEN(ary); mrb_gc_protect(mrb, regs[1]); - if (kd && !mrb_nil_p(kdict)) mrb_gc_protect(mrb, kdict); } /* strict argument check */ @@ -2077,6 +2187,7 @@ RETRY_TRY_BLOCK: else { mrb_int rnum = 0; if (argv0 != argv) { + mrb_gc_protect(mrb, blk); value_move(®s[1], argv, m1+o); } if (r) { @@ -2093,11 +2204,12 @@ RETRY_TRY_BLOCK: /* need to be update blk first to protect blk from GC */ mrb_int const kw_pos = len + kd; /* where kwhash should be */ mrb_int const blk_pos = kw_pos + 1; /* where block should be */ - regs[blk_pos] = blk; /* move block */ + regs[blk_pos] = blk; /* move block */ if (kd) { - if (mrb_nil_p(kdict)) + if (mrb_nil_p(kdict)) { kdict = mrb_hash_new_capa(mrb, 0); - regs[kw_pos] = kdict; /* set kwhash */ + } + regs[kw_pos] = kdict; /* set kwhash */ ci->nk = 15; } @@ -2151,249 +2263,151 @@ RETRY_TRY_BLOCK: } CASE(OP_BREAK, B) { - c = OP_R_BREAK; - goto L_RETURN; + if (mrb->exc) { + goto L_RAISE; + } + + if (MRB_PROC_STRICT_P(proc)) goto NORMAL_RETURN; + if (MRB_PROC_ORPHAN_P(proc) || !MRB_PROC_ENV_P(proc) || !MRB_ENV_ONSTACK_P(MRB_PROC_ENV(proc))) { + L_BREAK_ERROR: + RAISE_LIT(mrb, E_LOCALJUMP_ERROR, "break from proc-closure"); + } + else { + struct REnv *e = MRB_PROC_ENV(proc); + + if (e->cxt != mrb->c) { + goto L_BREAK_ERROR; + } + } + mrb_callinfo *ci = mrb->c->ci; + proc = proc->upper; + while (mrb->c->cibase < ci && ci[-1].proc != proc) { + ci--; + } + if (ci == mrb->c->cibase) { + goto L_BREAK_ERROR; + } + c = a; // release the "a" variable, which can handle 32-bit values + a = ci - mrb->c->cibase; + goto L_UNWINDING; } CASE(OP_RETURN_BLK, B) { - c = OP_R_RETURN; - goto L_RETURN; + if (mrb->exc) { + goto L_RAISE; + } + + mrb_callinfo *ci = mrb->c->ci; + + if (!MRB_PROC_ENV_P(proc) || MRB_PROC_STRICT_P(proc)) { + goto NORMAL_RETURN; + } + + const struct RProc *dst; + mrb_callinfo *cibase; + cibase = mrb->c->cibase; + dst = top_proc(mrb, proc); + + if (MRB_PROC_ENV_P(dst)) { + struct REnv *e = MRB_PROC_ENV(dst); + + if (!MRB_ENV_ONSTACK_P(e) || (e->cxt && e->cxt != mrb->c)) { + localjump_error(mrb, LOCALJUMP_ERROR_RETURN); + goto L_RAISE; + } + } + /* check jump destination */ + while (cibase <= ci && ci->proc != dst) { + ci--; + } + if (ci <= cibase) { /* no jump destination */ + localjump_error(mrb, LOCALJUMP_ERROR_RETURN); + goto L_RAISE; + } + c = a; // release the "a" variable, which can handle 32-bit values + a = ci - mrb->c->cibase; + goto L_UNWINDING; } - CASE(OP_RETURN, B) - c = OP_R_NORMAL; - L_RETURN: - { + CASE(OP_RETURN, B) { mrb_callinfo *ci; ci = mrb->c->ci; if (mrb->exc) { - L_RAISE: - ci = mrb->c->ci; - while ((ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ALL)) == NULL) { - if (ci != mrb->c->cibase) { - ci = cipop(mrb); - if (ci[1].cci == CINFO_SKIP && prev_jmp) { - mrb->jmp = prev_jmp; - MRB_THROW(prev_jmp); - } - pc = ci[0].pc; - } - else if (mrb->c == mrb->root_c) { - mrb->c->ci->stack = mrb->c->stbase; - goto L_STOP; - } - else { - struct mrb_context *c = mrb->c; - - c->status = MRB_FIBER_TERMINATED; - mrb->c = c->prev; - if (!mrb->c) mrb->c = mrb->root_c; - else c->prev = NULL; - goto L_RAISE; - } - } - - if (ch == NULL) goto L_STOP; - if (FALSE) { - L_CATCH_TAGGED_BREAK: /* from THROW_TAGGED_BREAK() or UNWIND_ENSURE() */ - ci = mrb->c->ci; - } - proc = ci->proc; - irep = proc->body.irep; - pool = irep->pool; - syms = irep->syms; - mrb_stack_extend(mrb, irep->nregs); - pc = irep->iseq + mrb_irep_catch_handler_unpack(ch->target); + goto L_RAISE; } else { mrb_int acc; mrb_value v; + NORMAL_RETURN: ci = mrb->c->ci; + + if (ci == mrb->c->cibase) { + struct mrb_context *c; + c = mrb->c; + + if (c->prev && !c->vmexec && c->prev->ci == c->prev->cibase) { + RAISE_LIT(mrb, E_FIBER_ERROR, "double resume"); + } + } + v = regs[a]; mrb_gc_protect(mrb, v); - switch (c) { - case OP_R_RETURN: - /* Fall through to OP_R_NORMAL otherwise */ - if (ci->cci == CINFO_NONE && MRB_PROC_ENV_P(proc) && !MRB_PROC_STRICT_P(proc)) { - const struct RProc *dst; - mrb_callinfo *cibase; - cibase = mrb->c->cibase; - dst = top_proc(mrb, proc); - - if (MRB_PROC_ENV_P(dst)) { - struct REnv *e = MRB_PROC_ENV(dst); - - if (!MRB_ENV_ONSTACK_P(e) || (e->cxt && e->cxt != mrb->c)) { - localjump_error(mrb, LOCALJUMP_ERROR_RETURN); - goto L_RAISE; - } - } - /* check jump destination */ - while (cibase <= ci && ci->proc != dst) { - if (ci->cci > CINFO_NONE) { /* jump cross C boundary */ - localjump_error(mrb, LOCALJUMP_ERROR_RETURN); - goto L_RAISE; - } - ci--; - } - if (ci <= cibase) { /* no jump destination */ - localjump_error(mrb, LOCALJUMP_ERROR_RETURN); - goto L_RAISE; - } - ci = mrb->c->ci; - while (cibase <= ci && ci->proc != dst) { - CHECKPOINT_RESTORE(RBREAK_TAG_RETURN_BLOCK) { - cibase = mrb->c->cibase; - dst = top_proc(mrb, proc); - } - CHECKPOINT_MAIN(RBREAK_TAG_RETURN_BLOCK) { - UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN_BLOCK, proc, v); - } - CHECKPOINT_END(RBREAK_TAG_RETURN_BLOCK); - ci = cipop(mrb); - pc = ci->pc; - } - proc = ci->proc; - mrb->exc = NULL; /* clear break object */ - break; - } - /* fallthrough */ - case OP_R_NORMAL: - NORMAL_RETURN: - if (ci == mrb->c->cibase) { - struct mrb_context *c; - c = mrb->c; - - if (!c->prev) { - if (c != mrb->root_c) { - /* fiber termination should transfer to root */ - c->prev = mrb->root_c; - } - else { /* toplevel return */ - regs[irep->nlocals] = v; - goto CHECKPOINT_LABEL_MAKE(RBREAK_TAG_STOP); - } - } - else if (!c->vmexec && c->prev->ci == c->prev->cibase) { - RAISE_LIT(mrb, E_FIBER_ERROR, "double resume"); - } - CHECKPOINT_RESTORE(RBREAK_TAG_RETURN_TOPLEVEL) { - c = mrb->c; - } - CHECKPOINT_MAIN(RBREAK_TAG_RETURN_TOPLEVEL) { - UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN_TOPLEVEL, proc, v); - } - CHECKPOINT_END(RBREAK_TAG_RETURN_TOPLEVEL); - /* automatic yield at the end */ - c->status = MRB_FIBER_TERMINATED; - mrb->c = c->prev; - mrb->c->status = MRB_FIBER_RUNNING; - c->prev = NULL; - if (c->vmexec) { - mrb_gc_arena_restore(mrb, ai); - c->vmexec = FALSE; - mrb->jmp = prev_jmp; - return v; - } - ci = mrb->c->ci; - } - CHECKPOINT_RESTORE(RBREAK_TAG_RETURN) { - /* do nothing */ - } - CHECKPOINT_MAIN(RBREAK_TAG_RETURN) { - UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN, proc, v); - } - CHECKPOINT_END(RBREAK_TAG_RETURN); - mrb->exc = NULL; /* clear break object */ - break; - case OP_R_BREAK: - if (MRB_PROC_STRICT_P(proc)) goto NORMAL_RETURN; - if (MRB_PROC_ORPHAN_P(proc)) { - L_BREAK_ERROR: - RAISE_LIT(mrb, E_LOCALJUMP_ERROR, "break from proc-closure"); - } - if (!MRB_PROC_ENV_P(proc) || !MRB_ENV_ONSTACK_P(MRB_PROC_ENV(proc))) { - goto L_BREAK_ERROR; + CHECKPOINT_RESTORE(RBREAK_TAG_BREAK) { + if (TRUE) { + struct RBreak *brk = (struct RBreak*)mrb->exc; + ci = &mrb->c->cibase[brk->ci_break_index]; + v = mrb_break_value_get(brk); } else { - struct REnv *e = MRB_PROC_ENV(proc); - - if (e->cxt != mrb->c) { - goto L_BREAK_ERROR; - } + L_UNWINDING: // for a check on the role of `a` and `c`, see `goto L_UNWINDING` + ci = mrb->c->cibase + a; + v = regs[c]; } - CHECKPOINT_RESTORE(RBREAK_TAG_BREAK) { - /* do nothing */ - } - CHECKPOINT_MAIN(RBREAK_TAG_BREAK) { - UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK, proc, v); - } - CHECKPOINT_END(RBREAK_TAG_BREAK); - /* break from fiber block */ - if (ci == mrb->c->cibase && ci->pc) { - struct mrb_context *c = mrb->c; - - mrb->c = c->prev; - c->prev = NULL; - ci = mrb->c->ci; - } - if (ci->cci > CINFO_NONE) { - ci = cipop(mrb); - mrb->exc = (struct RObject*)break_new(mrb, RBREAK_TAG_BREAK, proc, v); - mrb_gc_arena_restore(mrb, ai); - mrb->c->vmexec = FALSE; - mrb->jmp = prev_jmp; - MRB_THROW(prev_jmp); - } - if (FALSE) { - struct RBreak *brk; - - L_BREAK: - brk = (struct RBreak*)mrb->exc; - proc = mrb_break_proc_get(brk); - v = mrb_break_value_get(brk); - ci = mrb->c->ci; - - switch (mrb_break_tag_get(brk)) { -#define DISPATCH_CHECKPOINTS(n, i) case n: goto CHECKPOINT_LABEL_MAKE(n); - RBREAK_TAG_FOREACH(DISPATCH_CHECKPOINTS) -#undef DISPATCH_CHECKPOINTS - default: - mrb_assert(!"wrong break tag"); - } - } - while (mrb->c->cibase < ci && ci[-1].proc != proc->upper) { - if (ci[-1].cci == CINFO_SKIP) { - goto L_BREAK_ERROR; - } - CHECKPOINT_RESTORE(RBREAK_TAG_BREAK_UPPER) { - /* do nothing */ - } - CHECKPOINT_MAIN(RBREAK_TAG_BREAK_UPPER) { - UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK_UPPER, proc, v); - } - CHECKPOINT_END(RBREAK_TAG_BREAK_UPPER); - ci = cipop(mrb); - pc = ci->pc; - } - CHECKPOINT_RESTORE(RBREAK_TAG_BREAK_INTARGET) { - /* do nothing */ - } - CHECKPOINT_MAIN(RBREAK_TAG_BREAK_INTARGET) { - UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK_INTARGET, proc, v); - } - CHECKPOINT_END(RBREAK_TAG_BREAK_INTARGET); - if (ci == mrb->c->cibase) { - goto L_BREAK_ERROR; - } - mrb->exc = NULL; /* clear break object */ - break; - default: - /* cannot happen */ - break; + mrb_gc_protect(mrb, v); + } + CHECKPOINT_MAIN(RBREAK_TAG_BREAK) { + for (;;) { + UNWIND_ENSURE(mrb, mrb->c->ci, mrb->c->ci->pc, RBREAK_TAG_BREAK, ci, v); + + if (mrb->c->ci == ci) { + break; + } + cipop(mrb); + if (mrb->c->ci[1].cci != CINFO_NONE) { + mrb_assert(prev_jmp != NULL); + mrb->exc = (struct RObject*)break_new(mrb, RBREAK_TAG_BREAK, ci, v); + mrb_gc_arena_restore(mrb, ai); + mrb->c->vmexec = FALSE; + mrb->jmp = prev_jmp; + MRB_THROW(prev_jmp); + } + } + } + CHECKPOINT_END(RBREAK_TAG_BREAK); + mrb->exc = NULL; /* clear break object */ + + if (ci == mrb->c->cibase) { + struct mrb_context *c = mrb->c; + if (c == mrb->root_c) { + /* toplevel return */ + regs[irep->nlocals] = v; + goto L_STOP; + } + + /* fiber termination should automatic yield or transfer to root */ + c->status = MRB_FIBER_TERMINATED; + mrb->c = c->prev ? c->prev : mrb->root_c; + c->prev = NULL; + mrb->c->status = MRB_FIBER_RUNNING; + if (c->vmexec || + (mrb->c == mrb->root_c && mrb->c->ci == mrb->c->cibase) /* case using Fiber#transfer in mrb_fiber_resume() */) { + mrb_gc_arena_restore(mrb, ai); + c->vmexec = FALSE; + mrb->jmp = prev_jmp; + return v; + } + ci = mrb->c->ci; } - mrb_assert(ci == mrb->c->ci); - mrb_assert(mrb->exc == NULL); if (mrb->c->vmexec && !CI_TARGET_CLASS(ci)) { mrb_gc_arena_restore(mrb, ai); @@ -2627,13 +2641,13 @@ RETRY_TRY_BLOCK: /* need to check if - is overridden */\ switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\ case TYPES2(MRB_TT_INTEGER,MRB_TT_INTEGER):\ - result = OP_CMP_BODY(op,mrb_fixnum,mrb_fixnum);\ + result = OP_CMP_BODY(op,mrb_integer,mrb_integer);\ break;\ case TYPES2(MRB_TT_INTEGER,MRB_TT_FLOAT):\ - result = OP_CMP_BODY(op,mrb_fixnum,mrb_float);\ + result = OP_CMP_BODY(op,mrb_integer,mrb_float);\ break;\ case TYPES2(MRB_TT_FLOAT,MRB_TT_INTEGER):\ - result = OP_CMP_BODY(op,mrb_float,mrb_fixnum);\ + result = OP_CMP_BODY(op,mrb_float,mrb_integer);\ break;\ case TYPES2(MRB_TT_FLOAT,MRB_TT_FLOAT):\ result = OP_CMP_BODY(op,mrb_float,mrb_float);\ @@ -2824,10 +2838,9 @@ RETRY_TRY_BLOCK: CASE(OP_HASH, BB) { mrb_value hash = mrb_hash_new_capa(mrb, b); - int i; int lim = a+b*2; - for (i=a; ibody.irep; pool = irep->pool; syms = irep->syms; - mrb_stack_extend(mrb, irep->nregs); + stack_extend(mrb, irep->nregs); stack_clear(regs+1, irep->nregs-1); pc = irep->iseq; JUMP; @@ -3067,7 +3079,7 @@ RETRY_TRY_BLOCK: /* do nothing */ } CHECKPOINT_MAIN(RBREAK_TAG_STOP) { - UNWIND_ENSURE(mrb, mrb->c->ci, pc, RBREAK_TAG_STOP, proc, mrb_nil_value()); + UNWIND_ENSURE(mrb, mrb->c->ci, mrb->c->ci->pc, RBREAK_TAG_STOP, mrb->c->ci, mrb_nil_value()); } CHECKPOINT_END(RBREAK_TAG_STOP); L_STOP: @@ -3097,24 +3109,16 @@ RETRY_TRY_BLOCK: static mrb_value mrb_run(mrb_state *mrb, const struct RProc *proc, mrb_value self) { - return mrb_vm_run(mrb, proc, self, mrb_ci_bidx(mrb->c->ci) + 1); + return mrb_vm_run(mrb, proc, self, ci_bidx(mrb->c->ci) + 1); } MRB_API mrb_value mrb_top_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep) { - mrb_value v; - - if (!mrb->c->cibase) { - return mrb_vm_run(mrb, proc, self, stack_keep); + if (mrb->c->cibase && mrb->c->ci > mrb->c->cibase) { + cipush(mrb, 0, CINFO_SKIP, mrb->object_class, NULL, NULL, 0, 0); } - if (mrb->c->ci == mrb->c->cibase) { - return mrb_vm_run(mrb, proc, self, stack_keep); - } - cipush(mrb, 0, CINFO_SKIP, mrb->object_class, NULL, NULL, 0, 0); - v = mrb_vm_run(mrb, proc, self, stack_keep); - - return v; + return mrb_vm_run(mrb, proc, self, stack_keep); } #if defined(MRB_USE_CXX_EXCEPTION) && defined(__cplusplus) diff --git a/yass/third_party/nghttp2/third-party/mruby/super-linter.report/.keep b/yass/third_party/nghttp2/third-party/mruby/super-linter.report/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/yass/third_party/nghttp2/third-party/mruby/tasks/doc.rake b/yass/third_party/nghttp2/third-party/mruby/tasks/doc.rake index 50dc361801..11c0bd2514 100644 --- a/yass/third_party/nghttp2/third-party/mruby/tasks/doc.rake +++ b/yass/third_party/nghttp2/third-party/mruby/tasks/doc.rake @@ -9,7 +9,7 @@ namespace :doc do begin sh "mrbdoc" rescue - puts "ERROR: To generate yard documentation, you should install yard-mruby gem." + puts "ERROR: To generate YARD documentation, you should install yard-mruby gem." puts " $ gem install yard-mruby yard-coderay" puts "https://yardoc.org/" puts "https://rubygems.org/gems/yard-mruby" diff --git a/yass/third_party/nghttp2/third-party/mruby/tasks/install.rake b/yass/third_party/nghttp2/third-party/mruby/tasks/install.rake new file mode 100644 index 0000000000..234bec8d8e --- /dev/null +++ b/yass/third_party/nghttp2/third-party/mruby/tasks/install.rake @@ -0,0 +1,33 @@ +desc "install compiled products (on host)" +task :install => "install:full:host" + +desc "install compiled executable (on host)" +task :install_bin => "install:bin:host" + +desc "install compiled products (all build targets)" +task "install:full" + +desc "install compiled executable (all build targets)" +task "install:bin" + +MRuby.each_target do |build| + next if build.internal? + + prefix = File.join(MRuby::INSTALL_DESTDIR, build.install_prefix) + + task "install:full" => "install:full:#{build.name}" + + task "install:full:#{build.name}" => "install:bin:#{build.name}" do + Dir.glob(File.join(build.build_dir.gsub(/[\[\{\*\?]/, "\\\0"), "{include,lib}/**/*")) do |path| + install_D path, File.join(prefix, path.relative_path_from(build.build_dir)) if File.file? path + end + end + + task "install:bin" => "install:bin:#{build.name}" + + task "install:bin:#{build.name}" => "all" do + Dir.glob(File.join(build.build_dir.gsub(/[\[\{\*\?]/, "\\\0"), "{bin,host-bin}/**/*")) do |path| + install_D path, File.join(prefix, path.relative_path_from(build.build_dir)) if File.file? path + end + end +end diff --git a/yass/third_party/nghttp2/third-party/mruby/tasks/libmruby.rake b/yass/third_party/nghttp2/third-party/mruby/tasks/libmruby.rake index 1fb3cbc313..eafac3d25b 100644 --- a/yass/third_party/nghttp2/third-party/mruby/tasks/libmruby.rake +++ b/yass/third_party/nghttp2/third-party/mruby/tasks/libmruby.rake @@ -7,31 +7,82 @@ MRuby.each_target do next unless libmruby_enabled? + copy_headers_task = "expose_header_files:#{self.name}" file libmruby_static => libmruby_objs.flatten do |t| + Rake::Task[copy_headers_task].invoke archiver.run t.name, t.prerequisites end + task copy_headers_task do |t| + # Since header files may be generated dynamically and it is hard to know all of them, + # the task is executed depending on when libmruby.a is generated. + + gemsbasedir = File.join(build_dir, "include/mruby/gems") + dirmap = { + MRUBY_ROOT => build_dir + } + gems.each { |g| + dirmap[g.dir] = File.join(gemsbasedir, g.name) + dirmap[g.build_dir] = File.join(gemsbasedir, g.name) + } + + dirs = each_header_files.to_a + dirs.uniq! + dirs.replace_prefix_by(dirmap).zip(dirs).each do |dest, src| + if File.mtime(src).to_i > (File.mtime(dest).to_i rescue 0) + mkpath File.dirname(dest) + cp src, dest + end + end + end + file "#{build_dir}/lib/libmruby.flags.mak" => [__FILE__, libmruby_static] do |t| mkdir_p File.dirname t.name open(t.name, 'w') do |f| - gemincs = gems.map { |g| g.export_include_paths.map { |n| g.filename(n) } }.flatten.uniq - f.puts "MRUBY_CFLAGS = #{cc.all_flags([], gemincs)}" + f.puts <<~FLAGS_MAKE + # GNU make is required to use this file. + MRUBY_PACKAGE_DIR_GNU := $(shell dirname "$(lastword $(MAKEFILE_LIST))") + MRUBY_PACKAGE_DIR != dirname "$(MRUBY_PACKAGE_DIR_GNU)" + FLAGS_MAKE + + [ + [cc, "MRUBY_CC", "MRUBY_CFLAGS"], + [cxx, "MRUBY_CXX", "MRUBY_CXXFLAGS"], + [asm, "MRUBY_AS", "MRUBY_ASFLAGS"], + [objc, "MRUBY_OBJC", "MRUBY_OBJCFLAGS"] + ].each do |cc, cmd, flags| + incpaths = cc.include_paths.dup + dirmaps = { + MRUBY_ROOT => "$(MRUBY_PACKAGE_DIR)", + build_dir => "$(MRUBY_PACKAGE_DIR)" + } + gems.each do |g| + incpaths.concat g.export_include_paths + dirmaps[g.dir] = "$(MRUBY_PACKAGE_DIR)/include/mruby/gems/#{g.name}" + dirmaps[g.build_dir] = "$(MRUBY_PACKAGE_DIR)/include/mruby/gems/#{g.name}" + end + modcc = cc.clone + modcc.include_paths = incpaths.replace_prefix_by(dirmaps).uniq + + f.puts "#{cmd} = #{cc.command}" + f.puts "#{flags} = #{modcc.all_flags}" + end - f.puts "MRUBY_CC = #{cc.command}" f.puts "MRUBY_LD = #{linker.command}" libgems = gems.reject{|g| g.bin?} gem_flags = libgems.map {|g| g.linker.flags } gem_library_paths = libgems.map {|g| g.linker.library_paths } - f.puts "MRUBY_LDFLAGS = #{linker.all_flags(gem_library_paths, gem_flags)} #{linker.option_library_path % "#{build_dir}/lib"}" + f.puts "MRUBY_LDFLAGS = #{linker.all_flags(gem_library_paths, gem_flags)} #{linker.option_library_path % "$(MRUBY_PACKAGE_DIR)/lib"}" gem_flags_before_libraries = libgems.map {|g| g.linker.flags_before_libraries } f.puts "MRUBY_LDFLAGS_BEFORE_LIBS = #{[linker.flags_before_libraries, gem_flags_before_libraries].flatten.join(' ')}" gem_libraries = libgems.map {|g| g.linker.libraries } - f.puts "MRUBY_LIBS = #{linker.option_library % 'mruby'} #{linker.library_flags(gem_libraries)}" + libmruby = (toolchains.find { |e| e == "visualcpp" }) ? "libmruby" : "mruby" + f.puts "MRUBY_LIBS = #{linker.option_library % libmruby} #{linker.library_flags(gem_libraries)}" - f.puts "MRUBY_LIBMRUBY_PATH = #{libmruby_static}" + f.puts "MRUBY_LIBMRUBY_PATH = #{libmruby_static.replace_prefix_by(build_dir => "$(MRUBY_PACKAGE_DIR)")}" end end diff --git a/yass/third_party/nghttp2/third-party/mruby/tasks/mrbgems.rake b/yass/third_party/nghttp2/third-party/mruby/tasks/mrbgems.rake index 1e6b031928..686facb255 100644 --- a/yass/third_party/nghttp2/third-party/mruby/tasks/mrbgems.rake +++ b/yass/third_party/nghttp2/third-party/mruby/tasks/mrbgems.rake @@ -13,41 +13,82 @@ MRuby.each_target do mkdir_p "#{build_dir}/mrbgems" open(t.name, 'w') do |f| gem_func_gems = gems.select { |g| g.generate_functions } - gem_func_decls = gem_func_gems.each_with_object('') do |g, s| - s << "void GENERATED_TMP_mrb_#{g.funcname}_gem_init(mrb_state*);\n" \ - "void GENERATED_TMP_mrb_#{g.funcname}_gem_final(mrb_state*);\n" - end - gem_init_calls = gem_func_gems.each_with_object('') do |g, s| - s << " GENERATED_TMP_mrb_#{g.funcname}_gem_init(mrb);\n" - end - gem_final_calls = gem_func_gems.reverse_each.with_object('') do |g, s| - s << " GENERATED_TMP_mrb_#{g.funcname}_gem_final(mrb);\n" + gem_func_decls = '' + gem_funcs = '' + gem_func_gems.each do |g| + init = "GENERATED_TMP_mrb_#{g.funcname}_gem_init" + final = "GENERATED_TMP_mrb_#{g.funcname}_gem_final" + gem_func_decls << "void #{init}(mrb_state*);\n" \ + "void #{final}(mrb_state*);\n" + gem_funcs << " { #{init}, #{final} },\n" end f.puts %Q[/*] f.puts %Q[ * This file contains a list of all] f.puts %Q[ * initializing methods which are] f.puts %Q[ * necessary to bootstrap all gems.] f.puts %Q[ *] + f.puts %Q[ * This file was generated by mruby/#{__FILE__.relative_path_from(MRUBY_ROOT)}.] + f.puts %Q[ *] f.puts %Q[ * IMPORTANT:] f.puts %Q[ * This file was generated!] f.puts %Q[ * All manual changes will get lost.] f.puts %Q[ */] f.puts %Q[] f.puts %Q[#include ] + f.puts %Q[#include ] + f.puts %Q[#include ] f.puts %Q[] - f.write gem_func_decls - unless gem_final_calls.empty? + unless gem_funcs.empty? + f.write gem_func_decls + f.puts %Q[] + f.puts %Q[static const struct {] + f.puts %Q[ void (*init)(mrb_state*);] + f.puts %Q[ void (*final)(mrb_state*);] + f.puts %Q[} gem_funcs[] = {] + f.write gem_funcs + f.puts %Q[};] + f.puts %Q[] + f.puts %Q[#define NUM_GEMS ((int)(sizeof(gem_funcs) / sizeof(gem_funcs[0])))] + f.puts %Q[] + f.puts %Q[struct final_mrbgems {] + f.puts %Q[ int i;] + f.puts %Q[ int ai;] + f.puts %Q[};] + f.puts %Q[] + f.puts %Q[static mrb_value] + f.puts %Q[final_mrbgems_body(mrb_state *mrb, void *ud) {] + f.puts %Q[ struct final_mrbgems *p = (struct final_mrbgems*)ud;] + f.puts %Q[ for (; p->i >= 0; p->i--) {] + f.puts %Q[ gem_funcs[p->i].final(mrb);] + f.puts %Q[ mrb_gc_arena_restore(mrb, p->ai);] + f.puts %Q[ }] + f.puts %Q[ return mrb_nil_value();] + f.puts %Q[}] f.puts %Q[] f.puts %Q[static void] f.puts %Q[mrb_final_mrbgems(mrb_state *mrb) {] - f.write gem_final_calls + f.puts %Q[ struct final_mrbgems a = { NUM_GEMS - 1, mrb_gc_arena_save(mrb) };] + f.puts %Q[ for (; a.i >= 0; a.i--) {] + f.puts %Q[ mrb_protect_error(mrb, final_mrbgems_body, &a, NULL);] + f.puts %Q[ mrb_gc_arena_restore(mrb, a.ai);] + f.puts %Q[ }] f.puts %Q[}] + f.puts %Q[] end - f.puts %Q[] f.puts %Q[void] f.puts %Q[mrb_init_mrbgems(mrb_state *mrb) {] - f.write gem_init_calls - f.puts %Q[ mrb_state_atexit(mrb, mrb_final_mrbgems);] unless gem_final_calls.empty? + unless gem_funcs.empty? + f.puts %Q[ int ai = mrb_gc_arena_save(mrb);] + f.puts %Q[ for (int i = 0; i < NUM_GEMS; i++) {] + f.puts %Q[ gem_funcs[i].init(mrb);] + f.puts %Q[ mrb_gc_arena_restore(mrb, ai);] + f.puts %Q[ mrb_vm_ci_env_clear(mrb, mrb->c->cibase);] + f.puts %Q[ if (mrb->exc) {] + f.puts %Q[ mrb_exc_raise(mrb, mrb_obj_value(mrb->exc));] + f.puts %Q[ }] + f.puts %Q[ }] + f.puts %Q[ mrb_state_atexit(mrb, mrb_final_mrbgems);] + end f.puts %Q[}] end end diff --git a/yass/third_party/nghttp2/third-party/mruby/tasks/toolchains/android.rake b/yass/third_party/nghttp2/third-party/mruby/tasks/toolchains/android.rake index 6e4648e632..98e413042e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/tasks/toolchains/android.rake +++ b/yass/third_party/nghttp2/third-party/mruby/tasks/toolchains/android.rake @@ -2,7 +2,7 @@ require "json" class MRuby::Toolchain::Android - DEFAULT_ARCH = 'armeabi' # TODO : Revise if arch should have a default + DEFAULT_ARCH = 'armeabi-v7a' # TODO : Revise if arch should have a default DEFAULT_TOOLCHAIN = :clang @@ -15,14 +15,14 @@ class MRuby::Toolchain::Android %LOCALAPPDATA%/Android/Sdk/ndk/* ~/Library/Android/sdk/ndk-bundle ~/Library/Android/ndk + /opt/android-ndk } - TOOLCHAINS = [:clang, :gcc] + TOOLCHAINS = [:clang] ARCHITECTURES = %w{ - armeabi armeabi-v7a arm64-v8a + armeabi-v7a arm64-v8a x86 x86_64 - mips mips64 } class AndroidNDKHomeNotFound < StandardError @@ -40,21 +40,6 @@ Set ANDROID_NDK_HOME environment variable or set :ndk_home parameter @params = params end - def bin_gcc(command) - command = command.to_s - - command = case arch - when /armeabi/ then 'arm-linux-androideabi-' - when /arm64-v8a/ then 'aarch64-linux-android-' - when /x86_64/ then 'x86_64-linux-android-' - when /x86/ then 'i686-linux-android-' - when /mips64/ then 'mips64el-linux-android-' - when /mips/ then 'mipsel-linux-android-' - end + command - - gcc_toolchain_path.join('bin', command).to_s - end - def bin(command) command = command.to_s toolchain_path.join('bin', command).to_s @@ -97,38 +82,7 @@ Set ANDROID_NDK_HOME environment variable or set :ndk_home parameter end def toolchain_path - @toolchain_path ||= case toolchain - when :gcc - gcc_toolchain_path - when :clang - home_path.join('toolchains', 'llvm' , 'prebuilt', host_platform) - end - end - - def gcc_toolchain_path - if @gcc_toolchain_path === nil then - prefix = case arch - when /armeabi/ then 'arm-linux-androideabi-' - when /arm64-v8a/ then 'aarch64-linux-android-' - when /x86_64/ then 'x86_64-' - when /x86/ then 'x86-' - when /mips64/ then 'mips64el-linux-android-' - when /mips/ then 'mipsel-linux-android-' - end - - test = case arch - when /armeabi/ then 'arm-linux-androideabi-*' - when /arm64-v8a/ then 'aarch64-linux-android-*' - when /x86_64/ then 'x86_64-*' - when /x86/ then 'x86-*' - when /mips64/ then 'mips64el-linux-android-*' - when /mips/ then 'mipsel-linux-android-*' - end - - gcc_toolchain_version = Dir[home_path.join('toolchains', test)].map{|t| t.match(/-(\d+\.\d+)$/); $1.to_f }.max - @gcc_toolchain_path = home_path.join('toolchains', prefix + gcc_toolchain_version.to_s, 'prebuilt', host_platform) - end - @gcc_toolchain_path + @toolchain_path ||= home_path.join('toolchains', 'llvm' , 'prebuilt', host_platform) end def host_platform @@ -189,15 +143,13 @@ Set ANDROID_NDK_HOME environment variable or set :ndk_home parameter def cc case toolchain - when :gcc then bin_gcc('gcc') when :clang then bin('clang') end end def ar case toolchain - when :gcc then bin_gcc('ar') - when :clang then bin_gcc('ar') + when :clang then bin('llvm-ar') end end @@ -206,38 +158,15 @@ Set ANDROID_NDK_HOME environment variable or set :ndk_home parameter v = sdk_version case toolchain - when :gcc - case arch - when /armeabi-v7a/ then flags += %W(-march=armv7-a) - when /armeabi/ then flags += %W(-march=armv5te) - when /arm64-v8a/ then flags += %W(-march=armv8-a) - when /x86_64/ then flags += %W(-march=x86-64) - when /x86/ then flags += %W(-march=i686) - when /mips64/ then flags += %W(-march=mips64r6) - when /mips/ then flags += %W(-march=mips32) - end when :clang case arch - when /armeabi-v7a/ then flags += %W(-target armv7-none-linux-androideabi#{v}) - when /armeabi/ then flags += %W(-target armv5te-none-linux-androideabi#{v}) - when /arm64-v8a/ then flags += %W(-target aarch64-none-linux-android#{v}) - when /x86_64/ then flags += %W(-target x86_64-none-linux-android#{v}) - when /x86/ then flags += %W(-target i686-none-linux-android#{v}) - when /mips64/ then flags += %W(-target mips64el-none-linux-android#{v}) - when /mips/ then flags += %W(-target mipsel-none-linux-android#{v}) + when /armeabi-v7a/ then flags += %W(-target armv7a-linux-androideabi#{v} -mfpu=#{armeabi_v7a_mfpu} -mfloat-abi=#{armeabi_v7a_mfloat_abi}) + when /arm64-v8a/ then flags += %W(-target aarch64-linux-android#{v}) + when /x86_64/ then flags += %W(-target x86_64-linux-android#{v}) + when /x86/ then flags += %W(-target i686-linux-android#{v}) end end - case arch - when /armeabi-v7a/ then flags += %W(-mfpu=#{armeabi_v7a_mfpu} -mfloat-abi=#{armeabi_v7a_mfloat_abi}) - when /armeabi/ then flags += %W(-mtune=xscale -msoft-float) - when /arm64-v8a/ then flags += %W() - when /x86_64/ then flags += %W() - when /x86/ then flags += %W() - when /mips64/ then flags += %W(-fmessage-length=0) - when /mips/ then flags += %W(-fmessage-length=0) - end - flags end @@ -252,11 +181,6 @@ Set ANDROID_NDK_HOME environment variable or set :ndk_home parameter flags += %W(-MMD -MP -D__android__ -DANDROID) flags += ctarget - case toolchain - when :gcc - when :clang - flags += %W(-gcc-toolchain "#{gcc_toolchain_path}" -Wno-invalid-command-line-argument -Wno-unused-command-line-argument) - end flags += %W(-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes) flags @@ -273,20 +197,12 @@ Set ANDROID_NDK_HOME environment variable or set :ndk_home parameter v = sdk_version case toolchain - when :gcc - case arch - when /armeabi-v7a/ then flags += %W(-Wl#{no_warn_mismatch}) - end when :clang - flags += %W(-gcc-toolchain "#{gcc_toolchain_path.to_s}") case arch when /armeabi-v7a/ then flags += %W(-target armv7-none-linux-androideabi#{v} -Wl,--fix-cortex-a8#{no_warn_mismatch}) - when /armeabi/ then flags += %W(-target armv5te-none-linux-androideabi#{v}) when /arm64-v8a/ then flags += %W(-target aarch64-none-linux-android#{v}) when /x86_64/ then flags += %W(-target x86_64-none-linux-android#{v}) when /x86/ then flags += %W(-target i686-none-linux-android#{v}) - when /mips64/ then flags += %W(-target mips64el-none-linux-android#{v}) - when /mips/ then flags += %W(-target mipsel-none-linux-android#{v}) end end flags += %W(-no-canonical-prefixes) diff --git a/yass/third_party/nghttp2/third-party/mruby/tasks/toolchains/gcc.rake b/yass/third_party/nghttp2/third-party/mruby/tasks/toolchains/gcc.rake index aa1cf777dc..675c26880e 100644 --- a/yass/third_party/nghttp2/third-party/mruby/tasks/toolchains/gcc.rake +++ b/yass/third_party/nghttp2/third-party/mruby/tasks/toolchains/gcc.rake @@ -20,6 +20,10 @@ MRuby::Toolchain.new(:gcc) do |conf, params| compiler.cxx_compile_flag = '-x c++ -std=gnu++03' compiler.cxx_exception_flag = '-fexceptions' compiler.cxx_invalid_flags = c_mandatory_flags + cxx_invalid_flags + + def compiler.setup_debug(conf) + self.flags << %w(-g3 -O0) + end end conf.linker do |linker| diff --git a/yass/third_party/nghttp2/third-party/mruby/test/t/bs_block.rb b/yass/third_party/nghttp2/third-party/mruby/test/t/bs_block.rb index c37d1b5389..08580d58a3 100644 --- a/yass/third_party/nghttp2/third-party/mruby/test/t/bs_block.rb +++ b/yass/third_party/nghttp2/third-party/mruby/test/t/bs_block.rb @@ -313,7 +313,7 @@ assert('BS Block 25') do end assert('BS Block 26') do - def m a + def m(a) yield a end assert_equal(2) do diff --git a/yass/third_party/nghttp2/third-party/mruby/test/t/class.rb b/yass/third_party/nghttp2/third-party/mruby/test/t/class.rb index 1b4b84890d..f4d99318ab 100644 --- a/yass/third_party/nghttp2/third-party/mruby/test/t/class.rb +++ b/yass/third_party/nghttp2/third-party/mruby/test/t/class.rb @@ -40,7 +40,7 @@ assert('Class#new', '15.2.3.3.3') do end class TestClass - def initialize args, &block + def initialize(args, &block) @result = if not args.nil? and block.nil? # only arguments :only_args diff --git a/yass/third_party/nghttp2/third-party/mruby/test/t/codegen.rb b/yass/third_party/nghttp2/third-party/mruby/test/t/codegen.rb index acb9e1bf53..0cb86efc7a 100644 --- a/yass/third_party/nghttp2/third-party/mruby/test/t/codegen.rb +++ b/yass/third_party/nghttp2/third-party/mruby/test/t/codegen.rb @@ -56,12 +56,11 @@ assert('undef with 127 or more arguments') do end end -assert('next in normal loop with 127 arguments') do - assert_raise NameError do - while true - next A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A,A - end - end +assert('break in normal loop with 127 arguments') do + assert_equal 127, + 1.times{ + break 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 + }.size end assert('negate literal register alignment') do diff --git a/yass/third_party/nghttp2/third-party/mruby/test/t/float.rb b/yass/third_party/nghttp2/third-party/mruby/test/t/float.rb index e4c25b34ea..1a7f6c99a1 100644 --- a/yass/third_party/nghttp2/third-party/mruby/test/t/float.rb +++ b/yass/third_party/nghttp2/third-party/mruby/test/t/float.rb @@ -216,7 +216,7 @@ assert('Float#truncate', '15.2.9.3.15') do end assert('Float#divmod') do - def check_floats exp, act + def check_floats(exp, act) assert_float exp[0], act[0] assert_float exp[1], act[1] end diff --git a/yass/third_party/nghttp2/third-party/mruby/test/t/hash.rb b/yass/third_party/nghttp2/third-party/mruby/test/t/hash.rb index 9ff066b8c2..3ce2e14f68 100644 --- a/yass/third_party/nghttp2/third-party/mruby/test/t/hash.rb +++ b/yass/third_party/nghttp2/third-party/mruby/test/t/hash.rb @@ -880,17 +880,6 @@ end hh[hh] = :recur assert_equal("{#{s}, {...}=>:recur}", hh.__send__(meth)) end - - [ar_entries, ht_entries].each do |entries| - cls = Class.new do - attr_accessor :h - def inspect; @h.replace(@h.dup); to_s; end - end - v = cls.new - h = entries.hash_for({_k: v}) - v.h = h - assert_nothing_raised{h.__send__(meth)} - end end end diff --git a/yass/third_party/nghttp2/third-party/mruby/test/t/string.rb b/yass/third_party/nghttp2/third-party/mruby/test/t/string.rb index 11b5cae0f8..0bb9acfb3f 100644 --- a/yass/third_party/nghttp2/third-party/mruby/test/t/string.rb +++ b/yass/third_party/nghttp2/third-party/mruby/test/t/string.rb @@ -898,3 +898,72 @@ assert('String#byteslice') do assert_equal("o", str1.byteslice(4.0)) assert_equal("\x82ab", str2.byteslice(2.0, 3.0)) end + +assert('String#bytesplice') do + # range, replace (len1=len2) + a = "0123456789" + assert_equal "0ab3456789", a.bytesplice(1..2, "ab") + + # range, replace (len1>len2) + a = "0123456789" + assert_equal "0ab456789", a.bytesplice(1..3, "ab") + + # range, replace (len1len2) + a = "0123456789" + assert_equal "0ab456789", a.bytesplice(1, 3, "ab") + + # idx, len, replace (len1len2) + a = "0123456789" + assert_equal "0bc456789", a.bytesplice(1..3, b, 1..2) + + # range, replace, range (len1len2) + a = "0123456789" + assert_equal "0bc456789", a.bytesplice(1, 3, b, 1, 2) + + # idx, len, replace, idx, len (len1= 0x013d00 + // nghttp2 REQUIRES setting max number of CONTINUATION frames. + // 1024 is chosen to accommodate Envoy's 8Mb max limit of max_request_headers_kb + // in both headers and trailers + nghttp2_option_set_max_continuations(owned_options, 1024); +#endif nghttp2_option_set_user_recv_extension_type(owned_options, kMetadataFrameType); options_ = owned_options; diff --git a/yass/yass.spec.in b/yass/yass.spec.in index 89f37e03a5..28ab2fa4c5 100644 --- a/yass/yass.spec.in +++ b/yass/yass.spec.in @@ -240,6 +240,8 @@ for embedded devices and low end boxes. %systemd_postun_with_restart yass-redir.service %changelog +* Fri Apr 5 2024 Chilledheart - 1.8.2-1 + - fix (nghttp2) CVE-2024-30255 * Tue Mar 26 2024 Chilledheart - 1.8.1-1 - bump to chromium 124 dependents. - miscellaneous fixes diff --git a/youtube-dl/youtube_dl/utils.py b/youtube-dl/youtube_dl/utils.py index 083446342b..e1b05b3072 100644 --- a/youtube-dl/youtube_dl/utils.py +++ b/youtube-dl/youtube_dl/utils.py @@ -2371,15 +2371,24 @@ def make_HTTPS_handler(params, **kwargs): return YoutubeDLHTTPSHandler(params, context=context, **kwargs) -def bug_reports_message(): +def bug_reports_message(before=';'): if ytdl_is_updateable(): update_cmd = 'type youtube-dl -U to update' else: - update_cmd = 'see https://yt-dl.org/update on how to update' - msg = '; please report this issue on https://yt-dl.org/bug .' - msg += ' Make sure you are using the latest version; %s.' % update_cmd - msg += ' Be sure to call youtube-dl with the --verbose flag and include its complete output.' - return msg + update_cmd = 'see https://github.com/ytdl-org/youtube-dl/#user-content-installation on how to update' + + msg = ( + 'please report this issue on https://github.com/ytdl-org/youtube-dl/issues ,' + ' using the appropriate issue template.' + ' Make sure you are using the latest version; %s.' + ' Be sure to call youtube-dl with the --verbose option and include the complete output.' + ) % update_cmd + + before = (before or '').rstrip() + if not before or before.endswith(('.', '!', '?')): + msg = msg[0].title() + msg[1:] + + return (before + ' ' if before else '') + msg class YoutubeDLError(Exception):