From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Schwab Newsgroups: gmane.emacs.devel Subject: Re: using libmagic in Emacs? Date: Fri, 21 Aug 2009 20:31:50 +0200 Message-ID: References: <83k50xh1m8.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1250879540 24107 80.91.229.12 (21 Aug 2009 18:32:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 21 Aug 2009 18:32:20 +0000 (UTC) Cc: Eli Zaretskii , monnier@iro.umontreal.ca, emacs-devel@gnu.org To: joakim@verona.se Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 21 20:32:12 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MeYuJ-0006Qh-G5 for ged-emacs-devel@m.gmane.org; Fri, 21 Aug 2009 20:32:11 +0200 Original-Received: from localhost ([127.0.0.1]:42521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeYuI-00013Q-M6 for ged-emacs-devel@m.gmane.org; Fri, 21 Aug 2009 14:32:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeYuD-00013J-Le for emacs-devel@gnu.org; Fri, 21 Aug 2009 14:32:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeYu9-000136-76 for emacs-devel@gnu.org; Fri, 21 Aug 2009 14:32:05 -0400 Original-Received: from [199.232.76.173] (port=54472 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeYu9-000133-18 for emacs-devel@gnu.org; Fri, 21 Aug 2009 14:32:01 -0400 Original-Received: from mail-out.m-online.net ([212.18.0.9]:51309) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MeYu2-0003RQ-Ew; Fri, 21 Aug 2009 14:31:54 -0400 Original-Received: from mail01.m-online.net (mail.m-online.net [192.168.3.149]) by mail-out.m-online.net (Postfix) with ESMTP id 6A4FC1C155AC; Fri, 21 Aug 2009 20:31:52 +0200 (CEST) Original-Received: from localhost (dynscan2.mnet-online.de [192.168.1.215]) by mail.m-online.net (Postfix) with ESMTP id 1C13790483; Fri, 21 Aug 2009 20:31:52 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Original-Received: from mail.mnet-online.de ([192.168.3.149]) by localhost (dynscan2.mnet-online.de [192.168.1.215]) (amavisd-new, port 10024) with ESMTP id cdfJ1Ku01ebC; Fri, 21 Aug 2009 20:31:51 +0200 (CEST) Original-Received: from igel.home (DSL01.83.171.166.81.ip-pool.NEFkom.net [83.171.166.81]) by mail.mnet-online.de (Postfix) with ESMTP; Fri, 21 Aug 2009 20:31:50 +0200 (CEST) Original-Received: by igel.home (Postfix, from userid 501) id C18CD10C499; Fri, 21 Aug 2009 20:31:50 +0200 (CEST) X-Yow: I want to TAKE IT HOME and DRESS IT UP in HOT PANTS!! In-Reply-To: (joakim@verona.se's message of "Fri, 21 Aug 2009 19:38:15 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:114485 Archived-At: joakim@verona.se writes: > +#ifdef HAVE_LIBMAGIC > +DEFUN ("libmagic-file-internal", Flibmagic_file_internal, Slibmagic_file_internal, 1,1,0, > + doc: /* Return (MIME-TYPE MIME-ENCODING DESCRIPTION) for The first doc line needs to be a complete sentence fitting in about 75 columns. You should only mention the argument here, and explain the structure of the return value in the second sentence. > + char* f = NULL; > + const char* rvs; > + Lisp_Object file_freetext; > + Lisp_Object rv; > + Lisp_Object file_mime; > + Lisp_Object file_encoding; > + > + Lisp_Object filename, absname, encoded_absname; > + struct gcpro gcpro1; > + > + GCPRO1 (f); You cannot GCPRO pointers, only Lisp_Objects. > + if (STRINGP (filename_or_buffer)) > + filename = filename_or_buffer; > + if (BUFFERP (filename_or_buffer)) > + filename = XBUFFER (filename_or_buffer)->filename; > + absname = Fexpand_file_name (filename, current_buffer->directory); > + f = SDATA(ENCODE_FILE (absname)); Since ENCODE_FILE can GC you need to protect every Lisp_Object variable used around the call, especially all that are Lisp_Strings. > + libmagic_error: > + if (cookie != NULL) magic_close (cookie); > + report_file_error("Libmagic error",Qnil); You need to make sure that errno is preserved from the failed operation and that you get a meaningful errno in the first place. Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."