patch: macros changed to inline functions (msvcrt headers)

madhura sahasrabudhe sahasrab at usc.edu
Fri Mar 21 14:21:02 CST 2003


Hi, 

I have changed the macros in the msvcrt headers to static inline functions.  
The modified files are: conio.h, ctype.h, direct.h, malloc.h, process.h, search.h, stdio.h, stdlib.h and string.h (in the include/msvcrt directory).

I have attached a patch for the same. 

Thank you. 

Madhura Sahasrabudhe 

>Re: Middleware regression test suites, e.g. ACE
>From: Dimitrie O. Paun (dpaun at rogers.com)
>Date: Thu Feb 27 2003 - 07:49:55 CST 
>--------------------------------------------------------------------------------

>>On February 25, 2003 02:08 pm, Dan Kegel wrote:
>> ACE is a set of object-oriented
>> wrappers around operating system primitives,
>> See http://www.cs.wustl.edu/~schmidt/ACE.html

>A perfect test for my winegcc/wineg++ stuff, and
>for our C++ Winelib support! I've tried a little
>bit, it breaks badly because we use lots of macros
>in the msvcrt headers and the code expects functions
>(which, unlike macros, respect scope). I've signaled
>this problem before, and I've send a patch for
>include/msvcrt/io.h transforming those macros into
>inline functions, but a lot more is left to do.

>That is to say, all things from include/msvcrt/* of the form:

>#define isascii __isascii

>must become:

>static inline int isascii(int c) { return __isascii(c); }

>Any takers? :)

>-- 
>Dimi.


-------------- next part --------------
--- wine-20030318/include/msvcrt/conio.h	Thu Mar 20 17:28:28 2003
+++ wine-inline/include/msvcrt/conio.h	Thu Mar 20 17:19:10 2003
@@ -39,20 +39,20 @@
 
 
 #ifndef USE_MSVCRT_PREFIX
-#define cgets _cgets
+static inline char* cgets(char* str) { return _cgets(str); }
 #define cprintf _cprintf
-#define cputs _cputs
+static inline int cputs(const char* str) { return _cputs(str); }
 #define cscanf _cscanf
-#define getch _getch
-#define getche _getche
-#define kbhit _kbhit
-#define putch _putch
-#define ungetch _ungetch
+static inline int getch(void) { return _getch(); }
+static inline int getche(void) { return _getche(); }
+static inline int kbhit(void) { return _kbhit(); }
+static inline int putch(int c) { return _putch(c); }
+static inline int ungetch(int c) { return _ungetch(c); }
 #ifdef _M_IX86
-#define inp _inp
-#define inpw _inpw
-#define outp _outp
-#define outpw _outpw
+static inline int inp(unsigned short i) { return _inp(i); }
+static inline unsigned short inpw(unsigned short i) { return _inpw(i); }
+static inline int outp(unsigned short i, int j) { return _outp(i, j); }
+static inline unsigned short outpw(unsigned short i, unsigned short j) { return _outpw(i, j); }
 #endif
 #endif /* USE_MSVCRT_PREFIX */
 
--- wine-20030318/include/msvcrt/ctype.h	Thu Mar 20 17:28:36 2003
+++ wine-inline/include/msvcrt/ctype.h	Thu Mar 20 17:22:00 2003
@@ -104,10 +104,10 @@
 
 
 #ifndef USE_MSVCRT_PREFIX
-#define isascii __isascii
-#define iscsym  __iscsym
-#define iscsymf __iscsymf
-#define toascii __toascii
+static inline int isascii(int c) { return __isascii(c); }
+static inline int iscsym(int c) { return __iscsym(c); }
+static inline int iscsymf(int c) { return __iscsymf(c); }
+static inline int toascii(int c) { return __toascii(c); }
 #endif /* USE_MSVCRT_PREFIX */
 
 #endif /* __WINE_CTYPE_H */
--- wine-20030318/include/msvcrt/direct.h	Thu Mar 20 17:28:41 2003
+++ wine-inline/include/msvcrt/direct.h	Thu Mar 20 17:22:07 2003
@@ -67,10 +67,10 @@
 
 
 #ifndef USE_MSVCRT_PREFIX
-#define chdir _chdir
-#define getcwd _getcwd
-#define mkdir _mkdir
-#define rmdir _rmdir
+static inline int chdir(const char* newdir) { return _chdir(newdir); }
+static inline char* getcwd(char * buf, int size) { return _getcwd(buf, size); }
+static inline int mkdir(const char* newdir) { return _mkdir(newdir); }
+static inline int rmdir(const char* dir) { return _rmdir(dir); }
 #endif /* USE_MSVCRT_PREFIX */
 
 #endif /* __WINE_DIRECT_H */
--- wine-20030318/include/msvcrt/malloc.h	Thu Mar 20 17:28:45 2003
+++ wine-inline/include/msvcrt/malloc.h	Thu Mar 20 17:22:17 2003
@@ -81,7 +81,7 @@
 
 
 #ifndef USE_MSVCRT_PREFIX
-#define alloca _alloca
+static inline void* alloca(MSVCRT(size_t) i) { return _alloca(i); }
 #endif /* USE_MSVCRT_PREFIX */
 
 #endif /* __WINE_MALLOC_H */
--- wine-20030318/include/msvcrt/process.h	Thu Mar 20 17:28:50 2003
+++ wine-inline/include/msvcrt/process.h	Thu Mar 20 17:22:23 2003
@@ -121,24 +121,24 @@
 #define WAIT_CHILD      _WAIT_CHILD
 #define WAIT_GRANDCHILD _WAIT_GRANDCHILD
 
-#define cwait    _cwait
-#define getpid   _getpid
+static inline int cwait(int *status, int pid, int action) { return _cwait(status, pid, action); }
+static inline int getpid(void) { return _getpid(); }
 #define execl    _execl
 #define execle   _execle
 #define execlp   _execlp
 #define execlpe  _execlpe
-#define execv    _execv
-#define execve   _execve
-#define execvp   _execvp
-#define execvpe  _execvpe
+static inline int execv(const char* name, char* const* argv) { return _execv(name, argv); }
+static inline int execve(const char* name, char* const* argv, const char* const* envv) { return _execve(name, argv, envv); }
+static inline int execvp(const char* name, char* const* argv) { return _execvp(name, argv); }
+static inline int execvpe(const char* name, char* const* argv, const char* const* envv) { return _execvpe(name, argv, envv); }
 #define spawnl   _spawnl
 #define spawnle  _spawnle
 #define spawnlp  _spawnlp
 #define spawnlpe _spawnlpe
-#define spawnv   _spawnv
-#define spawnve  _spawnve
-#define spawnvp  _spawnvp
-#define spawnvpe _spawnvpe
+static inline int spawnv(int flags, const char* name, const char* const* argv) { return _spawnv(flags, name, argv); }
+static inline int spawnve(int flags, const char* name, const char* const* argv, const char* const* envv) { return _spawnve(flags, name, argv, envv); }
+static inline int spawnvp(int flags, const char* name, const char* const* argv) { return _spawnvp(flags, name, argv); }
+static inline int spawnvpe(int flags, const char* name, const char* const* argv, const char* const* envv) { return _spawnvpe(flags, name, argv, envv); }
 #endif /* USE_MSVCRT_PREFIX */
 
 #endif /* __WINE_PROCESS_H */
--- wine-20030318/include/msvcrt/search.h	Thu Mar 20 17:28:55 2003
+++ wine-inline/include/msvcrt/search.h	Thu Mar 20 17:22:29 2003
@@ -54,8 +54,8 @@
 
 
 #ifndef USE_MSVCRT_PREFIX
-#define lfind _lfind
-#define lsearch _lsearch
+static inline void* lfind(const void* match, const void* start, unsigned int* array_size, unsigned int elem_size, int (*cf)(const void*,const void*)) { return _lfind(match, start, array_size, elem_size, cf); 
+static inline void* lsearch(const void* match, void* start, unsigned int* array_size, unsigned int elem_size, int (*cf)(const void*,const void*) ) { return _lsearch(match, start, array_size, elem_size, cf); }
 #endif /* USE_MSVCRT_PREFIX */
 
 #endif /* __WINE_SEARCH_H */
--- wine-20030318/include/msvcrt/stdio.h	Thu Mar 20 17:29:00 2003
+++ wine-inline/include/msvcrt/stdio.h	Thu Mar 20 17:22:38 2003
@@ -256,22 +256,22 @@
 
 
 #ifndef USE_MSVCRT_PREFIX
-#define fdopen   _fdopen
-#define fgetchar _fgetchar
-#define fileno   _fileno
-#define fputchar _fputchar
-#define pclose   _pclose
-#define popen    _popen
-#define tempnam  _tempnam
+static inline MSVCRT(FILE)* fdopen(int fd, const char *mode) { return _fdopen(fd, mode); }
+static inline int fgetchar(void) { return _fgetchar(); }
+static inline int fileno(MSVCRT(FILE)* file) { return _fileno(file); }
+static inline int fputchar(int c) { return _fputchar(c); }
+static inline int pclose(MSVCRT(FILE)* file) { return _pclose(file); }
+static inline MSVCRT(FILE)* popen(const char* command, const char* mode) { return _popen(command, mode); }
+static inline char* tempnam(const char *dir, const char *prefix) { return _tempnam(dir, prefix); }
 #ifndef MSVCRT_UNLINK_DEFINED
 static inline int unlink(const char* path) { return _unlink(path); }
 #define MSVCRT_UNLINK_DEFINED
 #endif
 
-#define fgetwchar _fgetwchar
-#define fputwchar _fputwchar
-#define getw     _getw
-#define putw     _putw
+static inline MSVCRT(wint_t) fgetwchar(void) { return _fgetwchar(); }
+static inline MSVCRT(wint_t) fputwchar(MSVCRT(wint_t) wc) { return _fputwchar(wc); }
+static inline int getw(MSVCRT(FILE)* file) { return _getw(file); }
+static inline int putw(int val, MSVCRT(FILE)* file) { return _putw(val, file); }
 #define wpopen   _wpopen
 #endif /* USE_MSVCRT_PREFIX */
 
--- wine-20030318/include/msvcrt/stdlib.h	Thu Mar 20 17:29:03 2003
+++ wine-inline/include/msvcrt/stdlib.h	Thu Mar 20 17:22:44 2003
@@ -231,15 +231,15 @@
 #define environ _environ
 #define onexit_t _onexit_t
 
-#define ecvt _ecvt
-#define fcvt _fcvt
-#define gcvt _gcvt
-#define itoa _itoa
-#define ltoa _ltoa
-#define onexit _onexit
-#define putenv _putenv
-#define swab _swab
-#define ultoa _ultoa
+static inline char* ecvt(double value, int ndigit, int* decpt, int* sign) { return _ecvt(value, ndigit, decpt, sign); }
+static inline char* fcvt(double value, int ndigit, int* decpt, int* sign) { return _fcvt(value, ndigit, decpt, sign); }
+static inline char* gcvt(double value, int ndigit, char* buf) { return _gcvt(value, ndigit, buf); }
+static inline char* itoa(int value, char* str, int radix) { return _itoa(value, str, radix); }
+static inline char* ltoa(long value, char* str, int radix) { return _ltoa(value, str, radix); }
+static inline _onexit_t onexit(_onexit_t func) { return _onexit(func); }
+static inline int putenv(const char* str) { return _putenv(str); }
+static inline void swab(char* src, char* dst, int len) { return _swab(src, dst, len); }
+static inline char* ultoa(unsigned long value, char* str, int radix) { return _ultoa(value, str, radix); }
 #endif /* USE_MSVCRT_PREFIX */
 
 #endif /* __WINE_STDLIB_H */
--- wine-20030318/include/msvcrt/string.h	Thu Mar 20 17:29:11 2003
+++ wine-inline/include/msvcrt/string.h	Thu Mar 20 17:22:48 2003
@@ -119,29 +119,29 @@
 
 
 #ifndef USE_MSVCRT_PREFIX
-#define memccpy _memccpy
-#define memicmp _memicmp
-#define strcasecmp _stricmp
-#define strcmpi _strcmpi
-#define strdup _strdup
-#define stricmp _stricmp
-#define stricoll _stricoll
-#define strlwr _strlwr
-#define strncasecmp _strncasecmp
-#define strnicmp _strnicmp
-#define strnset _strnset
-#define strrev _strrev
-#define strset _strset
-#define strupr _strupr
+static inline void* memccpy(void *s1, const void *s2, int c, MSVCRT(size_t) n) { return _memccpy(s1, s2, c, n); }
+static inline int memicmp(const void* s1, const void* s2, MSVCRT(size_t) len) { return _memicmp(s1, s2, len); }
+static inline int strcasecmp(const char* s1, const char* s2) { return _stricmp(s1, s2); }
+static inline int strcmpi(const char* s1, const char* s2) { return _strcmpi(s1, s2); }
+static inline char* strdup(const char* buf) { return _strdup(buf); }
+static inline int stricmp(const char* s1, const char* s2) { return _stricmp(s1, s2); }
+static inline int stricoll(const char* s1, const char* s2) { return _stricoll(s1, s2); }
+static inline char* strlwr(char* str) { return _strlwr(str); }
+static inline int strncasecmp(const char *str1, const char *str2, size_t n) { return _strncasecmp(str1, str2, n); }
+static inline int strnicmp(const char* s1, const char* s2, MSVCRT(size_t) n) { return _strnicmp(s1, s2, n); }
+static inline char* strnset(char* str, int value, unsigned int len) { return _strnset(str, value, len); }
+static inline char* strrev(char* str) { return _strrev(str); }
+static inline char* strset(char* str, int value) { return _strset(str, value); }
+static inline char* strupr(char* str) { return _strupr(str); }
 
-#define wcsdup _wcsdup
-#define wcsicoll _wcsicoll
-#define wcslwr _wcslwr
-#define wcsnicmp _wcsnicmp
-#define wcsnset _wcsnset
-#define wcsrev _wcsrev
-#define wcsset _wcsset
-#define wcsupr _wcsupr
+static inline MSVCRT(wchar_t)* wcsdup(const MSVCRT(wchar_t)* str) { return _wcsdup(str); }
+static inline int wcsicoll(const MSVCRT(wchar_t)* str1, const MSVCRT(wchar_t)* str2) { return _wcsicoll(str1, str2); }
+static inline MSVCRT(wchar_t)* wcslwr(MSVCRT(wchar_t)* str) { return _wcslwr(str); }
+static inline int wcsnicmp(const MSVCRT(wchar_t)* str1, const MSVCRT(wchar_t)* str2, MSVCRT(size_t) n) { return _wcsnicmp(str1, str2, n); }
+static inline MSVCRT(wchar_t)* wcsnset(MSVCRT(wchar_t)* str, MSVCRT(wchar_t) c, MSVCRT(size_t) n) { return _wcsnset(str, c, n); }
+static inline MSVCRT(wchar_t)* wcsrev(MSVCRT(wchar_t)* str) { return _wcsrev(str); }
+static inline MSVCRT(wchar_t)* wcsset(MSVCRT(wchar_t)* str, MSVCRT(wchar_t) c) { return _wcsset(str, c); }
+static inline MSVCRT(wchar_t)* wcsupr(MSVCRT(wchar_t)* str) { return _wcsupr(str); }
 #endif /* USE_MSVCRT_PREFIX */
 
 #endif /* __WINE_STRING_H */


More information about the wine-devel mailing list