summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.se>2020-08-12 11:58:31 +0100
committerMartin Braun <martin@gnuradio.org>2020-08-14 04:08:48 -0700
commit25e1d2aa99a5f60cc047f6009715925d3a6a01ca (patch)
treef00dadaae8ad87257031ed3f3c4a74b2eb696958
parent752593a347de25cc28ec981c27b2e5f381f843a6 (diff)
digital/header: Remove manual memory management
-rw-r--r--gr-digital/lib/header_format_counter.cc12
-rw-r--r--gr-digital/lib/header_format_crc.cc13
-rw-r--r--gr-digital/lib/header_format_default.cc12
3 files changed, 15 insertions, 22 deletions
diff --git a/gr-digital/lib/header_format_counter.cc b/gr-digital/lib/header_format_counter.cc
index 16ae220ccb..cbf641fc2e 100644
--- a/gr-digital/lib/header_format_counter.cc
+++ b/gr-digital/lib/header_format_counter.cc
@@ -15,7 +15,7 @@
#include <gnuradio/digital/header_format_counter.h>
#include <gnuradio/math.h>
#include <string.h>
-#include <volk/volk.h>
+#include <volk/volk_alloc.hh>
#include <iomanip>
#include <iostream>
@@ -45,9 +45,10 @@ bool header_format_counter::format(int nbytes_in,
pmt::pmt_t& info)
{
- uint8_t* bytes_out = (uint8_t*)volk_malloc(header_nbytes(), volk_get_alignment());
+ // Creating the output pmt copies data; free our own here when done.
+ volk::vector<uint8_t> bytes_out(header_nbytes());
- header_buffer header(bytes_out);
+ header_buffer header(bytes_out.data());
header.add_field64(d_access_code, d_access_code_len);
header.add_field16((uint16_t)(nbytes_in));
header.add_field16((uint16_t)(nbytes_in));
@@ -55,10 +56,7 @@ bool header_format_counter::format(int nbytes_in,
header.add_field16((uint16_t)(d_counter));
// Package output data into a PMT vector
- output = pmt::init_u8vector(header_nbytes(), bytes_out);
-
- // Creating the output pmt copies data; free our own here.
- volk_free(bytes_out);
+ output = pmt::init_u8vector(header_nbytes(), bytes_out.data());
d_counter++;
diff --git a/gr-digital/lib/header_format_crc.cc b/gr-digital/lib/header_format_crc.cc
index 4b4bcb8216..b779e1c09b 100644
--- a/gr-digital/lib/header_format_crc.cc
+++ b/gr-digital/lib/header_format_crc.cc
@@ -14,7 +14,7 @@
#include <gnuradio/digital/header_buffer.h>
#include <gnuradio/digital/header_format_crc.h>
#include <string.h>
-#include <volk/volk.h>
+#include <volk/volk_alloc.hh>
namespace gr {
namespace digital {
@@ -40,8 +40,8 @@ bool header_format_crc::format(int nbytes_in,
pmt::pmt_t& output,
pmt::pmt_t& info)
{
- uint8_t* bytes_out = (uint8_t*)volk_malloc(header_nbytes(), volk_get_alignment());
- memset(bytes_out, 0, header_nbytes());
+ // Creating the output pmt copies data; free our own here when done.
+ volk::vector<uint8_t> bytes_out(header_nbytes());
// Should this throw instead of mask if the payload is too big
// for 12-bit representation?
@@ -56,7 +56,7 @@ bool header_format_crc::format(int nbytes_in,
uint32_t concat = 0;
concat = (d_header_number << 12) | (nbytes_in);
- header_buffer header(bytes_out);
+ header_buffer header(bytes_out.data());
header.add_field32(concat, 24, true);
header.add_field8(crc);
@@ -64,10 +64,7 @@ bool header_format_crc::format(int nbytes_in,
d_header_number &= 0x0FFF;
// Package output data into a PMT vector
- output = pmt::init_u8vector(header_nbytes(), bytes_out);
-
- // Creating the output pmt copies data; free our own here.
- volk_free(bytes_out);
+ output = pmt::init_u8vector(header_nbytes(), bytes_out.data());
return true;
}
diff --git a/gr-digital/lib/header_format_default.cc b/gr-digital/lib/header_format_default.cc
index 96376f6229..a37ad14181 100644
--- a/gr-digital/lib/header_format_default.cc
+++ b/gr-digital/lib/header_format_default.cc
@@ -14,7 +14,7 @@
#include <gnuradio/digital/header_format_default.h>
#include <gnuradio/math.h>
#include <string.h>
-#include <volk/volk.h>
+#include <volk/volk_alloc.hh>
#include <iostream>
namespace gr {
@@ -85,18 +85,16 @@ bool header_format_default::format(int nbytes_in,
pmt::pmt_t& output,
pmt::pmt_t& info)
{
- uint8_t* bytes_out = (uint8_t*)volk_malloc(header_nbytes(), volk_get_alignment());
+ // Creating the output pmt copies data; free our own here when done.
+ volk::vector<uint8_t> bytes_out(header_nbytes());
- header_buffer header(bytes_out);
+ header_buffer header(bytes_out.data());
header.add_field64(d_access_code, d_access_code_len);
header.add_field16((uint16_t)(nbytes_in));
header.add_field16((uint16_t)(nbytes_in));
// Package output data into a PMT vector
- output = pmt::init_u8vector(header_nbytes(), bytes_out);
-
- // Creating the output pmt copies data; free our own here.
- volk_free(bytes_out);
+ output = pmt::init_u8vector(header_nbytes(), bytes_out.data());
return true;
}