예제 #1
0
파일: jdtest.c 프로젝트: AndyA/emitron
int main(void) {
  try {
    JD_2VARS(a, b);
    jd_set_string(a, "This is A");
    jd_throw("Oops: a=%J", a);
    jd_set_bool(b, 1);
  }
  puts("cleanup");
  catch (e) jd_rethrow(e);
예제 #2
0
파일: exception.c 프로젝트: nevali/jsondata
static void test_simple_throw(void) {
  try {
    JD_2VARS(a, b);
    jd_set_string(a, "This is A");
    jd_throw("Oops: a=%J", a);
    jd_set_bool(b, 1);
  }
  catch (e) {
    jdt_is_string(jd_rv(e, "$.message"),
                  "Oops: a=\"This is A\"",
                  "exception message matches");
    jd_release(e);
  }
}
예제 #3
0
파일: jd_path.c 프로젝트: AndyA/emitron
jd_var *jd_get_context(jd_var *root, jd_var *path,
                       jd_path_context *ctx, int vivify) {
  jd_var *ptr = NULL;

  JD_SCOPE {
    JD_2VARS(part, elt);

    if (path->type == ARRAY)
      jd_clone(part, path, 0);
    else
      jd_split(part, path, jd_nsv("."));

    if (!jd_shift(part, 1, elt) || jd_compare(elt, jd_nsv("$")))
      jd_throw("Bad path");

    for (ptr = root; ptr && jd_shift(part, 1, elt);) {
      if (ptr->type == VOID) {
        /* empty slot: type depends on key format */
        if (is_positive_int(elt))
          jd_set_array(ptr, 1);
        else
          jd_set_hash(ptr, 1);
      }

      if (ptr->type == ARRAY) {
        size_t ac = jd_count(ptr);
        jd_int ix = jd_get_int(elt);
        if (ix == ac && vivify)
          ptr = jd_push(ptr, 1);
        else if (ix < ac)
          ptr = jd_get_idx(ptr, ix);
        else {
          ptr = NULL;
        }
      }
      else if (ptr->type == HASH) {
        ptr = jd_get_key(ptr, elt, vivify);
      }
      else {
        jd_throw("Unexpected element in structure");
      }
    }
  }

  return ptr;
}