コード例 #1
0
ファイル: Gdyn-remote.c プロジェクト: vegard/libunwind
static void
free_regions (unw_dyn_region_info_t *region)
{
  if (region->next)
    free_regions (region->next);
  free (region);
}
コード例 #2
0
ファイル: Gdyn-remote.c プロジェクト: vegard/libunwind
static void
free_dyn_info (unw_dyn_info_t *di)
{
  switch (di->format)
    {
    case UNW_INFO_FORMAT_DYNAMIC:
      if (di->u.pi.regions)
        {
          free_regions (di->u.pi.regions);
          di->u.pi.regions = NULL;
        }
      break;

    case UNW_INFO_FORMAT_TABLE:
      if (di->u.ti.table_data)
        {
          free (di->u.ti.table_data);
          di->u.ti.table_data = NULL;
        }
      break;

    case UNW_INFO_FORMAT_REMOTE_TABLE:
    default:
      break;
    }
}
コード例 #3
0
ファイル: save.c プロジェクト: mbi/NitroHack
void freelev(xchar levnum)
{
	struct level *lev = levels[levnum];
	
	/* must be freed before mons, objs, and buried objs */
	free_timers(lev);
	free_light_sources(lev);

	free_monchn(lev->monlist);
	free_worm(lev);
	freetrapchn(lev->lev_traps);
	free_objchn(lev->objlist);
	free_objchn(lev->buriedobjlist);
	free_objchn(lev->billobjs);
	
	lev->monlist = NULL;
	lev->lev_traps = NULL;
	lev->objlist = NULL;
	lev->buriedobjlist = NULL;
	lev->billobjs = NULL;
	
	free_engravings(lev);
	freedamage(lev);
	free_regions(lev);
	
	free(lev);
	levels[levnum] = NULL;
}
コード例 #4
0
ファイル: Gdyn-remote.c プロジェクト: vegard/libunwind
static int
intern_regions (unw_addr_space_t as, unw_accessors_t *a,
                unw_word_t *addr, unw_dyn_region_info_t **regionp, void *arg)
{
  uint32_t insn_count, op_count, i;
  unw_dyn_region_info_t *region;
  unw_word_t next_addr;
  int ret;

  *regionp = NULL;

  if (!*addr)
    return 0;   /* NULL region-list */

  if ((ret = fetchw (as, a, addr, &next_addr, arg)) < 0
      || (ret = fetch32 (as, a, addr, (int32_t *) &insn_count, arg)) < 0
      || (ret = fetch32 (as, a, addr, (int32_t *) &op_count, arg)) < 0)
    return ret;

  region = calloc (1, _U_dyn_region_info_size (op_count));
  if (!region)
    {
      ret = -UNW_ENOMEM;
      goto out;
    }

  region->insn_count = insn_count;
  region->op_count = op_count;
  for (i = 0; i < op_count; ++i)
    if ((ret = intern_op (as, a, addr, region->op + i, arg)) < 0)
      goto out;

  if (next_addr)
    if ((ret = intern_regions (as, a, &next_addr, &region->next, arg)) < 0)
      goto out;

  *regionp = region;
  return 0;

 out:
  if (region)
    free_regions (region);
  return ret;
}
コード例 #5
0
void
rest_regions(struct memfile *mf, struct level *lev, boolean ghostly)
{       /* If a bones file restore */
    int i, j;
    unsigned len1, len2;
    long tmstamp;
    char *msg_buf;
    struct region *r;

    free_regions(lev);  /* Just for security */
    mfmagic_check(mf, REGION_MAGIC);
    tmstamp = save_decode_32(mread32(mf), moves, moves);
    if (ghostly)
        tmstamp = 0;
    else
        tmstamp = (moves - tmstamp);
    lev->n_regions = mread32(mf);
    lev->max_regions = lev->n_regions;
    if (lev->n_regions > 0)
        lev->regions = malloc(sizeof (struct region *) * lev->n_regions);

    for (i = 0; i < lev->n_regions; i++) {
        lev->regions[i] = malloc(sizeof (struct region));

        r = lev->regions[i];
        memset(r, 0, sizeof (struct region));

        r->lev = lev;

        restore_rect(mf, &r->bounding_box);
        r->attach_2_m = mread32(mf);
        r->effect_id = mread32(mf);
        r->arg = mread32(mf);
        r->nrects = mread16(mf);
        if (r->nrects > 0)
            r->rects = malloc(sizeof (struct nhrect) * r->nrects);
        for (j = 0; j < r->nrects; j++)
            restore_rect(mf, &r->rects[j]);
        r->ttl = mread16(mf);
        r->expire_f = mread16(mf);
        r->can_enter_f = mread16(mf);
        r->enter_f = mread16(mf);
        r->can_leave_f = mread16(mf);
        r->leave_f = mread16(mf);
        r->inside_f = mread16(mf);
        r->n_monst = mread16(mf);
        r->max_monst = r->n_monst;
        r->player_flags = mread8(mf);
        r->attach_2_u = mread8(mf);
        r->visible = mread8(mf);

        if (r->n_monst > 0)
            r->monsters = malloc(sizeof (unsigned) * r->n_monst);
        for (j = 0; j < r->n_monst; j++)
            r->monsters[j] = mread32(mf);

        len1 = mread16(mf);
        len2 = mread16(mf);

        if (len1 > 0) {
            msg_buf = malloc(len1);
            mread(mf, msg_buf, len1);
            msg_buf[len1 - 1] = '\0';
            r->enter_msg = msg_buf;
        }

        if (len2 > 0) {
            msg_buf = malloc(len2);
            mread(mf, msg_buf, len2);
            msg_buf[len2 - 1] = '\0';
            r->leave_msg = msg_buf;
        }

        /* check for expired region */
        if (r->ttl >= 0)
            r->ttl = (r->ttl > tmstamp) ? r->ttl - tmstamp : 0;

        if (ghostly) {  /* settings pertained to old player */
            clear_hero_inside(r);
            clear_heros_fault(r);
        }
    }
    for (i = lev->n_regions - 1; i >= 0; i--)
        if (ghostly && lev->regions[i]->n_monst > 0)
            reset_region_mids(lev->regions[i]);
}
コード例 #6
0
bool Cconnectivity_analysis::On_Execute(void)
{
	CSG_Grid *pinpgrid, *bingrid, *symb_grid, *hgrid;
	CSG_Shapes *pOutlines;

	bool filter, corners_centers, remove_marginal_regions;
	unsigned short numrows;
	unsigned short numcols;
	unsigned char center;
	double xmin;
	double ymin;
	short interm_grid_created;
    simple_REGIONC_list *reg_first;
    simple_REGIONC_list *reg_last;
	simple_REGIONC_list *reg_curr;

	pinpgrid = Parameters ("INPUT_GRID")->asGrid();
	bingrid = Parameters ("FILTERED_MASK")->asGrid();
	filter = Parameters ("FILTER")->asBool();
	corners_centers = Parameters ("BORDER_PIXEL_CENTERS")->asBool();
	remove_marginal_regions = Parameters ("REMOVE_MARGINAL_REGIONS")->asBool();
	pOutlines = Parameters("OUTLINES")->asShapes();
	symb_grid = Parameters ("SYMBOLIC_IMAGE")->asGrid();
	CSG_String	sName = pOutlines->Get_Name();
	pOutlines->Destroy();
	pOutlines->Set_Name(sName);
	pOutlines->Add_Field(SG_T("ID"), SG_DATATYPE_Int);

	numrows=pinpgrid->Get_NY()+2;
	numcols=pinpgrid->Get_NX()+2;
//	xmin=pinpgrid->Get_XMin()-2*pinpgrid->Get_Cellsize();
//	ymin=pinpgrid->Get_YMin()-2*pinpgrid->Get_Cellsize();

	xmin=pinpgrid->Get_XMin();
	ymin=pinpgrid->Get_YMin();

	unsigned char **bin_image;
	long **symb_image;

	if (corners_centers)
		center = 1;
	else
		center = 0;

	bin_image = (unsigned char **) matrix_all_alloc (numrows, numcols, 'U', 0);
	symb_image = (long **) matrix_all_alloc (numrows, numcols, 'L', 0);

	interm_grid_created = 0;

	//SG_Free(bin_image);
	//CSG_Grid *pTmp = new CSG_Grid();
	//delete pTmp;

	if (filter)
	{
		if (bingrid == NULL)
		{
			SG_UI_Msg_Add(_TL("Filtered mask will be created automatically ..."), true);

			bingrid = SG_Create_Grid(SG_DATATYPE_Char,
				                     pinpgrid->Get_NX(),
									 pinpgrid->Get_NY(),
									 pinpgrid->Get_Cellsize(),
									 pinpgrid->Get_XMin(),
									 pinpgrid->Get_YMin());

			if (bingrid == NULL)
			{
				SG_UI_Msg_Add_Error(_TL("Unable to create filtered mask grid!"));
	            matrix_all_free ((void **) bin_image);
	            matrix_all_free ((void **) symb_image);

				return (false);
			}

			Parameters("FILTERED_MASK")->Set_Value(bingrid);
			interm_grid_created = 1;
		}


		//-----------------------------------------------------
		RUN_MODULE("grid_filter"			, 13,
				SET_PARAMETER("INPUT_GRID"  , pinpgrid)
			&&	SET_PARAMETER("OUTPUT_GRID"	, bingrid)
			&&	SET_PARAMETER("RADIUS"		, Parameters ("SIZE")->asInt())
		)

		hgrid = bingrid;
	}
	else
	{
	    hgrid = pinpgrid;
	}

    for (int y = 0; y < hgrid->Get_NY () && Set_Progress(y, hgrid->Get_NY()); y++)
	{
	    for (int x = 0; x < hgrid->Get_NX(); x++)
		{
            if (hgrid->is_NoData(x,y))
		        bin_image[y+1][x+1] = 0;
			else
		        bin_image[y+1][x+1] = hgrid->asChar(x,y);
		}
	}


	// Here the regions are removed which have contact with the image margins;
	// this is achieved by a region growing

	if (remove_marginal_regions)
	{
		for (int y = 1; y < numrows - 1; y++)
		{
			if (bin_image [y][1] != 0)
				background_region_growing (bin_image, numrows, numcols, y, 1);

			if (bin_image [y][numcols - 2] != 0)
				background_region_growing (bin_image, numrows, numcols, y, numcols-2);
		}

		for (int x = 1; x < numcols - 1; x++)
		{
			if (bin_image [1][x] != 0)
				background_region_growing (bin_image, numrows, numcols, 1, x);

			if (bin_image [numrows-2][x] != 0)
				background_region_growing (bin_image, numrows, numcols, numrows-2, x);
		}

		if (filter)
		{
		    for (int y = 0; y < bingrid->Get_NY (); y++)
 	        {
     		    #pragma omp parallel for
		        for (int x = 0; x < bingrid->Get_NX(); x++)
		        {
			        bingrid->Set_Value(x, y, bin_image[y+1][x+1]);
		        }
	        }
		}
	}

	if (interm_grid_created)
		bingrid->Destroy();


	// The function which does the proper work: 
	// computation of the symbolic image, construction of the border chains (shapes)
	
	comb_contour_region_marking (numrows,
                                 numcols,
                                 bin_image,
                                 symb_image,
                                 &reg_first,
                                 &reg_last,
                                 center);


	for (int y = 0; y < symb_grid->Get_NY () && Set_Progress(y, symb_grid->Get_NY()); y++)
 	{
		#pragma omp parallel for
		for (int x = 0; x < symb_grid->Get_NX(); x++)
		{
			symb_grid->Set_Value(x, y, symb_image[y+1][x+1]);
		}
	}


	// Here the shapes are generated

	int iPolygon;

	for (iPolygon = 0, reg_curr = reg_first; reg_curr != NULL; reg_curr = reg_curr -> next, iPolygon++)
	{
		CSG_Shape	*pShape = pOutlines->Add_Shape();

		pShape->Set_Value(0, iPolygon);		// set ID field (= first field in table) to polygon ID

		for (simple_PIXELC_list *pix_curr = reg_curr->first_pix; pix_curr != NULL; pix_curr = pix_curr->next)
		{
			TSG_Point point = symb_grid->Get_System().Get_Grid_to_World(pix_curr->col - 1, pix_curr->row - 1);
			pShape->Add_Point(point, 0);
		}

		int iHoles;
		simple_INNER_REGION_list *inner_curr;

		for (iHoles=0, inner_curr = reg_curr->inner_first;
			 iHoles < reg_curr->num_holes;
			 iHoles++, inner_curr = inner_curr->next)
		{
			for (simple_PIXELC_list *pix_curr = inner_curr->first_pix; pix_curr != NULL; pix_curr = pix_curr->next)
			{
				TSG_Point point = symb_grid->Get_System().Get_Grid_to_World(pix_curr->col - 1, pix_curr->row - 1);
				pShape->Add_Point(point, iHoles+1);
			}
		}

        if (!corners_centers)
            shift_shape (pShape, -Get_Cellsize()/2.0, -Get_Cellsize()/2.0);
	}

	matrix_all_free ((void **) bin_image);
	matrix_all_free ((void **) symb_image);
	free_regions (&reg_first, &reg_last);

	return( true );
}