Skip to content

Commit 82957fd

Browse files
committed
yacc: correct a few mistakes
1 parent 6ff6caa commit 82957fd

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

bld/yacc/c/alloc.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void MemFini( void )
7575
{
7676
#ifdef TRMEM
7777
if( memHandle != NULL ) {
78-
_trmem_prt_list( memHandle );
78+
_trmem_prt_list_ex( memHandle, 100 );
7979
_trmem_close( memHandle );
8080
if( memFile != NULL ) {
8181
fclose( memFile );
@@ -107,11 +107,16 @@ void *YaccCalloc( size_t n, size_t size )
107107
{
108108
void *ptr;
109109

110-
ptr = YaccAlloc( n * size );
110+
size *= n;
111+
#ifdef TRMEM
112+
ptr = _trmem_alloc( size, _trmem_guess_who(), memHandle );
113+
#else
114+
ptr = malloc( size );
115+
#endif
111116
if( ptr == NULL ) {
112117
msg( "Out of memory\n" );
113118
}
114-
memset( ptr, 0, n * size );
119+
memset( ptr, 0, size );
115120
return( ptr );
116121
}
117122

@@ -144,6 +149,7 @@ void YaccFree( void *ptr )
144149
}
145150

146151
char *YaccStrDup( const char *str )
152+
/*********************************/
147153
{
148154
size_t size;
149155
char *ptr;

bld/yacc/c/lalr1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,11 @@ void lalr1( void )
523523
puts( "internal error" );
524524
}
525525
FREE( stk );
526+
FREE( look );
526527
Conflict();
527528
nbstate = nstate;
528-
FreeSet( rset );
529-
FreeSet( lset );
530-
FREE( look );
529+
// FreeSet( rset );
530+
// FreeSet( lset );
531531
}
532532

533533
void showstates( void )

bld/yacc/c/sentence.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
#include "yaccins.h"
3939
#include "alloc.h"
4040

41-
typedef struct traceback traceback;
42-
struct traceback {
43-
traceback *next;
44-
a_state *state;
45-
a_sym *sym;
46-
};
41+
42+
typedef struct traceback {
43+
struct traceback *next;
44+
a_state *state;
45+
a_sym *sym;
46+
} traceback;
4747

4848
static void pushTrace( traceback **h, a_state *state, a_sym *sym )
4949
{
@@ -60,8 +60,7 @@ static void popTrace( traceback **h )
6060
{
6161
traceback *token;
6262

63-
token = *h;
64-
if( token != NULL ) {
63+
if( (token = *h) != NULL ) {
6564
*h = token->next;
6665
FREE( token );
6766
}

bld/yacc/c/yacc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "alloc.h"
3939
#include "walloca.h"
4040

41+
4142
FILE *yaccin;
4243
char *loadpath;
4344
char *srcname_norm = NULL;
@@ -236,7 +237,7 @@ static char *fname_normalize( char *name )
236237
char *p;
237238
char *dst;
238239

239-
p = dst = malloc( strlen( name ) + 1 );
240+
p = dst = MALLOC( strlen( name ) + 1, char );
240241
while( (c = *name++) != '\0' ) {
241242
if( c == '\\' )
242243
c = '/';
@@ -318,7 +319,7 @@ int main( int argc, char **argv )
318319
loadpath = argv[0];
319320
*getname( loadpath ) = '\0';
320321
srcname = argv[i];
321-
if( !strrchr( srcname, '.' ) ) {
322+
if( strrchr( srcname, '.' ) == NULL ) {
322323
srcname = alloca( strlen( argv[i] )+3 );
323324
srcname = strcat( strcpy( srcname, argv[i] ), ".y" );
324325
}

bld/yacc/h/alloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include <stdlib.h>
3838

3939
#define MALLOC(n,t) ((t *)YaccAlloc((n) * sizeof(t)))
40-
#define REALLOC(p,n,t) ((t *)YaccRealloc((char *)p,(n) * sizeof(t)))
40+
#define REALLOC(p,n,t) ((t *)YaccRealloc((p),(n) * sizeof(t)))
4141
#define CALLOC(n,t) ((t *)YaccCalloc((n),sizeof(t)))
4242
#define FREE(n) YaccFree((n))
4343
#define STRDUP(p) YaccStrDup((p))

0 commit comments

Comments
 (0)