Thread overview
core.sys.posix.setjmp unavailable for OS X?
Jan 15, 2018
bpr
Jan 15, 2018
H. S. Teoh
Jan 16, 2018
Jacob Carlborg
Jan 16, 2018
Jacob Carlborg
Jan 16, 2018
H. S. Teoh
January 15, 2018
Is there a reason that it's unavailable on OS X when it works fine on Linux? The functions exist on OS X, and it's easy enough to compile C programs using setjmp there; but not D programs. I don't think I'm getting a betterC experience on the Mac.

I'd also ask why the there are no D docs for core.sys.posix but I read the responses to the last time the question was asked and now I'm D-pressed. :-(
January 15, 2018
On Mon, Jan 15, 2018 at 07:06:42PM +0000, bpr via Digitalmars-d-learn wrote:
> Is there a reason that it's unavailable on OS X when it works fine on Linux?  The functions exist on OS X, and it's easy enough to compile C programs using setjmp there; but not D programs. I don't think I'm getting a betterC experience on the Mac.
[...]

It's probably just a matter of adding the appropriate prototypes / declarations to druntime. Provided that they actually work as advertised, of course. There may be incompatibilities that I'm not aware of that would preclude it from being added to druntime.

In any case, if druntime doesn't provide the right declarations, you *could* just declare them yourself with an extern(C). E.g.:

	extern(C) int setjmp(jmp_buf env);
	extern(C) void longjmp(jmp_buf env, int val);
	...
	jmp_buf buf;
	int rc = setjmp(buf);
	if (rc == 0) {
		...
		longjmp(buf, rc);
	} else {
		// handle error
	}

You'll need to obtain your system's definition of jmp_buf, of course, and translate it into D appropriately. You can find it in the usual system include directories, like /usr/include or something along those lines.  Most C structs can be copied verbatim into D and it would work.

(Note that you'll need to find the *exact* declaration used; especially for structs, you may not be able to just use generic declarations given by the Posix spec, because if your OS has additional fields for internal use, you want to make sure those fields are declared properly, otherwise the struct will have the wrong size and you may get problems at runtime.)

Better yet, once you figure out how to do it, submit a PR against druntime so that future users of your OS will benefit from it. ;-)


T

-- 
A program should be written to model the concepts of the task it performs rather than the physical world or a process because this maximizes the potential for it to be applied to tasks that are conceptually similar and, more important, to tasks that have not yet been conceived. -- Michael B. Allen
January 15, 2018
On Tue, Jan 16, 2018 at 08:29:57AM +0100, Jacob Carlborg via Digitalmars-d-learn wrote:
> On 2018-01-16 08:29, Jacob Carlborg wrote:
> 
> > They're used to implement Objective-C exceptions on macOS 32bit and iOS.
> 
> Forgot the second part:
> 
> ... so I assume that means it works.
[...]

So we should add that to druntime, then.


T

-- 
MSDOS = MicroSoft's Denial Of Service
January 16, 2018
On 2018-01-15 20:37, H. S. Teoh wrote:

> It's probably just a matter of adding the appropriate prototypes /
> declarations to druntime. Provided that they actually work as
> advertised, of course.

They're used to implement Objective-C exceptions on macOS 32bit and iOS.

-- 
/Jacob Carlborg
January 16, 2018
On 2018-01-16 08:29, Jacob Carlborg wrote:

> They're used to implement Objective-C exceptions on macOS 32bit and iOS.

Forgot the second part:

... so I assume that means it works.

-- 
/Jacob Carlborg