Re: [go-nuts] Execute so exported function in Go

2025-05-15 Thread Bruno Albuquerque
You can not directly call a C function pointer from Go. You will need a CGO wrapper that calls it and them you call that wrapper from Go. -Bruno On Thu, May 15, 2025, 5:20 AM rudeus greyrat wrote: > Hello, > > Thanks for your answer. > > Three points to note: > >- I never asked how to crea

Re: [go-nuts] stamped lock in Go?

2025-01-31 Thread Bruno Albuquerque
texes. > > On Jan 31, 2025, at 11:13 AM, Bruno Albuquerque wrote: > > I did not look at the java code (I went for the description on the link > you posted). > > The idea in TryOptimisticRead() is that the TryLock() helps avoiding > reordering/cache effects. Consider this: >

Re: [go-nuts] stamped lock in Go?

2025-01-31 Thread Bruno Albuquerque
tamp := atomic.LoadUint64(&sl.stamp) > if sl.mu.TryLock() { > sl.mu.Unlock() > return stamp > } > return stamp > } > > // Java - state is a “volatile” integer > > public long tryOptimisticRead() { > long s; > return (((s = state) & WBIT) == 0L

Re: [go-nuts] stamped lock in Go?

2025-01-31 Thread Bruno Albuquerque
I wonder if the TryLock() call in the TryOptimisticRead() (used here as an acquire barrier/half fence) is making the race detector happy enough. -Bruno On Fri, Jan 31, 2025 at 11:51 AM Bruno Albuquerque wrote: > Ops. There was a bug due to left over of me testing. Here is a fixed > v

Re: [go-nuts] stamped lock in Go?

2025-01-31 Thread Bruno Albuquerque
Ops. There was a bug due to left over of me testing. Here is a fixed version: https://go.dev/play/p/UuIWVlV0UTN Also, don't try to run in the playground as this runs forever (it could be changed but I am lazy). -Bruno On Fri, Jan 31, 2025 at 11:31 AM Bruno Albuquerque wrote: > Thi

Re: [go-nuts] stamped lock in Go?

2025-01-31 Thread Bruno Albuquerque
This seemed expected to me but I went ahead and created a Go implementation (which might not be 100% correct so take it for what it will) and I was surprised that the race detector did not really complain about anything. https://go.dev/play/p/R1alMCc-xN9 -Bruno On Fri, Jan 31, 2025, 6:13 AM Rob

Re: [go-nuts] Re: help with thread limit

2024-02-01 Thread Bruno Albuquerque
In Go, you can not really limit the maximum number of threads that will be created. The runtime itself will create threads whenever needed for things like blocking CGO calls, garbage collection, network polling, etc. As I understand it, GOMAXPROCS only limits the number of threads that would be spa

Re: [go-nuts] Re: Windows Go programs not running under Wine anymore.

2023-12-17 Thread Bruno Albuquerque
Apparently wine 9.0 rc2 includes bcryptprimitives.dll now (I tested on it and it did work). So I guess it sorted itself. -Bruno On Sun, Dec 17, 2023 at 2:31 PM Juliusz Chroboczek wrote: > > Apparently the change below broke Windows apps when running under Wine as > > it made bcryptprimitives.d

[go-nuts] Windows Go programs not running under Wine anymore.

2023-12-14 Thread Bruno Albuquerque
I know this is not a common thing so here goes nothing. Apparently the change below broke Windows apps when running under Wine as it made bcryptprimitives.dll a hard requirement now and this dll is not bundled with Wine. This is true even for programs that do not use it all (like a simple "hello w

Re: [go-nuts] gomobile/gobind failing to build a library with interface argument

2023-11-28 Thread Bruno Albuquerque
The way around that is to usually wrap the API you want to use and only expose what you actually need. When you need something with some type of unsupported parameter or return type, write some code around it to convert to sensible supported types. Here is an example of what I end up doing instead

Re: [go-nuts] On the arm64 architecture m1, go1.21.4.darwin-amd64.pkg can be successfully installed, and it seems to run normally.

2023-11-20 Thread Bruno Albuquerque
If you are running the amd64 Go version on a Apple silicon Mac, it is. That is exactly what Rosetta 2 makes possible. It works for Go and also for most AMD64 binaries out there. On Mon, Nov 20, 2023, 8:42 AM fliter wrote: > Thanks. It does seem to be related to Rosetta > > 在2023年11月20日星期一 UTC+8

Re: [go-nuts] On the arm64 architecture m1, go1.21.4.darwin-amd64.pkg can be successfully installed, and it seems to run normally.

2023-11-20 Thread Bruno Albuquerque
This is Rosetta 2. It is not Go, it is MacOS. -Bruno On Mon, Nov 20, 2023, 6:51 AM fliter wrote: > On the arm64 architecture m1, go1.21.4.darwin-amd64.pkg can be > successfully installed, and it seems to run normallyI am very shocked. > > Is this because of any adaptations made by Go? Going

Re: [go-nuts] Re: Recommended way to distribute pre-compiled C-dependencies for modules using CGO ?

2023-10-16 Thread Bruno Albuquerque
I guess you switched things here. Shared libraries (.so) need to be available at engine. Static libraries (.a) are bagged into the binary. -Bruno On Sun, Oct 15, 2023, 3:55 PM Jan wrote: > Thanks Tamas, this is useful information. > > One of my libraries is using a `.a` library -- as opposed t

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-09 Thread Bruno Albuquerque
Now including the list and hopefully with less typos. :) append returns a new slice. Appending to nil just means that you are guaranteed that the returned slice will be allocated inside the append function. The same happens if you try to append to a slice that does not have enough capacity to hold

[go-nuts] Re: Weird error when trying to fetch a module.

2023-09-15 Thread Bruno Albuquerque
and flatgeobuf currently does not? While we are at it, I can not find the go.mod for flatbuffers! It is not in the root of the repository and also not inside the go subdir where the code resides. Is there some special casing for this project in place? -Bruno On Thu, Sep 14, 2023 at 5:58 PM Bruno

Re: [go-nuts] Re: Weird error when trying to fetch a module.

2023-09-15 Thread Bruno Albuquerque
Ok, this is promising. Thanks for testing it. -Bruno On Fri, Sep 15, 2023 at 4:58 AM Jan Mercl <0xj...@gmail.com> wrote: > On Fri, Sep 15, 2023 at 10:31 AM 'Jim Idle' via golang-nuts < > golang-nuts@googlegroups.com> wrote: > > > The go.mod at the root was one thing that might work, but it will

Re: [go-nuts] Re: Weird error when trying to fetch a module.

2023-09-15 Thread Bruno Albuquerque
d works `github.com/flatgeobuf/flatgeobuf/src/go@master` >> <http://github.com/flatgeobuf/flatgeobuf/src/go@master>. >> I wonder if `@master` is needed because the repo has no packages >> published? >> There's more info about pseudo-versions here >> <https:

Re: [go-nuts] Re: Weird error when trying to fetch a module.

2023-09-15 Thread Bruno Albuquerque
That might be doable. I will discuss this with the maintainers. Thanks for the suggestion. It is still a shame that workarounds like this need to exist. -Bruno On Fri, Sep 15, 2023 at 3:15 AM Brian Candler wrote: > > Keep your go source at the root of the repo and tag that > > Or would it be

Re: [go-nuts] Re: Weird error when trying to fetch a module.

2023-09-15 Thread Bruno Albuquerque
repo has no packages published? > There's more info about pseudo-versions here > <https://go.dev/ref/mod#pseudo-versions> > > -Lenny- > > On Thursday, September 14, 2023 at 5:59:39 PM UTC-4 Bruno Albuquerque > wrote: > >> It is likely that I am doing something

[go-nuts] Weird error when trying to fetch a module.

2023-09-14 Thread Bruno Albuquerque
It is likely that I am doing something stupid but as I am out of ideas, here goes nothing. I pushed an initial Go flatgeobuf implementation here: github.com/flatgeobuf/flatgeobuf/src/go This directory in the repository has a go.mod file with the following contents: module github.com/flatgeobuf/

Re: [go-nuts] getting the size of an io.ReaderAt?

2023-03-31 Thread Bruno Albuquerque
Not a direct answer to your question (your code looks like a reasonable implementation modulo any bugs I did not notice) but: Aren't you over engineering things? If the source is a PDF file, why not also pass the size to the function instead of doing all this work to get it? At some point you have

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Bruno Albuquerque
I wonder if what is needed here is just null-terminated strings. -Bruno On Mon, Mar 13, 2023 at 1:28 PM Kurtis Rader wrote: > On Mon, Mar 13, 2023 at 9:41 AM Van Fury wrote: > >> Relating to my previous question, I have been reading but it is still not >> clear to me what raw binary is, how i

Re: [go-nuts] cannot register generic function with template.Funcs

2023-03-06 Thread Bruno Albuquerque
You can easily get it to work, but not in a useful way I guess. https://go.dev/play/p/mq0O8OhJ1-a You could have a different template for each type you use I guess. -Bruno On Mon, Mar 6, 2023 at 4:43 PM Rory Campbell-Lange wrote: > Hi. I have a generic function > > func slicerG[A any](s []A,

Re: [go-nuts] HTTP client - streaming POST body?

2023-03-06 Thread Bruno Albuquerque
The body is just an io.Reader. You just need to write one that materializes and streams the data you want instead of using a buffer with all of it. The entire design is to allow things like what you want to do. :) -Bruno On Mon, Mar 6, 2023 at 10:08 AM 'Jim Smart' via golang-nuts < golang-nuts@g

Re: [go-nuts] Chromebook golang environment?

2022-12-12 Thread Bruno Albuquerque
If you just mean being able to write Go programs in a Chromebook, most recent ones have Linux support so you can just use that. On Mon, Dec 12, 2022 at 2:59 AM Ken wrote: > > Hi, does a golang dev environment exist for Chromebook computers? > > Sent from my iPhone > > -- > You received this messa

Re: [go-nuts] Generic interface compiles with incorrectly instantiated types

2022-06-21 Thread Bruno Albuquerque
One reason is that then your type can have a method like "Convert() T" where the actual type is not relevant (i.e. you do not need to actually have a generic type associated with it) but you can have a function that returns a specific type anyway. As methods can not have extra type parameters, this

Re: [go-nuts] Nil could be the zero value for type variables

2022-05-30 Thread Bruno Albuquerque
This should work on your example: var zeroValue V On Mon, May 30, 2022, 6:39 PM Will Faught wrote: > Hello, fellow Gophers! > > Currently, if I understand correctly, there's no expression for the zero > value for a type variable: > > type Map[K comparable, V any] struct { > ks []K > vs

Re: [go-nuts] Re: golang-announce is blocked in Google Groups?

2022-01-21 Thread Bruno Albuquerque
FWIIW, the same happens here. When creating a filter (assuming one is using GMail) you can tell it to never send emails that match the filter to Spam and that6 is what I ended up doing. On Fri, Jan 21, 2022 at 8:43 AM Peter Aronoff wrote: > On Thu, Jan 20, 2022 at 2:35 PM Ian Lance Taylor wrot

Re: [go-nuts] Two Questions About Maps

2021-12-19 Thread Bruno Albuquerque
https://go.dev/play/p/fglmNnWFUxP I would not worry about using pointers inside the map if the data is really read only. If it is not, you must use pointers, otherwise you can not do something like this: ft["a"].name = "b" As the entries in the map are non-addressable. On Sun, Dec 19, 2021 at

Re: [go-nuts] Can I play with go1.18 beta while keeping my stable 1.17 version around for production code?

2021-12-15 Thread Bruno Albuquerque
Yes, see instructions on how to download/install go1.18beta1. It explicitly suggests a way that will allow this. On Wed, Dec 15, 2021 at 9:03 AM Travis Keep wrote: > This may be silly question, but is there a way for me to download and play > with 1.18 while keeping my existing 1.17 installatio

[go-nuts] Tour of Go seems to be broken.

2021-11-22 Thread Bruno Albuquerque
Not sure if this is the appropriate channel to report it but here it goes. I pointed it to a friend as a means to learn Go and I tried to click the Run button for the Hello World example (https://go.dev/tour/welcome/1) and it is failing: Error communicating with remote server. Program exited. --

Re: [go-nuts] What is the point of gzip Reader.Close?

2021-06-21 Thread Bruno Albuquerque
But it is not "because we said so". There were actual replies that pointed to specific issues that, in my opinion, were reason enough. To create a specific test case that would break (assuming there is not such a test in the standard library already. Worth checking) it would take some time for some

Re: [go-nuts] What is the point of gzip Reader.Close?

2021-06-21 Thread Bruno Albuquerque
Dan just pointed out that the Close() method for the gzip reader actually does other things. If you are ok with not detecting a possible error with deferred reporting through the Close() method then, yes, you are ok. I see no good reason why you would though. On Mon, Jun 21, 2021 at 3:30 PM Steve

Re: [go-nuts] What is the point of gzip Reader.Close?

2021-06-21 Thread Bruno Albuquerque
Not to mention this all is an implementation detail and even if it did nothing today, relying on this behavior would be a recipe so see cobe breaking in the future. In this sense, the advice "if there is a Close() method, call it when you are done with it" is a very good one. On Mon, Jun 21, 2021

Re: [go-nuts] No generic, part -2

2021-03-13 Thread Bruno Albuquerque
FWIIW, I also agree that "ignore" makes no sense here. You might listen and think about several opinions/options and conclude that one of them is the best one. This does not mean you ignored all the others. On Sat, Mar 13, 2021 at 7:06 AM 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.c

[go-nuts] [generics] Do we really need explicit type lists in constraints?

2020-06-18 Thread Bruno Albuquerque
It looks to me one point of contention on using interfaces instead of contracts is the fact that now interfaces have to support type lists but only when used as contracts. This, no matter how you slice it, looks ugly. Now type lists are there to support built-in operations like operators in genera

Re: [go-nuts] Trying to port Go to HPE NonStop x86 - Need some guidance

2020-05-13 Thread Bruno Albuquerque
Now you create your branch or whatever of the Go code and start porting it to your platform. As a first step, you will probably want to add the new nsx GOOS. Then you use your go1.14.2 installation to compile it (with bootstarp.sh) setting GOOS=nsx for cross compiling. Something like this: GOOS=ns

Re: [go-nuts] Converting a C char[] to []byte of string with cgo

2020-04-30 Thread Bruno Albuquerque
C.GoString((*C.char)(&p.mach_name)) On Thu, Apr 30, 2020 at 1:21 PM Dean Schulze wrote: > This expression > > C.GoString(C.char*(&p.mach_name)) > > gives this error: > > type _Ctype_char is not an expression > > On Thu, Apr 30, 2020 at 2:09 PM Bruno

Re: [go-nuts] Converting a C char[] to []byte of string with cgo

2020-04-30 Thread Bruno Albuquerque
Not pretty but if you are sure the array is zero-terminated, you can simply cast it to the correct type: C.GoString((C.char*)(&p.hostname)) (untested) On Thu, Apr 30, 2020 at 1:06 PM Dean Schulze wrote: > That gives this error (which I've gotten with just about everything I try): > > cannot u

Re: [go-nuts] Bound checks elimination hint.

2020-02-22 Thread Bruno Albuquerque
, Feb 22, 2020 at 3:36 AM Nigel Tao wrote: > On 2/22/20, Bruno Albuquerque wrote: > > https://play.golang.org/p/Y7ICg7t4_nd > > > > ... > > > > Unfortunately, I could not find an incantation that would remove the > bound > > checks. > > The code fr

Re: [go-nuts] Bound checks elimination hint.

2020-02-22 Thread Bruno Albuquerque
Ah. Now it makes more sense. I completely abstracted away overflows (again, not a scenario that would happen in practice in any case). On Sat, Feb 22, 2020 at 3:54 AM Nigel Tao wrote: > On 2/22/20, Bruno Albuquerque wrote: > > https://play.golang.org/p/P2JPI42YJa8 > > > &g

Re: [go-nuts] Bound checks elimination hint.

2020-02-21 Thread Bruno Albuquerque
slice length. Either that or I am missing something On Fri, Feb 21, 2020 at 10:24 AM Bruno Albuquerque wrote: > This is interesting. If I simplify the loop to something like this: > > nrgbaData := make([]byte, len(rgbData)+(len(rgbData)/3)) > > _ = nrgbaData[len(rgbData)] &g

Re: [go-nuts] Bound checks elimination hint.

2020-02-21 Thread Bruno Albuquerque
inated. Considering it is still guaranteed that "i" inside the loop will never be equal to or greater than len(rgbData), I do not understand why the bounds check is now required. Any ideas? On Fri, Feb 21, 2020 at 10:07 AM Bruno Albuquerque wrote: > Nope. Bound checks are still there. I

Re: [go-nuts] Bound checks elimination hint.

2020-02-21 Thread Bruno Albuquerque
Nope. Bound checks are still there. I am puzzled by this one. On Fri, Feb 21, 2020 at 9:34 AM Sebastien Binet wrote: > > > On Fri, Feb 21, 2020 at 5:36 PM Bruno Albuquerque wrote: > >> I wrote some simple code to convert a RGB24 image represented as a []byte >> to

[go-nuts] Bound checks elimination hint.

2020-02-21 Thread Bruno Albuquerque
I wrote some simple code to convert a RGB24 image represented as a []byte to a NRGBA image (also as a []byte), like so: https://play.golang.org/p/Y7ICg7t4_nd Unfortunately, the performance is lacking here and I am trying to improve it. The first low hanging fruit seems to be taking advantage of B

Re: [go-nuts] annoing: runtime error: cgo argument has Go pointer to Go pointer

2020-01-29 Thread Bruno Albuquerque
One way to work this around is to use https://github.com/mattn/go-pointer. On Wed, Jan 29, 2020 at 2:12 PM wrote: > Hi, > > I try to use a *C* library with *GO* and have a small problem passing a > *GO* pointer through *C* into a *GO* callback. > If I set: "*export GODEBUG=cgocheck=0*" everythin

[go-nuts] Can individual struct attributes be garbage collected?

2020-01-23 Thread Bruno Albuquerque
Considering something like this: https://play.golang.org/p/VKUq1oDvL_I Is it conceivable that t.unused will be garbage collected even if t might still be around? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and

Re: [go-nuts] Re: net.conn TCP connection

2019-12-30 Thread Bruno Albuquerque
Linux anyway). On Mon, Dec 30, 2019 at 12:23 PM Robert Engels wrote: > That option requires proprietary protocols not standard tcp/udp. > > On Dec 30, 2019, at 12:04 PM, Bruno Albuquerque wrote: > >  > But, to complicate things, you can create what is basically a TCp > c

Re: [go-nuts] Re: net.conn TCP connection

2019-12-30 Thread Bruno Albuquerque
But, to complicate things, you can create what is basically a TCp connection with packet boundaries using SOCK_SEQPACKET (as opposed to SOCK_STREAM or SOCK_DGRAM). On Mon, Dec 30, 2019 at 9:04 AM Jake Montgomery wrote: > It sounds like maybe you have some misconceptions about TCP. It is a > stre

Re: [go-nuts] Simple worker pool in golnag

2019-12-27 Thread Bruno Albuquerque
This might be useful too you, in any case: https://git.bug-br.org.br/bga/workerpool On Thu, Dec 26, 2019 at 8:12 PM Amarjeet Anand wrote: > Hi > > I have to produce some task to kafka parallely. So I want to implement a > simple worker group pattern in go. > > Does the below code decent enough

[go-nuts] Appending static libraries to cgo LDFLAGS.

2019-12-18 Thread Bruno Albuquerque
I am trying to get a version of GoCV that works with OpenCV static libraries. The final issue I have is that pkg-config is not really listing all required libraries so i need to append some extra ones. Here is how my cgo configuration looks like without the extra libraries: #cgo !windows pkg-confi

Re: [go-nuts] tricks for installing go a single time on Windows 10 with Bash for Windows

2019-12-05 Thread Bruno Albuquerque
Can you clarify what exactly your problem is? I am asking because the only configuration that should be needed for go is to make sure it is in your system path (which mishandled by the installer). There is nothing else that you *MUST* configure for it to work. What is the actual problem you are ha

[go-nuts] Go modules and project-local imports.

2019-12-03 Thread Bruno Albuquerque
When working with Go modules, what is the idiomatic way to deal with project-local imports (i.e. directories that are not supposed to be checked out separately from everything else. A simple example would be something like this: project/ library.go example/ example.go Here, projec

Re: [go-nuts] Generics Draft: Mixing types and methods.

2019-08-02 Thread Bruno Albuquerque
Taylor wrote: > On Fri, Aug 2, 2019 at 1:12 PM Bruno Albuquerque wrote: > > > > I was thinking about a way to "extend" usual operations (say, equality > checks) to types that can not be compared the usual way (they are not > "comparable" in the contract se

[go-nuts] Generics Draft: Mixing types and methods.

2019-08-02 Thread Bruno Albuquerque
I was thinking about a way to "extend" usual operations (say, equality checks) to types that can not be compared the usual way (they are not "comparable" in the contract sense) and came up with something like this: // Just to use for type assertion later. type Equaler interface { Equal(Equaler)

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread Bruno Albuquerque
This is what my solution does, except that it uses items associated with priorities instead of 2 channels. if 2 channels are really needed for some reason, it is easy to adapt the solution to this. On Fri, May 24, 2019 at 12:12 PM Daniela Petruzalek < daniela.petruza...@gmail.com> wrote: > If I

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread Bruno Albuquerque
On Fri, May 24, 2019 at 1:50 AM roger peppe wrote: > On Thu, 23 May 2019 at 19:28, Bruno Albuquerque wrote: > >> This was my attempt at a channel with priorities: >> >> >> https://git.bug-br.org.br/bga/channels/src/master/priority/channel_adapter.go >> >&g

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread Bruno Albuquerque
On Fri, May 24, 2019 at 8:40 AM roger peppe wrote: > On Fri, 24 May 2019 at 16:25, Bruno Albuquerque wrote: > >> On Fri, May 24, 2019 at 1:50 AM roger peppe wrote: >> >>> On Thu, 23 May 2019 at 19:28, Bruno Albuquerque wrote: >>> >>>>

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-23 Thread Bruno Albuquerque
This was my attempt at a channel with priorities: https://git.bug-br.org.br/bga/channels/src/master/priority/channel_adapter.go Based on the assumption that priorities only make sense if items are queued. If they are pulled out from a channel as fast as they are added to it, then there is no need

Re: [go-nuts] Trivial(?) Go v2 proposal: Named goroutines and/or named nested funcs

2018-11-25 Thread Bruno Albuquerque
Terra os a FAQ Abbott this, if I understand what you want correctly: https://golang.org/doc/faq#no_goroutine_id On Sun, Nov 25, 2018, 4:04 PM Russtopia That still doesn't address what I'm getting at -- it doesn't give a > semantically meaningful name to the goroutines, in stack traces, source > c

Re: [go-nuts] Trivial(?) Go v2 proposal: Named goroutines and/or named nested funcs

2018-11-25 Thread Bruno Albuquerque
Sorry, auto correct. I meant to say there is a FAQ about this. On Sun, Nov 25, 2018, 4:16 PM Bruno Albuquerque Terra os a FAQ Abbott this, if I understand what you want correctly: > https://golang.org/doc/faq#no_goroutine_id > > On Sun, Nov 25, 2018, 4:04 PM Russtopia >> Tha

Re: [go-nuts] struct type assertion

2018-11-01 Thread Bruno Albuquerque
item.(record) (in the specific case). On Thu, Nov 1, 2018 at 3:59 PM Alex Dvoretskiy wrote: > Is it possible to implement type assertion from interface to struct?: > > https://play.golang.org/p/xK4mlF32_NR > > -- > You received this message because you are subscribed to the Google Groups > "gol

Re: [go-nuts] Heap of structs

2018-11-01 Thread Bruno Albuquerque
You just need to implement the required methods (Len, Less, Swap) for your type (str is a terrible name, BTW. First time I saw it I though of string, not struct). On Thu, Nov 1, 2018 at 11:57 AM Alex Dvoretskiy wrote: > How can I rewrite this code to use a heap of structs instead of a heap of >

Re: [go-nuts] An issue with the select statement.

2018-05-04 Thread Bruno Albuquerque
Here is an example that came up in the list that might help you: https://play.golang.org/p/I8MS0DFgZ2 That being said, It looks like you are over engineering. If I really understand what you want to accomplish, wouldn't this help? https://github.com/brunoga/workerpool You can call Stop()/Start()

Re: [go-nuts] context.Context and worker pools

2018-02-16 Thread Bruno Albuquerque
I did something like this here: https://github.com/brunoga/workerpool I do not store the context anywhere, I pass it to my Start() method and it passes it down to any place I need it. On Fri, Feb 16, 2018 at 1:05 PM andrey mirtchovski wrote: > While trying to retrofit context.Context within a

Re: [go-nuts] How to bufio.Write with a length specified?

2018-01-18 Thread Bruno Albuquerque
Actually, it is even possible that not even a new slice header is created in this case, but I did not check. On Thu, Jan 18, 2018 at 3:56 PM Bruno Albuquerque wrote: > It creates a new slice header, but the backing array is not copied. > > On Thu, Jan 18, 2018 at 3:35 PM Peng

Re: [go-nuts] How to bufio.Write with a length specified?

2018-01-18 Thread Bruno Albuquerque
It creates a new slice header, but the backing array is not copied. On Thu, Jan 18, 2018 at 3:35 PM Peng Yu wrote: > Dan & Bruno, > > I didn't realize that it is as simple as that :) Thanks. > > Does it involve any extra copy of the byte slice? Or f.Write literally > access the memory of d and o

Re: [go-nuts] How to bufio.Write with a length specified?

2018-01-18 Thread Bruno Albuquerque
n, err := f.Write(d[:length]) ? Where length is the amount of data you want to write. On Thu, Jan 18, 2018 at 3:04 PM Peng Yu wrote: > Hi, > > The following example shows how to write a byte slice to a buffer. But > what if I want only write a length shorter (say 2 instead of 5) than > the size

Re: [go-nuts] Go Compiler How Work?!

2017-12-13 Thread Bruno Albuquerque
Oh, and the generic compiler frontend: https://go.googlesource.com/go/+/go1.4.2/src/cmd/gc/ On Wed, Dec 13, 2017 at 11:27 AM Bruno Albuquerque wrote: > Go 1.4.2 compiler and linker code for x86-64. > > https://go.googlesource.com/go/+/go1.4.2/src/cmd/6c/ > https://go.googles

Re: [go-nuts] Go Compiler How Work?!

2017-12-13 Thread Bruno Albuquerque
compiler , linker of go1.4.(Based on C) > > https://storage.googleapis.com/golang/go1.4-bootstrap-20170531.tar.gz > > > On Wednesday, December 13, 2017 at 10:39:24 PM UTC+3:30, Bruno Albuquerque > wrote: > >> Here is the entry point for the compiler code: >> >>

Re: [go-nuts] Go Compiler How Work?!

2017-12-13 Thread Bruno Albuquerque
Here is the entry point for the compiler code: https://go.googlesource.com/go/+/master/src/cmd/compile/ And here is the entry point for the linker code: https://go.googlesource.com/go/+/master/src/cmd/link/ Note this is all non-trivial. You do need to know how compilers/linkers work before tryi

Re: [go-nuts] Re: Go Compiler How Work?!

2017-12-13 Thread Bruno Albuquerque
It directly generates a binary suitable for the target platform, yes. Again, you do not need a C compiler to compile a Go program unless you are using CGO. On Wed, Dec 13, 2017 at 8:54 AM Compiler wrote: > please answer this. > > > On Wednesday, December 13, 2017 at 4:30:52 PM UTC+3:30, Compile

Re: [go-nuts] Re: Go Compiler How Work?!

2017-12-12 Thread Bruno Albuquerque
Why do you want to explicitly use an old go version? Why not 1.9.2? You can find pre-compiled packages for various platforms here: https://golang.org/dl/ On Tue, Dec 12, 2017 at 3:22 PM wrote: > im want test main go compiler. > > so should try > https://storage.googleapis.com/golang/go1.4-b

Re: [go-nuts] Re: Go Compiler How Work?!

2017-12-12 Thread Bruno Albuquerque
No the compiler does not generate C code. The compiler compiles Go code to the actual final binary. On Tue, Dec 12, 2017 at 2:28 PM wrote: > so go compiler is made with c. > > so go compiler how work : > -- > so in current golang version , golang generate c code and compile with > c-

Re: [go-nuts] Re: Go Compiler How Work?!

2017-12-12 Thread Bruno Albuquerque
What is expected (assuming the code is correctly written). An executable file is generated and can be run normally. I am sorry but I could not parse your following questions, but I will try some general answers: 1 - No, you do not need a C compiler to compile recent Go versions. You do need an ex

Re: [go-nuts] Re: Go Compiler How Work?!

2017-12-12 Thread Bruno Albuquerque
Go will work fine without a C compiler. Only if you use CGO ( https://blog.golang.org/c-go-cgo) you need one. On Tue, Dec 12, 2017 at 2:51 PM wrote: > so GOLANG will not work, if not install C-Compiler on system. > > yeah? > > > On Wednesday, December 13, 2017 at 2:16:23 AM UTC+3:30, C Banning w

Re: [go-nuts] Re: Go Compiler How Work?!

2017-12-12 Thread Bruno Albuquerque
Most likely not. The current version was compiled with a previous version that was also written in Go. it you continue going down this chain you eventually get to a Go version that was compiled with a C compiler but this is only needed for platforms that do not have a Go version yet (which is also

Re: [go-nuts] Writing your own Context, making sure it's compatible with context.Context

2017-11-08 Thread Bruno Albuquerque
FYI, I just started writing a drop in replacement for Context that supports waiting on child contexts. I literally just submitted de initial code and did not test anything seriously yet, but this can help you find your with some ideas of how to proceed: http://github.com/brunoga/context On Wed, N

Re: [go-nuts] Re: How to know if interface{} data is nil w/o reflecting?

2017-10-31 Thread Bruno Albuquerque
I am not sure what exactly is the issue you are complaining about. You can think of interface as a container for some data type. The container can be nil and the data contained in it can be nil. This looks reasonable to me as much as having a C++ vector that contains nil (well, nullptr) pointers.

Re: [go-nuts] Re: Debugging error: plugin.Open: plugin was built with a different version of package

2017-10-23 Thread Bruno Albuquerque
This is most likely https://github.com/golang/go/issues/21373 It should be fixed in Go 1.9.1. On Sun, Oct 22, 2017 at 11:21 PM Miki Tebeka wrote: > This happened to me as well when using vendored dependencies. Is this your > case? If so move the dependencies to GOPATH > > On Thursday, October

Re: [go-nuts] How to covert simple RPC Call in Python to Go?

2017-10-10 Thread Bruno Albuquerque
Yes, the server is not an http/rpc server so using DialHTTP() does not make much sense. Try with net.DialTCP() and use Write() and Read() on the returned TCPConn to send requests and get the responses. On Tue, Oct 10, 2017 at 11:48 AM Christian LeMoussel wrote: > I'm having trouble translating

Re: [go-nuts] Worker pool library.

2017-07-30 Thread Bruno Albuquerque
o#L202 > > because multiple workers are going to write to the waitError entry in the > worker pool struct upon failure. But there may be other data races about. > > > On Fri, Jul 28, 2017 at 7:27 PM Bruno Albuquerque > wrote: > >> I wrote something up for a personal pro

[go-nuts] Worker pool library.

2017-07-28 Thread Bruno Albuquerque
I wrote something up for a personal project and I thought this might be useful to some of you: https://github.com/brunoga/workerpool This tries to simplify executing the same task of a set of items in parallel. It does all the expected stuff from this kind of library and also accepts a context wh

[go-nuts] Unexpected need to use runtime.KeepAlive().

2017-05-07 Thread Bruno Albuquerque
I have this struct that has an associated method that simply call a C function that might take a long time to use. It is defined more or less like this: import "C" type Indexer struct { cIndexer *C.Indexer } func NewIndexer() *Indexer { i := &Indexer{getCIndexerPointer()} runtime.SetFinali

Re: [go-nuts] Re: Gracefully Shutdown File Server

2017-03-10 Thread Bruno Albuquerque
Forget it. It is in a defer call. I guess I have no idea why it is behaving how it is. On Fri, Mar 10, 2017 at 12:49 PM Bruno Albuquerque wrote: > Wait, you are explicitly calling the context cancel function. As I > understand it that will shutdown the server immediately). > > On

Re: [go-nuts] Re: Gracefully Shutdown File Server

2017-03-10 Thread Bruno Albuquerque
Wait, you are explicitly calling the context cancel function. As I understand it that will shutdown the server immediately). On Fri, Mar 10, 2017 at 12:35 PM Andrew wrote: > go install and run the program, get the same result. > > -- > You received this message because you are subscribed to the

Re: [go-nuts] Re: Gracefully Shutdown File Server

2017-03-10 Thread Bruno Albuquerque
I am not very familiar with the shutdown process yet (I did not try to use it anywhere), but the documentation seems to imply that what you expected to happen is what should happen. So if the download is being interrupted, I guess that is a bug. On Fri, Mar 10, 2017 at 11:33 AM Andrew wrote: >

Re: [go-nuts] Re: Gracefully Shutdown File Server

2017-03-10 Thread Bruno Albuquerque
I am not sure what you were expecting as a result of your example, but it appears to work for me in Ubuntu: $ go run test.go 2017/03/11 03:03:13 Server started at localhost:8080 ^C2017/03/11 03:03:19 Shutting down server... 2017/03/11 03:03:19 Server gracefully stopped On Fri, Mar 10, 2017 at 1

Re: [go-nuts] Re: Gracefully Shutdown File Server

2017-03-10 Thread Bruno Albuquerque
https://golang.org/pkg/net/http/#Server.Shutdown func (*Server) Shutdown func (srv *Server ) Shutdown (ctx context .

[go-nuts] Weird GOPATH issue with go 1.8.

2017-03-04 Thread Bruno Albuquerque
Something appears to be broken: $ echo $GOPATH /home/bga/go-dev $ echo $GOBIN /home/bga/go-dev/bin $ go env GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/bga/go" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCG

Re: [go-nuts] Negative (BC) dates.

2016-09-06 Thread Bruno Albuquerque
#x27;t need to refer to a time and date in a year > billions of years ago? > > //jb > On Tue, 6 Sep 2016 at 18:41, Bruno Albuquerque wrote: > >> I was trying to store BC dates in a database and due to various issues >> with date handling and assumptions about date ran

Re: [go-nuts] interactive debugger for go ??

2016-09-06 Thread Bruno Albuquerque
https://github.com/derekparker/delve Em ter, 6 de set de 2016 às 13:42, JM escreveu: > Will there be a debugger that will allow me to step into my code, watch > the flow, and go line by line in real time, see values set, etc..? does > this already exist and i'm just not aware of it? I'

[go-nuts] Negative (BC) dates.

2016-09-06 Thread Bruno Albuquerque
I was trying to store BC dates in a database and due to various issues with date handling and assumptions about date ranges, I decided to store the date as a int64 number and use time.Unix() to convert it to a time object. This mostly works but I found some weird behavior: https://play.golang.org/

Re: [go-nuts] rune vs (single code-point) string - size and printing

2016-08-22 Thread Bruno Albuquerque
A rune is just an alias for int32. So when you are printing r, you are printing a int32 number. s is a string. So when you print it, you get the expected output ("a"). Em seg, 22 de ago de 2016 às 12:51, JC escreveu: > Dear gophers, > > I'd appreciate some help. > > Given: > > func main() { >

[go-nuts] Shouldn't net/http Client.Do() return EOF when a connection is closed?

2016-08-08 Thread Bruno Albuquerque
I am seeing a weird issue when using Client.Do() to do a request. Here is the scenario: go version go1.7rc5 linux/amd64 The server I am sending the request to, receives it and, for this specific request, closes the connection immediately without sending any replies. To detect this, I wanted to co