Re: [go-nuts] fatal error:malloc deadlock

2016-09-19 Thread Wanghb Wang
new issue address is https://github.com/golang/go/issues/17165

在 2016年9月20日星期二 UTC+8下午12:04:09,Ian Lance Taylor写道:
>
> On Mon, Sep 19, 2016 at 6:34 PM, Wanghb Wang  > wrote: 
> > 
> > 
> > 在 2016年9月20日星期二 UTC+8上午3:41:09,Ian Lance Taylor写道: 
> >> 
> >> On Mon, Sep 19, 2016 at 8:34 AM, Wanghb Wang  
> wrote: 
> >> > 
> >> > when I use stattcpupprof in my program, I got fatal error malloc 
> >> > deadlock. 
> >> > delete the cpu pprof,  the program run well. 
> >> > 
> >> > 
> >> > my question is : 
> >> > Does startcpuprof infect the malloc or resulting OOM Problem 
> >> 
> >> I'm sorry, I don't understand the question. 
> >> 
> >> 
> >> > this is my panic stack trace: 
> >> 
> >> It looks like you have C code that calls goCbStr.  Somehow when that 
> >> happens the malloc lock is held for the thread.  The only way I can 
> >> see that happening is if your C code has a SIGPROF handler that calls 
> >> into Go. 
> >> 
> > 
> > However, I have no  SIGPROF handler(you mean 
> sigaction(SIGPROF,,NULL)?) 
>
> Yes, that kind of thing. 
>
> > my question is: 
> >  why I add startcpupprof  in my golang program (I did have C calls into 
> Go) 
> > result in malloc deadlock? 
>
> I don't know.  Sorry.  If you can tell us precisely how to recreate 
> the problem ourselves--what program to run--please open an issue at 
> https://golang.org/issue.  Thanks. 
>
> 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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: fatal error:malloc deadlock

2016-09-19 Thread Wanghb Wang

>
> my dll is compile by visual studio 2015 on windows10
>

If you think this is safe ,  you can rename the attachment test001DLL  as 
test0001.dll, or you can find code from 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


test.go
Description: Binary data


test0001DLL
Description: Binary data


Re: [go-nuts] fatal error:malloc deadlock

2016-09-19 Thread Ian Lance Taylor
On Mon, Sep 19, 2016 at 6:34 PM, Wanghb Wang  wrote:
>
>
> 在 2016年9月20日星期二 UTC+8上午3:41:09,Ian Lance Taylor写道:
>>
>> On Mon, Sep 19, 2016 at 8:34 AM, Wanghb Wang  wrote:
>> >
>> > when I use stattcpupprof in my program, I got fatal error malloc
>> > deadlock.
>> > delete the cpu pprof,  the program run well.
>> >
>> >
>> > my question is :
>> > Does startcpuprof infect the malloc or resulting OOM Problem
>>
>> I'm sorry, I don't understand the question.
>>
>>
>> > this is my panic stack trace:
>>
>> It looks like you have C code that calls goCbStr.  Somehow when that
>> happens the malloc lock is held for the thread.  The only way I can
>> see that happening is if your C code has a SIGPROF handler that calls
>> into Go.
>>
>
> However, I have no  SIGPROF handler(you mean sigaction(SIGPROF,,NULL)?)

Yes, that kind of thing.

> my question is:
>  why I add startcpupprof  in my golang program (I did have C calls into Go)
> result in malloc deadlock?

I don't know.  Sorry.  If you can tell us precisely how to recreate
the problem ourselves--what program to run--please open an issue at
https://golang.org/issue.  Thanks.

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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Calling a Go function from asm ("fatal error: missing stackmap")

2016-09-19 Thread Peng Gao


On Tuesday, September 20, 2016 at 11:00:34 AM UTC+8, Peng Gao wrote:
>
> BTW in your test file, you can directly append your bytes slice.
> b1 = append(b1, vs...)
> and slicesEqual is redundant, bytes.Equal does test the length of two 
> arguments
>
I mix up cap and len, just ignore it. 

>
> On Tuesday, September 20, 2016 at 6:56:55 AM UTC+8, Caleb Spare wrote:
>>
>> I'm trying to call a Go function from asm and I'm having trouble figuring 
>> out the details.
>>
>> (In the past I've always endeavored to avoid this situation and make all 
>> my asm functions be leaf functions, but in my current use case it would be 
>> most helpful to be able to call a Go helper.)
>>
>> See the demo code at 
>> https://github.com/cespare/misc/tree/master/asm/stackmap or go get 
>> github.com/cespare/misc/asm/stackmap.
>>
>> For 
>> ​the​
>>  demo, I have a small function with an append-style API:
>>
>> func X(b []byte) []byte
>>
>> This calls a Go helper growSlice.
>>
>> This code sometimes works, but if I run `go test -count 1000` I'll 
>> quickly see
>>
>> runtime: frame github.com/cespare/misc/asm/stackmap.X untyped locals 
>> 0xc420042bf8+0x30
>> fatal error: missing stackmap
>> ...
>>
>> I've read through the Runtime Coordination section of the 
>> ​asm
>>  walkthrough (https://golang.org/doc/asm#runtime) several times, but I 
>> don't see the problem.
>>
>> Here is my understanding of a few relevant bits of that section (which 
>> might be incorrect):
>>
>> If the results will hold live pointers during a call instruction, the 
>>> function should start by zeroing the results and then executing the 
>>> pseudo-instruction GO_RESULTS_INITIALIZED.
>>
>>
>> This doesn't seem to apply to my code because the results aren't 
>> populated until after the CALL.
>>
>> If a function has no local stack frame, the pointer information can be 
>>> omitted. This is indicated by a local frame size annotation of $0-n on the 
>>> TEXT instruction. The pointer information can also be omitted if the 
>>> function contains no call instructions. Otherwise, the local stack frame 
>>> must not contain pointers, and the assembly must confirm this fact by 
>>> executing the pseudo-instruction NO_LOCAL_POINTERS.
>>
>>
>> ​My function makes a CALL with arguments. But it has to ​have a pointer 
>> (the slice) on the local stack frame in order to pass to that helper. I 
>> don't really understand what this section means.
>>
>> `go vet` doesn't say anything about my code.
>>
>> Any ideas?
>>
>> Thanks!
>> Caleb
>>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Calling a Go function from asm ("fatal error: missing stackmap")

2016-09-19 Thread Peng Gao
BTW in your test file, you can directly append your bytes slice.
b1 = append(b1, vs...)
and slicesEqual is redundant, bytes.Equal does test the length of two 
arguments.


On Tuesday, September 20, 2016 at 6:56:55 AM UTC+8, Caleb Spare wrote:
>
> I'm trying to call a Go function from asm and I'm having trouble figuring 
> out the details.
>
> (In the past I've always endeavored to avoid this situation and make all 
> my asm functions be leaf functions, but in my current use case it would be 
> most helpful to be able to call a Go helper.)
>
> See the demo code at 
> https://github.com/cespare/misc/tree/master/asm/stackmap or go get 
> github.com/cespare/misc/asm/stackmap.
>
> For 
> ​the​
>  demo, I have a small function with an append-style API:
>
> func X(b []byte) []byte
>
> This calls a Go helper growSlice.
>
> This code sometimes works, but if I run `go test -count 1000` I'll quickly 
> see
>
> runtime: frame github.com/cespare/misc/asm/stackmap.X untyped locals 
> 0xc420042bf8+0x30
> fatal error: missing stackmap
> ...
>
> I've read through the Runtime Coordination section of the 
> ​asm
>  walkthrough (https://golang.org/doc/asm#runtime) several times, but I 
> don't see the problem.
>
> Here is my understanding of a few relevant bits of that section (which 
> might be incorrect):
>
> If the results will hold live pointers during a call instruction, the 
>> function should start by zeroing the results and then executing the 
>> pseudo-instruction GO_RESULTS_INITIALIZED.
>
>
> This doesn't seem to apply to my code because the results aren't populated 
> until after the CALL.
>
> If a function has no local stack frame, the pointer information can be 
>> omitted. This is indicated by a local frame size annotation of $0-n on the 
>> TEXT instruction. The pointer information can also be omitted if the 
>> function contains no call instructions. Otherwise, the local stack frame 
>> must not contain pointers, and the assembly must confirm this fact by 
>> executing the pseudo-instruction NO_LOCAL_POINTERS.
>
>
> ​My function makes a CALL with arguments. But it has to ​have a pointer 
> (the slice) on the local stack frame in order to pass to that helper. I 
> don't really understand what this section means.
>
> `go vet` doesn't say anything about my code.
>
> Any ideas?
>
> Thanks!
> Caleb
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Newbie Struggling w/ Hashing

2016-09-19 Thread Jesse McNelis
On 20 Sep 2016 9:03 a.m., "Robert Solomon"  wrote:
>
> FileReadBuffer := make([]byte,ReadBufferSize);
> for {   // Repeat Until eof loop.
>   n,err := TargetFile.Read(FileReadBuffer);
>   if n == 0 || err == io.EOF { break }
>   check(err," Unexpected error while reading the target file on which
to compute the hash,");
>   hasher.Write(FileReadBuffer);
>   FileSize += int64(n);
> } // Repeat Until

The problem you encounter is that .Read() isn't required to fill the buffer
you give it, it can give you less than that.

Handling that requires you to slice the result
eg. hasher.Write(FileReadBuffer[:n]);

But you should avoid calling Read() and Write() and instead use higher
level functions like io.Copy() which will handle these low level details
for you.

Read the io package docs for more information.
https://golang.org/pkg/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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread 'Paul Borman' via golang-nuts
In theory the compiler can be smart enough, if it knows that the string
passed to fmt.Println is not stored and re-used someplace, but I do not
believe that is currently true.   It probably has at least 2 copies, one to
the string in your code and a second one to make it a []byte to pass to the
io.Writer.  I am not sure if the later has been optimized out or not.

-Paul

On Mon, Sep 19, 2016 at 4:10 PM, 'simon place' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> well, seems to me if you need to access a string by index, you are
> assuming 1 byte per char. say ASCII, so for me you should be using []byte
> to store it, then 'cast' to see it as a string.
>
> https://play.golang.org/p/2NMye8gnzg
>
> surely this doesn't do any copying?
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Calling a Go function from asm ("fatal error: missing stackmap")

2016-09-19 Thread Ian Lance Taylor
On Mon, Sep 19, 2016 at 3:56 PM, Caleb Spare  wrote:
> I'm trying to call a Go function from asm and I'm having trouble figuring
> out the details.
>
> (In the past I've always endeavored to avoid this situation and make all my
> asm functions be leaf functions, but in my current use case it would be most
> helpful to be able to call a Go helper.)
>
> See the demo code at
> https://github.com/cespare/misc/tree/master/asm/stackmap or go get
> github.com/cespare/misc/asm/stackmap.
>
> For
> the
>  demo, I have a small function with an append-style API:
>
> func X(b []byte) []byte
>
> This calls a Go helper growSlice.
>
> This code sometimes works, but if I run `go test -count 1000` I'll quickly
> see
>
> runtime: frame github.com/cespare/misc/asm/stackmap.X untyped locals
> 0xc420042bf8+0x30
> fatal error: missing stackmap
> ...
>
> I've read through the Runtime Coordination section of the
> asm
>  walkthrough (https://golang.org/doc/asm#runtime) several times, but I don't
> see the problem.
>
> Here is my understanding of a few relevant bits of that section (which might
> be incorrect):
>
>> If the results will hold live pointers during a call instruction, the
>> function should start by zeroing the results and then executing the
>> pseudo-instruction GO_RESULTS_INITIALIZED.
>
>
> This doesn't seem to apply to my code because the results aren't populated
> until after the CALL.
>
>> If a function has no local stack frame, the pointer information can be
>> omitted. This is indicated by a local frame size annotation of $0-n on the
>> TEXT instruction. The pointer information can also be omitted if the
>> function contains no call instructions. Otherwise, the local stack frame
>> must not contain pointers, and the assembly must confirm this fact by
>> executing the pseudo-instruction NO_LOCAL_POINTERS.
>
>
> My function makes a CALL with arguments. But it has to have a pointer (the
> slice) on the local stack frame in order to pass to that helper. I don't
> really understand what this section means.
>
> `go vet` doesn't say anything about my code.
>
> Any ideas?

You've run into a really hairy area of asm code.

My first suggestion is not try to call from assembler into Go.

Otherwise, the problem is that when you call into Go the garbage
collector may run.  The garbage collector will walk up the stack and
mark all pointers on the stack as live.  That means that it needs to
know which values on the stack are live pointers and which are not.
For Go code the compiler generates this information automatically.
For assembler code you need to generate this information yourself.

Also, calling into Go code may cause the stack to be copied so, again,
the stack copier needs to know which stack pointers are live.

In your case you do apparently have a pointer on the stack while
calling the Go function.  That means that you need to write PCDATA
$PCDATA_StackMapIndex pseudo-ops that specifies the stack map.  But
frankly I don't know what the value should be.  If you run "go tool
compile -S" on some similar Go code you will see the PCDATA
statements, probably one per function call.  But the details are so
complex that they are undocumented.  To get further on this you will
need to read through cmd/compile/internal/gc/plive.go.

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Alignment and Padding / Packing of structs

2016-09-19 Thread Ali Demir
Yes, so what you are describing to me needs to be told to the C compiler
users in a formal way so that they make sure their alignment is the same as
Go. Thanks.

On Mon, Sep 19, 2016 at 2:27 PM, Ian Lance Taylor  wrote:

> On Mon, Sep 19, 2016 at 2:08 PM, Ali Demir  wrote:
> > Packing option is explicitly specified for VC++:
> >
> > https://msdn.microsoft.com/en-us/library/xh3e3fd0.aspx
> >
> > The user needs to make sure whatever they pick (or default) in their
> project
> > matches what Go compiler used. So it may help to specify what go
> compiler is
> > using.
>
> There is no answer to that question.  The Go compiler is not running
> the C compiler.
>
> In general the Go compiler expects fields to be aligned to their size.
> That is, a four byte field is aligned to a four byte boundary, and an
> eight byte field is aligned to an eight byte boundary.  As I said
> earlier, the compiler emits padding fields so that everything will
> work if the C compiler uses a smaller alignment.  However, things will
> fail if the C compiler uses a larger alignment.  I'm not aware of any
> such C compiler, but I guess it wouldn't shock me.
>
> Ian
>
> > On Mon, Sep 19, 2016 at 10:00 AM, Ian Lance Taylor 
> wrote:
> >>
> >> On Mon, Sep 19, 2016 at 8:50 AM, Ali Demir  wrote:
> >> > Header file won't have padding / alignment info. That would be a
> >> > compiler
> >> > setting on the C side that is using the header. So the programmer
> needs
> >> > to
> >> > setup C compiler in a way that is compatible with the go compiler. How
> >> > would
> >> > he know how to set it up? Do we just assume defaults are the same
> >> > between Go
> >> > and C?
> >>
> >> The cgo tool will generate padding fields as needed to ensure that the
> >> fields are aligned as expected.
> >>
> >> It's true that the cgo tool does assume that it knows the alignment
> >> requirements of the basic types.  These requirements are not normally
> >> changed by compiler options.  The alignment requirements of unusual
> >> types, such as processor-specific vector types, are not relevant,
> >> since Go can't represent them and they will therefore never appear in
> >> the Go/C interface.
> >>
> >> Do you have a specific concern, or is this purely abstract?
> >>
> >> 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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Newbie Struggling w/ Hashing

2016-09-19 Thread Robert Solomon
Hi.  I'm trying to learn Go after many years of using a different
language.  My development machine runs Ubuntu 16.04 amd64, go 1.6.2
linux/amd

I compared the output of the following code, and my output differs from the
std utilities such as sha1sum, sha215sum, etc.  I used
go1.6.3.windows-386.msi as my test file.

I also noticed that the hashes that were output were different, depending
on the value I set for my ReadBufferSize.  I don't understand why the
output I'm seeing doesn't match the std utilities, and why the hashes vary
w/ my buffer size.

Thanks,
Rob Solomon

package main;

import (
"os"
"fmt"
"runtime"
"encoding/hex"
"crypto/sha512"
"crypto/sha256"
"crypto/sha1"
"crypto/md5"
"io"
"hash"
"getcommandline"   // this one's mine.
)

func main() {

  const K = 1024;
  const M = 1024*1024;

  const (
 md5hash = iota
 sha1hash
 sha256hash
 sha384hash
 sha512hash
 HashType
);

  const ReadBufferSize = 10 * M;

  var HashName = [...]string{"md5","sha1","sha256","sha384","sha512"};
  var WhichHash int;
  var hasher hash.Hash;
  var FileSize int64;


  if len(os.Args) <= 1 {
fmt.Println(" Need input filename as a param. ");
os.Exit(0);
  }
  FileToHash := getcommandline.GetCommandLineString();

  fmt.Println();
  fmt.Print(" GOOS =",runtime.GOOS,".  ARCH=",runtime.GOARCH);
  fmt.Println("  WhichHash = ",HashName[WhichHash]);
  fmt.Println();
  fmt.Println();

  for {
FileSize = 0;

/* Create Hash Section */
TargetFile,readErr := os.Open(FileToHash);
check(readErr," Error opening FileToHash.");
defer TargetFile.Close();

switch WhichHash { // Initialing case switch on WhichHash
case md5hash :
   hasher = md5.New();
case sha1hash :
   hasher = sha1.New();
case sha256hash :
   hasher = sha256.New();
case sha384hash :
   hasher = sha512.New384();
case sha512hash :
   hasher = sha512.New();
default:
   hasher = sha256.New();
} /* initializing case on WhichHash */

FileReadBuffer := make([]byte,ReadBufferSize);
for {   // Repeat Until eof loop.
  n,err := TargetFile.Read(FileReadBuffer);
  if n == 0 || err == io.EOF { break }
  check(err," Unexpected error while reading the target file on which
to compute the hash,");
  hasher.Write(FileReadBuffer);
  FileSize += int64(n);
} // Repeat Until TargetFile.eof loop;

HashValueComputedStr := hex.EncodeToString(hasher.Sum(nil));

fmt.Println(" Filename  = ",FileToHash,", FileSize = ",FileSize,",
",HashName[WhichHash]," computed hash string, followed by hash string in
the file are : ");
fmt.Println(" Computed hash hex encoded:",HashValueComputedStr);

TargetFile.Close(); // Close the handle to allow opening a target
from the next line, if there is one.
fmt.Println();
fmt.Println();

WhichHash++
if WhichHash > sha512hash {break}
  }   /* outer LOOP */

  fmt.Println();
}

// --- check
---
func check(e error, msg string) {
  if e != nil {
fmt.Errorf("%s : ",msg);
panic(e);
  }
}

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Calling a Go function from asm ("fatal error: missing stackmap")

2016-09-19 Thread Caleb Spare
I'm trying to call a Go function from asm and I'm having trouble figuring
out the details.

(In the past I've always endeavored to avoid this situation and make all my
asm functions be leaf functions, but in my current use case it would be
most helpful to be able to call a Go helper.)

See the demo code at
https://github.com/cespare/misc/tree/master/asm/stackmap or go get
github.com/cespare/misc/asm/stackmap.

For
​the​
 demo, I have a small function with an append-style API:

func X(b []byte) []byte

This calls a Go helper growSlice.

This code sometimes works, but if I run `go test -count 1000` I'll quickly
see

runtime: frame github.com/cespare/misc/asm/stackmap.X untyped locals
0xc420042bf8+0x30
fatal error: missing stackmap
...

I've read through the Runtime Coordination section of the
​asm
 walkthrough (https://golang.org/doc/asm#runtime) several times, but I
don't see the problem.

Here is my understanding of a few relevant bits of that section (which
might be incorrect):

If the results will hold live pointers during a call instruction, the
> function should start by zeroing the results and then executing the
> pseudo-instruction GO_RESULTS_INITIALIZED.


This doesn't seem to apply to my code because the results aren't populated
until after the CALL.

If a function has no local stack frame, the pointer information can be
> omitted. This is indicated by a local frame size annotation of $0-n on the
> TEXT instruction. The pointer information can also be omitted if the
> function contains no call instructions. Otherwise, the local stack frame
> must not contain pointers, and the assembly must confirm this fact by
> executing the pseudo-instruction NO_LOCAL_POINTERS.


​My function makes a CALL with arguments. But it has to ​have a pointer
(the slice) on the local stack frame in order to pass to that helper. I
don't really understand what this section means.

`go vet` doesn't say anything about my code.

Any ideas?

Thanks!
Caleb

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] interpreting in a traceback

2016-09-19 Thread Ian Lance Taylor
On Mon, Sep 19, 2016 at 3:49 PM, Alex Flint  wrote:
>
> Just to confirm: it's not possible that the dynamic type of x as seen from
> Go code would be ExplicitFunc, but the interface stores a *ExplicitFunc
> internally within the itab, and so the compiler generates
> (*ExplicitFunc).Call?

That is correct: that would not happen.

Ian

> On Mon, Sep 19, 2016 at 3:46 PM Ian Lance Taylor  wrote:
>>
>> On Mon, Sep 19, 2016 at 3:21 PM, Alex Flint  wrote:
>> > I am looking for help understanding the following lines in a Go
>> > traceback:
>> >
>> > 6 File "specialized.go" line 163 in pythontype.ExplicitFunc.Call
>> > 7 File "" line 510 in pythontype.(*ExplicitFunc).Call
>> > 8 File "propagate.go" line 622 in
>> > pythonstatic.(*propagator).evaluateCallExpr
>> >
>> > I am trying to understand what line 7 means in the following context:
>> > evaluateCallExpr takes a parameter x of type pythontype.Value, which is
>> > an
>> > interface, and invokes x.Call(), which is one of the methods on that
>> > interface. One implementation of that interface is
>> > pythontype.ExplicitFunc.
>> > Am I right in understanding from that traceback that the dynamic type of
>> > the
>> > pythontype.Value was *pythontype.ExplicitFunc, not
>> > pythontype.ExplicitFunc?
>>
>> Yes.
>>
>> 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] interpreting in a traceback

2016-09-19 Thread Alex Flint
Thanks Ian.

Just to confirm: it's not possible that the dynamic type of x as seen from
Go code would be ExplicitFunc, but the interface stores a *ExplicitFunc
internally within the itab, and so the compiler generates
(*ExplicitFunc).Call?

On Mon, Sep 19, 2016 at 3:46 PM Ian Lance Taylor  wrote:

> On Mon, Sep 19, 2016 at 3:21 PM, Alex Flint  wrote:
> > I am looking for help understanding the following lines in a Go
> traceback:
> >
> > 6 File "specialized.go" line 163 in pythontype.ExplicitFunc.Call
> > 7 File "" line 510 in pythontype.(*ExplicitFunc).Call
> > 8 File "propagate.go" line 622 in
> > pythonstatic.(*propagator).evaluateCallExpr
> >
> > I am trying to understand what line 7 means in the following context:
> > evaluateCallExpr takes a parameter x of type pythontype.Value, which is
> an
> > interface, and invokes x.Call(), which is one of the methods on that
> > interface. One implementation of that interface is
> pythontype.ExplicitFunc.
> > Am I right in understanding from that traceback that the dynamic type of
> the
> > pythontype.Value was *pythontype.ExplicitFunc, not
> pythontype.ExplicitFunc?
>
> Yes.
>
> 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread 'Paul Borman' via golang-nuts
A string is immutable, a byte slice is not.

Suppose you have:

b := []byte("hello world")
s := string(b)
fmt.Println(s)
b[0] = 'H'
fmt.Println(s)


What is printed?

hello world
hello word

Using the OPs function:

b := []byte("hello world")
s := fastBytesToString(b)
fmt.Println(s)
b[0] = 'H'
fmt.Println(s)


This results in

hello world
Hello world


So the immutable string pointed to by s has been mutated, so this program
violates Go's memory model.

"casting" a byte slice to/from a string involves a memory allocation and
copy, to be valid Go.

-Paul

On Mon, Sep 19, 2016 at 3:33 PM, 'simon place' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> i thought strings were just byte[]s, when you 'cast' all you do is tell
> the compiler to change the way the underlying bytes can are used. it
> doesn't 'cost' anything.
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] memory profiler for benchmark test reports 0s across the board

2016-09-19 Thread Dave Cheney
Try b.ReportAllocs() before your benchmark loop. That's the easiest way to 
benchmark the allocations per operation.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread 'Paul Borman' via golang-nuts
As long as no one modifies the bytes in the byteslice.  Go can no longer
enforce that the string is immutable with this hack.

On Mon, Sep 19, 2016 at 2:35 PM,  wrote:

> I don't like the extra allocation and copies involved when casting from
> byte slice to string or vice versa just because one type or the other is
> required. The code below reuses the data pointer and as far as I can tell
> in my tests so far, it even works well with garbage collection. My question
> is... why shouldn't I do this?
>
>
> func fastStringToBytes(str string) []byte {
> var b []byte
>
> strhdr := (*reflect.StringHeader)(unsafe.Pointer())
> bythdr := (*reflect.SliceHeader)(unsafe.Pointer())
>
> d := strhdr.Data
> l := strhdr.Len
>
> // strhdr.Data = bythdr.Data
> // strhdr.Len = bythdr.Len
>
> bythdr.Data = d
> bythdr.Len = l
> bythdr.Cap = l
>
> return b
> }
>
> func fastBytesToString(b []byte) string {
> var str string
>
> strhdr := (*reflect.StringHeader)(unsafe.Pointer())
> bythdr := (*reflect.SliceHeader)(unsafe.Pointer())
>
> // d := strhdr.Data
> // l := strhdr.Len
>
> strhdr.Data = bythdr.Data
> strhdr.Len = bythdr.Len
>
> // bythdr.Data = d
> // bythdr.Len = l
> // bythdr.Cap = l
>
> return str
> }
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread badrelish
I don't like the extra allocation and copies involved when casting from 
byte slice to string or vice versa just because one type or the other is 
required. The code below reuses the data pointer and as far as I can tell 
in my tests so far, it even works well with garbage collection. My question 
is... why shouldn't I do this?


func fastStringToBytes(str string) []byte {
var b []byte

strhdr := (*reflect.StringHeader)(unsafe.Pointer())
bythdr := (*reflect.SliceHeader)(unsafe.Pointer())

d := strhdr.Data
l := strhdr.Len

// strhdr.Data = bythdr.Data
// strhdr.Len = bythdr.Len

bythdr.Data = d
bythdr.Len = l
bythdr.Cap = l

return b
}

func fastBytesToString(b []byte) string {
var str string

strhdr := (*reflect.StringHeader)(unsafe.Pointer())
bythdr := (*reflect.SliceHeader)(unsafe.Pointer())

// d := strhdr.Data
// l := strhdr.Len

strhdr.Data = bythdr.Data
strhdr.Len = bythdr.Len

// bythdr.Data = d
// bythdr.Len = l
// bythdr.Cap = l

return str
}

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] How to implement In Golang

2016-09-19 Thread James
Try this tutorial:
http://go-database-sql.org/

On 20 September 2016 at 03:42, kumargv  wrote:

> import MySQLdb
>
> conn = MySQLdb.Connect(
> host='localhost', user='user',
> passwd='secret', db='test')
> cursor = conn.cursor()
> cursor.execute("SELECT this,that FROM foobar")
> rows = cursor.fetchall()
> cursor.close()
> conn.close()
>
>
> I am unable to Implement The above code in golang
> Please suggest
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Compiler plugins or something?

2016-09-19 Thread Mateusz Czapliński
The pkg plugin is intended to allow writing "plugin-aware" Go apps, and 
plugins for them - cooperatively (that is, a "host" app must use this 
package and provide explicit "hook" points for plugins). The idea is 
outlined (since quite long ago) at the link mentioned by Ian L.T. earlier: 
https://golang.org/s/execmodes In other words, if an app author wants to 
enable writing plugins for his app, he/she can use pkg plugin as basic 
infrastructure for that.

On the other hand, from other posts by Ian in this thread it seems there 
are no plans for *compiler* plugins (that is, where the Go compiler 
specifically would provide some "hook" points into its internals, possibly 
by means of pkg plugin).

W dniu niedziela, 18 września 2016 17:46:05 UTC+2 użytkownik Ian Byrd 
napisał:
>
> Ian, how would you comment this: https://tip.golang.org/pkg/plugin/?
>
> On Wed, Aug 31, 2016 at 11:00 AM, Ian Lance Taylor > > wrote:
>>
>>> The status is unchanged.  There is no support for compiler plugins and
>>> no plans for them.  I make no promise that the Go compiler will ever
>>> support plugins.  I think an external program, along the lines of go
>>> vet, is the right approach to use for additional static checking.
>>>
>>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] memory profiler for benchmark test reports 0s across the board

2016-09-19 Thread 'Ethan Kennedy' via golang-nuts
I've got a function that reads `map[string]interface{}` off a channel, 
processing each one until that channel is closed. Processing each `map` 
entails allocating some slices and other data structures, grouping by like 
keys, etc.

I've got a benchmark that reads 1 rows of JSON from a file, unmarshals 
each to a `map[string]interface`, sets up channels, runs the aforementioned 
function in a Goroutine, and sends each unmarshaled JSON over the input 
channel of the function, etc., etc.

When I profile CPU usage, I get insightful output, and I've managed to 
improve performance by a factor of 4.

However, when I run the benchmark with `memprofile` flag and point pprof at 
it, I get something like:

0 of 0 total ( 0%)
 flat flat% sum%  cum cum%
00%  0%  0  0% pkgname.SomeFunc
00%  0%  0  0% pkgname.SomeOtherFunc

I'm running Go 1.6 on Ubuntu 12.04.

I've searched and searched but not found any answers as to why I am unable 
to obtain a good heap profile. `runtime.mallocgc` features prominently in 
my cpu profiles, so I know objects are getting allocated and collected.

Any help?

Thanks

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Alignment and Padding / Packing of structs

2016-09-19 Thread Ali Demir
Packing option is explicitly specified for VC++:

https://msdn.microsoft.com/en-us/library/xh3e3fd0.aspx

The user needs to make sure whatever they pick (or default) in their
project matches what Go compiler used. So it may help to specify what go
compiler is using.


On Mon, Sep 19, 2016 at 10:00 AM, Ian Lance Taylor  wrote:

> On Mon, Sep 19, 2016 at 8:50 AM, Ali Demir  wrote:
> > Header file won't have padding / alignment info. That would be a compiler
> > setting on the C side that is using the header. So the programmer needs
> to
> > setup C compiler in a way that is compatible with the go compiler. How
> would
> > he know how to set it up? Do we just assume defaults are the same
> between Go
> > and C?
>
> The cgo tool will generate padding fields as needed to ensure that the
> fields are aligned as expected.
>
> It's true that the cgo tool does assume that it knows the alignment
> requirements of the basic types.  These requirements are not normally
> changed by compiler options.  The alignment requirements of unusual
> types, such as processor-specific vector types, are not relevant,
> since Go can't represent them and they will therefore never appear in
> the Go/C interface.
>
> Do you have a specific concern, or is this purely abstract?
>
> 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] fatal error:malloc deadlock

2016-09-19 Thread Ian Lance Taylor
On Mon, Sep 19, 2016 at 8:34 AM, Wanghb Wang  wrote:
>
> when I use stattcpupprof in my program, I got fatal error malloc deadlock.
> delete the cpu pprof,  the program run well.
>
>
> my question is :
> Does startcpuprof infect the malloc or resulting OOM Problem

I'm sorry, I don't understand the question.


> this is my panic stack trace:

It looks like you have C code that calls goCbStr.  Somehow when that
happens the malloc lock is held for the thread.  The only way I can
see that happening is if your C code has a SIGPROF handler that calls
into Go.

Ian


> fatal error: malloc deadlock
> goroutine 17 [running, locked to thread]:
> runtime.throw(0x845aa0, 0xf)
> C:/Go/src/runtime/panic.go:547 +0x97 fp=0xc082025c68 sp=0xc082025c50
> runtime.mallocgc(0x5, 0x0, 0x3, 0x822aa0)
> C:/Go/src/runtime/malloc.go:544 +0x1e1 fp=0xc082025d40
> sp=0xc082025c68
> runtime.rawstring(0x5, 0x0, 0x0, 0x0, 0x0, 0x0)
> C:/Go/src/runtime/string.go:284 +0x77 fp=0xc082025d88
> sp=0xc082025d40
> runtime.gostring(0x7ff94f7f992c, 0x0, 0x0)
> C:/Go/src/runtime/string.go:341 +0x62 fp=0xc082025df0
> sp=0xc082025d88
> main._Cfunc_GoString(0x7ff94f7f992c, 0x0, 0x0)
> test/_obj/_cgo_gotypes.go:44 +0x34 fp=0xc082025e10 sp=0xc082025df0
> main.goCbStr(0x1, 0x2, 0x7ff94f7f992c, 0xa20fd0)
> C:/Programming/go-src/src/test/test.go:125 +0x62 fp=0xc082025ed0
> sp=0xc082025e10
> runtime.call32(0x0, 0x8eb238, 0x3befdd0, 0x20)
> C:/Go/src/runtime/asm_amd64.s:472 +0x45 fp=0xc082025ef8
> sp=0xc082025ed0
> runtime.cgocallbackg1()
> C:/Go/src/runtime/cgocall.go:267 +0x11a fp=0xc082025f30
> sp=0xc082025ef8
> runtime.cgocallbackg()
> C:/Go/src/runtime/cgocall.go:180 +0xde fp=0xc082025f90
> sp=0xc082025f30
> runtime.cgocallback_gofunc(0x0, 0x0, 0x0)
> C:/Go/src/runtime/asm_amd64.s:716 +0x6d fp=0xc082025fa0
> sp=0xc082025f90
> runtime.goexit()
> C:/Go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc082025fa8
> sp=0xc082025fa0
>
> goroutine 1 [sleep]:
> time.Sleep(0x3b9aca00)
> C:/Go/src/runtime/time.go:59 +0x107
> main.main()
> C:/Programming/go-src/src/test/test.go:64 +0x4c3
>
> goroutine 18 [syscall, locked to thread]:
> runtime.goexit()
> C:/Go/src/runtime/asm_amd64.s:1998 +0x1
>
> goroutine 6 [syscall]:
> runtime.CPUProfile(0x0, 0x0, 0x0)
> C:/Go/src/runtime/cpuprof.go:421 +0x3b
> runtime/pprof.profileWriter(0x1742f0, 0xc082026038)
> C:/Go/src/runtime/pprof/pprof.go:607 +0x23
> created by runtime/pprof.StartCPUProfile
> C:/Go/src/runtime/pprof/pprof.go:601 +0x14c
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Rational number to floating point

2016-09-19 Thread Hotei
I think you'll need something like x := float(355) / float(113)   - where 
float is either float32 or float64 depending on your preferred trade-off 
for accuracy vs bytes required per number.

On Monday, September 19, 2016 at 12:38:12 PM UTC-4, Mark Longtin wrote:
>
> Hey guys, 
>
> I'm new to Go - through the Ivy app on IOS- so I have a newbie question. 
> What's the easiest way to cast or convert a rational number to its floating 
> point representation?
>
> EG, looking for something like this:
>
>
> *float 355/113*3.14159292035
>
> I could do something inelegant like
>
>
> *floor .5+1e11* 355/113*314159292035
>
> but was hoping there would be a native function for this.
>
> Thanks
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] glog incorrectly checks CommandLine.Parsed()

2016-09-19 Thread Eric Paris
Some projects (such as kubernetes and docker) do not use the standard
'flag' package and instead use the posix complaint(ish)

https://github.com/spf13/pflag

package. It however appears that

https://github.com/golang/glog/pull/13

Added a check for `flag.Parsed()`. This is not correct for programs
which don't use flag and thus `flag.Parsed()` will return false. This
patch broke two of the largest golang projects. If there were a way to
overwrite this I'd be willing to try to work around it, but breaking
properly functioning code in order to catch improperly written code
does not seem like an acceptable tradeoff.

I would like to see this PR reverted and would be happy to talk about
how to better address this if others have ideas.

-Eric

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Install vim-go as a pacakge in vim 8

2016-09-19 Thread Johann Höchtl


Am Montag, 19. September 2016 13:51:17 UTC+2 schrieb Jan Mercl:
>
> On Sun, Sep 18, 2016 at 10:46 AM Johann Höchtl  > wrote:
>
> > I thought Vim 8 packages are all automatic. vim-go commands like :help 
> vim-go or :GoUpdateBinaries do not work.
>
> Are you using the vim-8.0 branch? (
> https://github.com/fatih/vim-go/tree/vim-8.0)
>
> Wasn't, did it, and worked. After manually running

:helpt ~/.vim/pack/plugins/start/vim-go/doc/

I now have vim-go help. Thanks!
 

> -- 
>
> -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 email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Alignment and Padding / Packing of structs

2016-09-19 Thread Ian Lance Taylor
On Mon, Sep 19, 2016 at 8:50 AM, Ali Demir  wrote:
> Header file won't have padding / alignment info. That would be a compiler
> setting on the C side that is using the header. So the programmer needs to
> setup C compiler in a way that is compatible with the go compiler. How would
> he know how to set it up? Do we just assume defaults are the same between Go
> and C?

The cgo tool will generate padding fields as needed to ensure that the
fields are aligned as expected.

It's true that the cgo tool does assume that it knows the alignment
requirements of the basic types.  These requirements are not normally
changed by compiler options.  The alignment requirements of unusual
types, such as processor-specific vector types, are not relevant,
since Go can't represent them and they will therefore never appear in
the Go/C interface.

Do you have a specific concern, or is this purely abstract?

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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Rational number to floating point

2016-09-19 Thread Tamás Gulácsi
float64(355)/113

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Rational number to floating point

2016-09-19 Thread Mark Longtin
Hey guys, 

I'm new to Go - through the Ivy app on IOS- so I have a newbie question. 
What's the easiest way to cast or convert a rational number to its floating 
point representation?

EG, looking for something like this:


*float 355/113*3.14159292035

I could do something inelegant like


*floor .5+1e11* 355/113*314159292035

but was hoping there would be a native function for this.

Thanks

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] collect2.exe: error: ld returned 1 exit status

2016-09-19 Thread yourhso
What version of Go are you using (go version)?

go version go1.7 windows/amd64
What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Go_workspace
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 
-fdebug-prefix-map=C:\Users\hisha\AppData\Local\Temp\go-build226207278=/tmp/go-build
 -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1

What did you do?

i am using iris framework and gorm every thing was ok until using gorm

├───controllers
├───models
├───static
│   ├───css
│   │   └───images
│   │   └───prettyPhoto
│   │   ├───dark_rounded
│   │   ├───dark_square
│   │   ├───default
│   │   ├───facebook
│   │   ├───light_rounded
│   │   └───light_square
│   ├───fonts
│   ├───img
│   │   ├───clients
│   │   ├───portfolio
│   │   └───team
│   └───js
└───templates

main.go :

package main


import (
"mywebsite/controllers"
"mywebsite/models"

"github.com/kataras/go-template/django"
"github.com/kataras/iris"
)

func main() {
iris.UseTemplate(django.New()).Directory("templates", ".html")
iris.StaticServe("./static", "/public")
iris.Handle("GET", "/", controllers.MainHandler{})
models.DB_init()
iris.Listen(":8080")
}


models.go :

package models

import (
"time"

"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)

type User struct {
gorm.Model
FirstName string `gorm:"size:25"`
LastName  string `gorm:"size:25"`
Email string `gorm:"type:varchar(60);unique"`
Password  string
IsAdmin   bool
LastLogin time.Time
Posts []Post `gorm:"ForeignKey:UserID;"`
}
type Post struct {
gorm.Model
Title   string `gorm:"type:varchar(60)"`
Content string `gorm:"type:text"`
UserID  uint
}

//Init Function Initialize database and Migrate Scheme
func DB_init() {
db, err := gorm.Open("sqlite3", "db.db")
defer db.Close()
if err != nil {
panic("Failed to Connect to Database")
}
db.AutoMigrate({}, {})
}


controllers :

package controllers

import "github.com/kataras/iris"

type MainHandler struct {
}

func (c MainHandler) Serve(ctx *iris.Context) {
ctx.MustRender("home.html", map[string]interface{}{"message": "Hi Our 
Visitor"}, iris.RenderOptions{"gzip": true})
}


What did you expect to see?

C:\Go_workspace\src\mywebsite>iris run main.go
 _  _
|_   _|(_)
  | |   _  ___
  | | | __|| |/ __|
 _| |_| |  | |\__ \
|_|_|  |_||___/ 4.2.7

Mon, 19 Sep 2016 04:50:46 GMT: Running at 0.0.0.0:8080

What did you see instead?

go run "c:\Go_workspace\src\mywebsite\main.go"
# command-line-arguments
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920260): 
multiple definition of `r2r1kp'
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920270): 
first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x9202a0): 
multiple definition of `r4r3kp'
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920290): 
first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x91eae0): 
multiple definition of `r5kp'
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x91ead8): 
first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920360): 
multiple definition of `rupolykp'
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920350): 
first defined here
collect2.exe: error: ld returned 1 exit status

iris run main.go
# command-line-arguments
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920260): 
multiple definition of `r2r1kp'
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920270): 
first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x9202a0): 
multiple definition of `r4r3kp'
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920290): 
first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x91eae0): 
multiple definition of `r5kp'
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x91ead8): 
first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920360): 
multiple definition of `rupolykp'
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920350): 
first defined here
collect2.exe: error: ld returned 1 exit status


Error: Failed to build the program.

-- 
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 

[go-nuts] Escape special shell characters when using os.Getenv

2016-09-19 Thread weiteng . huang
I tried to `escape` dollar sign when using os.Getenv; 
I found that golang doesn’t do exactly what I expect (for example 
`$$var_one` —> print `$var_one`). 
Any suggestion?
https://play.golang.org/p/8fXS4QfCIi , 
my temporary solution requires copying code from golang os pkg 
https://play.golang.org/p/nnsK9llwvr

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] SQL database connection

2016-09-19 Thread lochbm
I fixed that but I still get errors connecting to the SQL database. Should 
I deactivate XAMPP before trying it out?

On Monday, September 19, 2016 at 12:35:30 PM UTC+3, Harald Weidner wrote:
>
> Hello, 
>
> On Mon, Sep 19, 2016 at 01:37:14AM -0700, loc...@gmail.com  
> wrote: 
>
> > import( 
> >  _ "github.com/go-sql-driver" 
> > ) 
>
> The correct name of this package is: github.com/go-sql-driver/mysql 
>
> Harald 
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] file or folder encryption tool

2016-09-19 Thread DrGo
Thanks Nick,
This looks promising!

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Alignment and Padding / Packing of structs

2016-09-19 Thread Ali Demir
Header file won't have padding / alignment info. That would be a compiler
setting on the C side that is using the header. So the programmer needs to
setup C compiler in a way that is compatible with the go compiler. How
would he know how to set it up? Do we just assume defaults are the same
between Go and C?

Typical alignment options are listed for various data types here:

https://en.wikipedia.org/wiki/Data_structure_alignment


Thanks,
Suavi


On Mon, Sep 19, 2016 at 7:58 AM, Ian Lance Taylor  wrote:

> On Sun, Sep 18, 2016 at 11:10 PM,   wrote:
> > Is there any update to alignment/padding for structs now that we can
> write
> > .so files that can be called by C programs? We would have to know it to
> tell
> > the C compiler what to expect from go side imho.
>
> When you use //export with cmd/cgo you will get a header file that
> your C code can #include.  See
> https://golang.org/cmd/cgo/#hdr-C_references_to_Go .
>
> Ian
>
>
> > On Thursday, April 5, 2012 at 9:10:48 PM UTC-7, Kyle Lemons wrote:
> >>
> >> On Thu, Apr 5, 2012 at 7:11 AM, LRN  wrote:
> >>>
> >>> Related question:
> >>> If alignment and padding is platform dependent, how do you write and
> read
> >>> structs to/from a socket?
> >>
> >>
> >> The solution is to not write platform dependent code.  The related topic
> >> of byte ordering and platform independence is covered in this blog post.
> >> The gob package (incidentally, if I'm not mistaken, also written by the
> >> author of that blog post), is a performant binary encoding scheme that
> will
> >> work from and to any platform that supports go.
> >>
> >>>
> >>> For example, in C it is not uncommon to declare a struct, initialize
> its
> >>> fields with values (converted to big-endian format), then write it
> into a
> >>> socket in one call.
> >>> The receiver will, again, read the struct from a socket in one call,
> then
> >>> will do big-endian-to-native format conversion on each field where it
> is
> >>> applicable - and will get the same struct the sender had.
> >>> This only works when definitions of the struct on both the sender and
> the
> >>> receiver are aligned in the same way (usually - 1-byte aligned).
> >>>
> >>> I've encountered this problem recently, which is why i'm asking.
> >>>
> >>> Also, MSVC uses a padding algorithm different from the one gcc has,
> which
> >>> is why there's a -mms-bitfields option in gcc. It forces gcc to use
> >>> MSVC-style padding, which is required if the caller wants to pass
> certain
> >>> structs to W32 API.
> >>> How will that work in Go? (h-m-m-m...i can probably infer that from W32
> >>> port of Go by reading its source code...)
> >>
> >>
> > --
> > 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.
> > For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] How to implement this In golang

2016-09-19 Thread kumargv


  cursor = conn.cursor(MySQLdb.cursors.DictCursor)

   cursor.execute('SHOW SLAVE STATUS')

   result = cursor.fetchone()

   cursor.close()



I am unable to Impement this in golang 

Please suggest 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] How to impelment this Golang

2016-09-19 Thread kumargv
import MySQLdb
import MySQLdb.cursors

conn = MySQLdb.Connect(
host='localhost', user='user',
passwd='secret', db='test')
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor.execute("SELECT this,that FROM foobar")
rows = cursor.fetchall()
for row in rows:
print row['this'], row['that']
cursor.close()
conn.close()


Please suggest 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] How to implement In Golang

2016-09-19 Thread kumargv
import MySQLdb

conn = MySQLdb.Connect(
host='localhost', user='user',
passwd='secret', db='test')
cursor = conn.cursor()
cursor.execute("SELECT this,that FROM foobar")
rows = cursor.fetchall()
cursor.close()
conn.close()


I am unable to Implement The above code in golang 
Please suggest  

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] fatal error:malloc deadlock

2016-09-19 Thread Wanghb Wang
when I use stattcpupprof in my program, I got fatal error malloc deadlock.
delete the cpu pprof,  the program run well.


my question is :
Does startcpuprof infect the malloc or resulting OOM Problem
this is my panic stack trace:


fatal error: malloc deadlock
goroutine 17 [running, locked to thread]:
runtime.throw(0x845aa0, 0xf)
C:/Go/src/runtime/panic.go:547 +0x97 fp=0xc082025c68 sp=0xc082025c50
runtime.mallocgc(0x5, 0x0, 0x3, 0x822aa0)
C:/Go/src/runtime/malloc.go:544 +0x1e1 fp=0xc082025d40 
sp=0xc082025c68
runtime.rawstring(0x5, 0x0, 0x0, 0x0, 0x0, 0x0)
C:/Go/src/runtime/string.go:284 +0x77 fp=0xc082025d88 
sp=0xc082025d40
runtime.gostring(0x7ff94f7f992c, 0x0, 0x0)
C:/Go/src/runtime/string.go:341 +0x62 fp=0xc082025df0 
sp=0xc082025d88
main._Cfunc_GoString(0x7ff94f7f992c, 0x0, 0x0)
test/_obj/_cgo_gotypes.go:44 +0x34 fp=0xc082025e10 sp=0xc082025df0
main.goCbStr(0x1, 0x2, 0x7ff94f7f992c, 0xa20fd0)
C:/Programming/go-src/src/test/test.go:125 +0x62 fp=0xc082025ed0 
sp=0xc082025e10
runtime.call32(0x0, 0x8eb238, 0x3befdd0, 0x20)
C:/Go/src/runtime/asm_amd64.s:472 +0x45 fp=0xc082025ef8 
sp=0xc082025ed0
runtime.cgocallbackg1()
C:/Go/src/runtime/cgocall.go:267 +0x11a fp=0xc082025f30 
sp=0xc082025ef8
runtime.cgocallbackg()
C:/Go/src/runtime/cgocall.go:180 +0xde fp=0xc082025f90 
sp=0xc082025f30
runtime.cgocallback_gofunc(0x0, 0x0, 0x0)
C:/Go/src/runtime/asm_amd64.s:716 +0x6d fp=0xc082025fa0 
sp=0xc082025f90
runtime.goexit()
C:/Go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc082025fa8 
sp=0xc082025fa0

goroutine 1 [sleep]:
time.Sleep(0x3b9aca00)
C:/Go/src/runtime/time.go:59 +0x107
main.main()
C:/Programming/go-src/src/test/test.go:64 +0x4c3

goroutine 18 [syscall, locked to thread]:
runtime.goexit()
C:/Go/src/runtime/asm_amd64.s:1998 +0x1

goroutine 6 [syscall]:
runtime.CPUProfile(0x0, 0x0, 0x0)
C:/Go/src/runtime/cpuprof.go:421 +0x3b
runtime/pprof.profileWriter(0x1742f0, 0xc082026038)
C:/Go/src/runtime/pprof/pprof.go:607 +0x23
created by runtime/pprof.StartCPUProfile
C:/Go/src/runtime/pprof/pprof.go:601 +0x14c

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [ANN] go-scp: a scp client library in go

2016-09-19 Thread 'Paul Borman' via golang-nuts
Adding an scp package is a nice addition.

You might want to consider simple names like:

Send - Sends from []byte to file on remote host
SendDir - Send files in dir to a remote host
SendFile - Sends the contents of a file to the remote host
Fetch - Fetches the contents of a file on remote host into memory
FetchFile - Fetches a file from remote host into file on local host
FetchDir - Fetches the files in a directory from the remote host

These would translate in code to names like scp.SendFile, which is pretty
descriptive all by itself.

For the directory copy, it might be better to have a function return the
io.Writer to write the file to, rather than force the files into a
directory.  This would make it easy to keep the contents in memory, change
file names, or whatever.

On Fri, Sep 16, 2016 at 9:41 AM, Hiroaki Nakamura 
wrote:

> Hi all,
>
> I noticed the golang.org/x/crypto/ssh package exists, but the scp
> package does not.
> So I wrote a scp client library in go.
> https://github.com/hnakamur/go-scp
>
> I also wrote a sshd server just usable for testing go-scp.
> https://github.com/hnakamur/go-sshd
>
> Right now, go-scp only exports high level functions which are supposed
> to be easy to use.
> https://godoc.org/github.com/hnakamur/go-scp
>
> However I wonder if there APIs can be improved. For example,
> better function names and better arguments.
>
> Could you tell me what you think?
> Thanks!
>
> Hiroaki Nakamura
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Alignment and Padding / Packing of structs

2016-09-19 Thread Ian Lance Taylor
On Sun, Sep 18, 2016 at 11:10 PM,   wrote:
> Is there any update to alignment/padding for structs now that we can write
> .so files that can be called by C programs? We would have to know it to tell
> the C compiler what to expect from go side imho.

When you use //export with cmd/cgo you will get a header file that
your C code can #include.  See
https://golang.org/cmd/cgo/#hdr-C_references_to_Go .

Ian


> On Thursday, April 5, 2012 at 9:10:48 PM UTC-7, Kyle Lemons wrote:
>>
>> On Thu, Apr 5, 2012 at 7:11 AM, LRN  wrote:
>>>
>>> Related question:
>>> If alignment and padding is platform dependent, how do you write and read
>>> structs to/from a socket?
>>
>>
>> The solution is to not write platform dependent code.  The related topic
>> of byte ordering and platform independence is covered in this blog post.
>> The gob package (incidentally, if I'm not mistaken, also written by the
>> author of that blog post), is a performant binary encoding scheme that will
>> work from and to any platform that supports go.
>>
>>>
>>> For example, in C it is not uncommon to declare a struct, initialize its
>>> fields with values (converted to big-endian format), then write it into a
>>> socket in one call.
>>> The receiver will, again, read the struct from a socket in one call, then
>>> will do big-endian-to-native format conversion on each field where it is
>>> applicable - and will get the same struct the sender had.
>>> This only works when definitions of the struct on both the sender and the
>>> receiver are aligned in the same way (usually - 1-byte aligned).
>>>
>>> I've encountered this problem recently, which is why i'm asking.
>>>
>>> Also, MSVC uses a padding algorithm different from the one gcc has, which
>>> is why there's a -mms-bitfields option in gcc. It forces gcc to use
>>> MSVC-style padding, which is required if the caller wants to pass certain
>>> structs to W32 API.
>>> How will that work in Go? (h-m-m-m...i can probably infer that from W32
>>> port of Go by reading its source code...)
>>
>>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Ivy crashes on iOS 10

2016-09-19 Thread Jan Mercl
On Mon, Sep 19, 2016 at 3:58 PM  wrote:

> Anybody with same experiences?

https://github.com/robpike/ivy/issues/29

-- 

-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 email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: net/http: In the infinite loop, refused all requests.

2016-09-19 Thread James Bardin

A busy loop is always a programming error, and there's no reason to do this 
is your code. If you actually did have a loop with no function calls that's 
somehow useful, you could add occasional calls to runtime.Gosched() to 
yield to the scheduler. 


-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] differences between pointer and value slice in for-range loop

2016-09-19 Thread Marvin Renich
* Fei Ding  [160918 02:58]:
> Thanks, Marvin, I've learned a lot from your reply. And, I've written more
> code, like:
> 
> a, b, c := 1, 2, 3
> > slice1 := []int{a, b, c}
> > for _, n := range slice1 {
> > go func(n *int) {fmt.Println(*n)}()
> > }
> 
> 
>  It seems that pass *n's address *in the code above will make a data race,
> which you have already explained why. But still, I have another question:
> If the coder do really want the addresses of elements in slice, how to do
> it correctly?

* Marvin Stenger  [160918 07:12]:
> https://play.golang.org/p/9LQMDrDIOv should work.

Marvin Stenger gives two good solutions in the above link.  I will
explain what each does and why you might use one over the other.

for i, _ := range values {
go values[i].print()
}

In this case, the expression values[i].print is evaluated to determine
the function to be scheduled, so the function that is scheduled is the
print method with an implied first argument of [i].  This
expression is evaluated prior to scheduling, so neither the variable
values nor the variable i are referenced in the goroutine.  However, the
value of [i] is a pointer into the backing array for the slice,
which will be important in choosing which solution to use.

for _, v := range values {
w := v
go w.print()
}

In the second case, although the same v is reused for all iterations of
the loop, a new w is created each time through the loop.  The assignment
to v at the beginning of the loop makes a copy of the slice element and
puts it in v.  Then it is copied a second time and stored in w.  (The
compiler may be able to optimize the generated code to avoid making two
copies.)  Now the function call that is scheduled is a call to the print
method with an implied first argument of   Because each iteration of
the loop uses a new variable w, each goroutine has its own copy of the
slice element associated with the iteration of the loop in which the
goroutine was created.

The primary consideration in choosing between these two solutions is
whether or not the goroutine can safely access the slice element in the
backing array.  If it can, use the first solution.  If it cannot, either
because the backing array might be modified or because the element
itself is not safe to reference concurrently, then use the second
solution.  I would probably modify the second solution like this:

for i, _ := range values {
var w = values[i]
go w.print()
}

This doesn't rely on the compiler's ability to optimize copying the
element twice into copying it only once, and it is just as clear to the
next programmer who reads your code.

...Marvin

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] net/http: In the infinite loop, refused all requests.

2016-09-19 Thread Tony Chen


What version of Go are you using (go version)?

go 1.6.2 mac/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/data/apps/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments 
-fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

package main

import (
"net/http"
"strconv"
"fmt"
)

func main() {
http.HandleFunc("/", httpHandler)
http.ListenAndServe(":8001", nil)
}

func httpHandler(w http.ResponseWriter, r *http.Request) {
b, _ := strconv.ParseBool(r.URL.Query().Get("loop"))
if b {
loop()
}
fmt.Fprintf(w, "ok")
}

func loop() {
i := 0
for {
if i == 1 {
i = 0
}
i++
}
}

1. curl http://127.0.0.1:8001/?loop=true
2. curl http://127.0.0.1:8001/?loop=false

When the loop to the CPU processing and about 8 times the request, refused to 
all the HTTP request.

What did you expect to see?

export GODEBUG=schedtrace=1000

SCHED 1010ms: gomaxprocs=8 idleprocs=8 threads=6 spinningthreads=0 
idlethreads=3 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 2016ms: gomaxprocs=8 idleprocs=8 threads=6 spinningthreads=0 
idlethreads=3 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 3019ms: gomaxprocs=8 idleprocs=8 threads=6 spinningthreads=0 
idlethreads=3 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 4028ms: gomaxprocs=8 idleprocs=7 threads=6 spinningthreads=0 
idlethreads=2 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 5033ms: gomaxprocs=8 idleprocs=5 threads=6 spinningthreads=0 
idlethreads=0 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 6033ms: gomaxprocs=8 idleprocs=3 threads=8 spinningthreads=0 
idlethreads=0 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 7035ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 
idlethreads=0 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 8037ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 
idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
SCHED 9044ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 
idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
SCHED 10050ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 
idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
SCHED 11059ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 
idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
SCHED 12060ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 
idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Alignment and Padding / Packing of structs

2016-09-19 Thread demir9
Is there any update to alignment/padding for structs now that we can write 
.so files that can be called by C programs? We would have to know it to 
tell the C compiler what to expect from go side imho. 


On Thursday, April 5, 2012 at 9:10:48 PM UTC-7, Kyle Lemons wrote:
>
> On Thu, Apr 5, 2012 at 7:11 AM, LRN  
> wrote:
>
>> Related question:
>> If alignment and padding is platform dependent, how do you write and read 
>> structs to/from a socket?
>>
>
> The solution is to not write platform dependent code.  The related topic 
> of byte ordering and platform independence is covered in this blog post 
> .  The gob 
> package  (incidentally, if I'm not 
> mistaken, also written by the author of that blog post), is a performant 
> binary encoding scheme that will work from and to any platform that 
> supports go.
>  
>
>> For example, in C it is not uncommon to declare a struct, initialize its 
>> fields with values (converted to big-endian format), then write it into a 
>> socket in one call.
>> The receiver will, again, read the struct from a socket in one call, then 
>> will do big-endian-to-native format conversion on each field where it is 
>> applicable - and will get the same struct the sender had.
>> This only works when definitions of the struct on both the sender and the 
>> receiver are aligned in the same way (usually - 1-byte aligned).
>>
>> I've encountered this problem recently, which is why i'm asking.
>>
>> Also, MSVC uses a padding algorithm different from the one gcc has, which 
>> is why there's a -mms-bitfields option in gcc. It forces gcc to use 
>> MSVC-style padding, which is required if the caller wants to pass certain 
>> structs to W32 API.
>> How will that work in Go? (h-m-m-m...i can probably infer that from W32 
>> port of Go by reading its source code...)
>>
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Ivy crashes on iOS 10

2016-09-19 Thread matthias
- Downloaded Ivy 1.0 from the Apple AppStore
- Tried to open it but immediately crashes

Anybody with same experiences?

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Install vim-go as a pacakge in vim 8

2016-09-19 Thread Jan Mercl
On Sun, Sep 18, 2016 at 10:46 AM Johann Höchtl 
wrote:

> I thought Vim 8 packages are all automatic. vim-go commands like :help
vim-go or :GoUpdateBinaries do not work.

Are you using the vim-8.0 branch? (
https://github.com/fatih/vim-go/tree/vim-8.0)

-- 

-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 email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] file or folder encryption tool

2016-09-19 Thread Nick Craig-Wood
On 19/09/16 10:49, DrGo wrote:
> Has any used Go to develop a cross-platform an easy-to-use utility to encrypt 
> individual files or folders? 
> 

You could use rclone to encrypt a directory of files.  It can also
transfer them to cloud storage systems too!

See rclone.org for docs and github.com/ncw/rclone for code.

What you would do is configure a crypt remote using a directory on your
disk.  You can then rclone copy /path/to/unencryptedfiles remote:

It perhaps isn't exactly the workflow you want but it is written in Go!

It uses the go port of secret box for encrypting stuff.

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Install vim-go as a pacakge in vim 8

2016-09-19 Thread Sean Russell
On Monday, September 19, 2016 at 5:13:21 AM UTC-4, Tamás Gulácsi wrote:
>
> Nope, I'm on neovim (with plug for the plugins) for a long time now...


I don't think I even needed a plug for the plugins -- I just cp -r ~/.vim 
~/.config/nvim and everything worked, including vim-go.

--- SER

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: write in file the result of code

2016-09-19 Thread Dave Cheney
I'm sorry this did not fix your problem. Can you please try to explain your 
problem, I don't think I understand what the issue you are having is. 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] SQL database connection

2016-09-19 Thread Harald Weidner
Hello,

On Mon, Sep 19, 2016 at 01:37:14AM -0700, loc...@gmail.com wrote:

> import(
>  _ "github.com/go-sql-driver"
> )

The correct name of this package is: github.com/go-sql-driver/mysql

Harald

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: write in file the result of code

2016-09-19 Thread Anonymous


it changes nothing :(

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Install vim-go as a pacakge in vim 8

2016-09-19 Thread Tamás Gulácsi
Nope, I'm on neovim (with plug for the plugins) for a long time now...

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: write in file the result of code

2016-09-19 Thread Anonymous
here is my code :

package main
import (
"fmt"
"math/big"
"log"
"os"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/base58"
)

func main() {
// Print header


// Initialise big numbers with small numbers
count, one := big.NewInt(0), big.NewInt(900)

count.SetString("102987336249554097029535212322581322789799900648198034993379397001115665086549",10)

// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)

// Loop forever because we're never going to hit the end anyway
for {
// Increment our counter
count.Add(count, one)

// Copy count value's bytes to padded slice
copy(padded[32-len(count.Bytes()):], count.Bytes())

// Get public key
_, public := btcec.PrivKeyFromBytes(btcec.S256(), padded)

// Get compressed and uncompressed addresses
caddr, _ := btcutil.NewAddressPubKey(public.SerializeCompressed(), 
)
decoded, version, err := base58.CheckDecode(caddr.EncodeAddress())
if err != nil {
 fmt.Println(err)
return
}

// Print keys
   str := fmt.Sprintf("%49s\n", big.NewInt(0).SetBytes(decoded), 
version)

// Create a new file called file.txt.
   f, err := os.Create("file.txt")
   if err != nil {
   log.Fatalln(err)
   }
   
// Close the file when we're done.
   defer f.Close()

// Create and write to a new file called file.txt.
   for {
   _  , err = f.WriteString(str)
   }
  if err != nil {
  log.Fatalln(err)
}
  fmt.Printf(str)
}
}

result : in file.txt

%!(EXTRA uint8=0)1249045137724672133690259881462329489226509877080
%!(EXTRA uint8=0)1249045137724672133690259881462329489226509877080
%!(EXTRA uint8=0)1249045137724672133690259881462329489226509877080
%!(EXTRA uint8=0)1249045137724672133690259881462329489226509877080
%!(EXTRA uint8=0)1249045137724672133690259881462329489226509877080
%!(EXTRA uint8=0)1249045137724672133690259881462329489226509877080

ect...


-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Install vim-go as a pacakge in vim 8

2016-09-19 Thread Johann Höchtl
Guys, nobody using Vim 8 and the venerable go-vim plugin in Vim 8 as a 
package? Don't let me down on that!

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] SQL database connection

2016-09-19 Thread Dave Cheney
What did you expect to see when you ran that code?

What did you see instead?

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] SQL database connection

2016-09-19 Thread lochbm
Hello, everyone. I downloaded the SQL-connect driver for GOlang from GitHub 
and cannot seem to connect to my MYSQL database which was installed along 
with XAMPP. Below is the code:

package main

import(
 "fmt"
 "database/sql"
 _ "github.com/go-sql-driver"
)

func main(){
 mysql, err := sql.Open("mysql", "user:pass@tcp(127.0.0.1)/database")
 p.DBstatus = mysql == nil
 mysql.Close()
 fmt.Println(err)
}

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] write in file the result of code

2016-09-19 Thread Dave Cheney
What did you expect to happen when you ran this program?

What happened instead?

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] write in file the result of code

2016-09-19 Thread Nosferatu fist
Hello I have a desire to write in the result of the code file:

package main
import (
"fmt"
"math/big"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/base58"
)

func main() {
// Print header
fmt.Printf("%64s %34s %49s", "Private", "Public", "decoded")

// Initialise big numbers with small numbers
count, one := big.NewInt(0), big.NewInt(1)

// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)

// Loop forever because we're never going to hit the end anyway
for {
// Increment our counter
count.Add(count, one)

// Copy count value's bytes to padded slice
copy(padded[32-len(count.Bytes()):], count.Bytes())

// Get public key
_, public := btcec.PrivKeyFromBytes(btcec.S256(), padded)

// Get compressed and uncompressed addresses
caddr, _ := btcutil.NewAddressPubKey(public.SerializeCompressed(), 
)
decoded, version, err := base58.CheckDecode(caddr.EncodeAddress())
if err != nil {
 fmt.Println(err)
return
}

// Print keys
fmt.Printf("%x %34s %49s", padded, caddr.EncodeAddress(), 
big.NewInt(0).SetBytes(decoded))
fmt.Println("", version)
}
}

-- 
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.
For more options, visit https://groups.google.com/d/optout.