From e523504424cf3b1e0e6f0b9491911f4bcb5550e3 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sun, 10 Dec 2006 03:11:04 +0000 Subject: [PATCH] Add .cached to struct document This allows code to use document->cached instead of find_in_cache(document->uri), thereby increasing the likelihood of getting the correct cache entry. This should fix Bug 756 - "assertion (cached)->object.refcount >= 0 failed" after HTTP proxy was changed. Patches for this were written by me and then later by Jonas. This commit combines our independent implementations. --- src/dialogs/status.c | 6 ++---- src/document/document.c | 17 +++++------------ src/document/document.h | 1 + src/viewer/text/draw.c | 5 +++-- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/dialogs/status.c b/src/dialogs/status.c index 3c37acefe..cd73a042c 100644 --- a/src/dialogs/status.c +++ b/src/dialogs/status.c @@ -503,10 +503,8 @@ display_window_title(struct session *ses, struct terminal *term) static inline void display_leds(struct session *ses, struct session_status *status) { - if (ses->doc_view && ses->doc_view->document - && ses->doc_view->document->uri) { - struct cache_entry *cached = - find_in_cache(ses->doc_view->document->uri); + if (ses->doc_view && ses->doc_view->document) { + struct cache_entry *cached = ses->doc_view->document->cached; if (cached) { if (cached->ssl_info) diff --git a/src/document/document.c b/src/document/document.c index f8ca3668c..966b8093f 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -46,6 +46,7 @@ init_document(struct cache_entry *cached, struct document_options *options) object_lock(cached); document->id = cached->id; + document->cached = cached; init_list(document->forms); init_list(document->tags); @@ -106,19 +107,14 @@ done_link_members(struct link *link) void done_document(struct document *document) { - struct cache_entry *cached; - assert(document); if_assert_failed return; assertm(!is_object_used(document), "Attempt to free locked formatted data."); if_assert_failed return; - cached = find_in_cache(document->uri); - if (!cached) - INTERNAL("no cache entry for document"); - else - object_unlock(cached); + assert(document->cached); + object_unlock(document->cached); if (document->uri) done_uri(document->uri); mem_free_if(document->title); @@ -270,17 +266,14 @@ shrink_format_cache(int whole) int format_cache_entries = 0; foreachsafe (document, next, format_cache) { - struct cache_entry *cached; - if (is_object_used(document)) continue; format_cache_entries++; /* Destroy obsolete renderer documents which are already * out-of-sync. */ - cached = find_in_cache(document->uri); - assertm(cached, "cached formatted document has no cache entry"); - if (cached->id == document->id) continue; + if (document->cached->id == document->id) + continue; done_document(document); format_cache_entries--; diff --git a/src/document/document.h b/src/document/document.h index ad2944c5d..4ea7781bb 100644 --- a/src/document/document.h +++ b/src/document/document.h @@ -169,6 +169,7 @@ struct document { struct uri *uri; unsigned char *title; + struct cache_entry *cached; struct frame_desc *frame; struct frameset_desc *frame_desc; /* RENAME ME */ diff --git a/src/viewer/text/draw.c b/src/viewer/text/draw.c index 4a1c0f62c..c3dbff400 100644 --- a/src/viewer/text/draw.c +++ b/src/viewer/text/draw.c @@ -64,9 +64,10 @@ check_document_fragment(struct session *ses, struct document_view *doc_view) /* Omit the leading '#' when calling find_tag. */ vy = find_tag(document, fragment.source + 1, fragment.length - 1); if (vy == -1) { - struct cache_entry *cached = find_in_cache(document->uri); + struct cache_entry *cached = document->cached; - if (!cached || cached->incomplete || cached->id != document->id) { + assert(cached); + if (cached->incomplete || cached->id != document->id) { done_string(&fragment); return -2; }