Files
neovim/src/nvim/api/private/defs.h
James McCoy 37e64d79cc object_to_vim: Fix buffer/window/tabpage conversion on BE systems
Since data.integer is a different (larger) integer type than
data.{buffer,window,tabpage}, we cannot abuse the union by using
data.integer to access the value for all 4 types.  Instead, remove the
{buffer,window,tabpage} members and always use the integer member.

In order to accomodate this, perform distinct validation and coercion
between the Integer type and Buffer/Window/Tabpage types in
object_to_vim, msgpack_rpc helpers, and gendispatch.lua.
2016-11-02 10:06:27 -04:00

110 lines
2.0 KiB
C

#ifndef NVIM_API_PRIVATE_DEFS_H
#define NVIM_API_PRIVATE_DEFS_H
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
#define STRING_INIT {.data = NULL, .size = 0}
#define OBJECT_INIT { .type = kObjectTypeNil }
#define ERROR_INIT { .set = false }
#define REMOTE_TYPE(type) typedef handle_T type
#ifdef INCLUDE_GENERATED_DECLARATIONS
# define ArrayOf(...) Array
# define DictionaryOf(...) Dictionary
#endif
typedef int handle_T;
// Basic types
typedef enum {
kErrorTypeException,
kErrorTypeValidation
} ErrorType;
typedef enum {
kMessageTypeRequest,
kMessageTypeResponse,
kMessageTypeNotification
} MessageType;
/// Used as the message ID of notifications.
#define NO_RESPONSE UINT64_MAX
/// Used as channel_id when the call is local.
#define INTERNAL_CALL UINT64_MAX
typedef struct {
ErrorType type;
char msg[1024];
bool set;
} Error;
typedef bool Boolean;
typedef int64_t Integer;
typedef double Float;
/// Maximum value of an Integer
#define API_INTEGER_MAX INT64_MAX
/// Minimum value of an Integer
#define API_INTEGER_MIN INT64_MIN
typedef struct {
char *data;
size_t size;
} String;
REMOTE_TYPE(Buffer);
REMOTE_TYPE(Window);
REMOTE_TYPE(Tabpage);
typedef struct object Object;
typedef struct {
Object *items;
size_t size, capacity;
} Array;
typedef struct key_value_pair KeyValuePair;
typedef struct {
KeyValuePair *items;
size_t size, capacity;
} Dictionary;
typedef enum {
kObjectTypeBuffer,
kObjectTypeWindow,
kObjectTypeTabpage,
kObjectTypeNil,
kObjectTypeBoolean,
kObjectTypeInteger,
kObjectTypeFloat,
kObjectTypeString,
kObjectTypeArray,
kObjectTypeDictionary,
} ObjectType;
struct object {
ObjectType type;
union {
Boolean boolean;
Integer integer;
Float floating;
String string;
Array array;
Dictionary dictionary;
} data;
};
struct key_value_pair {
String key;
Object value;
};
#endif // NVIM_API_PRIVATE_DEFS_H