FAQ
Hi all,

I am reading the runtime code related to channel, the runtime·makechan()
required three arguments, the first of which is ChanType*:

void

runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


My question is that is there a way to get a ChanType or Type value from any
given value of any type?


For example, I define a struct type in runtime.h:

type Stu struct{}


then in some runtime function, I want to create a channel with type Stu*, I
suppose I can only use runtime·makechan to create the channel, right? But I
could not see a way to get the ChanType value corresponding to Stu*. Can
anyone give some hint?


Thanks,

Robert

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Ian Lance Taylor at Mar 15, 2013 at 4:52 am

    On Thu, Mar 14, 2013 at 8:12 PM, Robert Sandra wrote:

    I am reading the runtime code related to channel, the runtime·makechan()
    required three arguments, the first of which is ChanType*:

    void

    runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    My question is that is there a way to get a ChanType or Type value from any
    given value of any type?


    For example, I define a struct type in runtime.h:

    type Stu struct{}


    then in some runtime function, I want to create a channel with type Stu*, I
    suppose I can only use runtime·makechan to create the channel, right? But I
    could not see a way to get the ChanType value corresponding to Stu*. Can
    anyone give some hint?
    That function can't be called directly from Go code; instead, you need
    to call reflect.MakeChan, which calls it using a type that is not
    exported from the reflect package.

    MakeChan takes a reflect.Type. If you have a type T, and you want to
    get the reflect.Type of a chan T, use reflect.ChanOf.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Robert Sandra at Mar 15, 2013 at 5:46 am
    I'm not trying to call the makechan in go application codes, I am trying to
    use it in the runtime system, for example, in some codes under
    src/pkg/runtime/

    So I suppose I need to use the functions in src/pkg/runtime/chan.c to
    create a channel. Here are two makechan in chan.c, which are

    void reflect·makechan(ChanType *t, uint64 size, Hchan *c)

    void runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    Both of them use a ChanType* argument. My problem is that I could not find
    a way to get a ChanType. For example, if I try to create a channel with
    type StructA*, then I need a ChanType* related to StructA* so that I can
    give it to the makechan fucntion. Am I right?

    But so far according to my understanding, the ChanType or Type information
    are all coming from AST level, correct?

    Thanks,
    Robert


    On Friday, March 15, 2013 12:52:26 AM UTC-4, Ian Lance Taylor wrote:

    On Thu, Mar 14, 2013 at 8:12 PM, Robert Sandra
    <robert.s...@gmail.com <javascript:>> wrote:
    I am reading the runtime code related to channel, the runtime·makechan()
    required three arguments, the first of which is ChanType*:

    void

    runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    My question is that is there a way to get a ChanType or Type value from any
    given value of any type?


    For example, I define a struct type in runtime.h:

    type Stu struct{}


    then in some runtime function, I want to create a channel with type Stu*, I
    suppose I can only use runtime·makechan to create the channel, right? But I
    could not see a way to get the ChanType value corresponding to Stu*. Can
    anyone give some hint?
    That function can't be called directly from Go code; instead, you need
    to call reflect.MakeChan, which calls it using a type that is not
    exported from the reflect package.

    MakeChan takes a reflect.Type. If you have a type T, and you want to
    get the reflect.Type of a chan T, use reflect.ChanOf.

    Ian
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dmitry Vyukov at Mar 15, 2013 at 5:54 am

    On Fri, Mar 15, 2013 at 9:46 AM, Robert Sandra wrote:
    I'm not trying to call the makechan in go application codes, I am trying to
    use it in the runtime system, for example, in some codes under
    src/pkg/runtime/
    You can implement that in Go. That is the simplest option.


    So I suppose I need to use the functions in src/pkg/runtime/chan.c to create
    a channel. Here are two makechan in chan.c, which are

    void reflect·makechan(ChanType *t, uint64 size, Hchan *c)

    void runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    Both of them use a ChanType* argument. My problem is that I could not find a
    way to get a ChanType. For example, if I try to create a channel with type
    StructA*, then I need a ChanType* related to StructA* so that I can give it
    to the makechan fucntion. Am I right?

    But so far according to my understanding, the ChanType or Type information
    are all coming from AST level, correct?

    Thanks,
    Robert


    On Friday, March 15, 2013 12:52:26 AM UTC-4, Ian Lance Taylor wrote:

    On Thu, Mar 14, 2013 at 8:12 PM, Robert Sandra
    wrote:
    I am reading the runtime code related to channel, the runtime·makechan()
    required three arguments, the first of which is ChanType*:

    void

    runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    My question is that is there a way to get a ChanType or Type value from
    any
    given value of any type?


    For example, I define a struct type in runtime.h:

    type Stu struct{}


    then in some runtime function, I want to create a channel with type
    Stu*, I
    suppose I can only use runtime·makechan to create the channel, right?
    But I
    could not see a way to get the ChanType value corresponding to Stu*. Can
    anyone give some hint?
    That function can't be called directly from Go code; instead, you need
    to call reflect.MakeChan, which calls it using a type that is not
    exported from the reflect package.

    MakeChan takes a reflect.Type. If you have a type T, and you want to
    get the reflect.Type of a chan T, use reflect.ChanOf.

    Ian
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Robert Sandra at Mar 15, 2013 at 6:37 am
    By implementing in Go, do you mean I implement another makechan function or
    another function to get a CharType or Type? Thank you.

    On Friday, March 15, 2013 1:54:36 AM UTC-4, Dmitry Vyukov wrote:

    On Fri, Mar 15, 2013 at 9:46 AM, Robert Sandra
    <robert.s...@gmail.com <javascript:>> wrote:
    I'm not trying to call the makechan in go application codes, I am trying to
    use it in the runtime system, for example, in some codes under
    src/pkg/runtime/
    You can implement that in Go. That is the simplest option.


    So I suppose I need to use the functions in src/pkg/runtime/chan.c to create
    a channel. Here are two makechan in chan.c, which are

    void reflect·makechan(ChanType *t, uint64 size, Hchan *c)

    void runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    Both of them use a ChanType* argument. My problem is that I could not find a
    way to get a ChanType. For example, if I try to create a channel with type
    StructA*, then I need a ChanType* related to StructA* so that I can give it
    to the makechan fucntion. Am I right?

    But so far according to my understanding, the ChanType or Type
    information
    are all coming from AST level, correct?

    Thanks,
    Robert


    On Friday, March 15, 2013 12:52:26 AM UTC-4, Ian Lance Taylor wrote:

    On Thu, Mar 14, 2013 at 8:12 PM, Robert Sandra
    wrote:
    I am reading the runtime code related to channel, the
    runtime·makechan()
    required three arguments, the first of which is ChanType*:

    void

    runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    My question is that is there a way to get a ChanType or Type value
    from
    any
    given value of any type?


    For example, I define a struct type in runtime.h:

    type Stu struct{}


    then in some runtime function, I want to create a channel with type
    Stu*, I
    suppose I can only use runtime·makechan to create the channel, right?
    But I
    could not see a way to get the ChanType value corresponding to Stu*.
    Can
    anyone give some hint?
    That function can't be called directly from Go code; instead, you need
    to call reflect.MakeChan, which calls it using a type that is not
    exported from the reflect package.

    MakeChan takes a reflect.Type. If you have a type T, and you want to
    get the reflect.Type of a chan T, use reflect.ChanOf.

    Ian
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dmitry Vyukov at Mar 15, 2013 at 7:22 am
    No, I mean just implement your functionality in Go, then you can use
    make(chan T).

    On Fri, Mar 15, 2013 at 10:37 AM, Robert Sandra
    wrote:
    By implementing in Go, do you mean I implement another makechan function or
    another function to get a CharType or Type? Thank you.

    On Friday, March 15, 2013 1:54:36 AM UTC-4, Dmitry Vyukov wrote:

    On Fri, Mar 15, 2013 at 9:46 AM, Robert Sandra
    wrote:
    I'm not trying to call the makechan in go application codes, I am trying
    to
    use it in the runtime system, for example, in some codes under
    src/pkg/runtime/
    You can implement that in Go. That is the simplest option.


    So I suppose I need to use the functions in src/pkg/runtime/chan.c to
    create
    a channel. Here are two makechan in chan.c, which are

    void reflect·makechan(ChanType *t, uint64 size, Hchan *c)

    void runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    Both of them use a ChanType* argument. My problem is that I could not
    find a
    way to get a ChanType. For example, if I try to create a channel with
    type
    StructA*, then I need a ChanType* related to StructA* so that I can give
    it
    to the makechan fucntion. Am I right?

    But so far according to my understanding, the ChanType or Type
    information
    are all coming from AST level, correct?

    Thanks,
    Robert


    On Friday, March 15, 2013 12:52:26 AM UTC-4, Ian Lance Taylor wrote:

    On Thu, Mar 14, 2013 at 8:12 PM, Robert Sandra
    wrote:
    I am reading the runtime code related to channel, the
    runtime·makechan()
    required three arguments, the first of which is ChanType*:

    void

    runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    My question is that is there a way to get a ChanType or Type value
    from
    any
    given value of any type?


    For example, I define a struct type in runtime.h:

    type Stu struct{}


    then in some runtime function, I want to create a channel with type
    Stu*, I
    suppose I can only use runtime·makechan to create the channel, right?
    But I
    could not see a way to get the ChanType value corresponding to Stu*.
    Can
    anyone give some hint?
    That function can't be called directly from Go code; instead, you need
    to call reflect.MakeChan, which calls it using a type that is not
    exported from the reflect package.

    MakeChan takes a reflect.Type. If you have a type T, and you want to
    get the reflect.Type of a chan T, use reflect.ChanOf.

    Ian
    --
    You received this message because you are subscribed to the Google
    Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an
    email to golang-nuts...@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ian Lance Taylor at Mar 15, 2013 at 1:20 pm

    On Thu, Mar 14, 2013 at 10:46 PM, Robert Sandra wrote:
    I'm not trying to call the makechan in go application codes, I am trying to
    use it in the runtime system, for example, in some codes under
    src/pkg/runtime/

    So I suppose I need to use the functions in src/pkg/runtime/chan.c to create
    a channel. Here are two makechan in chan.c, which are

    void reflect·makechan(ChanType *t, uint64 size, Hchan *c)

    void runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    Both of them use a ChanType* argument. My problem is that I could not find a
    way to get a ChanType. For example, if I try to create a channel with type
    StructA*, then I need a ChanType* related to StructA* so that I can give it
    to the makechan fucntion. Am I right?
    Yes. But it seems a peculiar thing to want to do.
    But so far according to my understanding, the ChanType or Type information
    are all coming from AST level, correct?
    No. They mostly come from the AST, but, as I said earlier, you can
    also get one via reflect.ChanOf.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Robert Sandra at Mar 15, 2013 at 5:34 am

    On Thursday, March 14, 2013 11:12:46 PM UTC-4, Robert Sandra wrote:
    Hi all,

    I am reading the runtime code related to channel, the runtime·makechan()
    required three arguments, the first of which is ChanType*:

    void

    runtime·makechan(ChanType *t, int64 hint, Hchan *ret)


    My question is that is there a way to get a ChanType or Type value from
    any given value of any type?


    For example, I define a struct type in runtime.h:

    type Stu struct{}


    then in some runtime function, I want to create a channel with type Stu*,
    I suppose I can only use runtime·makechan to create the channel, right?
    But I could not see a way to get the ChanType value corresponding to Stu*.
    Can anyone give some hint?


    Thanks,

    Robert
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 15, '13 at 3:12a
activeMar 15, '13 at 1:20p
posts8
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase