diff options
author | obrien <obrien@FreeBSD.org> | 2002-01-27 12:00:11 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2002-01-27 12:00:11 +0000 |
commit | fc89183cdc6be5afa8deb7250fd15a20832ab528 (patch) | |
tree | 5c493199a70976c54e1b9c6a7804a3de85b43e84 /contrib/binutils/bfd/opncls.c | |
parent | 94820fd8060f6f43089d1a3ddb8a482402e7e494 (diff) | |
download | FreeBSD-src-fc89183cdc6be5afa8deb7250fd15a20832ab528.zip FreeBSD-src-fc89183cdc6be5afa8deb7250fd15a20832ab528.tar.gz |
Enlist the FreeBSD-CURRENT users as testers of what is to become Binutils
version 2.12.0. These bits are taken from the FSF anoncvs repo on
27-January-2002 03:41 PST.
Diffstat (limited to 'contrib/binutils/bfd/opncls.c')
-rw-r--r-- | contrib/binutils/bfd/opncls.c | 105 |
1 files changed, 60 insertions, 45 deletions
diff --git a/contrib/binutils/bfd/opncls.c b/contrib/binutils/bfd/opncls.c index 0c3d2c9..0b285d4 100644 --- a/contrib/binutils/bfd/opncls.c +++ b/contrib/binutils/bfd/opncls.c @@ -49,7 +49,7 @@ _bfd_new_bfd () { bfd *nbfd; - nbfd = (bfd *) bfd_zmalloc (sizeof (bfd)); + nbfd = (bfd *) bfd_zmalloc ((bfd_size_type) sizeof (bfd)); if (nbfd == NULL) return NULL; @@ -57,6 +57,7 @@ _bfd_new_bfd () if (nbfd->memory == NULL) { bfd_set_error (bfd_error_no_memory); + free (nbfd); return NULL; } @@ -65,10 +66,16 @@ _bfd_new_bfd () nbfd->direction = no_direction; nbfd->iostream = NULL; nbfd->where = 0; + if (!bfd_hash_table_init (&nbfd->section_htab, bfd_section_hash_newfunc)) + { + free (nbfd); + return NULL; + } nbfd->sections = (asection *) NULL; + nbfd->section_tail = &nbfd->sections; nbfd->format = bfd_unknown; nbfd->my_archive = (bfd *) NULL; - nbfd->origin = 0; + nbfd->origin = 0; nbfd->opened_once = false; nbfd->output_has_begun = false; nbfd->section_count = 0; @@ -96,6 +103,17 @@ _bfd_new_bfd_contained_in (obfd) return nbfd; } +/* Delete a BFD. */ + +void +_bfd_delete_bfd (abfd) + bfd *abfd; +{ + bfd_hash_table_free (&abfd->section_htab); + objalloc_free ((struct objalloc *) abfd->memory); + free (abfd); +} + /* SECTION Opening and closing BFDs @@ -107,7 +125,7 @@ FUNCTION bfd_openr SYNOPSIS - bfd *bfd_openr(CONST char *filename, CONST char *target); + bfd *bfd_openr(const char *filename, const char *target); DESCRIPTION Open the file @var{filename} (using <<fopen>>) with the target @@ -122,8 +140,8 @@ DESCRIPTION bfd * bfd_openr (filename, target) - CONST char *filename; - CONST char *target; + const char *filename; + const char *target; { bfd *nbfd; const bfd_target *target_vec; @@ -135,9 +153,8 @@ bfd_openr (filename, target) target_vec = bfd_find_target (target, nbfd); if (target_vec == NULL) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); bfd_set_error (bfd_error_invalid_target); + _bfd_delete_bfd (nbfd); return NULL; } @@ -148,8 +165,7 @@ bfd_openr (filename, target) { /* File didn't exist, or some such */ bfd_set_error (bfd_error_system_call); - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -169,7 +185,7 @@ FUNCTION bfd_fdopenr SYNOPSIS - bfd *bfd_fdopenr(CONST char *filename, CONST char *target, int fd); + bfd *bfd_fdopenr(const char *filename, const char *target, int fd); DESCRIPTION <<bfd_fdopenr>> is to <<bfd_fopenr>> much like <<fdopen>> is to <<fopen>>. @@ -192,8 +208,8 @@ DESCRIPTION bfd * bfd_fdopenr (filename, target, fd) - CONST char *filename; - CONST char *target; + const char *filename; + const char *target; int fd; { bfd *nbfd; @@ -216,8 +232,7 @@ bfd_fdopenr (filename, target, fd) if (target_vec == NULL) { bfd_set_error (bfd_error_invalid_target); - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -236,8 +251,7 @@ bfd_fdopenr (filename, target, fd) if (nbfd->iostream == NULL) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -259,8 +273,7 @@ bfd_fdopenr (filename, target, fd) if (! bfd_cache_init (nbfd)) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } nbfd->opened_once = true; @@ -299,19 +312,17 @@ bfd_openstreamr (filename, target, streamarg) if (target_vec == NULL) { bfd_set_error (bfd_error_invalid_target); - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } nbfd->iostream = (PTR) stream; nbfd->filename = filename; nbfd->direction = read_direction; - + if (! bfd_cache_init (nbfd)) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -328,7 +339,7 @@ FUNCTION bfd_openw SYNOPSIS - bfd *bfd_openw(CONST char *filename, CONST char *target); + bfd *bfd_openw(const char *filename, const char *target); DESCRIPTION Create a BFD, associated with file @var{filename}, using the @@ -340,8 +351,8 @@ DESCRIPTION bfd * bfd_openw (filename, target) - CONST char *filename; - CONST char *target; + const char *filename; + const char *target; { bfd *nbfd; const bfd_target *target_vec; @@ -358,8 +369,7 @@ bfd_openw (filename, target) target_vec = bfd_find_target (target, nbfd); if (target_vec == NULL) { - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -369,8 +379,7 @@ bfd_openw (filename, target) if (bfd_open_file (nbfd) == NULL) { bfd_set_error (bfd_error_system_call); /* File not writeable, etc */ - objalloc_free ((struct objalloc *) nbfd->memory); - free (nbfd); + _bfd_delete_bfd (nbfd); return NULL; } @@ -429,7 +438,7 @@ bfd_close (abfd) if (stat (abfd->filename, &buf) == 0) { - int mask = umask (0); + unsigned int mask = umask (0); umask (mask); chmod (abfd->filename, (0777 @@ -437,8 +446,7 @@ bfd_close (abfd) } } - objalloc_free ((struct objalloc *) abfd->memory); - free (abfd); + _bfd_delete_bfd (abfd); return ret; } @@ -484,7 +492,7 @@ bfd_close_all_done (abfd) if (stat (abfd->filename, &buf) == 0) { - int mask = umask (0); + unsigned int mask = umask (0); umask (mask); chmod (abfd->filename, (0777 @@ -492,8 +500,7 @@ bfd_close_all_done (abfd) } } - objalloc_free ((struct objalloc *) abfd->memory); - free (abfd); + _bfd_delete_bfd (abfd); return ret; } @@ -503,7 +510,7 @@ FUNCTION bfd_create SYNOPSIS - bfd *bfd_create(CONST char *filename, bfd *templ); + bfd *bfd_create(const char *filename, bfd *templ); DESCRIPTION Create a new BFD in the manner of @@ -515,7 +522,7 @@ DESCRIPTION bfd * bfd_create (filename, templ) - CONST char *filename; + const char *filename; bfd *templ; { bfd *nbfd; @@ -560,9 +567,10 @@ bfd_make_writable(abfd) return false; } - bim = (struct bfd_in_memory *) bfd_malloc (sizeof (struct bfd_in_memory)); + bim = ((struct bfd_in_memory *) + bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory))); abfd->iostream = (PTR) bim; - /* bfd_write will grow these as needed */ + /* bfd_bwrite will grow these as needed */ bim->size = 0; bim->buffer = 0; @@ -613,7 +621,7 @@ bfd_make_readable(abfd) abfd->sections = (asection *) NULL; abfd->format = bfd_unknown; abfd->my_archive = (bfd *) NULL; - abfd->origin = 0; + abfd->origin = 0; abfd->opened_once = false; abfd->output_has_begun = false; abfd->section_count = 0; @@ -650,10 +658,16 @@ DESCRIPTION PTR bfd_alloc (abfd, size) bfd *abfd; - size_t size; + bfd_size_type size; { PTR ret; + if (size != (unsigned long) size) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + ret = objalloc_alloc (abfd->memory, (unsigned long) size); if (ret == NULL) bfd_set_error (bfd_error_no_memory); @@ -663,17 +677,18 @@ bfd_alloc (abfd, size) PTR bfd_zalloc (abfd, size) bfd *abfd; - size_t size; + bfd_size_type size; { PTR res; res = bfd_alloc (abfd, size); if (res) - memset (res, 0, size); + memset (res, 0, (size_t) size); return res; } -/* Free a block allocated for a BFD. */ +/* Free a block allocated for a BFD. + Note: Also frees all more recently allocated blocks! */ void bfd_release (abfd, block) |