Revert "Refactor to avoid nonnull checks on "this" pointer."

This reverts commit 0008bdea02.

This patch introduced a regression.  Calling FOO=$(...) in zsh hangs
indefinitely and has to be killed forcefully.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2016-04-05 10:26:06 +02:00
parent 722e363c4d
commit 41abcc5825
9 changed files with 38 additions and 75 deletions

View File

@ -342,7 +342,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
size_t n; size_t n;
pid_t pid = va_arg (arg, pid_t); pid_t pid = va_arg (arg, pid_t);
pinfo p (pid); pinfo p (pid);
res = p ? (uintptr_t) p->cmdline (n) : 0; res = (uintptr_t) p->cmdline (n);
} }
break; break;
case CW_CHECK_NTSEC: case CW_CHECK_NTSEC:

View File

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

View File

@ -371,11 +371,6 @@ format_process_fd (void *data, char *&destbuf)
case a trailing slash and more followup chars are allowed, provided the case a trailing slash and more followup chars are allowed, provided the
descriptor symlink points to a directory. */ descriptor symlink points to a directory. */
char *fdp = strchr (path, '/') + 3; char *fdp = strchr (path, '/') + 3;
if (!p)
{
set_errno (ENOENT);
return 0;
}
/* The "fd" directory itself? */ /* The "fd" directory itself? */
if (fdp[0] =='\0' || (fdp[0] == '/' && fdp[1] == '\0')) if (fdp[0] =='\0' || (fdp[0] == '/' && fdp[1] == '\0'))
{ {
@ -484,7 +479,7 @@ format_process_root (void *data, char *&destbuf)
cfree (destbuf); cfree (destbuf);
destbuf = NULL; destbuf = NULL;
} }
destbuf = p ? p->root (fs) : NULL; destbuf = p->root (fs);
if (!destbuf || !*destbuf) if (!destbuf || !*destbuf)
{ {
destbuf = cstrdup ("<defunct>"); destbuf = cstrdup ("<defunct>");
@ -504,7 +499,7 @@ format_process_cwd (void *data, char *&destbuf)
cfree (destbuf); cfree (destbuf);
destbuf = NULL; destbuf = NULL;
} }
destbuf = p ? p->cwd (fs) : NULL; destbuf = p->cwd (fs);
if (!destbuf || !*destbuf) if (!destbuf || !*destbuf)
{ {
destbuf = cstrdup ("<defunct>"); destbuf = cstrdup ("<defunct>");
@ -524,7 +519,7 @@ format_process_cmdline (void *data, char *&destbuf)
cfree (destbuf); cfree (destbuf);
destbuf = NULL; destbuf = NULL;
} }
destbuf = p ? p->cmdline (fs) : NULL; destbuf = p->cmdline (fs);
if (!destbuf || !*destbuf) if (!destbuf || !*destbuf)
{ {
destbuf = cstrdup ("<defunct>"); destbuf = cstrdup ("<defunct>");

View File

@ -134,7 +134,7 @@ tty_min::kill_pgrp (int sig)
for (unsigned i = 0; i < pids.npids; i++) for (unsigned i = 0; i < pids.npids; i++)
{ {
_pinfo *p = pids[i]; _pinfo *p = pids[i];
if (!p || !p->exists () || p->ctty != ntty || p->pgid != pgid) if (!p->exists () || p->ctty != ntty || p->pgid != pgid)
continue; continue;
if (p == myself) if (p == myself)
killself = sig != __SIGSETPGRP && !exit_state; killself = sig != __SIGSETPGRP && !exit_state;

View File

@ -3932,7 +3932,7 @@ fcwd_access_t::Free (PVOID heap)
{ {
/* Decrement the reference count. If it's down to 0, free /* Decrement the reference count. If it's down to 0, free
structure from heap. */ structure from heap. */
if (InterlockedDecrement (&ReferenceCount ()) == 0) if (this && InterlockedDecrement (&ReferenceCount ()) == 0)
{ {
/* In contrast to pre-Vista, the handle on init is always a /* In contrast to pre-Vista, the handle on init is always a
fresh one and not the handle inherited from the parent fresh one and not the handle inherited from the parent
@ -4320,8 +4320,7 @@ cwdstuff::override_win32_cwd (bool init, ULONG old_dismount_count)
f_cwd->CopyPath (upp_cwd_str); f_cwd->CopyPath (upp_cwd_str);
upp_cwd_hdl = dir; upp_cwd_hdl = dir;
RtlLeaveCriticalSection (peb.FastPebLock); RtlLeaveCriticalSection (peb.FastPebLock);
if (old_cwd) old_cwd->Free (heap);
old_cwd->Free (heap);
} }
else else
{ {

View File

@ -514,7 +514,7 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags)
bool __reg1 bool __reg1
_pinfo::exists () _pinfo::exists ()
{ {
return process_state && !(process_state & (PID_EXITED | PID_REAPED | PID_EXECED)); return this && process_state && !(process_state & (PID_EXITED | PID_REAPED | PID_EXECED));
} }
bool bool
@ -685,7 +685,7 @@ _pinfo::commune_request (__uint32_t code, ...)
res.s = NULL; res.s = NULL;
res.n = 0; res.n = 0;
if (!pid) if (!this || !pid)
{ {
set_errno (ESRCH); set_errno (ESRCH);
goto err; goto err;
@ -783,7 +783,7 @@ out:
fhandler_pipe * fhandler_pipe *
_pinfo::pipe_fhandler (int64_t unique_id, size_t &n) _pinfo::pipe_fhandler (int64_t unique_id, size_t &n)
{ {
if (!pid) if (!this || !pid)
return NULL; return NULL;
if (pid == myself->pid) if (pid == myself->pid)
return NULL; return NULL;
@ -796,7 +796,7 @@ char *
_pinfo::fd (int fd, size_t &n) _pinfo::fd (int fd, size_t &n)
{ {
char *s; char *s;
if (!pid) if (!this || !pid)
return NULL; return NULL;
if (pid != myself->pid) if (pid != myself->pid)
{ {
@ -820,7 +820,7 @@ char *
_pinfo::fds (size_t &n) _pinfo::fds (size_t &n)
{ {
char *s; char *s;
if (!pid) if (!this || !pid)
return NULL; return NULL;
if (pid != myself->pid) if (pid != myself->pid)
{ {
@ -848,7 +848,7 @@ char *
_pinfo::root (size_t& n) _pinfo::root (size_t& n)
{ {
char *s; char *s;
if (!pid) if (!this || !pid)
return NULL; return NULL;
if (pid != myself->pid && !ISSTATE (this, PID_NOTCYGWIN)) if (pid != myself->pid && !ISSTATE (this, PID_NOTCYGWIN))
{ {
@ -893,7 +893,7 @@ char *
_pinfo::cwd (size_t& n) _pinfo::cwd (size_t& n)
{ {
char *s = NULL; char *s = NULL;
if (!pid) if (!this || !pid)
return NULL; return NULL;
if (ISSTATE (this, PID_NOTCYGWIN)) if (ISSTATE (this, PID_NOTCYGWIN))
{ {
@ -939,7 +939,7 @@ char *
_pinfo::cmdline (size_t& n) _pinfo::cmdline (size_t& n)
{ {
char *s = NULL; char *s = NULL;
if (!pid) if (!this || !pid)
return NULL; return NULL;
if (ISSTATE (this, PID_NOTCYGWIN)) if (ISSTATE (this, PID_NOTCYGWIN))
{ {

View File

@ -263,7 +263,7 @@ _pinfo::kill (siginfo_t& si)
} }
this_pid = pid; this_pid = pid;
} }
else if (si.si_signo == 0 && process_state == PID_EXITED) else if (si.si_signo == 0 && this && process_state == PID_EXITED)
{ {
this_process_state = process_state; this_process_state = process_state;
this_pid = pid; this_pid = pid;
@ -299,12 +299,8 @@ kill0 (pid_t pid, siginfo_t& si)
syscall_printf ("signal %d out of range", si.si_signo); syscall_printf ("signal %d out of range", si.si_signo);
return -1; return -1;
} }
if (pid > 0) {
pinfo p(pid); return (pid > 0) ? pinfo (pid)->kill (si) : kill_pgrp (-pid, si);
return p && p->kill(si);
} else {
return kill_pgrp(-pid, si);
}
} }
int int
@ -330,7 +326,7 @@ kill_pgrp (pid_t pid, siginfo_t& si)
{ {
_pinfo *p = pids[i]; _pinfo *p = pids[i];
if (!p || !p->exists ()) if (!p->exists ())
continue; continue;
/* Is it a process we want to kill? */ /* Is it a process we want to kill? */

View File

@ -155,8 +155,7 @@ proc_can_be_signalled (_pinfo *p)
bool __reg1 bool __reg1
pid_exists (pid_t pid) pid_exists (pid_t pid)
{ {
pinfo p(pid); return pinfo (pid)->exists ();
return p && p->exists ();
} }
/* Return true if this is one of our children, false otherwise. */ /* Return true if this is one of our children, false otherwise. */
@ -1144,7 +1143,7 @@ remove_proc (int ci)
if (_my_tls._ctinfo != procs[ci].wait_thread) if (_my_tls._ctinfo != procs[ci].wait_thread)
procs[ci].wait_thread->terminate_thread (); procs[ci].wait_thread->terminate_thread ();
} }
else if (procs[ci] && procs[ci]->exists ()) else if (procs[ci]->exists ())
return true; return true;
sigproc_printf ("removing procs[%d], pid %d, nprocs %d", ci, procs[ci]->pid, sigproc_printf ("removing procs[%d], pid %d, nprocs %d", ci, procs[ci]->pid,

View File

@ -542,7 +542,7 @@ clock_gettime (clockid_t clk_id, struct timespec *tp)
pid = getpid (); pid = getpid ();
pinfo p (pid); pinfo p (pid);
if (!p || !p->exists ()) if (!p->exists ())
{ {
set_errno (EINVAL); set_errno (EINVAL);
return -1; return -1;
@ -765,8 +765,7 @@ clock_setres (clockid_t clk_id, struct timespec *tp)
extern "C" int extern "C" int
clock_getcpuclockid (pid_t pid, clockid_t *clk_id) clock_getcpuclockid (pid_t pid, clockid_t *clk_id)
{ {
pinfo p(pid); if (pid != 0 && !pinfo (pid)->exists ())
if (pid != 0 && (!p || !p->exists ()))
return (ESRCH); return (ESRCH);
*clk_id = (clockid_t) PID_TO_CLOCKID (pid); *clk_id = (clockid_t) PID_TO_CLOCKID (pid);
return 0; return 0;