Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Postgres Modifications

viveksengupta edited this page Aug 14, 2015 · 8 revisions

Useful Links

Autogenerated files

The following files should be automatically generated:

  • /src/postgres/backend/bootstrap/bootparse.c
  • /src/postgres/backend/bootstrap/bootscanner.c
  • /src/postgres/backend/parser/scan.c
  • /src/postgres/backend/parser/gram.c
  • /src/postgres/backend/replication/repl_gram.c
  • /src/postgres/backend/replication/repl_scanner.c
  • /src/postgres/backend/utils/fmgrtab.c
  • /src/postgres/backend/utils/misc/guc-file.c
  • /src/postgres/backend/utils/sort/qsort_tuple.c
  • /tools/pg_psql/sql_help.c
  • /tools/pg_psql/psql_scan.c

Porting to C++

In order to port Postgres to C++, we made the following changes:

  1. Avoid keyword conflict

All variables that have conflicts with C++ keyword are appended with "___". Details of the cases are as follows:

  • new
  • namespace
  • friend
  • public
  • private
  • typename
  • typeid
  • constexpr
  • operator
  • class
  1. Make use of C++ inheritance to avoid casting

    All derived nodes struct in parsenodes.h are redefined using C++ inheritance.

  2. Resolve error for missing operator=

    Define operator= manually for the cases where volatile qualifier is used. C++ does not generate assignment operator for such cases by default. Deails of the cases are as follows:

    • RelFileNode at include/storage/relfilnode.h
    • QueuePosition at backend/commands/async.cpp
    • BufferTag at include/storage/buf_internals.h
  3. Resolve error for implicitly deleted default constructor

    union's default constructor is implictly deleted if one of its member has non-trivial constructor. The work around is to define the constructor mannually. Details of the cases are as follows:

    • SharedInvalidationMessage ar include/storage/sinval.h
  4. Resolve error for missing operator++

    The work around is to use operator+, instead of operator++. We changed all the occurrances of forkNum++ to forkNum = forkNum + 1

  5. Resolve error for missing namespace for inner enum

    Member enums have to be resolved by specifying class name. Details of the cases are as follows:

    • JsonbValue
  6. Avoid redefinition for static array

    Forward declaration for static array would be recognized as redefinition in C++. The work around is to add an anonymous namespace for them. The details of the the cases are as follows:

    • pg_crc32c_table at port/pg_crc32c_sb8.cpp
  7. Resolve unreference problem for extern const variable

    The work around is to add extern at the place where the variable is defined Details of the cases are as follows:

    • sync_method_options at backend/access/transam/xlog.cpp
    • wal_level_options at backend/access/rmgrdesc/xlogdesc.cpp
    • dynamic_shared_memory_options at backend/access/transam/xlog.cpp
    • archive_mode_options at backend/access/transam/xlog.cpp
  8. Resolve the differece of function pointer in C and C++

    In C, it is possible to declare a function that takes arbitray number of argument. But it is not the case in C++. The work around is to explicitly define funciton pointer types for different number of arguments. The datails of the cases are as follows:

    • func_ptr0 at backend/utils/fmgr/fmgr.c
    • func_ptr1 at backend/utils/fmgr/fmgr.c
    • func_ptr2 at backend/utils/fmgr/fmgr.c
    • func_ptr3 at backend/utils/fmgr/fmgr.c
    • func_ptr4 at backend/utils/fmgr/fmgr.c
    • func_ptr5 at backend/utils/fmgr/fmgr.c
    • func_ptr6 at backend/utils/fmgr/fmgr.c
    • func_ptr7 at backend/utils/fmgr/fmgr.c
    • func_ptr8 at backend/utils/fmgr/fmgr.c
    • func_ptr9 at backend/utils/fmgr/fmgr.c
    • func_ptr10 at backend/utils/fmgr/fmgr.c
    • func_ptr11 at backend/utils/fmgr/fmgr.c
    • func_ptr12 at backend/utils/fmgr/fmgr.c
    • func_ptr13 at backend/utils/fmgr/fmgr.c
    • func_ptr14 at backend/utils/fmgr/fmgr.c
    • func_ptr15 at backend/utils/fmgr/fmgr.c
    • func_ptr16 at backend/utils/fmgr/fmgr.c
    • expression_tree_walker at include/nodes/nodeFunc.h
    • expression_tree_mutator at include/nodes/nodeFunc.h
    • query_tree_walker at include/nodes/nodeFunc.h
    • query_tree_mutator at include/nodes/nodeFunc.h
    • range_table_walker at include/nodes/nodeFunc.h
    • range_table_mutator at include/nodes/nodeFunc.h
    • query_or_expression_tree_walker at include/nodes/nodeFunc.h
    • query_or_expression_tree_mutator at include/nodes/nodeFunc.h
    • raw_expression_tree_walker at include/nodes/nodeFunc.h

Fixing Warnings

  1. Changed C-style typecasts to static_cast in multiple files at:

    • /src/postgres/interfaces/libpq
    • /src/postgres/backend/access/brin
    • /src/postgres/backend/access/gin
    • /src/postgres/backend/access/gist
  2. Changed 3 C-style casts in the same directory in fe-lobj.cpp fileto reinterpret_cast

  3. Suppressed warnings for String to char * conversion (which has been deprecated) by adding the CXXFLAG Wno-write-string

  4. Added a macro at the end of c.h file to suppress compiler warning for unused variables in various function calls. Used this UNUSED macro wherever variables passed to a function were unused or used in #ifdef ... #endif

Clone this wiki locally