@@ -5517,7 +5517,7 @@ parseKeyUsage(PCCERT_CONTEXT pCertCtx, DWORD flags)
5517
5517
}
5518
5518
return PyErr_SetFromWindowsErr (error );
5519
5519
}
5520
- retval = PySet_New (NULL );
5520
+ retval = PyFrozenSet_New (NULL );
5521
5521
if (retval == NULL ) {
5522
5522
goto error ;
5523
5523
}
@@ -5592,20 +5592,6 @@ ssl_collect_certificates(const char *store_name)
5592
5592
return hCollectionStore ;
5593
5593
}
5594
5594
5595
- /* code from Objects/listobject.c */
5596
-
5597
- static int
5598
- list_contains (PyListObject * a , PyObject * el )
5599
- {
5600
- Py_ssize_t i ;
5601
- int cmp ;
5602
-
5603
- for (i = 0 , cmp = 0 ; cmp == 0 && i < Py_SIZE (a ); ++ i )
5604
- cmp = PyObject_RichCompareBool (el , PyList_GET_ITEM (a , i ),
5605
- Py_EQ );
5606
- return cmp ;
5607
- }
5608
-
5609
5595
/*[clinic input]
5610
5596
_ssl.enum_certificates
5611
5597
store_name: str
@@ -5628,7 +5614,7 @@ _ssl_enum_certificates_impl(PyObject *module, const char *store_name)
5628
5614
PyObject * keyusage = NULL , * cert = NULL , * enc = NULL , * tup = NULL ;
5629
5615
PyObject * result = NULL ;
5630
5616
5631
- result = PyList_New ( 0 );
5617
+ result = PySet_New ( NULL );
5632
5618
if (result == NULL ) {
5633
5619
return NULL ;
5634
5620
}
@@ -5668,11 +5654,10 @@ _ssl_enum_certificates_impl(PyObject *module, const char *store_name)
5668
5654
enc = NULL ;
5669
5655
PyTuple_SET_ITEM (tup , 2 , keyusage );
5670
5656
keyusage = NULL ;
5671
- if (!list_contains ((PyListObject * )result , tup )) {
5672
- if (PyList_Append (result , tup ) < 0 ) {
5673
- Py_CLEAR (result );
5674
- break ;
5675
- }
5657
+ if (PySet_Add (result , tup ) == -1 ) {
5658
+ Py_CLEAR (result );
5659
+ Py_CLEAR (tup );
5660
+ break ;
5676
5661
}
5677
5662
Py_CLEAR (tup );
5678
5663
}
@@ -5696,7 +5681,14 @@ _ssl_enum_certificates_impl(PyObject *module, const char *store_name)
5696
5681
return PyErr_SetFromWindowsErr (GetLastError ());
5697
5682
}
5698
5683
5699
- return result ;
5684
+ /* convert set to list */
5685
+ if (result == NULL ) {
5686
+ return NULL ;
5687
+ } else {
5688
+ PyObject * lst = PySequence_List (result );
5689
+ Py_DECREF (result );
5690
+ return lst ;
5691
+ }
5700
5692
}
5701
5693
5702
5694
/*[clinic input]
@@ -5720,7 +5712,7 @@ _ssl_enum_crls_impl(PyObject *module, const char *store_name)
5720
5712
PyObject * crl = NULL , * enc = NULL , * tup = NULL ;
5721
5713
PyObject * result = NULL ;
5722
5714
5723
- result = PyList_New ( 0 );
5715
+ result = PySet_New ( NULL );
5724
5716
if (result == NULL ) {
5725
5717
return NULL ;
5726
5718
}
@@ -5750,11 +5742,10 @@ _ssl_enum_crls_impl(PyObject *module, const char *store_name)
5750
5742
PyTuple_SET_ITEM (tup , 1 , enc );
5751
5743
enc = NULL ;
5752
5744
5753
- if (!list_contains ((PyListObject * )result , tup )) {
5754
- if (PyList_Append (result , tup ) < 0 ) {
5755
- Py_CLEAR (result );
5756
- break ;
5757
- }
5745
+ if (PySet_Add (result , tup ) == -1 ) {
5746
+ Py_CLEAR (result );
5747
+ Py_CLEAR (tup );
5748
+ break ;
5758
5749
}
5759
5750
Py_CLEAR (tup );
5760
5751
}
@@ -5776,7 +5767,14 @@ _ssl_enum_crls_impl(PyObject *module, const char *store_name)
5776
5767
Py_XDECREF (result );
5777
5768
return PyErr_SetFromWindowsErr (GetLastError ());
5778
5769
}
5779
- return result ;
5770
+ /* convert set to list */
5771
+ if (result == NULL ) {
5772
+ return NULL ;
5773
+ } else {
5774
+ PyObject * lst = PySequence_List (result );
5775
+ Py_DECREF (result );
5776
+ return lst ;
5777
+ }
5780
5778
}
5781
5779
5782
5780
#endif /* _MSC_VER */
0 commit comments