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