Skip to content

opencog::attentionbank(...) should not rely that objects compared by references are equal #6

@stellarspot

Description

@stellarspot

opencog::attentionbank(AtomSpace* asp) method in AttentionBank has the following check to compare if two AtomSpaces are equal:

https://github.com/opencog/opencog/blob/802f0ec84e90db55389ee8ace40be6004a1ec9d1/opencog/attentionbank/bank/AttentionBank.cc#L249

This can fail if one AtomSpace is deleted and immediately after that the second one is created.
because the the new AtomSpace can be created with the same memory address as the previous one.

I encountered it in the Python test that can or can't fail depending with each address the new AtomSpace is created:
(note that the opencog/opencog#3549 pull request is required to run the test)

import unittest
from unittest import TestCase

from opencog.type_constructors import *
from opencog.utilities import initialize_opencog, finalize_opencog
from opencog.bank import AttentionBank, af_bindlink


class AttentionBankTest(TestCase):

    def setUp(self):
        self.atomspace = AtomSpace()
        initialize_opencog(self.atomspace)

    def tearDown(self):
        finalize_opencog()
        del self.atomspace

    def test_get_handles_by_av_different_as1(self):
        attention_bank = AttentionBank(self.atomspace)

        node1 = ConceptNode("node1")
        attention_bank.set_sti(node1, 2.0)

        atoms = attention_bank.get_atoms_by_av(1.0, 4.0)
        self.assertEqual(1, len(atoms))

    def test_get_handles_by_av_different_as2(self):
        attention_bank = AttentionBank(self.atomspace)

        node2 = ConceptNode("node2")
        attention_bank.set_sti(node2, 2.0)

        atoms = attention_bank.get_atoms_by_av(1.0, 4.0)
        self.assertEqual(1, len(atoms))


if __name__ == '__main__':
    unittest.main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions