This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [PATCH] Improve strncpy performance further


> Well, bcopy and bzero are both used in several non-test sources in GLIBC, 
> but one is always defined as __bzero, and the other as bcopy.

There are no uses of bcopy outside of tests, and portability macros in code
(possibly, or once) shared with gnulib.  There is a bcopy macro in
locale/programs/simple-hash.c, but it's not used anywhere.  I've removed
that in the patch below.

There are three uses of bzero outside of tests.  I've changed those to
memset in the patch below.  In my build (x86_64-linux-gnu, GCC 4.8.3) this
did not change the compiled code at all--so they were already being reduced
to memset or inlined directly by the compiler.

There are also two uses of bcmp outside of tests (both in old resolver
code), which is a similar case (but even easier and less useful, since it
is nothing but exactly an alias for memcmp).  I've changed those to memcmp
in the patch below.

There is a handful of uses of __bzero, all in sunrpc/ (none even in tests).
We're avoiding touching sunrpc/ when it's not thoroughly necessary, so
we'll leave those alone.

> It's unclear to me what the exact namespace rules are (or whether there is 
> even a concise description of them somewhere), however it is obvious that 
> this is not consistent. Note any rule that relies on whether a function is
> called or not from within the same library is risky unless you have 
> automated checks to catch that.

The rules per se can be described concisely, but they incorporate by
reference the set of each symbols in each standard and the dependency graph
of standards that are specified as supersets of others.  However, the
linknamespace tests should already be prepared to catch any concrete
violations.


Here's what I've just committed.  As I mentioned above, it caused no
changes to the compiled code on x86_64-linux-gnu with gcc-4.8.3, except for
the expected s/bcmp/memcmp/ changes that are trivially provably harmless.


Thanks,
Roland


2015-01-13  Roland McGrath  <roland@hack.frob.com>

	* login/logout.c (logout): Use memset rather than bzero.
	* nis/nss_compat/compat-pwd.c (getpwent_next_file): Likewise.
	* nis/nss_compat/compat-spwd.c (getspent_next_file): Likewise.
	* resolv/gethnamaddr.c (gethostbyaddr): Use memcmp rather than bcmp.
	(_gethtbyaddr): Likewise.
	* locale/programs/simple-hash.c (bcopy): Macro removed.

--- a/locale/programs/simple-hash.c
+++ b/locale/programs/simple-hash.c
@@ -42,10 +42,6 @@
 # define BITSPERBYTE 8
 #endif
 
-#ifndef bcopy
-# define bcopy(s, d, n)	memcpy ((d), (s), (n))
-#endif
-
 #define hashval_t uint32_t
 #include "hashval.h"
 
--- a/login/logout.c
+++ b/login/logout.c
@@ -45,9 +45,9 @@ logout (const char *line)
   if (getutline_r (&tmp, &utbuf, &ut) >= 0)
     {
       /* Clear information about who & from where.  */
-      bzero (ut->ut_name, sizeof ut->ut_name);
+      memset (ut->ut_name, '\0', sizeof ut->ut_name);
 #if _HAVE_UT_HOST - 0
-      bzero (ut->ut_host, sizeof ut->ut_host);
+      memset (ut->ut_host, '\0', sizeof ut->ut_host);
 #endif
 #if _HAVE_UT_TV - 0
       struct timeval tv;
--- a/nis/nss_compat/compat-pwd.c
+++ b/nis/nss_compat/compat-pwd.c
@@ -578,7 +578,7 @@ getpwent_next_file (struct passwd *result, ent_t *ent,
 	  char *user, *host, *domain;
 	  struct __netgrent netgrdata;
 
-	  bzero (&netgrdata, sizeof (struct __netgrent));
+	  memset (&netgrdata, 0, sizeof (struct __netgrent));
 	  __internal_setnetgrent (&result->pw_name[2], &netgrdata);
 	  while (__internal_getnetgrent_r (&host, &user, &domain, &netgrdata,
 					   buf2, sizeof (buf2), errnop))
--- a/nis/nss_compat/compat-spwd.c
+++ b/nis/nss_compat/compat-spwd.c
@@ -532,7 +532,7 @@ getspent_next_file (struct spwd *result, ent_t *ent,
 	  char *user, *host, *domain;
 	  struct __netgrent netgrdata;
 
-	  bzero (&netgrdata, sizeof (struct __netgrent));
+	  memset (&netgrdata, 0, sizeof (struct __netgrent));
 	  __internal_setnetgrent (&result->sp_namp[2], &netgrdata);
 	  while (__internal_getnetgrent_r (&host, &user, &domain,
 					   &netgrdata, buf2, sizeof (buf2),
--- a/resolv/gethnamaddr.c
+++ b/resolv/gethnamaddr.c
@@ -672,8 +672,8 @@ gethostbyaddr(addr, len, af)
 		return (NULL);
 	}
 	if (af == AF_INET6 && len == IN6ADDRSZ &&
-	    (!bcmp(uaddr, mapped, sizeof mapped) ||
-	     !bcmp(uaddr, tunnelled, sizeof tunnelled))) {
+	    (!memcmp(uaddr, mapped, sizeof mapped) ||
+	     !memcmp(uaddr, tunnelled, sizeof tunnelled))) {
 		/* Unmap. */
 		addr += sizeof mapped;
 		uaddr += sizeof mapped;
@@ -922,7 +922,7 @@ _gethtbyaddr(addr, len, af)
 
 	_sethtent(0);
 	while ((p = _gethtent()))
-		if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len))
+		if (p->h_addrtype == af && !memcmp(p->h_addr, addr, len))
 			break;
 	_endhtent();
 	return (p);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]