summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/genapi.py48
-rw-r--r--numpy/core/code_generators/generate_numpy_api.py26
-rw-r--r--numpy/core/code_generators/generate_ufunc_api.py10
-rw-r--r--numpy/core/code_generators/numpy_api.py695
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h4
-rw-r--r--numpy/core/include/numpy/npy_common.h24
-rw-r--r--numpy/core/setup.py5
-rw-r--r--numpy/core/setup_common.py2
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c2
-rw-r--r--numpy/core/src/multiarray/ctors.c6
-rw-r--r--numpy/core/src/multiarray/methods.c3
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c2
-rw-r--r--numpy/core/src/multiarray/scalarapi.c5
-rw-r--r--numpy/distutils/command/config.py5
14 files changed, 449 insertions, 388 deletions
diff --git a/numpy/core/code_generators/genapi.py b/numpy/core/code_generators/genapi.py
index ad054920a..c73209d04 100644
--- a/numpy/core/code_generators/genapi.py
+++ b/numpy/core/code_generators/genapi.py
@@ -74,6 +74,29 @@ def remove_whitespace(s):
def _repl(str):
return str.replace('Bool', 'npy_bool')
+
+class StealRef:
+ def __init__(self, arg):
+ self.arg = arg # counting from 1
+
+ def __str__(self):
+ try:
+ return ' '.join('NPY_STEALS_REF_TO_ARG(%d)' % x for x in self.arg)
+ except TypeError:
+ return 'NPY_STEALS_REF_TO_ARG(%d)' % self.arg
+
+
+class NonNull:
+ def __init__(self, arg):
+ self.arg = arg # counting from 1
+
+ def __str__(self):
+ try:
+ return ' '.join('NPY_GCC_NONNULL(%d)' % x for x in self.arg)
+ except TypeError:
+ return 'NPY_GCC_NONNULL(%d)' % self.arg
+
+
class Function(object):
def __init__(self, name, return_type, args, doc=''):
self.name = name
@@ -350,9 +373,10 @@ NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
return astr
class FunctionApi(object):
- def __init__(self, name, index, return_type, args, api_name):
+ def __init__(self, name, index, annotations, return_type, args, api_name):
self.name = name
self.index = index
+ self.annotations = annotations
self.return_type = return_type
self.args = args
self.api_name = api_name
@@ -377,17 +401,21 @@ class FunctionApi(object):
return " (void *) %s" % self.name
def internal_define(self):
+ annstr = []
+ for a in self.annotations:
+ annstr.append(str(a))
+ annstr = ' '.join(annstr)
astr = """\
-NPY_NO_EXPORT %s %s \\\n (%s);""" % (self.return_type,
- self.name,
- self._argtypes_string())
+NPY_NO_EXPORT %s %s %s \\\n (%s);""" % (annstr, self.return_type,
+ self.name,
+ self._argtypes_string())
return astr
def order_dict(d):
"""Order dict by its values."""
o = list(d.items())
def _key(x):
- return (x[1], x[0])
+ return x[1] + (x[0],)
return sorted(o, key=_key)
def merge_api_dicts(dicts):
@@ -419,7 +447,7 @@ Same index has been used twice in api definition: %s
raise ValueError(msg)
# No 'hole' in the indexes may be allowed, and it must starts at 0
- indexes = set(d.values())
+ indexes = set(v[0] for v in d.values())
expected = set(range(len(indexes)))
if not indexes == expected:
diff = expected.symmetric_difference(indexes)
@@ -434,7 +462,7 @@ def get_api_functions(tagname, api_dict):
functions.extend(find_functions(f, tagname))
dfunctions = []
for func in functions:
- o = api_dict[func.name]
+ o = api_dict[func.name][0]
dfunctions.append( (o, func) )
dfunctions.sort()
return [a[1] for a in dfunctions]
@@ -444,11 +472,7 @@ def fullapi_hash(api_dicts):
of the list of items in the API (as a string)."""
a = []
for d in api_dicts:
- def sorted_by_values(d):
- """Sort a dictionary by its values. Assume the dictionary items is of
- the form func_name -> order"""
- return sorted(d.items(), key=lambda x_y: (x_y[1], x_y[0]))
- for name, index in sorted_by_values(d):
+ for name, index in order_dict(d):
a.extend(name)
a.extend(str(index))
diff --git a/numpy/core/code_generators/generate_numpy_api.py b/numpy/core/code_generators/generate_numpy_api.py
index ce270a6a0..a590cfb48 100644
--- a/numpy/core/code_generators/generate_numpy_api.py
+++ b/numpy/core/code_generators/generate_numpy_api.py
@@ -183,13 +183,11 @@ def do_generate_api(targets, sources):
doc_file = targets[2]
global_vars = sources[0]
- global_vars_types = sources[1]
- scalar_bool_values = sources[2]
- types_api = sources[3]
- multiarray_funcs = sources[4]
+ scalar_bool_values = sources[1]
+ types_api = sources[2]
+ multiarray_funcs = sources[3]
- # Remove global_vars_type: not a api dict
- multiarray_api = sources[:1] + sources[2:]
+ multiarray_api = sources[:]
module_list = []
extension_list = []
@@ -208,18 +206,22 @@ def do_generate_api(targets, sources):
multiarray_api_dict = {}
for f in numpyapi_list:
name = f.name
- index = multiarray_funcs[name]
- multiarray_api_dict[f.name] = FunctionApi(f.name, index, f.return_type,
+ index = multiarray_funcs[name][0]
+ annotations = multiarray_funcs[name][1:]
+ multiarray_api_dict[f.name] = FunctionApi(f.name, index, annotations,
+ f.return_type,
f.args, api_name)
- for name, index in global_vars.items():
- type = global_vars_types[name]
+ for name, val in global_vars.items():
+ index, type = val
multiarray_api_dict[name] = GlobalVarApi(name, index, type, api_name)
- for name, index in scalar_bool_values.items():
+ for name, val in scalar_bool_values.items():
+ index = val[0]
multiarray_api_dict[name] = BoolValuesApi(name, index, api_name)
- for name, index in types_api.items():
+ for name, val in types_api.items():
+ index = val[0]
multiarray_api_dict[name] = TypeApi(name, index, 'PyTypeObject', api_name)
if len(multiarray_api_dict) != len(multiarray_api_index):
diff --git a/numpy/core/code_generators/generate_ufunc_api.py b/numpy/core/code_generators/generate_ufunc_api.py
index 6305385af..b594fccf7 100644
--- a/numpy/core/code_generators/generate_ufunc_api.py
+++ b/numpy/core/code_generators/generate_ufunc_api.py
@@ -172,11 +172,13 @@ def do_generate_api(targets, sources):
api_name = 'PyUFunc_API'
for f in ufunc_api_list:
name = f.name
- index = ufunc_api_index[name]
- ufunc_api_dict[name] = FunctionApi(f.name, index, f.return_type,
- f.args, api_name)
+ index = ufunc_api_index[name][0]
+ annotations = ufunc_api_index[name][1:]
+ ufunc_api_dict[name] = FunctionApi(f.name, index, annotations,
+ f.return_type, f.args, api_name)
- for name, index in numpy_api.ufunc_types_api.items():
+ for name, val in numpy_api.ufunc_types_api.items():
+ index = val[0]
ufunc_api_dict[name] = TypeApi(name, index, 'PyTypeObject', api_name)
# set up object API
diff --git a/numpy/core/code_generators/numpy_api.py b/numpy/core/code_generators/numpy_api.py
index 791bc6ffc..cd6d2f176 100644
--- a/numpy/core/code_generators/numpy_api.py
+++ b/numpy/core/code_generators/numpy_api.py
@@ -14,64 +14,64 @@ exception, so it should hopefully not get unnoticed).
"""
from __future__ import division, absolute_import, print_function
-multiarray_global_vars = {
- 'NPY_NUMUSERTYPES': 7,
- 'NPY_DEFAULT_ASSIGN_CASTING': 292,
-}
+from code_generators.genapi import StealRef, NonNull
-multiarray_global_vars_types = {
- 'NPY_NUMUSERTYPES': 'int',
- 'NPY_DEFAULT_ASSIGN_CASTING': 'NPY_CASTING',
+# index, type
+multiarray_global_vars = {
+ 'NPY_NUMUSERTYPES': (7, 'int'),
+ 'NPY_DEFAULT_ASSIGN_CASTING': (292, 'NPY_CASTING'),
}
multiarray_scalar_bool_values = {
- '_PyArrayScalar_BoolValues': 9
+ '_PyArrayScalar_BoolValues': (9,)
}
+# index, annotations
+# please mark functions that have been checked to not need any annotations
multiarray_types_api = {
- 'PyBigArray_Type': 1,
- 'PyArray_Type': 2,
- 'PyArrayDescr_Type': 3,
- 'PyArrayFlags_Type': 4,
- 'PyArrayIter_Type': 5,
- 'PyArrayMultiIter_Type': 6,
- 'PyBoolArrType_Type': 8,
- 'PyGenericArrType_Type': 10,
- 'PyNumberArrType_Type': 11,
- 'PyIntegerArrType_Type': 12,
- 'PySignedIntegerArrType_Type': 13,
- 'PyUnsignedIntegerArrType_Type': 14,
- 'PyInexactArrType_Type': 15,
- 'PyFloatingArrType_Type': 16,
- 'PyComplexFloatingArrType_Type': 17,
- 'PyFlexibleArrType_Type': 18,
- 'PyCharacterArrType_Type': 19,
- 'PyByteArrType_Type': 20,
- 'PyShortArrType_Type': 21,
- 'PyIntArrType_Type': 22,
- 'PyLongArrType_Type': 23,
- 'PyLongLongArrType_Type': 24,
- 'PyUByteArrType_Type': 25,
- 'PyUShortArrType_Type': 26,
- 'PyUIntArrType_Type': 27,
- 'PyULongArrType_Type': 28,
- 'PyULongLongArrType_Type': 29,
- 'PyFloatArrType_Type': 30,
- 'PyDoubleArrType_Type': 31,
- 'PyLongDoubleArrType_Type': 32,
- 'PyCFloatArrType_Type': 33,
- 'PyCDoubleArrType_Type': 34,
- 'PyCLongDoubleArrType_Type': 35,
- 'PyObjectArrType_Type': 36,
- 'PyStringArrType_Type': 37,
- 'PyUnicodeArrType_Type': 38,
- 'PyVoidArrType_Type': 39,
+ 'PyBigArray_Type': (1,),
+ 'PyArray_Type': (2,),
+ 'PyArrayDescr_Type': (3,),
+ 'PyArrayFlags_Type': (4,),
+ 'PyArrayIter_Type': (5,),
+ 'PyArrayMultiIter_Type': (6,),
+ 'PyBoolArrType_Type': (8,),
+ 'PyGenericArrType_Type': (10,),
+ 'PyNumberArrType_Type': (11,),
+ 'PyIntegerArrType_Type': (12,),
+ 'PySignedIntegerArrType_Type': (13,),
+ 'PyUnsignedIntegerArrType_Type': (14,),
+ 'PyInexactArrType_Type': (15,),
+ 'PyFloatingArrType_Type': (16,),
+ 'PyComplexFloatingArrType_Type': (17,),
+ 'PyFlexibleArrType_Type': (18,),
+ 'PyCharacterArrType_Type': (19,),
+ 'PyByteArrType_Type': (20,),
+ 'PyShortArrType_Type': (21,),
+ 'PyIntArrType_Type': (22,),
+ 'PyLongArrType_Type': (23,),
+ 'PyLongLongArrType_Type': (24,),
+ 'PyUByteArrType_Type': (25,),
+ 'PyUShortArrType_Type': (26,),
+ 'PyUIntArrType_Type': (27,),
+ 'PyULongArrType_Type': (28,),
+ 'PyULongLongArrType_Type': (29,),
+ 'PyFloatArrType_Type': (30,),
+ 'PyDoubleArrType_Type': (31,),
+ 'PyLongDoubleArrType_Type': (32,),
+ 'PyCFloatArrType_Type': (33,),
+ 'PyCDoubleArrType_Type': (34,),
+ 'PyCLongDoubleArrType_Type': (35,),
+ 'PyObjectArrType_Type': (36,),
+ 'PyStringArrType_Type': (37,),
+ 'PyUnicodeArrType_Type': (38,),
+ 'PyVoidArrType_Type': (39,),
# End 1.5 API
- 'PyTimeIntegerArrType_Type': 214,
- 'PyDatetimeArrType_Type': 215,
- 'PyTimedeltaArrType_Type': 216,
- 'PyHalfArrType_Type': 217,
- 'NpyIter_Type': 218,
+ 'PyTimeIntegerArrType_Type': (214,),
+ 'PyDatetimeArrType_Type': (215,),
+ 'PyTimedeltaArrType_Type': (216,),
+ 'PyHalfArrType_Type': (217,),
+ 'NpyIter_Type': (218,),
# End 1.6 API
}
@@ -80,318 +80,318 @@ multiarray_types_api = {
#define _PyArrayScalar_BoolValues ((PyBoolScalarObject *)PyArray_API[8])
multiarray_funcs_api = {
- 'PyArray_GetNDArrayCVersion': 0,
- 'PyArray_SetNumericOps': 40,
- 'PyArray_GetNumericOps': 41,
- 'PyArray_INCREF': 42,
- 'PyArray_XDECREF': 43,
- 'PyArray_SetStringFunction': 44,
- 'PyArray_DescrFromType': 45,
- 'PyArray_TypeObjectFromType': 46,
- 'PyArray_Zero': 47,
- 'PyArray_One': 48,
- 'PyArray_CastToType': 49,
- 'PyArray_CastTo': 50,
- 'PyArray_CastAnyTo': 51,
- 'PyArray_CanCastSafely': 52,
- 'PyArray_CanCastTo': 53,
- 'PyArray_ObjectType': 54,
- 'PyArray_DescrFromObject': 55,
- 'PyArray_ConvertToCommonType': 56,
- 'PyArray_DescrFromScalar': 57,
- 'PyArray_DescrFromTypeObject': 58,
- 'PyArray_Size': 59,
- 'PyArray_Scalar': 60,
- 'PyArray_FromScalar': 61,
- 'PyArray_ScalarAsCtype': 62,
- 'PyArray_CastScalarToCtype': 63,
- 'PyArray_CastScalarDirect': 64,
- 'PyArray_ScalarFromObject': 65,
- 'PyArray_GetCastFunc': 66,
- 'PyArray_FromDims': 67,
- 'PyArray_FromDimsAndDataAndDescr': 68,
- 'PyArray_FromAny': 69,
- 'PyArray_EnsureArray': 70,
- 'PyArray_EnsureAnyArray': 71,
- 'PyArray_FromFile': 72,
- 'PyArray_FromString': 73,
- 'PyArray_FromBuffer': 74,
- 'PyArray_FromIter': 75,
- 'PyArray_Return': 76,
- 'PyArray_GetField': 77,
- 'PyArray_SetField': 78,
- 'PyArray_Byteswap': 79,
- 'PyArray_Resize': 80,
- 'PyArray_MoveInto': 81,
- 'PyArray_CopyInto': 82,
- 'PyArray_CopyAnyInto': 83,
- 'PyArray_CopyObject': 84,
- 'PyArray_NewCopy': 85,
- 'PyArray_ToList': 86,
- 'PyArray_ToString': 87,
- 'PyArray_ToFile': 88,
- 'PyArray_Dump': 89,
- 'PyArray_Dumps': 90,
- 'PyArray_ValidType': 91,
- 'PyArray_UpdateFlags': 92,
- 'PyArray_New': 93,
- 'PyArray_NewFromDescr': 94,
- 'PyArray_DescrNew': 95,
- 'PyArray_DescrNewFromType': 96,
- 'PyArray_GetPriority': 97,
- 'PyArray_IterNew': 98,
- 'PyArray_MultiIterNew': 99,
- 'PyArray_PyIntAsInt': 100,
- 'PyArray_PyIntAsIntp': 101,
- 'PyArray_Broadcast': 102,
- 'PyArray_FillObjectArray': 103,
- 'PyArray_FillWithScalar': 104,
- 'PyArray_CheckStrides': 105,
- 'PyArray_DescrNewByteorder': 106,
- 'PyArray_IterAllButAxis': 107,
- 'PyArray_CheckFromAny': 108,
- 'PyArray_FromArray': 109,
- 'PyArray_FromInterface': 110,
- 'PyArray_FromStructInterface': 111,
- 'PyArray_FromArrayAttr': 112,
- 'PyArray_ScalarKind': 113,
- 'PyArray_CanCoerceScalar': 114,
- 'PyArray_NewFlagsObject': 115,
- 'PyArray_CanCastScalar': 116,
- 'PyArray_CompareUCS4': 117,
- 'PyArray_RemoveSmallest': 118,
- 'PyArray_ElementStrides': 119,
- 'PyArray_Item_INCREF': 120,
- 'PyArray_Item_XDECREF': 121,
- 'PyArray_FieldNames': 122,
- 'PyArray_Transpose': 123,
- 'PyArray_TakeFrom': 124,
- 'PyArray_PutTo': 125,
- 'PyArray_PutMask': 126,
- 'PyArray_Repeat': 127,
- 'PyArray_Choose': 128,
- 'PyArray_Sort': 129,
- 'PyArray_ArgSort': 130,
- 'PyArray_SearchSorted': 131,
- 'PyArray_ArgMax': 132,
- 'PyArray_ArgMin': 133,
- 'PyArray_Reshape': 134,
- 'PyArray_Newshape': 135,
- 'PyArray_Squeeze': 136,
- 'PyArray_View': 137,
- 'PyArray_SwapAxes': 138,
- 'PyArray_Max': 139,
- 'PyArray_Min': 140,
- 'PyArray_Ptp': 141,
- 'PyArray_Mean': 142,
- 'PyArray_Trace': 143,
- 'PyArray_Diagonal': 144,
- 'PyArray_Clip': 145,
- 'PyArray_Conjugate': 146,
- 'PyArray_Nonzero': 147,
- 'PyArray_Std': 148,
- 'PyArray_Sum': 149,
- 'PyArray_CumSum': 150,
- 'PyArray_Prod': 151,
- 'PyArray_CumProd': 152,
- 'PyArray_All': 153,
- 'PyArray_Any': 154,
- 'PyArray_Compress': 155,
- 'PyArray_Flatten': 156,
- 'PyArray_Ravel': 157,
- 'PyArray_MultiplyList': 158,
- 'PyArray_MultiplyIntList': 159,
- 'PyArray_GetPtr': 160,
- 'PyArray_CompareLists': 161,
- 'PyArray_AsCArray': 162,
- 'PyArray_As1D': 163,
- 'PyArray_As2D': 164,
- 'PyArray_Free': 165,
- 'PyArray_Converter': 166,
- 'PyArray_IntpFromSequence': 167,
- 'PyArray_Concatenate': 168,
- 'PyArray_InnerProduct': 169,
- 'PyArray_MatrixProduct': 170,
- 'PyArray_CopyAndTranspose': 171,
- 'PyArray_Correlate': 172,
- 'PyArray_TypestrConvert': 173,
- 'PyArray_DescrConverter': 174,
- 'PyArray_DescrConverter2': 175,
- 'PyArray_IntpConverter': 176,
- 'PyArray_BufferConverter': 177,
- 'PyArray_AxisConverter': 178,
- 'PyArray_BoolConverter': 179,
- 'PyArray_ByteorderConverter': 180,
- 'PyArray_OrderConverter': 181,
- 'PyArray_EquivTypes': 182,
- 'PyArray_Zeros': 183,
- 'PyArray_Empty': 184,
- 'PyArray_Where': 185,
- 'PyArray_Arange': 186,
- 'PyArray_ArangeObj': 187,
- 'PyArray_SortkindConverter': 188,
- 'PyArray_LexSort': 189,
- 'PyArray_Round': 190,
- 'PyArray_EquivTypenums': 191,
- 'PyArray_RegisterDataType': 192,
- 'PyArray_RegisterCastFunc': 193,
- 'PyArray_RegisterCanCast': 194,
- 'PyArray_InitArrFuncs': 195,
- 'PyArray_IntTupleFromIntp': 196,
- 'PyArray_TypeNumFromName': 197,
- 'PyArray_ClipmodeConverter': 198,
- 'PyArray_OutputConverter': 199,
- 'PyArray_BroadcastToShape': 200,
- '_PyArray_SigintHandler': 201,
- '_PyArray_GetSigintBuf': 202,
- 'PyArray_DescrAlignConverter': 203,
- 'PyArray_DescrAlignConverter2': 204,
- 'PyArray_SearchsideConverter': 205,
- 'PyArray_CheckAxis': 206,
- 'PyArray_OverflowMultiplyList': 207,
- 'PyArray_CompareString': 208,
- 'PyArray_MultiIterFromObjects': 209,
- 'PyArray_GetEndianness': 210,
- 'PyArray_GetNDArrayCFeatureVersion': 211,
- 'PyArray_Correlate2': 212,
- 'PyArray_NeighborhoodIterNew': 213,
+ 'PyArray_GetNDArrayCVersion': (0,),
+ 'PyArray_SetNumericOps': (40,),
+ 'PyArray_GetNumericOps': (41,),
+ 'PyArray_INCREF': (42,),
+ 'PyArray_XDECREF': (43,),
+ 'PyArray_SetStringFunction': (44,),
+ 'PyArray_DescrFromType': (45,),
+ 'PyArray_TypeObjectFromType': (46,),
+ 'PyArray_Zero': (47,),
+ 'PyArray_One': (48,),
+ 'PyArray_CastToType': (49, StealRef(2), NonNull(2)),
+ 'PyArray_CastTo': (50,),
+ 'PyArray_CastAnyTo': (51,),
+ 'PyArray_CanCastSafely': (52,),
+ 'PyArray_CanCastTo': (53,),
+ 'PyArray_ObjectType': (54,),
+ 'PyArray_DescrFromObject': (55,),
+ 'PyArray_ConvertToCommonType': (56,),
+ 'PyArray_DescrFromScalar': (57,),
+ 'PyArray_DescrFromTypeObject': (58,),
+ 'PyArray_Size': (59,),
+ 'PyArray_Scalar': (60,),
+ 'PyArray_FromScalar': (61, StealRef(2)),
+ 'PyArray_ScalarAsCtype': (62,),
+ 'PyArray_CastScalarToCtype': (63,),
+ 'PyArray_CastScalarDirect': (64,),
+ 'PyArray_ScalarFromObject': (65,),
+ 'PyArray_GetCastFunc': (66,),
+ 'PyArray_FromDims': (67,),
+ 'PyArray_FromDimsAndDataAndDescr': (68, StealRef(3)),
+ 'PyArray_FromAny': (69, StealRef(2)),
+ 'PyArray_EnsureArray': (70, StealRef(1)),
+ 'PyArray_EnsureAnyArray': (71, StealRef(1)),
+ 'PyArray_FromFile': (72,),
+ 'PyArray_FromString': (73,),
+ 'PyArray_FromBuffer': (74,),
+ 'PyArray_FromIter': (75, StealRef(2)),
+ 'PyArray_Return': (76, StealRef(1)),
+ 'PyArray_GetField': (77, StealRef(2), NonNull(2)),
+ 'PyArray_SetField': (78, StealRef(2), NonNull(2)),
+ 'PyArray_Byteswap': (79,),
+ 'PyArray_Resize': (80,),
+ 'PyArray_MoveInto': (81,),
+ 'PyArray_CopyInto': (82,),
+ 'PyArray_CopyAnyInto': (83,),
+ 'PyArray_CopyObject': (84,),
+ 'PyArray_NewCopy': (85, NonNull(1)),
+ 'PyArray_ToList': (86,),
+ 'PyArray_ToString': (87,),
+ 'PyArray_ToFile': (88,),
+ 'PyArray_Dump': (89,),
+ 'PyArray_Dumps': (90,),
+ 'PyArray_ValidType': (91,),
+ 'PyArray_UpdateFlags': (92,),
+ 'PyArray_New': (93, NonNull(1)),
+ 'PyArray_NewFromDescr': (94, StealRef(2), NonNull([1, 2])),
+ 'PyArray_DescrNew': (95,),
+ 'PyArray_DescrNewFromType': (96,),
+ 'PyArray_GetPriority': (97,),
+ 'PyArray_IterNew': (98,),
+ 'PyArray_MultiIterNew': (99,),
+ 'PyArray_PyIntAsInt': (100,),
+ 'PyArray_PyIntAsIntp': (101,),
+ 'PyArray_Broadcast': (102,),
+ 'PyArray_FillObjectArray': (103,),
+ 'PyArray_FillWithScalar': (104,),
+ 'PyArray_CheckStrides': (105,),
+ 'PyArray_DescrNewByteorder': (106,),
+ 'PyArray_IterAllButAxis': (107,),
+ 'PyArray_CheckFromAny': (108, StealRef(2)),
+ 'PyArray_FromArray': (109, StealRef(2)),
+ 'PyArray_FromInterface': (110,),
+ 'PyArray_FromStructInterface': (111,),
+ 'PyArray_FromArrayAttr': (112,),
+ 'PyArray_ScalarKind': (113,),
+ 'PyArray_CanCoerceScalar': (114,),
+ 'PyArray_NewFlagsObject': (115,),
+ 'PyArray_CanCastScalar': (116,),
+ 'PyArray_CompareUCS4': (117,),
+ 'PyArray_RemoveSmallest': (118,),
+ 'PyArray_ElementStrides': (119,),
+ 'PyArray_Item_INCREF': (120,),
+ 'PyArray_Item_XDECREF': (121,),
+ 'PyArray_FieldNames': (122,),
+ 'PyArray_Transpose': (123,),
+ 'PyArray_TakeFrom': (124,),
+ 'PyArray_PutTo': (125,),
+ 'PyArray_PutMask': (126,),
+ 'PyArray_Repeat': (127,),
+ 'PyArray_Choose': (128,),
+ 'PyArray_Sort': (129,),
+ 'PyArray_ArgSort': (130,),
+ 'PyArray_SearchSorted': (131,),
+ 'PyArray_ArgMax': (132,),
+ 'PyArray_ArgMin': (133,),
+ 'PyArray_Reshape': (134,),
+ 'PyArray_Newshape': (135,),
+ 'PyArray_Squeeze': (136,),
+ 'PyArray_View': (137, StealRef(2)),
+ 'PyArray_SwapAxes': (138,),
+ 'PyArray_Max': (139,),
+ 'PyArray_Min': (140,),
+ 'PyArray_Ptp': (141,),
+ 'PyArray_Mean': (142,),
+ 'PyArray_Trace': (143,),
+ 'PyArray_Diagonal': (144,),
+ 'PyArray_Clip': (145,),
+ 'PyArray_Conjugate': (146,),
+ 'PyArray_Nonzero': (147,),
+ 'PyArray_Std': (148,),
+ 'PyArray_Sum': (149,),
+ 'PyArray_CumSum': (150,),
+ 'PyArray_Prod': (151,),
+ 'PyArray_CumProd': (152,),
+ 'PyArray_All': (153,),
+ 'PyArray_Any': (154,),
+ 'PyArray_Compress': (155,),
+ 'PyArray_Flatten': (156,),
+ 'PyArray_Ravel': (157,),
+ 'PyArray_MultiplyList': (158,),
+ 'PyArray_MultiplyIntList': (159,),
+ 'PyArray_GetPtr': (160,),
+ 'PyArray_CompareLists': (161,),
+ 'PyArray_AsCArray': (162, StealRef(5)),
+ 'PyArray_As1D': (163,),
+ 'PyArray_As2D': (164,),
+ 'PyArray_Free': (165,),
+ 'PyArray_Converter': (166,),
+ 'PyArray_IntpFromSequence': (167,),
+ 'PyArray_Concatenate': (168,),
+ 'PyArray_InnerProduct': (169,),
+ 'PyArray_MatrixProduct': (170,),
+ 'PyArray_CopyAndTranspose': (171,),
+ 'PyArray_Correlate': (172,),
+ 'PyArray_TypestrConvert': (173,),
+ 'PyArray_DescrConverter': (174,),
+ 'PyArray_DescrConverter2': (175,),
+ 'PyArray_IntpConverter': (176,),
+ 'PyArray_BufferConverter': (177,),
+ 'PyArray_AxisConverter': (178,),
+ 'PyArray_BoolConverter': (179,),
+ 'PyArray_ByteorderConverter': (180,),
+ 'PyArray_OrderConverter': (181,),
+ 'PyArray_EquivTypes': (182,),
+ 'PyArray_Zeros': (183, StealRef(3)),
+ 'PyArray_Empty': (184, StealRef(3)),
+ 'PyArray_Where': (185,),
+ 'PyArray_Arange': (186,),
+ 'PyArray_ArangeObj': (187,),
+ 'PyArray_SortkindConverter': (188,),
+ 'PyArray_LexSort': (189,),
+ 'PyArray_Round': (190,),
+ 'PyArray_EquivTypenums': (191,),
+ 'PyArray_RegisterDataType': (192,),
+ 'PyArray_RegisterCastFunc': (193,),
+ 'PyArray_RegisterCanCast': (194,),
+ 'PyArray_InitArrFuncs': (195,),
+ 'PyArray_IntTupleFromIntp': (196,),
+ 'PyArray_TypeNumFromName': (197,),
+ 'PyArray_ClipmodeConverter': (198,),
+ 'PyArray_OutputConverter': (199,),
+ 'PyArray_BroadcastToShape': (200,),
+ '_PyArray_SigintHandler': (201,),
+ '_PyArray_GetSigintBuf': (202,),
+ 'PyArray_DescrAlignConverter': (203,),
+ 'PyArray_DescrAlignConverter2': (204,),
+ 'PyArray_SearchsideConverter': (205,),
+ 'PyArray_CheckAxis': (206,),
+ 'PyArray_OverflowMultiplyList': (207,),
+ 'PyArray_CompareString': (208,),
+ 'PyArray_MultiIterFromObjects': (209,),
+ 'PyArray_GetEndianness': (210,),
+ 'PyArray_GetNDArrayCFeatureVersion': (211,),
+ 'PyArray_Correlate2': (212,),
+ 'PyArray_NeighborhoodIterNew': (213,),
# End 1.5 API
- 'PyArray_SetDatetimeParseFunction': 219,
- 'PyArray_DatetimeToDatetimeStruct': 220,
- 'PyArray_TimedeltaToTimedeltaStruct': 221,
- 'PyArray_DatetimeStructToDatetime': 222,
- 'PyArray_TimedeltaStructToTimedelta': 223,
+ 'PyArray_SetDatetimeParseFunction': (219,),
+ 'PyArray_DatetimeToDatetimeStruct': (220,),
+ 'PyArray_TimedeltaToTimedeltaStruct': (221,),
+ 'PyArray_DatetimeStructToDatetime': (222,),
+ 'PyArray_TimedeltaStructToTimedelta': (223,),
# NDIter API
- 'NpyIter_New': 224,
- 'NpyIter_MultiNew': 225,
- 'NpyIter_AdvancedNew': 226,
- 'NpyIter_Copy': 227,
- 'NpyIter_Deallocate': 228,
- 'NpyIter_HasDelayedBufAlloc': 229,
- 'NpyIter_HasExternalLoop': 230,
- 'NpyIter_EnableExternalLoop': 231,
- 'NpyIter_GetInnerStrideArray': 232,
- 'NpyIter_GetInnerLoopSizePtr': 233,
- 'NpyIter_Reset': 234,
- 'NpyIter_ResetBasePointers': 235,
- 'NpyIter_ResetToIterIndexRange': 236,
- 'NpyIter_GetNDim': 237,
- 'NpyIter_GetNOp': 238,
- 'NpyIter_GetIterNext': 239,
- 'NpyIter_GetIterSize': 240,
- 'NpyIter_GetIterIndexRange': 241,
- 'NpyIter_GetIterIndex': 242,
- 'NpyIter_GotoIterIndex': 243,
- 'NpyIter_HasMultiIndex': 244,
- 'NpyIter_GetShape': 245,
- 'NpyIter_GetGetMultiIndex': 246,
- 'NpyIter_GotoMultiIndex': 247,
- 'NpyIter_RemoveMultiIndex': 248,
- 'NpyIter_HasIndex': 249,
- 'NpyIter_IsBuffered': 250,
- 'NpyIter_IsGrowInner': 251,
- 'NpyIter_GetBufferSize': 252,
- 'NpyIter_GetIndexPtr': 253,
- 'NpyIter_GotoIndex': 254,
- 'NpyIter_GetDataPtrArray': 255,
- 'NpyIter_GetDescrArray': 256,
- 'NpyIter_GetOperandArray': 257,
- 'NpyIter_GetIterView': 258,
- 'NpyIter_GetReadFlags': 259,
- 'NpyIter_GetWriteFlags': 260,
- 'NpyIter_DebugPrint': 261,
- 'NpyIter_IterationNeedsAPI': 262,
- 'NpyIter_GetInnerFixedStrideArray': 263,
- 'NpyIter_RemoveAxis': 264,
- 'NpyIter_GetAxisStrideArray': 265,
- 'NpyIter_RequiresBuffering': 266,
- 'NpyIter_GetInitialDataPtrArray': 267,
- 'NpyIter_CreateCompatibleStrides': 268,
+ 'NpyIter_New': (224,),
+ 'NpyIter_MultiNew': (225,),
+ 'NpyIter_AdvancedNew': (226,),
+ 'NpyIter_Copy': (227,),
+ 'NpyIter_Deallocate': (228,),
+ 'NpyIter_HasDelayedBufAlloc': (229,),
+ 'NpyIter_HasExternalLoop': (230,),
+ 'NpyIter_EnableExternalLoop': (231,),
+ 'NpyIter_GetInnerStrideArray': (232,),
+ 'NpyIter_GetInnerLoopSizePtr': (233,),
+ 'NpyIter_Reset': (234,),
+ 'NpyIter_ResetBasePointers': (235,),
+ 'NpyIter_ResetToIterIndexRange': (236,),
+ 'NpyIter_GetNDim': (237,),
+ 'NpyIter_GetNOp': (238,),
+ 'NpyIter_GetIterNext': (239,),
+ 'NpyIter_GetIterSize': (240,),
+ 'NpyIter_GetIterIndexRange': (241,),
+ 'NpyIter_GetIterIndex': (242,),
+ 'NpyIter_GotoIterIndex': (243,),
+ 'NpyIter_HasMultiIndex': (244,),
+ 'NpyIter_GetShape': (245,),
+ 'NpyIter_GetGetMultiIndex': (246,),
+ 'NpyIter_GotoMultiIndex': (247,),
+ 'NpyIter_RemoveMultiIndex': (248,),
+ 'NpyIter_HasIndex': (249,),
+ 'NpyIter_IsBuffered': (250,),
+ 'NpyIter_IsGrowInner': (251,),
+ 'NpyIter_GetBufferSize': (252,),
+ 'NpyIter_GetIndexPtr': (253,),
+ 'NpyIter_GotoIndex': (254,),
+ 'NpyIter_GetDataPtrArray': (255,),
+ 'NpyIter_GetDescrArray': (256,),
+ 'NpyIter_GetOperandArray': (257,),
+ 'NpyIter_GetIterView': (258,),
+ 'NpyIter_GetReadFlags': (259,),
+ 'NpyIter_GetWriteFlags': (260,),
+ 'NpyIter_DebugPrint': (261,),
+ 'NpyIter_IterationNeedsAPI': (262,),
+ 'NpyIter_GetInnerFixedStrideArray': (263,),
+ 'NpyIter_RemoveAxis': (264,),
+ 'NpyIter_GetAxisStrideArray': (265,),
+ 'NpyIter_RequiresBuffering': (266,),
+ 'NpyIter_GetInitialDataPtrArray': (267,),
+ 'NpyIter_CreateCompatibleStrides': (268,),
#
- 'PyArray_CastingConverter': 269,
- 'PyArray_CountNonzero': 270,
- 'PyArray_PromoteTypes': 271,
- 'PyArray_MinScalarType': 272,
- 'PyArray_ResultType': 273,
- 'PyArray_CanCastArrayTo': 274,
- 'PyArray_CanCastTypeTo': 275,
- 'PyArray_EinsteinSum': 276,
- 'PyArray_NewLikeArray': 277,
- 'PyArray_GetArrayParamsFromObject': 278,
- 'PyArray_ConvertClipmodeSequence': 279,
- 'PyArray_MatrixProduct2': 280,
+ 'PyArray_CastingConverter': (269,),
+ 'PyArray_CountNonzero': (270,),
+ 'PyArray_PromoteTypes': (271,),
+ 'PyArray_MinScalarType': (272,),
+ 'PyArray_ResultType': (273,),
+ 'PyArray_CanCastArrayTo': (274,),
+ 'PyArray_CanCastTypeTo': (275,),
+ 'PyArray_EinsteinSum': (276,),
+ 'PyArray_NewLikeArray': (277, StealRef(3), NonNull(1)),
+ 'PyArray_GetArrayParamsFromObject': (278,),
+ 'PyArray_ConvertClipmodeSequence': (279,),
+ 'PyArray_MatrixProduct2': (280,),
# End 1.6 API
- 'NpyIter_IsFirstVisit': 281,
- 'PyArray_SetBaseObject': 282,
- 'PyArray_CreateSortedStridePerm': 283,
- 'PyArray_RemoveAxesInPlace': 284,
- 'PyArray_DebugPrint': 285,
- 'PyArray_FailUnlessWriteable': 286,
- 'PyArray_SetUpdateIfCopyBase': 287,
- 'PyDataMem_NEW': 288,
- 'PyDataMem_FREE': 289,
- 'PyDataMem_RENEW': 290,
- 'PyDataMem_SetEventHook': 291,
- 'PyArray_MapIterSwapAxes': 293,
- 'PyArray_MapIterArray': 294,
- 'PyArray_MapIterNext': 295,
+ 'NpyIter_IsFirstVisit': (281,),
+ 'PyArray_SetBaseObject': (282, StealRef(2)),
+ 'PyArray_CreateSortedStridePerm': (283,),
+ 'PyArray_RemoveAxesInPlace': (284,),
+ 'PyArray_DebugPrint': (285,),
+ 'PyArray_FailUnlessWriteable': (286,),
+ 'PyArray_SetUpdateIfCopyBase': (287, StealRef(2)),
+ 'PyDataMem_NEW': (288,),
+ 'PyDataMem_FREE': (289,),
+ 'PyDataMem_RENEW': (290,),
+ 'PyDataMem_SetEventHook': (291,),
+ 'PyArray_MapIterSwapAxes': (293,),
+ 'PyArray_MapIterArray': (294,),
+ 'PyArray_MapIterNext': (295,),
# End 1.7 API
- 'PyArray_Partition': 296,
- 'PyArray_ArgPartition': 297,
- 'PyArray_SelectkindConverter': 298,
- 'PyDataMem_NEW_ZEROED': 299,
+ 'PyArray_Partition': (296,),
+ 'PyArray_ArgPartition': (297,),
+ 'PyArray_SelectkindConverter': (298,),
+ 'PyDataMem_NEW_ZEROED': (299,),
# End 1.8 API
}
ufunc_types_api = {
- 'PyUFunc_Type': 0
+ 'PyUFunc_Type': (0,)
}
ufunc_funcs_api = {
- 'PyUFunc_FromFuncAndData': 1,
- 'PyUFunc_RegisterLoopForType': 2,
- 'PyUFunc_GenericFunction': 3,
- 'PyUFunc_f_f_As_d_d': 4,
- 'PyUFunc_d_d': 5,
- 'PyUFunc_f_f': 6,
- 'PyUFunc_g_g': 7,
- 'PyUFunc_F_F_As_D_D': 8,
- 'PyUFunc_F_F': 9,
- 'PyUFunc_D_D': 10,
- 'PyUFunc_G_G': 11,
- 'PyUFunc_O_O': 12,
- 'PyUFunc_ff_f_As_dd_d': 13,
- 'PyUFunc_ff_f': 14,
- 'PyUFunc_dd_d': 15,
- 'PyUFunc_gg_g': 16,
- 'PyUFunc_FF_F_As_DD_D': 17,
- 'PyUFunc_DD_D': 18,
- 'PyUFunc_FF_F': 19,
- 'PyUFunc_GG_G': 20,
- 'PyUFunc_OO_O': 21,
- 'PyUFunc_O_O_method': 22,
- 'PyUFunc_OO_O_method': 23,
- 'PyUFunc_On_Om': 24,
- 'PyUFunc_GetPyValues': 25,
- 'PyUFunc_checkfperr': 26,
- 'PyUFunc_clearfperr': 27,
- 'PyUFunc_getfperr': 28,
- 'PyUFunc_handlefperr': 29,
- 'PyUFunc_ReplaceLoopBySignature': 30,
- 'PyUFunc_FromFuncAndDataAndSignature': 31,
- 'PyUFunc_SetUsesArraysAsData': 32,
+ 'PyUFunc_FromFuncAndData': (1,),
+ 'PyUFunc_RegisterLoopForType': (2,),
+ 'PyUFunc_GenericFunction': (3,),
+ 'PyUFunc_f_f_As_d_d': (4,),
+ 'PyUFunc_d_d': (5,),
+ 'PyUFunc_f_f': (6,),
+ 'PyUFunc_g_g': (7,),
+ 'PyUFunc_F_F_As_D_D': (8,),
+ 'PyUFunc_F_F': (9,),
+ 'PyUFunc_D_D': (10,),
+ 'PyUFunc_G_G': (11,),
+ 'PyUFunc_O_O': (12,),
+ 'PyUFunc_ff_f_As_dd_d': (13,),
+ 'PyUFunc_ff_f': (14,),
+ 'PyUFunc_dd_d': (15,),
+ 'PyUFunc_gg_g': (16,),
+ 'PyUFunc_FF_F_As_DD_D': (17,),
+ 'PyUFunc_DD_D': (18,),
+ 'PyUFunc_FF_F': (19,),
+ 'PyUFunc_GG_G': (20,),
+ 'PyUFunc_OO_O': (21,),
+ 'PyUFunc_O_O_method': (22,),
+ 'PyUFunc_OO_O_method': (23,),
+ 'PyUFunc_On_Om': (24,),
+ 'PyUFunc_GetPyValues': (25,),
+ 'PyUFunc_checkfperr': (26,),
+ 'PyUFunc_clearfperr': (27,),
+ 'PyUFunc_getfperr': (28,),
+ 'PyUFunc_handlefperr': (29,),
+ 'PyUFunc_ReplaceLoopBySignature': (30,),
+ 'PyUFunc_FromFuncAndDataAndSignature': (31,),
+ 'PyUFunc_SetUsesArraysAsData': (32,),
# End 1.5 API
- 'PyUFunc_e_e': 33,
- 'PyUFunc_e_e_As_f_f': 34,
- 'PyUFunc_e_e_As_d_d': 35,
- 'PyUFunc_ee_e': 36,
- 'PyUFunc_ee_e_As_ff_f': 37,
- 'PyUFunc_ee_e_As_dd_d': 38,
+ 'PyUFunc_e_e': (33,),
+ 'PyUFunc_e_e_As_f_f': (34,),
+ 'PyUFunc_e_e_As_d_d': (35,),
+ 'PyUFunc_ee_e': (36,),
+ 'PyUFunc_ee_e_As_ff_f': (37,),
+ 'PyUFunc_ee_e_As_dd_d': (38,),
# End 1.6 API
- 'PyUFunc_DefaultTypeResolver': 39,
- 'PyUFunc_ValidateCasting': 40,
+ 'PyUFunc_DefaultTypeResolver': (39,),
+ 'PyUFunc_ValidateCasting': (40,),
# End 1.7 API
- 'PyUFunc_RegisterLoopForDescr': 41,
+ 'PyUFunc_RegisterLoopForDescr': (41,),
# End 1.8 API
}
@@ -399,7 +399,6 @@ ufunc_funcs_api = {
# XXX: DO NOT CHANGE THE ORDER OF TUPLES BELOW !
multiarray_api = (
multiarray_global_vars,
- multiarray_global_vars_types,
multiarray_scalar_bool_values,
multiarray_types_api,
multiarray_funcs_api,
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index ce348ed11..21ff8cd1a 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -1492,13 +1492,13 @@ PyArray_STRIDE(const PyArrayObject *arr, int istride)
return ((PyArrayObject_fields *)arr)->strides[istride];
}
-static NPY_INLINE PyObject *
+static NPY_INLINE NPY_RETURNS_BORROWED_REF PyObject *
PyArray_BASE(PyArrayObject *arr)
{
return ((PyArrayObject_fields *)arr)->base;
}
-static NPY_INLINE PyArray_Descr *
+static NPY_INLINE NPY_RETURNS_BORROWED_REF PyArray_Descr *
PyArray_DESCR(PyArrayObject *arr)
{
return ((PyArrayObject_fields *)arr)->descr;
diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h
index 46c745c99..6244783f5 100644
--- a/numpy/core/include/numpy/npy_common.h
+++ b/numpy/core/include/numpy/npy_common.h
@@ -25,6 +25,16 @@
#define NPY_GCC_OPT_3
#endif
+/*
+ * mark an argument (starting from 1) that must not be NULL and is not checked
+ * DO NOT USE IF FUNCTION CHECKS FOR NULL!! the compiler will remove the check
+ */
+#ifdef HAVE_ATTRIBUTE_NONNULL
+#define NPY_GCC_NONNULL(n) __attribute__((nonnull(n)))
+#else
+#define NPY_GCC_NONNULL(n)
+#endif
+
#if defined HAVE_XMMINTRIN_H && defined HAVE__MM_LOAD_PS
#define NPY_HAVE_SSE_INTRINSICS
#endif
@@ -63,6 +73,20 @@
#define NPY_INLINE
#endif
+#ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE
+ #define NPY_RETURNS_BORROWED_REF \
+ __attribute__((cpychecker_returns_borrowed_ref))
+#else
+ #define NPY_RETURNS_BORROWED_REF
+#endif
+
+#ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE
+ #define NPY_STEALS_REF_TO_ARG(n) \
+ __attribute__((cpychecker_steals_reference_to_arg(n)))
+#else
+ #define NPY_STEALS_REF_TO_ARG(n)
+#endif
+
/* 64 bit file position support, also on win-amd64. Ticket #1660 */
#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400) || \
defined(__MINGW32__) || defined(__MINGW64__)
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index d48368ca1..c28de7c11 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -176,9 +176,8 @@ def check_math_capabilities(config, moredefs, mathlibs):
moredefs.append((fname2def(f), 1))
for dec, fn in OPTIONAL_GCC_ATTRIBUTES:
- if config.check_funcs_once([fn],
- decl=dict((('%s %s' % (dec, fn), True),)),
- call=False):
+ if config.check_func(fn, decl='int %s %s(void *);' % (dec, fn),
+ call=False):
moredefs.append((fname2def(fn), 1))
# C99 functions: float and long double versions
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py
index af2590fc7..4188f4c3f 100644
--- a/numpy/core/setup_common.py
+++ b/numpy/core/setup_common.py
@@ -127,6 +127,8 @@ OPTIONAL_GCC_ATTRIBUTES = [('__attribute__((optimize("unroll-loops")))',
'attribute_optimize_unroll_loops'),
('__attribute__((optimize("O3")))',
'attribute_optimize_opt_3'),
+ ('__attribute__((nonnull (1)))',
+ 'attribute_nonnull'),
]
# Subset of OPTIONAL_STDFUNCS which may alreay have HAVE_* defined by Python.h
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index 849386504..1db3bfe85 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -36,7 +36,7 @@ NPY_NO_EXPORT npy_intp REQUIRED_STR_LEN[] = {0, 3, 5, 10, 10, 20, 20, 20, 20};
* For backward compatibility
*
* Cast an array using typecode structure.
- * steals reference to at --- cannot be NULL
+ * steals reference to dtype --- cannot be NULL
*
* This function always makes a copy of arr, even if the dtype
* doesn't change.
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index a45a470bf..5f8fbc4dc 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -26,6 +26,7 @@
#include "array_assign.h"
#include "mapping.h" /* for array_item_asarray */
#include "scalarmathmodule.h" /* for npy_mul_with_overflow_intp */
+#include <assert.h>
/*
* Reading from a file or a string.
@@ -885,12 +886,15 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
int i;
size_t sd;
npy_intp size;
+ assert(dims != NULL || (nd == 0));
if (descr->subarray) {
PyObject *ret;
npy_intp newdims[2*NPY_MAXDIMS];
npy_intp *newstrides = NULL;
- memcpy(newdims, dims, nd*sizeof(npy_intp));
+ if (nd > 0) {
+ memcpy(newdims, dims, nd * sizeof(npy_intp));
+ }
if (strides) {
newstrides = newdims + NPY_MAXDIMS;
memcpy(newstrides, strides, nd*sizeof(npy_intp));
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index abfa04cb6..9104ffd03 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -352,9 +352,9 @@ array_swapaxes(PyArrayObject *self, PyObject *args)
}
-/* steals typed reference */
/*NUMPY_API
Get a subset of bytes from each element of the array
+ steals reference to typed, must not be NULL
*/
NPY_NO_EXPORT PyObject *
PyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)
@@ -410,6 +410,7 @@ array_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)
/*NUMPY_API
Set a subset of bytes from each element of the array
+ steals reference to dtype, must not be NULL
*/
NPY_NO_EXPORT int
PyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index c6d3c632f..a05e87e84 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -1540,7 +1540,7 @@ PyArray_EquivTypenums(int typenum1, int typenum2)
* NPY_RELAXED_STRIDES_CHECKING: If the strides logic is changed, the
* order specific stride setting is not necessary.
*/
-static PyObject *
+static NPY_STEALS_REF_TO_ARG(1) PyObject *
_prepend_ones(PyArrayObject *arr, int nd, int ndmin, NPY_ORDER order)
{
npy_intp newdims[NPY_MAXDIMS];
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 8bbfb41fa..d71823566 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -831,8 +831,9 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
/*NUMPY_API
*
- *Return either an array or the appropriate Python object if the array
- *is 0d and matches a Python type.
+ * Return either an array or the appropriate Python object if the array
+ * is 0d and matches a Python type.
+ * steals reference to mp
*/
NPY_NO_EXPORT PyObject *
PyArray_Return(PyArrayObject *mp)
diff --git a/numpy/distutils/command/config.py b/numpy/distutils/command/config.py
index cadcc1dde..0086e3632 100644
--- a/numpy/distutils/command/config.py
+++ b/numpy/distutils/command/config.py
@@ -307,7 +307,10 @@ int main ()
self._check_compiler()
body = []
if decl:
- body.append("int %s (void);" % func)
+ if type(decl) == str:
+ body.append(decl)
+ else:
+ body.append("int %s (void);" % func)
# Handle MSVC intrinsics: force MS compiler to make a function call.
# Useful to test for some functions when built with optimization on, to
# avoid build error because the intrinsic and our 'fake' test