butler icon indicating copy to clipboard operation
butler copied to clipboard

Build fails with Go 1.21

Open SuperSamus opened this issue 1 year ago • 1 comments

Both on release v15.21.0 and on the current latest commit 50d55e90a90f4d03b5cfc7d35d135b30584c91a7, when building with Go 1.21:

# github.com/itchio/dmcunrar-go/dmcunrar
../go/pkg/mod/github.com/itchio/[email protected]/dmcunrar/glue.go:179:11: cannot define new methods on non-local type *C.dmc_unrar_file
# crawshaw.io/sqlite
In file included from /nix/store/x8lqlydsxbrwvf6p7v18gws8kn1xl37f-glibc-2.38-23-dev/include/string.h:548,
                 from ../go/pkg/mod/crawshaw.io/[email protected]/./c/sqlite3.c:14113,
                 from ../go/pkg/mod/crawshaw.io/[email protected]/static.go:19:
In function 'memcpy',
    inlined from 'sqlite3Fts5IndexQuery' at ../go/pkg/mod/crawshaw.io/[email protected]/./c/sqlite3.c:220863:18:
/nix/store/x8lqlydsxbrwvf6p7v18gws8kn1xl37f-glibc-2.38-23-dev/include/bits/string_fortified.h:29:10: warning: '__builtin_memcpy' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~

(The weird path names are because I'm compiling on NixOS)

Compiles fine with Go 1.20.

SuperSamus avatar Oct 26 '23 09:10 SuperSamus

../go/pkg/mod/github.com/itchio/[email protected]/dmcunrar/glue.go:179:11: cannot define new methods on non-local type *C.dmc_unrar_file

As a workaround, editing glue.go and adding a typedef while changing the function type seems to work:

+type dmcUnrarFile C.dmc_unrar_file

-func (fs *C.dmc_unrar_file) GetUncompressedSize() int64 {
+func (fs *dmcUnrarFile) GetUncompressedSize() int64 {
        return int64(fs.uncompressed_size)
 }

https://github.com/itchio/dmcunrar-go/blob/master/dmcunrar/glue.go#L179-L181

diff --git a/dmcunrar/glue.go b/dmcunrar/glue.go
index 3c2fe63..51d7b79 100644
--- a/dmcunrar/glue.go
+++ b/dmcunrar/glue.go
@@ -165,8 +165,9 @@ func (a *Archive) GetFilename(i int64) (string, error) {
        return C.GoString(filename), nil
 }
 
-func (a *Archive) GetFileStat(i int64) *C.dmc_unrar_file {
-       return C.dmc_unrar_get_file_stat(a.archive, C.dmc_unrar_size_t(i))
+func (a *Archive) GetFileStat(i int64) *dmcUnrarFile {
+       var f *C.dmc_unrar_file = C.dmc_unrar_get_file_stat(a.archive, C.dmc_unrar_size_t(i))
+       return (*dmcUnrarFile)(unsafe.Pointer(f))
 }
 
 func (a *Archive) FileIsDirectory(i int64) bool {

LinuxUserGD avatar Mar 04 '24 23:03 LinuxUserGD