Sha256: a1e0aabaec051eba3d6ca99e0772342ff219550741b44478bc049174d850f3f2

Contents?: true

Size: 1.84 KB

Versions: 28

Compression:

Stored size: 1.84 KB

Contents

// Copyright (c) 2011 Peter Ohler. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for license details.

#ifndef OJ_ERR_H
#define OJ_ERR_H

#include <errno.h>
#include "ruby.h"

// Needed to silence 2.4.0 warnings.
#ifndef NORETURN
#define NORETURN(x) x
#endif

#define OJ_ERR_START		300

typedef enum {
    OJ_OK		= 0,
    OJ_ERR_MEMORY	= ENOMEM,
    OJ_ERR_PARSE	= OJ_ERR_START,
    OJ_ERR_READ,
    OJ_ERR_WRITE,
    OJ_ERR_OVERFLOW,
    OJ_ERR_ARG,
    OJ_ERR_TOO_MANY,
    OJ_ERR_TYPE,
    OJ_ERR_KEY,
    OJ_ABORT,
    OJ_ERR_LAST,
} ojStatus;

#define set_error(err, eclas, msg, json, current) \
    _oj_err_set_with_location(err, eclas, msg, json, current, FILE, LINE)

typedef struct _err {
    VALUE clas;
    char  msg[128];
} * Err;

extern VALUE oj_parse_error_class;

extern void oj_err_set(Err e, VALUE clas, const char *format, ...);
extern void _oj_err_set_with_location(Err         err,
                                      VALUE       eclas,
                                      const char *msg,
                                      const char *json,
                                      const char *current,
                                      const char *file,
                                      int         line);

NORETURN(extern void oj_err_raise(Err e));

#define raise_error(msg, json, current) _oj_raise_error(msg, json, current, __FILE__, __LINE__)

NORETURN(extern void _oj_raise_error(const char *msg,
                                     const char *json,
                                     const char *current,
                                     const char *file,
                                     int         line));

inline static void err_init(Err e) {
    e->clas = Qnil;
    *e->msg = '\0';
}

inline static int err_has(Err e) {
    return (Qnil != e->clas);
}

#endif /* OJ_ERR_H */

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/oj-3.13.2/ext/oj/err.h
oj-3.14.2 ext/oj/err.h
oj-3.14.1 ext/oj/err.h
oj-3.14.0 ext/oj/err.h
oj-3.13.23 ext/oj/err.h
oj-3.13.22 ext/oj/err.h
oj-3.13.21 ext/oj/err.h
oj-3.13.20 ext/oj/err.h
oj-3.13.19 ext/oj/err.h
oj-3.13.18 ext/oj/err.h
oj-3.13.17 ext/oj/err.h
oj-3.13.16 ext/oj/err.h
oj-3.13.15 ext/oj/err.h
oj-3.13.14 ext/oj/err.h
oj-3.13.13 ext/oj/err.h
oj-3.13.12 ext/oj/err.h
oj-3.13.11 ext/oj/err.h
oj-3.13.10 ext/oj/err.h
oj-3.13.9 ext/oj/err.h
oj-3.13.8 ext/oj/err.h