summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author couriersud <couriersud@arcor.de>2015-01-18 01:43:59 +0100
committer couriersud <couriersud@arcor.de>2015-01-18 01:43:59 +0100
commit29045039232974a5187b22c70561131b7e9726dc (patch)
treef06b1fc49f43996d63b2d454aaa81ba90d75b351
parent8cea1bf9e64b163143551a8060ab55f2ca25cc08 (diff)
Fixed memory allocation in netlist code. This caused a number of memory
leaks to disappear. (nw)
-rw-r--r--src/emu/netlist/analog/nld_ms_direct.h24
-rw-r--r--src/emu/netlist/analog/nld_solver.c43
-rw-r--r--src/emu/netlist/analog/nld_solver.h4
-rw-r--r--src/emu/netlist/devices/net_lib.c55
-rw-r--r--src/emu/netlist/devices/net_lib.h2
-rw-r--r--src/emu/netlist/netlist.mak1
-rw-r--r--src/emu/netlist/nl_base.c2
-rw-r--r--src/emu/netlist/nl_base.h76
-rw-r--r--src/emu/netlist/nl_config.h19
-rw-r--r--src/emu/netlist/nl_dice_compat.h2
-rw-r--r--src/emu/netlist/nl_factory.c102
-rw-r--r--src/emu/netlist/nl_factory.h95
-rw-r--r--src/emu/netlist/nl_setup.c10
-rw-r--r--src/emu/netlist/nl_setup.h1
-rw-r--r--src/emu/netlist/plists.h16
-rw-r--r--src/emu/netlist/pstate.c10
-rw-r--r--src/emu/netlist/pstate.h8
-rw-r--r--src/emu/netlist/pstring.c1
18 files changed, 285 insertions, 186 deletions
diff --git a/src/emu/netlist/analog/nld_ms_direct.h b/src/emu/netlist/analog/nld_ms_direct.h
index ed1215ec293..eef61d0b5a6 100644
--- a/src/emu/netlist/analog/nld_ms_direct.h
+++ b/src/emu/netlist/analog/nld_ms_direct.h
@@ -69,10 +69,16 @@ netlist_matrix_solver_direct_t<m_N, _storage_N>::~netlist_matrix_solver_direct_t
{
//delete[] m_A[k];
}
- //delete[] m_last_RHS;
+ for (int k = 0; k < N(); k++)
+ {
+ nl_free(m_terms[k]);
+ nl_free(m_row_ops[k]);
+ }
+ nl_free(m_row_ops[N()]);
+ //delete[] m_last_RHS;
//delete[] m_RHS;
- delete[] m_terms;
- delete[] m_rails_temp;
+ nl_free_array(m_terms);
+ nl_free_array(m_rails_temp);
//delete[] m_row_ops;
}
@@ -452,12 +458,12 @@ netlist_matrix_solver_direct_t<m_N, _storage_N>::netlist_matrix_solver_direct_t(
, m_dim(size)
, m_lp_fact(0)
{
- m_terms = new terms_t *[N()];
- m_rails_temp = new terms_t[N()];
+ m_terms = nl_alloc_array(terms_t *, N());
+ m_rails_temp = nl_alloc_array(terms_t, N());
for (int k = 0; k < N(); k++)
{
- m_terms[k] = new terms_t;
+ m_terms[k] = nl_alloc(terms_t);
m_row_ops[k] = vector_ops_t::create_ops(k);
}
m_row_ops[N()] = vector_ops_t::create_ops(N());
@@ -469,12 +475,12 @@ netlist_matrix_solver_direct_t<m_N, _storage_N>::netlist_matrix_solver_direct_t(
, m_dim(size)
, m_lp_fact(0)
{
- m_terms = new terms_t *[N()];
- m_rails_temp = new terms_t[N()];
+ m_terms = nl_alloc_array(terms_t *, N());
+ m_rails_temp = nl_alloc_array(terms_t, N());
for (int k = 0; k < N(); k++)
{
- m_terms[k] = new terms_t;
+ m_terms[k] = nl_alloc(terms_t);
m_row_ops[k] = vector_ops_t::create_ops(k);
}
m_row_ops[N()] = vector_ops_t::create_ops(N());
diff --git a/src/emu/netlist/analog/nld_solver.c b/src/emu/netlist/analog/nld_solver.c
index bef3dcbcd77..6b3d7dbeb18 100644
--- a/src/emu/netlist/analog/nld_solver.c
+++ b/src/emu/netlist/analog/nld_solver.c
@@ -44,31 +44,31 @@ vector_ops_t *vector_ops_t::create_ops(const int size)
switch (size)
{
case 1:
- return new vector_ops_impl_t<1>();
+ return nl_alloc(vector_ops_impl_t<1>);
case 2:
- return new vector_ops_impl_t<2>();
+ return nl_alloc(vector_ops_impl_t<2>);
case 3:
- return new vector_ops_impl_t<3>();
+ return nl_alloc(vector_ops_impl_t<3>);
case 4:
- return new vector_ops_impl_t<4>();
+ return nl_alloc(vector_ops_impl_t<4>);
case 5:
- return new vector_ops_impl_t<5>();
+ return nl_alloc(vector_ops_impl_t<5>);
case 6:
- return new vector_ops_impl_t<6>();
+ return nl_alloc(vector_ops_impl_t<6>);
case 7:
- return new vector_ops_impl_t<7>();
+ return nl_alloc(vector_ops_impl_t<7>);
case 8:
- return new vector_ops_impl_t<8>();
+ return nl_alloc(vector_ops_impl_t<8>);
case 9:
- return new vector_ops_impl_t<9>();
+ return nl_alloc(vector_ops_impl_t<9>);
case 10:
- return new vector_ops_impl_t<10>();
+ return nl_alloc(vector_ops_impl_t<10>);
case 11:
- return new vector_ops_impl_t<11>();
+ return nl_alloc(vector_ops_impl_t<11>);
case 12:
- return new vector_ops_impl_t<12>();
+ return nl_alloc(vector_ops_impl_t<12>);
default:
- return new vector_ops_impl_t<0>(size);
+ return nl_alloc(vector_ops_impl_t<0>, size);
}
}
@@ -91,8 +91,6 @@ ATTR_COLD void terms_t::set_pointers()
m_term[i]->m_Idr1 = &m_Idr[i];
m_other_curanalog[i] = &m_term[i]->m_otherterm->net().as_analog().m_cur_Analog;
}
-
- m_ops = vector_ops_t::create_ops(m_gt.count());
}
// ----------------------------------------------------------------------------------------
@@ -112,7 +110,7 @@ ATTR_COLD netlist_matrix_solver_t::netlist_matrix_solver_t(const eSolverType typ
ATTR_COLD netlist_matrix_solver_t::~netlist_matrix_solver_t()
{
for (int i = 0; i < m_inps.count(); i++)
- delete m_inps[i];
+ global_free(m_inps[i]);
}
ATTR_COLD void netlist_matrix_solver_t::setup(netlist_analog_net_t::list_t &nets)
@@ -176,7 +174,7 @@ ATTR_COLD void netlist_matrix_solver_t::setup(netlist_analog_net_t::list_t &nets
if (net_proxy_output == NULL)
{
- net_proxy_output = new netlist_analog_output_t();
+ net_proxy_output = nl_alloc(netlist_analog_output_t);
net_proxy_output->init_object(*this, this->name() + "." + pstring::sprintf("m%d", m_inps.count()));
m_inps.add(net_proxy_output);
net_proxy_output->m_proxied_net = &p->net().as_analog();
@@ -380,7 +378,7 @@ NETLIB_NAME(solver)::~NETLIB_NAME(solver)()
while (e != NULL)
{
netlist_matrix_solver_t * const *en = m_mat_solvers.next(e);
- delete *e;
+ global_free(*e);
e = en;
}
@@ -435,15 +433,16 @@ template <int m_N, int _storage_N>
netlist_matrix_solver_t * NETLIB_NAME(solver)::create_solver(int size, const int gs_threshold, const bool use_specific)
{
if (use_specific && m_N == 1)
- return new netlist_matrix_solver_direct1_t(m_params);
+ return nl_alloc(netlist_matrix_solver_direct1_t, m_params);
else if (use_specific && m_N == 2)
- return new netlist_matrix_solver_direct2_t(m_params);
+ return nl_alloc(netlist_matrix_solver_direct2_t, m_params);
else
{
+ typedef netlist_matrix_solver_gauss_seidel_t<m_N,_storage_N> solver_N;
if (size >= gs_threshold)
- return new netlist_matrix_solver_gauss_seidel_t<m_N,_storage_N>(m_params, size);
+ return nl_alloc(solver_N, m_params, size);
else
- return new netlist_matrix_solver_direct_t<m_N, _storage_N>(m_params, size);
+ return nl_alloc(solver_N, m_params, size);
}
}
diff --git a/src/emu/netlist/analog/nld_solver.h b/src/emu/netlist/analog/nld_solver.h
index 255170b40a7..3c17cce0d8c 100644
--- a/src/emu/netlist/analog/nld_solver.h
+++ b/src/emu/netlist/analog/nld_solver.h
@@ -155,7 +155,7 @@ class ATTR_ALIGNED(64) terms_t
NETLIST_PREVENT_COPYING(terms_t)
public:
- ATTR_COLD terms_t() : m_railstart(0), m_ops(NULL)
+ ATTR_COLD terms_t() : m_railstart(0)
{}
ATTR_COLD void clear()
@@ -175,7 +175,6 @@ class ATTR_ALIGNED(64) terms_t
ATTR_HOT inline double *go() { return m_go; }
ATTR_HOT inline double *Idr() { return m_Idr; }
ATTR_HOT inline double **other_curanalog() { return m_other_curanalog; }
- ATTR_HOT vector_ops_t *ops() { return m_ops; }
ATTR_COLD void set_pointers();
@@ -188,7 +187,6 @@ private:
plinearlist_t<double> m_gt;
plinearlist_t<double> m_Idr;
plinearlist_t<double *> m_other_curanalog;
- vector_ops_t * m_ops;
};
class netlist_matrix_solver_t : public netlist_device_t
diff --git a/src/emu/netlist/devices/net_lib.c b/src/emu/netlist/devices/net_lib.c
index b9d6686b964..deb6411a3b0 100644
--- a/src/emu/netlist/devices/net_lib.c
+++ b/src/emu/netlist/devices/net_lib.c
@@ -49,6 +49,7 @@
#include "net_lib.h"
#include "nld_system.h"
+#include "../nl_factory.h"
NETLIST_START(diode_models)
NET_MODEL(".model 1N914 D(Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon)")
@@ -64,24 +65,10 @@ NETLIST_END()
#define xstr(s) # s
-#define ENTRY1(_nic, _name, _defparam) register_device<_nic>( # _name, xstr(_nic), _defparam );
+#define ENTRY1(_nic, _name, _defparam) factory.register_device<_nic>( # _name, xstr(_nic), _defparam );
#define ENTRY(_nic, _name, _defparam) ENTRY1(NETLIB_NAME(_nic), _name, _defparam)
-netlist_factory_t::netlist_factory_t()
-{
-}
-
-netlist_factory_t::~netlist_factory_t()
-{
- for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e))
- {
- net_device_t_base_factory *p = *e;
- delete p;
- }
- m_list.clear();
-}
-
-void netlist_factory_t::initialize()
+void nl_initialize_factory(netlist_factory_t &factory)
{
ENTRY(R, RES, "R")
ENTRY(POT, POT, "R")
@@ -162,39 +149,3 @@ void netlist_factory_t::initialize()
ENTRY(NE555_dip, NE555_DIP, "-")
}
-netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &classname, netlist_setup_t &setup) const
-{
- for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e))
- {
- net_device_t_base_factory *p = *e;
- if (strcmp(p->classname(), classname) == 0)
- {
- netlist_device_t *ret = p->Create();
- return ret;
- }
- p++;
- }
- setup.netlist().error("Class %s not found!\n", classname.cstr());
- return NULL; // appease code analysis
-}
-
-netlist_device_t *netlist_factory_t::new_device_by_name(const pstring &name, netlist_setup_t &setup) const
-{
- net_device_t_base_factory *f = factory_by_name(name, setup);
- return f->Create();
-}
-
-net_device_t_base_factory * netlist_factory_t::factory_by_name(const pstring &name, netlist_setup_t &setup) const
-{
- for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e))
- {
- net_device_t_base_factory *p = *e;
- if (strcmp(p->name(), name) == 0)
- {
- return p;
- }
- p++;
- }
- setup.netlist().error("Class %s not found!\n", name.cstr());
- return NULL; // appease code analysis
-}
diff --git a/src/emu/netlist/devices/net_lib.h b/src/emu/netlist/devices/net_lib.h
index 8161f84cf45..f3db97584fe 100644
--- a/src/emu/netlist/devices/net_lib.h
+++ b/src/emu/netlist/devices/net_lib.h
@@ -99,4 +99,6 @@
NETLIST_EXTERNAL(diode_models);
NETLIST_EXTERNAL(bjt_models);
+void nl_initialize_factory(netlist_factory_t &factory);
+
#endif
diff --git a/src/emu/netlist/netlist.mak b/src/emu/netlist/netlist.mak
index e5140e74c67..b3d1c7a4817 100644
--- a/src/emu/netlist/netlist.mak
+++ b/src/emu/netlist/netlist.mak
@@ -26,6 +26,7 @@ NETLISTOBJS+= \
$(NETLISTOBJ)/nl_base.o \
$(NETLISTOBJ)/nl_parser.o \
$(NETLISTOBJ)/nl_setup.o \
+ $(NETLISTOBJ)/nl_factory.o \
$(NETLISTOBJ)/pstring.o \
$(NETLISTOBJ)/pstate.o \
$(NETLISTOBJ)/analog/nld_bjt.o \
diff --git a/src/emu/netlist/nl_base.c b/src/emu/netlist/nl_base.c
index 8dd4ade0b4e..06eed63bffd 100644
--- a/src/emu/netlist/nl_base.c
+++ b/src/emu/netlist/nl_base.c
@@ -152,7 +152,7 @@ netlist_base_t::~netlist_base_t()
{
if (!m_nets[i]->isRailNet())
{
- delete m_nets[i];
+ global_free(m_nets[i]);
}
}
diff --git a/src/emu/netlist/nl_base.h b/src/emu/netlist/nl_base.h
index f571da5339b..8ee96c8f184 100644
--- a/src/emu/netlist/nl_base.h
+++ b/src/emu/netlist/nl_base.h
@@ -1370,80 +1370,4 @@ ATTR_HOT inline void netlist_analog_output_t::set_Q(const double newQ)
}
}
-
-// -----------------------------------------------------------------------------
-// net_dev class factory
-// -----------------------------------------------------------------------------
-
-class net_device_t_base_factory
-{
- NETLIST_PREVENT_COPYING(net_device_t_base_factory)
-public:
- ATTR_COLD net_device_t_base_factory(const pstring &name, const pstring &classname,
- const pstring &def_param)
- : m_name(name), m_classname(classname), m_def_param(def_param)
- {}
-
- ATTR_COLD virtual ~net_device_t_base_factory() {}
-
- ATTR_COLD virtual netlist_device_t *Create() const = 0;
-
- ATTR_COLD const pstring &name() const { return m_name; }
- ATTR_COLD const pstring &classname() const { return m_classname; }
- ATTR_COLD const pstring &param_desc() const { return m_def_param; }
- ATTR_COLD const nl_util::pstring_list term_param_list();
- ATTR_COLD const nl_util::pstring_list def_params();
-
-protected:
- pstring m_name; /* device name */
- pstring m_classname; /* device class name */
- pstring m_def_param; /* default parameter */
-};
-
-template <class C>
-class net_device_t_factory : public net_device_t_base_factory
-{
- NETLIST_PREVENT_COPYING(net_device_t_factory)
-public:
- ATTR_COLD net_device_t_factory(const pstring &name, const pstring &classname,
- const pstring &def_param)
- : net_device_t_base_factory(name, classname, def_param) { }
-
- ATTR_COLD netlist_device_t *Create() const
- {
- netlist_device_t *r = new C();
- //r->init(setup, name);
- return r;
- }
-};
-
-class netlist_factory_t
-{
-public:
- typedef plinearlist_t<net_device_t_base_factory *> list_t;
-
- ATTR_COLD netlist_factory_t();
- ATTR_COLD ~netlist_factory_t();
-
- ATTR_COLD void initialize();
-
- template<class _C>
- ATTR_COLD void register_device(const pstring &name, const pstring &classname,
- const pstring &def_param)
- {
- m_list.add(new net_device_t_factory< _C >(name, classname, def_param) );
- }
-
- ATTR_COLD netlist_device_t *new_device_by_classname(const pstring &classname, netlist_setup_t &setup) const;
- ATTR_COLD netlist_device_t *new_device_by_name(const pstring &name, netlist_setup_t &setup) const;
- ATTR_COLD net_device_t_base_factory * factory_by_name(const pstring &name, netlist_setup_t &setup) const;
-
- const list_t &list() { return m_list; }
-
-private:
- list_t m_list;
-
-};
-
-
#endif /* NLBASE_H_ */
diff --git a/src/emu/netlist/nl_config.h b/src/emu/netlist/nl_config.h
index 32ca799da43..3977c703073 100644
--- a/src/emu/netlist/nl_config.h
+++ b/src/emu/netlist/nl_config.h
@@ -109,6 +109,10 @@
// this macro passes an item followed by a string version of itself as two consecutive parameters
#define NLNAME(x) x, #x
+//============================================================
+// Exceptions
+//============================================================
+
// emu_fatalerror is a generic fatal exception that provides an error string
class nl_fatalerror : public std::exception
{
@@ -130,6 +134,21 @@ public:
}
};
+//============================================================
+// Memory allocation
+//============================================================
+
+#define nl_alloc(T, ...) global_alloc(T(__VA_ARGS__))
+#define nl_alloc_array(T, N) global_alloc_array(T, N)
+
+#define nl_free(_ptr) global_free(_ptr)
+#define nl_free_array(_ptr) global_free_array(_ptr)
+
+
+//============================================================
+// Asserts
+//============================================================
+
#ifdef MAME_DEBUG
#define nl_assert(x) do { if (!(x)) throw nl_fatalerror("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0)
#define nl_assert_always(x, msg) do { if (!(x)) throw nl_fatalerror("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0)
diff --git a/src/emu/netlist/nl_dice_compat.h b/src/emu/netlist/nl_dice_compat.h
index 6fbede6d453..e4e8c28add9 100644
--- a/src/emu/netlist/nl_dice_compat.h
+++ b/src/emu/netlist/nl_dice_compat.h
@@ -13,7 +13,7 @@
* -------------------------------------------------------------------- */
//#define CHIP(_n, _t) netlist.register_dev(NET_NEW(_t ## _dip), _n);
-#define CHIP(_n, _t) setup.register_dev( new nld_ ## _t ## _dip(), _n);
+#define CHIP(_n, _t) setup.register_dev( nL_alloc(nld_ ## _t ## _dip()), _n);
#define CONNECTION( ... ) CONNECTIONY( CONNECTIONX( __VA_ARGS__ ) )
#define CONNECTIONY(_a) _a
diff --git a/src/emu/netlist/nl_factory.c b/src/emu/netlist/nl_factory.c
new file mode 100644
index 00000000000..dc097c53069
--- /dev/null
+++ b/src/emu/netlist/nl_factory.c
@@ -0,0 +1,102 @@
+// license:GPL-2.0+
+// copyright-holders:Couriersud
+/***************************************************************************
+
+ nl_factory.c
+
+ Discrete netlist implementation.
+
+****************************************************************************
+
+ Couriersud reserves the right to license the code under a less restrictive
+ license going forward.
+
+ Copyright Nicola Salmoria and the MAME team
+ All rights reserved.
+
+ Redistribution and use of this code or any derivative works are permitted
+ provided that the following conditions are met:
+
+ * Redistributions may not be sold, nor may they be used in a commercial
+ product or activity.
+
+ * Redistributions that are modified from the original source must include the
+ complete source code, including the source code for all components used by a
+ binary built from the modified sources. However, as a special exception, the
+ source code distributed need not include anything that is normally distributed
+ (in either source or binary form) with the major components (compiler, kernel,
+ and so on) of the operating system on which the executable runs, unless that
+ component itself accompanies the executable.
+
+ * Redistributions must reproduce the above copyright notice, this list of
+ conditions and the following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+
+****************************************************************************/
+
+#include "nl_factory.h"
+#include "nl_setup.h"
+
+netlist_factory_t::netlist_factory_t()
+{
+}
+
+netlist_factory_t::~netlist_factory_t()
+{
+ for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e))
+ {
+ net_device_t_base_factory *p = *e;
+ global_free(p);
+ }
+ m_list.clear();
+}
+
+netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &classname, netlist_setup_t &setup) const
+{
+ for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e))
+ {
+ net_device_t_base_factory *p = *e;
+ if (strcmp(p->classname(), classname) == 0)
+ {
+ netlist_device_t *ret = p->Create();
+ return ret;
+ }
+ p++;
+ }
+ setup.netlist().error("Class %s not found!\n", classname.cstr());
+ return NULL; // appease code analysis
+}
+
+netlist_device_t *netlist_factory_t::new_device_by_name(const pstring &name, netlist_setup_t &setup) const
+{
+ net_device_t_base_factory *f = factory_by_name(name, setup);
+ return f->Create();
+}
+
+net_device_t_base_factory * netlist_factory_t::factory_by_name(const pstring &name, netlist_setup_t &setup) const
+{
+ for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e))
+ {
+ net_device_t_base_factory *p = *e;
+ if (strcmp(p->name(), name) == 0)
+ {
+ return p;
+ }
+ p++;
+ }
+ setup.netlist().error("Class %s not found!\n", name.cstr());
+ return NULL; // appease code analysis
+}
diff --git a/src/emu/netlist/nl_factory.h b/src/emu/netlist/nl_factory.h
new file mode 100644
index 00000000000..90b79ae9b45
--- /dev/null
+++ b/src/emu/netlist/nl_factory.h
@@ -0,0 +1,95 @@
+// license:GPL-2.0+
+// copyright-holders:Couriersud
+/*
+ * nl_factory.h
+ *
+ *
+ */
+
+#ifndef NLFACTORY_H_
+#define NLFACTORY_H_
+
+#include "nl_config.h"
+#include "plists.h"
+#include "nl_base.h"
+#if 0
+#include "nl_time.h"
+#include "nl_util.h"
+#include "pstate.h"
+#endif
+#include "pstring.h"
+
+// -----------------------------------------------------------------------------
+// net_dev class factory
+// -----------------------------------------------------------------------------
+
+class net_device_t_base_factory
+{
+ NETLIST_PREVENT_COPYING(net_device_t_base_factory)
+public:
+ ATTR_COLD net_device_t_base_factory(const pstring &name, const pstring &classname,
+ const pstring &def_param)
+ : m_name(name), m_classname(classname), m_def_param(def_param)
+ {}
+
+ ATTR_COLD virtual ~net_device_t_base_factory() {}
+
+ ATTR_COLD virtual netlist_device_t *Create() const = 0;
+
+ ATTR_COLD const pstring &name() const { return m_name; }
+ ATTR_COLD const pstring &classname() const { return m_classname; }
+ ATTR_COLD const pstring &param_desc() const { return m_def_param; }
+ ATTR_COLD const nl_util::pstring_list term_param_list();
+ ATTR_COLD const nl_util::pstring_list def_params();
+
+protected:
+ pstring m_name; /* device name */
+ pstring m_classname; /* device class name */
+ pstring m_def_param; /* default parameter */
+};
+
+template <class C>
+class net_device_t_factory : public net_device_t_base_factory
+{
+ NETLIST_PREVENT_COPYING(net_device_t_factory)
+public:
+ ATTR_COLD net_device_t_factory(const pstring &name, const pstring &classname,
+ const pstring &def_param)
+ : net_device_t_base_factory(name, classname, def_param) { }
+
+ ATTR_COLD netlist_device_t *Create() const
+ {
+ netlist_device_t *r = nl_alloc(C);
+ //r->init(setup, name);
+ return r;
+ }
+};
+
+class netlist_factory_t
+{
+public:
+ typedef plinearlist_t<net_device_t_base_factory *> list_t;
+
+ ATTR_COLD netlist_factory_t();
+ ATTR_COLD ~netlist_factory_t();
+
+ template<class _C>
+ ATTR_COLD void register_device(const pstring &name, const pstring &classname,
+ const pstring &def_param)
+ {
+ m_list.add(nl_alloc(net_device_t_factory< _C >, name, classname, def_param));
+ }
+
+ ATTR_COLD netlist_device_t *new_device_by_classname(const pstring &classname, netlist_setup_t &setup) const;
+ ATTR_COLD netlist_device_t *new_device_by_name(const pstring &name, netlist_setup_t &setup) const;
+ ATTR_COLD net_device_t_base_factory * factory_by_name(const pstring &name, netlist_setup_t &setup) const;
+
+ const list_t &list() { return m_list; }
+
+private:
+ list_t m_list;
+
+};
+
+
+#endif /* NLFACTORY_H_ */
diff --git a/src/emu/netlist/nl_setup.c b/src/emu/netlist/nl_setup.c
index 9f4f17003fc..95f62470944 100644
--- a/src/emu/netlist/nl_setup.c
+++ b/src/emu/netlist/nl_setup.c
@@ -41,7 +41,7 @@ netlist_setup_t::netlist_setup_t(netlist_base_t &netlist)
void netlist_setup_t::init()
{
- m_factory.initialize();
+ nl_initialize_factory(factory());
NETLIST_NAME(base)(*this);
}
@@ -390,7 +390,7 @@ nld_base_d_to_a_proxy *netlist_setup_t::get_d_a_proxy(netlist_output_t &out)
if (proxy == NULL)
{
// create a new one ...
- proxy = new nld_d_to_a_proxy(out);
+ proxy = nl_alloc(nld_d_to_a_proxy ,out);
pstring x = pstring::sprintf("proxy_da_%s_%d", out.name().cstr(), m_proxy_cnt);
m_proxy_cnt++;
@@ -419,7 +419,7 @@ void netlist_setup_t::connect_input_output(netlist_input_t &in, netlist_output_t
{
if (out.isFamily(netlist_terminal_t::ANALOG) && in.isFamily(netlist_terminal_t::LOGIC))
{
- nld_a_to_d_proxy *proxy = new nld_a_to_d_proxy(in);
+ nld_a_to_d_proxy *proxy = nl_alloc(nld_a_to_d_proxy, in);
pstring x = pstring::sprintf("proxy_ad_%s_%d", in.name().cstr(), m_proxy_cnt);
m_proxy_cnt++;
@@ -455,7 +455,7 @@ void netlist_setup_t::connect_terminal_input(netlist_terminal_t &term, netlist_i
else if (inp.isFamily(netlist_terminal_t::LOGIC))
{
NL_VERBOSE_OUT(("connect_terminal_input: connecting proxy\n"));
- nld_a_to_d_proxy *proxy = new nld_a_to_d_proxy(inp);
+ nld_a_to_d_proxy *proxy = nl_alloc(nld_a_to_d_proxy, inp);
pstring x = pstring::sprintf("proxy_ad_%s_%d", inp.name().cstr(), m_proxy_cnt);
m_proxy_cnt++;
@@ -523,7 +523,7 @@ void netlist_setup_t::connect_terminals(netlist_core_terminal_t &t1, netlist_cor
else
{
NL_VERBOSE_OUT(("adding net ...\n"));
- netlist_analog_net_t *anet = new netlist_analog_net_t();
+ netlist_analog_net_t *anet = nl_alloc(netlist_analog_net_t);
t1.set_net(*anet);
//m_netlist.solver()->m_nets.add(anet);
// FIXME: Nets should have a unique name
diff --git a/src/emu/netlist/nl_setup.h b/src/emu/netlist/nl_setup.h
index 9a6028c4848..d437755af11 100644
--- a/src/emu/netlist/nl_setup.h
+++ b/src/emu/netlist/nl_setup.h
@@ -11,6 +11,7 @@
#define NLSETUP_H_
#include "nl_base.h"
+#include "nl_factory.h"
//============================================================
// MACROS / inline netlist definitions
diff --git a/src/emu/netlist/plists.h b/src/emu/netlist/plists.h
index ad5d34fc2ad..9493317b709 100644
--- a/src/emu/netlist/plists.h
+++ b/src/emu/netlist/plists.h
@@ -28,7 +28,7 @@ public:
if (m_num_elements == 0)
m_list = NULL;
else
- m_list = new _ListClass[m_num_elements];
+ m_list = nl_alloc_array(_ListClass, m_num_elements);
m_count = 0;
}
@@ -38,7 +38,7 @@ public:
if (m_num_elements == 0)
m_list = NULL;
else
- m_list = new _ListClass[m_num_elements];
+ m_list = nl_alloc_array(_ListClass, m_num_elements);
m_count = 0;
for (int i=0; i<rhs.count(); i++)
{
@@ -60,7 +60,7 @@ public:
ATTR_COLD ~plinearlist_t()
{
if (m_list != NULL)
- delete[] m_list;
+ nl_free_array(m_list);
m_list = NULL;
}
@@ -157,18 +157,18 @@ public:
{
for (_ListClass *i = m_list; i < m_list + m_count; i++)
{
- delete *i;
+ nl_free(*i);
}
clear();
}
private:
- ATTR_HOT inline void resize(const int new_size)
+ ATTR_COLD void resize(const int new_size)
{
int cnt = count();
if (new_size > 0)
{
- _ListClass *m_new = new _ListClass[new_size];
+ _ListClass *m_new = nl_alloc_array(_ListClass, new_size);
_ListClass *pd = m_new;
if (cnt > new_size)
@@ -176,14 +176,14 @@ private:
for (_ListClass *ps = m_list; ps < m_list + cnt; ps++, pd++)
*pd = *ps;
if (m_list != NULL)
- delete[] m_list;
+ nl_free_array(m_list);
m_list = m_new;
m_count = cnt;
}
else
{
if (m_list != NULL)
- delete[] m_list;
+ nl_free_array(m_list);
m_list = NULL;
m_count = 0;
}
diff --git a/src/emu/netlist/pstate.c b/src/emu/netlist/pstate.c
index 6dfa6c62527..5b50b6dbceb 100644
--- a/src/emu/netlist/pstate.c
+++ b/src/emu/netlist/pstate.c
@@ -27,7 +27,7 @@ ATTR_COLD void pstate_manager_t::save_state_ptr(const pstring &stname, const pst
};
NL_VERBOSE_OUT(("SAVE: <%s> %s(%d) %p\n", fullname.cstr(), ts[dt].cstr(), size, ptr));
- pstate_entry_t *p = new pstate_entry_t(stname, dt, owner, size, count, ptr, is_ptr);
+ pstate_entry_t *p = nl_alloc(pstate_entry_t, stname, dt, owner, size, count, ptr, is_ptr);
m_save.add(p);
}
@@ -60,3 +60,11 @@ ATTR_COLD void pstate_manager_t::post_load()
if (m_save[i]->m_dt == DT_CUSTOM)
m_save[i]->m_callback->on_post_load();
}
+
+template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname)
+{
+ //save_state_ptr(stname, DT_CUSTOM, 0, 1, &state);
+ pstate_entry_t *p = nl_alloc(pstate_entry_t, stname, owner, &state);
+ m_save.add(p);
+ state.register_state(*this, stname);
+}
diff --git a/src/emu/netlist/pstate.h b/src/emu/netlist/pstate.h
index 59f91bc59a1..8c7b7763ed9 100644
--- a/src/emu/netlist/pstate.h
+++ b/src/emu/netlist/pstate.h
@@ -145,13 +145,7 @@ private:
pstate_entry_t::list_t m_save;
};
-template<> ATTR_COLD inline void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname)
-{
- //save_state_ptr(stname, DT_CUSTOM, 0, 1, &state);
- pstate_entry_t *p = new pstate_entry_t(stname, owner, &state);
- m_save.add(p);
- state.register_state(*this, stname);
-}
+template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname);
template<> ATTR_COLD inline void pstate_manager_t::save_item(netlist_time &nlt, const void *owner, const pstring &stname)
{
diff --git a/src/emu/netlist/pstring.c b/src/emu/netlist/pstring.c
index 4e7c578a61e..d6c00b550fd 100644
--- a/src/emu/netlist/pstring.c
+++ b/src/emu/netlist/pstring.c
@@ -14,7 +14,6 @@
//pstring::str_t *pstring::m_zero = new(pstring::m_pool, 0) pstring::str_t(0);
pblockpool pstring::m_pool;
-
pstring::str_t pstring::m_zero;
/*