From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH kvm-unit-tests 2/4] Introduce a C++ wrapper for the kvm APIs Date: Sun, 28 Nov 2010 16:12:16 -0600 Message-ID: <4CF2D3C0.3050200@codemonkey.ws> References: <1290595933-13122-1-git-send-email-avi@redhat.com> <1290595933-13122-3-git-send-email-avi@redhat.com> <20101126101625.GA3657@redhat.com> <4CF0CB9A.5060403@redhat.com> <20101128085833.GA3330@redhat.com> <4CF2215D.9060201@redhat.com> <20101128095056.GA4499@redhat.com> <4CF226D2.6030102@redhat.com> <20101128114424.GB4499@redhat.com> <4CF255A9.6030502@redhat.com> <20101128144020.GC12874@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Avi Kivity , Marcelo Tosatti , kvm@vger.kernel.org To: "Michael S. Tsirkin" Return-path: Received: from mail-gx0-f174.google.com ([209.85.161.174]:46873 "EHLO mail-gx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751813Ab0K1WMS (ORCPT ); Sun, 28 Nov 2010 17:12:18 -0500 Received: by gxk22 with SMTP id 22so1706861gxk.19 for ; Sun, 28 Nov 2010 14:12:18 -0800 (PST) In-Reply-To: <20101128144020.GC12874@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 11/28/2010 08:40 AM, Michael S. Tsirkin wrote: > >> This code is not reusable. Everywhere you use an fd, you have to >> repeat this code. >> > But that's not a lot of code. And you can abstract it away at a higher > level. For example kvm_init and kvm_cleanup would setup/cleanup > state in a consistent way. > > My experience tells me C++ code has much more boilerplate code that you > are forced to repeat over and over. This is especially true for unix > system programming: by the time you are done wrapping all of unix you > have created more LOC than you are ever likely to save. > I've said it earlier but I think it's worth repeating--trying to wrap libc in "pretty" C++ interfaces is a waste of time. In an ideal world, the device model doesn't interact at all with libc. Most of the code simply manipulates internal state and some code will provide a bridge to well defined internal interfaces. The nice thing about C++ though is that you can still write "C" code and compile it with g++ (or even gcc if you care). So you can use objects where they make sense and not use them where they don't. >> class kvm::fd is reusable, if you embed it in another object you >> don't have to worry about errors any more (as long as the object's >> methods are exception safe). >> > To get exception safe code, you have to constantly worry about errors. > And it's easier to spot an unhandled return code than exception-unsafe > code: gcc actually has __attribute__((warn_unused_result)) which > might help catch common errors. No such tool to catch > exception-unsafe code AFAIK. > I tend to agree that writing exception safe code and using exceptions for expected errors is a bad idea. I think exceptions should be used primarily for unexpected errors. Regards, Anthony Liguori > >> -- >> error compiling committee.c: too many arguments to function >> > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >