public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [RFC PATCH v3] Refactor to avoid nonnull checks on "this" pointer.
@ 2016-04-01 15:43 Peter Foley
  2016-04-01 16:24 ` Corinna Vinschen
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Foley @ 2016-04-01 15:43 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Peter Foley

G++ 6.0 asserts that the "this" pointer is non-null for member
functions.
Refactor methods that check if this is non-null to resolve this.

Signed-off-by: Peter Foley <pefoley2@pefoley.com>
---
Just wanted to make sure that this approach looked good before I fix all the problematic files.

 winsup/cygwin/fhandler_dsp.cc | 55 +++++++++++++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 15 deletions(-)

diff --git a/winsup/cygwin/fhandler_dsp.cc b/winsup/cygwin/fhandler_dsp.cc
index 9fa2c6e..55944b4 100644
--- a/winsup/cygwin/fhandler_dsp.cc
+++ b/winsup/cygwin/fhandler_dsp.cc
@@ -65,7 +65,7 @@ class fhandler_dev_dsp::Audio
   void convert_S16LE_S16BE (unsigned char *buffer, int size_bytes);
   void fillFormat (WAVEFORMATEX * format,
 		   int rate, int bits, int channels);
-  unsigned blockSize (int rate, int bits, int channels);
+  static unsigned blockSize (int rate, int bits, int channels);
   void (fhandler_dev_dsp::Audio::*convert_)
     (unsigned char *buffer, int size_bytes);
 
@@ -117,6 +117,7 @@ class fhandler_dev_dsp::Audio_out: public Audio
   void stop (bool immediately = false);
   int write (const char *pSampleData, int nBytes);
   void buf_info (audio_buf_info *p, int rate, int bits, int channels);
+  static void default_buf_info (audio_buf_info *p, int rate, int bits, int channels);
   void callback_sampledone (WAVEHDR *pHdr);
   bool parsewav (const char *&pData, int &nBytes,
 		 int rate, int bits, int channels);
@@ -151,6 +152,7 @@ public:
   void stop ();
   bool read (char *pSampleData, int &nBytes);
   void buf_info (audio_buf_info *p, int rate, int bits, int channels);
+  static void default_buf_info (audio_buf_info *p, int rate, int bits, int channels);
   void callback_blockfull (WAVEHDR *pHdr);
 
 private:
@@ -501,11 +503,11 @@ void
 fhandler_dev_dsp::Audio_out::buf_info (audio_buf_info *p,
 				       int rate, int bits, int channels)
 {
-  p->fragstotal = MAX_BLOCKS;
-  if (this && dev_)
+  if (dev_)
     {
       /* If the device is running we use the internal values,
 	 possibly set from the wave file. */
+      p->fragstotal = MAX_BLOCKS;
       p->fragsize = blockSize (freq_, bits_, channels_);
       p->fragments = Qisr2app_->query ();
       if (pHdr_ != NULL)
@@ -516,10 +518,17 @@ fhandler_dev_dsp::Audio_out::buf_info (audio_buf_info *p,
     }
   else
     {
+      default_buf_info(p, rate, bits, channels);
+    }
+}
+
+void fhandler_dev_dsp::Audio_out::default_buf_info (audio_buf_info *p,
+                                                int rate, int bits, int channels)
+{
+      p->fragstotal = MAX_BLOCKS;
       p->fragsize = blockSize (rate, bits, channels);
       p->fragments = MAX_BLOCKS;
       p->bytes = p->fragsize * p->fragments;
-    }
 }
 
 /* This is called on an interupt so use locking.. Note Qisr2app_
@@ -953,14 +962,23 @@ fhandler_dev_dsp::Audio_in::waitfordata ()
   return true;
 }
 
+void fhandler_dev_dsp::Audio_in::default_buf_info (audio_buf_info *p,
+                                                int rate, int bits, int channels)
+{
+  p->fragstotal = MAX_BLOCKS;
+  p->fragsize = blockSize (rate, bits, channels);
+  p->fragments = 0;
+  p->bytes = 0;
+}
+
 void
 fhandler_dev_dsp::Audio_in::buf_info (audio_buf_info *p,
 				      int rate, int bits, int channels)
 {
-  p->fragstotal = MAX_BLOCKS;
-  p->fragsize = blockSize (rate, bits, channels);
-  if (this && dev_)
+  if (dev_)
     {
+      p->fragstotal = MAX_BLOCKS;
+      p->fragsize = blockSize (rate, bits, channels);
       p->fragments = Qisr2app_->query ();
       if (pHdr_ != NULL)
 	p->bytes = pHdr_->dwBytesRecorded - bufferIndex_
@@ -970,8 +988,7 @@ fhandler_dev_dsp::Audio_in::buf_info (audio_buf_info *p,
     }
   else
     {
-      p->fragments = 0;
-      p->bytes = 0;
+      default_buf_info(p, rate, bits, channels);
     }
 }
 
@@ -1345,9 +1362,13 @@ fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf)
 	    return -1;
 	  }
 	audio_buf_info *p = (audio_buf_info *) buf;
-	audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
-	debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
-		      buf, p->fragments, p->fragsize, p->bytes);
+        if (audio_out_) {
+            audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
+        } else {
+            Audio_out::default_buf_info(p, audiofreq_, audiobits_, audiochannels_);
+        }
+        debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
+                      buf, p->fragments, p->fragsize, p->bytes);
 	return 0;
       }
 
@@ -1359,9 +1380,13 @@ fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf)
 	    return -1;
 	  }
 	audio_buf_info *p = (audio_buf_info *) buf;
-	audio_in_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
-	debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
-		      buf, p->fragments, p->fragsize, p->bytes);
+        if (audio_in_) {
+            audio_in_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
+        } else {
+            Audio_in::default_buf_info(p, audiofreq_, audiobits_, audiochannels_);
+        }
+        debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
+                      buf, p->fragments, p->fragsize, p->bytes);
 	return 0;
       }
 
-- 
2.8.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH v3] Refactor to avoid nonnull checks on "this" pointer.
  2016-04-01 15:43 [RFC PATCH v3] Refactor to avoid nonnull checks on "this" pointer Peter Foley
@ 2016-04-01 16:24 ` Corinna Vinschen
  2016-04-01 16:26   ` Peter Foley
  0 siblings, 1 reply; 3+ messages in thread
From: Corinna Vinschen @ 2016-04-01 16:24 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 1422 bytes --]

On Apr  1 11:42, Peter Foley wrote:
> G++ 6.0 asserts that the "this" pointer is non-null for member
> functions.
> Refactor methods that check if this is non-null to resolve this.
> 
> Signed-off-by: Peter Foley <pefoley2@pefoley.com>
> ---
> Just wanted to make sure that this approach looked good before I fix
> all the problematic files.

Looks good to me, except for a style issue:

> -	audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
> -	debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
> -		      buf, p->fragments, p->fragsize, p->bytes);
> +        if (audio_out_) {
> +            audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
> +        } else {
> +            Audio_out::default_buf_info(p, audiofreq_, audiobits_, audiochannels_);
> +        }

I guess this was just a result of speed-typing :) but that should be

  if (audio_out_)
    {
      ...
    }
  else
    {
      ...
    }

OTOH, single-line statements shouldn't use braces at all:

   if (audio_out_)
     audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
   else
     Audio_out::default_buf_info(p, audiofreq_, audiobits_, audiochannels_);

Other than that, please go ahead.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH v3] Refactor to avoid nonnull checks on "this" pointer.
  2016-04-01 16:24 ` Corinna Vinschen
@ 2016-04-01 16:26   ` Peter Foley
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Foley @ 2016-04-01 16:26 UTC (permalink / raw)
  To: cygwin-patches

On Fri, Apr 1, 2016 at 12:24 PM, Corinna Vinschen
<corinna-cygwin@cygwin.com> wrote:
> Other than that, please go ahead.

Will do.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-01 16:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-01 15:43 [RFC PATCH v3] Refactor to avoid nonnull checks on "this" pointer Peter Foley
2016-04-01 16:24 ` Corinna Vinschen
2016-04-01 16:26   ` Peter Foley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).