utils.inc 711 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. function ffi_cdef($code, $lib)
  3. {
  4. if (isset($lib)) {
  5. return FFI::cdef($code, $lib);
  6. } else {
  7. return FFI::cdef($code);
  8. }
  9. }
  10. function ffi_get_php_dll_name()
  11. {
  12. if (PHP_OS_FAMILY === 'Windows') {
  13. return "php" . PHP_MAJOR_VERSION . (PHP_ZTS ? "ts" : "") . (PHP_DEBUG ? "_debug" : "") . ".dll";
  14. } else {
  15. return null;
  16. }
  17. }
  18. function ffi_get_fastcall_specifier()
  19. {
  20. foreach (['__attribute__((fastcall))', '__fastcall', '__vectorcall'] as $spec) {
  21. try {
  22. ffi_cdef("extern size_t $spec zend_list_insert(void *ptr, int type);", ffi_get_php_dll_name());
  23. return "$spec ";
  24. } catch (Throwable $e) {}
  25. }
  26. return "";
  27. }