Commit 9ea53ec6 authored by Kirill Smelkov's avatar Kirill Smelkov

libgolang: Provide string as alias for std::string

std::string is frequently too cumbersome. Providing string in golang::
namespace allows to have a more closer feel of a Go environment after
`using namespace golang`.
parent cf96559c
......@@ -24,8 +24,7 @@
See also https://golang.org/pkg/errors for Go errors package documentation.
"""
from golang cimport error
from libcpp.string cimport string
from golang cimport error, string
cdef extern from "golang/errors.h" namespace "golang::errors" nogil:
error New(const string& text)
......@@ -46,7 +46,6 @@ In addition to Cython/nogil API, golang.pyx provides runtime for golang.py:
from libcpp cimport nullptr_t, nullptr as nil
from libcpp.utility cimport pair
from libcpp.string cimport string
from libc.stdint cimport uint64_t
cdef extern from *:
ctypedef bint cbool "bool"
......@@ -61,6 +60,7 @@ cdef extern from *:
#
# -> golang.pyx users need to add `except +topyexc` to their functions that are
# on the edge of Python/nogil world.
from libcpp.string cimport string # golang::string = std::string
cdef extern from "golang/libgolang.h" namespace "golang" nogil:
void panic(const char *)
const char *recover()
......
......@@ -21,7 +21,6 @@
// See errors.h for package overview.
#include "golang/errors.h"
using std::string;
// golang::errors::
......
......@@ -33,7 +33,7 @@ namespace golang {
namespace errors {
// New creates new error with provided text.
LIBGOLANG_API error New(const std::string& text);
LIBGOLANG_API error New(const string& text);
}} // golang::errors::
......
......@@ -298,12 +298,16 @@ LIBGOLANG_API extern void (*_tblockforever)(void);
#include <functional>
#include <initializer_list>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
namespace golang {
// string is alias for std::string.
using string = std::string;
// func is alias for std::function.
template<typename F>
using func = std::function<F>;
......@@ -713,7 +717,7 @@ typedef refptr<_interface> interface;
// error is the interface describing errors.
struct _error : _interface {
virtual std::string Error() = 0;
virtual string Error() = 0;
};
typedef refptr<_error> error;
......
......@@ -65,7 +65,7 @@ public:
LIBPYXRUNTIME_API void decref();
// error interface
std::string Error();
string Error();
private:
_PyError(const _PyError&); // don't copy
......
......@@ -25,9 +25,8 @@ Python/Cython runtimes that can be used from nogil code.
- `PyFunc` represents Python function that can be called from nogil code.
"""
from golang cimport error, _error, refptr, gobject
from golang cimport error, _error, refptr, gobject, string
from cpython cimport PyObject
from libcpp.string cimport string
cdef extern from "golang/pyx/runtime.h" namespace "golang::pyx::runtime" nogil:
......
......@@ -54,7 +54,6 @@ using std::bad_alloc;
using std::exception;
using std::max;
using std::numeric_limits;
using std::string;
using std::unique_ptr;
using std::vector;
......
......@@ -26,7 +26,6 @@
#include "golang/sync.h"
#include "golang/errors.h"
using namespace golang;
using std::string;
#include <utility>
using std::tuple;
......
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