示例#1
0
void gpy_vec_free (gpy_vector_t * v)
{
  if (v)
    {
      if (v->vector)
	gpy_free (v->vector);
      gpy_free (v);
    }
  v = NULL;
}
示例#2
0
/* free's the object state not the */
void gpy_object_func_dealloc (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_DECL);
  gpy_object_state_t object_state = OBJECT_STATE (self);

  gpy_free (object_state.state);
  object_state.state = NULL;
}
示例#3
0
void gpy_obj_string_destroy (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_DECL);
  gpy_object_state_t * object_state = self->o.object_state;

  gpy_free (object_state->state);
  object_state->state = NULL;
}
示例#4
0
/* Destroys self (type) not the object state */
void gpy_obj_integer_destroy (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t x = OBJECT_STATE (self);
  struct gpy_obj_integer_t *x1 =
    (struct gpy_obj_integer_t *) x.state;
  gpy_free (x1);
  x.state = NULL;
}
示例#5
0
void gpy_obj_list_destroy (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t * x = self->o.object_state;
  struct gpy_obj_list *x1 = (struct gpy_obj_list *)
    x->state;

  gpy_free (x1);
  x->state = NULL;
}
示例#6
0
void gpy_dd_hash_grow_table (gpy_hash_tab_t * tbl)
{
  unsigned int prev_size = tbl->size, size = 0, i;
  gpy_hash_entry_t *prev_array = tbl->array, *array;

  size = gpy_threshold_alloc (prev_size);
  array = (gpy_hash_entry_t *)
    gpy_calloc (size, sizeof (gpy_hash_entry_t));

  tbl->length = 0;
  tbl->size = size;
  tbl->array = array;

  for (i = 0; i < prev_size; ++i)
    {
      gpy_hashval_t h = prev_array[i].hash;
      void * s = prev_array[i].data;

      if (s)
        gpy_dd_hash_insert (h, s, tbl);
    }
  if (prev_array)
    gpy_free (prev_array);
}
示例#7
0
void gpy_wrap_builtins (gpy_typedef_t * const type, size_t len)
{
  struct gpy_builtinAttribs_t * builtins = type->builtins;
  struct gpy_builtinAttribs_t atm;

  if (len > 1)
    {
      gpy_object_t ** folded = (gpy_object_t **)
	gpy_calloc (len -1, sizeof (gpy_object_t *));

      int idx;
      for (idx = 0; builtins[idx].identifier != NULL; ++idx)
	{
	  atm = builtins [idx];
	  gpy_object_t * builtin = NULL_OBJECT;

	  gpy_object_t ** args = (gpy_object_t **)
	    gpy_calloc (4, sizeof(gpy_object_t*));

	  gpy_literal_t i;
	  i.type = TYPE_STRING;
	  i.literal.string = (char *)atm.identifier;

	  gpy_literal_t p;
	  p.type = TYPE_ADDR;
	  p.literal.addr = (unsigned char *) atm.addr;

	  gpy_literal_t n;
	  n.type = TYPE_INTEGER;
	  n.literal.integer = atm.nargs;

	  gpy_object_t a1 = { .T = TYPE_OBJECT_LIT, .o.literal = &i };
	  gpy_object_t a2 = { .T = TYPE_OBJECT_LIT, .o.literal = &p };
	  gpy_object_t a3 = { .T = TYPE_OBJECT_LIT, .o.literal = &n };
	  gpy_object_t a4 = { .T = TYPE_NULL, .o.literal = NULL };

	  args[0] = &a1;
	  args[1] = &a2;
	  args[2] = &a3;
	  args[3] = &a4;

	  gpy_typedef_t * def = __gpy_func_type_node;
	  builtin = def->tp_new (def, args);
	  gpy_free (args);
	  gpy_assert (builtin->T == TYPE_OBJECT_DECL);

	  folded [idx] = builtin;
	}
      /* Now to append/create the attribute access table .. */
      struct gpy_object_attrib_t ** members = (struct gpy_object_attrib_t **)
	gpy_calloc (len, sizeof (struct gpy_object_attrib_t *));

      for (idx = 0; idx < len - 1; ++idx)
	{
	  atm = builtins [idx];
	  struct gpy_object_attrib_t * fattr = (struct gpy_object_attrib_t *)
	    gpy_malloc (sizeof (struct gpy_object_attrib_t));

	  fattr->identifier = strdup (atm.identifier);
	  fattr->T = GPY_CATTR;
	  fattr->offset = 0;
	  fattr->addr = folded [idx];

	  members[idx] = fattr;
	}
      // sentinal
      members[idx] = NULL;
      type->members_defintion = members;
      gpy_free (folded);
    }
}