Permalink
Browse files

Allow different sorting mechnisms for values stored within hashes

  • Loading branch information...
derickr committed Jan 13, 2018
1 parent 8a28a93 commit 10529fbc5cfba3bb65f30ddab441554ceda26647
Showing with 36 additions and 17 deletions.
  1. +4 −4 xdebug_handler_dbgp.c
  2. +22 −6 xdebug_hash.c
  3. +9 −6 xdebug_hash.h
  4. +1 −1 xdebug_monitor.c
View
@@ -2253,11 +2253,11 @@ int xdebug_dbgp_init(xdebug_con *context, int mode)
options->runtime[i].current_element_nr = 0;
}
context->breakpoint_list = xdebug_hash_alloc(64, (xdebug_hash_dtor) xdebug_hash_admin_dtor);
context->function_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor) xdebug_hash_brk_dtor);
context->exception_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor) xdebug_hash_brk_dtor);
context->breakpoint_list = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_admin_dtor);
context->function_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_brk_dtor);
context->exception_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_brk_dtor);
context->line_breakpoints = xdebug_llist_alloc((xdebug_llist_dtor) xdebug_llist_brk_dtor);
context->eval_id_lookup = xdebug_hash_alloc(64, (xdebug_hash_dtor) xdebug_hash_eval_info_dtor);
context->eval_id_lookup = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_eval_info_dtor);
context->eval_id_sequence = 0;
context->send_notifications = 0;
context->inhibit_notifications = 0;
View
@@ -23,10 +23,15 @@
#include "xdebug_hash.h"
#include "xdebug_llist.h"
/*
* Helper function to make a null terminated string from a key
* Forwards declarations
*/
static int xdebug_compare_le_name(const void *le1, const void *le2);
/*
* Helper function to make a null terminated string from a key
*/
char *xdebug_hash_key_to_str(xdebug_hash_key* key, int* new_len)
{
char *tmp;
@@ -80,15 +85,16 @@ static void hash_element_dtor(void *u, void *ele)
e = NULL;
}
xdebug_hash *xdebug_hash_alloc(int slots, xdebug_hash_dtor dtor)
xdebug_hash *xdebug_hash_alloc(int slots, xdebug_hash_dtor_t dtor)
{
xdebug_hash *h;
int i;
h = malloc(sizeof(xdebug_hash));
h->dtor = dtor;
h->size = 0;
h->slots = slots;
h->dtor = dtor;
h->sorter = xdebug_compare_le_name;
h->size = 0;
h->slots = slots;
h->table = (xdebug_llist **) malloc(slots * sizeof(xdebug_llist *));
for (i = 0; i < h->slots; ++i) {
@@ -98,6 +104,16 @@ xdebug_hash *xdebug_hash_alloc(int slots, xdebug_hash_dtor dtor)
return h;
}
xdebug_hash *xdebug_hash_alloc_with_sort(int slots, xdebug_hash_dtor_t dtor, xdebug_hash_apply_sorter_t sorter)
{
xdebug_hash *h;
h = xdebug_hash_alloc(slots, dtor);
h->sorter = sorter;
return h;
}
#define FIND_SLOT(__h, __s_key, __s_key_len, __n_key) \
((__s_key ? xdebug_hash_str(__s_key, __s_key_len) : xdebug_hash_num(__n_key)) % (__h)->slots)
@@ -254,7 +270,7 @@ void xdebug_hash_apply_with_argument(xdebug_hash *h, void *user, void (*cb)(void
pp_he_list[j++] = XDEBUG_LLIST_VALP(le);
}
}
qsort(pp_he_list, num_items, sizeof(xdebug_llist_element *), xdebug_compare_le_name);
qsort(pp_he_list, num_items, sizeof(xdebug_llist_element *), h->sorter);
for (i = 0; i < num_items; ++i) {
cb(user, pp_he_list[i], argument);
}
View
@@ -28,13 +28,15 @@
#define xdebug_ui32 unsigned long
typedef void (*xdebug_hash_dtor)(void *);
typedef void (*xdebug_hash_dtor_t)(void *);
typedef int (*xdebug_hash_apply_sorter_t)(const void *le1, const void *le2);
typedef struct _xdebug_hash {
xdebug_llist **table;
xdebug_hash_dtor dtor;
int slots;
size_t size;
xdebug_llist **table;
xdebug_hash_dtor_t dtor;
xdebug_hash_apply_sorter_t sorter;
int slots;
size_t size;
} xdebug_hash;
typedef struct _xdebug_hash_key {
@@ -59,7 +61,8 @@ typedef struct _xdebug_hash_element {
char* xdebug_hash_key_to_str(xdebug_hash_key* key, int* new_len);
/* Standard functions */
xdebug_hash *xdebug_hash_alloc(int slots, xdebug_hash_dtor dtor);
xdebug_hash *xdebug_hash_alloc(int slots, xdebug_hash_dtor_t dtor);
xdebug_hash *xdebug_hash_alloc_with_sort(int slots, xdebug_hash_dtor_t dtor, xdebug_hash_apply_sorter_t sort_func);
int xdebug_hash_add_or_update(xdebug_hash *h, const char *str_key, unsigned int str_key_len, unsigned long num_key, const void *p);
int xdebug_hash_extended_delete(xdebug_hash *h, const char *str_key, unsigned int str_key_len, unsigned long num_key);
int xdebug_hash_extended_find(xdebug_hash *h, const char *str_key, unsigned int str_key_len, unsigned long num_key, void **p);
View
@@ -86,7 +86,7 @@ PHP_FUNCTION(xdebug_start_function_monitor)
}
/* We add "1" here so that we don't alloc a 0-slot hash table */
XG(functions_to_monitor) = xdebug_hash_alloc(zend_hash_num_elements(functions_to_monitor) + 1, (xdebug_hash_dtor) xdebug_hash_function_monitor_dtor);
XG(functions_to_monitor) = xdebug_hash_alloc(zend_hash_num_elements(functions_to_monitor) + 1, (xdebug_hash_dtor_t) xdebug_hash_function_monitor_dtor);
init_function_monitor_hash(XG(functions_to_monitor), functions_to_monitor);
XG(do_monitor_functions) = 1;

0 comments on commit 10529fb

Please sign in to comment.