deferencing pointer to incomplete type C Struct CUNIT

211 Views Asked by At

Excuse me i'm getting this error deferencing pointer to incomplete type,i have defined buffer_t in a buffer.c file, and i'm in CUNIT i initialize the buffer before each test

#include "msg.h"
#include <stdio.h>
#include <string.h>
#include "CUnit/Basic.h"
#include <pthread.h>
#include "buffer.h"
/* Pointer to the file used by the tests. */
 buffer_t * buffer = NULL;

/* The suite initialization function.
 * Opens the temporary file used by the tests.
 * Returns zero on success, non-zero otherwise.
 */
int init_suite1(void)
{
    buffer=buffer_init(5);
    if(buffer!=NULL){
            printf("buffer creato");
        }
}

/* The suite cleanup function.
 * Closes the temporary file used by the tests.
 * Returns zero on success, non-zero otherwise.
 */
int clean_suite1(void)
{
    buffer_destroy(buffer);
    if(buffer==NULL){
        printf("buffer distrutto");
    }

}
//(P=1; C=0; N=1) Produzione di un solo messaggio in un buffer vuoto
void test1(void)
{
    msg_t* msg = msg_init_string("ciao");
    put_nb(buffer,  msg);

      CU_ASSERT(1 == buffer->msg_presenti);
      CU_ASSERT( "ciao"== (*(buffer->array_msg[0]))->content);

at these two last lines i got the error:

CU_ASSERT(1 == buffer->msg_presenti);
          CU_ASSERT( "ciao"== (*(buffer->array_msg[0]))->content);

here buffer.c:

/*
 * Buffer.c
 *
 *  Created on: 19/nov/2013
 *      Author: lele */



#include "buffer.h"
#include <stdio.h>
#include "msg.h"
#include <stdlib.h>
#include <pthread.h>

#define BUFFER_ERROR (msg_t *) NULL


typedef struct buffer {
    int size;
    int T;
    int D;
    int msg_presenti;

    pthread_cond_t not_full;
    pthread_cond_t not_empty;
    pthread_mutex_t mutex;
    msg_t ** array_msg;

} buffer_t;
/* allocazione / deallocazione buffer */
// creazione di un buffer vuoto di dim. max nota





    buffer_t * buffer_init(unsigned int maxsize){
        buffer_t * new_buffer = (buffer_t*)malloc( sizeof(buffer_t) );
        new_buffer->T=0;
        new_buffer->D=0;
        new_buffer->msg_presenti=0;
        new_buffer->array_msg =(msg_t **)malloc(sizeof(msg_t*) * maxsize);
        new_buffer->size=maxsize;
        pthread_cond_init(&(new_buffer->not_empty),NULL);
        pthread_cond_init(&(new_buffer->not_full),NULL);
        pthread_mutex_init(&(new_buffer->mutex),NULL);

        return new_buffer;
    }
    // deallocazione di un buffer



    void buffer_destroy(buffer_t* buffer){
        int i;
        for(i=0;i<buffer->size;i++){
            msg_destroy_string(buffer->array_msg[i]);

        }
        free(buffer->array_msg);
        free(buffer);



    }


    msg_t* put_non_bloccante(buffer_t* buffer, msg_t* msg){
        // inserimento non bloccante: restituisce BUFFER_ERROR se pieno,
            // altrimenti effettua l'inserimento e restituisce il messaggio
            // inserito; N.B.: msg!=null
         if( ( pthread_mutex_trylock(&(buffer->mutex))) !=0){

                   return BUFFER_ERROR; }

        while(buffer->msg_presenti==buffer->size){
            pthread_cond_wait(&(buffer->not_full),&(buffer->mutex));

    }
        buffer->array_msg[buffer->D]=msg;
        buffer->D = (buffer->D+1)%buffer->size;
        buffer->msg_presenti= buffer->msg_presenti+1;
        pthread_cond_signal(&(buffer->not_empty));
        pthread_mutex_unlock(&(buffer->mutex));
        return msg;
    }
    // estrazione bloccante: sospende se vuoto, quindi
    // restituisce il valore estratto non appena disponibile
    msg_t* get_bloccante(buffer_t* buffer){
    // estrazione non bloccante: restituisce BUFFER_ERROR se vuoto
    // ed il valore estratto in caso contrario

        pthread_mutex_lock(&(buffer->mutex));
        while(buffer->msg_presenti==0){
            pthread_cond_wait(&(buffer->not_empty),&(buffer->mutex));
        }
        msg_t * msg =buffer->array_msg[buffer->T];
        buffer->T=(buffer->T+1)%buffer->size;
        buffer->msg_presenti--;
        pthread_cond_signal(&(buffer->not_full));
        pthread_mutex_unlock(&(buffer->mutex));
        return msg;

    }
    msg_t* get_non_bloccante(buffer_t* buffer){
        if( (pthread_mutex_trylock(&(buffer->mutex))) !=0){

                   return BUFFER_ERROR;

               }
                while(buffer->msg_presenti==0){
                    pthread_cond_wait(&(buffer->not_empty),&(buffer->mutex));
                }
                msg_t* msg =buffer->array_msg[buffer->T];
                buffer->T=(buffer->T+1)%buffer->size;
                buffer->msg_presenti--;
                pthread_cond_signal(&(buffer->not_full));
                pthread_mutex_unlock(&(buffer->mutex));
                return msg;
    }


    msg_t* put_bloccante(buffer_t *buffer, msg_t *msg){
        // inserimento non bloccante: restituisce BUFFER_ERROR se pieno,
            // altrimenti effettua l'inserimento e restituisce il messaggio
            // inserito; N.B.: msg!=null
       pthread_mutex_lock(&(buffer->mutex));
        while(buffer->msg_presenti==buffer->size){
            pthread_cond_wait(&(buffer->not_full),&(buffer->mutex));

    }
        buffer->array_msg[buffer->D]=msg;
        buffer->D = (buffer->D+1)%buffer->size;
        buffer->msg_presenti= buffer->msg_presenti+1;
        pthread_cond_signal(&(buffer->not_empty));
        pthread_mutex_unlock(&(buffer->mutex));
        return msg;
    }

and BUFFER.H :

#ifndef BUFFER_H_
#define BUFFER_H_
#endif  BUFFER_H_





#include <pthread.h>
#include "msg.h"
#define BUFFER_ERROR (msg_t *) NULL

typedef struct buffer buffer_t;


    buffer_t * buffer_init(unsigned int maxsize);
    void buffer_destroy(buffer_t* buffer);
    msg_t* put_non_bloccante(buffer_t* buffer, msg_t* msg);
    msg_t* get_bloccante(buffer_t* buffer);
    msg_t* get_non_bloccante(buffer_t* buffer);
    msg_t* put_bloccante(buffer_t *buffer, msg_t *msg);
0

There are 0 best solutions below