+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.
return prebrk;
}
-extern "C" void __stdcall
+void __stdcall
cygheap_init ()
{
cygheap_protect.init ("cygheap_protect");
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)))
}
};
-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")));
-}
--- /dev/null
+/* 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*/
{
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)
{
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);
}
}
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))
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)
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
{
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)
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';
}
}
}
{
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)
#include "devices.h"
#include "mount.h"
+#include "cygheap_malloc.h"
#include <sys/ioctl.h>
#include <fcntl.h>
PATH_SOCKET = 0x40000000
};
-extern "C" char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
-
class symlink_info;
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;
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);
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 */
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);
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.
}
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++)
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;}
};