• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ erl_free_term函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中erl_free_term函数的典型用法代码示例。如果您正苦于以下问题:C++ erl_free_term函数的具体用法?C++ erl_free_term怎么用?C++ erl_free_term使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了erl_free_term函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: new_image_blank

ETERM * new_image_blank(ETERM *arg, int c_node) { 
    int stride, cbufsize, status, key_length;
    ETERM *width, *height;
    cairo_context *ctx = NULL;             
    width = erl_element(1, arg);
    height = erl_element(2, arg);
    stride = ERL_INT_VALUE(width) * 4;
    cbufsize = ERL_INT_VALUE(height) * stride;
    ctx = malloc(sizeof(cairo_context));
    if (ctx) {
        ctx->cbuf = (byte *)malloc(cbufsize);
        if (ctx->cbuf) {
            memset(ctx->cbuf, 0, cbufsize);
            ctx->sf = cairo_image_surface_create_for_data(ctx->cbuf, 
                    CAIRO_FORMAT_ARGB32, ERL_INT_VALUE(width), 
                    ERL_INT_VALUE(height), stride);
            ctx->cr = cairo_create(ctx->sf);
            return erl_format("{c_node, ~i, {ok, ~i}}", c_node, ctx);
        } else {
            free(ctx);
            return erl_format("{c_node, ~i, {error, '~s'}}", c_node, ERR_CONTEXT);
        }
    } else {
        return erl_format("{c_node, ~i, {error, '~s'}}", c_node, ERR_CONTEXT);
    }
    erl_free_term(width);
    erl_free_term(height);
}
开发者ID:chinnurtb,项目名称:erlycairo,代码行数:28,代码来源:erlycairo.c


示例2: handle_prev

void
handle_prev(ETERM *msg)
{
  ETERM *ecols, *erows, *resp;

  if (results == NULL) {
    resp = erl_format("{error, result_set_does_not_exist}");
    write_msg(resp);
    erl_free_term(resp);

    return;
  }

  ecols = make_cols();
  if (resultoffset <= 1) {
    resp = erl_format("{selected, ~w, []}", ecols);
  } else {
    resultoffset--;
    mysql_stmt_data_seek(sth, resultoffset - 1);
    erows = make_rows(1);
    resp = erl_format("{selected, ~w, ~w}", ecols, erows);
    erl_free_term(erows);
  }

  erl_free_term(ecols);
  write_msg(resp);
  erl_free_term(resp);
}
开发者ID:bjc,项目名称:mysqlerl,代码行数:28,代码来源:mysqlerl.c


示例3: process_auth

static int process_auth(ETERM *pid, ETERM *data)
{
  int retval = 0;
  ETERM *pattern, *srv, *user, *pass;
  char *service, *username, *password;
  pattern = erl_format("{Srv, User, Pass}");
  if (erl_match(pattern, data))
    {
      srv = erl_var_content(pattern, "Srv");
      service = erl_iolist_to_string(srv);
      user = erl_var_content(pattern, "User");
      username = erl_iolist_to_string(user);
      pass = erl_var_content(pattern, "Pass");
      password = erl_iolist_to_string(pass);
      retval = process_reply(pid, CMD_AUTH, auth(service, username, password));
      erl_free_term(srv);
      erl_free_term(user);
      erl_free_term(pass);
      erl_free(service);
      erl_free(username);
      erl_free(password);
    };
  erl_free_term(pattern);
  return retval;
}
开发者ID:0879dc,项目名称:ejabberd,代码行数:25,代码来源:epam.c


示例4: handle_last

void
handle_last(ETERM *msg)
{
  ETERM *ecols, *erows, *resp;

  if (results == NULL) {
    resp = erl_format("{error, result_set_does_not_exist}");
    write_msg(resp);
    erl_free_term(resp);

    return;
  }

  mysql_stmt_data_seek(sth, numrows - 1);
  resultoffset = numrows;

  ecols = make_cols();
  erows = make_rows(1);
  resp = erl_format("{selected, ~w, ~w}", ecols, erows);
  erl_free_term(erows);

  erl_free_term(ecols);
  write_msg(resp);
  erl_free_term(resp);
}
开发者ID:bjc,项目名称:mysqlerl,代码行数:25,代码来源:mysqlerl.c


示例5: vaskerl_loop

void vaskerl_loop (int fd)
{
    unsigned char buf[MAX_BUF];

    while (1)
    {
        ErlMessage emsg;
        int got = erl_receive_msg(fd, buf, MAX_BUF, &emsg);

        if (got == ERL_TICK)
            continue;
        else if (got == ERL_ERROR)
        {
            fprintf(stderr, "erl_error\n");
            break;
        }

        if (emsg.type == ERL_REG_SEND)
        {
            printf("Got something...\n");

            ETERM *resp = erl_format("{cnode, \"hello\"}");
            erl_send(fd, emsg.from, resp);
            erl_free_term(resp);

            erl_free_term(emsg.from);
            erl_free_term(emsg.msg);
        }
    }
}
开发者ID:humasect,项目名称:erl-dev,代码行数:30,代码来源:node.c


示例6: process_command

static int process_command(byte *buf)
{
  int retval = 0;
  ETERM *pattern, *tuple, *cmd, *port, *data;
  pattern = erl_format("{Cmd, Port, Data}");
  tuple = erl_decode(buf);
  if (erl_match(pattern, tuple))
    {
      cmd = erl_var_content(pattern, "Cmd");
      port = erl_var_content(pattern, "Port");
      data = erl_var_content(pattern, "Data");
      switch (ERL_INT_VALUE(cmd))
	{
	case CMD_AUTH:
	  retval = process_auth(port, data);
	  break;
	case CMD_ACCT:
	  retval = process_acct(port, data);
	  break;
	};
      erl_free_term(cmd);
      erl_free_term(port);
      erl_free_term(data);
    }
  erl_free_term(pattern);
  erl_free_term(tuple);
  return retval;
}
开发者ID:0879dc,项目名称:ejabberd,代码行数:28,代码来源:epam.c


示例7: make_row

ETERM *
make_row()
{
  ETERM **rowtup, *rc;
  unsigned int i;

  rowtup = (ETERM **)safe_malloc(numfields * sizeof(ETERM *));
  for (i = 0; i < numfields; i++) {
    if (*r_bind[i].is_null)
      rowtup[i] = erl_mk_atom("null");
    else
      rowtup[i] = erl_mk_estring(r_bind[i].buffer, *r_bind[i].length);
  }

  rc = erl_mk_tuple(rowtup, numfields);
  if (rc == NULL) {
    ETERM *resp;

    resp = erl_format("{error, {erl_mk_tuple, ~i}}", numfields);
    write_msg(resp);
    erl_free_term(resp);
    exit(3);
  }

  for (i = 0; i < numfields; i++)
    erl_free_term(rowtup[i]);
  free(rowtup);

  return rc;
}
开发者ID:bjc,项目名称:mysqlerl,代码行数:30,代码来源:mysqlerl.c


示例8: term_test

static int term_test(IC_Env *env)
{
    ETERM *ti, *to, *tr;

    ti = erl_format("[{hej, 1, 23}, \"string\", {1.23, 45}]");

    fprintf(stdout, "\n======== m_i_term test ======\n\n");
    tr = m_i_term_test(NULL, ti, &to, env);
    CHECK_EXCEPTION(env);
    RETURN_IF_OK(erl_match(ti, to) && erl_match(ti, tr));
    if (!erl_match(ti, to)) {
	fprintf(stdout, " out parameter error, sent:\n");
	print_term(ti);
	fprintf(stdout, "got:\n");
	print_term(to);
    }
    if (!erl_match(ti, tr)) {
	fprintf(stdout, " result error, sent:\n");
	print_term(ti);
	fprintf(stdout, "got:\n");
	print_term(tr);
    }
    erl_free_term(ti);
    erl_free_term(to);
    erl_free_term(tr);
    return -1;
}
开发者ID:3112517927,项目名称:otp,代码行数:27,代码来源:c_client.c


示例9: typedef_test

static int typedef_test(IC_Env *env)
{
    m_banan mbi, mbo;		/* erlang_port */
    m_apa mai;			/* ETERM* */
    m_apa mao = NULL;
    long tl;

    strcpy(mbi.node,"node");
    mbi.id = 15;
    mbi.creation = 1;

    fprintf(stdout, "\n======== m_i_typedef test ======\n\n");
    mai = erl_format("[{hej, 1, 23}, \"string\", {1.23, 45}]");
    tl = m_i_typedef_test(NULL, mai, &mbi, &mao, &mbo, env);
    CHECK_EXCEPTION(env);
    RETURN_IF_OK(erl_match(mai, mao) && cmp_port(&mbi, &mbo) && tl == 4711);
    if (!erl_match(mai, mao)) {
	fprintf(stdout, " out parameter error (term), sent:\n");
	print_term(mai);
	fprintf(stdout, "got:\n");
	print_term(mao);
    }
    if (!cmp_port(&mbi, &mbo)) {
	fprintf(stdout, " out parameter error (port), sent:\n");
	print_port(&mbi);
	fprintf(stdout, "got:\n");
	print_port(&mbo);
    }
    if (tl != 4711) {
	fprintf(stdout, " result error, sent: 4711, got %ld\n", tl);
    }
    erl_free_term(mai);
    erl_free_term(mao);
    return -1;
} 
开发者ID:3112517927,项目名称:otp,代码行数:35,代码来源:c_client.c


示例10: main

int main() {
  ETERM *tuplep, *intp;
  ETERM *fnp, *argp;
  int res;
  byte buf[100];
  long allocated, freed;

  erl_init(NULL, 0);

  while (read_cmd(buf) > 0) {
    tuplep = erl_decode(buf);
    fnp    = erl_element(1, tuplep);
    argp   = erl_element(2, tuplep);
    
    if (strncmp(ERL_ATOM_PTR(fnp), "foo", 3) == 0) {
      res = foo(ERL_INT_VALUE(argp));
    } else if (strncmp(ERL_ATOM_PTR(fnp), "bar", 17) == 0) {
      res = bar(ERL_INT_VALUE(argp));
    }

    intp = erl_mk_int(res);
    erl_encode(intp, buf);
    write_cmd(buf, erl_term_len(intp));

    erl_free_compound(tuplep);
    erl_free_term(fnp);
    erl_free_term(argp);
    erl_free_term(intp);
  }
}
开发者ID:dmichael,项目名称:signalers,代码行数:30,代码来源:ei.c


示例11: process_hashpw

static int
process_hashpw(ETERM *pid, ETERM *data)
{
  int retval = 0;
  ETERM *pattern, *pwd, *slt;
  char *password, *salt;
  char *ret = NULL;
  pattern = erl_format("{Pass, Salt}");
  if (erl_match(pattern, data)) {
    pwd = erl_var_content(pattern, "Pass");
    password = erl_iolist_to_string(pwd);
    slt = erl_var_content(pattern, "Salt");
    salt = erl_iolist_to_string(slt);
    if (NULL == (ret = bcrypt(password, salt)) ||
        0 == strcmp(ret, ":")) {
      retval = process_reply(pid, CMD_HASHPW, "Invalid salt");
    } else {
      retval = process_reply(pid, CMD_HASHPW, ret);
    }
    erl_free_term(pwd);
    erl_free_term(slt);
    erl_free(password);
    erl_free(salt);
  };
  erl_free_term(pattern);
  return retval;
}
开发者ID:chinnurtb,项目名称:erlang-bcrypt-wo_autotools,代码行数:27,代码来源:bcrypt_erlang.c


示例12: process_encode_salt

static int
process_encode_salt(ETERM *pid, ETERM *data)
{
  int retval = 0;
  ETERM *pattern, *cslt, *lr;
  byte *csalt = NULL;
  long log_rounds = -1;
  int csaltlen = -1;
  char ret[64];
  pattern = erl_format("{Csalt, LogRounds}");
  if (erl_match(pattern, data)) {
    cslt = erl_var_content(pattern, "Csalt");
    csaltlen = ERL_BIN_SIZE(cslt);
    csalt = ERL_BIN_PTR(cslt);
    lr = erl_var_content(pattern, "LogRounds");
    log_rounds = ERL_INT_UVALUE(lr);
    if (16 != csaltlen) {
      retval = process_reply(pid, CMD_SALT, "Invalid salt length");
    } else if (log_rounds < 4 || log_rounds > 31) {
      retval = process_reply(pid, CMD_SALT, "Invalid number of rounds");
    } else {
      encode_salt(ret, (u_int8_t*)csalt, csaltlen, log_rounds);
      retval = process_reply(pid, CMD_SALT, ret);
    }
    erl_free_term(cslt);
    erl_free_term(lr);
  };
  erl_free_term(pattern);
  return retval;
}
开发者ID:chinnurtb,项目名称:erlang-bcrypt-wo_autotools,代码行数:30,代码来源:bcrypt_erlang.c


示例13: process_command

static int
process_command(unsigned char *buf)
{
  int retval = 0;
  ETERM *pattern, *tuple, *cmd, *port, *data;
  pattern = erl_format("{Cmd, Port, Data}");
  tuple = erl_decode(buf);
  if (erl_match(pattern, tuple)) {
    cmd = erl_var_content(pattern, "Cmd");
    port = erl_var_content(pattern, "Port");
    data = erl_var_content(pattern, "Data");
    switch (ERL_INT_VALUE(cmd)) {
    case CMD_SALT:
      retval = process_encode_salt(port, data);
      break;
    case CMD_HASHPW:
      retval = process_hashpw(port, data);
      break;
    };
    erl_free_term(cmd);
    erl_free_term(port);
    erl_free_term(data);
  }
  erl_free_term(pattern);
  erl_free_term(tuple);
  return retval;
}
开发者ID:chinnurtb,项目名称:erlang-bcrypt-wo_autotools,代码行数:27,代码来源:bcrypt_erlang.c


示例14: erl_format

erlang_pid *erl_whereis(int fd, const char *name)
{
  ETERM *reply;
  ETERM *n;
  /* FIXME problem for threaded ? */
  static erlang_pid pid;
  
  n = erl_format("[~a]",name);
  reply = erl_rpc(fd,"erlang","whereis",n);
  erl_free_term(n);

  if (reply && (ERL_IS_PID(reply))) {
    char *node;
    node =  ERL_PID_NODE(reply);
    strcpy(pid.node,node);
    pid.num = ERL_PID_NUMBER(reply);
    pid.serial = ERL_PID_SERIAL(reply);
    pid.creation = ERL_PID_CREATION(reply);
    erl_free_term(reply);
    return &pid;
  }

  if (reply) erl_free_term(reply);
  return NULL;
}
开发者ID:system,项目名称:erlang-otp,代码行数:25,代码来源:whereis.c


示例15: main

int main()
{
  ETERM *tuplep;
  ETERM *fnp;
  ETERM *args;
  byte buf[100];
  const char* func_name;

#ifdef __WIN32__
  /* Attention Windows programmers: you need [to pay Serge Aleynikov a
   * beer because he's the one who figured out how to get this to work
   * on windows :)] explicitly set mode of stdin/stdout to binary or
   * else the port program won't work.
   */
  _setmode(_fileno(stdout), _O_BINARY);
  _setmode(_fileno(stdin), _O_BINARY);
#endif

  eNotify_init();
  erl_init(NULL, 0);

  while (read_cmd(buf) > 0) {
    tuplep = erl_decode(buf);
    fnp = erl_element(1, tuplep);

    func_name =  (const char*)ERL_ATOM_PTR(fnp);
    args = erl_element(2, tuplep);

    // MATCH FIRST! -> REMEMBER THAT!
    if (strncmp(func_name, "get_error_desc", 14) == 0)
      {
		local_get_error_desc(args);
      }
    else if (strncmp(func_name, "add_watch", 9) == 0)
      {
	local_add_watch(args);
      }
    else if (strncmp(func_name, "remove_watch", 12) == 0)
      {
	local_remove_watch(args);
      }
    else
      {
	byte buf[10];
	ETERM *nok = erl_mk_atom("undef"); // alloc nok
	erl_encode(nok, buf);
	write_cmd(buf, erl_term_len(nok));
	erl_free_term(nok); // free nok
      }
    erl_free_compound(tuplep);
    erl_free_term(fnp);
  }
  return 0;
}
开发者ID:alepharchives,项目名称:enotify-1,代码行数:54,代码来源:enotify.c


示例16: main

int main(int argc, char** argv)
{
    int erl_fd; // FD to the ERL VM
    char* bufp; // storage for incoming messages
    int bufsz = 1024;

    // the following are basically magic values.
    erl_fd = setup_connection(1, "secretcookie", 0, "[email protected]");

    ErlMessage* emsg;
    emsg = (ErlMessage*)malloc(sizeof(ErlMessage));
    bufp = (char*)malloc(bufsz * sizeof(char));

    while (1) // main loop - we don't ever expect to leave.
    {
        TRACE(("starting main loop"));

        TRACE(("waiting for a message..."));
        int msg_status = erl_receive_msg(erl_fd, bufp, bufsz, emsg);
        TRACE(("got a message"));

        switch (msg_status)
        {
        case (ERL_MSG): 
            TRACE(("message status is ERL_MSG"));
            process_msg(emsg, erl_fd);
            break;
        case (ERL_TICK):
            TRACE(("message status is ERL_TICK"));
            break;
        case (ERL_ERROR):
        default:
            TRACE(("message status is ERL_ERROR"));
            process_error();
            break;
        }

        TRACE(("cleaning up at end of main loop"));
        erl_free_term(emsg->msg);
        erl_free_term(emsg->from);
        erl_free_term(emsg->to);

    } // end while loop

    if (erl_close_connection(erl_fd) < 0)
    {
        perror("failed to close connection. plowing onward.");
    }

    free(emsg);
    free(bufp);

}
开发者ID:thenewwazoo,项目名称:erl_poc,代码行数:53,代码来源:node.c


示例17: translate

ETERM * translate(ETERM* arg, int c_node) {
    ETERM *tx, *ty;
    cairo_context *ctx = get_cairo_context(arg);
    if (ctx) {
        tx = erl_element(2, arg);  
        ty = erl_element(3, arg); 
        cairo_translate(ctx->cr, val(tx), val(ty));
        erl_free_term(tx);
        erl_free_term(ty);
        return erl_format("{c_node, ~i, ok}", c_node);
    } else { 
        return erl_format("{c_node, ~i, {error, '~s'}}", c_node, ERR_CONTEXT);
    }
}
开发者ID:chinnurtb,项目名称:erlycairo,代码行数:14,代码来源:erlycairo.c


示例18: scale

ETERM * scale(ETERM* arg, int c_node) {
    ETERM *sx, *sy;
    cairo_context *ctx = get_cairo_context(arg);
    if (ctx) {
        sx = erl_element(2, arg);  
        sy = erl_element(3, arg); 
        cairo_scale(ctx->cr, val(sx), val(sy));
        erl_free_term(sx);
        erl_free_term(sy);
        return erl_format("{c_node, ~i, ok}", c_node);
    } else { 
        return erl_format("{c_node, ~i, {error, '~s'}}", c_node, ERR_CONTEXT);
    }
}
开发者ID:chinnurtb,项目名称:erlycairo,代码行数:14,代码来源:erlycairo.c


示例19: rel_line_to

ETERM * rel_line_to(ETERM* arg, int c_node) {
    ETERM *x, *y;
    cairo_context *ctx = get_cairo_context(arg);
    if (ctx) {
        x = erl_element(2, arg);  
        y = erl_element(3, arg); 
        cairo_rel_line_to(ctx->cr, val(x), val(y));
        erl_free_term(x);
        erl_free_term(y);
        return erl_format("{c_node, ~i, ok}", c_node);
    } else { 
        return erl_format("{c_node, ~i, {error, '~s'}}", c_node, ERR_CONTEXT);
    }
}
开发者ID:chinnurtb,项目名称:erlycairo,代码行数:14,代码来源:erlycairo.c


示例20: main

int main(int argc, char **argv) {
  int fd;                       /* file descriptor of Erlang node */

  int loop = 1;                 /* Loop flag                      */
  int got;                      /* Result of receive              */
  unsigned char buf[BUFSIZE];   /* Buffer for incoming message    */
  ErlMessage emsg;              /* Incoming message               */

  ETERM *fromp, *argp, *resp;   /* Reps of Erlang terms           */
  int res;                      /* Result of the fac call         */

    /* initialize erl_interface (once only) */           
  erl_init(NULL, 0);  
         
    /* initialize the connection mechanism  */
  if (erl_connect_init(1, "refactorcookie", 0) == -1)
    erl_err_quit("erl_connect_init");

    /* connect to a running Erlang node     */
  if ((fd = erl_connect("[email protected]")) < 0)
    erl_err_quit("erl_connect");

  while (loop) {
      /* message received */
    got = erl_receive_msg(fd, buf, BUFSIZE, &emsg);

    if (got == ERL_TICK) {
      /* ignore */
    } else if (got == ERL_ERROR) {
      loop = 0;
    } else {
      if (emsg.type == ERL_REG_SEND) {
	  /* unpack message fields         */
        fromp = erl_element(1, emsg.msg);
        argp = erl_element(2, emsg.msg);

	  /* call fac and send result back */
        resp = erl_format("{ok, ~i}", fac(ERL_INT_VALUE(argp)));
        erl_send(fd, fromp, resp);

	  /* free the term storage used    */
        erl_free_term(emsg.from); erl_free_term(emsg.msg);
        erl_free_term(fromp); erl_free_term(argp);
        erl_free_term(resp);
      }
    }
  }
}
开发者ID:ElinChan,项目名称:codes-from-books,代码行数:48,代码来源:fac.c



注:本文中的erl_free_term函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ err函数代码示例发布时间:2022-05-30
下一篇:
C++ erl_format函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap