示例#1
0
void
test1()
{
	int i;

	for (i = 0; i < 256; i++) {
		printf(" %02x: ", i);
		check_bool(isalnum(i), iswalnum(i), '1');
		check_bool(isalpha(i), iswalpha(i), '2');
		check_bool(isblank(i), iswblank(i), '3');
		check_bool(iscntrl(i), iswcntrl(i), '4');
		check_bool(isdigit(i), iswdigit(i), '5');
		check_bool(isgraph(i), iswgraph(i), '6');
		check_bool(islower(i), iswlower(i), '6');
		check_bool(isprint(i), iswprint(i), '7');
		check_bool(ispunct(i), iswpunct(i), '8');
		check_bool(isspace(i), iswspace(i), '9');
		check_bool(isupper(i), iswupper(i), 'a');
		check_bool(isxdigit(i), iswxdigit(i), 'b');
		check_value(tolower(i), towlower(i), 'c');
		check_value(toupper(i), towupper(i), 'd');
		if (i % 8 == 7)
			printf("\n");
	}
	printf("%\n");
}
示例#2
0
static int	check_value_form(const std::string &value)
{
  int		n;

  if (value.at(0) != '-' && (value.at(0) < '0' || value.at(0) > '9'))
    return (-1);
  n = value.find('.', 1);
  if (n == (int)(value.size() - 1))
    return (-1);
  if (value.at(0) == '-' && value.at(1) == '.')
    return (-1);
  if (n != -1)
    {
      if (check_value(1, n - 1, value) == -1)
	return (-1);
      if (check_value(n + 1, value.size() - 1, value) == -1)
	return (-1);
    }
  else
    {
      if (check_value(1, value.size() - 1, value) == -1)
	return (-1);
    }
  return (0);
}
示例#3
0
// Test boost::tie() interoperabiliy.
int test_main( int, char* [] )
{
  typedef X T ;
          
  try
  {
    TRACE( std::endl << BOOST_CURRENT_FUNCTION  );
  
    T z(0);
    T a(1);
    T b(2);
  
    optional<T> oa, ob ;
  
    // T::T( T const& x ) is used
    set_pending_dtor( ARG(T) ) ;
    set_pending_copy( ARG(T) ) ;
    boost::tie(oa,ob) = std::make_pair(a,b) ;
    check_is_not_pending_dtor( ARG(T) ) ;
    check_is_not_pending_copy( ARG(T) ) ;
    check_initialized(oa);
    check_initialized(ob);
    check_value(oa,a,z);
    check_value(ob,b,z);
    
  }
  catch ( ... )
  {
    BOOST_ERROR("Unexpected Exception caught!");
  }

  return 0;
}
示例#4
0
static int hj_value(lua_State *lua)
{
  rj::Value *v = check_value(lua);
  if (!v) {
    lua_pushnil(lua);
    return 1;
  }

  switch (v->GetType()) {
  case rj::kStringType:
    lua_pushlstring(lua, v->GetString(), (size_t)v->GetStringLength());
    break;
  case rj::kNumberType:
    lua_pushnumber(lua, (lua_Number)v->GetDouble());
    break;
  case rj::kFalseType:
  case rj::kTrueType:
    lua_pushboolean(lua, v->GetBool());
    break;
  case rj::kObjectType:
    return luaL_error(lua, "value() not allowed on an object");
    break;
  case rj::kArrayType:
    return luaL_error(lua, "value() not allowed on an array");
    break;
  default:
    lua_pushnil(lua);
    break;
  }
  return 1;
}
示例#5
0
static int hj_size(lua_State *lua)
{
  rj::Value *v = check_value(lua);
  if (!v) {
    lua_pushnil(lua);
    return 1;
  }

  switch (v->GetType()) {
  case rj::kStringType:
    lua_pushnumber(lua, (lua_Number)v->GetStringLength());
    break;
  case rj::kNumberType:
    return luaL_error(lua, "attempt to get length of a number");
  case rj::kFalseType:
  case rj::kTrueType:
    return luaL_error(lua, "attempt to get length of a boolean");
  case rj::kObjectType:
    lua_pushnumber(lua, (lua_Number)v->MemberCount());
    break;
  case rj::kArrayType:
    lua_pushnumber(lua, (lua_Number)v->Size());
    break;
  case rj::kNullType:
    return luaL_error(lua, "attempt to get length of a NULL");
  }
  return 1;
}
示例#6
0
static int hj_type(lua_State *lua)
{
  rj::Value *v = check_value(lua);
  if (!v) {
    lua_pushnil(lua);
    return 1;
  }

  switch (v->GetType()) {
  case rj::kStringType:
    lua_pushstring(lua, "string");
    break;
  case rj::kNumberType:
    lua_pushstring(lua, "number");
    break;
  case rj::kFalseType:
  case rj::kTrueType:
    lua_pushstring(lua, "boolean");
    break;
  case rj::kObjectType:
    lua_pushstring(lua, "object");
    break;
  case rj::kArrayType:
    lua_pushstring(lua, "array");
    break;
  case rj::kNullType:
    lua_pushstring(lua, "null");
    break;
  }
  return 1;
}
示例#7
0
void lexerParser::check_parenthese(const std::list<std::list<std::string> >::const_iterator &it,
				   std::list<std::string>::const_iterator &it2, const int &i, const int &line) const
{
  it2++;
  if (it2 != (*it).end())
    if ((*it2).compare("(") == 0)
      {
	it2++;
	if (it2 != (*it).end())
	  {
	    if ((*it2).compare("(") == 0)
	      throw except(std::string("Too many \"(\""), line);
	    if ((*it2).compare(")") == 0)
	      throw except(std::string("No value between \"()\""), line);
	    it2++;
	    if (it2 != (*it).end())
	      {
		if ((*it2).compare(")") == 0 && ++it2 == (*it).end())
		  {
		    --it2;
		    check_value(--it2, i, line);
		    return ;
		  }
		throw except(std::string("No value after first parameter for push and assert"), line);
	      }
	  }
      }
  throw except(std::string("Parentheses not found"), line);
}
示例#8
0
文件: genmatch.c 项目: dwillmer/ponyc
static bool dynamic_value_ptr(compile_t* c, LLVMValueRef ptr,
  LLVMValueRef desc, ast_t* pattern, LLVMBasicBlockRef next_block)
{
  // Get the type of the right-hand side of the pattern's eq() function.
  ast_t* param_type = eq_param_type(pattern);

  // Check the runtime type. We pass a pointer to the fields because we may
  // still need to match a tuple type inside a type expression.
  if(!check_type(c, ptr, desc, param_type, next_block))
    return false;

  // We now know that ptr points to something of type pattern_type, and that
  // it isn't a boxed primitive, as that would go through the other path, ie
  // dynamic_match_object(). We also know it isn't an unboxed tuple. We can
  // load from ptr with a type based on the static type of the pattern.
  gentype_t g;

  if(!gentype(c, param_type, &g))
    return false;

  LLVMTypeRef ptr_type = LLVMPointerType(g.use_type, 0);
  ptr = LLVMBuildIntToPtr(c->builder, ptr, ptr_type, "");
  LLVMValueRef value = LLVMBuildLoad(c->builder, ptr, "");

  return check_value(c, pattern, param_type, value, next_block);
}
示例#9
0
static int
set_void_ptr(void **vpp, PyObject *o, const char *name)
{
    void *vp = 0;

    if (check_value(o, name)) {
        return -1;
    }
    if (INT_CHECK(o)) {
        vp = PyLong_AsVoidPtr(o);
        if (PyErr_Occurred()) {
            return -1;
        }
    }
    else if (o == Py_None) {
        vp = 0;
    }
    else {
        PyErr_Format(PyExc_TypeError,
                     "property %400s must be a Python integer, not '%400s'",
                     name, Py_TYPE(o)->tp_name);
        return -1;
    }
    *vpp = vp;
    return 0;
}
示例#10
0
    void check_block(const Block *b) {
      for (auto input : b->inputs()) {
        check_value(input);
        JIT_ASSERT(input->node()->kind_ == kParam);
      }

      for (auto n : b->nodes()) {
        JIT_ASSERT(n->kind_ != kParam);
        JIT_ASSERT(n->kind_ != kReturn);
        check_node(n);
      }

      JIT_ASSERT(b->output_->kind() == kReturn);
      check_node(b->output_);

      // all_nodes
      // - inputs_, output_ and nodes_ are all included in all_nodes
      // - all_nodes does not contain dead nodes??? (likely to be temporarily
      // suspended).  Weaker: all_nodes contains all inputs and returns
      // - only one return node???

      node_set nodes_set(ALL_OF(b->nodes()));
      node_set inputs_set {b->input_};
      node_set output_set {b->output_};
      // TODO: Make a more type safe std::includes wrapper which disallows use on
      // non-ordered containers
      JIT_ASSERT(std::includes(ALL_OF(all_nodes_set), ALL_OF(nodes_set)));
      JIT_ASSERT(std::includes(ALL_OF(all_nodes_set), ALL_OF(inputs_set)));
      JIT_ASSERT(std::includes(ALL_OF(all_nodes_set), ALL_OF(output_set)));

      sum_set.insert(ALL_OF(nodes_set));
      sum_set.insert(ALL_OF(inputs_set));
      sum_set.insert(ALL_OF(output_set));
    }
示例#11
0
void nand_init(void)
{
	uint32_t val;

	board_nand_init();

	val = readl(SUNXI_NFC_BASE + NFC_CTL);
	/* enable and reset CTL */
	writel(val | NFC_CTL_EN | NFC_CTL_RESET,
	       SUNXI_NFC_BASE + NFC_CTL);

	if (!check_value_negated(SUNXI_NFC_BASE + NFC_CTL,
				 NFC_CTL_RESET, DEFAULT_TIMEOUT_US)) {
		printf("Couldn't initialize nand\n");
	}

	/* reset NAND */
	writel(NFC_ST_CMD_INT_FLAG, SUNXI_NFC_BASE + NFC_ST);
	writel(NFC_SEND_CMD1 | NFC_WAIT_FLAG | NAND_CMD_RESET,
	       SUNXI_NFC_BASE + NFC_CMD);

	if (!check_value(SUNXI_NFC_BASE + NFC_ST, NFC_ST_CMD_INT_FLAG,
			 DEFAULT_TIMEOUT_US)) {
		printf("Error timeout waiting for nand reset\n");
		return;
	}
	writel(NFC_ST_CMD_INT_FLAG, SUNXI_NFC_BASE + NFC_ST);
}
示例#12
0
 MetaEntry::MetaEntry(size_t line,
                      std::string const & id,
                      std::map<std::string, std::string> const & key_values,
                      std::shared_ptr<Source> source)
 : line{line}, id{id}, structure{Structure::KeyValue}, value{key_values}, source{source}
 {
     check_value();
 }
示例#13
0
 MetaEntry::MetaEntry(size_t line,
                      std::string const & id,
                      std::string const & plain_value,
                      std::shared_ptr<Source> source)
 : line{line}, id{id}, structure{Structure::PlainValue}, value{plain_value}, source{source}
 {
     check_value();
 }
示例#14
0
static int set_operations_test()
{
   VCOS_EVENT_FLAGS_T event;
   int passed = 1;

   if(vcos_event_flags_create(&event,"test") != VCOS_SUCCESS)
      passed = 0;
   else
   {
      check_value(&event, 0, 1, &passed);

      vcos_event_flags_set(&event, 1, VCOS_AND);
      check_value(&event, 0, 1, &passed);

      vcos_event_flags_set(&event, 1, VCOS_OR);
      check_value(&event, 1, 0, &passed);

      vcos_event_flags_set(&event, 8, VCOS_OR);
      check_value(&event, 9, 0, &passed);

      vcos_event_flags_set(&event, 96, VCOS_OR);
      check_value(&event, 9|96, 0, &passed);

      vcos_event_flags_set(&event, 65|1024, VCOS_AND);
      check_value(&event, 65, 0, &passed);

      vcos_event_flags_set(&event, -1, VCOS_OR);
      check_value(&event, -1, 1, &passed);

      vcos_event_flags_delete(&event);
   }

   return passed;
}
RegionBasedActiveContourYUV::RegionBasedActiveContourYUV(const ofeli::Matrix<const unsigned char>& img_rgb1,
                                     bool hasEllipse1, double shape_width_ratio1, double shape_height_ratio1, double center_x_ratio1, double center_y_ratio1,
                                     bool hasCycle2_1, unsigned int kernel_length1, double sigma1, unsigned int Na1, unsigned int Ns1,
                                     int lambda_out1, int lambda_in1, int alpha1, int beta1, int gamma1) :
    ActiveContour(img_rgb1.get_width(), img_rgb1.get_height(),
                  hasEllipse1, shape_width_ratio1, shape_height_ratio1, center_x_ratio1, center_y_ratio1,
                  hasCycle2_1, kernel_length1, sigma1, Na1, Ns1),
    img_rgb(img_rgb1),
    lambda_out(check_value(lambda_out1)), lambda_in(check_value(lambda_in1)), alpha(check_value(alpha1)), beta(check_value(beta1)), gamma(check_value(gamma1))
{
    if( !isValid_matrix(img_rgb1) )
    {
        std::cerr << std::endl <<
        "img_rgb1 is not valid."
        << std::endl;
    }

    initialize_sums();
    calculate_means();
}
示例#16
0
int main(void){
 int count = 1,nines = 0;
 while(count<=100){
  if(check_value(count)){
   printf("%d ",count);
   nines ++;
  }
  count++;
 }
 printf("\nThere are %d numbers contain \"9\" inside.\n",nines);
 return 0;
}
示例#17
0
文件: symbol.c 项目: andyfischer/ice
Value gensym(Value str)
{
    check_value(str);

    if (!is_blob(str) && !is_symbol(str))
        str = stringify(str);

    str = append_str_len(str, "#", 1);
    str = stringify_append(str, int_value(g_nextGensymId++));
    str = set_logical_type(str, SYMBOL_TYPE);
    return str;
}
示例#18
0
 bool set_value(const T& val)
 {
   T tmp;
   if(check_value(val,tmp)||(next&&next->check_value(val,tmp)))
     {
   current_value=tmp;
   value_set=true;
   return true;
     }
   else
     return false;
 }
RegionBasedActiveContourYUV::RegionBasedActiveContourYUV(const ofeli::Matrix<const unsigned char>& img_rgb1,
                                     const ofeli::Matrix<const signed char>& phi_init1,
                                     bool hasCycle2_1, unsigned int kernel_length1, double sigma1, unsigned int Na1, unsigned int Ns1,
                                     int lambda_out1, int lambda_in1, int alpha1, int beta1, int gamma1) :
    ActiveContour(phi_init1,
                  hasCycle2_1, kernel_length1, sigma1, Na1, Ns1),
    img_rgb(img_rgb1),
    lambda_out(check_value(lambda_out1)), lambda_in(check_value(lambda_in1)), alpha(check_value(alpha1)), beta(check_value(beta1)), gamma(check_value(gamma1))
{
    if( !isValid_matrix(img_rgb1) )
    {
        std::cerr << std::endl <<
        "img_rgb1 is not valid."
        << std::endl;
    }
    if( !isValid_matrix(phi_init1) )
    {
        std::cerr << std::endl <<
        "phi_init1 is not valid."
        << std::endl;
    }

    if( phi_init1.get_width() != img_rgb1.get_width() )
    {
        std::cerr << std::endl <<
        "Precondition, phi_init1 must have the same width of the input image img_rgb1."
        << std::endl;
    }
    if( phi_init1.get_height() != img_rgb1.get_height() )
    {
        std::cerr << std::endl <<
        "Precondition, phi_init1 must have the same height of the input image img_rgb1."
        << std::endl;
    }

    initialize_sums();
    calculate_means();
}
示例#20
0
void
ArOptions_evaluate_values(ArOptions* ao)
{
  assert(ao != NULL);
  if (ao == NULL) {
    return;
  }
  if (ao->artries) {
    ao->tries = check_value_liberal(ao->artries, "Invalid ar-tries value");
  }
  if (ao->ardelay) {
    ao->delay = check_value(ao->ardelay, "Invalid ar-delay value");
  }
}
示例#21
0
/*
 * This function opens all the datasets in a certain, checks the data using
 * dataset_vrfy function.
 *
 * Changes:     Updated function to use a dynamically calculated size,
 *              instead of the old SIZE #define.  This should allow it
 *              to function with an arbitrary number of processors.
 *
 *                                              JRM - 8/11/04
 */
int read_dataset(hid_t memspace, hid_t filespace, hid_t gid)
{
    int i, j, n, mpi_rank, mpi_size, size, attr_errors=0, vrfy_errors=0;
    char dname[32];
    DATATYPE *outdata = NULL, *indata = NULL;
    hid_t did;

    MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);

    size = get_size();

    indata = (DATATYPE*)HDmalloc((size_t)(size * size * sizeof(DATATYPE)));
    VRFY((indata != NULL), "HDmalloc succeeded for indata");

    outdata = (DATATYPE*)HDmalloc((size_t)(size * size * sizeof(DATATYPE)));
    VRFY((outdata != NULL), "HDmalloc succeeded for outdata");

    for(n=0; n<NDATASET; n++) {
        sprintf(dname, "dataset%d", n);
        did = H5Dopen(gid, dname);
        VRFY((did>0), dname);

        H5Dread(did, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT,
                indata);

        /* this is the original value */
        for(i=0; i<size; i++)
	    for(j=0; j<size; j++) {
	         *outdata = n*1000 + mpi_rank;
                 outdata++;
	    }
        outdata -= size * size;

        /* compare the original value(outdata) to the value in file(indata).*/
        vrfy_errors = check_value(indata, outdata, size);

        /* check attribute.*/
        if( (attr_errors = read_attribute(did, is_dset, n))>0 )
            vrfy_errors += attr_errors;

        H5Dclose(did);
    }

    HDfree(indata);
    HDfree(outdata);

    return vrfy_errors;
}
示例#22
0
static int hj_make_field(lua_State *lua)
{
  rj::Value *v = check_value(lua);
  if (!v) {
    lua_pushnil(lua);
    return 1;
  }

  lua_createtable(lua, 0, 2);
  lua_pushlightuserdata(lua, (void *)v);
  lua_setfield(lua, -2, "value");
  lua_pushvalue(lua, 1);
  lua_setfield(lua, -2, "userdata");
  return 1;
}
示例#23
0
static bool static_value(compile_t* c, LLVMValueRef value, ast_t* type,
  ast_t* pattern, LLVMBasicBlockRef next_block)
{
  // Get the type of the right-hand side of the pattern's eq() function.
  ast_t* param_type = eq_param_type(c, pattern);

  if(!is_subtype(type, param_type, NULL, c->opt))
  {
    // Switch to dynamic value checking.
    assert(LLVMTypeOf(value) == c->object_ptr);
    LLVMValueRef desc = gendesc_fetch(c, value);
    return dynamic_value_object(c, value, desc, pattern, next_block);
  }

  return check_value(c, pattern, param_type, value, next_block);
}
示例#24
0
static bool dynamic_value_object(compile_t* c, LLVMValueRef object,
  LLVMValueRef desc, ast_t* pattern, LLVMBasicBlockRef next_block)
{
  // Get the type of the right-hand side of the pattern's eq() function.
  ast_t* param_type = eq_param_type(c, pattern);

  // Build a base pointer that skips the object header.
  LLVMValueRef ptr = gendesc_ptr_to_fields(c, object, desc);

  // Check the runtime type. We pass a pointer to the fields because we may
  // still need to match a tuple type inside a type expression.
  if(!check_type(c, ptr, desc, param_type, next_block))
    return false;

  return check_value(c, pattern, param_type, object, next_block);
}
示例#25
0
static int
buffer_set_readonly(BufferObject *self, PyObject *value, void *closure)
{
    int readonly = 1;

    if (check_view_set(self, (const char *)closure)) {
        return -1;
    }
    if (check_value(value, (const char *)closure)) {
        return -1;
    }
    readonly = PyObject_IsTrue(value);
    if (readonly == -1) {
        return -1;
    }
    self->view_p->readonly = readonly;
    return 0;
}
示例#26
0
/* Open and read datasets and compare data
 *
 * Changes:     Updated function to use a dynamically calculated size,
 *              instead of the old SIZE #define.  This should allow it
 *              to function with an arbitrary number of processors.
 *
 *		Also added code to verify the results of dynamic memory
 *		allocations, and to free dynamically allocated memeory
 *		when we are done with it.
 *
 *                                              JRM - 8/16/04
 */
void group_dataset_read(hid_t fid, int mpi_rank, int m)
{
    int      ret, i, j, size;
    char     gname[64], dname[32];
    hid_t    gid, did;
    DATATYPE *outdata = NULL;
    DATATYPE *indata = NULL;

    size = get_size();

    indata = (DATATYPE*)HDmalloc((size_t)(size * size * sizeof(DATATYPE)));
    VRFY((indata != NULL), "HDmalloc succeeded for indata");

    outdata = (DATATYPE*)HDmalloc((size_t)(size * size * sizeof(DATATYPE)));
    VRFY((outdata != NULL), "HDmalloc succeeded for outdata");

    /* open every group under root group. */
    sprintf(gname, "group%d", m);
    gid = H5Gopen(fid, gname);
    VRFY((gid > 0), gname);

    /* check the data. */
    sprintf(dname, "dataset%d", m);
    did = H5Dopen(gid, dname);
    VRFY((did>0), dname);

    H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, indata);

    /* this is the original value */
    for(i=0; i<size; i++)
       for(j=0; j<size; j++) {
           outdata[(i * size) + j] = (i+j)*1000 + mpi_rank;
       }

    /* compare the original value(outdata) to the value in file(indata).*/
    ret = check_value(indata, outdata, size);
    VRFY((ret==0), "check the data");

    H5Dclose(did);
    H5Gclose(gid);

    HDfree(indata);
    HDfree(outdata);
}
示例#27
0
static int nand_reset_column(void)
{
	writel((NFC_CMD_RNDOUTSTART << NFC_RANDOM_READ_CMD1_OFFSET) |
	       (NFC_CMD_RNDOUT << NFC_RANDOM_READ_CMD0_OFFSET) |
	       (NFC_CMD_RNDOUTSTART << NFC_READ_CMD_OFFSET),
	       SUNXI_NFC_BASE + NFC_RCMD_SET);
	writel(0, SUNXI_NFC_BASE + NFC_ADDR_LOW);
	writel(NFC_SEND_CMD1 | NFC_SEND_CMD2 | NFC_RAW_CMD |
	       (1 << NFC_ADDR_NUM_OFFSET) | NFC_SEND_ADR | NFC_CMD_RNDOUT,
	       SUNXI_NFC_BASE + NFC_CMD);

	if (!check_value(SUNXI_NFC_BASE + NFC_ST, NFC_ST_CMD_INT_FLAG,
			 DEFAULT_TIMEOUT_US)) {
		printf("Error while initializing dma interrupt\n");
		return -1;
	}

	return 0;
}
示例#28
0
/*
 * struct Ganglia_metadata_message {
 *   char *type;
 *   char *name;
 *   char *value;
 *   char *units;
 *   u_int slope;
 *   u_int tmax;
 *   u_int dmax;
 * };
 */
int
Ganglia_metric_set( Ganglia_metric gmetric, char *name, char *value, char *type, char *units, unsigned int slope, unsigned int tmax, unsigned int dmax)
{
  apr_pool_t *gm_pool;

  /* Make sure all the params look ok */
  if(!gmetric||!name||!value||!type||!units||slope>4)
    return 1;

  gm_pool = (apr_pool_t*)gmetric->pool;

  /* Make sure none of the string params have a '"' in them (breaks the xml) */
  if(strchr(name, '"')||strchr(value,'"')||strchr(type,'"')||strchr(units,'"'))
    {
      return 2;
    }

  /* Make sure the type is one that is supported (string|int8|uint8|int16|uint16|int32|uint32|float|double)*/
  if(!(!strcmp(type,"string")||!strcmp(type,"int8")||!strcmp(type,"uint8")||
     !strcmp(type,"int16")||!strcmp(type,"uint16")||!strcmp(type,"int32")||
     !strcmp(type,"uint32")||!strcmp(type,"float")||!strcmp(type,"double")))
    {
      return 3;
    }

  /* Make sure we have a number for (int8|uint8|int16|uint16|int32|uint32|float|double)*/
  if(strcmp(type, "string") != 0)
    {
      if(check_value(type,value)) return 4;
    }

  /* All the data is there and validated... copy it into the structure */
  gmetric->msg->name = apr_pstrdup( gm_pool, name);
  gmetric->value = apr_pstrdup( gm_pool, value);
  gmetric->msg->type  = apr_pstrdup( gm_pool, type);
  gmetric->msg->units = apr_pstrdup( gm_pool, units);
  gmetric->msg->slope = slope;
  gmetric->msg->tmax = tmax;
  gmetric->msg->dmax = dmax;

  return 0;
}
示例#29
0
static int hj_iter(lua_State *lua)
{
  rj::Value *v = check_value(lua);
  if (!v) {
    lua_pushnil(lua);
    return 1;
  }

  switch (v->GetType()) {
  case rj::kObjectType:
    {
      heka_object_iter *hoi = static_cast<heka_object_iter *>
          (lua_newuserdata(lua, sizeof*hoi));
      hoi->it = new rj::Value::MemberIterator;
      hoi->end = new rj::Value::MemberIterator;
      luaL_getmetatable(lua, mozsvc_heka_object_iter);
      lua_setmetatable(lua, -2);
      if (!hoi->it || !hoi->end) {
        return luaL_error(lua, "memary allocation failure");
      }
      *hoi->it = v->MemberBegin();
      *hoi->end = v->MemberEnd();
      lua_pushlightuserdata(lua, (void *)v);
      lua_pushvalue(lua, 1);
      lua_pushcclosure(lua, hj_object_iter, 3);
    }
    break;
  case rj::kArrayType:
    {
      lua_pushnumber(lua, 0);
      lua_pushnumber(lua, (lua_Number)v->Size());
      lua_pushlightuserdata(lua, (void *)v);
      lua_pushvalue(lua, 1);
      lua_pushcclosure(lua, hj_array_iter, 4);
    }
    break;
  default:
    return luaL_error(lua, "iter() not allowed on a primitive type");
    break;
  }
  return 1;
}
示例#30
0
static int
set_py_ssize_t(Py_ssize_t *ip, PyObject *o, const char *name)
{
    Py_ssize_t i;

    if (check_value(o, name)) {
        return -1;
    }
    if (!INT_CHECK(o)) {
        PyErr_Format(PyExc_TypeError,
                     "property %100s must be a Python integer, not '%400s'",
                     name, Py_TYPE(o)->tp_name);
        return -1;
    }
    i = INT_AS_PY_SSIZE_T(o);
    if (PyErr_Occurred()) {
        return -1;
    }
    *ip = i;
    return 0;
}