Commit 11e023cf authored by Kirill Smelkov's avatar Kirill Smelkov

wcfs: client: Adjust to be forward-compatible with upcoming pygolang changes

Don't use golang::* namespaces to avoid clashes with pygolang adding
something in there and getting compilation error due to conflict, when
e.g. nexedi/pygolang!17 lands.

-> use xgolang:: as top-level namespace for what was previously living
in golang:: shipped in wendelin.core.

Inside that xgolang:: namespace don't use the same package names that
might be used inside golang:: in pygolang. This avoids ambiguation and
compile error in the future on e.g. os::AfterFork - is `using namespace
golang` and `using namespace xgolang` were both activated.

-> Prefix all namespaces inside xgolang:: also with "x".
parent 493ac6ce
// Copyright (C) 2019-2021 Nexedi SA and Contributors. // Copyright (C) 2019-2022 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
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "bigfile/_file_zodb.h" #include "bigfile/_file_zodb.h"
#include <ccan/container_of/container_of.h> #include <ccan/container_of/container_of.h>
using namespace xgolang;
static int zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blklen) { static int zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blklen) {
_ZBigFile* _zfile = container_of(file, _ZBigFile, __pyx_base.file); _ZBigFile* _zfile = container_of(file, _ZBigFile, __pyx_base.file);
...@@ -39,7 +41,7 @@ static int zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blkl ...@@ -39,7 +41,7 @@ static int zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blkl
tie(mmap, err) = fileh->mmap(blk, blklen, vma); tie(mmap, err) = fileh->mmap(blk, blklen, vma);
if (err != nil) { if (err != nil) {
log::Errorf("%s", v(err)); // XXX no way to return error details to virtmem xlog::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
return -1; return -1;
} }
...@@ -56,7 +58,7 @@ static int zfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) { ...@@ -56,7 +58,7 @@ static int zfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) {
error err; error err;
err = mmap->remmap_blk(blk); err = mmap->remmap_blk(blk);
if (err != nil) { if (err != nil) {
log::Errorf("%s", v(err)); // XXX no way to return error details to virtmem xlog::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
return -1; return -1;
} }
...@@ -74,7 +76,7 @@ static int zfile_munmap(VMA *vma, BigFile *file) { ...@@ -74,7 +76,7 @@ static int zfile_munmap(VMA *vma, BigFile *file) {
error err; error err;
err = mmap->unmap(); err = mmap->unmap();
if (err != nil) { if (err != nil) {
log::Errorf("%s", v(err)); // XXX no way to return error details to virtmem xlog::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
return -1; return -1;
} }
......
...@@ -229,7 +229,7 @@ using std::min; ...@@ -229,7 +229,7 @@ using std::min;
using std::max; using std::max;
using std::vector; using std::vector;
namespace ioutil = io::ioutil; namespace ioutil = xgolang::io::ioutil;
#define TRACE 0 #define TRACE 0
......
// Copyright (C) 2018-2021 Nexedi SA and Contributors. // Copyright (C) 2018-2022 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
...@@ -118,6 +118,10 @@ struct VMA; ...@@ -118,6 +118,10 @@ struct VMA;
namespace wcfs { namespace wcfs {
using namespace golang; using namespace golang;
namespace os = xgolang::xos;
namespace mm = xgolang::xmm;
namespace xstrconv = xgolang::xstrconv;
namespace log = xgolang::xlog;
using cxx::dict; using cxx::dict;
using cxx::set; using cxx::set;
using std::tuple; using std::tuple;
......
...@@ -36,11 +36,13 @@ using namespace golang; ...@@ -36,11 +36,13 @@ using namespace golang;
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
// golang:: // xgolang::
namespace golang { namespace xgolang {
// os:: // xos::
namespace os { namespace xos {
namespace io = golang::io;
global<error> ErrClosed = errors::New("file already closed"); global<error> ErrClosed = errors::New("file already closed");
...@@ -196,16 +198,16 @@ static string _sysErrString(int syserr) { ...@@ -196,16 +198,16 @@ static string _sysErrString(int syserr) {
return string(estr); return string(estr);
} }
} // os:: } // xos::
// mm:: // xmm::
namespace mm { namespace xmm {
// map memory-maps f.fd[offset +size) somewhere into memory. // map memory-maps f.fd[offset +size) somewhere into memory.
// prot is PROT_* from mmap(2). // prot is PROT_* from mmap(2).
// flags is MAP_* from mmap(2); MAP_FIXED must not be used. // flags is MAP_* from mmap(2); MAP_FIXED must not be used.
tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t size) { tuple<uint8_t*, error> map(int prot, int flags, xos::File f, off_t offset, size_t size) {
void *addr; void *addr;
if (flags & MAP_FIXED) if (flags & MAP_FIXED)
...@@ -213,7 +215,7 @@ tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t ...@@ -213,7 +215,7 @@ tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t
addr = ::mmap(nil, size, prot, flags, f->_sysfd(), offset); addr = ::mmap(nil, size, prot, flags, f->_sysfd(), offset);
if (addr == MAP_FAILED) if (addr == MAP_FAILED)
return make_tuple(nil, os::_pathError("mmap", f->Name(), errno)); return make_tuple(nil, xos::_pathError("mmap", f->Name(), errno));
return make_tuple((uint8_t*)addr, nil); return make_tuple((uint8_t*)addr, nil);
} }
...@@ -221,12 +223,12 @@ tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t ...@@ -221,12 +223,12 @@ tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t
// map_into memory-maps f.fd[offset +size) into [addr +size). // map_into memory-maps f.fd[offset +size) into [addr +size).
// prot is PROT_* from mmap(2). // prot is PROT_* from mmap(2).
// flags is MAP_* from mmap(2); MAP_FIXED is added automatically. // flags is MAP_* from mmap(2); MAP_FIXED is added automatically.
error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t offset) { error map_into(void *addr, size_t size, int prot, int flags, xos::File f, off_t offset) {
void *addr2; void *addr2;
addr2 = ::mmap(addr, size, prot, MAP_FIXED | flags, f->_sysfd(), offset); addr2 = ::mmap(addr, size, prot, MAP_FIXED | flags, f->_sysfd(), offset);
if (addr2 == MAP_FAILED) if (addr2 == MAP_FAILED)
return os::_pathError("mmap", f->Name(), errno); return xos::_pathError("mmap", f->Name(), errno);
if (addr2 != addr) if (addr2 != addr)
panic("mmap(addr, MAP_FIXED): returned !addr"); panic("mmap(addr, MAP_FIXED): returned !addr");
return nil; return nil;
...@@ -236,11 +238,11 @@ error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t o ...@@ -236,11 +238,11 @@ error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t o
error unmap(void *addr, size_t size) { error unmap(void *addr, size_t size) {
int err = ::munmap(addr, size); int err = ::munmap(addr, size);
if (err != 0) if (err != 0)
return os::_pathError("munmap", "<memory>", errno); return xos::_pathError("munmap", "<memory>", errno);
return nil; return nil;
} }
} // mm:: } // xmm::
// io::ioutil:: // io::ioutil::
...@@ -249,10 +251,10 @@ namespace ioutil { ...@@ -249,10 +251,10 @@ namespace ioutil {
tuple<string, error> ReadFile(const string& path) { tuple<string, error> ReadFile(const string& path) {
// errctx is ok as returned by all calls. // errctx is ok as returned by all calls.
os::File f; xos::File f;
error err; error err;
tie(f, err) = os::Open(path); tie(f, err) = xos::Open(path);
if (err != nil) if (err != nil)
return make_tuple("", err); return make_tuple("", err);
...@@ -264,7 +266,7 @@ tuple<string, error> ReadFile(const string& path) { ...@@ -264,7 +266,7 @@ tuple<string, error> ReadFile(const string& path) {
tie(n, err) = f->Read(&buf[0], buf.size()); tie(n, err) = f->Read(&buf[0], buf.size());
data.append(&buf[0], n); data.append(&buf[0], n);
if (err != nil) { if (err != nil) {
if (err == io::EOF_) if (err == golang::io::EOF_)
err = nil; err = nil;
break; break;
} }
...@@ -318,7 +320,7 @@ tuple<uint64_t, error> parseUint(const string& s) { ...@@ -318,7 +320,7 @@ tuple<uint64_t, error> parseUint(const string& s) {
} // xstrconv:: } // xstrconv::
} // golang:: } // xgolang::
// xerr:: // xerr::
...@@ -354,9 +356,9 @@ error Contextf::operator() (error err) const { ...@@ -354,9 +356,9 @@ error Contextf::operator() (error err) const {
#include <sys/types.h> #include <sys/types.h>
#include <sys/syscall.h> #include <sys/syscall.h>
// golang::log:: // xgolang::xlog::
namespace golang { namespace xgolang {
namespace log { namespace xlog {
void __Logf(const char *file, int line, char level, const char *format, ...) { void __Logf(const char *file, int line, char level, const char *format, ...) {
double t = time::now(); double t = time::now();
...@@ -385,7 +387,7 @@ void __Logf(const char *file, int line, char level, const char *format, ...) { ...@@ -385,7 +387,7 @@ void __Logf(const char *file, int line, char level, const char *format, ...) {
funlockfile(stderr); funlockfile(stderr);
} }
}} // golang::log:: }} // xgolang::xlog::
// wcfs:: // wcfs::
......
...@@ -55,11 +55,11 @@ using std::vector; ...@@ -55,11 +55,11 @@ using std::vector;
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
// golang:: // xgolang::
namespace golang { namespace xgolang {
// os:: // xos::
namespace os { namespace xos {
extern global<error> ErrClosed; extern global<error> ErrClosed;
...@@ -126,15 +126,15 @@ void RegisterAfterFork(IAfterFork obj); ...@@ -126,15 +126,15 @@ void RegisterAfterFork(IAfterFork obj);
// It is noop if obj was not registered. // It is noop if obj was not registered.
void UnregisterAfterFork(IAfterFork obj); void UnregisterAfterFork(IAfterFork obj);
} // os:: } // xos::
// mm:: // xmm::
namespace mm { namespace xmm {
tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t size); tuple<uint8_t*, error> map(int prot, int flags, xos::File f, off_t offset, size_t size);
error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t offset); error map_into(void *addr, size_t size, int prot, int flags, xos::File f, off_t offset);
error unmap(void *addr, size_t size); error unmap(void *addr, size_t size);
} // mm:: } // xmm::
// io::ioutil:: // io::ioutil::
...@@ -157,8 +157,8 @@ tuple<uint64_t, error> parseUint(const string& s); ...@@ -157,8 +157,8 @@ tuple<uint64_t, error> parseUint(const string& s);
} // xstrconv:: } // xstrconv::
// log:: // xlog::
namespace log { namespace xlog {
#define Debugf(format, ...) __Logf(__FILE__, __LINE__, 'D', format, ##__VA_ARGS__) #define Debugf(format, ...) __Logf(__FILE__, __LINE__, 'D', format, ##__VA_ARGS__)
#define Infof(format, ...) __Logf(__FILE__, __LINE__, 'I', format, ##__VA_ARGS__) #define Infof(format, ...) __Logf(__FILE__, __LINE__, 'I', format, ##__VA_ARGS__)
...@@ -167,9 +167,9 @@ namespace log { ...@@ -167,9 +167,9 @@ namespace log {
#define Fatalf(format, ...) __Logf(__FILE__, __LINE__, 'F', format, ##__VA_ARGS__) #define Fatalf(format, ...) __Logf(__FILE__, __LINE__, 'F', format, ##__VA_ARGS__)
void __Logf(const char *file, int line, char level, const char *format, ...); void __Logf(const char *file, int line, char level, const char *format, ...);
} // log:: } // xlog::
} // golang:: } // xgolang::
// zodb:: // zodb::
......
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