Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes & module mexname option support #60

Merged
merged 3 commits into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/matlab/matlabcontainer.swg
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ namespace swig
}

// KT TODO need to get this in matlab conventions
void paren_asgn(difference_type i, value_type x) throw (std::out_of_range) {
void paren_asgn(value_type x, difference_type i) throw (std::out_of_range) {
*(swig::getpos(self,i)) = x;
}

Expand Down
10 changes: 5 additions & 5 deletions Lib/matlab/matlabrun.swg
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ SWIGRUNTIME swig_module_info *SWIG_Matlab_GetModule(void *SWIGUNUSEDPARM(clientd
/* First call for this module, fetch pointer from MATLAB */
mxArray* mem = 0;
int flag = mexCallMATLAB(1, &mem, 0, 0, "SwigMem");
if (flag || !mem) mexErrMsgIdAndTxt("SWIG_Matlab_GetModule", "Cannot call SwigMem");
if (flag || !mem) mexErrMsgIdAndTxt("SWIG:GetModule", "Cannot call SwigMem");
/* On first call, mem is an empty matrix */
if (mxGetNumberOfElements(mem)!= 0) {
if (!mxIsStruct(mem)) {
mexErrMsgIdAndTxt("SWIG_Matlab_GetModule", "Corrupted memory");
mexErrMsgIdAndTxt("SWIG:GetModule", "Corrupted memory");
}
mxArray *module = mxGetField(mem, 0,
"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
Expand All @@ -302,7 +302,7 @@ SWIGRUNTIME void SWIG_Matlab_SetModule(swig_module_info *pointer) {
mxArray* mem = 0;
const char *fields[1] = {"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME};
int flag = mexCallMATLAB(1, &mem, 0, 0, "SwigMem");
if (flag || !mem) mexErrMsgIdAndTxt("SWIG_Matlab_GetModule", "Cannot call SwigMem");
if (flag || !mem) mexErrMsgIdAndTxt("SWIG:SetModule", "Cannot call SwigMem");
/* Under normal circumstances, swigMem is an empty matrix */
/* but is not required to be for a valid call to SWIG_Matlab_SetModule() */
if (mxGetNumberOfElements(mem) == 0) {
Expand All @@ -318,7 +318,7 @@ SWIGRUNTIME void SWIG_Matlab_SetModule(swig_module_info *pointer) {
int fieldNum = 0;
/* Add to existing mem if not the same */
if (!mxIsStruct(mem)) {
mexErrMsgIdAndTxt("SWIG_Matlab_GetModule", "Corrupted memory");
mexErrMsgIdAndTxt("SWIG:SetModule", "Corrupted memory");
}
nfields = mxGetNumberOfFields(mem);
/* Check if same type table */
Expand All @@ -329,7 +329,7 @@ SWIGRUNTIME void SWIG_Matlab_SetModule(swig_module_info *pointer) {
}
}
fieldNum = mxAddField(mem, fields[0]);
if (fieldNum < 0) mexErrMsgIdAndTxt("SWIG_Matlab_GetModule", "Error adding field to SwigMem");
if (fieldNum < 0) mexErrMsgIdAndTxt("SWIG:SetModule", "Error adding field to SwigMem");
mxArray *module = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
if(!module) mexErrMsgIdAndTxt("SWIG:SetModule","mxCreateNumericMatrix failed");
*(uint64_T *)mxGetData(module) = (uint64_T)pointer;
Expand Down
23 changes: 19 additions & 4 deletions Source/Modules/matlab.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static const char *usage = (char *) "\
Matlab Options (available with -matlab)\n\
-opprefix <str> - Prefix <str> for global operator functions [default: 'op_']\n\
-pkgname <str> - Prefix <str> for package name ' [default: '<module_name>']\n\
-mexname <str> - Specify mex function name <str> ' [default: '<module_name>MEX']\n\
\n";

class MATLAB : public Language {
Expand Down Expand Up @@ -276,6 +277,11 @@ int MATLAB::top(Node *n) {
if (!pkg_name && Getattr(options, "package")) {
pkg_name = Getattr(options, "package");
}
// Set mex name via module option if not set via command-line
// Otherwise use module name as default (see below)
if (!mex_name && Getattr(options, "mexname")) {
mex_name = Getattr(options, "mexname");
}
}
}
}
Expand Down Expand Up @@ -731,10 +737,19 @@ int MATLAB::importDirective(Node *n) {
String *modname = Getattr(n, "module");

if (modname) {
// Construct name of intermediary layer
// TODO: If option mexname set for module, use instead
String *import_mexname = Copy(modname);
Append(import_mexname, "MEX");
// Find the module node for this imported module. It should be the
// first child but search just in case.
Node *mod = firstChild(n);
while (mod && Strcmp(nodeType(mod), "module") != 0)
mod = nextSibling(mod);

// If option mexname set for module, use instead
Node *options = Getattr(mod, "options");
String *import_mexname = options ? Getattr(options, "mexname") : 0;
if (import_mexname == 0) {
import_mexname = Copy(modname);
Append(import_mexname, "MEX");
}

/* Add to list of modules to be imported */
Append(l_modules, import_mexname);
Expand Down