server: Expose few functions and structures from object.c [dir_object #4]

Vitaliy Margolen wine-patch at kievinfo.com
Wed Nov 2 12:42:09 CST 2005



Vitaliy Margolen

changelog:
  server
  - Expose few functions and structures from object.c
  - Add parent to the object_name
  - Move hash_size outside of get_name_hash
-------------- next part --------------
Index: server/object.c
===================================================================
RCS file: /home/wine/wine/server/object.c,v
retrieving revision 1.36
diff -u -p -r1.36 object.c
--- server/object.c	1 Nov 2005 10:22:38 -0000	1.36
+++ server/object.c	2 Nov 2005 18:20:32 -0000
@@ -35,14 +35,6 @@
 #include "unicode.h"
 
 
-struct object_name
-{
-    struct list         entry;    /* entry in the hash list */
-    struct object      *obj;
-    size_t              len;
-    WCHAR               name[1];
-};
-
 struct namespace
 {
     unsigned int        hash_size;       /* size of hash table */
@@ -89,22 +81,23 @@ void *memdup( const void *data, size_t l
 
 /*****************************************************************/
 
-static int get_name_hash( const struct namespace *namespace, const WCHAR *name, size_t len )
+int get_name_hash( const WCHAR *name, size_t len )
 {
     WCHAR hash = 0;
     len /= sizeof(WCHAR);
     while (len--) hash ^= tolowerW(*name++);
-    return hash % namespace->hash_size;
+    return hash;
 }
 
 /* allocate a name for an object */
-static struct object_name *alloc_name( const WCHAR *name, size_t len )
+struct object_name *alloc_name( const WCHAR *name, size_t len )
 {
     struct object_name *ptr;
 
     if ((ptr = mem_alloc( sizeof(*ptr) + len - sizeof(ptr->name) )))
     {
         ptr->len = len;
+        ptr->parent = NULL;
         memcpy( ptr->name, name, len );
     }
     return ptr;
@@ -122,7 +115,7 @@ static void free_name( struct object *ob
 static void set_object_name( struct namespace *namespace,
                              struct object *obj, struct object_name *ptr )
 {
-    int hash = get_name_hash( namespace, ptr->name, ptr->len );
+    int hash = get_name_hash( ptr->name, ptr->len ) % namespace->hash_size;
 
     list_add_head( &namespace->names[hash], &ptr->entry );
     ptr->obj = obj;
@@ -215,7 +211,12 @@ void release_object( void *ptr )
         /* if the refcount is 0, nobody can be in the wait queue */
         assert( list_empty( &obj->wait_queue ));
         obj->ops->destroy( obj );
-        if (obj->name) free_name( obj );
+        if (obj->name)
+        {
+            if (obj->name->parent)
+                release_object( obj->name->parent );
+            free_name( obj );
+        }
 #ifdef DEBUG_OBJECTS
         list_remove( &obj->obj_list );
         memset( obj, 0xaa, obj->ops->size );
@@ -232,7 +233,7 @@ struct object *find_object( const struct
 
     if (!name || !len) return NULL;
 
-    list = &namespace->names[ get_name_hash( namespace, name, len ) ];
+    list = &namespace->names[ get_name_hash( name, len ) % namespace->hash_size ];
     LIST_FOR_EACH( p, list )
     {
         const struct object_name *ptr = LIST_ENTRY( p, const struct object_name, entry );
Index: server/object.h
===================================================================
RCS file: /home/wine/wine/server/object.h,v
retrieving revision 1.68
diff -u -p -r1.68 object.h
--- server/object.h	1 Nov 2005 10:22:38 -0000	1.68
+++ server/object.h	2 Nov 2005 18:20:32 -0000
@@ -64,5 +93,14 @@ struct object_ops
     void (*destroy)(struct object *);
 };
 
+struct object_name
+{
+    struct list               entry;       /* entry in the hash list */
+    struct object            *obj;         /* pointer to an object */
+    struct object            *parent;      /* parent directory */
+    size_t                    len;         /* name lengh in bytes */
+    WCHAR                     name[1];
+};
+
 struct object
 {
@@ -90,6 +133,8 @@ struct wait_queue_entry
 
 extern void *mem_alloc( size_t size );  /* malloc wrapper */
 extern void *memdup( const void *data, size_t len );
+extern int get_name_hash( const WCHAR *name, size_t len );
+extern struct object_name *alloc_name( const WCHAR *name, size_t len );
 extern void *alloc_object( const struct object_ops *ops );
 extern const WCHAR *get_object_name( struct object *obj, size_t *len );
 extern void dump_object_name( struct object *obj );


More information about the wine-patches mailing list