all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#14005: 24.3.50; cc-mode: Incorrectly-indented C code (wrong syntax). Test case and bisection.
@ 2013-03-20  8:48 Dima Kogan
  2015-12-24 21:47 ` Alan Mackenzie
  0 siblings, 1 reply; 2+ messages in thread
From: Dima Kogan @ 2013-03-20  8:48 UTC (permalink / raw)
  To: 14005

[-- Attachment #1: Type: text/plain, Size: 1999 bytes --]

I'm observing very uninteresting-looking C code get
incorrectly-indented. The sample source file (attached) ends with the
following function:

 static Matrix *NonMaximalSuppression(Matrix *strength, Matrix *orientation)
 {
   int x, y, i, rows = strength->rows, cols = strength->cols;
   int pixels = strength->rows * strength->cols, maximum;
   double str1, str2;              /* interpolated edge strength */
   double a1, a2, b1, b2, c1, c2;  /* nearest pixels' edge strength */
   float ux, uy;                   /* weights of a, b, c, and str */
   double ori, str;       /* strength and orientation at center */
   Matrix *newstrength;

   /* Newstrength holds the NMS'ed strength values */
   newstrength = (Matrix *)malloc(sizeof(Matrix));
   newstrength->rows = strength->rows;
   newstrength->sheets = 1;
   newstrength->cols = strength->cols;
   newstrength->ptr = (double *)calloc(pixels, sizeof(double));

   return(newstrength);
 }

I'm observing that everything after the /* Newstrength .... */ comment
gets "string" syntax, which is incorrect. This can be seen with
(c-guess-basic-syntax). This also causes incorrect indentation of the
empty line before the return statement (TAB there should move to column
2, but it stays at 0).

The full test source file is attached (called "tst.c"). This is a slight
modification of the source from http://ai.stanford.edu/~ruzon/compass/.
This test case is much longer than I'd like, but the bug appears to be
very sensitive to preceding code, so I'm leaving it alone.

To observe the issue, you can run

 $ emacs -Q --batch --eval '(progn (find-file "/tmp/tst.c") (goto-char
 6072) (message "%s" (c-guess-basic-syntax)))

The right answer is "statement", but the current version of emacs says
"string". I did a bisection. This problem was introduced in early 2012
with this commit:

http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=b0b68fedb6a6fe7bc55c1fe4f256bda9a93134b5

This means that all releases of emacs 24 are affected.

Thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test case --]
[-- Type: text/x-csrc, Size: 6313 bytes --]

/***************************************************************************
 * The Greyscale Compass Operator -- an algorithm to find edges in         *
 *   greyscale images by representing regions with distributions           *
 *                                                                         *
 * Mark A. Ruzon                                                           *
 * Stanford Vision Laboratory                                              *
 * October, 1997                                                           *
 * Copyright 1997-1999.  All rights reserved.                              *
 *                                                                         *
 * Details -- The compass operator uses a circular window centered at a    *
 *   junction where 4 pixel squares meet.  The needle is a diameter at a   *
 *   given orientation.  The intensity distributions of the two            *
 *   semicircles are computed, and the distance between them is measured   *
 *   using the Earth Mover's Distance (EMD).  The maximum EMD over all     *
 *   orientations gives the edge strength and orientation at that point.   *
 *   Uncertainty and abnormality are also measured.                        *
 *                                                                         *
 * This file contains the Unix wrapper for the compass operator.           *
 *                                                                         *
 * 2 August 1999 -- extended for use with greyscale images                 *
 *                                                                         *
 * 7 October 1999 -- creation of the Unix wrapper.  Most of the            *
 *   functionality of the MATLAB version (e.g. subimages, spacing, plot,   *
 *   maxclusters, multiple sigmas, abnormality, uncertainty, etc.)         *
 *   is being removed.                                                     *
 *                                                                         *
 * 21 October 1999 -- allowed only compass operator and NMS routine, or    *
 *                    only thresholding, or both to be computed.           *
 ***************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <opencv2/highgui/highgui_c.h>

#include "greycompass.h"

#define MAXVAL 255
#define MAXLINE 2000
#define PI 3.14159265358979323846
#define MODEC 0x2
#define MODET 0x1

#warning this should generate an error since it should be exported
static void Error(char *text)
{
  fprintf(stderr,text);
  exit(1);
}


static void PrintHelp(char *programname)
{
  fprintf(stderr,"Function: %s <infile> <outfile> [options]\n", programname);
  fprintf(stderr,"   <infile>/<outfile> are input/output images\n");
  fprintf(stderr,"   options include:\n");
  fprintf(stderr,"   -s <sigma>, the standard deviation of the Gaussian (default 1.0)\n");
  fprintf(stderr,"   -m C|T, the mode, compass operator or thresholding (default: both)\n"); 
  fprintf(stderr,"   -l <low>, the low threshold for edge detection (default 0.5)\n");
  fprintf(stderr,"   -h <high>, the high threshold for edge detection (default 0.7)\n");
  exit(1);
}


static CvMat* readIntoMat( const char* filename, int type )
{
  CvMat* img = cvLoadImageM( filename, CV_LOAD_IMAGE_GRAYSCALE );
  if( !img ) return NULL;

  if( type == img->type )
    return img;

  CvMat* img_wantedtype = cvCreateMat( img->rows, img->cols, type );
  if( !img_wantedtype ) return NULL;

  cvConvert( img, img_wantedtype );
  cvRelease( &img );

  return img_wantedtype;
}

static void ParseArguments(int argc, char *argv[], CvMat** input,
                           double sigma[], double *low, double *high, int *mode)
{
  int curarg = 3;
  char modechar;

  if (argc < 3)
    PrintHelp(argv[0]);

  while (curarg < argc) {
    if (argv[curarg][0] == '-') {  /* New argument has appeared */
      switch(argv[curarg][1]) {
      case 's': /* Sigma */
	if (curarg < argc) {
	  sigma[0] = strtod(argv[curarg+1],NULL);
	  if (sigma[0] <= 0.0)
	    Error("Sigma must be positive\n");
	} else
	  Error("No sigma value specified\n");
	break;
      case 'l': /* Low */
	if (curarg < argc) {
	  *low = strtod(argv[curarg+1],NULL);
	  if (*low < 0.0 || *low > 1.0)
	    Error("Low threshold must lie in [0,1]\n");
	} else
	  Error("No low threshold specified\n");
	break;
      case 'h': /* High */
	if (curarg < argc) {
	  *high = strtod(argv[curarg+1],NULL);
	  if (*high < 0.0 || *high > 1.0)
	    Error("High threshold must lie in [0,1]\n");
	} else
	  Error("No high threshold specified\n");
	break;
      case 'm': /* Mode */
	if (curarg < argc) {
	  modechar = argv[curarg+1][0];
	  if (modechar == 'C' || modechar == 'c')
	    *mode = MODEC;
	  else if (modechar == 'T' || modechar == 't')
	    *mode = MODET;
	  else
	    Error("Mode must be 'C' or 'T'\n");
	} else
	  Error("No mode specified\n");
	break;	
      default: /* Help */
	fprintf(stderr,"Unrecognized command option\n");
	PrintHelp(argv[0]);
	break;
      }
      curarg += 2;
    }
  }
  if (*high < *low)
    Error("High threshold cannot be below low threshold\n");

  *input = readIntoMat( argv[1], (*mode & MODEC) ? CV_8UC1 : CV_64FC1 );
  if( ! *input )
    Error("Error reading input\n");
}


/*  NonMaximalSuppression
 *
 *  The standard Canny non-maximal suppression algorithm; looks in a 3x3
 *  neighborhood to determine if the pixel is a maximum in the direction
 *  perpendicular to that of the edge orientation.
 */
static Matrix *NonMaximalSuppression(Matrix *strength, Matrix *orientation)
{
  int x, y, i, rows = strength->rows, cols = strength->cols;
  int pixels = strength->rows * strength->cols, maximum;
  double str1, str2;              /* interpolated edge strength */
  double a1, a2, b1, b2, c1, c2;  /* nearest pixels' edge strength */
  float ux, uy;                   /* weights of a, b, c, and str */
  double ori, str;       /* strength and orientation at center */
  Matrix *newstrength;

  /* Newstrength holds the NMS'ed strength values */
  newstrength = (Matrix *)malloc(sizeof(Matrix));
  newstrength->rows = strength->rows;
  newstrength->sheets = 1;
  newstrength->cols = strength->cols;
  newstrength->ptr = (double *)calloc(pixels, sizeof(double));

  return(newstrength);
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#14005: 24.3.50; cc-mode: Incorrectly-indented C code (wrong syntax). Test case and bisection.
  2013-03-20  8:48 bug#14005: 24.3.50; cc-mode: Incorrectly-indented C code (wrong syntax). Test case and bisection Dima Kogan
@ 2015-12-24 21:47 ` Alan Mackenzie
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Mackenzie @ 2015-12-24 21:47 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 14005-done

Hello, Dima.

The problem is no longer apparent in the current emacs-25 branch at
savannah, so I'm closing this bug as fixed.

On Tue, Mar 19, 2013 at 10:48:14PM -1000, Dima Kogan wrote:
> I'm observing very uninteresting-looking C code get
> incorrectly-indented. The sample source file (attached) ends with the
> following function:

>  static Matrix *NonMaximalSuppression(Matrix *strength, Matrix *orientation)
>  {
>    int x, y, i, rows = strength->rows, cols = strength->cols;
>    int pixels = strength->rows * strength->cols, maximum;
>    double str1, str2;              /* interpolated edge strength */
>    double a1, a2, b1, b2, c1, c2;  /* nearest pixels' edge strength */
>    float ux, uy;                   /* weights of a, b, c, and str */
>    double ori, str;       /* strength and orientation at center */
>    Matrix *newstrength;

>    /* Newstrength holds the NMS'ed strength values */
>    newstrength = (Matrix *)malloc(sizeof(Matrix));
>    newstrength->rows = strength->rows;
>    newstrength->sheets = 1;
>    newstrength->cols = strength->cols;
>    newstrength->ptr = (double *)calloc(pixels, sizeof(double));

>    return(newstrength);
>  }

> I'm observing that everything after the /* Newstrength .... */ comment
> gets "string" syntax, which is incorrect. This can be seen with
> (c-guess-basic-syntax). This also causes incorrect indentation of the
> empty line before the return statement (TAB there should move to column
> 2, but it stays at 0).

> The full test source file is attached (called "tst.c"). This is a slight
> modification of the source from http://ai.stanford.edu/~ruzon/compass/.
> This test case is much longer than I'd like, but the bug appears to be
> very sensitive to preceding code, so I'm leaving it alone.

> To observe the issue, you can run

>  $ emacs -Q --batch --eval '(progn (find-file "/tmp/tst.c") (goto-char
>  6072) (message "%s" (c-guess-basic-syntax)))

> The right answer is "statement", but the current version of emacs says
> "string". I did a bisection. This problem was introduced in early 2012
> with this commit:

> http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=b0b68fedb6a6fe7bc55c1fe4f256bda9a93134b5

> This means that all releases of emacs 24 are affected.

> Thanks.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-24 21:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-20  8:48 bug#14005: 24.3.50; cc-mode: Incorrectly-indented C code (wrong syntax). Test case and bisection Dima Kogan
2015-12-24 21:47 ` Alan Mackenzie

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.