These functions don't belong in opncls.c.
* libbfd-in.h (bfd_release): Delete prototype.
* opncls.c (bfd_alloc, bfd_zalloc, bfd_release): Move to..
* libbfd.c: ..here. Include objalloc.c and provide bfd_release
with a FUNCTION comment.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.
bool bfd_make_readable (bfd *abfd);
-void *bfd_alloc (bfd *abfd, bfd_size_type wanted);
-
-void *bfd_zalloc (bfd *abfd, bfd_size_type wanted);
-
uint32_t bfd_calc_gnu_debuglink_crc32
(uint32_t crc, const bfd_byte *buf, bfd_size_type len);
const char *bfd_set_filename (bfd *abfd, const char *filename);
/* Extracted from libbfd.c. */
+void *bfd_alloc (bfd *abfd, bfd_size_type wanted);
+
+void *bfd_zalloc (bfd *abfd, bfd_size_type wanted);
+
+void bfd_release (bfd *, void *);
+
/* Byte swapping macros for user section data. */
memcpy (buf, str, len);
return buf;
}
-/* These routines allocate and free things on the BFD's objalloc. */
-
-extern void bfd_release
- (bfd *, void *) ATTRIBUTE_HIDDEN;
extern bfd * _bfd_create_empty_archive_element_shell
(bfd *) ATTRIBUTE_HIDDEN;
#include "sysdep.h"
#include "bfd.h"
#include "libbfd.h"
+#include "objalloc.h"
#ifndef HAVE_GETPAGESIZE
#define getpagesize() 2048
return ptr;
}
+/*
+FUNCTION
+ bfd_alloc
+
+SYNOPSIS
+ void *bfd_alloc (bfd *abfd, bfd_size_type wanted);
+
+DESCRIPTION
+ Allocate a block of @var{wanted} bytes of memory attached to
+ <<abfd>> and return a pointer to it.
+*/
+
+void *
+bfd_alloc (bfd *abfd, bfd_size_type size)
+{
+ void *ret;
+ unsigned long ul_size = (unsigned long) size;
+
+ if (size != ul_size
+ /* Note - although objalloc_alloc takes an unsigned long as its
+ argument, internally the size is treated as a signed long. This can
+ lead to problems where, for example, a request to allocate -1 bytes
+ can result in just 1 byte being allocated, rather than
+ ((unsigned long) -1) bytes. Also memory checkers will often
+ complain about attempts to allocate a negative amount of memory.
+ So to stop these problems we fail if the size is negative. */
+ || ((signed long) ul_size) < 0)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ return NULL;
+ }
+
+ ret = objalloc_alloc ((struct objalloc *) abfd->memory, ul_size);
+ if (ret == NULL)
+ bfd_set_error (bfd_error_no_memory);
+ else
+ abfd->alloc_size += size;
+ return ret;
+}
+
+/*
+FUNCTION
+ bfd_zalloc
+
+SYNOPSIS
+ void *bfd_zalloc (bfd *abfd, bfd_size_type wanted);
+
+DESCRIPTION
+ Allocate a block of @var{wanted} bytes of zeroed memory
+ attached to <<abfd>> and return a pointer to it.
+*/
+
+void *
+bfd_zalloc (bfd *abfd, bfd_size_type size)
+{
+ void *res;
+
+ res = bfd_alloc (abfd, size);
+ if (res)
+ memset (res, 0, (size_t) size);
+ return res;
+}
+
+/*
+FUNCTION
+ bfd_release
+
+SYNOPSIS
+ void bfd_release (bfd *, void *);
+
+DESCRIPTION
+ Free a block allocated for a BFD.
+ Note: Also frees all more recently allocated blocks!
+*/
+
+void
+bfd_release (bfd *abfd, void *block)
+{
+ objalloc_free_block ((struct objalloc *) abfd->memory, block);
+}
+
/*
INTERNAL_FUNCTION
bfd_write_bigendian_4byte_int
memcpy (buf, str, len);
return buf;
}
-/* These routines allocate and free things on the BFD's objalloc. */
-
-extern void bfd_release
- (bfd *, void *) ATTRIBUTE_HIDDEN;
extern bfd * _bfd_create_empty_archive_element_shell
(bfd *) ATTRIBUTE_HIDDEN;
return true;
}
-/*
-FUNCTION
- bfd_alloc
-
-SYNOPSIS
- void *bfd_alloc (bfd *abfd, bfd_size_type wanted);
-
-DESCRIPTION
- Allocate a block of @var{wanted} bytes of memory attached to
- <<abfd>> and return a pointer to it.
-*/
-
-void *
-bfd_alloc (bfd *abfd, bfd_size_type size)
-{
- void *ret;
- unsigned long ul_size = (unsigned long) size;
-
- if (size != ul_size
- /* Note - although objalloc_alloc takes an unsigned long as its
- argument, internally the size is treated as a signed long. This can
- lead to problems where, for example, a request to allocate -1 bytes
- can result in just 1 byte being allocated, rather than
- ((unsigned long) -1) bytes. Also memory checkers will often
- complain about attempts to allocate a negative amount of memory.
- So to stop these problems we fail if the size is negative. */
- || ((signed long) ul_size) < 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return NULL;
- }
-
- ret = objalloc_alloc ((struct objalloc *) abfd->memory, ul_size);
- if (ret == NULL)
- bfd_set_error (bfd_error_no_memory);
- else
- abfd->alloc_size += size;
- return ret;
-}
-
-/*
-FUNCTION
- bfd_zalloc
-
-SYNOPSIS
- void *bfd_zalloc (bfd *abfd, bfd_size_type wanted);
-
-DESCRIPTION
- Allocate a block of @var{wanted} bytes of zeroed memory
- attached to <<abfd>> and return a pointer to it.
-*/
-
-void *
-bfd_zalloc (bfd *abfd, bfd_size_type size)
-{
- void *res;
-
- res = bfd_alloc (abfd, size);
- if (res)
- memset (res, 0, (size_t) size);
- return res;
-}
-
-/* Free a block allocated for a BFD.
- Note: Also frees all more recently allocated blocks! */
-
-void
-bfd_release (bfd *abfd, void *block)
-{
- objalloc_free_block ((struct objalloc *) abfd->memory, block);
-}
-
-
/*
GNU Extension: separate debug-info files