<commit_before>
/*
 * Copyright (C) 2010-2013, Directed Edge, Inc. | Licensed under the MPL and LGPL
 */

#include <ruby.h>
#include <QDebug>
#include <QList>

namespace SharedObject
{
    class Scope
    {
    public:
        Scope()
        {
            m_self = Data_Wrap_Struct(rb_cData, &mark, &free, this);
            rb_gc_register_address(&m_self);
        }

        ~Scope()
        {
            rb_gc_unregister_address(&m_self);
        }

        static void mark(Scope *scope)
        {
            scope->markObjects();
        }

        static void free(Scope *scope)
        {
            // do nothing.
        }

        void markObjects()
        {
            foreach(VALUE obj, m_objects)
            {
                rb_gc_mark(obj);
            }
        }

        void registerObject(VALUE obj)
        {
            m_objects.append(obj);
        }

    private:
        VALUE m_self;
        QList<VALUE> m_objects;
    };

    template <class T>
    class Wrapper
    {
    public:
        Wrapper(Scope &scope)
        {
            T *object = new T();
            m_value = Data_Wrap_Struct(rb_cData, 0, &free_obj, object);
            scope.registerObject(m_value);
        }

        Wrapper(VALUE val)<commit_msg>Store scoped objects in registered ruby array<commit_after>
/*
 * Copyright (C) 2010-2013, Directed Edge, Inc. | Licensed under the MPL and LGPL
 */

#include <ruby.h>
#include <QDebug>
#include <QList>

namespace SharedObject
{
    class Scope
    {
    public:
        Scope()
        {
            m_objects = rb_ary_new();
            rb_gc_register_address(&m_objects);
        }

        ~Scope()
        {
            rb_gc_unregister_address(&m_objects);
        }

        void registerObject(VALUE obj)
        {
            rb_ary_push(m_objects, obj);
        }

    private:
        VALUE m_objects;
    };

    template <class T>
    class Wrapper
    {
    public:
        Wrapper(Scope &scope)
        {
            T *object = new T();
            m_value = Data_Wrap_Struct(rb_cData, 0, &free_obj, object);
            scope.registerObject(m_value);
        }

        Wrapper(VALUE val)
{'fraction_non_alphanumeric': 0.10009267840593142, 'fraction_numerical': 0.008341056533827619, 'mean_word_length': 1.5489964580873672, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, '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': '723614', 'n_tokens_mistral': 693, 'n_tokens_neox': 650, 'n_words': 142}