4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-02 12:30:24 +08:00

Cygwin: fhandler: clean up 'copyto' logic

Analyzing the fhandler::copyto logic shows that the fhandler_base::reset
method was only called from copyto anyway.

Trying to convert reset to a protected method uncovered that the copyto
method is actually thought upside down from an object oriented POV.

Rather than calling copyto, manipulating the object given as parameter,
rename the method to copy_from, which manipulates the calling object
itself with data from the object given as parameter.

Eventually make reset a protected method and rename it to
_copy_from_reset_helper to clarify it's only called from copy_from.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2021-02-10 10:42:05 +01:00 committed by Ken Brown
parent 518f0b8ef9
commit 0be0fce618
3 changed files with 197 additions and 197 deletions

View File

@ -41,17 +41,6 @@ struct __cygwin_perfile *perfile_table;
HANDLE NO_COPY fhandler_base_overlapped::asio_done; HANDLE NO_COPY fhandler_base_overlapped::asio_done;
LONG NO_COPY fhandler_base_overlapped::asio_close_counter; LONG NO_COPY fhandler_base_overlapped::asio_close_counter;
void
fhandler_base::reset (const fhandler_base *from)
{
ra.rabuf = NULL;
ra.ralen = 0;
ra.raixget = 0;
ra.raixput = 0;
ra.rabuflen = 0;
_refcnt = 0;
}
int int
fhandler_base::puts_readahead (const char *s, size_t len) fhandler_base::puts_readahead (const char *s, size_t len)
{ {
@ -479,7 +468,7 @@ fhandler_base::open_with_arch (int flags, mode_t mode)
{ {
if (!archetype->get_handle ()) if (!archetype->get_handle ())
{ {
copyto (archetype); archetype->copy_from (this);
archetype_usecount (1); archetype_usecount (1);
archetype->archetype = NULL; archetype->archetype = NULL;
usecount = 0; usecount = 0;
@ -496,7 +485,7 @@ fhandler_base::open_with_arch (int flags, mode_t mode)
strcpy (name, get_name ()); strcpy (name, get_name ());
} }
fhandler_base *arch = archetype; fhandler_base *arch = archetype;
archetype->copyto (this); copy_from (archetype);
if (name) if (name)
set_name (name); set_name (name);
archetype = arch; archetype = arch;

View File

@ -229,7 +229,6 @@ class fhandler_base
path_conv pc; path_conv pc;
void reset (const fhandler_base *);
virtual bool use_archetype () const {return false;} virtual bool use_archetype () const {return false;}
virtual void set_name (path_conv &pc); virtual void set_name (path_conv &pc);
virtual void set_name (const char *s) virtual void set_name (const char *s)
@ -496,18 +495,30 @@ public:
fhandler_base (void *) {} fhandler_base (void *) {}
virtual void copyto (fhandler_base *x) protected:
void _copy_from_reset_helper ()
{ {
x->pc.free_strings (); ra.rabuf = NULL;
*reinterpret_cast<fhandler_base *> (x) = *this; ra.ralen = 0;
x->reset (this); ra.raixget = 0;
ra.raixput = 0;
ra.rabuflen = 0;
_refcnt = 0;
}
public:
virtual void copy_from (fhandler_base *x)
{
pc.free_strings ();
*this = *reinterpret_cast<fhandler_base *> (x);
_copy_from_reset_helper ();
} }
virtual fhandler_base *clone (cygheap_types malloc_type = HEAP_FHANDLER) virtual fhandler_base *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_base)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_base));
fhandler_base *fh = new (ptr) fhandler_base (ptr); fhandler_base *fh = new (ptr) fhandler_base (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -759,18 +770,18 @@ class fhandler_socket_inet: public fhandler_socket_wsock
/* from here on: CLONING */ /* from here on: CLONING */
fhandler_socket_inet (void *) {} fhandler_socket_inet (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_socket_inet *> (x) = *this; *this = *reinterpret_cast<fhandler_socket_inet *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_socket_inet *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_socket_inet *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_socket_inet)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_socket_inet));
fhandler_socket_inet *fh = new (ptr) fhandler_socket_inet (ptr); fhandler_socket_inet *fh = new (ptr) fhandler_socket_inet (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -859,18 +870,18 @@ class fhandler_socket_local: public fhandler_socket_wsock
/* from here on: CLONING */ /* from here on: CLONING */
fhandler_socket_local (void *) {} fhandler_socket_local (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_socket_local *> (x) = *this; *this = *reinterpret_cast<fhandler_socket_local *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_socket_local *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_socket_local *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_socket_local)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_socket_local));
fhandler_socket_local *fh = new (ptr) fhandler_socket_local (ptr); fhandler_socket_local *fh = new (ptr) fhandler_socket_local (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -1302,18 +1313,18 @@ class fhandler_socket_unix : public fhandler_socket
/* from here on: CLONING */ /* from here on: CLONING */
fhandler_socket_unix (void *) {} fhandler_socket_unix (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_socket_unix *> (x) = *this; *this = *reinterpret_cast<fhandler_socket_unix *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_socket_unix *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_socket_unix *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_socket_unix)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_socket_unix));
fhandler_socket_unix *fh = new (ptr) fhandler_socket_unix (ptr); fhandler_socket_unix *fh = new (ptr) fhandler_socket_unix (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -1371,19 +1382,19 @@ public:
cfree (atomic_write_buf); cfree (atomic_write_buf);
} }
virtual void copyto (fhandler_base *x) virtual void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_base_overlapped *> (x) = *this; *this = *reinterpret_cast<fhandler_base_overlapped *> (x);
reinterpret_cast<fhandler_base_overlapped *> (x)->atomic_write_buf = NULL; atomic_write_buf = NULL;
x->reset (this); _copy_from_reset_helper ();
} }
virtual fhandler_base_overlapped *clone (cygheap_types malloc_type = HEAP_FHANDLER) virtual fhandler_base_overlapped *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_base_overlapped)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_base_overlapped));
fhandler_base_overlapped *fh = new (ptr) fhandler_base_overlapped (ptr); fhandler_base_overlapped *fh = new (ptr) fhandler_base_overlapped (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
@ -1423,19 +1434,19 @@ public:
fhandler_pipe (void *) {} fhandler_pipe (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_pipe *> (x) = *this; *this = *reinterpret_cast<fhandler_pipe *> (x);
reinterpret_cast<fhandler_pipe *> (x)->atomic_write_buf = NULL; atomic_write_buf = NULL;
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_pipe *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_pipe *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_pipe)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_pipe));
fhandler_pipe *fh = new (ptr) fhandler_pipe (ptr); fhandler_pipe *fh = new (ptr) fhandler_pipe (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -1678,18 +1689,18 @@ public:
fhandler_fifo (void *) {} fhandler_fifo (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_fifo *> (x) = *this; *this = *reinterpret_cast<fhandler_fifo *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_fifo *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_fifo *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_fifo)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_fifo));
fhandler_fifo *fhf = new (ptr) fhandler_fifo (ptr); fhandler_fifo *fhf = new (ptr) fhandler_fifo (ptr);
copyto (fhf); fhf->copy_from (this);
fhf->pipe_name_buf = NULL; fhf->pipe_name_buf = NULL;
return fhf; return fhf;
} }
@ -1732,18 +1743,18 @@ class fhandler_dev_raw: public fhandler_base
fhandler_dev_raw (void *) {} fhandler_dev_raw (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev_raw *> (x) = *this; *this = *reinterpret_cast<fhandler_dev_raw *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev_raw *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev_raw *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_raw)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_raw));
fhandler_dev_raw *fh = new (ptr) fhandler_dev_raw (ptr); fhandler_dev_raw *fh = new (ptr) fhandler_dev_raw (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -1793,18 +1804,18 @@ class fhandler_dev_floppy: public fhandler_dev_raw
fhandler_dev_floppy (void *) {} fhandler_dev_floppy (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev_floppy *> (x) = *this; *this = *reinterpret_cast<fhandler_dev_floppy *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev_floppy *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev_floppy *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_floppy)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_floppy));
fhandler_dev_floppy *fh = new (ptr) fhandler_dev_floppy (ptr); fhandler_dev_floppy *fh = new (ptr) fhandler_dev_floppy (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -1843,18 +1854,18 @@ class fhandler_dev_tape: public fhandler_dev_raw
fhandler_dev_tape (void *) {} fhandler_dev_tape (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev_tape *> (x) = *this; *this = *reinterpret_cast<fhandler_dev_tape *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev_tape *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev_tape *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_tape)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_tape));
fhandler_dev_tape *fh = new (ptr) fhandler_dev_tape (ptr); fhandler_dev_tape *fh = new (ptr) fhandler_dev_tape (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -1918,18 +1929,18 @@ class fhandler_disk_file: public fhandler_base
fhandler_disk_file (void *) {} fhandler_disk_file (void *) {}
dev_t get_dev () { return pc.fs_serial_number (); } dev_t get_dev () { return pc.fs_serial_number (); }
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_disk_file *> (x) = *this; *this = *reinterpret_cast<fhandler_disk_file *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_disk_file *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_disk_file *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_disk_file)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_disk_file));
fhandler_disk_file *fh = new (ptr) fhandler_disk_file (ptr); fhandler_disk_file *fh = new (ptr) fhandler_disk_file (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -1956,18 +1967,18 @@ public:
dev_t get_dev () { return dir_exists ? pc.fs_serial_number () dev_t get_dev () { return dir_exists ? pc.fs_serial_number ()
: get_device (); } : get_device (); }
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev *> (x) = *this; *this = *reinterpret_cast<fhandler_dev *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev));
fhandler_dev *fh = new (ptr) fhandler_dev (ptr); fhandler_dev *fh = new (ptr) fhandler_dev (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -1989,18 +2000,18 @@ class fhandler_cygdrive: public fhandler_disk_file
fhandler_cygdrive (void *) {} fhandler_cygdrive (void *) {}
dev_t get_dev () { return get_device (); } dev_t get_dev () { return get_device (); }
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_cygdrive *> (x) = *this; *this = *reinterpret_cast<fhandler_cygdrive *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_cygdrive *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_cygdrive *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_cygdrive)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_cygdrive));
fhandler_cygdrive *fh = new (ptr) fhandler_cygdrive (ptr); fhandler_cygdrive *fh = new (ptr) fhandler_cygdrive (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2050,18 +2061,18 @@ class fhandler_serial: public fhandler_base
fhandler_serial (void *) {} fhandler_serial (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_serial *> (x) = *this; *this = *reinterpret_cast<fhandler_serial *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_serial *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_serial *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_serial)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_serial));
fhandler_serial *fh = new (ptr) fhandler_serial (ptr); fhandler_serial *fh = new (ptr) fhandler_serial (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2122,18 +2133,18 @@ class fhandler_termios: public fhandler_base
fhandler_termios (void *) {} fhandler_termios (void *) {}
virtual void copyto (fhandler_base *x) virtual void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_termios *> (x) = *this; *this = *reinterpret_cast<fhandler_termios *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
virtual fhandler_termios *clone (cygheap_types malloc_type = HEAP_FHANDLER) virtual fhandler_termios *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_termios)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_termios));
fhandler_termios *fh = new (ptr) fhandler_termios (ptr); fhandler_termios *fh = new (ptr) fhandler_termios (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2384,18 +2395,18 @@ private:
fhandler_console (void *) {} fhandler_console (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_console *> (x) = *this; *this = *reinterpret_cast<fhandler_console *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_console *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_console *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_console)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_console));
fhandler_console *fh = new (ptr) fhandler_console (ptr); fhandler_console *fh = new (ptr) fhandler_console (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
input_states process_input_message (); input_states process_input_message ();
@ -2459,18 +2470,18 @@ class fhandler_pty_common: public fhandler_termios
fhandler_pty_common (void *) {} fhandler_pty_common (void *) {}
virtual void copyto (fhandler_base *x) virtual void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_pty_common *> (x) = *this; *this = *reinterpret_cast<fhandler_pty_common *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
virtual fhandler_pty_common *clone (cygheap_types malloc_type = HEAP_FHANDLER) virtual fhandler_pty_common *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_pty_common)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_pty_common));
fhandler_pty_common *fh = new (ptr) fhandler_pty_common (ptr); fhandler_pty_common *fh = new (ptr) fhandler_pty_common (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
@ -2542,18 +2553,18 @@ class fhandler_pty_slave: public fhandler_pty_common
fhandler_pty_slave (void *) {} fhandler_pty_slave (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_pty_slave *> (x) = *this; *this = *reinterpret_cast<fhandler_pty_slave *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_pty_slave *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_pty_slave *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_pty_slave)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_pty_slave));
fhandler_pty_slave *fh = new (ptr) fhandler_pty_slave (ptr); fhandler_pty_slave *fh = new (ptr) fhandler_pty_slave (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
bool setup_pseudoconsole (bool nopcon); bool setup_pseudoconsole (bool nopcon);
@ -2640,18 +2651,18 @@ public:
fhandler_pty_master (void *) {} fhandler_pty_master (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_pty_master *> (x) = *this; *this = *reinterpret_cast<fhandler_pty_master *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_pty_master *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_pty_master *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_pty_master)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_pty_master));
fhandler_pty_master *fh = new (ptr) fhandler_pty_master (ptr); fhandler_pty_master *fh = new (ptr) fhandler_pty_master (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
bool to_be_read_from_pcon (void); bool to_be_read_from_pcon (void);
@ -2672,18 +2683,18 @@ class fhandler_dev_null: public fhandler_base
fhandler_dev_null (void *) {} fhandler_dev_null (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev_null *> (x) = *this; *this = *reinterpret_cast<fhandler_dev_null *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev_null *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev_null *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_null)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_null));
fhandler_dev_null *fh = new (ptr) fhandler_dev_null (ptr); fhandler_dev_null *fh = new (ptr) fhandler_dev_null (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
@ -2710,18 +2721,18 @@ class fhandler_dev_zero: public fhandler_base
fhandler_dev_zero (void *) {} fhandler_dev_zero (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev_zero *> (x) = *this; *this = *reinterpret_cast<fhandler_dev_zero *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev_zero *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev_zero *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_zero)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_zero));
fhandler_dev_zero *fh = new (ptr) fhandler_dev_zero (ptr); fhandler_dev_zero *fh = new (ptr) fhandler_dev_zero (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2744,18 +2755,18 @@ class fhandler_dev_random: public fhandler_base
fhandler_dev_random () : fhandler_base () {} fhandler_dev_random () : fhandler_base () {}
fhandler_dev_random (void *) {} fhandler_dev_random (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev_random *> (x) = *this; *this = *reinterpret_cast<fhandler_dev_random *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev_random *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev_random *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_random)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_random));
fhandler_dev_random *fh = new (ptr) fhandler_dev_random (ptr); fhandler_dev_random *fh = new (ptr) fhandler_dev_random (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2784,18 +2795,18 @@ class fhandler_dev_clipboard: public fhandler_base
fhandler_dev_clipboard (void *) {} fhandler_dev_clipboard (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev_clipboard *> (x) = *this; *this = *reinterpret_cast<fhandler_dev_clipboard *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev_clipboard *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev_clipboard *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_clipboard)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_clipboard));
fhandler_dev_clipboard *fh = new (ptr) fhandler_dev_clipboard (ptr); fhandler_dev_clipboard *fh = new (ptr) fhandler_dev_clipboard (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2824,18 +2835,18 @@ class fhandler_windows: public fhandler_base
fhandler_windows (void *) {} fhandler_windows (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_windows *> (x) = *this; *this = *reinterpret_cast<fhandler_windows *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_windows *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_windows *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_windows)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_windows));
fhandler_windows *fh = new (ptr) fhandler_windows (ptr); fhandler_windows *fh = new (ptr) fhandler_windows (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2880,18 +2891,18 @@ class fhandler_dev_dsp: public fhandler_base
fhandler_dev_dsp (void *) {} fhandler_dev_dsp (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_dev_dsp *> (x) = *this; *this = *reinterpret_cast<fhandler_dev_dsp *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_dev_dsp *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_dev_dsp *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_dsp)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_dsp));
fhandler_dev_dsp *fh = new (ptr) fhandler_dev_dsp (ptr); fhandler_dev_dsp *fh = new (ptr) fhandler_dev_dsp (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2933,18 +2944,18 @@ class fhandler_virtual : public fhandler_base
fhandler_virtual (void *) {} fhandler_virtual (void *) {}
virtual void copyto (fhandler_base *x) virtual void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_virtual *> (x) = *this; *this = *reinterpret_cast<fhandler_virtual *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
virtual fhandler_virtual *clone (cygheap_types malloc_type = HEAP_FHANDLER) virtual fhandler_virtual *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_virtual)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_virtual));
fhandler_virtual *fh = new (ptr) fhandler_virtual (ptr); fhandler_virtual *fh = new (ptr) fhandler_virtual (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -2967,18 +2978,18 @@ class fhandler_proc: public fhandler_virtual
fhandler_proc (void *) {} fhandler_proc (void *) {}
virtual void copyto (fhandler_base *x) virtual void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_proc *> (x) = *this; *this = *reinterpret_cast<fhandler_proc *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
virtual fhandler_proc *clone (cygheap_types malloc_type = HEAP_FHANDLER) virtual fhandler_proc *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_proc)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_proc));
fhandler_proc *fh = new (ptr) fhandler_proc (ptr); fhandler_proc *fh = new (ptr) fhandler_proc (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3005,18 +3016,18 @@ class fhandler_procsys: public fhandler_virtual
fhandler_procsys (void *) {} fhandler_procsys (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_procsys *> (x) = *this; *this = *reinterpret_cast<fhandler_procsys *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_procsys *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_procsys *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_procsys)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_procsys));
fhandler_procsys *fh = new (ptr) fhandler_procsys (ptr); fhandler_procsys *fh = new (ptr) fhandler_procsys (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3036,18 +3047,18 @@ class fhandler_procsysvipc: public fhandler_proc
fhandler_procsysvipc (void *) {} fhandler_procsysvipc (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_procsysvipc *> (x) = *this; *this = *reinterpret_cast<fhandler_procsysvipc *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_procsysvipc *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_procsysvipc *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_procsysvipc)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_procsysvipc));
fhandler_procsysvipc *fh = new (ptr) fhandler_procsysvipc (ptr); fhandler_procsysvipc *fh = new (ptr) fhandler_procsysvipc (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3069,18 +3080,18 @@ class fhandler_netdrive: public fhandler_virtual
fhandler_netdrive (void *) {} fhandler_netdrive (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_netdrive *> (x) = *this; *this = *reinterpret_cast<fhandler_netdrive *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_netdrive *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_netdrive *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_netdrive)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_netdrive));
fhandler_netdrive *fh = new (ptr) fhandler_netdrive (ptr); fhandler_netdrive *fh = new (ptr) fhandler_netdrive (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3112,18 +3123,18 @@ class fhandler_registry: public fhandler_proc
fhandler_registry (void *) {} fhandler_registry (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_registry *> (x) = *this; *this = *reinterpret_cast<fhandler_registry *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_registry *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_registry *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_registry)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_registry));
fhandler_registry *fh = new (ptr) fhandler_registry (ptr); fhandler_registry *fh = new (ptr) fhandler_registry (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3148,18 +3159,18 @@ class fhandler_process: public fhandler_proc
fhandler_process (void *) {} fhandler_process (void *) {}
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_process *> (x) = *this; *this = *reinterpret_cast<fhandler_process *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_process *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_process *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_process)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_process));
fhandler_process *fh = new (ptr) fhandler_process (ptr); fhandler_process *fh = new (ptr) fhandler_process (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3178,18 +3189,18 @@ class fhandler_process_fd : public fhandler_process
size_t get_size () const { return sizeof *this; } size_t get_size () const { return sizeof *this; }
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_process_fd *> (x) = *this; *this = *reinterpret_cast<fhandler_process_fd *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_process_fd *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_process_fd *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_process_fd)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_process_fd));
fhandler_process_fd *fh = new (ptr) fhandler_process_fd (ptr); fhandler_process_fd *fh = new (ptr) fhandler_process_fd (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3208,18 +3219,18 @@ class fhandler_procnet: public fhandler_proc
size_t get_size () const { return sizeof *this; } size_t get_size () const { return sizeof *this; }
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_procnet *> (x) = *this; *this = *reinterpret_cast<fhandler_procnet *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_procnet *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_procnet *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_procnet)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_procnet));
fhandler_procnet *fh = new (ptr) fhandler_procnet (ptr); fhandler_procnet *fh = new (ptr) fhandler_procnet (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3250,18 +3261,18 @@ class fhandler_signalfd : public fhandler_base
size_t get_size () const { return sizeof *this; } size_t get_size () const { return sizeof *this; }
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_signalfd *> (x) = *this; *this = *reinterpret_cast<fhandler_signalfd *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_signalfd *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_signalfd *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_signalfd)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_signalfd));
fhandler_signalfd *fh = new (ptr) fhandler_signalfd (ptr); fhandler_signalfd *fh = new (ptr) fhandler_signalfd (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };
@ -3302,18 +3313,18 @@ class fhandler_timerfd : public fhandler_base
size_t get_size () const { return sizeof *this; } size_t get_size () const { return sizeof *this; }
void copyto (fhandler_base *x) void copy_from (fhandler_base *x)
{ {
x->pc.free_strings (); pc.free_strings ();
*reinterpret_cast<fhandler_timerfd *> (x) = *this; *this = *reinterpret_cast<fhandler_timerfd *> (x);
x->reset (this); _copy_from_reset_helper ();
} }
fhandler_timerfd *clone (cygheap_types malloc_type = HEAP_FHANDLER) fhandler_timerfd *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{ {
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_timerfd)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_timerfd));
fhandler_timerfd *fh = new (ptr) fhandler_timerfd (ptr); fhandler_timerfd *fh = new (ptr) fhandler_timerfd (ptr);
copyto (fh); fh->copy_from (this);
return fh; return fh;
} }
}; };

View File

@ -96,7 +96,7 @@ fhandler_pipe::open (int flags, mode_t mode)
if ((rwflags == O_RDONLY && !(cfd->get_access () & GENERIC_READ)) if ((rwflags == O_RDONLY && !(cfd->get_access () & GENERIC_READ))
|| (rwflags == O_WRONLY && !(cfd->get_access () & GENERIC_WRITE))) || (rwflags == O_WRONLY && !(cfd->get_access () & GENERIC_WRITE)))
continue; continue;
cfd->copyto (this); copy_from (cfd);
set_handle (NULL); set_handle (NULL);
pc.close_conv_handle (); pc.close_conv_handle ();
if (!cfd->dup (this, flags)) if (!cfd->dup (this, flags))