static int getaddr(char *node, char *service, void **addr, size_t *len) { struct addrinfo *ai; int ret; if (!node) { *addr = NULL; *len = 0; return 0; } ret = getaddrinfo(node, service, NULL, &ai); if (ret) { FT_ERR("getaddrinfo error %s\n", gai_strerror(ret)); return ret; } if ((*addr = malloc(ai->ai_addrlen))) { memcpy(*addr, ai->ai_addr, ai->ai_addrlen); *len = (size_t)ai->ai_addrlen; } else { FT_ERR("addr allocation failed\n"); ret = EAI_MEMORY; } freeaddrinfo(ai); return ret; }
static int check_address(struct fid *fid, const char *message) { char buf1[BUFSIZ], buf2[BUFSIZ]; union sockaddr_any tmp; size_t tmplen; const char *ep_addr, *addr_expected; int ret; memset(&tmp, 0, sizeof tmp); tmplen = sizeof tmp; ret = fi_getname(fid, &tmp, &tmplen); if (ret) { FT_PRINTERR("fi_getname", ret); } if (sockaddrcmp(&tmp, tmplen, &bound_addr, bound_addr_len)) { ep_addr = sockaddrstr(&tmp, tmplen, buf1, BUFSIZ); if (!ep_addr) { FT_ERR("Unable to get ep_addr as string!\n"); return -FI_EINVAL; } addr_expected = sockaddrstr(&bound_addr, bound_addr_len, buf2, BUFSIZ); if (!addr_expected) { FT_ERR("Unable to get addr_expected as string!\n"); return -FI_EINVAL; } FT_ERR("address changed after %s: got %s expected %s\n", message, ep_addr, addr_expected); return -FI_EINVAL; } return 0; }
static int server_listen(size_t paramlen) { size_t expected; uint32_t event; int ret; expected = paramlen + sizeof(*entry); memset(entry, 0, expected); ret = fi_eq_sread(eq, &event, entry, expected, -1, 0); if (ret != expected) { FT_PROCESS_EQ_ERR(ret, eq, "fi_eq_sread", "listen"); return ret; } if (event != FI_CONNREQ) { FT_ERR("Unexpected CM event %d", event); return -FI_EOTHER; } ret = ft_check_buf(entry->data, paramlen); if (ret) return ret; fi = entry->info; return 0; }
pfr_get_advance( FT_Face pfrface, /* PFR_Face */ FT_UInt gindex, FT_Pos *anadvance ) { PFR_Face face = (PFR_Face)pfrface; FT_Error error = FT_ERR( Invalid_Argument ); *anadvance = 0; if ( !gindex ) goto Exit; gindex--; if ( face ) { PFR_PhyFont phys = &face->phy_font; if ( gindex < phys->num_chars ) { *anadvance = phys->chars[gindex].advance; error = FT_Err_Ok; } } Exit: return error; }
FT_Set_Var_Blend_Coordinates( FT_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Error error; FT_Service_MultiMasters service; /* check of `face' delayed to `ft_face_get_mm_service' */ if ( !coords ) return FT_THROW( Invalid_Argument ); error = ft_face_get_mm_service( face, &service ); if ( !error ) { error = FT_ERR( Invalid_Argument ); if ( service->set_mm_blend ) error = service->set_mm_blend( face, num_coords, coords ); } /* enforce recomputation of auto-hinting data */ if ( !error && face->autohint.finalizer ) { face->autohint.finalizer( face->autohint.data ); face->autohint.data = NULL; } return error; }
FT_Get_BDF_Charset_ID( FT_Face face, const char* *acharset_encoding, const char* *acharset_registry ) { FT_Error error; const char* encoding = NULL; const char* registry = NULL; error = FT_ERR( Invalid_Argument ); if ( face ) { FT_Service_BDF service; FT_FACE_FIND_SERVICE( face, service, BDF ); if ( service && service->get_charset_id ) error = service->get_charset_id( face, &encoding, ®istry ); } if ( acharset_encoding ) *acharset_encoding = encoding; if ( acharset_registry ) *acharset_registry = registry; return error; }
FT_Get_CID_Registry_Ordering_Supplement( FT_Face face, const char* *registry, const char* *ordering, FT_Int *supplement) { FT_Error error; const char* r = NULL; const char* o = NULL; FT_Int s = 0; error = FT_ERR( Invalid_Argument ); if ( face ) { FT_Service_CID service; FT_FACE_FIND_SERVICE( face, service, CID ); if ( service && service->get_ros ) error = service->get_ros( face, &r, &o, &s ); } if ( registry ) *registry = r; if ( ordering ) *ordering = o; if ( supplement ) *supplement = s; return error; }
static FT_Error ft_face_get_mm_service( FT_Face face, FT_Service_MultiMasters *aservice ) { FT_Error error; *aservice = NULL; if ( !face ) return FT_THROW( Invalid_Face_Handle ); error = FT_ERR( Invalid_Argument ); if ( FT_HAS_MULTIPLE_MASTERS( face ) ) { FT_FACE_LOOKUP_SERVICE( face, *aservice, MULTI_MASTERS ); if ( *aservice ) error = FT_Err_Ok; } return error; }
ssize_t ft_post_rma(enum ft_rma_opcodes op, struct fid_ep *ep, size_t size, struct fi_rma_iov *remote, void *context) { switch (op) { case FT_RMA_WRITE: FT_POST(fi_write, ft_get_tx_comp, tx_seq, "fi_write", ep, tx_buf, opts.transfer_size, fi_mr_desc(mr), remote_fi_addr, remote->addr, remote->key, context); break; case FT_RMA_WRITEDATA: FT_POST(fi_writedata, ft_get_tx_comp, tx_seq, "fi_writedata", ep, tx_buf, opts.transfer_size, fi_mr_desc(mr), remote_cq_data, remote_fi_addr, remote->addr, remote->key, context); break; case FT_RMA_READ: FT_POST(fi_read, ft_get_tx_comp, tx_seq, "fi_read", ep, rx_buf, opts.transfer_size, fi_mr_desc(mr), remote_fi_addr, remote->addr, remote->key, context); break; default: FT_ERR("Unknown RMA op type\n"); return EXIT_FAILURE; } return 0; }
/* * PROPERTY SERVICE * */ static FT_Error tt_property_set( FT_Module module, /* TT_Driver */ const char* property_name, const void* value ) { FT_Error error = FT_Err_Ok; TT_Driver driver = (TT_Driver)module; if ( !ft_strcmp( property_name, "interpreter-version" ) ) { FT_UInt* interpreter_version = (FT_UInt*)value; #ifndef TT_CONFIG_OPTION_SUBPIXEL_HINTING if ( *interpreter_version != TT_INTERPRETER_VERSION_35 ) error = FT_ERR( Unimplemented_Feature ); else #endif driver->interpreter_version = *interpreter_version; return error; } FT_TRACE0(( "tt_property_set: missing property `%s'\n", property_name )); return FT_THROW( Missing_Property ); }
static int client_expect_accept(size_t paramlen) { size_t expected; uint32_t event; int ret; expected = paramlen + sizeof(*entry); ret = client_connect(paramlen); if (ret) { FT_PRINTERR("fi_connect", ret); return ret; } ret = fi_eq_sread(eq, &event, entry, expected, -1, 0); if (ret != expected) { FT_PROCESS_EQ_ERR(ret, eq, "fi_eq_sread", "connect"); return ret; } if (event != FI_CONNECTED || entry->fid != &ep->fid) { FT_ERR("Unexpected CM event %d fid %p (ep %p)", event, entry->fid, ep); return -FI_EOTHER; } /* Check data on FI_CONNECTED event. */ ret = ft_check_buf(entry->data, paramlen); if (ret) return ret; fi_shutdown(ep, 0); return read_shutdown_event(); }
/* * PROPERTY SERVICE * */ static FT_Error tt_property_set( FT_Module module, /* TT_Driver */ const char* property_name, const void* value, FT_Bool value_is_string ) { FT_Error error = FT_Err_Ok; TT_Driver driver = (TT_Driver)module; #ifndef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES FT_UNUSED( value_is_string ); #endif if ( !ft_strcmp( property_name, "interpreter-version" ) ) { FT_UInt interpreter_version; #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES if ( value_is_string ) { const char* s = (const char*)value; interpreter_version = (FT_UInt)ft_strtol( s, NULL, 10 ); } else #endif { FT_UInt* iv = (FT_UInt*)value; interpreter_version = *iv; } if ( interpreter_version == TT_INTERPRETER_VERSION_35 #ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY || interpreter_version == TT_INTERPRETER_VERSION_38 #endif #ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL || interpreter_version == TT_INTERPRETER_VERSION_40 #endif ) driver->interpreter_version = interpreter_version; else error = FT_ERR( Unimplemented_Feature ); return error; } FT_TRACE0(( "tt_property_set: missing property `%s'\n", property_name )); return FT_THROW( Missing_Property ); }
static int dupaddr(void **dst_addr, size_t *dst_addrlen, void *src_addr, size_t src_addrlen) { *dst_addr = malloc(src_addrlen); if (!*dst_addr) { FT_ERR("address allocation failed"); return EAI_MEMORY; } *dst_addrlen = src_addrlen; memcpy(*dst_addr, src_addr, src_addrlen); return 0; }
FT_New_Face_From_FSSpec( FT_Library library, const FSSpec* spec, FT_Long face_index, FT_Face* aface ) { #if HAVE_FSREF FSRef ref; if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr ) return FT_THROW( Invalid_Argument ); else return FT_New_Face_From_FSRef( library, &ref, face_index, aface ); #elif HAVE_FSSPEC FT_Error error; FT_Open_Args args; OSErr err; UInt8 pathname[PATH_MAX]; if ( !spec ) return FT_THROW( Invalid_Argument ); err = FT_FSpMakePath( spec, pathname, sizeof ( pathname ) ); if ( err ) error = FT_ERR( Cannot_Open_Resource ); error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); if ( error || *aface ) return error; /* fallback to datafork font */ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); #else FT_UNUSED( library ); FT_UNUSED( spec ); FT_UNUSED( face_index ); FT_UNUSED( aface ); return FT_THROW( Unimplemented_Feature ); #endif /* HAVE_FSREF, HAVE_FSSPEC */ }
static int ft_comp_x(struct fid_cq *cq, struct ft_xcontrol *ft_x, const char *x_str, int timeout) { uint8_t buf[FT_COMP_BUF_SIZE]; struct timespec s, e; int poll_time = 0; int ret; switch(test_info.cq_wait_obj) { case FI_WAIT_NONE: do { if (!poll_time) clock_gettime(CLOCK_MONOTONIC, &s); ft_cq_read(fi_cq_read, cq, buf, comp_entry_cnt[ft_x->cq_format], ft_x->credits, x_str, ret); clock_gettime(CLOCK_MONOTONIC, &e); poll_time = get_elapsed(&s, &e, MILLI); } while (ret == -FI_EAGAIN && poll_time < timeout); break; case FI_WAIT_UNSPEC: case FI_WAIT_FD: case FI_WAIT_MUTEX_COND: ft_cq_read(fi_cq_sread, cq, buf, comp_entry_cnt[ft_x->cq_format], ft_x->credits, x_str, ret, NULL, timeout); break; case FI_WAIT_SET: FT_ERR("fi_ubertest: Unsupported cq wait object"); return -1; default: FT_ERR("Unknown cq wait object"); return -1; } return (ret == -FI_EAGAIN && timeout) ? ret : 0; }
FTC_Manager_RegisterCache( FTC_Manager manager, FTC_CacheClass clazz, FTC_Cache *acache ) { FT_Error error = FT_ERR( Invalid_Argument ); FTC_Cache cache = NULL; if ( manager && clazz && acache ) { FT_Memory memory = manager->memory; if ( manager->num_caches >= FTC_MAX_CACHES ) { error = FT_THROW( Too_Many_Caches ); FT_ERROR(( "FTC_Manager_RegisterCache:" " too many registered caches\n" )); goto Exit; } if ( !FT_ALLOC( cache, clazz->cache_size ) ) { cache->manager = manager; cache->memory = memory; cache->clazz = clazz[0]; cache->org_class = clazz; /* THIS IS VERY IMPORTANT! IT WILL WRETCH THE MANAGER */ /* IF IT IS NOT SET CORRECTLY */ cache->index = manager->num_caches; error = clazz->cache_init( cache ); if ( error ) { clazz->cache_done( cache ); FT_FREE( cache ); goto Exit; } manager->caches[manager->num_caches++] = cache; } } Exit: if ( acache ) *acache = cache; return error; }
int ft_get_tx_comp(uint64_t total) { int ret; if (txcq) { ret = ft_get_cq_comp(txcq, &tx_cq_cntr, total, -1); } else if (txcntr) { ret = fi_cntr_wait(txcntr, total, -1); if (ret) FT_PRINTERR("fi_cntr_wait", ret); } else { FT_ERR("Trying to get a TX completion when no TX CQ or counter were opened"); ret = -FI_EOTHER; } return ret; }
int main( int argc, char** argv ) { FT_Library library; FT_StreamRec stream; FT_Error error = FT_Err_Ok; AFM_FontInfoRec fi; if ( argc < 2 ) return FT_ERR( Invalid_Argument ); error = FT_Init_FreeType( &library ); if ( error ) return error; FT_ZERO( &stream ); error = FT_Stream_Open( &stream, argv[1] ); if ( error ) goto Exit; stream.memory = library->memory; FT_ZERO( &fi ); error = parse_afm( library, &stream, &fi ); if ( !error ) { FT_Memory memory = library->memory; dump_fontinfo( &fi ); if ( fi.KernPairs ) FT_FREE( fi.KernPairs ); if ( fi.TrackKerns ) FT_FREE( fi.TrackKerns ); } else printf( "parse error\n" ); FT_Stream_Close( &stream ); Exit: FT_Done_FreeType( library ); return error; }
FT_Get_Sfnt_Name( FT_Face face, FT_UInt idx, FT_SfntName *aname ) { FT_Error error = FT_ERR( Invalid_Argument ); if ( aname && face && FT_IS_SFNT( face ) ) { TT_Face ttface = (TT_Face)face; if ( idx < (FT_UInt)ttface->num_names ) { TT_NameEntryRec* entry = ttface->name_table.names + idx; /* load name on demand */ if ( entry->stringLength > 0 && entry->string == NULL ) { FT_Memory memory = face->memory; FT_Stream stream = face->stream; if ( FT_NEW_ARRAY ( entry->string, entry->stringLength ) || FT_STREAM_SEEK( entry->stringOffset ) || FT_STREAM_READ( entry->string, entry->stringLength ) ) { FT_FREE( entry->string ); entry->stringLength = 0; } } aname->platform_id = entry->platformID; aname->encoding_id = entry->encodingID; aname->language_id = entry->languageID; aname->name_id = entry->nameID; aname->string = (FT_Byte*)entry->string; aname->string_len = entry->stringLength; error = FT_Err_Ok; } } return error; }
FT_Get_MM_Var( FT_Face face, FT_MM_Var* *amaster ) { FT_Error error; FT_Service_MultiMasters service; error = ft_face_get_mm_service( face, &service ); if ( !error ) { error = FT_ERR( Invalid_Argument ); if ( service->get_mm_var ) error = service->get_mm_var( face, amaster ); } return error; }
int ft_av_insert(struct fid_av *av, void *addr, size_t count, fi_addr_t *fi_addr, uint64_t flags, void *context) { int ret; ret = fi_av_insert(av, addr, count, fi_addr, flags, context); if (ret < 0) { FT_PRINTERR("fi_av_insert", ret); return ret; } else if (ret != count) { FT_ERR("fi_av_insert: number of addresses inserted = %d;" " number of addresses given = %zd\n", ret, count); return -EXIT_FAILURE; } return 0; }
FT_Set_MM_Design_Coordinates( FT_Face face, FT_UInt num_coords, FT_Long* coords ) { FT_Error error; FT_Service_MultiMasters service; error = ft_face_get_mm_service( face, &service ); if ( !error ) { error = FT_ERR( Invalid_Argument ); if ( service->set_mm_design ) error = service->set_mm_design( face, num_coords, coords ); } return error; }
FT_Set_Var_Blend_Coordinates( FT_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Error error; FT_Service_MultiMasters service; error = ft_face_get_mm_service( face, &service ); if ( !error ) { error = FT_ERR( Invalid_Argument ); if ( service->set_mm_blend ) error = service->set_mm_blend( face, num_coords, coords ); } return error; }
FT_New_Face_From_FSRef( FT_Library library, const FSRef* ref, FT_Long face_index, FT_Face* aface ) { #if !HAVE_FSREF FT_UNUSED( library ); FT_UNUSED( ref ); FT_UNUSED( face_index ); FT_UNUSED( aface ); return FT_THROW( Unimplemented_Feature ); #else FT_Error error; FT_Open_Args args; OSErr err; UInt8 pathname[PATH_MAX]; /* test for valid `library' and `aface' delayed to `FT_Open_Face' */ if ( !ref ) return FT_THROW( Invalid_Argument ); err = FSRefMakePath( ref, pathname, sizeof ( pathname ) ); if ( err ) error = FT_ERR( Cannot_Open_Resource ); error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); if ( error || *aface ) return error; /* fallback to datafork font */ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); #endif /* HAVE_FSREF */ }
/* Create a new FT_Face from a file spec to a suitcase file. */ static FT_Error FT_New_Face_From_Suitcase( FT_Library library, const UInt8* pathname, FT_Long face_index, FT_Face* aface ) { FT_Error error = FT_ERR( Cannot_Open_Resource ); ResFileRefNum res_ref; ResourceIndex res_index; Handle fond; short num_faces_in_res; if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) ) return FT_THROW( Cannot_Open_Resource ); UseResFile( res_ref ); if ( ResError() ) return FT_THROW( Cannot_Open_Resource ); num_faces_in_res = 0; for ( res_index = 1; ; ++res_index ) { short num_faces_in_fond; fond = Get1IndResource( TTAG_FOND, res_index ); if ( ResError() ) break; num_faces_in_fond = count_faces( fond, pathname ); num_faces_in_res += num_faces_in_fond; if ( 0 <= face_index && face_index < num_faces_in_fond && error ) error = FT_New_Face_From_FOND( library, fond, face_index, aface ); face_index -= num_faces_in_fond; } CloseResFile( res_ref ); if ( !error && aface ) (*aface)->num_faces = num_faces_in_res; return error; }
FT_Get_PS_Font_Private( FT_Face face, PS_PrivateRec* afont_private ) { FT_Error error = FT_ERR( Invalid_Argument ); if ( face ) { FT_Service_PsInfo service = NULL; FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO ); if ( service && service->ps_get_font_private ) error = service->ps_get_font_private( face, afont_private ); } return error; }
static int read_shutdown_event() { int ret; uint32_t event; memset(entry, 0, sizeof(*entry)); ret = fi_eq_sread(eq, &event, entry, sizeof(*entry), -1, 0); if (ret < 0) { FT_PROCESS_EQ_ERR(ret, eq, "fi_eq_sread", "shutdown"); return ret; } if (event != FI_SHUTDOWN || entry->fid != &ep->fid) { FT_ERR("Unexpected CM event %d fid %p (ep %p)", event, entry->fid, ep); ret = -FI_EOTHER; return ret; } return 0; }
FT_Outline_Render( FT_Library library, FT_Outline* outline, FT_Raster_Params* params ) { FT_Error error; FT_Renderer renderer; FT_ListNode node; if ( !library ) return FT_THROW( Invalid_Library_Handle ); if ( !outline ) return FT_THROW( Invalid_Outline ); if ( !params ) return FT_THROW( Invalid_Argument ); renderer = library->cur_renderer; node = library->renderers.head; params->source = (void*)outline; error = FT_ERR( Cannot_Render_Glyph ); while ( renderer ) { error = renderer->raster_render( renderer->raster, params ); if ( !error || FT_ERR_NEQ( error, Cannot_Render_Glyph ) ) break; /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ /* is unsupported by the current renderer for this glyph image */ /* format */ /* now, look for another renderer that supports the same */ /* format */ renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, &node ); } return error; }
int ft_set_rma_caps(struct fi_info *fi, enum ft_rma_opcodes rma_op) { switch (rma_op) { case FT_RMA_READ: fi->caps |= FI_REMOTE_READ; if (fi->mode & FI_LOCAL_MR) fi->caps |= FI_READ; break; case FT_RMA_WRITE: case FT_RMA_WRITEDATA: fi->caps |= FI_REMOTE_WRITE; if (fi->mode & FI_LOCAL_MR) fi->caps |= FI_WRITE; break; default: FT_ERR("Invalid rma op type\n"); return -FI_EINVAL; } return 0; }
int ft_get_rx_comp(uint64_t total) { int ret = FI_SUCCESS; if (rxcq) { ret = ft_get_cq_comp(rxcq, &rx_cq_cntr, total, timeout); } else if (rxcntr) { while (fi_cntr_read(rxcntr) < total) { ret = fi_cntr_wait(rxcntr, total, timeout); if (ret) FT_PRINTERR("fi_cntr_wait", ret); else break; } } else { FT_ERR("Trying to get a RX completion when no RX CQ or counter were opened"); ret = -FI_EOTHER; } return ret; }