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: Running ert tests on buffers in rst.el and elsewhere Date: Tue, 19 Jun 2012 14:06:53 -0400 Message-ID: References: <6280.1340054412@theowa.merten-home.homelinux.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1340129239 8569 80.91.229.3 (19 Jun 2012 18:07:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2012 18:07:19 +0000 (UTC) Cc: Christian Ohler , emacs-devel@gnu.org To: Stefan Merten Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 19 20:07:17 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 1Sh2pc-0000uL-Nd for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2012 20:07:12 +0200 Original-Received: from localhost ([::1]:42081 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sh2pc-0005JG-Ft for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2012 14:07:12 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sh2pZ-0005Ih-M7 for emacs-devel@gnu.org; Tue, 19 Jun 2012 14:07:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sh2pU-0000k6-Pk for emacs-devel@gnu.org; Tue, 19 Jun 2012 14:07:09 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:53730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sh2pM-0000i0-72; Tue, 19 Jun 2012 14:06:56 -0400 Original-Received: from faina.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id q5JI6r8x015876; Tue, 19 Jun 2012 14:06:53 -0400 Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 3B4EEB422C; Tue, 19 Jun 2012 14:06:53 -0400 (EDT) In-Reply-To: <6280.1340054412@theowa.merten-home.homelinux.org> (Stefan Merten's message of "Mon, 18 Jun 2012 23:20:12 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4255=0 X-NAI-Spam-Version: 2.2.0.9309 : core <4255> : streams <770542> : uri <1143611> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 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:151027 Archived-At: > I wanted to test functions which operate on buffers - i.e. use buffer > content as input and possibly modify the buffer. Buffer includes point > and mark in this case. Since I found no support for this requirement > in the ert package I wrote some support code for it. I just polished > it a bit to better fit into Emacs standards. Sounds OK. The code looks mostly OK, except: - It should either use (require 'cl-lib) or (eval-when-compile (require 'cl)). - You can use the "--" convention for internal functions/variables (e.g. use ert--equal-buffer instead of ert-equal-buffer-internal). - ert-Buf-create-string could probably use car-less-than-car if a speed boost is needed (probably not worth the trouble, tho). - the docstrings talk about "run list FOO" which is meaningless to me (a list can't be run). So describe FUNCALL a bit better (e.g. making it clear that it's expected to have the shape (FUN . ARGS)). BTW, instead of (apply (car funcall) (cdr funcall)) you can do (apply #'funcall funcall) or even (apply #'funcall #'funcall #'funcall funcall) for extra fun. Ideally, tho you should be able to just do (apply funcall). If interested, the patch below fixes `apply' to accept this use. Stefan === modified file 'src/eval.c' --- src/eval.c 2012-06-09 03:14:44 +0000 +++ src/eval.c 2012-06-19 18:02:07 +0000 @@ -2202,7 +2202,7 @@ return val; } -DEFUN ("apply", Fapply, Sapply, 2, MANY, 0, +DEFUN ("apply", Fapply, Sapply, 1, MANY, 0, doc: /* Call FUNCTION with our remaining args, using our last arg as list of args. Then return the value FUNCTION returns. Thus, (apply '+ 1 2 '(3 4)) returns 10. @@ -2213,11 +2213,10 @@ EMACS_INT numargs; register Lisp_Object spread_arg; register Lisp_Object *funcall_args; - Lisp_Object fun, retval; + Lisp_Object retval; struct gcpro gcpro1; USE_SAFE_ALLOCA; - fun = args [0]; funcall_args = 0; spread_arg = args [nargs - 1]; CHECK_LIST (spread_arg); @@ -2232,43 +2231,14 @@ return Ffuncall (nargs, args); } - numargs += nargs - 2; + numargs += nargs - 1; - /* Optimize for no indirection. */ - if (SYMBOLP (fun) && !EQ (fun, Qunbound) - && (fun = XSYMBOL (fun)->function, SYMBOLP (fun))) - fun = indirect_function (fun); - if (EQ (fun, Qunbound)) - { - /* Let funcall get the error. */ - fun = args[0]; - goto funcall; - } - - if (SUBRP (fun)) - { - if (numargs < XSUBR (fun)->min_args - || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs)) - goto funcall; /* Let funcall get the error. */ - else if (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args > numargs) - { - /* Avoid making funcall cons up a yet another new vector of arguments - by explicitly supplying nil's for optional values. */ - SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args); - for (i = numargs; i < XSUBR (fun)->max_args;) - funcall_args[++i] = Qnil; - GCPRO1 (*funcall_args); - gcpro1.nvars = 1 + XSUBR (fun)->max_args; - } - } - funcall: - /* We add 1 to numargs because funcall_args includes the - function itself as well as its arguments. */ + /* `numargs' includes the function itself as well as its arguments. */ if (!funcall_args) { - SAFE_ALLOCA_LISP (funcall_args, 1 + numargs); + SAFE_ALLOCA_LISP (funcall_args, numargs); GCPRO1 (*funcall_args); - gcpro1.nvars = 1 + numargs; + gcpro1.nvars = numargs; } memcpy (funcall_args, args, nargs * sizeof (Lisp_Object));