Skip to content

Commit 3cedbfa

Browse files
Merge pull request #162 from MuAlphaOmegaEpsilon/odr-fixes
ODR fixes
2 parents 917e4e3 + b14c978 commit 3cedbfa

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

src/mfast/allocator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
// See the file license.txt for licensing information.
66
#include "allocator.h"
77
#include <new>
8+
#include "allocator_utils.h"
89
#include <cstring>
910

1011
namespace mfast {
1112

12-
inline std::size_t align(std::size_t n, std::size_t x) {
13-
const std::size_t y = x - 1;
14-
return (n + y) & ~y;
15-
}
16-
1713
std::size_t allocator::reallocate(void *&pointer, std::size_t old_size,
1814
std::size_t new_size) {
1915
// make the new_size at least 64 bytes

src/mfast/allocator_utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#include <cstddef>
3+
4+
namespace mfast {
5+
6+
inline std::size_t align(std::size_t n, std::size_t x) {
7+
const std::size_t y = x - 1;
8+
return (n + y) & ~y;
9+
}
10+
11+
}

src/mfast/arena_allocator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
// This file is part of mFAST.
55
// See the file license.txt for licensing information.
66
#include "arena_allocator.h"
7+
#include "allocator_utils.h"
78
#include <cstring>
89
#include <algorithm>
910
#include <cstdlib>
1011

1112
namespace mfast {
1213

13-
inline std::size_t align(std::size_t n, std::size_t x) {
14-
const std::size_t y = x - 1;
15-
return (n + y) & ~y;
16-
}
17-
1814
void arena_allocator::free_list(memory_chunk_base *head) {
1915
memory_chunk_base *tmp;
2016
while (head) {

src/mfast/xml_parser/FastXMLVisitor.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
// This file is part of mFAST.
55
// See the file license.txt for licensing information.
66
#include "FastXMLVisitor.h"
7+
#include "xml_util.h"
78
#include <cstring>
89
#include <cstdlib>
910
#include <iostream>
1011
const char *FastXMLVisitor::get_optional_attr(const XMLElement &element,
1112
const char *attr_name,
1213
const char *default_value) const {
13-
const XMLAttribute *attr = element.FindAttribute(attr_name);
14-
if (attr == nullptr) {
15-
return default_value;
16-
}
17-
return attr->Value();
14+
return mfast::xml_parser::get_optional_attr(element, attr_name, default_value);
1815
}
1916

2017
bool FastXMLVisitor::is_mandatory_constant(const XMLElement &element) {

src/mfast/xml_parser/view_info_builder.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cstring>
22
#include <string.h>
33
#include "view_info_builder.h"
4+
#include "xml_util.h"
45
#include "../exceptions.h"
56
#include <algorithm>
67
namespace mfast {
@@ -158,16 +159,6 @@ void view_info_builder::visit(const set_field_instruction *inst,
158159
struct tag_reference_name;
159160
typedef boost::error_info<tag_reference_name, std::string> reference_name_info;
160161

161-
inline const char *get_optional_attr(const tinyxml2::XMLElement &element,
162-
const char *attr_name,
163-
const char *default_value) {
164-
const tinyxml2::XMLAttribute *attr = element.FindAttribute(attr_name);
165-
if (attr == nullptr) {
166-
return default_value;
167-
}
168-
return attr->Value();
169-
}
170-
171162
void view_info_builder::build_field_view(const tinyxml2::XMLElement &element,
172163
unsigned &max_depth,
173164
std::deque<field_view_info> &fields) {

src/mfast/xml_parser/xml_util.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ inline const char *get_optional_attr(const XMLElement &element,
1515
const char *attr_name,
1616
const char *default_value) {
1717
const XMLAttribute *attr = element.FindAttribute(attr_name);
18-
if (attr == nullptr) {
19-
return default_value;
20-
}
21-
return attr->Value();
18+
return attr ? attr->Value() : default_value;
2219
}
2320

2421
inline const char *string_dup(const char *str, arena_allocator &alloc) {

0 commit comments

Comments
 (0)