Re: Need help implementing a machine dependent function

Jon Leighton <[email protected]> Mon, 25 May 2009 03:25:58 -0400
Newsgroups gmane.comp.mozilla.devel.nspr
Message-ID <[email protected]>
Nelson Bolyard wrote:
> Jonathan Leighton wrote, On 2009-05-20 22:17:
>> I'm trying to add a machine dependent function to NSPR, but I'm having 
>> some trouble understanding how the existing code translates from a 
>> function like _PR_MD_FUNCTION() to the platform specific function 
>> _MD_function().  In my case I'm using a function called 
>> _PR_MD_SCTP_RECVMSG() in pr/src/pthreads/ptio.c and I want that to 
>> translate to different MD_sctp_recvmsg() functions defined in the various
>> pr/src/md files.  For example, on Solaris I'd expect 
>> _PR_MD_SCTP_RECVMSG() to use the _MD_sctp_recvmsg() that I've added to 
>> pr/src/md/unix/solaris.c.
>>
>> I've tried to mimic the existing approach using several #define's and 
>> extern function prototypes in various files, but I haven't been able to 
>> make it work. 
> 
> Why not?  In what manner does it fail?
> We can't help you solve the problem if you don't describe it.

Thanks for responding Nelson, and sorry I didn't provide more detail. 
If I look at how _PR_MD_ACCEPT is implemented I see

in file primpl.h
extern PROsfd _PR_MD_ACCCEPT(...);
#define  _PR_MD_ACCEPT     _MD_ACCEPT

in file _win95.h
extern PROsfd _MD_Accept(...);
#define  _MD_ACCEPT     _MD_Accept

in file wsock95.c
PROsfd  _MD_Accept(...) {...}

I tried to mimic this in Mac OS X with _PR_MD_SCTP_RECVMSG by adding the 
following

in file primpl.h
extern PRInt32 _PR_MD_SCTP_RECVMSG(...);
#define  _PR_MD_SCTP_RECVMSG     _MD_SCTP_RECVMSG

in file _darwin.h
extern PRInt32 _MD_Sctp_Recvmsg(...);
#define  _MD_SCTP_RECVMSG     _MD_Sctp_Recvmsg

in file darwin.c
PRInt32 _MD_Sctp_Recvmsg(...) {...}

When I try to build I end up with a warning about an implicit definition 
of _PR_MD_SCTP_RECVMSG in ptio.c (where I call the function), and the 
build fails on nspr.dylib stating that _PR_MD_SCTP_RECV is an undefined 
symbol.  I can include the compiler output if that would be helpful.

- Jon


> 
>> As a fallback, I've simply specified an extern function prototype for
>> _PR_MD_SCTP_RECVMSG() in pr/include/private/primpl.h and then defined
>> _PR_MD_SCTP_RECVMSG() as extern in the various pr/src/md files such as
>> solaris.c.  This works but it doesn't seem like the "right" way to do it.
> 
> You're right.  It's not.
> 
>> I'd be grateful for any help explaining how to do this correctly.  Thanks
>> very much.
>>
>> - Jon
>