Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 862eece

Browse files
Merge pull request h5py#2482 from neutrinoceros/rfc/platform_dependent_code
2 parents 325d5da + a59d0b3 commit 862eece

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

h5py/api_types_ext.pxd

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ from libc.time cimport time_t
2222

2323
from libc.stdint cimport int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t
2424

25-
IF UNAME_SYSNAME != "Windows":
26-
cdef extern from "unistd.h":
27-
ctypedef long ssize_t
28-
ELSE:
25+
cdef extern from *:
26+
"""
27+
#if !(defined(_WIN32) || defined(MS_WINDOWS) || defined(_MSC_VER))
28+
#include <unistd.h>
29+
#endif
30+
"""
2931
ctypedef long ssize_t
3032

3133
# Can't use Cython defs because they keep moving them around

h5py/h5g.pyx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
include "config.pxi"
1616

17+
import sys
18+
1719
# C-level imports
1820
from ._objects cimport pdefault
1921
from .utils cimport emalloc, efree
@@ -25,6 +27,9 @@ from ._errors cimport set_error_handler, err_cookie
2527
# Python level imports
2628
from ._objects import phil, with_phil
2729

30+
31+
_IS_WINDOWS = sys.platform.startswith("win")
32+
2833
# === Public constants and data structures ====================================
2934

3035
# Enumerated object types for groups "H5G_obj_t"
@@ -389,9 +394,9 @@ cdef class GroupID(ObjectID):
389394
if statbuf.type != H5G_LINK:
390395
raise ValueError('"%s" is not a symbolic link.' % name)
391396

392-
IF UNAME_SYSNAME == "Windows":
397+
if _IS_WINDOWS:
393398
linklen = 2049 # Windows statbuf.linklen seems broken
394-
ELSE:
399+
else:
395400
linklen = statbuf.linklen+1
396401
value = <char*>emalloc(sizeof(char)*linklen)
397402
try:

h5py/h5t.pyx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,23 @@ from .utils cimport emalloc, efree, require_tuple, convert_dims,\
2828

2929
# Python imports
3030
import codecs
31+
import os
3132
import sys
3233
from collections import namedtuple
33-
import sys
3434
import numpy as np
3535
from .h5 import get_config
3636

3737
from ._objects import phil, with_phil
3838

3939
cfg = get_config()
4040

41-
DEF MACHINE = UNAME_MACHINE # processor architecture, provided by Cython
41+
if sys.platform.startswith("win"):
42+
_IS_PPC64 = False
43+
_IS_PPC64LE = False
44+
else:
45+
_IS_PPC64 = os.uname() == "ppc64"
46+
_IS_PPC64LE = os.uname() == "ppc64le"
47+
4248
cdef char* H5PY_PYTHON_OPAQUE_TAG = "PYTHON:OBJECT"
4349

4450
# === Custom C API ============================================================
@@ -291,12 +297,12 @@ cdef (int, int, int) _correct_float_info(ftype_, finfo):
291297
maxexp = finfo.maxexp
292298
minexp = finfo.minexp
293299
# workaround for numpy's buggy finfo on float128 on ppc64 archs
294-
if ftype_ == np.longdouble and MACHINE == 'ppc64':
300+
if ftype_ == np.longdouble and _IS_PPC64:
295301
# values reported by hdf5
296302
nmant = 116
297303
maxexp = 1024
298304
minexp = -1022
299-
elif ftype_ == np.longdouble and MACHINE == 'ppc64le':
305+
elif ftype_ == np.longdouble and _IS_PPC64LE:
300306
# values reported by hdf5
301307
nmant = 52
302308
maxexp = 1024

0 commit comments

Comments
 (0)