Mailing List Archive

gpgme fails to compile with mingw due to wrong macro
* compiler:

gcc version 13.1.0 (Rev6, Built by MSYS2 project)
Target: x86_64-w64-mingw32
Thread model: posix

* compiler error:

python3.10-gpg/helpers.h:30:28: error: expected expression before '{' token
30 | #define write(fd, str, sz) {DWORD written; WriteFile((HANDLE)
fd, str, sz, &written, 0);}
| ^
python3.10-gpg/helpers.c:407:11: note: in expansion of macro 'write'
407 | if (write(fd, "\n", 1) < 0) {
| ^~~~~

* suggestion:
1. Disable the write() macro with `#ifdef _MSC_VER` (true for msvc
only). I am not sure if Microsoft Windows' write function is
equivalent with *nix's one.
2. Rewrite the write() macro as following.

static ssize_t gpgme_win32_write(int fd, const void *str, size_t sz)
{
DWORD written;
return WriteFile((HANDLE) fd, str, sz, &written, 0);
}

#define write(fd, str, sz) gpgme_win32_write(fd, str, sz)

I can provide further information if required. Thank you.

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-devel
Re: gpgme fails to compile with mingw due to wrong macro [ In reply to ]
Hi!

> python3.10-gpg/helpers.h:30:28: error: expected expression before '{' token
> 30 | #define write(fd, str, sz) {DWORD written; WriteFile((HANDLE)
> fd, str, sz, &written, 0);}

I don't believe what I see in gpgme:

#ifdef _WIN32
#include <windows.h>
#define write(fd, str, sz) {DWORD written; \
WriteFile((HANDLE) fd, str, sz, &written, 0);}
#endif

This looks more like an experimental test code. The function does not
return anything (which is the cause of the above error) and WriteFile
and write have different properties. Thus the suggested fix is not also
not right. Someone(tm) needs to look at the use cases of write.

> 1. Disable the write() macro with `#ifdef _MSC_VER` (true for msvc
> only). I am not sure if Microsoft Windows' write function is
> equivalent with *nix's one.

Yes, it is but if you may need to use _write instead of write unless you
include the oldnames.h or so header.


Shalom-Salam,

Werner

--
The pioneers of a warless world are the youth that
refuse military service. - A. Einstein
Re: gpgme fails to compile with mingw due to wrong macro [ In reply to ]
Hi,

tracked as https://dev.gnupg.org/T6501


Salam-Shalom,

Werner

--
The pioneers of a warless world are the youth that
refuse military service. - A. Einstein