<commit_before>/*
 * Copyright 2011, 2012, 2013, 2014 <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "esql_private.h"

typedef struct Esql_Row_Iterator
{
   Eina_Iterator   iterator;
   Esql_Res *res;
   Esql_Row *current;
} Esql_Row_Iterator;

static Eina_Bool
esql_row_iterator_next(Esql_Row_Iterator *it,
                       Esql_Row         **r)
{
   Eina_Inlist *l;

   if (!it->current) return EINA_FALSE;

   *r = (Esql_Row *)it->current;

   l = EINA_INLIST_GET((Esql_Row *)it->current);
   it->current = l ? EINA_INLIST_CONTAINER_GET(l->next, Esql_Row) : NULL;

   return EINA_TRUE;
}

static Esql_Res *
esql_row_iterator_container_get(Esql_Row_Iterator *it)
{
   return it->res;
}

static void
eina_row_iterator_free(Esql_Row_Iterator *it)
{
   esql_res_unref(it->res);
   free(it);
}

static void
esql_row_free(Esql_Row *r)
{
   eina_value_flush(&(r->value));
   esql_row_mp_free(r);
}

static void
_esql_res_free(Esql_Res *res)
{
   Esql_Row *r;
   Eina_Inlist *l;

   DBG("res=%p (refcount=%d)", res, res->refcount);

   if (res->rows)
     EINA_INLIST_FOREACH_SAFE(res->rows, l, r)
       esql_row_free(r);

   if (res->desc)
     {
        /* memset is not needed, but leave it here to find if people
         * kept reference to values after row is removed, see below.
         */
        memset(res->desc, 0, sizeof(res->desc));
        free(res->desc);

        /* NOTE: after this point, if users are still holding 'desc' they will
         * have problems. This can be done if user calls eina_value_copy()
         * on some esql_row_value_struct_get()
         *<commit_msg>Fix a memset over a struct with size of pointer instead of struct.<commit_after>/*
 * Copyright 2011, 2012, 2013, 2014 <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "esql_private.h"

typedef struct Esql_Row_Iterator
{
   Eina_Iterator   iterator;
   Esql_Res *res;
   Esql_Row *current;
} Esql_Row_Iterator;

static Eina_Bool
esql_row_iterator_next(Esql_Row_Iterator *it,
                       Esql_Row         **r)
{
   Eina_Inlist *l;

   if (!it->current) return EINA_FALSE;

   *r = (Esql_Row *)it->current;

   l = EINA_INLIST_GET((Esql_Row *)it->current);
   it->current = l ? EINA_INLIST_CONTAINER_GET(l->next, Esql_Row) : NULL;

   return EINA_TRUE;
}

static Esql_Res *
esql_row_iterator_container_get(Esql_Row_Iterator *it)
{
   return it->res;
}

static void
eina_row_iterator_free(Esql_Row_Iterator *it)
{
   esql_res_unref(it->res);
   free(it);
}

static void
esql_row_free(Esql_Row *r)
{
   eina_value_flush(&(r->value));
   esql_row_mp_free(r);
}

static void
_esql_res_free(Esql_Res *res)
{
   Esql_Row *r;
   Eina_Inlist *l;

   DBG("res=%p (refcount=%d)", res, res->refcount);

   if (res->rows)
     EINA_INLIST_FOREACH_SAFE(res->rows, l, r)
       esql_row_free(r);

   if (res->desc)
     {
        /* memset is not needed, but leave it here to find if people
         * kept reference to values after row is removed, see below.
         */
        memset(res->desc, 0, sizeof(*res->desc));
        free(res->desc);

        /* NOTE: after this point, if users are still holding 'desc' they will
         * have problems. This can be done if user calls eina_value_copy()
         * on some esql_row_value_struct_get()
         *
{'fraction_non_alphanumeric': 0.10039456378781236, 'fraction_numerical': 0.008329679964927663, 'mean_word_length': 3.2724719101123596, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4849075', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1517, 'n_words': 484}