Skip to content

Commit

Permalink
Merge pull request #881 from Zbysekz/getSpecDoubleFree2
Browse files Browse the repository at this point in the history
Get spec double free2
  • Loading branch information
breznak authored Sep 2, 2020
2 parents b79dd3a + a2b8ab1 commit e376e49
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion bindings/py/cpp_src/bindings/engine/py_Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ namespace htm_ext
///////////////////
// Spec
///////////////////
py::class_<Spec> py_Spec(m, "Spec");
py::class_<Spec, std::shared_ptr<Spec>> py_Spec(m, "Spec");

py_Spec.def("toString", &Spec::toString);



Expand Down
2 changes: 1 addition & 1 deletion py/htm/advanced/regions/GridCellLocationRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GridCellLocationRegion(PyRegion):
gaussian activity bumps that move as the population receives motor input. When
two bumps are near each other, the intermediate cells have higher firing rates
than they would with a single bump. The cells with firing rates above a
certain threshold are considered "active". When the network receives a motor
certain threshold are considered 'active'. When the network receives a motor
command, it shifts its bumps.
The cells are distributed uniformly through the rhombus, packed in the optimal
Expand Down
4 changes: 2 additions & 2 deletions py/htm/advanced/regions/RawValues.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

class RawValues(PyRegion):
"""
RawDate is a simple region used to send raw scalar values into networks.
RawValues is a simple region used to send raw scalar values into networks.
It accepts data using the command "addDataToQueue" or through the function
It accepts data using the command 'addDataToQueue' or through the function
addDataToQueue() which can be called directly from Python. Data is queued up
in a FIFO and each call to compute pops the top element.
Expand Down
15 changes: 14 additions & 1 deletion py/tests/networkapi/getParameters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NetworkAPI_getParameters_Test(unittest.TestCase):
""" Unit tests for Network class. """


def testGetSpec(self):
def testGetSpecJSON(self):
"""
A test of the Network.getSpecJSON( ) function.
"""
Expand Down Expand Up @@ -127,6 +127,19 @@ def testGetSpec(self):
net = Network()
json_str = net.getSpecJSON("RDSEEncoderRegion")
self.assertEqual(json_str, expected)

def testGetSpec(self):
"""
Test of region.getSpec() function. Testing if pybind pointers are correctly handled
"""
net = Network()
dateRegion = net.addRegion('dateEncoder', 'DateEncoderRegion',
str(dict(timeOfDay_width=30,
timeOfDay_radius=1,
weekend_width=21)))

dateRegion.getSpec()# twice times to check if no double free arises
dateRegion.getSpec()


def testGetParameters(self):
Expand Down
2 changes: 1 addition & 1 deletion src/htm/engine/Region.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Region : public Serializable {
*
* @returns The spec that describes this region
*/
const std::shared_ptr<Spec> &getSpec() const { return spec_; }
const std::shared_ptr<Spec> getSpec() const { return spec_; }


/**
Expand Down
2 changes: 1 addition & 1 deletion src/htm/engine/RegionImplFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ RegionImpl *RegionImplFactory::deserializeRegionImpl(const std::string nodeType,



std::shared_ptr<Spec>& RegionImplFactory::getSpec(const std::string nodeType) {
std::shared_ptr<Spec> RegionImplFactory::getSpec(const std::string nodeType) {
auto it = regionSpecMap.find(nodeType);
if (it == regionSpecMap.end()) {
NTA_THROW << "getSpec() -- unknown node type: '" << nodeType
Expand Down
2 changes: 1 addition & 1 deletion src/htm/engine/RegionImplFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class RegionImplFactory {


// Returns node spec for a specific node type as a shared pointer.
std::shared_ptr<Spec>& getSpec(const std::string nodeType);
std::shared_ptr<Spec> getSpec(const std::string nodeType);

// RegionImplFactory caches nodespecs and the dynamic library reference
// This frees up the cached information.
Expand Down
6 changes: 3 additions & 3 deletions src/htm/regions/SPRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Spec *SPRegion::createSpec() {
"SPRegion. This implements the Spatial Pooler algorithm as a plugin "
"for the Network framework. The Spatial Pooler manages relationships "
"between the columns of a region and the inputs bits. The primary "
"public interface to this function is the \"compute\" method, which "
"public interface to this function is the 'compute' method, which "
"takes in an input vector and returns a list of activeColumns columns.";


Expand Down Expand Up @@ -372,7 +372,7 @@ Spec *SPRegion::createSpec() {
ParameterSpec("(float)\n"
"The default connected threshold.Any synapse whose "
"permanence value is "
"above the connected threshold is a \"connected synapse\", "
"above the connected threshold is a 'connected synapse', "
"meaning it can "
"contribute to the cell's firing. Default ``0.1``.",
NTA_BasicType_Real32, // type
Expand Down Expand Up @@ -404,7 +404,7 @@ Spec *SPRegion::createSpec() {
"when "
"either its previously learned inputs are no longer ever active, or "
"when "
"the vast majority of them have been \"hijacked\" by other "
"the vast majority of them have been 'hijacked' by other "
"columns.Default "
"``0.001``.",
NTA_BasicType_Real32, // type
Expand Down

0 comments on commit e376e49

Please sign in to comment.