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>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -27,6 +27,8 @@
#include "bigfile/_file_zodb.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) {
_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
tie(mmap, err) = fileh->mmap(blk, blklen, vma);
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;
}
......@@ -56,7 +58,7 @@ static int zfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) {
error err;
err = mmap->remmap_blk(blk);
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;
}
......@@ -74,7 +76,7 @@ static int zfile_munmap(VMA *vma, BigFile *file) {
error err;
err = mmap->unmap();
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;
}
......
......@@ -229,7 +229,7 @@ using std::min;
using std::max;
using std::vector;
namespace ioutil = io::ioutil;
namespace ioutil = xgolang::io::ioutil;
#define TRACE 0
......
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Copyright (C) 2018-2022 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -118,6 +118,10 @@ struct VMA;
namespace wcfs {
using namespace golang;
namespace os = xgolang::xos;
namespace mm = xgolang::xmm;
namespace xstrconv = xgolang::xstrconv;
namespace log = xgolang::xlog;
using cxx::dict;
using cxx::set;
using std::tuple;
......
......@@ -36,11 +36,13 @@ using namespace golang;
#include <algorithm>
#include <memory>
// golang::
namespace golang {
// xgolang::
namespace xgolang {
// os::
namespace os {
// xos::
namespace xos {
namespace io = golang::io;
global<error> ErrClosed = errors::New("file already closed");
......@@ -196,16 +198,16 @@ static string _sysErrString(int syserr) {
return string(estr);
}
} // os::
} // xos::
// mm::
namespace mm {
// xmm::
namespace xmm {
// map memory-maps f.fd[offset +size) somewhere into memory.
// prot is PROT_* from mmap(2).
// 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;
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
addr = ::mmap(nil, size, prot, flags, f->_sysfd(), offset);
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);
}
......@@ -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).
// prot is PROT_* from mmap(2).
// 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;
addr2 = ::mmap(addr, size, prot, MAP_FIXED | flags, f->_sysfd(), offset);
if (addr2 == MAP_FAILED)
return os::_pathError("mmap", f->Name(), errno);
return xos::_pathError("mmap", f->Name(), errno);
if (addr2 != addr)
panic("mmap(addr, MAP_FIXED): returned !addr");
return nil;
......@@ -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) {
int err = ::munmap(addr, size);
if (err != 0)
return os::_pathError("munmap", "<memory>", errno);
return xos::_pathError("munmap", "<memory>", errno);
return nil;
}
} // mm::
} // xmm::
// io::ioutil::
......@@ -249,10 +251,10 @@ namespace ioutil {
tuple<string, error> ReadFile(const string& path) {
// errctx is ok as returned by all calls.
os::File f;
error err;
xos::File f;
error err;
tie(f, err) = os::Open(path);
tie(f, err) = xos::Open(path);
if (err != nil)
return make_tuple("", err);
......@@ -264,7 +266,7 @@ tuple<string, error> ReadFile(const string& path) {
tie(n, err) = f->Read(&buf[0], buf.size());
data.append(&buf[0], n);
if (err != nil) {
if (err == io::EOF_)
if (err == golang::io::EOF_)
err = nil;
break;
}
......@@ -318,7 +320,7 @@ tuple<uint64_t, error> parseUint(const string& s) {
} // xstrconv::
} // golang::
} // xgolang::
// xerr::
......@@ -354,9 +356,9 @@ error Contextf::operator() (error err) const {
#include <sys/types.h>
#include <sys/syscall.h>
// golang::log::
namespace golang {
namespace log {
// xgolang::xlog::
namespace xgolang {
namespace xlog {
void __Logf(const char *file, int line, char level, const char *format, ...) {
double t = time::now();
......@@ -385,7 +387,7 @@ void __Logf(const char *file, int line, char level, const char *format, ...) {
funlockfile(stderr);
}
}} // golang::log::
}} // xgolang::xlog::
// wcfs::
......
......@@ -55,11 +55,11 @@ using std::vector;
#include <sys/stat.h>
#include <fcntl.h>
// golang::
namespace golang {
// xgolang::
namespace xgolang {
// os::
namespace os {
// xos::
namespace xos {
extern global<error> ErrClosed;
......@@ -126,15 +126,15 @@ void RegisterAfterFork(IAfterFork obj);
// It is noop if obj was not registered.
void UnregisterAfterFork(IAfterFork obj);
} // os::
} // xos::
// mm::
namespace mm {
tuple<uint8_t*, error> map(int prot, int flags, os::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);
// xmm::
namespace xmm {
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, xos::File f, off_t offset);
error unmap(void *addr, size_t size);
} // mm::
} // xmm::
// io::ioutil::
......@@ -157,8 +157,8 @@ tuple<uint64_t, error> parseUint(const string& s);
} // xstrconv::
// log::
namespace log {
// xlog::
namespace xlog {
#define Debugf(format, ...) __Logf(__FILE__, __LINE__, 'D', format, ##__VA_ARGS__)
#define Infof(format, ...) __Logf(__FILE__, __LINE__, 'I', format, ##__VA_ARGS__)
......@@ -167,9 +167,9 @@ namespace log {
#define Fatalf(format, ...) __Logf(__FILE__, __LINE__, 'F', format, ##__VA_ARGS__)
void __Logf(const char *file, int line, char level, const char *format, ...);
} // log::
} // xlog::
} // golang::
} // xgolang::
// 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