Commit a245ab56 authored by Kirill Smelkov's avatar Kirill Smelkov

errors: New package

With just one function - errors.New() - to create new error with given
text.

This will be soon used in Pyx/nogil context package to create context.canceled
and context.deadlineExceeded errors.

Pyx/nogil only for now.
parent 5a99b769
include COPYING README.rst CHANGELOG.rst tox.ini pyproject.toml trun include COPYING README.rst CHANGELOG.rst tox.ini pyproject.toml trun
include golang/libgolang.h include golang/libgolang.h
include golang/runtime/libgolang.cpp include golang/runtime/libgolang.cpp
include golang/errors.h
include golang/errors.cpp
include golang/sync.h include golang/sync.h
include golang/sync.cpp include golang/sync.cpp
include golang/time.h include golang/time.h
......
# cython: language_level=2
# Copyright (C) 2019 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.
"""Package errors mirrors Go package errors.
- `New` creates new error with provided text.
See also https://golang.org/pkg/errors for Go errors package documentation.
"""
from golang cimport error
from libcpp.string cimport string
cdef extern from "golang/errors.h" namespace "golang::errors" nogil:
error New(const string& text)
// Copyright (C) 2019 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.
// Package errors mirrors Go package errors.
// See errors.h for package overview.
#include "golang/errors.h"
using std::string;
// golang::errors::
namespace golang {
namespace errors {
// _TextError implements error with text string created by New.
struct _TextError final : _error, object {
string _text;
void incref() {
object::incref();
}
void decref() {
if (__decref())
delete this;
}
~_TextError() {}
_TextError(const string& text) : _text(text) {}
string Error() {
return _text;
}
};
error New(const string& text) {
return adoptref(static_cast<_error*>(new _TextError(text)));
}
}} // golang::errors::
#ifndef _NXD_LIBGOLANG_ERRORS_H
#define _NXD_LIBGOLANG_ERRORS_H
// Copyright (C) 2019 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.
// Package errors mirrors Go package errors.
//
// - `New` creates new error with provided text.
//
// See also https://golang.org/pkg/errors for Go errors package documentation.
#include <golang/libgolang.h>
// golang::errors::
namespace golang {
namespace errors {
// New creates new error with provided text.
LIBGOLANG_API error New(const std::string& text);
}} // golang::errors::
#endif // _NXD_LIBGOLANG_ERRORS_H
# cython: language_level=2
# Copyright (C) 2019 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.
"""Package errors mirrors Go package errors.
See _errors.pxd for package documentation.
"""
# redirect cimport: golang.errors -> golang._errors (see __init__.pxd for rationale)
from golang._errors cimport *
...@@ -166,6 +166,9 @@ def Extension(name, sources, **kw): ...@@ -166,6 +166,9 @@ def Extension(name, sources, **kw):
dependv.append('%s/golang/libgolang.h' % pygo) dependv.append('%s/golang/libgolang.h' % pygo)
dependv.append('%s/golang/_golang.pxd' % pygo) dependv.append('%s/golang/_golang.pxd' % pygo)
dependv.append('%s/golang/__init__.pxd' % pygo) dependv.append('%s/golang/__init__.pxd' % pygo)
dependv.append('%s/golang/errors.h' % pygo)
dependv.append('%s/golang/errors.pxd' % pygo)
dependv.append('%s/golang/_errors.pxd' % pygo)
dependv.append('%s/golang/sync.h' % pygo) dependv.append('%s/golang/sync.h' % pygo)
dependv.append('%s/golang/sync.pxd' % pygo) dependv.append('%s/golang/sync.pxd' % pygo)
dependv.append('%s/golang/_sync.pxd' % pygo) dependv.append('%s/golang/_sync.pxd' % pygo)
......
...@@ -193,10 +193,12 @@ setup( ...@@ -193,10 +193,12 @@ setup(
x_dsos = [DSO('golang.runtime.libgolang', x_dsos = [DSO('golang.runtime.libgolang',
['golang/runtime/libgolang.cpp', ['golang/runtime/libgolang.cpp',
'golang/errors.cpp',
'golang/sync.cpp', 'golang/sync.cpp',
'golang/time.cpp'], 'golang/time.cpp'],
depends = [ depends = [
'golang/libgolang.h', 'golang/libgolang.h',
'golang/errors.h',
'golang/sync.h', 'golang/sync.h',
'golang/time.h'], 'golang/time.h'],
include_dirs = ['.', '3rdparty/include'], include_dirs = ['.', '3rdparty/include'],
......
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