Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not all macros inside signal.h are expanded #30

Closed
nemanja-boric-sociomantic opened this issue Apr 9, 2018 · 3 comments
Closed

Not all macros inside signal.h are expanded #30

nemanja-boric-sociomantic opened this issue Apr 9, 2018 · 3 comments
Labels

Comments

@nemanja-boric-sociomantic

On my Ubuntu system, sigaction is defined as:

/* Structure describing the action to be taken when a signal arrives.  */                                             
struct sigaction                                                                                                      
  {                                                                                                                   
    /* Signal handler.  */                                                                                            
#ifdef __USE_POSIX199309                                                                                              
    union                                                                                                             
      {                                                                                                               
   /* Used if SA_SIGINFO is not set.  */                                                                             
   __sighandler_t sa_handler;                                                                                        
   /* Used if SA_SIGINFO is set.  */                                                                                 
   void (*sa_sigaction) (int, siginfo_t *, void *);                                                                  
      }                                                                                                               
    __sigaction_handler;                                                                                              
#define sa_handler __sigaction_handler.sa_handler                                                                    
#define sa_sigaction   __sigaction_handler.sa_sigaction                                                              
#else                                                                                                                 
    __sighandler_t sa_handler;                                                                                        
#endif                                                                                                                
                                                                                                                      
    /* Additional set of signals to be blocked.  */                                                                   
    __sigset_t sa_mask;                                                                                               
                                                                                                                      
    /* Special flags.  */                                                                                             
    int sa_flags;                                                                                                     
                                                                                                                      
    /* Restore handler.  */                                                                                           
    void (*sa_restorer) (void);                                                                                       
  };                           

but it ends up as:

    struct sigaction                                                                                                  
    {                                                                                                                 
        union _Anonymous_1                                                                                            
        {                                                                                                             
            __sighandler_t sa_handler;                                                                                
            void function(int, siginfo_t*, void*) sa_sigaction;                                                       
        }                                                                                                             
        _Anonymous_1 __sigaction_handler;                                                                             
        __sigset_t sa_mask;                                                                                           
        int sa_flags;                                                                                                 
        void function() sa_restorer;                                                                                  
    }                                                                                                                 

So, __USE_POSIX199309 ifdef is expanded (there's __sigaction__handler generated), but the inner defines are not expanded into aliases.

@nemanja-boric-sociomantic
Copy link
Author

Unrelated interesting note: sigaction(2) method is expanded into:

    pragma(mangle, "sigaction") int sigaction_(int, const(sigaction)*, sigaction*, );                                 

which makes it interestingly to call :-).

@atilaneves
Copy link
Owner

I think there's been a misunderstanding about what d++ is supposed to do. The "inner defines" aren't supposed to be translated as aliases - they get used as-is, as macros. One could use them in C program as follows:

#include <signal.h>
#include <stddef.h>

int main() {
    struct sigaction s;
    s.sa_sigaction = NULL;
}

The equivalent D program using d++ is:

#include <signal.h>

void main() {
    sigaction s;
    s.sa_sigaction = null;
}

Which compiles fine. Notice that sa_sigaction was used just the same as it was in the C program.

As for how the sigaction function gets translated, that's exactly as intended since there's a name collision with the struct of the same name. In C++ one can use struct sigaction to disambiguate, and in C it's necessary. There's no equivalent construct in D.

@nemanja-boric-sociomantic
Copy link
Author

Thank you, that makes sense, it was a misunderstanding- I was too eager to try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants