tdebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xrescheck.c 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "xrescheck.h"
  2. static xrc_xid_record_t *gs_xid_records = NULL;
  3. #define HASH_ADD_XID(head, xidfield, add) \
  4. HASH_ADD(hh, head, xidfield, sizeof(xid), add)
  5. #define HASH_FIND_XID(head, findxid, out) \
  6. HASH_FIND(hh, head, findxid, sizeof(xid), out)
  7. #define M_CPY_POS_DATA(prec) \
  8. prec->file = file; \
  9. prec->func = func; \
  10. prec->line = line; \
  11. /**
  12. * @brief Add a record of given XID to the allocation table.
  13. */
  14. void
  15. xrc_add_xid_(XID xid, const char *type, M_POS_DATA_PARAMS) {
  16. xrc_xid_record_t *prec = cmalloc(1, xrc_xid_record_t);
  17. prec->xid = xid;
  18. prec->type = type;
  19. M_CPY_POS_DATA(prec);
  20. HASH_ADD_XID(gs_xid_records, xid, prec);
  21. }
  22. /**
  23. * @brief Delete a record of given XID in the allocation table.
  24. */
  25. void
  26. xrc_delete_xid_(XID xid, M_POS_DATA_PARAMS) {
  27. xrc_xid_record_t *prec = NULL;
  28. HASH_FIND_XID(gs_xid_records, &xid, prec);
  29. if (!prec) {
  30. printf_err("XRC: %s:%d %s(): Can't find XID %#010lx we want to delete.",
  31. file, line, func, xid);
  32. return;
  33. }
  34. HASH_DEL(gs_xid_records, prec);
  35. free(prec);
  36. }
  37. /**
  38. * @brief Report about issues found in the XID allocation table.
  39. */
  40. void
  41. xrc_report_xid(void) {
  42. for (xrc_xid_record_t *prec = gs_xid_records; prec; prec = prec->hh.next)
  43. printf_dbg("XRC: %s:%d %s(): %#010lx (%s) not freed.\n",
  44. prec->file, prec->line, prec->func, prec->xid, prec->type);
  45. }
  46. /**
  47. * @brief Clear the XID allocation table.
  48. */
  49. void
  50. xrc_clear_xid(void) {
  51. xrc_xid_record_t *prec = NULL, *ptmp = NULL;
  52. HASH_ITER(hh, gs_xid_records, prec, ptmp) {
  53. HASH_DEL(gs_xid_records, prec);
  54. free(prec);
  55. }
  56. }