Software /
code /
prosody
Comparison
util-src/pposix.c @ 12154:760dd1fc3dc1
util.pposix: Use mallinfo2() on glibc 2.33, fix #1649
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 06 Jan 2022 18:56:06 +0100 |
parent | 11656:c368b4f6ee04 |
child | 12575:1f6f05a98fcd |
comparison
equal
deleted
inserted
replaced
12153:26af75c20163 | 12154:760dd1fc3dc1 |
---|---|
726 return 1; | 726 return 1; |
727 } | 727 } |
728 | 728 |
729 #ifdef WITH_MALLINFO | 729 #ifdef WITH_MALLINFO |
730 static int lc_meminfo(lua_State *L) { | 730 static int lc_meminfo(lua_State *L) { |
731 #if __GLIBC_PREREQ(2, 33) | |
732 struct mallinfo2 info = mallinfo2(); | |
733 #define MALLINFO_T size_t | |
734 #else | |
731 struct mallinfo info = mallinfo(); | 735 struct mallinfo info = mallinfo(); |
736 #define MALLINFO_T unsigned | |
737 #endif | |
732 lua_createtable(L, 0, 5); | 738 lua_createtable(L, 0, 5); |
733 /* This is the total size of memory allocated with sbrk by malloc, in bytes. */ | 739 /* This is the total size of memory allocated with sbrk by malloc, in bytes. */ |
734 lua_pushinteger(L, (unsigned)info.arena); | 740 lua_pushinteger(L, (MALLINFO_T)info.arena); |
735 lua_setfield(L, -2, "allocated"); | 741 lua_setfield(L, -2, "allocated"); |
736 /* This is the total size of memory allocated with mmap, in bytes. */ | 742 /* This is the total size of memory allocated with mmap, in bytes. */ |
737 lua_pushinteger(L, (unsigned)info.hblkhd); | 743 lua_pushinteger(L, (MALLINFO_T)info.hblkhd); |
738 lua_setfield(L, -2, "allocated_mmap"); | 744 lua_setfield(L, -2, "allocated_mmap"); |
739 /* This is the total size of memory occupied by chunks handed out by malloc. */ | 745 /* This is the total size of memory occupied by chunks handed out by malloc. */ |
740 lua_pushinteger(L, (unsigned)info.uordblks); | 746 lua_pushinteger(L, (MALLINFO_T)info.uordblks); |
741 lua_setfield(L, -2, "used"); | 747 lua_setfield(L, -2, "used"); |
742 /* This is the total size of memory occupied by free (not in use) chunks. */ | 748 /* This is the total size of memory occupied by free (not in use) chunks. */ |
743 lua_pushinteger(L, (unsigned)info.fordblks); | 749 lua_pushinteger(L, (MALLINFO_T)info.fordblks); |
744 lua_setfield(L, -2, "unused"); | 750 lua_setfield(L, -2, "unused"); |
745 /* This is the size of the top-most releasable chunk that normally borders the | 751 /* This is the size of the top-most releasable chunk that normally borders the |
746 end of the heap (i.e., the high end of the virtual address space's data segment). */ | 752 end of the heap (i.e., the high end of the virtual address space's data segment). */ |
747 lua_pushinteger(L, (unsigned)info.keepcost); | 753 lua_pushinteger(L, (MALLINFO_T)info.keepcost); |
748 lua_setfield(L, -2, "returnable"); | 754 lua_setfield(L, -2, "returnable"); |
749 return 1; | 755 return 1; |
750 } | 756 } |
757 #undef MALLINFO_T | |
751 #endif | 758 #endif |
752 | 759 |
753 /* | 760 /* |
754 * Append some data to a file handle | 761 * Append some data to a file handle |
755 * Attempt to allocate space first | 762 * Attempt to allocate space first |