|
From: <sv...@va...> - 2005-06-21 23:45:02
|
Author: njn
Date: 2005-06-22 00:44:58 +0100 (Wed, 22 Jun 2005)
New Revision: 3995
Log:
Remove VG_(getcwd_alloc)(), which can be done otherwise pretty easily.
This halves m_libcfile's dependence on m_mallocfree.
Modified:
trunk/cachegrind/cg_main.c
trunk/coregrind/m_libcfile.c
trunk/include/pub_tool_libcfile.h
trunk/massif/ms_main.c
Modified: trunk/cachegrind/cg_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/cachegrind/cg_main.c 2005-06-21 23:09:45 UTC (rev 3994)
+++ trunk/cachegrind/cg_main.c 2005-06-21 23:44:58 UTC (rev 3995)
@@ -1146,10 +1146,10 @@
VG_(register_profile_event)(VgpCacheResults, "cache-results");
}
=20
+static Char base_dir[VKI_PATH_MAX];
+
static void cg_pre_clo_init(void)
{
- Char* base_dir =3D NULL;
-
VG_(details_name) ("Cachegrind");
VG_(details_version) (NULL);
VG_(details_description) ("an I1/D1/L2 cache profiler");
@@ -1168,13 +1168,12 @@
cg_print_debug_usage);
=20
/* Get working directory */
- tl_assert( VG_(getcwd_alloc)(&base_dir) );
+ tl_assert( VG_(getcwd)(base_dir, VKI_PATH_MAX) );
=20
/* Block is big enough for dir name + cachegrind.out.<pid> */
cachegrind_out_file =3D VG_(malloc)((VG_(strlen)(base_dir) + 32)*size=
of(Char));
VG_(sprintf)(cachegrind_out_file, "%s/cachegrind.out.%d",
base_dir, VG_(getpid)());
- VG_(free)(base_dir);
=20
instr_info_table =3D VG_(HT_construct)();
}
Modified: trunk/coregrind/m_libcfile.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcfile.c 2005-06-21 23:09:45 UTC (rev 3994)
+++ trunk/coregrind/m_libcfile.c 2005-06-21 23:44:58 UTC (rev 3995)
@@ -174,33 +174,14 @@
=20
/* Nb: we do not allow the Linux extension which malloc()s memory for th=
e
buffer if buf=3D=3DNULL, because we don't want Linux calling malloc()=
*/
-Char* VG_(getcwd) ( Char* buf, SizeT size )
+Bool VG_(getcwd) ( Char* buf, SizeT size )
{
SysRes res;
vg_assert(buf !=3D NULL);
res =3D VG_(do_syscall2)(__NR_getcwd, (UWord)buf, size);
- return res.isError ? ((Char*)NULL) : (Char*)res.val;
+ return res.isError ? False : True;
}
=20
-/* Alternative version that does allocate the memory. Easier to use. */
-Bool VG_(getcwd_alloc) ( Char** out )
-{
- SizeT size =3D 4;
-
- *out =3D NULL;
- while (True) {
- *out =3D VG_(malloc)(size);
- if (NULL =3D=3D VG_(getcwd)(*out, size)) {
- VG_(free)(*out);
- if (size > 65535)
- return False;
- size *=3D 2;
- } else {
- return True;
- }
- }
-}
-
Int VG_(readlink) (Char* path, Char* buf, UInt bufsiz)
{
SysRes res;
Modified: trunk/include/pub_tool_libcfile.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/pub_tool_libcfile.h 2005-06-21 23:09:45 UTC (rev 3994)
+++ trunk/include/pub_tool_libcfile.h 2005-06-21 23:44:58 UTC (rev 3995)
@@ -48,7 +48,8 @@
extern Int VG_(rename) ( Char* old_name, Char* new_name );
extern Int VG_(unlink) ( Char* file_name );
=20
-extern Char* VG_(getcwd) ( Char* buf, SizeT size );
+// Returns False on failure (eg. if the buffer isn't big enough).
+extern Bool VG_(getcwd) ( Char* buf, SizeT size );
=20
/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
Modified: trunk/massif/ms_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/massif/ms_main.c 2005-06-21 23:09:45 UTC (rev 3994)
+++ trunk/massif/ms_main.c 2005-06-21 23:44:58 UTC (rev 3995)
@@ -265,7 +265,7 @@
static UInt n_heap_blocks =3D 0;
=20
// Current directory at startup.
-static Char* base_dir;
+static Char base_dir[VKI_PATH_MAX];
=20
#define MAX_ALLOC_FNS 32 // includes the builtin ones
=20
@@ -1835,7 +1835,7 @@
// Dummy node at top of the context structure.
alloc_xpt =3D new_XPt(0, NULL, /*is_bottom*/False);
=20
- tl_assert( VG_(getcwd_alloc)(&base_dir) );
+ tl_assert( VG_(getcwd)(base_dir, VKI_PATH_MAX) );
}
=20
VG_DETERMINE_INTERFACE_VERSION(ms_pre_clo_init, 0)
|