<commit_before>/* Copyright (C) 2015, WSID   */

/* Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


#define CRANKCORE_INSIDE

#include <glib.h>
#include <glib-object.h>

#include "crankbase.h"
#include "crankshape.h"

#include "crankplaceentity.h"

#include "cranksession.h"
#include "cranksessionmodule.h"
#include "cranksessionmoduleplaced.h"


//////// Virtual function override /////////////////////////////////////////////

static void crank_session_module_placed_constructed (GObject *object);

static void crank_session_module_placed_dispose (GObject *object);



//////// Private functions /////////////////////////////////////////////////////

static void alloc_data_fini (gpointer alloc_data);

static void fini_pointer (gpointer data,
                          gpointer userdata);

static void fini_boxed (gpointer data,
                        gpointer userdata);

//////// Type Definition ///////////////////////////////////////////////////////

typedef struct _AllocData {
  goffset         offset;
  gssize          size;
  GFunc           fini;
  gpointer        fini_userdata;
  GDestroyNotify  fini_destroy;
} AllocData;

typedef struct _CrankSessionModulePlacedPrivate {
  // Allocation Data
  GArray *alloc_place;
  GArray *alloc_entity;

  gsize place_base_size;
  gsize entity_base_size;
  gsize place_size;
  gsize entity_size;

  // Places
  GPtrArray *places;
  //GPtrArray *places_active;

  // Entities
  GPtrArray *entities;
  GPtrArray *entities_placeless;

} CrankSessionModulePlacedPrivate;

G_DEFINE_TYPE_WITH_PRIVATE (CrankSessionModulePlaced,
                            crank_session_module_placed,
                            CRANK_TYPE_SESSION_MODULE)


//////// GTypeInstance /////////////////////////////////////////////////////////

static void
crank_session_module_placed_init (CrankSessionModulePlaced *self)
{
}

static void
crank_session_module_placed_class_init (CrankSessionModulePlacedClass *c)
{
  GObjectClass *c_gobject = G_OBJECT_CLASS (c);

  c_gobject->constructed =crank_session_module_placed_constructed;
  c_gobject->dispose = crank_session_module_placed_dispose;
}


//////// GObject ///////////////////////////////////////////////////////////////

static void
crank_session_module_placed_constructed (GObject *object)
{
  GObjectClass *pc_gobject;
  CrankSessionModulePlaced *module;
  CrankSessionModulePlacedPrivate *priv;

  pc_gobject = (GObjectClass*) crank_session_module_placed_parent_class;
  pc_gobject->constructed (object);

  module = (CrankSessionModulePlaced*) object;
  priv = crank_session_module_placed_get_instance_private (module);

  priv->alloc_place = g_array_new(FALSE, TRUE, sizeof(AllocData));
  priv->alloc_entity = g_array_new(FALSE, TRUE, sizeof(AllocData));
  g_array_set_clear_func (priv->alloc_place, alloc_data_fini);
  g_array_set_clear_func (priv->alloc_entity, alloc_data_fini);

  priv->place_size = priv->place_base_size;
  priv->entity_size = priv->entity_base_size;

  priv->places = g_ptr_array_new ();
  priv->entities = g_ptr_array_new ();
  priv->entities_placeless = g_ptr_array_new ();
}

static void
crank_session_module_placed_dispose (GObject *object)
{
  GObjectClass *pc_gobject;
  CrankSessionModulePlaced* module;
  CrankSessionModulePlacedPrivate* priv;

  pc_gobject = (GObjectClass*) crank_session_module_placed_parent_class;

  module = (CrankSessionModulePlaced*)object;
  priv = crank_session_module_placed_get_instance_private (module);

  g_array_unref (priv->alloc_place);
  g_array_unref (priv->alloc_entity);

  if (priv->places->len != 0)
    g_error ("Places are left and module is being disposed.");

  if (priv->entities->len != 0)
    g_error ("Entities are left and module is being disposed.");

  g_ptr_array_unref (priv->places);
  g_ptr_array_unref (priv->entities);
  g_ptr_array_unref (priv->entities_placeless);

  pc_gobject->dispose (object);
}



//////// Private Functions /////////////////////////////////////////////////////

static void
alloc_data_fini (gpointer data)
{
  AllocData *alloc_data = (AllocData*) data;

  alloc_data->fini_destroy (alloc_data->fini_userdata);
}

static void
fini_pointer (gpointer data,
              gpointer userdata)
{
  gpointer *pptr = (gpointer*)data;
  GDestroyNotify free_func = (GDestroyNotify)userdata;

  if (*pptr != NULL)
    free_func (*pptr);
}

static void
fini_boxed (gpointer data,
            gpointer userdata)
{
  gpointer *pptr = (gpointer*)data;<commit_msg>CrankSessionModulePlace: Not invoke (NULL) fini_destroy when disposing module itself.<commit_after>/* Copyright (C) 2015, WSID   */

/* Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


#define CRANKCORE_INSIDE

#include <glib.h>
#include <glib-object.h>

#include "crankbase.h"
#include "crankshape.h"

#include "crankplaceentity.h"

#include "cranksession.h"
#include "cranksessionmodule.h"
#include "cranksessionmoduleplaced.h"


//////// Virtual function override /////////////////////////////////////////////

static void crank_session_module_placed_constructed (GObject *object);

static void crank_session_module_placed_dispose (GObject *object);



//////// Private functions /////////////////////////////////////////////////////

static void alloc_data_fini (gpointer alloc_data);

static void fini_pointer (gpointer data,
                          gpointer userdata);

static void fini_boxed (gpointer data,
                        gpointer userdata);

//////// Type Definition ///////////////////////////////////////////////////////

typedef struct _AllocData {
  goffset         offset;
  gssize          size;
  GFunc           fini;
  gpointer        fini_userdata;
  GDestroyNotify  fini_destroy;
} AllocData;

typedef struct _CrankSessionModulePlacedPrivate {
  // Allocation Data
  GArray *alloc_place;
  GArray *alloc_entity;

  gsize place_base_size;
  gsize entity_base_size;
  gsize place_size;
  gsize entity_size;

  // Places
  GPtrArray *places;
  //GPtrArray *places_active;

  // Entities
  GPtrArray *entities;
  GPtrArray *entities_placeless;

} CrankSessionModulePlacedPrivate;

G_DEFINE_TYPE_WITH_PRIVATE (CrankSessionModulePlaced,
                            crank_session_module_placed,
                            CRANK_TYPE_SESSION_MODULE)


//////// GTypeInstance /////////////////////////////////////////////////////////

static void
crank_session_module_placed_init (CrankSessionModulePlaced *self)
{
}

static void
crank_session_module_placed_class_init (CrankSessionModulePlacedClass *c)
{
  GObjectClass *c_gobject = G_OBJECT_CLASS (c);

  c_gobject->constructed =crank_session_module_placed_constructed;
  c_gobject->dispose = crank_session_module_placed_dispose;
}


//////// GObject ///////////////////////////////////////////////////////////////

static void
crank_session_module_placed_constructed (GObject *object)
{
  GObjectClass *pc_gobject;
  CrankSessionModulePlaced *module;
  CrankSessionModulePlacedPrivate *priv;

  pc_gobject = (GObjectClass*) crank_session_module_placed_parent_class;
  pc_gobject->constructed (object);

  module = (CrankSessionModulePlaced*) object;
  priv = crank_session_module_placed_get_instance_private (module);

  priv->alloc_place = g_array_new(FALSE, TRUE, sizeof(AllocData));
  priv->alloc_entity = g_array_new(FALSE, TRUE, sizeof(AllocData));
  g_array_set_clear_func (priv->alloc_place, alloc_data_fini);
  g_array_set_clear_func (priv->alloc_entity, alloc_data_fini);

  priv->place_size = priv->place_base_size;
  priv->entity_size = priv->entity_base_size;

  priv->places = g_ptr_array_new ();
  priv->entities = g_ptr_array_new ();
  priv->entities_placeless = g_ptr_array_new ();
}

static void
crank_session_module_placed_dispose (GObject *object)
{
  GObjectClass *pc_gobject;
  CrankSessionModulePlaced* module;
  CrankSessionModulePlacedPrivate* priv;

  pc_gobject = (GObjectClass*) crank_session_module_placed_parent_class;

  module = (CrankSessionModulePlaced*)object;
  priv = crank_session_module_placed_get_instance_private (module);

  g_array_unref (priv->alloc_place);
  g_array_unref (priv->alloc_entity);

  if (priv->places->len != 0)
    g_error ("Places are left and module is being disposed.");

  if (priv->entities->len != 0)
    g_error ("Entities are left and module is being disposed.");

  g_ptr_array_unref (priv->places);
  g_ptr_array_unref (priv->entities);
  g_ptr_array_unref (priv->entities_placeless);

  pc_gobject->dispose (object);
}



//////// Private Functions /////////////////////////////////////////////////////

static void
alloc_data_fini (gpointer data)
{
  AllocData *alloc_data = (AllocData*) data;

  if (alloc_data->fini_destroy != NULL)
    alloc_data->fini_destroy (alloc_data->fini_userdata);
}

static void
fini_pointer (gpointer data,
              gpointer userdata)
{
  gpointer *pptr = (gpointer*)data;
  GDestroyNotify free_func = (GDestroyNotify)userdata;

  if (*pptr != NULL)
    free_func (*pptr);
}

static void
fini_boxed (gpointer data,
            gpointer userdata)
{
  gpointer *pptr = (gpointer*)data;
{'fraction_non_alphanumeric': 0.14148897723165885, 'fraction_numerical': 0.0010842067220816769, 'mean_word_length': 3.2361270570225793, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6942787', 'n_tokens_mistral': 3379, 'n_tokens_neox': 3225, 'n_words': 868}