geertjohan / cgo.wchar Goto Github PK
View Code? Open in Web Editor NEWThe cgo.wchar package is to be used with go/cgo and helps with the conversion from and to C.wchar_t and wchar_t strings (*C.wchar_t with null terminator or length int).
The cgo.wchar package is to be used with go/cgo and helps with the conversion from and to C.wchar_t and wchar_t strings (*C.wchar_t with null terminator or length int).
Hi
Running 'go test' on masters tip presents me with the following error:
http://sillymon.ch/data/gotesterror.txt
I am running Go tip at
go version devel +6e10ddc0bbc2 Tue May 13 12:17:49 2014 -0700 + linux/amd64
The panic seems to occur in the Go runtime at runtime/mcentral.c because of an empty memory list (the cause seems to be the runeCString := C.CString(string(r))
line in convert.go:184). Can you see anything obviously wrong?
Interestingly enough, after applying the following patch
diff --git a/convert.go b/convert.go
index e669ba9..97e9974 100644
--- a/convert.go
+++ b/convert.go
@@ -173,7 +173,7 @@ func convertGoRuneToWchar(r rune) (output Wchar, err error) {
// bufferSizes for C
bytesLeftInCSize := C.size_t(4)
- bytesLeftOutCSize := C.size_t(4 * 4)
+ bytesLeftOutCSize := C.size_t(4)
// TODO/FIXME: the last 4 bytes as indicated by bytesLeftOutCSize wont be used...
// iconv assumes each given char to be one wchar.
// in this case we know that the given 4 chars will actually be one unicode-point and therefore will result in one wchar.
the tests run (no panic occurs) but iconv(3) sets errno to E2BIG which indicates that the output buffer is too small. This seems odd to me because according to the iconv(3) man page both sizes are in bytes and since a Golang rune is encoded in UTF-8 (and will only contain one Unicode code point) both sizes should never have to be bigger than 4 bytes when converting one rune. I hit this 'go test' issue when I was trying to correct the output buffer size issue.
I also do not know why changing the value of the bytesLeftOutCSize function parameter would result in the C.CString copy suddenly working... any ideas?
Hi,
Could you please add license information?
... in order to compile. (Otherwise we hit a lots of failed casts)
Location: https://github.com/GeertJohan/cgo.wchar/blob/master/wchar.go#L8
I don't know how to define this type conditionally of used platform (Windows or not Windows), so I am not sending a pull request :-/
I get the following when running go test
or use this library (eg. via go.hid) on Windows. I've tried various versions of libiconv-2.dll
to no effect.
Would you have any idea as to what the issue might be?
C:\Users\Seon-Wook\Go\src\github.com\GeertJohan\cgo.wchar>go test
Exception 0xc0000005 0x0 0x876c5bd 0x5a00ac
PC=0x5a00ac
signal arrived during cgo execution
github.com/GeertJohan/cgo%2ewchar._C2func_iconv_open(0x2713c0, 0x272b98, 0x0, 0x0, 0x0)
github.com/GeertJohan/cgo.wchar/_test/_obj_test/_cgo_gotypes.go:39 +0x4f
github.com/GeertJohan/cgo%2ewchar.convertGoStringToWcharString(0x52b5a8, 0x1b, 0x0, 0x0, 0x0, 0x0, 0x0)
C:/Users/Seon-Wook/Go/src/github.com/GeertJohan/cgo.wchar/convert.go:43 +0x15a
github.com/GeertJohan/cgo%2ewchar.FromGoString(0x52b5a8, 0x1b, 0x0, 0x0, 0x0, 0x0, 0x0)
C:/Users/Seon-Wook/Go/src/github.com/GeertJohan/cgo.wchar/wchar.go:47 +0x58
github.com/GeertJohan/cgo%2ewchar.TestStringConversion(0x202220c0)
C:/Users/Seon-Wook/Go/src/github.com/GeertJohan/cgo.wchar/wchar_test.go:16 +0x86
testing.tRunner(0x202220c0, 0x5b1040)
c:/go/src/testing/testing.go:447 +0xb1
created by testing.RunTests
c:/go/src/testing/testing.go:555 +0x863
goroutine 1 [chan receive]:
testing.RunTests(0x54c2e0, 0x5b1040, 0x4, 0x4, 0x201f2001)
c:/go/src/testing/testing.go:556 +0x89f
testing.(*M).Run(0x201e82d0, 0x5b9960)
c:/go/src/testing/testing.go:485 +0x5e
main.main()
github.com/GeertJohan/cgo.wchar/_test/_testmain.go:58 +0x177
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
c:/go/src/runtime/asm_386.s:2287 +0x1
eax 0x4d3240
ebx 0x201fbe14
ecx 0x5ba0c0
edx 0x201fbdd4
edi 0x22c
esi 0x5b22e0
ebp 0x5b2500
esp 0x18fe9c
eip 0x5a00ac
eflags 0x10206
cs 0x23
fs 0x53
gs 0x2b
exit status 2
FAIL github.com/GeertJohan/cgo.wchar 0.316s
When running on raspberry pi (linux arm) this will not cast.
./go.hid/hid.go:597: cannot convert ws.Pointer() (type *wchar.Wchar) to type *C.wchar_t
The new rules: https://golang.org/cmd/cgo/#hdr-Passing_pointers
causes a crash in convert.go line 150:
_, errno = C.iconv(iconv, &inputAsCCharsPtr, &bytesLeftInCSize, &outputCharsPtr, &bytesLeftOutCSize)
With the trace:
panic: runtime error: cgo argument has Go pointer to Go pointer
goroutine 3 [running]:
panic(0x437c780, 0xc82000a1c0)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
github.com/GeertJohan/cgo%2ewchar.convertWcharStringToGoString(0xc8200e4100, 0x12, 0x20, 0x0, 0x0, 0x0, 0x0)
/Users/stant/Documents/hackerloop/rotonde/src/github.com/GeertJohan/cgo.wchar/convert.go:150 +0x521
github.com/GeertJohan/cgo%2ewchar.WcharStringPtrToGoString(0x53059f0, 0x0, 0x0, 0x0, 0x0)
/Users/stant/Documents/hackerloop/rotonde/src/github.com/GeertJohan/cgo.wchar/wchar.go:141 +0x91
github.com/GeertJohan/go%2ehid.Enumerate(0x42, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/stant/Documents/hackerloop/rotonde/src/github.com/GeertJohan/go.hid/hid.go:205 +0x35f
main.StartHID.func2(0xc820010140, 0xc820010160, 0xc820010180, 0xc82006e1e0)
[...]
There must be other places in the code causing this crash.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.