Commit 35ed2492 authored by Kirill Smelkov's avatar Kirill Smelkov

libgolang: Provide custom bzero, mode_t and unistd.h on MSVC

We need unistd.h because e.g. `cimport posix.stat` forces inclusion of unistd.h
even if we use part of posix.stat that is available everywhere.

We use bzero in libgolang.cpp - provide it in similar way via compat
strings.h because on windows there is only string.h (no "s" in the end).

We also use mode_t in several places - provide it via typedef in
libgolang.h directly, because fcntl.h is present on MSVC.
parent 5f107215
...@@ -34,6 +34,8 @@ include golang/sync_test.cpp ...@@ -34,6 +34,8 @@ include golang/sync_test.cpp
include golang/time.h include golang/time.h
include golang/time.cpp include golang/time.cpp
include golang/_testing.h include golang/_testing.h
include golang/_compat/windows/strings.h
include golang/_compat/windows/unistd.h
recursive-include golang *.py *.pxd *.pyx *.toml *.txt* recursive-include golang *.py *.pxd *.pyx *.toml *.txt*
recursive-include gpython *.py recursive-include gpython *.py
recursive-include 3rdparty *.h recursive-include 3rdparty *.h
......
#ifndef _NXD_LIBGOLANG_COMPAT_WIN_STRINGS_H
#define _NXD_LIBGOLANG_COMPAT_WIN_STRINGS_H
//
// Copyright (C) 2023 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
#include <string.h>
static inline void bzero(void *p, size_t n) {
memset(p, '\0', n);
}
#endif // _NXD_LIBGOLANG_COMPAT_WIN_STRINGS_H
#ifndef _NXD_LIBGOLANG_COMPAT_WIN_UNISTD_H
#define _NXD_LIBGOLANG_COMPAT_WIN_UNISTD_H
//
// Copyright (C) 2023 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// stub unistd.h to be used on Windows where it is absent.
// we need this because e.g. `cimport posix.stat` forces inclusion of unistd.h
// even if we use part of posix.stat that is available everywhere.
#include <io.h>
#endif // _NXD_LIBGOLANG_COMPAT_WIN_UNISTD_H
...@@ -176,6 +176,12 @@ ...@@ -176,6 +176,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h>
#ifdef _MSC_VER // no mode_t on msvc
typedef int mode_t;
#endif
// DSO symbols visibility (based on https://gcc.gnu.org/wiki/Visibility) // DSO symbols visibility (based on https://gcc.gnu.org/wiki/Visibility)
#if defined _WIN32 || defined __CYGWIN__ #if defined _WIN32 || defined __CYGWIN__
#define LIBGOLANG_DSO_EXPORT __declspec(dllexport) #define LIBGOLANG_DSO_EXPORT __declspec(dllexport)
......
...@@ -170,8 +170,10 @@ def _with_build_defaults(name, kw): # -> (pygo, kw') ...@@ -170,8 +170,10 @@ def _with_build_defaults(name, kw): # -> (pygo, kw')
msvc = win # TODO also support mingw ? msvc = win # TODO also support mingw ?
# prepend -I<pygolang> so that e.g. golang/libgolang.h is found # prepend -I<pygolang> so that e.g. golang/libgolang.h is found
# same with -I<pygolang>/golang/_compat/<os>
incv = kw.get('include_dirs', [])[:] incv = kw.get('include_dirs', [])[:]
incv.insert(0, pygo) incv.insert(0, pygo)
incv.insert(1, join(pygo, 'golang', '_compat', sysname))
kw['include_dirs'] = incv kw['include_dirs'] = incv
# link with libgolang.so if it is not libgolang itself # link with libgolang.so if it is not libgolang itself
...@@ -225,6 +227,8 @@ def _with_build_defaults(name, kw): # -> (pygo, kw') ...@@ -225,6 +227,8 @@ def _with_build_defaults(name, kw): # -> (pygo, kw')
'os/signal.h', 'os/signal.h',
'pyx/runtime.h', 'pyx/runtime.h',
'_testing.h', '_testing.h',
'_compat/windows/strings.h',
'_compat/windows/unistd.h',
]]) ]])
kw['depends'] = dependv kw['depends'] = dependv
......
// Copyright (C) 2018-2022 Nexedi SA and Contributors. // Copyright (C) 2018-2023 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strings.h>
// linux/list.h needs ARRAY_SIZE XXX -> better use c.h or ccan/array_size.h ? // linux/list.h needs ARRAY_SIZE XXX -> better use c.h or ccan/array_size.h ?
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment