Skip site navigation (1) Skip section navigation (2)

Re: how to add my source file?

From: dakotali kasap <dakotalidavid(at)yahoo(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: how to add my source file?
Date: 2006-12-27 19:08:24
Message-ID: 354060.24913.qm@web31315.mail.mud.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Thanks a lot, it worked:) Actually, I have tried to include "postgres.h" before, but not at the top of the other includes.

regards,

dakotali

Bruce Momjian <bruce(at)momjian(dot)us> wrote: 
Ah, all *.c files must have this at the top before they include _any_
other files, including system include files:

 #include "postgres.h"

You will see that all our backend files follow this rule.

---------------------------------------------------------------------------

dakotali kasap wrote:
> Sorry I did not want to bother you with the details, I just thought that there is smth that I have to do apart from adding the object file name into the Makefile.
> 
> So, here is the whole picture:
> 
> 
> I want to write a function that takes the raw parsetree and rewrites it according to my rules, then produce new raw parsetrees.
> 
> I will call this function inside backend/tcop/postgres.c . I wrote an header file called my_rewriter.h and include this inside postgres.c.
> 
> my_writer.h looks like:
> -------------------------------------------------
> #ifndef UWSDREWRITE_H
> #define UWSDREWRITE_H
> 
> #include "nodes/pg_list.h"
> #include "nodes/nodes.h"
> 
> typedef struct my_Projection
> {
>     char *relname;
>     List attnames;
>     char *result_relname;
> 
> } my_Projection;
> 
> .
> .
> .
> 
> extern void  my_analyze(Node *parsetree);
> extern void my_rewrite(List *parsetree_list);
> 
> #endif  UWSDREWRITE_H
> ---------------------------------------------
> 
> 
> my_writer.c looks like:
> -------------------------------------------------
> #include "nodes/nodes.h"
> #include 
> #include "nodes/pg_list.h"
> 
> 
> static void my_string_print(char *s);
> static void my_int_print(int i);
> 
> static void my_string_print(char *s)
> {
>     FILE *outfile = fopen("/home/?/the_log.txt", "a");
>     fprintf(outfile,"\n%s\n", s);
>     fflush(stdout);
>     fclose(outfile);
> }
> 
> static void my_int_print(int i)
> {
>     FILE *outfile = fopen("/home/?/the_log.txt", "a");
>     fprintf(outfile,"\n the int is: %d\n", i);
>     fflush(stdout);
>     fclose(outfile);
> }
> 
> void UWSD_rewrite(List *parsetree_list)
> {
>     ListCell   *parsetree_item;
>     
>     foreach(parsetree_item, parsetree_list)
>     {
>         Node       *parsetree = (Node *) lfirst(parsetree_item);
>         UWSD_analyze(parsetree);
>     }
> }
> 
> void UWSD_analyze(Node *parsetree)
> {
>     if(nodeTag(parsetree)==T_SelectStmt)
>     {
>         my_string_print("THIS IS A SELECT STMT");
>     }
>     else my_int_print(nodeTag(parsetree));
> }
> 
> -----------------------------------------------------------
> 
> 
> Then I wrote a C file called my_writer.c, and do the implementation of my_analyze(Node *parsetree) and my_rewrite(List *parsetree_list) functions.  I need Node and List structures here, but when I include the necessary header files (#include "nodes/pg_list.h", #include "nodes/nodes.h"), I got errors at compile time like:
> 
> ---------------------------------------
> ../../../src/include/nodes/nodes.h:359: error: syntax error before ?Node?
> ../../../src/include/nodes/nodes.h:398: error: syntax error before ?equal?
> ../../../src/include/nodes/nodes.h:398: warning: type defaults to ?int? in declaration of ?equal?
> ../../../src/include/nodes/nodes.h:398: warning: data definition has no type or storage class
> ----------------------------------------
> 
> I added the object file my_writer.o  to the  Makefile inside  backend/parser/Makefile and configured again, but it did not work, what else should I do?
> 
> regards,
> 
> dakotali
> 
> 
> 
> Andrew Dunstan  wrote: dakotali kasap wrote:
> > Hi,
> >
> > I have one source and one header file which are called my_writer.h and 
> > my_writer.c. I included my_writer.h inside postgres.c and do the 
> > implementation of declared functions inside my_writer.c. When I 
> > include, some other header files of postgresql (like nodes/pg_list.h 
> > or nodes/nodes.h) in my_writer.c, it gives me compile errors that are 
> > related with these header files of postgresql, although there is no 
> > problem.
> >
> > Do you know why?
> >
> 
> We're not magicians, nor mindreaders. Unless you give us enough 
> information we can't possibly guess. At the very least you need to show 
> us what the offending code is and what the compiler error is.
> 
> cheers
> 
> andrew
> 
> 
>  __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
-- 
  Bruce Momjian   bruce(at)momjian(dot)us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings


 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2006-12-27 19:15:02
Subject: Re: [BUGS] BUG #2846: inconsistent and confusing handling of
Previous:From: Bruce MomjianDate: 2006-12-27 18:44:31
Subject: Re: [BUGS] BUG #2846: inconsistent and confusing handling of

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group