Changeset: 55f979961baf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=55f979961baf
Modified Files:
clients/Tests/exports.stable.out
common/stream/stream.c
common/stream/stream.h
monetdb5/modules/mal/mal_mapi.c
Branch: default
Log Message:
Simplify conversion from block_stream to block_stream2.
diffs (119 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -2710,7 +2710,6 @@ void bs2_resetbuf(stream *ss);
int bs2_resizebuf(stream *ss, size_t bufsiz);
void bs2_setpos(stream *ss, size_t pos);
void *bs2_stealbuf(stream *ss);
-stream *bs_stealstream(stream *s);
stream *bs_stream(stream *s);
bstream *bstream_create(stream *rs, size_t chunk_size);
void bstream_destroy(bstream *s);
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -4122,16 +4122,6 @@ bs_stream(stream *s)
}
stream *
-bs_stealstream(stream *s)
-{
- stream *res;
- assert(isa_block_stream(s));
- res = ((bs *) s->stream_data.p)->s;
- ((bs *) s->stream_data.p)->s = NULL;
- return res;
-}
-
-stream *
block_stream(stream *s)
{
stream *ns;
@@ -4807,10 +4797,18 @@ stream *
block_stream2(stream *s, size_t bufsiz, compression_method comp,
column_compression colcomp)
{
stream *ns;
+ stream *os = NULL;
bs2 *b;
if (s == NULL)
return NULL;
+ if (s->read == bs_read || s->write == bs_write) {
+ /* if passed in a block_stream instance, extract the
+ * underlying stream */
+ os = s;
+ s = ((bs *) s->stream_data.p)->s;
+ }
+
#ifdef STREAM_DEBUG
fprintf(stderr, "block_stream2 %s\n", s->name ? s->name : "<unnamed>");
#endif
@@ -4823,7 +4821,7 @@ block_stream2(stream *s, size_t bufsiz,
b->colcomp = colcomp;
/* blocksizes have a fixed little endian byteorder */
#ifdef WORDS_BIGENDIAN
- s->byteorder = 3412; /* simply != 1234 */
+ ns->byteorder = 3412; /* simply != 1234 */
#endif
ns->type = s->type;
ns->access = s->access;
@@ -4837,6 +4835,13 @@ block_stream2(stream *s, size_t bufsiz,
ns->isalive = bs2_isalive;
ns->stream_data.p = (void *) b;
+ if (os != NULL) {
+ /* we extracted the underlying stream, destroy the old
+ * shell */
+ ((bs *) os->stream_data.p)->s = NULL;
+ bs_destroy(os);
+ }
+
return ns;
}
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -216,7 +216,6 @@ stream_export stream *block_stream(strea
stream_export int isa_block_stream(stream *s);
stream_export int isa_fixed_block_stream(stream *s);
stream_export stream *bs_stream(stream *s);
-stream_export stream *bs_stealstream(stream *s);
typedef enum {
diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -241,20 +241,17 @@ doChallenge(void *data)
{
// convert the block_stream into a block_stream2
stream *from, *to;
- from = bs_stealstream(fdin);
- to = bs_stealstream(fdout);
- close_stream(fdin);
- close_stream(fdout);
- fdin = block_stream2(from, buflen, comp, colcomp);
- fdout = block_stream2(to, buflen, comp, colcomp);
- }
-
- if (fdin == NULL || fdout == NULL) {
- GDKsyserror("SERVERlisten:"MAL_MALLOC_FAIL);
- close_stream(fdin);
- close_stream(fdout);
- GDKfree(buf);
- return;
+ from = block_stream2(fdin, buflen, comp, colcomp);
+ to = block_stream2(fdout, buflen, comp, colcomp);
+ if (from == NULL || to == NULL) {
+ GDKsyserror("SERVERlisten:"MAL_MALLOC_FAIL);
+ close_stream(fdin);
+ close_stream(fdout);
+ GDKfree(buf);
+ return;
+ }
+ fdin = from;
+ fdout = to;
}
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list