emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using libmagic in Emacs?


From: Andreas Schwab
Subject: Re: using libmagic in Emacs?
Date: Fri, 21 Aug 2009 20:31:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

address@hidden 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, address@hidden
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]