* [PATCH] mingw: redefine the wrapper macro after the corresponding function
@ 2014-06-05 8:05 Stepan Kasal
2014-06-05 14:51 ` Karsten Blees
2014-06-05 16:56 ` [msysGit] " Johannes Sixt
0 siblings, 2 replies; 11+ messages in thread
From: Stepan Kasal @ 2014-06-05 8:05 UTC (permalink / raw)
To: GIT Mailing-list; +Cc: msysGit
mingw.c defines several wrapper functionsi, like mingw_unlink().
These wrappers are deployed by macros like this:
#define unlink mingw_unlink
The function itself is preceded by #undef, leaving the wrapper out
of the game for the rest of mingw.c.
This was not probably intentional; for example, there are three
calls to open() below the definition mingw_open() that probably
have no reason to circumvent the wrapper.
OTOH, there is one call to gethostbyname() before it was undefined;
probably happy that it actually calls mingw_gethostbyname().
This patch adds back the #define after each wrapper definition.
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
compat/mingw.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/compat/mingw.c b/compat/mingw.c
index a0e13bc..e7193c0 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)
ret = unlink(pathname);
return ret;
}
+#define unlink mingw_unlink
static int is_dir_empty(const char *path)
{
@@ -279,6 +280,7 @@ int mingw_rmdir(const char *pathname)
ret = rmdir(pathname);
return ret;
}
+#define rmdir mingw_rmdir
#undef open
int mingw_open (const char *filename, int oflags, ...)
@@ -303,6 +305,7 @@ int mingw_open (const char *filename, int oflags, ...)
}
return fd;
}
+#define open mingw_open
static BOOL WINAPI ctrl_ignore(DWORD type)
{
@@ -328,6 +331,7 @@ int mingw_fgetc(FILE *stream)
SetConsoleCtrlHandler(ctrl_ignore, FALSE);
return ch;
}
+#define fgetc mingw_fgetc
#undef fopen
FILE *mingw_fopen (const char *filename, const char *otype)
@@ -336,6 +340,7 @@ FILE *mingw_fopen (const char *filename, const char *otype)
filename = "nul";
return fopen(filename, otype);
}
+#define fopen mingw_fopen
#undef freopen
FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
@@ -344,6 +349,7 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
filename = "nul";
return freopen(filename, otype, stream);
}
+#define freopen mingw_freopen
#undef fflush
int mingw_fflush(FILE *stream)
@@ -366,6 +372,7 @@ int mingw_fflush(FILE *stream)
return ret;
}
+#define fflush mingw_fflush
/*
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
@@ -629,6 +636,7 @@ char *mingw_getcwd(char *pointer, int len)
pointer[i] = '/';
return ret;
}
+#define getcwd mingw_getcwd
/*
* See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
@@ -1183,6 +1191,7 @@ char *mingw_getenv(const char *name)
}
return result;
}
+#define getenv mingw_getenv
/*
* Note, this isn't a complete replacement for getaddrinfo. It assumes
@@ -1366,6 +1375,7 @@ int mingw_gethostname(char *name, int namelen)
ensure_socket_initialization();
return gethostname(name, namelen);
}
+#define gethostname mingw_gethostname
#undef gethostbyname
struct hostent *mingw_gethostbyname(const char *host)
@@ -1373,6 +1383,7 @@ struct hostent *mingw_gethostbyname(const char *host)
ensure_socket_initialization();
return gethostbyname(host);
}
+#define gethostbyname mingw_gethostbyname
void mingw_freeaddrinfo(struct addrinfo *res)
{
@@ -1429,6 +1440,7 @@ int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return connect(s, sa, sz);
}
+#define connect mingw_connect
#undef bind
int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)
@@ -1436,6 +1448,7 @@ int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return bind(s, sa, sz);
}
+#define bind mingw_bind
#undef setsockopt
int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)
@@ -1443,6 +1456,7 @@ int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return setsockopt(s, lvl, optname, (const char*)optval, optlen);
}
+#define setsockopt mingw_setsockopt
#undef shutdown
int mingw_shutdown(int sockfd, int how)
@@ -1450,6 +1464,7 @@ int mingw_shutdown(int sockfd, int how)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return shutdown(s, how);
}
+#define shutdown mingw_shutdown
#undef listen
int mingw_listen(int sockfd, int backlog)
@@ -1457,6 +1472,7 @@ int mingw_listen(int sockfd, int backlog)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return listen(s, backlog);
}
+#define listen mingw_listen
#undef accept
int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)
@@ -1475,6 +1491,7 @@ int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)
}
return sockfd2;
}
+#define accept mingw_accept
#undef rename
int mingw_rename(const char *pold, const char *pnew)
@@ -1530,6 +1547,7 @@ repeat:
errno = EACCES;
return -1;
}
+#define rename mingw_rename
/*
* Note that this doesn't return the actual pagesize, but
@@ -1684,6 +1702,7 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
return old;
}
+#define signal mingw_signal
#undef raise
int mingw_raise(int sig)
@@ -1709,6 +1728,7 @@ int mingw_raise(int sig)
return raise(sig);
}
}
+#define raise mingw_raise
static const char *make_backslash_path(const char *path)
--
2.0.0.9635.g0be03cb
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-05 8:05 [PATCH] mingw: redefine the wrapper macro after the corresponding function Stepan Kasal
@ 2014-06-05 14:51 ` Karsten Blees
2014-06-05 15:13 ` [msysGit] " Stepan Kasal
2014-06-05 16:56 ` [msysGit] " Johannes Sixt
1 sibling, 1 reply; 11+ messages in thread
From: Karsten Blees @ 2014-06-05 14:51 UTC (permalink / raw)
To: Stepan Kasal, GIT Mailing-list; +Cc: msysGit
Am 05.06.2014 10:05, schrieb Stepan Kasal:
> mingw.c defines several wrapper functionsi, like mingw_unlink().
> These wrappers are deployed by macros like this:
> #define unlink mingw_unlink
> The function itself is preceded by #undef, leaving the wrapper out
> of the game for the rest of mingw.c.
>
In the current msysgit HEAD, most of these #undef's can simply be removed or have already been removed (e.g. there's no '#undef mingw_unlink'). The reason is that the mingw_unlink implementation calls the unicode version _wunlink, so there's no name clash here.
If you apply this patch in msysgit, you'll most likely get compile errors due to redefining macros.
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [msysGit] Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-05 14:51 ` Karsten Blees
@ 2014-06-05 15:13 ` Stepan Kasal
2014-06-05 22:12 ` Karsten Blees
0 siblings, 1 reply; 11+ messages in thread
From: Stepan Kasal @ 2014-06-05 15:13 UTC (permalink / raw)
To: Karsten Blees; +Cc: GIT Mailing-list, msysGit
Hello Karsten,
On Thu, Jun 05, 2014 at 04:51:39PM +0200, Karsten Blees wrote:
> In the current msysgit HEAD, most of these #undef's can simply be
> removed or have already been removed [...]
not "most of." According to my quick count, 6 of 20 have been removed,
2 more can be removed. The remaining 12 do play their role.
(The point you overlooked is that there are several socket related,
like bind().)
> If you apply this patch in msysgit, you'll most likely get compile
> errors due to redefining macros.
It would be warnings only. But a quick test shows that redefining
with identical definition does not trigger the warning.
Stepan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [msysGit] [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-05 8:05 [PATCH] mingw: redefine the wrapper macro after the corresponding function Stepan Kasal
2014-06-05 14:51 ` Karsten Blees
@ 2014-06-05 16:56 ` Johannes Sixt
2014-06-05 22:00 ` Karsten Blees
1 sibling, 1 reply; 11+ messages in thread
From: Johannes Sixt @ 2014-06-05 16:56 UTC (permalink / raw)
To: Stepan Kasal; +Cc: GIT Mailing-list, msysGit
Am 05.06.2014 10:05, schrieb Stepan Kasal:
> mingw.c defines several wrapper functionsi, like mingw_unlink().
> These wrappers are deployed by macros like this:
> #define unlink mingw_unlink
> The function itself is preceded by #undef, leaving the wrapper out
> of the game for the rest of mingw.c.
>
> This was not probably intentional; for example, there are three
> calls to open() below the definition mingw_open() that probably
> have no reason to circumvent the wrapper.
> OTOH, there is one call to gethostbyname() before it was undefined;
> probably happy that it actually calls mingw_gethostbyname().
>
> This patch adds back the #define after each wrapper definition.
>
> Signed-off-by: Stepan Kasal <kasal@ucw.cz>
> ---
> compat/mingw.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/compat/mingw.c b/compat/mingw.c
> index a0e13bc..e7193c0 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)
> ret = unlink(pathname);
> return ret;
> }
> +#define unlink mingw_unlink
(etc...)
I don't particularly like this approach: It robs the precise control of
which function we can invoke from other places in mingw.c.
Within mingw.c, if some other function inside mingw.c wants to use
mingw_unlink, then it should be written as 'mingw_unlink(foo)', not
'unlink(foo)'.
So, IMO the macros should be #undef'ed at the top of the file, and all
users (like the open() and gethostbyname() invocations that you
identified) should be audited and changed to call the function they
actually need (i.e., the system open vs. mingw_open).
-- Hannes
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-05 16:56 ` [msysGit] " Johannes Sixt
@ 2014-06-05 22:00 ` Karsten Blees
2014-06-06 8:32 ` Stepan Kasal
0 siblings, 1 reply; 11+ messages in thread
From: Karsten Blees @ 2014-06-05 22:00 UTC (permalink / raw)
To: Johannes Sixt, Stepan Kasal; +Cc: GIT Mailing-list, msysGit
Am 05.06.2014 18:56, schrieb Johannes Sixt:
> Am 05.06.2014 10:05, schrieb Stepan Kasal:
>> mingw.c defines several wrapper functionsi, like mingw_unlink().
>> These wrappers are deployed by macros like this:
>> #define unlink mingw_unlink
>> The function itself is preceded by #undef, leaving the wrapper out
>> of the game for the rest of mingw.c.
>>
>> This was not probably intentional; for example, there are three
>> calls to open() below the definition mingw_open() that probably
>> have no reason to circumvent the wrapper.
>> OTOH, there is one call to gethostbyname() before it was undefined;
>> probably happy that it actually calls mingw_gethostbyname().
>>
>> This patch adds back the #define after each wrapper definition.
>>
>> Signed-off-by: Stepan Kasal <kasal@ucw.cz>
>> ---
>> compat/mingw.c | 20 ++++++++++++++++++++
>> 1 file changed, 20 insertions(+)
>>
>> diff --git a/compat/mingw.c b/compat/mingw.c
>> index a0e13bc..e7193c0 100644
>> --- a/compat/mingw.c
>> +++ b/compat/mingw.c
>> @@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)
>> ret = unlink(pathname);
>> return ret;
>> }
>> +#define unlink mingw_unlink
> (etc...)
>
> I don't particularly like this approach: It robs the precise control of
> which function we can invoke from other places in mingw.c.
>
> Within mingw.c, if some other function inside mingw.c wants to use
> mingw_unlink, then it should be written as 'mingw_unlink(foo)', not
> 'unlink(foo)'.
>
I very much like this approach. In fact, we already do this for e.g. mingw_raise.
> So, IMO the macros should be #undef'ed at the top of the file, and all
> users (like the open() and gethostbyname() invocations that you
> identified) should be audited and changed to call the function they
> actually need (i.e., the system open vs. mingw_open).
>
I'm sceptical of moving all #undef's to the top. Other callers would typically want the wrapped version (i.e. mingw_*). At least I can't think of a scenario in which a higher level function would want to bypass the wrapper...
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-05 15:13 ` [msysGit] " Stepan Kasal
@ 2014-06-05 22:12 ` Karsten Blees
0 siblings, 0 replies; 11+ messages in thread
From: Karsten Blees @ 2014-06-05 22:12 UTC (permalink / raw)
To: Stepan Kasal; +Cc: GIT Mailing-list, msysGit
Am 05.06.2014 17:13, schrieb Stepan Kasal:
> Hello Karsten,
>
> On Thu, Jun 05, 2014 at 04:51:39PM +0200, Karsten Blees wrote:
>> In the current msysgit HEAD, most of these #undef's can simply be
>> removed or have already been removed [...]
>
> not "most of." According to my quick count, 6 of 20 have been removed,
> 2 more can be removed. The remaining 12 do play their role.
> (The point you overlooked is that there are several socket related,
> like bind().)
>
Right, premature generalization on my part from looking at the first two or so entries.
However, I suspect some of the remaining 12 could be improved so that no #undef is necessary. E.g. gethostbyname could probably be implemented using GetAddrInfoW (supports non-ASCII names and IPv6).
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-05 22:00 ` Karsten Blees
@ 2014-06-06 8:32 ` Stepan Kasal
2014-06-06 8:41 ` [PATCH v2] " Stepan Kasal
2014-06-06 9:43 ` [PATCH] " Karsten Blees
0 siblings, 2 replies; 11+ messages in thread
From: Stepan Kasal @ 2014-06-06 8:32 UTC (permalink / raw)
To: Karsten Blees; +Cc: Johannes Sixt, GIT Mailing-list, msysGit
Hello,
On Fri, Jun 06, 2014 at 12:00:51AM +0200, Karsten Blees wrote:
> Am 05.06.2014 18:56, schrieb Johannes Sixt:
> > Within mingw.c, if some other function inside mingw.c wants to use
> > mingw_unlink, then it should be written as 'mingw_unlink(foo)', not
> > 'unlink(foo)'.
> I very much like this approach. In fact, we already do this for e.g. mingw_raise.
Hannes, this is consistent with your commit 06bc4b7. Settled.
> Other callers would typically want the wrapped version (i.e.
> mingw_*).
If this assumption were true, then we have to keep the wrapper macros
defined, both above and below the wrapper function definition.
You are in fact advocating my patch.
Updated version follows.
Stepan
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2] mingw: redefine the wrapper macro after the corresponding function
2014-06-06 8:32 ` Stepan Kasal
@ 2014-06-06 8:41 ` Stepan Kasal
2014-06-06 9:43 ` [PATCH] " Karsten Blees
1 sibling, 0 replies; 11+ messages in thread
From: Stepan Kasal @ 2014-06-06 8:41 UTC (permalink / raw)
To: Karsten Blees; +Cc: Johannes Sixt, GIT Mailing-list, msysGit
>From 624d15bd5d2d06035abc17415127a7cf37b5f981 Mon Sep 17 00:00:00 2001
From: Stepan Kasal <kasal@ucw.cz>
Date: Thu, 5 Jun 2014 09:17:17 +0200
mingw.c defines several wrapper functions, e.g., mingw_unlink().
These wrappers are deployed by macros like this:
#define unlink mingw_unlink
The mingw_foo() wrapper often calls the original function, so it has
to be #undef'ed at that place.
But for the rest of mingw.c, if the function is used, the user probably
meant the fixed functionality. So it is safer to redefine the macro
back.
Nonetheless, it is preferable to call mingw_foo() explicitly throughout
mingw.c itself.
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
compat/mingw.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index a0e13bc..ee83211 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)
ret = unlink(pathname);
return ret;
}
+#define unlink mingw_unlink
static int is_dir_empty(const char *path)
{
@@ -279,6 +280,7 @@ int mingw_rmdir(const char *pathname)
ret = rmdir(pathname);
return ret;
}
+#define rmdir mingw_rmdir
#undef open
int mingw_open (const char *filename, int oflags, ...)
@@ -303,6 +305,7 @@ int mingw_open (const char *filename, int oflags, ...)
}
return fd;
}
+#define open mingw_open
static BOOL WINAPI ctrl_ignore(DWORD type)
{
@@ -328,6 +331,7 @@ int mingw_fgetc(FILE *stream)
SetConsoleCtrlHandler(ctrl_ignore, FALSE);
return ch;
}
+#define fgetc mingw_fgetc
#undef fopen
FILE *mingw_fopen (const char *filename, const char *otype)
@@ -336,6 +340,7 @@ FILE *mingw_fopen (const char *filename, const char *otype)
filename = "nul";
return fopen(filename, otype);
}
+#define fopen mingw_fopen
#undef freopen
FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
@@ -344,6 +349,7 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
filename = "nul";
return freopen(filename, otype, stream);
}
+#define freopen mingw_freopen
#undef fflush
int mingw_fflush(FILE *stream)
@@ -366,6 +372,7 @@ int mingw_fflush(FILE *stream)
return ret;
}
+#define fflush mingw_fflush
/*
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
@@ -525,7 +532,7 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
SetFileAttributes(file_name, attrs & ~FILE_ATTRIBUTE_READONLY);
}
- if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0) {
+ if ((fh = mingw_open(file_name, O_RDWR | O_BINARY)) < 0) {
rc = -1;
goto revert_attrs;
}
@@ -564,7 +571,7 @@ int mkstemp(char *template)
char *filename = mktemp(template);
if (filename == NULL)
return -1;
- return open(filename, O_RDWR | O_CREAT, 0600);
+ return mingw_open(filename, O_RDWR | O_CREAT, 0600);
}
int gettimeofday(struct timeval *tv, void *tz)
@@ -629,6 +636,7 @@ char *mingw_getcwd(char *pointer, int len)
pointer[i] = '/';
return ret;
}
+#define getcwd mingw_getcwd
/*
* See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
@@ -700,7 +708,7 @@ static const char *parse_interpreter(const char *cmd)
if (n >= 4 && !strcasecmp(cmd+n-4, ".exe"))
return NULL;
- fd = open(cmd, O_RDONLY);
+ fd = mingw_open(cmd, O_RDONLY);
if (fd < 0)
return NULL;
n = read(fd, buf, sizeof(buf)-1);
@@ -1183,6 +1191,7 @@ char *mingw_getenv(const char *name)
}
return result;
}
+#define getenv mingw_getenv
/*
* Note, this isn't a complete replacement for getaddrinfo. It assumes
@@ -1199,7 +1208,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
struct sockaddr_in *sin;
if (node) {
- h = gethostbyname(node);
+ h = mingw_gethostbyname(node);
if (!h)
return WSAGetLastError();
}
@@ -1366,6 +1375,7 @@ int mingw_gethostname(char *name, int namelen)
ensure_socket_initialization();
return gethostname(name, namelen);
}
+#define gethostname mingw_gethostname
#undef gethostbyname
struct hostent *mingw_gethostbyname(const char *host)
@@ -1373,6 +1383,7 @@ struct hostent *mingw_gethostbyname(const char *host)
ensure_socket_initialization();
return gethostbyname(host);
}
+#define gethostbyname mingw_gethostbyname
void mingw_freeaddrinfo(struct addrinfo *res)
{
@@ -1429,6 +1440,7 @@ int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return connect(s, sa, sz);
}
+#define connect mingw_connect
#undef bind
int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)
@@ -1436,6 +1448,7 @@ int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return bind(s, sa, sz);
}
+#define bind mingw_bind
#undef setsockopt
int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)
@@ -1443,6 +1456,7 @@ int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return setsockopt(s, lvl, optname, (const char*)optval, optlen);
}
+#define setsockopt mingw_setsockopt
#undef shutdown
int mingw_shutdown(int sockfd, int how)
@@ -1450,6 +1464,7 @@ int mingw_shutdown(int sockfd, int how)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return shutdown(s, how);
}
+#define shutdown mingw_shutdown
#undef listen
int mingw_listen(int sockfd, int backlog)
@@ -1457,6 +1472,7 @@ int mingw_listen(int sockfd, int backlog)
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
return listen(s, backlog);
}
+#define listen mingw_listen
#undef accept
int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)
@@ -1475,6 +1491,7 @@ int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)
}
return sockfd2;
}
+#define accept mingw_accept
#undef rename
int mingw_rename(const char *pold, const char *pnew)
@@ -1530,6 +1547,7 @@ repeat:
errno = EACCES;
return -1;
}
+#define rename mingw_rename
/*
* Note that this doesn't return the actual pagesize, but
@@ -1684,6 +1702,7 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
return old;
}
+#define signal mingw_signal
#undef raise
int mingw_raise(int sig)
@@ -1709,6 +1728,7 @@ int mingw_raise(int sig)
return raise(sig);
}
}
+#define raise mingw_raise
static const char *make_backslash_path(const char *path)
--
2.0.0.9635.g0be03cb
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-06 8:32 ` Stepan Kasal
2014-06-06 8:41 ` [PATCH v2] " Stepan Kasal
@ 2014-06-06 9:43 ` Karsten Blees
2014-06-06 11:10 ` Stepan Kasal
1 sibling, 1 reply; 11+ messages in thread
From: Karsten Blees @ 2014-06-06 9:43 UTC (permalink / raw)
To: Stepan Kasal; +Cc: Johannes Sixt, GIT Mailing-list, msysGit
Am 06.06.2014 10:32, schrieb Stepan Kasal:
> Hello,
>
> On Fri, Jun 06, 2014 at 12:00:51AM +0200, Karsten Blees wrote:
>> Am 05.06.2014 18:56, schrieb Johannes Sixt:
>>> Within mingw.c, if some other function inside mingw.c wants to use
>>> mingw_unlink, then it should be written as 'mingw_unlink(foo)', not
>>> 'unlink(foo)'.
>> I very much like this approach. In fact, we already do this for e.g. mingw_raise.
>
> Hannes, this is consistent with your commit 06bc4b7. Settled.
>
>> Other callers would typically want the wrapped version (i.e.
>> mingw_*).
>
> If this assumption were true, then we have to keep the wrapper macros
> defined, both above and below the wrapper function definition.
That's not what I meant. Assume all other callers are written 'mingw_foo', as suggested by Hannes, and no one except 'mingw_foo' has the need to call MSVCRT's 'foo' directly. Then its irrelevant whether the #undef is at the top or immediately before 'mingw_foo'. Having the #undef in close vicinity of the function definition helps removing it when its no longer needed.
Thinking about this some more, the best solution is probably to eliminate the problem altogether by adding inline-wrappers for required CRT-functions, e.g.:
mingw.h:
static inline int crt_gethostname(char *host, int namelen)
{
return gethostname(host, namelen);
}
int mingw_gethostname(char *host, int namelen);
#define gethostname mingw_gethostname
mingw.c:
int mingw_gethostname(char *name, int namelen)
{
ensure_socket_initialization();
return crt_gethostname(name, namelen);
}
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-06 9:43 ` [PATCH] " Karsten Blees
@ 2014-06-06 11:10 ` Stepan Kasal
2014-06-06 18:20 ` Karsten Blees
0 siblings, 1 reply; 11+ messages in thread
From: Stepan Kasal @ 2014-06-06 11:10 UTC (permalink / raw)
To: Karsten Blees; +Cc: Johannes Sixt, GIT Mailing-list, msysGit
Hi Karsten,
On Fri, Jun 06, 2014 at 11:43:03AM +0200, Karsten Blees wrote:
> [...] Assume all other callers are written
> 'mingw_foo', as suggested by Hannes, and no one except 'mingw_foo'
> has the need to call MSVCRT's 'foo' directly. Then its irrelevant
> whether the #undef is at the top or immediately before 'mingw_foo'.
Yet there is still danger that someone calls foo() by mistake.
It is still best to have a protection:
#define foo choke_here_do_not_use_this
> Thinking about this some more, the best solution is probably to
> eliminate the problem altogether by adding inline-wrappers for
> required CRT-functions, e.g.:
Yes, this is acceptable. But I wouldn't pollute mingw.h. You can do
it on top of mingw.c like this:
#undef gethostname
static inline int crt_gethostname(char *host, int namelen)
{
return gethostname(host, namelen);
}
#define gethostname please_call_the_mingw_or_crt_version
This would also be an acceptable solution, though I still prefer my
solution, because, as you put it:
> Having the #undef in close vicinity of the function definition
> helps removing it when it's no longer needed.
Stepan
PS: Anyway, this is another patch which I can mark as "too much
discussion, try later." Then I can proceed and submit your unicode
branch.
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function
2014-06-06 11:10 ` Stepan Kasal
@ 2014-06-06 18:20 ` Karsten Blees
0 siblings, 0 replies; 11+ messages in thread
From: Karsten Blees @ 2014-06-06 18:20 UTC (permalink / raw)
To: Stepan Kasal; +Cc: Johannes Sixt, GIT Mailing-list, msysGit
Am 06.06.2014 13:10, schrieb Stepan Kasal:
> Hi Karsten,
>
> On Fri, Jun 06, 2014 at 11:43:03AM +0200, Karsten Blees wrote:
>> Thinking about this some more, the best solution is probably to
>> eliminate the problem altogether by adding inline-wrappers for
>> required CRT-functions, e.g.:
>
> Yes, this is acceptable. But I wouldn't pollute mingw.h. You can do
> it on top of mingw.c like this:
But having it in the .h file may come in handy if we want to split the overlong mingw.c into several compilation units...
>
> #undef gethostname
> static inline int crt_gethostname(char *host, int namelen)
> {
> return gethostname(host, namelen);
> }
> #define gethostname please_call_the_mingw_or_crt_version
>
Now you're mixing all three variants...note that with my suggestion to #define crt_foo in mingw.h, you don't need '#undef foo', nor redefine foo (your variant), nor rename other callers in mingw.c to 'mingw_foo' (Hannes' variant).
Callers of foo() would simply write "foo()", no matter whether in mingw.c or anywhere else. In the special case that you really want the CRT version, you'd write crt_foo(). This works everywhere, even in core-git code wrapped in #ifdef GIT_WINDOWS_NATIVE.
--
--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.
You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en
---
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-06-06 18:20 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-05 8:05 [PATCH] mingw: redefine the wrapper macro after the corresponding function Stepan Kasal
2014-06-05 14:51 ` Karsten Blees
2014-06-05 15:13 ` [msysGit] " Stepan Kasal
2014-06-05 22:12 ` Karsten Blees
2014-06-05 16:56 ` [msysGit] " Johannes Sixt
2014-06-05 22:00 ` Karsten Blees
2014-06-06 8:32 ` Stepan Kasal
2014-06-06 8:41 ` [PATCH v2] " Stepan Kasal
2014-06-06 9:43 ` [PATCH] " Karsten Blees
2014-06-06 11:10 ` Stepan Kasal
2014-06-06 18:20 ` Karsten Blees
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).