1  /* A toy re-implementation of CPython's object model.  */
       2  
       3  #include <stdlib.h>
       4  #include <string.h>
       5  
       6  #include "analyzer-decls.h"
       7  
       8  typedef struct base_obj base_obj;
       9  typedef struct string_obj string_obj;
      10  
      11  struct base_obj
      12  {
      13    int ob_refcnt;
      14  };
      15  
      16  struct string_obj
      17  {
      18    base_obj str_base;
      19    size_t str_len;
      20    char str_buf[];
      21  };
      22  
      23  base_obj *alloc_obj (const char *str)
      24  {
      25    size_t len = strlen (str);
      26    base_obj *obj = (base_obj *)malloc (sizeof (string_obj) + len + 1);
      27    if (!obj)
      28      return NULL;
      29    obj->ob_refcnt = 1;
      30    string_obj *str_obj = (string_obj *)obj;
      31    __analyzer_eval (str_obj->str_base.ob_refcnt == 1); /* { dg-warning "TRUE" } */
      32    return obj;
      33  }