AbdulYadi / pgqr

PostgreSQL extension to generate QR code
BSD 3-Clause "New" or "Revised" License
16 stars 4 forks source link

Add PostgreSQL 16/17 support #4

Open Vonng opened 1 month ago

Vonng commented 1 month ago

Fail to build against PostgreSQL 16/17

QR_Encode.c:585:5: warning: no previous prototype for 'IsNumeralData' [-Wmissing-prototypes]
 int IsNumeralData(unsigned char c)
     ^~~~~~~~~~~~~
QR_Encode.c:599:5: warning: no previous prototype for 'IsAlphabetData' [-Wmissing-prototypes]
 int IsAlphabetData(unsigned char c)
     ^~~~~~~~~~~~~~
QR_Encode.c:620:5: warning: no previous prototype for 'IsKanjiData' [-Wmissing-prototypes]
 int IsKanjiData(unsigned char c1, unsigned char c2)
     ^~~~~~~~~~~
QR_Encode.c:639:6: warning: no previous prototype for 'AlphabetToBinary' [-Wmissing-prototypes]
 BYTE AlphabetToBinary(unsigned char c)
      ^~~~~~~~~~~~~~~~
QR_Encode.c:669:6: warning: no previous prototype for 'KanjiToBinaly' [-Wmissing-prototypes]
 WORD KanjiToBinaly(WORD wc)
      ^~~~~~~~~~~~~
QR_Encode.c:679:5: warning: no previous prototype for 'SetBitStream' [-Wmissing-prototypes]
 int SetBitStream(int nIndex, WORD wData, int ncData,BYTE m_byDataCodeWord[MAX_DATACODEWORD])
     ^~~~~~~~~~~~
QR_Encode.c:698:5: warning: no previous prototype for 'GetBitLength' [-Wmissing-prototypes]
 int GetBitLength(BYTE nMode, int ncData, int nVerGroup)
     ^~~~~~~~~~~~
QR_Encode.c:739:5: warning: no previous prototype for 'EncodeSourceData' [-Wmissing-prototypes]
 int EncodeSourceData(LPCSTR lpsSource, int ncLength, int nVerGroup,int m_nBlockLength[MAX_DATACODEWORD],BYTE m_byBlockMode[MAX_DATACODEWORD],BYTE m_byDataCodeWord[MAX_DATACODEWORD])
     ^~~~~~~~~~~~~~~~
In file included from QR_Encode.c:2:
QR_Encode.c: In function 'EncodeSourceData':
QR_Encode.c:742:35: warning: 'sizeof' on array function parameter 'm_nBlockLength' will return size of 'int *' [-Wsizeof-array-argument]
  ZeroMemory(m_nBlockLength, sizeof(m_nBlockLength));
                                   ^
QR_Encode.h:84:64: note: in definition of macro 'ZeroMemory'
 #define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
                                                                ^~~~~~
QR_Encode.c:739:72: note: declared here
 int EncodeSourceData(LPCSTR lpsSource, int ncLength, int nVerGroup,int m_nBlockLength[MAX_DATACODEWORD],BYTE m_byBlockMode[MAX_DATACODEWORD],BYTE m_byDataCodeWord[MAX_DATACODEWORD])
                                                                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from QR_Encode.c:2:
QR_Encode.c:742:35: warning: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
  ZeroMemory(m_nBlockLength, sizeof(m_nBlockLength));
                                   ^
QR_Encode.h:84:64: note: in definition of macro 'ZeroMemory'
 #define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
                                                                ^~~~~~
QR_Encode.c:744:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int i, j;
  ^~~
QR_Encode.c:780:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int ncSrcBits, ncDstBits; //The bit length of the block mode if you have over the original bit length and a single alphanumeric
  ^~~
QR_Encode.c:1004:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int ncComplete = 0; //Data pre-processing counter
  ^~~
QR_Encode.c:1131:10: warning: declaration of 'wBinCode' shadows a previous local [-Wshadow=compatible-local]
     WORD wBinCode = KanjiToBinaly((WORD)(((BYTE)lpsSource[ncComplete + (j * 2)] << 8) + (BYTE)lpsSource[ncComplete + (j * 2) + 1]));
          ^~~~~~~~
QR_Encode.c:1006:7: note: shadowed declaration is here
  WORD wBinCode;
       ^~~~~~~~
QR_Encode.c: At top level:
QR_Encode.c:1152:5: warning: no previous prototype for 'GetEncodeVersion' [-Wmissing-prototypes]
 int GetEncodeVersion(int nVersion, LPCSTR lpsSource, int ncLength,int m_nBlockLength[MAX_DATACODEWORD],BYTE m_byBlockMode[MAX_DATACODEWORD],BYTE m_byDataCodeWord[MAX_DATACODEWORD])
     ^~~~~~~~~~~~~~~~
QR_Encode.c:1192:5: warning: no previous prototype for 'min' [-Wmissing-prototypes]
 int min(int a, int b) {
     ^~~
QR_Encode.c:1201:6: warning: no previous prototype for 'GetRSCodeWord' [-Wmissing-prototypes]
 void GetRSCodeWord(LPBYTE lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord)
      ^~~~~~~~~~~~~
QR_Encode.c:1237:6: warning: no previous prototype for 'SetFinderPattern' [-Wmissing-prototypes]
 void SetFinderPattern(int x, int y,BYTE m_byModuleData[177][177])
      ^~~~~~~~~~~~~~~~
QR_Encode.c:1257:6: warning: no previous prototype for 'SetVersionPattern' [-Wmissing-prototypes]
 void SetVersionPattern(BYTE m_byModuleData[177][177])
      ^~~~~~~~~~~~~~~~~
QR_Encode.c: In function 'SetVersionPattern':
QR_Encode.c:1264:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int nVerData = QR_m_nVersion << 12;
  ^~~
QR_Encode.c: At top level:
QR_Encode.c:1288:6: warning: no previous prototype for 'SetAlignmentPattern' [-Wmissing-prototypes]
 void SetAlignmentPattern(int x, int y,BYTE m_byModuleData[177][177])
      ^~~~~~~~~~~~~~~~~~~
QR_Encode.c:1313:6: warning: no previous prototype for 'SetFunctionModule' [-Wmissing-prototypes]
 void SetFunctionModule(BYTE m_byModuleData[177][177])
      ^~~~~~~~~~~~~~~~~
QR_Encode.c:1368:6: warning: no previous prototype for 'SetCodeWordPattern' [-Wmissing-prototypes]
 void SetCodeWordPattern(BYTE m_byModuleData[177][177],BYTE m_byAllCodeWord[MAX_ALLCODEWORD])
      ^~~~~~~~~~~~~~~~~~
QR_Encode.c:1413:6: warning: no previous prototype for 'SetMaskingPattern' [-Wmissing-prototypes]
 void SetMaskingPattern(int nPatternNo,BYTE m_byModuleData[177][177])
      ^~~~~~~~~~~~~~~~~
QR_Encode.c:1466:6: warning: no previous prototype for 'SetFormatInfoPattern' [-Wmissing-prototypes]
 void SetFormatInfoPattern(int nPatternNo,BYTE m_byModuleData[177][177])
      ^~~~~~~~~~~~~~~~~~~~
QR_Encode.c: In function 'SetFormatInfoPattern':
QR_Encode.c:1492:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int nFormatData = nFormatInfo << 10;
  ^~~
QR_Encode.c: At top level:
QR_Encode.c:1535:5: warning: no previous prototype for 'CountPenalty' [-Wmissing-prototypes]
 int CountPenalty(BYTE m_byModuleData[177][177])
     ^~~~~~~~~~~~
QR_Encode.c: In function 'CountPenalty':
QR_Encode.c:1669:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int nCount = 0;
  ^~~
QR_Encode.c: At top level:
QR_Encode.c:1688:6: warning: no previous prototype for 'FormatModule' [-Wmissing-prototypes]
 void FormatModule(BYTE m_byModuleData[177][177],BYTE m_byAllCodeWord[MAX_ALLCODEWORD])
      ^~~~~~~~~~~~
In file included from QR_Encode.c:2:
QR_Encode.c: In function 'FormatModule':
QR_Encode.c:1692:35: warning: 'sizeof' on array function parameter 'm_byModuleData' will return size of 'BYTE (*)[177]' {aka 'unsigned char (*)[177]'} [-Wsizeof-array-argument]
  ZeroMemory(m_byModuleData, sizeof(m_byModuleData));
                                   ^
QR_Encode.h:84:64: note: in definition of macro 'ZeroMemory'
 #define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
                                                                ^~~~~~
QR_Encode.c:1688:24: note: declared here
 void FormatModule(BYTE m_byModuleData[177][177],BYTE m_byAllCodeWord[MAX_ALLCODEWORD])
                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from QR_Encode.c:2:
QR_Encode.c:1692:35: warning: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
  ZeroMemory(m_byModuleData, sizeof(m_byModuleData));
                                   ^
QR_Encode.h:84:64: note: in definition of macro 'ZeroMemory'
 #define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
                                                                ^~~~~~
QR_Encode.c:1711:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   int nMinPenalty = CountPenalty(m_byModuleData);
   ^~~
QR_Encode.c:1718:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    int nPenalty = CountPenalty(m_byModuleData);
    ^~~
QR_Encode.c: At top level:
QR_Encode.c:1743:6: warning: no previous prototype for 'putBitToPos' [-Wmissing-prototypes]
 void putBitToPos(unsigned int pos,int bw,unsigned char *bits)
      ^~~~~~~~~~~
QR_Encode.c: In function 'putBitToPos':
QR_Encode.c:1746:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
         unsigned int tmp;
         ^~~~~~~~
QR_Encode.c: At top level:
QR_Encode.c:1760:6: warning: no previous prototype for 'fillData' [-Wmissing-prototypes]
 void fillData(BYTE m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE], unsigned char QR_m_data[]) {
      ^~~~~~~~
QR_Encode.c: In function 'EncodeData':
QR_Encode.c:1805:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int ncLength = strlen(lpsSource);
  ^~~
QR_Encode.c:1841:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int ncDataCodeWord = QR_VersionInfo[QR_m_nVersion].ncDataCodeWord[nLevel];
  ^~~
QR_Encode.c:1850:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  BYTE byPaddingCode = 0xec;
  ^~~~
QR_Encode.c:1865:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int nDataCwIndex = 0;   // Position data processing code word
  ^~~
QR_Encode.c:1919:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int ncRSCw1 = QR_VersionInfo[QR_m_nVersion].RS_BlockInfo1[nLevel].ncAllCodeWord - ncDataCw1;
  ^~~
QR_Encode.c: In function 'bmpOut':
QR_Encode.c:1984:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int headerSize=sizeof(BITMAPFILEHEADER)
  ^~~
QR_Encode.c:1991:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  unsigned char* p=*pBuffer;
  ^~~~~~~~
QR_Encode.c:2000:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  PBITMAPINFOHEADER info=(PBITMAPINFOHEADER)p;
  ^~~~~~~~~~~~~~~~~
QR_Encode.c:2014:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  PBITMAPCOLORTABLE clr=(PBITMAPCOLORTABLE)p;
  ^~~~~~~~~~~~~~~~~
QR_Encode.c:2028:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  int i,j,k,m;
  ^~~
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -fvisibility=hidden -shared -o pgqr.so pgqr.o QR_Encode.o -L/usr/pgsql-16/lib  -Wl,--as-needed -L/usr/lib64 -L/usr/lib  -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-16/lib',--enable-new-dtags  -fvisibility=hidden
QR_Encode.c:742:35: warning: sizeof on array function parameter will return size of 'int *' instead of 'int[2956]' [-Wsizeof-array-argument]
  742 |         ZeroMemory(m_nBlockLength, sizeof(m_nBlockLength));
      |                                          ^
QR_Encode.c:739:72: note: declared here
  739 | int EncodeSourceData(LPCSTR lpsSource, int ncLength, int nVerGroup,int m_nBlockLength[MAX_DATACODEWORD],BYTE m_byBlockMode[MAX_DATACODEWORD],BYTE m_byDataCodeWord[MAX_DATACODEWORD])
      |                                                                        ^
QR_Encode.c:742:36: warning: 'ZeroMemory' call operates on objects of type 'int' while the size is based on a different type 'int *' [-Wsizeof-pointer-memaccess]
  742 |         ZeroMemory(m_nBlockLength, sizeof(m_nBlockLength));
      |                    ~~~~~~~~~~~~~~         ^~~~~~~~~~~~~~
QR_Encode.c:742:36: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?
  742 |         ZeroMemory(m_nBlockLength, sizeof(m_nBlockLength));
      |                                           ^~~~~~~~~~~~~~
pgqr.c:62:9: error: call to undeclared function 'VARDATA'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   62 |         memcpy(VARDATA(blobout), p_bmp, bmp_size);
      |                ^
pgqr.c:62:9: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'void *' [-Wint-conversion]
   62 |         memcpy(VARDATA(blobout), p_bmp, bmp_size);
      |                ^~~~~~~~~~~~~~~~
/usr/include/string.h:43:39: note: passing argument to parameter '__dest' here
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |                                       ^
pgqr.c:64:2: error: call to undeclared function 'SET_VARSIZE'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   64 |         SET_VARSIZE(blobout, bmp_size+VARHDRSZ);
      |         ^
3 errors generated.
make: *** [/usr/pgsql-16/lib/pgxs/src/makefiles/../../src/Makefile.global:1093: pgqr.bc] Error 1
make: *** Waiting for unfinished jobs....
QR_Encode.c:1692:35: warning: sizeof on array function parameter will return size of 'BYTE (*)[177]' (aka 'unsigned char (*)[177]') instead of 'BYTE[177][177]' (aka 'unsigned char[177][177]') [-Wsizeof-array-argument]
 1692 |         ZeroMemory(m_byModuleData, sizeof(m_byModuleData));
      |                                          ^
QR_Encode.c:1688:24: note: declared here
 1688 | void FormatModule(BYTE m_byModuleData[177][177],BYTE m_byAllCodeWord[MAX_ALLCODEWORD])
      |                        ^
QR_Encode.c:1692:36: warning: 'ZeroMemory' call operates on objects of type 'BYTE[177]' (aka 'unsigned char[177]') while the size is based on a different type 'BYTE (*)[177]' (aka 'unsigned char (*)[177]') [-Wsizeof-pointer-memaccess]
 1692 |         ZeroMemory(m_byModuleData, sizeof(m_byModuleData));
      |                    ~~~~~~~~~~~~~~         ^~~~~~~~~~~~~~
QR_Encode.c:1692:36: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?
 1692 |         ZeroMemory(m_byModuleData, sizeof(m_byModuleData));
      |                                           ^~~~~~~~~~~~~~
4 warnings generated.
error: Bad exit status from /var/tmp/rpm-tmp.IzNFmG (%build)

RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.IzNFmG (%build)
robertbruno commented 1 month ago

I was able to resolve the compilation issue for PostgreSQL 16 and 17 by including the varatt.h header.

It seems that the required definitions for varatt.h have been modified or added in these newer PostgreSQL versions. By explicitly including this header, the compiler can find the necessary declarations and successfully build the extension.

To implement this solution:

  1. Locate the relevant source file(s): Identify the C/C++ files in your extension where the missing declarations were causing the compilation errors.
  2. Add the include directive: At the beginning of these files, add the following line:
    #include "varatt.h"
  3. Recompile the extension: Rebuild your extension using the updated source files.

    Additional considerations:

    • Conditional inclusion: If you want to maintain compatibility with older PostgreSQL versions, you can use conditional compilation directives (e.g., #ifdef and #endif) to include varatt.h only when compiling for PostgreSQL 16 or 17.
    • Dependency management: Ensure that your build system is configured correctly to find the varatt.h header file. This might involve setting appropriate include paths.