You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/30 10:20:59 UTC
svn commit: r809266 - in /commons/sandbox/runtime/trunk/src/main/native:
include/acr_tables.h include/acr_types.h os/unix/temps.c shared/sbuf.c
shared/tables.c
Author: mturk
Date: Sun Aug 30 08:20:58 2009
New Revision: 809266
URL: http://svn.apache.org/viewvc?rev=809266&view=rev
Log:
Few fixes
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr_tables.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c
commons/sandbox/runtime/trunk/src/main/native/shared/tables.c
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_tables.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_tables.h?rev=809266&r1=809265&r2=809266&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_tables.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_tables.h Sun Aug 30 08:20:58 2009
@@ -18,7 +18,7 @@
#define _ACR_TABLES_H
#include "acr.h"
-#include <jni.h>
+#include "acr_ring.h"
#ifdef __cplusplus
extern "C" {
@@ -216,7 +216,8 @@
/** Callback function used in ACR_TableForEach.
* If the function returns non zero the for each loop will break.
*/
-typedef int (acr_table_callback_fn_t)(void *opaque, char *key, void *data,
+typedef int (acr_table_callback_fn_t)(int mode, void *opaque,
+ char *key, void *data,
acr_size_t dlen);
/**
@@ -224,7 +225,7 @@
* @param t Table to use.
* @param callback Callback function
*/
-ACR_DECLARE(void) ACR_TableForEach(acr_table_t *t, void *opaque,
+ACR_DECLARE(void) ACR_TableForEach(acr_table_t *t, int mode, void *opaque,
acr_table_callback_fn_t *callback);
#ifdef __cplusplus
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h?rev=809266&r1=809265&r2=809266&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h Sun Aug 30 08:20:58 2009
@@ -138,7 +138,31 @@
/** @see toupper */
#define acr_toupper(c) (toupper(((unsigned char)(c))))
+/** Generic data type
+ * Key/data structure -- a Data-Base Thang
+ */
+typedef struct acr_dbt_t {
+ void *data;
+ size_t size;
+} acr_dbt_t;
+/**
+ * Generic storage data type for holding the data copy.
+ * The structure size is 'sizeof(acr_dbs_t) + size'
+ */
+typedef struct acr_dbs_t {
+ size_t size; /* Size of the structure */
+ size_t dlen; /* Data length */
+ char data[1];
+} acr_dbs_t;
+
+/**
+ * Generic array pointer type.
+ */
+typedef struct acr_dba_t {
+ void **data; /* Pointer array */
+ size_t size; /* Number of the pointers */
+} acr_dba_t;
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c?rev=809266&r1=809265&r2=809266&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c Sun Aug 30 08:20:58 2009
@@ -127,7 +127,7 @@
* to create temp file template
*/
ACR_THROW_IO_IF_ERR(ACR_E2BIG);
- return -1;
+ return NULL;
}
fd = mkstemp(name);
if (fd < 0) {
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c?rev=809266&r1=809265&r2=809266&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c Sun Aug 30 08:20:58 2009
@@ -45,13 +45,10 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_error.h"
#include "acr_sbuf.h"
-/**
- * Structure definitions
- */
-#define KASSERT(e, m)
-
/*
* Predicates
*/
@@ -73,10 +70,6 @@
#define SBUF_MAXEXTENDSIZE 65536 /* Original is PAGESIZE */
#define SBUF_MAXEXTENDINCR 65536 /* Original is PAGESIZE */
-
-#define assert_sbuf_integrity(s) do { } while (0)
-#define assert_sbuf_state(s, i) do { } while (0)
-
static size_t
acr_sbuf_extendsize(size_t size)
{
@@ -106,12 +99,12 @@
return -1;
newsize = acr_sbuf_extendsize(s->s_size + addlen);
- newbuf = malloc(newsize);
+ newbuf = x_malloc(newsize);
if (newbuf == NULL)
return -1;
memcpy(newbuf, s->s_buf, s->s_size);
if (SBUF_ISDYNAMIC(s))
- free(s->s_buf);
+ x_free(s->s_buf);
else
SBUF_SETFLAG(s, ACR_SBUF_DYNAMIC);
s->s_buf = newbuf;
@@ -129,20 +122,23 @@
acr_sbuf_new(acr_sbuf_t *s, char *buf, size_t length, int flags)
{
- KASSERT(length >= 0,
- ("attempt to create an sbuf of negative length (%d)", length));
- KASSERT((flags & ~ACR_SBUF_USRFLAGMSK) == 0,
- ("%s called with invalid flags", __func__));
-
+ if (length < 0) {
+ ACR_SET_OS_ERROR(ACR_EINVAL);
+ return NULL;
+ }
+ if ((flags & ~ACR_SBUF_USRFLAGMSK)) {
+ ACR_SET_OS_ERROR(ACR_EINVAL);
+ return NULL;
+ }
flags &= ACR_SBUF_USRFLAGMSK;
if (s == NULL) {
- s = calloc(1, sizeof(*s));
+ s = x_calloc(sizeof(acr_sbuf_t));
if (s == NULL)
return NULL;
s->s_flags = flags;
SBUF_SETFLAG(s, ACR_SBUF_DYNSTRUCT);
} else {
- memset(s, 0, sizeof(*s));
+ memset(s, 0, sizeof(acr_sbuf_t));
s->s_flags = flags;
}
s->s_size = length;
@@ -152,10 +148,10 @@
}
if (flags & ACR_SBUF_AUTOEXTEND)
s->s_size = acr_sbuf_extendsize(s->s_size);
- s->s_buf = malloc(s->s_size);
+ s->s_buf = x_malloc(s->s_size);
if (s->s_buf == NULL) {
if (SBUF_ISDYNSTRUCT(s))
- free(s);
+ x_free(s);
return NULL;
}
SBUF_SETFLAG(s, ACR_SBUF_DYNAMIC);
@@ -169,7 +165,6 @@
acr_sbuf_clear(acr_sbuf_t *s)
{
- assert_sbuf_integrity(s);
/* don't care if it's finished or not */
SBUF_CLRFLAG(s, ACR_SBUF_FINISHED);
@@ -185,14 +180,14 @@
acr_sbuf_setpos(acr_sbuf_t *s, size_t pos)
{
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
- KASSERT(pos >= 0,
- ("attempt to seek to a negative position (%d)", pos));
- KASSERT(pos < s->s_size,
- ("attempt to seek past end of sbuf (%d >= %d)", pos, s->s_size));
-
+ if (pos < 0) {
+ ACR_SET_OS_ERROR(ACR_EINVAL);
+ return -1;
+ }
+ if (pos >= s->s_size) {
+ ACR_SET_OS_ERROR(ACR_EINVAL);
+ return -1;
+ }
if (pos > s->s_len)
return -1;
s->s_len = pos;
@@ -207,9 +202,6 @@
{
const char *str = (const char *)buf;
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
if (SBUF_HASOVERFLOWED(s))
return -1;
for (; len; len--) {
@@ -231,9 +223,6 @@
acr_sbuf_bcpy(acr_sbuf_t *s, const void *buf, size_t len)
{
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
acr_sbuf_clear(s);
return acr_sbuf_bcat(s, buf, len);
}
@@ -245,12 +234,15 @@
acr_sbuf_cat(acr_sbuf_t *s, const char *str)
{
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
if (SBUF_HASOVERFLOWED(s))
return -1;
-
+ if (!str || !*str) {
+ /* Nothing to do.
+ * Empty strings cannot be added.
+ * We use finish() for that
+ */
+ return 0;
+ }
while (*str) {
if (!SBUF_HASROOM(s) && acr_sbuf_extend(s, strlen(str)) < 0)
break;
@@ -270,9 +262,6 @@
acr_sbuf_cpy(acr_sbuf_t *s, const char *str)
{
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
acr_sbuf_clear(s);
return acr_sbuf_cat(s, str);
}
@@ -285,16 +274,13 @@
{
va_list ap_copy;
int len;
-
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
- KASSERT(fmt != NULL,
- ("%s called with a NULL format string", __func__));
-
- if (SBUF_HASOVERFLOWED(s))
+ if (fmt == NULL) {
+ ACR_SET_OS_ERROR(ACR_EINVAL);
return -1;
-
+ }
+ if (SBUF_HASOVERFLOWED(s)) {
+ return -1;
+ }
do {
#if defined(_MSC_VER) || defined(HPUX11)
ap_copy = ap;
@@ -324,9 +310,6 @@
if (!SBUF_HASROOM(s) && !SBUF_CANEXTEND(s))
SBUF_SETFLAG(s, ACR_SBUF_OVERFLOWED);
- KASSERT(s->s_len < s->s_size,
- ("wrote past end of sbuf (%d >= %d)", s->s_len, s->s_size));
-
if (SBUF_HASOVERFLOWED(s))
return -1;
return 0;
@@ -354,17 +337,17 @@
acr_sbuf_putc(acr_sbuf_t *s, int c)
{
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
if (SBUF_HASOVERFLOWED(s))
return -1;
+ if (c == 0) {
+ /* Nothing to add */
+ return 0;
+ }
if (!SBUF_HASROOM(s) && acr_sbuf_extend(s, 1) < 0) {
SBUF_SETFLAG(s, ACR_SBUF_OVERFLOWED);
return -1;
}
- if (c != '\0')
- s->s_buf[s->s_len++] = (char)(c & 0xFF);
+ s->s_buf[s->s_len++] = (char)(c & 0xFF);
return 0;
}
@@ -375,9 +358,6 @@
acr_sbuf_rtrim(acr_sbuf_t *s)
{
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
if (SBUF_HASOVERFLOWED(s))
return -1;
@@ -397,8 +377,6 @@
{
char *p = s->s_buf;
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
if (SBUF_HASOVERFLOWED(s))
return NULL;
@@ -445,10 +423,7 @@
acr_sbuf_finish(acr_sbuf_t *s)
{
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
- s->s_buf[s->s_len] = '\0';
+ s->s_buf[s->s_len] = '\0';
SBUF_CLRFLAG(s, ACR_SBUF_OVERFLOWED);
SBUF_SETFLAG(s, ACR_SBUF_FINISHED);
@@ -461,9 +436,6 @@
acr_sbuf_data(acr_sbuf_t *s)
{
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, ACR_SBUF_FINISHED);
-
return s->s_buf;
}
@@ -474,9 +446,7 @@
acr_sbuf_len(acr_sbuf_t *s)
{
- assert_sbuf_integrity(s);
/* don't care if it's finished or not */
-
if (SBUF_HASOVERFLOWED(s))
return 0;
return s->s_len;
@@ -490,14 +460,12 @@
{
int isdyn;
- assert_sbuf_integrity(s);
/* don't care if it's finished or not */
-
if (SBUF_ISDYNAMIC(s))
- free(s->s_buf);
+ x_free(s->s_buf);
isdyn = SBUF_ISDYNSTRUCT(s);
if (isdyn)
- free(s);
+ x_free(s);
else
memset(s, 0, sizeof(*s));
}
@@ -508,7 +476,5 @@
int
acr_sbuf_done(acr_sbuf_t *s)
{
-
return SBUF_ISFINISHED(s);
}
-
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/tables.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/tables.c?rev=809266&r1=809265&r2=809266&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/tables.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/tables.c Sun Aug 30 08:20:58 2009
@@ -329,7 +329,7 @@
return 1;
}
-ACR_DECLARE(void) ACR_TableForEach(acr_table_t *t, void *opaque,
+ACR_DECLARE(void) ACR_TableForEach(acr_table_t *t, int mode, void *opaque,
acr_table_callback_fn_t *callback)
{
@@ -337,9 +337,8 @@
acr_size_t i;
table_entry_t *e = (table_entry_t *)t->a.elts;
for (i = 0; i < t->a.nelts; i++) {
- if ((*callback)(opaque, e[i].key, e[i].data, e[i].dlen))
+ if ((*callback)(mode, opaque, e[i].key, e[i].data, e[i].dlen))
break;
}
}
}
-