From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Lisp object that refers to a C struct Date: Tue, 16 Oct 2012 09:11:25 -0400 Message-ID: References: <83ehkz4edw.fsf@gnu.org> <83bog33wdr.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1350393111 11107 80.91.229.3 (16 Oct 2012 13:11:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Oct 2012 13:11:51 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 16 15:11:58 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TO6w8-00074c-ID for ged-emacs-devel@m.gmane.org; Tue, 16 Oct 2012 15:11:56 +0200 Original-Received: from localhost ([::1]:50617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO6w1-00039Z-8v for ged-emacs-devel@m.gmane.org; Tue, 16 Oct 2012 09:11:49 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO6vv-000392-3z for emacs-devel@gnu.org; Tue, 16 Oct 2012 09:11:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TO6vp-00089w-6l for emacs-devel@gnu.org; Tue, 16 Oct 2012 09:11:42 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:14074) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO6vf-000888-9k; Tue, 16 Oct 2012 09:11:27 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09MCoeh/2dsb2JhbABEtBGBCIIVAQEEAVYjBQsLNBIUGA0kiBwFugmQRAOjM4FYgwU X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="201772640" Original-Received: from 76-10-135-161.dsl.teksavvy.com (HELO pastel.home) ([76.10.135.161]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 16 Oct 2012 09:11:26 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id D6CA959520; Tue, 16 Oct 2012 09:11:25 -0400 (EDT) In-Reply-To: <83bog33wdr.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 16 Oct 2012 05:53:52 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:154369 Archived-At: >> Otherwise, better define your own type so that its printed >> representation can be more helpful, indicating what it's used for > How do I define my own type? Either by adding one more lisp_misc or one more pseudovector. For either of them, you need to add the corresponding new tag to their enumeration (Lisp_Misc_Type or pvec_type). For lisp_misc you additionally need to add your entry to the union type (but make sure the first word has the same structure as the others, starting with a 16bit type and a 1bit markbit) and make sure the overall size of the union type is not increased. Then you need to add the corresponding switch branches in print.c and in alloc.c. > In particular, what to do with gcmarkbit in Lisp_Misc? The markbit represents whether or not the object you created was found by the tracing GC, so just set it like we do for the other types. The other question is "when should we free the C struct to which this new lisp_misc points"? And that depends. You could have the GC free it when it finds your lisp_misc can be freed, or you could have instead a notion of "deleted file-watcher" (like we have for buffers/windows/...) which is when the underlying C struct has been freed (but of course, this state needs to be represented, e.g. by setting the pointer to NULL, which means that you need to be able to enumerate all the file-watcher objects (or the only one, if you enforce there can only be one) corresponding to a particular C struct). Stefan