From b2a284bf2640b26639a81266d8e5e926e91e303d Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 1 Dec 2008 20:03:38 +0000 Subject: Merged r9798:9801 from michaelld/memalign into trunk. Passes distcheck on Ubuntu 8.10. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10098 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/missing/posix_memalign.cc | 109 ++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 gnuradio-core/src/lib/missing/posix_memalign.cc (limited to 'gnuradio-core/src/lib/missing/posix_memalign.cc') diff --git a/gnuradio-core/src/lib/missing/posix_memalign.cc b/gnuradio-core/src/lib/missing/posix_memalign.cc new file mode 100644 index 000000000..50022d96f --- /dev/null +++ b/gnuradio-core/src/lib/missing/posix_memalign.cc @@ -0,0 +1,109 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "posix_memalign.h" + +#ifndef HAVE_POSIX_MEMALIGN + +/* emulate posix_memalign functionality, to some degree */ + +#include +#include "gr_pagesize.h" + +int posix_memalign +(void **memptr, size_t alignment, size_t size) +{ + /* emulate posix_memalign functionality, to some degree */ + + /* make sure the return handle is valid; return "bad address" if not valid */ + if (memptr == 0) + return (EFAULT); + *memptr = (void*) 0; + + /* make sure 'alignment' is a power of 2 + * and multiple of sizeof (void*) + */ + + /* make sure 'alignment' is a multiple of sizeof (void*) */ + if ((alignment % sizeof (void*)) != 0) + return (EINVAL); + + /* make sure 'alignment' is a power of 2 */ + if ((alignment & (alignment - 1)) != 0) + return (EINVAL); + + /* good alignment */ + +#if (ALIGNED_MALLOC != 0) + + /* if 'malloc' is known to be aligned, and the desired 'alignment' + * matches is <= that provided by 'malloc', then use 'malloc'. This + * works on, e.g., Darwin 8 & 9: for which malloc is 16-byte aligned. + */ + size_t am = (size_t) ALIGNED_MALLOC; + if (alignment <= am) { + /* make sure ALIGNED_MALLOC is a power of 2, to guarantee that the + * alignment is correct (since 'alignment' must be a power of 2). + */ + if ((am & (am - 1)) != 0) + return (EINVAL); + /* good malloc alignment */ + *memptr = malloc (size); + } + +#endif /* (ALIGNED_MALLOC != 0) */ +#ifdef HAVE_VALLOC + + if (*memptr == (void*) 0) { + /* try valloc if it exists */ + /* cheap and easy way to make sure alignment is met, so long as it + * is <= pagesize () */ + if (alignment <= (size_t) gr_pagesize ()) { + *memptr = valloc (size); + } + } + +#endif /* HAVE_VALLOC */ + +#if (ALIGNED_MALLOC == 0) && !defined (HAVE_VALLOC) + /* no posix_memalign, valloc, and malloc isn't known to be aligned + * (enough for the input arguments); no idea what to do. + */ + +#error gnuradio-core/src/libmissing/posix_memalign.cc: Cannot find a way to alloc aligned memory. + +#endif + + /* if the pointer wasn't allocated properly, return that there was + * not enough memory to allocate; otherwise, return OK (0). + */ + if (*memptr == (void*) 0) + return (ENOMEM); + else + return (0); +}; + +#endif /* ! HAVE_POSIX_MEMALIGN */ -- cgit From 32358d121afcd3e1430f08a05fbb813eba322365 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sun, 8 Feb 2009 21:06:13 +0000 Subject: Fix missing header include (Don Ward) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10410 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/missing/posix_memalign.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/missing/posix_memalign.cc') diff --git a/gnuradio-core/src/lib/missing/posix_memalign.cc b/gnuradio-core/src/lib/missing/posix_memalign.cc index 50022d96f..d51e79b64 100644 --- a/gnuradio-core/src/lib/missing/posix_memalign.cc +++ b/gnuradio-core/src/lib/missing/posix_memalign.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,6 +25,7 @@ #endif #include "posix_memalign.h" +#include #ifndef HAVE_POSIX_MEMALIGN -- cgit From 9f6bc9d5da0e504008b7d692fd6c9cbe55753d90 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 10 Feb 2009 14:41:18 +0000 Subject: Better fix for missing header file include git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10417 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/missing/posix_memalign.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/missing/posix_memalign.cc') diff --git a/gnuradio-core/src/lib/missing/posix_memalign.cc b/gnuradio-core/src/lib/missing/posix_memalign.cc index d51e79b64..a1a707ae5 100644 --- a/gnuradio-core/src/lib/missing/posix_memalign.cc +++ b/gnuradio-core/src/lib/missing/posix_memalign.cc @@ -25,7 +25,7 @@ #endif #include "posix_memalign.h" -#include +#include #ifndef HAVE_POSIX_MEMALIGN -- cgit From 5d1b71031124406721a701c259c12392cd52c4aa Mon Sep 17 00:00:00 2001 From: michaelld Date: Wed, 18 Feb 2009 15:18:23 +0000 Subject: Merging in branch to add malloc.h to posix_memalign.cc for Cygwin. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10461 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/missing/posix_memalign.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/missing/posix_memalign.cc') diff --git a/gnuradio-core/src/lib/missing/posix_memalign.cc b/gnuradio-core/src/lib/missing/posix_memalign.cc index a1a707ae5..a2e98b018 100644 --- a/gnuradio-core/src/lib/missing/posix_memalign.cc +++ b/gnuradio-core/src/lib/missing/posix_memalign.cc @@ -25,7 +25,11 @@ #endif #include "posix_memalign.h" -#include + +#ifdef HAVE_MALLOC_H +// for Cygwin valloc () prototype +#include +#endif #ifndef HAVE_POSIX_MEMALIGN -- cgit From f919f9dcbb54a08e6e26d6c229ce92fb784fa1b2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 13 Apr 2012 18:36:53 -0400 Subject: Removed whitespace and added dtools/bin/remove-whitespace as a tool to do this in the future. The sed script was provided by Moritz Fischer. --- gnuradio-core/src/lib/missing/posix_memalign.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/missing/posix_memalign.cc') diff --git a/gnuradio-core/src/lib/missing/posix_memalign.cc b/gnuradio-core/src/lib/missing/posix_memalign.cc index a2e98b018..aaeff7804 100644 --- a/gnuradio-core/src/lib/missing/posix_memalign.cc +++ b/gnuradio-core/src/lib/missing/posix_memalign.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2008,2009 Free Software Foundation, Inc. - * + * * This file is part of GNU Radio - * + * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. - * + * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, -- cgit