mercurial/cext/charencode.c
changeset 33926 f4433f2713d0
parent 33925 2c37f9dabc32
child 34030 e97be042fa1b
equal deleted inserted replaced
33925:2c37f9dabc32 33926:f4433f2713d0
    10 #define PY_SSIZE_T_CLEAN
    10 #define PY_SSIZE_T_CLEAN
    11 #include <Python.h>
    11 #include <Python.h>
    12 #include <assert.h>
    12 #include <assert.h>
    13 
    13 
    14 #include "charencode.h"
    14 #include "charencode.h"
       
    15 #include "compat.h"
    15 #include "util.h"
    16 #include "util.h"
    16 
    17 
    17 #ifdef IS_PY3K
    18 #ifdef IS_PY3K
    18 /* The mapping of Python types is meant to be temporary to get Python
    19 /* The mapping of Python types is meant to be temporary to get Python
    19  * 3 to compile. We should remove this once Python 3 support is fully
    20  * 3 to compile. We should remove this once Python 3 support is fully
   123 	}
   124 	}
   124 
   125 
   125 	return ret;
   126 	return ret;
   126 }
   127 }
   127 
   128 
       
   129 PyObject *isasciistr(PyObject *self, PyObject *args)
       
   130 {
       
   131 	const char *buf;
       
   132 	Py_ssize_t i, len;
       
   133 	if (!PyArg_ParseTuple(args, "s#:isasciistr", &buf, &len))
       
   134 		return NULL;
       
   135 	i = 0;
       
   136 	/* char array in PyStringObject should be at least 4-byte aligned */
       
   137 	if (((uintptr_t)buf & 3) == 0) {
       
   138 		const uint32_t *p = (const uint32_t *)buf;
       
   139 		for (; i < len / 4; i++) {
       
   140 			if (p[i] & 0x80808080U)
       
   141 				Py_RETURN_FALSE;
       
   142 		}
       
   143 		i *= 4;
       
   144 	}
       
   145 	for (; i < len; i++) {
       
   146 		if (buf[i] & 0x80)
       
   147 			Py_RETURN_FALSE;
       
   148 	}
       
   149 	Py_RETURN_TRUE;
       
   150 }
       
   151 
   128 static inline PyObject *_asciitransform(PyObject *str_obj,
   152 static inline PyObject *_asciitransform(PyObject *str_obj,
   129 					const char table[128],
   153 					const char table[128],
   130 					PyObject *fallback_fn)
   154 					PyObject *fallback_fn)
   131 {
   155 {
   132 	char *str, *newstr;
   156 	char *str, *newstr;