<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>dbus-dataslot.c Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="pages.html">Related Pages</a> </center> <hr><h1>dbus-dataslot.c</h1><div class="fragment"><pre>00001 <font class="comment">/* -*- mode: C; c-file-style: "gnu" -*- */</font> 00002 <font class="comment">/* dbus-dataslot.c storing data on objects</font> 00003 <font class="comment"> *</font> 00004 <font class="comment"> * Copyright (C) 2003 Red Hat, Inc.</font> 00005 <font class="comment"> *</font> 00006 <font class="comment"> * Licensed under the Academic Free License version 2.0</font> 00007 <font class="comment"> * </font> 00008 <font class="comment"> * This program is free software; you can redistribute it and/or modify</font> 00009 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> 00010 <font class="comment"> * the Free Software Foundation; either version 2 of the License, or</font> 00011 <font class="comment"> * (at your option) any later version.</font> 00012 <font class="comment"> *</font> 00013 <font class="comment"> * This program is distributed in the hope that it will be useful,</font> 00014 <font class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</font> 00015 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</font> 00016 <font class="comment"> * GNU General Public License for more details.</font> 00017 <font class="comment"> * </font> 00018 <font class="comment"> * You should have received a copy of the GNU General Public License</font> 00019 <font class="comment"> * along with this program; if not, write to the Free Software</font> 00020 <font class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font> 00021 <font class="comment"> *</font> 00022 <font class="comment"> */</font> 00023 <font class="preprocessor">#include "dbus-dataslot.h"</font> 00024 <font class="preprocessor">#include "dbus-threads.h"</font> 00025 00043 dbus_bool_t <a name="l00044"></a><a class="code" href="group__DBusDataSlot.html#a0">00044</a> _dbus_data_slot_allocator_init (<a class="code" href="structDBusDataSlotAllocator.html">DBusDataSlotAllocator</a> *allocator) 00045 { 00046 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a> = NULL; 00047 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a> = 0; 00048 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m2">n_used_slots</a> = 0; 00049 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a> = NULL; 00050 00051 <font class="keywordflow">return</font> TRUE; 00052 } 00053 00066 dbus_bool_t <a name="l00067"></a><a class="code" href="group__DBusDataSlot.html#a1">00067</a> _dbus_data_slot_allocator_alloc (<a class="code" href="structDBusDataSlotAllocator.html">DBusDataSlotAllocator</a> *allocator, 00068 DBusMutex *mutex, 00069 dbus_int32_t *slot_id_p) 00070 { 00071 dbus_int32_t slot; 00072 00073 <font class="keywordflow">if</font> (!dbus_mutex_lock (mutex)) 00074 <font class="keywordflow">return</font> FALSE; 00075 00076 <font class="keywordflow">if</font> (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a> == 0) 00077 { 00078 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a> == NULL); 00079 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a> = mutex; 00080 } 00081 <font class="keywordflow">else</font> 00082 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a> == mutex); 00083 00084 <font class="keywordflow">if</font> (*slot_id_p >= 0) 00085 { 00086 slot = *slot_id_p; 00087 00088 _dbus_assert (slot < allocator->n_allocated_slots); 00089 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> == slot); 00090 00091 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m1">refcount</a> += 1; 00092 00093 <font class="keywordflow">goto</font> out; 00094 } 00095 00096 _dbus_assert (*slot_id_p < 0); 00097 00098 <font class="keywordflow">if</font> (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m2">n_used_slots</a> < allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a>) 00099 { 00100 slot = 0; 00101 <font class="keywordflow">while</font> (slot < allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a>) 00102 { 00103 <font class="keywordflow">if</font> (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> < 0) 00104 { 00105 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> = slot; 00106 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m1">refcount</a> = 1; 00107 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m2">n_used_slots</a> += 1; 00108 <font class="keywordflow">break</font>; 00109 } 00110 ++slot; 00111 } 00112 00113 _dbus_assert (slot < allocator->n_allocated_slots); 00114 } 00115 <font class="keywordflow">else</font> 00116 { 00117 <a class="code" href="structDBusAllocatedSlot.html">DBusAllocatedSlot</a> *tmp; 00118 00119 slot = -1; 00120 tmp = dbus_realloc (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>, 00121 sizeof (<a class="code" href="structDBusAllocatedSlot.html">DBusAllocatedSlot</a>) * (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a> + 1)); 00122 <font class="keywordflow">if</font> (tmp == NULL) 00123 <font class="keywordflow">goto</font> out; 00124 00125 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a> = tmp; 00126 slot = allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a>; 00127 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a> += 1; 00128 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m2">n_used_slots</a> += 1; 00129 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> = slot; 00130 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m1">refcount</a> = 1; 00131 } 00132 00133 _dbus_assert (slot >= 0); 00134 _dbus_assert (slot < allocator->n_allocated_slots); 00135 _dbus_assert (*slot_id_p < 0); 00136 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> == slot); 00137 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m1">refcount</a> == 1); 00138 00139 *slot_id_p = slot; 00140 00141 _dbus_verbose (<font class="stringliteral">"Allocated slot %d on allocator %p total %d slots allocated %d used\n"</font>, 00142 slot, allocator, allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a>, allocator-><a class="code" href="structDBusDataSlotAllocator.html#m2">n_used_slots</a>); 00143 00144 out: 00145 dbus_mutex_unlock (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>); 00146 <font class="keywordflow">return</font> slot >= 0; 00147 } 00148 00160 <font class="keywordtype">void</font> <a name="l00161"></a><a class="code" href="group__DBusDataSlot.html#a2">00161</a> _dbus_data_slot_allocator_free (<a class="code" href="structDBusDataSlotAllocator.html">DBusDataSlotAllocator</a> *allocator, 00162 dbus_int32_t *slot_id_p) 00163 { 00164 dbus_mutex_lock (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>); 00165 00166 _dbus_assert (*slot_id_p < allocator->n_allocated_slots); 00167 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> == *slot_id_p); 00168 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#m1">refcount</a> > 0); 00169 00170 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#m1">refcount</a> -= 1; 00171 00172 <font class="keywordflow">if</font> (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#m1">refcount</a> > 0) 00173 { 00174 dbus_mutex_unlock (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>); 00175 <font class="keywordflow">return</font>; 00176 } 00177 00178 <font class="comment">/* refcount is 0, free the slot */</font> 00179 _dbus_verbose (<font class="stringliteral">"Freeing slot %d on allocator %p total %d allocated %d used\n"</font>, 00180 *slot_id_p, allocator, allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a>, allocator-><a class="code" href="structDBusDataSlotAllocator.html#m2">n_used_slots</a>); 00181 00182 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> = -1; 00183 *slot_id_p = -1; 00184 00185 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m2">n_used_slots</a> -= 1; 00186 00187 <font class="keywordflow">if</font> (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m2">n_used_slots</a> == 0) 00188 { 00189 DBusMutex *mutex = allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>; 00190 00191 dbus_free (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>); 00192 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a> = NULL; 00193 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m1">n_allocated_slots</a> = 0; 00194 allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a> = NULL; 00195 00196 dbus_mutex_unlock (mutex); 00197 } 00198 <font class="keywordflow">else</font> 00199 { 00200 dbus_mutex_unlock (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>); 00201 } 00202 } 00203 00208 <font class="keywordtype">void</font> <a name="l00209"></a><a class="code" href="group__DBusDataSlot.html#a3">00209</a> _dbus_data_slot_list_init (<a class="code" href="structDBusDataSlotList.html">DBusDataSlotList</a> *list) 00210 { 00211 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a> = NULL; 00212 list-><a class="code" href="structDBusDataSlotList.html#m1">n_slots</a> = 0; 00213 } 00214 00232 dbus_bool_t <a name="l00233"></a><a class="code" href="group__DBusDataSlot.html#a4">00233</a> _dbus_data_slot_list_set (<a class="code" href="structDBusDataSlotAllocator.html">DBusDataSlotAllocator</a> *allocator, 00234 <a class="code" href="structDBusDataSlotList.html">DBusDataSlotList</a> *list, 00235 <font class="keywordtype">int</font> slot, 00236 <font class="keywordtype">void</font> *data, 00237 DBusFreeFunction free_data_func, 00238 DBusFreeFunction *old_free_func, 00239 <font class="keywordtype">void</font> **old_data) 00240 { 00241 <font class="preprocessor">#ifndef DBUS_DISABLE_ASSERT</font> 00242 <font class="preprocessor"></font> <font class="comment">/* We need to take the allocator lock here, because the allocator could</font> 00243 <font class="comment"> * be e.g. realloc()ing allocated_slots. We avoid doing this if asserts</font> 00244 <font class="comment"> * are disabled, since then the asserts are empty.</font> 00245 <font class="comment"> */</font> 00246 <font class="keywordflow">if</font> (!dbus_mutex_lock (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>)) 00247 <font class="keywordflow">return</font> FALSE; 00248 _dbus_assert (slot < allocator->n_allocated_slots); 00249 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> == slot); 00250 dbus_mutex_unlock (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>); 00251 <font class="preprocessor">#endif</font> 00252 <font class="preprocessor"></font> 00253 <font class="keywordflow">if</font> (slot >= list-><a class="code" href="structDBusDataSlotList.html#m1">n_slots</a>) 00254 { 00255 <a class="code" href="structDBusDataSlot.html">DBusDataSlot</a> *tmp; 00256 <font class="keywordtype">int</font> i; 00257 00258 tmp = dbus_realloc (list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>, 00259 sizeof (<a class="code" href="structDBusDataSlot.html">DBusDataSlot</a>) * (slot + 1)); 00260 <font class="keywordflow">if</font> (tmp == NULL) 00261 <font class="keywordflow">return</font> FALSE; 00262 00263 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a> = tmp; 00264 i = list-><a class="code" href="structDBusDataSlotList.html#m1">n_slots</a>; 00265 list-><a class="code" href="structDBusDataSlotList.html#m1">n_slots</a> = slot + 1; 00266 <font class="keywordflow">while</font> (i < list-><a class="code" href="structDBusDataSlotList.html#m1">n_slots</a>) 00267 { 00268 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[i].<a class="code" href="structDBusDataSlot.html#m0">data</a> = NULL; 00269 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[i].<a class="code" href="structDBusDataSlot.html#m1">free_data_func</a> = NULL; 00270 ++i; 00271 } 00272 } 00273 00274 _dbus_assert (slot < list->n_slots); 00275 00276 *old_data = list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#m0">data</a>; 00277 *old_free_func = list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#m1">free_data_func</a>; 00278 00279 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#m0">data</a> = data; 00280 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#m1">free_data_func</a> = free_data_func; 00281 00282 <font class="keywordflow">return</font> TRUE; 00283 } 00284 00294 <font class="keywordtype">void</font>* <a name="l00295"></a><a class="code" href="group__DBusDataSlot.html#a5">00295</a> _dbus_data_slot_list_get (<a class="code" href="structDBusDataSlotAllocator.html">DBusDataSlotAllocator</a> *allocator, 00296 <a class="code" href="structDBusDataSlotList.html">DBusDataSlotList</a> *list, 00297 <font class="keywordtype">int</font> slot) 00298 { 00299 <font class="preprocessor">#ifndef DBUS_DISABLE_ASSERT</font> 00300 <font class="preprocessor"></font> <font class="comment">/* We need to take the allocator lock here, because the allocator could</font> 00301 <font class="comment"> * be e.g. realloc()ing allocated_slots. We avoid doing this if asserts</font> 00302 <font class="comment"> * are disabled, since then the asserts are empty.</font> 00303 <font class="comment"> */</font> 00304 <font class="keywordflow">if</font> (!dbus_mutex_lock (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>)) 00305 <font class="keywordflow">return</font> FALSE; 00306 _dbus_assert (slot >= 0); 00307 _dbus_assert (slot < allocator->n_allocated_slots); 00308 _dbus_assert (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m0">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#m0">slot_id</a> == slot); 00309 dbus_mutex_unlock (allocator-><a class="code" href="structDBusDataSlotAllocator.html#m3">lock</a>); 00310 <font class="preprocessor">#endif</font> 00311 <font class="preprocessor"></font> 00312 <font class="keywordflow">if</font> (slot >= list-><a class="code" href="structDBusDataSlotList.html#m1">n_slots</a>) 00313 <font class="keywordflow">return</font> NULL; 00314 <font class="keywordflow">else</font> 00315 <font class="keywordflow">return</font> list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#m0">data</a>; 00316 } 00317 00325 <font class="keywordtype">void</font> <a name="l00326"></a><a class="code" href="group__DBusDataSlot.html#a6">00326</a> _dbus_data_slot_list_free (<a class="code" href="structDBusDataSlotList.html">DBusDataSlotList</a> *list) 00327 { 00328 <font class="keywordtype">int</font> i; 00329 00330 i = 0; 00331 <font class="keywordflow">while</font> (i < list-><a class="code" href="structDBusDataSlotList.html#m1">n_slots</a>) 00332 { 00333 <font class="keywordflow">if</font> (list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[i].<a class="code" href="structDBusDataSlot.html#m1">free_data_func</a>) 00334 (* list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[i].<a class="code" href="structDBusDataSlot.html#m1">free_data_func</a>) (list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[i].<a class="code" href="structDBusDataSlot.html#m0">data</a>); 00335 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[i].<a class="code" href="structDBusDataSlot.html#m0">data</a> = NULL; 00336 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>[i].<a class="code" href="structDBusDataSlot.html#m1">free_data_func</a> = NULL; 00337 ++i; 00338 } 00339 00340 dbus_free (list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a>); 00341 list-><a class="code" href="structDBusDataSlotList.html#m0">slots</a> = NULL; 00342 list-><a class="code" href="structDBusDataSlotList.html#m1">n_slots</a> = 0; 00343 } 00344 00347 <font class="preprocessor">#ifdef DBUS_BUILD_TESTS</font> 00348 <font class="preprocessor"></font><font class="preprocessor">#include "dbus-test.h"</font> 00349 <font class="preprocessor">#include <stdio.h></font> 00350 00351 <font class="keyword">static</font> <font class="keywordtype">int</font> free_counter; 00352 00353 <font class="keyword">static</font> <font class="keywordtype">void</font> 00354 test_free_slot_data_func (<font class="keywordtype">void</font> *data) 00355 { 00356 <font class="keywordtype">int</font> i = _DBUS_POINTER_TO_INT (data); 00357 00358 _dbus_assert (free_counter == i); 00359 ++free_counter; 00360 } 00361 00365 dbus_bool_t 00366 _dbus_data_slot_test (<font class="keywordtype">void</font>) 00367 { 00368 <a class="code" href="structDBusDataSlotAllocator.html">DBusDataSlotAllocator</a> allocator; 00369 <a class="code" href="structDBusDataSlotList.html">DBusDataSlotList</a> list; 00370 <font class="keywordtype">int</font> i; 00371 DBusFreeFunction old_free_func; 00372 <font class="keywordtype">void</font> *old_data; 00373 DBusMutex *mutex; 00374 00375 <font class="keywordflow">if</font> (!_dbus_data_slot_allocator_init (&allocator)) 00376 _dbus_assert_not_reached (<font class="stringliteral">"no memory for allocator"</font>); 00377 00378 _dbus_data_slot_list_init (&list); 00379 00380 mutex = dbus_mutex_new (); 00381 <font class="keywordflow">if</font> (mutex == NULL) 00382 _dbus_assert_not_reached (<font class="stringliteral">"failed to alloc mutex"</font>); 00383 00384 <font class="preprocessor">#define N_SLOTS 100</font> 00385 <font class="preprocessor"></font> 00386 i = 0; 00387 <font class="keywordflow">while</font> (i < N_SLOTS) 00388 { 00389 <font class="comment">/* we don't really want apps to rely on this ordered</font> 00390 <font class="comment"> * allocation, but it simplifies things to rely on it</font> 00391 <font class="comment"> * here.</font> 00392 <font class="comment"> */</font> 00393 dbus_int32_t tmp = -1; 00394 00395 _dbus_data_slot_allocator_alloc (&allocator, mutex, &tmp); 00396 00397 <font class="keywordflow">if</font> (tmp != i) 00398 _dbus_assert_not_reached (<font class="stringliteral">"did not allocate slots in numeric order\n"</font>); 00399 00400 ++i; 00401 } 00402 00403 i = 0; 00404 <font class="keywordflow">while</font> (i < N_SLOTS) 00405 { 00406 <font class="keywordflow">if</font> (!_dbus_data_slot_list_set (&allocator, &list, 00407 i, 00408 _DBUS_INT_TO_POINTER (i), 00409 test_free_slot_data_func, 00410 &old_free_func, &old_data)) 00411 _dbus_assert_not_reached (<font class="stringliteral">"no memory to set data"</font>); 00412 00413 _dbus_assert (old_free_func == NULL); 00414 _dbus_assert (old_data == NULL); 00415 00416 _dbus_assert (_dbus_data_slot_list_get (&allocator, &list, i) == 00417 _DBUS_INT_TO_POINTER (i)); 00418 00419 ++i; 00420 } 00421 00422 free_counter = 0; 00423 i = 0; 00424 <font class="keywordflow">while</font> (i < N_SLOTS) 00425 { 00426 <font class="keywordflow">if</font> (!_dbus_data_slot_list_set (&allocator, &list, 00427 i, 00428 _DBUS_INT_TO_POINTER (i), 00429 test_free_slot_data_func, 00430 &old_free_func, &old_data)) 00431 _dbus_assert_not_reached (<font class="stringliteral">"no memory to set data"</font>); 00432 00433 _dbus_assert (old_free_func == test_free_slot_data_func); 00434 _dbus_assert (_DBUS_POINTER_TO_INT (old_data) == i); 00435 00436 (* old_free_func) (old_data); 00437 _dbus_assert (i == (free_counter - 1)); 00438 00439 _dbus_assert (_dbus_data_slot_list_get (&allocator, &list, i) == 00440 _DBUS_INT_TO_POINTER (i)); 00441 00442 ++i; 00443 } 00444 00445 free_counter = 0; 00446 _dbus_data_slot_list_free (&list); 00447 00448 _dbus_assert (N_SLOTS == free_counter); 00449 00450 i = 0; 00451 <font class="keywordflow">while</font> (i < N_SLOTS) 00452 { 00453 dbus_int32_t tmp = i; 00454 00455 _dbus_data_slot_allocator_free (&allocator, &tmp); 00456 _dbus_assert (tmp == -1); 00457 ++i; 00458 } 00459 00460 dbus_mutex_free (mutex); 00461 00462 <font class="keywordflow">return</font> TRUE; 00463 } 00464 00465 <font class="preprocessor">#endif </font><font class="comment">/* DBUS_BUILD_TESTS */</font> </pre></div><hr><address align="right"><small>Generated on Wed Jun 9 05:01:25 2004 for D-BUS by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>