Re: [go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-18 Thread Konstantin Khomoutov
On Wed, 19 Apr 2017 14:23:09 +0800 hui zhang wrote: > 1) getpath() return a temp string, its c_str() pointer will be > free out of function. So I use malloc I'm not completely sure you're correct. C++ does not implement garbage collection and the object on which you have called c_str() con

Re: [go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-18 Thread hui zhang
1) getpath() return a temp string, its c_str() pointer will be free out of function. So I use malloc 2) Assume we use the malloc way , are C.GoString() copying the pointer memory ? for we need C.free() malloc memory. 2017-04-19 14:17 GMT+08:00 Konstantin Khomoutov < flatw...@users.sour

Re: [go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-18 Thread Konstantin Khomoutov
On Tue, 18 Apr 2017 18:09:03 -0700 (PDT) hui zhang wrote: > > > c code > > > string getstring() {...} > > > go > > > string gostr = (C.getstring()) > > Oh, and note that std::string is a fat object. > > > > So if getstring() really returns an instance of std::string, > > and you need to

[go-nuts] how to set different flags for different os in cgo

2017-04-18 Thread hui zhang
I want to set different flags for different os in cgo, how to do that in cgo? //#cgo amd64 darwin CFLAGS: -Dxxx > //#cgo amd64 darwin CXXFLAGS: -Dxxx > //#cgo amd64 darwin LDFLAGS: -Lxxx > //#cgo arm darwin CFLAGS: -Dxxx > //#cgo arm darwin CXXFLAGS: -Dxxx > //#cgo arm darwin LDFLAGS: -Lxxx /

Re: [go-nuts] Re: how embedded go in existing c/c++ program.

2017-04-18 Thread hui zhang
Thank you It did work . Build go code as a static c lib ,and go code also link another c lib. 在 2017年4月19日星期三 UTC+8上午9:04:37,Ian Lance Taylor写道: > > On Tue, Apr 18, 2017 at 6:01 PM, hui zhang > wrote: > > > > C functions have to be available when the Go package is built. > > yes, but

Re: [go-nuts] Zero value of the map

2017-04-18 Thread Matt Harden
It seems to me the equivalent of append for maps is merge, which would be a very useful operation to have in its own right. A useful design for map could have been an immutable structure supporting literals, merge, lookup and delete operations, where all except lookup would return a new map value.

Re: [go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-18 Thread hui zhang
assume there is a c++ function string getpath() you mean I should do this ? > char *CGetPath() { > auto str=getpath; > char *c = malloc(str.length()), > strcpy(c,str.c_str()); > return c; > } p :=C.CGetPath() > gostr := C.GoString() >C.free(p) 在 2017年4月18日星期二 U

Re: [go-nuts] Re: how embedded go in existing c/c++ program.

2017-04-18 Thread Ian Lance Taylor
On Tue, Apr 18, 2017 at 6:01 PM, hui zhang wrote: > > C functions have to be available when the Go package is built. > yes, but static lib is kind of definition. > > //#cgo CFLAGS: -I > //#cgo CXXFLAGS="${CFLAGS}" > //#cgo LDFLAGS: -L -l > > will this above work ? if I want to build a go stati

Re: [go-nuts] Re: how embedded go in existing c/c++ program.

2017-04-18 Thread hui zhang
C functions have to be available when the Go package is built. yes, but static lib is kind of definition. //#cgo CFLAGS: -I //#cgo CXXFLAGS="${CFLAGS}" //#cgo LDFLAGS: -L -l will this above work ? if I want to build a go static lib? > how about go call c wrapper function , c wrapper fun

Re: [go-nuts] Re: how embedded go in existing c/c++ program.

2017-04-18 Thread Ian Lance Taylor
On Tue, Apr 18, 2017 at 1:37 AM, hui zhang wrote: > add a c wrapper around cfunc.h not help either. > > 在 2017年4月18日星期二 UTC+8下午4:36:26,hui zhang写道: >> >> I want to embedded go code in c/c++ program. >> my approach as below, however go code can not be compiled >> C main() --> go func --> c func

Re: [go-nuts] Is everything passed as a value in Go?

2017-04-18 Thread Caleb Spare
The fact that https://github.com/golang/go/issues/5083 still hasn't been sorted out means that it's hard to explain this to people using officially sanctioned terminology. I usually end up just using the phrase "reference types" along with some further description of what I mean (in particular to d

[go-nuts] Re: Is everything passed as a value in Go?

2017-04-18 Thread st ov
Wow! Thanks everyone! So if I got this right, Go always makes a copy but whats actually being copied differs by type. It seems that I don't need to worry about a lot of data being copied about with the larger data structures, but by passing the pointer value by default isn't that an implicit

Re: [go-nuts] Re: Building with "go install" vs "go build"

2017-04-18 Thread Dave Cheney
To each their own, but please consider using the -v flag so you understand how many packages are bring recompiled each time. It is very common for a Go user to upgrade their Go version and find that compilation slowed down as the set of packages compiled each time now includes many long forgotte

Re: [go-nuts] Is everything passed as a value in Go?

2017-04-18 Thread Ian Lance Taylor
On Tue, Apr 18, 2017 at 2:13 PM, st ov wrote: > I read everything is pass-by-value in Go, is that correct? > What does it encompass? Are there any exceptions? There are no exceptions. But it does require a clear understanding of what Go means by a value. > Does that mean the following: > > int

Re: [go-nuts] Is everything passed as a value in Go?

2017-04-18 Thread Jan Mercl
On Tue, Apr 18, 2017 at 11:13 PM st ov wrote: > I read everything is pass-by-value in Go, is that correct? > What does it encompass? Are there any exceptions? > > Does that mean the following: > > int passes full integer byte value > float64 passes full float byte value > string passes full strin

[go-nuts] Is everything passed as a value in Go?

2017-04-18 Thread Dave Cheney
That is correct, every assignment in Go is a copy, including every function argument and return value. -- 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-nu

[go-nuts] Re: Is everything passed as a value in Go?

2017-04-18 Thread Collin VanDyck
Anything that goes on the stack is copied. On Tuesday, April 18, 2017 at 5:13:14 PM UTC-4, st ov wrote: > > I read everything is pass-by-value in Go, is that correct? > What does it encompass? Are there any exceptions? > > Does that mean the following: > > int passes full integer byte value > flo

[go-nuts] Is everything passed as a value in Go?

2017-04-18 Thread st ov
I read everything is pass-by-value in Go, is that correct? What does it encompass? Are there any exceptions? Does that mean the following: int passes full integer byte value float64 passes full float byte value string passes full string []byte value slice passes pointer value to slice in memory

Re: [go-nuts] Re: Building with "go install" vs "go build"

2017-04-18 Thread Diego Medina
> Often, this involves incrementing the version [...] If the process of saying "this binary is good to go, deploy it locally for use" already involve more than go install, maybe you could also "deploy" the binary to a different location than $GOPATH/bin . The benefit there is that you can take

Re: [go-nuts] amd64 prefetch asm

2017-04-18 Thread Ian Lance Taylor
On Tue, Apr 18, 2017 at 11:41 AM, wrote: > > I have some code do prefetching that I borrowed from src/runtime > > // asm_amd64.s > > TEXT ·prefetch(SB), $0-8 >MOVQ addr+0(FP), AX >PREFETCHNTA (AX) >RET > > > This compiles fine, $ go tool objdump shows: > > TEXT .pref

[go-nuts] Re: about the []byte -> string comversion optimization, is it some weird?

2017-04-18 Thread 'Keith Randall' via golang-nuts
This is a weird corner case in string concatenation optimization. runtime.concatstrings (what the + in this code gets rewritten to) has an optimization where if all the strings but one that it is concatenating are 0 length, then it returns the remaining one without doing any allocation. Because

Re: [go-nuts] Infinite loops

2017-04-18 Thread Frank Davidson
Thanks, Ian! That's exactly my use case... On Tuesday, April 18, 2017 at 2:11:45 PM UTC-4, Ian Davis wrote: > > On Tue, 18 Apr 2017, at 05:58 PM, Jan Mercl wrote: > > On Tue, Apr 18, 2017 at 6:57 PM Frank Davidson > wrote: > > > Which loop uses the least computer resources? > > select{} > > > Not

[go-nuts] amd64 prefetch asm

2017-04-18 Thread alexandru
Hi! I have some code do prefetching that I borrowed from src/runtime // asm_amd64.s TEXT ·prefetch(SB), $0-8 MOVQ addr+0(FP), AX PREFETCHNTA (AX) RET This compiles fine, $ go tool objdump shows: TEXT .prefetch(SB) asm_amd64.s 0x4f18e0 488b442408

Re: [go-nuts] Infinite loops

2017-04-18 Thread Ian Davis
On Tue, 18 Apr 2017, at 05:58 PM, Jan Mercl wrote: > On Tue, Apr 18, 2017 at 6:57 PM Frank Davidson > wrote: > > > Which loop uses the least computer resources? > > select{} Note though that select is not a loop so it will not infinitely repeat instructions. select{} can be used to bloc

Re: [go-nuts] Infinite loops

2017-04-18 Thread Frank Davidson
Thank, Jan! Just out of curiosity, why is that? On Tuesday, April 18, 2017 at 12:58:53 PM UTC-4, Jan Mercl wrote: > > On Tue, Apr 18, 2017 at 6:57 PM Frank Davidson > wrote: > > > Which loop uses the least computer resources? > > select{} > > -- > > -j > -- You received this message because

Re: [go-nuts] Re: Building with "go install" vs "go build"

2017-04-18 Thread Marvin Renich
* Dave Cheney [170418 09:57]: > > Apparently Dave Cheney says to prefer "go install" over "go build"[3], > except when cross-compiling [4]. However, many of these posts are older, > and Golang moves at such a rapid clip that it's difficult to keep track of > what everybody is doing. > > This i

Re: [go-nuts] Infinite loops

2017-04-18 Thread Jan Mercl
On Tue, Apr 18, 2017 at 6:57 PM Frank Davidson wrote: > Which loop uses the least computer resources? select{} -- -j -- 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 e

[go-nuts] Infinite loops

2017-04-18 Thread Frank Davidson
Hi All, Which loop uses the least computer resources? for { } or for { time.Sleep(1 * time.Second) } or another type of infinite loop? Cheers, Frank -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and sto

Re: [go-nuts] http.Server handlers seem to stick around forever

2017-04-18 Thread Ken Simon
On Tuesday, April 18, 2017 at 8:19:06 AM UTC-7, Peter Mogensen wrote: > > > and even if one was > > still open, I'm making a new http.Client object, too! > > Yes. But you don't make a new Transport. > Both your clients use DefaultTransport - which has the connection pool. > > /Peter > > Bingo.

Re: [go-nuts] http.Server handlers seem to stick around forever

2017-04-18 Thread Peter Mogensen
On 2017-04-18 17:08, Ken Simon wrote: Yes that's very strange. My impression was that net.Listener.Close() would actually sever the running connections... It won't. That's why Go 1.8 has Server.Close() and even if one was still open, I'm making a new http.Client object, too! Yes. But yo

Re: [go-nuts] http.Server handlers seem to stick around forever

2017-04-18 Thread Peter Mogensen
On 2017-04-18 17:00, Ken Simon wrote: net/http.Server.Close() only exists in golang 1.8... I'm stuck in 1.7 right now so I can't use that. No, but you can do something equivalent with either a connection manager like in the various "graceful" libraries or simply (as also suggested) disable

Re: [go-nuts] http.Server handlers seem to stick around forever

2017-04-18 Thread Ken Simon
On Tuesday, April 18, 2017 at 5:51:40 AM UTC-7, Yuwei Ba wrote: > > Disabling the HTTP connection keep-alive may help for this situation by > calling: `srv.SetKeepAlivesEnabled(false)` and get the expected output > **sometimes** > > $ go run a.go > In handler wrapper, f = 0xc4200111a0 > 1 > In ha

Re: [go-nuts] http.Server handlers seem to stick around forever

2017-04-18 Thread Ken Simon
On Monday, April 17, 2017 at 10:30:43 PM UTC-7, Peter Mogensen wrote: > > However... If you call net/http.Server.Close() between the two calls you > get the expected result... which indicates you might be struggling with > the client side connection pool still having a keepalive HTTP connection

Re: [go-nuts] Zero value of the map

2017-04-18 Thread Tad Vizbaras
Thank you for detailed explanation. I find myself never using "var a map[int]int" or similar var like map. Maybe just my limited understanding. But I am glad we end up with map[int]int instead of *map[int]int. -- You received this message because you are subscribed to the Google Groups "gola

Re: [go-nuts] C union type to go native types

2017-04-18 Thread andrey mirtchovski
I usually create a separate struct for each part of the union and provide interface methods for un/marshalling. It is more work, but I find it to be much cleaner in the end: once those are created the union doesn't "leak" into the go code. On Tue, Apr 18, 2017 at 8:41 AM, Vasiliy Tolstov wrote: >

[go-nuts] C union type to go native types

2017-04-18 Thread Vasiliy Tolstov
I have Some C struct like https://libvirt.org/html/libvirt-libvirt-common.html#virTypedParameter that needs to be binary Unmarshal to go native interface (xdr2), does it possible to represent via one go struct all needed things, or i need to create for each type struct and provide needed interface

Re: [go-nuts] Zero value of the map

2017-04-18 Thread Ian Davis
On Tue, 18 Apr 2017, at 03:20 PM, Chris Hopkins wrote: > I'm not sure what you mean by the append doesn't modify the original. > Append will use the same backing store (if there is available capacity > in it) and by definition the address of the slice in question must be > invariant across its c

Re: [go-nuts] Zero value of the map

2017-04-18 Thread Chris Hopkins
I'm not sure what you mean by the append doesn't modify the original. Append will use the same backing store (if there is available capacity in it) and by definition the address of the slice in question must be invariant across its context. e.g.: https://play.golang.org/p/lBRpKSo-9P I think of a

Re: [go-nuts] Zero value of the map

2017-04-18 Thread Ian Lance Taylor
On Tue, Apr 18, 2017 at 7:02 AM, Jesse McNelis wrote: > On Tue, Apr 18, 2017 at 10:04 PM, Tad Vizbaras wrote: >> I am just curious what is the reason behind not making zero maps more >> useful? Is it space? > > The problem is that maps are mutable. > > var a map[int]int > a[1] = 1 // could be fi

Re: [go-nuts] Re: Building with "go install" vs "go build"

2017-04-18 Thread Michael Jones
The good news is that Dave Cheney moves at that same rapid clip. :-) On Tue, Apr 18, 2017 at 6:57 AM, Dave Cheney wrote: > > Apparently Dave Cheney says to prefer "go install" over "go build"[3], > except when cross-compiling [4]. However, many of these posts are older, > and Golang moves at suc

Re: [go-nuts] Zero value of the map

2017-04-18 Thread Jesse McNelis
On Tue, Apr 18, 2017 at 10:04 PM, Tad Vizbaras wrote: > I am just curious what is the reason behind not making zero maps more > useful? Is it space? The problem is that maps are mutable. var a map[int]int a[1] = 1 // could be fine and useful. var a map[int]int someFunc(a) // Does someFunc nee

[go-nuts] Re: Building with "go install" vs "go build"

2017-04-18 Thread Dave Cheney
> Apparently Dave Cheney says to prefer "go install" over "go build"[3], except when cross-compiling [4]. However, many of these posts are older, and Golang moves at such a rapid clip that it's difficult to keep track of what everybody is doing. This information is still correct. On Friday, 10

[go-nuts] Re: redeclaration in runtime/utf8.go after installing Go 1.8 on Windows

2017-04-18 Thread Dave Cheney
What's happened is C:\Go contains the parts of two different Go installations and is corrupt. Ideally the windows installer shouldn't do this, but here we are. The fix should be to remove C:\Go and run the Go 1.8.1 installer again, that should fix the problem. On Tuesday, 18 April 2017 22:51:2

[go-nuts] Re: os.Getwd() on windows changes drive letter casing

2017-04-18 Thread Guy Allard
Peter - Yep, with a little more experimentation I just found that out. Either result can be reproduced. Guy On Tuesday, April 18, 2017 at 9:06:41 AM UTC-4, peterGo wrote: > > Guy, > > It's easy to get any result you want: same case, different case. It's an > easyjson problem. > > Peter > > On T

[go-nuts] Re: os.Getwd() on windows changes drive letter casing

2017-04-18 Thread peterGo
Guy, It's easy to get any result you want: same case, different case. It's an easyjson problem. Peter On Tuesday, April 18, 2017 at 8:55:03 AM UTC-4, Guy Allard wrote: > > I do net see that here. C: is uppercase in both cases. > > go 1.8 > Win 7 > > On Monday, April 17, 2017 at 11:06:50 AM UTC-

[go-nuts] Re: os.Getwd() on windows changes drive letter casing

2017-04-18 Thread peterGo
Andreas, To fix the easyjson library, please provide a simple recipe for reproducing the error. A complete runnable program is good. A link on play.golang.org is best. What did you expect to see? What did you see instead? Peter On Tuesday, April 18, 2017 at 3:14:47 AM UTC-4, Andreas Reuterberg

[go-nuts] Re: os.Getwd() on windows changes drive letter casing

2017-04-18 Thread Guy Allard
I do net see that here. C: is uppercase in both cases. go 1.8 Win 7 On Monday, April 17, 2017 at 11:06:50 AM UTC-4, Andreas Reuterberg wrote: > > I'm calling os.Getwd() as part of a very simple test, but I get different > responses > depending on if I'm executing the test as a binary or not. The

[go-nuts] Re: redeclaration in runtime/utf8.go after installing Go 1.8 on Windows

2017-04-18 Thread Geert Van Laethem
Somebody got a fix on that yet. Got the same thing On Saturday, February 18, 2017 at 6:42:12 PM UTC+1, Vincent Rischmann wrote: > > Hi, > > I'm on Windows, I had Go 1.7.4 installed from the MSI installer. Today I > decided to upgrade to Go 1.8, so I downloaded the new MSI, ran it and that > was

Re: [go-nuts] http.Server handlers seem to stick around forever

2017-04-18 Thread Yuwei Ba
Disabling the HTTP connection keep-alive may help for this situation by calling: `srv.SetKeepAlivesEnabled(false)` and get the expected output **sometimes** $ go run a.go In handler wrapper, f = 0xc4200111a0 1 In handler wrapper, f = 0xc4200111a8 2 Though, it’s strange that you’ll still need t

Re: [go-nuts] Zero value of the map

2017-04-18 Thread Ian Davis
On Tue, 18 Apr 2017, at 01:04 PM, Tad Vizbaras wrote: > > The argument could be that slices are read-only too. Just that > "append" is special and it makes zero value slices useful. > var a []int > a[0] = 1 // Fails. > // panic: runtime error: index out of range > > I am just curious what

[go-nuts] Zero value of the map

2017-04-18 Thread Tad Vizbaras
Making zero value useful is great idea. It works for slice, mutex and many others. var a []int a = append(a, 1) fmt.Println(a) This works and prints: [1] Sadly maps do not seem to have useful zero value. They require call to make() or literal to get to useful state. var a map[int]int a[1] =

[go-nuts] `go tool trace` blank page (404 + Uncaught ReferenceError: tr is not defined)

2017-04-18 Thread Dave Cheney
Did you install go from source? I've seen in the past that some operating system distributions strip the misc/ directory which breaks the go trace tool. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop rec

[go-nuts] `go tool trace` blank page (404 + Uncaught ReferenceError: tr is not defined)

2017-04-18 Thread Pierre Neidhardt
- OS: Arch Linux 64-bit - go version: go version go1.8.1 linux/amd64 - browser: Chromium 57.0.2987.133 I've been willing to use the `trace` tool a long time ago (1 year?) but it wasn't working: clicking on "View trace" would simply return a blank page. It seems it is working for most people out

Re: [go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-18 Thread Konstantin Khomoutov
On Tue, 18 Apr 2017 02:25:07 -0700 (PDT) hui zhang wrote: > c code > string getstring() {...} > > go > > string gostr = (C.getstring()) Oh, and note that std::string is a fat object. So if getstring() really returns an instance of std::string, and you need to actually extract its "raw b

Re: [go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-18 Thread Konstantin Khomoutov
On Tue, 18 Apr 2017 02:25:07 -0700 (PDT) hui zhang wrote: > c code > string getstring() {...} > > go > > string gostr = (C.getstring()) https://github.com/golang/go/wiki/cgo#go-strings-and-c-strings ? -- You received this message because you are subscribed to the Google Groups "golang

[go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-18 Thread hui zhang
c code string getstring() {...} go string gostr = (C.getstring()) -- 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

[go-nuts] Re: how embedded go in existing c/c++ program.

2017-04-18 Thread hui zhang
add a c wrapper around cfunc.h not help either. 在 2017年4月18日星期二 UTC+8下午4:36:26,hui zhang写道: > > I want to embedded go code in c/c++ program. > my approach as below, however go code can not be compiled > C main() --> go func --> c func(in static lib) > > > ** > #include "libgofunc.h" > int main

[go-nuts] how embedded go in existing c/c++ program.

2017-04-18 Thread hui zhang
I want to embedded go code in c/c++ program. my approach as below, however go code can not be compiled C main() --> go func --> c func(in static lib) ** #include "libgofunc.h" int main() { Gofunc(); } ** CGO_ENABLED=1 go build -buildmode=c-archive -o libgofunc.a --> error U

Re: [go-nuts] Link documentation sources

2017-04-18 Thread Nathan Kerr
All the package documentation on https://golang.org/pkg and https://godoc.org is generated from the source. The headers for functions, types, etc. link to the source line where the function, type, etc. was defined. You can read more about godoc

[go-nuts] Re: http.Server handlers seem to stick around forever

2017-04-18 Thread Nathan Kerr
Instead of trying to restart the server, switch the handler: package main import ( "fmt" "io/ioutil" "log" "net/http" "strconv" ) // Some state so we can show the old handler is in effect... type Foo struct { SomeVar int } func (f *Foo) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Pr

[go-nuts] Re: os.Getwd() on windows changes drive letter casing

2017-04-18 Thread Andreas Reuterberg
I care because the library I am trying out breaks due to this issue (easyjson). But also, isn't it a bit odd and interesting that the code works differently as a binary? Andreas -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe fr