Re: [go-nuts] cgo & long jump

2019-12-09 Thread Ian Lance Taylor
On Mon, Dec 9, 2019 at 10:30 AM  wrote:
>
> So should I interpret your answer as long jumps are not supported and
> caller of C function from Go must ensure that called C function would
> not call longjmp()?

Correct: Go code should not call C code that calls longjmp.  (Well,
it's OK to call C code that calls setjmp and then calls longjmp back
to that setjmp; what's not OK is using longjmp to jump across or out
of the Go code.)

> And another interesting question, it is possible to call longjmp() from
> Go code? To throw C exception back to the main C application.

No.

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXX6_%2BUTHduk51%2BWuivk1g5DN9xar-g93RR-th9J6rsWQ%40mail.gmail.com.


Re: [go-nuts] Help with Go channels and select talk

2019-12-09 Thread 'Bryan C. Mills' via golang-nuts
I agree. It seems to me that the problem in example 2 is deep in the 
architecture of the program, not just a detail of the `select` statements.
The `connect` function essentially functions as a single-worker “worker 
pool”, storing the data in a goroutine (specifically, in the closure of the 
`srv` function). The need for the channels at all seems unmotivated, and so 
the use of the channels seems inappropriate — I suspect that that is why 
you aren't finding a satisfactory solution.


Stepping up a level: Egon, you say that you “want to show what not to do.”
That is pretty much the premise of my GopherCon 2018 talk, Rethinking 
Classical Concurrency Patterns (https://www.youtube.com/watch?v=5zXAHh5tJqQ
).

I would suggest going back to a more concrete problem and re-examining it 
with the advice of that talk in mind.
(If you would like more detail on how to apply that advice, I'd be happy to 
take a look at concrete examples — but I agree with Robert that the code 
posted earlier is too abstract to elicit useful feedback.)


On Sunday, December 8, 2019 at 1:57:09 AM UTC-5, Robert Engels wrote:
>
> I’m sorry, but it’s very hard to understand when you start with solutions. 
> I think maybe clearly restating the problem will allow more people to offer 
> up ideas. To be honest at this point I’m not really certain what you’re 
> trying to demonstrate or why. 
>
> On Dec 8, 2019, at 12:44 AM, Egon Kocjan > 
> wrote:
>
> I meant lock-free as in "without explicit locks".
>
> The original challenge still stands if someone has a better solution than 
> me:
> "The deadlocks in 2_1.go and 2_2.go are caused by the simplistic and wrong 
> implementation of bidi-comm, which is what I'll be illustrating. I have 
> three working solutions - 1_1.go, 2_3.go, 2_4.go. So the question is, can 
> we remove the extra goroutine from 1_1.go and make the code nicer to read 
> than 2_3.go and 2_4.go. The extra goroutine that I'd like to be removed is 
> started here:
> https://github.com/egonk/chandemo/blob/master/1_1.go#L14 (line 14)"
>
> On Sunday, December 8, 2019 at 7:18:16 AM UTC+1, Robert Engels wrote:
>>
>> I understand what you are saying but I’ll still suggest that your 
>> premise/design is not correct. There are plenty of useful lock free 
>> structures in Go (see github.com/robaho/go-concurrency-test) but that is 
>> not what you are attempting here... you are using async processing - these 
>> are completely different things. Using async in Go is an anti-pattern IMO. 
>>
>> On Dec 8, 2019, at 12:11 AM, Egon Kocjan  wrote:
>>
>> 
>> I'll cite myself:
>> "I'm preparing a short talk about Go channels and select. More 
>> specifically, I want to show what not to do."
>> and
>> "it would be tempting to just combine two goroutines into one and handle 
>> caching in a single loop without using locks (I see developers avoid 
>> atomics and locks if they don't have a lot of previous experience with 
>> traditional MT primitives)"
>>
>> Before I say one can't do something in Go, I wanted to ask here to make 
>> sure I'm not missing something obvious. Basically, I intend to show how 
>> difficult lock-free programming can be so don't force it - just use 
>> goroutines and locks.
>>
>> On Saturday, December 7, 2019 at 3:46:43 PM UTC+1, Robert Engels wrote:
>>>
>>> Probably not. Go is designed for 1:1 and there is no reason to do it 
>>> differently. You could probably try to write an async event driven layer 
>>> (which it looks like you’ve tried) but why???
>>>
>>> It’s like saying I’d really like my plane to float - you can do that 
>>> -but most likely you want a boat instead of a plane. 
>>>
>>> On Dec 7, 2019, at 2:38 AM, Egon Kocjan  wrote:
>>>
>>> 
>>> I'll try to clarify as best as I can, thanks again to anyone looking at 
>>> this.
>>>
>>> The simple server implementation of "output <- input+1" is here and it 
>>> is not "under our control" - it's what we have to work with: 
>>> https://github.com/egonk/chandemo/blob/master/server.go
>>>
>>> The test runner or client is here: 
>>> https://github.com/egonk/chandemo/blob/master/demo.go (it just pushes 
>>> in ints and gets server replies back through a connection layer)
>>>
>>> The deadlocks in 2_1.go and 2_2.go are caused by the simplistic and 
>>> wrong implementation of bidi-comm, which is what I'll be illustrating. I 
>>> have three working solutions - 1_1.go, 2_3.go, 2_4.go. So the question is, 
>>> can we remove the extra goroutine from 1_1.go and make the code nicer to 
>>> read than 2_3.go and 2_4.go. The extra goroutine that I'd like to be 
>>> removed is started here:
>>> https://github.com/egonk/chandemo/blob/master/1_1.go#L14 (line 14)
>>>
>>> What I mean by removed - no go statement, replaced presumably by some 
>>> kind of for/select combination.
>>>
>>> On Saturday, December 7, 2019 at 7:02:50 AM UTC+1, robert engels wrote:

 I’m sorry but your design is not comprehendible by me, and I’ve done 
 lots of TCP based services. 

 i think 

Re: [go-nuts] Re: help with reflect

2019-12-09 Thread Dan Kortschak
On Mon, 2019-12-09 at 14:57 +0300, Vasiliy Tolstov wrote:
> Nevermind. I found the error

https://paulcunningham.me/nevermind-found-answer/

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/082f8b8be7059b9a747cb5eb2b33e51124cf6a10.camel%40kortschak.io.


Re: [go-nuts] cgo & long jump

2019-12-09 Thread Dan Kortschak
This breaks my already fairly tenuous grasp of the progression of time;
what do you mean by since "since then" when that event is a personal
that is in the past (do you mean between going to sleep in the future
and waking up in the past).

Time [travel] is hard.

On Mon, 2019-12-09 at 11:24 -0800, Michael Jones wrote:
> It's premise is that the app can go back in time, like you
> waking up last week with no knowledge of what happened since then.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6ce80e6c9aacecd27df6f0b75eb2d2f9b933.camel%40kortschak.io.


[go-nuts] Re: [golang-dev] Go 1.13.5 and Go 1.12.14 are released

2019-12-09 Thread Brian Hatfield
Hi there,

This appears to still not be available in Homebrew:
https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb

Is there a plan for releasing 1.13.5 to Homebrew?

Thanks!

On Wed, Dec 4, 2019 at 9:01 PM Alexander Rakoczy  wrote:

> Hello gophers,
>
> We have just released Go versions 1.13.5 and 1.12.14, minor point releases.
>
> These releases include fixes to the go command, the runtime, the linker,
> and the net/http package.
>
> View the release notes for more information:
> https://golang.org/doc/devel/release.html#go1.13.minor
>
> You can download the binary and source distributions from the Go web site:
> https://golang.org/dl/
>
> To compile from source using a Git clone, update to the release with
> "git checkout go1.13.5" and build as usual.
>
> Thanks to everyone who contributed to the release.
>
> Cheers,
> Carlos & Alex from the Go team
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-dev/CAFtHmMgzr5nJZ%3DRW03rhEtbB524HiQQUXfvL_XWWES0gKsrwOQ%40mail.gmail.com
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANGiwgamzAb50AWPeniJ%3DzjG-g8%2BA0jVofet-oxk5Zo5Q13_MQ%40mail.gmail.com.


Re: [go-nuts] cgo & long jump

2019-12-09 Thread Robert Engels


That usage of setjmp and longjmp are pretty much banned in modern C by every 
linter. You can only call setjmp/longjmp within the current call stack (at 
least that's my understanding) - intermixing the context switch to Go would not 
be correct.

Just have a wrapper on f2() that takes the setjmp address() and set it and call 
f2().



-Original Message-
>From: p...@cpan.org
>Sent: Dec 9, 2019 12:30 PM
>To: Ian Lance Taylor 
>Cc: golang-nuts 
>Subject: Re: [go-nuts] cgo & long jump
>
>On Monday 09 December 2019 10:18:26 Ian Lance Taylor wrote:
>> On Mon, Dec 9, 2019 at 8:57 AM  wrote:
>> >
>> > I would like to ask some technical question about cgo and long jumps.
>> >
>> > In Go I have written shared library which exports C API and therefore
>> > can be called by other C applications. This my library is compiling with
>> > cgo, more precisely via: go build -buildmode=c-shared -compiler gc
>> >
>> > Now I would like to call from my Go library some C function which may
>> > call longjmp(). And setjmp() was already called by application which is
>> > using my Go library.
>> >
>> > It is possible to call from Go C function which calls longjmp() which
>> > jumps outside of that my Go library? What would happen with Go garbage
>> > collector and "defer" code?
>> >
>> > To imagine, whole stack looks like this:
>> >
>> >   +--+
>> >   | C application|
>> >   | main():  |
>> >   |   call setjmp()  |
>> >   |   call f1() from Go library  |
>> >   |   ...|
>> >   +--+
>> >   | Go library with exported C f1() function |
>> >   | f1():|
>> >   |   do something in Go |
>> >   |   call f2() from C library   |
>> >   |   ...|
>> >   |   return from f1()   |
>> >   +--+
>> >   | C library with exported f2() function|
>> >   | f2():|
>> >   |   do something in C  |
>> >   |   if error call longjmp()|
>> >   |   else return from f2()  |
>> >   +--+
>> >
>> > And if longjmp() is called then it jumps to main() where setjmp() was
>> > called. So effectively f1() function (in Go) does not return.
>> 
>> I'm pretty sure that won't work at all.  Sorry.
>
>Hi Ian! Thank you for your answer.
>
>I was trying to find any resource on Internet about long jumps and
>"import C" but neither in official Go documentation nor in any other
>blog post is written about it.
>
>There are many resources how Go is (fully) compatible with C and can
>call C functions, but absolutely zero information how it is implemented
>nor what would happen with such core feature of C language as long jumps
>or signals.
>
>> Certainly no Go deferred functions will be run.  I don't think this
>> would break the garbage collector as such, but I expect that it would
>> break the Go scheduler.  In the best case you'll be left with a
>> dangling goroutine that will never be run and never go away.
>
>So should I interpret your answer as long jumps are not supported and
>caller of C function from Go must ensure that called C function would
>not call longjmp()?
>
>
>And another interesting question, it is possible to call longjmp() from
>Go code? To throw C exception back to the main C application.
>
>-- 
>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+unsubscr...@googlegroups.com.
>To view this discussion on the web visit 
>https://groups.google.com/d/msgid/golang-nuts/20191209183039.khrexxnpedzitepy%40pali.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/168169317.2354.1575919493589%40wamui-lola.atl.sa.earthlink.net.


Re: [go-nuts] cgo & long jump

2019-12-09 Thread Michael Jones
The longjmp() facility is a wild, dangerous, improper, and popular
mechanism. It's premise is that the app can go back in time, like you
waking up last week with no knowledge of what happened since then. If you
can follow that analogy, then imagine your surprise when external things
you did last week--ordering from Amazon or getting married--start showing
up in your life by surprise or you fail to show up as you should in theirs,
through ignorance, with consequences either way. So it will be with the
relationship between C and Go. You'll leave many things hanging or
abandoned when you longump() back to your application's youth.

(I imagine this is colorful terms, like getting a text on my phone reading
"setjmp() returned 1" and having a paroxysm of imagined crises like "maybe
I got married, had a daughter, and she's waiting for me now at daycare!
OMG, I just don't know.")

On Mon, Dec 9, 2019 at 10:30 AM  wrote:

> On Monday 09 December 2019 10:18:26 Ian Lance Taylor wrote:
> > On Mon, Dec 9, 2019 at 8:57 AM  wrote:
> > >
> > > I would like to ask some technical question about cgo and long jumps.
> > >
> > > In Go I have written shared library which exports C API and therefore
> > > can be called by other C applications. This my library is compiling
> with
> > > cgo, more precisely via: go build -buildmode=c-shared -compiler gc
> > >
> > > Now I would like to call from my Go library some C function which may
> > > call longjmp(). And setjmp() was already called by application which is
> > > using my Go library.
> > >
> > > It is possible to call from Go C function which calls longjmp() which
> > > jumps outside of that my Go library? What would happen with Go garbage
> > > collector and "defer" code?
> > >
> > > To imagine, whole stack looks like this:
> > >
> > >   +--+
> > >   | C application|
> > >   | main():  |
> > >   |   call setjmp()  |
> > >   |   call f1() from Go library  |
> > >   |   ...|
> > >   +--+
> > >   | Go library with exported C f1() function |
> > >   | f1():|
> > >   |   do something in Go |
> > >   |   call f2() from C library   |
> > >   |   ...|
> > >   |   return from f1()   |
> > >   +--+
> > >   | C library with exported f2() function|
> > >   | f2():|
> > >   |   do something in C  |
> > >   |   if error call longjmp()|
> > >   |   else return from f2()  |
> > >   +--+
> > >
> > > And if longjmp() is called then it jumps to main() where setjmp() was
> > > called. So effectively f1() function (in Go) does not return.
> >
> > I'm pretty sure that won't work at all.  Sorry.
>
> Hi Ian! Thank you for your answer.
>
> I was trying to find any resource on Internet about long jumps and
> "import C" but neither in official Go documentation nor in any other
> blog post is written about it.
>
> There are many resources how Go is (fully) compatible with C and can
> call C functions, but absolutely zero information how it is implemented
> nor what would happen with such core feature of C language as long jumps
> or signals.
>
> > Certainly no Go deferred functions will be run.  I don't think this
> > would break the garbage collector as such, but I expect that it would
> > break the Go scheduler.  In the best case you'll be left with a
> > dangling goroutine that will never be run and never go away.
>
> So should I interpret your answer as long jumps are not supported and
> caller of C function from Go must ensure that called C function would
> not call longjmp()?
>
>
> And another interesting question, it is possible to call longjmp() from
> Go code? To throw C exception back to the main C application.
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/20191209183039.khrexxnpedzitepy%40pali
> .
>


-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQzJ9hJXv%3DSmnsXHuiQtHHghBRwZcZMQBBQOD%2BfJADBrZA%40mail.gmail.com.


Re: [go-nuts] Re: Why Iran is banned by Google?

2019-12-09 Thread Michael Jones
Hello parisaparvizi1994,

Your frustration feels natural and understandable to me. Jan just answered
you clearly, but since my words did not help, I'm thinking to try again.
Maybe I can do better this time. First though, I must be clear that *I no
longer speak for Google*--well, at least not officially
--though
what I said back then is still true now.

Every country has rules concerning its citizens' actions and potential
interactions with other countries.

Every company, from Mobarakeh Steel Company to Coca-Cola Inc., has a main
office in its home country, such as Iran or the USA. In every case, the
company is a "legal person" responsible to obey the laws of its home
country as well as any other countries where it does business.

When a pair of countries have some disagreement or debate, and it takes the
form of restrictions on free trade, then there will be laws shaping,
restricting, or preventing commerce, import, export, or even visiting. Many
pairs of countries have at least some form of this and such cases, citizens
and local businesses are limited in their actions.

The United States law includes: *"Title 31 → Subtitle B → Chapter V → Part
560 → Subpart B → §560.204: Prohibited exportation, reexportation, sale, or
supply of goods, technology, or services to Iran
."*
These
and other regulations are the barriers you feel; barriers that do not mean
the companies or people obeying the law are happy about it. Maybe Mobarakeh
Steel would like to sell steel in the USA, and in much the same way,
Google's stated desire is to share information helpfully with everyone
everywhere.

Hopefully you can see that it is Google being banned from freely sharing to
Iran and not Google banning Iran or its people from information.

Michael

P.S. Thank you Jan

On Mon, Dec 9, 2019 at 9:34 AM Jan Mercl <0xj...@gmail.com> wrote:

> On Mon, Dec 9, 2019 at 5:57 PM  wrote:
>
> > So in simpler words, Google has banned Iran, right?
>
> Wrong. Michael was, 5 years ago, very precise and clear about the
> facts, which are exactly the opposite.
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAA40n-X_FnrLAoVnL10QgDz_3KDytCD8KXrN%3DK5wmN3xySdxTA%40mail.gmail.com
> .
>


-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQz8hZdqafRJuU%3Dx5QgdpgTfRESgrZ-3sApZfOj-7Md%3DBg%40mail.gmail.com.


Re: [go-nuts] cgo & long jump

2019-12-09 Thread pali
On Monday 09 December 2019 10:18:26 Ian Lance Taylor wrote:
> On Mon, Dec 9, 2019 at 8:57 AM  wrote:
> >
> > I would like to ask some technical question about cgo and long jumps.
> >
> > In Go I have written shared library which exports C API and therefore
> > can be called by other C applications. This my library is compiling with
> > cgo, more precisely via: go build -buildmode=c-shared -compiler gc
> >
> > Now I would like to call from my Go library some C function which may
> > call longjmp(). And setjmp() was already called by application which is
> > using my Go library.
> >
> > It is possible to call from Go C function which calls longjmp() which
> > jumps outside of that my Go library? What would happen with Go garbage
> > collector and "defer" code?
> >
> > To imagine, whole stack looks like this:
> >
> >   +--+
> >   | C application|
> >   | main():  |
> >   |   call setjmp()  |
> >   |   call f1() from Go library  |
> >   |   ...|
> >   +--+
> >   | Go library with exported C f1() function |
> >   | f1():|
> >   |   do something in Go |
> >   |   call f2() from C library   |
> >   |   ...|
> >   |   return from f1()   |
> >   +--+
> >   | C library with exported f2() function|
> >   | f2():|
> >   |   do something in C  |
> >   |   if error call longjmp()|
> >   |   else return from f2()  |
> >   +--+
> >
> > And if longjmp() is called then it jumps to main() where setjmp() was
> > called. So effectively f1() function (in Go) does not return.
> 
> I'm pretty sure that won't work at all.  Sorry.

Hi Ian! Thank you for your answer.

I was trying to find any resource on Internet about long jumps and
"import C" but neither in official Go documentation nor in any other
blog post is written about it.

There are many resources how Go is (fully) compatible with C and can
call C functions, but absolutely zero information how it is implemented
nor what would happen with such core feature of C language as long jumps
or signals.

> Certainly no Go deferred functions will be run.  I don't think this
> would break the garbage collector as such, but I expect that it would
> break the Go scheduler.  In the best case you'll be left with a
> dangling goroutine that will never be run and never go away.

So should I interpret your answer as long jumps are not supported and
caller of C function from Go must ensure that called C function would
not call longjmp()?


And another interesting question, it is possible to call longjmp() from
Go code? To throw C exception back to the main C application.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191209183039.khrexxnpedzitepy%40pali.


Re: [go-nuts] cgo & long jump

2019-12-09 Thread Ian Lance Taylor
On Mon, Dec 9, 2019 at 8:57 AM  wrote:
>
> I would like to ask some technical question about cgo and long jumps.
>
> In Go I have written shared library which exports C API and therefore
> can be called by other C applications. This my library is compiling with
> cgo, more precisely via: go build -buildmode=c-shared -compiler gc
>
> Now I would like to call from my Go library some C function which may
> call longjmp(). And setjmp() was already called by application which is
> using my Go library.
>
> It is possible to call from Go C function which calls longjmp() which
> jumps outside of that my Go library? What would happen with Go garbage
> collector and "defer" code?
>
> To imagine, whole stack looks like this:
>
>   +--+
>   | C application|
>   | main():  |
>   |   call setjmp()  |
>   |   call f1() from Go library  |
>   |   ...|
>   +--+
>   | Go library with exported C f1() function |
>   | f1():|
>   |   do something in Go |
>   |   call f2() from C library   |
>   |   ...|
>   |   return from f1()   |
>   +--+
>   | C library with exported f2() function|
>   | f2():|
>   |   do something in C  |
>   |   if error call longjmp()|
>   |   else return from f2()  |
>   +--+
>
> And if longjmp() is called then it jumps to main() where setjmp() was
> called. So effectively f1() function (in Go) does not return.

I'm pretty sure that won't work at all.  Sorry.

Certainly no Go deferred functions will be run.  I don't think this
would break the garbage collector as such, but I expect that it would
break the Go scheduler.  In the best case you'll be left with a
dangling goroutine that will never be run and never go away.

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXuHZWAkvWWu5DKR1aMAGQG26PRBvQz7UpSEsN81huq%2Bw%40mail.gmail.com.


Re: [go-nuts] Задача: Дано число int 324. Как получить 9?

2019-12-09 Thread Hayato Kawakami
Вы имеете в виду, как рассчитать сумму каждой цифры?

Пример кода выглядит следующим образом.


https://play.golang.org/p/Wht4jgELnTI


Do you mean how to calculate  sum of the each digit?
The sample code is as follows.

https://play.golang.org/p/Wht4jgELnTI


2019年12月9日(月) 17:40 Vital Nabokov :

> Данное число 324. Как получить число 9?
>
> ср, 4 дек. 2019 г., 20:13 Hayato Kawakami :
>
>> Здравствуйте.
>> Что значит получить int 9 из int 324? Если вы разделите на 36, это будет 9, 
>> но это ожидаемый ответ?
>>
>> Hello.
>> What does it mean to get int 9 from int 324? If you divide by 36, it will be 
>> 9, but is it the expected answer?
>>
>>
>>
>> 2019年12月4日(水) 22:48 Vital Nabokov :
>>
>>> Добрый день.
>>> Задача: №1 Дано число int 324. Как получить int 9?
>>> Задача: №2 Дано число string "324". Как получить int 9?
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/dda7c67a-fcc5-460a-8c76-ea43ef5b1b2c%40googlegroups.com
>>> 
>>> .
>>>
>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGZEK-T4wep1gs0eF%2Bfj0nEdSiGn%2BOmGke4DD-PCNzrtnxkDig%40mail.gmail.com.


Re: [go-nuts] Re: Why Iran is banned by Google?

2019-12-09 Thread Jan Mercl
On Mon, Dec 9, 2019 at 5:57 PM  wrote:

> So in simpler words, Google has banned Iran, right?

Wrong. Michael was, 5 years ago, very precise and clear about the
facts, which are exactly the opposite.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-X_FnrLAoVnL10QgDz_3KDytCD8KXrN%3DK5wmN3xySdxTA%40mail.gmail.com.


Re: [go-nuts] rpc.debugLog unexported

2019-12-09 Thread Atakan Çolak
Hi,

I had tried a similar approach for customizing golokia 
. 

Why do we need to move the imported packages code to the project directory? 
Doesn't go compile using the local copy of the imported package in GOPATH? 

What am I missing here?

8 Aralık 2019 Pazar 21:07:55 UTC+3 tarihinde dickmao yazdı:
>
> Thanks for your reply.  Do you regularly edit standard libs as described 
> (and 
> then presumably edit them back)? 
>
> I copied /usr/lib/go-1.13/net/rpc to my project directory, then changed 
> all 
> imports of "net/rpc" to "./net/rpc", and then set debugLog (in my shadow 
> copy, 
> not /usr/lib/go-1.13).  It got the job done but still felt wrong. 
>
> > Ian Lance Taylor > writes: 
>
> > On Sat, Dec 7, 2019 at 9:12 AM > 
> wrote: 
> >> 
> >> How can I turn on debugging in net/rpc/server.go? 
> >> 
> >> There is a promising variable called `debugLog` in there.  How should I 
> toggle it? 
>
> > I don't know how much it will help, but the way to toggle it is to 
> literally 
> > edit net/rpc/debug.go to set debugLog to true.  There's no mechanism for 
> > setting it dynamically. 
>
> > 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6aebd06b-aab4-4c9a-be88-ae2d72822362%40googlegroups.com.


[go-nuts] cgo & long jump

2019-12-09 Thread pali
Hello!

I would like to ask some technical question about cgo and long jumps.

In Go I have written shared library which exports C API and therefore
can be called by other C applications. This my library is compiling with
cgo, more precisely via: go build -buildmode=c-shared -compiler gc

Now I would like to call from my Go library some C function which may
call longjmp(). And setjmp() was already called by application which is
using my Go library.

It is possible to call from Go C function which calls longjmp() which
jumps outside of that my Go library? What would happen with Go garbage
collector and "defer" code?

To imagine, whole stack looks like this:

  +--+
  | C application|
  | main():  |
  |   call setjmp()  |
  |   call f1() from Go library  |
  |   ...|
  +--+
  | Go library with exported C f1() function |
  | f1():|
  |   do something in Go |
  |   call f2() from C library   |
  |   ...|
  |   return from f1()   |
  +--+
  | C library with exported f2() function|
  | f2():|
  |   do something in C  |
  |   if error call longjmp()|
  |   else return from f2()  |
  +--+

And if longjmp() is called then it jumps to main() where setjmp() was
called. So effectively f1() function (in Go) does not return.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191209113208.6owfrqfnr3vjn3nf%40pali.


Re: [go-nuts] Re: Why Iran is banned by Google?

2019-12-09 Thread parisaparvizi1994
So in simpler words, Google has banned Iran, right?
because I live in Iran and being unable to access some website by our 
government is cruel enough but being banned by others specially google is 
just unbearable.
we grew up with google and we always admire its company and we don't 
deserve to be treated like this.
we are stuck here, just like north Korean people. dreaming loses its 
meaning round here...
...


On Saturday, October 18, 2014 at 6:54:27 PM UTC+3:30, Michael Jones wrote:
>
> It is my job to explain things like this so I will clarify that Google 
> works to provide as much useful information as laws and regulations allow. 
> It is not that we are "sanctioning" any nation, it merely means that we are 
> obeying the applicable law as we understand it. It is regrettable that easy 
> sharing of educational and scientific knowledge is not yet a universal 
> truth. After all,  the greatest Go programmers may live in Iran.
>
> Michael Jones
>
> On Sat, Oct 18, 2014 at 7:49 AM, Erfan Akbarimanesh  > wrote:
>
>> I agree with ehedgehog comment
>> I'm an Iranian, but I'm sure Google has specific reasons for this sanction
>> You're from any country or nationality 
>> You're like my brother. 
>> I'm always looking for peace and friendship among nations.
>> Good Luck 
>>
>> -- 
>> 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 golan...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *Michael T. Jones | Chief Technology Advocate  | m...@google.com 
>  |  +1 650-335-5765*
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f58f4a2e-2a4f-49f4-9955-180098c765dc%40googlegroups.com.


[go-nuts] Help with Go channels and select talk

2019-12-09 Thread luka . venac
You can do it without a goroutine as long as the channel has at least one 
buffer slot so execution passes to the select and uses the data.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b713e498-fdba-41f6-90ec-71c7845a5398%40googlegroups.com.


[go-nuts] Re: help with reflect

2019-12-09 Thread Vasiliy Tolstov
Nevermind. I found the error

пн, 9 дек. 2019 г. в 12:30, Vasiliy Tolstov :
>
> Hi! I'm stuck at reflection based struct assignment.
>
> example struct
> type TestStruct struct {
>   Slice []*string
> }
>
> func TestReflect(t *testing.T) {
>   s1 := "one"
>   s2 := "two"
> s1 := "one"
> s2 := "two"
> nodes := []*string{, }
> v := {}
> valueOf := reflectValue(v)
> typeOf := reflectType(v)
>
> for i := 0; i < valueOf.NumField(); i++ {
>   field := valueOf.Field(i)
>   sfield := typeOf.Field(i)
>
>   slice := reflect.MakeSlice(sfield.Type, 0, 0)
>
>   log.Printf("field %v\n", field)
>   log.Printf("sfield %v\n", sfield)
>   log.Printf("slice %v\n", slice)
>
>   for _, node := range nodes {
> log.Printf("sfield elem %v\n", sfield.Type.Elem())
> value := reflect.New(sfield.Type.Elem())
> setVal := reflect.ValueOf(node)
> log.Printf("value %v\n", value)
> value.Set(setVal)
>   }
> }
>
> but i'm have error
> panic: reflect: reflect.flag.mustBeAssignable using unaddressable
> value [recovered]
> panic: reflect: reflect.flag.mustBeAssignable using unaddressable 
> value
>
>
> --
> Vasiliy Tolstov,
> e-mail: v.tols...@selfip.ru



-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACaajQtAa2ncNSk0b3cLO6S1OYBbEbH9%2BnxZM1FnH65mFOtcAA%40mail.gmail.com.


Re: [go-nuts] querying whether the go command would run in module mode

2019-12-09 Thread Paul Jolly
I raised https://github.com/golang/go/issues/36052 for discussion.

On Mon, 9 Dec 2019 at 10:29, Dan Kortschak  wrote:
>
> Thanks.
>
> Yes, I always have GO111MODULE=on, hence the difference.
>
> On Mon, 2019-12-09 at 10:04 +, Paul Jolly wrote:
> > > When you're not in a module it returns /dev/null on linux. I don't
> > > suppose this is platform independent?
> >
> > I have to say what you saw surprised me until Daniel Martí and I did
> > a
> > bit of experimentation.
> >
> > It seems the value of GO111MODULE matters here. If you have
> > GO111MODULE=on then the result of go mod env outside of a module
> > context is /dev/null (or your system's equivalent)
> >
> > If you have GO111MODULE unset (i.e. auto) then it is empty string.
> >
> > This is certainly not clear to me from the docs in go help
> > environment.
> >
> > I realise that this way (i.e. with the /dev/null output when
> > GO111MODULE=on) you can distinguish between modules being on/off, as
> > well as whether you're in a module context or not (regardless of
> > whether you have modules on/auto).
> >
> > But this doesn't exactly jump out at you from the docs of go help
> > environment, and I for one have incorrectly advised people on how to
> > check "are you in a module context or not". Because the logic becomes
> > something like:
> >
> > if gomod != "" && gomod != os.DevNull {
> > // we are in a module context
> >
> > I'm going to raise an issue to suggest that the docs are clarified
> > here.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACoUkn7U-TspDFgvqgiFHO2Vu2YUrnHZsz2Pfj-4SY9%3Dv7uevw%40mail.gmail.com.


Re: [go-nuts] querying whether the go command would run in module mode

2019-12-09 Thread Dan Kortschak
Thanks.

Yes, I always have GO111MODULE=on, hence the difference.

On Mon, 2019-12-09 at 10:04 +, Paul Jolly wrote:
> > When you're not in a module it returns /dev/null on linux. I don't
> > suppose this is platform independent?
> 
> I have to say what you saw surprised me until Daniel Martí and I did
> a
> bit of experimentation.
> 
> It seems the value of GO111MODULE matters here. If you have
> GO111MODULE=on then the result of go mod env outside of a module
> context is /dev/null (or your system's equivalent)
> 
> If you have GO111MODULE unset (i.e. auto) then it is empty string.
> 
> This is certainly not clear to me from the docs in go help
> environment.
> 
> I realise that this way (i.e. with the /dev/null output when
> GO111MODULE=on) you can distinguish between modules being on/off, as
> well as whether you're in a module context or not (regardless of
> whether you have modules on/auto).
> 
> But this doesn't exactly jump out at you from the docs of go help
> environment, and I for one have incorrectly advised people on how to
> check "are you in a module context or not". Because the logic becomes
> something like:
> 
> if gomod != "" && gomod != os.DevNull {
> // we are in a module context
> 
> I'm going to raise an issue to suggest that the docs are clarified
> here.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/aef097cd5f48edfdfb3fbeb552f7f1377b31777d.camel%40kortschak.io.


[go-nuts] Re: help with reflect

2019-12-09 Thread Vasiliy Tolstov
Mainly i have bigger requirement:
type TestStruct struct {
  Slice []*TestItem
}

type TestItem struct {
  Value1 string
  Value2 string
}

so i need to create slice via reflect in TestStruct variable, create
variable for TestItem and iterate over TestItem fields and assign to
it Value1 and Value2 some text

after some changes i have reflect: call of reflect.Value.NumField on ptr Value
so reflect.New(sfield.Type.Elem()).Elem() returns pointer to needed
struct, but if i'm use reflect.Indirect i have nil variable and can't
do NumField on it

пн, 9 дек. 2019 г. в 12:30, Vasiliy Tolstov :

>
> Hi! I'm stuck at reflection based struct assignment.
>
> example struct
> type TestStruct struct {
>   Slice []*string
> }
>
> func TestReflect(t *testing.T) {
>   s1 := "one"
>   s2 := "two"
> s1 := "one"
> s2 := "two"
> nodes := []*string{, }
> v := {}
> valueOf := reflectValue(v)
> typeOf := reflectType(v)
>
> for i := 0; i < valueOf.NumField(); i++ {
>   field := valueOf.Field(i)
>   sfield := typeOf.Field(i)
>
>   slice := reflect.MakeSlice(sfield.Type, 0, 0)
>
>   log.Printf("field %v\n", field)
>   log.Printf("sfield %v\n", sfield)
>   log.Printf("slice %v\n", slice)
>
>   for _, node := range nodes {
> log.Printf("sfield elem %v\n", sfield.Type.Elem())
> value := reflect.New(sfield.Type.Elem())
> setVal := reflect.ValueOf(node)
> log.Printf("value %v\n", value)
> value.Set(setVal)
>   }
> }
>
> but i'm have error
> panic: reflect: reflect.flag.mustBeAssignable using unaddressable
> value [recovered]
> panic: reflect: reflect.flag.mustBeAssignable using unaddressable 
> value
>
>
> --
> Vasiliy Tolstov,
> e-mail: v.tols...@selfip.ru



--
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACaajQsKQx4PfYqga8vtyKpKXKVMTR3y3Zt9VReD4Op9nsFmoQ%40mail.gmail.com.


Re: [go-nuts] querying whether the go command would run in module mode

2019-12-09 Thread Paul Jolly
> When you're not in a module it returns /dev/null on linux. I don't
> suppose this is platform independent?

I have to say what you saw surprised me until Daniel Martí and I did a
bit of experimentation.

It seems the value of GO111MODULE matters here. If you have
GO111MODULE=on then the result of go mod env outside of a module
context is /dev/null (or your system's equivalent)

If you have GO111MODULE unset (i.e. auto) then it is empty string.

This is certainly not clear to me from the docs in go help environment.

I realise that this way (i.e. with the /dev/null output when
GO111MODULE=on) you can distinguish between modules being on/off, as
well as whether you're in a module context or not (regardless of
whether you have modules on/auto).

But this doesn't exactly jump out at you from the docs of go help
environment, and I for one have incorrectly advised people on how to
check "are you in a module context or not". Because the logic becomes
something like:

if gomod != "" && gomod != os.DevNull {
// we are in a module context

I'm going to raise an issue to suggest that the docs are clarified here.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACoUkn4GP287B7E7nMHnBwZsHUzcNS-4Km_x6GX%3DZvoGbbr2PQ%40mail.gmail.com.


Re: [go-nuts] querying whether the go command would run in module mode

2019-12-09 Thread Jamil Djadala
On Mon, 09 Dec 2019 19:57:48 +1030
Dan Kortschak  wrote:

> Thanks.
> 
> When you're not in a module it returns /dev/null on linux. I don't
> suppose this is platform independent?

Hi,
This command:
go env GOMOD

returns 1 emty line,
i dont see any /dev/null ?

-- 
Jamil Djadala

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191209114053.5bf5bd76%40beast.


[go-nuts] help with reflect

2019-12-09 Thread Vasiliy Tolstov
Hi! I'm stuck at reflection based struct assignment.

example struct
type TestStruct struct {
  Slice []*string
}

func TestReflect(t *testing.T) {
  s1 := "one"
  s2 := "two"
s1 := "one"
s2 := "two"
nodes := []*string{, }
v := {}
valueOf := reflectValue(v)
typeOf := reflectType(v)

for i := 0; i < valueOf.NumField(); i++ {
  field := valueOf.Field(i)
  sfield := typeOf.Field(i)

  slice := reflect.MakeSlice(sfield.Type, 0, 0)

  log.Printf("field %v\n", field)
  log.Printf("sfield %v\n", sfield)
  log.Printf("slice %v\n", slice)

  for _, node := range nodes {
log.Printf("sfield elem %v\n", sfield.Type.Elem())
value := reflect.New(sfield.Type.Elem())
setVal := reflect.ValueOf(node)
log.Printf("value %v\n", value)
value.Set(setVal)
  }
}

but i'm have error
panic: reflect: reflect.flag.mustBeAssignable using unaddressable
value [recovered]
panic: reflect: reflect.flag.mustBeAssignable using unaddressable value


-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACaajQuwv2Pqjm_sN3n0y9CNMo8VbfWfWid0kdbE_QoA3gwBXA%40mail.gmail.com.


Re: [go-nuts] querying whether the go command would run in module mode

2019-12-09 Thread Dan Kortschak
Thanks.

When you're not in a module it returns /dev/null on linux. I don't
suppose this is platform independent?

On Mon, 2019-12-09 at 06:52 +, Paul Jolly wrote:
> go env GOMOD - gives the path to the go.mod in use in module mode,
> and is
> empty otherwise (i.e. GOPATH mode)
> 
> On Mon, 9 Dec 2019, 00:25 Dan Kortschak,  wrote:
> 
> > Is there a way to query whether an invocation of the go command
> > would
> > be running in module mode?
> > 
> > thanks
> > Dan
> > 
> > --
> > 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+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> > 
https://groups.google.com/d/msgid/golang-nuts/c0c406db898a66fb1fe2638242922512315ff190.camel%40kortschak.io
> > .
> > 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2cb0889e0a0de4b44c79c0e3ccd5502e01f16c4e.camel%40kortschak.io.