Mercurial > hg > octave-terminal
changeset 7172:e9a590a137d8
[project @ 2007-11-14 16:17:10 by jwe]
author | jwe |
---|---|
date | Wed, 14 Nov 2007 16:17:11 +0000 |
parents | 9bc096bc59d4 |
children | ff2ff2c09865 |
files | src/ChangeLog src/mex.cc |
diffstat | 2 files changed, 54 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2007-11-14 John W. Eaton <jwe@octave.org> + + * mex.cc (mex::mark, mex::unmark): Now public. + (mex::persistent): Delete. + (mexMakeArrayPersistent): Call maybe_unmark_array instead of + mex::persistent. + (mexMakeMemoryPersistent): Call maybe_unmark instead of + mex::persistent. + (maybe_unmark (void *)): New function. + (mxSetDimensions, mxSetPr, mxSetPi, mxSetData, mxSetImagData, + mxSetIr, mxSetJc): Use it. From David Bateman. + 2007-11-13 Joseph P. Skudlarek <Jskud@Jskud.com> * DLD-FUNCTIONS/rand.cc (Frand): Update URL reference in doc string.
--- a/src/mex.cc +++ b/src/mex.cc @@ -2177,8 +2177,30 @@ } } - // Mark a pointer so that it will not be freed on exit. - void persistent (void *ptr) { unmark (ptr); } + // Mark a pointer to be freed on exit. + void mark (void *ptr) + { +#ifdef DEBUG + if (memlist.find (ptr) != memlist.end ()) + warning ("%s: double registration ignored", function_name ()); +#endif + + memlist.insert (ptr); + } + + // Unmark a pointer to be freed on exit, either because it was + // made persistent, or because it was already freed. + void unmark (void *ptr) + { + std::set<void *>::iterator p = memlist.find (ptr); + + if (p != memlist.end ()) + memlist.erase (p); +#ifdef DEBUG + else + warning ("%s: value not marked", function_name ()); +#endif + } mxArray *mark_array (mxArray *ptr) { @@ -2222,9 +2244,6 @@ return inlist; } - // Remove PTR from the list of arrays to be free on exit. - void persistent (mxArray *ptr) { unmark_array (ptr); } - octave_mex_function *current_mex_function (void) const { return curr_mex_fcn; @@ -2252,31 +2271,6 @@ // The name of the currently executing function. mutable char *fname; - // Mark a pointer to be freed on exit. - void mark (void *ptr) - { -#ifdef DEBUG - if (memlist.find (ptr) != memlist.end ()) - warning ("%s: double registration ignored", function_name ()); -#endif - - memlist.insert (ptr); - } - - // Unmark a pointer to be freed on exit, either because it was - // made persistent, or because it was already freed. - void unmark (void *ptr) - { - std::set<void *>::iterator p = memlist.find (ptr); - - if (p != memlist.end ()) - memlist.erase (p); -#ifdef DEBUG - else - warning ("%s: value not marked", function_name ()); -#endif - } - // List of memory resources we allocated. static std::set<void *> global_memlist; @@ -2333,6 +2327,15 @@ return ptr; } +static inline void * +maybe_unmark (void *ptr) +{ + if (mex_context) + mex_context->unmark (ptr); + + return ptr; +} + void mxArray_struct::set_field_by_number (mwIndex index, int key_num, mxArray *val) { @@ -2722,7 +2725,7 @@ void mxSetDimensions (mxArray *ptr, mwSize *dims, mwSize ndims) { - ptr->set_dimensions (dims, ndims); + ptr->set_dimensions (static_cast<mwSize *> (maybe_unmark (dims)), ndims); } // Data extractors. @@ -2772,25 +2775,25 @@ void mxSetPr (mxArray *ptr, double *pr) { - ptr->set_data (pr); + ptr->set_data (maybe_unmark (pr)); } void mxSetPi (mxArray *ptr, double *pi) { - ptr->set_imag_data (pi); + ptr->set_imag_data (maybe_unmark (pi)); } void mxSetData (mxArray *ptr, void *pr) { - ptr->set_data (pr); + ptr->set_data (maybe_unmark (pr)); } void mxSetImagData (mxArray *ptr, void *pi) { - ptr->set_imag_data (pi); + ptr->set_imag_data (maybe_unmark (pi)); } // Classes. @@ -2847,13 +2850,13 @@ void mxSetIr (mxArray *ptr, mwIndex *ir) { - ptr->set_ir (ir); + ptr->set_ir (static_cast <mwIndex *> (maybe_unmark (ir))); } void mxSetJc (mxArray *ptr, mwIndex *jc) { - ptr->set_jc (jc); + ptr->set_jc (static_cast<mwIndex *> (maybe_unmark (jc))); } void @@ -3267,15 +3270,13 @@ void mexMakeArrayPersistent (mxArray *ptr) { - if (mex_context) - mex_context->persistent (ptr); + maybe_unmark_array (ptr); } void mexMakeMemoryPersistent (void *ptr) { - if (mex_context) - mex_context->persistent (ptr); + maybe_unmark (ptr); } int