of_object_t * of_object_dup_(of_object_t *src) { of_object_t *dst; of_object_init_f init_fn; if ((dst = (of_object_t *)MALLOC(sizeof(of_generic_t))) == NULL) { return NULL; } MEMSET(dst, 0, sizeof(*dst)); /* Allocate a minimal wire buffer assuming we will not write to it. */ if ((dst->wire_object.wbuf = of_wire_buffer_new(src->length)) == NULL) { FREE(dst); return NULL; } dst->wire_object.owned = 1; init_fn = of_object_init_map[src->object_id]; init_fn(dst, src->version, src->length, 0); MEMCPY(OF_OBJECT_BUFFER_INDEX(dst, 0), OF_OBJECT_BUFFER_INDEX(src, 0), src->length); return dst; }
of_object_t * of_object_new(int bytes) { of_object_t *obj; if ((obj = (of_object_t *)MALLOC(sizeof(*obj))) == NULL) { return NULL; } MEMSET(obj, 0, sizeof(*obj)); if (bytes > 0) { if ((obj->wbuf = of_wire_buffer_new(bytes)) == NULL) { FREE(obj); return NULL; } } return obj; }
of_object_t * of_object_new(int bytes) { of_object_t *obj; if ((obj = (of_object_t *)MALLOC(sizeof(of_generic_t))) == NULL) { return NULL; } MEMSET(obj, 0, sizeof(of_generic_t)); if (bytes > 0) { if ((obj->wire_object.wbuf = of_wire_buffer_new(bytes)) == NULL) { FREE(obj); return NULL; } obj->wire_object.owned = 1; } return obj; }