Thanks to visit codestin.com
Credit goes to github.com

Skip to content

unsafe.Pointer(nil) doesn't convert correctly to other pointer types. #1060

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

Open
nevkontakte opened this issue Sep 17, 2021 · 0 comments
Open

Comments

@nevkontakte
Copy link
Member

GopherJS's zero value for unsafe.Pointer is a numeric 0 (I'm guessing for interop with uintptr, but not entirely sure). However, this is incompatible with a pointer interface and causes incorrect behavior when converted into another pointer type:

package main

import (
	"unsafe"
)

func main() {
	var up unsafe.Pointer

	p := (*bool)(up)
	if p != nil {
		println("error: p should be nil")
	}
	println("not nil", *p)
}

By contrast, if up is initialized with unsafe.Pointer((*bool)(nil)), the program works correctly.

nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Sep 17, 2021
The fix is two-fold:

 1. `disableSplice` is initialized with `(*bool)(nil)` to work around
    gopherjs#1060.
 2. Skipped `TestSplicePipePool`, which relies in runtime features
    GopherJS doesn't support.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Sep 17, 2021
The fix is two-fold:

 1. `disableSplice` is initialized with `(*bool)(nil)` to work around
    gopherjs#1060.
 2. Skipped `TestSplicePipePool`, which relies in runtime features
    GopherJS doesn't support.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Sep 17, 2021
The fix is two-fold:

 1. `disableSplice` is initialized with `(*bool)(nil)` to work around
    gopherjs#1060.
 2. Skipped `TestSplicePipePool`, which relies in runtime features
    GopherJS doesn't support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant