bugGNU Octave - Bugs: bug #50157, fwrite input argument type

 
 

bug #50157: fwrite input argument type

Submitted by:  Guillaume <gyom>
Submitted on:  Thu 26 Jan 2017 04:09:40 PM UTC  
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  Closed
Release:  dev Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Fri 27 Jan 2017 10:23:52 AM UTC, comment #9: 

Many thanks for the quick fix - I can confirm it works fine now.

Guillaume <gyom>
Thu 26 Jan 2017 06:12:32 PM UTC, comment #8: 

And yes, the tests are better, but many more could be added.

The tests I just added are good for scalar/matrix types, but not for reading without conversion (result is double) or for other conversion combinations when reading and writing.  There's a lot to test for just fread/fwrite...

John W. Eaton <jwe>
Project Administrator
Thu 26 Jan 2017 06:11:04 PM UTC, comment #7: 

Oh damn, I copied the test to a separate file for quick testing, then fixed the problems there and forgot to copy them back.  Checking in a fix as soon as I can verify that I haven't made some other stupid mistake.

John W. Eaton <jwe>
Project Administrator
Thu 26 Jan 2017 05:49:05 PM UTC, comment #6: 

New failing test in io.tst after running 'make check':

>>>>> processing io.tst
***** test
classes = {"int8", "int16", "int32", "int64", ...
            "uint8", "uint16", "uint32", "uint64", ...
            "single", "double"};
nm = tempname ();
id = fopen (nm, "wb+");
n = numel (classes);
for i = 1:n
   cls = classes{i};
   s_in = ones (1, 1, cls);
   m_in = ones (2, 2, cls);
   m_shape = size (m);
   fwrite (id, s, numel (s), cls);
   fwrite (id, m, numel (m), cls);
   frewind (id);
   s_out = fread (id, numel (s_in), sprintf ("%s=>%s", cls, cls));
   m_out = fread (id, numel (m_in), sprintf ("%s=>%s", cls, cls));
   m_out = reshape (m_out, m_shape);
   fclose (id);
   unlink (nm);
   assert (s_in, s_out);
   assert (m_in, m_out);
endfor
!!!!! test failed
'm' undefined near line 13 column 20

Looks like instances of "m" should be replaced with "m_in", and "s" with "s_in".

Rik <rik5>
Project Administrator
Thu 26 Jan 2017 05:40:13 PM UTC, comment #5: 

On the testing note, we still don't have 100% function coverage, let alone 100% line coverage, but I think the test suite has grown large enough to finally be valuable.  I don't think we are making so many quick fixes that lead to later bugs because more of those problems are getting caught early by the regression tests.

That's mostly a "hurray for us" statement as things are getting better.

Rik <rik5>
Project Administrator
Thu 26 Jan 2017 05:25:04 PM UTC, comment #4: 

I pushed the following fix (with a test!):

  http://hg.savannah.gnu.org/hgweb/octave/rev/8aba6d170887

Reopen if this doesn't fix the problem.

The skip parameter probably should be octave_idx_type, but that's something to fix for another day...

John W. Eaton <jwe>
Project Administrator
Thu 26 Jan 2017 05:13:15 PM UTC, comment #3: 

jwe's diagnosis is correct.  The problem is the difference between scalar/matrix rather than between say double/uint32.  See the following.

octave:1> fid = fopen ('file.dat', 'wb');
octave:2> fwrite (fid, uint32([1 2]), 'uint32')
ans =  2
octave:3> fwrite (fid, uint32([1]), 'uint32')
error: octave_base_value::write(): wrong type argument 'uint32 scalar'

Rik <rik5>
Project Administrator
Thu 26 Jan 2017 04:56:27 PM UTC, comment #2: 

It's not the conversion routines, it's a mistake in the prototype for the write function for scalar integer octave_value types, int vs octave_idx_type.  I'll fix.

John W. Eaton <jwe>
Project Administrator
Thu 26 Jan 2017 04:50:33 PM UTC, comment #1: 

Confirmed.  Octave seems to be missing a large number of conversion routines.

Rik <rik5>
Project Administrator
Thu 26 Jan 2017 04:09:40 PM UTC, original submission:  

Running the follwing with current tip:

fid = fopen ('file.dat', 'wb')
fwrite (fid, int32(1), 'int32')

returns:

error: octave_base_value::write(): wrong type argument 'int32 scalar

fwrite returns 1 as expected if second argument is double, or with 4.2.

Guillaume <gyom>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by gyom (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-01-26 jwe StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2017-01-26 rik5 StatusNone => Confirmed

    Back to the top


    Powered by Savane 3.5