Changeset 10892 for branches/jch-memory/psLib/src/sys/psMemory.c
- Timestamp:
- Jan 3, 2007, 11:53:56 AM (19 years ago)
- File:
-
- 1 edited
-
branches/jch-memory/psLib/src/sys/psMemory.c (modified) (39 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/jch-memory/psLib/src/sys/psMemory.c
r10888 r10892 8 8 * @author Robert Lupton, Princeton University 9 9 * 10 * @version $Revision: 1.88.2. 4$ $Name: not supported by cvs2svn $11 * @date $Date: 2007-01-03 04:46:32$10 * @version $Revision: 1.88.2.5 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2007-01-03 21:53:56 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psMemory.h" 25 25 #include "psError.h" 26 #include "psAssert.h" 27 #include "psLogMsg.h" 26 28 27 #include "psBitSet.h" 29 28 #include "psFits.h" … … 51 50 // this and would deadlock while trying to allocate memory. 52 51 #define PS_MEM_ABORT(name, ...) \ 53 fprintf(stderr, "Memory Management Error. This error can not be logged.\n") ;\ 52 P_PS_MEM_ABORT(__FILE__, __LINE__, __func__, name, __VA_ARGS__) 53 54 #define P_PS_MEM_ABORT(filename, lineno, func, name, ...) \ 55 fprintf(stderr, "%s (%s:%d) ", func, filename, lineno); \ 54 56 fprintf(stderr, __VA_ARGS__);\ 57 psErrorStackPrint(stderr, "\nAborting. Error stack:"); \ 55 58 fprintf(stderr, "\n");\ 56 59 abort(); 60 61 #define PS_MEM_ERROR(code, new, ...) \ 62 P_PS_MEM_ERROR(__FILE__, __LINE__, __func__, code, new, __VA_ARGS__) 63 64 #define P_PS_MEM_ERROR(filename, lineno, func, code, new, ...) \ 65 fprintf(stderr, "%s (%s:%d) ", func, filename, lineno); \ 66 fprintf(stderr, __VA_ARGS__);\ 67 fprintf(stderr, "\n"); 57 68 58 69 static psS32 checkMemBlock(const psMemBlock* m, const char *funcName); … … 109 120 { 110 121 if (ptr->refCounter < 1) { 111 psError(PS_ERR_MEMORY_CORRUPTION, false,112 _("Block %lu, allocated at %s:%d, freed multiple times at %s:%d."),113 (unsigned long)ptr->id, ptr->file, ptr->lineno, file, lineno);122 PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, false, 123 _("Block %lu, allocated at %s:%d, freed multiple times at %s:%d."), 124 (unsigned long)ptr->id, ptr->file, ptr->lineno, file, lineno); 114 125 } 115 126 … … 131 142 132 143 if (m == NULL) { 133 psError(PS_ERR_MEMORY_CORRUPTION, true,134 _("NULL memory block found."));144 PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true, 145 _("NULL memory block found.")); 135 146 return 1; 136 147 } … … 138 149 if (m->refCounter == 0) { 139 150 // using an unreferenced block of memory, are you? 140 psError(PS_ERR_MEMORY_CORRUPTION, true,141 _("Memory block %lu was freed but still being used."),142 (unsigned long)m->id);151 PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true, 152 _("Memory block %lu was freed but still being used."), 153 (unsigned long)m->id); 143 154 return 1; 144 155 } 145 156 146 157 if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) { 147 psError(PS_ERR_MEMORY_CORRUPTION, true,148 _("Memory block %lu is corrupted; buffer underflow detected."),149 (unsigned long)m->id);158 PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true, 159 _("Memory block %lu is corrupted; buffer underflow detected."), 160 (unsigned long)m->id); 150 161 return 1; 151 162 } 152 163 if (*(psPtr *)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) { 153 psError(PS_ERR_MEMORY_CORRUPTION, true,154 _("Memory block %lu is corrupted; buffer overflow detected."),155 (unsigned long)m->id);164 PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true, 165 _("Memory block %lu is corrupted; buffer overflow detected."), 166 (unsigned long)m->id); 156 167 return 1; 157 168 } … … 709 720 psPtr ptr) 710 721 { 711 PS_ASSERT_PTR(ptr, false);722 // PS_ASSERT_PTR(ptr, false); 712 723 713 724 switch(type) { … … 716 727 return true; 717 728 else { 718 psError(PS_ERR_BAD_PARAMETER_VALUE, false,719 "Incorrect pointer. Datatypes do not match.\n");729 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 730 "Incorrect pointer. Datatypes do not match.\n"); 720 731 break; 721 732 } … … 724 735 return true; 725 736 else { 726 psError(PS_ERR_BAD_PARAMETER_VALUE, false,727 "Incorrect pointer. Datatypes do not match.\n");737 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 738 "Incorrect pointer. Datatypes do not match.\n"); 728 739 break; 729 740 } … … 732 743 return true; 733 744 else { 734 psError(PS_ERR_BAD_PARAMETER_VALUE, false,735 "Incorrect pointer. Datatypes do not match.\n");745 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 746 "Incorrect pointer. Datatypes do not match.\n"); 736 747 break; 737 748 } … … 740 751 return true; 741 752 else { 742 psError(PS_ERR_BAD_PARAMETER_VALUE, false,743 "Incorrect pointer. Datatypes do not match.\n");753 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 754 "Incorrect pointer. Datatypes do not match.\n"); 744 755 break; 745 756 } … … 748 759 return true; 749 760 else { 750 psError(PS_ERR_BAD_PARAMETER_VALUE, false,751 "Incorrect pointer. Datatypes do not match.\n");761 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 762 "Incorrect pointer. Datatypes do not match.\n"); 752 763 break; 753 764 } … … 756 767 return true; 757 768 else { 758 psError(PS_ERR_BAD_PARAMETER_VALUE, false,759 "Incorrect pointer. Datatypes do not match.\n");769 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 770 "Incorrect pointer. Datatypes do not match.\n"); 760 771 break; 761 772 } … … 764 775 return true; 765 776 else { 766 psError(PS_ERR_BAD_PARAMETER_VALUE, false,767 "Incorrect pointer. Datatypes do not match.\n");777 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 778 "Incorrect pointer. Datatypes do not match.\n"); 768 779 break; 769 780 } … … 772 783 return true; 773 784 else { 774 psError(PS_ERR_BAD_PARAMETER_VALUE, false,775 "Incorrect pointer. Datatypes do not match.\n");785 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 786 "Incorrect pointer. Datatypes do not match.\n"); 776 787 break; 777 788 } … … 780 791 return true; 781 792 else { 782 psError(PS_ERR_BAD_PARAMETER_VALUE, false,783 "Incorrect pointer. Datatypes do not match.\n");793 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 794 "Incorrect pointer. Datatypes do not match.\n"); 784 795 break; 785 796 } … … 788 799 return true; 789 800 else { 790 psError(PS_ERR_BAD_PARAMETER_VALUE, false,791 "Incorrect pointer. Datatypes do not match.\n");801 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 802 "Incorrect pointer. Datatypes do not match.\n"); 792 803 break; 793 804 } … … 796 807 return true; 797 808 else { 798 psError(PS_ERR_BAD_PARAMETER_VALUE, false,799 "Incorrect pointer. Datatypes do not match.\n");809 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 810 "Incorrect pointer. Datatypes do not match.\n"); 800 811 break; 801 812 } … … 804 815 return true; 805 816 else { 806 psError(PS_ERR_BAD_PARAMETER_VALUE, false,807 "Incorrect pointer. Datatypes do not match.\n");817 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 818 "Incorrect pointer. Datatypes do not match.\n"); 808 819 break; 809 820 } … … 812 823 return true; 813 824 else { 814 psError(PS_ERR_BAD_PARAMETER_VALUE, false,815 "Incorrect pointer. Datatypes do not match.\n");825 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 826 "Incorrect pointer. Datatypes do not match.\n"); 816 827 break; 817 828 } … … 820 831 return true; 821 832 else { 822 psError(PS_ERR_BAD_PARAMETER_VALUE, false,823 "Incorrect pointer. Datatypes do not match.\n");833 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 834 "Incorrect pointer. Datatypes do not match.\n"); 824 835 break; 825 836 } … … 828 839 return true; 829 840 else { 830 psError(PS_ERR_BAD_PARAMETER_VALUE, false,831 "Incorrect pointer. Datatypes do not match.\n");841 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 842 "Incorrect pointer. Datatypes do not match.\n"); 832 843 break; 833 844 } … … 836 847 return true; 837 848 else { 838 psError(PS_ERR_BAD_PARAMETER_VALUE, false,839 "Incorrect pointer. Datatypes do not match.\n");849 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 850 "Incorrect pointer. Datatypes do not match.\n"); 840 851 break; 841 852 } … … 844 855 return true; 845 856 else { 846 psError(PS_ERR_BAD_PARAMETER_VALUE, false,847 "Incorrect pointer. Datatypes do not match.\n");857 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 858 "Incorrect pointer. Datatypes do not match.\n"); 848 859 break; 849 860 } … … 852 863 return true; 853 864 else { 854 psError(PS_ERR_BAD_PARAMETER_VALUE, false,855 "Incorrect pointer. Datatypes do not match.\n");865 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 866 "Incorrect pointer. Datatypes do not match.\n"); 856 867 break; 857 868 } … … 860 871 return true; 861 872 else { 862 psError(PS_ERR_BAD_PARAMETER_VALUE, false,863 "Incorrect pointer. Datatypes do not match.\n");873 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 874 "Incorrect pointer. Datatypes do not match.\n"); 864 875 break; 865 876 } … … 868 879 return true; 869 880 else { 870 psError(PS_ERR_BAD_PARAMETER_VALUE, false,871 "Incorrect pointer. Datatypes do not match.\n");881 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 882 "Incorrect pointer. Datatypes do not match.\n"); 872 883 break; 873 884 } … … 876 887 return true; 877 888 else { 878 psError(PS_ERR_BAD_PARAMETER_VALUE, false,879 "Incorrect pointer. Datatypes do not match.\n");889 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 890 "Incorrect pointer. Datatypes do not match.\n"); 880 891 break; 881 892 } … … 884 895 return true; 885 896 else { 886 psError(PS_ERR_BAD_PARAMETER_VALUE, false,887 "Incorrect pointer. Datatypes do not match.\n");897 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 898 "Incorrect pointer. Datatypes do not match.\n"); 888 899 break; 889 900 } … … 892 903 return true; 893 904 else { 894 psError(PS_ERR_BAD_PARAMETER_VALUE, false,895 "Incorrect pointer. Datatypes do not match.\n");905 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 906 "Incorrect pointer. Datatypes do not match.\n"); 896 907 break; 897 908 } … … 900 911 return true; 901 912 else { 902 psError(PS_ERR_BAD_PARAMETER_VALUE, false,903 "Incorrect pointer. Datatypes do not match.\n");913 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 914 "Incorrect pointer. Datatypes do not match.\n"); 904 915 break; 905 916 } … … 908 919 return true; 909 920 else { 910 psError(PS_ERR_BAD_PARAMETER_VALUE, false,911 "Incorrect pointer. Datatypes do not match.\n");921 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 922 "Incorrect pointer. Datatypes do not match.\n"); 912 923 break; 913 924 } … … 916 927 return true; 917 928 else { 918 psError(PS_ERR_BAD_PARAMETER_VALUE, false,919 "Incorrect pointer. Datatypes do not match.\n");929 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 930 "Incorrect pointer. Datatypes do not match.\n"); 920 931 break; 921 932 } … … 924 935 return true; 925 936 else { 926 psError(PS_ERR_BAD_PARAMETER_VALUE, false,927 "Incorrect pointer. Datatypes do not match.\n");937 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 938 "Incorrect pointer. Datatypes do not match.\n"); 928 939 break; 929 940 } … … 932 943 return true; 933 944 else { 934 psError(PS_ERR_BAD_PARAMETER_VALUE, false,935 "Incorrect pointer. Datatypes do not match.\n");945 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 946 "Incorrect pointer. Datatypes do not match.\n"); 936 947 break; 937 948 } … … 940 951 return true; 941 952 else { 942 psError(PS_ERR_BAD_PARAMETER_VALUE, false,943 "Incorrect pointer. Datatypes do not match.\n");953 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 954 "Incorrect pointer. Datatypes do not match.\n"); 944 955 break; 945 956 } … … 948 959 return true; 949 960 else { 950 psError(PS_ERR_BAD_PARAMETER_VALUE, false,951 "Incorrect pointer. Datatypes do not match.\n");961 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 962 "Incorrect pointer. Datatypes do not match.\n"); 952 963 break; 953 964 } … … 956 967 return true; 957 968 else { 958 psError(PS_ERR_BAD_PARAMETER_VALUE, false,959 "Incorrect pointer. Datatypes do not match.\n");969 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 970 "Incorrect pointer. Datatypes do not match.\n"); 960 971 break; 961 972 } … … 964 975 return true; 965 976 else { 966 psError(PS_ERR_BAD_PARAMETER_VALUE, false,967 "Incorrect pointer. Datatypes do not match.\n");977 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false, 978 "Incorrect pointer. Datatypes do not match.\n"); 968 979 break; 969 980 } 970 981 default: 971 psError(PS_ERR_BAD_PARAMETER_TYPE, true,972 "Invalid datatype specified.\n");982 PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_TYPE, true, 983 "Invalid datatype specified.\n"); 973 984 } 974 985 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
