NEOERR *wdbr_dump (WDB *wdb, WDBRow *row)
{
  int x;

  ne_warn ("version: %d", row->table_version);
  ne_warn ("key: %s", row->key_value);
  ne_warn ("count: %d", row->data_count);
  for (x=0; x < row->data_count; x++)
    ne_warn ("data[%d]: %s", x, row->data[x]);

  return STATUS_OK;
}
示例#2
0
/* We can't really have an error return from this (and the other
 * cgiwrap) function, because the API doesn't have an error return,
 * and if we get back to python, the error will occur at the next random
 * place that python actually checks for errors independent of an error
 * return.  Not the best way to do things, but its what we've got.  Some
 * of these we can check for in cgiWrap() */
static char *p_getenv (void *data, const char *s)
{
  WRAPPER_DATA *wrap = (WRAPPER_DATA *)data;
  PyObject *get;
  PyObject *args = NULL;
  PyObject *result;
  char *ret = NULL;

  get = PyObject_GetAttrString(wrap->p_env, "__getitem__");
  if (get != NULL)
  {
    args = Py_BuildValue("(s)", s);
    if (args == NULL) {
      Py_DECREF(get);
      PyErr_Clear();
      return NULL;
    }
  }
  else 
  {
    /* Python 1.5.2 and earlier don't have __getitem__ on the standard
     * dict object, so we'll just use get for them */

    get = PyObject_GetAttrString(wrap->p_env, "get");
    if (get != NULL)
    {
      args = Py_BuildValue("(s,O)", s, Py_None);
      if (args == NULL) 
      {
	Py_DECREF(get);
	PyErr_Clear();
	return NULL;
      }
    }
  }
  if (get == NULL)
  {
    ne_warn("Unable to get __getitem__ from env");
    PyErr_Clear();
    return NULL;
  }
  result = PyEval_CallObject(get, args);
  Py_DECREF(get);
  Py_DECREF(args);
  if (result != NULL && !PyString_Check(result) && (result != Py_None)) 
  {
    Py_DECREF(result);
    result = NULL;
    PyErr_SetString(PyExc_TypeError,
	"env.get() returned non-string");
  }
  if (result != NULL && result != Py_None)
  {
    ret = strdup (PyString_AsString(result));
    Py_DECREF (result);
  }

  PyErr_Clear();
  return ret;
}
示例#3
0
int main(int argc, char **argv)
{
  char *path;
  ULIST *files = NULL;
  char *filename;
  NEOERR *err;
  int x;

  if (argc > 1)
    path = argv[1];
  else
    path = ".";

  ne_warn("Testing ne_listdir()");
  err = ne_listdir(path, &files);
  if (err)
  {
    nerr_log_error(err);
    return -1;
  }

  for (x = 0; x < uListLength(files); x++)
  {
    err = uListGet(files, x, (void *)&filename);
    printf("%s\n", filename);
  }

  uListDestroy(&files, ULIST_FREE);

  ne_warn("Testing ne_listdir_match() with *.c");
  err = ne_listdir_match(path, &files, "*.c");
  if (err)
  {
    nerr_log_error(err);
    return -1;
  }

  for (x = 0; x < uListLength(files); x++)
  {
    err = uListGet(files, x, (void *)&filename);
    printf("%s\n", filename);
  }

  uListDestroy(&files, ULIST_FREE);
  return 0;
}
示例#4
0
文件: neo_err.c 项目: DerPapst/hhvm
static NEOERR *_err_alloc(void)
{
  NEOERR *err = (NEOERR *)calloc (1, sizeof (NEOERR));
  if (err == NULL)
  {
    ne_warn ("INTERNAL ERROR: Unable to allocate memory for NEOERR");
    return INTERNAL_ERR;
  }
  return err;
}
示例#5
0
int main(int argc, char *argv[])
{
  HDF *hdf = NULL;
  int i, j;

  hdf_init(&hdf);

  ne_warn("creating 100000x10 nodes");
  for (i = 0; i < 100000; i++) {
    char buffer[64];
    for (j = 0; j < 10; j++) {
      snprintf(buffer, sizeof(buffer), "node.%d.test.%d", i, j);
      hdf_set_value(hdf, buffer, "test");
    }
  }

  ne_warn("calling dealloc");
  hdf_destroy(&hdf);    // <-- this takes forever to return with a hugely
  return 0;
}
示例#6
0
文件: neo_err.c 项目: DerPapst/hhvm
/* In the future, we'll allow someone to register an error handler */
void nerr_log_error (NEOERR *err)
{
  NEOERR *more;
  char buf[1024];
  char *err_name;

  if (err == STATUS_OK)
    return;

  if (err == INTERNAL_ERR)
  {
    ne_warn ("Internal error");
    return;
  }

  more = err;
  fprintf (stderr, "Traceback (innermost last):\n");
  while (more && more != INTERNAL_ERR)
  {
    err = more;
    more = err->next;
    if (err->error != NERR_PASS)
    {
      NEOERR *r;
      if (err->error == 0)
      {
	err_name = buf;
	snprintf (buf, sizeof (buf), "Unknown Error");
      }
      else
      {
	r = uListGet (Errors, err->error - 1, (void **)&err_name);
	if (r != STATUS_OK)
	{
	  err_name = buf;
	  snprintf (buf, sizeof (buf), "Error %d", err->error);
	}
      }

      fprintf (stderr, "  File \"%s\", line %d, in %s()\n%s: %s\n", err->file,
	  err->lineno, err->func, err_name, err->desc);
    }
    else
    {
      fprintf (stderr, "  File \"%s\", line %d, in %s()\n", err->file,
	  err->lineno, err->func);
      if (err->desc[0])
      {
	fprintf (stderr, "    %s\n", err->desc);
      }
    }
  }
}
示例#7
0
int main(void) {
  HDF *hdf_1, *hdf_2;
  HDF *cur_node,*last_node;

  hdf_init(&hdf_1);

  hdf_read_file(hdf_1,"hdf_copy_test.hdf");
  hdf_dump(hdf_1,NULL);

  cur_node = hdf_get_obj(hdf_1,"Chart");
  last_node = cur_node;

  cur_node = hdf_get_obj(cur_node,"next_stage");
  while (hdf_get_obj(cur_node,"next_stage") && strcmp(hdf_get_value(cur_node,"Bucket.FieldId",""),"QUEUE")) {
    last_node = cur_node;
    cur_node = hdf_get_obj(cur_node,"next_stage");
  }

  if (hdf_get_obj(cur_node,"next_stage")) {
    hdf_copy(hdf_1,"TempHolderPlace",hdf_get_obj(cur_node,"next_stage"));
  }
  ne_warn("Delete tree from node: %s", hdf_obj_name(last_node));
  hdf_remove_tree(last_node,"next_stage");

  hdf_dump(hdf_1,NULL);
  fprintf(stderr,"-----------------\n");


  hdf_copy(last_node,"next_stage",hdf_get_obj(hdf_1,"TempHolderPlace"));
  hdf_dump(hdf_1,NULL);

  /* Test copy and destroy, make sure we actually copy everything and
   * don't reference anything */
  hdf_init(&hdf_2);
  hdf_copy(hdf_2, "", hdf_1);
  hdf_destroy(&hdf_1);
  hdf_dump(hdf_2, NULL);
  hdf_destroy(&hdf_2);

  return 0;
}
示例#8
0
文件: neo_err.c 项目: 191919/hhvm
static NEOERR *_err_alloc(void)
{
  NEOERR *err;

  if (!UseFreeList || FreeList == NULL)
  {
    err = (NEOERR *)calloc (1, sizeof (NEOERR));
    if (err == NULL)
    {
      ne_warn ("INTERNAL ERROR: Unable to allocate memory for NEOERR");
      return INTERNAL_ERR;
    }
    return err;
  }
  else
  {
    err = FreeList;
    FreeList = FreeList->next;
  }
  err->flags |= NE_IN_USE;
  err->next = NULL;
  return err;
}
示例#9
0
int main(int argc, char *argv[])
{
  NEOERR *err;
  HDF *hdf;
  double tstart = 0;

  err = hdf_init(&hdf);
  if (err != STATUS_OK) 
  {
    nerr_log_error(err);
    return -1;
  }

  tstart = ne_timef();
  TestSort(hdf);
  ne_warn("sort took %5.5fs", ne_timef() - tstart);

  hdf_dump(hdf, NULL);

  hdf_destroy(&hdf);

  return 0;
}
NEOERR *ne_net_accept(NSOCK **sock, int sfd, int data_timeout)
{
  NSOCK *my_sock;
  int fd;
  struct sockaddr_in client_addr;
  socklen_t len;

  len = sizeof(struct sockaddr_in);
  while (1)
  {
    fd = accept(sfd, (struct sockaddr *)&client_addr, &len);
    if (fd >= 0) break;
    if (ShutdownAccept || errno != EINTR)
    {
      return nerr_raise_errno(NERR_IO, "accept() returned error");
    }
    if (errno == EINTR)
    {
      ne_warn("accept received EINTR");
    }
  }

  my_sock = (NSOCK *) calloc(1, sizeof(NSOCK));
  if (my_sock == NULL)
  {
    close(fd);
    return nerr_raise(NERR_NOMEM, "Unable to allocate memory for NSOCK");
  }
  my_sock->fd = fd;
  my_sock->remote_ip = ntohl(client_addr.sin_addr.s_addr);
  my_sock->remote_port = ntohs(client_addr.sin_port);
  my_sock->data_timeout = data_timeout;

  *sock = my_sock;

  return STATUS_OK;
}
示例#11
0
int main (int argc, char *argv[])
{
  NEOERR *err;
  CSPARSE *parse;
  HDF *hdf;
  int verbose = 0;
  char *hdf_file, *cs_file;

  if (argc < 3)
  {
    ne_warn ("Usage: cstest [-v] <file.hdf> <file.cs>");
    return -1;
  }

  if (!strcmp(argv[1], "-v"))
  {
    verbose = 1;
    if (argc < 4)
    {
      ne_warn ("Usage: cstest [-v] <file.hdf> <file.cs>");
      return -1;
    }
    hdf_file = argv[2];
    cs_file = argv[3];
  }
  else
  {
    hdf_file = argv[1];
    cs_file = argv[2];
  }

  err = hdf_init(&hdf);
  if (err != STATUS_OK)
  {
    nerr_warn_error(err);
    return -1;
  }
  err = hdf_read_file(hdf, hdf_file);
  if (err != STATUS_OK)
  {
    nerr_warn_error(err);
    return -1;
  }

  printf ("Parsing %s\n", cs_file);
  err = cs_init (&parse, hdf);
  if (err != STATUS_OK)
  {
    nerr_warn_error(err);
    return -1;
  }
  err = cgi_register_strfuncs(parse);
  if (err != STATUS_OK)
  {
    nerr_warn_error(err);
    return -1;
  }

  err = cs_parse_file (parse, cs_file);
  if (err != STATUS_OK)
  {
    err = nerr_pass(err);
    nerr_warn_error(err);
    return -1;
  }

  err = cs_render(parse, NULL, output);
  if (err != STATUS_OK)
  {
    err = nerr_pass(err);
    nerr_warn_error(err);
    return -1;
  }

  if (verbose)
  {
    printf ("\n-----------------------\nCS DUMP\n");
    err = cs_dump(parse, NULL, output);
  }

  cs_destroy (&parse);

  if (verbose)
  {
    printf ("\n-----------------------\nHDF DUMP\n");
    hdf_dump (hdf, NULL);
  }
  hdf_destroy(&hdf);


  return 0;
}
示例#12
0
int main(int argc, char *argv[])
{
  NEOERR *err;
  HDF *hdf;
  int x;
  char name[256];
  char value[256];
  double tstart = 0;

  err = hdf_init(&hdf);
  DIE_NOT_OK(err);

  err = hdf_set_value (hdf, "Beware", "1");
  DIE_NOT_OK(err);
  err = hdf_set_value (hdf, "Beware.The", "2");
  DIE_NOT_OK(err);
  err = hdf_set_valuef (hdf, "Beware.The.%s=%d", "Ides", 3);
  DIE_NOT_OK(err);
  err = hdf_set_value (hdf, "Beware.Off", "4");
  DIE_NOT_OK(err);
  err = hdf_set_value (hdf, "Beware.The.Ides.Of", "5");
  DIE_NOT_OK(err);
  err = hdf_set_value (hdf, "Beware.The.Butter", "6");
  DIE_NOT_OK(err);
  err = hdf_set_attr (hdf, "Beware.The.Butter", "Lang", "en");
  DIE_NOT_OK(err);
  err = hdf_set_attr (hdf, "Beware.The.Butter", "Lang", "1");
  DIE_NOT_OK(err);
  err = hdf_set_attr (hdf, "Beware.The.Butter", "Lang", NULL);
  DIE_NOT_OK(err);

  err = hdf_read_file (hdf, "test.hdf");
  DIE_NOT_OK(err);
  hdf_dump(hdf, NULL);


  x = hdf_get_int_value (hdf, "Beware.The.Ides", 0);
  if (x != 3)
  {
    ne_warn("hdf_get_int_value returned %d, expected 3", x);
    return -1;
  } 

  /* test symlinks */
  {
    const char *v;
    err = hdf_set_value(hdf, "Destination.Foo", "bar");
    DIE_NOT_OK(err);
    err = hdf_set_symlink(hdf, "Symlink.baz", "Destination.Foo");
    DIE_NOT_OK(err);
    v = hdf_get_value(hdf, "Symlink.baz", "notfound");
    if (strcmp(v, "bar")) {
      ne_warn("hdf_get_value through symlink returned %s, expected bar", v);
      return -1;
    }
    err = hdf_set_value(hdf, "Symlink.baz", "newvalue");
    DIE_NOT_OK(err);
    v = hdf_get_value(hdf, "Symlink.baz", "notfound");
    if (strcmp(v, "newvalue")) {
      ne_warn("hdf_get_value through symlink returned %s, expected newvalue",
              v);
      return -1;
    }
    err = hdf_set_value(hdf, "Symlink.baz.too", "newtoo");
    DIE_NOT_OK(err);
    v = hdf_get_value(hdf, "Symlink.baz.too", "newtoo");
    if (strcmp(v, "newtoo")) {
      ne_warn("hdf_get_value through symlink returned %s, expected newtoo",
              v);
      return -1;
    }
    v = hdf_get_value(hdf, "Destination.Foo.too", "newtoo");
    if (strcmp(v, "newtoo")) {
      ne_warn("hdf_get_value through symlink returned %s, expected newtoo",
              v);
      return -1;
    }
  }

  for (x = 0; x < 10000; x++)
  {
    rand_name(name, sizeof(name));
    neo_rand_word(value, sizeof(value));
    /* ne_warn("Setting %s = %s", name, value); */
    err = hdf_set_value (hdf, name, value);
    DIE_NOT_OK(err);
  }

  tstart = ne_timef();
  hdf_sort_obj(hdf, sortByName);
  ne_warn("sort took %5.5fs", ne_timef() - tstart);

  hdf_dump(hdf, NULL);

  hdf_destroy(&hdf);

  return 0;
}
示例#13
0
static int p_iterenv (void *data, int x, char **rk, char **rv)
{
  WRAPPER_DATA *wrap = (WRAPPER_DATA *)data;
  PyObject *items;
  PyObject *env_list;
  PyObject *result;
  PyObject *k, *v;

  items = PyObject_GetAttrString(wrap->p_env, "items");
  if (items == NULL)
  {
    ne_warn ("p_iterenv: Unable to get items method");
    PyErr_Clear();
    return -1;
  }
  env_list = PyEval_CallObject(items, NULL);
  Py_DECREF(items);
  if (env_list == NULL)
  {
    ne_warn ("p_iterenv: Unable to call items method");
    PyErr_Clear();
    return -1;
  }
  if (x >= PyList_Size(env_list))
  {
    *rk = NULL;
    *rv = NULL;
    Py_DECREF(env_list); 
    return 0;
  }
  result = PyList_GetItem (env_list, x);
  if (result == NULL)
  {
    ne_warn ("p_iterenv: Unable to get env %d", x);
    Py_DECREF(env_list); 
    PyErr_Clear();
    return -1;
  }
  k = PyTuple_GetItem (result, 0);
  v = PyTuple_GetItem (result, 1);
  if (k == NULL || v == NULL)
  {
    ne_warn ("p_iterenv: Unable to get k,v %p,%p", k, v); 
    Py_DECREF(env_list); 
    PyErr_Clear();
    return -1;
  }
  *rk = strdup(PyString_AsString(k));
  *rv = strdup(PyString_AsString(v));
  if (*rk == NULL || *rv == NULL)
  {
    if (*rk) free (*rk);
    if (*rv) free (*rv);
    Py_DECREF(env_list); 
    PyErr_Clear();
    return -1;
  }

  Py_DECREF(env_list); 
  PyErr_Clear();
  return 0;
}