emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114671: Disallow bool vector operations on mixed-le


From: Paul Eggert
Subject: [Emacs-diffs] trunk r114671: Disallow bool vector operations on mixed-length operands.
Date: Tue, 15 Oct 2013 16:38:41 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114671
revision-id: address@hidden
parent: address@hidden
author: Paul Eggert  <address@hidden>
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2013-10-15 09:38:36 -0700
message:
  Disallow bool vector operations on mixed-length operands.
  
  The old behavior left garbage in the result vector sometimes,
  and didn't seem to be useful.
  * data.c (Qwrong_length_argument): New static var.
  (wrong_length_argument): New function.
  (bool_vector_binop_driver): Check that args agree in length.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/data.c                     data.c-20091113204419-o5vbwnq5f7feedwu-251
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-10-15 13:57:37 +0000
+++ b/src/ChangeLog     2013-10-15 16:38:36 +0000
@@ -1,5 +1,12 @@
 2013-10-15  Paul Eggert  <address@hidden>
 
+       Disallow bool vector operations on mixed-length operands.
+       The old behavior left garbage in the result vector sometimes,
+       and didn't seem to be useful.
+       * data.c (Qwrong_length_argument): New static var.
+       (wrong_length_argument): New function.
+       (bool_vector_binop_driver): Check that args agree in length.
+
        * keyboard.c, keyboard.h (all_kboards): Now static.
 
 2013-10-15  Xue Fuqiao  <address@hidden>

=== modified file 'src/data.c'
--- a/src/data.c        2013-10-14 07:12:49 +0000
+++ b/src/data.c        2013-10-15 16:38:36 +0000
@@ -41,6 +41,7 @@
 static Lisp_Object Qsubr;
 Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
 Lisp_Object Qerror, Quser_error, Qquit, Qargs_out_of_range;
+static Lisp_Object Qwrong_length_argument;
 static Lisp_Object Qwrong_type_argument;
 Lisp_Object Qvoid_variable, Qvoid_function;
 static Lisp_Object Qcyclic_function_indirection;
@@ -179,6 +180,18 @@
   blv->valcell = val;
 }
 
+static _Noreturn void
+wrong_length_argument (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
+{
+  Lisp_Object size1 = make_number (bool_vector_size (a1));
+  Lisp_Object size2 = make_number (bool_vector_size (a2));
+  if (NILP (a3))
+    xsignal2 (Qwrong_length_argument, size1, size2);
+  else
+    xsignal3 (Qwrong_length_argument, size1, size2,
+             make_number (bool_vector_size (a3)));
+}
+
 Lisp_Object
 wrong_type_argument (register Lisp_Object predicate, register Lisp_Object 
value)
 {
@@ -3004,7 +3017,9 @@
   CHECK_BOOL_VECTOR (op1);
   CHECK_BOOL_VECTOR (op2);
 
-  nr_bits = min (bool_vector_size (op1), bool_vector_size (op2));
+  nr_bits = bool_vector_size (op1);
+  if (bool_vector_size (op2) != nr_bits)
+    wrong_length_argument (op1, op2, dest);
 
   if (NILP (dest))
     {
@@ -3014,7 +3029,8 @@
   else
     {
       CHECK_BOOL_VECTOR (dest);
-      nr_bits = min (nr_bits, bool_vector_size (dest));
+      if (bool_vector_size (dest) != nr_bits)
+       wrong_length_argument (op1, op2, dest);
     }
 
   nr_words = ROUNDUP (nr_bits, BITS_PER_BITS_WORD) / BITS_PER_BITS_WORD;
@@ -3103,11 +3119,10 @@
 
 DEFUN ("bool-vector-exclusive-or", Fbool_vector_exclusive_or,
        Sbool_vector_exclusive_or, 2, 3, 0,
-       doc: /* Compute C = A ^ B, bitwise exclusive or.
-A, B, and C must be bool vectors.  If C is nil, allocate a new bool
-vector in which to store the result.  Return the destination vector if
-it changed or nil otherwise.  */
-       )
+       doc: /* Return A ^ B, bitwise exclusive or.
+If optional third argument C is given, store result into C.
+A, B, and C must be bool vectors of the same length.
+Return the destination vector if it changed or nil otherwise.  */)
   (Lisp_Object a, Lisp_Object b, Lisp_Object c)
 {
   return bool_vector_binop_driver (a, b, c, bool_vector_exclusive_or);
@@ -3115,10 +3130,10 @@
 
 DEFUN ("bool-vector-union", Fbool_vector_union,
        Sbool_vector_union, 2, 3, 0,
-       doc: /* Compute C = A | B, bitwise or.
-A, B, and C must be bool vectors.  If C is nil, allocate a new bool
-vector in which to store the result.  Return the destination vector if
-it changed or nil otherwise.  */)
+       doc: /* Return A | B, bitwise or.
+If optional third argument C is given, store result into C.
+A, B, and C must be bool vectors of the same length.
+Return the destination vector if it changed or nil otherwise.  */)
   (Lisp_Object a, Lisp_Object b, Lisp_Object c)
 {
   return bool_vector_binop_driver (a, b, c, bool_vector_union);
@@ -3126,10 +3141,10 @@
 
 DEFUN ("bool-vector-intersection", Fbool_vector_intersection,
        Sbool_vector_intersection, 2, 3, 0,
-       doc: /* Compute C = A & B, bitwise and.
-A, B, and C must be bool vectors.  If C is nil, allocate a new bool
-vector in which to store the result.  Return the destination vector if
-it changed or nil otherwise.  */)
+       doc: /* Return A & B, bitwise and.
+If optional third argument C is given, store result into C.
+A, B, and C must be bool vectors of the same length.
+Return the destination vector if it changed or nil otherwise.  */)
   (Lisp_Object a, Lisp_Object b, Lisp_Object c)
 {
   return bool_vector_binop_driver (a, b, c, bool_vector_intersection);
@@ -3137,10 +3152,10 @@
 
 DEFUN ("bool-vector-set-difference", Fbool_vector_set_difference,
        Sbool_vector_set_difference, 2, 3, 0,
-       doc: /* Compute C = A &~ B, set difference.
-A, B, and C must be bool vectors.  If C is nil, allocate a new bool
-vector in which to store the result.  Return the destination vector if
-it changed or nil otherwise.  */)
+       doc: /* Return A &~ B, set difference.
+If optional third argument C is given, store result into C.
+A, B, and C must be bool vectors of the same length.
+Return the destination vector if it changed or nil otherwise.  */)
   (Lisp_Object a, Lisp_Object b, Lisp_Object c)
 {
   return bool_vector_binop_driver (a, b, c, bool_vector_set_difference);
@@ -3157,9 +3172,9 @@
 
 DEFUN ("bool-vector-not", Fbool_vector_not,
        Sbool_vector_not, 1, 2, 0,
-       doc: /* Compute B = ~A.
-B must be a bool vector.  A must be a bool vector or nil.
-If A is nil, allocate a new bool vector in which to store the result.
+       doc: /* Compute ~A, set complement.
+If optional second argument B is given, store result into B.
+A and B must be bool vectors of the same length.
 Return the destination vector.  */)
   (Lisp_Object a, Lisp_Object b)
 {
@@ -3176,7 +3191,8 @@
   else
     {
       CHECK_BOOL_VECTOR (b);
-      nr_bits = min (nr_bits, bool_vector_size (b));
+      if (bool_vector_size (b) != nr_bits)
+       wrong_length_argument (a, b, Qnil);
     }
 
   bdata = (bits_word *) XBOOL_VECTOR (b)->data;
@@ -3323,6 +3339,7 @@
   DEFSYM (Qerror, "error");
   DEFSYM (Quser_error, "user-error");
   DEFSYM (Qquit, "quit");
+  DEFSYM (Qwrong_length_argument, "wrong-length-argument");
   DEFSYM (Qwrong_type_argument, "wrong-type-argument");
   DEFSYM (Qargs_out_of_range, "args-out-of-range");
   DEFSYM (Qvoid_function, "void-function");
@@ -3397,6 +3414,7 @@
   PUT_ERROR (Qquit, Qnil, "Quit");
 
   PUT_ERROR (Quser_error, error_tail, "");
+  PUT_ERROR (Qwrong_length_argument, error_tail, "Wrong length argument");
   PUT_ERROR (Qwrong_type_argument, error_tail, "Wrong type argument");
   PUT_ERROR (Qargs_out_of_range, error_tail, "Args out of range");
   PUT_ERROR (Qvoid_function, error_tail,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]