@@ -60,7 +60,7 @@ create_string(const char *str)
60
60
#else
61
61
obj = PyString_FromString (str );
62
62
#endif
63
- assert (obj != NULL );
63
+ assert (obj != _Py_NULL );
64
64
return obj ;
65
65
}
66
66
@@ -173,27 +173,27 @@ test_frame_getvar(PyFrameObject *frame)
173
173
174
174
// test PyFrame_GetVar() and PyFrame_GetVarString()
175
175
PyObject * attr = PyUnicode_FromString ("name" );
176
- assert (attr != NULL );
176
+ assert (attr != _Py_NULL );
177
177
PyObject * name1 = PyFrame_GetVar (frame , attr );
178
178
Py_DECREF (attr );
179
- assert (name1 != NULL );
179
+ assert (name1 != _Py_NULL );
180
180
Py_DECREF (name1 );
181
181
182
182
PyObject * name2 = PyFrame_GetVarString (frame , "name" );
183
- assert (name2 != NULL );
183
+ assert (name2 != _Py_NULL );
184
184
Py_DECREF (name2 );
185
185
186
186
// test PyFrame_GetVar() and PyFrame_GetVarString() NameError
187
187
PyObject * attr3 = PyUnicode_FromString ("dontexist" );
188
- assert (attr3 != NULL );
188
+ assert (attr3 != _Py_NULL );
189
189
PyObject * name3 = PyFrame_GetVar (frame , attr3 );
190
190
Py_DECREF (attr3 );
191
- assert (name3 == NULL );
191
+ assert (name3 == _Py_NULL );
192
192
assert (PyErr_ExceptionMatches (PyExc_NameError ));
193
193
PyErr_Clear ();
194
194
195
195
PyObject * name4 = PyFrame_GetVarString (frame , "dontexist" );
196
- assert (name4 == NULL );
196
+ assert (name4 == _Py_NULL );
197
197
assert (PyErr_ExceptionMatches (PyExc_NameError ));
198
198
PyErr_Clear ();
199
199
}
@@ -438,7 +438,7 @@ test_module_addobjectref(PyObject *module)
438
438
{
439
439
const char * name = "test_module_addobjectref" ;
440
440
PyObject * obj = PyUnicode_FromString (name );
441
- assert (obj != NULL );
441
+ assert (obj != _Py_NULL );
442
442
#ifdef CHECK_REFCNT
443
443
Py_ssize_t refcnt = Py_REFCNT (obj );
444
444
#endif
@@ -474,7 +474,7 @@ test_module_add(PyObject *module)
474
474
{
475
475
const char * name = "test_module_add" ;
476
476
PyObject * obj = PyUnicode_FromString (name );
477
- assert (obj != NULL );
477
+ assert (obj != _Py_NULL );
478
478
#ifdef CHECK_REFCNT
479
479
Py_ssize_t refcnt = Py_REFCNT (obj );
480
480
#endif
@@ -508,8 +508,8 @@ static PyObject *
508
508
test_module (PyObject * Py_UNUSED (module ), PyObject * Py_UNUSED (ignored ))
509
509
{
510
510
PyObject * module = PyImport_ImportModule ("sys" );
511
- if (module == NULL ) {
512
- return NULL ;
511
+ if (module == _Py_NULL ) {
512
+ return _Py_NULL ;
513
513
}
514
514
assert (PyModule_Check (module ));
515
515
@@ -611,7 +611,7 @@ test_code(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
611
611
// PyCode_GetVarnames
612
612
{
613
613
PyObject * co_varnames = PyCode_GetVarnames (code );
614
- assert (co_varnames != NULL );
614
+ assert (co_varnames != _Py_NULL );
615
615
assert (PyTuple_CheckExact (co_varnames ));
616
616
assert (PyTuple_GET_SIZE (co_varnames ) != 0 );
617
617
Py_DECREF (co_varnames );
@@ -620,7 +620,7 @@ test_code(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
620
620
// PyCode_GetCellvars
621
621
{
622
622
PyObject * co_cellvars = PyCode_GetCellvars (code );
623
- assert (co_cellvars != NULL );
623
+ assert (co_cellvars != _Py_NULL );
624
624
assert (PyTuple_CheckExact (co_cellvars ));
625
625
assert (PyTuple_GET_SIZE (co_cellvars ) == 0 );
626
626
Py_DECREF (co_cellvars );
@@ -629,7 +629,7 @@ test_code(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
629
629
// PyCode_GetFreevars
630
630
{
631
631
PyObject * co_freevars = PyCode_GetFreevars (code );
632
- assert (co_freevars != NULL );
632
+ assert (co_freevars != _Py_NULL );
633
633
assert (PyTuple_CheckExact (co_freevars ));
634
634
assert (PyTuple_GET_SIZE (co_freevars ) == 0 );
635
635
Py_DECREF (co_freevars );
@@ -715,15 +715,15 @@ static PyObject *
715
715
test_import (PyObject * Py_UNUSED (module ), PyObject * Py_UNUSED (args ))
716
716
{
717
717
PyObject * mod = PyImport_ImportModule ("sys" );
718
- if (mod == NULL ) {
719
- return NULL ;
718
+ if (mod == _Py_NULL ) {
719
+ return _Py_NULL ;
720
720
}
721
721
Py_ssize_t refcnt = Py_REFCNT (mod );
722
722
723
723
// test PyImport_AddModuleRef()
724
724
PyObject * mod2 = PyImport_AddModuleRef ("sys" );
725
- if (mod2 == NULL ) {
726
- return NULL ;
725
+ if (mod2 == _Py_NULL ) {
726
+ return _Py_NULL ;
727
727
}
728
728
assert (PyModule_Check (mod2 ));
729
729
assert (Py_REFCNT (mod ) == (refcnt + 1 ));
@@ -740,11 +740,11 @@ gc_collect(void)
740
740
{
741
741
#if defined(PYPY_VERSION )
742
742
PyObject * mod = PyImport_ImportModule ("gc" );
743
- assert (mod != NULL );
743
+ assert (mod != _Py_NULL );
744
744
745
- PyObject * res = PyObject_CallMethod (mod , "collect" , NULL );
745
+ PyObject * res = PyObject_CallMethod (mod , "collect" , _Py_NULL );
746
746
Py_DECREF (mod );
747
- assert (res != NULL );
747
+ assert (res != _Py_NULL );
748
748
Py_DECREF (res );
749
749
#else
750
750
PyGC_Collect ();
@@ -755,7 +755,7 @@ gc_collect(void)
755
755
static PyObject *
756
756
func_varargs (PyObject * Py_UNUSED (module ), PyObject * args , PyObject * kwargs )
757
757
{
758
- if (kwargs != NULL ) {
758
+ if (kwargs != _Py_NULL ) {
759
759
return PyTuple_Pack (2 , args , kwargs );
760
760
}
761
761
else {
@@ -784,20 +784,20 @@ test_weakref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
784
784
// type. This object supports weak references.
785
785
PyObject * new_type = PyObject_CallFunction ((PyObject * )& PyType_Type ,
786
786
"s(){}" , "TypeName" );
787
- if (new_type == NULL ) {
788
- return NULL ;
787
+ if (new_type == _Py_NULL ) {
788
+ return _Py_NULL ;
789
789
}
790
790
PyObject * obj = PyObject_CallNoArgs (new_type );
791
791
Py_DECREF (new_type );
792
- if (obj == NULL ) {
793
- return NULL ;
792
+ if (obj == _Py_NULL ) {
793
+ return _Py_NULL ;
794
794
}
795
795
Py_ssize_t refcnt = Py_REFCNT (obj );
796
796
797
797
// create a weak reference
798
- PyObject * weakref = PyWeakref_NewRef (obj , NULL );
799
- if (weakref == NULL ) {
800
- return NULL ;
798
+ PyObject * weakref = PyWeakref_NewRef (obj , _Py_NULL );
799
+ if (weakref == _Py_NULL ) {
800
+ return _Py_NULL ;
801
801
}
802
802
803
803
// test PyWeakref_GetRef(), reference is alive
@@ -814,23 +814,23 @@ test_weakref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
814
814
// test PyWeakref_GetRef(), reference is dead
815
815
ref = Py_True ;
816
816
assert (PyWeakref_GetRef (weakref , & ref ) == 0 );
817
- assert (ref == NULL );
817
+ assert (ref == _Py_NULL );
818
818
819
819
// test PyWeakref_GetRef(), invalid type
820
820
PyObject * invalid_weakref = Py_None ;
821
821
assert (!PyErr_Occurred ());
822
822
ref = Py_True ;
823
823
assert (PyWeakref_GetRef (invalid_weakref , & ref ) == -1 );
824
824
assert (PyErr_ExceptionMatches (PyExc_TypeError ));
825
- assert (ref == NULL );
825
+ assert (ref == _Py_NULL );
826
826
PyErr_Clear ();
827
827
828
828
#ifndef PYPY_VERSION
829
829
// test PyWeakref_GetRef(NULL)
830
830
ref = Py_True ;
831
- assert (PyWeakref_GetRef (NULL , & ref ) == -1 );
831
+ assert (PyWeakref_GetRef (_Py_NULL , & ref ) == -1 );
832
832
assert (PyErr_ExceptionMatches (PyExc_SystemError ));
833
- assert (ref == NULL );
833
+ assert (ref == _Py_NULL );
834
834
PyErr_Clear ();
835
835
#endif
836
836
@@ -842,8 +842,8 @@ test_weakref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
842
842
static void
843
843
test_vectorcall_noargs (PyObject * func_varargs )
844
844
{
845
- PyObject * res = PyObject_Vectorcall (func_varargs , NULL , 0 , NULL );
846
- assert (res != NULL );
845
+ PyObject * res = PyObject_Vectorcall (func_varargs , _Py_NULL , 0 , _Py_NULL );
846
+ assert (res != _Py_NULL );
847
847
848
848
assert (PyTuple_Check (res ));
849
849
assert (PyTuple_GET_SIZE (res ) == 1 );
@@ -860,13 +860,13 @@ static void
860
860
test_vectorcall_args (PyObject * func_varargs )
861
861
{
862
862
PyObject * args_tuple = Py_BuildValue ("ii" , 1 , 2 );
863
- assert (args_tuple != NULL );
863
+ assert (args_tuple != _Py_NULL );
864
864
size_t nargs = (size_t )PyTuple_GET_SIZE (args_tuple );
865
865
PyObject * * args = & PyTuple_GET_ITEM (args_tuple , 0 );
866
866
867
- PyObject * res = PyObject_Vectorcall (func_varargs , args , nargs , NULL );
867
+ PyObject * res = PyObject_Vectorcall (func_varargs , args , nargs , _Py_NULL );
868
868
Py_DECREF (args_tuple );
869
- assert (res != NULL );
869
+ assert (res != _Py_NULL );
870
870
871
871
assert (PyTuple_Check (res ));
872
872
assert (PyTuple_GET_SIZE (res ) == 1 );
@@ -886,15 +886,15 @@ test_vectorcall_args_offset(PyObject *func_varargs)
886
886
{
887
887
// args contains 3 values, but only pass 2 last values
888
888
PyObject * args_tuple = Py_BuildValue ("iii" , 1 , 2 , 3 );
889
- assert (args_tuple != NULL );
889
+ assert (args_tuple != _Py_NULL );
890
890
size_t nargs = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET ;
891
891
PyObject * * args = & PyTuple_GET_ITEM (args_tuple , 1 );
892
892
PyObject * arg0 = PyTuple_GET_ITEM (args_tuple , 0 );
893
893
894
- PyObject * res = PyObject_Vectorcall (func_varargs , args , nargs , NULL );
894
+ PyObject * res = PyObject_Vectorcall (func_varargs , args , nargs , _Py_NULL );
895
895
assert (PyTuple_GET_ITEM (args_tuple , 0 ) == arg0 );
896
896
Py_DECREF (args_tuple );
897
- assert (res != NULL );
897
+ assert (res != _Py_NULL );
898
898
899
899
assert (PyTuple_Check (res ));
900
900
assert (PyTuple_GET_SIZE (res ) == 1 );
@@ -913,7 +913,7 @@ static void
913
913
test_vectorcall_args_kwnames (PyObject * func_varargs )
914
914
{
915
915
PyObject * args_tuple = Py_BuildValue ("iiiii" , 1 , 2 , 3 , 4 , 5 );
916
- assert (args_tuple != NULL );
916
+ assert (args_tuple != _Py_NULL );
917
917
PyObject * * args = & PyTuple_GET_ITEM (args_tuple , 0 );
918
918
919
919
#ifdef PYTHON3
@@ -923,16 +923,16 @@ test_vectorcall_args_kwnames(PyObject *func_varargs)
923
923
PyObject * key1 = PyString_FromString ("key1" );
924
924
PyObject * key2 = PyString_FromString ("key2" );
925
925
#endif
926
- assert (key1 != NULL );
927
- assert (key2 != NULL );
926
+ assert (key1 != _Py_NULL );
927
+ assert (key2 != _Py_NULL );
928
928
PyObject * kwnames = PyTuple_Pack (2 , key1 , key2 );
929
- assert (kwnames != NULL );
929
+ assert (kwnames != _Py_NULL );
930
930
size_t nargs = (size_t )(PyTuple_GET_SIZE (args_tuple ) - PyTuple_GET_SIZE (kwnames ));
931
931
932
932
PyObject * res = PyObject_Vectorcall (func_varargs , args , nargs , kwnames );
933
933
Py_DECREF (args_tuple );
934
934
Py_DECREF (kwnames );
935
- assert (res != NULL );
935
+ assert (res != _Py_NULL );
936
936
937
937
assert (PyTuple_Check (res ));
938
938
assert (PyTuple_GET_SIZE (res ) == 2 );
@@ -976,14 +976,14 @@ test_vectorcall(PyObject *module, PyObject *Py_UNUSED(args))
976
976
{
977
977
#ifndef PYTHON3
978
978
module = PyImport_ImportModule (MODULE_NAME_STR );
979
- assert (module != NULL );
979
+ assert (module != _Py_NULL );
980
980
#endif
981
981
PyObject * func_varargs = PyObject_GetAttrString (module , "func_varargs" );
982
982
#ifndef PYTHON3
983
983
Py_DECREF (module );
984
984
#endif
985
- if (func_varargs == NULL ) {
986
- return NULL ;
985
+ if (func_varargs == _Py_NULL ) {
986
+ return _Py_NULL ;
987
987
}
988
988
989
989
// test PyObject_Vectorcall()
@@ -1003,8 +1003,8 @@ test_getattr(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1003
1003
assert (!PyErr_Occurred ());
1004
1004
1005
1005
PyObject * obj = PyImport_ImportModule ("sys" );
1006
- if (obj == NULL ) {
1007
- return NULL ;
1006
+ if (obj == _Py_NULL ) {
1007
+ return _Py_NULL ;
1008
1008
}
1009
1009
PyObject * attr_name ;
1010
1010
PyObject * value ;
@@ -1013,28 +1013,28 @@ test_getattr(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1013
1013
attr_name = create_string ("version" );
1014
1014
value = Py_True ; // marker value
1015
1015
assert (PyObject_GetOptionalAttr (obj , attr_name , & value ) == 1 );
1016
- assert (value != NULL );
1016
+ assert (value != _Py_NULL );
1017
1017
Py_DECREF (value );
1018
1018
Py_DECREF (attr_name );
1019
1019
1020
1020
// test PyObject_GetOptionalAttrString(): attribute exists
1021
1021
value = Py_True ; // marker value
1022
1022
assert (PyObject_GetOptionalAttrString (obj , "version" , & value ) == 1 );
1023
- assert (value != NULL );
1023
+ assert (value != _Py_NULL );
1024
1024
Py_DECREF (value );
1025
1025
1026
1026
// test PyObject_GetOptionalAttr(): attribute doesn't exist
1027
1027
attr_name = create_string ("nonexistant_attr_name" );
1028
1028
value = Py_True ; // marker value
1029
1029
assert (PyObject_GetOptionalAttr (obj , attr_name , & value ) == 0 );
1030
- assert (value == NULL );
1030
+ assert (value == _Py_NULL );
1031
1031
Py_DECREF (attr_name );
1032
1032
assert (!PyErr_Occurred ());
1033
1033
1034
1034
// test PyObject_GetOptionalAttrString(): attribute doesn't exist
1035
1035
value = Py_True ; // marker value
1036
1036
assert (PyObject_GetOptionalAttrString (obj , "nonexistant_attr_name" , & value ) == 0 );
1037
- assert (value == NULL );
1037
+ assert (value == _Py_NULL );
1038
1038
assert (!PyErr_Occurred ());
1039
1039
1040
1040
Py_DECREF (obj );
@@ -1048,9 +1048,9 @@ test_getitem(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1048
1048
assert (!PyErr_Occurred ());
1049
1049
1050
1050
PyObject * value = Py_BuildValue ("s" , "value" );
1051
- assert (value != NULL );
1051
+ assert (value != _Py_NULL );
1052
1052
PyObject * obj = Py_BuildValue ("{sO}" , "key" , value );
1053
- assert (obj != NULL );
1053
+ assert (obj != _Py_NULL );
1054
1054
PyObject * key ;
1055
1055
PyObject * item ;
1056
1056
@@ -1072,13 +1072,13 @@ test_getitem(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1072
1072
key = create_string ("dontexist" );
1073
1073
item = Py_True ; // marker value
1074
1074
assert (PyMapping_GetOptionalItem (obj , key , & item ) == 0 );
1075
- assert (item == NULL );
1075
+ assert (item == _Py_NULL );
1076
1076
Py_DECREF (key );
1077
1077
1078
1078
// test PyMapping_GetOptionalItemString(): missing key
1079
1079
item = Py_True ; // marker value
1080
1080
assert (PyMapping_GetOptionalItemString (obj , "dontexist" , & item ) == 0 );
1081
- assert (item == NULL );
1081
+ assert (item == _Py_NULL );
1082
1082
1083
1083
Py_DECREF (obj );
1084
1084
Py_DECREF (value );
@@ -1172,12 +1172,12 @@ PyMODINIT_FUNC
1172
1172
INIT_FUNC (void )
1173
1173
{
1174
1174
PyObject * module = PyModule_Create (& module_def );
1175
- if (module == NULL ) {
1176
- return NULL ;
1175
+ if (module == _Py_NULL ) {
1176
+ return _Py_NULL ;
1177
1177
}
1178
1178
if (module_exec (module ) < 0 ) {
1179
1179
Py_DECREF (module );
1180
- return NULL ;
1180
+ return _Py_NULL ;
1181
1181
}
1182
1182
return module ;
1183
1183
}
@@ -1197,7 +1197,7 @@ INIT_FUNC(void)
1197
1197
_Py_NULL ,
1198
1198
_Py_NULL ,
1199
1199
PYTHON_API_VERSION );
1200
- if (module == NULL ) {
1200
+ if (module == _Py_NULL ) {
1201
1201
return ;
1202
1202
}
1203
1203
0 commit comments