Bug 1046509 - ruby-libguestfs throws "expecting 0 or 1 arguments" on Guestfs::Guestfs.new
Summary: ruby-libguestfs throws "expecting 0 or 1 arguments" on Guestfs::Guestfs.new
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: libguestfs
Version: 20
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: Richard W.M. Jones
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1072062 1072079
TreeView+ depends on / blocked
 
Reported: 2013-12-25 22:35 UTC by Dominic Cleal
Modified: 2014-03-03 21:16 UTC (History)
4 users (show)

Fixed In Version: libguestfs-1.24.5-1.fc20
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-01-13 03:00:12 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Dominic Cleal 2013-12-25 22:35:12 UTC
Description of problem:
When trying to use ruby-libguestfs and instantiate the top-level class, the following error is always thrown:

$ irb -rguestfs
irb(main):001:0> Guestfs::Guestfs.new
ArgumentError: expecting 0 or 1 arguments
	from (irb):1:in `new'
	from (irb):1
	from /usr/bin/irb:12:in `<main>'

Attaching gdb shows:
#0  ruby_guestfs_create (argc=22729240, argv=0x2, m=23435168)
    at _guestfs.c:134

Version-Release number of selected component (if applicable):
ruby-2.0.0.353-16.fc19.x86_64
ruby-libguestfs-1.22.7-4.fc19.x86_64

How reproducible:
Always

Steps to Reproduce:
1. ruby -rguestfs -e 'puts Guestfs::Guestfs.new'

Actual results:
-e:1:in `new': expecting 0 or 1 arguments (ArgumentError)
	from -e:1:in `<main>'

Expected results:
#<Guestfs::Guestfs:0x000000020df708> or similar.

Comment 1 Richard W.M. Jones 2013-12-27 09:13:01 UTC
$ irb -rguestfs
irb(main):001:0> Guestfs::Guestfs.new
ArgumentError: expecting 0 or 1 arguments
	from (irb):1:in `new'
	from (irb):1
	from /usr/bin/irb:12:in `<main>'
irb(main):003:0> Guestfs::create()
=> #<Guestfs::Guestfs:0x0000000255b110>

The documentation and examples all refer to using the new()
method, but the tests all use create().

The examples worked when I wrote them, but aren't routinely
tested so seem to have regressed since then.  Since the tests
use create(), they didn't pick up the regression.

I'm not over familiar with ruby, so I'm not sure which syntax
is correct, but there's clearly a bug here.

Comment 2 Richard W.M. Jones 2013-12-27 09:16:05 UTC
I just found this commit:

https://github.com/libguestfs/libguestfs/commit/25521f17d5b0841a13d66fc515fac0cffe23d9a1

which indicates that new() should work, and is better than
using create().

commit 25521f17d5b0841a13d66fc515fac0cffe23d9a1
Author: Richard Jones <rjones>
Date:   Thu Sep 2 12:01:06 2010 +0100

    ruby: Add Guestfs::Guestfs.new() method.
    
    This is a more standard way to create objects in Ruby.  The old
    way was to call the module function Guestfs::create() which still
    works.

diff --git a/src/generator.ml b/src/generator.ml
index 97dc6ac..3f5fd6c 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -10835,6 +10835,10 @@ void Init__guestfs ()
   c_guestfs = rb_define_class_under (m_guestfs, \"Guestfs\", rb_cObject);
   e_Error = rb_define_class_under (m_guestfs, \"Error\", rb_eStandardError);
 
+#ifdef HAVE_RB_DEFINE_ALLOC_FUNC
+  rb_define_alloc_func (c_guestfs, ruby_guestfs_create);
+#endif
+
   rb_define_module_function (m_guestfs, \"create\", ruby_guestfs_create, 0);
   rb_define_method (c_guestfs, \"close\", ruby_guestfs_close, 0);

Comment 3 Richard W.M. Jones 2013-12-27 12:54:37 UTC
I've posted a rather large patch which should fix this mess.

However it would be good if someone who knows Ruby a bit better
could take a look.

https://www.redhat.com/archives/libguestfs/2013-December/msg00095.html

Comment 4 Richard W.M. Jones 2014-01-02 16:21:05 UTC
Well, works for me and no one cared enough to comment, so I
have pushed this.

Fixed in 1.25.19.

Candidate for backporting to 1.24.4, hence setting bug to F20.

The ::create module function will work if you want compatibility
with F19 and forwards, use .new if you don't care about F19.

https://github.com/libguestfs/libguestfs/commit/ee4ce2a0298d012bd8c500c35dc50e1f53e88c8b

Comment 5 Fedora Update System 2014-01-04 19:40:46 UTC
libguestfs-1.24.4-1.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/libguestfs-1.24.4-1.fc20

Comment 6 Fedora Update System 2014-01-05 06:00:45 UTC
Package libguestfs-1.24.4-1.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing libguestfs-1.24.4-1.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-0216/libguestfs-1.24.4-1.fc20
then log in and leave karma (feedback).

Comment 7 Fedora Update System 2014-01-13 03:00:12 UTC
libguestfs-1.24.4-1.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 8 Fedora Update System 2014-01-21 08:44:49 UTC
libguestfs-1.24.5-1.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/libguestfs-1.24.5-1.fc20

Comment 9 Fedora Update System 2014-01-30 03:39:07 UTC
libguestfs-1.24.5-1.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.