summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-09-07 23:16:29 +0000
committerThomas Martitz <kugel@rockbox.org>2011-09-07 23:16:29 +0000
commit5296af838c39b8b7c4b00a3c896345f9e0719dcf (patch)
treee3e31a974f23bd4cd810c00b892c1eabaec4c676
parent6a989b8d4dec4750ad474598bd52897381d2f3cb (diff)
downloadrockbox-5296af838c39b8b7c4b00a3c896345f9e0719dcf.tar.gz
rockbox-5296af838c39b8b7c4b00a3c896345f9e0719dcf.zip
Buflib: Clarification about invalid handles
* Enhance allocation function comments to better state the return value and what an invalid value is * Change clients to check for "< 0" instead of "<= 0" or "== 0" * Return -1 or -2 depending on the exact failure in buflib_alloc_ex. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30469 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/filetypes.c2
-rw-r--r--apps/plugins/pictureflow/pictureflow.c6
-rw-r--r--apps/scrobbler.c2
-rw-r--r--firmware/buflib.c4
-rw-r--r--firmware/include/buflib.h11
5 files changed, 15 insertions, 10 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index 942ff329fe..8f2e91222a 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -344,7 +344,7 @@ void filetype_init(void)
344 344
345 strdup_bufsize = filesize(fd); 345 strdup_bufsize = filesize(fd);
346 strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops); 346 strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops);
347 if (strdup_handle <= 0) 347 if (strdup_handle < 0)
348 return; 348 return;
349 read_builtin_types(); 349 read_builtin_types();
350 read_config(fd); 350 read_config(fd);
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index c13aca1a95..a572586886 100644
--- a/apps/plugins/pictureflow/pictureflow.c
+++ b/apps/plugins/pictureflow/pictureflow.c
@@ -1520,9 +1520,11 @@ int read_pfraw(char* filename, int prio)
1520 sizeof( pix_t ) * bmph.width * bmph.height; 1520 sizeof( pix_t ) * bmph.width * bmph.height;
1521 1521
1522 int hid; 1522 int hid;
1523 while (!(hid = rb->buflib_alloc(&buf_ctx, size)) && free_slide_prio(prio)); 1523 do {
1524 hid = rb->buflib_alloc(&buf_ctx, size);
1525 } while (hid < 0 && free_slide_prio(prio));
1524 1526
1525 if (!hid) { 1527 if (hid < 0) {
1526 rb->close( fh ); 1528 rb->close( fh );
1527 return 0; 1529 return 0;
1528 } 1530 }
diff --git a/apps/scrobbler.c b/apps/scrobbler.c
index 78414f3d88..06c957cd6c 100644
--- a/apps/scrobbler.c
+++ b/apps/scrobbler.c
@@ -255,7 +255,7 @@ int scrobbler_init(void)
255 return -1; 255 return -1;
256 256
257 scrobbler_cache = core_alloc("scrobbler", SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); 257 scrobbler_cache = core_alloc("scrobbler", SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN);
258 if (scrobbler_cache <= 0) 258 if (scrobbler_cache < 0)
259 { 259 {
260 logf("SCROOBLER: OOM"); 260 logf("SCROOBLER: OOM");
261 return -1; 261 return -1;
diff --git a/firmware/buflib.c b/firmware/buflib.c
index f7ef35ea8b..7c5f3d208e 100644
--- a/firmware/buflib.c
+++ b/firmware/buflib.c
@@ -425,7 +425,7 @@ handle_alloc:
425 goto handle_alloc; 425 goto handle_alloc;
426 } 426 }
427 } 427 }
428 return 0; 428 return -1;
429 } 429 }
430 } 430 }
431 431
@@ -471,7 +471,7 @@ buffer_alloc:
471 } else { 471 } else {
472 handle->val=1; 472 handle->val=1;
473 handle_free(ctx, handle); 473 handle_free(ctx, handle);
474 return 0; 474 return -2;
475 } 475 }
476 } 476 }
477 477
diff --git a/firmware/include/buflib.h b/firmware/include/buflib.h
index db7b5ec50a..3d8f43ef5f 100644
--- a/firmware/include/buflib.h
+++ b/firmware/include/buflib.h
@@ -153,7 +153,8 @@ size_t buflib_available(struct buflib_context *ctx);
153 * 153 *
154 * size: How many bytes to allocate 154 * size: How many bytes to allocate
155 * 155 *
156 * Returns: An integer handle identifying this allocation 156 * Returns: A positive integer handle identifying this allocation, or
157 * a negative value on error (0 is also not a valid handle)
157 */ 158 */
158int buflib_alloc(struct buflib_context *context, size_t size); 159int buflib_alloc(struct buflib_context *context, size_t size);
159 160
@@ -166,7 +167,8 @@ int buflib_alloc(struct buflib_context *context, size_t size);
166 * size: How many bytes to allocate 167 * size: How many bytes to allocate
167 * ops: a struct with pointers to callback functions (see above) 168 * ops: a struct with pointers to callback functions (see above)
168 * 169 *
169 * Returns: An integer handle identifying this allocation 170 * Returns: A positive integer handle identifying this allocation, or
171 * a negative value on error (0 is also not a valid handle)
170 */ 172 */
171int buflib_alloc_ex(struct buflib_context *ctx, size_t size, const char *name, 173int buflib_alloc_ex(struct buflib_context *ctx, size_t size, const char *name,
172 struct buflib_callbacks *ops); 174 struct buflib_callbacks *ops);
@@ -188,7 +190,8 @@ int buflib_alloc_ex(struct buflib_context *ctx, size_t size, const char *name,
188 * size: The actual size will be returned into size 190 * size: The actual size will be returned into size
189 * ops: a struct with pointers to callback functions 191 * ops: a struct with pointers to callback functions
190 * 192 *
191 * Returns: An integer handle identifying this allocation 193 * Returns: A positive integer handle identifying this allocation, or
194 * a negative value on error (0 is also not a valid handle)
192 */ 195 */
193int buflib_alloc_maximum(struct buflib_context* ctx, const char* name, 196int buflib_alloc_maximum(struct buflib_context* ctx, const char* name,
194 size_t *size, struct buflib_callbacks *ops); 197 size_t *size, struct buflib_callbacks *ops);
@@ -233,7 +236,7 @@ bool buflib_shrink(struct buflib_context *ctx, int handle, void* newstart, size_
233/** 236/**
234 * Frees memory associated with the given handle 237 * Frees memory associated with the given handle
235 * 238 *
236 * Returns: 0 (to invalidate handles in one line) 239 * Returns: 0 (to invalidate handles in one line, 0 is not a valid handle)
237 */ 240 */
238int buflib_free(struct buflib_context *context, int handle); 241int buflib_free(struct buflib_context *context, int handle);
239 242