]> granicus.if.org Git - php/commitdiff
Merge branch 'PHP-5.6'
authorTjerk Meesters <datibbaw@php.net>
Thu, 9 Oct 2014 23:05:36 +0000 (07:05 +0800)
committerTjerk Meesters <datibbaw@php.net>
Thu, 9 Oct 2014 23:05:36 +0000 (07:05 +0800)
* PHP-5.6:
  Add 64 bit formats to pack() and unpack()

1  2 
ext/standard/pack.c

index f2bcb0972337fbc328ba2e3cb4a15130c63658ca,9427db90a01f81f2722272d3c8c646c758f1fdc3..a690b7bee867d217908cc9eaa0fb7b35f1746f48
@@@ -82,9 -82,16 +82,16 @@@ static int machine_endian_long_map[4]
  static int big_endian_long_map[4];
  static int little_endian_long_map[4];
  
+ #if SIZEOF_LONG > 4
+ /* Mappings of bytes from quads (64bit) for all endian environments */
+ static int machine_endian_longlong_map[8];
+ static int big_endian_longlong_map[8];
+ static int little_endian_longlong_map[8];
+ #endif
  /* {{{ php_pack
   */
 -static void php_pack(zval **val, int size, int *map, char *output)
 +static void php_pack(zval *val, size_t size, int *map, char *output)
  {
        int i;
        char *v;
@@@ -430,9 -464,34 +457,30 @@@ PHP_FUNCTION(pack
                                break;
                        }
  
+ #if SIZEOF_LONG > 4
+                       case 'q':
+                       case 'Q':
+                       case 'J':
+                       case 'P': {
+                               int *map = machine_endian_longlong_map;
+                               if (code == 'J') {
+                                       map = big_endian_longlong_map;
+                               } else if (code == 'P') {
+                                       map = little_endian_longlong_map;
+                               }
+                               while (arg-- > 0) {
+                                       php_pack(argv[currentarg++], 8, map, &output[outputpos]);
+                                       outputpos += 8;
+                               }
+                               break;
+                       }
+ #endif
                        case 'f': {
 -                              float v;
 -
                                while (arg-- > 0) {
 -                                      val = argv[currentarg++];
 -                                      convert_to_double_ex(val);
 -                                      v = (float) Z_DVAL_PP(val);
 +                                      float v = (float) zval_get_double(&argv[currentarg++]);
                                        memcpy(&output[outputpos], &v, sizeof(v));
                                        outputpos += sizeof(v);
                                }