Commit 202808a5 authored by Albertas Agejevas's avatar Albertas Agejevas

Update the persistence headers.

Hashes of the files' commits in the persistent repo are as follows:

  - cPersistence.h: 8699c7fc
  - ring.h:         5364296a
  - _compat.h:      3769ede0
parent ef694c35
/*****************************************************************************
Copyright (c) 2012 Zope Foundation and Contributors.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE
****************************************************************************/
#ifndef PERSISTENT__COMPAT_H
#define PERSISTENT__COMPAT_H
#include "Python.h"
#if PY_MAJOR_VERSION >= 3
#define PY3K
#endif
#ifdef PY3K
#define INTERN PyUnicode_InternFromString
#define NATIVE_FROM_STRING_AND_SIZE PyUnicode_FromStringAndSize
#define Py_TPFLAGS_HAVE_RICHCOMPARE 0
#define INT_FROM_LONG(x) PyLong_FromLong(x)
#define INT_CHECK(x) PyLong_Check(x)
#define INT_AS_LONG(x) PyLong_AS_LONG(x)
#define CAPI_CAPSULE_NAME "persistent.cPersistence.CAPI"
#else
#define INTERN PyString_InternFromString
#define NATIVE_FROM_STRING_AND_SIZE PyString_FromStringAndSize
#define INT_FROM_LONG(x) PyInt_FromLong(x)
#define INT_CHECK(x) PyInt_Check(x)
#define INT_AS_LONG(x) PyInt_AS_LONG(x)
#endif
#endif
/*****************************************************************************
Copyright (c) 2001, 2002 Zope Corporation and Contributors.
Copyright (c) 2001, 2002 Zope Foundation and Contributors.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
......@@ -15,17 +15,20 @@
#ifndef CPERSISTENCE_H
#define CPERSISTENCE_H
#include "Python.h"
#include "_compat.h"
#include "bytesobject.h"
#include "ring.h"
#define CACHE_HEAD \
PyObject_HEAD \
CPersistentRing ring_home; \
int non_ghost_count;
int non_ghost_count; \
PY_LONG_LONG total_estimated_size;
struct ccobject_head_struct;
typedef struct ccobject_head_struct PerCache;
typedef struct ccobject_head_struct PerCache;
/* How big is a persistent object?
......@@ -36,13 +39,14 @@ typedef struct ccobject_head_struct PerCache;
8 ring struct
8 serialno
4 state + extra
4 size info
(52) so far
(56) so far
4 dict ptr
4 weaklist ptr
-------------------------
64 only need 62, but obmalloc rounds up to multiple of eight
68 only need 62, but obmalloc rounds up to multiple of eight
Even a ghost requires 64 bytes. It's possible to make a persistent
instance with slots and no dict, which changes the storage needed.
......@@ -56,8 +60,28 @@ typedef struct ccobject_head_struct PerCache;
PerCache *cache; \
CPersistentRing ring; \
char serial[8]; \
signed char state; \
unsigned char reserved[3];
signed state:8; \
unsigned estimated_size:24;
/* We recently added estimated_size. We originally added it as a new
unsigned long field after a signed char state field and a
3-character reserved field. This didn't work because there
are packages in the wild that have their own copies of cPersistence.h
that didn't see the update.
To get around this, we used the reserved space by making
estimated_size a 24-bit bit field in the space occupied by the old
3-character reserved field. To fit in 24 bits, we made the units
of estimated_size 64-character blocks. This allows is to handle up
to a GB. We should never see that, but to be paranoid, we also
truncate sizes greater than 1GB. We also set the minimum size to
64 bytes.
We use the _estimated_size_in_24_bits and _estimated_size_in_bytes
macros both to avoid repetition and to make intent a little clearer.
*/
#define _estimated_size_in_24_bits(I) ((I) > 1073741696 ? 16777215 : (I)/64+1)
#define _estimated_size_in_bytes(I) ((I)*64)
#define cPersistent_GHOST_STATE -1
#define cPersistent_UPTODATE_STATE 0
......@@ -79,6 +103,7 @@ typedef struct {
void (*ghostify)(cPersistentObject*);
int (*setstate)(PyObject*);
percachedelfunc percachedel;
int (*readCurrent)(cPersistentObject*);
} cPersistenceCAPIstruct;
#define cPersistenceType cPersistenceCAPI->pertype
......@@ -95,6 +120,9 @@ static cPersistenceCAPIstruct *cPersistenceCAPI;
#define PER_CHANGED(O) (cPersistenceCAPI->changed((cPersistentObject*)(O)))
#define PER_READCURRENT(O, E) \
if (cPersistenceCAPI->readCurrent((cPersistentObject*)(O)) < 0) { E; }
#define PER_GHOSTIFY(O) (cPersistenceCAPI->ghostify((cPersistentObject*)(O)))
/* If the object is sticky, make it non-sticky, so that it can be ghostified.
......
/*****************************************************************************
Copyright (c) 2003 Zope Corporation and Contributors.
Copyright (c) 2003 Zope Foundation and Contributors.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment