30 YAP_BLOB_MAGIC_B, PL_BLOB_NOCOPY | PL_BLOB_TEXT,
"unregistered"};
32char *Yap_blob_to_string(
AtomEntry *ref,
const char *s0,
size_t sz) {
37 blob_type_t *type = RepBlobProp(ref->PropsOfAE)->blob_type;
39 FILE *f = fmemopen(s, sz,
"w");
44 Atom at = AbsAtom(ref);
45 int rc = type->write(f, at, 0);
47 Yap_Error(EVALUATION_ERROR_UNDEFINED, MkAtomTerm(at),
48 "failure in user-defined blob to string code");
55 size_t sz0 = strlcpy(s, (
char *)RepAtom(AtomSWIStream)->StrOfAE, sz);
58 char *f = (
char *)memcpy(s, (
char *)RepAtom(AtomSWIStream)->StrOfAE, sz);
64#if defined(__linux__) || defined(__APPLE__)
65 snprintf(s + strlen(s), sz0,
"(%p)", ref);
67 snprintf(s + strlen(s), sz0,
"(0x%p)", ref);
76int Yap_write_blob(
AtomEntry *ref, FILE *stream) {
77 blob_type_t *type = RepBlobProp(ref->PropsOfAE)->blob_type;
81 Atom at = AbsAtom(ref);
82 return type->write(stream, at, 0);
84#if defined(__linux__) || defined(__APPLE__)
85 return fprintf(stream,
"\'%s\'(%p)", RepAtom(AtomSWIStream)->StrOfAE, ref);
87 return fprintf(stream,
"\'%s\'(0x%p)", RepAtom(AtomSWIStream)->StrOfAE,
96 Term yt = Yap_GetFromSlot(t);
107 b = RepBlobProp(a->PropsOfAE);
108 *type = b->blob_type;
124AtomEntry *Yap_lookupBlob(
void *blob,
size_t len,
void *type0,
int *
new) {
132 if (type->flags & PL_BLOB_UNIQUE) {
136 if (ae->PropsOfAE && RepBlobProp(ae->PropsOfAE)->blob_type == type &&
137 ae->rep.blob->length == len &&
138 !memcmp(ae->rep.blob->data, blob, len)) {
142 ae = RepAtom(ae->NextOfAE);
153 b->KindOfPE = BlobProperty;
162 INIT_RWLOCK(ae->ARWLock);
163 ae->PropsOfAE = AbsBlobProp(b);
164 ae->NextOfAE = AbsAtom(Blobs);
165 ae->rep.blob->length = len;
166 memcpy(ae->rep.blob->data, blob, len);
168 if (NOfBlobs > NOfBlobsMax) {
169 Yap_signal(YAP_CDOVF_SIGNAL);
175bool YAP_unify_blob(Term *t,
void *blob,
size_t len,
blob_type_t *type) {
180 ae = Yap_lookupBlob(blob, len, type, NULL);
185 type->acquire(AbsAtom(ae));
187 *t = MkAtomTerm(AbsAtom(ae));
191bool YAP_get_blob(Term t,
void **blob,
size_t *len,
blob_type_t **type) {
197 tt = Yap_GetFromSlot(t);
207 *type = RepBlobProp(ae->PropsOfAE)->blob_type;
209 *len = ae->rep.blob[0].length;
211 *blob = ae->rep.blob[0].data;
215void *YAP_blob_data(YAP_Atom at,
size_t *len,
blob_type_t **type) {
220 *len = strlen_utf8(x->UStrOfAE);
222 *type = &unregistered_blob_atom;
226 *len = x->rep.blob[0].length;
228 *type = RepBlobProp(x->PropsOfAE)->blob_type;
229 return x->rep.blob[0].data;
233 type->next = (
void *)BlobTypes;
234 BlobTypes = (
void *)type;
238 AtomEntry *a = RepAtom(Yap_LookupAtom(name));
240 return &unregistered_blob_atom;
242 return RepBlobProp(a->PropsOfAE)->blob_type;
246 fprintf(stderr,
"YAP_unregister_blob_type not implemented yet\n");
250void Yap_install_blobs(
void) {}