[BACK]Return to tre-python.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / external / bsd / tre / dist / python

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/external/bsd/tre/dist/python/tre-python.c between version 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2010/02/25 07:33:18 version 1.1.1.2, 2017/11/17 16:11:12
Line 337  PyTrePattern_search(TrePatternObject *se
Line 337  PyTrePattern_search(TrePatternObject *se
   char *targ;    char *targ;
   size_t tlen;    size_t tlen;
   
   if (!PyArg_ParseTuple(args, "SO!|i:match", &pstring, &TreFuzzynessType,    if (PyTuple_Size(args) > 0 && PyUnicode_Check(PyTuple_GetItem(args, 0)))
       {
         if (!PyArg_ParseTuple(args, "UO!|i:search", &pstring, &TreFuzzynessType,
                         &fz, &eflags))                          &fz, &eflags))
     return NULL;        return NULL;
       }
     else
       {
         if (!PyArg_ParseTuple(args, "SO!|i:search", &pstring, &TreFuzzynessType,
                           &fz, &eflags))
         return NULL;
       }
   
   mo = newTreMatchObject();    mo = newTreMatchObject();
   if (mo == NULL)    if (mo == NULL)
Line 347  PyTrePattern_search(TrePatternObject *se
Line 356  PyTrePattern_search(TrePatternObject *se
   
   nsub = self->rgx.re_nsub + 1;    nsub = self->rgx.re_nsub + 1;
   pm = PyMem_New(regmatch_t, nsub);    pm = PyMem_New(regmatch_t, nsub);
   if (pm != NULL)    if (!pm)
     {  
       mo->am.nmatch = nsub;  
       mo->am.pmatch = pm;  
     }  
   else  
     {      {
       /* XXX */  
       Py_DECREF(mo);        Py_DECREF(mo);
       return NULL;        return PyErr_NoMemory();
     }      }
   
   targ = PyString_AsString(pstring);    mo->am.nmatch = nsub;
   tlen = PyString_Size(pstring);    mo->am.pmatch = pm;
   
   rc = tre_reganexec(&self->rgx, targ, tlen, &mo->am, fz->ap, eflags);    if (PyUnicode_Check(pstring))
       {
         Py_ssize_t len = PyUnicode_GetSize(pstring);
         wchar_t *buf = calloc(sizeof(wchar_t), len);
         if(!buf)
           {
             Py_DECREF(mo);
             return PyErr_NoMemory();
           }
         PyUnicode_AsWideChar(pstring, buf, len);
         rc = tre_regawnexec(&self->rgx, buf, len, &mo->am, fz->ap, eflags);
         free(buf);
       }
     else
       {
         targ = PyString_AsString(pstring);
         tlen = PyString_Size(pstring);
   
         rc = tre_reganexec(&self->rgx, targ, tlen, &mo->am, fz->ap, eflags);
       }
   
   if (PyErr_Occurred())    if (PyErr_Occurred())
     {      {
Line 392  PyTrePattern_search(TrePatternObject *se
Line 414  PyTrePattern_search(TrePatternObject *se
   
 static PyMethodDef TrePattern_methods[] = {  static PyMethodDef TrePattern_methods[] = {
   { "search", (PyCFunction)PyTrePattern_search, METH_VARARGS,    { "search", (PyCFunction)PyTrePattern_search, METH_VARARGS,
     "try to match against given string, returning " TRE_MODULE ".match object "      "try to search in the given string, returning " TRE_MODULE ".match object "
     "or None on failure" },      "or None on failure" },
   {NULL, NULL}    {NULL, NULL}
 };  };
Line 445  static PyTypeObject TrePatternType = {
Line 467  static PyTypeObject TrePatternType = {
 };  };
   
 static TrePatternObject *  static TrePatternObject *
 newTrePatternObject(PyObject *args)  newTrePatternObject()
 {  {
   TrePatternObject *self;    TrePatternObject *self;
   
Line 460  static PyObject *
Line 482  static PyObject *
 PyTre_ncompile(PyObject *self, PyObject *args)  PyTre_ncompile(PyObject *self, PyObject *args)
 {  {
   TrePatternObject *rv;    TrePatternObject *rv;
   char *pattern;    PyUnicodeObject *upattern = NULL;
     char *pattern = NULL;
   int pattlen;    int pattlen;
   int cflags = 0;    int cflags = 0;
   int rc;    int rc;
   
   if (!PyArg_ParseTuple(args, "s#|i:compile", &pattern, &pattlen, &cflags))    if (PyTuple_Size(args) > 0 && PyUnicode_Check(PyTuple_GetItem(args, 0)))
     return NULL;      {
         if (!PyArg_ParseTuple(args, "U|i:compile", &upattern, &cflags))
           return NULL;
       }
     else
       {
         if (!PyArg_ParseTuple(args, "s#|i:compile", &pattern, &pattlen, &cflags))
           return NULL;
       }
   
   rv = newTrePatternObject(args);    rv = newTrePatternObject();
   if (rv == NULL)    if (rv == NULL)
     return NULL;      return NULL;
   
   rc = tre_regncomp(&rv->rgx, (char*)pattern, pattlen, cflags);    if (upattern != NULL)
       {
         Py_ssize_t len = PyUnicode_GetSize(upattern);
         wchar_t *buf = calloc(sizeof(wchar_t), len);
         if(!buf)
           {
             Py_DECREF(rv);
             return PyErr_NoMemory();
           }
         PyUnicode_AsWideChar(upattern, buf, len);
         rc = tre_regwncomp(&rv->rgx, buf, len, cflags);
         free(buf);
       }
     else
       rc = tre_regncomp(&rv->rgx, (char*)pattern, pattlen, cflags);
   
   if (rc != REG_OK)    if (rc != REG_OK)
     {      {
       if (!PyErr_Occurred())        if (!PyErr_Occurred())

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2

CVSweb <webmaster@jp.NetBSD.org>