Topic
  • No replies
NenadV
NenadV
4 Posts

Pinned topic Porting 7zip to z/OS USS - compile error

‏2013-02-01T09:33:55Z |
Hello,

could you help me with the following error ?

1 // ConsoleClose.cpp
2
3 #include "StdAfx.h"
4
5 #include "ConsoleClose.h"
6
7 #include <signal.h>
8
9 static int g_BreakCounter = 0;
10 static const int kBreakAbortThreshold = 2;
11
12 namespace NConsoleClose {
13
14
15 #ifdef __cplusplus /* the __cplusplus macro */
16 extern "C" void HandlerRoutine(int); /* is automatically defined */
17 #else /* by the C++/MVS compiler */
18 void HandlerRoutine(int);
19 #endif
20
21 static void HandlerRoutine(int)
22 {
23 g_BreakCounter++;
24 if (g_BreakCounter < kBreakAbortThreshold)
25 return ;
26 exit(EXIT_FAILURE);
27 }
28
29 bool TestBreakSignal()
30 {
31 return (g_BreakCounter > 0);
32 }
33
34 void CheckCtrlBreak()
35 {
36 if (TestBreakSignal())
37 throw CCtrlBreakException();
38 }
39
40
41 CCtrlHandlerSetter::CCtrlHandlerSetter()
42
43 {
44 memo_sig_int = signal(SIGINT,HandlerRoutine); // CTRL-C
45 if (memo_sig_int == SIG_ERR)
46 throw "SetConsoleCtrlHandler fails (SIGINT)";
47 memo_sig_term = signal(SIGTERM,HandlerRoutine); // for kill -15 (before "kill -9")
48 if (memo_sig_term == SIG_ERR)
49 throw "SetConsoleCtrlHandler fails (SIGTERM)";
Compile error:

"../../UI/Console/ConsoleClose.cpp", line 21.13: CCN5400 (S) "NConsoleClose::HandlerRoutine(int)" has a conflicting declaration.
"../../UI/Console/ConsoleClose.cpp", line 16.18: CCN5424 (I) "HandlerRoutine" is declared on line 16 of "../../UI/Console/ConsoleClose.cpp".
If I remove "static" in line 21, I get :

"../../UI/Console/ConsoleClose.cpp", line 44.25: CCN5216 (S) An expression of type "extern "C" void (*)(int)" cannot be converted to type "void (*)(int)".
"../../UI/Console/ConsoleClose.cpp", line 45.8: CCN5207 (S) No common type found for operands with type "void (*)(int)" and "extern "C" void (*)(int)".
"../../UI/Console/ConsoleClose.cpp", line 47.26: CCN5216 (S) An expression of type "extern "C" void (*)(int)" cannot be converted to type "void (*)(int)".
Regards,
Nenad
Updated on 2013-03-28T12:41:02Z at 2013-03-28T12:41:02Z by NenadV
  • DaveyC
    DaveyC
    55 Posts

    Re: Porting 7zip to z/OS USS - compile error

    ‏2013-02-04T06:44:06Z  
    That code is not really portable, although probably compiles fine on most compilers. "extern" and "static" are conflicting declarations. What you need is an unnamed namespace

    namespace 
    {
        void HandlerRoutine(int)
        {
           ....
        }
    }
    

    David Crayford
    Updated on 2014-03-24T22:16:14Z at 2014-03-24T22:16:14Z by iron-man
  • DaveyC
    DaveyC
    55 Posts

    Re: Porting 7zip to z/OS USS - compile error

    ‏2013-02-04T08:20:22Z  
    • DaveyC
    • ‏2013-02-04T06:44:06Z
    That code is not really portable, although probably compiles fine on most compilers. "extern" and "static" are conflicting declarations. What you need is an unnamed namespace

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">namespace { void HandlerRoutine(int) { .... } } </pre>
    David Crayford
    I'm not sure how the compiler handles mangling in a namespace but you might also fix the problem by ditching the declaration (prototype) and declare extern "C" in the definition. That normally works for me.

    extern "C" void HandlerRoutine(int)
        {
           .... // code goes here
        }
    


    David Crayford
    Updated on 2014-03-24T22:15:56Z at 2014-03-24T22:15:56Z by iron-man
  • NenadV
    NenadV
    4 Posts

    Re: Porting 7zip to z/OS USS - compile error

    ‏2013-02-08T10:34:29Z  
    • DaveyC
    • ‏2013-02-04T06:44:06Z
    That code is not really portable, although probably compiles fine on most compilers. "extern" and "static" are conflicting declarations. What you need is an unnamed namespace

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">namespace { void HandlerRoutine(int) { .... } } </pre>
    David Crayford
    Hello,

    did you mean unnamed namespace instead of existent (namespace NConsoleClose) or ... ? I tried different combinations but without success ....

    Regards,
    Nenad
  • NenadV
    NenadV
    4 Posts

    Re: Porting 7zip to z/OS USS - compile error

    ‏2013-02-08T10:37:35Z  
    • DaveyC
    • ‏2013-02-04T08:20:22Z
    I'm not sure how the compiler handles mangling in a namespace but you might also fix the problem by ditching the declaration (prototype) and declare extern "C" in the definition. That normally works for me.

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">extern "C" void HandlerRoutine(int) { .... // code goes here } </pre>

    David Crayford
    "extern "C"" solution also doesn't work ....

    .
    .
    .
    11
    12 namespace NConsoleClose {
    13
    14 extern "C" void HandlerRoutine(int)
    15 {
    16 g_BreakCounter++;
    17 if (g_BreakCounter < kBreakAbortThreshold)
    18 return ;
    19 exit(EXIT_FAILURE);
    20 }
    21
    22
    23 bool TestBreakSignal()
    24 {
    25 return (g_BreakCounter > 0);
    26 }
    27
    28 void CheckCtrlBreak()
    29 {
    30 if (TestBreakSignal())
    31 throw CCtrlBreakException();
    32 }
    33
    34
    35 CCtrlHandlerSetter::CCtrlHandlerSetter()
    36
    37 {
    38 memo_sig_int = signal(SIGINT,HandlerRoutine); // CTRL-C
    39 if (memo_sig_int == SIG_ERR)
    .
    .
    .
    ."../../UI/Console/ConsoleClose.cpp", line 38.25: CCN5216 (S) An expression of type "extern "C" void (*)(int)" cannot be converted to type "void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 39.8: CCN5207 (S) No common type found for operands with type "void (*)(int)" and "extern "C" void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 41.26: CCN5216 (S) An expression of type "extern "C" void (*)(int)" cannot be converted to type "void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 42.8: CCN5207 (S) No common type found for operands with type "void (*)(int)" and "extern "C" void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 48.18: CCN5256 (S) A parameter of type "extern "C" void (*)(int)" cannot be initialized with an expression of type "void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 48.18: CCN6205 (I) The error occurred while converting to parameter 2 of "signal(int, extern "C" void (*)(int))".
    "../../UI/Console/ConsoleClose.cpp", line 49.19: CCN5256 (S) A parameter of type "extern "C" void (*)(int)" cannot be initialized with an expression of type "void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 49.19: CCN6205 (I) The error occurred while converting to parameter 2 of "signal(int, extern "C" void (*)(int))".
    CCN0793(I) Compilation failed for file ../../UI/Console/ConsoleClose.cpp. Object file not created.
  • NenadV
    NenadV
    4 Posts

    Re: Porting 7zip to z/OS USS - compile error

    ‏2013-03-28T12:41:02Z  
    • NenadV
    • ‏2013-02-08T10:37:35Z
    "extern "C"" solution also doesn't work ....

    .
    .
    .
    11
    12 namespace NConsoleClose {
    13
    14 extern "C" void HandlerRoutine(int)
    15 {
    16 g_BreakCounter++;
    17 if (g_BreakCounter < kBreakAbortThreshold)
    18 return ;
    19 exit(EXIT_FAILURE);
    20 }
    21
    22
    23 bool TestBreakSignal()
    24 {
    25 return (g_BreakCounter > 0);
    26 }
    27
    28 void CheckCtrlBreak()
    29 {
    30 if (TestBreakSignal())
    31 throw CCtrlBreakException();
    32 }
    33
    34
    35 CCtrlHandlerSetter::CCtrlHandlerSetter()
    36
    37 {
    38 memo_sig_int = signal(SIGINT,HandlerRoutine); // CTRL-C
    39 if (memo_sig_int == SIG_ERR)
    .
    .
    .
    ."../../UI/Console/ConsoleClose.cpp", line 38.25: CCN5216 (S) An expression of type "extern "C" void (*)(int)" cannot be converted to type "void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 39.8: CCN5207 (S) No common type found for operands with type "void (*)(int)" and "extern "C" void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 41.26: CCN5216 (S) An expression of type "extern "C" void (*)(int)" cannot be converted to type "void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 42.8: CCN5207 (S) No common type found for operands with type "void (*)(int)" and "extern "C" void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 48.18: CCN5256 (S) A parameter of type "extern "C" void (*)(int)" cannot be initialized with an expression of type "void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 48.18: CCN6205 (I) The error occurred while converting to parameter 2 of "signal(int, extern "C" void (*)(int))".
    "../../UI/Console/ConsoleClose.cpp", line 49.19: CCN5256 (S) A parameter of type "extern "C" void (*)(int)" cannot be initialized with an expression of type "void (*)(int)".
    "../../UI/Console/ConsoleClose.cpp", line 49.19: CCN6205 (I) The error occurred while converting to parameter 2 of "signal(int, extern "C" void (*)(int))".
    CCN0793(I) Compilation failed for file ../../UI/Console/ConsoleClose.cpp. Object file not created.
    Hello,

    a new issues emerged:

    stuck with
    building Threads.c file:

    /c390/archive/zosv1r13/dataset/xlc -O -s -qlonglong -D_XOPEN_SOURCE=500
    -D_ISOC99_SOURCE -D_OPEN_THREADS=3 -DPTHREAD_CREATE_JOINABLE=0
    -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -DNDEBUG
    -D_REENTRANT -DENV_UNIX -DBREAK_HANDLER -DUNICODE -D_UNICODE -c -I.
    -I../../../../C -I../../../myWindows -I../../../include_windows
    -I../../.. ../../../../C/Threads.c -D_NO_PROTO
    ERROR CCN3068 <source file>:<line number> Operation between types
    "struct {...}" and "int" is not allowed.

    The reason for failure: implementation of pthread_t is platform
    specific and the p7zip code is written in such a way that it works on
    AIX/Linux, but it probably requires some porting efforts to make it work
    on z/OS.

    Particularly, on z/OS pthread_t declaration is done via structure:

    vi /usr/include/sys/types.h
    ...
    ...
    280 #ifndef __pthread_t
    281 #define __pthread_t 1
    282 typedef struct {
    283 char __0x08;
    284 } pthread_t;
    285 #endif

    vs AIX (and Linux) type of OS which declares pthread_t as of type
    unsigned int:

    vi /usr/include/sys/types.h
    ...
    ...
    +400
    +401 typedef unsigned int pthread_t;
    +402 typedef unsigned int pthread_key_t;
    +403
    Going back to the source, the offending line in the C/Threads.c file is
    here:

    55 WRes Thread_Close(CThread *thread)
    56 {
    57 if (!thread->_created) return SZ_OK;
    58
    59 thread->_tid = B_BAD_THREAD_ID; <---- An error is coming
    from here
    60 thread->_created = 0;
    61 return SZ_OK;
    62 }

    where _tid is earlier declared as of type pthread_t:

    #line 19 "../../../../C/Threads.h"
    typedef struct _CThread
    {
    #line 24
    pthread_t _tid;
    int _created;
    } CThread;
    Any help will be appreciated.