vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| In the following code from hstore_io.c, is HStore a varlena? In which case is the following code buggy because it omits to subtract VARHDRSZ from in->size and therefore is not handling the empty hstore and also starting the loop from the varlena header instead of the first data byte? Or if HStore is not a varlena then PG_GETARG_HS is buggy since it calls PG_DETOAST_DATUM() on the argument. PG_FUNCTION_INFO_V1(hstore_out); Datum hstore_out(PG_FUNCTION_ARGS); Datum hstore_out(PG_FUNCTION_ARGS) { HStore *in = PG_GETARG_HS(0); int buflen, i; char *out, *ptr; char *base = STRPTR(in); HEntry *entries = ARRPTR(in); if (in->size == 0) { out = palloc(1); *out = '\0'; PG_FREE_IF_COPY(in, 0); PG_RETURN_CSTRING(out); } buflen = (4 /* " */ + 2 /* => */ + 2 /* , */ ) * in->size + 2 /* esc */ * (in->len - CALCDATASIZE(in->size, 0)); out = ptr = palloc(buflen); for (i = 0; i < in->size; i++) { *ptr++ = '"'; ptr = cpw(ptr, base + entries[i].pos, entries[i].keylen); *ptr++ = '"'; *ptr++ = '='; *ptr++ = '>'; -- Gregory Stark EnterpriseDB http://www.enterprisedb.com ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org |
| ||||
| "Gregory Stark" <stark@enterprisedb.com> writes: > In the following code from hstore_io.c, is HStore a varlena? Sorry, thinko, it is a varlena but "size" isn't the first struct field, there's a "len" field first. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |