'porting python ctypes from linux to windows, testing
I'm currently trying to contribute to an open source python package (ObsPy) with a python module that uses c-code at its core (using ctypes). The code I'm adding have been developed, tested, used on linux for several years now. The ObsPy project is hosted on github with with several build and test actions activated. I've gotten as far as to get my contribution to build properly but all the tests fail on windows (no reported issues for the linux or mac builds and tests). The code piece I'm contributing with is an update of a reader/writer for a data format (GCF) and I suspect that the issue lies in my attempt to use pre-compiler macros to swap between the use of file i/o functions on linux/windows, basically:
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#include <windows.h>
#include <sys/types.h>
#include <inttypes.h>
#include <io.h>
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#ifndef O_RDONLY
#define O_RDONLY _O_RDONLY
#endif
#ifndef O_WRONLY
#define O_WRONLY _O_WRONLY
#endif
#ifndef O_CREAT
#define O_CREAT _O_CREAT
#endif
#ifndef O_TRUNC
#define O_TRUNC _O_TRUNC
#endif
#ifndef open
#define open(path, flags, mode) _open(path, flags, mode)
#endif
#ifndef close
#define close(fd) _close(fd)
#endif
#ifndef write
#define write(fd, buffer, count) _write(fd, buffer, count)
#endif
#ifndef read
#define read(fd, buffer, count) _write(fd, buffer, count)
#endif
#define FPERM _S_IWRITE
#else
#include <unistd.h>
#define FPERM S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
#endif
So I'm seeking advice on either how to improve this (if there are some obvious flaws with this approach) or if there is some appropriate (free) tools around that I can use locally on my linux machine to build in a windows environment and run the tests in order to pinpoint and fix the problem.
Solution 1:[1]
I've seen similar code in other projects, including the MSVC C library. The challenge this code faces is that it tries to mimick the POSIX API using the WinAPI, only using a handful of preprocessor macros. However, those APIs are very different the more you go into details.
My advise for you would be to provide a separate WinAPI implementation for low-level stuff instead of trying to shoe-horn the code into compiling on both systems. Instead, consider creating a common interface on a higher abstraction level.
Concerning the question about testing on Linux, you might be able to use a cross-compiler, e.g. mingw. That would at least cover the compilation part of it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ulrich Eckhardt |
