Added boilerplate for CObjStream

This commit is contained in:
2021-03-20 01:44:03 -05:00
committed by cpunch
parent d13cc398c8
commit 7b5825668d
4 changed files with 26 additions and 2 deletions

View File

@@ -7,6 +7,7 @@
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
// we don't actually hash the whole string :eyes:
uint32_t hashString(const char *str, size_t sz) {
@@ -54,6 +55,12 @@ void cosmoO_free(CState *state, CObj *obj) {
cosmoM_free(state, CObjObject, objTbl);
break;
}
case COBJ_STREAM: {
CObjStream *objStrm = (CObjStream*)obj;
close(objStrm->fd);
cosmoM_free(state, CObjStream, objStrm);
break;
}
case COBJ_TABLE: {
CObjTable *tbl = (CObjTable*)obj;
cosmoT_clearTable(state, &tbl->tbl);
@@ -181,6 +188,13 @@ CObjObject *cosmoO_newObject(CState *state) {
return obj;
}
CObjStream *cosmoO_newStream(CState *state, int fd) {
CObjStream *strm = (CObjStream*)cosmoO_allocateBase(state, sizeof(CObjStream), COBJ_STREAM);
strm->fd = fd;
return strm;
}
CObjTable *cosmoO_newTable(CState *state) {
CObjTable *obj = (CObjTable*)cosmoO_allocateBase(state, sizeof(CObjTable), COBJ_TABLE);