Atom Tk_InternAtom( Tk_Window tkwin, /* Window token; map name to atom for this * window's display. */ const char *name) /* Name to turn into atom. */ { TkDisplay *dispPtr; Tcl_HashEntry *hPtr; int isNew; dispPtr = ((TkWindow *) tkwin)->dispPtr; if (!dispPtr->atomInit) { AtomInit(dispPtr); } hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &isNew); if (isNew) { Tcl_HashEntry *hPtr2; Atom atom; atom = XInternAtom(dispPtr->display, name, False); Tcl_SetHashValue(hPtr, INT2PTR(atom)); hPtr2 = Tcl_CreateHashEntry(&dispPtr->atomTable, INT2PTR(atom), &isNew); Tcl_SetHashValue(hPtr2, Tcl_GetHashKey(&dispPtr->nameTable, hPtr)); } return (Atom)PTR2INT(Tcl_GetHashValue(hPtr)); }
static void AtomInit( TkDisplay *dispPtr)/* Display to initialize. */ { Tcl_HashEntry *hPtr; Atom atom; dispPtr->atomInit = 1; Tcl_InitHashTable(&dispPtr->nameTable, TCL_STRING_KEYS); Tcl_InitHashTable(&dispPtr->atomTable, TCL_ONE_WORD_KEYS); for (atom = 1; atom <= XA_LAST_PREDEFINED; atom++) { const char *name; int isNew; hPtr = Tcl_FindHashEntry(&dispPtr->atomTable, INT2PTR(atom)); if (hPtr != NULL) { continue; } name = atomNameArray[atom - 1]; hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &isNew); Tcl_SetHashValue(hPtr, INT2PTR(atom)); name = Tcl_GetHashKey(&dispPtr->nameTable, hPtr); hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, INT2PTR(atom), &isNew); Tcl_SetHashValue(hPtr, (char *)name); } }
int Tcl_CreatePipe( Tcl_Interp *interp, /* Errors returned in result. */ Tcl_Channel *rchan, /* Returned read side. */ Tcl_Channel *wchan, /* Returned write side. */ int flags) /* Reserved for future use. */ { int fileNums[2]; if (pipe(fileNums) < 0) { Tcl_SetObjResult(interp, Tcl_ObjPrintf("pipe creation failed: %s", Tcl_PosixError(interp))); return TCL_ERROR; } fcntl(fileNums[0], F_SETFD, FD_CLOEXEC); fcntl(fileNums[1], F_SETFD, FD_CLOEXEC); *rchan = Tcl_MakeFileChannel(INT2PTR(fileNums[0]), TCL_READABLE); Tcl_RegisterChannel(interp, *rchan); *wchan = Tcl_MakeFileChannel(INT2PTR(fileNums[1]), TCL_WRITABLE); Tcl_RegisterChannel(interp, *wchan); return TCL_OK; }
int main(int argc, char **argv) { int i, key, inmap, insert, data; void *datap; struct hashmap_t *map = hashmap_new(5); srandom(0); for (i=0; i<10000; i++) { key = rand()%DATASET_SIZE; insert = rand()%2; inmap = test_status[key]; data = test_data[key]; if (inmap && insert) { /* update */ data++; hashmap_upsert(map, &key, sizeof(int), INT2PTR(data), &datap); assert((intptr_t)datap == (intptr_t)test_data[key]); test_data[key] = data; } else if ( !inmap && insert) { /* insert */ hashmap_upsert(map, &key, sizeof(int), INT2PTR(data), &datap); assert( (intptr_t)datap == 0); test_status[key] = 1; } else if (inmap && !insert) { /* delete */ hashmap_delete(map, &key, sizeof(int), &datap); assert((intptr_t)datap == (intptr_t)test_data[key]); test_status[key] = 0; } else if (!inmap && !insert) { /* nothing to be deleted */ hashmap_delete(map, &key, sizeof(int), &datap); assert((intptr_t)datap == 0); } } return 0; }
static int TestgetwindowinfoObjCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { long hwnd; Tcl_Obj *dictObj = NULL, *classObj = NULL, *textObj = NULL; Tcl_Obj *childrenObj = NULL; TCHAR buf[512]; int cch, cchBuf = 256; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "hwnd"); return TCL_ERROR; } if (Tcl_GetLongFromObj(interp, objv[1], &hwnd) != TCL_OK) return TCL_ERROR; cch = GetClassName(INT2PTR(hwnd), buf, cchBuf); if (cch == 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to get class name: ", -1)); AppendSystemError(interp, GetLastError()); return TCL_ERROR; } else { Tcl_DString ds; Tcl_WinTCharToUtf(buf, -1, &ds); classObj = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)); Tcl_DStringFree(&ds); } dictObj = Tcl_NewDictObj(); Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("class", 5), classObj); Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("id", 2), Tcl_NewLongObj(GetWindowLongA(INT2PTR(hwnd), GWL_ID))); cch = GetWindowText(INT2PTR(hwnd), (LPTSTR)buf, cchBuf); textObj = Tcl_NewUnicodeObj((LPCWSTR)buf, cch); Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("text", 4), textObj); Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("parent", 6), Tcl_NewLongObj(PTR2INT(GetParent((INT2PTR(hwnd)))))); childrenObj = Tcl_NewListObj(0, NULL); EnumChildWindows(INT2PTR(hwnd), EnumChildrenProc, (LPARAM)childrenObj); Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("children", -1), childrenObj); Tcl_SetObjResult(interp, dictObj); return TCL_OK; }
int TkFindStateNumObj( Tcl_Interp *interp, /* Interp for error reporting. */ Tcl_Obj *optionPtr, /* String to use when constructing error. */ const TkStateMap *mapPtr, /* Lookup table. */ Tcl_Obj *keyPtr) /* String key to find in lookup table. */ { const TkStateMap *mPtr; const char *key; const Tcl_ObjType *typePtr; /* * See if the value is in the object cache. */ if ((keyPtr->typePtr == &tkStateKeyObjType) && (keyPtr->internalRep.twoPtrValue.ptr1 == mapPtr)) { return PTR2INT(keyPtr->internalRep.twoPtrValue.ptr2); } /* * Not there. Look in the state map. */ key = Tcl_GetString(keyPtr); for (mPtr = mapPtr; mPtr->strKey != NULL; mPtr++) { if (strcmp(key, mPtr->strKey) == 0) { typePtr = keyPtr->typePtr; if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) { typePtr->freeIntRepProc(keyPtr); } keyPtr->internalRep.twoPtrValue.ptr1 = (void *) mapPtr; keyPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(mPtr->numKey); keyPtr->typePtr = &tkStateKeyObjType; return mPtr->numKey; } } /* * Not there either. Generate an error message (if we can) and return the * default. */ if (interp != NULL) { Tcl_Obj *msgObj; mPtr = mapPtr; msgObj = Tcl_ObjPrintf( "bad %s value \"%s\": must be %s", Tcl_GetString(optionPtr), key, mPtr->strKey); for (mPtr++; mPtr->strKey != NULL; mPtr++) { Tcl_AppendPrintfToObj(msgObj, ",%s %s", ((mPtr[1].strKey != NULL) ? "" : " or"), mPtr->strKey); } Tcl_SetObjResult(interp, msgObj); Tcl_SetErrorCode(interp, "TK", "LOOKUP", Tcl_GetString(optionPtr), key, NULL); } return mPtr->numKey; }
static void GetMenuIndicatorGeometry( TkMenu *menuPtr, /* The menu we are drawing. */ TkMenuEntry *mePtr, /* The entry we are interested in. */ Tk_Font tkfont, /* The precalculated font */ const Tk_FontMetrics *fmPtr,/* The precalculated metrics */ int *widthPtr, /* The resulting width */ int *heightPtr) /* The resulting height */ { int borderWidth; if ((mePtr->type == CHECK_BUTTON_ENTRY) || (mePtr->type == RADIO_BUTTON_ENTRY)) { if (!mePtr->hideMargin && mePtr->indicatorOn) { if ((mePtr->image != NULL) || (mePtr->bitmapPtr != NULL)) { *widthPtr = (14 * mePtr->height) / 10; *heightPtr = mePtr->height; if (mePtr->type == CHECK_BUTTON_ENTRY) { mePtr->platformEntryData = (TkMenuPlatformEntryData) INT2PTR((65 * mePtr->height) / 100); } else { mePtr->platformEntryData = (TkMenuPlatformEntryData) INT2PTR((75 * mePtr->height) / 100); } } else { *widthPtr = *heightPtr = mePtr->height; if (mePtr->type == CHECK_BUTTON_ENTRY) { mePtr->platformEntryData = (TkMenuPlatformEntryData) INT2PTR((80 * mePtr->height) / 100); } else { mePtr->platformEntryData = (TkMenuPlatformEntryData) INT2PTR(mePtr->height); } } } else { Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr, &borderWidth); *heightPtr = 0; *widthPtr = borderWidth; } } else { Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr, &borderWidth); *heightPtr = 0; *widthPtr = borderWidth; } }
static void ui_bridge_put(UI *b, uint8_t *text, size_t size) { uint8_t *t = NULL; if (text) { t = xmalloc(sizeof(((UCell *)0)->data)); memcpy(t, text, size); } UI_CALL(b, put, 3, b, t, INT2PTR(size)); }
static int PipeGetHandleProc( ClientData instanceData, /* The pipe state. */ int direction, /* TCL_READABLE or TCL_WRITABLE */ ClientData *handlePtr) /* Where to store the handle. */ { PipeState *psPtr = (PipeState *) instanceData; if (direction == TCL_READABLE && psPtr->inFile) { *handlePtr = (ClientData) INT2PTR(GetFd(psPtr->inFile)); return TCL_OK; } if (direction == TCL_WRITABLE && psPtr->outFile) { *handlePtr = (ClientData) INT2PTR(GetFd(psPtr->outFile)); return TCL_OK; } return TCL_ERROR; }
/* ARGSUSED */ static int TcpGetHandleProc( ClientData instanceData, /* The socket state. */ int direction, /* Not used. */ ClientData *handlePtr) /* Where to store the handle. */ { TcpState *statePtr = instanceData; *handlePtr = INT2PTR(statePtr->fds.fd); return TCL_OK; }
/*========================================== * チャットルームから蹴り出す *------------------------------------------ */ void chat_kickchat(struct map_session_data *sd, const char *kickusername) { struct chat_data *cd; int i; nullpo_retv(sd); cd = map_id2cd(sd->chatID); if(cd == NULL || &sd->bl != (*cd->owner)) return; for(i = 0; i < cd->users; i++) { if(strncmp(cd->usersd[i]->status.name, kickusername, 24) == 0) { linkdb_insert(&cd->ban_list, INT2PTR(cd->usersd[i]->status.char_id), INT2PTR(1)); chat_leavechat(cd->usersd[i], 1); break; } } return; }
const char * Tk_GetAtomName( Tk_Window tkwin, /* Window token; map atom to name relative to * this window's display. */ Atom atom) /* Atom whose name is wanted. */ { TkDisplay *dispPtr; Tcl_HashEntry *hPtr; dispPtr = ((TkWindow *) tkwin)->dispPtr; if (!dispPtr->atomInit) { AtomInit(dispPtr); } hPtr = Tcl_FindHashEntry(&dispPtr->atomTable, INT2PTR(atom)); if (hPtr == NULL) { const char *name; Tk_ErrorHandler handler; int isNew; char *mustFree = NULL; handler = Tk_CreateErrorHandler(dispPtr->display, BadAtom, -1, -1, NULL, NULL); name = mustFree = XGetAtomName(dispPtr->display, atom); if (name == NULL) { name = "?bad atom?"; } Tk_DeleteErrorHandler(handler); hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &isNew); Tcl_SetHashValue(hPtr, INT2PTR(atom)); if (mustFree) { XFree(mustFree); } name = Tcl_GetHashKey(&dispPtr->nameTable, hPtr); hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, INT2PTR(atom), &isNew); Tcl_SetHashValue(hPtr, (char *)name); } return Tcl_GetHashValue(hPtr); }
static int FileGetHandleProc( ClientData instanceData, /* The file state. */ int direction, /* TCL_READABLE or TCL_WRITABLE */ ClientData *handlePtr) /* Where to store the handle. */ { FileState *fsPtr = instanceData; if (direction & fsPtr->validMask) { *handlePtr = INT2PTR(fsPtr->fd); return TCL_OK; } return TCL_ERROR; }
/* *---------------------------------------------------------------------- * * Tcl_CreatePipe -- * * System dependent interface to create a pipe for the [chan pipe] * command. Stolen from TclX. * * Parameters: * o interp - Errors returned in result. * o rchan, wchan - Returned read and write side. * o flags - Reserved for future use. * Results: * TCL_OK or TCL_ERROR. * *---------------------------------------------------------------------- */ int Tcl_CreatePipe( Tcl_Interp *interp, Tcl_Channel *rchan, Tcl_Channel *wchan, int flags) { int fileNums[2]; if (pipe(fileNums) < 0) { Tcl_AppendResult(interp, "pipe creation failed: ", Tcl_PosixError(interp), NULL); return TCL_ERROR; } *rchan = Tcl_MakeFileChannel((ClientData) INT2PTR(fileNums[0]), TCL_READABLE); Tcl_RegisterChannel(interp, *rchan); *wchan = Tcl_MakeFileChannel((ClientData) INT2PTR(fileNums[1]), TCL_WRITABLE); Tcl_RegisterChannel(interp, *wchan); return TCL_OK; }
/* *---------------------------------------------------------------------- * AsmInstructionArgvSet -- * * Set argument to be passed to an instruction of the assemble * code. * *---------------------------------------------------------------------- */ static void AsmInstructionArgvSet(Tcl_Interp *interp, int from, int to, int currentArg, AsmInstruction *inst, AsmCompiledProc *asmProc, Tcl_Obj **wordOv, int verbose) { int j; for (j = from; j < to; j += 2, currentArg++) { int argIndex, intValue; Tcl_GetIndexFromObj(interp, wordOv[j], asmStatementArgType, "asm cmd arg type", 0, &argIndex); Tcl_GetIntFromObj(interp, wordOv[j+1], &intValue); if (verbose != 0) { fprintf(stderr, "AsmInstructionArgvSet (type %d) arg[%d] := %s[%s]\n", argIndex, currentArg, ObjStr(wordOv[j]), ObjStr(wordOv[j+1])); } switch (argIndex) { case asmStatementArgTypeObjIdx: inst->argv[currentArg] = asmProc->slots[intValue]; break; case asmStatementArgTypeArgIdx: AsmArgSet(asmProc, intValue, &inst->argv[currentArg]); break; case asmStatementArgTypeResultIdx: inst->argv[currentArg] = NULL; break; case asmStatementArgTypeSlotIdx: case asmStatementArgTypeInstructionIdx: case asmStatementArgTypeIntIdx: inst->argv[currentArg] = INT2PTR(intValue); break; case asmStatementArgTypeVarIdx: fprintf(stderr, ".... var set [%d] = %s\n", currentArg, ObjStr(wordOv[j+1])); inst->argv[currentArg] = wordOv[j+1]; Tcl_IncrRefCount(inst->argv[currentArg]); // TODO: DECR missing break; } /*fprintf(stderr, "[%d] inst %p name %s arg[%d] %s\n", currentAsmInstruction, inst, ObjStr(inst->argv[0]), currentArg, inst->argv[currentArg] ? ObjStr(inst->argv[currentArg]) : "NULL");*/ } }
Tcl_Pid Tcl_WaitPid( Tcl_Pid pid, int *statPtr, int options) { int result; pid_t real_pid = (pid_t) PTR2INT(pid); while (1) { result = (int) waitpid(real_pid, statPtr, options); if ((result != -1) || (errno != EINTR)) { return (Tcl_Pid) INT2PTR(result); } } }
rdpDevPrivateKey rdpAllocatePixmapPrivate(ScreenPtr pScreen, int bytes) { rdpDevPrivateKey rv; #if XRDP_PRI == 1 rv = INT2PTR(AllocatePixmapPrivateIndex()); AllocatePixmapPrivate(pScreen, PTR2INT(rv), bytes); #elif XRDP_PRI == 2 dixRequestPrivate(&g_privateKeyRecPixmap, bytes); rv = &g_privateKeyRecPixmap; #else dixRegisterPrivateKey(&g_privateKeyRecPixmap, PRIVATE_PIXMAP, bytes); rv = &g_privateKeyRecPixmap; #endif return rv; }
//Connect to the remote host cnaccess_t * centernode_connect (centernode_t *cn, const char *host, uint16_t port, cnaccess_t *a, int type, int isp) { int fd = 0; struct sockaddr_in server; if ((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1) { #ifdef CDNDEBUG LOG("ER", "create sock-(%d)%s.\n", errno, strerror(errno)); #endif return 0; } //nonblocking connect call fcntl(fd, F_SETFL, O_NONBLOCK | fcntl(fd, F_GETFL, 0)); memset((uint8_t *)&server, 0, sizeof(server)); server.sin_family = PF_INET; server.sin_port = htons(port); server.sin_addr.s_addr = inet_addr(host); int r = connect(fd, (struct sockaddr *) &server, sizeof(server)); if (r == -1 && errno != EINPROGRESS) { #ifdef CDNDEBUG LOG("ER", "conn to %s.%d-(%d)%s.\n", host, port, errno, strerror(errno)); #endif return (close(fd), NULL); } cnaccess_t *ca = a; if (ca) { /* reconnect */ ca->fd = fd; ca->interaction = time(0); strncpy(ca->host,host,strlen(host)); ca->port = port; } else ca = cnaccess_create(cn, fd, host, port, type, isp); if (r == -1 && ++ca->retry > 4) ca->retry = 1; ca->status = r ? NS_CONNECTING: NS_NORMAL; printf("cat %d\n", ca->status); pthread_mutex_lock(&cn->objlock), /* add it to sesstion table */ gdsl_hash_insert(cn->accesses, ca); pthread_mutex_unlock(&cn->objlock); pthread_mutex_lock(&cn->reglock), /* register it to libevent */ gdsl_queue_insert(cn->registration, INT2PTR(ca->fd)), pthread_mutex_unlock(&cn->reglock); return ca; }
rdpDevPrivateKey rdpAllocateWindowPrivate(ScreenPtr pScreen, int bytes) { rdpDevPrivateKey rv; #if XRDP_PRI == 1 rv = INT2PTR(AllocateWindowPrivateIndex()); AllocateWindowPrivate(pScreen, PTR2INT(rv), bytes); #elif XRDP_PRI == 2 dixRequestPrivate(&g_privateKeyRecWindow, bytes); rv = &g_privateKeyRecWindow; #else dixRegisterPrivateKey(&g_privateKeyRecWindow, PRIVATE_WINDOW, bytes); rv = &g_privateKeyRecWindow; #endif return rv; }
//create TCP server cnaccess_t * centernode_server (centernode_t *cn, const char *host, uint16_t port, uint32_t type, int isp) { int fd = 0; struct sockaddr_in self; printf("Host %s port %u\n", host, port); //Create listen socket if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { #ifdef CDNDEBUG LOG("WR", "ct sock(%d)%s.\n", errno, strerror(errno)); #endif return 0; } memset((uint8_t *)&self, 0, sizeof(self)); self.sin_family = PF_INET; self.sin_port = htons(port); self.sin_addr.s_addr = inet_addr(host); int val = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*)&val, sizeof(val)) == -1) { #ifdef CDNDEBUG LOG("WR", "set SO_REUSEADDR option - (%d) %s.\n", errno, strerror(errno)); #endif return (close(fd), NULL); } if (bind(fd, (struct sockaddr *)&self, sizeof(self)) == -1) { #ifdef CDNDEBUG LOG("WR", "bind the address %s.%d - (%d) %s.\n", host, port, errno, strerror(errno)); #endif return (close(fd), NULL); } if (listen(fd, 200) < 0) { #ifdef CDNDEBUG LOG("WR", "listen on %s.%d - (%d) %s.\n", host, port, errno, strerror(errno)); #endif return (close(fd), NULL); } cnaccess_t *ca = cnaccess_create(cn, fd, host, port, type, isp); gdsl_hash_insert(cn->accesses, ca); gdsl_queue_insert(cn->registration, INT2PTR(ca->fd)); return ca; }
void srl_path_set(pTHX_ srl_path_t *path, SV *src) { path->expr = NULL; CLEAR_RESULTS(path); CLEAR_ITERATOR(path); if (sv_isobject(src) && sv_isa(src, "Sereal::Path::Iterator")) { path->iter = INT2PTR(srl_iterator_ptr, SvIV((SV*) SvRV(src))); path->i_own_iterator = 0; } else if (SvPOK(src)) { path->iter = srl_build_iterator_struct(aTHX_ NULL); path->i_own_iterator = 1; srl_iterator_set(aTHX_ path->iter, src); } else { croak("Sereal::Path: input should be either Sereal::Path::Iterator object or encoded Sereal document"); } }
Tcl_TimerToken TclCreateAbsoluteTimerHandler( Tcl_Time *timePtr, Tcl_TimerProc *proc, ClientData clientData) { register TimerHandler *timerHandlerPtr, *tPtr2, *prevPtr; ThreadSpecificData *tsdPtr; tsdPtr = InitTimer(); timerHandlerPtr = (TimerHandler *) ckalloc(sizeof(TimerHandler)); /* * Fill in fields for the event. */ memcpy((void *)&timerHandlerPtr->time, (void *)timePtr, sizeof(Tcl_Time)); timerHandlerPtr->proc = proc; timerHandlerPtr->clientData = clientData; tsdPtr->lastTimerId++; timerHandlerPtr->token = (Tcl_TimerToken) INT2PTR(tsdPtr->lastTimerId); /* * Add the event to the queue in the correct position * (ordered by event firing time). */ for (tPtr2 = tsdPtr->firstTimerHandlerPtr, prevPtr = NULL; tPtr2 != NULL; prevPtr = tPtr2, tPtr2 = tPtr2->nextPtr) { if (TCL_TIME_BEFORE(timerHandlerPtr->time, tPtr2->time)) { break; } } timerHandlerPtr->nextPtr = tPtr2; if (prevPtr == NULL) { tsdPtr->firstTimerHandlerPtr = timerHandlerPtr; } else { prevPtr->nextPtr = timerHandlerPtr; } TimerSetupProc(NULL, TCL_ALL_EVENTS); return timerHandlerPtr->token; }
Tcl_Channel Tcl_MakeFileChannel( ClientData handle, /* OS level handle. */ int mode) /* ORed combination of TCL_READABLE and * TCL_WRITABLE to indicate file mode. */ { FileState *fsPtr; char channelName[16 + TCL_INTEGER_SPACE]; int fd = PTR2INT(handle); const Tcl_ChannelType *channelTypePtr; struct sockaddr sockaddr; socklen_t sockaddrLen = sizeof(sockaddr); if (mode == 0) { return NULL; } sockaddr.sa_family = AF_UNSPEC; #ifdef SUPPORTS_TTY if (isatty(fd)) { channelTypePtr = &ttyChannelType; sprintf(channelName, "serial%d", fd); } else #endif /* SUPPORTS_TTY */ if ((getsockname(fd, (struct sockaddr *)&sockaddr, &sockaddrLen) == 0) && (sockaddrLen > 0) && (sockaddr.sa_family == AF_INET || sockaddr.sa_family == AF_INET6)) { return TclpMakeTcpClientChannelMode(INT2PTR(fd), mode); } else { channelTypePtr = &fileChannelType; sprintf(channelName, "file%d", fd); } fsPtr = ckalloc(sizeof(FileState)); fsPtr->fd = fd; fsPtr->validMask = mode | TCL_EXCEPTION; fsPtr->channel = Tcl_CreateChannel(channelTypePtr, channelName, fsPtr, mode); return fsPtr->channel; }
gpointer c_obj_from_sv( SV *sv, const char *derived_from) { SV *referent; IV tmp; if (!sv) return NULL; if (!SvOK(sv)) return NULL; /* Peel back the layers. The sv should be a blessed reference to a PV, * and we check the class against derived_from to ensure we have the right * stuff. */ if (!sv_isobject(sv) || !sv_derived_from(sv, derived_from)) { croak("Value is not an object of type %s", derived_from); return NULL; } referent = (SV *)SvRV(sv); tmp = SvIV(referent); return INT2PTR(gpointer, tmp); }
//Remove the tunnel from list and destroy the route object if empty. void centernode_cancel(centernode_t *cn, cnaccess_t *ca) { cngroup_t *cg = NULL; cnchild_t *cc = NULL; return ; pthread_mutex_lock(&cn->objlock); /* unregister the child node */ cg = gdsl_hash_search(cn->groups, INT2PTR(xtoi(ca->nid)/1000000)); if (cg != NULL) { cc = gdsl_list_search(cg->childs, (gdsl_compare_func_t)searchChild, ca->nid); if (cc != NULL) { int i = 0; int bfound = 0; for (i=0;i<cc->chused;i++) { if (cc->channel[i] == ca || bfound == 1){ if (i==(cc->chused-1)) { cc->channel[i] = 0; cc->chused --; } else cc->channel[i] = cc->channel[i+1]; bfound = 1; } } if (cc->chused == 0) { printf("hello %s\n", ca->nid); gdsl_list_remove(cg->childs, (gdsl_compare_func_t)searchChild, ca->nid); cnchild_destroy(cc); cn->cc_sum --; } } // else gdsl_list_insert_tail(cg->childs, cc); } else {} pthread_mutex_unlock(&cn->objlock); }
static void EdgeEvent(int dir) { static int lastdir = -1; #if 0 Eprintf("EdgeEvent %d -> %d\n", lastdir, dir); #endif if (lastdir == dir || Conf.desks.edge_flip_mode == EDGE_FLIP_OFF) return; if (Conf.desks.edge_flip_mode == EDGE_FLIP_MOVE && Mode.mode != MODE_MOVE) return; TIMER_DEL(edge_timer); if (dir >= 0) { if (Conf.desks.edge_flip_resistance <= 0) Conf.desks.edge_flip_resistance = 1; TIMER_ADD(edge_timer, 10 * Conf.desks.edge_flip_resistance, EdgeTimeout, INT2PTR(dir)); } lastdir = dir; }
void TclpThreadExit( int status) { pthread_exit(INT2PTR(status)); }
/* ARGSUSED */ static int PipeCloseProc( ClientData instanceData, /* The pipe to close. */ Tcl_Interp *interp) /* For error reporting. */ { PipeState *pipePtr; Tcl_Channel errChan; int errorCode, result; errorCode = 0; result = 0; pipePtr = (PipeState *) instanceData; if (pipePtr->inFile) { if (TclpCloseFile(pipePtr->inFile) < 0) { errorCode = errno; } } if (pipePtr->outFile) { if ((TclpCloseFile(pipePtr->outFile) < 0) && (errorCode == 0)) { errorCode = errno; } } if (pipePtr->isNonBlocking || TclInExit()) { /* * If the channel is non-blocking or Tcl is being cleaned up, just * detach the children PIDs, reap them (important if we are in a * dynamic load module), and discard the errorFile. */ Tcl_DetachPids(pipePtr->numPids, pipePtr->pidPtr); Tcl_ReapDetachedProcs(); if (pipePtr->errorFile) { TclpCloseFile(pipePtr->errorFile); } } else { /* * Wrap the error file into a channel and give it to the cleanup * routine. */ if (pipePtr->errorFile) { errChan = Tcl_MakeFileChannel( (ClientData) INT2PTR(GetFd(pipePtr->errorFile)), TCL_READABLE); } else { errChan = NULL; } result = TclCleanupChildren(interp, pipePtr->numPids, pipePtr->pidPtr, errChan); } if (pipePtr->numPids != 0) { ckfree((char *) pipePtr->pidPtr); } ckfree((char *) pipePtr); if (errorCode == 0) { return result; } return errorCode; }
/* ARGSUSED */ int TclpCreateProcess( Tcl_Interp *interp, /* Interpreter in which to leave errors that * occurred when creating the child process. * Error messages from the child process * itself are sent to errorFile. */ int argc, /* Number of arguments in following array. */ const char **argv, /* Array of argument strings in UTF-8. * argv[0] contains the name of the executable * translated using Tcl_TranslateFileName * call). Additional arguments have not been * converted. */ TclFile inputFile, /* If non-NULL, gives the file to use as input * for the child process. If inputFile file is * not readable or is NULL, the child will * receive no standard input. */ TclFile outputFile, /* If non-NULL, gives the file that receives * output from the child process. If * outputFile file is not writeable or is * NULL, output from the child will be * discarded. */ TclFile errorFile, /* If non-NULL, gives the file that receives * errors from the child process. If errorFile * file is not writeable or is NULL, errors * from the child will be discarded. errorFile * may be the same as outputFile. */ Tcl_Pid *pidPtr) /* If this function is successful, pidPtr is * filled with the process id of the child * process. */ { TclFile errPipeIn, errPipeOut; int count, status, fd; char errSpace[200 + TCL_INTEGER_SPACE]; Tcl_DString *dsArray; char **newArgv; int pid, i; errPipeIn = NULL; errPipeOut = NULL; pid = -1; /* * Create a pipe that the child can use to return error information if * anything goes wrong. */ if (TclpCreatePipe(&errPipeIn, &errPipeOut) == 0) { Tcl_AppendResult(interp, "couldn't create pipe: ", Tcl_PosixError(interp), NULL); goto error; } /* * We need to allocate and convert this before the fork so it is properly * deallocated later */ dsArray = (Tcl_DString *) TclStackAlloc(interp, argc * sizeof(Tcl_DString)); newArgv = (char **) TclStackAlloc(interp, (argc+1) * sizeof(char *)); newArgv[argc] = NULL; for (i = 0; i < argc; i++) { newArgv[i] = Tcl_UtfToExternalDString(NULL, argv[i], -1, &dsArray[i]); } #ifdef USE_VFORK /* * After vfork(), do not call code in the child that changes global state, * because it is using the parent's memory space at that point and writes * might corrupt the parent: so ensure standard channels are initialized in * the parent, otherwise SetupStdFile() might initialize them in the child. */ if (!inputFile) { Tcl_GetStdChannel(TCL_STDIN); } if (!outputFile) { Tcl_GetStdChannel(TCL_STDOUT); } if (!errorFile) { Tcl_GetStdChannel(TCL_STDERR); } #endif pid = fork(); if (pid == 0) { int joinThisError = errorFile && (errorFile == outputFile); fd = GetFd(errPipeOut); /* * Set up stdio file handles for the child process. */ if (!SetupStdFile(inputFile, TCL_STDIN) || !SetupStdFile(outputFile, TCL_STDOUT) || (!joinThisError && !SetupStdFile(errorFile, TCL_STDERR)) || (joinThisError && ((dup2(1,2) == -1) || (fcntl(2, F_SETFD, 0) != 0)))) { sprintf(errSpace, "%dforked process couldn't set up input/output: ", errno); (void)write(fd, errSpace, (size_t) strlen(errSpace)); _exit(1); } /* * Close the input side of the error pipe. */ RestoreSignals(); execvp(newArgv[0], newArgv); /* INTL: Native. */ sprintf(errSpace, "%dcouldn't execute \"%.150s\": ", errno, argv[0]); (void)write(fd, errSpace, (size_t) strlen(errSpace)); _exit(1); } /* * Free the mem we used for the fork */ for (i = 0; i < argc; i++) { Tcl_DStringFree(&dsArray[i]); } TclStackFree(interp, newArgv); TclStackFree(interp, dsArray); if (pid == -1) { Tcl_AppendResult(interp, "couldn't fork child process: ", Tcl_PosixError(interp), NULL); goto error; } /* * Read back from the error pipe to see if the child started up OK. The * info in the pipe (if any) consists of a decimal errno value followed by * an error message. */ TclpCloseFile(errPipeOut); errPipeOut = NULL; fd = GetFd(errPipeIn); count = read(fd, errSpace, (size_t) (sizeof(errSpace) - 1)); if (count > 0) { char *end; errSpace[count] = 0; errno = strtol(errSpace, &end, 10); Tcl_AppendResult(interp, end, Tcl_PosixError(interp), NULL); goto error; } TclpCloseFile(errPipeIn); *pidPtr = (Tcl_Pid) INT2PTR(pid); return TCL_OK; error: if (pid != -1) { /* * Reap the child process now if an error occurred during its startup. * We don't call this with WNOHANG because that can lead to defunct * processes on an MP system. We shouldn't have to worry about hanging * here, since this is the error case. [Bug: 6148] */ Tcl_WaitPid((Tcl_Pid) INT2PTR(pid), &status, 0); } if (errPipeIn) { TclpCloseFile(errPipeIn); } if (errPipeOut) { TclpCloseFile(errPipeOut); } return TCL_ERROR; }
Tcl_Channel Tcl_OpenTcpServer( Tcl_Interp *interp, /* For error reporting - may be NULL. */ int port, /* Port number to open. */ const char *myHost, /* Name of local host. */ Tcl_TcpAcceptProc *acceptProc, /* Callback for accepting connections from new * clients. */ ClientData acceptProcData) /* Data for the callback. */ { int status = 0, sock = -1, reuseaddr = 1, chosenport = 0; struct addrinfo *addrlist = NULL, *addrPtr; /* socket address */ TcpState *statePtr = NULL; char channelName[SOCK_CHAN_LENGTH]; const char *errorMsg = NULL; TcpFdList *fds = NULL, *newfds; /* * Try to record and return the most meaningful error message, i.e. the * one from the first socket that went the farthest before it failed. */ enum { LOOKUP, SOCKET, BIND, LISTEN } howfar = LOOKUP; int my_errno = 0; if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) { my_errno = errno; goto error; } for (addrPtr = addrlist; addrPtr != NULL; addrPtr = addrPtr->ai_next) { sock = socket(addrPtr->ai_family, addrPtr->ai_socktype, addrPtr->ai_protocol); if (sock == -1) { if (howfar < SOCKET) { howfar = SOCKET; my_errno = errno; } continue; } /* * Set the close-on-exec flag so that the socket will not get * inherited by child processes. */ fcntl(sock, F_SETFD, FD_CLOEXEC); /* * Set kernel space buffering */ TclSockMinimumBuffers(INT2PTR(sock), SOCKET_BUFSIZE); /* * Set up to reuse server addresses automatically and bind to the * specified port. */ (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &reuseaddr, sizeof(reuseaddr)); /* * Make sure we use the same port number when opening two server * sockets for IPv4 and IPv6 on a random port. * * As sockaddr_in6 uses the same offset and size for the port member * as sockaddr_in, we can handle both through the IPv4 API. */ if (port == 0 && chosenport != 0) { ((struct sockaddr_in *) addrPtr->ai_addr)->sin_port = htons(chosenport); } #ifdef IPV6_V6ONLY /* Missing on: Solaris 2.8 */ if (addrPtr->ai_family == AF_INET6) { int v6only = 1; (void) setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, sizeof(v6only)); } #endif /* IPV6_V6ONLY */ status = bind(sock, addrPtr->ai_addr, addrPtr->ai_addrlen); if (status == -1) { if (howfar < BIND) { howfar = BIND; my_errno = errno; } close(sock); sock = -1; continue; } if (port == 0 && chosenport == 0) { address sockname; socklen_t namelen = sizeof(sockname); /* * Synchronize port numbers when binding to port 0 of multiple * addresses. */ if (getsockname(sock, &sockname.sa, &namelen) >= 0) { chosenport = ntohs(sockname.sa4.sin_port); } } status = listen(sock, SOMAXCONN); if (status < 0) { if (howfar < LISTEN) { howfar = LISTEN; my_errno = errno; } close(sock); sock = -1; continue; } if (statePtr == NULL) { /* * Allocate a new TcpState for this socket. */ statePtr = ckalloc(sizeof(TcpState)); memset(statePtr, 0, sizeof(TcpState)); statePtr->acceptProc = acceptProc; statePtr->acceptProcData = acceptProcData; sprintf(channelName, SOCK_TEMPLATE, (long) statePtr); newfds = &statePtr->fds; } else { newfds = ckalloc(sizeof(TcpFdList)); memset(newfds, (int) 0, sizeof(TcpFdList)); fds->next = newfds; } newfds->fd = sock; newfds->statePtr = statePtr; fds = newfds; /* * Set up the callback mechanism for accepting connections from new * clients. */ Tcl_CreateFileHandler(sock, TCL_READABLE, TcpAccept, fds); } error: if (addrlist != NULL) { freeaddrinfo(addrlist); } if (statePtr != NULL) { statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, statePtr, 0); return statePtr->channel; } if (interp != NULL) { Tcl_Obj *errorObj = Tcl_NewStringObj("couldn't open socket: ", -1); if (errorMsg == NULL) { errno = my_errno; Tcl_AppendToObj(errorObj, Tcl_PosixError(interp), -1); } else { Tcl_AppendToObj(errorObj, errorMsg, -1); } Tcl_SetObjResult(interp, errorObj); } if (sock != -1) { close(sock); } return NULL; }