Skip to content

Commit 0b68b63

Browse files
committed
ctx fixes, move from void* to uint64 (MATLAB doesn't like pointers)
1 parent b416cc1 commit 0b68b63

File tree

5 files changed

+3468
-3460
lines changed

5 files changed

+3468
-3460
lines changed

+DSS_MATLAB/APIUtil.m

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
is_prime
1212
end
1313
methods
14-
function obj = APIUtil(create)
14+
function obj = APIUtil(varargin)
1515

1616
if getenv('DSS_EXTENSIONS_DEBUG') == '1'
1717
warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the DSS C-API library')
@@ -25,8 +25,9 @@
2525
PropertiesMOfilePath = fullfile(MfilePath, 'messages', 'properties-en-US.mo');
2626
DSS_MATLAB.librefcount(1);
2727
if libisloaded(obj.libname)
28-
if (nargin > 0) && (create ~= 0)
28+
if (nargin > 0) && (varargin{1} ~= 0)
2929
obj.dssctx = calllib(obj.libname, 'ctx_New');
30+
DSS_MATLAB.ctxrefcount(obj.dssctx, 1);
3031
obj.is_prime = 0;
3132
else
3233
obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime');
@@ -44,9 +45,10 @@
4445
loadlibrary(DLLfilePath, @DSS_MATLAB.dss_capi_no_thunk);
4546
end
4647
calllib(obj.libname, 'DSS_Start', 0);
47-
calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath);
48-
if (nargin > 0) && (create ~= 0)
48+
% calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath);
49+
if (nargin > 0) && (varargin{1} ~= 0)
4950
obj.dssctx = calllib(obj.libname, 'ctx_New');
51+
DSS_MATLAB.ctxrefcount(obj.dssctx, 1);
5052
obj.is_prime = 0;
5153
else
5254
obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime');
@@ -56,15 +58,19 @@
5658
end
5759

5860
function delete(obj)
59-
if obj.is_prime ~= 0
60-
calllib(obj.libname, 'ctx_Dispose', obj.dssctx);
61+
62+
if obj.is_prime == 0
63+
cnt = DSS_MATLAB.ctxrefcount(obj.dssctx, -1);
64+
if cnt == 0
65+
calllib(obj.libname, 'ctx_Dispose', obj.dssctx);
66+
end
6167
end
6268

6369
% If nothing is using the library, unload it.
6470
% Required to properly exit MATLAB.
6571
cnt = DSS_MATLAB.librefcount(-1);
6672
if (cnt == 0)
67-
prime_ctx = calllib(obj.libname, 'ctx_Get_Prime')
73+
prime_ctx = calllib(obj.libname, 'ctx_Get_Prime');
6874
calllib(obj.libname, 'ctx_Text_Set_Command', prime_ctx, 'Set Parallel=no');
6975
calllib(obj.libname, 'ctx_DSS_ClearAll', prime_ctx);
7076
unloadlibrary(obj.libname);

+DSS_MATLAB/Base.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
methods
3434

3535
function varargout = CheckForError(obj, varargin)
36-
error = calllib(obj.libname, 'Error_Get_Number');
36+
error = calllib(obj.libname, 'ctx_Error_Get_Number', obj.dssctx);
3737
if error ~= 0
38-
ME = MException(['DSS_MATLAB:Error' int2str(error)], strrep(calllib(obj.libname, 'Error_Get_Description'), '\', '\\'));
38+
ME = MException(['DSS_MATLAB:Error' int2str(error)], strrep(calllib(obj.libname, 'ctx_Error_Get_Description', obj.dssctx), '\', '\\'));
3939
throw(ME);
4040
end
4141
varargout = varargin;
4242
end
4343

4444
function obj = clear_api_buffers(obj)
45-
calllib(obj.libname, 'DSS_DisposeGRData');
46-
calllib(obj.libname, 'DSS_ResetStringBuffer');
45+
calllib(obj.libname, 'ctx_DSS_DisposeGRData', obj.dssctx);
46+
calllib(obj.libname, 'ctx_DSS_ResetStringBuffer', obj.dssctx);
4747
end
4848
end
4949
end

+DSS_MATLAB/ICktElement.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
methods (Access = public)
105105
function obj = ICktElement(apiutil)
106106
obj@DSS_MATLAB.Base(apiutil);
107-
obj.Properties = DSS_MATLAB.IDSSProperty(obj.apiutil);
107+
obj.PropertiesRef = DSS_MATLAB.IDSSProperty(obj.apiutil);
108108
end
109109

110110
function obj = Close(obj, Term, Phs)

+DSS_MATLAB/IDSS.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
end
6565

6666
methods (Access = public)
67-
function obj = IDSS(create)
68-
apiutil = DSS_MATLAB.APIUtil(create);
67+
function obj = IDSS(varargin)
68+
apiutil = DSS_MATLAB.APIUtil(varargin{:});
6969
apiutil.InitBuffers();
7070
obj@DSS_MATLAB.Base(apiutil);
7171
obj.ActiveCircuit = DSS_MATLAB.ICircuit(obj.apiutil);
@@ -119,7 +119,7 @@
119119
% manually, the management of threads and potential issues should be handled by the user.
120120
%
121121
% (API Extension)
122-
result = IDSS(1);
122+
result = DSS_MATLAB.IDSS(1);
123123
end
124124
end
125125
methods

0 commit comments

Comments
 (0)