Skip to content

Stdlib: pack()/unpack() — machine-endian integer formats (P/p/I/i/L/l/Q/q/J/j/V/v) and @ alignment (ext/standard/pack.c) #4675

Description

@PurHur

Category

stdlib

Problem

After basic pack() / unpack() exist, this build must match Zend for machine-dependent and explicitly sized integer formats and the @ alignment specifier. Float codes d/e/f/g are tracked in #4662; this issue covers integer / endian / padding codes from pack.c.

Typical gaps when not using host pack(): wrong endianness, wrong sizeof for P/p, @ skip misaligned, Q/J 64-bit layout.

php-src reference

Repro

<?php
// 32-bit little-endian unsigned (format N) vs machine (I)
$bin = pack('Nn', 0x11223344, 0x5566);
var_export(unpack('Nn', $bin));
echo "\n";
// padding / alignment
var_export(strlen(pack('I@4I', 1, 2)));
echo "\n";
// 64-bit (platform-dependent width for J/Q on 64-bit PHP)
var_export(unpack('P', pack('P', 0x1234)));

Compare Zend vs this compiler (VM):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_pack_int.php
php bin/vm.php repro_pack_int.php
'

Scope (this repo)

  • ext/standard/VmPack.php (or native port from bootstrap issue)
  • lib/AOT/runtime/__compiler_pack / __compiler_unpack
  • ext/standard/JitPack.php, ext/standard/JitUnpack.php
  • Compliance: test/compliance/cases/stdlib/pack_integer_endian.phpt

Done when

  • VM returns Zend-identical binary strings and unpack() arrays for c/C, s/S, n/N, v/V, i/I, l/L, q/Q, j/J, p/P on the CI target arch
  • @ alignment and x/X/Z padding bytes match pack.c
  • Invalid specifier warnings/false return follow #4532
  • JIT/AOT use the same encoder/decoder as VM

Related

  • #4662 float/double formats
  • #4673 bootstrap native pack (prerequisite if VmPack still delegates)
  • #4204 numeric-string length params on other builtins

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions