GIR: Don't use `unsafe.Pointer` where we don't have to
Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
- commit
- 8316da1ba9b21825b2eb18365f69b5b706bfcf26
- author
- Felicitas Pojtinger · · 2025-11-18 03:08 UTC
- committer
- Jeroen Wijenbergh · · 2025-12-01 16:14 UTC
- parent
- 42fe8d7
- signature
- unsigned
1 file · +4 -6
M internal/gir/types/template.go +4 -6
| @@ -47,7 +47,7 @@ func (f *funcArgsTemplate) AddAPI(t string, n string, k Kind, ns string, nullabl | |||
| 47 | 47 | // For primitive Go types we need to manually add the * | |
| 48 | 48 | t = "*" + t | |
| 49 | 49 | } | |
| 50 | - | c = fmt.Sprintf("uintptr(unsafe.Pointer(%s))", n) | |
| 50 | + | c = n | |
| 51 | 51 | } else { | |
| 52 | 52 | switch k { | |
| 53 | 53 | case CallbackType: | |
| @@ -96,14 +96,12 @@ func (f *funcArgsTemplate) AddPure(t string, n string, k Kind, isOut bool) { | |||
| 96 | 96 | stars := strings.Count(t, "*") | |
| 97 | 97 | ||
| 98 | 98 | if isOut { | |
| 99 | - | // Out parameters are always pointers in C, so we can use uintptr for the type | |
| 100 | - | goPointerType := t | |
| 99 | + | // Out parameters are always pointers in C | |
| 101 | 100 | if stars == 0 { | |
| 102 | 101 | // For primitive Go types we need to manually add the * | |
| 103 | - | goPointerType = "*" + t | |
| 102 | + | t = "*" + t | |
| 104 | 103 | } | |
| 105 | - | t = "uintptr" | |
| 106 | - | c = fmt.Sprintf("(%s)(unsafe.Pointer(%s))", goPointerType, n) | |
| 104 | + | c = n | |
| 107 | 105 | } else { | |
| 108 | 106 | switch k { | |
| 109 | 107 | case RecordsType: | |
| @@ -47,7 +47,7 @@ func (f *funcArgsTemplate) AddAPI(t string, n string, k Kind, ns string, nullabl | |||||
| 47 | // For primitive Go types we need to manually add the * | 47 | // For primitive Go types we need to manually add the * | ||
| 48 | t = "*" + t | 48 | t = "*" + t | ||
| 49 | } | 49 | } | ||
| 50 | - | c = fmt.Sprintf("uintptr(unsafe.Pointer(%s))", n) | 50 | + | c = n |
| 51 | } else { | 51 | } else { | ||
| 52 | switch k { | 52 | switch k { | ||
| 53 | case CallbackType: | 53 | case CallbackType: | ||
| @@ -96,14 +96,12 @@ func (f *funcArgsTemplate) AddPure(t string, n string, k Kind, isOut bool) { | |||||
| 96 | stars := strings.Count(t, "*") | 96 | stars := strings.Count(t, "*") | ||
| 97 | 97 | ||||
| 98 | if isOut { | 98 | if isOut { | ||
| 99 | - | // Out parameters are always pointers in C, so we can use uintptr for the type | 99 | + | // Out parameters are always pointers in C |
| 100 | - | goPointerType := t | |||
| 101 | if stars == 0 { | 100 | if stars == 0 { | ||
| 102 | // For primitive Go types we need to manually add the * | 101 | // For primitive Go types we need to manually add the * | ||
| 103 | - | goPointerType = "*" + t | 102 | + | t = "*" + t |
| 104 | } | 103 | } | ||
| 105 | - | t = "uintptr" | 104 | + | c = n |
| 106 | - | c = fmt.Sprintf("(%s)(unsafe.Pointer(%s))", goPointerType, n) | |||
| 107 | } else { | 105 | } else { | ||
| 108 | switch k { | 106 | switch k { | ||
| 109 | case RecordsType: | 107 | case RecordsType: | ||