diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-16 08:25:47 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-17 08:05:44 -0300 |
commit | a8b0c9e576e9c0155546b03944314449d3f1a5c3 (patch) | |
tree | f81e15b8d2280c3035ef474b065ea4d6f88b0b3d /src | |
parent | b7108002bb7ac910bf9c88596d1075ce9bc9f0a7 (diff) | |
download | rneovim-a8b0c9e576e9c0155546b03944314449d3f1a5c3.tar.gz rneovim-a8b0c9e576e9c0155546b03944314449d3f1a5c3.tar.bz2 rneovim-a8b0c9e576e9c0155546b03944314449d3f1a5c3.zip |
Refactor API to use one integer type: int64_t
This should make the API simpler, and int64_t is enough to represent any integer
value we might need.
Range checks should be done inside the API functions, that way we can modify the
types of the actual fields/variables modified by the API without changes to the
API prototypes.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/defs.h | 8 | ||||
-rw-r--r-- | src/nvim/os/msgpack_rpc.c | 39 |
2 files changed, 20 insertions, 27 deletions
diff --git a/src/nvim/api/defs.h b/src/nvim/api/defs.h index d451667a6c..914ff3c5d5 100644 --- a/src/nvim/api/defs.h +++ b/src/nvim/api/defs.h @@ -15,9 +15,9 @@ typedef struct { size_t size; } String; -typedef uint16_t Buffer; -typedef uint16_t Window; -typedef uint16_t Tabpage; +typedef int64_t Buffer; +typedef int64_t Window; +typedef int64_t Tabpage; typedef struct object Object; @@ -27,7 +27,7 @@ typedef struct { } StringArray; typedef struct { - uint16_t row, col; + int64_t row, col; } Position; typedef struct { diff --git a/src/nvim/os/msgpack_rpc.c b/src/nvim/os/msgpack_rpc.c index 3ce0d7b63c..4e14373b88 100644 --- a/src/nvim/os/msgpack_rpc.c +++ b/src/nvim/os/msgpack_rpc.c @@ -4,8 +4,6 @@ #include "nvim/vim.h" #include "nvim/memory.h" -static bool msgpack_rpc_to_uint16_t(msgpack_object *obj, uint16_t *arg); - void msgpack_rpc_call(msgpack_object *req, msgpack_packer *res) { // The initial response structure is the same no matter what happens, @@ -83,9 +81,15 @@ bool msgpack_rpc_to_bool(msgpack_object *obj, bool *arg) bool msgpack_rpc_to_int64_t(msgpack_object *obj, int64_t *arg) { + + if (obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER + && obj->via.u64 <= INT64_MAX) { + *arg = obj->via.u64; + return true; + } + *arg = obj->via.i64; - return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER - || obj->type == MSGPACK_OBJECT_NEGATIVE_INTEGER; + return obj->type == MSGPACK_OBJECT_NEGATIVE_INTEGER; } bool msgpack_rpc_to_double(msgpack_object *obj, double *arg) @@ -103,17 +107,17 @@ bool msgpack_rpc_to_string(msgpack_object *obj, String *arg) bool msgpack_rpc_to_buffer(msgpack_object *obj, Buffer *arg) { - return msgpack_rpc_to_uint16_t(obj, arg); + return msgpack_rpc_to_int64_t(obj, arg); } bool msgpack_rpc_to_window(msgpack_object *obj, Window *arg) { - return msgpack_rpc_to_uint16_t(obj, arg); + return msgpack_rpc_to_int64_t(obj, arg); } bool msgpack_rpc_to_tabpage(msgpack_object *obj, Tabpage *arg) { - return msgpack_rpc_to_uint16_t(obj, arg); + return msgpack_rpc_to_int64_t(obj, arg); } bool msgpack_rpc_to_object(msgpack_object *obj, Object *arg) @@ -245,11 +249,6 @@ void msgpack_rpc_from_int64_t(int64_t result, msgpack_packer *res) msgpack_pack_int64(res, result); } -void msgpack_rpc_from_uint64_t(uint64_t result, msgpack_packer *res) -{ - msgpack_pack_uint64(res, result); -} - void msgpack_rpc_from_double(double result, msgpack_packer *res) { msgpack_pack_double(res, result); @@ -263,17 +262,17 @@ void msgpack_rpc_from_string(String result, msgpack_packer *res) void msgpack_rpc_from_buffer(Buffer result, msgpack_packer *res) { - msgpack_rpc_from_uint64_t(result, res); + msgpack_rpc_from_int64_t(result, res); } void msgpack_rpc_from_window(Window result, msgpack_packer *res) { - msgpack_rpc_from_uint64_t(result, res); + msgpack_rpc_from_int64_t(result, res); } void msgpack_rpc_from_tabpage(Tabpage result, msgpack_packer *res) { - msgpack_rpc_from_uint64_t(result, res); + msgpack_rpc_from_int64_t(result, res); } void msgpack_rpc_from_object(Object result, msgpack_packer *res) @@ -324,8 +323,8 @@ void msgpack_rpc_from_stringarray(StringArray result, msgpack_packer *res) void msgpack_rpc_from_position(Position result, msgpack_packer *res) { msgpack_pack_array(res, 2);; - msgpack_pack_uint16(res, result.row); - msgpack_pack_uint16(res, result.col); + msgpack_pack_int64(res, result.row); + msgpack_pack_int64(res, result.col); } void msgpack_rpc_from_array(Array result, msgpack_packer *res) @@ -400,9 +399,3 @@ void msgpack_rpc_free_dictionary(Dictionary value) free(value.items); } -static bool msgpack_rpc_to_uint16_t(msgpack_object *obj, uint16_t *arg) -{ - *arg = obj->via.u64; - return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER; -} - |