@@ -1896,13 +1896,17 @@ namespace Cpp {
18961896 void make_narg_ctor (const FunctionDecl* FD, const unsigned N,
18971897 std::ostringstream& typedefbuf,
18981898 std::ostringstream& callbuf,
1899- const std::string& class_name, int indent_level) {
1899+ const std::string& class_name, int indent_level, bool array = false ) {
19001900 // Make a code string that follows this pattern:
19011901 //
19021902 // ClassName(args...)
1903+ // OR
1904+ // ClassName[nary](args...) // array of objects
19031905 //
1904-
1905- callbuf << class_name << " (" ;
1906+
1907+ callbuf << class_name;
1908+ if (array) callbuf << " [nary]" ;
1909+ callbuf << " (" ;
19061910 for (unsigned i = 0U ; i < N; ++i) {
19071911 const ParmVarDecl* PVD = FD->getParamDecl (i);
19081912 QualType Ty = PVD->getType ();
@@ -2085,16 +2089,39 @@ namespace Cpp {
20852089 std::ostringstream& buf, int indent_level) {
20862090 // Make a code string that follows this pattern:
20872091 //
2088- // (*(ClassName**)ret) = (obj) ?
2089- // new (*(ClassName**)ret) ClassName(args...) : new ClassName(args...);
2090- //
2092+ // // array of objects construction
2093+ // if (nary > 1) {
2094+ // (*(ClassName**)ret) = (obj) ? new (*(ClassName**)ret) ClassName[nary](args...) : new ClassName[nary](args...);
2095+ // }
2096+ // else {
2097+ // (*(ClassName**)ret) = (obj) ? new (*(ClassName**)ret) ClassName(args...) : new ClassName(args...);
2098+ // }
20912099 {
20922100 std::ostringstream typedefbuf;
20932101 std::ostringstream callbuf;
20942102 //
20952103 // Write the return value assignment part.
20962104 //
20972105 indent (callbuf, indent_level);
2106+ callbuf << " if (nary > 1) {\n " ;
2107+ indent (callbuf, indent_level);
2108+ callbuf << " (*(" << class_name << " **)ret) = " ;
2109+ callbuf << " (obj) ? new (*(" << class_name << " **)ret) " ;
2110+ make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level, true );
2111+
2112+ callbuf << " : new " ;
2113+ //
2114+ // Write the actual expression.
2115+ //
2116+ make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level, true );
2117+ //
2118+ // End the new expression statement.
2119+ //
2120+ callbuf << " ;\n " ;
2121+ indent (callbuf, indent_level);
2122+ callbuf << " }\n " ;
2123+ callbuf << " else {\n " ;
2124+ indent (callbuf, indent_level);
20982125 callbuf << " (*(" << class_name << " **)ret) = " ;
20992126 callbuf << " (obj) ? new (*(" << class_name << " **)ret) " ;
21002127 make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level);
@@ -2108,6 +2135,8 @@ namespace Cpp {
21082135 // End the new expression statement.
21092136 //
21102137 callbuf << " ;\n " ;
2138+ indent (callbuf, --indent_level);
2139+ callbuf << " }\n " ;
21112140 //
21122141 // Output the whole new expression and return statement.
21132142 //
@@ -2626,7 +2655,7 @@ namespace Cpp {
26262655 " __attribute__((annotate(\" __cling__ptrcheck(off)\" )))\n "
26272656 " extern \" C\" void " ;
26282657 buf << wrapper_name;
2629- buf << " (void* obj, int nargs, void** args, void* ret)\n "
2658+ buf << " (void* obj, int nargs, void** args, void* ret, unsigned long nary )\n "
26302659 " {\n " ;
26312660 ++indent_level;
26322661 if (min_args == num_params) {
@@ -3577,17 +3606,19 @@ namespace Cpp {
35773606 }
35783607 }
35793608
3580- TCppObject_t Allocate (TCppScope_t scope) {
3581- return (TCppObject_t)::operator new (Cpp::SizeOf (scope));
3609+ TCppObject_t Allocate (TCppScope_t scope, TCppIndex_t count ) {
3610+ return (TCppObject_t)::operator new (Cpp::SizeOf (scope) * count );
35823611 }
35833612
3584- void Deallocate (TCppScope_t scope, TCppObject_t address) {
3585- ::operator delete (address);
3613+ void Deallocate (TCppScope_t scope, TCppObject_t address, TCppIndex_t count)
3614+ {
3615+ size_t bytes = Cpp::SizeOf (scope) * count;
3616+ ::operator delete (address, bytes);
35863617 }
35873618
35883619 // FIXME: Add optional arguments to the operator new.
35893620 TCppObject_t Construct (compat::Interpreter& interp, TCppScope_t scope,
3590- void * arena /* =nullptr*/ ) {
3621+ void * arena /* =nullptr*/ , TCppIndex_t count /* =1UL */ ) {
35913622 auto * Class = (Decl*) scope;
35923623 // FIXME: Diagnose.
35933624 if (!HasDefaultConstructor (Class))
@@ -3596,7 +3627,7 @@ namespace Cpp {
35963627 auto * const Ctor = GetDefaultConstructor (interp, Class);
35973628 if (JitCall JC = MakeFunctionCallable (&interp, Ctor)) {
35983629 if (arena) {
3599- JC.Invoke (&arena, {}, (void *)~0 ); // Tell Invoke to use placement new.
3630+ JC.Invoke (&arena, {}, (void *)~0 , count ); // Tell Invoke to use placement new.
36003631 return arena;
36013632 }
36023633
@@ -3607,22 +3638,22 @@ namespace Cpp {
36073638 return nullptr ;
36083639 }
36093640
3610- TCppObject_t Construct (TCppScope_t scope, void * arena /* =nullptr*/ ) {
3611- return Construct (getInterp (), scope, arena);
3641+ TCppObject_t Construct (TCppScope_t scope, void * arena /* =nullptr*/ , TCppIndex_t count /* =0UL */ ) {
3642+ return Construct (getInterp (), scope, arena, count );
36123643 }
36133644
36143645 void Destruct (compat::Interpreter& interp, TCppObject_t This, Decl* Class,
3615- bool withFree) {
3646+ bool withFree, TCppIndex_t nary ) {
36163647 if (auto wrapper = make_dtor_wrapper (interp, Class)) {
3617- (*wrapper)(This, /* nary= */ 0 , withFree);
3648+ (*wrapper)(This, nary, withFree);
36183649 return ;
36193650 }
36203651 // FIXME: Diagnose.
36213652 }
36223653
3623- void Destruct (TCppObject_t This, TCppScope_t scope, bool withFree /* =true*/ ) {
3654+ void Destruct (TCppObject_t This, TCppScope_t scope, bool withFree /* =true*/ , TCppIndex_t count /* =1UL */ ) {
36243655 auto * Class = static_cast <Decl*>(scope);
3625- Destruct (getInterp (), This, Class, withFree);
3656+ Destruct (getInterp (), This, Class, withFree, count );
36263657 }
36273658
36283659 class StreamCaptureInfo {
0 commit comments