Skip to content

Instantly share code, notes, and snippets.

@tav
Created June 13, 2009 19:25
Show Gist options
  • Save tav/129396 to your computer and use it in GitHub Desktop.
Save tav/129396 to your computer and use it in GitHub Desktop.
diff --git a/third_party/generic/pypy/pypy/rpython/module/ll_os.py b/third_party/generic/pypy/pypy/rpython/module/ll_os.py
index ebcccf7..e7d02a1 100644
--- a/third_party/generic/pypy/pypy/rpython/module/ll_os.py
+++ b/third_party/generic/pypy/pypy/rpython/module/ll_os.py
@@ -88,10 +88,31 @@ class RegisterOs(BaseLazyRegistering):
def __init__(self):
self.configure(CConfig)
+ # on some platforms, e.g. OS X Leopard, the following constants which
+ # may be defined in pyconfig.h triggers "legacy" behaviour for functions
+ # like setpgrp():
+ #
+ # _POSIX_C_SOURCE 200112L
+ # _XOPEN_SOURCE 600
+ # _DARWIN_C_SOURCE 1
+ #
+ # since the translation currently includes pyconfig.h, the checkcompiles
+ # call below include the pyconfig.h file so that the same behaviour is
+ # present in both the check and the final translation...
+
if hasattr(os, 'getpgrp'):
- self.GETPGRP_HAVE_ARG = platform.checkcompiles("getpgrp(0)", "#include <unistd.h>")
+ self.GETPGRP_HAVE_ARG = platform.checkcompiles(
+ "getpgrp(0)",
+ '#include "pyconfig.h"\n#include <unistd.h>',
+ [platform.get_python_include_dir()]
+ )
+
if hasattr(os, 'setpgrp'):
- self.SETPGRP_HAVE_ARG = platform.checkcompiles("setpgrp(0,0)", "#include <unistd.h>")
+ self.SETPGRP_HAVE_ARG = platform.checkcompiles(
+ "setpgrp(0,0)",
+ '#include "pyconfig.h"\n#include <unistd.h>',
+ [platform.get_python_include_dir()]
+ )
# we need an indirection via c functions to get macro calls working on llvm XXX still?
if hasattr(os, 'WCOREDUMP'):
diff --git a/third_party/generic/pypy/pypy/rpython/tool/rffi_platform.py b/third_party/generic/pypy/pypy/rpython/tool/rffi_platform.py
index 3c383e4..aa4620a 100755
--- a/third_party/generic/pypy/pypy/rpython/tool/rffi_platform.py
+++ b/third_party/generic/pypy/pypy/rpython/tool/rffi_platform.py
@@ -14,9 +14,10 @@ import distutils
#
# Helpers for simple cases
-def eci_from_header(c_header_source):
+def eci_from_header(c_header_source, include_dirs=[]):
return ExternalCompilationInfo(
- pre_include_bits=[c_header_source]
+ pre_include_bits=[c_header_source],
+ include_dirs=include_dirs
)
def getstruct(name, c_header_source, interesting_fields):
@@ -43,9 +44,9 @@ def getdefined(macro, c_header_source):
DEFINED = Defined(macro)
return configure(CConfig)['DEFINED']
-def has(name, c_header_source):
+def has(name, c_header_source, include_dirs=[]):
class CConfig:
- _compilation_info_ = eci_from_header(c_header_source)
+ _compilation_info_ = eci_from_header(c_header_source, include_dirs)
HAS = Has(name)
return configure(CConfig)['HAS']
@@ -57,9 +58,9 @@ def verify_eci(eci):
WORKS = Works()
configure(CConfig)
-def checkcompiles(expression, c_header_source):
+def checkcompiles(expression, c_header_source, include_dirs=[]):
"""Check if expression compiles. If not, returns False"""
- return has(expression, c_header_source)
+ return has(expression, c_header_source, include_dirs)
def sizeof(name, eci, **kwds):
class CConfig:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment