mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-04 13:29:51 -05:00
Make sure we initialize object hash.
This patch also move the hash implementation details to wayland-util.c.
This commit is contained in:
parent
997e71eb1e
commit
864c468b42
3 changed files with 42 additions and 11 deletions
|
|
@ -21,8 +21,34 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "wayland.h"
|
#include "wayland.h"
|
||||||
|
|
||||||
|
struct wl_hash {
|
||||||
|
struct wl_object **objects;
|
||||||
|
uint32_t count, alloc;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wl_hash *
|
||||||
|
wl_hash_create(void)
|
||||||
|
{
|
||||||
|
struct wl_hash *hash;
|
||||||
|
|
||||||
|
hash = malloc(sizeof *hash);
|
||||||
|
if (hash == NULL)
|
||||||
|
return hash;
|
||||||
|
|
||||||
|
memset(hash, 0, sizeof *hash);
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wl_hash_destroy(struct wl_hash *hash)
|
||||||
|
{
|
||||||
|
free(hash);
|
||||||
|
}
|
||||||
|
|
||||||
int wl_hash_insert(struct wl_hash *hash, struct wl_object *object)
|
int wl_hash_insert(struct wl_hash *hash, struct wl_object *object)
|
||||||
{
|
{
|
||||||
struct wl_object **objects;
|
struct wl_object **objects;
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,10 @@
|
||||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||||
|
|
||||||
struct wl_hash {
|
struct wl_object;
|
||||||
struct wl_object **objects;
|
struct wl_hash;
|
||||||
uint32_t count, alloc, id;
|
struct wl_hash *wl_hash_create(void);
|
||||||
};
|
void wl_hash_destroy(struct wl_hash *hash);
|
||||||
|
|
||||||
int wl_hash_insert(struct wl_hash *hash, struct wl_object *object);
|
int wl_hash_insert(struct wl_hash *hash, struct wl_object *object);
|
||||||
struct wl_object *wl_hash_lookup(struct wl_hash *hash, uint32_t id);
|
struct wl_object *wl_hash_lookup(struct wl_hash *hash, uint32_t id);
|
||||||
void wl_hash_delete(struct wl_hash *hash, struct wl_object *object);
|
void wl_hash_delete(struct wl_hash *hash, struct wl_object *object);
|
||||||
|
|
|
||||||
18
wayland.c
18
wayland.c
|
|
@ -49,7 +49,7 @@ struct wl_client {
|
||||||
struct wl_display {
|
struct wl_display {
|
||||||
struct wl_object base;
|
struct wl_object base;
|
||||||
struct wl_event_loop *loop;
|
struct wl_event_loop *loop;
|
||||||
struct wl_hash objects;
|
struct wl_hash *objects;
|
||||||
|
|
||||||
struct wl_object *pointer;
|
struct wl_object *pointer;
|
||||||
|
|
||||||
|
|
@ -317,7 +317,7 @@ wl_client_demarshal(struct wl_client *client, struct wl_object *target,
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
types[i] = &ffi_type_pointer;
|
types[i] = &ffi_type_pointer;
|
||||||
object = wl_hash_lookup(&client->display->objects, *p);
|
object = wl_hash_lookup(client->display->objects, *p);
|
||||||
if (object == NULL)
|
if (object == NULL)
|
||||||
printf("unknown object (%d)\n", *p);
|
printf("unknown object (%d)\n", *p);
|
||||||
if (object->interface != method->types[j])
|
if (object->interface != method->types[j])
|
||||||
|
|
@ -329,7 +329,7 @@ wl_client_demarshal(struct wl_client *client, struct wl_object *target,
|
||||||
case 'n':
|
case 'n':
|
||||||
types[i] = &ffi_type_uint32;
|
types[i] = &ffi_type_uint32;
|
||||||
values[i].new_id = *p;
|
values[i].new_id = *p;
|
||||||
object = wl_hash_lookup(&client->display->objects, *p);
|
object = wl_hash_lookup(client->display->objects, *p);
|
||||||
if (object != NULL)
|
if (object != NULL)
|
||||||
printf("object already exists (%d)\n", *p);
|
printf("object already exists (%d)\n", *p);
|
||||||
p++;
|
p++;
|
||||||
|
|
@ -380,7 +380,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
|
||||||
if (len < size)
|
if (len < size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
object = wl_hash_lookup(&client->display->objects, p[0]);
|
object = wl_hash_lookup(client->display->objects, p[0]);
|
||||||
if (object == NULL) {
|
if (object == NULL) {
|
||||||
wl_client_marshal(client, &client->display->base,
|
wl_client_marshal(client, &client->display->base,
|
||||||
WL_DISPLAY_INVALID_OBJECT, p[0]);
|
WL_DISPLAY_INVALID_OBJECT, p[0]);
|
||||||
|
|
@ -518,7 +518,7 @@ wl_display_create_surface(struct wl_client *client,
|
||||||
}
|
}
|
||||||
|
|
||||||
ref->object = &surface->base;
|
ref->object = &surface->base;
|
||||||
wl_hash_insert(&display->objects, &surface->base);
|
wl_hash_insert(display->objects, &surface->base);
|
||||||
wl_list_insert(client->object_list.prev, &ref->link);
|
wl_list_insert(client->object_list.prev, &ref->link);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -575,6 +575,12 @@ wl_display_create(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
display->objects = wl_hash_create();
|
||||||
|
if (display->objects == NULL) {
|
||||||
|
free(display);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
wl_list_init(&display->surface_list);
|
wl_list_init(&display->surface_list);
|
||||||
wl_list_init(&display->client_list);
|
wl_list_init(&display->client_list);
|
||||||
wl_list_init(&display->global_list);
|
wl_list_init(&display->global_list);
|
||||||
|
|
@ -597,7 +603,7 @@ WL_EXPORT void
|
||||||
wl_display_add_object(struct wl_display *display, struct wl_object *object)
|
wl_display_add_object(struct wl_display *display, struct wl_object *object)
|
||||||
{
|
{
|
||||||
object->id = display->id++;
|
object->id = display->id++;
|
||||||
wl_hash_insert(&display->objects, object);
|
wl_hash_insert(display->objects, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT int
|
WL_EXPORT int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue