[go-nuts] Re: unsafe.Pointer conversions

2023-07-26 Thread 'Keith Randall' via golang-nuts


On Wednesday, July 26, 2023 at 9:56:54 AM UTC-7 Nigel van Keulen wrote:

Since unsafe.Pointer can convert between types that have the same 
underlying type, can unsafe.Pointer also convert between function types 
who's arguments & return values have the same underlying type?

The code I would like to use this technique on:
```
type JSExtFunc func(this Value, args Args) interface{} 

func (f JSExtFunc) MarshalJS() js.Func { 
// I am not sure if this is correct. 
var function = *(*func(this js.Value, args []js.Value) interface
{})(unsafe.Pointer()) 
return js.FuncOf(function)
 } 
// Arguments for wrapped functions. 
type Args []js.Value 
type Value js.Value
```

I have tried this out in the go playground, and it does seem to work.
https://go.dev/play/p/XVwRatkuTQv

However, this is undocumented in the language specification. 
How likely is this that this code would break, using the same version of Go?
Is this perhaps something to be added in the language specification?


Yes, that will probably work. It is the unsafe package though, so we don't 
promise it will continue to work.
If we were to specify it, we'd need to be more explicit about what 
"equivalent memory layout" means in rule 1 of pkg.go.dev/unsafe#Pointer . 
All function values technically have an equivalent memory layout (they are 
all just one pointer), so we'd need to say something about 
arguments+returns being the same size and recursively have equivalent 
layout.
 

Maybe even a more interesting question, breaking all safety guards, could 
this be extended by casting a function which takes a uint64 (`func 
myFunc(uint64)`) to a function which takes two uint32's? (`*(*func(uint32, 
uint32)(unsafe.Pointer(ptrToMyFuncValue)))`)


This will not work. The calling convention differs between one int64 and 
two int32s.
 

The latter is something I do not nescessarily desire an answer to, but it 
does make me curious.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/403ac487-0f3e-43cc-b4f2-7ebe9bf89e3en%40googlegroups.com.


Re: [go-nuts] Is there a pure Go packet capture and analysis tool?

2023-07-26 Thread Eli Lindsey
gopacket’s C bindings are for different ways of initially capturing the packets 
(libpcap, pfring, and so on). I would recommend seeing if you can create a pure 
Go PacketDataSource for the platform and API that you care about and reuse the 
rest of gopacket’s layered decoding support. gopacket does have some support 
for this (see the SOCK_RAW based pcapgo in the source tree), though I’m not 
sure how complete it is and it may have significantly worse performance than 
the other collection methods - at the very least it could be a useful starting 
point for writing your own.

-eli

> On Jul 26, 2023, at 3:28 PM, Aurora  wrote:
> 
> I'm looking for a pure Go method to capture live TCP traffic.
> 
> I've tried using gopacket. It works fine, but it's using C behind the scenes 
> and that makes it not suitable for my situation.
> 
> Is there any way to this in pure Go?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/4aec5d94-c2d3-46ec-967d-41bc4623ca65n%40googlegroups.com
>  
> .

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/466D15D5-AC72-4360-A6DE-EE75A6CBF1B2%40siliconsprawl.com.


[go-nuts] Is there a pure Go packet capture and analysis tool?

2023-07-26 Thread Aurora
I'm looking for a pure Go method to capture live TCP traffic.

I've tried using gopacket. It works fine, but it's using C behind the 
scenes and that makes it not suitable for my situation.

Is there any way to this in pure Go?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4aec5d94-c2d3-46ec-967d-41bc4623ca65n%40googlegroups.com.


Re: [go-nuts] map type conversion

2023-07-26 Thread Nigel van Keulen
Maybe my question could be of interest in this topic. I am not sure, and 
haven't tested if it works with maps, and I am also not sure if it is 
supposed to work / will work consistently. 
https://groups.google.com/g/golang-nuts/c/0RqzD2jNADE/m/3Hf14DllBAAJ?utm_medium=email_source=footer
Op dinsdag 18 juli 2023 om 09:22:33 UTC+2 schreef Jakob Borg:

> On 17 Jul 2023, at 14:50, Leonard Mittmann  wrote:
>
>
> Yes, but my thought was that it might be possible to do an unsafe 
> conversion as the underlying types are the same. I just have no idea how.
>
>
> https://go.dev/play/p/ViLnLvInv-1
>
> The unsafe conversion appears to work, but it’s unsafe and not obvious to 
> me that this is guaranteed to work. It’s allowed to convert one pointer to 
> another if they have an “equivalent memory layout”, and I would guess that 
> two map types with equivalent underlying types would share memory layout, 
> but I don’t think the specs say anything about map memory layouts one way 
> or the other.
>
> //jb
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/18774f52-1d62-45fb-bdde-6322c0476a23n%40googlegroups.com.


[go-nuts] unsafe.Pointer conversions

2023-07-26 Thread Nigel van Keulen
Since unsafe.Pointer can convert between types that have the same 
underlying type, can unsafe.Pointer also convert between function types 
who's arguments & return values have the same underlying type?

The code I would like to use this technique on:
```
type JSExtFunc func(this Value, args Args) interface{} 

func (f JSExtFunc) MarshalJS() js.Func { 
// I am not sure if this is correct. 
var function = *(*func(this js.Value, args []js.Value) interface
{})(unsafe.Pointer()) 
return js.FuncOf(function)
 } 
// Arguments for wrapped functions. 
type Args []js.Value 
type Value js.Value
```

I have tried this out in the go playground, and it does seem to work.
https://go.dev/play/p/XVwRatkuTQv

However, this is undocumented in the language specification. 
How likely is this that this code would break, using the same version of Go?
Is this perhaps something to be added in the language specification?

Maybe even a more interesting question, breaking all safety guards, could 
this be extended by casting a function which takes a uint64 (`func 
myFunc(uint64)`) to a function which takes two uint32's? (`*(*func(uint32, 
uint32)(unsafe.Pointer(ptrToMyFuncValue)))`)

The latter is something I do not nescessarily desire an answer to, but it 
does make me curious.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2975445d-69ff-46fe-bc44-3cc4bb515fa8n%40googlegroups.com.


Re: [go-nuts] Re: [windows] c:= exec.CommandContext(ctx, ...) + c.Output() don't return when process is killed upon context expiration until child termination

2023-07-26 Thread 'Bryan C. Mills' via golang-nuts
On Friday, February 4, 2022 at 6:23:45 PM UTC-5 Pablo Caballero wrote:

Hi Ian! Thank you so much for sharing that link with me. It was very 
enriching to read it.

As I commented in my first message, the fact that the problem did not occur 
on Mac got me a bit confused at first.


macOS does not have a `cmd.exe` or `notepad.exe`. What were the actual 
steps you took to check the behavior there?
(My guess is that you were testing against a child program that does not 
hold stderr or stdout open.)

Either way, the solutions are to either use explicit pipes for I/O (and 
close them or stop reading them when you are confident the output is done), 
or (as of Go 1.20) set a nonzero WaitDelay on the exec.Cmd.


On Friday, February 4, 2022 at 5:42:00 PM UTC-3 Ian Lance Taylor wrote:

On Fri, Feb 4, 2022 at 12:30 PM Pablo Caballero  wrote: 
> 
> Errata 
> 
> Go is blocked trying to read from the channel (exec\exec.go): 
> 
> for range c.goroutine { if err := <-c.errch; err != nil && copyError == 
nil { copyError = err } } 
> 
> I think that the problem happens if you specify an io.Writer as 
cmd.Stdout and such writer doesn’t satisfy os.File (Output() uses a 
bytes.Buffer internally) because in that case a Pipe is used (to copy data 
between the writer/process). It seems like the pipe is inherited by the 
child process and isn’t closed until the child finish (blocking the 
goroutine that reads from the pipe and writes to the writer even if the 
parent process is gone). 

For reference, this class of problems is https://go.dev/issue/23019. 

Ian 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/06f5a80a-de84-4456-a834-bccf73e5cf5bn%40googlegroups.com.


Re: [go-nuts] [go test] pure Test Classes.

2023-07-26 Thread Jan Mercl
On Wed, Jul 26, 2023 at 9:44 AM sumith s  wrote:

> Currently, we do not have pure Test Classes defined by us. We are using 
> Golang specific Test Class structure. Each FILENAME_test.go will have its own 
> test class under "Golang Test".
> I'm trying to define a  pure Test Classes. how can do that?

(Go does not have classes. Go has types and types may have methods attached.)

Anyway, please explain what you mean by "pure" in "pure Test Classes".

The go tool, when invoked like "go test" looks for functions in files
matching '.*_test.go', with name matching 'Test.*' and the signature
func(t *testing.T), "testing" being the stdlib package. Such functions
will be then executed automatically during the test.

It is of course possible to write any other kind of tests and invoke
them independently of the "go test" facility, using any preferred
method of doing so.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-W4PGv00tUGs7SjmDrxecDdJJDNMwhCkdFbFWO5EYNzzA%40mail.gmail.com.


[go-nuts] [go test] pure Test Classes.

2023-07-26 Thread sumith s
Currently, we do not have pure Test Classes defined by us. We are using 
Golang specific Test Class structure. Each FILENAME_test.go will have its 
own test class under "Golang Test".
I'm trying to define a  pure Test Classes. how can do 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8f79241f-3d01-49d8-b44e-7ce7ec1e0c12n%40googlegroups.com.


Re: [go-nuts] go package dating back to 2009

2023-07-26 Thread 'Jim Idle' via golang-nuts
Decred is a project that was originally put together by someone who never
claimed the moniker used by the originator.  I suggest that 'Bravo Moua' is
trying to claim authorship.  HOwever, it is clear that I am Spartacus.

https://thedecreddigest.wordpress.com/2017/06/10/decred-where-did-it-all-begin/

On Wed, Jul 26, 2023 at 2:49 PM Rob Pike  wrote:

> I am delighted to learn that I, the original author of Go's fmt and bytes
> packages, am actually Satoshi Nakamoto. I always wondered who he was.
> Thanks for clearing that up.
>
> All kidding aside, I do not understand what you are trying to achieve by
> claiming authorship of this code. Or even if that's what you are doing. As
> Ian said, there was no public Go code in early 2009, and the private,
> internal code that became the public release was all written by a handful
> of Google engineers, your name (or Satoshi's) not among them.
>
> -rob
>
>
> On Wed, Jul 26, 2023 at 3:07 PM Jan Mercl <0xj...@gmail.com> wrote:
>
>> On Wed, Jul 26, 2023 at 12:32 AM Bravo Moua  wrote:
>>
>> > For a fact, bytes, fmt, and packages in those category are from Satoshi
>> Nakamoto and myself.
>>
>> Extraordinary claims require extraordinary evidence.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/CAA40n-Xna5Zg-RRygLRquchVC4Z3945kjpE-Z69YBbskB-z0wg%40mail.gmail.com
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAOXNBZSKRRNZ2LJLmOP617%3Dtfi9tm4SD%2BOopp5s0V3cKKk-Xsw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGPPfg-sDQSNa6MRQctnJq0ObdqWdC3SXwMkaOJtkqUawM-NsQ%40mail.gmail.com.


Re: [go-nuts] go package dating back to 2009

2023-07-26 Thread Rob Pike
I am delighted to learn that I, the original author of Go's fmt and bytes
packages, am actually Satoshi Nakamoto. I always wondered who he was.
Thanks for clearing that up.

All kidding aside, I do not understand what you are trying to achieve by
claiming authorship of this code. Or even if that's what you are doing. As
Ian said, there was no public Go code in early 2009, and the private,
internal code that became the public release was all written by a handful
of Google engineers, your name (or Satoshi's) not among them.

-rob


On Wed, Jul 26, 2023 at 3:07 PM Jan Mercl <0xj...@gmail.com> wrote:

> On Wed, Jul 26, 2023 at 12:32 AM Bravo Moua  wrote:
>
> > For a fact, bytes, fmt, and packages in those category are from Satoshi
> Nakamoto and myself.
>
> Extraordinary claims require extraordinary evidence.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAA40n-Xna5Zg-RRygLRquchVC4Z3945kjpE-Z69YBbskB-z0wg%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOXNBZSKRRNZ2LJLmOP617%3Dtfi9tm4SD%2BOopp5s0V3cKKk-Xsw%40mail.gmail.com.