From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: good examples of Emacs modules? Date: Fri, 01 Apr 2016 17:07:50 +0300 Message-ID: <8360w1toax.fsf@gnu.org> References: <56FC5E99.7090804@cs.ucla.edu> <8737r67jbo.fsf@wanadoo.es> <83a8levbaf.fsf@gnu.org> <87y48y60fi.fsf@wanadoo.es> <834mbmv95h.fsf@gnu.org> <87twjm5rc3.fsf@wanadoo.es> <83twjlu9ta.fsf@gnu.org> <87h9fl5ull.fsf@wanadoo.es> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1459519711 32642 80.91.229.3 (1 Apr 2016 14:08:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Apr 2016 14:08:31 +0000 (UTC) Cc: emacs-devel@gnu.org To: =?iso-8859-1?Q?=D3scar?= Fuentes Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Apr 01 16:08:26 2016 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 1alzkP-0004OT-OY for ged-emacs-devel@m.gmane.org; Fri, 01 Apr 2016 16:08:25 +0200 Original-Received: from localhost ([::1]:44633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alzkK-00020I-7w for ged-emacs-devel@m.gmane.org; Fri, 01 Apr 2016 10:08:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alzkG-000209-Sn for emacs-devel@gnu.org; Fri, 01 Apr 2016 10:08:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alzkB-0005B0-98 for emacs-devel@gnu.org; Fri, 01 Apr 2016 10:08:16 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:43541) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alzkB-0005Aw-5x; Fri, 01 Apr 2016 10:08:11 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2975 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1alzkA-0007xB-Gc; Fri, 01 Apr 2016 10:08:10 -0400 In-reply-to: <87h9fl5ull.fsf@wanadoo.es> (message from =?iso-8859-1?Q?=D3s?= =?iso-8859-1?Q?car?= Fuentes on Fri, 01 Apr 2016 15:25:42 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e 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:202569 Archived-At: > From: Óscar Fuentes > Date: Fri, 01 Apr 2016 15:25:42 +0200 > > Eli Zaretskii writes: > > > I think you want to wrap some kind of "handle" that is meaningful to > > libgit2 into a user-ptr object (see the existing docs about modules > > for details about these). A user-ptr object has a finalizer, a > > function that is called by GC when the object goes out of scope. > > This means that GCing the object is unpredictable, right? It's as predictable and as unpredictable as what you have with any other Lisp object. As long as the object is referenced, it will not be GC'ed. > Also, if the API uses a struct as the session object, you need to > store it somewhere and expose a pointer to it to the Elisp code; > that is, you can't put arbitrary data on the Elisp memory space. The user-ptr object is precisely the way to produce a Lisp object that holds such a pointer, so I'm not sure why you are describing this as some kind of problem: it's a solution, not a problem. You allocate memory for the struct, store the info there, then wrap the resulting pointer in user-ptr, and that's it. (The finalizer should free the memory and perform whatever other cleanup is needed.) If this is somehow problematic, please tell why.