-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nusserver example panics on NRF51 (microbit-v1) #176
Comments
I have found another workaround to prevent C call to cause heap allocation. I wrote a simple wrapper CGO function that accepts a struct and calls actual function with pointer to that struct:
It is not perfect since it creates unnecessary copy of a struct, but it is much better solution than using a global. |
@HattoriHanzo031 I think that wrapper function is a nice workaround. It's probably inlined so the big parameter doesn't really matter (especially if you make the wrapper function static). Can you make a PR out of this? Also, that CGo noescape proposal looks quite interesting, that's another way this issue could be fixed. |
PR #192 created |
Here is the proposal: golang/go#56378 They are documented here: https://pkg.go.dev/cmd/cgo@master#hdr-Optimizing_calls_of_C_code This would have been very useful to fix tinygo-org/bluetooth#176 in a nice way. That bug is now fixed in a different way using a wrapper function, but once this new noescape pragma gets included in TinyGo we could remove the workaround and use `#cgo noescape` instead.
I've implemented |
Here is the proposal: golang/go#56378 They are documented here: https://pkg.go.dev/cmd/cgo@master#hdr-Optimizing_calls_of_C_code This would have been very useful to fix tinygo-org/bluetooth#176 in a nice way. That bug is now fixed in a different way using a wrapper function, but once this new noescape pragma gets included in TinyGo we could remove the workaround and use `#cgo noescape` instead.
Here is the proposal: golang/go#56378 They are documented here: https://pkg.go.dev/cmd/cgo@master#hdr-Optimizing_calls_of_C_code This would have been very useful to fix tinygo-org/bluetooth#176 in a nice way. That bug is now fixed in a different way using a wrapper function, but once this new noescape pragma gets included in TinyGo we could remove the workaround and use `#cgo noescape` instead.
Here is the proposal: golang/go#56378 They are documented here: https://pkg.go.dev/cmd/cgo@master#hdr-Optimizing_calls_of_C_code This would have been very useful to fix tinygo-org/bluetooth#176 in a nice way. That bug is now fixed in a different way using a wrapper function, but once this new noescape pragma gets included in TinyGo we could remove the workaround and use `#cgo noescape` instead.
Here is the proposal: golang/go#56378 They are documented here: https://pkg.go.dev/cmd/cgo@master#hdr-Optimizing_calls_of_C_code This would have been very useful to fix tinygo-org/bluetooth#176 in a nice way. That bug is now fixed in a different way using a wrapper function, but once this new noescape pragma gets included in TinyGo we could remove the workaround and use `#cgo noescape` instead.
When running unmodified nusserver example on microbit-v1 after connecting and disconnecting to the device, following panic occurs:
Also, if I try to send any message from the client, following panic occurs:
I am using nRF Toolbox Android app as a client.
The first panic occurs in:
where
params
escapes to heap since escape analysis can't look intoC.sd_ble_gap_adv_start
.start
is called onBLE_GAP_EVT_DISCONNECTED
event inhandleEvent
function, hence the panic.Similar thing happens in second case, and the reason is that in example
WriteEvent
of RX Characteristics writes back to TX Characteristics, and thisWrite
callsC.sd_ble_gatts_hvx
that will escape the pointer to heap.I have made a dirty workaround for this issue on my fork which solves both issue by using global params variables, but I don't think this is a good solution.
Looking at the NRF SDK code it is clear that the
sd_ble_gatts_hvx
call does not need heap allocated argument since in SDK stack variable is used:I think the proper solution would be to somehow force the compiler not to escape the
params
to heap, but I didn't find a way to do this. I tried the trick fromsrc/strings/builder.go
noescape
function, but it didn't work (or I am doing something wrong)The text was updated successfully, but these errors were encountered: