static PyObject* __import__(FILE *file, char *name, char *path, char *as, PyObject *local, PyObject *global) { assert(file); assert(name); PyObject *m; PyCodeObject *co = NULL; char *module_name = as ? as : name; if((m = get_exists(name, path))) { Py_INCREF(m); return m; } co = compile(file); //Ps_LogObject((PyObject*)co, Ps_LOG_WARING); if(co == NULL) { Ps_Log("compile failed\n", Ps_LOG_WARING); return NULL; } m = create_module(name, (PyObject*)co); if(m == NULL) { Ps_Log("create_module failed\n", Ps_LOG_WARING); return NULL; } Py_DECREF(co); if(local && PyDict_Check(local)) { Py_INCREF(m); #ifdef IMPORT_DEBUG Ps_LogFormat("The module name is %s\n", Ps_LOG_NORMAL, module_name); Ps_LogObject(local, Ps_LOG_WARING); Ps_LogObject(m, Ps_LOG_WARING); int ret = #endif PyDict_SetItemString(local, module_name, m); #ifdef IMPORT_DEBUG if(ret == 0) Ps_LogFormat("ret is %d, Import module %s successfully\n", Ps_LOG_NORMAL, ret, module_name); else Ps_LogFormat("ret is %d, Import module %s failed\n", Ps_LOG_NORMAL, ret, module_name); #endif } else { PyObject *info = PyString_FromFormat("Import module %s failed", name); if(!info) { PyErr_SetString(PyExc_ImportError, "Import module failed"); } else PyErr_SetObject(PyExc_ImportError, info); return NULL; } return m; }
void receive_data (void) { unsigned int count; u_short perm; char *buffer; int bufsize; int fd; int len, len2; int error; char exists; int readsize; if (debug) diag("receiving data"); if ((tempmode&SEND_OVER) == 0) exists = 0; else if ( ! get_exists ( &exists ) ) efatal("server read failed"); if (debug) diag("exists %d", exists); if (exists) { if ( ! get_perm ( &perm ) ) efatal("server read failed"); if ( ! get_count ( &count ) ) efatal("server read failed"); } else { perm = 0600; count = 0; } concat ( temppath, sizeof(temppath), tempdir, "/", tempfile, NULL ); tempfile = temppath; if (debug) { diag("perm %#o, count %d", perm, count); diag("d: %s f: %s p: %s", tempdir, tempfile, temppath ); } fd = open ( tempfile, O_CREAT | O_RDWR, 0600 ); if (debug) diag("tempfile %s", tempfile); if (fchmod(fd, (mode_t) (perm & ( S_IRWXU | S_IRWXG | S_IRWXO ) ) ) < 0) efatal("fchmod failed"); if (!exists) (void) unlink(tempfile); if (count == 0) { (void) close(fd); return; } /* * should check for space on disk, but could be expensive and unreliable */ if ((bufsize = count) > 10*1024) buffer = (char *) malloc(bufsize = 10*1024); else buffer = (char *) malloc(bufsize); if (buffer == NULL) fatal("malloc failed"); while (count != 0) { if (debug) diag("loop count %d", count); if ( count > bufsize ) readsize = bufsize; else readsize = count; /* if */ get_buffer ( buffer, &len, readsize, fd ); if ((len2 = write(fd, buffer, len)) != len) { error = errno; (void) close(fd); (void) unlink(tempfile); (void) rmdir(tempdir); errno = error; efatal("write", error); } count -= len; if (count < bufsize) bufsize = count; } if (close(fd) < 0) { error = errno; (void) unlink(tempfile); (void) rmdir(tempdir); errno = error; efatal("close"); } (void) free(buffer); if (debug) diag("transfer complete"); } /* end receive_data */