[Libvir] [PATCH] NIC should define in order
by Hiroyuki Kaguchi
Currently NIC definition order is reversed.
If we set over 4-NICs for a domain by virt-install,
this causes a network communication problem.
This is because virtual mac to eth relation is lost.
This patch fixes the NIC definition order.
N.B.
If less than 3-NICs, this problem does not occur.
Sign-off-by: Hiroyuki Kaguchi <fj7025cf(a)aa.jp.fujitsu.com>
Index: xm_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xm_internal.c,v
retrieving revision 1.53
diff -u -p -r1.53 xm_internal.c
--- xm_internal.c 14 Dec 2007 15:51:42 -0000 1.53
+++ xm_internal.c 16 Jan 2008 00:43:17 -0000
@@ -2232,7 +2232,7 @@ virConfPtr xenXMParseXMLToConfig(virConn
}
vifs->type = VIR_CONF_LIST;
vifs->list = NULL;
- for (i = 0; i < obj->nodesetval->nodeNr; i++) {
+ for (i = obj->nodesetval->nodeNr - 1; i >= 0; i--) {
virConfValuePtr thisVif;
char *vif = xenXMParseXMLVif(conn, obj->nodesetval->nodeTab[i], hvm);
if (!vif)
16 years, 11 months
[Libvir] What do the docs/APIchunk*.html files do ?
by Daniel P. Berrange
Whenever we change any of the embedded API docs or add new APIs we end up
with huge diffs on the docs/APIchunk*.html files. These HTML files don't
seem to be visible anywhere on the website, nor are there even any <a href>
links to them in other pages on the website.
Can we just kill off these APIchunk* files from the doc generator in CVS
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
16 years, 11 months
[Libvir] PATCH: Add xstrtol variants for long long
by Daniel P. Berrange
Jim's xstrtol convenience function simplified the use of strtol, but only
support the 'int' variant. For the storage drivers I need a similar function
that will always be at minimum 64-bit since we may have files > 2 GB even
on 32-bit. So this adds a variant of the xstrtol functions which use a
long long / unsigned long long type
Regards,
Dan.
diff -r 83e80c558f4d src/internal.h
--- a/src/internal.h Wed Jan 16 09:28:01 2008 -0500
+++ b/src/internal.h Wed Jan 16 09:28:05 2008 -0500
@@ -304,6 +304,42 @@ xstrtol_ui(char const *s, char **end_ptr
return 0;
}
+static inline int
+xstrtol_ll(char const *s, char **end_ptr, int base, long long *result)
+{
+ long long val;
+ char *p;
+ int err;
+
+ errno = 0;
+ val = strtoll(s, &p, base);
+ err = (errno || (!end_ptr && *p) || p == s || (long long) val != val);
+ if (end_ptr)
+ *end_ptr = p;
+ if (err)
+ return -1;
+ *result = val;
+ return 0;
+}
+
+/* Just like xstrtol_i, above, but produce an "unsigned long long" value. */
+static inline int
+xstrtol_ull(char const *s, char **end_ptr, int base, unsigned long long *result)
+{
+ unsigned long long val;
+ char *p;
+ int err;
+
+ errno = 0;
+ val = strtoull(s, &p, base);
+ err = (errno || (!end_ptr && *p) || p == s || (unsigned long long) val != val);
+ if (end_ptr)
+ *end_ptr = p;
+ if (err)
+ return -1;
+ *result = val;
+ return 0;
+}
#ifdef __cplusplus
}
#endif /* __cplusplus */
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
16 years, 11 months
[Libvir] PATCH: RFC: env var to set default connection URI
by Daniel P. Berrange
Currently, if the app provides NULL as the connect URI, we always connect
to a Xen hypervisor.
virsh provides a VIR_DEFAULT_CONNECT_URI env var which can be used to
override this. virt-install/virt-manager never use NULL, and now try
to 'guess' a default URI based on whether /dev/kvm or /proc/xen exist.
Users have requested that VIR_DEFAULT_CONNECT_URI apply to other apps
besides virsh.
So this patch adds support for LIBVIRT_DEFAULT_URI env variable which will
be used if the connect URI is NULL. If that variable is not set it will
still default to Xen.
diff -r 673c98e11c78 src/libvirt.c
--- a/src/libvirt.c Wed Jan 16 09:27:56 2008 -0500
+++ b/src/libvirt.c Wed Jan 16 09:28:00 2008 -0500
@@ -516,8 +516,13 @@ do_open (const char *name,
xmlURIPtr uri;
/* Convert NULL or "" to xen:/// for back compat */
- if (!name || name[0] == '\0')
- name = "xen:///";
+ if (!name || name[0] == '\0') {
+ char *defname = getenv("LIBVIRT_DEFAULT_URI");
+ if (defname && *defname)
+ name = defname;
+ else
+ name = "xen:///";
+ }
/* Convert xen -> xen:/// for back compat */
if (!strcasecmp(name, "xen"))
Regards,
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
16 years, 11 months
[Libvir] PATCH: Fix compat for Xen 3.2.0
by Daniel P. Berrange
Xen 3.2.0 removed the sockets_per_node field from the nodeinfo data returned
by XenD. I previously add compat for this, but got it in the wrong place
so it would most likely end up in a divide-by-zero error. This patch
re-arranges it to be correct.
diff -rup libvirt-0.4.0.orig/src/xend_internal.c libvirt-0.4.0.new/src/xend_internal.c
--- libvirt-0.4.0.orig/src/xend_internal.c 2007-12-17 18:05:27.000000000 -0500
+++ libvirt-0.4.0.new/src/xend_internal.c 2008-01-18 21:13:30.000000000 -0500
@@ -1907,6 +1907,9 @@ sexpr_to_xend_node_info(struct sexpr *ro
info->mhz = sexpr_int(root, "node/cpu_mhz");
info->nodes = sexpr_int(root, "node/nr_nodes");
info->sockets = sexpr_int(root, "node/sockets_per_node");
+ info->cores = sexpr_int(root, "node/cores_per_socket");
+ info->threads = sexpr_int(root, "node/threads_per_core");
+
/* Xen 3.2.0 replaces sockets_per_node with 'nr_cpus'.
* Old Xen calculated sockets_per_node using its internal
* nr_cpus / (nodes*cores*threads), so fake it ourselves
@@ -1921,8 +1924,6 @@ sexpr_to_xend_node_info(struct sexpr *ro
if (info->sockets == 0)
info->sockets = 1;
}
- info->cores = sexpr_int(root, "node/cores_per_socket");
- info->threads = sexpr_int(root, "node/threads_per_core");
return (0);
}
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
16 years, 11 months
[Libvir] PATCH: make debug builds quiet by default
by Daniel P. Berrange
During development I like to have the --enable-debug flag enabled all the
time because its very handy at times. I don't want it spewing to stderr
all the time though, just because I turned on the compile option. So this
patch adds an env variable 'LIBVIRT_DEBUG' which controls whether it is
chatty or not. So with this patch you can use --enable-debug all the time,
and just run
LIBVIRT_DEBUG=1 ./src/virsh ....
to turn it on for a particular test, or likewise for the daemon
LIBVIRT_DEBUG=1 ./qemud/libvirtd
Dan.
libvirt.c | 64 +++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 37 insertions(+), 27 deletions(-)
diff -r c747561694fc src/libvirt.c
--- a/src/libvirt.c Tue Jan 08 23:52:20 2008 -0500
+++ b/src/libvirt.c Tue Jan 08 23:53:57 2008 -0500
@@ -59,10 +59,11 @@ static int initialized = 0;
* are printed to stderr for debugging.
*/
#ifdef ENABLE_DEBUG
+static int debugFlag = 0;
#define DEBUG(fs,...) \
- fprintf (stderr, "libvirt: %s (" fs ")\n", __func__, __VA_ARGS__)
+ do { if (debugFlag) fprintf (stderr, "libvirt: %s (" fs ")\n", __func__, __VA_ARGS__); } while (0)
#define DEBUG0 \
- fprintf (stderr, "libvirt: %s ()\n", __func__)
+ do { if (debugFlag) fprintf (stderr, "libvirt: %s ()\n", __func__); } while (0)
#else
#define DEBUG0
#define DEBUG(fs,...)
@@ -179,10 +180,20 @@ int
int
virInitialize(void)
{
- DEBUG0;
+#ifdef ENABLE_DEBUG
+ char *debugEnv;
+#endif
if (initialized)
return(0);
initialized = 1;
+
+#ifdef ENABLE_DEBUG
+ debugEnv = getenv("LIBVIRT_DEBUG");
+ if (debugEnv && *debugEnv)
+ debugFlag = 1;
+#endif
+
+ DEBUG0;
#if HAVE_WINSOCK2_H
if (winsock_init () == -1) return -1;
@@ -543,18 +554,17 @@ do_open (const char *name,
}
#ifdef ENABLE_DEBUG
- fprintf (stderr,
- "libvirt: do_open: name \"%s\" to URI components:\n"
- " scheme %s\n"
- " opaque %s\n"
- " authority %s\n"
- " server %s\n"
- " user %s\n"
- " port %d\n"
- " path %s\n",
- name,
- uri->scheme, uri->opaque, uri->authority, uri->server,
- uri->user, uri->port, uri->path);
+ DEBUG("libvirt: do_open: name \"%s\" to URI components:\n"
+ " scheme %s\n"
+ " opaque %s\n"
+ " authority %s\n"
+ " server %s\n"
+ " user %s\n"
+ " port %d\n"
+ " path %s\n",
+ name,
+ uri->scheme, uri->opaque, uri->authority, uri->server,
+ uri->user, uri->port, uri->path);
#endif
ret->name = strdup (name);
@@ -565,16 +575,16 @@ do_open (const char *name,
for (i = 0; i < virDriverTabCount; i++) {
#ifdef ENABLE_DEBUG
- fprintf (stderr, "libvirt: do_open: trying driver %d (%s) ...\n",
- i, virDriverTab[i]->name);
+ DEBUG("libvirt: do_open: trying driver %d (%s) ...\n",
+ i, virDriverTab[i]->name);
#endif
res = virDriverTab[i]->open (ret, uri, auth, flags);
#ifdef ENABLE_DEBUG
- fprintf (stderr, "libvirt: do_open: driver %d %s returned %s\n",
- i, virDriverTab[i]->name,
- res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
- (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
- (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
+ DEBUG("libvirt: do_open: driver %d %s returned %s\n",
+ i, virDriverTab[i]->name,
+ res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
+ (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
+ (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
#endif
if (res == VIR_DRV_OPEN_ERROR) goto failed;
else if (res == VIR_DRV_OPEN_SUCCESS) {
@@ -592,11 +602,11 @@ do_open (const char *name,
for (i = 0; i < virNetworkDriverTabCount; i++) {
res = virNetworkDriverTab[i]->open (ret, uri, auth, flags);
#ifdef ENABLE_DEBUG
- fprintf (stderr, "libvirt: do_open: network driver %d %s returned %s\n",
- i, virNetworkDriverTab[i]->name,
- res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
- (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
- (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
+ DEBUG("libvirt: do_open: network driver %d %s returned %s\n",
+ i, virNetworkDriverTab[i]->name,
+ res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
+ (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
+ (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
#endif
if (res == VIR_DRV_OPEN_ERROR) {
if (STREQ(virNetworkDriverTab[i]->name, "remote")) {
Regards,
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
16 years, 11 months
[Libvir] [PATCH] Update from gnulib.
by Jim Meyering
I ran ./bootstrap against a just-updated gnulib directory, so these
changes now sync into libvirt all of the changes from gnulib since
the last time:
Update from gnulib.
FYI, nearly all of these changes are also in the latest coreutils
beta/test release, so if there are problems, I should hear about
it soon.
If you'd like to see justification for a particular change,
you'll probably find it in a combination of these:
gnulib's ChangeLog file
a unit test change or addition,
a message on the bug-gnulib mailing list.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
gnulib/lib/Makefile.am | 11 +++++++
gnulib/lib/float.in.h | 2 +-
gnulib/lib/fseeko.c | 3 ++
gnulib/lib/printf-parse.c | 40 ++++++++++++++++++++++++-
gnulib/lib/stdint.in.h | 10 +++++-
gnulib/lib/stdio.in.h | 4 +-
gnulib/lib/stdlib.in.h | 25 +++++++++++++++-
gnulib/lib/string.in.h | 70 +++++++++++++++++++++++++++++++++++---------
gnulib/lib/unistd.in.h | 5 ++-
gnulib/lib/vasnprintf.h | 4 +-
gnulib/m4/alloca.m4 | 8 +----
gnulib/m4/float_h.m4 | 4 +-
gnulib/m4/gnulib-comp.m4 | 14 +++++++++
gnulib/m4/stdlib_h.m4 | 7 ++++-
gnulib/m4/string_h.m4 | 9 +++++-
gnulib/m4/unistd_h.m4 | 1 +
gnulib/tests/Makefile.am | 3 +-
gnulib/tests/test-fseeko.c | 26 +++++++++++++++-
18 files changed, 209 insertions(+), 37 deletions(-)
diff --git a/gnulib/lib/Makefile.am b/gnulib/lib/Makefile.am
index a94ed2d..e7a6edf 100644
--- a/gnulib/lib/Makefile.am
+++ b/gnulib/lib/Makefile.am
@@ -420,13 +420,18 @@ stdlib.h: stdlib.in.h
-e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
-e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
-e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
+ -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
+ -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
-e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
-e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
-e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
-e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
-e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
+ -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
+ -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
-e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
-e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
+ -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \
-e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
< $(srcdir)/stdlib.in.h; \
} > $@-t
@@ -482,9 +487,11 @@ string.h: string.in.h
-e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \
-e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \
-e 's|@''GNULIB_STRSEP''@|$(GNULIB_STRSEP)|g' \
+ -e 's|@''GNULIB_STRSTR''@|$(GNULIB_STRSTR)|g' \
-e 's|@''GNULIB_STRCASESTR''@|$(GNULIB_STRCASESTR)|g' \
-e 's|@''GNULIB_STRTOK_R''@|$(GNULIB_STRTOK_R)|g' \
-e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \
+ -e 's|@''GNULIB_STRSIGNAL''@|$(GNULIB_STRSIGNAL)|g' \
-e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
-e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
-e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \
@@ -500,6 +507,9 @@ string.h: string.in.h
-e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \
-e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \
-e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \
+ -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
+ -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
+ -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
-e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
-e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
< $(srcdir)/string.in.h; \
@@ -677,6 +687,7 @@ unistd.h: unistd.in.h
-e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
-e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
-e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
+ -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
-e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
-e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
< $(srcdir)/unistd.in.h; \
diff --git a/gnulib/lib/float.in.h b/gnulib/lib/float.in.h
index 7cf0791..1984fd7 100644
--- a/gnulib/lib/float.in.h
+++ b/gnulib/lib/float.in.h
@@ -24,7 +24,7 @@
#define _GL_FLOAT_H
/* 'long double' properties. */
-#if defined __i386__ && defined __BEOS__
+#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
/* Number of mantissa units, in base FLT_RADIX. */
# undef LDBL_MANT_DIG
# define LDBL_MANT_DIG 64
diff --git a/gnulib/lib/fseeko.c b/gnulib/lib/fseeko.c
index c66ba26..8543d42 100644
--- a/gnulib/lib/fseeko.c
+++ b/gnulib/lib/fseeko.c
@@ -111,6 +111,9 @@ rpl_fseeko (FILE *fp, off_t offset, int whence)
#if defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */
fp->_offset = pos;
fp->_flags |= __SOFF;
+ fp->_flags &= ~__SEOF;
+#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, mingw */
+ fp->_flag &= ~_IOEOF;
#endif
return 0;
}
diff --git a/gnulib/lib/printf-parse.c b/gnulib/lib/printf-parse.c
index 94c6c61..66b45a7 100644
--- a/gnulib/lib/printf-parse.c
+++ b/gnulib/lib/printf-parse.c
@@ -1,5 +1,5 @@
/* Formatted output to strings.
- Copyright (C) 1999-2000, 2002-2003, 2006-2007 Free Software Foundation, Inc.
+ Copyright (C) 1999-2000, 2002-2003, 2006-2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -392,6 +392,44 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
}
cp++;
}
+#if defined __APPLE__ && defined __MACH__
+ /* On MacOS X 10.3, PRIdMAX is defined as "qd".
+ We cannot change it to "lld" because PRIdMAX must also
+ be understood by the system's printf routines. */
+ else if (*cp == 'q')
+ {
+ if (64 / 8 > sizeof (long))
+ {
+ /* int64_t = long long */
+ flags += 16;
+ }
+ else
+ {
+ /* int64_t = long */
+ flags += 8;
+ }
+ cp++;
+ }
+#endif
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ /* On native Win32, PRIdMAX is defined as "I64d".
+ We cannot change it to "lld" because PRIdMAX must also
+ be understood by the system's printf routines. */
+ else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
+ {
+ if (64 / 8 > sizeof (long))
+ {
+ /* __int64 = long long */
+ flags += 16;
+ }
+ else
+ {
+ /* __int64 = long */
+ flags += 8;
+ }
+ cp += 3;
+ }
+#endif
else
break;
}
diff --git a/gnulib/lib/stdint.in.h b/gnulib/lib/stdint.in.h
index af31648..fbe39c5 100644
--- a/gnulib/lib/stdint.in.h
+++ b/gnulib/lib/stdint.in.h
@@ -23,6 +23,12 @@
#ifndef _GL_STDINT_H
+/* When including a system file that in turn includes <inttypes.h>,
+ use the system <inttypes.h>, not our substitute. This avoids
+ problems with (for example) VMS, whose <sys/bitypes.h> includes
+ <inttypes.h>. */
+#define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
+
/* Get those types that are already defined in other system include
files, so that we can "#define int8_t signed char" below without
worrying about a later system include file containing a "typedef
@@ -66,9 +72,7 @@
/* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
<inttypes.h> also defines intptr_t and uintptr_t. */
-# define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
# include <inttypes.h>
-# undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
#elif @HAVE_SYS_INTTYPES_H@
/* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
@@ -91,6 +95,8 @@
#endif
+#undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
+
/* Minimum and maximum values for a integer type under the usual assumption.
Return an unspecified value if BITS == 0, adding a check to pacify
picky compilers. */
diff --git a/gnulib/lib/stdio.in.h b/gnulib/lib/stdio.in.h
index b176424..d5962aa 100644
--- a/gnulib/lib/stdio.in.h
+++ b/gnulib/lib/stdio.in.h
@@ -1,6 +1,6 @@
/* A GNU-like <stdio.h>.
- Copyright (C) 2004, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2007-2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -45,7 +45,7 @@
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec) /* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
diff --git a/gnulib/lib/stdlib.in.h b/gnulib/lib/stdlib.in.h
index baebcce..bc7dc4f 100644
--- a/gnulib/lib/stdlib.in.h
+++ b/gnulib/lib/stdlib.in.h
@@ -1,6 +1,6 @@
/* A GNU-like <stdlib.h>.
- Copyright (C) 1995, 2001-2002, 2006-2007 Free Software Foundation, Inc.
+ Copyright (C) 1995, 2001-2004, 2006-2007 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -176,6 +176,29 @@ extern int putenv (char *string);
#endif
+#if @GNULIB_SETENV@
+# if !@HAVE_SETENV@
+/* Set NAME to VALUE in the environment.
+ If REPLACE is nonzero, overwrite an existing value. */
+extern int setenv (const char *name, const char *value, int replace);
+# endif
+#endif
+
+
+#if @GNULIB_UNSETENV@
+# if @HAVE_UNSETENV@
+# if @VOID_UNSETENV@
+/* On some systems, unsetenv() returns void.
+ This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */
+# define unsetenv(name) ((unsetenv)(name), 0)
+# endif
+# else
+/* Remove the variable NAME from the environment. */
+extern int unsetenv (const char *name);
+# endif
+#endif
+
+
#ifdef __cplusplus
}
#endif
diff --git a/gnulib/lib/string.in.h b/gnulib/lib/string.in.h
index a371e5c..dbbe2fd 100644
--- a/gnulib/lib/string.in.h
+++ b/gnulib/lib/string.in.h
@@ -1,6 +1,6 @@
/* A GNU-like <string.h>.
- Copyright (C) 1995-1996, 2001-2007 Free Software Foundation, Inc.
+ Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -25,6 +25,18 @@
#define _GL_STRING_H
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+# define __attribute__(Spec) /* empty */
+# endif
+/* The attribute __pure__ was added in gcc 2.96. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
+# define __pure__ /* empty */
+# endif
+#endif
+
+
/* The definition of GL_LINK_WARNING is copied here. */
@@ -35,15 +47,20 @@ extern "C" {
/* Return the first occurrence of NEEDLE in HAYSTACK. */
#if @GNULIB_MEMMEM@
-# if ! @HAVE_DECL_MEMMEM@
+# if @REPLACE_MEMMEM@
+# define memmem rpl_memmem
+# endif
+# if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@
extern void *memmem (void const *__haystack, size_t __haystack_len,
- void const *__needle, size_t __needle_len);
+ void const *__needle, size_t __needle_len)
+ __attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef memmem
# define memmem(a,al,b,bl) \
- (GL_LINK_WARNING ("memmem is unportable - " \
- "use gnulib module memmem for portability"), \
+ (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \
+ "use gnulib module memmem-simple for portability, " \
+ "and module memmem for speed" ), \
memmem (a, al, b, bl))
#endif
@@ -65,7 +82,8 @@ extern void *mempcpy (void *restrict __dest, void const *restrict __src,
/* Search backwards through a block for a byte (specified as an int). */
#if @GNULIB_MEMRCHR@
# if ! @HAVE_DECL_MEMRCHR@
-extern void *memrchr (void const *, int, size_t);
+extern void *memrchr (void const *, int, size_t)
+ __attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef memrchr
@@ -118,7 +136,8 @@ extern char *stpncpy (char *restrict __dst, char const *restrict __src,
/* Find the first occurrence of C in S or the final NUL byte. */
#if @GNULIB_STRCHRNUL@
# if ! @HAVE_STRCHRNUL@
-extern char *strchrnul (char const *__s, int __c_in);
+extern char *strchrnul (char const *__s, int __c_in)
+ __attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef strchrnul
@@ -163,7 +182,8 @@ extern char *strndup (char const *__string, size_t __n);
return MAXLEN. */
#if @GNULIB_STRNLEN@
# if ! @HAVE_DECL_STRNLEN@
-extern size_t strnlen (char const *__string, size_t __maxlen);
+extern size_t strnlen (char const *__string, size_t __maxlen)
+ __attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef strnlen
@@ -189,7 +209,8 @@ extern size_t strnlen (char const *__string, size_t __maxlen);
/* Find the first occurrence in S of any character in ACCEPT. */
#if @GNULIB_STRPBRK@
# if ! @HAVE_STRPBRK@
-extern char *strpbrk (char const *__s, char const *__accept);
+extern char *strpbrk (char const *__s, char const *__accept)
+ __attribute__ ((__pure__));
# endif
# if defined GNULIB_POSIXCHECK
/* strpbrk() assumes the second argument is a list of single-byte characters.
@@ -269,23 +290,32 @@ extern char *strsep (char **restrict __stringp, char const *restrict __delim);
strsep (s, d))
#endif
-#if defined GNULIB_POSIXCHECK
+#if @GNULIB_STRSTR@
+# if @REPLACE_STRSTR@
+# define strstr rpl_strstr
+char *strstr (const char *haystack, const char *needle)
+ __attribute__ ((__pure__));
+# endif
+#elif defined GNULIB_POSIXCHECK
/* strstr() does not work with multibyte strings if the locale encoding is
different from UTF-8:
POSIX says that it operates on "strings", and "string" in POSIX is defined
as a sequence of bytes, not of characters. */
# undef strstr
# define strstr(a,b) \
- (GL_LINK_WARNING ("strstr cannot work correctly on character strings " \
- "in most multibyte locales - " \
- "use mbsstr if you care about internationalization"), \
+ (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \
+ "work correctly on character strings in most " \
+ "multibyte locales - " \
+ "use mbsstr if you care about internationalization, " \
+ "or use strstr if you care about speed"), \
strstr (a, b))
#endif
/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
comparison. */
#if ! @HAVE_STRCASESTR@
-extern char *strcasestr (const char *haystack, const char *needle);
+extern char *strcasestr (const char *haystack, const char *needle)
+ __attribute__ ((__pure__));
#endif
#if defined GNULIB_POSIXCHECK
/* strcasestr() does not work with multibyte strings:
@@ -511,6 +541,18 @@ extern char *strerror (int);
strerror (e))
#endif
+#if @GNULIB_STRSIGNAL@
+# if ! @HAVE_DECL_STRSIGNAL@
+extern char *strsignal (int __sig);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef strsignal
+# define strsignal(a) \
+ (GL_LINK_WARNING ("strsignal is unportable - " \
+ "use gnulib module strsignal for portability"), \
+ strsignal (a))
+#endif
+
#ifdef __cplusplus
}
diff --git a/gnulib/lib/unistd.in.h b/gnulib/lib/unistd.in.h
index 4916f75..10678f4 100644
--- a/gnulib/lib/unistd.in.h
+++ b/gnulib/lib/unistd.in.h
@@ -181,7 +181,10 @@ extern int getlogin_r (char *name, size_t size);
#if @GNULIB_GETPAGESIZE@
-# if !@HAVE_GETPAGESIZE@
+# if @REPLACE_GETPAGESIZE@
+# define getpagesize rpl_getpagesize
+extern int getpagesize (void);
+# elif !@HAVE_GETPAGESIZE@
/* This is for POSIX systems. */
# if !defined getpagesize && defined _SC_PAGESIZE
# if ! (defined __VMS && __VMS_VER < 70000000)
diff --git a/gnulib/lib/vasnprintf.h b/gnulib/lib/vasnprintf.h
index 4524ce7..7f5770a 100644
--- a/gnulib/lib/vasnprintf.h
+++ b/gnulib/lib/vasnprintf.h
@@ -1,5 +1,5 @@
/* vsprintf with automatic memory allocation.
- Copyright (C) 2002-2004, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2002-2004, 2007-2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -26,7 +26,7 @@
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec) /* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
diff --git a/gnulib/m4/alloca.m4 b/gnulib/m4/alloca.m4
index eb62e0e..95f54a6 100644
--- a/gnulib/m4/alloca.m4
+++ b/gnulib/m4/alloca.m4
@@ -1,5 +1,5 @@
-# alloca.m4 serial 7
-dnl Copyright (C) 2002-2004, 2006 Free Software Foundation, Inc.
+# alloca.m4 serial 8
+dnl Copyright (C) 2002-2004, 2006, 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -39,10 +39,6 @@ AC_DEFUN([gl_FUNC_ALLOCA],
ALLOCA_H=alloca.h
fi
AC_SUBST([ALLOCA_H])
-
- AC_DEFINE(HAVE_ALLOCA_H, 1,
- [Define HAVE_ALLOCA_H for backward compatibility with older code
- that includes <alloca.h> only if HAVE_ALLOCA_H is defined.])
])
# Prerequisites of lib/alloca.c.
diff --git a/gnulib/m4/float_h.m4 b/gnulib/m4/float_h.m4
index 1b1ad10..d36e3a4 100644
--- a/gnulib/m4/float_h.m4
+++ b/gnulib/m4/float_h.m4
@@ -1,4 +1,4 @@
-# float_h.m4 serial 2
+# float_h.m4 serial 3
dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -10,7 +10,7 @@ AC_DEFUN([gl_FLOAT_H],
AC_REQUIRE([AC_CANONICAL_HOST])
FLOAT_H=
case "$host_os" in
- beos*)
+ beos* | openbsd*)
FLOAT_H=float.h
gl_CHECK_NEXT_HEADERS([float.h])
;;
diff --git a/gnulib/m4/gnulib-comp.m4 b/gnulib/m4/gnulib-comp.m4
index d92a377..1b91a1e 100644
--- a/gnulib/m4/gnulib-comp.m4
+++ b/gnulib/m4/gnulib-comp.m4
@@ -157,6 +157,13 @@ AC_DEFUN([gl_LIBOBJ], [
gl_LIBOBJS="$gl_LIBOBJS $1.$ac_objext"
])
+# m4_foreach_w is provided by autoconf-2.59c and later.
+# This definition is to accommodate developers using versions
+# of autoconf older than that.
+m4_ifndef([m4_foreach_w],
+ [m4_define([m4_foreach_w],
+ [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
+
# Like AC_REPLACE_FUNCS, except that the module name goes
# into gl_LIBOBJS instead of into LIBOBJS.
AC_DEFUN([gl_REPLACE_FUNCS], [
@@ -185,6 +192,13 @@ AC_DEFUN([gltests_LIBOBJ], [
gltests_LIBOBJS="$gltests_LIBOBJS $1.$ac_objext"
])
+# m4_foreach_w is provided by autoconf-2.59c and later.
+# This definition is to accommodate developers using versions
+# of autoconf older than that.
+m4_ifndef([m4_foreach_w],
+ [m4_define([m4_foreach_w],
+ [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
+
# Like AC_REPLACE_FUNCS, except that the module name goes
# into gltests_LIBOBJS instead of into LIBOBJS.
AC_DEFUN([gltests_REPLACE_FUNCS], [
diff --git a/gnulib/m4/stdlib_h.m4 b/gnulib/m4/stdlib_h.m4
index 278df74..fe4ce12 100644
--- a/gnulib/m4/stdlib_h.m4
+++ b/gnulib/m4/stdlib_h.m4
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 4
+# stdlib_h.m4 serial 5
dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -26,12 +26,17 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
+ GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV])
+ GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX])
HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX])
HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
+ HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
+ HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV])
REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
+ VOID_UNSETENV=0; AC_SUBST([VOID_UNSETENV])
])
diff --git a/gnulib/m4/string_h.m4 b/gnulib/m4/string_h.m4
index 8371179..69761d7 100644
--- a/gnulib/m4/string_h.m4
+++ b/gnulib/m4/string_h.m4
@@ -1,10 +1,12 @@
# Configure a GNU-like replacement for <string.h>.
-# Copyright (C) 2007 Free Software Foundation, Inc.
+# Copyright (C) 2007, 2008 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
+# serial 3
+
# Written by Paul Eggert.
AC_DEFUN([gl_HEADER_STRING_H],
@@ -41,6 +43,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN])
GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK])
GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP])
+ GNULIB_STRSTR=0; AC_SUBST([GNULIB_STRSTR])
GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR])
GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R])
GNULIB_MBSLEN=0; AC_SUBST([GNULIB_MBSLEN])
@@ -58,6 +61,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
GNULIB_MBSSEP=0; AC_SUBST([GNULIB_MBSSEP])
GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R])
GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR])
+ GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM])
HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY])
@@ -74,5 +78,8 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR])
HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R])
HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR])
+ HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL])
REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR])
+ REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM])
+ REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR])
])
diff --git a/gnulib/m4/unistd_h.m4 b/gnulib/m4/unistd_h.m4
index 91c02e7..4b8857c 100644
--- a/gnulib/m4/unistd_h.m4
+++ b/gnulib/m4/unistd_h.m4
@@ -55,6 +55,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR])
REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
+ REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE])
REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
])
diff --git a/gnulib/tests/Makefile.am b/gnulib/tests/Makefile.am
index db70ba1..4dae90d 100644
--- a/gnulib/tests/Makefile.am
+++ b/gnulib/tests/Makefile.am
@@ -34,12 +34,13 @@ AM_CPPFLAGS = \
-I../.. -I$(srcdir)/../.. \
-I../../gnulib/lib -I$(srcdir)/../../gnulib/lib
-LDADD = libtests.a $(LIBTESTS_LIBDEPS) ../../gnulib/lib/libgnu.la
+LDADD = libtests.a ../../gnulib/lib/libgnu.la libtests.a $(LIBTESTS_LIBDEPS)
libtests_a_SOURCES =
libtests_a_LIBADD = $(gltests_LIBOBJS)
libtests_a_DEPENDENCIES = $(gltests_LIBOBJS)
EXTRA_libtests_a_SOURCES =
+AM_LIBTOOLFLAGS = --preserve-dup-deps
## begin gnulib module alloca-opt-tests
diff --git a/gnulib/tests/test-fseeko.c b/gnulib/tests/test-fseeko.c
index bcafeea..25289ce 100644
--- a/gnulib/tests/test-fseeko.c
+++ b/gnulib/tests/test-fseeko.c
@@ -26,10 +26,32 @@
int
main (int argc, char **argv)
{
- /* Assume stdin is seekable iff argc > 1. */
+ /* Assume stdin is non-empty and seekable iff argc > 1. */
int expected = argc > 1 ? 0 : -1;
/* Exit with success only if fseek/fseeko agree. */
int r1 = fseeko (stdin, (off_t)0, SEEK_CUR);
int r2 = fseek (stdin, (long)0, SEEK_CUR);
- return ! (r1 == r2 && r1 == expected);
+ if (r1 != r2 || r1 != expected)
+ return 1;
+ if (argc > 1)
+ {
+ /* Test that fseek discards ungetc data. */
+ int ch = fgetc (stdin);
+ if (ch == EOF)
+ return 1;
+ if (ungetc (ch ^ 0xff, stdin) != (ch ^ 0xff))
+ return 1;
+ if (fseeko (stdin, (off_t) 0, SEEK_END))
+ return 1;
+ if (fgetc (stdin) != EOF)
+ return 1;
+ /* Test that fseek resets end-of-file marker. */
+ if (!feof (stdin))
+ return 1;
+ if (fseeko (stdin, (off_t) 0, SEEK_END))
+ return 1;
+ if (feof (stdin))
+ return 1;
+ }
+ return 0;
}
--
1.5.4.rc1.11.gd2f82
16 years, 12 months
Re: [Libvir] [PATCH] python/libvir.c (VIR_PY_NONE): New macro, to encapsulate a common two-statement sequence. Handle PyTuple_New's malloc failure. Use VIR_PY_NONE.
by Jim Meyering
Thanks for the review, Rich.
Seeing that messed-up Subject: line, I realized that
I sent a patch produced by "git-format-patch",
forgetting that the ancient version of mailman behind
this list would remove important parts of it.
For the record, here's what I really sent:
(with the "From " line escaped)
From: Jim Meyering <jim(a)meyering.net>
To: "Daniel P. Berrange" <berrange(a)redhat.com>
Cc: Libvirt <libvir-list(a)redhat.com>
Subject: Re: [Libvir] handle PyTuple_New's malloc failure
In-Reply-To: <20080117155200.GC21549(a)redhat.com> (Daniel P. Berrange's message
of "Thu, 17 Jan 2008 15:52:00 +0000")
References: <87zlv4larm.fsf(a)rho.meyering.net>
<20080117155200.GC21549(a)redhat.com>
Date: Thu, 17 Jan 2008 19:59:07 +0100
Message-ID: <87y7aojn2c.fsf(a)rho.meyering.net>
"Daniel P. Berrange" <berrange(a)redhat.com> wrote:
> On Thu, Jan 17, 2008 at 04:41:49PM +0100, Jim Meyering wrote:
>> python/libvir.c calls PyTuple_New, but doesn't handle the possibility
>> of a NULL return value. Subsequent use of the result pointer in e.g.,
>> PyTuple_SetItem, would dereference it.
>>
>> This fixes most of them, but leaves the ones in
>> virConnectCredCallbackWrapper untouched. Fixing them
>> properly is not as easy, and IMHO will require actual testing.
>>
>> In this patch, I combined each new test like this
>>
>> ((info = PyTuple_New(8)) == NULL)
>>
>> with the preceding "if (c_retval < 0)", since the bodies would be the same.
>>
>> Duplicating that 2-line body might look more readable,
>> depending on which side of the bed you get up on...
>> I can go either way.
> Might be useful to have a macro to combine the Py_INCREF and return
> (Py_None) in one convenient blob. return VIR_PY_NONE();
Good idea. That makes the patch a lot bigger, but makes the
resulting code more readable, too.
> I think it'd be nicer to keep the PyTuple_new bit separate as it is
> now, because in some APIs there can be other code between the existing
> c_retval < 0 check, and the point at which we create the Tuple.
>
> eg, the libvirt_virDomainGetSchedulerParameters method in the
> patch I'm attaching which implements a number of missing APIs
> NB, this patch is not tested yet, so not intended to be applied
Makes sense. And with VIR_PY_NONE, the duplication isn't a problem.
New patch below.
> I curious as to why we ever return(NULL) here rather than Py_None. I'm
> not sure of the python runtime / C binding contract - but returning an
> actual NULL seems odd.
Me too.
Here's the combined patch.
Considering the number of uses of VIR_PY_NONE this introduces,
I'll have to do the right thing and split it into two: one that
adds VIR_PY_NONE, and another that fixes the NULL-deref bugs.
> From 55bafd1bdaf6dde1bd019397f569d397fea366a6 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering(a)redhat.com>
> Date: Thu, 17 Jan 2008 16:40:17 +0100
> Subject: [PATCH] python/libvir.c (VIR_PY_NONE): New macro, to encapsulate a common
two-statement sequence.
Handle PyTuple_New's malloc failure.
Use VIR_PY_NONE.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
python/libvir.c | 177 +++++++++++++++++++++----------------------------------
1 files changed, 68 insertions(+), 109 deletions(-)
diff --git a/python/libvir.c b/python/libvir.c
index 3b41dc1..dbf148e 100644
--- a/python/libvir.c
+++ b/python/libvir.c
@@ -31,6 +31,11 @@ PyObject * libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject
PyObject * libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
PyObject * libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
+/* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
+ is so common that we encapsulate it here. Now, each use is simply
+ return VIR_PY_NONE; */
+#define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
+
/************************************************************************
* *
* Statistics *
@@ -48,17 +53,16 @@ libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainBlockStats",
&pyobj_domain,&path))
- return(NULL);
+ return(NULL);
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
c_retval = virDomainBlockStats(domain, path, &stats, sizeof(stats));
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
- /* convert to a Python tupple of long objects */
- info = PyTuple_New(5);
+ /* convert to a Python tuple of long objects */
+ if ((info = PyTuple_New(5)) == NULL)
+ return VIR_PY_NONE;
PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rd_req));
PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rd_bytes));
PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.wr_req));
@@ -82,13 +86,12 @@ libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
c_retval = virDomainInterfaceStats(domain, path, &stats, sizeof(stats));
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
- /* convert to a Python tupple of long objects */
- info = PyTuple_New(8);
+ /* convert to a Python tuple of long objects */
+ if ((info = PyTuple_New(8)) == NULL)
+ return VIR_PY_NONE;
PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rx_bytes));
PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rx_packets));
PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.rx_errs));
@@ -114,12 +117,11 @@ libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUT
virError err;
PyObject *info;
- if (virCopyLastError(&err) <= 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (virCopyLastError(&err) <= 0)
+ return VIR_PY_NONE;
- info = PyTuple_New(9);
+ if ((info = PyTuple_New(9)) == NULL)
+ return VIR_PY_NONE;
PyTuple_SetItem(info, 0, PyInt_FromLong((long) err.code));
PyTuple_SetItem(info, 1, PyInt_FromLong((long) err.domain));
PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err.message));
@@ -145,12 +147,11 @@ libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
return(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
- if (virConnCopyLastError(conn, &err) <= 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (virConnCopyLastError(conn, &err) <= 0)
+ return VIR_PY_NONE;
- info = PyTuple_New(9);
+ if ((info = PyTuple_New(9)) == NULL)
+ return VIR_PY_NONE;
PyTuple_SetItem(info, 0, PyInt_FromLong((long) err.code));
PyTuple_SetItem(info, 1, PyInt_FromLong((long) err.domain));
PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err.message));
@@ -348,10 +349,8 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if (auth.ncredtype) {
int i;
auth.credtype = malloc(sizeof(*auth.credtype) * auth.ncredtype);
- if (auth.credtype == NULL) {
- Py_INCREF(Py_None);
- return (Py_None);
- }
+ if (auth.credtype == NULL)
+ return VIR_PY_NONE;
for (i = 0 ; i < auth.ncredtype ; i++) {
PyObject *val;
val = PyList_GetItem(pycredtype, i);
@@ -395,10 +394,8 @@ libvirt_virGetVersion (PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval == -1) {
- Py_INCREF(Py_None);
- return (Py_None);
- }
+ if (c_retval == -1)
+ return VIR_PY_NONE;
if (type == NULL)
return PyInt_FromLong (libVer);
@@ -458,10 +455,8 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virConnectListDomains(conn, &ids[0], 500);
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
py_retval = PyList_New(c_retval);
for (i = 0;i < c_retval;i++) {
PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i]));
@@ -484,22 +479,17 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
c_retval = virConnectNumOfDefinedDomains(conn);
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return (Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
if (c_retval) {
names = malloc(sizeof(*names) * c_retval);
- if (!names) {
- Py_INCREF(Py_None);
- return (Py_None);
- }
+ if (!names)
+ return VIR_PY_NONE;
c_retval = virConnectListDefinedDomains(conn, names, c_retval);
if (c_retval < 0) {
free(names);
- Py_INCREF(Py_None);
- return(Py_None);
+ return VIR_PY_NONE;
}
}
py_retval = PyList_New(c_retval);
@@ -530,10 +520,8 @@ libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virDomainGetInfo(domain, &info);
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
py_retval = PyList_New(5);
PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
PyList_SetItem(py_retval, 1, libvirt_ulongWrap(info.maxMem));
@@ -559,10 +547,8 @@ libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virNodeGetInfo(conn, &info);
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
py_retval = PyList_New(8);
PyList_SetItem(py_retval, 0, libvirt_constcharPtrWrap(&info.model[0]));
PyList_SetItem(py_retval, 1, libvirt_longWrap((long) info.memory >> 10));
@@ -587,18 +573,14 @@ libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(NULL);
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
- if (domain == NULL) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (domain == NULL)
+ return VIR_PY_NONE;
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virDomainGetUUID(domain, &uuid[0]);
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
return(py_retval);
@@ -617,10 +599,8 @@ libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
- if ((uuid == NULL) || (len != VIR_UUID_BUFLEN)) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
+ return VIR_PY_NONE;
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virDomainLookupByUUID(conn, uuid);
@@ -664,22 +644,17 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
c_retval = virConnectNumOfNetworks(conn);
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return (Py_None);
- }
-
+ if (c_retval < 0)
+ return VIR_PY_NONE;
+
if (c_retval) {
names = malloc(sizeof(*names) * c_retval);
- if (!names) {
- Py_INCREF(Py_None);
- return (Py_None);
- }
+ if (!names)
+ return VIR_PY_NONE;
c_retval = virConnectListNetworks(conn, names, c_retval);
if (c_retval < 0) {
free(names);
- Py_INCREF(Py_None);
- return(Py_None);
+ return VIR_PY_NONE;
}
}
py_retval = PyList_New(c_retval);
@@ -711,22 +686,17 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
c_retval = virConnectNumOfDefinedNetworks(conn);
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return (Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
if (c_retval) {
names = malloc(sizeof(*names) * c_retval);
- if (!names) {
- Py_INCREF(Py_None);
- return (Py_None);
- }
+ if (!names)
+ return VIR_PY_NONE;
c_retval = virConnectListDefinedNetworks(conn, names, c_retval);
if (c_retval < 0) {
free(names);
- Py_INCREF(Py_None);
- return(Py_None);
+ return VIR_PY_NONE;
}
}
py_retval = PyList_New(c_retval);
@@ -755,18 +725,14 @@ libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(NULL);
domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain);
- if (domain == NULL) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (domain == NULL)
+ return VIR_PY_NONE;
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virNetworkGetUUID(domain, &uuid[0]);
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
return(py_retval);
@@ -785,10 +751,8 @@ libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
return(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
- if ((uuid == NULL) || (len != VIR_UUID_BUFLEN)) {
- Py_INCREF(Py_None);
- return(Py_None);
- }
+ if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
+ return VIR_PY_NONE;
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virNetworkLookupByUUID(conn, uuid);
@@ -814,10 +778,8 @@ libvirt_virDomainGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
c_retval = virDomainGetAutostart(domain, &autostart);
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return Py_None;
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
py_retval = libvirt_intWrap(autostart);
return(py_retval);
}
@@ -839,10 +801,8 @@ libvirt_virNetworkGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
c_retval = virNetworkGetAutostart(network, &autostart);
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval < 0) {
- Py_INCREF(Py_None);
- return Py_None;
- }
+ if (c_retval < 0)
+ return VIR_PY_NONE;
py_retval = libvirt_intWrap(autostart);
return(py_retval);
}
@@ -873,10 +833,9 @@ PyObject * libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED,
LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0) {
- free(freeMems);
+ free(freeMems);
error:
- Py_INCREF(Py_None);
- return Py_None;
+ return VIR_PY_NONE;
}
py_retval = PyList_New(c_retval);
for (i = 0;i < c_retval;i++) {
--
1.5.4.rc3.14.g44397
16 years, 12 months
[Libvir] handle PyTuple_New's malloc failure
by Jim Meyering
python/libvir.c calls PyTuple_New, but doesn't handle the possibility
of a NULL return value. Subsequent use of the result pointer in e.g.,
PyTuple_SetItem, would dereference it.
This fixes most of them, but leaves the ones in
virConnectCredCallbackWrapper untouched. Fixing them
properly is not as easy, and IMHO will require actual testing.
In this patch, I combined each new test like this
((info = PyTuple_New(8)) == NULL)
with the preceding "if (c_retval < 0)", since the bodies would be the same.
Duplicating that 2-line body might look more readable,
depending on which side of the bed you get up on...
I can go either way.
Subject: [PATCH] python/libvir.c: Handle PyTuple_New's malloc failure.
---
python/libvir.c | 27 ++++++++++++---------------
1 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/python/libvir.c b/python/libvir.c
index 3b41dc1..13b809f 100644
--- a/python/libvir.c
+++ b/python/libvir.c
@@ -48,17 +48,16 @@ libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainBlockStats",
&pyobj_domain,&path))
- return(NULL);
+ return(NULL);
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
c_retval = virDomainBlockStats(domain, path, &stats, sizeof(stats));
- if (c_retval < 0) {
+ if (c_retval < 0 || (info = PyTuple_New(5)) == NULL) {
Py_INCREF(Py_None);
- return(Py_None);
+ return(Py_None);
}
- /* convert to a Python tupple of long objects */
- info = PyTuple_New(5);
+ /* convert to a Python tuple of long objects */
PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rd_req));
PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rd_bytes));
PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.wr_req));
@@ -82,13 +81,12 @@ libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
c_retval = virDomainInterfaceStats(domain, path, &stats, sizeof(stats));
- if (c_retval < 0) {
+ if (c_retval < 0 || (info = PyTuple_New(8)) == NULL) {
Py_INCREF(Py_None);
- return(Py_None);
+ return(Py_None);
}
- /* convert to a Python tupple of long objects */
- info = PyTuple_New(8);
+ /* convert to a Python tuple of long objects */
PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rx_bytes));
PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rx_packets));
PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.rx_errs));
@@ -114,12 +112,11 @@ libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUT
virError err;
PyObject *info;
- if (virCopyLastError(&err) <= 0) {
+ if (virCopyLastError(&err) <= 0 || (info = PyTuple_New(9)) == NULL) {
Py_INCREF(Py_None);
- return(Py_None);
+ return(Py_None);
}
- info = PyTuple_New(9);
PyTuple_SetItem(info, 0, PyInt_FromLong((long) err.code));
PyTuple_SetItem(info, 1, PyInt_FromLong((long) err.domain));
PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err.message));
@@ -145,12 +142,12 @@ libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
return(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
- if (virConnCopyLastError(conn, &err) <= 0) {
+ if (virConnCopyLastError(conn, &err) <= 0
+ || (info = PyTuple_New(9)) == NULL) {
Py_INCREF(Py_None);
- return(Py_None);
+ return(Py_None);
}
- info = PyTuple_New(9);
PyTuple_SetItem(info, 0, PyInt_FromLong((long) err.code));
PyTuple_SetItem(info, 1, PyInt_FromLong((long) err.domain));
PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err.message));
--
1.5.4.rc3.14.g44397
16 years, 12 months