[bug #55810] sizeof() and whos() returns 0 bytes for classdef objects

Thomas <[email protected]>
Newsgroups gmane.comp.gnu.octave.bugs
Message-ID <[email protected]>
Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only notification stream.  Info posted to this mailing list address won't appear in the tracker database where it is most useful.

Follow-up Comment #11, bug #55810 (group octave):

Thanks for the review Markus.

I've attached a patch that fixes the identation issue, and also uses
Octave-specific syntax (with commenting conventions).

Your `dependent_prop` class fails because the `set` method shouldn't actually
set a dependent property. I think it's worth consulting the MATLAB
documentation for how Dependent properties are supposed to be used:
https://www.mathworks.com/help/matlab/matlab_oop/access-methods-for-dependent-properties.html.

Here's a slightly tweaked classdef that illustrates the same idea:

classdef dependent_prop < handle
  properties
    a = uint8(1)
  end
  properties (Dependent)
    b
  end

  methods
    function value = get.b(this)
      value = this.a + 5;
    end
  end
end


In your example, since `dependent_prop` is a handle class, then the size of
the machine word is returned by a `sizeof(dependent_prop)` call (8 bytes if
you're on a 64-bit computer).

If `dependent_prop` is a value class, then


>> dependent_prop
ans =

  1x1 dependent_prop object with properties:

      a: 1
      b: 6

>> sizeof(dependent_prop)
ans = 1


so yes, the size of the dependent property is not calculated in the size.
That's because the dependent property is not actually stored in the underlying
`octave_scalar_map` structure, which is what's used to compute the byte size
of a classdef.

No idea about MATLAB compatibility in this case, but because `sizeof` is very
much about the implementation of Octave internals, I don't think it really
matters in this case.

This patch can be pushed to the dev branch if you're not confident about
pushing it to stable.



(file #58443)

    _______________________________________________________

Additional Item Attachment:

Name: bug55810_v2.patch              Size: 11KiB
    <https://file.savannah.gnu.org/file/bug55810_v2.patch?file_id=58443>


    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-f290f6b25beb8cb99bbe243a6cd2c5fef79ffcde.tar.gz


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?55810>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCac+8xQAKCRCqLAuaBUf3
ThhjAQDveBn+B33exTjwwLe2ADLL2fe0uHAcYo4o4n4y7OwX+wEAkXTkUEsJnxfD
PCHPgP4tpX51uFgojes2f8WLvaLQ8QQ=
=xerL
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.