Skip to content

Commit

Permalink
It appears that the "Str" type (which is built into the core X protocol)
Browse files Browse the repository at this point in the history
doesn't specify any padding. So it has to be treated as a special case.

Close BurntSushi#12.
  • Loading branch information
BurntSushi committed Dec 28, 2013
1 parent 2763384 commit c354120
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 49 deletions.
4 changes: 2 additions & 2 deletions dri2/dri2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions glx/glx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions randr/randr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions xf86dri/xf86dri.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions xf86vidmode/xf86vidmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions xfixes/xfixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion xgbgen/go_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
16 changes: 8 additions & 8 deletions xproto/xproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions xselinux/xselinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions xv/xv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c354120

Please sign in to comment.