xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] tools/libxl: Correct libxl__zalloc() to take an unsigned number of bytes
@ 2014-03-27 17:41 Andrew Cooper
  2014-03-27 17:41 ` [PATCH 2/2] tools/libxl: Introduce libxl__malloc() Andrew Cooper
  2014-04-01 10:51 ` [PATCH 1/2] tools/libxl: Correct libxl__zalloc() to take an unsigned number of bytes Ian Campbell
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Cooper @ 2014-03-27 17:41 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson, Ian Campbell

Convert 'int bytes' to 'size_t size' to mirror malloc(3) which it is
imitating, and calloc(3) which it is actually using.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 tools/libxl/libxl_internal.c |    6 +++---
 tools/libxl/libxl_internal.h |    4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index 1db48b6..6c105de 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -78,10 +78,10 @@ void libxl__free_all(libxl__gc *gc)
     gc->alloc_maxsize = 0;
 }
 
-void *libxl__zalloc(libxl__gc *gc, int bytes)
+void *libxl__zalloc(libxl__gc *gc, size_t size)
 {
-    void *ptr = calloc(bytes, 1);
-    if (!ptr) libxl__alloc_failed(CTX, __func__, bytes, 1);
+    void *ptr = calloc(size, 1);
+    if (!ptr) libxl__alloc_failed(CTX, __func__, size, 1);
 
     libxl__ptr_add(gc, ptr);
     return ptr;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index b3a200d..be325bb 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -504,8 +504,8 @@ static inline int libxl__gc_is_real(const libxl__gc *gc)
 _hidden void libxl__ptr_add(libxl__gc *gc_opt, void *ptr /* may be NULL */) NN1;
 /* if this is the outermost libxl callframe then free all pointers in @gc */
 _hidden void libxl__free_all(libxl__gc *gc);
-/* allocate and zero @bytes. (similar to a gc'd malloc(3)+memzero()) */
-_hidden void *libxl__zalloc(libxl__gc *gc_opt, int bytes) NN1;
+/* allocate and zero @size. (similar to a gc'd malloc(3)+memzero()) */
+_hidden void *libxl__zalloc(libxl__gc *gc_opt, size_t size) NN1;
 /* allocate and zero memory for an array of @nmemb members of @size each.
  * (similar to a gc'd calloc(3)). */
 _hidden void *libxl__calloc(libxl__gc *gc_opt, size_t nmemb, size_t size) NN1;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] tools/libxl: Introduce libxl__malloc()
  2014-03-27 17:41 [PATCH 1/2] tools/libxl: Correct libxl__zalloc() to take an unsigned number of bytes Andrew Cooper
@ 2014-03-27 17:41 ` Andrew Cooper
  2014-04-01 10:51 ` [PATCH 1/2] tools/libxl: Correct libxl__zalloc() to take an unsigned number of bytes Ian Campbell
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2014-03-27 17:41 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson, Ian Campbell

For those large allocations which are going to be filled immediately, where
redundantly clearing the memory would just be a waste of time.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 tools/libxl/libxl_internal.c |    9 +++++++++
 tools/libxl/libxl_internal.h |    2 ++
 2 files changed, 11 insertions(+)

diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index 6c105de..6c94d3e 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -78,6 +78,15 @@ void libxl__free_all(libxl__gc *gc)
     gc->alloc_maxsize = 0;
 }
 
+void *libxl__malloc(libxl__gc *gc, size_t size)
+{
+    void *ptr = malloc(size);
+    if (!ptr) libxl__alloc_failed(CTX, __func__, size, 1);
+
+    libxl__ptr_add(gc, ptr);
+    return ptr;
+}
+
 void *libxl__zalloc(libxl__gc *gc, size_t size)
 {
     void *ptr = calloc(size, 1);
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index be325bb..c2b73c4 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -504,6 +504,8 @@ static inline int libxl__gc_is_real(const libxl__gc *gc)
 _hidden void libxl__ptr_add(libxl__gc *gc_opt, void *ptr /* may be NULL */) NN1;
 /* if this is the outermost libxl callframe then free all pointers in @gc */
 _hidden void libxl__free_all(libxl__gc *gc);
+/* allocate @size bytes. (a gc'd malloc(3)) */
+_hidden void *libxl__malloc(libxl__gc *gc_opt, size_t size) NN1;
 /* allocate and zero @size. (similar to a gc'd malloc(3)+memzero()) */
 _hidden void *libxl__zalloc(libxl__gc *gc_opt, size_t size) NN1;
 /* allocate and zero memory for an array of @nmemb members of @size each.
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] tools/libxl: Correct libxl__zalloc() to take an unsigned number of bytes
  2014-03-27 17:41 [PATCH 1/2] tools/libxl: Correct libxl__zalloc() to take an unsigned number of bytes Andrew Cooper
  2014-03-27 17:41 ` [PATCH 2/2] tools/libxl: Introduce libxl__malloc() Andrew Cooper
@ 2014-04-01 10:51 ` Ian Campbell
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Campbell @ 2014-04-01 10:51 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Ian Jackson, Xen-devel

On Thu, 2014-03-27 at 17:41 +0000, Andrew Cooper wrote:
> Convert 'int bytes' to 'size_t size' to mirror malloc(3) which it is
> imitating, and calloc(3) which it is actually using.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>

Acked + applied both patches, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-01 10:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-27 17:41 [PATCH 1/2] tools/libxl: Correct libxl__zalloc() to take an unsigned number of bytes Andrew Cooper
2014-03-27 17:41 ` [PATCH 2/2] tools/libxl: Introduce libxl__malloc() Andrew Cooper
2014-04-01 10:51 ` [PATCH 1/2] tools/libxl: Correct libxl__zalloc() to take an unsigned number of bytes Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).