You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 line
1.0 KiB

  1. #include "jiffy.h"
  2. static int
  3. load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
  4. {
  5. jiffy_st* st = enif_alloc(sizeof(jiffy_st));
  6. if(st == NULL) {
  7. return 1;
  8. }
  9. st->atom_ok = make_atom(env, "ok");
  10. st->atom_error = make_atom(env, "error");
  11. st->atom_null = make_atom(env, "null");
  12. st->atom_true = make_atom(env, "true");
  13. st->atom_false = make_atom(env, "false");
  14. st->atom_bignum = make_atom(env, "bignum");
  15. st->ref_object = enif_make_ref(env);
  16. st->ref_array = enif_make_ref(env);
  17. *priv = (void*) st;
  18. return 0;
  19. }
  20. static int
  21. reload(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
  22. {
  23. return 0;
  24. }
  25. static int
  26. upgrade(ErlNifEnv* env, void** priv, void** old_priv, ERL_NIF_TERM info)
  27. {
  28. *priv = *old_priv;
  29. return 0;
  30. }
  31. static void
  32. unload(ErlNifEnv* env, void* priv)
  33. {
  34. enif_free(priv);
  35. return;
  36. }
  37. static ErlNifFunc funcs[] =
  38. {
  39. {"nif_decode", 1, decode},
  40. {"nif_encode", 1, encode}
  41. };
  42. ERL_NIF_INIT(jiffy, funcs, &load, &reload, &upgrade, &unload);