blob: 2fb98d3c9d728bddf2f7cf5546c7730fbde8c00f [file] [log] [blame]
/* A toy re-implementation of CPython's object model. */
#include <stdlib.h>
#include <string.h>
#include "analyzer-decls.h"
typedef struct base_obj base_obj;
typedef struct string_obj string_obj;
struct base_obj
{
int ob_refcnt;
};
struct string_obj
{
base_obj str_base;
size_t str_len;
char str_buf[];
};
base_obj *alloc_obj (const char *str)
{
size_t len = strlen (str);
base_obj *obj = (base_obj *)malloc (sizeof (string_obj) + len + 1);
if (!obj)
return NULL;
obj->ob_refcnt = 1;
string_obj *str_obj = (string_obj *)obj;
__analyzer_eval (str_obj->str_base.ob_refcnt == 1); /* { dg-warning "TRUE" } */
return obj;
}