Change 11098 by jhi@alpha on 2001/07/02 17:37:44

        Based on
        
        Subject: Re: sizeof(struct sembuf)
        From: Nicholas Clark <[EMAIL PROTECTED]>
        Date: Sun, 1 Jul 2001 22:26:48 +0100
        Message-ID: <[EMAIL PROTECTED]>
        
        but do semop() always the slow way.

Affected files ...

... //depot/perl/doio.c#164 edit

Differences ...

==== //depot/perl/doio.c#164 (text) ====
Index: perl/doio.c
--- perl/doio.c.~1~     Mon Jul  2 11:45:05 2001
+++ perl/doio.c Mon Jul  2 11:45:05 2001
@@ -2029,13 +2029,42 @@
     id = SvIVx(*++mark);
     opstr = *++mark;
     opbuf = SvPV(opstr, opsize);
-    if (opsize < sizeof(struct sembuf)
-       || (opsize % sizeof(struct sembuf)) != 0) {
+    if (opsize < 3 * SHORTSIZE
+       || (opsize % (3 * SHORTSIZE))) {
        SETERRNO(EINVAL,LIB$_INVARG);
        return -1;
     }
     SETERRNO(0,0);
-    return semop(id, (struct sembuf *)opbuf, opsize/sizeof(struct sembuf));
+    /* We can't assume that sizeof(struct sembuf) == 3 * sizeof(short). */
+    {
+        int nsops  = opsize / (3 * sizeof (short));
+        int i      = nsops;
+        short *ops = (short *) opbuf;
+        short *o   = ops;
+        struct sembuf *temps, *t;
+        I32 result;
+
+        New (0, temps, nsops, struct sembuf);
+        t = temps;
+        while (i--) {
+            t->sem_num = *o++;
+            t->sem_op  = *o++;
+            t->sem_flg = *o++;
+            t++;
+        }
+        result = semop(id, temps, nsops);
+        t = temps;
+        o = ops;
+        i = nsops;
+        while (i--) {
+            *o++ = t->sem_num;
+            *o++ = t->sem_op;
+            *o++ = t->sem_flg;
+            t++;
+        }
+        Safefree(temps);
+        return result;
+    }
 #else
     Perl_croak(aTHX_ "semop not implemented");
 #endif
End of Patch.

Reply via email to