Обсуждение: how to add my source file?

Поиск
Список
Период
Сортировка

how to add my source file?

От
dakotali kasap
Дата:
<div style="font-family:times new roman, new york, times, serif;font-size:12pt">Hi,<br /><br />I want to add my .c and
.hsource files into the postgresql project. What kind of changes should I make with the Makefiles. It seems that, it is
notenough just to add the object file of the C files into the Makefile.<br /><br />Can anyone help to me please?<br
/><br/>kind regards,<br /><br />dakotali<br /><br /></div><br />__________________________________________________<br
/>DoYou Yahoo!?<br />Tired of spam? Yahoo! Mail has the best spam protection around <br />http://mail.yahoo.com  

Re: how to add my source file?

От
Alvaro Herrera
Дата:
dakotali kasap wrote:
> Hi,
> 
> I want to add my .c and .h source files into the postgresql project.
> What kind of changes should I make with the Makefiles. It seems that,
> it is not enough just to add the object file of the C files into the
> Makefile.

Huh, why not?  Typically you just add the files to OBJS.  What problem
are you having?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: how to add my source file?

От
dakotali kasap
Дата:
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?

regards,

dakotali



dakotali kasap wrote:
> Hi,
>
> I want to add my .c and .h source files into the postgresql project.
> What kind of changes should I make with the Makefiles. It seems that,
> it is not enough just to add the object file of the C files into the
> Makefile.

Huh, why not?  Typically you just add the files to OBJS.  What problem
are you having?

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

                http://www.postgresql.org/about/donate


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

Re: how to add my source file?

От
dakotali kasap
Дата:
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
addingthe object file name into the Makefile.<br /><br />So, here is the whole picture:<br /><br /><br />I want to
writea function that takes the raw parsetree and rewrites it according to my rules, then produce new raw parsetrees.<br
/><br/>I will call this function inside backend/tcop/postgres.c . I wrote an header file called my_rewriter.h and
includethis inside postgres.c.<br /><br />my_writer.h looks like:<br
/>-------------------------------------------------<br/>#ifndef UWSDREWRITE_H<br />#define UWSDREWRITE_H<br /><br
/>#include"nodes/pg_list.h"<br />#include "nodes/nodes.h"<br /><br />typedef struct my_Projection<br />{<br />    char
*relname;<br/>    List attnames;<br />    char *result_relname;<br /><br />} my_Projection;<br /><br />.<br />.<br
/>.<br/><br />extern void  my_analyze(Node *parsetree);<br />extern void my_rewrite(List *parsetree_list);<br /><br
/>#endifUWSDREWRITE_H<br />---------------------------------------------<br /><br /><br />my_writer.c looks like:<br
/>-------------------------------------------------<br/>#include "nodes/nodes.h"<br />#include <stdio.h><br
/>#include"nodes/pg_list.h"<br /><br /><br />static void my_string_print(char *s);<br />static void my_int_print(int
i);<br/><br />static void my_string_print(char *s)<br />{<br />    FILE *outfile = fopen("/home/?/the_log.txt",
"a");<br/>    fprintf(outfile,"\n%s\n", s);<br />    fflush(stdout);<br />    fclose(outfile);<br />}<br /><br />static
voidmy_int_print(int i)<br />{<br />    FILE *outfile = fopen("/home/?/the_log.txt", "a");<br />    fprintf(outfile,"\n
theint is: %d\n", i);<br />    fflush(stdout);<br />    fclose(outfile);<br />}<br /><br />void UWSD_rewrite(List
*parsetree_list)<br/>{<br />    ListCell   *parsetree_item;<br />    <br />    foreach(parsetree_item,
parsetree_list)<br/>    {<br />        Node       *parsetree = (Node *) lfirst(parsetree_item);<br />       
UWSD_analyze(parsetree);<br/>    }<br />}<br /><br />void UWSD_analyze(Node *parsetree)<br />{<br />   
if(nodeTag(parsetree)==T_SelectStmt)<br/>    {<br />        my_string_print("THIS IS A SELECT STMT");<br />    }<br
/>   else my_int_print(nodeTag(parsetree));<br />}<br /><br
/>-----------------------------------------------------------<br/><br /><br />Then I wrote a C file called my_writer.c,
anddo the implementation of my_analyze(Node *parsetree) and my_rewrite(List *parsetree_list) functions.  I need Node
andList 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:<br /><br />---------------------------------------<br
/>../../../src/include/nodes/nodes.h:359:error: syntax error before ¡Node¢<br />../../../src/include/nodes/nodes.h:398:
error:syntax error before ¡equal¢<br />../../../src/include/nodes/nodes.h:398: warning: type defaults to ¡int¢ in
declarationof ¡equal¢<br />../../../src/include/nodes/nodes.h:398: warning: data definition has no type or storage
class<br/>----------------------------------------<br /><br />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?<br /><br />regards,<br
/><br/>dakotali<br /><br /><br /><br /><b><i>Andrew Dunstan <andrew@dunslane.net></i></b> wrote:<blockquote
class="replbq"style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> dakotali kasap
wrote:<br/>> Hi,<br />><br />> I have one source and one header file which are called my_writer.h and <br
/>>my_writer.c. I included my_writer.h inside postgres.c and do the <br />> implementation of declared functions
insidemy_writer.c. When I <br />> include, some other header files of postgresql (like nodes/pg_list.h <br />> or
nodes/nodes.h)in my_writer.c, it gives me compile errors that are <br />> related with these header files of
postgresql,although there is no <br />> problem.<br />><br />> Do you know why?<br />><br /><br />We're not
magicians,nor mindreaders. Unless you give us enough <br />information we can't possibly guess. At the very least you
needto show <br />us what the offending code is and what the compiler error is.<br /><br />cheers<br /><br />andrew<br
/></blockquote><br/><p> __________________________________________________<br />Do You Yahoo!?<br />Tired of spam?
Yahoo!Mail has the best spam protection around <br />http://mail.yahoo.com  

Re: how to add my source file?

От
Andrew Dunstan
Дата:
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


Re: how to add my source file?

От
Bruce Momjian
Дата:
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
addingthe 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
thisinside 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 <stdio.h>
> #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
headerfiles (#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
didnot work, what else should I do?
 
> 
> regards,
> 
> dakotali
> 
> 
> 
> Andrew Dunstan <andrew@dunslane.net> 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@momjian.us EnterpriseDB    http://www.enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: how to add my source file?

От
Andrew Dunstan
Дата:
dakotali kasap wrote:
>
> my_writer.c looks like:
> -------------------------------------------------
> #include "nodes/nodes.h"
> #include <stdio.h>
> #include "nodes/pg_list.h"
>
>

well, you normally have to include "postgres.h" before any other 
postgres header.

cheers

andrew


Re: how to add my source file?

От
dakotali kasap
Дата:
Thanks a lot, it worked:) Actually, I have tried to include "postgres.h" before, but not at the top of the other
includes.<br/><br />regards,<br /><br />dakotali<br /><br /><b><i>Bruce Momjian <bruce@momjian.us></i></b>
wrote:<blockquoteclass="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left:
5px;"><br/>Ah, all *.c files must have this at the top before they include _any_<br />other files, including system
includefiles:<br /><br /> #include "postgres.h"<br /><br />You will see that all our backend files follow this rule.<br
/><br/>---------------------------------------------------------------------------<br /><br />dakotali kasap wrote:<br
/>>Sorry I did not want to bother you with the details, I just thought that there is smth that I have to do apart
fromadding the object file name into the Makefile.<br />> <br />> So, here is the whole picture:<br />> <br
/>><br />> I want to write a function that takes the raw parsetree and rewrites it according to my rules, then
producenew raw parsetrees.<br />> <br />> I will call this function inside backend/tcop/postgres.c . I wrote an
headerfile called my_rewriter.h and include this inside postgres.c.<br />> <br />> my_writer.h looks like:<br
/>>-------------------------------------------------<br />> #ifndef UWSDREWRITE_H<br />> #define
UWSDREWRITE_H<br/>> <br />> #include "nodes/pg_list.h"<br />> #include "nodes/nodes.h"<br />> <br />>
typedefstruct my_Projection<br />> {<br />> char *relname;<br />> List attnames;<br />> char
*result_relname;<br/>> <br />> } my_Projection;<br />> <br />> .<br />> .<br />> .<br />> <br
/>>extern void my_analyze(Node *parsetree);<br />> extern void my_rewrite(List *parsetree_list);<br />> <br
/>>#endif UWSDREWRITE_H<br />> ---------------------------------------------<br />> <br />> <br />>
my_writer.clooks like:<br />> -------------------------------------------------<br />> #include
"nodes/nodes.h"<br/>> #include <br />> #include "nodes/pg_list.h"<br />> <br />> <br />> static void
my_string_print(char*s);<br />> static void my_int_print(int i);<br />> <br />> static void
my_string_print(char*s)<br />> {<br />> FILE *outfile = fopen("/home/?/the_log.txt", "a");<br />>
fprintf(outfile,"\n%s\n",s);<br />> fflush(stdout);<br />> fclose(outfile);<br />> }<br />> <br />>
staticvoid my_int_print(int i)<br />> {<br />> FILE *outfile = fopen("/home/?/the_log.txt", "a");<br />>
fprintf(outfile,"\nthe int is: %d\n", i);<br />> fflush(stdout);<br />> fclose(outfile);<br />> }<br />>
<br/>> void UWSD_rewrite(List *parsetree_list)<br />> {<br />> ListCell *parsetree_item;<br />> <br />>
foreach(parsetree_item,parsetree_list)<br />> {<br />> Node *parsetree = (Node *) lfirst(parsetree_item);<br
/>>UWSD_analyze(parsetree);<br />> }<br />> }<br />> <br />> void UWSD_analyze(Node *parsetree)<br
/>>{<br />> if(nodeTag(parsetree)==T_SelectStmt)<br />> {<br />> my_string_print("THIS IS A SELECT
STMT");<br/>> }<br />> else my_int_print(nodeTag(parsetree));<br />> }<br />> <br />>
-----------------------------------------------------------<br/>> <br />> <br />> 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
needNode 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:<br />> <br />> ---------------------------------------<br
/>>../../../src/include/nodes/nodes.h:359: error: syntax error before ?Node?<br />>
../../../src/include/nodes/nodes.h:398:error: syntax error before ?equal?<br />>
../../../src/include/nodes/nodes.h:398:warning: type defaults to ?int? in declaration of ?equal?<br />>
../../../src/include/nodes/nodes.h:398:warning: data definition has no type or storage class<br />>
----------------------------------------<br/>> <br />> I added the object file my_writer.o to the Makefile inside
backend/parser/Makefileand configured again, but it did not work, what else should I do?<br />> <br />>
regards,<br/>> <br />> dakotali<br />> <br />> <br />> <br />> Andrew Dunstan  wrote: dakotali kasap
wrote:<br/>> > Hi,<br />> ><br />> > I have one source and one header file which are called
my_writer.hand <br />> > my_writer.c. I included my_writer.h inside postgres.c and do the <br />> >
implementationof declared functions inside my_writer.c. When I <br />> > include, some other header files of
postgresql(like nodes/pg_list.h <br />> > or nodes/nodes.h) in my_writer.c, it gives me compile errors that are
<br/>> > related with these header files of postgresql, although there is no <br />> > problem.<br />>
><br/>> > Do you know why?<br />> ><br />> <br />> We're not magicians, nor mindreaders. Unless
yougive us enough <br />> information we can't possibly guess. At the very least you need to show <br />> us what
theoffending code is and what the compiler error is.<br />> <br />> cheers<br />> <br />> andrew<br />>
<br/>> <br />> __________________________________________________<br />> Do You Yahoo!?<br />> Tired of
spam?Yahoo! Mail has the best spam protection around <br />> http://mail.yahoo.com <br />-- <br /> Bruce Momjian
bruce@momjian.us<br/> EnterpriseDB http://www.enterprisedb.com<br /><br /> + If your life is a hard drive, Christ can
beyour backup. +<br /><br />---------------------------(end of broadcast)---------------------------<br />TIP 5: don't
forgetto increase your free space map settings<br /></blockquote><br /><p>
__________________________________________________<br/>Do You Yahoo!?<br />Tired of spam? Yahoo! Mail has the best spam
protectionaround <br />http://mail.yahoo.com