Mercurial > octave
changeset 32130:dedc746ecd58
allow octave_value_factory functions to work
The octave_value_factory functions added in changeset 920e88fd8ab7
relied on the following new octave_value constructors
// For use by inline octave_value "factory" octave_value_inline
octave_value (int, octave_base_value *rep) : m_rep (rep) { }
// Also increase the counter, for a "copy"
octave_value(int, int, octave_base_value *rep) : m_rep (rep)
{
m_rep->m_count++;
}
but those were accidentally omitted when I extracted the changeset
from a larger set of VM-related changes. However, we already have the
following octave_value constructor that does the same job:
octave_value (octave_base_value *new_rep, bool borrow = false)
: m_rep (new_rep)
{
if (borrow)
m_rep->m_count++;
}
and we can use that instead of adding the new functions.
* ov.h, ov.cc (octave_value (octave_base_value *, bool = false)):
Move definition to header file to make trivial constructor available
for inlining.
* ov-inline.h: Use the octave_value (octave_base_value *, bool = false)
constructor in octave_value_factory::make_copy and all
octave_value_factory::make functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 16 Jun 2023 15:04:39 -0400 |
parents | 13fbc97f9362 |
children | fbadf4ce94c7 |
files | libinterp/octave-value/ov-inline.h libinterp/octave-value/ov.cc libinterp/octave-value/ov.h |
diffstat | 3 files changed, 27 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-inline.h Thu Jun 15 14:08:45 2023 -0400 +++ b/libinterp/octave-value/ov-inline.h Fri Jun 16 15:04:39 2023 -0400 @@ -46,88 +46,93 @@ static octave_value make (double d) { - return octave_value (0, new octave_scalar (d)); + return octave_value (new octave_scalar (d)); } static octave_value make (float d) { - return octave_value (0, new octave_float_scalar (d)); + return octave_value (new octave_float_scalar (d)); } static octave_value make (short int i) { - return octave_value (0, new octave_scalar (i)); + return octave_value (new octave_scalar (i)); } static octave_value make (unsigned short int i) { - return octave_value (0, new octave_scalar (i)); + return octave_value (new octave_scalar (i)); } static octave_value make (int i) { - return octave_value (0, new octave_scalar (i)); + return octave_value (new octave_scalar (i)); } static octave_value make (unsigned int i) { - return octave_value (0, new octave_scalar (i)); + return octave_value (new octave_scalar (i)); } static octave_value make (long int i) { - return octave_value (0, new octave_scalar (i)); + return octave_value (new octave_scalar (i)); } static octave_value make (unsigned long int i) { - return octave_value (0, new octave_scalar (i)); + return octave_value (new octave_scalar (i)); } #if defined (OCTAVE_HAVE_LONG_LONG_INT) static octave_value make (long long int i) { - return octave_value (0, new octave_scalar (i)); + return octave_value (new octave_scalar (i)); } #endif #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT) static octave_value make (unsigned long long int i) { - return octave_value (0, new octave_scalar (i)); + return octave_value (new octave_scalar (i)); } #endif static octave_value make (octave::sys::time t) { - return octave_value (0, new octave_scalar (t.double_value ())); + return octave_value (new octave_scalar (t.double_value ())); } static octave_value make (const Complex& C) { - octave_value ov(0, new octave_complex (C)); + octave_value ov (new octave_complex (C)); ov.maybe_mutate (); // Fold e.g. 1+0i to 1 return ov; } static octave_value make (const FloatComplex& C) { - octave_value ov(0, new octave_float_complex (C)); + octave_value ov (new octave_float_complex (C)); ov.maybe_mutate (); return ov; } static octave_value make (bool b) { - return octave_value (0, new octave_bool (b)); + return octave_value (new octave_bool (b)); } + // FIXME: The octave_value (octave_base_value *rep, bool) constructor + // is already defined in the ov.h header file so is the + // octave_value_factory::make_copy function really necessary? + static octave_value make_copy (octave_base_value *rep) { - return octave_value (0, 0, rep); + return octave_value (rep, true); } - private: +private: + ~octave_value_factory () = delete; octave_value_factory () = delete; };
--- a/libinterp/octave-value/ov.cc Thu Jun 15 14:08:45 2023 -0400 +++ b/libinterp/octave-value/ov.cc Fri Jun 16 15:04:39 2023 -0400 @@ -1117,13 +1117,6 @@ : m_rep (new octave_magic_colon ()) { } -octave_value::octave_value (octave_base_value *new_rep, bool borrow) - : m_rep (new_rep) -{ - if (borrow) - m_rep->m_count++; -} - octave_base_value * octave_value::clone () const {
--- a/libinterp/octave-value/ov.h Thu Jun 15 14:08:45 2023 -0400 +++ b/libinterp/octave-value/ov.h Fri Jun 16 15:04:39 2023 -0400 @@ -306,7 +306,12 @@ OCTINTERP_API octave_value (octave_value::magic_colon); - OCTINTERP_API octave_value (octave_base_value *new_rep, bool borrow = false); + octave_value (octave_base_value *new_rep, bool borrow = false) + : m_rep (new_rep) + { + if (borrow) + m_rep->m_count++; + } // Copy constructor.