Skip to content

Commit ba5ee16

Browse files
committed
Store classdef name separately from type name in "-text" format (bug #45833).
* libinterp/corefcn/ls-oct-text.cc (save_text_data): Store type name as identifier also for "classdef" objects. (read_text_data): Read class name and look up classdef class if type name is "object". * libinterp/octave-value/ov-classdef.cc (octave_classdef::save_ascii): Store identifier for classdef name separately in "-text" file format.
1 parent a1265e1 commit ba5ee16

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

libinterp/corefcn/ls-oct-text.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ read_text_data (std::istream& is, const std::string& filename, bool& global,
324324
else
325325
typ = tag;
326326

327-
octave::cdef_class cls = octave::lookup_class (typ, false, true);
328327

329328
// Special case for backward compatibility. A small bit of cruft
330329
if (SUBSTRING_COMPARE_EQ (typ, 0, 12, "string array"))
@@ -335,8 +334,20 @@ read_text_data (std::istream& is, const std::string& filename, bool& global,
335334
tc = load_inline_fcn (is, filename);
336335
return name;
337336
}
338-
else if (cls.ok ())
337+
else if (SUBSTRING_COMPARE_EQ (typ, 0, 6, "object"))
339338
{
339+
// classdef object
340+
std::string class_nm = extract_keyword (is, "classname");
341+
342+
if (class_nm.empty ())
343+
error ("load: failed to extract keyword specifying classdef class");
344+
345+
octave::cdef_class cls = octave::lookup_class (class_nm, false, true);
346+
347+
if (! cls.ok () || (cls.get_name () != class_nm))
348+
error ("load: no definition for classdef '%s' available",
349+
class_nm.c_str ());
350+
340351
bool skip_constructor = ! cls.get ("ConstructOnLoad").bool_value ();
341352
tc = cls.construct (octave_value_list (), skip_constructor);
342353
}
@@ -379,10 +390,7 @@ save_text_data (std::ostream& os, const octave_value& val_arg,
379390
else
380391
os << "# type: ";
381392

382-
if (val.is_classdef_object ())
383-
os << val.class_name () << "\n";
384-
else
385-
os << val.type_name () << "\n";
393+
os << val.type_name () << "\n";
386394

387395
if (! precision)
388396
precision = Vsave_precision;

libinterp/octave-value/ov-classdef.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ octave_classdef::loadobj (std::vector<std::tuple<octave_map, uint32_t, bool>>& m
248248
bool
249249
octave_classdef::save_ascii (std::ostream& os)
250250
{
251+
os << "# classname: " << class_name () << "\n";
252+
251253
const dim_vector dv = m_object.dims ();
252254
os << "# ndims: " << dv.ndims () << "\n";
253255

0 commit comments

Comments
 (0)