xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
To: xen-devel <xen-devel@lists.xensource.com>
Cc: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Subject: [PATCH 4/5] use new gc functions to deep copy structure and only free once the gc.
Date: Tue, 10 Aug 2010 12:46:52 +0100	[thread overview]
Message-ID: <1281440813-22610-5-git-send-email-vincent.hanquez@eu.citrix.com> (raw)
In-Reply-To: <1281440813-22610-1-git-send-email-vincent.hanquez@eu.citrix.com>

[-- Attachment #1: Type: text/plain, Size: 191 bytes --]


Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
---
 tools/ocaml/libs/xl/xl_stubs.c |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-use-new-gc-functions-to-deep-copy-structure-and-only.patch --]
[-- Type: text/x-patch; name="0004-use-new-gc-functions-to-deep-copy-structure-and-only.patch", Size: 1246 bytes --]

diff --git a/tools/ocaml/libs/xl/xl_stubs.c b/tools/ocaml/libs/xl/xl_stubs.c
index 7ba9272..8134e8e 100644
--- a/tools/ocaml/libs/xl/xl_stubs.c
+++ b/tools/ocaml/libs/xl/xl_stubs.c
@@ -63,18 +63,38 @@ void log_destroy(struct xentoollog_logger *logger)
 		failwith_xl("cannot init context", &lg);
 
 #define FREE_CTX()  \
+	gc_free(&gc); \
 	libxl_ctx_free(&ctx)
 
 static void * gc_calloc(caml_gc *gc, size_t nmemb, size_t size)
 {
 	void *ptr;
 	ptr = calloc(nmemb, size);
+	if (!ptr)
+		caml_raise_out_of_memory();
+	gc->ptrs[gc->offset++] = ptr;
 	return ptr;
 }
 
 static char * dup_String_val(caml_gc *gc, value s)
 {
-	return String_val(s);
+	int len;
+	char *c;
+	len = caml_string_length(s);
+	c = calloc(len + 1, sizeof(char));
+	if (!c)
+		caml_raise_out_of_memory();
+	gc->ptrs[gc->offset++] = c;
+	memcpy(c, String_val(s), len);
+	return c;
+}
+
+static void gc_free(caml_gc *gc)
+{
+	int i;
+	for (i = 0; i < gc->offset; i++) {
+		free(gc->ptrs[i]);
+	}
 }
 
 void failwith_xl(char *fname, struct caml_logger *lg)
@@ -349,9 +369,6 @@ value stub_xl_domain_make(value info)
 
 	FREE_CTX();
 
-	free(c_info.xsdata);
-	free(c_info.platformdata);
-
 	CAMLreturn(Val_int(domid));
 }
 

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

  parent reply	other threads:[~2010-08-10 11:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-10 11:46 [PATCH 0/5] xl ocaml: drop lock in the bindings Vincent Hanquez
2010-08-10 11:46 ` [PATCH 1/5] Put a valid version number in the META files Vincent Hanquez
2010-08-10 11:46 ` [PATCH 2/5] Wrap init context procedure into a macro. Introduce a gc structure Vincent Hanquez
2010-08-10 11:46 ` [PATCH 3/5] use new functions to get elements out of ocaml values Vincent Hanquez
2010-08-10 11:46 ` Vincent Hanquez [this message]
2010-08-10 11:46 ` [PATCH 5/5] always drop the caml lock during any xl operations Vincent Hanquez
2010-08-10 14:29 ` [PATCH 0/5] xl ocaml: drop lock in the bindings Stefano Stabellini
2010-08-10 15:14   ` Vincent Hanquez
2010-08-10 15:36     ` Stefano Stabellini
  -- strict thread matches above, loose matches on Subject: below --
2010-08-10 15:12 Vincent Hanquez
2010-08-10 15:12 ` [PATCH 4/5] use new gc functions to deep copy structure and only free once the gc Vincent Hanquez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1281440813-22610-5-git-send-email-vincent.hanquez@eu.citrix.com \
    --to=vincent.hanquez@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).