<commit_before># frozen_string_literal: true
require 'gir_ffi/property_not_found_error'

GObject.load_class :Object

module GObject
  # Overrides for GObject, GObject's generic base class.
  class Object
    setup_method 'new'

    def initialize_with_automatic_gtype(properties = {})
      gparameters = properties.map do |name, value|
        name = name.to_s
        property_param_spec(name)
        GObject::Parameter.new.tap do |gparam|
          gparam.name = name
          gparam.value = value
        end
      end
      initialize_without_automatic_gtype(self.class.gtype, gparameters)
    end

    alias_method :initialize_without_automatic_gtype, :initialize
    alias_method :initialize, :initialize_with_automatic_gtype
    alias_method :base_initialize, :initialize

    private :base_initialize

    remove_method :ref

    def ref
      Lib.g_object_ref self
      self
    end

    def store_pointer(ptr)
      super
      klass = self.class
      ObjectSpace.define_finalizer self, klass.make_finalizer(ptr, klass.name)
    end

    def self.make_finalizer(ptr, name)
      proc do
        rc = GObject::Object::Struct.new(ptr)[:ref_count]
        if rc.zero?
          warn "not unreffing #{name}:#{ptr} (#{rc})"
        else
          GObject::Lib.g_object_unref ptr
        end
      end
    end

    # TODO: Generate accessor methods from GIR at class definition time
    def method_missing(method, *args)
      getter_name = "get_#{method}"
      return send(getter_name, *args) if respond_to?(getter_name)<commit_msg>Assume class knows its own name during finalization<commit_after># frozen_string_literal: true
require 'gir_ffi/property_not_found_error'

GObject.load_class :Object

module GObject
  # Overrides for GObject, GObject's generic base class.
  class Object
    setup_method 'new'

    def initialize_with_automatic_gtype(properties = {})
      gparameters = properties.map do |name, value|
        name = name.to_s
        property_param_spec(name)
        GObject::Parameter.new.tap do |gparam|
          gparam.name = name
          gparam.value = value
        end
      end
      initialize_without_automatic_gtype(self.class.gtype, gparameters)
    end

    alias_method :initialize_without_automatic_gtype, :initialize
    alias_method :initialize, :initialize_with_automatic_gtype
    alias_method :base_initialize, :initialize

    private :base_initialize

    remove_method :ref

    def ref
      Lib.g_object_ref self
      self
    end

    def store_pointer(ptr)
      super
      ObjectSpace.define_finalizer self, self.class.make_finalizer(ptr)
    end

    def self.make_finalizer(ptr)
      proc do
        rc = GObject::Object::Struct.new(ptr)[:ref_count]
        if rc.zero?
          warn "not unreffing #{name}:#{ptr} (#{rc})"
        else
          GObject::Lib.g_object_unref ptr
        end
      end
    end

    # TODO: Generate accessor methods from GIR at class definition time
    def method_missing(method, *args)
      getter_name = "get_#{method}"
      return send(getter_name, *args) if respond_to?(getter_name)
{'fraction_non_alphanumeric': 0.07712248865845756, 'fraction_numerical': 0.0, 'mean_word_length': 2.927480916030534, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '630956', 'n_tokens_mistral': 957, 'n_tokens_neox': 941, 'n_words': 224}