Re: [go-nuts] CGO error : cannot use f ( type func(_Ctype_int, **_Ctype_char) _Ctype_int) as *[0]byte value in argument

2023-11-21 Thread Kurtis Rader
I think the error is trying to tell you the C reopen function takes a
pointer to a function and you are passing it a Go func. Try googling "cgo
pass function pointer". That should yield documents like
https://eli.thegreenplace.net/2019/passing-callbacks-and-pointers-to-cgo/
which should point you in the right direction. I have to say, trying to do
something like this after using Go for just one month is very ambitious. I
think you are going to run into lots of problems due to your lack of
experience with Go (not Golang).

On Tue, Nov 21, 2023 at 7:28 PM ulis lee  wrote:

> *Hi, all*
>
> It's been a month since I started Golang.
> But I was in a difficult situation. I need your help.
>
> *C code*
>
> int reopen (const char *fn, time_t check_interval_sec, int
> (*callback_func) (int num_entry, char **entry), int retry);
>
>
> *Go code*
>
> func _Open(fileName string, intervalSec int, f func(C.int, **C.char)
> C.int) int {
>
>cFileName := C.CString(fileName)
>
>defer C.free(unsafe.Pointer(cFileName))
>
>
> ret := C.reopen(cFileName, C.long(intervalSec), f, 1)
>
> return int(ret)
>
> }
>
> error message
> cannot use f (variable of type func(_Ctype_int, **_Ctype_char) _Ctype_int)
> as *[0]byte value in argument to (_Cfunc_reopen)
>
> --
> 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/644e20e4-0734-4fe7-be0e-0b4d101df1fdn%40googlegroups.com
> 
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
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/CABx2%3DD_LoPj%2BkoMy%3DTrt6vA2Y0GxAp4h4ngTKmwZfkenStD7rg%40mail.gmail.com.


[go-nuts] Re: CGO error : cannot use f ( type func(_Ctype_int, **_Ctype_char) _Ctype_int) as *[0]byte value in argument

2023-11-21 Thread Tzu-Yu Lee
Hi,

You cannot pass f, which is a Go function, in a CGo call directly because 
of the pointer passing rules. You need to create some wrappers, and I have 
found this article 
(https://eli.thegreenplace.net/2019/passing-callbacks-and-pointers-to-cgo) 
very helpful. 

That being said, I have a feeling that if you provide some more details 
about what you are trying to achieve, people here might be able to help you 
get a simpler solution in Go.

Tzu-Yu
ulis lee 在 2023年11月22日 星期三上午11:28:20 [UTC+8] 的信中寫道:

> *Hi, all*
>
> It's been a month since I started Golang.
> But I was in a difficult situation. I need your help.
>
> *C code*
>
> int reopen (const char *fn, time_t check_interval_sec, int 
> (*callback_func) (int num_entry, char **entry), int retry);
>
>
> *Go code*
>
> func _Open(fileName string, intervalSec int, f func(C.int, **C.char) 
> C.int) int {
>
>cFileName := C.CString(fileName)
>
>defer C.free(unsafe.Pointer(cFileName))
>
>
> ret := C.reopen(cFileName, C.long(intervalSec), f, 1)
>
> return int(ret)
>
> }
>
> error message 
> cannot use f (variable of type func(_Ctype_int, **_Ctype_char) _Ctype_int) 
> as *[0]byte value in argument to (_Cfunc_reopen)
>

-- 
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/2b58349f-4d8f-44c9-805b-f7b52f92bbedn%40googlegroups.com.


[go-nuts] CGO error : cannot use f ( type func(_Ctype_int, **_Ctype_char) _Ctype_int) as *[0]byte value in argument

2023-11-21 Thread ulis lee


*Hi, all*

It's been a month since I started Golang.
But I was in a difficult situation. I need your help.

*C code*

int reopen (const char *fn, time_t check_interval_sec, int (*callback_func) 
(int num_entry, char **entry), int retry);


*Go code*

func _Open(fileName string, intervalSec int, f func(C.int, **C.char) C.int) 
int {

   cFileName := C.CString(fileName)

   defer C.free(unsafe.Pointer(cFileName))


ret := C.reopen(cFileName, C.long(intervalSec), f, 1)

return int(ret)

}

error message 
cannot use f (variable of type func(_Ctype_int, **_Ctype_char) _Ctype_int) 
as *[0]byte value in argument to (_Cfunc_reopen)

-- 
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/644e20e4-0734-4fe7-be0e-0b4d101df1fdn%40googlegroups.com.


[go-nuts] CGo error : Cannot use f (type func func(_Ctype_int, **_Ctype_char) _Ctype_int) as *[0]byte value in argument

2023-11-21 Thread ulis lee
Hi all,

*C code*
int reopen (const char *fn, time_t check_interval_sec, int (*callback_func) 
(int num_entry, char **entry), int retry);

*Go code*

func _Open(fileName string, intervalSec int, f func(C.int, **C.char) C.int) 
int {

cFileName := C.CString(fileName)

defer C.free(unsafe.Pointer(cFileName))

ret := C.reopen(cFileName, C.long(intervalSec), f, 1)

 return int(ret)

}

-- 
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/909103a6-c8c0-48bd-8a7d-69ab4aa60ec3n%40googlegroups.com.


Re: [go-nuts] Re: Measuring the total time of serving a request

2023-11-21 Thread Ulrich Kunitz
You are right Flush needs to write the header first, so the additional
header lines cannot be added by the server after Flush. The automatic
Content-Type might also not be written. A local proxy in front of your
server might be a simpler approach to measure full performance.

If the actual processing time of the request is not sufficient for you, you
might want to use a proxy in front of the server to measure performance.

Am Di., 21. Nov. 2023 um 12:28 Uhr schrieb Mitar :

> Hi!
>
> On Mon, Nov 20, 2023 at 10:51 PM Uli Kunitz  wrote:
> > You could convert the original ResponseWriter to a ResponseController
> and call Flush in your middleware before you measure the duration.
> Alternatively you can try to convert ResponseWriter to a http.Flusher and
> call Flush if the conversion is successful.
>
> Yes, I was thinking something along those lines. But are there any
> side effects by calling Flush after the main handler returns? Like in
> Write documentation it says:
>
> "if the total size of all written data is under a few KB and there are
> no Flush calls, the Content-Length header is added automatically."
>
> "Once the headers have been flushed (...), the request body may be
> unavailable."
>
> My understanding is that after the main handler returns, none of this
> matters anymore. But are there any other similar side effects?
>
>
> Mitar
>
> --
> https://mitar.tnode.com/
> https://twitter.com/mitar_m
> https://noc.social/@mitar
>

-- 
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/CAPibus4%2BH3hKmnA8n-yLJLKYTL%3DJX6oricOSMitayE%2BCpwHGUg%40mail.gmail.com.


[go-nuts] Re: Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread 'Mark' via golang-nuts
My reply was to Salih but somehow my reply ended up appearing first.

According to the purego docs you don't need a compiler, essentially it 
provides a means of opening a dll/so and registering and calling functions 
within the dll/so.

On Tuesday, November 21, 2023 at 12:58:20 PM UTC Tamás Gulácsi wrote:

> Which is what?
> Please share with the golang-nuts list if you've found a solution!
>
> Mark a következőt írta (2023. november 21., kedd, 11:54:11 UTC+1):
>
>> Thank you, that looks just like what I want.
>>
>> On Tuesday, November 21, 2023 at 10:21:14 AM UTC Mark wrote:
>>
>>> I would like to be able to access a dynamic C library (and ideally C++), 
>>> i.e., `.so` or `.dll` _without_ using cgo, i.e., without needing a compiler 
>>> on the target platform.
>>> Python provides a `ctypes` module with this facility. Is there an 
>>> equivalent for 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/94a176f0-a076-4140-8179-5813ef061249n%40googlegroups.com.


Re: [go-nuts] Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread 'Salih Muhammed' via golang-nuts



I know that there's purego https://github.com/ebitengine/purego but not
totally sure about it can preform without a compiler.

--
Regards,
Salih

-- 
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/87bkbn2xpv.fsf%40gmx.com.


[go-nuts] Re: Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread Tamás Gulácsi
Which is what?
Please share with the golang-nuts list if you've found a solution!

Mark a következőt írta (2023. november 21., kedd, 11:54:11 UTC+1):

> Thank you, that looks just like what I want.
>
> On Tuesday, November 21, 2023 at 10:21:14 AM UTC Mark wrote:
>
>> I would like to be able to access a dynamic C library (and ideally C++), 
>> i.e., `.so` or `.dll` _without_ using cgo, i.e., without needing a compiler 
>> on the target platform.
>> Python provides a `ctypes` module with this facility. Is there an 
>> equivalent for 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/605afdc7-0e27-4480-8f60-41b9ccb0ee64n%40googlegroups.com.


Re: [go-nuts] Re: Measuring the total time of serving a request

2023-11-21 Thread Mitar
Hi!

On Mon, Nov 20, 2023 at 10:51 PM Uli Kunitz  wrote:
> You could convert the original ResponseWriter to a ResponseController and 
> call Flush in your middleware before you measure the duration. Alternatively 
> you can try to convert ResponseWriter to a http.Flusher and call Flush if the 
> conversion is successful.

Yes, I was thinking something along those lines. But are there any
side effects by calling Flush after the main handler returns? Like in
Write documentation it says:

"if the total size of all written data is under a few KB and there are
no Flush calls, the Content-Length header is added automatically."

"Once the headers have been flushed (...), the request body may be unavailable."

My understanding is that after the main handler returns, none of this
matters anymore. But are there any other similar side effects?


Mitar

-- 
https://mitar.tnode.com/
https://twitter.com/mitar_m
https://noc.social/@mitar

-- 
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/CAKLmikPFW%3Dh5AJnW1QbMB8%3DKjNKd%3Dook6HYkz%2BuajsXkyBFDPw%40mail.gmail.com.


[go-nuts] Re: Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread 'Mark' via golang-nuts
Thank you, that looks just like what I want.

On Tuesday, November 21, 2023 at 10:21:14 AM UTC Mark wrote:

> I would like to be able to access a dynamic C library (and ideally C++), 
> i.e., `.so` or `.dll` _without_ using cgo, i.e., without needing a compiler 
> on the target platform.
> Python provides a `ctypes` module with this facility. Is there an 
> equivalent for 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/6e31d1e4-159e-4120-a76a-931df7a213f5n%40googlegroups.com.


[go-nuts] Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread 'Mark' via golang-nuts
I would like to be able to access a dynamic C library (and ideally C++), 
i.e., `.so` or `.dll` _without_ using cgo, i.e., without needing a compiler 
on the target platform.
Python provides a `ctypes` module with this facility. Is there an 
equivalent for 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/f7f9a1e1-51d2-4144-9cec-d0dcaa31411en%40googlegroups.com.