Exemplo n.º 1
0
Arquivo: dbpack.c Projeto: braddr/cold
static cDict *unpack_dict(cBuf *buf, Long *buf_pos)
{
    cDict *dict;
    cList *keys, *values;
    Int i;

    keys = unpack_list(buf, buf_pos);
    values = unpack_list(buf, buf_pos);
    if (keys->len <= 64) {
        dict = dict_new(keys, values);
        list_discard(keys);
        list_discard(values);
        return dict;
    } else {
        dict = EMALLOC(cDict, 1);
        dict->keys = keys;
        dict->values = values;
        dict->hashtab_size = read_long(buf, buf_pos);
        dict->links = EMALLOC(Int, dict->hashtab_size);
        dict->hashtab = EMALLOC(Int, dict->hashtab_size);
        for (i = 0; i < dict->hashtab_size; i++) {
            dict->links[i] = read_long(buf, buf_pos);
            dict->hashtab[i] = read_long(buf, buf_pos);
        }
        dict->refs = 1;
        return dict;
    }
}
Exemplo n.º 2
0
bool CACHE_SESSION::save()
{
  bool ret = false;
  unsigned int binlen, sqllen;
  char *sqlbuff;
  char *binbuff;
	binlen = this->serialize_bin(NULL);		// obtient la taille maximum n�cessaire
	if(binbuff = (char *)EMALLOC(binlen))
	{
		binlen = this->serialize_bin((long *)binbuff);		// obtient la taille r�elle et s�rialise
		sqllen = epublisher->escape_string(binbuff, binlen, NULL);	// obtient la taille maximum n�cessaire
		if(sqlbuff = (char *)EMALLOC(sqllen))
		{
		  char *sql;
		  int l;
			sqllen = epublisher->escape_string(binbuff, binlen, sqlbuff);	// escape et obtient la taille r�elle
			l = sizeof("UPDATE cache SET session='' WHERE session_id=???????????") + sqllen;
			if(sql = (char *)EMALLOC(l))
			{
				sprintf(sql, "UPDATE cache SET session='%s' WHERE session_id=%li", sqlbuff, this->session_id);

				if(epublisher->query(sql))
				{
					if(epublisher->affected_rows() == 1)
						ret = true;
				}
				EFREE(sql);
			}
			EFREE(sqlbuff);
		}
		EFREE(binbuff);
	}
	return(ret);
}
Exemplo n.º 3
0
Hash * hash_new_with(cList *keys) {
    Hash *cnew;
    Int i, j;

    /* Construct a new hash */
    cnew = EMALLOC(Hash, 1);
    cnew->keys = list_dup(keys);

    /* Calculate initial size of chain and hash table. */
    cnew->hashtab_size = HASHTAB_STARTING_SIZE;
    while (cnew->hashtab_size < keys->len)
	cnew->hashtab_size = cnew->hashtab_size * 2 + MALLOC_DELTA;

    /* Initialize chain entries and hash table. */
    cnew->links   = EMALLOC(Int, cnew->hashtab_size);
    cnew->hashtab = EMALLOC(Int, cnew->hashtab_size);
    memset(cnew->links,   -1, sizeof(Long)*cnew->hashtab_size);
    memset(cnew->hashtab, -1, sizeof(Long)*cnew->hashtab_size);

    /* Insert the keys into the hash table, eliminating duplicates. */
    i = j = 0;
    while (i < cnew->keys->len) {
	if (i != j)
	    cnew->keys->el[j] = cnew->keys->el[i];
	if (hash_find(cnew, &keys->el[i]) == F_FAILURE)
	    quickhash_insert_key(cnew, j++);
	else
	    data_discard(&cnew->keys->el[i]);
	i++;
    }
    cnew->keys->len = j;

    cnew->refs = 1;
    return cnew;
}
Exemplo n.º 4
0
Arquivo: dbpack.c Projeto: braddr/cold
static void unpack_methods(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i, size;

    size = read_long(buf, buf_pos);

    if (size == -1) {
        obj->methods = NULL;
        return;
    }

    obj->methods = EMALLOC(ObjMethods, 1);

    obj->methods->size = size;
    obj->methods->blanks = read_long(buf, buf_pos);

    obj->methods->hashtab = EMALLOC(Int, obj->methods->size);
    obj->methods->tab = EMALLOC(struct mptr, obj->methods->size);

    for (i = 0; i < obj->methods->size; i++) {
	obj->methods->hashtab[i] = read_long(buf, buf_pos);
	obj->methods->tab[i].m = unpack_method(buf, buf_pos);
	if (obj->methods->tab[i].m)
	    obj->methods->tab[i].m->object = obj;
	obj->methods->tab[i].next = read_long(buf, buf_pos);
    }

    unpack_strings(buf, buf_pos, obj);
    unpack_idents(buf, buf_pos, obj);
}
Exemplo n.º 5
0
CACHE_COLL::CACHE_COLL(long coll_id, long base_id, char *name, char *prefs) //, bool registered)
{
  int lstr, lram;
	this->coll_id = coll_id;
	this->base_id = base_id;
	this->name = NULL;
	this->name_lenPAD = 0;
	this->prefs = NULL;
	this->prefs_lenPAD = 0;
//	this->registered = registered;
	this->binsize = sizeof(this->coll_id)			// coll_id
					+ sizeof(this->base_id)			// base_id
//					+ sizeof(this->phserver_port)	// phserver_port
//					+ sizeof(long)					// registered
					+ PAD							// name	(if null)
#if GETPREFS
					+ PAD							// prefs (if null)
#endif
					;
	if(name)
	{
		lstr = strlen(name);
		lram = LSTRPAD(lstr);			// room for the final '\0', rounded to the next multiple of PAD
		if(this->name = (char *)EMALLOC(lram))
		{
			this->name_lenPAD = lram;
			memcpy(this->name, name, lstr+1);
			while(lstr<lram)
				this->name[lstr++] = '\0';	// pad with 0
			this->binsize += lram-PAD;		// PAD was already counted
		}
	}
#if GETPREFS
	if(prefs)
	{
		lstr = strlen(prefs);
		lram = LSTRPAD(lstr);			// room for the final '\0', rounded to the next multiple of PAD
		if(this->prefs = (char *)EMALLOC(lram))
		{
			this->prefs_lenPAD = lram;
			memcpy(this->prefs, prefs, lstr+1);
			while(lstr<lram)
				this->prefs[lstr++] = '\0';	// pad with 0
			this->binsize += lram-PAD;		// PAD was already counted
		}
	}
#endif
	this->nextcoll = NULL;
}
Exemplo n.º 6
0
char* charToStr(int x)
{
    char* buf = EMALLOC(2*sizeof(char));
    buf[0] = (char)x;
    buf[1] = '\0';
    return buf;
}
Exemplo n.º 7
0
static int
_pango_xft_Load(TextState * ts, const char *name)
{
   FontCtxPangoXft    *fdc;
   PangoFontDescription *font;
   PangoFontMask       flags;

   if (!_pango_ctx)
      _pango_ctx = pango_xft_get_context(disp, Dpy.screen);
   if (!_pango_ctx)
      return -1;

   font = pango_font_description_from_string(name);
   if (!font)
      return -1;

   flags = pango_font_description_get_set_fields(font);
   if ((flags & PANGO_FONT_MASK_FAMILY) == 0)
      pango_font_description_set_family(font, "sans");
   if ((flags & PANGO_FONT_MASK_SIZE) == 0)
      pango_font_description_set_size(font, 10 * PANGO_SCALE);

   fdc = EMALLOC(FontCtxPangoXft, 1);
   if (!fdc)
      return -1;
   fdc->font = font;
   ts->fdc = fdc;
   ts->need_utf8 = 1;
   ts->type = FONT_TYPE_PANGO_XFT;
   ts->ops = &FontOps_pango;
   return 0;
}
Exemplo n.º 8
0
Arquivo: stdfuns.c Projeto: avsm/EpiVM
mpz_t* strToBigInt(char* str)
{
    mpz_t* answer = EMALLOC(sizeof(mpz_t));
    mpz_init(*answer);
    mpz_set_str(*answer, str, 10);
    return answer;
}
Exemplo n.º 9
0
Arquivo: stdfuns.c Projeto: avsm/EpiVM
void* doWithin(int limit, void* proc, void* doOnFail)
{
    pthread_t* t = EMALLOC(sizeof(pthread_t));
//    printf("CREATING THREAD %d\n", t);
    struct threadinfo th;
    th.proc = proc;
    th.result = NULL;

    struct timeval tv;
    gettimeofday(&tv, NULL);
    int tnow, tthen = do_utime();

    pthread_create(t, NULL, runThread, &th);
//    printf("tthen %d\n", tthen);

    void* ans;

    do 
    {
	// If the answer has been updated, we're done.
	if (th.result!=NULL) {
	    pthread_join(*t, &ans);
	    return ans;
	}
	gettimeofday(&tv, NULL);
	tnow = do_utime();
	usleep(100);
//	printf("tnow %d\n", tnow);
    }
    while(tnow<(tthen+(limit*1000)));
    pthread_cancel(*t);
    return DO_EVAL(doOnFail,1);
}
Exemplo n.º 10
0
Arquivo: stdfuns.c Projeto: avsm/EpiVM
// FIXME: Do this properly!
char* readStr() {
    char *buf = NULL;
    if (buf==NULL) { buf = EMALLOC(sizeof(char)*512); } // yeah, right...
    fgets(buf,512,stdin);
    char *loc = strchr(buf,'\n');
    *loc = '\0';
    return buf;
}
Exemplo n.º 11
0
Arquivo: stdfuns.c Projeto: avsm/EpiVM
void doFork(void* proc)
{
    pthread_t* t = EMALLOC(sizeof(pthread_t));
    struct threadinfo th;
    th.proc = proc;
    th.result = NULL;
    pthread_create(t, NULL, runThread, &th);
}
Exemplo n.º 12
0
Arquivo: stdfuns.c Projeto: avsm/EpiVM
char* bigIntToStr(mpz_t x)
{
    char* str = mpz_get_str(NULL,10,x);
    char* buf = EMALLOC(strlen(str)+1);
    strcpy(buf,str);
    free(str);
    return buf;
}
Exemplo n.º 13
0
bool CACHE_SESSION::save()
{
  bool ret = false;
  MYSQL_STMT   *stmt;
  MYSQL_BIND   bind[2];
  char *query = (char *)("UPDATE cache SET session=? WHERE session_id=?");
  char *binbuff;
  unsigned long binlen;
  int session_id = this->session_id;
  MYSQL *mysql = (MYSQL *)epublisher->get_native_conn();

//zend_printf("LINE %i <br/>\n", __LINE__);
	if( (stmt = mysql_stmt_init(mysql)) )
	{
//zend_printf("LINE %i <br/>\n", __LINE__);
		if( (mysql_stmt_prepare(stmt, query, strlen(query))) == 0 )
		{
//zend_printf("LINE %i <br/>\n", __LINE__);
			binlen = this->get_binsize();		// obtient la taille maximum n�cessaire
			if(binbuff = (char *)EMALLOC(binlen))
			{
//zend_printf("LINE %i <br/>\n", __LINE__);
				binlen = this->serialize_bin((long *)binbuff);		// s�rialise et obtient la taille r�elle

//zend_printf("LINE %i binlen=%li <br/>\n", __LINE__, binlen);
				bind[0].buffer_type = MYSQL_TYPE_VAR_STRING;
				bind[0].buffer = binbuff;
				bind[0].buffer_length = binlen;
				bind[0].is_null= 0;
				bind[0].length= &binlen;

				bind[1].buffer_type= MYSQL_TYPE_LONG;
				bind[1].buffer= (char *)&session_id;
				bind[1].is_null= 0;
				bind[1].length= 0;

				if (mysql_stmt_bind_param(stmt, bind) == 0)
				{
//zend_printf("LINE %i <br/>\n", __LINE__);
					if (mysql_stmt_execute(stmt) == 0)
					{
//zend_printf("LINE %i <br/>\n", __LINE__);
						if(mysql_stmt_affected_rows(stmt) == 1)
						{
//zend_printf("LINE %i <br/>\n", __LINE__);
							ret = true;
						}
					}
				}
				EFREE(binbuff);
			}
		}
		mysql_stmt_close(stmt);
	}
	return(ret);
}
Exemplo n.º 14
0
Arquivo: stdfuns.c Projeto: avsm/EpiVM
char* strrev(char* str) {
    char* buf = EMALLOC((1+strlen(str))*sizeof(char));
    int x = strlen(str);
    buf[x+1]='\0';
    int y = 0; 
    while(x>0) {
	buf[y++] = str[--x];
    }
    return buf;
}
Exemplo n.º 15
0
Arquivo: dbpack.c Projeto: braddr/cold
static Method *unpack_method(cBuf *buf, Long *buf_pos)
{
    Int     i, j, n;
    Method *method;
    Int     name;

    /* Read in the name.  If this is -1, it was a marker for a blank entry. */
    name = read_ident(buf, buf_pos);
    if (name == NOT_AN_IDENT)
	return NULL;

    method = EMALLOC(Method, 1);

    method->name = name;
    method->m_access = read_long(buf, buf_pos);
    method->m_flags = read_long(buf, buf_pos);
    method->native = read_long(buf, buf_pos);
    method->refs = 1;

    method->num_args = read_long(buf, buf_pos);
    if (method->num_args) {
	method->argnames = TMALLOC(Int, method->num_args);
	for (i = 0; i < method->num_args; i++) {
	    method->argnames[i] = read_long(buf, buf_pos);
        }
    }
    method->rest = read_long(buf, buf_pos);

    method->num_vars = read_long(buf, buf_pos);
    if (method->num_vars) {
	method->varnames = TMALLOC(Int, method->num_vars);
	for (i = 0; i < method->num_vars; i++) {
	    method->varnames[i] = read_long(buf, buf_pos);
        }
    }

    method->num_opcodes = read_long(buf, buf_pos);
    method->opcodes = TMALLOC(Long, method->num_opcodes);
    for (i = 0; i < method->num_opcodes; i++)
	method->opcodes[i] = read_long(buf, buf_pos);

    method->num_error_lists = read_long(buf, buf_pos);
    if (method->num_error_lists) {
	method->error_lists = TMALLOC(Error_list, method->num_error_lists);
	for (i = 0; i < method->num_error_lists; i++) {
	    n = read_long(buf, buf_pos);
	    method->error_lists[i].num_errors = n;
	    method->error_lists[i].error_ids = TMALLOC(Int, n);
	    for (j = 0; j < n; j++)
		method->error_lists[i].error_ids[j] = read_ident(buf, buf_pos);
	}
    }

    return method;
}
Exemplo n.º 16
0
Arquivo: stdfuns.c Projeto: avsm/EpiVM
int newLock(int sem)
{
    pthread_mutex_t m;

    pthread_mutex_init(&m, NULL);
    Mutex* newm = EMALLOC(sizeof(Mutex));
    newm->m_id = m;

    // Increase space for the mutexes
    if (ms==NULL) {
	ms = (Mutex**)EMALLOC(sizeof(Mutex*));
	mutexes=1;
    } else {
	ms = (Mutex**)(EREALLOC(ms, sizeof(Mutex*)*(mutexes+1)));
	mutexes++;
    }

    ms[mutexes-1] = newm;
    return mutexes-1;
}
Exemplo n.º 17
0
Arquivo: stdfuns.c Projeto: avsm/EpiVM
int newRef() {
    // Increase space for the iorefs
    if (iorefs==NULL) {
	iorefs = (void**)(EMALLOC(sizeof(void*)));
	numrefs=1;
    } else {
	iorefs = (void**)(EREALLOC(iorefs, sizeof(void*)*(numrefs+1)));
	numrefs++;
    }
    return numrefs-1;
}
Exemplo n.º 18
0
Arquivo: dbpack.c Projeto: braddr/cold
static void unpack_vars(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i;

    obj->vars.size = read_long(buf, buf_pos);
    obj->vars.blanks = read_long(buf, buf_pos);

    obj->vars.hashtab = EMALLOC(Int, obj->vars.size);
    obj->vars.tab = EMALLOC(Var, obj->vars.size);

    for (i = 0; i < obj->vars.size; i++) {
	obj->vars.hashtab[i] = read_long(buf, buf_pos);
	obj->vars.tab[i].name = read_ident(buf, buf_pos);
	if (obj->vars.tab[i].name != NOT_AN_IDENT) {
	    obj->vars.tab[i].cclass = read_long(buf, buf_pos);
	    unpack_data(buf, buf_pos, &obj->vars.tab[i].val);
	}
	obj->vars.tab[i].next = read_long(buf, buf_pos);
    }

}
Exemplo n.º 19
0
Arquivo: dbpack.c Projeto: braddr/cold
static void unpack_idents(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i;

    obj->methods->idents_size = read_long(buf, buf_pos);
    obj->methods->num_idents = read_long(buf, buf_pos);
    obj->methods->idents = EMALLOC(Ident_entry, obj->methods->idents_size);
    for (i = 0; i < obj->methods->num_idents; i++) {
	obj->methods->idents[i].id = read_ident(buf, buf_pos);
	if (obj->methods->idents[i].id != NOT_AN_IDENT)
	    obj->methods->idents[i].refs = read_long(buf, buf_pos);
    }
}
Exemplo n.º 20
0
bool CACHE_SESSION::save()
{
  bool ret = false;
  MYSQL_STMT   *stmt;
  MYSQL_BIND   bind[2];
  char *query = (char *)("UPDATE cache SET session=? WHERE session_id=?");
  char *binbuff;
  unsigned long binlen;
  int session_id = this->session_id;
  MYSQL *mysql = (MYSQL *)epublisher->get_native_conn();

	if( (stmt = mysql_stmt_init(mysql)) )
	{
		if( (mysql_stmt_prepare(stmt, query, strlen(query))) == 0 )
		{
			binlen = this->get_binsize();		// get size needed
			if(binbuff = (char *)EMALLOC(binlen))
			{
				memset(binbuff, 0, binlen);
				binlen = this->serialize_bin((long *)binbuff);		// serialize and get the real size

				memset(bind, 0, sizeof(bind));
				
				bind[0].buffer_type = MYSQL_TYPE_VAR_STRING;
				bind[0].buffer = binbuff;
				bind[0].buffer_length = binlen;
				bind[0].is_null= 0;
				bind[0].length= &binlen;

				bind[1].buffer_type= MYSQL_TYPE_LONG;
				bind[1].buffer= (char *)&session_id;
				bind[1].is_null= 0;
				bind[1].length= 0;

				if (mysql_stmt_bind_param(stmt, bind) == 0)
				{
					if (mysql_stmt_execute(stmt) == 0)
					{
						if(mysql_stmt_affected_rows(stmt) == 1)
						{
							ret = true;
						}
					}
				}
				EFREE(binbuff);
			}
		}
		mysql_stmt_close(stmt);
	}
	return(ret);
}
Exemplo n.º 21
0
Arquivo: comms.c Projeto: Limsik/e17
Client             *
ClientCreate(Window win)
{
   Client             *c;

   c = EMALLOC(Client, 1);
   if (!c)
      return NULL;

   c->win = win;
   c->msg = NULL;

   return c;
}
Exemplo n.º 22
0
void sprintfSQLERR(char **str, const char *format, ...)
{
	int l = 0;
	va_list args;
	va_start(args, format);
	*str = NULL;
	l = vsnprintf(*str, l, format, args);
	if( (*str = (char *)(EMALLOC(l+1))) )
	{
	 	va_start(args, format);
		vsnprintf(*str, l+1, format, args);
	}
	va_end(args);
}
Exemplo n.º 23
0
Arquivo: file.c Projeto: nrhtr/genesis
filec_t *file_new(void)
{
    filec_t *fnew = EMALLOC(filec_t, 1);

    fnew->fp = NULL;
    fnew->objnum = INV_OBJNUM;
    fnew->f.readable = 0;
    fnew->f.writable = 0;
    fnew->f.closed = 0;
    fnew->f.binary = 0;
    fnew->path = NULL;
    fnew->next = NULL;

    return fnew;
}
Exemplo n.º 24
0
void io_com_dump(MPI_Comm comm, const Coords *coords, const char *name, long id, int n, const int *ii, const float3 *rr) {
    char fname[FILENAME_MAX] = {0}, *data;
    long nchar = 0;
    
    EMALLOC(MAX_CHAR_PER_LINE * n, &data);

    if (m::is_master(comm))
        UC(os_mkdir(BASE));

    gen_fname(name, id, fname);
    
    UC(nchar = swrite(coords, n, ii, rr, /**/ data));
    write_mpi(comm, fname, nchar, data);
    
    EFREE(data);
}
Exemplo n.º 25
0
SQLCONN::SQLCONN(char *host, unsigned int port, char *user, char *passwd, char *dbname)
{
// ftrace("%s \n", dbname);
    this->ukey = NULL;
    this->connok = false;
    this->mysql_active_result_id = 0;

    strcpy(this->host, host);
    strcpy(this->user, user);
    strcpy(this->passwd, passwd);
    strcpy(this->dbname, dbname);
    this->port = port;

    // this->mysql_conn = NULL;
    int l = strlen(host) + 1 + 65 + 1 + (dbname ? strlen(dbname) : 0);
    if(this->ukey = (char *) EMALLOC(l))
        sprintf(this->ukey, "%s_%u_%s", host, (unsigned int) port, (dbname ? dbname : ""));
}
Exemplo n.º 26
0
// VAL is RawPacket
VAL prim_recv(int socket)
{
    // TMP HACK: 512 should be enough for the purposes of this experiment...
    // Do it properly some time.
    uint32_t* buf = (uint32_t*)EMALLOC(512*sizeof(uint32_t));

    if (!isReadable(socket, 10000)) {
	return CONSTRUCTOR2(0, EMPTYPKT, NOADDR);
    }

    int recvlen = recv(socket, buf, 512*sizeof(word32), 0);

    if (recvlen==-1) {
	return CONSTRUCTOR2(0, EMPTYPKT, NOADDR);
    } 

    return CONSTRUCTOR2(0, MKPTR(buf), MKINT(recvlen << 3));
}
Exemplo n.º 27
0
static void main0(const char *cell, Out *out) {
    int nv, nm;
    MeshVertArea *vert_area;
    Vectors  *pos;
    double *vert_areas;
    UC(mesh_read_ini_off(cell, /**/ &out->mesh));
    UC(mesh_vert_area_ini(out->mesh, &vert_area));
    nv = mesh_read_get_nv(out->mesh);
    UC(vectors_float_ini(nv, mesh_read_get_vert(out->mesh), /**/ &pos));

    nm = 1;
    EMALLOC(nv, &vert_areas);
    mesh_vert_area_apply(vert_area, nm, pos, /**/ vert_areas);
    dump(nv, nm, vert_areas, pos, out);

    mesh_vert_area_fin(vert_area);
    UC(vectors_fin(pos));
    UC(mesh_read_fin(out->mesh));
    EFREE(vert_areas);
}
Exemplo n.º 28
0
void
AtomListIntern(const char *const *names, unsigned int num, unsigned int *atoms)
{
#if SIZEOF_INT == SIZEOF_LONG
   XInternAtoms(disp, (char **)names, num, False, (Atom *) atoms);
#else
   unsigned int        i;
   Atom               *_atoms;

   _atoms = EMALLOC(Atom, num);
   if (!_atoms)
      return;

   XInternAtoms(disp, (char **)names, num, False, _atoms);
   for (i = 0; i < num; i++)
      atoms[i] = _atoms[i];

   Efree(_atoms);
#endif
}
Exemplo n.º 29
0
SQLCONN::SQLCONN(const char *host, unsigned int port, const char *user, const char *passwd, const char *dbname)
{
	this->ukey = NULL;
	this->connok = false;
	this->mysql_active_result_id = 0;
//	this->stmt_th = NULL;
//	this->DOMThesaurus = NULL;
//	this->thesaurus_buffer = NULL;
//	this->XPathCtx_thesaurus = NULL;

	strcpy(this->host, host);
	strcpy(this->user, user);
	strcpy(this->passwd, passwd);
	strcpy(this->dbname, dbname);
	this->port = port;

	// this->mysql_conn = NULL;
	int l = strlen(host) + 1 + 65 + 1 + (dbname ? strlen(dbname) : 0);
	if( (this->ukey = (char *) EMALLOC(l)) != NULL)
		sprintf(this->ukey, "%s_%u_%s", host, (unsigned int) port, (dbname ? dbname : ""));
}
Exemplo n.º 30
0
static int
_xft_Load(TextState * ts, const char *name)
{
   XftFont            *font;
   FontCtxXft         *fdc;

   if (name[0] == '-')
      font = XftFontOpenXlfd(disp, Dpy.screen, name);
   else
      font = XftFontOpenName(disp, Dpy.screen, name);

   if (!font)
      return -1;

#if 0				/* Debug */
   {
      FT_Face             ftf = XftLockFace(font);

      if (ftf == NULL)
	 return -1;
      Eprintf("Font %s family_name=%s style_name=%s\n", name,
	      ftf->family_name, ftf->style_name);
      XftUnlockFace(font);
   }
#endif

   fdc = EMALLOC(FontCtxXft, 1);
   if (!fdc)
      return -1;
   fdc->font = font;
   ts->fdc = fdc;
   ts->need_utf8 = 1;
   ts->type = FONT_TYPE_XFT;
   ts->ops = &FontOps_xft;
   return 0;
}