Skip to content

Commit b5a28a6

Browse files
committed
Merge pull request #1462 from mgreter/bugfix/msvc-memory-manager
Fix memory manager for MSVC
2 parents 8fbaaf7 + 202a4ea commit b5a28a6

16 files changed

+825
-723
lines changed

src/ast.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ namespace Sass {
287287
}
288288
if (!found)
289289
{
290-
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(*rhs);
290+
Compound_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, *rhs);
291291
(*cpy) << this;
292292
return cpy;
293293
}
294-
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->pstate());
294+
Compound_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, rhs->pstate());
295295
for (size_t j = 0; j < i; ++j)
296296
{ (*cpy) << (*rhs)[j]; }
297297
(*cpy) << this;
@@ -311,7 +311,7 @@ namespace Sass {
311311
if (!rhs->is_universal_ns())
312312
{
313313
// creaty the copy inside (avoid unnecessary copies)
314-
Type_Selector* ts = new (ctx.mem) Type_Selector(*this);
314+
Type_Selector* ts = SASS_MEMORY_NEW(ctx.mem, Type_Selector, *this);
315315
// overwrite the name if star is given as name
316316
if (ts->name() == "*") { ts->name(rhs->name()); }
317317
// now overwrite the namespace name and flag
@@ -325,7 +325,7 @@ namespace Sass {
325325
if (name() == "*" && rhs->name() != "*")
326326
{
327327
// creaty the copy inside (avoid unnecessary copies)
328-
Type_Selector* ts = new (ctx.mem) Type_Selector(*this);
328+
Type_Selector* ts = SASS_MEMORY_NEW(ctx.mem, Type_Selector, *this);
329329
// simply set the new name
330330
ts->name(rhs->name());
331331
// return copy
@@ -341,7 +341,7 @@ namespace Sass {
341341

342342
// if the rhs is empty, just return a copy of this
343343
if (rhs->length() == 0) {
344-
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->pstate());
344+
Compound_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, rhs->pstate());
345345
(*cpy) << this;
346346
return cpy;
347347
}
@@ -353,14 +353,14 @@ namespace Sass {
353353
if (typeid(*rhs_0) == typeid(Type_Selector))
354354
{
355355
// if rhs is universal, just return this tagname + rhs's qualifiers
356-
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(*rhs);
356+
Compound_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, *rhs);
357357
Type_Selector* ts = static_cast<Type_Selector*>(rhs_0);
358358
(*cpy)[0] = this->unify_with(ts, ctx);
359359
return cpy;
360360
}
361361
else if (dynamic_cast<Selector_Qualifier*>(rhs_0)) {
362362
// qualifier is `.class`, so we can prefix with `ns|*.class`
363-
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->pstate());
363+
Compound_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, rhs->pstate());
364364
if (has_ns() && !rhs_0->has_ns()) {
365365
if (ns() != "*") (*cpy) << this;
366366
}
@@ -378,13 +378,13 @@ namespace Sass {
378378
// if rhs is universal, just return this tagname + rhs's qualifiers
379379
if (rhs_0->name() != "*" && rhs_0->ns() != "*" && rhs_0->name() != name()) return 0;
380380
// otherwise create new compound and unify first simple selector
381-
Compound_Selector* copy = new (ctx.mem) Compound_Selector(*rhs);
381+
Compound_Selector* copy = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, *rhs);
382382
(*copy)[0] = this->unify_with(rhs_0, ctx);
383383
return copy;
384384

385385
}
386386
// else it's a tag name and a bunch of qualifiers -- just append them
387-
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(rhs->pstate());
387+
Compound_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, rhs->pstate());
388388
if (name() != "*") (*cpy) << this;
389389
(*cpy) += rhs;
390390
return cpy;
@@ -588,10 +588,11 @@ namespace Sass {
588588
Complex_Selector* Compound_Selector::to_complex(Memory_Manager<AST_Node>& mem)
589589
{
590590
// create an intermediate complex selector
591-
return new (mem) Complex_Selector(pstate(),
592-
Complex_Selector::ANCESTOR_OF,
593-
this,
594-
0);
591+
return SASS_MEMORY_NEW(mem, Complex_Selector,
592+
pstate(),
593+
Complex_Selector::ANCESTOR_OF,
594+
this,
595+
0);
595596
}
596597

597598
Selector_List* Complex_Selector::unify_with(Complex_Selector* other, Context& ctx)
@@ -652,7 +653,7 @@ namespace Sass {
652653

653654
// do some magic we inherit from node and extend
654655
Node node = Extend::subweave(lhsNode, rhsNode, ctx);
655-
Selector_List* result = new (ctx.mem) Selector_List(pstate());
656+
Selector_List* result = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
656657
NodeDequePtr col = node.collection(); // move from collection to list
657658
for (NodeDeque::iterator it = col->begin(), end = col->end(); it != end; it++)
658659
{ (*result) << nodeToComplexSelector(Node::naiveTrim(*it, ctx), ctx); }
@@ -796,7 +797,7 @@ namespace Sass {
796797
{
797798
if (!tail()) return 0;
798799
if (!head()) return tail()->context(ctx);
799-
Complex_Selector* cpy = new (ctx.mem) Complex_Selector(pstate(), combinator(), head(), tail()->context(ctx));
800+
Complex_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Complex_Selector, pstate(), combinator(), head(), tail()->context(ctx));
800801
cpy->media_block(media_block());
801802
return cpy;
802803
}
@@ -829,7 +830,7 @@ namespace Sass {
829830

830831
if (last()) {
831832
if (last()->combinator() != ANCESTOR_OF && c != ANCESTOR_OF) {
832-
Complex_Selector* inter = new (ctx.mem) Complex_Selector(pstate());
833+
Complex_Selector* inter = SASS_MEMORY_NEW(ctx.mem, Complex_Selector, pstate());
833834
inter->reference(r);
834835
inter->combinator(c);
835836
inter->tail(t);
@@ -848,9 +849,9 @@ namespace Sass {
848849

849850
Selector_List* Selector_List::parentize(Selector_List* ps, Context& ctx)
850851
{
851-
Selector_List* ss = new (ctx.mem) Selector_List(pstate());
852+
Selector_List* ss = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
852853
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
853-
Selector_List* list = new (ctx.mem) Selector_List(pstate());
854+
Selector_List* list = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
854855
*list << (*ps)[pi];
855856
for (size_t si = 0, sL = this->length(); si < sL; ++si) {
856857
*ss += (*this)[si]->parentize(list, ctx);
@@ -874,7 +875,7 @@ namespace Sass {
874875
// mix parent complex selector into the compound list
875876
if (dynamic_cast<Parent_Selector*>((*head)[0])) {
876877
if (parents && parents->length()) {
877-
Selector_List* retval = new (ctx.mem) Selector_List(pstate());
878+
Selector_List* retval = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
878879
if (tails && tails->length() > 0) {
879880
for (size_t n = 0, nL = tails->length(); n < nL; ++n) {
880881
for (size_t i = 0, iL = parents->length(); i < iL; ++i) {
@@ -912,12 +913,12 @@ namespace Sass {
912913
}
913914
// have no parent but some tails
914915
else {
915-
Selector_List* retval = new (ctx.mem) Selector_List(pstate());
916+
Selector_List* retval = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
916917
if (tails && tails->length() > 0) {
917918
for (size_t n = 0, nL = tails->length(); n < nL; ++n) {
918919
Complex_Selector* cpy = this->clone(ctx);
919920
cpy->tail((*tails)[n]->cloneFully(ctx));
920-
cpy->head(new (ctx.mem) Compound_Selector(head->pstate()));
921+
cpy->head(SASS_MEMORY_NEW(ctx.mem, Compound_Selector, head->pstate()));
921922
for (size_t i = 1, L = this->head()->length(); i < L; ++i)
922923
*cpy->head() << (*this->head())[i];
923924
if (!cpy->head()->length()) cpy->head(0);
@@ -927,7 +928,7 @@ namespace Sass {
927928
// have no parent and not tails
928929
else {
929930
Complex_Selector* cpy = this->clone(ctx);
930-
cpy->head(new (ctx.mem) Compound_Selector(head->pstate()));
931+
cpy->head(SASS_MEMORY_NEW(ctx.mem, Compound_Selector, head->pstate()));
931932
for (size_t i = 1, L = this->head()->length(); i < L; ++i)
932933
*cpy->head() << (*this->head())[i];
933934
if (!cpy->head()->length()) cpy->head(0);
@@ -953,7 +954,7 @@ namespace Sass {
953954

954955
Selector_List* Complex_Selector::tails(Context& ctx, Selector_List* tails)
955956
{
956-
Selector_List* rv = new (ctx.mem) Selector_List(pstate_);
957+
Selector_List* rv = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate_);
957958
if (tails && tails->length()) {
958959
for (size_t i = 0, iL = tails->length(); i < iL; ++i) {
959960
Complex_Selector* pr = this->clone(ctx);
@@ -1050,14 +1051,14 @@ namespace Sass {
10501051

10511052
Complex_Selector* Complex_Selector::clone(Context& ctx) const
10521053
{
1053-
Complex_Selector* cpy = new (ctx.mem) Complex_Selector(*this);
1054+
Complex_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Complex_Selector, *this);
10541055
if (tail()) cpy->tail(tail()->clone(ctx));
10551056
return cpy;
10561057
}
10571058

10581059
Complex_Selector* Complex_Selector::cloneFully(Context& ctx) const
10591060
{
1060-
Complex_Selector* cpy = new (ctx.mem) Complex_Selector(*this);
1061+
Complex_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Complex_Selector, *this);
10611062

10621063
if (head()) {
10631064
cpy->head(head()->clone(ctx));
@@ -1072,19 +1073,19 @@ namespace Sass {
10721073

10731074
Compound_Selector* Compound_Selector::clone(Context& ctx) const
10741075
{
1075-
Compound_Selector* cpy = new (ctx.mem) Compound_Selector(*this);
1076+
Compound_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, *this);
10761077
return cpy;
10771078
}
10781079

10791080
Selector_List* Selector_List::clone(Context& ctx) const
10801081
{
1081-
Selector_List* cpy = new (ctx.mem) Selector_List(*this);
1082+
Selector_List* cpy = SASS_MEMORY_NEW(ctx.mem, Selector_List, *this);
10821083
return cpy;
10831084
}
10841085

10851086
Selector_List* Selector_List::cloneFully(Context& ctx) const
10861087
{
1087-
Selector_List* cpy = new (ctx.mem) Selector_List(pstate());
1088+
Selector_List* cpy = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
10881089
for (size_t i = 0, L = length(); i < L; ++i) {
10891090
*cpy << (*this)[i]->cloneFully(ctx);
10901091
}
@@ -1182,7 +1183,7 @@ namespace Sass {
11821183
}
11831184

11841185
// Creates the final Selector_List by combining all the complex selectors
1185-
Selector_List* final_result = new (ctx.mem) Selector_List(pstate());
1186+
Selector_List* final_result = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
11861187
for (auto itr = unified_complex_selectors.begin(); itr != unified_complex_selectors.end(); ++itr) {
11871188
*final_result << *itr;
11881189
}
@@ -1235,7 +1236,7 @@ namespace Sass {
12351236
Compound_Selector* Compound_Selector::minus(Compound_Selector* rhs, Context& ctx)
12361237
{
12371238
To_String to_string(&ctx);
1238-
Compound_Selector* result = new (ctx.mem) Compound_Selector(pstate());
1239+
Compound_Selector* result = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, pstate());
12391240
// result->has_parent_reference(has_parent_reference());
12401241

12411242
// not very efficient because it needs to preserve order

src/bind.cpp

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,19 @@ namespace Sass {
7474
// otherwise we will not be able to fetch it again
7575
else {
7676
// create a new list object for wrapped items
77-
List* arglist = new (ctx.mem) List(p->pstate(),
78-
0,
79-
rest->separator(),
80-
true);
77+
List* arglist = SASS_MEMORY_NEW(ctx.mem, List,
78+
p->pstate(),
79+
0,
80+
rest->separator(),
81+
true);
8182
// wrap each item from list as an argument
8283
for (Expression* item : rest->elements()) {
83-
(*arglist) << new (ctx.mem) Argument(item->pstate(),
84-
item,
85-
"",
86-
false,
87-
false);
84+
(*arglist) << SASS_MEMORY_NEW(ctx.mem, Argument,
85+
item->pstate(),
86+
item,
87+
"",
88+
false,
89+
false);
8890
}
8991
// assign new arglist to environment
9092
env->local_frame()[p->name()] = arglist;
@@ -97,25 +99,27 @@ namespace Sass {
9799
} else if (a->is_keyword_argument()) {
98100

99101
// expand keyword arguments into their parameters
100-
List* arglist = new (ctx.mem) List(p->pstate(), 0, SASS_COMMA, true);
102+
List* arglist = SASS_MEMORY_NEW(ctx.mem, List, p->pstate(), 0, SASS_COMMA, true);
101103
env->local_frame()[p->name()] = arglist;
102104
Map* argmap = static_cast<Map*>(a->value());
103105
for (auto key : argmap->keys()) {
104106
std::string name = unquote(static_cast<String_Constant*>(key)->value());
105-
(*arglist) << new (ctx.mem) Argument(key->pstate(),
106-
argmap->at(key),
107-
name,
108-
false,
109-
false);
107+
(*arglist) << SASS_MEMORY_NEW(ctx.mem, Argument,
108+
key->pstate(),
109+
argmap->at(key),
110+
name,
111+
false,
112+
false);
110113
}
111114

112115
} else {
113116

114117
// create a new list object for wrapped items
115-
List* arglist = new (ctx.mem) List(p->pstate(),
116-
0,
117-
SASS_COMMA,
118-
true);
118+
List* arglist = SASS_MEMORY_NEW(ctx.mem, List,
119+
p->pstate(),
120+
0,
121+
SASS_COMMA,
122+
true);
119123
// consume the next args
120124
while (ia < LA) {
121125
// get and post inc
@@ -125,11 +129,12 @@ namespace Sass {
125129
// skip any list completely if empty
126130
if (ls && ls->empty()) continue;
127131
// check if we have rest argument
128-
(*arglist) << new (ctx.mem) Argument(a->pstate(),
129-
a->value(),
130-
a->name(),
131-
false,
132-
false);
132+
(*arglist) << SASS_MEMORY_NEW(ctx.mem, Argument,
133+
a->pstate(),
134+
a->value(),
135+
a->name(),
136+
false,
137+
false);
133138
// check if we have rest argument
134139
if (a->is_rest_argument()) {
135140
// preserve the list separator from rest args
@@ -160,11 +165,12 @@ namespace Sass {
160165
// otherwise move one of the rest args into the param, converting to argument if necessary
161166
if (!(a = dynamic_cast<Argument*>((*arglist)[0]))) {
162167
Expression* a_to_convert = (*arglist)[0];
163-
a = new (ctx.mem) Argument(a_to_convert->pstate(),
164-
a_to_convert,
165-
"",
166-
false,
167-
false);
168+
a = SASS_MEMORY_NEW(ctx.mem, Argument,
169+
a_to_convert->pstate(),
170+
a_to_convert,
171+
"",
172+
false,
173+
false);
168174
}
169175
arglist->elements().erase(arglist->elements().begin());
170176
if (!arglist->length() || (!arglist->is_arglist() && ip + 1 == LP)) {
@@ -235,10 +241,11 @@ namespace Sass {
235241
// cerr << "********" << endl;
236242
if (!env->has_local(leftover->name())) {
237243
if (leftover->is_rest_parameter()) {
238-
env->local_frame()[leftover->name()] = new (ctx.mem) List(leftover->pstate(),
239-
0,
240-
SASS_COMMA,
241-
true);
244+
env->local_frame()[leftover->name()] = SASS_MEMORY_NEW(ctx.mem, List,
245+
leftover->pstate(),
246+
0,
247+
SASS_COMMA,
248+
true);
242249
}
243250
else if (leftover->default_value()) {
244251
Expression* dv = leftover->default_value()->perform(eval);

src/context.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,13 @@ namespace Sass {
438438

439439
void register_overload_stub(Context& ctx, std::string name, Env* env)
440440
{
441-
Definition* stub = new (ctx.mem) Definition(ParserState("[built-in function]"),
442-
0,
443-
name,
444-
0,
445-
0,
446-
true);
441+
Definition* stub = SASS_MEMORY_NEW(ctx.mem, Definition,
442+
ParserState("[built-in function]"),
443+
0,
444+
name,
445+
0,
446+
0,
447+
true);
447448
(*env)[name + "[f]"] = stub;
448449
}
449450

0 commit comments

Comments
 (0)