* cygheap_malloc.h: New file.

* cygheap.h: Remove stuff now included in cygheap_malloc.h and include that
file.  Make cygheap_init a standard c++ function.  Remove unneeded child_info
declaration.
* path.h: Include cygheap_malloc.h.  Remove extra cstrdup declaration.
(path_conv): Reorganize to group variables together.
(path_conv::path): Make const char *.
(path_conv::known_suffix): Ditto.
(path_conv::normalized_path): Ditto.
(path_conv::path_conv): Reorganize initializers to reflect new element
ordering.
(path_conv::get_win32): Change return value to const char *.
(path_conv::set_path): Move back here from spawn.cc.
(parh_conv::modifiable_path): New function.
* path.cc (path_conv::add_ext_from_sym): Accommodate const'ness of
known_suffixes.
(path_conv::set_normalized_path): Ditto for normalized_path.
(path_conv::check): Use modifiable_path whereever we need to modify the path
element.  Use set_path to set the path.
(path_conv::~path_conv): Accommodate new const'ness.
* spawn.cc (perhaps_suffix): Declare ext as const since that's what is being
returned.
(path_conv::set_path): Move back to path.h.
* winf.f (linebuf): Perform minor cleanup.
(linebuf::fromargv): Change second parameter to const.
* winf.cc (linebuf::fromargv): Ditto.
This commit is contained in:
Christopher Faylor 2009-08-01 19:52:46 +00:00
parent 8cc84a8ce3
commit fafbf75509
9 changed files with 132 additions and 86 deletions

View File

@ -1,3 +1,32 @@
2009-08-01 Christopher Faylor <me+cygwin@cgf.cx>
* cygheap_malloc.h: New file.
* cygheap.h: Remove stuff now included in cygheap_malloc.h and include
that file. Make cygheap_init a standard c++ function. Remove unneeded
child_info declaration.
* path.h: Include cygheap_malloc.h. Remove extra cstrdup declaration.
(path_conv): Reorganize to group variables together.
(path_conv::path): Make const char *.
(path_conv::known_suffix): Ditto.
(path_conv::normalized_path): Ditto.
(path_conv::path_conv): Reorganize initializers to reflect new element
ordering.
(path_conv::get_win32): Change return value to const char *.
(path_conv::set_path): Move back here from spawn.cc.
(parh_conv::modifiable_path): New function.
* path.cc (path_conv::add_ext_from_sym): Accommodate const'ness of
known_suffixes.
(path_conv::set_normalized_path): Ditto for normalized_path.
(path_conv::check): Use modifiable_path whereever we need to modify the
path element. Use set_path to set the path.
(path_conv::~path_conv): Accommodate new const'ness.
* spawn.cc (perhaps_suffix): Declare ext as const since that's what is
being returned.
(path_conv::set_path): Move back to path.h.
* winf.f (linebuf): Perform minor cleanup.
(linebuf::fromargv): Change second parameter to const.
* winf.cc (linebuf::fromargv): Ditto.
2009-08-01 Christopher Faylor <me+cygwin@cgf.cx>
* path.h (path_conv::set_path): Change return value.

View File

@ -151,7 +151,7 @@ _csbrk (int sbs)
return prebrk;
}
extern "C" void __stdcall
void __stdcall
cygheap_init ()
{
cygheap_protect.init ("cygheap_protect");

View File

@ -9,31 +9,7 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "hires.h"
#undef cfree
enum cygheap_types
{
HEAP_FHANDLER,
HEAP_STR,
HEAP_ARGV,
HEAP_BUF,
HEAP_MOUNT,
HEAP_SIGS,
HEAP_ARCHETYPES,
HEAP_TLS,
HEAP_COMMUNE,
HEAP_1_START,
HEAP_1_HOOK,
HEAP_1_STR,
HEAP_1_ARGV,
HEAP_1_BUF,
HEAP_1_EXEC,
HEAP_1_MAX = 100,
HEAP_2_STR,
HEAP_2_DLL,
HEAP_MMAP = 200
};
#include "cygheap_malloc.h"
#define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
@ -437,21 +413,6 @@ class cygheap_fdenum : public cygheap_fdmanip
}
};
class child_info;
void __stdcall cygheap_fixup_in_child (bool);
extern "C" {
void __stdcall cfree (void *) __attribute__ ((regparm(1)));
void *__stdcall cmalloc (cygheap_types, DWORD) __attribute__ ((regparm(2)));
void *__stdcall crealloc (void *, DWORD) __attribute__ ((regparm(2)));
void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
void *__stdcall cmalloc_abort (cygheap_types, DWORD) __attribute__ ((regparm(2)));
void *__stdcall crealloc_abort (void *, DWORD) __attribute__ ((regparm(2)));
void *__stdcall ccalloc_abort (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
PWCHAR __stdcall cwcsdup (const PWCHAR) __attribute__ ((regparm(1)));
PWCHAR __stdcall cwcsdup1 (const PWCHAR) __attribute__ ((regparm(1)));
char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
void __stdcall cfree_and_set (char *&, char * = NULL) __attribute__ ((regparm(2)));
void __stdcall cygheap_init ();
extern char _cygheap_start[] __attribute__((section(".idata")));
}

View File

@ -0,0 +1,54 @@
/* cygheap_malloc.h: Cygwin heap manager allocation functions.
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _CYGHEAP_MALLOC_H
#define _CYGHEAP_MALLOC_H
#undef cfree
enum cygheap_types
{
HEAP_FHANDLER,
HEAP_STR,
HEAP_ARGV,
HEAP_BUF,
HEAP_MOUNT,
HEAP_SIGS,
HEAP_ARCHETYPES,
HEAP_TLS,
HEAP_COMMUNE,
HEAP_1_START,
HEAP_1_HOOK,
HEAP_1_STR,
HEAP_1_ARGV,
HEAP_1_BUF,
HEAP_1_EXEC,
HEAP_1_MAX = 100,
HEAP_2_STR,
HEAP_2_DLL,
HEAP_MMAP = 200
};
extern "C" {
void __stdcall cfree (void *) __attribute__ ((regparm(1)));
void *__stdcall cmalloc (cygheap_types, DWORD) __attribute__ ((regparm(2)));
void *__stdcall crealloc (void *, DWORD) __attribute__ ((regparm(2)));
void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
void *__stdcall cmalloc_abort (cygheap_types, DWORD) __attribute__ ((regparm(2)));
void *__stdcall crealloc_abort (void *, DWORD) __attribute__ ((regparm(2)));
void *__stdcall ccalloc_abort (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
PWCHAR __stdcall cwcsdup (const PWCHAR) __attribute__ ((regparm(1)));
PWCHAR __stdcall cwcsdup1 (const PWCHAR) __attribute__ ((regparm(1)));
char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
void __stdcall cfree_and_set (char *&, char * = NULL) __attribute__ ((regparm(2)));
}
#endif /*_CYGHEAP_MALLOC_H*/

View File

@ -328,11 +328,13 @@ path_conv::add_ext_from_sym (symlink_info &sym)
{
known_suffix = path + sym.extn;
if (sym.ext_tacked_on)
strcpy (known_suffix, sym.ext_here);
strcpy ((char *) known_suffix, sym.ext_here);
}
}
static void __stdcall mkrelpath (char *dst, bool caseinsensitive) __attribute__ ((regparm (2)));
static void __stdcall mkrelpath (char *dst, bool caseinsensitive)
__attribute__ ((regparm (2)));
static void __stdcall
mkrelpath (char *path, bool caseinsensitive)
{
@ -379,9 +381,8 @@ path_conv::set_normalized_path (const char *path_copy)
if (path_copy)
{
size_t n = strlen (path_copy) + 1;
normalized_path = (char *) cmalloc_abort (HEAP_STR, n);
memcpy (normalized_path, path_copy, n);
char *p = (char *) cmalloc_abort (HEAP_STR, n);
normalized_path = (const char *) memcpy (p, path_copy, n);
}
}
@ -653,13 +654,17 @@ path_conv::check (const char *src, unsigned opt,
cfree (wide_path);
wide_path = NULL;
if (path)
cfree (path);
path = NULL;
{
cfree (modifiable_path ());
path = NULL;
}
memset (&dev, 0, sizeof (dev));
fs.clear ();
if (normalized_path)
cfree (normalized_path);
normalized_path = NULL;
{
cfree ((void *) normalized_path);
normalized_path = NULL;
}
int component = 0; // Number of translated components
if (!(opt & PC_NULLEMPTY))
@ -993,8 +998,7 @@ virtual_component_retry:
add_ext = true;
out:
this->path = (char *) cmalloc_abort (HEAP_STR, strlen (THIS_path) + 7);
stpcpy (this->path, THIS_path);
set_path (THIS_path);
if (add_ext)
add_ext_from_sym (sym);
if (dev.devn == FH_NETDRIVE && component)
@ -1014,7 +1018,7 @@ out:
else if (!need_directory || error)
/* nothing to do */;
else if (fileattr == INVALID_FILE_ATTRIBUTES)
strcat (path, "\\"); /* Reattach trailing dirsep in native path. */
strcat (modifiable_path (), "\\"); /* Reattach trailing dirsep in native path. */
else if (fileattr & FILE_ATTRIBUTE_DIRECTORY)
path_flags &= ~PATH_SYMLINK;
else
@ -1067,7 +1071,7 @@ out:
{
if (is_relpath)
{
mkrelpath (this->path, !!caseinsensitive);
mkrelpath (this->modifiable_path (), !!caseinsensitive);
/* Invalidate wide_path so that wide relpath can be created
in later calls to get_nt_native_path or get_wide_win32_path. */
if (wide_path)
@ -1081,8 +1085,8 @@ out:
if (this->path[n - 1] != '\\' &&
(strncmp (this->path, "\\\\.\\", 4) != 0))
{
this->path[n] = '\\';
this->path[n + 1] = '\0';
this->modifiable_path ()[n] = '\\';
this->modifiable_path ()[n + 1] = '\0';
}
}
}
@ -1112,12 +1116,12 @@ path_conv::~path_conv ()
{
if (normalized_path)
{
cfree (normalized_path);
cfree ((void *) normalized_path);
normalized_path = NULL;
}
if (path)
{
cfree (path);
cfree (modifiable_path ());
path = NULL;
}
if (wide_path)

View File

@ -11,6 +11,7 @@ details. */
#include "devices.h"
#include "mount.h"
#include "cygheap_malloc.h"
#include <sys/ioctl.h>
#include <fcntl.h>
@ -83,8 +84,6 @@ enum path_types
PATH_SOCKET = 0x40000000
};
extern "C" char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
class symlink_info;
class path_conv
@ -95,10 +94,12 @@ class path_conv
PWCHAR wide_path;
UNICODE_STRING uni_path;
void add_ext_from_sym (symlink_info&);
DWORD symlink_length;
const char *path;
public:
unsigned path_flags;
char *known_suffix;
const char *known_suffix;
const char *normalized_path;
int error;
device dev;
@ -165,39 +166,39 @@ class path_conv
path_conv (const device& in_dev)
: fileattr (INVALID_FILE_ATTRIBUTES), wide_path (NULL), path_flags (0),
known_suffix (NULL), error (0), dev (in_dev), normalized_path (NULL)
known_suffix (NULL), normalized_path (NULL), error (0), dev (in_dev)
{
path = cstrdup (in_dev.native);
}
path_conv (int, const char *src, unsigned opt = PC_SYM_FOLLOW,
const suffix_info *suffixes = NULL)
: wide_path (NULL), normalized_path (NULL), path (NULL)
: wide_path (NULL), path (NULL), normalized_path (NULL)
{
check (src, opt, suffixes);
}
path_conv (const UNICODE_STRING *src, unsigned opt = PC_SYM_FOLLOW,
const suffix_info *suffixes = NULL)
: wide_path (NULL), normalized_path (NULL), path (NULL)
: wide_path (NULL), path (NULL), normalized_path (NULL)
{
check (src, opt | PC_NULLEMPTY, suffixes);
}
path_conv (const char *src, unsigned opt = PC_SYM_FOLLOW,
const suffix_info *suffixes = NULL)
: wide_path (NULL), normalized_path (NULL), path (NULL)
: wide_path (NULL), path (NULL), normalized_path (NULL)
{
check (src, opt | PC_NULLEMPTY, suffixes);
}
path_conv ()
: fileattr (INVALID_FILE_ATTRIBUTES), wide_path (NULL), path_flags (0),
known_suffix (NULL), error (0), normalized_path (NULL), path (NULL)
: fileattr (INVALID_FILE_ATTRIBUTES), wide_path (NULL), path (NULL),
path_flags (0), known_suffix (NULL), normalized_path (NULL), error (0)
{}
~path_conv ();
inline char *get_win32 () { return path; }
inline const char *get_win32 () { return path; }
PUNICODE_STRING get_nt_native_path ();
POBJECT_ATTRIBUTES get_object_attr (OBJECT_ATTRIBUTES &attr,
SECURITY_ATTRIBUTES &sa);
@ -232,17 +233,22 @@ class path_conv
bool fs_is_cdrom () const {return fs.is_cdrom ();}
bool fs_is_mvfs () const {return fs.is_mvfs ();}
ULONG fs_serial_number () const {return fs.serial_number ();}
inline char *set_path (const char *p);
inline const char *set_path (const char *p)
{
if (path)
cfree (modifiable_path ());
char *new_path = (char *) cmalloc_abort (HEAP_STR, strlen (p) + 7);
strcpy (new_path, p);
return path = new_path;
}
void fillin (HANDLE h);
bool is_binary ();
unsigned __stdcall ndisk_links (DWORD);
char *normalized_path;
void set_normalized_path (const char *) __attribute__ ((regparm (2)));
DWORD get_symlink_length () { return symlink_length; };
private:
DWORD symlink_length;
char *path;
char *modifiable_path () {return (char *) path;}
};
/* Symlink marker */

View File

@ -61,7 +61,7 @@ child_info_spawn *chExeced;
static const char *
perhaps_suffix (const char *prog, path_conv& buf, int& err, unsigned opt)
{
char *ext;
const char *ext;
err = 0;
debug_printf ("prog '%s'", prog);
@ -87,14 +87,6 @@ perhaps_suffix (const char *prog, path_conv& buf, int& err, unsigned opt)
return ext;
}
inline char *
path_conv::set_path (const char *p)
{
if (path)
cfree (path);
return path = cstrdup (p);
}
/* Find an executable name, possibly by appending known executable
suffixes to it. The win32-translated name is placed in 'buf'.
Any found suffix is returned in known_suffix.

View File

@ -65,7 +65,7 @@ linebuf::prepend (const char *what, int len)
}
bool
linebuf::fromargv (av& newargv, char *real_path, bool cmdlenoverflow_ok)
linebuf::fromargv (av& newargv, const char *real_path, bool cmdlenoverflow_ok)
{
bool success = true;
for (int i = 0; i < newargv.argc; i++)

View File

@ -78,11 +78,11 @@ class linebuf
size_t alloced;
linebuf () : ix (0), buf (NULL), alloced (0) {}
~linebuf () {if (buf) free (buf);}
void add (const char *what, int len) __attribute__ ((regparm (3)));
void add (const char *, int) __attribute__ ((regparm (3)));
void add (const char *what) {add (what, strlen (what));}
void prepend (const char *what, int len);
void prepend (const char *, int);
void finish (bool) __attribute__ ((regparm (2)));
bool fromargv(av&, char *, bool) __attribute__ ((regparm (3)));;
bool fromargv(av&, const char *, bool) __attribute__ ((regparm (3)));;
operator char *() {return buf;}
};