Work on reducing allocation leaks in read_number(). This is now improved, but not yet satisfactory.
This commit is contained in:
parent
e489d02069
commit
351ca5bd17
9 changed files with 275 additions and 17 deletions
|
|
@ -86,6 +86,7 @@ struct cons_pointer make_integer( int64_t value, struct cons_pointer more ) {
|
|||
struct cons_space_object *cell = &pointer2cell( result );
|
||||
cell->payload.integer.value = value;
|
||||
cell->payload.integer.more = more;
|
||||
inc_ref(result);
|
||||
}
|
||||
|
||||
debug_print( L"make_integer: returning\n", DEBUG_ALLOC );
|
||||
|
|
|
|||
15
src/init.c
15
src/init.c
|
|
@ -28,6 +28,7 @@
|
|||
#include "memory/hashmap.h"
|
||||
#include "ops/intern.h"
|
||||
#include "io/io.h"
|
||||
#include "io/fopen.h"
|
||||
#include "ops/lispops.h"
|
||||
#include "ops/meta.h"
|
||||
#include "arith/peano.h"
|
||||
|
|
@ -124,6 +125,7 @@ int main( int argc, char *argv[] ) {
|
|||
int option;
|
||||
bool dump_at_end = false;
|
||||
bool show_prompt = false;
|
||||
char * infilename = NULL;
|
||||
|
||||
setlocale( LC_ALL, "" );
|
||||
if ( io_init( ) != 0 ) {
|
||||
|
|
@ -131,7 +133,7 @@ int main( int argc, char *argv[] ) {
|
|||
exit( 1 );
|
||||
}
|
||||
|
||||
while ( ( option = getopt( argc, argv, "phdv:" ) ) != -1 ) {
|
||||
while ( ( option = getopt( argc, argv, "phdv:i:" ) ) != -1 ) {
|
||||
switch ( option ) {
|
||||
case 'd':
|
||||
dump_at_end = true;
|
||||
|
|
@ -141,6 +143,9 @@ int main( int argc, char *argv[] ) {
|
|||
print_options( stdout );
|
||||
exit( 0 );
|
||||
break;
|
||||
case 'i' :
|
||||
infilename = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
show_prompt = true;
|
||||
break;
|
||||
|
|
@ -191,8 +196,12 @@ int main( int argc, char *argv[] ) {
|
|||
fwide( stdout, 1 );
|
||||
fwide( stderr, 1 );
|
||||
fwide( sink->handle.file, 1 );
|
||||
bind_value( L"*in*", make_read_stream( file_to_url_file( stdin ),
|
||||
make_cons( make_cons
|
||||
|
||||
FILE *infile = infilename == NULL ? stdin : fopen( infilename, "r");
|
||||
|
||||
|
||||
bind_value( L"*in*", make_read_stream( file_to_url_file(infile),
|
||||
make_cons( make_cons
|
||||
( c_string_to_lisp_keyword
|
||||
( L"url" ),
|
||||
c_string_to_lisp_string
|
||||
|
|
|
|||
|
|
@ -330,17 +330,20 @@ struct cons_pointer read_number( struct stack_frame *frame,
|
|||
debug_print( L"read_number: ratio slash seen\n",
|
||||
DEBUG_IO );
|
||||
dividend = result;
|
||||
|
||||
result = make_integer( 0, NIL );
|
||||
}
|
||||
break;
|
||||
case LCOMMA:
|
||||
// silently ignore comma.
|
||||
break;
|
||||
default:
|
||||
result = add_integers( multiply_integers( result, base ),
|
||||
make_integer( ( int ) c - ( int ) '0',
|
||||
NIL ) );
|
||||
{
|
||||
struct cons_pointer digit = make_integer( ( int ) c - ( int ) '0',
|
||||
NIL );
|
||||
struct cons_pointer new_result = add_integers( multiply_integers( result, base ),
|
||||
digit );
|
||||
dec_ref( result);
|
||||
dec_ref( digit);
|
||||
result = new_result;
|
||||
|
||||
debug_printf( DEBUG_IO,
|
||||
L"read_number: added character %c, result now ",
|
||||
|
|
@ -351,6 +354,7 @@ struct cons_pointer read_number( struct stack_frame *frame,
|
|||
if ( seen_period ) {
|
||||
places_of_decimals++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -360,13 +364,14 @@ struct cons_pointer read_number( struct stack_frame *frame,
|
|||
url_ungetwc( c, input );
|
||||
|
||||
if ( seen_period ) {
|
||||
debug_print( L"read_number: converting result to real\n", DEBUG_IO );
|
||||
struct cons_pointer div = make_ratio( result,
|
||||
make_integer( powl
|
||||
( to_long_double
|
||||
( base ),
|
||||
struct cons_pointer divisor = make_integer( powl( to_long_double( base ),
|
||||
places_of_decimals ),
|
||||
NIL ) );
|
||||
NIL );
|
||||
debug_print( L"read_number: converting result to real\n", DEBUG_IO );
|
||||
|
||||
struct cons_pointer div = make_ratio( result,
|
||||
divisor);
|
||||
dec_ref( divisor);
|
||||
inc_ref( div );
|
||||
|
||||
result = make_real( to_long_double( div ) );
|
||||
|
|
@ -378,15 +383,19 @@ struct cons_pointer read_number( struct stack_frame *frame,
|
|||
}
|
||||
|
||||
if ( neg ) {
|
||||
struct cons_pointer negt = negative( result );
|
||||
debug_print( L"read_number: converting result to negative\n",
|
||||
DEBUG_IO );
|
||||
|
||||
result = negative( result );
|
||||
dec_ref( result);
|
||||
result = negt;
|
||||
}
|
||||
|
||||
debug_print( L"read_number returning\n", DEBUG_IO );
|
||||
debug_dump_object( result, DEBUG_IO );
|
||||
|
||||
dec_ref( base);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue