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 09:23:13 +0300 Message-ID: <83twjlu9ta.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> 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 1459491830 6762 80.91.229.3 (1 Apr 2016 06:23:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Apr 2016 06:23:50 +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 08:23:46 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 1alsUf-0004rS-H0 for ged-emacs-devel@m.gmane.org; Fri, 01 Apr 2016 08:23:41 +0200 Original-Received: from localhost ([::1]:36193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alsUe-0000Hf-R6 for ged-emacs-devel@m.gmane.org; Fri, 01 Apr 2016 02:23:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alsUR-0000HZ-Kk for emacs-devel@gnu.org; Fri, 01 Apr 2016 02:23:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alsUM-0004hU-Ki for emacs-devel@gnu.org; Fri, 01 Apr 2016 02:23:27 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alsUM-0004hQ-HL; Fri, 01 Apr 2016 02:23:22 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2571 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1alsUL-0000Jg-RD; Fri, 01 Apr 2016 02:23:22 -0400 In-reply-to: <87twjm5rc3.fsf@wanadoo.es> (message from =?iso-8859-1?Q?=D3s?= =?iso-8859-1?Q?car?= Fuentes on Thu, 31 Mar 2016 22:23:56 +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:202549 Archived-At: > From: Óscar Fuentes > Date: Thu, 31 Mar 2016 22:23:56 +0200 > > Some APIs are session-based. Those give the user an object that lives > through the session and needs to be disposed at the end. On the case of > VC or Magit, Emacs would request from libgit2 to work with a given repo, > operate on it and close the session. That means that if the user kills > the magit-status buffer that was visiting a repo, the associated session > object must be closed (this is a simplistic scenario, in practice things > are more complicated.) It would be nice to explain how to handle this > use case on a robust way (the failure to properly close a session, > transaction, whatever on some packages can produce very annoying > consequences.) How objects created by the module system interact with > garbage collection is an start. 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. The finalizer function should do whatever libgit2 needs to close the session and free whatever resources the session used. You have a demo if using a user-ptr in modules/mod-test/.