Skip to content

Commit

Permalink
Remove unused LDAPberval helper functions
Browse files Browse the repository at this point in the history
LDAPberval_from_object(), LDAPberval_from_object_check(), and
LDAPberval_release() were introduced in 20bee65 but never used.

Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes committed Nov 24, 2017
1 parent 4c9c526 commit cc64929
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
67 changes: 0 additions & 67 deletions Modules/berval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,6 @@
#include "common.h"
#include "berval.h"

/*
* Converts a Python object into a data for a berval structure.
*
* New memory is allocated, and the content of the object is copied into it.
* Then the (pre-existing) berval structure's field are filled in with pointer
* and length data.
*
* The source object must implement the buffer interface, or be None.
* If the source object is None, bv->bv_val will be set to NULL and bv_len to 0.
* Otherwise, bv->bv_val will be non-NULL (even for zero-length data).
* This allows the caller to distinguish a None argument as something special.
*
* Returns 0 on failure, leaving *bv unchanged, and setting an error.
* Returns 1 on success: the berval must be freed with LDAPberval_release().
*/
int
LDAPberval_from_object(PyObject *obj, struct berval *bv)
{
const void *data;
char *datacp;
Py_ssize_t len;

if (PyNone_Check(obj)) {
bv->bv_len = 0;
bv->bv_val = NULL;
return 1;
}

if (!PyObject_AsReadBuffer(obj, &data, &len))
return 0;

datacp = PyMem_MALLOC(len ? len : 1);
if (!datacp) {
PyErr_NoMemory();
return 0;
}
memcpy(datacp, data, len);

bv->bv_len = len;
bv->bv_val = datacp;
return 1;
}

/*
* Returns true if the object could be used to initialize a berval structure
* with LDAPberval_from_object()
*/
int
LDAPberval_from_object_check(PyObject *obj)
{
return PyNone_Check(obj) ||
PyObject_CheckReadBuffer(obj);
}

/*
* Releases memory allocated by LDAPberval_from_object().
* Has no effect if the berval pointer is NULL or the berval data is NULL.
*/
void
LDAPberval_release(struct berval *bv) {
if (bv && bv->bv_val) {
PyMem_FREE(bv->bv_val);
bv->bv_len = 0;
bv->bv_val = NULL;
}
}

/*
* Copies out the data from a berval, and returns it as a new Python object,
* Returns None if the berval pointer is NULL.
Expand Down
3 changes: 0 additions & 3 deletions Modules/berval.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include "common.h"
#include "lber.h"

int LDAPberval_from_object(PyObject *obj, struct berval *bv);
int LDAPberval_from_object_check(PyObject *obj);
void LDAPberval_release(struct berval *bv);
PyObject *LDAPberval_to_object(const struct berval *bv);
PyObject *LDAPberval_to_unicode_object(const struct berval *bv);

Expand Down

0 comments on commit cc64929

Please sign in to comment.