Skip to content

Commit

Permalink
console update
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanwerner committed Sep 25, 2016
1 parent 1aa9843 commit 28fe76a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
11 changes: 8 additions & 3 deletions BERT/BERT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,15 @@ void logMessage(const char *buf, int len, bool console)

void resetXlOper(LPXLOPER12 x)
{
if (x->xltype == xltypeStr && x->val.str)
if ( x->xltype == (xltypeStr | xlbitDLLFree) && x->val.str)
{
delete[] x->val.str;
// we pass a static string with zero length -- don't delete that

if( x->val.str[0] )
delete[] x->val.str;
x->val.str = 0;
}
else if (x->xltype == xltypeMulti && x->val.array.lparray)
else if ((x->xltype == xltypeMulti || x->xltype == ( xltypeMulti | xlbitDLLFree )) && x->val.array.lparray)
{
// have to consider the case that there are strings
// in the array, or even nested multis (not that that
Expand All @@ -216,8 +219,10 @@ void resetXlOper(LPXLOPER12 x)
delete[] x->val.array.lparray;
x->val.array.lparray = 0;
}

x->val.err = xlerrNull;
x->xltype = xltypeNil;

}

LPXLOPER BERT_Volatile(LPXLOPER arg)
Expand Down
2 changes: 1 addition & 1 deletion BERT/BERT_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef __BERT_VERSION_H
#define __BERT_VERSION_H

#define BERT_VERSION L"1.02"
#define BERT_VERSION L"1.03"

#endif // #ifndef __BERT_VERSION_H

11 changes: 9 additions & 2 deletions BERT/ExcelFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ void WINAPI xlAutoFree12(LPXLOPER12 pxFree)
if (pxFree->xltype == (xltypeMulti | xlbitDLLFree))
{
// NOTE: ALWAYS NEW ARRAYS (wait, what about multidim? CHECKME FIXME TODO)
delete[] pxFree->val.array.lparray;
//if(pxFree->val.array.lparray )
// delete[] pxFree->val.array.lparray;
//pxFree->val.array.lparray = 0;
resetXlOper(pxFree);

}
else if (pxFree->xltype == (xltypeStr | xlbitDLLFree))
{
// always new XCHAR[] for strings, except for zero-length strings
// which should use static fields somewhere

if( pxFree->val.str[0] != 0 ) delete[] pxFree->val.str;
//if( pxFree->val.str[0] != 0 ) delete[] pxFree->val.str;
//pxFree->val.str[0] = 0;
resetXlOper(pxFree);

}
else
{
Expand Down
17 changes: 11 additions & 6 deletions BERT/RInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,12 +1376,12 @@ void SEXP2XLOPER(LPXLOPER12 xloper, SEXP sexp, bool inner = false, int r_offset
xllen = xlrows * xlcols;

if (xllen > 1) {
xloper->xltype = xltypeMulti;
xloper->xltype = xltypeMulti | xlbitDLLFree;
xloper->val.array.rows = xlrows;
xloper->val.array.columns = xlcols;
xloper->val.array.lparray = new XLOPER12[xlrows * xlcols];
for (int i = 0; i < xllen; i++) {
xloper->val.array.lparray[i].xltype = xltypeStr | xlbitDLLFree;
xloper->val.array.lparray[i].xltype = xltypeStr; // no free bit: this is static
xloper->val.array.lparray[i].val.str = emptyStr;
}
}
Expand All @@ -1395,11 +1395,12 @@ void SEXP2XLOPER(LPXLOPER12 xloper, SEXP sexp, bool inner = false, int r_offset
xloper->val.num = 0;
}

LPXLOPER12 firstRef = xloper->xltype == xltypeMulti ? xloper->val.array.lparray : xloper;
LPXLOPER12 firstRef = xloper->xltype == ( xltypeMulti | xlbitDLLFree ) ? xloper->val.array.lparray : xloper;

// check early and return

if (!sexp || Rf_isNull( sexp )) {
resetXlOper(firstRef);
firstRef->xltype = xltypeErr;
firstRef->val.err = xlerrNull;
return;
Expand All @@ -1423,6 +1424,7 @@ void SEXP2XLOPER(LPXLOPER12 xloper, SEXP sexp, bool inner = false, int r_offset
SEXP rslt = R_tryEval(Rf_lang2(Rf_install("capture.output"), Rf_lang2(Rf_install("print"), sexp )), R_GlobalEnv, &err);
if (!err) STRSXP2XLOPER(firstRef, rslt);
else {
resetXlOper(firstRef);
firstRef->xltype = xltypeErr;
firstRef->val.err = xlerrValue;
}
Expand Down Expand Up @@ -1460,16 +1462,16 @@ void SEXP2XLOPER(LPXLOPER12 xloper, SEXP sexp, bool inner = false, int r_offset
xllen = xlrows * xlcols;

if (xllen > 1) {
xloper->xltype = xltypeMulti;
xloper->xltype = xltypeMulti | xlbitDLLFree;
xloper->val.array.rows = xlrows;
xloper->val.array.columns = xlcols;
xloper->val.array.lparray = new XLOPER12[xlrows * xlcols];
for (int i = 0; i < xllen; i++) {
xloper->val.array.lparray[i].xltype = xltypeStr | xlbitDLLFree;
xloper->val.array.lparray[i].xltype = xltypeStr; // no free bit
xloper->val.array.lparray[i].val.str = emptyStr;
}
}
firstRef = xloper->xltype == xltypeMulti ? xloper->val.array.lparray : xloper;
firstRef = xloper->xltype == ( xltypeMulti | xlbitDLLFree ) ? xloper->val.array.lparray : xloper;

}

Expand Down Expand Up @@ -2001,6 +2003,9 @@ bool RExec4(LPXLOPER12 rslt, RFuncDesc2 &func, std::vector< LPXLOPER12 > &args)

::WaitForSingleObject(muxExecR, INFINITE);

DebugOut(" ** Function call\n");
DebugOut(" ** Function: %s\n", func.r_name.c_str());

PROTECT(sargs = Rf_allocVector(VECSXP, args.size()));
for (i = 0; i < args.size(); i++)
{
Expand Down

0 comments on commit 28fe76a

Please sign in to comment.