Skip to content

Commit

Permalink
Refactor all "int" to "int32" for sizeof() compatibility. Fixes #683 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kamphaus authored and elliotchance committed Apr 27, 2018
1 parent a3608c3 commit b8188d8
Show file tree
Hide file tree
Showing 33 changed files with 270 additions and 195 deletions.
4 changes: 2 additions & 2 deletions darwin/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
)

// BuiltinExpect handles __builtin_expect().
func BuiltinExpect(a, b int) int {
func BuiltinExpect(a, b int32) int32 {
return noarch.BoolToInt(a != b)
}

// AssertRtn handles __assert_rtn().
func AssertRtn(
functionName, filePath []byte,
lineNumber int,
lineNumber int32,
expression []byte,
) bool {
fmt.Fprintf(
Expand Down
2 changes: 1 addition & 1 deletion darwin/ctype.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// CtRuneT represents __darwin_ct_rune_t.
type CtRuneT int
type CtRuneT int32

// Apple defines a bunch of magic values for the type of character, see
// https://opensource.apple.com/source/Libc/Libc-320/include/ctype.h.auto.html
Expand Down
8 changes: 4 additions & 4 deletions darwin/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package darwin
import "github.com/elliotchance/c2go/noarch"

// BuiltinVsprintfChk - implementation __builtin___vsprintf_chk
func BuiltinVsprintfChk(buffer []byte, _ int, n int, format []byte, args noarch.VaList) int {
func BuiltinVsprintfChk(buffer []byte, _ int32, n int32, format []byte, args noarch.VaList) int32 {
return noarch.Sprintf(buffer, format, args.Args)
}

// BuiltinVsnprintfChk - implementation __builtin___vsnprintf_chk
func BuiltinVsnprintfChk(buffer []byte, n int, _ int, _ int, format []byte, args noarch.VaList) int {
func BuiltinVsnprintfChk(buffer []byte, n int32, _ int32, _ int32, format []byte, args noarch.VaList) int32 {
return noarch.Sprintf(buffer, format, args.Args)
}

// BuiltinSprintfChk - implementation __builtin___sprintf_chk
func BuiltinSprintfChk(buffer []byte, _ int, n int, format []byte, args ...interface{}) int {
func BuiltinSprintfChk(buffer []byte, _ int32, n int32, format []byte, args ...interface{}) int32 {
return noarch.Sprintf(buffer, format, args)
}

// BuiltinSnprintfChk - implementation __builtin___snprintf_chk
func BuiltinSnprintfChk(buffer []byte, n int, _ int, _ int, format []byte, args ...interface{}) int {
func BuiltinSnprintfChk(buffer []byte, n int32, _ int32, _ int32, format []byte, args ...interface{}) int32 {
return noarch.Sprintf(buffer, format, args)
}
8 changes: 4 additions & 4 deletions darwin/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import "github.com/elliotchance/c2go/noarch"

// BuiltinStrcpy is for __builtin___strcpy_chk.
// https://opensource.apple.com/source/Libc/Libc-498/include/secure/_string.h
func BuiltinStrcpy(dest, src []byte, size int) []byte {
func BuiltinStrcpy(dest, src []byte, size int32) []byte {
return noarch.Strcpy(dest, src)
}

// BuiltinObjectSize is for __builtin_object_size.
// https://github.com/elliotchance/c2go/issues/359
func BuiltinObjectSize(ptr []byte, theType int) int {
func BuiltinObjectSize(ptr []byte, theType int32) int32 {
return 5
}

// BuiltinStrncpy is for __builtin___strncpy_chk.
// https://opensource.apple.com/source/Libc/Libc-498/include/secure/_string.h
func BuiltinStrncpy(dest, src []byte, len, size int) []byte {
func BuiltinStrncpy(dest, src []byte, len, size int32) []byte {
return noarch.Strncpy(dest, src, len)
}

// BuiltinStrcat is for __builtin___strcat_chk
// https://opensource.apple.com/source/Libc/Libc-763.12/include/secure/_string.h.auto.html
func BuiltinStrcat(dest, src []byte, _ int) []byte {
func BuiltinStrcat(dest, src []byte, _ int32) []byte {
return noarch.Strcat(dest, src)
}
8 changes: 4 additions & 4 deletions linux/ctype.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func CtypeLoc() [][]uint16 {
}

// ToLower handles tolower().
func ToLower(_c int) int {
return int(unicode.ToLower(rune(_c)))
func ToLower(_c int32) int32 {
return int32(unicode.ToLower(rune(_c)))
}

// ToUpper handles toupper().
func ToUpper(_c int) int {
return int(unicode.ToUpper(rune(_c)))
func ToUpper(_c int32) int32 {
return int32(unicode.ToUpper(rune(_c)))
}
6 changes: 3 additions & 3 deletions linux/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"github.com/elliotchance/c2go/noarch"
)

func IsNanf(x float32) int {
func IsNanf(x float32) int32 {
return noarch.BoolToInt(math.IsNaN(float64(x)))
}

func IsInff(x float32) int {
func IsInff(x float32) int32 {
return noarch.BoolToInt(math.IsInf(float64(x), 0))
}

func IsInf(x float64) int {
func IsInf(x float64) int32 {
return noarch.BoolToInt(math.IsInf(x, 0))
}
14 changes: 10 additions & 4 deletions noarch/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ import (
"math"
)

func Signbitf(x float32) int {
func Signbitf(x float32) int32 {
return BoolToInt(math.Signbit(float64(x)))
}

func Signbitd(x float64) int {
func Signbitd(x float64) int32 {
return BoolToInt(math.Signbit(x))
}

func Signbitl(x float64) int {
func Signbitl(x float64) int32 {
return BoolToInt(math.Signbit(x))
}

func IsNaN(x float64) int {
func IsNaN(x float64) int32 {
return BoolToInt(math.IsNaN(x))
}

// Ldexp is the inverse of Frexp.
// Ldexp uses math.Ldexp to calculate the value.
func Ldexp(frac float64, exp int32) float64 {
return math.Ldexp(frac, int(exp))
}
20 changes: 19 additions & 1 deletion noarch/noarch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package noarch

// BoolToInt converts boolean value to an int, which is a common operation in C.
// 0 and 1 represent false and true respectively.
func BoolToInt(x bool) int {
func BoolToInt(x bool) int32 {
if x {
return 1
}
Expand All @@ -20,6 +20,15 @@ func NotInt(x int) int {
return 0
}

// NotInt32 works the same as NotInt, but on a int32.
func NotInt32(x int32) int32 {
if x == 0 {
return 1
}

return 0
}

// NotUint16 works the same as NotInt, but on a uint16.
func NotUint16(x uint16) uint16 {
if x == 0 {
Expand All @@ -29,6 +38,15 @@ func NotUint16(x uint16) uint16 {
return 0
}

// NotInt8 works the same as NotInt, but on a int8.
func NotInt8(x int8) int8 {
if x == 0 {
return 1
}

return 0
}

// Ternary simulates the ternary (also known as the conditional operator). Go
// does not have the equivalent of using if statements as expressions or inline
// if statements. This function takes the true and false parts as closures to be
Expand Down
Loading

0 comments on commit b8188d8

Please sign in to comment.