diff --git a/luajit-2.1-fedora.patch b/luajit-2.1-fedora.patch index e84dfa1..d98f5dd 100644 --- a/luajit-2.1-fedora.patch +++ b/luajit-2.1-fedora.patch @@ -1,4 +1,4 @@ -From 86a1a5033a3eb07e694f8e7f7024550928191024 Mon Sep 17 00:00:00 2001 +From d5b06e912851816bed265905f4d86d82b78f26ab Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Thu, 21 Oct 2021 11:04:58 +0200 Subject: [PATCH 01/10] Merge in LuaJIT-test-cleanup into the main repo @@ -530,10 +530,10 @@ index 00000000..a1c9209b +Vlad Krasnov +William Adams diff --git a/Makefile b/Makefile -index aa1b84bd..cb2b3418 100644 +index b0288b4d..b3c88f23 100644 --- a/Makefile +++ b/Makefile -@@ -106,14 +106,14 @@ endif +@@ -110,14 +110,14 @@ endif ############################################################################## @@ -551,7 +551,7 @@ index aa1b84bd..cb2b3418 100644 @echo "==== Installing LuaJIT $(VERSION) to $(PREFIX) ====" $(MKDIR) $(INSTALL_DIRS) cd src && $(INSTALL_X) $(FILE_T) $(INSTALL_T) -@@ -152,6 +152,17 @@ uninstall: +@@ -156,6 +156,17 @@ uninstall: $(RMDIR) $(UNINSTALL_DIRS) || : @echo "==== Successfully uninstalled LuaJIT $(VERSION) from $(PREFIX) ====" @@ -569,7 +569,7 @@ index aa1b84bd..cb2b3418 100644 ############################################################################## amalg: -@@ -161,6 +172,6 @@ amalg: +@@ -165,6 +176,6 @@ amalg: clean: $(MAKE) -C src clean @@ -188575,10 +188575,10 @@ index 00000000..ef4de129 +-- Pointless: deg, rad, min, max, pow +-- LATER: %, fmod, frexp, ldexp, modf, sinh, cosh, tanh -- -2.31.1 +2.37.1 -From 6508eeb5c841344e3f128267a04e8150dd36f926 Mon Sep 17 00:00:00 2001 +From 78914a298dbadaa30613df89d94b8dddb1b64d03 Mon Sep 17 00:00:00 2001 From: Sameera Deshpande Date: Fri, 15 Feb 2019 07:46:16 +0530 Subject: [PATCH 02/10] Add support for FNMADD and FNMSUB. @@ -188588,7 +188588,7 @@ Subject: [PATCH 02/10] Add support for FNMADD and FNMSUB. 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/lj_asm_arm64.h b/src/lj_asm_arm64.h -index 67c53ee2..0e913fa5 100644 +index 1f44d023..dd3d1408 100644 --- a/src/lj_asm_arm64.h +++ b/src/lj_asm_arm64.h @@ -353,6 +353,35 @@ static int asm_fusemadd(ASMState *as, IRIns *ir, A64Ins ai, A64Ins air) @@ -188638,10 +188638,10 @@ index 67c53ee2..0e913fa5 100644 } asm_intneg(as, ir); -- -2.31.1 +2.37.1 -From aa0b2a0c837af307d26468fce05a7c24ab6045d3 Mon Sep 17 00:00:00 2001 +From 84e0677c95af42b1ccfa6f55a572880d93854026 Mon Sep 17 00:00:00 2001 From: Vivien HENRIET Date: Wed, 30 Jan 2019 23:44:51 +0100 Subject: [PATCH 03/10] Fix os.date() for timezone change awareness @@ -188663,7 +188663,7 @@ To fix the issue tzset is called before localtime_r. 1 file changed, 1 insertion(+) diff --git a/src/lib_os.c b/src/lib_os.c -index f19b831c..609cb2ec 100644 +index 6bcd0147..4b4e1503 100644 --- a/src/lib_os.c +++ b/src/lib_os.c @@ -185,6 +185,7 @@ LJLIB_CF(os_date) @@ -188675,10 +188675,10 @@ index f19b831c..609cb2ec 100644 #else stm = localtime(&t); -- -2.31.1 +2.37.1 -From a62dc6306c4e5a4b672040067c169143da804a4f Mon Sep 17 00:00:00 2001 +From c874fa39e227ce3a8f33820b7d5046779b690fb4 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Thu, 14 Mar 2019 23:08:24 +0530 Subject: [PATCH 04/10] Revert "FFI: Make FP to U64 conversions match JIT @@ -188700,10 +188700,10 @@ making things worse. There needs to be a better fix for this. 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/lj_obj.h b/src/lj_obj.h -index 1a6445fc..97885683 100644 +index 67e41181..ad9dba5d 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h -@@ -995,22 +995,14 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n) +@@ -996,22 +996,14 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n) #define lj_num2int(n) ((int32_t)(n)) @@ -188732,10 +188732,10 @@ index 1a6445fc..97885683 100644 static LJ_AINLINE int32_t numberVint(cTValue *o) -- -2.31.1 +2.37.1 -From fe2399a76bab67b32409fda1de82c34e8d5d7904 Mon Sep 17 00:00:00 2001 +From f452a25f4daf8c20fb09f42624881a127ee6f335 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Sun, 17 Mar 2019 11:34:04 +0530 Subject: [PATCH 05/10] Guard against undefined behaviour when casting from @@ -188751,10 +188751,10 @@ TODO: Do the same for JIT as well as for float to other ranges. 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lj_obj.h b/src/lj_obj.h -index 97885683..9878059f 100644 +index ad9dba5d..cbfa67c3 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h -@@ -997,12 +997,18 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n) +@@ -998,12 +998,18 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n) static LJ_AINLINE uint64_t lj_num2u64(lua_Number n) { @@ -188775,10 +188775,10 @@ index 97885683..9878059f 100644 static LJ_AINLINE int32_t numberVint(cTValue *o) -- -2.31.1 +2.37.1 -From c193115e16a138dac69f774a7f57a5b4cc7f1097 Mon Sep 17 00:00:00 2001 +From 47e6173d38bd0a20847ebce22dd67ba7a0e82f5c Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Mon, 25 Mar 2019 17:56:53 +0530 Subject: [PATCH 06/10] Fix build erro with fnmsub fusing @@ -188788,7 +188788,7 @@ Subject: [PATCH 06/10] Fix build erro with fnmsub fusing 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_asm_arm64.h b/src/lj_asm_arm64.h -index 0e913fa5..4c7bf401 100644 +index dd3d1408..1061b7d0 100644 --- a/src/lj_asm_arm64.h +++ b/src/lj_asm_arm64.h @@ -1495,7 +1495,7 @@ static void asm_mul(ASMState *as, IRIns *ir) @@ -188801,10 +188801,10 @@ index 0e913fa5..4c7bf401 100644 return; } -- -2.31.1 +2.37.1 -From b5c2492406bf07ab80e134f351c1066e8f6224f2 Mon Sep 17 00:00:00 2001 +From 9cae182f30be1bbab4defb9f1b9f848555a14522 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Thu, 28 Mar 2019 09:19:34 +0530 Subject: [PATCH 07/10] aarch64: better float to unsigned int conversion @@ -188826,7 +188826,7 @@ This currently works only for 64-bit conversions, 32-bit is still WIP. 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/lj_asm_arm64.h b/src/lj_asm_arm64.h -index 4c7bf401..e7e744a8 100644 +index 1061b7d0..1b0a82a8 100644 --- a/src/lj_asm_arm64.h +++ b/src/lj_asm_arm64.h @@ -626,14 +626,28 @@ static void asm_conv(ASMState *as, IRIns *ir) @@ -188867,7 +188867,7 @@ index 4c7bf401..e7e744a8 100644 } else if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */ Reg dest = ra_dest(as, ir, RSET_GPR); diff --git a/src/lj_target_arm64.h b/src/lj_target_arm64.h -index 6d39ffb8..370699d9 100644 +index d45af2e4..7051e1d1 100644 --- a/src/lj_target_arm64.h +++ b/src/lj_target_arm64.h @@ -283,6 +283,7 @@ typedef enum A64Ins { @@ -188879,10 +188879,10 @@ index 6d39ffb8..370699d9 100644 A64I_FCSELd = 0x1e600c00, A64I_FRINTMd = 0x1e654000, -- -2.31.1 +2.37.1 -From bd79b1d4596ed6780470c8d02f77b8398d80cd3a Mon Sep 17 00:00:00 2001 +From d3bd1eb4f097422e8f225af848d713faaba7a6a6 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Thu, 28 Mar 2019 10:50:23 +0530 Subject: [PATCH 08/10] Better behaviour for float to uint32_t conversions @@ -188900,7 +188900,7 @@ during the narrowing pass. 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lj_cconv.c b/src/lj_cconv.c -index 613f66e2..7e8a8b92 100644 +index 3bbfd3f1..35efe3c9 100644 --- a/src/lj_cconv.c +++ b/src/lj_cconv.c @@ -203,7 +203,13 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, @@ -188919,10 +188919,10 @@ index 613f66e2..7e8a8b92 100644 if (!(dinfo & CTF_UNSIGNED)) *(int64_t *)dp = (int64_t)n; -- -2.31.1 +2.37.1 -From a1636c6e1879b5eeb55a51ebba796501c93614dd Mon Sep 17 00:00:00 2001 +From a745c003a562ee8392346953214951cf62bfba85 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Mon, 17 Jun 2019 13:50:57 +0530 Subject: [PATCH 09/10] test: Check for package.searchers only in compat5.2 @@ -188955,10 +188955,10 @@ index 2baacd5c..09866f6f 100644 assert(not package.loaders) assert(package.searchers) -- -2.31.1 +2.37.1 -From ec04137a0873c09eef216b32f3df3b66209f47d5 Mon Sep 17 00:00:00 2001 +From e11f638adbb95f3975d4f5c0fa610cff43d9a434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 19 Nov 2015 16:29:02 +0200 Subject: [PATCH 10/10] Get rid of LUAJIT_VERSION_SYM that changes ABI on every @@ -188966,12 +188966,12 @@ Subject: [PATCH 10/10] Get rid of LUAJIT_VERSION_SYM that changes ABI on every --- src/lj_dispatch.c | 5 ----- - src/luajit.c | 2 -- + src/luajit.c | 1 - src/luajit.h | 3 --- - 3 files changed, 10 deletions(-) + 3 files changed, 9 deletions(-) diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c -index 7b73d3dd..3f69d0d1 100644 +index ded382aa..62e5a15b 100644 --- a/src/lj_dispatch.c +++ b/src/lj_dispatch.c @@ -318,11 +318,6 @@ int luaJIT_setmode(lua_State *L, int idx, int mode) @@ -188987,20 +188987,19 @@ index 7b73d3dd..3f69d0d1 100644 /* This function can be called asynchronously (e.g. during a signal). */ diff --git a/src/luajit.c b/src/luajit.c -index 6aed5337..a4a11cb1 100644 +index 6dd64026..9c0b5767 100644 --- a/src/luajit.c +++ b/src/luajit.c -@@ -518,8 +518,6 @@ static int pmain(lua_State *L) +@@ -515,7 +515,6 @@ static int pmain(lua_State *L) + int argn; + int flags = 0; globalL = L; - if (argv[0] && argv[0][0]) progname = argv[0]; - - LUAJIT_VERSION_SYM(); /* Linker-enforced version check. */ -- + argn = collectargs(argv, &flags); if (argn < 0) { /* Invalid args? */ - print_usage(); diff --git a/src/luajit.h b/src/luajit.h -index 2ee1f908..04f6b456 100644 +index 31f1eb1f..54a40ac3 100644 --- a/src/luajit.h +++ b/src/luajit.h @@ -73,7 +73,4 @@ LUA_API void luaJIT_profile_stop(lua_State *L); @@ -189012,5 +189011,5 @@ index 2ee1f908..04f6b456 100644 - #endif -- -2.31.1 +2.37.1 diff --git a/luajit-2.1-update.patch b/luajit-2.1-update.patch index 93fa207..24354bc 100644 --- a/luajit-2.1-update.patch +++ b/luajit-2.1-update.patch @@ -1,5 +1,5 @@ diff --git a/COPYRIGHT b/COPYRIGHT -index 6ed40025..9c2bca55 100644 +index 6ed40025..c74216c3 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,7 +1,7 @@ @@ -8,7 +8,7 @@ index 6ed40025..9c2bca55 100644 +LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/ -Copyright (C) 2005-2017 Mike Pall. All rights reserved. -+Copyright (C) 2005-2021 Mike Pall. All rights reserved. ++Copyright (C) 2005-2022 Mike Pall. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,7 +30,7 @@ index 6ed40025..9c2bca55 100644 =============================================================================== diff --git a/Makefile b/Makefile -index 0f933089..aa1b84bd 100644 +index 0f933089..b0288b4d 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ @@ -38,11 +38,21 @@ index 0f933089..aa1b84bd 100644 # For MinGW and Cygwin, cd to src and run make with the Makefile there. # -# Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h -+# Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h ++# Copyright (C) 2005-2022 Mike Pall. See Copyright Notice in luajit.h ############################################################################## MAJVER= 2 -@@ -75,7 +75,7 @@ SYMLINK= ln -sf +@@ -33,7 +33,8 @@ DPREFIX= $(DESTDIR)$(PREFIX) + INSTALL_BIN= $(DPREFIX)/bin + INSTALL_LIB= $(DPREFIX)/$(MULTILIB) + INSTALL_SHARE= $(DPREFIX)/share +-INSTALL_INC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER) ++INSTALL_DEFINC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER) ++INSTALL_INC= $(INSTALL_DEFINC) + + INSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(VERSION) + INSTALL_JITLIB= $(INSTALL_LJLIBD)/jit +@@ -75,9 +76,12 @@ SYMLINK= ln -sf INSTALL_X= install -m 0755 INSTALL_F= install -m 0644 UNINSTALL= $(RM) @@ -50,8 +60,13 @@ index 0f933089..aa1b84bd 100644 +LDCONFIG= ldconfig -n 2>/dev/null SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \ -e "s|^multilib=.*|multilib=$(MULTILIB)|" ++ifneq ($(INSTALL_DEFINC),$(INSTALL_INC)) ++ SED_PC+= -e "s|^includedir=.*|includedir=$(INSTALL_INC)|" ++endif -@@ -121,7 +121,7 @@ install: $(INSTALL_DEP) + FILE_T= luajit + FILE_A= libluajit.a +@@ -121,7 +125,7 @@ install: $(INSTALL_DEP) $(RM) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2) cd src && test -f $(FILE_SO) && \ $(INSTALL_X) $(FILE_SO) $(INSTALL_DYN) && \ @@ -61,7 +76,7 @@ index 0f933089..aa1b84bd 100644 $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2) || : cd etc && $(INSTALL_F) $(FILE_MAN) $(INSTALL_MAN) diff --git a/README b/README -index 2b9ae9d2..c9f7d9ad 100644 +index 2b9ae9d2..1faef255 100644 --- a/README +++ b/README @@ -3,9 +3,9 @@ README for LuaJIT 2.1.0-beta3 @@ -72,27 +87,27 @@ index 2b9ae9d2..c9f7d9ad 100644 +Project Homepage: https://luajit.org/ -LuaJIT is Copyright (C) 2005-2017 Mike Pall. -+LuaJIT is Copyright (C) 2005-2021 Mike Pall. ++LuaJIT is Copyright (C) 2005-2022 Mike Pall. LuaJIT is free software, released under the MIT license. See full Copyright Notice in the COPYRIGHT file or in luajit.h. diff --git a/doc/bluequad-print.css b/doc/bluequad-print.css -index 62e1c165..0b385cee 100644 +index 62e1c165..a49d309f 100644 --- a/doc/bluequad-print.css +++ b/doc/bluequad-print.css @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2017 Mike Pall. -+/* Copyright (C) 2004-2021 Mike Pall. ++/* Copyright (C) 2004-2022 Mike Pall. * * You are welcome to use the general ideas of this design for your own sites. * But please do not steal the stylesheet, the layout or the color scheme. diff --git a/doc/bluequad.css b/doc/bluequad.css -index be2c4bf2..86cd9ac0 100644 +index be2c4bf2..4c1a9082 100644 --- a/doc/bluequad.css +++ b/doc/bluequad.css @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2017 Mike Pall. -+/* Copyright (C) 2004-2021 Mike Pall. ++/* Copyright (C) 2004-2022 Mike Pall. * * You are welcome to use the general ideas of this design for your own sites. * But please do not steal the stylesheet, the layout or the color scheme. @@ -986,7 +1001,7 @@ index a66a8d95..00000000 - - diff --git a/doc/contact.html b/doc/contact.html -index fe4751c0..c253a08b 100644 +index fe4751c0..89c1af95 100644 --- a/doc/contact.html +++ b/doc/contact.html @@ -1,17 +1,16 @@ @@ -999,7 +1014,7 @@ index fe4751c0..c253a08b 100644 - - + -+ ++ @@ -1066,7 +1081,7 @@ index fe4751c0..c253a08b 100644

All documentation is -Copyright © 2005-2017 Mike Pall. -+Copyright © 2005-2021 Mike Pall. ++Copyright © 2005-2022 Mike Pall.

@@ -1075,22 +1090,22 @@ index fe4751c0..c253a08b 100644 +
+@@ -161,7 +157,7 @@ call the binding function. Phew! +

Motivating Example: Using C Data Structures

+

+ The FFI library allows you to create and access C data +-structures. Of course the main use for this is for interfacing with ++structures. Of course, the main use for this is for interfacing with + C functions. But they can be used stand-alone, too. +

+

+@@ -173,7 +169,7 @@ implemented with a big table holding lots of tiny tables. This imposes + both a substantial memory overhead as well as a performance overhead. +

+

+-Here's a sketch of a library that operates on color images plus a ++Here's a sketch of a library that operates on color images, plus a + simple benchmark. First, the plain Lua version: +

+
+@@ -188,7 +184,7 @@ local function image_ramp_green(n)
+   return img
+ end
+ 
+-local function image_to_grey(img, n)
++local function image_to_gray(img, n)
+   for i=1,n do
+     local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue)
+     img[i].red = y; img[i].green = y; img[i].blue = y
+@@ -198,14 +194,14 @@ end
+ local N = 400*400
+ local img = image_ramp_green(N)
+ for i=1,1000 do
+-  image_to_grey(img, N)
++  image_to_gray(img, N)
+ end
+ 
+

+ This creates a table with 160.000 pixels, each of which is a table +-holding four number values in the range of 0-255. First an image with ++holding four number values in the range of 0-255. First, an image with + a green ramp is created (1D for simplicity), then the image is +-converted to greyscale 1000 times. Yes, that's silly, but I was in ++converted to grayscale 1000 times. Yes, that's silly, but I was in + need of a simple example ... +

+

+@@ -312,7 +308,7 @@ be more compact and faster. This is certainly true (by a factor of + ~1.7x). Switching to a struct-of-arrays would help, too. +

+

+-However the resulting code would be less idiomatic and rather ++However, the resulting code would be less idiomatic and rather + error-prone. And it still doesn't get even close to the performance of + the FFI version of the code. Also, high-level data structures cannot + be easily passed to other C functions, especially I/O functions, @@ -322,7 +318,7 @@ without undue conversion penalties.

-@@ -261,7 +257,7 @@ contents of an __index table (if any) may be modified +@@ -125,7 +121,7 @@ separated by semicolons. The trailing semicolon for a single + declaration may be omitted. +

+

+-Please note that external symbols are only declared, but they ++Please note, that external symbols are only declared, but they + are not bound to any specific address, yet. Binding is + achieved with C library namespaces (see below). +

+@@ -213,7 +209,7 @@ parse the cdecl only once and get its ctype with + ffi.typeof(). Then use the ctype as a constructor repeatedly. +

+

+-Please note that an anonymous struct declaration implicitly ++Please note, that an anonymous struct declaration implicitly + creates a new and distinguished ctype every time you use it for + ffi.new(). This is probably not what you want, + especially if you create more than one cdata object. Different anonymous +@@ -260,12 +256,12 @@ afterwards. Neither the contents of the metatable nor the + contents of an __index table (if any) may be modified afterwards. The associated metatable automatically applies to all uses of this type, no matter how the objects are created or where they - originate from. Note that pre-defined operations on types have +-originate from. Note that pre-defined operations on types have -precedence (e.g. declared field names cannot be overriden). ++originate from. Note that predefined operations on types have +precedence (e.g. declared field names cannot be overridden).

All standard Lua metamethods are implemented. These are called directly, +-without shortcuts and on any mix of types. For binary operations, the ++without shortcuts, and on any mix of types. For binary operations, the + left operand is checked first for a valid ctype metamethod. The + __gc metamethod only applies to struct/union + types and performs an implicit ffi.gc() @@ -469,6 +465,8 @@ otherwise. The following parameters are currently defined: winWindows variant of the standard ABI @@ -2015,17 +2131,26 @@ index 91af2e1d..061cc42a 100644 gc6464 bit GC references +@@ -494,7 +492,7 @@ have some extra methods: +

+ Free the resources associated with a callback. The associated Lua + function is unanchored and may be garbage collected. The callback +-function pointer is no longer valid and must not be called anymore ++function pointer is no longer valid and must not be called again + (it may be reused by a subsequently created callback). +

+ @@ -560,7 +558,7 @@ named i.
-@@ -678,7 +674,7 @@ through unions is explicitly detected and allowed. +@@ -92,7 +88,7 @@ footprint. It's used by the ffi.* library + functions to declare C types or external symbols. +

+

+-It's only purpose is to parse C declarations, as found e.g. in ++Its only purpose is to parse C declarations, as found e.g. in + C header files. Although it does evaluate constant expressions, + it's not a C compiler. The body of inline + C function definitions is simply ignored. +@@ -169,7 +165,7 @@ function declarations. + + +

+-The following C types are pre-defined by the C parser (like ++The following C types are predefined by the C parser (like + a typedef, except re-declarations will be ignored): +

+
    +@@ -587,9 +583,9 @@ ffi.new("struct nested", {x=1,y={2,3}}) --> x = 1, y.a = 2, y.b = 3 + +

    Operations on cdata Objects

    +

    +-All of the standard Lua operators can be applied to cdata objects or a ++All standard Lua operators can be applied to cdata objects or a + mix of a cdata object and another Lua object. The following list shows +-the pre-defined operations. ++the predefined operations. +

    +

    + Reference types are dereferenced before performing each of +@@ -597,7 +593,7 @@ the operations below — the operation is applied to the + C type pointed to by the reference. +

    +

    +-The pre-defined operations are always tried first before deferring to a ++The predefined operations are always tried first before deferring to a + metamethod or index table (if any) for the corresponding ctype (except + for __new). An error is raised if the metamethod lookup or + index table lookup fails. +@@ -647,7 +643,7 @@ assigning to an index of a vector raises an error. +

+

+ A ctype object can be indexed with a string key, too. The only +-pre-defined operation is reading scoped constants of ++predefined operation is reading scoped constants of + struct/union types. All other accesses defer + to the corresponding metamethods or index tables (if any). +

+@@ -660,7 +656,7 @@ certain optimizations. +

+ As a consequence, the elements of complex numbers and + vectors are immutable. But the elements of an aggregate holding these +-types may be modified of course. I.e. you cannot assign to ++types may be modified, of course. I.e. you cannot assign to + foo.c.im, but you can assign a (newly created) complex number + to foo.c. +

+@@ -678,9 +674,9 @@ through unions is explicitly detected and allowed. constructor. This is equivalent to ffi.new(ct, ...), unless a __new metamethod is defined. The __new metamethod is called with the ctype object -plus any other arguments passed to the contructor. Note that you have to +-use ffi.new inside of it, since calling ct(...) would +-cause infinite recursion. +plus any other arguments passed to the constructor. Note that you have to - use ffi.new inside of it, since calling ct(...) would - cause infinite recursion. ++use ffi.new inside the metamethod, since calling ct(...) ++would cause infinite recursion. + +
  • C function call: a cdata function or cdata function + pointer can be called. The passed arguments are +@@ -691,7 +687,7 @@ variable argument part of vararg C function use + C function is called and the return value (if any) is + converted to a Lua object.
    + On Windows/x86 systems, __stdcall functions are automatically +-detected and a function declared as __cdecl (the default) is ++detected, and a function declared as __cdecl (the default) is + silently fixed up after the first call.
  • + + +@@ -701,7 +697,7 @@ silently fixed up after the first call. + +
  • Pointer arithmetic: a cdata pointer/array and a cdata + number or a Lua number can be added or subtracted. The number must be +-on the right hand side for a subtraction. The result is a pointer of ++on the right-hand side for a subtraction. The result is a pointer of + the same type with an address plus or minus the number value + multiplied by the element size in bytes. An error is raised if the + element size is undefined.
  • +@@ -716,7 +712,7 @@ operators (+ - * / % ^ and unary + minus) can be applied to two cdata numbers, or a cdata number and a + Lua number. If one of them is an uint64_t, the other side is + converted to an uint64_t and an unsigned arithmetic operation +-is performed. Otherwise both sides are converted to an ++is performed. Otherwise, both sides are converted to an + int64_t and a signed arithmetic operation is performed. The + result is a boxed 64 bit cdata object.
    + +@@ -763,7 +759,7 @@ which is compatible with any other pointer type. +
  • 64 bit integer comparison: two cdata numbers, or a + cdata number and a Lua number can be compared with each other. If one + of them is an uint64_t, the other side is converted to an +-uint64_t and an unsigned comparison is performed. Otherwise ++uint64_t and an unsigned comparison is performed. Otherwise, + both sides are converted to an int64_t and a signed + comparison is performed.
    + +@@ -788,9 +784,9 @@ keys! + A cdata object is treated like any other garbage-collected object and + is hashed and compared by its address for table indexing. Since + there's no interning for cdata value types, the same value may be +-boxed in different cdata objects with different addresses. Thus ++boxed in different cdata objects with different addresses. Thus, + t[1LL+1LL] and t[2LL] usually do not point to +-the same hash slot and they certainly do not point to the same ++the same hash slot, and they certainly do not point to the same + hash slot as t[2]. +

    +

    +@@ -812,7 +808,7 @@ the resulting Lua number as a key when indexing tables.
    + One obvious benefit: t[tonumber(2LL)] does point to + the same slot as t[2].

  • + +-
  • Otherwise use either tostring() on 64 bit integers ++
  • Otherwise, use either tostring() on 64 bit integers + or complex numbers or combine multiple fields of a cdata aggregate to + a Lua string (e.g. with + ffi.string()). Then +@@ -820,7 +816,7 @@ use the resulting Lua string as a key when indexing tables.
  • + +
  • Create your own specialized hash table implementation using the + C types provided by the FFI library, just like you would in +-C code. Ultimately this may give much better performance than the ++C code. Ultimately, this may give much better performance than the + other alternatives or what a generic by-value hash table could + possibly provide.
  • @@ -864,7 +860,7 @@ place of a type, you'd need to use ffi.typeof("int") instead.

    @@ -2106,6 +2358,100 @@ index 800b6b18..fef39c32 100644 similar to what can be achieved with C++ template metaprogramming. Another use case are derived types of anonymous structs, which avoids pollution of the global struct namespace. +@@ -886,7 +882,7 @@ garbage collector will automatically free the memory used by it (at + the end of the next GC cycle). +

    +

    +-Please note that pointers themselves are cdata objects, however they ++Please note, that pointers themselves are cdata objects, however they + are not followed by the garbage collector. So e.g. if you + assign a cdata array to a pointer, you must keep the cdata object + holding the array alive as long as the pointer is still in use: +@@ -935,18 +931,18 @@ of the function pointer and the Lua function object (closure). +

    +

    + This can happen implicitly due to the usual conversions, e.g. when +-passing a Lua function to a function pointer argument. Or you can use ++passing a Lua function to a function pointer argument. Or, you can use + ffi.cast() to explicitly cast a Lua function to a + C function pointer. +

    +

    +-Currently only certain C function types can be used as callback ++Currently, only certain C function types can be used as callback + functions. Neither C vararg functions nor functions with + pass-by-value aggregate argument or result types are supported. There +-are no restrictions for the kind of Lua functions that can be called ++are no restrictions on the kind of Lua functions that can be called + from the callback — no checks for the proper number of arguments + are made. The return value of the Lua function will be converted to the +-result type and an error will be thrown for invalid conversions. ++result type, and an error will be thrown for invalid conversions. +

    +

    + It's allowed to throw errors across a callback invocation, but it's not +@@ -1007,7 +1003,7 @@ convention cannot be automatically detected, unlike for + __stdcall calls to Windows functions. +

    +

    +-For some use cases it's necessary to free up the resources or to ++For some use cases, it's necessary to free up the resources or to + dynamically redirect callbacks. Use an explicit cast to a + C function pointer and keep the resulting cdata object. Then use + the cb:free() +@@ -1060,7 +1056,7 @@ GUI application, which waits for user input most of the time, anyway. +

    +

    + For new designs avoid push-style APIs: a C function repeatedly +-calling a callback for each result. Instead use pull-style APIs: ++calling a callback for each result. Instead, use pull-style APIs: + call a C function repeatedly to get a new result. Calls from Lua + to C via the FFI are much faster than the other way round. Most well-designed + libraries already use pull-style APIs (read/write, get/put). +@@ -1079,7 +1075,7 @@ function. +

    +

    + Indexing a C library namespace object with a symbol name (a Lua +-string) automatically binds it to the library. First the symbol type ++string) automatically binds it to the library. First, the symbol type + is resolved — it must have been declared with + ffi.cdef. Then the + symbol address is resolved by searching for the symbol name in the +@@ -1134,7 +1130,7 @@ Performance notice: the JIT compiler specializes to the identity of + namespace objects and to the strings used to index it. This + effectively turns function cdata objects into constants. It's not + useful and actually counter-productive to explicitly cache these +-function objects, e.g. local strlen = ffi.C.strlen. OTOH it ++function objects, e.g. local strlen = ffi.C.strlen. OTOH, it + is useful to cache the namespace itself, e.g. local C = + ffi.C. +

    +@@ -1159,14 +1155,14 @@ This behavior is inevitable, since the goal is to provide full + interoperability with C code. Adding extra safety measures, like + bounds checks, would be futile. There's no way to detect + misdeclarations of C functions, since shared libraries only +-provide symbol names, but no type information. Likewise there's no way ++provide symbol names, but no type information. Likewise, there's no way + to infer the valid range of indexes for a returned pointer. +

    +

    + Again: the FFI library is a low-level library. This implies it needs + to be used with care, but it's flexibility and performance often + outweigh this concern. If you're a C or C++ developer, it'll be easy +-to apply your existing knowledge. OTOH writing code for the FFI ++to apply your existing knowledge. OTOH, writing code for the FFI + library is not for the faint of heart and probably shouldn't be the + first exercise for someone with little experience in Lua, C or C++. +

    +@@ -1194,7 +1190,7 @@ currently incomplete: +
  • C declarations are not passed through a C pre-processor, + yet.
  • +
  • The C parser is able to evaluate most constant expressions +-commonly found in C header files. However it doesn't handle the ++commonly found in C header files. However, it doesn't handle the + full range of C expression semantics and may fail for some + obscure constructs.
  • +
  • static const declarations only work for integer types @@ -1225,7 +1221,7 @@ suboptimal performance, especially when used in inner loops:
  • Table initializers.
  • Initialization of nested struct/union types.
  • @@ -2120,12 +2466,12 @@ index 800b6b18..fef39c32 100644
    +@@ -89,7 +85,7 @@ of its functions: + local ffi = require("ffi") + +

    +-Please note this doesn't define an ffi variable in the table ++Please note, this doesn't define an ffi variable in the table + of globals — you really need to use the local variable. The + require function ensures the library is only loaded once. +

    +@@ -198,7 +194,7 @@ don't need to declare them as such. + The poll() + function takes a couple more arguments we're not going to use. You can + simply use nil to pass a NULL pointer and 0 +-for the nfds parameter. Please note that the ++for the nfds parameter. Please note, that the + number 0 does not convert to a pointer value, + unlike in C++. You really have to pass pointers to pointer arguments + and numbers to number arguments. @@ -222,7 +218,7 @@ a fascinating best-selling game is left as an exercise for the reader.

    Accessing the zlib Compression Library

    @@ -2197,7 +2561,19 @@ index 36500664..ca71be4d 100644 We'll define two convenience wrapper functions that take a string and compress or uncompress it to another string:

    -@@ -305,7 +301,7 @@ comes pre-installed. Since ffi.load() automatically adds any +@@ -295,17 +291,17 @@ Here's the step-by-step explanation: +

    + This defines some of the + C functions provided by zlib. For the sake of this example, some +-type indirections have been reduced and it uses the pre-defined ++type indirections have been reduced and it uses the predefined + fixed-size integer types, while still adhering to the zlib API/ABI. +

    +

    + This loads the zlib shared +-library. On POSIX systems it's named libz.so and usually ++library. On POSIX systems, it's named libz.so and usually + comes pre-installed. Since ffi.load() automatically adds any missing standard prefixes/suffixes, we can simply load the "z" library. On Windows it's named zlib1.dll and you'll have to download it first from the @@ -2206,17 +2582,87 @@ index 36500664..ca71be4d 100644 ffi.os makes sure we pass the right name to ffi.load().

    +@@ -328,7 +324,7 @@ actual length that was used. +

    + In C you'd pass in the address of a local variable + (&buflen). But since there's no address-of operator in +-Lua, we'll just pass in a one-element array. Conveniently it can be ++Lua, we'll just pass in a one-element array. Conveniently, it can be + initialized with the maximum buffer size in one step. Calling the + actual zlib.compress2 function is then straightforward. +

    +@@ -352,7 +348,7 @@ for garbage collection and string interning. + The uncompress + functions does the exact opposite of the compress function. + The compressed data doesn't include the size of the original string, +-so this needs to be passed in. Otherwise no surprises here. ++so this needs to be passed in. Otherwise, no surprises here. +

    +

    + The code, that makes use +@@ -386,7 +382,7 @@ Ok, so the ffi.* functions generally accept cdata objects + wherever you'd want to use a number. That's why we get a away with + passing n to ffi.string() above. But other Lua + library functions or modules don't know how to deal with this. So for +-maximum portability one needs to use tonumber() on returned ++maximum portability, one needs to use tonumber() on returned + long results before passing them on. Otherwise the + application might work on some systems, but would fail in a POSIX/x64 + environment. +@@ -458,7 +454,7 @@ the origin. +

    +

    + If we run out of operators, we can +-define named methods, too. Here the __index table defines an ++define named methods, too. Here, the __index table defines an + area function. For custom indexing needs, one might want to + define __index and __newindex functions instead. +

    +@@ -472,13 +468,13 @@ be used e.g. to create an array of points. The metamethods automatically + apply to any and all uses of this type. +

    +

    +-Please note that the association with a metatable is permanent and ++Please note, that the association with a metatable is permanent and + the metatable must not be modified afterwards! Ditto for the + __index table. +

    +

    + Here are some simple usage examples +-for the point type and their expected results. The pre-defined ++for the point type and their expected results. The predefined + operations (such as a.x) can be freely mixed with the newly + defined metamethods. Note that area is a method and must be + called with the Lua syntax for methods: a:area(), not +@@ -487,7 +483,7 @@ called with the Lua syntax for methods: a:area(), not +

    + The C type metamethod mechanism is most useful when used in + conjunction with C libraries that are written in an object-oriented +-style. Creators return a pointer to a new instance and methods take an ++style. Creators return a pointer to a new instance, and methods take an + instance pointer as the first argument. Sometimes you can just point + __index to the library namespace and __gc to the + destructor and you're done. But often enough you'll want to add +@@ -573,7 +569,7 @@ end + +

    + This turns them into indirect calls and generates bigger and slower +-machine code. Instead you'll want to cache the namespace itself and ++machine code. Instead, you'll want to cache the namespace itself and + rely on the JIT compiler to eliminate the lookups: +

    +
     @@ -593,7 +589,7 @@ it to a local variable in the function scope is unnecessary.
      
    -@@ -153,7 +149,7 @@ Contains the target OS name: +@@ -153,12 +149,12 @@ Contains the target OS name:

    jit.arch

    Contains the target architecture name: @@ -2287,17 +2733,32 @@ index e4088bcb..6dd54c70 100644

    jit.opt.* — JIT compiler optimization control

    +

    +-This sub-module provides the backend for the -O command line ++This submodule provides the backend for the -O command line + option. +

    +

    +@@ -178,7 +174,7 @@ which was one of the ways to enable optimization. + +

    jit.util.* — JIT compiler introspection

    +

    +-This sub-module holds functions to introspect the bytecode, generated ++This submodule holds functions to introspect the bytecode, generated + traces, the IR and the generated machine code. The functionality + provided by this module is still in flux and therefore undocumented. +

    @@ -191,7 +187,7 @@ if you want to know more.
    +@@ -162,7 +158,7 @@ To see how much time is spent in different VM states or + Combinations of v/z with f/F/l produce two-level + views, e.g. -jp=vf or -jp=fv. This shows the time + spent in a VM state or zone vs. hotspots. This can be used to answer +-questions like "Which time consuming functions are only interpreted?" or ++questions like "Which time-consuming functions are only interpreted?" or + "What's the garbage collector overhead for a specific function?". +

    +

    +@@ -221,7 +217,7 @@ local profile = require("jit.profile") + This module can be used to implement your own higher-level profiler. + A typical profiling run starts the profiler, captures stack dumps in + the profiler callback, adds them to a hash table to aggregate the number +-of samples, stops the profiler and then analyzes all of the captured ++of samples, stops the profiler and then analyzes all captured + stack dumps. Other parameters can be sampled in the profiler callback, + too. But it's important not to spend too much time in the callback, + since this may skew the statistics. +@@ -275,9 +271,9 @@ returns a string with a stack dump for the thread (coroutine), + formatted according to the fmt argument: +

    +
      +-
    • p — Preserve the full path for module names. Otherwise ++
    • p — Preserve the full path for module names. Otherwise, + only the file name is used.
    • +-
    • f — Dump the function name if it can be derived. Otherwise ++
    • f — Dump the function name if it can be derived. Otherwise, + use module:line.
    • +
    • F — Ditto, but dump module:name.
    • +
    • l — Dump module:line.
    • @@ -355,7 +351,7 @@ use.