The following commit has been merged in the master branch:
commit a419f4b30d4c6872b38fe068a38f75db28a02de1
Author: Nicolas Dandrimont <nicolas.dandrim...@crans.org>
Date:   Fri May 27 01:20:16 2011 +0200

    Fix FTBFS on hurd-i386

diff --git a/debian/changelog b/debian/changelog
index 9d8f71f..8d7b410 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+lwt (2.3.0-2) unstable; urgency=low
+
+  * Fix FTBFS on Hurd due to use of PATH_MAX and HOSTNAME_MAX
+
+ -- Nicolas Dandrimont <nicolas.dandrim...@crans.org>  Fri, 27 May 2011 
01:16:15 +0200
+
 lwt (2.3.0-1) unstable; urgency=low
 
   [ St├ęphane Glondu ]
diff --git a/debian/patches/0002-Fix-FTBFS-on-hurd.patch 
b/debian/patches/0002-Fix-FTBFS-on-hurd.patch
new file mode 100644
index 0000000..84044a0
--- /dev/null
+++ b/debian/patches/0002-Fix-FTBFS-on-hurd.patch
@@ -0,0 +1,137 @@
+From: Nicolas Dandrimont <nicolas.dandrim...@crans.org>
+Date: Fri, 27 May 2011 01:21:19 +0200
+Subject: Fix FTBFS on hurd
+
+This patch introduces a variable-size buffer for readlink and gethostname
+---
+ src/unix/lwt_unix_unix.c |   61 +++++++++++++++++++++++++++++++++++++++-------
+ 1 files changed, 52 insertions(+), 9 deletions(-)
+
+diff --git a/src/unix/lwt_unix_unix.c b/src/unix/lwt_unix_unix.c
+index 85459ec..543dd0c 100644
+--- a/src/unix/lwt_unix_unix.c
++++ b/src/unix/lwt_unix_unix.c
+@@ -2328,8 +2328,8 @@ CAMLprim value lwt_unix_symlink_free(value val_job)
+ struct job_readlink {
+   struct lwt_unix_job job;
+   char *name;
+-  char buffer[MAXPATHLEN];
+-  size_t result;
++  char *buffer;
++  ssize_t result;
+   int error_code;
+ };
+ 
+@@ -2337,8 +2337,32 @@ struct job_readlink {
+ 
+ static void worker_readlink(struct job_readlink *job)
+ {
+-  job->result = readlink(job->name, job->buffer, MAXPATHLEN);
+-  job->error_code = errno;
++
++  ssize_t buffer_size = 1024;
++  ssize_t link_length;
++
++  for (;;) {
++
++    job->buffer = lwt_unix_malloc(buffer_size);
++
++    link_length = readlink(job->name, job->buffer, buffer_size);
++
++    if (link_length < buffer_size) {
++      if (link_length >= 0) {
++        job->buffer = realloc(job->buffer, link_length + 1);
++        job->buffer[link_length] = '\0';
++      } else {
++        free (job->buffer);
++        job->buffer = NULL;
++      }
++      job->result = link_length;
++      job->error_code = errno;
++      break;
++    } else {
++      free(job->buffer);
++      buffer_size *= 2;
++    }
++  }
+ }
+ 
+ CAMLprim value lwt_unix_readlink_job(value val_name)
+@@ -2346,6 +2370,7 @@ CAMLprim value lwt_unix_readlink_job(value val_name)
+   struct job_readlink *job = lwt_unix_new(struct job_readlink);
+   job->job.worker = (lwt_unix_job_worker)worker_readlink;
+   job->name = lwt_unix_strdup(String_val(val_name));
++  job->buffer = NULL;
+   return lwt_unix_alloc_job(&(job->job));
+ }
+ 
+@@ -2353,7 +2378,6 @@ CAMLprim value lwt_unix_readlink_result(value val_job)
+ {
+   struct job_readlink *job = Job_readlink_val(val_job);
+   if (job->result < 0) unix_error(job->error_code, "readlink", Nothing);
+-  job->buffer[job->result] = 0;
+   return caml_copy_string(job->buffer);
+ }
+ 
+@@ -2361,6 +2385,7 @@ CAMLprim value lwt_unix_readlink_free(value val_job)
+ {
+   struct job_readlink *job = Job_readlink_val(val_job);
+   free(job->name);
++  free(job->buffer);
+   lwt_unix_free_job(&job->job);
+   return Val_unit;
+ }
+@@ -2698,7 +2723,7 @@ CAMLprim value lwt_unix_getgrgid_free(value val_job)
+ 
+ struct job_gethostname {
+   struct lwt_unix_job job;
+-  char buffer[MAXHOSTNAMELEN];
++  char *buffer;
+   int result;
+   int error_code;
+ };
+@@ -2707,15 +2732,32 @@ struct job_gethostname {
+ 
+ static void worker_gethostname(struct job_gethostname *job)
+ {
+-  job->result = gethostname(job->buffer, MAXHOSTNAMELEN);
+-  job->buffer[MAXHOSTNAMELEN - 1] = 0;
+-  job->error_code = errno;
++  int buffer_size = 64;
++  int err;
++
++  for (;;) {
++
++    job->buffer = lwt_unix_malloc(buffer_size + 1);
++
++    err = gethostname(job->buffer, buffer_size);
++
++    if (err == -1 && errno == ENAMETOOLONG) {
++      free(job->buffer);
++      buffer_size *= 2;
++    } else {
++      job->buffer[buffer_size] = '\0';
++      job->result = err;
++      job->error_code = errno;
++      break;
++    }
++  }
+ }
+ 
+ CAMLprim value lwt_unix_gethostname_job()
+ {
+   struct job_gethostname *job = lwt_unix_new(struct job_gethostname);
+   job->job.worker = (lwt_unix_job_worker)worker_gethostname;
++  job->buffer = NULL;
+   return lwt_unix_alloc_job(&(job->job));
+ }
+ 
+@@ -2729,6 +2771,7 @@ CAMLprim value lwt_unix_gethostname_result(value val_job)
+ CAMLprim value lwt_unix_gethostname_free(value val_job)
+ {
+   struct job_gethostname *job = Job_gethostname_val(val_job);
++  free(job->buffer);
+   lwt_unix_free_job(&job->job);
+   return Val_unit;
+ }
+-- 
diff --git a/debian/patches/series b/debian/patches/series
index 97db22b..880e4d9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 0001-Do-not-build-manual-manual.pdf.patch
+0002-Fix-FTBFS-on-hurd.patch

-- 
Cooperative light-weight thread library for OCaml

_______________________________________________
Pkg-ocaml-maint-commits mailing list
Pkg-ocaml-maint-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-ocaml-maint-commits

Reply via email to