on master help sign in
Drop a magic number
commit36e23b5bc96f0f681f7714a9fdb14cc59a4d4005 authorBryan O'Sullivan <bos@serpentine.com> dateSun 22 Sep 2013, 14:19 (13 years ago) parent3861303
4 files changed+19−3
Data/Text/Encoding.hs+4−2 cbits/cbits.c+1 include/text_cbits.h+11 text.cabal+3−1
Data/Text/Encoding.hs+4−2
@@ -83,6 +83,8 @@ import qualified Data.Text.Encoding.Utf16 as U16
8383import qualified Data.Text.Fusion as F
8484import Data.Text.Unsafe (unsafeDupablePerformIO)
8585
86+#include "text_cbits.h"
87+
8688-- $strict
8789--
8890-- All of the single-parameter functions for decoding bytestrings
@@ -169,7 +171,7 @@ decodeUtf8With' onErr = decodeChunk (0,0)
169171 codepointPtr statePtr
170172 state <- peek statePtr
171173 case state of
172− 12 -> do
174+ UTF8_REJECT -> do
173175 -- We encountered an encoding error
174176 x <- peek curPtr'
175177 case onErr desc (Just x) of
@@ -181,7 +183,7 @@ decodeUtf8With' onErr = decodeChunk (0,0)
181183 poke destOffPtr (destOff + fromIntegral w)
182184 poke statePtr 0
183185 loop $ curPtr' `plusPtr` 1
184−
186+
185187 _ -> do
186188 -- We encountered the end of the buffer while decoding
187189 n <- peek destOffPtr
cbits/cbits.c+1
@@ -9,6 +9,7 @@
99#include <string.h>
1010#include <stdint.h>
1111#include <stdio.h>
12+#include "text_cbits.h"
1213
1314void _hs_text_memcpy(void *dest, size_t doff, const void *src, size_t soff,
1415 size_t n)
include/text_cbits.hnew file+11
@@ -0,0 +1,11 @@
1+/*
2+ * Copyright (c) 2013 Bryan O'Sullivan <bos@serpentine.com>.
3+ */
4+
5+#ifndef _text_cbits_h
6+#define _text_cbits_h
7+
8+#define UTF8_ACCEPT 0
9+#define UTF8_REJECT 12
10+
11+#endif
text.cabal+3−1
@@ -77,7 +77,8 @@ flag integer-simple
7777 default: False
7878
7979library
80− c-sources: cbits/cbits.c
80+ c-sources: cbits/cbits.c
81+ include-dirs: include
8182
8283 exposed-modules:
8384 Data.Text
@@ -160,6 +161,7 @@ test-suite tests
160161 hs-source-dirs: tests .
161162 main-is: Tests.hs
162163 c-sources: cbits/cbits.c
164+ include-dirs: include
163165
164166 ghc-options:
165167 -Wall -threaded -O0 -rtsopts