<commit_before>/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/


#include <vis.h>
#include <stdio.h>

#ifdef DMALLOC
#include "dmalloc.h"
#endif

typedef Ppoint_t ilcoord_t;

#ifdef DEBUG
static void printVconfig(vconfig_t * cp);
static void printVis(char *lbl, COORD * vis, int n);
static void printDad(int *vis, int n);
#endif

#ifdef GASP
static void gasp_print_obstacles(vconfig_t * conf);
static void gasp_print_point(Ppoint_t p);
static void gasp_print_polyline(Ppolyline_t * route);
static void gasp_print_bezier(Ppolyline_t * route);
#endif

#if 0				/* not used */
static void *myrealloc(void *p, size_t newsize)
{
    void *rv;

    if (p == (void *) 0)
	rv = malloc(newsize);
    else
	rv = realloc(p, newsize);
    return rv;
}
#endif

static void *mymalloc(size_t newsize)
{
    void *rv;

    if (newsize > 0)
	rv = malloc(newsize);
    else
	rv = (void *) 0;
    return rv;
}


vconfig_t *Pobsopen(Ppoly_t ** obs, int n_obs)
{
    vconfig_t *rv;
    int poly_i, pt_i, i, n;
    int start, end;

    rv = malloc(sizeof(vconfig_t));

    /* get storage */
    n = 0;
    for (poly_i = 0; poly_i < n_obs; poly_i++)
	n = n + obs[poly_i]->pn;
    rv->P = mymalloc(n * sizeof(Ppoint_t));
    rv->start = mymalloc((n_obs + 1) * sizeof(int));
    rv->next = mymalloc(n * sizeof(int));
    rv->prev = mymalloc(n * sizeof(int));
    rv->N = n;
    rv->Npoly = n_obs;

    /* build arrays */
    i = 0;
    for (poly_i = 0; poly_i < n_obs; poly_i++) {
	start = i;
	rv->start[poly_i] = start;
	end = start + obs[poly_i]->pn - 1;
	for (pt_i = 0; pt_i < obs[poly_i]->pn; pt_i++) {
	    rv->P[i] = obs[poly_i]->ps[pt_i];
	    rv->next[i] = i + 1;
	    rv->prev[i] = i - 1;
	    i++;
	}
	rv->next[end] = start;
	rv->prev[start] = end;
    }
    rv->start[poly_i] = i;
    visibility(rv);
    return rv;
}

void Pobsclose(vconfig_t * config)
{
    free(config->P);
    free(config->start);
    free(config->next);
    free(config->prev);
    free(config->vis);
}

int Pobspath(vconfig_t * config, Ppoint_t p0, int poly0, Ppoint_t p1,
	     int poly1, Ppolyline_t * output_route)
{
    int i, j, *dad;
    int opn;
    Ppoint_t *ops;
    COORD *ptvis0, *ptvis1;<commit_msg>Fix memory leak - Pobsclose should free object as well as its parts.<commit_after>/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/


#include <vis.h>
#include <stdio.h>

#ifdef DMALLOC
#include "dmalloc.h"
#endif

typedef Ppoint_t ilcoord_t;

#ifdef DEBUG
static void printVconfig(vconfig_t * cp);
static void printVis(char *lbl, COORD * vis, int n);
static void printDad(int *vis, int n);
#endif

#ifdef GASP
static void gasp_print_obstacles(vconfig_t * conf);
static void gasp_print_point(Ppoint_t p);
static void gasp_print_polyline(Ppolyline_t * route);
static void gasp_print_bezier(Ppolyline_t * route);
#endif

#if 0				/* not used */
static void *myrealloc(void *p, size_t newsize)
{
    void *rv;

    if (p == (void *) 0)
	rv = malloc(newsize);
    else
	rv = realloc(p, newsize);
    return rv;
}
#endif

static void *mymalloc(size_t newsize)
{
    void *rv;

    if (newsize > 0)
	rv = malloc(newsize);
    else
	rv = (void *) 0;
    return rv;
}


vconfig_t *Pobsopen(Ppoly_t ** obs, int n_obs)
{
    vconfig_t *rv;
    int poly_i, pt_i, i, n;
    int start, end;

    rv = malloc(sizeof(vconfig_t));

    /* get storage */
    n = 0;
    for (poly_i = 0; poly_i < n_obs; poly_i++)
	n = n + obs[poly_i]->pn;
    rv->P = mymalloc(n * sizeof(Ppoint_t));
    rv->start = mymalloc((n_obs + 1) * sizeof(int));
    rv->next = mymalloc(n * sizeof(int));
    rv->prev = mymalloc(n * sizeof(int));
    rv->N = n;
    rv->Npoly = n_obs;

    /* build arrays */
    i = 0;
    for (poly_i = 0; poly_i < n_obs; poly_i++) {
	start = i;
	rv->start[poly_i] = start;
	end = start + obs[poly_i]->pn - 1;
	for (pt_i = 0; pt_i < obs[poly_i]->pn; pt_i++) {
	    rv->P[i] = obs[poly_i]->ps[pt_i];
	    rv->next[i] = i + 1;
	    rv->prev[i] = i - 1;
	    i++;
	}
	rv->next[end] = start;
	rv->prev[start] = end;
    }
    rv->start[poly_i] = i;
    visibility(rv);
    return rv;
}

void Pobsclose(vconfig_t * config)
{
    free(config->P);
    free(config->start);
    free(config->next);
    free(config->prev);
    free(config->vis);
    free(config);
}

int Pobspath(vconfig_t * config, Ppoint_t p0, int poly0, Ppoint_t p1,
	     int poly1, Ppolyline_t * output_route)
{
    int i, j, *dad;
    int opn;
    Ppoint_t *ops;
    COORD *ptvis0, *ptvis1;
{'fraction_non_alphanumeric': 0.17600954165956723, 'fraction_numerical': 0.010563980235133753, 'mean_word_length': 2.1764069264069263, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3903647', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2083, 'n_words': 527}