From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (unknown [IPv6:2602:4b:a4ef:2500:12bf:48ff:fe7c:5584]) by hurricane.the-brannons.com (Postfix) with ESMTPSA id 69393779C1 for ; Sat, 25 Jan 2014 09:21:00 -0800 (PST) From: Chris Brannon To: Edbrowse-dev@lists.the-brannons.com References: <20140025114736.eklhad@comcast.net> Date: Sat, 25 Jan 2014 09:20:42 -0800 In-Reply-To: <20140025114736.eklhad@comcast.net> (Karl Dahlke's message of "Sat, 25 Jan 2014 11:47:36 -0500") Message-ID: <871tzwou51.fsf@mushroom.PK5001Z> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Edbrowse-dev] gc rooted X-BeenThere: edbrowse-dev@lists.the-brannons.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: Edbrowse Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jan 2014 17:21:00 -0000 Karl Dahlke writes: > The guide talks about local variables, parameters, returns, > heap, but nothing about global or static. Ok, here's my suggestion. Actually I've been implementing it along with my other work on html.cpp and buffers.c. Let's get rid of the global jwin altogether. It duplicates the data in cw->jsw. There's always going to be a current edbrowse window, and that window's jsc and jsw should never go out of sync with the globals jcx and jwin. Instead of the globals, let's pack all of this JS stuff into an opaque struct on the heap, with a pointer stored in ebWindow, like so: /* file eb.h */ /* Forward decl, fully declared in js.h. */ struct ebJSState; struct ebWindow { ... struct ebJSState *jsstate; /* Struct is opaque outside js-related files. */ }; /* File js.h */ struct ebJSState { JSContext *jcx; jS::Heap jwin; JS::Heap jdoc; }; So now jdoc and jwin are rooted. We could keep using the jdoc and jwin globals, and use JS_AddObjectRoot to root them, but I think the opaque struct is the safest bet. It also eliminates void pointers. The jcx global is ok, but I'd argue for getting rid of it as well, since it just duplicates the JSContext * from the current window. -- Chris