Re: [go-nuts] How to determine the correct method signature to override fopen

2017-11-06 Thread Ian Lance Taylor
On Mon, Nov 6, 2017 at 10:58 AM,   wrote:
>
> In that case - do you know how I can inspect the comparison it's doing?
> Since I'm already doing this for the open system call, I know that it's
> possible to write a function with the same definition. It seems in this case
> that I'm not matching the representation that cgo is expecting. I would
> therefore like to see what cgo thing it looks like so I can attempt to get a
> perfect match. Would that be possible?

Perhaps it is possible but I don't see a way.  I think it works for
open coincidentally; there just happens to be no conflict between the
declaration in the header file and the definition that cgo generates.

Ian


> On Friday, November 3, 2017 at 11:50:36 PM UTC-4, Ian Lance Taylor wrote:
>>
>> On Fri, Nov 3, 2017 at 5:44 PM,   wrote:
>> >
>> > Thanks Ian. I had included that because it seems required in order for
>> > me to
>> > refer to the return type (C.FILE) and so I can access the underlying
>> > C.fopen
>> > function.  This is the approach I have with open but perhaps this is
>> > different.
>> > If I'm not supposed to use the include, can you advise how I should
>> > refer to
>> > the type/function from the header?
>>
>> I'm sorry, nothing comes to mind.  In C you would just write the
>> declaration the way the header file expects, but cgo doesn't provide a
>> way to do that.
>>
>> Ian
>>
>>
>> > On Friday, November 3, 2017 at 8:28:38 PM UTC-4, Ian Lance Taylor wrote:
>> >>
>> >> On Fri, Nov 3, 2017 at 2:24 PM,   wrote:
>> >> >
>> >> > I've been writing a shared-object which I'll use via LD_PRELOAD to
>> >> > override
>> >> > the open syscall. This is currently working OK but now I want to move
>> >> > on
>> >> > to
>> >> > fopen. I've defined it (as far as I can tell) in-line with the stdio
>> >> > header
>> >> > see here. However, when I try and build:
>> >> >
>> >> > $ go build -buildmode=c-shared
>> >> > # github.com/walkert/loader
>> >> > In file included from
>> >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:0:
>> >> > ./main.go:56:14: error: conflicting types for ‘fopen’
>> >> > In file included from ./main.go:5:0,
>> >> >  from
>> >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:
>> >> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’
>> >> > was
>> >> > here
>> >> >  extern FILE *fopen (const char *__restrict __filename,
>> >> >   ^
>> >> >
>> >> >
>> >> > /tmp/go-build775342366/github.com/walkert/loader/_obj/_cgo_export.c:17:7:
>> >> > error: conflicting types for ‘fopen’
>> >> >  FILE* fopen(char* p0, char* p1)
>> >> >^
>> >> > In file included from ./main.go:5:0,
>> >> >  from
>> >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:
>> >> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’
>> >> > was
>> >> > here
>> >> >  extern FILE *fopen (const char *__restrict __filename,
>> >> >   ^
>> >> >
>> >> > I've seen this before when I was trying to return an int instead of
>> >> > C.int so
>> >> > I have a feeling I'm missing something simple here. Any pointers
>> >> > would
>> >> > be
>> >> > much appreciated.
>> >>
>> >> It looks like the same file is doing #include  and `//export
>> >> fopen`.  That won't work, because, as you can see, the definition of
>> >> the Go function fopen will conflict with the declaration in stdio.h.
>> >>
>> >> 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...@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.

-- 
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 determine the correct method signature to override fopen

2017-11-06 Thread tonywalker . uk
In that case - do you know how I can inspect the comparison it's doing? 
Since I'm already doing this for the open system call, I know that it's 
possible to write a function with the same definition. It seems in this 
case that I'm not matching the representation that cgo is expecting. I 
would therefore like to see what cgo thing it looks like so I can attempt 
to get a perfect match. Would that be possible?

On Friday, November 3, 2017 at 11:50:36 PM UTC-4, Ian Lance Taylor wrote:
>
> On Fri, Nov 3, 2017 at 5:44 PM,   
> wrote: 
> > 
> > Thanks Ian. I had included that because it seems required in order for 
> me to 
> > refer to the return type (C.FILE) and so I can access the underlying 
> C.fopen 
> > function.  This is the approach I have with open but perhaps this is 
> > different. 
> > If I'm not supposed to use the include, can you advise how I should 
> refer to 
> > the type/function from the header? 
>
> I'm sorry, nothing comes to mind.  In C you would just write the 
> declaration the way the header file expects, but cgo doesn't provide a 
> way to do that. 
>
> Ian 
>
>
> > On Friday, November 3, 2017 at 8:28:38 PM UTC-4, Ian Lance Taylor wrote: 
> >> 
> >> On Fri, Nov 3, 2017 at 2:24 PM,   wrote: 
> >> > 
> >> > I've been writing a shared-object which I'll use via LD_PRELOAD to 
> >> > override 
> >> > the open syscall. This is currently working OK but now I want to move 
> on 
> >> > to 
> >> > fopen. I've defined it (as far as I can tell) in-line with the stdio 
> >> > header 
> >> > see here. However, when I try and build: 
> >> > 
> >> > $ go build -buildmode=c-shared 
> >> > # github.com/walkert/loader 
> >> > In file included from 
> >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:0: 
> >> > ./main.go:56:14: error: conflicting types for ‘fopen’ 
> >> > In file included from ./main.go:5:0, 
> >> >  from 
> >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3: 
> >> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ 
> was 
> >> > here 
> >> >  extern FILE *fopen (const char *__restrict __filename, 
> >> >   ^ 
> >> > 
> >> > /tmp/go-build775342366/
> github.com/walkert/loader/_obj/_cgo_export.c:17:7: 
> >> > error: conflicting types for ‘fopen’ 
> >> >  FILE* fopen(char* p0, char* p1) 
> >> >^ 
> >> > In file included from ./main.go:5:0, 
> >> >  from 
> >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3: 
> >> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ 
> was 
> >> > here 
> >> >  extern FILE *fopen (const char *__restrict __filename, 
> >> >   ^ 
> >> > 
> >> > I've seen this before when I was trying to return an int instead of 
> >> > C.int so 
> >> > I have a feeling I'm missing something simple here. Any pointers 
> would 
> >> > be 
> >> > much appreciated. 
> >> 
> >> It looks like the same file is doing #include  and `//export 
> >> fopen`.  That won't work, because, as you can see, the definition of 
> >> the Go function fopen will conflict with the declaration in stdio.h. 
> >> 
> >> 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...@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] How to determine the correct method signature to override fopen

2017-11-03 Thread Ian Lance Taylor
On Fri, Nov 3, 2017 at 5:44 PM,   wrote:
>
> Thanks Ian. I had included that because it seems required in order for me to
> refer to the return type (C.FILE) and so I can access the underlying C.fopen
> function.  This is the approach I have with open but perhaps this is
> different.
> If I'm not supposed to use the include, can you advise how I should refer to
> the type/function from the header?

I'm sorry, nothing comes to mind.  In C you would just write the
declaration the way the header file expects, but cgo doesn't provide a
way to do that.

Ian


> On Friday, November 3, 2017 at 8:28:38 PM UTC-4, Ian Lance Taylor wrote:
>>
>> On Fri, Nov 3, 2017 at 2:24 PM,   wrote:
>> >
>> > I've been writing a shared-object which I'll use via LD_PRELOAD to
>> > override
>> > the open syscall. This is currently working OK but now I want to move on
>> > to
>> > fopen. I've defined it (as far as I can tell) in-line with the stdio
>> > header
>> > see here. However, when I try and build:
>> >
>> > $ go build -buildmode=c-shared
>> > # github.com/walkert/loader
>> > In file included from
>> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:0:
>> > ./main.go:56:14: error: conflicting types for ‘fopen’
>> > In file included from ./main.go:5:0,
>> >  from
>> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:
>> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ was
>> > here
>> >  extern FILE *fopen (const char *__restrict __filename,
>> >   ^
>> >
>> > /tmp/go-build775342366/github.com/walkert/loader/_obj/_cgo_export.c:17:7:
>> > error: conflicting types for ‘fopen’
>> >  FILE* fopen(char* p0, char* p1)
>> >^
>> > In file included from ./main.go:5:0,
>> >  from
>> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:
>> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ was
>> > here
>> >  extern FILE *fopen (const char *__restrict __filename,
>> >   ^
>> >
>> > I've seen this before when I was trying to return an int instead of
>> > C.int so
>> > I have a feeling I'm missing something simple here. Any pointers would
>> > be
>> > much appreciated.
>>
>> It looks like the same file is doing #include  and `//export
>> fopen`.  That won't work, because, as you can see, the definition of
>> the Go function fopen will conflict with the declaration in stdio.h.
>>
>> 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.

-- 
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 determine the correct method signature to override fopen

2017-11-03 Thread tonywalker . uk
This is without the include:

$ go build -buildmode=c-shared

# github.com/walkert

./main.go:6:41: could not determine kind of name for C.FILE

./main.go:7:8: could not determine kind of name for C.fopen

-- 
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 determine the correct method signature to override fopen

2017-11-03 Thread tonywalker . uk
Thanks Ian. I had included that because it seems required in order for me 
to refer to the return type (C.FILE) and so I can access the underlying 
C.fopen function.  This is the approach I have with open but perhaps this 
is different.
If I'm not supposed to use the include, can you advise how I should refer 
to the type/function from the header?

Tony

On Friday, November 3, 2017 at 8:28:38 PM UTC-4, Ian Lance Taylor wrote:
>
> On Fri, Nov 3, 2017 at 2:24 PM,   
> wrote: 
> > 
> > I've been writing a shared-object which I'll use via LD_PRELOAD to 
> override 
> > the open syscall. This is currently working OK but now I want to move on 
> to 
> > fopen. I've defined it (as far as I can tell) in-line with the stdio 
> header 
> > see here. However, when I try and build: 
> > 
> > $ go build -buildmode=c-shared 
> > # github.com/walkert/loader 
> > In file included from 
> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:0: 
> > ./main.go:56:14: error: conflicting types for ‘fopen’ 
> > In file included from ./main.go:5:0, 
> >  from $WORK/
> github.com/walkert/loader/_obj/_cgo_export.c:3: 
> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ was 
> here 
> >  extern FILE *fopen (const char *__restrict __filename, 
> >   ^ 
> > /tmp/go-build775342366/github.com/walkert/loader/_obj/_cgo_export.c:17:7: 
>
> > error: conflicting types for ‘fopen’ 
> >  FILE* fopen(char* p0, char* p1) 
> >^ 
> > In file included from ./main.go:5:0, 
> >  from $WORK/
> github.com/walkert/loader/_obj/_cgo_export.c:3: 
> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ was 
> here 
> >  extern FILE *fopen (const char *__restrict __filename, 
> >   ^ 
> > 
> > I've seen this before when I was trying to return an int instead of 
> C.int so 
> > I have a feeling I'm missing something simple here. Any pointers would 
> be 
> > much appreciated. 
>
> It looks like the same file is doing #include  and `//export 
> fopen`.  That won't work, because, as you can see, the definition of 
> the Go function fopen will conflict with the declaration in stdio.h. 
>
> 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] How to determine the correct method signature to override fopen

2017-11-03 Thread tonywalker . uk
Hi,

I've been writing a shared-object which I'll use via LD_PRELOAD to override 
the open syscall. This is currently working OK but now I want to move on to 
fopen. I've defined it (as far as I can tell) in-line with the stdio header 
see here . However, when I try and 
build:

$ go build -buildmode=c-shared
# github.com/walkert/loader
In file included from 
$WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:0:
./main.go:56:14: error: conflicting types for ‘fopen’
In file included from ./main.go:5:0,
 from $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:
/usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ was here
 extern FILE *fopen (const char *__restrict __filename,
  ^
/tmp/go-build775342366/github.com/walkert/loader/_obj/_cgo_export.c:17:7: 
error: conflicting types for ‘fopen’
 FILE* fopen(char* p0, char* p1)
   ^
In file included from ./main.go:5:0,
 from $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:
/usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ was here
 extern FILE *fopen (const char *__restrict __filename,
  ^

I've seen this before when I was trying to return an int instead of C.int 
so I have a feeling I'm missing something simple here. Any pointers would 
be much appreciated.

Thanks in advance!

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