Exemple #1
0
static int     
vpush_extend(void *item, object ar) { 
  register int ind;
#ifdef DO_FUNLINK_DEBUG
  fprintf ( stderr, "vpush_extend: item %x, ar %x\n", item, ar );
#endif 
  ind = ar->ust.ust_fillp;  
 AGAIN:
  if (ind < ar->ust.ust_dim) {
    SET_ITEM(ar,ind,item);
    ind += sizeof(void *); 
    return(ar->v.v_fillp = ind);
  } else { 
    int newdim= ROUND_UP_PTR((2 + (int) (1.3 * ind)));
    unsigned char *newself;
    newself = (void *)alloc_relblock(newdim);
    bcopy(ar->ust.ust_self,newself,ind);
    ar->ust.ust_dim=newdim;
    ar->ust.ust_self=newself;
    goto AGAIN;
  }
#ifdef DO_FUNLINK_DEBUG_1
  fprintf ( stderr, "vpush_extend: item %x, ar %x END\n", item, ar );
#endif 
}
Exemple #2
0
#include<acoral.h>
#include"../include/hal_cfg.h"
#include"../include/hal_brd.h"
acoral_u32 *regs_save_ptr;
#define SET_ITEM(x) \
	{(x),0}
typedef struct{
	volatile acoral_u32 *reg;
	acoral_u32 val;
}hal_slp_save;
extern HAL_REAL_RESUME(acoral_u32 *regs);
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
static hal_slp_save core_save[] = {
	SET_ITEM(LOCKTIME),
	SET_ITEM(CLKCON),


	SET_ITEM(BWSCON),
	SET_ITEM(BANKCON0),
	SET_ITEM(BANKCON1),
	SET_ITEM(BANKCON2),
	SET_ITEM(BANKCON3),
	SET_ITEM(BANKCON4),
	SET_ITEM(BANKCON5),

	SET_ITEM(CLKDIVN),
	SET_ITEM(MPLLCON),
	SET_ITEM(UPLLCON),
	SET_ITEM(CLKSLOW),
	SET_ITEM(REFRESH),
};
Exemple #3
0
static int
replicationConnection_init(PyObject *obj, PyObject *args, PyObject *kwargs)
{
    replicationConnectionObject *self = (replicationConnectionObject *)obj;
    PyObject *dsn = NULL, *replication_type = NULL,
        *item = NULL, *ext = NULL, *make_dsn = NULL,
        *extras = NULL, *cursor = NULL;
    int async = 0;
    int ret = -1;

    /* 'replication_type' is not actually optional, but there's no
       good way to put it before 'async' in the list */
    static char *kwlist[] = {"dsn", "async", "replication_type", NULL};
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist,
                                     &dsn, &async, &replication_type)) { return ret; }

    /*
      We have to call make_dsn() to add replication-specific
      connection parameters, because the DSN might be an URI (if there
      were no keyword arguments to connect() it is passed unchanged).
    */
    /* we reuse args and kwargs to call make_dsn() and parent type's tp_init() */
    if (!(kwargs = PyDict_New())) { return ret; }
    Py_INCREF(args);

    /* we also reuse the dsn to hold the result of the make_dsn() call */
    Py_INCREF(dsn);

    if (!(ext = PyImport_ImportModule("psycopg2.extensions"))) { goto exit; }
    if (!(make_dsn = PyObject_GetAttrString(ext, "make_dsn"))) { goto exit; }

    /* all the nice stuff is located in python-level ReplicationCursor class */
    if (!(extras = PyImport_ImportModule("psycopg2.extras"))) { goto exit; }
    if (!(cursor = PyObject_GetAttrString(extras, "ReplicationCursor"))) { goto exit; }

    /* checking the object reference helps to avoid recognizing
       unrelated integer constants as valid input values */
    if (replication_type == replicationPhysicalConst) {
        self->type = REPLICATION_PHYSICAL;

#define SET_ITEM(k, v) \
        if (!(item = Text_FromUTF8(#v))) { goto exit; } \
        if (PyDict_SetItemString(kwargs, #k, item) != 0) { goto exit; } \
        Py_DECREF(item); \
        item = NULL;

        SET_ITEM(replication, true);
        SET_ITEM(dbname, replication);  /* required for .pgpass lookup */
    } else if (replication_type == replicationLogicalConst) {
        self->type = REPLICATION_LOGICAL;

        SET_ITEM(replication, database);
#undef SET_ITEM
    } else {
        PyErr_SetString(PyExc_TypeError,
                        "replication_type must be either REPLICATION_PHYSICAL or REPLICATION_LOGICAL");
        goto exit;
    }

    Py_DECREF(args);
    if (!(args = PyTuple_Pack(1, dsn))) { goto exit; }

    Py_DECREF(dsn);
    if (!(dsn = PyObject_Call(make_dsn, args, kwargs))) { goto exit; }

    Py_DECREF(args);
    if (!(args = Py_BuildValue("(Oi)", dsn, async))) { goto exit; }

    /* only attempt the connection once we've handled all possible errors */
    if ((ret = connectionType.tp_init(obj, args, NULL)) < 0) { goto exit; }

    self->conn.autocommit = 1;
    Py_INCREF(self->conn.cursor_factory = cursor);

exit:
    Py_XDECREF(item);
    Py_XDECREF(ext);
    Py_XDECREF(make_dsn);
    Py_XDECREF(extras);
    Py_XDECREF(cursor);
    Py_XDECREF(dsn);
    Py_XDECREF(args);
    Py_XDECREF(kwargs);

    return ret;
}