summaryrefslogtreecommitdiffstats
path: root/debian/patches/big_endian.patch
blob: c413860f98c712c02c7a3d50a9423c1f20b7bc5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Author: Michael R. Crusoe <crusoe@debian.org>, Julian Gilbey <jdg@debian.org>
Description: Default to pure python parsing on big endian systems
 The current version fails on big-endian systems as described in
 https://sourceforge.net/p/ruamel-yaml/tickets/360/ and
 https://sourceforge.net/p/ruamel-yaml-clib/tickets/34/
 .
 The current version of this patch completely disables the C extension on
 big-endian systems.
 .
 Thanks to Rebecca N. Palmer for the tip about sys.byteorder!
Forwarded: not-needed
Last-Update: 2024-04-18

--- a/__init__.py
+++ b/__init__.py
@@ -1,5 +1,6 @@
 
 from __future__ import annotations
+import sys
 
 if False:  # MYPY
     from typing import Dict, Any  # NOQA
@@ -47,11 +48,13 @@
 version_info = _package_data['version_info']
 __version__ = _package_data['__version__']
 
-try:
-    from .cyaml import *  # NOQA
-
-    __with_libyaml__ = True
-except (ImportError, ValueError):  # for Jython
-    __with_libyaml__ = False
+__with_libyaml__ = False
+if sys.byteorder == "little":
+    try:
+        from .cyaml import *  # NOQA
+
+        __with_libyaml__ = True
+    except (ImportError, ValueError):  # for Jython
+        pass
 
 from ruamel.yaml.main import *  # NOQA
--- a/_test/test_cyaml.py
+++ b/_test/test_cyaml.py
@@ -7,6 +7,10 @@
 
 NO_CLIB_VER = (3, 12)
 
+pytestmark = pytest.mark.skipif(
+    sys.byteorder == "big",
+    reason="compiled library disabled on big-endian machines"
+)
 
 @pytest.mark.skipif(  # type: ignore
     platform.python_implementation() in ['Jython', 'PyPy'],
--- a/main.py
+++ b/main.py
@@ -41,10 +41,12 @@
     from types import TracebackType
     from pathlib import Path
 
-try:
-    from _ruamel_yaml import CParser, CEmitter  # type: ignore
-except:  # NOQA
-    CParser = CEmitter = None
+CParser = CEmitter = None
+if sys.byteorder == "little":
+    try:
+        from _ruamel_yaml import CParser, CEmitter  # type: ignore
+    except:  # NOQA
+        pass
 
 # import io