~stepankk/pyopenssl/bug-845445

« back to all changes in this revision

Viewing changes to OpenSSL/ssl/ssl.c

  • Committer: Jean-Paul Calderone
  • Date: 2011-04-25 23:41:32 UTC
  • mfrom: (128.2.10 run-on-pypy)
  • Revision ID: exarkun@divmod.com-20110425234132-0f76yf59poaegjxu
Various fixes which make pyOpenSSL more likely to work with PyPy

  * Fix a consistent refcounting bug across most modules
  * switch from tp_setattr to tp_setattro
  * Fix a general bug in error handling when setting invalid X509Name attributes

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
    ssl_API[ssl_Context_New_NUM]    = (void *)ssl_Context_New;
140
140
    ssl_API[ssl_Connection_New_NUM] = (void *)ssl_Connection_New;
141
141
    ssl_api_object = PyCObject_FromVoidPtr((void *)ssl_API, NULL);
142
 
    if (ssl_api_object != NULL)
 
142
    if (ssl_api_object != NULL) {
 
143
        /* PyModule_AddObject steals a reference.
 
144
         */
 
145
        Py_INCREF(ssl_api_object);
143
146
        PyModule_AddObject(module, "_C_API", ssl_api_object);
 
147
    }
144
148
#endif
145
149
 
146
150
    /* Exceptions */
148
152
 * ADD_EXCEPTION(dict,name,base) expands to a correct Exception declaration,
149
153
 * inserting OpenSSL.SSL.name into dict, derviving the exception from base.
150
154
 */
151
 
#define ADD_EXCEPTION(_name, _base)                                    \
152
 
do {                                                                          \
 
155
#define ADD_EXCEPTION(_name, _base)                                     \
 
156
do {                                                                    \
153
157
    ssl_##_name = PyErr_NewException("OpenSSL.SSL."#_name, _base, NULL);\
154
158
    if (ssl_##_name == NULL)                                            \
155
 
        goto error;                                                           \
 
159
        goto error;                                                     \
 
160
    /* PyModule_AddObject steals a reference. */                        \
 
161
    Py_INCREF(ssl_##_name);                                             \
156
162
    if (PyModule_AddObject(module, #_name, ssl_##_name) != 0)           \
157
 
        goto error;                                                           \
 
163
        goto error;                                                     \
158
164
} while (0)
159
165
 
160
166
    ssl_Error = PyErr_NewException("OpenSSL.SSL.Error", NULL, NULL);
161
 
    if (ssl_Error == NULL)
 
167
    if (ssl_Error == NULL) {
162
168
        goto error;
 
169
    }
 
170
 
 
171
    /* PyModule_AddObject steals a reference. */
 
172
    Py_INCREF(ssl_Error);
163
173
    if (PyModule_AddObject(module, "Error", ssl_Error) != 0)
164
174
        goto error;
165
175