From 33509dbeb0acd7abbbb9e8c434d0c3f0ce8a3230 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 28 Dec 2013 10:02:18 -0500 Subject: [PATCH] It appears that the "Str" type (which is built into the core X protocol) doesn't specify any padding. So it has to be treated as a special case. Close #12. --- nexgb/dri2/dri2.go | 4 ++-- nexgb/glx/glx.go | 4 ++-- nexgb/randr/randr.go | 24 ++++++++++++------------ nexgb/xf86dri/xf86dri.go | 4 ++-- nexgb/xf86vidmode/xf86vidmode.go | 4 ++-- nexgb/xfixes/xfixes.go | 4 ++-- nexgb/xgbgen/go_list.go | 5 ++++- nexgb/xproto/xproto.go | 16 ++++++++-------- nexgb/xselinux/xselinux.go | 30 +++++++++++++++--------------- nexgb/xv/xv.go | 6 +++--- 10 files changed, 52 insertions(+), 49 deletions(-) diff --git a/nexgb/dri2/dri2.go b/nexgb/dri2/dri2.go index df13661..6cec3d0 100644 --- a/nexgb/dri2/dri2.go +++ b/nexgb/dri2/dri2.go @@ -562,7 +562,7 @@ func connectReply(buf []byte) *ConnectReply { byteString := make([]byte, v.DriverNameLength) copy(byteString[:v.DriverNameLength], buf[b:]) v.DriverName = string(byteString) - b += xgb.Pad(int(v.DriverNameLength)) + b += int(v.DriverNameLength) } v.AlignmentPad = make([]byte, (((int(v.DriverNameLength) + 3) & -4) - int(v.DriverNameLength))) @@ -573,7 +573,7 @@ func connectReply(buf []byte) *ConnectReply { byteString := make([]byte, v.DeviceNameLength) copy(byteString[:v.DeviceNameLength], buf[b:]) v.DeviceName = string(byteString) - b += xgb.Pad(int(v.DeviceNameLength)) + b += int(v.DeviceNameLength) } return v diff --git a/nexgb/glx/glx.go b/nexgb/glx/glx.go index 2db5798..979d577 100644 --- a/nexgb/glx/glx.go +++ b/nexgb/glx/glx.go @@ -6885,7 +6885,7 @@ func getStringReply(buf []byte) *GetStringReply { byteString := make([]byte, v.N) copy(byteString[:v.N], buf[b:]) v.String = string(byteString) - b += xgb.Pad(int(v.N)) + b += int(v.N) } return v @@ -9174,7 +9174,7 @@ func queryServerStringReply(buf []byte) *QueryServerStringReply { byteString := make([]byte, v.StrLen) copy(byteString[:v.StrLen], buf[b:]) v.String = string(byteString) - b += xgb.Pad(int(v.StrLen)) + b += int(v.StrLen) } return v diff --git a/nexgb/randr/randr.go b/nexgb/randr/randr.go index c7df090..c7893e3 100644 --- a/nexgb/randr/randr.go +++ b/nexgb/randr/randr.go @@ -504,6 +504,15 @@ func ModeInfoListBytes(buf []byte, list []ModeInfo) int { return xgb.Pad(b) } +const ( + NotifyCrtcChange = 0 + NotifyOutputChange = 1 + NotifyOutputProperty = 2 + NotifyProviderChange = 3 + NotifyProviderProperty = 4 + NotifyResourceChange = 5 +) + // Notify is the event number for a NotifyEvent. const Notify = 1 @@ -572,15 +581,6 @@ func init() { xgb.NewExtEventFuncs["RANDR"][1] = NotifyEventNew } -const ( - NotifyCrtcChange = 0 - NotifyOutputChange = 1 - NotifyOutputProperty = 2 - NotifyProviderChange = 3 - NotifyProviderProperty = 4 - NotifyResourceChange = 5 -) - // NotifyDataUnion is a represention of the NotifyDataUnion union type. // Note that to *create* a Union, you should *never* create // this struct directly (unless you know what you're doing). @@ -2826,7 +2826,7 @@ func getCrtcTransformReply(buf []byte) *GetCrtcTransformReply { byteString := make([]byte, v.PendingLen) copy(byteString[:v.PendingLen], buf[b:]) v.PendingFilterName = string(byteString) - b += xgb.Pad(int(v.PendingLen)) + b += int(v.PendingLen) } v.PendingParams = make([]render.Fixed, v.PendingNparams) @@ -2840,7 +2840,7 @@ func getCrtcTransformReply(buf []byte) *GetCrtcTransformReply { byteString := make([]byte, v.CurrentLen) copy(byteString[:v.CurrentLen], buf[b:]) v.CurrentFilterName = string(byteString) - b += xgb.Pad(int(v.CurrentLen)) + b += int(v.CurrentLen) } v.CurrentParams = make([]render.Fixed, v.CurrentNparams) @@ -3518,7 +3518,7 @@ func getProviderInfoReply(buf []byte) *GetProviderInfoReply { byteString := make([]byte, v.NameLen) copy(byteString[:v.NameLen], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.NameLen)) + b += int(v.NameLen) } return v diff --git a/nexgb/xf86dri/xf86dri.go b/nexgb/xf86dri/xf86dri.go index 46fabca..65fcfa0 100644 --- a/nexgb/xf86dri/xf86dri.go +++ b/nexgb/xf86dri/xf86dri.go @@ -659,7 +659,7 @@ func getClientDriverNameReply(buf []byte) *GetClientDriverNameReply { byteString := make([]byte, v.ClientDriverNameLen) copy(byteString[:v.ClientDriverNameLen], buf[b:]) v.ClientDriverName = string(byteString) - b += xgb.Pad(int(v.ClientDriverNameLen)) + b += int(v.ClientDriverNameLen) } return v @@ -1017,7 +1017,7 @@ func openConnectionReply(buf []byte) *OpenConnectionReply { byteString := make([]byte, v.BusIdLen) copy(byteString[:v.BusIdLen], buf[b:]) v.BusId = string(byteString) - b += xgb.Pad(int(v.BusIdLen)) + b += int(v.BusIdLen) } return v diff --git a/nexgb/xf86vidmode/xf86vidmode.go b/nexgb/xf86vidmode/xf86vidmode.go index 5a3f63d..44228c4 100644 --- a/nexgb/xf86vidmode/xf86vidmode.go +++ b/nexgb/xf86vidmode/xf86vidmode.go @@ -1543,7 +1543,7 @@ func getMonitorReply(buf []byte) *GetMonitorReply { byteString := make([]byte, v.VendorLength) copy(byteString[:v.VendorLength], buf[b:]) v.Vendor = string(byteString) - b += xgb.Pad(int(v.VendorLength)) + b += int(v.VendorLength) } v.AlignmentPad = make([]byte, (((int(v.VendorLength) + 3) & -4) - int(v.VendorLength))) @@ -1554,7 +1554,7 @@ func getMonitorReply(buf []byte) *GetMonitorReply { byteString := make([]byte, v.ModelLength) copy(byteString[:v.ModelLength], buf[b:]) v.Model = string(byteString) - b += xgb.Pad(int(v.ModelLength)) + b += int(v.ModelLength) } return v diff --git a/nexgb/xfixes/xfixes.go b/nexgb/xfixes/xfixes.go index a34df54..9a08c93 100644 --- a/nexgb/xfixes/xfixes.go +++ b/nexgb/xfixes/xfixes.go @@ -1495,7 +1495,7 @@ func getCursorImageAndNameReply(buf []byte) *GetCursorImageAndNameReply { byteString := make([]byte, v.Nbytes) copy(byteString[:v.Nbytes], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.Nbytes)) + b += int(v.Nbytes) } v.CursorImage = make([]uint32, (int(v.Width) * int(v.Height))) @@ -1602,7 +1602,7 @@ func getCursorNameReply(buf []byte) *GetCursorNameReply { byteString := make([]byte, v.Nbytes) copy(byteString[:v.Nbytes], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.Nbytes)) + b += int(v.Nbytes) } return v diff --git a/nexgb/xgbgen/go_list.go b/nexgb/xgbgen/go_list.go index 4cf962a..fa8df69 100644 --- a/nexgb/xgbgen/go_list.go +++ b/nexgb/xgbgen/go_list.go @@ -29,7 +29,10 @@ func (f *ListField) Read(c *Context, prefix string) { c.Putln("byteString := make([]%s, %s)", t.SrcName(), length) c.Putln("copy(byteString[:%s], buf[b:])", length) c.Putln("%s%s = string(byteString)", prefix, f.SrcName()) - c.Putln("b += xgb.Pad(int(%s))", length) + // This is apparently a special case. The "Str" type itself + // doesn't specify any padding. I suppose it's up to the + // request/reply spec that uses it to get the padding right? + c.Putln("b += int(%s)", length) c.Putln("}") } else if t.SrcName() == "byte" { c.Putln("%s%s = make([]%s, %s)", diff --git a/nexgb/xproto/xproto.go b/nexgb/xproto/xproto.go index 5579ba9..36ab545 100644 --- a/nexgb/xproto/xproto.go +++ b/nexgb/xproto/xproto.go @@ -5404,7 +5404,7 @@ func SetupAuthenticateRead(buf []byte, v *SetupAuthenticate) int { byteString := make([]byte, (int(v.Length) * 4)) copy(byteString[:(int(v.Length)*4)], buf[b:]) v.Reason = string(byteString) - b += xgb.Pad(int((int(v.Length) * 4))) + b += int((int(v.Length) * 4)) } return b @@ -5492,7 +5492,7 @@ func SetupFailedRead(buf []byte, v *SetupFailed) int { byteString := make([]byte, v.ReasonLen) copy(byteString[:v.ReasonLen], buf[b:]) v.Reason = string(byteString) - b += xgb.Pad(int(v.ReasonLen)) + b += int(v.ReasonLen) } return b @@ -5647,7 +5647,7 @@ func SetupInfoRead(buf []byte, v *SetupInfo) int { byteString := make([]byte, v.VendorLen) copy(byteString[:v.VendorLen], buf[b:]) v.Vendor = string(byteString) - b += xgb.Pad(int(v.VendorLen)) + b += int(v.VendorLen) } v.PixmapFormats = make([]Format, v.PixmapFormatsLen) @@ -5802,14 +5802,14 @@ func SetupRequestRead(buf []byte, v *SetupRequest) int { byteString := make([]byte, v.AuthorizationProtocolNameLen) copy(byteString[:v.AuthorizationProtocolNameLen], buf[b:]) v.AuthorizationProtocolName = string(byteString) - b += xgb.Pad(int(v.AuthorizationProtocolNameLen)) + b += int(v.AuthorizationProtocolNameLen) } { byteString := make([]byte, v.AuthorizationProtocolDataLen) copy(byteString[:v.AuthorizationProtocolDataLen], buf[b:]) v.AuthorizationProtocolData = string(byteString) - b += xgb.Pad(int(v.AuthorizationProtocolDataLen)) + b += int(v.AuthorizationProtocolDataLen) } return b @@ -5903,7 +5903,7 @@ func StrRead(buf []byte, v *Str) int { byteString := make([]byte, v.NameLen) copy(byteString[:v.NameLen], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.NameLen)) + b += int(v.NameLen) } return b @@ -9036,7 +9036,7 @@ func getAtomNameReply(buf []byte) *GetAtomNameReply { byteString := make([]byte, v.NameLen) copy(byteString[:v.NameLen], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.NameLen)) + b += int(v.NameLen) } return v @@ -11406,7 +11406,7 @@ func listFontsWithInfoReply(buf []byte) *ListFontsWithInfoReply { byteString := make([]byte, v.NameLen) copy(byteString[:v.NameLen], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.NameLen)) + b += int(v.NameLen) } return v diff --git a/nexgb/xselinux/xselinux.go b/nexgb/xselinux/xselinux.go index f24f5d7..454fdf2 100644 --- a/nexgb/xselinux/xselinux.go +++ b/nexgb/xselinux/xselinux.go @@ -62,14 +62,14 @@ func ListItemRead(buf []byte, v *ListItem) int { byteString := make([]byte, v.ObjectContextLen) copy(byteString[:v.ObjectContextLen], buf[b:]) v.ObjectContext = string(byteString) - b += xgb.Pad(int(v.ObjectContextLen)) + b += int(v.ObjectContextLen) } { byteString := make([]byte, v.DataContextLen) copy(byteString[:v.DataContextLen], buf[b:]) v.DataContext = string(byteString) - b += xgb.Pad(int(v.DataContextLen)) + b += int(v.DataContextLen) } return b @@ -224,7 +224,7 @@ func getClientContextReply(buf []byte) *GetClientContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -323,7 +323,7 @@ func getDeviceContextReply(buf []byte) *GetDeviceContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -422,7 +422,7 @@ func getDeviceCreateContextReply(buf []byte) *GetDeviceCreateContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -518,7 +518,7 @@ func getPropertyContextReply(buf []byte) *GetPropertyContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -620,7 +620,7 @@ func getPropertyCreateContextReply(buf []byte) *GetPropertyCreateContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -716,7 +716,7 @@ func getPropertyDataContextReply(buf []byte) *GetPropertyDataContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -818,7 +818,7 @@ func getPropertyUseContextReply(buf []byte) *GetPropertyUseContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -914,7 +914,7 @@ func getSelectionContextReply(buf []byte) *GetSelectionContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -1013,7 +1013,7 @@ func getSelectionCreateContextReply(buf []byte) *GetSelectionCreateContextReply byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -1109,7 +1109,7 @@ func getSelectionDataContextReply(buf []byte) *GetSelectionDataContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -1208,7 +1208,7 @@ func getSelectionUseContextReply(buf []byte) *GetSelectionUseContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -1304,7 +1304,7 @@ func getWindowContextReply(buf []byte) *GetWindowContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v @@ -1403,7 +1403,7 @@ func getWindowCreateContextReply(buf []byte) *GetWindowCreateContextReply { byteString := make([]byte, v.ContextLen) copy(byteString[:v.ContextLen], buf[b:]) v.Context = string(byteString) - b += xgb.Pad(int(v.ContextLen)) + b += int(v.ContextLen) } return v diff --git a/nexgb/xv/xv.go b/nexgb/xv/xv.go index d79a594..32bdd9e 100644 --- a/nexgb/xv/xv.go +++ b/nexgb/xv/xv.go @@ -74,7 +74,7 @@ func AdaptorInfoRead(buf []byte, v *AdaptorInfo) int { byteString := make([]byte, v.NameSize) copy(byteString[:v.NameSize], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.NameSize)) + b += int(v.NameSize) } v.Formats = make([]Format, v.NumFormats) @@ -177,7 +177,7 @@ func AttributeInfoRead(buf []byte, v *AttributeInfo) int { byteString := make([]byte, v.Size) copy(byteString[:v.Size], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.Size)) + b += int(v.Size) } return b @@ -420,7 +420,7 @@ func EncodingInfoRead(buf []byte, v *EncodingInfo) int { byteString := make([]byte, v.NameSize) copy(byteString[:v.NameSize], buf[b:]) v.Name = string(byteString) - b += xgb.Pad(int(v.NameSize)) + b += int(v.NameSize) } return b