Mercurial > jwe > octave
comparison libinterp/corefcn/mex.cc @ 21151:bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Switch from using class method mxArray_base::error to error from error.h
* mex.cc (mxArray_base::error, mxArray_matlab::invalid_type_error):
Delete functions.
* mex.cc (mxArray_matlab::err_invalid_type): New function declared with
OCTAVE_NORETURN.
* mex.cc: #include "error.h". Rename all invalid_type_error calls to
err_invalid_type. Remove useless statements appearing after calls to
err_invalid_type.
* mxarray.in.h: #include "error.h". Rename all invalid_type_error calls to
err_invalid_type.
* mxarray.in.h (mxArray_base::err_invalid_type): New function declared with
OCTAVE_NORETURN.
* mxarray.in.h (mxArray_base::invalid_type_error): Add OCTAVE_DEPRECATED
attribute to function.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 29 Jan 2016 11:32:23 -0800 |
parents | 48b2ad5ee801 |
children | 1edaf1ee65eb |
comparison
equal
deleted
inserted
replaced
21150:f090661930ba | 21151:bfd5e48c41a1 |
---|---|
34 #include "f77-fcn.h" | 34 #include "f77-fcn.h" |
35 #include "lo-ieee.h" | 35 #include "lo-ieee.h" |
36 #include "oct-locbuf.h" | 36 #include "oct-locbuf.h" |
37 | 37 |
38 #include "Cell.h" | 38 #include "Cell.h" |
39 #include "error.h" | |
39 // mxArray must be declared as a class before including mexproto.h. | 40 // mxArray must be declared as a class before including mexproto.h. |
40 #include "mxarray.h" | 41 #include "mxarray.h" |
41 #include "mexproto.h" | 42 #include "mexproto.h" |
42 #include "oct-map.h" | 43 #include "oct-map.h" |
43 #include "ovl.h" | 44 #include "ovl.h" |
101 | 102 |
102 return retval; | 103 return retval; |
103 } | 104 } |
104 | 105 |
105 // ------------------------------------------------------------------ | 106 // ------------------------------------------------------------------ |
106 | |
107 void | |
108 mxArray_base::error (const char *msg) const | |
109 { | |
110 // FIXME | |
111 ::error ("%s", msg); | |
112 } | |
113 | 107 |
114 static mwIndex | 108 static mwIndex |
115 calc_single_subscript_internal (mwSize ndims, const mwSize *dims, | 109 calc_single_subscript_internal (mwSize ndims, const mwSize *dims, |
116 mwSize nsubs, const mwIndex *subs) | 110 mwSize nsubs, const mwIndex *subs) |
117 { | 111 { |
790 strcpy (class_name, name_arg); | 784 strcpy (class_name, name_arg); |
791 } | 785 } |
792 | 786 |
793 mxArray *get_cell (mwIndex /*idx*/) const | 787 mxArray *get_cell (mwIndex /*idx*/) const |
794 { | 788 { |
795 invalid_type_error (); | 789 err_invalid_type (); |
796 return 0; | |
797 } | 790 } |
798 | 791 |
799 void set_cell (mwIndex /*idx*/, mxArray */*val*/) | 792 void set_cell (mwIndex /*idx*/, mxArray */*val*/) |
800 { | 793 { |
801 invalid_type_error (); | 794 err_invalid_type (); |
802 } | 795 } |
803 | 796 |
804 double get_scalar (void) const | 797 double get_scalar (void) const |
805 { | 798 { |
806 invalid_type_error (); | 799 err_invalid_type (); |
807 return 0; | |
808 } | 800 } |
809 | 801 |
810 void *get_data (void) const | 802 void *get_data (void) const |
811 { | 803 { |
812 invalid_type_error (); | 804 err_invalid_type (); |
813 return 0; | |
814 } | 805 } |
815 | 806 |
816 void *get_imag_data (void) const | 807 void *get_imag_data (void) const |
817 { | 808 { |
818 invalid_type_error (); | 809 err_invalid_type (); |
819 return 0; | |
820 } | 810 } |
821 | 811 |
822 void set_data (void */*pr*/) | 812 void set_data (void */*pr*/) |
823 { | 813 { |
824 invalid_type_error (); | 814 err_invalid_type (); |
825 } | 815 } |
826 | 816 |
827 void set_imag_data (void */*pi*/) | 817 void set_imag_data (void */*pi*/) |
828 { | 818 { |
829 invalid_type_error (); | 819 err_invalid_type (); |
830 } | 820 } |
831 | 821 |
832 mwIndex *get_ir (void) const | 822 mwIndex *get_ir (void) const |
833 { | 823 { |
834 invalid_type_error (); | 824 err_invalid_type (); |
835 return 0; | |
836 } | 825 } |
837 | 826 |
838 mwIndex *get_jc (void) const | 827 mwIndex *get_jc (void) const |
839 { | 828 { |
840 invalid_type_error (); | 829 err_invalid_type (); |
841 return 0; | |
842 } | 830 } |
843 | 831 |
844 mwSize get_nzmax (void) const | 832 mwSize get_nzmax (void) const |
845 { | 833 { |
846 invalid_type_error (); | 834 err_invalid_type (); |
847 return 0; | |
848 } | 835 } |
849 | 836 |
850 void set_ir (mwIndex */*ir*/) | 837 void set_ir (mwIndex */*ir*/) |
851 { | 838 { |
852 invalid_type_error (); | 839 err_invalid_type (); |
853 } | 840 } |
854 | 841 |
855 void set_jc (mwIndex */*jc*/) | 842 void set_jc (mwIndex */*jc*/) |
856 { | 843 { |
857 invalid_type_error (); | 844 err_invalid_type (); |
858 } | 845 } |
859 | 846 |
860 void set_nzmax (mwSize /*nzmax*/) | 847 void set_nzmax (mwSize /*nzmax*/) |
861 { | 848 { |
862 invalid_type_error (); | 849 err_invalid_type (); |
863 } | 850 } |
864 | 851 |
865 int add_field (const char */*key*/) | 852 int add_field (const char */*key*/) |
866 { | 853 { |
867 invalid_type_error (); | 854 err_invalid_type (); |
868 return -1; | |
869 } | 855 } |
870 | 856 |
871 void remove_field (int /*key_num*/) | 857 void remove_field (int /*key_num*/) |
872 { | 858 { |
873 invalid_type_error (); | 859 err_invalid_type (); |
874 } | 860 } |
875 | 861 |
876 mxArray *get_field_by_number (mwIndex /*index*/, int /*key_num*/) const | 862 mxArray *get_field_by_number (mwIndex /*index*/, int /*key_num*/) const |
877 { | 863 { |
878 invalid_type_error (); | 864 err_invalid_type (); |
879 return 0; | |
880 } | 865 } |
881 | 866 |
882 void set_field_by_number (mwIndex /*index*/, int /*key_num*/, | 867 void set_field_by_number (mwIndex /*index*/, int /*key_num*/, |
883 mxArray */*val*/) | 868 mxArray */*val*/) |
884 { | 869 { |
885 invalid_type_error (); | 870 err_invalid_type (); |
886 } | 871 } |
887 | 872 |
888 int get_number_of_fields (void) const | 873 int get_number_of_fields (void) const |
889 { | 874 { |
890 invalid_type_error (); | 875 err_invalid_type (); |
891 return 0; | |
892 } | 876 } |
893 | 877 |
894 const char *get_field_name_by_number (int /*key_num*/) const | 878 const char *get_field_name_by_number (int /*key_num*/) const |
895 { | 879 { |
896 invalid_type_error (); | 880 err_invalid_type (); |
897 return 0; | |
898 } | 881 } |
899 | 882 |
900 int get_field_number (const char */*key*/) const | 883 int get_field_number (const char */*key*/) const |
901 { | 884 { |
902 return -1; | 885 return -1; |
903 } | 886 } |
904 | 887 |
905 int get_string (char */*buf*/, mwSize /*buflen*/) const | 888 int get_string (char */*buf*/, mwSize /*buflen*/) const |
906 { | 889 { |
907 invalid_type_error (); | 890 err_invalid_type (); |
908 return 0; | |
909 } | 891 } |
910 | 892 |
911 char *array_to_string (void) const | 893 char *array_to_string (void) const |
912 { | 894 { |
913 invalid_type_error (); | 895 err_invalid_type (); |
914 return 0; | |
915 } | 896 } |
916 | 897 |
917 mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const | 898 mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const |
918 { | 899 { |
919 return calc_single_subscript_internal (ndims, dims, nsubs, subs); | 900 return calc_single_subscript_internal (ndims, dims, nsubs, subs); |
976 mxClassID id; | 957 mxClassID id; |
977 | 958 |
978 mwSize ndims; | 959 mwSize ndims; |
979 mwSize *dims; | 960 mwSize *dims; |
980 | 961 |
981 void invalid_type_error (void) const | 962 OCTAVE_NORETURN void err_invalid_type (void) const |
982 { | 963 { |
983 error ("invalid type for operation"); | 964 error ("invalid type for operation"); |
984 } | 965 } |
985 | 966 |
986 // No assignment! FIXME: should this be implemented? Note that we | 967 // No assignment! |
987 // do have a copy constructor. | 968 // FIXME: should this be implemented? |
969 // Note that we *do* have a copy constructor. | |
988 | 970 |
989 mxArray_matlab& operator = (const mxArray_matlab&); | 971 mxArray_matlab& operator = (const mxArray_matlab&); |
990 }; | 972 }; |
991 | 973 |
992 // Matlab-style numeric, character, and logical data. | 974 // Matlab-style numeric, character, and logical data. |
1340 | 1322 |
1341 template <typename ELT_T, typename ARRAY_T, typename ARRAY_ELT_T> | 1323 template <typename ELT_T, typename ARRAY_T, typename ARRAY_ELT_T> |
1342 octave_value | 1324 octave_value |
1343 int_to_ov (const dim_vector& dv) const | 1325 int_to_ov (const dim_vector& dv) const |
1344 { | 1326 { |
1345 octave_value retval; | |
1346 | |
1347 mwSize nel = get_number_of_elements (); | |
1348 | |
1349 ELT_T *ppr = static_cast<ELT_T *> (pr); | |
1350 | |
1351 if (pi) | 1327 if (pi) |
1352 error ("complex integer types are not supported"); | 1328 error ("complex integer types are not supported"); |
1353 else | 1329 |
1354 { | 1330 mwSize nel = get_number_of_elements (); |
1355 ARRAY_T val (dv); | 1331 |
1356 | 1332 ELT_T *ppr = static_cast<ELT_T *> (pr); |
1357 ARRAY_ELT_T *ptr = val.fortran_vec (); | 1333 |
1358 | 1334 ARRAY_T val (dv); |
1359 for (mwIndex i = 0; i < nel; i++) | 1335 |
1360 ptr[i] = ppr[i]; | 1336 ARRAY_ELT_T *ptr = val.fortran_vec (); |
1361 | 1337 |
1362 retval = val; | 1338 for (mwIndex i = 0; i < nel; i++) |
1363 } | 1339 ptr[i] = ppr[i]; |
1364 | 1340 |
1365 return retval; | 1341 return octave_value (val); |
1366 } | 1342 } |
1367 | 1343 |
1368 mxArray_number (const mxArray_number& val) | 1344 mxArray_number (const mxArray_number& val) |
1369 : mxArray_matlab (val), | 1345 : mxArray_matlab (val), |
1370 pr (mxArray::malloc (get_number_of_elements () * get_element_size ())), | 1346 pr (mxArray::malloc (get_number_of_elements () * get_element_size ())), |
2062 void *ptr = gnulib::malloc (n); | 2038 void *ptr = gnulib::malloc (n); |
2063 | 2039 |
2064 if (! ptr) | 2040 if (! ptr) |
2065 { | 2041 { |
2066 // FIXME: could use "octave_new_handler();" instead | 2042 // FIXME: could use "octave_new_handler();" instead |
2067 | |
2068 error ("%s: failed to allocate %d bytes of memory", | 2043 error ("%s: failed to allocate %d bytes of memory", |
2069 function_name (), n); | 2044 function_name (), n); |
2070 } | 2045 } |
2071 | 2046 |
2072 global_mark (ptr); | 2047 global_mark (ptr); |
3076 // FIXME: do we need unwind protect to clean up args? Off hand, I | 3051 // FIXME: do we need unwind protect to clean up args? Off hand, I |
3077 // would say that this problem is endemic to Octave and we will | 3052 // would say that this problem is endemic to Octave and we will |
3078 // continue to have memory leaks after Ctrl-C until proper exception | 3053 // continue to have memory leaks after Ctrl-C until proper exception |
3079 // handling is implemented. | 3054 // handling is implemented. |
3080 | 3055 |
3056 // FIXME: Proper exception handling has been implemented (Jan. 2016). | |
3057 // Can this code be re-factored? | |
3081 args.resize (nargin); | 3058 args.resize (nargin); |
3082 | 3059 |
3083 for (int i = 0; i < nargin; i++) | 3060 for (int i = 0; i < nargin; i++) |
3084 args(i) = mxArray::as_octave_value (argin[i]); | 3061 args(i) = mxArray::as_octave_value (argin[i]); |
3085 | 3062 |