mercurial/parsers.c
branchstable
changeset 16572 8d44b5a2974f
parent 16437 d126a0d16856
child 16597 b767382a8675
equal deleted inserted replaced
16571:1ff42ee98446 16572:8d44b5a2974f
   468 {
   468 {
   469 	if (self->cache) {
   469 	if (self->cache) {
   470 		Py_ssize_t i;
   470 		Py_ssize_t i;
   471 
   471 
   472 		for (i = 0; i < self->raw_length; i++) {
   472 		for (i = 0; i < self->raw_length; i++) {
   473 			Py_XDECREF(self->cache[i]);
   473 			if (self->cache[i]) {
   474 			self->cache[i] = NULL;
   474 				Py_DECREF(self->cache[i]);
       
   475 				self->cache[i] = NULL;
       
   476 			}
   475 		}
   477 		}
   476 		free(self->cache);
   478 		free(self->cache);
   477 		self->cache = NULL;
   479 		self->cache = NULL;
   478 	}
   480 	}
   479 	if (self->offsets) {
   481 	if (self->offsets) {
   955 	}
   957 	}
   956 
   958 
   957 	return len;
   959 	return len;
   958 }
   960 }
   959 
   961 
   960 static int index_real_init(indexObject *self, const char *data, int size,
   962 static int index_init(indexObject *self, PyObject *args)
   961 			   PyObject *inlined_obj, PyObject *data_obj)
   963 {
   962 {
   964 	PyObject *data_obj, *inlined_obj;
       
   965 	Py_ssize_t size;
       
   966 
       
   967 	if (!PyArg_ParseTuple(args, "OO", &data_obj, &inlined_obj))
       
   968 		return -1;
       
   969 	if (!PyString_Check(data_obj)) {
       
   970 		PyErr_SetString(PyExc_TypeError, "data is not a string");
       
   971 		return -1;
       
   972 	}
       
   973 	size = PyString_GET_SIZE(data_obj);
       
   974 
   963 	self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj);
   975 	self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj);
   964 	self->data = data_obj;
   976 	self->data = data_obj;
   965 	self->cache = NULL;
   977 	self->cache = NULL;
   966 
   978 
   967 	self->added = NULL;
   979 	self->added = NULL;
   969 	self->nt = NULL;
   981 	self->nt = NULL;
   970 	self->ntlength = self->ntcapacity = 0;
   982 	self->ntlength = self->ntcapacity = 0;
   971 	self->ntdepth = self->ntsplits = 0;
   983 	self->ntdepth = self->ntsplits = 0;
   972 	self->ntlookups = self->ntmisses = 0;
   984 	self->ntlookups = self->ntmisses = 0;
   973 	self->ntrev = -1;
   985 	self->ntrev = -1;
   974 	Py_INCREF(self->data);
       
   975 
   986 
   976 	if (self->inlined) {
   987 	if (self->inlined) {
   977 		long len = inline_scan(self, NULL);
   988 		long len = inline_scan(self, NULL);
   978 		if (len == -1)
   989 		if (len == -1)
   979 			goto bail;
   990 			goto bail;
   985 			goto bail;
   996 			goto bail;
   986 		}
   997 		}
   987 		self->raw_length = size / 64;
   998 		self->raw_length = size / 64;
   988 		self->length = self->raw_length + 1;
   999 		self->length = self->raw_length + 1;
   989 	}
  1000 	}
       
  1001 	Py_INCREF(self->data);
   990 
  1002 
   991 	return 0;
  1003 	return 0;
   992 bail:
  1004 bail:
   993 	return -1;
  1005 	return -1;
   994 }
  1006 }
   995 
  1007 
   996 static int index_init(indexObject *self, PyObject *args, PyObject *kwds)
       
   997 {
       
   998 	const char *data;
       
   999 	int size;
       
  1000 	PyObject *inlined_obj;
       
  1001 
       
  1002 	if (!PyArg_ParseTuple(args, "s#O", &data, &size, &inlined_obj))
       
  1003 		return -1;
       
  1004 
       
  1005 	return index_real_init(self, data, size, inlined_obj,
       
  1006 			       PyTuple_GET_ITEM(args, 0));
       
  1007 }
       
  1008 
       
  1009 static PyObject *index_nodemap(indexObject *self)
  1008 static PyObject *index_nodemap(indexObject *self)
  1010 {
  1009 {
       
  1010 	Py_INCREF(self);
  1011 	return (PyObject *)self;
  1011 	return (PyObject *)self;
  1012 }
  1012 }
  1013 
  1013 
  1014 static void index_dealloc(indexObject *self)
  1014 static void index_dealloc(indexObject *self)
  1015 {
  1015 {
  1104  *
  1104  *
  1105  * added complications are for backwards compatibility
  1105  * added complications are for backwards compatibility
  1106  */
  1106  */
  1107 static PyObject *parse_index2(PyObject *self, PyObject *args)
  1107 static PyObject *parse_index2(PyObject *self, PyObject *args)
  1108 {
  1108 {
  1109 	const char *data;
  1109 	PyObject *tuple = NULL, *cache = NULL;
  1110 	int size, ret;
       
  1111 	PyObject *inlined_obj, *tuple = NULL, *cache = NULL;
       
  1112 	indexObject *idx;
  1110 	indexObject *idx;
  1113 
  1111 	int ret;
  1114 	if (!PyArg_ParseTuple(args, "s#O", &data, &size, &inlined_obj))
       
  1115 		return NULL;
       
  1116 
  1112 
  1117 	idx = PyObject_New(indexObject, &indexType);
  1113 	idx = PyObject_New(indexObject, &indexType);
  1118 
       
  1119 	if (idx == NULL)
  1114 	if (idx == NULL)
  1120 		goto bail;
  1115 		goto bail;
  1121 
  1116 
  1122 	ret = index_real_init(idx, data, size, inlined_obj,
  1117 	ret = index_init(idx, args);
  1123 			      PyTuple_GET_ITEM(args, 0));
  1118 	if (ret == -1)
  1124 	if (ret)
       
  1125 		goto bail;
  1119 		goto bail;
  1126 
  1120 
  1127 	if (idx->inlined) {
  1121 	if (idx->inlined) {
  1128 		Py_INCREF(idx->data);
       
  1129 		cache = Py_BuildValue("iO", 0, idx->data);
  1122 		cache = Py_BuildValue("iO", 0, idx->data);
  1130 		if (cache == NULL)
  1123 		if (cache == NULL)
  1131 			goto bail;
  1124 			goto bail;
  1132 	} else {
  1125 	} else {
  1133 		cache = Py_None;
  1126 		cache = Py_None;
  1134 		Py_INCREF(cache);
  1127 		Py_INCREF(cache);
  1135 	}
  1128 	}
  1136 
       
  1137 	Py_INCREF(idx);
       
  1138 
  1129 
  1139 	tuple = Py_BuildValue("NN", idx, cache);
  1130 	tuple = Py_BuildValue("NN", idx, cache);
  1140 	if (!tuple)
  1131 	if (!tuple)
  1141 		goto bail;
  1132 		goto bail;
  1142 	return tuple;
  1133 	return tuple;