3
« en: Jueves 14 de Abril de 2011, 10:05 »
El error que obtengo es segmentation fault. Algo me dice que el problema esta en la definicion de AST_c11n.
Y este és el codigo: un main, el archivo de cabecera del mi tipo "AST"y el respectivo AST.c
//*****************************MAIN.c*************************************
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "AST.h"
#include "c11n.h"
#include "c11n_io.h"
#include "c11n_stream_FILE.h"
/// Main program
int main(int argc,char *argv[])
{
AST* a1=NULL;
a1 = InsertAST(a1, "prueba");
c11n_node * n = c11n_node_create("a1");
bool rc = c11n_serialize( AST_c11n, n, &a1);
c11n_node_destroy( n );
if( ! rc ) printf("SERIALIZE error !!!!!");
c11n_stream *str= c11n_stream_for_filename("a1.c11n", true);
bool rc2 = c11n_save_serializable( str, AST_c11n, &a1 );
c11n_serializable_save( str, AST_c11n, &a1, 0 );
str->api->destroy(str);
return 0;
}
//*****************************AST.h*************************************
#include "c11n.h"
typedef struct bnode AST;
//AST definitions FIELDs
struct bnode {
char widget_name[20];
int count;
AST *left;
AST *right;
};
AST* InsertAST ( AST* root, char* nodename);
extern const c11n_marshaller * AST_c11n;
//*****************************AST.c*************************************
#include "AST.h"
AST* InsertAST ( AST* root, char* nodename)
{
if ( root == NULL ) {
root = malloc ( sizeof ( AST ) );
strcpy ( root->widget_name, nodename );
root->count = 1;
root->left = root->right = NULL;
} else if ( strcmp (nodename, root->widget_name ) < 0 ){ //else if ( root->left == NULL)
root->left = InsertAST ( root->left, nodename);
}
else if ( strcmp (nodename, root->widget_name ) > 0 ){
root->right = InsertAST ( root->right, nodename);
}
else{ // must be equal
root->count++;
}
return root;
}
static const c11n_marshaller_api c11n_markshaller_api_AST =
C11N_MARSHALLER_API_INIT("AST",
NULL,
NULL,
NULL,
NULL,
NULL);
static const c11n_marshaller AST_c11nX = { &c11n_markshaller_api_AST };
const c11n_marshaller * AST_c11n = &AST_c11nX;