comparison src/glyphs.c @ 5736:3192994c49ca

Convert C (un)signed long long values to bignums properly. This patch also does the following: - Uses make_fixnum instead of make_integer when the argument is guaranteed to be in the fixnum range. - Introduces make_unsigned_integer so that we handle unsigned values with the high bit set correctly. - Introduces conversions between bignums and (un)signed long long values. - Uses mp_set_memory_functions with the BSD MP code, if it exists. - Eliminates some unnecessary consing in the Lisp + and * implementations. - Fixes a problem with check_valid_xbm_inline(). This function is called during intialization. It calls Ftimes. When using pdump, this is a problem, because (a) the bignum code is not initialized until *after* dumping, so we don't try to dump any bignums, and (b) multiplication of integers is done inside bignums so we handle fixnum overflow correctly. I decided that an XBM file with dimensions that don't fit into fixnums is probably not something we want to try to handle anyway, and did the arithmetic with C values instead of Lisp values. Doing that broke one test, which started getting a different error message from the one it expected, so I adjusted the test to match the new reality. - Fixes a few miscellaneous bugs in the BSD MP code. See <CAHCOHQk0u0=eD1fUMHTNWi2Yh=1WgiYyCXdMbsGzHBNhdqYz4w@mail.gmail.com> in xemacs-patches, as well as followup messages.
author Jerry James <james@xemacs.org>
date Mon, 17 Jun 2013 10:23:00 -0600
parents eb41da9b4469
children 427a72c6ee17
comparison
equal deleted inserted replaced
5735:ff13c44ce0d9 5736:3192994c49ca
2636 2636
2637 static void 2637 static void
2638 check_valid_xbm_inline (Lisp_Object data) 2638 check_valid_xbm_inline (Lisp_Object data)
2639 { 2639 {
2640 Lisp_Object width, height, bits, args[2]; 2640 Lisp_Object width, height, bits, args[2];
2641 unsigned long i_width, i_height;
2641 2642
2642 if (!CONSP (data) || 2643 if (!CONSP (data) ||
2643 !CONSP (XCDR (data)) || 2644 !CONSP (XCDR (data)) ||
2644 !CONSP (XCDR (XCDR (data))) || 2645 !CONSP (XCDR (XCDR (data))) ||
2645 !NILP (XCDR (XCDR (XCDR (data))))) 2646 !NILP (XCDR (XCDR (XCDR (data)))))
2649 height = XCAR (XCDR (data)); 2650 height = XCAR (XCDR (data));
2650 bits = XCAR (XCDR (XCDR (data))); 2651 bits = XCAR (XCDR (XCDR (data)));
2651 2652
2652 CHECK_STRING (bits); 2653 CHECK_STRING (bits);
2653 2654
2654 if (!NATNUMP (width)) 2655 if (!FIXNUMP (width) || XREALFIXNUM (width) < 0)
2655 invalid_argument ("Width must be a natural number", width); 2656 invalid_argument ("Width must be a natural number", width);
2656 2657
2657 if (!NATNUMP (height)) 2658 if (!FIXNUMP (height) || XREALFIXNUM (height) < 0)
2658 invalid_argument ("Height must be a natural number", height); 2659 invalid_argument ("Height must be a natural number", height);
2659 2660
2660 args[0] = width; 2661 i_width = (unsigned long) XREALFIXNUM (width);
2661 args[1] = height; 2662 i_height = (unsigned long) XREALFIXNUM (height);
2662 2663 if (i_width * i_height / 8UL > string_char_length (bits))
2663 args[0] = Ftimes (countof (args), args);
2664 args[1] = make_integer (8);
2665
2666 args[0] = Fquo (countof (args), args);
2667 args[1] = make_integer (string_char_length (bits));
2668
2669 if (!NILP (Fgtr (countof (args), args)))
2670 invalid_argument ("data is too short for width and height", 2664 invalid_argument ("data is too short for width and height",
2671 vector3 (width, height, bits)); 2665 vector3 (width, height, bits));
2672 } 2666 }
2673 2667
2674 /* Validate method for XBM's. */ 2668 /* Validate method for XBM's. */