[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Be more careful when caching attribute_lists (715ac8e)
Marcel Fabian Krüger
tex at 2krueger.de
Mon Jul 12 22:34:14 CEST 2021
Repository : https://github.com/latex3/luaotfload
On branch : dev
Link : https://github.com/latex3/luaotfload/commit/715ac8e20b9b41d67531c32145fa774f831da9c8
>---------------------------------------------------------------
commit 715ac8e20b9b41d67531c32145fa774f831da9c8
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Mon Jul 12 22:34:14 2021 +0200
Be more careful when caching attribute_lists
Fixes #195.
>---------------------------------------------------------------
715ac8e20b9b41d67531c32145fa774f831da9c8
src/luaotfload-letterspace.lua | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/luaotfload-letterspace.lua b/src/luaotfload-letterspace.lua
index 993c804..ec0744f 100644
--- a/src/luaotfload-letterspace.lua
+++ b/src/luaotfload-letterspace.lua
@@ -70,7 +70,7 @@ local todirect = nodedirect.todirect
local tonode = nodedirect.tonode
local insert_node_before = nodedirect.insert_before
-local free_node = nodedirect.free
+local real_free_node = nodedirect.free
local copy_node = nodedirect.copy
local new_node = nodedirect.new
@@ -86,9 +86,25 @@ local chardata = fonthashes.characters
local otffeatures = fonts.constructors.newfeatures "otf"
local markdata
+-- For every attribute list cached in attribute_table, we have to make
+-- sure that it doesn't get deleted. Therefore attribute_cleanup maps
+-- from a node which has the attribute_list referenced in
+-- attribute_table to the key from attribute_table.
+-- Whenever a node which has an entry in attribute_cleanup is deleted,
+-- we delete the corresponding entry from attribute_table since we can
+-- no longer guarantee that it's references somewhere.
local attribute_table = {}
+local attribute_cleanup = {}
local attr = luatexbase.new_attribute("luaotfload.letterspace_done")
+local function free_node(n)
+ local k = attribute_cleanup[n]
+ if k then
+ attribute_cleanup[n], attribute_table[k] = nil
+ end
+ return real_free_node(n)
+end
+
local function getprevreal(n)
repeat
n = getprev(n)
@@ -445,6 +461,7 @@ kerncharacters = function (head)
setattributelist(start, new_attr_list)
else
setattribute(start, attr, 1)
+ attribute_cleanup[start] = attr_list
attribute_table[attr_list] = getattributelist(start)
end
end --[[if prev]]
@@ -500,7 +517,8 @@ local function enablefontkerning ( )
"kerncharacters() failed to return a valid new head")
end
- for k in next, attribute_table do attribute_table[k] = nil end
+ for k, v in next, attribute_cleanup do attribute_cleanup[k], attribute_table[v] = nil end
+ assert(not next(attribute_table))
return tonode (direct_hd)
end
More information about the latex3-commits
mailing list.