use pic_blob_value
This commit is contained in:
parent
126989e4ec
commit
0a715e4916
|
@ -263,8 +263,7 @@ pic_socket_socket_recv(pic_state *pic)
|
|||
pic_errorf(pic, "%s", strerror(errno));
|
||||
}
|
||||
|
||||
bv = pic_make_blob(pic, len);
|
||||
memcpy(bv->data, buf, len);
|
||||
bv = pic_blob_value(pic, buf, len);
|
||||
free(buf);
|
||||
|
||||
return pic_obj_value(bv);
|
||||
|
|
|
@ -5,13 +5,16 @@
|
|||
#include "picrin.h"
|
||||
|
||||
struct pic_blob *
|
||||
pic_make_blob(pic_state *pic, int len)
|
||||
pic_blob_value(pic_state *pic, const unsigned char *buf, int len)
|
||||
{
|
||||
struct pic_blob *bv;
|
||||
|
||||
bv = (struct pic_blob *)pic_obj_alloc(pic, sizeof(struct pic_blob), PIC_TYPE_BLOB);
|
||||
bv->data = pic_malloc(pic, len);
|
||||
bv->len = len;
|
||||
if (buf) {
|
||||
memcpy(bv->data, buf, len);
|
||||
}
|
||||
return bv;
|
||||
}
|
||||
|
||||
|
@ -35,7 +38,7 @@ pic_blob_bytevector(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "*", &argc, &argv);
|
||||
|
||||
blob = pic_make_blob(pic, argc);
|
||||
blob = pic_blob_value(pic, 0, argc);
|
||||
|
||||
data = blob->data;
|
||||
|
||||
|
@ -63,7 +66,7 @@ pic_blob_make_bytevector(pic_state *pic)
|
|||
if (b < 0 || b > 255)
|
||||
pic_errorf(pic, "byte out of range");
|
||||
|
||||
blob = pic_make_blob(pic, k);
|
||||
blob = pic_blob_value(pic, 0, k);
|
||||
for (i = 0; i < k; ++i) {
|
||||
blob->data[i] = (unsigned char)b;
|
||||
}
|
||||
|
@ -157,7 +160,7 @@ pic_blob_bytevector_copy(pic_state *pic)
|
|||
pic_errorf(pic, "make-bytevector: end index must not be less than start index");
|
||||
}
|
||||
|
||||
to = pic_make_blob(pic, end - start);
|
||||
to = pic_blob_value(pic, 0, end - start);
|
||||
while (start < end) {
|
||||
to->data[i++] = from->data[start++];
|
||||
}
|
||||
|
@ -180,7 +183,7 @@ pic_blob_bytevector_append(pic_state *pic)
|
|||
len += pic_blob_ptr(argv[i])->len;
|
||||
}
|
||||
|
||||
blob = pic_make_blob(pic, len);
|
||||
blob = pic_blob_value(pic, 0, len);
|
||||
|
||||
len = 0;
|
||||
for (i = 0; i < argc; ++i) {
|
||||
|
@ -202,7 +205,7 @@ pic_blob_list_to_bytevector(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "o", &list);
|
||||
|
||||
blob = pic_make_blob(pic, pic_length(pic, list));
|
||||
blob = pic_blob_value(pic, 0, pic_length(pic, list));
|
||||
|
||||
data = blob->data;
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ struct pic_blob {
|
|||
|
||||
#define pic_blob_ptr(v) ((struct pic_blob *)pic_obj_ptr(v))
|
||||
|
||||
struct pic_blob *pic_make_blob(pic_state *, int);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -546,8 +546,7 @@ pic_port_get_output_bytevector(pic_state *pic)
|
|||
|
||||
s = port->file->vtable.cookie;
|
||||
|
||||
blob = pic_make_blob(pic, s->end);
|
||||
memcpy(blob->data, s->buf, s->end);
|
||||
blob = pic_blob_value(pic, (unsigned char *)s->buf, s->end);
|
||||
|
||||
return pic_obj_value(blob);
|
||||
}
|
||||
|
@ -717,7 +716,7 @@ pic_port_read_blob(pic_state *pic)
|
|||
|
||||
assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, "read-bytevector");
|
||||
|
||||
blob = pic_make_blob(pic, k);
|
||||
blob = pic_blob_value(pic, 0, k);
|
||||
|
||||
i = xfread(pic, blob->data, sizeof(char), k, port->file);
|
||||
if (i == 0) {
|
||||
|
|
|
@ -497,7 +497,7 @@ static pic_value
|
|||
read_blob(pic_state *pic, struct pic_port *port, int c)
|
||||
{
|
||||
int nbits, n;
|
||||
int len, i;
|
||||
int len;
|
||||
unsigned char *dat;
|
||||
struct pic_blob *blob;
|
||||
|
||||
|
@ -529,10 +529,7 @@ read_blob(pic_state *pic, struct pic_port *port, int c)
|
|||
c = next(pic, port);
|
||||
}
|
||||
|
||||
blob = pic_make_blob(pic, len);
|
||||
for (i = 0; i < len; ++i) {
|
||||
blob->data[i] = dat[i];
|
||||
}
|
||||
blob = pic_blob_value(pic, dat, len);
|
||||
|
||||
pic_free(pic, dat);
|
||||
return pic_obj_value(blob);
|
||||
|
|
Loading…
Reference in New Issue