summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2019-04-15 21:08:13 +0200
committer couriersud <couriersud@gmx.org>2019-04-15 21:41:01 +0200
commit86f0b315b66898d25fd6918a7eabef025fb4511b (patch)
tree8161cececc3de487638e873fc3e226f582e90b71 /src/lib
parent7e623cc8862f7b04a65924a99a9ab354008e2eea (diff)
netlist: Add validation support to netlist device.
mame -validate now also checks all netlist devices. It does this by constructing a temporary netlist. This commit also fixes some memory leaks and a bad bug which surfaced in validation.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/netlist/devices/nlid_truthtable.cpp4
-rw-r--r--src/lib/netlist/nl_base.h11
-rw-r--r--src/lib/netlist/nl_setup.cpp8
-rw-r--r--src/lib/netlist/plib/plists.h13
-rw-r--r--src/lib/netlist/plib/pmempool.h35
5 files changed, 52 insertions, 19 deletions
diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp
index 2221d855880..c62c67da3c1 100644
--- a/src/lib/netlist/devices/nlid_truthtable.cpp
+++ b/src/lib/netlist/devices/nlid_truthtable.cpp
@@ -207,7 +207,6 @@ namespace netlist
if (idx != plib::container::npos)
connect(m_Q[i], m_I[idx]);
}
-
m_ign = 0;
}
@@ -237,6 +236,9 @@ namespace netlist
if (m_family_name != "")
m_family_desc = anetlist.setup().family_from_model(m_family_name);
+ if (m_family_desc == nullptr)
+ throw nl_exception("family description not found for {1}", m_family_name);
+
return pool().make_poolptr<tt_type>(anetlist, name, m_family_desc, m_ttbl, m_desc);
}
private:
diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h
index cd43b5688ad..f52b720ab37 100644
--- a/src/lib/netlist/nl_base.h
+++ b/src/lib/netlist/nl_base.h
@@ -433,7 +433,11 @@ namespace netlist
void operator delete (void * mem) = delete;
#endif
protected:
- ~object_t() noexcept = default; // only childs should be destructible
+ // only childs should be destructible
+ ~object_t() noexcept
+ {
+ name_hash().erase(name_hash().find(this));
+ }
private:
//pstring m_name;
@@ -1369,7 +1373,10 @@ namespace netlist
{
for (auto & d : m_devices)
if (d.first == name)
- log().fatal(MF_1_DUPLICATE_NAME_DEVICE_LIST, d.first);
+ {
+ dev.release();
+ log().fatal(MF_1_DUPLICATE_NAME_DEVICE_LIST, name);
+ }
//m_devices.push_back(std::move(dev));
m_devices.insert(m_devices.end(), { name, std::move(dev) });
}
diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp
index 7fa3db867a9..6caafa27a66 100644
--- a/src/lib/netlist/nl_setup.cpp
+++ b/src/lib/netlist/nl_setup.cpp
@@ -272,8 +272,10 @@ pstring setup_t::get_initial_param_val(const pstring &name, const pstring &def)
void setup_t::register_term(detail::core_terminal_t &term)
{
if (!m_terminals.insert({term.name(), &term}).second)
+ {
log().fatal(MF_2_ADDING_1_2_TO_TERMINAL_LIST, termtype_as_str(term),
term.name());
+ }
log().debug("{1} {2}\n", termtype_as_str(term), term.name());
}
@@ -1144,7 +1146,11 @@ bool source_t::parse(nlparse_t &setup, const pstring &name)
return false;
else
{
- return setup.parse_stream(stream(name), name);
+ auto strm(stream(name));
+ if (strm)
+ return setup.parse_stream(std::move(strm), name);
+ else
+ return false;
}
}
diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h
index c2fee9c2f8e..525a65a97f2 100644
--- a/src/lib/netlist/plib/plists.h
+++ b/src/lib/netlist/plib/plists.h
@@ -34,13 +34,18 @@ public:
using iterator = C *;
using const_iterator = const C *;
- uninitialised_array_t() noexcept = default;
+ //uninitialised_array_t() noexcept = default;
+ uninitialised_array_t() noexcept
+ : m_initialized(0)
+ {
+ }
COPYASSIGNMOVE(uninitialised_array_t, delete)
~uninitialised_array_t() noexcept
{
- for (std::size_t i=0; i<N; i++)
- (*this)[i].~C();
+ if (m_initialized>=N)
+ for (std::size_t i=0; i<N; i++)
+ (*this)[i].~C();
}
size_t size() const { return N; }
@@ -58,6 +63,7 @@ public:
template<typename... Args>
void emplace(const std::size_t index, Args&&... args)
{
+ m_initialized++;
// allocate on buffer
new (&m_buf[index]) C(std::forward<Args>(args)...);
}
@@ -78,6 +84,7 @@ private:
/* ensure proper alignment */
PALIGNAS_VECTOROPT()
std::array<typename std::aligned_storage<sizeof(C), alignof(C)>::type, N> m_buf;
+ unsigned m_initialized;
};
// ----------------------------------------------------------------------------------------
diff --git a/src/lib/netlist/plib/pmempool.h b/src/lib/netlist/plib/pmempool.h
index f55807c86dc..87c74e14856 100644
--- a/src/lib/netlist/plib/pmempool.h
+++ b/src/lib/netlist/plib/pmempool.h
@@ -40,12 +40,18 @@ namespace plib {
{
min_bytes = std::max(mp->m_min_alloc, min_bytes);
m_free = min_bytes;
- std::size_t alloc_bytes = (min_bytes + mp->m_min_align - 1) & ~(mp->m_min_align - 1);
- m_data_allocated = static_cast<char *>(::operator new(alloc_bytes));
+ std::size_t alloc_bytes = (min_bytes + mp->m_min_align); // - 1); // & ~(mp->m_min_align - 1);
+ //m_data_allocated = ::operator new(alloc_bytes);
+ m_data_allocated = new char[alloc_bytes];
void *r = m_data_allocated;
std::align(mp->m_min_align, min_bytes, r, alloc_bytes);
m_data = reinterpret_cast<char *>(r);
}
+ ~block()
+ {
+ //::operator delete(m_data_allocated);
+ delete [] m_data_allocated;
+ }
std::size_t m_num_alloc;
std::size_t m_free;
std::size_t m_cur;
@@ -106,7 +112,8 @@ namespace plib {
plib::perrlogger("Found {} info blocks\n", sinfo().size());
plib::perrlogger("Found block with {} dangling allocations\n", b->m_num_alloc);
}
- ::operator delete(b->m_data);
+ plib::pdelete(b);
+ //::operator delete(b->m_data);
}
}
@@ -125,8 +132,6 @@ namespace plib {
auto *ret = reinterpret_cast<void *>(b->m_data + b->m_cur);
auto capacity(rs);
ret = std::align(align, size, ret, capacity);
- // FIXME: if (ret == nullptr)
- // printf("Oh no\n");
sinfo().insert({ ret, info(b, b->m_cur)});
rs -= (capacity - size);
b->m_cur += rs;
@@ -141,8 +146,6 @@ namespace plib {
auto *ret = reinterpret_cast<void *>(b->m_data + b->m_cur);
auto capacity(rs);
ret = std::align(align, size, ret, capacity);
- // FIXME: if (ret == nullptr)
- // printf("Oh no\n");
sinfo().insert({ ret, info(b, b->m_cur)});
rs -= (capacity - size);
b->m_cur += rs;
@@ -162,12 +165,20 @@ namespace plib {
plib::terminate("mempool::free - double free was called\n");
else
{
- //b->m_free = m_min_alloc;
- //b->cur_ptr = b->data;
+ b->m_num_alloc--;
+ //printf("Freeing in block %p %lu\n", b, b->m_num_alloc);
+ sinfo().erase(it);
+ if (b->m_num_alloc == 0)
+ {
+ mempool *mp = b->m_mempool;
+ auto itb = std::find(mp->m_blocks.begin(), mp->m_blocks.end(), b);
+ if (itb == mp->m_blocks.end())
+ plib::terminate("mempool::free - block not found\n");
+
+ mp->m_blocks.erase(itb);
+ plib::pdelete(b);
+ }
}
- b->m_num_alloc--;
- //printf("Freeing in block %p %lu\n", b, b->m_num_alloc);
- sinfo().erase(it);
}
template <typename T>