Coder Social home page Coder Social logo

Comments (7)

ianlancetaylor avatar ianlancetaylor commented on May 30, 2024 2

We can handle simple cases, but what if we import some other package that has type MyUnsafePointer = unsafe.Pointer and then refer to it as otherpkg.MyUnsafePointer(x) ? Is it better to have some type aliases work and some not, or is it better to not try to make type aliases work? It's not clear to me which approach is less confusing.

from go.

cuonglm avatar cuonglm commented on May 30, 2024

This seems to me a cmd/cgo issue, not the runtime.

cgo does not recorgnize that up(&x.self) is a type conversion, so it emits the cgo check pointer call with up(&x.self) as argument, not &x.self in case of unsafe.Pointer(&x.self).

from go.

ianlancetaylor avatar ianlancetaylor commented on May 30, 2024

I don't know how to fix this except to do full type checking on the cgo input file, which is difficult as we currently expect the type checker to run on cgo output, not cgo input. Fixing this correctly may require something like #16623, which is a lot of work.

from go.

cuonglm avatar cuonglm commented on May 30, 2024

@ianlancetaylor We could probably record type alias only, something like map[string]string{"up": "unsafe.Pointer"}, then the p.isType check can correctly recognize and stripe the type conversion.

from go.

adonovan avatar adonovan commented on May 30, 2024

A related previous issue was #57926, in which users exploited the desugaring of cgo to declare methods on types that appear to belong to package C: func (C.T) method() {} The resolution was to use syntactic heuristics to try to reject it, so that we at least make clear that this is not allowed, even if we can't detect it in general (e.g. in the presence of aliasing) without type checking, which is infeasible for the reason @ianlancetaylor noted.

from go.

dmitshur avatar dmitshur commented on May 30, 2024

@ianlancetaylor Assigned it to you for now, please feel free to update.

from go.

ianlancetaylor avatar ianlancetaylor commented on May 30, 2024

Thanks, I'm unassigning as I have no plans to work on this.

from go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.