[polyml] 08/09: Backport using POLYUNSIGNED consistently for stream IDs

James Clarke jrtc27-guest at moszumanska.debian.org
Tue Feb 2 21:21:00 UTC 2016


This is an automated email from the git hooks/post-receive script.

jrtc27-guest pushed a commit to branch master
in repository polyml.

commit 77a5be8b1f8ef90c11a55d757932279fcbfd7d57
Author: James Clarke <jrtc27 at jrtc27.com>
Date:   Sun Jan 31 19:41:50 2016 +0000

    Backport using POLYUNSIGNED consistently for stream IDs
---
 debian/changelog                                   |   3 +
 debian/patches/series                              |   1 +
 ...e-polyunsigned-consistently-for-stream-ids.diff | 158 +++++++++++++++++++++
 3 files changed, 162 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index bbcb900..bec2e14 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -16,6 +16,9 @@ polyml (5.6-2) UNRELEASED; urgency=low
       non-abicalls files.
     - unix-const-vec-unsigned.diff: Define unixConstVec as unsigned. Fixes
       narrowing conversion inside braces on PowerPC with GCC 6.
+    - use-polyunsigned-consistently-for-stream-ids.diff: Backport upstream's
+      fix so POLYUNSIGNED is used everywhere to refer to stream IDs, avoiding
+      implicit narrowing conversions. Includes fixed realloc failure handling.
 
  -- James Clarke <jrtc27 at jrtc27.com>  Sun, 31 Jan 2016 17:59:21 +0000
 
diff --git a/debian/patches/series b/debian/patches/series
index 975960d..2f387da 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -9,3 +9,4 @@ mips-abi.diff
 unix-const-vec-unsigned.diff
 fix-script-args.diff
 fix-heap-ratio-assert.diff
+use-polyunsigned-consistently-for-stream-ids.diff
diff --git a/debian/patches/use-polyunsigned-consistently-for-stream-ids.diff b/debian/patches/use-polyunsigned-consistently-for-stream-ids.diff
new file mode 100644
index 0000000..66c1c4c
--- /dev/null
+++ b/debian/patches/use-polyunsigned-consistently-for-stream-ids.diff
@@ -0,0 +1,158 @@
+Description: Use POLYUNSIGNED consistently for stream IDs
+ Handle failure in realloc correctly in make_stream_entry.
+Origin: upstream, https://github.com/polyml/polyml/commit/8423a37ce77b1811387a0932d44949f9c08970b8
+Author: David Matthews <dm at prolingua.co.uk>
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/libpolyml/basicio.cpp
++++ b/libpolyml/basicio.cpp
+@@ -255,7 +255,7 @@
+ 
+ #endif
+ 
+-static unsigned max_streams;
++static POLYUNSIGNED max_streams;
+ 
+ /* If we try opening a stream and it fails with EMFILE (too many files
+    open) we may be able to recover by garbage-collecting and closing some
+@@ -326,7 +326,7 @@
+    deleted if there is a garbage collection (Entries in the stream vector
+    itself are "weak". */ 
+ {
+-    unsigned stream_no;
++    POLYUNSIGNED stream_no;
+ 
+     ioLock.Lock();
+     // Find an unused entry.
+@@ -337,10 +337,12 @@
+     /* Check we have enough space. */
+     if (stream_no >= max_streams)
+     { /* No space. */
+-        int oldMax = max_streams;
++        POLYUNSIGNED oldMax = max_streams;
+         max_streams += max_streams/2;
+-        basic_io_vector =
++        PIOSTRUCT newVector =
+             (PIOSTRUCT)realloc(basic_io_vector, max_streams*sizeof(IOSTRUCT));
++        if (newVector == NULL) return NULL;
++        basic_io_vector = newVector;
+         /* Clear the new space. */
+         memset(basic_io_vector+oldMax, 0, (max_streams-oldMax)*sizeof(IOSTRUCT));
+     }
+@@ -375,7 +377,7 @@
+    run out and must perform a full garbage collection to recover
+    the unused ones. SPF 12/9/95
+ */ 
+-void free_stream_entry(unsigned stream_no)
++void free_stream_entry(POLYUNSIGNED stream_no)
+ {
+     ASSERT(0 <= stream_no && stream_no < max_streams);
+ 
+@@ -410,7 +412,8 @@
+         TempString cFileName(filename->Word()); // Get file name
+         if (cFileName == 0) raise_syscall(taskData, "Insufficient memory", ENOMEM);
+         Handle str_token = make_stream_entry(taskData);
+-        unsigned stream_no = STREAMID(str_token);
++        if (str_token == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
++        POLYUNSIGNED stream_no = STREAMID(str_token);
+         int stream = _topen(cFileName, mode, access);
+ 
+         if (stream >= 0)
+@@ -464,7 +467,7 @@
+ static Handle close_file(TaskData *taskData, Handle stream)
+ {
+     PIOSTRUCT strm = get_stream(DEREFHANDLE(stream));
+-    unsigned stream_no = STREAMID(stream);
++    POLYUNSIGNED stream_no = STREAMID(stream);
+ 
+     if (strm != NULL && stream_no > 2)
+         /* Ignore closed streams, stdin, stdout or stderr. */
+@@ -1057,7 +1060,8 @@
+     while (1) // Only certain errors
+     {
+         Handle str_token = make_stream_entry(taskData);
+-        unsigned stream_no    = STREAMID(str_token);
++        if (str_token == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
++        POLYUNSIGNED stream_no    = STREAMID(str_token);
+         PIOSTRUCT strm = &basic_io_vector[stream_no];
+ #if (defined(_WIN32) && ! defined(__CYGWIN__))
+         {
+@@ -1608,7 +1612,8 @@
+             }
+             /* Have to make a new entry. */
+             Handle str_token = make_stream_entry(taskData);
+-            unsigned stream_no    = STREAMID(str_token);
++            if (str_token == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
++            POLYUNSIGNED stream_no    = STREAMID(str_token);
+             str = &basic_io_vector[stream_no];
+             str->device.ioDesc = get_C_int(taskData, DEREFWORD(args));
+             /* We don't know whether it's open for read, write or even if
+--- a/libpolyml/io_internal.h
++++ b/libpolyml/io_internal.h
+@@ -106,7 +106,7 @@
+ extern PIOSTRUCT get_stream(PolyObject *obj);
+ 
+ extern Handle make_stream_entry(TaskData *mdTaskData);
+-extern void free_stream_entry(unsigned stream_no);
++extern void free_stream_entry(POLYUNSIGNED stream_no);
+ extern void close_stream(PIOSTRUCT str);
+ 
+ extern PIOSTRUCT basic_io_vector;
+--- a/libpolyml/network.cpp
++++ b/libpolyml/network.cpp
+@@ -548,8 +548,9 @@
+     case 14: /* Create a socket */
+         {
+             Handle str_token = make_stream_entry(taskData);
++            if (str_token == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
+             PIOSTRUCT strm;
+-            unsigned stream_no = STREAMID(str_token);
++            POLYUNSIGNED stream_no = STREAMID(str_token);
+             int af = get_C_int(taskData, DEREFHANDLE(args)->Get(0));
+             int type = get_C_int(taskData, DEREFHANDLE(args)->Get(1));
+             int proto = get_C_int(taskData, DEREFHANDLE(args)->Get(2));
+@@ -798,18 +799,17 @@
+             PIOSTRUCT strm = get_stream(args->WordP());
+             if (strm == NULL) raise_syscall(taskData, "Stream is closed", EBADF);
+             else {
+-                SOCKET sock = strm->device.sock, result;
++                SOCKET sock = strm->device.sock;
+                 struct sockaddr resultAddr;
+-                socklen_t addrLen;
+                 Handle addrHandle, pair;
+-                Handle str_token;
+                 PIOSTRUCT newStrm;
+                 /* Get a token for the new socket - may raise an
+                    exception if it fails. */
+-                str_token = make_stream_entry(taskData);
+-                unsigned stream_no = STREAMID(str_token);
+-                addrLen = sizeof(resultAddr);
+-                result = accept(sock, &resultAddr, &addrLen);
++                Handle str_token = make_stream_entry(taskData);
++                if (str_token == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
++                POLYUNSIGNED stream_no = STREAMID(str_token);
++                socklen_t addrLen = sizeof(resultAddr);
++                SOCKET result = accept(sock, &resultAddr, &addrLen);
+ 
+                 if (result == INVALID_SOCKET)
+                 {
+@@ -1184,7 +1184,9 @@
+ #else
+         {
+             Handle str_token1 = make_stream_entry(taskData);
++            if (str_token1 == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
+             Handle str_token2 = make_stream_entry(taskData);
++            if (str_token2 == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
+             Handle pair;
+             PIOSTRUCT strm1, strm2;
+             unsigned stream_no1 = STREAMID(str_token1);
+--- a/libpolyml/windows_specific.cpp
++++ b/libpolyml/windows_specific.cpp
+@@ -1013,6 +1013,7 @@
+     if (fIsText) mode |= _O_TEXT; else mode |= _O_BINARY;
+ 
+     Handle str_token = make_stream_entry(taskData);
++    if (str_token == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
+     PIOSTRUCT strm = &basic_io_vector[STREAMID(str_token)];
+     strm->device.ioDesc = _open_osfhandle ((POLYSIGNED) hStream, mode);
+     if (strm->device.ioDesc == -1)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/polyml.git



More information about the debian-science-commits mailing list