4545#define XXH128_BLOCKSIZE 64
4646
4747
48- /* Get a buffer from an object, or UTF-8 encode if it's a str.
49- * On success, *owner is set to the object that owns the buffer
50- * (NULL if the arg itself supports the buffer protocol).
51- * Caller must PyBuffer_Release(buf) and Py_XDECREF(*owner). */
48+ /* Get a buffer from an object. Rejects str with hashlib-compatible error. */
5249#ifndef Py_ALWAYS_INLINE
5350# define Py_ALWAYS_INLINE
5451#endif
5552
5653static Py_ALWAYS_INLINE int
5754_get_buffer_or_str (PyObject * obj , Py_buffer * buf , PyObject * * owner )
5855{
59- /* Check str first to avoid a guaranteed-failing PyObject_GetBuffer call
60- * and the resulting set/clear of a TypeError. */
6156 if (PyUnicode_Check (obj )) {
62- * owner = PyUnicode_AsUTF8String (obj );
63- if (* owner == NULL )
64- return -1 ;
65- if (PyObject_GetBuffer (* owner , buf , PyBUF_SIMPLE ) < 0 ) {
66- Py_DECREF (* owner );
67- return -1 ;
68- }
69- return 0 ;
57+ PyErr_SetString (PyExc_TypeError ,
58+ "Strings must be encoded before hashing" );
59+ return -1 ;
7060 }
7161 if (PyObject_GetBuffer (obj , buf , PyBUF_SIMPLE ) < 0 )
7262 return -1 ;
@@ -75,7 +65,7 @@ _get_buffer_or_str(PyObject *obj, Py_buffer *buf, PyObject **owner)
7565}
7666
7767/* Parse input buffer and optional seed from fastcall arguments.
78- * Handles: positional 'input ', positional 'seed', keyword 'input ',
68+ * Handles: positional 'data ', positional 'seed', keyword 'data ',
7969 * keyword 'seed', with proper error reporting for unknown keywords,
8070 * duplicate arguments, and too many positional args.
8171 * Returns 0 on success, -1 on error with exception set. */
@@ -120,10 +110,10 @@ _parse_fastcall_args(PyObject *const *args, Py_ssize_t nargs,
120110 PyObject * key = PyTuple_GET_ITEM (kwnames , i );
121111 PyObject * val = args [nargs + i ];
122112
123- if (PyUnicode_CompareWithASCIIString (key , "input " ) == 0 ) {
113+ if (PyUnicode_CompareWithASCIIString (key , "data " ) == 0 ) {
124114 if (input_found ) {
125115 PyErr_Format (PyExc_TypeError ,
126- "%s() got multiple values for argument 'input '" ,
116+ "%s() got multiple values for argument 'data '" ,
127117 funcname );
128118 goto error ;
129119 }
@@ -152,7 +142,7 @@ _parse_fastcall_args(PyObject *const *args, Py_ssize_t nargs,
152142
153143 if (!input_found && input_required ) {
154144 PyErr_Format (PyExc_TypeError ,
155- "%s() missing required argument 'input '" , funcname );
145+ "%s() missing required argument 'data '" , funcname );
156146 return -1 ;
157147 }
158148 return 0 ;
@@ -559,7 +549,7 @@ static PyObject *PYXXH32_new(PyTypeObject *type, PyObject *args, PyObject *kwarg
559549static int PYXXH32_init (PYXXH32Object * self , PyObject * args , PyObject * kwargs )
560550{
561551 XXH32_hash_t seed = 0 ;
562- char * keywords [] = {"input " , "seed" , NULL };
552+ char * keywords [] = {"data " , "seed" , NULL };
563553 Py_buffer buf ;
564554
565555 buf .buf = buf .obj = NULL ;
@@ -580,8 +570,8 @@ static int PYXXH32_init(PYXXH32Object *self, PyObject *args, PyObject *kwargs)
580570
581571PyDoc_STRVAR (
582572 PYXXH32_update_doc ,
583- "update (input )\n\n"
584- "Update the xxh32 object with the string input . Repeated calls are\n"
573+ "update (data )\n\n"
574+ "Update the xxh32 object with the string data . Repeated calls are\n"
585575 "equivalent to a single call with the concatenation of all the arguments." );
586576
587577static PyObject * PYXXH32_update (PYXXH32Object * self , PyObject * args )
@@ -768,7 +758,7 @@ PyDoc_STRVAR(
768758 "\n"
769759 "Methods:\n"
770760 "\n"
771- "update(input ) -- updates the current digest with the provided string .\n"
761+ "update(data ) -- updates the current digest with the provided data .\n"
772762 "digest() -- return the current digest value\n"
773763 "hexdigest() -- return the current digest as a string of hexadecimal digits\n"
774764 "intdigest() -- return the current digest as an integer\n"
@@ -915,7 +905,7 @@ static PyObject *PYXXH64_new(PyTypeObject *type, PyObject *args, PyObject *kwarg
915905static int PYXXH64_init (PYXXH64Object * self , PyObject * args , PyObject * kwargs )
916906{
917907 XXH64_hash_t seed = 0 ;
918- char * keywords [] = {"input " , "seed" , NULL };
908+ char * keywords [] = {"data " , "seed" , NULL };
919909 Py_buffer buf ;
920910
921911 buf .buf = buf .obj = NULL ;
@@ -936,8 +926,8 @@ static int PYXXH64_init(PYXXH64Object *self, PyObject *args, PyObject *kwargs)
936926
937927PyDoc_STRVAR (
938928 PYXXH64_update_doc ,
939- "update (input )\n\n"
940- "Update the xxh64 object with the string input . Repeated calls are\n"
929+ "update (data )\n\n"
930+ "Update the xxh64 object with the string data . Repeated calls are\n"
941931 "equivalent to a single call with the concatenation of all the arguments." );
942932
943933static PyObject * PYXXH64_update (PYXXH64Object * self , PyObject * args )
@@ -1124,7 +1114,7 @@ PyDoc_STRVAR(
11241114 "\n"
11251115 "Methods:\n"
11261116 "\n"
1127- "update(input ) -- updates the current digest with an additional string \n"
1117+ "update(data ) -- updates the current digest with additional data \n"
11281118 "digest() -- return the current digest value\n"
11291119 "hexdigest() -- return the current digest as a string of hexadecimal digits\n"
11301120 "intdigest() -- return the current digest as an integer\n"
@@ -1270,7 +1260,7 @@ static PyObject *PYXXH3_64_new(PyTypeObject *type, PyObject *args, PyObject *kwa
12701260static int PYXXH3_64_init (PYXXH3_64Object * self , PyObject * args , PyObject * kwargs )
12711261{
12721262 XXH64_hash_t seed = 0 ;
1273- char * keywords [] = {"input " , "seed" , NULL };
1263+ char * keywords [] = {"data " , "seed" , NULL };
12741264 Py_buffer buf ;
12751265
12761266 buf .buf = buf .obj = NULL ;
@@ -1291,8 +1281,8 @@ static int PYXXH3_64_init(PYXXH3_64Object *self, PyObject *args, PyObject *kwarg
12911281
12921282PyDoc_STRVAR (
12931283 PYXXH3_64_update_doc ,
1294- "update (input )\n\n"
1295- "Update the xxh3_64 object with the string input . Repeated calls are\n"
1284+ "update (data )\n\n"
1285+ "Update the xxh3_64 object with the string data . Repeated calls are\n"
12961286 "equivalent to a single call with the concatenation of all the arguments." );
12971287
12981288static PyObject * PYXXH3_64_update (PYXXH3_64Object * self , PyObject * args )
@@ -1487,7 +1477,7 @@ PyDoc_STRVAR(
14871477 "\n"
14881478 "Methods:\n"
14891479 "\n"
1490- "update(input ) -- updates the current digest with an additional string \n"
1480+ "update(data ) -- updates the current digest with additional data \n"
14911481 "digest() -- return the current digest value\n"
14921482 "hexdigest() -- return the current digest as a string of hexadecimal digits\n"
14931483 "intdigest() -- return the current digest as an integer\n"
@@ -1634,7 +1624,7 @@ static PyObject *PYXXH3_128_new(PyTypeObject *type, PyObject *args, PyObject *kw
16341624static int PYXXH3_128_init (PYXXH3_128Object * self , PyObject * args , PyObject * kwargs )
16351625{
16361626 XXH64_hash_t seed = 0 ;
1637- char * keywords [] = {"input " , "seed" , NULL };
1627+ char * keywords [] = {"data " , "seed" , NULL };
16381628 Py_buffer buf ;
16391629
16401630 buf .buf = buf .obj = NULL ;
@@ -1655,8 +1645,8 @@ static int PYXXH3_128_init(PYXXH3_128Object *self, PyObject *args, PyObject *kwa
16551645
16561646PyDoc_STRVAR (
16571647 PYXXH3_128_update_doc ,
1658- "update (input )\n\n"
1659- "Update the xxh3_128 object with the string input . Repeated calls are\n"
1648+ "update (data )\n\n"
1649+ "Update the xxh3_128 object with the string data . Repeated calls are\n"
16601650 "equivalent to a single call with the concatenation of all the arguments." );
16611651
16621652static PyObject * PYXXH3_128_update (PYXXH3_128Object * self , PyObject * args )
@@ -1868,7 +1858,7 @@ PyDoc_STRVAR(
18681858 "\n"
18691859 "Methods:\n"
18701860 "\n"
1871- "update(input ) -- updates the current digest with an additional string \n"
1861+ "update(data ) -- updates the current digest with additional data \n"
18721862 "digest() -- return the current digest value\n"
18731863 "hexdigest() -- return the current digest as a string of hexadecimal digits\n"
18741864 "intdigest() -- return the current digest as an integer\n"
0 commit comments