Skip to content

BUG: f2py not triggering ValueError with smaller-than-expected byte-size input in array #15311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
melissawm opened this issue Jan 10, 2020 · 3 comments

Comments

@melissawm
Copy link
Member

When executing this example from the f2py docs, we get the following:

>>> import mystring
>>> print(mystring.foo.__doc__)
foo(a,b,c,d)

Wrapper for ``foo``.

Parameters
----------
a : input string(len=5)
b : in/output rank-0 array(string(len=5),'c')
c : input string(len=-1)
d : in/output rank-0 array(string(len=-1),'c')

>>> from numpy import array
>>> a = array(b'123')
>>> b = array(b'123')
>>> c = array(b'123')
>>> d = array(b'123')
>>> mystring.foo(a, b, c, d)
 A=123KB=123KC=123
 D=D2 
 CHANGE A,B,C,D
 A=A23KB=B23KC=C23
 D=D2 
>>> a.tostring(), b.tostring(), c.tostring(), d.tostring()
(b'123', b'B2\x00', b'123', b'D2\x00')

a and b are expected to be of length 5. f2py should raise a ValueError when the input has a smaller byte-size than expected by array argument.

1.19.0.dev0+b7d0258 3.6.7 | packaged by conda-forge | (default, Jul  2 2019, 02:18:42) 
[GCC 7.3.0]
@pearu
Copy link
Contributor

pearu commented Apr 13, 2021

With #18759, the example works as documented:

>>> import mystring
>>> print(mystring.foo.__doc__)
foo(a,b,c,d)

Wrapper for ``foo``.

Parameters
----------
a : input string(len=5)
b : in/output rank-0 array(string(len=5),'c')
c : input string(len=-1)
d : in/output rank-0 array(string(len=-1),'c')

>>> from numpy import array
>>> a = array(b'123\0\0')
>>> b = array(b'123\0\0')
>>> c = array(b'123')
>>> d = array(b'123')
>>> mystring.foo(a, b, c, d)
 A=123 
 B=123 
 C=123
 D=123
 CHANGE A,B,C,D
 A=A23 
 B=B23 
 C=C23
 D=D23
>>> a[()], b[()], c[()], d[()]
(b'123', b'B23 ', b'123', b'D23')

@pearu
Copy link
Contributor

pearu commented Apr 13, 2021

Well, almost. The documentation has the following output:

(b'123', b'B23', b'123', b'D2')

The last item is wrong in the documentation.

@HaoZeke
Copy link
Member

HaoZeke commented Aug 26, 2021

Closing as fixed.

@HaoZeke HaoZeke closed this as completed Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants