[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnucap-devel] MS Windows, mingw compatibility of recent snapshots

From: al davis
Subject: Re: [Gnucap-devel] MS Windows, mingw compatibility of recent snapshots
Date: Thu, 4 Jan 2007 03:45:43 -0500
User-agent: KMail/1.9.5

On Monday 01 January 2007 05:34, Holger Vogt wrote:
> enclosed you will find an improved patch of for
> MS Windows with correct error message handling, now tested
> with the gnucap att and det commands.

Thanks..  I tried it on mingw, and it compiles now.  I have no 
way of testing it to see if it really works.

I made a header file defining dlopen etc. with the MS functions:
#include <windows.h>
#undef min
#undef max
inline void* dlopen(const char* f, int)
  return LoadLibrary(f);

inline void dlclose(void* h)

inline char* dlerror()
  static LPVOID lpMsgBuf = NULL;
  // free the error message buffer
  if (lpMsgBuf) {

  // get the error code
  DWORD dw = GetLastError();

  // get the corresponding error message
                (LPTSTR) &lpMsgBuf,
                0, NULL);

  return (char*)lpMsgBuf;

#define RTLD_NOW 2
#define RTLD_LOCAL 0
I suppose you could call it "dlfcn.h", but I called 
it "ms-dlfcn.h", so the only #ifdef is to select which to 
include.  It should move to md.h,, where all other portability 
hacks are.

I also changed the way the buffer is free'd.  The pointer is 
static, and gets freed on the next call, so they don't build 
up.  The way you did it causes a memory leak because 
cmd.warn(bERROR, ...  throws an exception and does not return.  
It must be compatible with dlerror() which returns a pointer to 
a static string.

In this case, defining the missing functions in terms of the 
ones available is the correct way to do it.  Why doesn't mingw 
provide this, and call it "dlfcn.h"??  It is a standard library 
function, as specified by POSIX.1-2001.

When a standard function is missing, I prefer to design for the 
correct library, and make an interface to supply the missing 
functions in a form as close to the standard as possible.  With 
no #define's it should use the standard, a #define 
like "MS_DLOPEN_IS_MISSING" enables the hack.  It is not a good 
idea to use something implied like _WIN32, because hopefully 
someday they will fix it.

Thanks again.  The next snapshot will have the patch, in md.h.
Can you make sure I didn't mess it up?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]